FFmpeg coverage


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