]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpc7.c
avcodec: rename the AV1 profiles
[ffmpeg] / libavcodec / mpc7.c
index 4e7584100889630af6bedde82c2c6ae05156129d..ebc3f5293b2fb3720476f839953515a82c82353a 100644 (file)
  * divided into 32 subbands.
  */
 
+#include "libavutil/channel_layout.h"
+#include "libavutil/internal.h"
 #include "libavutil/lfg.h"
+
 #include "avcodec.h"
-#include "get_bits.h"
-#include "dsputil.h"
+#include "bitstream.h"
+#include "internal.h"
 #include "mpegaudiodsp.h"
-#include "libavutil/audioconvert.h"
+#include "vlc.h"
 
 #include "mpc.h"
 #include "mpc7data.h"
@@ -52,7 +55,7 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
 {
     int i, j;
     MPCContext *c = avctx->priv_data;
-    GetBitContext gb;
+    BitstreamContext bc;
     LOCAL_ALIGNED_16(uint8_t, buf, [16]);
     static int vlc_initialized = 0;
 
@@ -63,8 +66,7 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
 
     /* Musepack SV7 is always stereo */
     if (avctx->channels != 2) {
-        av_log_ask_for_sample(avctx, "Unsupported number of channels: %d\n",
-                              avctx->channels);
+        avpriv_request_sample(avctx, "%d channels", avctx->channels);
         return AVERROR_PATCHWELCOME;
     }
 
@@ -74,27 +76,27 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
     }
     memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
     av_lfg_init(&c->rnd, 0xDEADBEEF);
-    ff_dsputil_init(&c->dsp, avctx);
+    ff_bswapdsp_init(&c->bdsp);
     ff_mpadsp_init(&c->mpadsp);
-    c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4);
+    c->bdsp.bswap_buf((uint32_t *) buf, (const uint32_t *) avctx->extradata, 4);
     ff_mpc_init();
-    init_get_bits(&gb, buf, 128);
+    bitstream_init(&bc, buf, 128);
 
-    c->IS = get_bits1(&gb);
-    c->MSS = get_bits1(&gb);
-    c->maxbands = get_bits(&gb, 6);
+    c->IS       = bitstream_read_bit(&bc);
+    c->MSS      = bitstream_read_bit(&bc);
+    c->maxbands = bitstream_read(&bc, 6);
     if(c->maxbands >= BANDS){
         av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->maxbands);
         return -1;
     }
-    skip_bits_long(&gb, 88);
-    c->gapless = get_bits1(&gb);
-    c->lastframelen = get_bits(&gb, 11);
+    bitstream_skip(&bc, 88);
+    c->gapless      = bitstream_read_bit(&bc);
+    c->lastframelen = bitstream_read(&bc, 11);
     av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n",
             c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands);
     c->frames_to_skip = 0;
 
-    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+    avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
     avctx->channel_layout = AV_CH_LAYOUT_STEREO;
 
     if(vlc_initialized) return 0;
@@ -137,16 +139,13 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
     }
     vlc_initialized = 1;
 
-    avcodec_get_frame_defaults(&c->frame);
-    avctx->coded_frame = &c->frame;
-
     return 0;
 }
 
 /**
  * Fill samples for given subband
  */
