MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / mpc7_decode_frame

Function mpc7_decode_frame

libavcodec/mpc7.c:178–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176}
177
178static int mpc7_decode_frame(AVCodecContext *avctx, AVFrame *frame,
179 int *got_frame_ptr, AVPacket *avpkt)
180{
181 const uint8_t *buf = avpkt->data;
182 int buf_size;
183 MPCContext *c = avctx->priv_data;
184 GetBitContext gb;
185 int i, ch;
186 int mb = -1;
187 Band *bands = c->bands;
188 int off, ret, last_frame, skip;
189 int bits_used, bits_avail;
190
191 memset(bands, 0, sizeof(*bands) * (c->maxbands + 1));
192
193 buf_size = avpkt->size & ~3;
194 if (buf_size <= 0) {
195 av_log(avctx, AV_LOG_ERROR, "packet size is too small (%i bytes)\n",
196 avpkt->size);
197 return AVERROR_INVALIDDATA;
198 }
199 if (buf_size != avpkt->size) {
200 av_log(avctx, AV_LOG_WARNING, "packet size is not a multiple of 4. "
201 "extra bytes at the end will be skipped.\n");
202 }
203
204 skip = buf[0];
205 last_frame = buf[1];
206 buf += 4;
207 buf_size -= 4;
208
209 /* get output buffer */
210 frame->nb_samples = MPC_FRAME_SIZE;
211 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
212 return ret;
213
214 av_fast_padded_malloc(&c->bits, &c->buf_size, buf_size);
215 if (!c->bits)
216 return AVERROR(ENOMEM);
217 c->bdsp.bswap_buf((uint32_t *) c->bits, (const uint32_t *) buf,
218 buf_size >> 2);
219 if ((ret = init_get_bits8(&gb, c->bits, buf_size)) < 0)
220 return ret;
221 skip_bits_long(&gb, skip);
222
223 /* read subband indexes */
224 for(i = 0; i <= c->maxbands; i++){
225 for(ch = 0; ch < 2; ch++){
226 int t = i ? get_vlc2(&gb, hdr_vlc, MPC7_HDR_BITS, 1) : 4;
227 if(t == 4) bands[i].res[ch] = get_bits(&gb, 4);
228 else bands[i].res[ch] = bands[i-1].res[ch] + t;
229 if (bands[i].res[ch] < -1 || bands[i].res[ch] > 17) {
230 av_log(avctx, AV_LOG_ERROR, "subband index invalid\n");
231 return AVERROR_INVALIDDATA;
232 }
233 }
234
235 if(bands[i].res[0] || bands[i].res[1]){

Callers

nothing calls this directly

Calls 12

av_logFunction · 0.85
ff_get_bufferFunction · 0.85
av_fast_padded_mallocFunction · 0.85
init_get_bits8Function · 0.85
skip_bits_longFunction · 0.85
get_vlc2Function · 0.85
get_bits1Function · 0.85
get_scale_idxFunction · 0.85
idx_to_quantFunction · 0.85
get_bits_countFunction · 0.85
get_bitsFunction · 0.70

Tested by

no test coverage detected