1This is the current media_seek_type from MediaTrack.h: 2 3enum media_seek_type { 4 B_MEDIA_SEEK_CLOSEST_FORWARD = 1, 5 B_MEDIA_SEEK_CLOSEST_BACKWARD = 2, 6 B_MEDIA_SEEK_DIRECTION_MASK = 3 7}; 8 9It is used as an argument to these BMediaTrack functions: 10 11status_t SeekToFrame(int64 *ioFrame, int32 flags = 0) 12status_t SeekToTime(bigtime_t *ioTime, int32 flags = 0) 13 14Those int32 should be changed to media_seek_type? 15 16============================ 17 18Here are some aspects of seeking: 19 20A. Where are you seeking from? 21 1. the start of the file 22 Currently is done always now. 23 2. the current position 24 Suggested for streams, or other situations where you might lose track of your position. 25 3. the end of the file 26 Suggested for completeness. 27 28B. Which direction are you seeking in? 29 1. backwards 30 This is most useful for A2, A3. 31 If you seek to before the beginning of the stream you could reasonably wait until enough time elapsed that you should be at the start of the stream, and then begin playing the beginning of the stream. 32 2. forwards 33 This is most useful for A1, A2. 34 If you seek past the end of the stream you can only hope that you receive data on the stream faster than time elapses. At that point you could begin playing. 35 36C. How far are you seeking? 37 1. specify by time 38 Currently supported via SeekToTime 39 2. specify by frame 40 Currently supported via SeekToFrame 41 3. specify by chunk 42 Suggested for completeness. This may prevent someone from having to loop over ReadChunk in order to get to a position. 43 4. specify by percentage 44 Suggested for efficiency. For applications such as players which do not require precise time/frame based seeking, this may allow fast seeking. (especially for nonindexed tracks) After seeking like this absolute time/frame information maybe not be available. 45 46------------ 47 48D. What constitutes a usable position? 49 0. track's discretion 50 1. a frame that can be decoded in 1 step 51 Currently supported by most tracks AFAIK. 52 2. a frame that can be decoded in multiple steps 53 Suggested to allow exact but slow searching. 54 3. any frame 55 Suggested to allow very fast searching. 56 57E. What should the track do if you specified a position that is not usable? 58 0. track's discretion 59 Currently supported by supplying no seek flags. 60 1. go backward until you reach a usable position 61 Currently supported by supplying B_MEDIA_SEEK_CLOSEST_BACKWARD as a seek flag. 62 2. go forward until you reach a usable position 63 Currently supported by supplying B_MEDIA_SEEK_CLOSEST_FORWARD as a seek flag. 64 3. go whichever direction has the nearest usable position 65 Suggested to get as close to the specified time/frame as possible. 66 67F. What state should the decoder for this track be left in? 68 1. whatever state it was in before 69 Not recommended. May even not be possible since the decoder's help may be required for seeking. 70 2. track's discretion 71 Suggested for efficiency. 72 3. prepared to return a correct, decoded frame 73 Currently supported by supplying no seek flags. 74 4. prepared to return meaningless frames until a usable position is reached 75 Not recommended: doubtful anyone would want to supply such a flag. 76 Only meaningful in conjunction with D3. 77 5. prepared to return empty frames until a usable position is reached 78 Not recommended. Requires some meaningful "empty" frame to be supplied: probably from the decoder. For video this would probably be a black colored frame (in whatever colorspace you are in). For audio this would probably be silence. Advantage: no work for app. Disadvantages: work for decoder, no way for app to know that this isn't the "real" frame. 79 6. prepared to return non-frames until a usable position is reached 80 Suggested for efficiency. Requires some sort of flag to be returned. Could be implemented by a status_t (B_EMPTY_FRAME or B_EMPTY_FRAMES) which would be returned from a subsequent call to ReadFrames() 81 Only meaningful in conjunction with D3. 82 83G. How much information must be reliable after the seek? 84 1. the current frame 85 2. the current time 86 3. the current percentage 87 4. the current chunk 88 5. track's discretion 89 90"<marcus_o> B_MEDIA_SEEK_LAZY -> resulting seek is inaccourate, timing information might be wrong after doing it, but it's very fast way to seek in files 91<marcus_o> used for display purposes, when you want to seek to about 85% of a MPEG video or something similar" 92 93H. What should be done about other tracks that are also from the same source as this track? 94 1. do nothing 95 Currently supported by suppling no seek flags. 96 2. seek the open tracks to whatever time this track ends up at 97 Suggested for convenience, efficiency. The track would seek itself first and then seek the other open tracks to the resulting position. 98 3. seek all other tracks to whatever time this track ends up at 99 Not recommended: may be uselessly costly if there are a lot of nonopen tracks. 100 4. seek the open tracks to the same time 101 Not recommended: this is just asking for trouble and if someone wants to do this then can simply loop over all the tracks. 102 5. seek all other tracks to the same time 103 Not recommended: this is just asking for trouble and maybe very costly if there are a lot of nonopen tracks 104 105"<marcus_o> B_MEDIA_SEEK_ALL_TRACKS -> seeks all tracks (audio and video) that belong to the file that this track belongs to 106<marcus_o> makes sure you can seek a file without introducing loss of sync betewwn audio/video/subtitles, whatever" 107 108============================ 109 110Andrew Bachmann's proposal: 111 112A: provide all by another parameter on each seek function. use the posix SEEK_SET, SEEK_CUR, SEEK_END 113 114B: use the sign of the first parameter (+=forward, -=backward) 115 116C: provide all by adding two new functions: 117SeekToChunk(int64 * ioChunk, media_seek_type flags) 118 same as calling ReadChunk for ioChunk times. not sure the flags are necessary. 119SeekToPercentage(int64 * ioNumerator, media_seek_type flags) 120 similar to SeekToTime(Duration()*(ioNumerator/MAX_INT64),flags) or 121 SeekToFrame(CountFrames()*(ioNumerator/MAX_INT64),flags) but 122 possibly much more efficient 123 124D: provide all by using new seek bits 125 supplying no bits is the same as supplying all bits (ANY) 126 ANY = IMMEDIATE | SLOW | IGNORE 127 B_MEDIA_SEEK_DECODABILITY_ANY (per D0) 128 B_MEDIA_SEEK_DECODABILITY_IMMEDIATE (per D1) 129 B_MEDIA_SEEK_DECODABILITY_SLOW (per D2) 130 B_MEDIA_SEEK_DECODABILITY_IGNORE (per D3) 131 132E: provide all by using the existing seek bits + new bit 133 supplying no bits is the same as suppling all bits (ANY) 134 ANY = BACKWARD | FORWARD | NEAREST 135 B_MEDIA_SEEK_DIRECTION_ANY (per E0) 136 B_MEDIA_SEEK_CLOSEST_BACKWARD (per E1) 137 B_MEDIA_SEEK_CLOSEST_FORWARD (per E2) 138 B_MEDIA_SEEK_DIRECTION_NEAREST (per E3) 139 140F: support F3 and F6 141 if B_MEDIA_SEEK_DECODABILITY_IMMEDIATE or B_MEDIA_SEEK_DECODABILITY_SLOW 142 then the decoder should be ready. (we want meaningful frames) 143 if B_MEDIA_SEEK_DECODABILITY_IGNORE 144 then if the decoder is not ready 145 ReadFrames() will return B_EMPTY_FRAMES until it is ready. 146 147G: provide all by using new seek bits 148 supplying no bits means is the same as suppling NOTHING 149 ALL = FRAME | TIME | PERCENTAGE | CHUNK 150 B_MEDIA_SEEK_CURRENT_NOTHING 151 B_MEDIA_SEEK_CURRENT_FRAME (H1) 152 B_MEDIA_SEEK_CURRENT_TIME (H2) 153 B_MEDIA_SEEK_CURRENT_PERCENTAGE (H3) 154 B_MEDIA_SEEK_CURRENT_CHUNK (H4) 155 B_MEDIA_SEEK_CURRENT_ALL 156 157H: support H1 and H2 by using a new seek bit 158 supplying no bits means don't seek open tracks 159 B_MEDIA_SEEK_SYNC_OPEN_TRACKS (per G2) 160 161