diff options
author | Mohamed Tarek <mt@rockbox.org> | 2009-07-12 14:36:06 +0000 |
---|---|---|
committer | Mohamed Tarek <mt@rockbox.org> | 2009-07-12 14:36:06 +0000 |
commit | edf3af2c68287943bbf8498965e80e7193279e5e (patch) | |
tree | e6c7a0971fcc9649fa8fb4e2d25715e3905fb1d0 /apps | |
parent | 59b9e3ab3f64c17aaf093f0031a5e93ea5120170 (diff) | |
download | rockbox-edf3af2c68287943bbf8498965e80e7193279e5e.tar.gz rockbox-edf3af2c68287943bbf8498965e80e7193279e5e.zip |
Add seeking support in cook codec.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21806 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/cook.c | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/apps/codecs/cook.c b/apps/codecs/cook.c index b23e523738..cebf192110 100644 --- a/apps/codecs/cook.c +++ b/apps/codecs/cook.c | |||
@@ -41,12 +41,12 @@ static void init_rm(RMContext *rmctx) | |||
41 | enum codec_status codec_main(void) | 41 | enum codec_status codec_main(void) |
42 | { | 42 | { |
43 | static size_t buff_size; | 43 | static size_t buff_size; |
44 | int datasize, res, consumed,i; | 44 | int datasize, res, consumed, i, j, time_offset; |
45 | uint8_t *bit_buffer; | 45 | uint8_t *bit_buffer; |
46 | int16_t outbuf[2048] __attribute__((aligned(32))); | 46 | int16_t outbuf[2048] __attribute__((aligned(32))); |
47 | uint16_t fs,sps,h; | 47 | uint16_t fs,sps,h; |
48 | uint32_t packet_count; | 48 | uint32_t packet_count; |
49 | int scrambling_unit_size; | 49 | int scrambling_unit_size, flag_seek_block = 0; |
50 | 50 | ||
51 | next_track: | 51 | next_track: |
52 | if (codec_init()) { | 52 | if (codec_init()) { |
@@ -95,26 +95,58 @@ seek_start : | |||
95 | DEBUGF("rm_get_packet failed\n"); | 95 | DEBUGF("rm_get_packet failed\n"); |
96 | return CODEC_ERROR; | 96 | return CODEC_ERROR; |
97 | } | 97 | } |
98 | /*DEBUGF(" version = %d\n" | 98 | |
99 | " length = %d\n" | ||
100 | " stream = %d\n" | ||
101 | " timestamp= %d\n",pkt.version,pkt.length,pkt.stream_number,pkt.timestamp);*/ | ||
102 | |||
103 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) | 99 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) |
104 | { | 100 | { |
105 | ci->yield(); | 101 | ci->yield(); |
106 | if (ci->stop_codec || ci->new_track) | 102 | if (ci->stop_codec || ci->new_track) |
107 | goto done; | 103 | goto done; |
108 | if (ci->seek_time == 1) { | 104 | |
105 | if (ci->seek_time) { | ||
109 | ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE); | 106 | ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE); |
110 | ci->set_elapsed(0); | ||
111 | packet_count = rmctx.nb_packets; | 107 | packet_count = rmctx.nb_packets; |
112 | rmctx.audio_pkt_cnt = 0; | 108 | rmctx.audio_pkt_cnt = 0; |
113 | rmctx.frame_number = 0; | 109 | rmctx.frame_number = 0; |
114 | ci->seek_complete(); | 110 | if (ci->seek_time == 1) { |
115 | goto seek_start; | 111 | ci->set_elapsed(0); |
116 | } | 112 | ci->seek_complete(); |
117 | 113 | goto seek_start; | |
114 | } | ||
115 | j = 0; | ||
116 | while(1) { | ||
117 | rmctx.audio_pkt_cnt = 0; | ||
118 | bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size); | ||
119 | consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt); | ||
120 | if(consumed < 0) { | ||
121 | DEBUGF("rm_get_packet failed\n"); | ||
122 | return CODEC_ERROR; | ||
123 | } | ||
124 | if(rmctx.audiotimestamp < (unsigned) ci->seek_time) { | ||
125 | ci->advance_buffer(consumed); | ||
126 | packet_count -= rmctx.audio_pkt_cnt; | ||
127 | rmctx.frame_number += h*(fs/sps); | ||
128 | j+= consumed; | ||
129 | } | ||
130 | if(rmctx.audiotimestamp > (unsigned) ci->seek_time) { | ||
131 | flag_seek_block = 1; | ||
132 | rmctx.audio_pkt_cnt = 0; | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | if(flag_seek_block) { | ||
138 | ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE + j - consumed); | ||
139 | bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size); | ||
140 | consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt); | ||
141 | packet_count += rmctx.audio_pkt_cnt; | ||
142 | rmctx.frame_number -= h*(fs/sps); | ||
143 | time_offset = ci->seek_time - rmctx.audiotimestamp; | ||
144 | i = (time_offset/((sps * 8 * 1000)/rmctx.bit_rate)); | ||
145 | flag_seek_block = 0; | ||
146 | ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i); | ||
147 | ci->seek_complete(); | ||
148 | } | ||
149 | } | ||
118 | res = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align); | 150 | res = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align); |
119 | rmctx.frame_number++; | 151 | rmctx.frame_number++; |
120 | 152 | ||
@@ -127,7 +159,7 @@ seek_start : | |||
127 | } | 159 | } |
128 | 160 | ||
129 | ci->pcmbuf_insert(outbuf, NULL, rmctx.samples_pf_pc / rmctx.nb_channels); | 161 | ci->pcmbuf_insert(outbuf, NULL, rmctx.samples_pf_pc / rmctx.nb_channels); |
130 | ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i); | 162 | ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i); |
131 | } | 163 | } |
132 | packet_count -= rmctx.audio_pkt_cnt; | 164 | packet_count -= rmctx.audio_pkt_cnt; |
133 | rmctx.audio_pkt_cnt = 0; | 165 | rmctx.audio_pkt_cnt = 0; |