summaryrefslogtreecommitdiff
path: root/apps/codecs/libasf
diff options
context:
space:
mode:
authorMohamed Tarek <mt@rockbox.org>2010-05-21 15:51:22 +0000
committerMohamed Tarek <mt@rockbox.org>2010-05-21 15:51:22 +0000
commit546edf36217573ec6813958552fda9330ac67131 (patch)
tree6036d48b28c0f1cdce561b7a9c6d3ef00926e91e /apps/codecs/libasf
parentff25b3a20838241da597212a5faf9cb275420ab7 (diff)
downloadrockbox-546edf36217573ec6813958552fda9330ac67131.tar.gz
rockbox-546edf36217573ec6813958552fda9330ac67131.zip
Move seek() from wma.c to libasf since it's really ASF-specific.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26235 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libasf')
-rw-r--r--apps/codecs/libasf/asf.c52
-rw-r--r--apps/codecs/libasf/asf.h5
2 files changed, 56 insertions, 1 deletions
diff --git a/apps/codecs/libasf/asf.c b/apps/codecs/libasf/asf.c
index 18503218b7..65d3fd8deb 100644
--- a/apps/codecs/libasf/asf.c
+++ b/apps/codecs/libasf/asf.c
@@ -376,3 +376,55 @@ int asf_get_timestamp(int *duration)
376 376
377 return send_time; 377 return send_time;
378} 378}
379
380/*entry point for seeks*/
381int seek(int ms, asf_waveformatex_t* wfx)
382{
383 int time, duration, delta, temp, count=0;
384
385 /*estimate packet number from bitrate*/
386 int initial_packet = ci->curpos/wfx->packet_size;
387 int packet_num = (((int64_t)ms)*(wfx->bitrate>>3))/wfx->packet_size/1000;
388 int last_packet = ci->id3->filesize / wfx->packet_size;
389
390 if (packet_num > last_packet) {
391 packet_num = last_packet;
392 }
393
394 /*calculate byte address of the start of that packet*/
395 int packet_offset = packet_num*wfx->packet_size;
396
397 /*seek to estimated packet*/
398 ci->seek_buffer(ci->id3->first_frame_offset+packet_offset);
399 temp = ms;
400 while (1)
401 {
402 /*for very large files it can be difficult and unimportant to find the exact packet*/
403 count++;
404
405 /*check the time stamp of our packet*/
406 time = asf_get_timestamp(&duration);
407 DEBUGF("seeked to %d ms with duration %d\n", time, duration);
408
409 if (time < 0) {
410 /*unknown error, try to recover*/
411 DEBUGF("UKNOWN SEEK ERROR\n");
412 ci->seek_buffer(ci->id3->first_frame_offset+initial_packet*wfx->packet_size);
413 /*seek failed so return time stamp of the initial packet*/
414 return asf_get_timestamp(&duration);
415 }
416
417 if ((time+duration>=ms && time<=ms) || count > 10) {
418 DEBUGF("Found our packet! Now at %d packet\n", packet_num);
419 return time;
420 } else {
421 /*seek again*/
422 delta = ms-time;
423 /*estimate new packet number from bitrate and our current position*/
424 temp += delta;
425 packet_num = ((temp/1000)*(wfx->bitrate>>3) - (wfx->packet_size>>1))/wfx->packet_size; //round down!
426 packet_offset = packet_num*wfx->packet_size;
427 ci->seek_buffer(ci->id3->first_frame_offset+packet_offset);
428 }
429 }
430}
diff --git a/apps/codecs/libasf/asf.h b/apps/codecs/libasf/asf.h
index c15bf4edec..9592618997 100644
--- a/apps/codecs/libasf/asf.h
+++ b/apps/codecs/libasf/asf.h
@@ -32,7 +32,8 @@ struct asf_waveformatex_s {
32 uint16_t blockalign; 32 uint16_t blockalign;
33 uint16_t bitspersample; 33 uint16_t bitspersample;
34 uint16_t datalen; 34 uint16_t datalen;
35 uint8_t data[6]; 35 uint16_t numpackets;
36 uint8_t data[18];
36}; 37};
37typedef struct asf_waveformatex_s asf_waveformatex_t; 38typedef struct asf_waveformatex_s asf_waveformatex_t;
38 39
@@ -41,5 +42,7 @@ int asf_read_packet(uint8_t** audiobuf, int* audiobufsize, int* packetlength,
41 42
42int asf_get_timestamp(int *duration); 43int asf_get_timestamp(int *duration);
43 44
45int seek(int ms, asf_waveformatex_t* wfx);
46
44 47
45#endif /* _ASF_H */ 48#endif /* _ASF_H */