]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cavsdec.c
rtmp: Store all the notify messages
[ffmpeg] / libavcodec / cavsdec.c
index e09802b6b17ff92a53fffa222d3920505b081eaa..e91ff6c877684cbab5f0d2a24a63793fd666136c 100644 (file)
@@ -516,8 +516,8 @@ static inline int get_ue_code(GetBitContext *gb, int order)
     return get_ue_golomb(gb);
 }
 
-static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
-                          DCTELEM *dst, int mul, int shift, int coeff_num)
+static inline int dequant(AVSContext *h, int16_t *level_buf, uint8_t *run_buf,
+                          int16_t *dst, int mul, int shift, int coeff_num)
 {
     int round = 1 << (shift - 1);
     int pos = -1;
@@ -551,9 +551,9 @@ static int decode_residual_block(AVSContext *h, GetBitContext *gb,
                                  int qp, uint8_t *dst, int stride)
 {
     int i, level_code, esc_code, level, run, mask;
-    DCTELEM level_buf[65];
+    int16_t level_buf[65];
     uint8_t run_buf[65];
-    DCTELEM *block = h->block;
+    int16_t *block = h->block;
 
     for (i = 0;i < 65; i++) {
         level_code = get_ue_code(gb, r->golomb_order);
@@ -632,7 +632,7 @@ static inline void set_mv_intra(AVSContext *h)
     set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
     h->mv[MV_BWD_X0] = ff_cavs_intra_mv;
     set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
-    if (h->pic_type != AV_PICTURE_TYPE_B)
+    if (h->cur.f->pict_type != AV_PICTURE_TYPE_B)
         h->col_type_base[h->mbidx] = I_8X8;
 }
 
@@ -671,7 +671,7 @@ static int decode_mb_i(AVSContext *h, int cbp_code)
     ff_cavs_modify_mb_i(h, &pred_mode_uv);
 
     /* get coded block pattern */
-    if (h->pic_type == AV_PICTURE_TYPE_I)
+    if (h->cur.f->pict_type == AV_PICTURE_TYPE_I)
         cbp_code = get_ue_golomb(gb);
     if (cbp_code > 63) {
         av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
@@ -889,7 +889,7 @@ static inline int decode_slice_header(AVSContext *h, GetBitContext *gb)
         h->qp       = get_bits(gb, 6);
     }
     /* inter frame or second slice can have weighting params */
-    if ((h->pic_type != AV_PICTURE_TYPE_I) ||
+    if ((h->cur.f->pict_type != AV_PICTURE_TYPE_I) ||
         (!h->pic_structure && h->mby >= h->mb_width / 2))
         if (get_bits1(gb)) { //slice_weighting_flag
             av_log(h->avctx, AV_LOG_ERROR,
@@ -931,19 +931,26 @@ static int decode_pic(AVSContext *h)
     int skip_count    = -1;
     enum cavs_mb mb_type;
 
+    if (!h->top_qp) {
+        av_log(h->avctx, AV_LOG_ERROR, "No sequence header decoded yet\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    av_frame_unref(h->cur.f);
+
     skip_bits(&h->gb, 16);//bbv_dwlay
     if (h->stc == PIC_PB_START_CODE) {
-        h->pic_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
-        if (h->pic_type > AV_PICTURE_TYPE_B) {
+        h->cur.f->pict_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
+        if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {
             av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
             return -1;
         }
         /* make sure we have the reference frames we need */
         if (!h->DPB[0].f->data[0] ||
-           (!h->DPB[1].f->data[0] && h->pic_type == AV_PICTURE_TYPE_B))
+           (!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))
             return -1;
     } else {
-        h->pic_type = AV_PICTURE_TYPE_I;
+        h->cur.f->pict_type = AV_PICTURE_TYPE_I;
         if (get_bits1(&h->gb))
             skip_bits(&h->gb, 24);//time_code
         /* old sample clips were all progressive and no low_delay,
@@ -956,11 +963,9 @@ static int decode_pic(AVSContext *h)
         if (h->stream_revision > 0)
             skip_bits(&h->gb, 1); //marker_bit
     }
-    /* release last B frame */
-    if (h->cur.f->data[0])
-        h->avctx->release_buffer(h->avctx, h->cur.f);
 
-    ff_get_buffer(h->avctx, h->cur.f);
+    ff_get_buffer(h->avctx, h->cur.f, h->cur.f->pict_type == AV_PICTURE_TYPE_B ?
+                  0 : AV_GET_BUFFER_FLAG_REF);
 
     if (!h->edge_emu_buffer) {
         int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
@@ -973,7 +978,7 @@ static int decode_pic(AVSContext *h)
     h->cur.poc = get_bits(&h->gb, 8) * 2;
 
     /* get temporal distances and MV scaling factors */
-    if (h->pic_type != AV_PICTURE_TYPE_B) {
+    if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
         h->dist[0] = (h->cur.poc - h->DPB[0].poc  + 512) % 512;
     } else {
         h->dist[0] = (h->DPB[0].poc  - h->cur.poc + 512) % 512;
@@ -981,7 +986,7 @@ static int decode_pic(AVSContext *h)
     h->dist[1] = (h->cur.poc - h->DPB[1].poc  + 512) % 512;
     h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
     h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
-    if (h->pic_type == AV_PICTURE_TYPE_B) {
+    if (h->cur.f->pict_type == AV_PICTURE_TYPE_B) {
         h->sym_factor = h->dist[0] * h->scale_den[1];
     } else {
         h->direct_den[0] = h->dist[0] ? 16384 / h->dist[0] : 0;
@@ -1000,12 +1005,12 @@ static int decode_pic(AVSContext *h)
     skip_bits1(&h->gb);        //repeat_first_field
     h->qp_fixed = get_bits1(&h->gb);
     h->qp       = get_bits(&h->gb, 6);
-    if (h->pic_type == AV_PICTURE_TYPE_I) {
+    if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
         if (!h->progressive && !h->pic_structure)
             skip_bits1(&h->gb);//what is this?
         skip_bits(&h->gb, 4);   //reserved bits
     } else {
-        if (!(h->pic_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))
+        if (!(h->cur.f->pict_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))
             h->ref_flag        = get_bits1(&h->gb);
         skip_bits(&h->gb, 4);   //reserved bits
         h->skip_mode_flag      = get_bits1(&h->gb);
@@ -1017,12 +1022,12 @@ static int decode_pic(AVSContext *h)
     } else {
         h->alpha_offset = h->beta_offset  = 0;
     }
-    if (h->pic_type == AV_PICTURE_TYPE_I) {
+    if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
         do {
             check_for_slice(h);
             decode_mb_i(h, 0);
         } while (ff_cavs_next_mb(h));
-    } else if (h->pic_type == AV_PICTURE_TYPE_P) {
+    } else if (h->cur.f->pict_type == AV_PICTURE_TYPE_P) {
         do {
             if (check_for_slice(h))
                 skip_count = -1;
@@ -1055,9 +1060,8 @@ static int decode_pic(AVSContext *h)
             }
         } while (ff_cavs_next_mb(h));
     }
-    if (h->pic_type != AV_PICTURE_TYPE_B) {
-        if (h->DPB[1].f->data[0])
-            h->avctx->release_buffer(h->avctx, h->DPB[1].f);
+    if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
+        av_frame_unref(h->DPB[1].f);
         FFSWAP(AVSFrame, h->cur, h->DPB[1]);
         FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);
     }
@@ -1082,7 +1086,8 @@ static int decode_seq_header(AVSContext *h)
     width  = get_bits(&h->gb, 14);
     height = get_bits(&h->gb, 14);
     if ((h->width || h->height) && (h->width != width || h->height != height)) {
-        av_log_missing_feature(h->avctx, "Width/height changing in CAVS", 0);
+        avpriv_report_missing_feature(h->avctx,
+                                      "Width/height changing in CAVS");
         return AVERROR_PATCHWELCOME;
     }
     h->width  = width;
@@ -1119,19 +1124,15 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     AVSContext *h      = avctx->priv_data;
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
-    AVFrame *picture   = data;
     uint32_t stc       = -1;
-    int input_size;
+    int input_size, ret;
     const uint8_t *buf_end;
     const uint8_t *buf_ptr;
 
     if (buf_size == 0) {
         if (!h->low_delay && h->DPB[0].f->data[0]) {
             *got_frame = 1;
-            *picture = *h->DPB[0].f;
-            if (h->cur.f->data[0])
-                avctx->release_buffer(avctx, h->cur.f);
-            FFSWAP(AVSFrame, h->cur, h->DPB[0]);
+            av_frame_move_ref(data, h->DPB[0].f);
         }
         return 0;
     }
@@ -1139,7 +1140,7 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     buf_ptr = buf;
     buf_end = buf + buf_size;
     for(;;) {
-        buf_ptr = avpriv_mpv_find_start_code(buf_ptr, buf_end, &stc);
+        buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc);
         if ((stc & 0xFFFFFE00) || buf_ptr == buf_end)
             return FFMAX(0, buf_ptr - buf);
         input_size = (buf_end - buf_ptr) * 8;
@@ -1150,10 +1151,8 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             break;
         case PIC_I_START_CODE:
             if (!h->got_keyframe) {
-                if(h->DPB[0].f->data[0])
-                    avctx->release_buffer(avctx, h->DPB[0].f);
-                if(h->DPB[1].f->data[0])
-                    avctx->release_buffer(avctx, h->DPB[1].f);
+                av_frame_unref(h->DPB[0].f);
+                av_frame_unref(h->DPB[1].f);
                 h->got_keyframe = 1;
             }
         case PIC_PB_START_CODE:
@@ -1165,14 +1164,16 @@ static int cavs_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             if (decode_pic(h))
                 break;
             *got_frame = 1;
-            if (h->pic_type != AV_PICTURE_TYPE_B) {
+            if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
                 if (h->DPB[1].f->data[0]) {
-                    *picture = *h->DPB[1].f;
+                    if ((ret = av_frame_ref(data, h->DPB[1].f)) < 0)
+                        return ret;
                 } else {
                     *got_frame = 0;
                 }
-            } else
-                *picture = *h->cur.f;
+            } else {
+                av_frame_move_ref(data, h->cur.f);
+            }
             break;
         case EXT_START_CODE:
             //mpeg_decode_extension(avctx, buf_ptr, input_size);