-static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *dst)
+static inline void idx_to_quant(MPCContext *c, BitstreamContext *bc, int idx, int *dst)
 {
     int i, i1, t;
     switch(idx){
@@ -156,53 +155,54 @@ static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *
         }
         break;
     case 1:
-        i1 = get_bits1(gb);
+        i1 = bitstream_read_bit(bc);
         for(i = 0; i < SAMPLES_PER_BAND/3; i++){
-            t = get_vlc2(gb, quant_vlc[0][i1].table, 9, 2);
+            t = bitstream_read_vlc(bc, quant_vlc[0][i1].table, 9, 2);
             *dst++ = mpc7_idx30[t];
             *dst++ = mpc7_idx31[t];
             *dst++ = mpc7_idx32[t];
         }
         break;
     case 2:
-        i1 = get_bits1(gb);
+        i1 = bitstream_read_bit(bc);
         for(i = 0; i < SAMPLES_PER_BAND/2; i++){
-            t = get_vlc2(gb, quant_vlc[1][i1].table, 9, 2);
+            t = bitstream_read_vlc(bc, quant_vlc[1][i1].table, 9, 2);
             *dst++ = mpc7_idx50[t];
             *dst++ = mpc7_idx51[t];
         }
         break;
     case  3: case  4: case  5: case  6: case  7:
-        i1 = get_bits1(gb);
+        i1 = bitstream_read_bit(bc);
         for(i = 0; i < SAMPLES_PER_BAND; i++)
-            *dst++ = get_vlc2(gb, quant_vlc[idx-1][i1].table, 9, 2) - mpc7_quant_vlc_off[idx-1];
+            *dst++ = bitstream_read_vlc(bc, quant_vlc[idx - 1][i1].table, 9, 2) - mpc7_quant_vlc_off[idx - 1];
         break;
     case  8: case  9: case 10: case 11: case 12:
     case 13: case 14: case 15: case 16: case 17:
         t = (1 << (idx - 2)) - 1;
         for(i = 0; i < SAMPLES_PER_BAND; i++)
-            *dst++ = get_bits(gb, idx - 1) - t;
+            *dst++ = bitstream_read(bc, idx - 1) - t;
         break;
     default: // case 0 and -2..-17
         return;
     }
 }
 
