FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/flvdec.c
Date: 2022-11-28 23:49:43
Exec Total Coverage
Lines: 35 65 53.8%
Branches: 11 26 42.3%

Line Branch Exec 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 "mpegvideodata.h"
28
29 315 int ff_flv_decode_picture_header(MpegEncContext *s)
30 {
31 int format, width, height;
32
33 /* picture header */
34
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 315 times.
315 if (get_bits(&s->gb, 17) != 1) {
35 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
36 return AVERROR_INVALIDDATA;
37 }
38 315 format = get_bits(&s->gb, 5);
39
2/4
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 315 times.
315 if (format != 0 && format != 1) {
40 av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
41 return AVERROR_INVALIDDATA;
42 }
43 315 s->h263_flv = format + 1;
44 315 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
45 315 format = get_bits(&s->gb, 3);
46
3/8
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 262 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
315 switch (format) {
47 51 case 0:
48 51 width = get_bits(&s->gb, 8);
49 51 height = get_bits(&s->gb, 8);
50 51 break;
51 case 1:
52 width = get_bits(&s->gb, 16);
53 height = get_bits(&s->gb, 16);
54 break;
55 262 case 2:
56 262 width = 352;
57 262 height = 288;
58 262 break;
59 case 3:
60 width = 176;
61 height = 144;
62 break;
63 case 4:
64 width = 128;
65 height = 96;
66 break;
67 2 case 5:
68 2 width = 320;
69 2 height = 240;
70 2 break;
71 case 6:
72 width = 160;
73 height = 120;
74 break;
75 default:
76 width = height = 0;
77 break;
78 }
79
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 315 times.
315 if (av_image_check_size(width, height, 0, s->avctx))
80 return AVERROR(EINVAL);
81 315 s->width = width;
82 315 s->height = height;
83
84 315 s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
85 315 s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
315 if (s->droppable)
87 s->pict_type = AV_PICTURE_TYPE_P;
88
89 315 skip_bits1(&s->gb); /* deblocking flag */
90 315 s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
91
92 315 s->h263_plus = 0;
93
94 315 s->h263_long_vectors = 0;
95
96 /* PEI */
97
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 315 times.
315 if (skip_1stop_8data_bits(&s->gb) < 0)
98 return AVERROR_INVALIDDATA;
99
100 315 s->f_code = 1;
101
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
315 if (s->ehc_mode)
103 s->avctx->sample_aspect_ratio= (AVRational){1,2};
104
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 315 times.
315 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
106 av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
107 s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
108 s->h263_flv - 1, s->qscale, s->picture_number);
109 }
110
111 315 return 0;
112 }
113
114 const FFCodec ff_flv_decoder = {
115 .p.name = "flv",
116 CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
117 .p.type = AVMEDIA_TYPE_VIDEO,
118 .p.id = AV_CODEC_ID_FLV1,
119 .priv_data_size = sizeof(MpegEncContext),
120 .init = ff_h263_decode_init,
121 .close = ff_h263_decode_end,
122 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
123 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
124 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
125 .p.max_lowres = 3,
126 .p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
127 AV_PIX_FMT_NONE },
128 };
129