diff options
Diffstat (limited to 'apps/codecs/cook.c')
-rw-r--r-- | apps/codecs/cook.c | 90 |
1 files changed, 44 insertions, 46 deletions
diff --git a/apps/codecs/cook.c b/apps/codecs/cook.c index 451fe34100..b23e523738 100644 --- a/apps/codecs/cook.c +++ b/apps/codecs/cook.c | |||
@@ -86,56 +86,54 @@ next_track: | |||
86 | ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE); | 86 | ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE); |
87 | 87 | ||
88 | /* The main decoder loop */ | 88 | /* The main decoder loop */ |
89 | while (1) | 89 | seek_start : |
90 | { | 90 | while(packet_count) |
91 | /*if (ci->seek_time) { | 91 | { |
92 | 92 | bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size); | |
93 | ci->set_elapsed(ci->seek_time); | 93 | consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt); |
94 | n = ci->seek_time/10; | 94 | if(consumed < 0) { |
95 | memset(buf,0,BUF_SIZE); | 95 | DEBUGF("rm_get_packet failed\n"); |
96 | ci->seek_complete(); | 96 | return CODEC_ERROR; |
97 | }*/ | 97 | } |
98 | 98 | /*DEBUGF(" version = %d\n" | |
99 | while(packet_count) | 99 | " length = %d\n" |
100 | { | 100 | " stream = %d\n" |
101 | bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size); | 101 | " timestamp= %d\n",pkt.version,pkt.length,pkt.stream_number,pkt.timestamp);*/ |
102 | consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt); | 102 | |
103 | if(consumed < 0) { | 103 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) |
104 | DEBUGF("rm_get_packet failed\n"); | 104 | { |
105 | ci->yield(); | ||
106 | if (ci->stop_codec || ci->new_track) | ||
107 | goto done; | ||
108 | if (ci->seek_time == 1) { | ||
109 | ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE); | ||
110 | ci->set_elapsed(0); | ||
111 | packet_count = rmctx.nb_packets; | ||
112 | rmctx.audio_pkt_cnt = 0; | ||
113 | rmctx.frame_number = 0; | ||
114 | ci->seek_complete(); | ||
115 | goto seek_start; | ||
116 | } | ||
117 | |||
118 | res = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align); | ||
119 | rmctx.frame_number++; | ||
120 | |||
121 | /* skip the first two frames; no valid audio */ | ||
122 | if(rmctx.frame_number < 3) continue; | ||
123 | |||
124 | if(res != rmctx.block_align) { | ||
125 | DEBUGF("codec error\n"); | ||
105 | return CODEC_ERROR; | 126 | return CODEC_ERROR; |
106 | } | 127 | } |
107 | /*DEBUGF(" version = %d\n" | 128 | |
108 | " length = %d\n" | 129 | ci->pcmbuf_insert(outbuf, NULL, rmctx.samples_pf_pc / rmctx.nb_channels); |
109 | " stream = %d\n" | 130 | ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i); |
110 | " timestamp= %d\n",pkt.version,pkt.length,pkt.stream_number,pkt.timestamp);*/ | ||
111 | |||
112 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) | ||
113 | { | ||
114 | ci->yield(); | ||
115 | if (ci->stop_codec || ci->new_track) | ||
116 | goto done; | ||
117 | |||
118 | res = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align); | ||
119 | rmctx.frame_number++; | ||
120 | |||
121 | /* skip the first two frames; no valid audio */ | ||
122 | if(rmctx.frame_number < 3) continue; | ||
123 | |||
124 | if(res != rmctx.block_align) { | ||
125 | DEBUGF("codec error\n"); | ||
126 | return CODEC_ERROR; | ||
127 | } | ||
128 | |||
129 | 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); | ||
131 | } | ||
132 | packet_count -= rmctx.audio_pkt_cnt; | ||
133 | rmctx.audio_pkt_cnt = 0; | ||
134 | ci->advance_buffer(consumed); | ||
135 | } | 131 | } |
136 | goto done; | 132 | packet_count -= rmctx.audio_pkt_cnt; |
137 | 133 | rmctx.audio_pkt_cnt = 0; | |
134 | ci->advance_buffer(consumed); | ||
138 | } | 135 | } |
136 | |||
139 | done : | 137 | done : |
140 | if (ci->request_next_track()) | 138 | if (ci->request_next_track()) |
141 | goto next_track; | 139 | goto next_track; |