| 76 | } |
| 77 | |
| 78 | static av_cold int mpc7_decode_init(AVCodecContext * avctx) |
| 79 | { |
| 80 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 81 | MPCContext *c = avctx->priv_data; |
| 82 | GetBitContext gb; |
| 83 | LOCAL_ALIGNED_16(uint8_t, buf, [16]); |
| 84 | |
| 85 | /* Musepack SV7 is always stereo */ |
| 86 | if (avctx->ch_layout.nb_channels != 2) { |
| 87 | avpriv_request_sample(avctx, "%d channels", avctx->ch_layout.nb_channels); |
| 88 | return AVERROR_PATCHWELCOME; |
| 89 | } |
| 90 | |
| 91 | if(avctx->extradata_size < 16){ |
| 92 | av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); |
| 93 | return AVERROR_INVALIDDATA; |
| 94 | } |
| 95 | memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); |
| 96 | av_lfg_init(&c->rnd, 0xDEADBEEF); |
| 97 | ff_bswapdsp_init(&c->bdsp); |
| 98 | ff_mpadsp_init(&c->mpadsp); |
| 99 | c->bdsp.bswap_buf((uint32_t *) buf, (const uint32_t *) avctx->extradata, 4); |
| 100 | init_get_bits(&gb, buf, 128); |
| 101 | |
| 102 | c->IS = get_bits1(&gb); |
| 103 | c->MSS = get_bits1(&gb); |
| 104 | c->maxbands = get_bits(&gb, 6); |
| 105 | if(c->maxbands >= BANDS){ |
| 106 | av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->maxbands); |
| 107 | return AVERROR_INVALIDDATA; |
| 108 | } |
| 109 | skip_bits_long(&gb, 88); |
| 110 | c->gapless = get_bits1(&gb); |
| 111 | c->lastframelen = get_bits(&gb, 11); |
| 112 | av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n", |
| 113 | c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands); |
| 114 | c->frames_to_skip = 0; |
| 115 | |
| 116 | avctx->sample_fmt = AV_SAMPLE_FMT_S16P; |
| 117 | av_channel_layout_uninit(&avctx->ch_layout); |
| 118 | avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; |
| 119 | |
| 120 | ff_thread_once(&init_static_once, mpc7_init_static); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Fill samples for given subband |
nothing calls this directly
no test coverage detected