]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/g723_1.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavcodec / g723_1.c
index e1dc431d0e7d6e5fc6a2b1621d0c1259842d4ec9..ec70e06f3ec27a9f30797f5bb40a726f62bba05d 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include "avcodec.h"
-#define ALT_BITSTREAM_READER_LE
+#define BITSTREAM_READER_LE
 #include "get_bits.h"
 #include "acelp_vectors.h"
 #include "celp_filters.h"
@@ -36,6 +36,7 @@
 #include "g723_1_data.h"
 
 typedef struct g723_1_context {
+    AVFrame frame;
     G723_1_Subframe subframe[4];
     FrameType cur_frame_type;
     FrameType past_frame_type;
@@ -76,10 +77,13 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
 {
     G723_1_Context *p  = avctx->priv_data;
 
-    avctx->sample_fmt  = SAMPLE_FMT_S16;
+    avctx->sample_fmt  = AV_SAMPLE_FMT_S16;
     p->pf_gain         = 1 << 12;
     memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(int16_t));
 
+    avcodec_get_frame_defaults(&p->frame);
+    avctx->coded_frame = &p->frame;
+
     return 0;
 }
 
@@ -950,12 +954,12 @@ static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf)
 }
 
 static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
-                               int *data_size, AVPacket *avpkt)
+                               int *got_frame_ptr, AVPacket *avpkt)
 {
     G723_1_Context *p  = avctx->priv_data;
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
-    int16_t *out       = data;
+    int16_t *out;
     int dec_mode       = buf[0] & 3;
 
     PPFParam ppf[SUBFRAMES];
@@ -963,10 +967,10 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
     int16_t lpc[SUBFRAMES * LPC_ORDER];
     int16_t acb_vector[SUBFRAME_LEN];
     int16_t *vector_ptr;
-    int bad_frame = 0, i, j;
+    int bad_frame = 0, i, j, ret;
 
     if (!buf_size || buf_size < frame_size[dec_mode]) {
-        *data_size = 0;
+        *got_frame_ptr = 0;
         return buf_size;
     }
 
@@ -976,7 +980,14 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
                             ActiveFrame : UntransmittedFrame;
     }
 
-    *data_size = FRAME_LEN * sizeof(int16_t);
+    p->frame.nb_samples = FRAME_LEN + LPC_ORDER;
+    if ((ret = avctx->get_buffer(avctx, &p->frame)) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+        return ret;
+    }
+    out= (int16_t*)p->frame.data[0];
+
+
     if(p->cur_frame_type == ActiveFrame) {
         if (!bad_frame) {
             p->erased_frames = 0;
@@ -1051,7 +1062,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
         memcpy(p->prev_excitation, p->excitation + FRAME_LEN,
                PITCH_MAX * sizeof(int16_t));
     } else {
-        memset(out, 0, *data_size);
+        memset(out, 0, sizeof(int16_t)*FRAME_LEN);
         av_log(avctx, AV_LOG_WARNING,
                "G.723.1: Comfort noise generation not supported yet\n");
         return frame_size[dec_mode];
@@ -1068,7 +1079,10 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
 
     formant_postfilter(p, lpc, out);
 
-    memmove(out, out + LPC_ORDER, *data_size);
+    memmove(out, out + LPC_ORDER, sizeof(int16_t)*FRAME_LEN);
+    p->frame.nb_samples = FRAME_LEN;
+    *(AVFrame*)data = p->frame;
+    *got_frame_ptr = 1;
 
     return frame_size[dec_mode];
 }
@@ -2210,7 +2224,7 @@ AVCodec ff_g723_1_encoder = {
     .init           = g723_1_encode_init,
     .encode         = g723_1_encode_frame,
     .long_name      = NULL_IF_CONFIG_SMALL("G.723.1"),
-    .sample_fmts    = (const enum SampleFormat[]){SAMPLE_FMT_S16,
-                                                  SAMPLE_FMT_NONE},
+    .sample_fmts    = (const enum SampleFormat[]){AV_SAMPLE_FMT_S16,
+                                                  AV_SAMPLE_FMT_NONE},
 };
 #endif