Skip to content

Commit a19cba7

Browse files
committed
design: tweak Clip interface to separate seeking
Seeking within the audio source is not always a trivial problem, e.g. the cases where the underlying source is encoded with a VBR compression algorithm, optimistic seeking and slurping the entire data source may be required. Separation of the Seek method allows us to explain the requirements from the implementors more easily. Since different encoders will have different stragies to Seek, it is also easy to document the cost and the underlying algorithm to the users. Also, the seperation helps us document the requirements of implementing an efficient Clip.Frames. We are explecting decoders to have a cursor on the data source and move forward as new Frames calls arrive. We only expect them to modify the cursor if seeking is required. Without a separate Seek method, implementors need to check if the offset is matching with their current internal cursor and seek if it is not. Separation saves them figuring out the conditional case for a requirement of seeking. Change-Id: I0b15d56df9457a462953aaaf915445e268462f97 Reviewed-on: https://go-review.googlesource.com/24702 Reviewed-by: David Crawshaw <[email protected]>
1 parent 09f1516 commit a19cba7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

design/13432-mobile-audio.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,16 @@ type FrameInfo struct {
148148
//
149149
// FrameInfo returns the basic frame information about the clip audio.
150150
//
151+
// Seek seeks (offset*framesize*channels) byte in the source audio data.
152+
// Seeking to negative offsets are illegal.
153+
// An error is returned if the offset is out of the bounds of the
154+
// audio data source.
155+
//
151156
// Size returns the total number of bytes of the underlying audio data.
152157
// TODO(jbd): Support cases where size is unknown?
153158
type Clip interface {
154-
Frames(buf []byte, offset int64) (n int, err error)
159+
Frames(buf []byte) (n int, err error)
160+
Seek(offset int64) (error)
155161
FrameInfo() FrameInfo
156162
Size() int64
157163
}

0 commit comments

Comments
 (0)