summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohamed Tarek <mt@rockbox.org>2009-10-03 00:18:42 +0000
committerMohamed Tarek <mt@rockbox.org>2009-10-03 00:18:42 +0000
commitf0c6c88f6d6afef6fa8bba311ce1bcf1873f8a90 (patch)
treec05bc252e50563196cc453de3b024f3ac5dde365
parent8d5acd64c9d0c3610ec595c7f61deb7f4eec417f (diff)
downloadrockbox-f0c6c88f6d6afef6fa8bba311ce1bcf1873f8a90.tar.gz
rockbox-f0c6c88f6d6afef6fa8bba311ce1bcf1873f8a90.zip
Smarter check for failed packet parsing in RM. Also fixes a bug in playback where sometimes "codec failure" is splashed at the end of playback.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22880 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/a52_rm.c19
-rw-r--r--apps/codecs/atrac3_rm.c27
-rw-r--r--apps/codecs/raac.c28
3 files changed, 56 insertions, 18 deletions
diff --git a/apps/codecs/a52_rm.c b/apps/codecs/a52_rm.c
index 50269aea9d..32b66d2826 100644
--- a/apps/codecs/a52_rm.c
+++ b/apps/codecs/a52_rm.c
@@ -130,7 +130,8 @@ enum codec_status codec_main(void)
130{ 130{
131 size_t n; 131 size_t n;
132 uint8_t *filebuf; 132 uint8_t *filebuf;
133 int retval, consumed, packet_offset; 133 int retval, consumed, packet_offset;
134 int playback_on = -1;
134 135
135 /* Generic codec initialisation */ 136 /* Generic codec initialisation */
136 ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); 137 ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED);
@@ -173,10 +174,20 @@ next_track:
173 174
174 filebuf = ci->request_buffer(&n, rmctx.block_align + PACKET_HEADER_SIZE); 175 filebuf = ci->request_buffer(&n, rmctx.block_align + PACKET_HEADER_SIZE);
175 consumed = rm_get_packet(&filebuf, &rmctx, &pkt); 176 consumed = rm_get_packet(&filebuf, &rmctx, &pkt);
176 if(consumed < 0) { 177
177 DEBUGF("rm_get_packet failed\n"); 178 if(consumed < 0 && playback_on != 0) {
178 return CODEC_ERROR; 179 if(playback_on == -1) {
180 /* Error only if packet-parsing failed and playback hadn't started */
181 DEBUGF("rm_get_packet failed\n");
182 return CODEC_ERROR;
183 }
184 else {
185 retval = CODEC_OK;
186 goto exit;
187 }
179 } 188 }
189
190 playback_on = 1;
180 a52_decode_data(filebuf, filebuf + rmctx.block_align); 191 a52_decode_data(filebuf, filebuf + rmctx.block_align);
181 ci->advance_buffer(pkt.length); 192 ci->advance_buffer(pkt.length);
182 } 193 }
diff --git a/apps/codecs/atrac3_rm.c b/apps/codecs/atrac3_rm.c
index f3bfa2f801..75c0d1581b 100644
--- a/apps/codecs/atrac3_rm.c
+++ b/apps/codecs/atrac3_rm.c
@@ -44,6 +44,7 @@ enum codec_status codec_main(void)
44 uint16_t fs,sps,h; 44 uint16_t fs,sps,h;
45 uint32_t packet_count; 45 uint32_t packet_count;
46 int scrambling_unit_size, num_units, elapsed = 0; 46 int scrambling_unit_size, num_units, elapsed = 0;
47 int playback_on = -1;
47 48
48next_track: 49next_track:
49 if (codec_init()) { 50 if (codec_init()) {
@@ -88,9 +89,14 @@ seek_start :
88 { 89 {
89 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size); 90 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size);
90 consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt); 91 consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt);
91 if(consumed < 0) { 92 if(consumed < 0 && playback_on != 0) {
92 DEBUGF("rm_get_packet failed\n"); 93 if(playback_on == -1) {
93 return CODEC_ERROR; 94 /* Error only if packet-parsing failed and playback hadn't started */
95 DEBUGF("rm_get_packet failed\n");
96 return CODEC_ERROR;
97 }
98 else
99 goto done;
94 } 100 }
95 101
96 for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) 102 for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
@@ -123,10 +129,16 @@ seek_start :
123 ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE + consumed * num_units); 129 ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE + consumed * num_units);
124 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size); 130 bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size);
125 consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt); 131 consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt);
126 if(consumed < 0) { 132 if(consumed < 0 && playback_on != 0) {
127 DEBUGF("rm_get_packet failed\n"); 133 if(playback_on == -1) {
128 return CODEC_ERROR; 134 /* Error only if packet-parsing failed and playback hadn't started */
129 } 135 DEBUGF("rm_get_packet failed\n");
136 return CODEC_ERROR;
137 }
138 else
139 goto done;
140 }
141
130 packet_count = rmctx.nb_packets - rmctx.audio_pkt_cnt * num_units; 142 packet_count = rmctx.nb_packets - rmctx.audio_pkt_cnt * num_units;
131 rmctx.frame_number = ((ci->seek_time)/(sps*1000*8/rmctx.bit_rate)); 143 rmctx.frame_number = ((ci->seek_time)/(sps*1000*8/rmctx.bit_rate));
132 while(rmctx.audiotimestamp > (unsigned) ci->seek_time) { 144 while(rmctx.audiotimestamp > (unsigned) ci->seek_time) {
@@ -155,6 +167,7 @@ seek_start :
155 167
156 if(datasize) 168 if(datasize)
157 ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024, q.samples_per_frame / rmctx.nb_channels); 169 ci->pcmbuf_insert(q.outSamples, q.outSamples + 1024, q.samples_per_frame / rmctx.nb_channels);
170 playback_on = 1;
158 elapsed = rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i; 171 elapsed = rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i;
159 ci->set_elapsed(elapsed); 172 ci->set_elapsed(elapsed);
160 rmctx.frame_number++; 173 rmctx.frame_number++;
diff --git a/apps/codecs/raac.c b/apps/codecs/raac.c
index db113b3494..b886136bd9 100644
--- a/apps/codecs/raac.c
+++ b/apps/codecs/raac.c
@@ -47,6 +47,8 @@ enum codec_status codec_main(void)
47 int err, consumed, pkt_offset, skipped = 0; 47 int err, consumed, pkt_offset, skipped = 0;
48 uint32_t s = 0; /* sample rate */ 48 uint32_t s = 0; /* sample rate */
49 unsigned char c = 0; /* channels */ 49 unsigned char c = 0; /* channels */
50 int playback_on = -1;
51
50 /* Generic codec initialisation */ 52 /* Generic codec initialisation */
51 ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); 53 ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED);
52 ci->configure(DSP_SET_SAMPLE_DEPTH, 16); 54 ci->configure(DSP_SET_SAMPLE_DEPTH, 16);
@@ -123,9 +125,14 @@ seek_start:
123 buffer = ci->request_buffer(&n,rmctx.audio_framesize + 1000); 125 buffer = ci->request_buffer(&n,rmctx.audio_framesize + 1000);
124 pkt_offset = skipped - pkt.length; 126 pkt_offset = skipped - pkt.length;
125 consumed = rm_get_packet(&buffer, &rmctx, &pkt); 127 consumed = rm_get_packet(&buffer, &rmctx, &pkt);
126 if(consumed < 0) { 128 if(consumed < 0 && playback_on != 0) {
127 DEBUGF("rm_get_packet failed\n"); 129 if(playback_on == -1) {
128 return CODEC_ERROR; 130 /* Error only if packet-parsing failed and playback hadn't started */
131 DEBUGF("rm_get_packet failed\n");
132 return CODEC_ERROR;
133 }
134 else
135 goto done;
129 } 136 }
130 skipped += pkt.length; 137 skipped += pkt.length;
131 if(pkt.timestamp > (unsigned)ci->seek_time) break; 138 if(pkt.timestamp > (unsigned)ci->seek_time) break;
@@ -139,11 +146,18 @@ seek_start:
139 /* Request the required number of bytes from the input buffer */ 146 /* Request the required number of bytes from the input buffer */
140 buffer=ci->request_buffer(&n,rmctx.audio_framesize + 1000); 147 buffer=ci->request_buffer(&n,rmctx.audio_framesize + 1000);
141 consumed = rm_get_packet(&buffer, &rmctx, &pkt); 148 consumed = rm_get_packet(&buffer, &rmctx, &pkt);
142 if(consumed < 0) {
143 DEBUGF("rm_get_packet failed\n");
144 return CODEC_ERROR;
145 }
146 149
150 if(consumed < 0 && playback_on != 0) {
151 if(playback_on == -1) {
152 /* Error only if packet-parsing failed and playback hadn't started */
153 DEBUGF("rm_get_packet failed\n");
154 return CODEC_ERROR;
155 }
156 else
157 goto done;
158 }
159
160 playback_on = 1;
147 if (pkt.timestamp >= ci->id3->length) 161 if (pkt.timestamp >= ci->id3->length)
148 goto done; 162 goto done;
149 /* Decode one block - returned samples will be host-endian */ 163 /* Decode one block - returned samples will be host-endian */