-static int get_scale_idx(GetBitContext *gb, int ref)
+static int get_scale_idx(BitstreamContext *bc, int ref)
 {
-    int t = get_vlc2(gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7;
+    int t = bitstream_read_vlc(bc, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7;
     if (t == 8)
-        return get_bits(gb, 6);
+        return bitstream_read(bc, 6);
     return av_clip_uintp2(ref + t, 7);
 }
 
 static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
                              int *got_frame_ptr, AVPacket *avpkt)
 {
+    AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size;
     MPCContext *c = avctx->priv_data;
-    GetBitContext gb;
+    BitstreamContext bc;
     int i, ch;
     int mb = -1;
     Band *bands = c->bands;
@@ -228,8 +228,8 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
     buf_size  -= 4;
 
     /* get output buffer */
-    c->frame.nb_samples = last_frame ? c->lastframelen : MPC_FRAME_SIZE;
-    if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) {
+    frame->nb_samples = last_frame ? c->lastframelen : MPC_FRAME_SIZE;
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
@@ -237,46 +237,51 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
     av_fast_padded_malloc(&c->bits, &c->buf_size, buf_size);
     if (!c->bits)
         return AVERROR(ENOMEM);
-    c->dsp.bswap_buf((uint32_t *)c->bits, (const uint32_t *)buf, buf_size >> 2);
-    init_get_bits(&gb, c->bits, buf_size * 8);
-    skip_bits_long(&gb, skip);
+    c->bdsp.bswap_buf((uint32_t *) c->bits, (const uint32_t *) buf,
+                      buf_size >> 2);
+    bitstream_init8(&bc, c->bits, buf_size);
+    bitstream_skip(&bc, skip);
 
     /* read subband indexes */
     for(i = 0; i <= c->maxbands; i++){
         for(ch = 0; ch < 2; ch++){
             int t = 4;
-            if(i) t = get_vlc2(&gb, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5;
-            if(t == 4) bands[i].res[ch] = get_bits(&gb, 4);
+            if (i)
+                t = bitstream_read_vlc(&bc, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5;
+            if (t == 4)
+                bands[i].res[ch] = bitstream_read(&bc, 4);
             else bands[i].res[ch] = av_clip(bands[i-1].res[ch] + t, 0, 17);
         }
 
         if(bands[i].res[0] || bands[i].res[1]){
             mb = i;
-            if(c->MSS) bands[i].msf = get_bits1(&gb);
+            if (c->MSS)
+                bands[i].msf = bitstream_read_bit(&bc);
         }
     }
     /* get scale indexes coding method */
     for(i = 0; i <= mb; i++)
         for(ch = 0; ch < 2; ch++)
-            if(bands[i].res[ch]) bands[i].scfi[ch] = get_vlc2(&gb, scfi_vlc.table, MPC7_SCFI_BITS, 1);
+            if (bands[i].res[ch])
+                bands[i].scfi[ch] = bitstream_read_vlc(&bc, scfi_vlc.table, MPC7_SCFI_BITS, 1);
     /* get scale indexes */
     for(i = 0; i <= mb; i++){
         for(ch = 0; ch < 2; ch++){
             if(bands[i].res[ch]){
                 bands[i].scf_idx[ch][2] = c->oldDSCF[ch][i];
-                bands[i].scf_idx[ch][0] = get_scale_idx(&gb, bands[i].scf_idx[ch][2]);
+                bands[i].scf_idx[ch][0] = get_scale_idx(&bc, bands[i].scf_idx[ch][2]);
                 switch(bands[i].scfi[ch]){
                 case 0:
-                    bands[i].scf_idx[ch][1] = get_scale_idx(&gb, bands[i].scf_idx[ch][0]);
-                    bands[i].scf_idx[ch][2] = get_scale_idx(&gb, bands[i].scf_idx[ch][1]);
+                    bands[i].scf_idx[ch][1] = get_scale_idx(&bc, bands[i].scf_idx[ch][0]);
+                    bands[i].scf_idx[ch][2] = get_scale_idx(&bc, bands[i].scf_idx[ch][1]);
                     break;
                 case 1:
-                    bands[i].scf_idx[ch][1] = get_scale_idx(&gb, bands[i].scf_idx[ch][0]);
+                    bands[i].scf_idx[ch][1] = get_scale_idx(&bc, bands[i].scf_idx[ch][0]);
                     bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1];
                     break;
                 case 2:
                     bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0];
-                    bands[i].scf_idx[ch][2] = get_scale_idx(&gb, bands[i].scf_idx[ch][1]);
+                    bands[i].scf_idx[ch][2] = get_scale_idx(&bc, bands[i].scf_idx[ch][1]);
                     break;
                 case 3:
                     bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0];
@@ -291,11 +296,11 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
     off = 0;
     for(i = 0; i < BANDS; i++, off += SAMPLES_PER_BAND)
         for(ch = 0; ch < 2; ch++)
-            idx_to_quant(c, &gb, bands[i].res[ch], c->Q[ch] + off);
+            idx_to_quant(c, &bc, bands[i].res[ch], c->Q[ch] + off);
 
-    ff_mpc_dequantize_and_synth(c, mb, c->frame.data[0], 2);
+    ff_mpc_dequantize_and_synth(c, mb, (int16_t **)frame->extended_data, 2);
 
-    bits_used = get_bits_count(&gb);
+    bits_used = bitstream_tell(&bc);
     bits_avail = buf_size * 8;
     if (!last_frame && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))) {
         av_log(avctx, AV_LOG_ERROR, "Error decoding frame: used %i of %i bits\n", bits_used, bits_avail);
@@ -307,8 +312,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data,
         return avpkt->size;
     }
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = c->frame;
+    *got_frame_ptr = 1;
 
     return avpkt->size;
 }
@@ -331,13 +335,15 @@ static av_cold int mpc7_decode_close(AVCodecContext *avctx)
 
 AVCodec ff_mpc7_decoder = {
     .name           = "mpc7",
+    .long_name      = NULL_IF_CONFIG_SMALL("Musepack SV7"),
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_MUSEPACK7,
+    .id             = AV_CODEC_ID_MUSEPACK7,
     .priv_data_size = sizeof(MPCContext),
     .init           = mpc7_decode_init,
     .close          = mpc7_decode_close,
     .decode         = mpc7_decode_frame,
-    .flush = mpc7_decode_flush,
-    .capabilities   = CODEC_CAP_DR1,
-    .long_name = NULL_IF_CONFIG_SMALL("Musepack SV7"),
+    .flush          = mpc7_decode_flush,
+    .capabilities   = AV_CODEC_CAP_DR1,
+    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
+                                                      AV_SAMPLE_FMT_NONE },
 };