Coverage Report

Created: 2026-07-25 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/flvdec.c
Line
Count
Source
1
/*
2
 * FLV decoding.
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
#include "libavutil/imgutils.h"
22
23
#include "codec_internal.h"
24
#include "flvdec.h"
25
#include "h263dec.h"
26
#include "mpegvideo.h"
27
#include "mpegvideodec.h"
28
29
int ff_flv_decode_picture_header(H263DecContext *const h)
30
92.0k
{
31
92.0k
    int format, width, height;
32
33
    /* picture header */
34
92.0k
    if (get_bits(&h->gb, 17) != 1) {
35
11.9k
        av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
36
11.9k
        return AVERROR_INVALIDDATA;
37
11.9k
    }
38
80.1k
    format = get_bits(&h->gb, 5);
39
80.1k
    if (format != 0 && format != 1) {
40
493
        av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
41
493
        return AVERROR_INVALIDDATA;
42
493
    }
43
79.6k
    h->flv            = format;
44
79.6k
    h->picture_number = get_bits(&h->gb, 8); /* picture timestamp */
45
79.6k
    format            = get_bits(&h->gb, 3);
46
79.6k
    switch (format) {
47
17.0k
    case 0:
48
17.0k
        width  = get_bits(&h->gb, 8);
49
17.0k
        height = get_bits(&h->gb, 8);
50
17.0k
        break;
51
4.19k
    case 1:
52
4.19k
        width  = get_bits(&h->gb, 16);
53
4.19k
        height = get_bits(&h->gb, 16);
54
4.19k
        break;
55
4.68k
    case 2:
56
4.68k
        width  = 352;
57
4.68k
        height = 288;
58
4.68k
        break;
59
1.54k
    case 3:
60
1.54k
        width  = 176;
61
1.54k
        height = 144;
62
1.54k
        break;
63
30.8k
    case 4:
64
30.8k
        width  = 128;
65
30.8k
        height = 96;
66
30.8k
        break;
67
3.68k
    case 5:
68
3.68k
        width  = 320;
69
3.68k
        height = 240;
70
3.68k
        break;
71
17.4k
    case 6:
72
17.4k
        width  = 160;
73
17.4k
        height = 120;
74
17.4k
        break;
75
297
    default:
76
297
        width = height = 0;
77
297
        break;
78
79.6k
    }
79
79.6k
    if (av_image_check_size(width, height, 0, h->c.avctx))
80
1.91k
        return AVERROR(EINVAL);
81
77.7k
    h->c.width  = width;
82
77.7k
    h->c.height = height;
83
84
77.7k
    h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->gb, 2);
85
77.7k
    h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P;
86
77.7k
    if (h->c.droppable)
87
2.39k
        h->c.pict_type = AV_PICTURE_TYPE_P;
88
89
77.7k
    skip_bits1(&h->gb); /* deblocking flag */
90
77.7k
    h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
91
92
77.7k
    h->h263_long_vectors = 0;
93
94
    /* PEI */
95
77.7k
    if (skip_1stop_8data_bits(&h->gb) < 0)
96
2.61k
        return AVERROR_INVALIDDATA;
97
98
75.1k
    if (h->ehc_mode)
99
0
        h->c.avctx->sample_aspect_ratio= (AVRational){1,2};
100
101
75.1k
    if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
102
0
        av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
103
0
               h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type),
104
0
               h->flv, h->c.qscale, h->picture_number);
105
0
    }
106
107
75.1k
    return 0;
108
77.7k
}
109
110
const FFCodec ff_flv_decoder = {
111
    .p.name         = "flv",
112
    CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
113
    .p.type         = AVMEDIA_TYPE_VIDEO,
114
    .p.id           = AV_CODEC_ID_FLV1,
115
    .priv_data_size = sizeof(H263DecContext),
116
    .init           = ff_h263_decode_init,
117
    FF_CODEC_DECODE_CB(ff_h263_decode_frame),
118
    .close          = ff_mpv_decode_close,
119
    .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
120
    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP |
121
                      FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
122
    .p.max_lowres   = 3,
123
};