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

Function decode_frame

libavcodec/vima.c:121–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
122 int *got_frame_ptr, AVPacket *pkt)
123{
124 GetBitContext gb;
125 int16_t pcm_data[2];
126 uint32_t samples;
127 int8_t channel_hint[2];
128 int ret, chan;
129 int channels = 1;
130
131 if (pkt->size < 13)
132 return AVERROR_INVALIDDATA;
133
134 if ((ret = init_get_bits8(&gb, pkt->data, pkt->size)) < 0)
135 return ret;
136
137 samples = get_bits_long(&gb, 32);
138 if (samples == 0xffffffff) {
139 skip_bits_long(&gb, 32);
140 samples = get_bits_long(&gb, 32);
141 }
142
143 if (samples > pkt->size * 2)
144 return AVERROR_INVALIDDATA;
145
146 channel_hint[0] = get_sbits(&gb, 8);
147 if (channel_hint[0] & 0x80) {
148 channel_hint[0] = ~channel_hint[0];
149 channels = 2;
150 }
151 av_channel_layout_uninit(&avctx->ch_layout);
152 av_channel_layout_default(&avctx->ch_layout, channels);
153 pcm_data[0] = get_sbits(&gb, 16);
154 if (channels > 1) {
155 channel_hint[1] = get_sbits(&gb, 8);
156 pcm_data[1] = get_sbits(&gb, 16);
157 }
158
159 frame->nb_samples = samples;
160 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
161 return ret;
162
163 if (show_bits_long(&gb, 32) == MKBETAG('I','M','A','4')) {
164 int16_t *dest = (int16_t *)frame->data[0];
165 ADPCMChannelStatus cs;
166
167 skip_bits_long(&gb, 32); /* skip the 'IMA4' tag */
168 cs.predictor = (int16_t)get_xbits_le(&gb, 16);
169 cs.step_index = av_clip(get_bits(&gb, 8), 0, 88);
170 for (int i = 0; i < samples; i++) {
171 ff_adpcm_ima_qt_expand_nibble(&cs, get_bits(&gb, 4));
172 for (int j = 0; j < channels; j++)
173 *dest++ = cs.predictor;
174 }
175 } else {
176 for (chan = 0; chan < channels; chan++) {
177 uint16_t *dest = (uint16_t *)frame->data[0] + chan;
178 int step_index = channel_hint[chan];

Callers

nothing calls this directly

Calls 11

init_get_bits8Function · 0.85
get_bits_longFunction · 0.85
skip_bits_longFunction · 0.85
get_sbitsFunction · 0.85
av_channel_layout_uninitFunction · 0.85
ff_get_bufferFunction · 0.85
show_bits_longFunction · 0.85
get_xbits_leFunction · 0.85
get_bitsFunction · 0.70

Tested by

no test coverage detected