LCOV - code coverage report
Current view: top level - libavcodec - h264_picture.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 75 91 82.4 %
Date: 2017-12-15 18:13:28 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * H.26L/H.264/AVC/JVT/14496-10/... decoder
       3             :  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : /**
      23             :  * @file
      24             :  * H.264 / AVC / MPEG-4 part10 codec.
      25             :  * @author Michael Niedermayer <michaelni@gmx.at>
      26             :  */
      27             : 
      28             : #include "libavutil/avassert.h"
      29             : #include "libavutil/imgutils.h"
      30             : #include "libavutil/timer.h"
      31             : #include "internal.h"
      32             : #include "cabac.h"
      33             : #include "cabac_functions.h"
      34             : #include "error_resilience.h"
      35             : #include "avcodec.h"
      36             : #include "h264dec.h"
      37             : #include "h264data.h"
      38             : #include "h264chroma.h"
      39             : #include "h264_mvpred.h"
      40             : #include "mathops.h"
      41             : #include "mpegutils.h"
      42             : #include "rectangle.h"
      43             : #include "thread.h"
      44             : 
      45      114306 : void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
      46             : {
      47      114306 :     int off = offsetof(H264Picture, tf) + sizeof(pic->tf);
      48             :     int i;
      49             : 
      50      114306 :     if (!pic->f || !pic->f->buf[0])
      51       68381 :         return;
      52             : 
      53       45925 :     ff_thread_release_buffer(h->avctx, &pic->tf);
      54       45925 :     av_buffer_unref(&pic->hwaccel_priv_buf);
      55             : 
      56       45925 :     av_buffer_unref(&pic->qscale_table_buf);
      57       45925 :     av_buffer_unref(&pic->mb_type_buf);
      58      137775 :     for (i = 0; i < 2; i++) {
      59       91850 :         av_buffer_unref(&pic->motion_val_buf[i]);
      60       91850 :         av_buffer_unref(&pic->ref_index_buf[i]);
      61             :     }
      62             : 
      63       45925 :     memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
      64             : }
      65             : 
      66       23435 : int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src)
      67             : {
      68             :     int ret, i;
      69             : 
      70       23435 :     av_assert0(!dst->f->buf[0]);
      71       23435 :     av_assert0(src->f->buf[0]);
      72       23435 :     av_assert0(src->tf.f == src->f);
      73             : 
      74       23435 :     dst->tf.f = dst->f;
      75       23435 :     ret = ff_thread_ref_frame(&dst->tf, &src->tf);
      76       23435 :     if (ret < 0)
      77           0 :         goto fail;
      78             : 
      79       23435 :     dst->qscale_table_buf = av_buffer_ref(src->qscale_table_buf);
      80       23435 :     dst->mb_type_buf      = av_buffer_ref(src->mb_type_buf);
      81       23435 :     if (!dst->qscale_table_buf || !dst->mb_type_buf) {
      82           0 :         ret = AVERROR(ENOMEM);
      83           0 :         goto fail;
      84             :     }
      85       23435 :     dst->qscale_table = src->qscale_table;
      86       23435 :     dst->mb_type      = src->mb_type;
      87             : 
      88       70305 :     for (i = 0; i < 2; i++) {
      89       46870 :         dst->motion_val_buf[i] = av_buffer_ref(src->motion_val_buf[i]);
      90       46870 :         dst->ref_index_buf[i]  = av_buffer_ref(src->ref_index_buf[i]);
      91       46870 :         if (!dst->motion_val_buf[i] || !dst->ref_index_buf[i]) {
      92           0 :             ret = AVERROR(ENOMEM);
      93           0 :             goto fail;
      94             :         }
      95       46870 :         dst->motion_val[i] = src->motion_val[i];
      96       46870 :         dst->ref_index[i]  = src->ref_index[i];
      97             :     }
      98             : 
      99       23435 :     if (src->hwaccel_picture_private) {
     100           0 :         dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
     101           0 :         if (!dst->hwaccel_priv_buf) {
     102           0 :             ret = AVERROR(ENOMEM);
     103           0 :             goto fail;
     104             :         }
     105           0 :         dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data;
     106             :     }
     107             : 
     108       70305 :     for (i = 0; i < 2; i++)
     109       46870 :         dst->field_poc[i] = src->field_poc[i];
     110             : 
     111       23435 :     memcpy(dst->ref_poc,   src->ref_poc,   sizeof(src->ref_poc));
     112       23435 :     memcpy(dst->ref_count, src->ref_count, sizeof(src->ref_count));
     113             : 
     114       23435 :     dst->poc           = src->poc;
     115       23435 :     dst->frame_num     = src->frame_num;
     116       23435 :     dst->mmco_reset    = src->mmco_reset;
     117       23435 :     dst->long_ref      = src->long_ref;
     118       23435 :     dst->mbaff         = src->mbaff;
     119       23435 :     dst->field_picture = src->field_picture;
     120       23435 :     dst->reference     = src->reference;
     121       23435 :     dst->recovered     = src->recovered;
     122       23435 :     dst->invalid_gap   = src->invalid_gap;
     123       23435 :     dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt;
     124             : 
     125       23435 :     return 0;
     126           0 : fail:
     127           0 :     ff_h264_unref_picture(h, dst);
     128           0 :     return ret;
     129             : }
     130             : 
     131      121030 : void ff_h264_set_erpic(ERPicture *dst, H264Picture *src)
     132             : {
     133             : #if CONFIG_ERROR_RESILIENCE
     134             :     int i;
     135             : 
     136      121030 :     memset(dst, 0, sizeof(*dst));
     137             : 
     138      121030 :     if (!src)
     139       77939 :         return;
     140             : 
     141       43091 :     dst->f = src->f;
     142       43091 :     dst->tf = &src->tf;
     143             : 
     144      129273 :     for (i = 0; i < 2; i++) {
     145       86182 :         dst->motion_val[i] = src->motion_val[i];
     146       86182 :         dst->ref_index[i] = src->ref_index[i];
     147             :     }
     148             : 
     149       43091 :     dst->mb_type = src->mb_type;
     150       43091 :     dst->field_picture = src->field_picture;
     151             : #endif /* CONFIG_ERROR_RESILIENCE */
     152             : }
     153             : 
     154       25098 : int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
     155             : {
     156       25098 :     AVCodecContext *const avctx = h->avctx;
     157       25098 :     int err = 0;
     158       25098 :     h->mb_y = 0;
     159             : 
     160       25098 :     if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {
     161       25098 :         if (!h->droppable) {
     162       16163 :             err = ff_h264_execute_ref_pic_marking(h);
     163       16163 :             h->poc.prev_poc_msb = h->poc.poc_msb;
     164       16163 :             h->poc.prev_poc_lsb = h->poc.poc_lsb;
     165             :         }
     166       25098 :         h->poc.prev_frame_num_offset = h->poc.frame_num_offset;
     167       25098 :         h->poc.prev_frame_num        = h->poc.frame_num;
     168             :     }
     169             : 
     170       25098 :     if (avctx->hwaccel) {
     171           0 :         err = avctx->hwaccel->end_frame(avctx);
     172           0 :         if (err < 0)
     173           0 :             av_log(avctx, AV_LOG_ERROR,
     174             :                    "hardware accelerator failed to decode picture\n");
     175             :     }
     176             : 
     177       25098 :     if (!in_setup && !h->droppable)
     178       16094 :         ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
     179       16094 :                                   h->picture_structure == PICT_BOTTOM_FIELD);
     180       25098 :     emms_c();
     181             : 
     182       25098 :     h->current_slice = 0;
     183             : 
     184       25098 :     return err;
     185             : }

Generated by: LCOV version 1.13