| 139 | } |
| 140 | |
| 141 | static av_cold int mpc8_decode_init(AVCodecContext * avctx) |
| 142 | { |
| 143 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 144 | MPCContext *c = avctx->priv_data; |
| 145 | GetBitContext gb; |
| 146 | int channels; |
| 147 | |
| 148 | if(avctx->extradata_size < 2){ |
| 149 | av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); |
| 150 | return -1; |
| 151 | } |
| 152 | memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); |
| 153 | av_lfg_init(&c->rnd, 0xDEADBEEF); |
| 154 | ff_mpadsp_init(&c->mpadsp); |
| 155 | |
| 156 | init_get_bits(&gb, avctx->extradata, 16); |
| 157 | |
| 158 | uint8_t sample_rate_idx = get_bits(&gb, 3); |
| 159 | static const int sample_rates[] = { 44100, 48000, 37800, 32000 }; |
| 160 | if (sample_rate_idx >= FF_ARRAY_ELEMS(sample_rates)) { |
| 161 | av_log(avctx, AV_LOG_ERROR, "invalid sample rate index (%u)\n", sample_rate_idx); |
| 162 | return AVERROR_INVALIDDATA; |
| 163 | } |
| 164 | avctx->sample_rate = sample_rates[sample_rate_idx]; |
| 165 | c->maxbands = get_bits(&gb, 5) + 1; |
| 166 | if (c->maxbands >= BANDS) { |
| 167 | av_log(avctx,AV_LOG_ERROR, "maxbands %d too high\n", c->maxbands); |
| 168 | return AVERROR_INVALIDDATA; |
| 169 | } |
| 170 | channels = get_bits(&gb, 4) + 1; |
| 171 | if (channels > 2) { |
| 172 | avpriv_request_sample(avctx, "Multichannel MPC SV8"); |
| 173 | return AVERROR_PATCHWELCOME; |
| 174 | } |
| 175 | c->MSS = get_bits1(&gb); |
| 176 | c->frames = 1 << (get_bits(&gb, 3) * 2); |
| 177 | |
| 178 | avctx->sample_fmt = AV_SAMPLE_FMT_S16P; |
| 179 | av_channel_layout_uninit(&avctx->ch_layout); |
| 180 | av_channel_layout_default(&avctx->ch_layout, channels); |
| 181 | |
| 182 | ff_thread_once(&init_static_once, mpc8_init_static); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static int mpc8_decode_frame(AVCodecContext *avctx, AVFrame *frame, |
| 188 | int *got_frame_ptr, AVPacket *avpkt) |
nothing calls this directly
no test coverage detected