summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libasf/asf.c52
-rw-r--r--apps/codecs/libasf/asf.h5
-rw-r--r--apps/codecs/wma.c54
3 files changed, 56 insertions, 55 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 */
diff --git a/apps/codecs/wma.c b/apps/codecs/wma.c
index 235f1a38c9..17d2af2e98 100644
--- a/apps/codecs/wma.c
+++ b/apps/codecs/wma.c
@@ -34,60 +34,6 @@ static uint32_t decoded[BLOCK_MAX_SIZE * MAX_CHANNELS] IBSS_ATTR;
34/* NOTE: WMADecodeContext is 120152 bytes (on x86) */ 34/* NOTE: WMADecodeContext is 120152 bytes (on x86) */
35static WMADecodeContext wmadec; 35static WMADecodeContext wmadec;
36 36
37/*entry point for seeks*/
38static int seek(int ms, asf_waveformatex_t* wfx)
39{
40 int time, duration, delta, temp, count=0;
41
42 /*estimate packet number from bitrate*/
43 int initial_packet = ci->curpos/wfx->packet_size;
44 int packet_num = (((int64_t)ms)*(wfx->bitrate>>3))/wfx->packet_size/1000;
45 int last_packet = ci->id3->filesize / wfx->packet_size;
46
47 if (packet_num > last_packet) {
48 packet_num = last_packet;
49 }
50
51 /*calculate byte address of the start of that packet*/
52 int packet_offset = packet_num*wfx->packet_size;
53
54 /*seek to estimated packet*/
55 ci->seek_buffer(ci->id3->first_frame_offset+packet_offset);
56 temp = ms;
57 while (1)
58 {
59 /*for very large files it can be difficult and unimportant to find the exact packet*/
60 count++;
61
62 /*check the time stamp of our packet*/
63 time = asf_get_timestamp(&duration);
64 DEBUGF("seeked to %d ms with duration %d\n", time, duration);
65
66 if (time < 0) {
67 /*unknown error, try to recover*/
68 DEBUGF("UKNOWN SEEK ERROR\n");
69 ci->seek_buffer(ci->id3->first_frame_offset+initial_packet*wfx->packet_size);
70 /*seek failed so return time stamp of the initial packet*/
71 return asf_get_timestamp(&duration);
72 }
73
74 if ((time+duration>=ms && time<=ms) || count > 10) {
75 DEBUGF("Found our packet! Now at %d packet\n", packet_num);
76 return time;
77 } else {
78 /*seek again*/
79 delta = ms-time;
80 /*estimate new packet number from bitrate and our current position*/
81 temp += delta;
82 packet_num = ((temp/1000)*(wfx->bitrate>>3) - (wfx->packet_size>>1))/wfx->packet_size; //round down!
83 packet_offset = packet_num*wfx->packet_size;
84 ci->seek_buffer(ci->id3->first_frame_offset+packet_offset);
85 }
86 }
87}
88
89
90
91/* this is the codec entry point */ 37/* this is the codec entry point */
92enum codec_status codec_main(void) 38enum codec_status codec_main(void)
93{ 39{