GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/h264_picture.c Lines: 75 91 82.4 %
Date: 2020-04-02 05:41:20 Branches: 33 48 68.8 %

Line Branch Exec Source
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 "internal.h"
31
#include "cabac.h"
32
#include "cabac_functions.h"
33
#include "error_resilience.h"
34
#include "avcodec.h"
35
#include "h264dec.h"
36
#include "h264data.h"
37
#include "h264chroma.h"
38
#include "h264_mvpred.h"
39
#include "mathops.h"
40
#include "mpegutils.h"
41
#include "rectangle.h"
42
#include "thread.h"
43
44
121765
void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
45
{
46
121765
    int off = offsetof(H264Picture, tf) + sizeof(pic->tf);
47
    int i;
48
49

121765
    if (!pic->f || !pic->f->buf[0])
50
73817
        return;
51
52
47948
    ff_thread_release_buffer(h->avctx, &pic->tf);
53
47948
    av_buffer_unref(&pic->hwaccel_priv_buf);
54
55
47948
    av_buffer_unref(&pic->qscale_table_buf);
56
47948
    av_buffer_unref(&pic->mb_type_buf);
57
143844
    for (i = 0; i < 2; i++) {
58
95896
        av_buffer_unref(&pic->motion_val_buf[i]);
59
95896
        av_buffer_unref(&pic->ref_index_buf[i]);
60
    }
61
62
47948
    memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
63
}
64
65
24603
int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src)
66
{
67
    int ret, i;
68
69
24603
    av_assert0(!dst->f->buf[0]);
70
24603
    av_assert0(src->f->buf[0]);
71
24603
    av_assert0(src->tf.f == src->f);
72
73
24603
    dst->tf.f = dst->f;
74
24603
    ret = ff_thread_ref_frame(&dst->tf, &src->tf);
75
24603
    if (ret < 0)
76
        goto fail;
77
78
24603
    dst->qscale_table_buf = av_buffer_ref(src->qscale_table_buf);
79
24603
    dst->mb_type_buf      = av_buffer_ref(src->mb_type_buf);
80

24603
    if (!dst->qscale_table_buf || !dst->mb_type_buf) {
81
        ret = AVERROR(ENOMEM);
82
        goto fail;
83
    }
84
24603
    dst->qscale_table = src->qscale_table;
85
24603
    dst->mb_type      = src->mb_type;
86
87
73809
    for (i = 0; i < 2; i++) {
88
49206
        dst->motion_val_buf[i] = av_buffer_ref(src->motion_val_buf[i]);
89
49206
        dst->ref_index_buf[i]  = av_buffer_ref(src->ref_index_buf[i]);
90

49206
        if (!dst->motion_val_buf[i] || !dst->ref_index_buf[i]) {
91
            ret = AVERROR(ENOMEM);
92
            goto fail;
93
        }
94
49206
        dst->motion_val[i] = src->motion_val[i];
95
49206
        dst->ref_index[i]  = src->ref_index[i];
96
    }
97
98
24603
    if (src->hwaccel_picture_private) {
99
        dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
100
        if (!dst->hwaccel_priv_buf) {
101
            ret = AVERROR(ENOMEM);
102
            goto fail;
103
        }
104
        dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data;
105
    }
106
107
73809
    for (i = 0; i < 2; i++)
108
49206
        dst->field_poc[i] = src->field_poc[i];
109
110
24603
    memcpy(dst->ref_poc,   src->ref_poc,   sizeof(src->ref_poc));
111
24603
    memcpy(dst->ref_count, src->ref_count, sizeof(src->ref_count));
112
113
24603
    dst->poc           = src->poc;
114
24603
    dst->frame_num     = src->frame_num;
115
24603
    dst->mmco_reset    = src->mmco_reset;
116
24603
    dst->long_ref      = src->long_ref;
117
24603
    dst->mbaff         = src->mbaff;
118
24603
    dst->field_picture = src->field_picture;
119
24603
    dst->reference     = src->reference;
120
24603
    dst->recovered     = src->recovered;
121
24603
    dst->invalid_gap   = src->invalid_gap;
122
24603
    dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt;
123
124
24603
    return 0;
125
fail:
126
    ff_h264_unref_picture(h, dst);
127
    return ret;
128
}
129
130
124442
void ff_h264_set_erpic(ERPicture *dst, H264Picture *src)
131
{
132
#if CONFIG_ERROR_RESILIENCE
133
    int i;
134
135
124442
    memset(dst, 0, sizeof(*dst));
136
137
124442
    if (!src)
138
80040
        return;
139
140
44402
    dst->f = src->f;
141
44402
    dst->tf = &src->tf;
142
143
133206
    for (i = 0; i < 2; i++) {
144
88804
        dst->motion_val[i] = src->motion_val[i];
145
88804
        dst->ref_index[i] = src->ref_index[i];
146
    }
147
148
44402
    dst->mb_type = src->mb_type;
149
44402
    dst->field_picture = src->field_picture;
150
#endif /* CONFIG_ERROR_RESILIENCE */
151
}
152
153
25906
int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
154
{
155
25906
    AVCodecContext *const avctx = h->avctx;
156
25906
    int err = 0;
157
25906
    h->mb_y = 0;
158
159

25906
    if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {
160
25874
        if (!h->droppable) {
161
16800
            err = ff_h264_execute_ref_pic_marking(h);
162
16800
            h->poc.prev_poc_msb = h->poc.poc_msb;
163
16800
            h->poc.prev_poc_lsb = h->poc.poc_lsb;
164
        }
165
25874
        h->poc.prev_frame_num_offset = h->poc.frame_num_offset;
166
25874
        h->poc.prev_frame_num        = h->poc.frame_num;
167
    }
168
169
25906
    if (avctx->hwaccel) {
170
        err = avctx->hwaccel->end_frame(avctx);
171
        if (err < 0)
172
            av_log(avctx, AV_LOG_ERROR,
173
                   "hardware accelerator failed to decode picture\n");
174
    }
175
176

25906
    if (!in_setup && !h->droppable)
177
16750
        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
178
16750
                                  h->picture_structure == PICT_BOTTOM_FIELD);
179
25906
    emms_c();
180
181
25906
    h->current_slice = 0;
182
183
25906
    return err;
184
}