FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
flvdec.c
Go to the documentation of this file.
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 
28 {
29  int format, width, height;
30 
31  /* picture header */
32  if (get_bits_long(&s->gb, 17) != 1) {
33  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
34  return AVERROR_INVALIDDATA;
35  }
36  format = get_bits(&s->gb, 5);
37  if (format != 0 && format != 1) {
38  av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
39  return AVERROR_INVALIDDATA;
40  }
41  s->h263_flv = format + 1;
42  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
43  format = get_bits(&s->gb, 3);
44  switch (format) {
45  case 0:
46  width = get_bits(&s->gb, 8);
47  height = get_bits(&s->gb, 8);
48  break;
49  case 1:
50  width = get_bits(&s->gb, 16);
51  height = get_bits(&s->gb, 16);
52  break;
53  case 2:
54  width = 352;
55  height = 288;
56  break;
57  case 3:
58  width = 176;
59  height = 144;
60  break;
61  case 4:
62  width = 128;
63  height = 96;
64  break;
65  case 5:
66  width = 320;
67  height = 240;
68  break;
69  case 6:
70  width = 160;
71  height = 120;
72  break;
73  default:
74  width = height = 0;
75  break;
76  }
77  if (av_image_check_size(width, height, 0, s->avctx))
78  return AVERROR(EINVAL);
79  s->width = width;
80  s->height = height;
81 
82  s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
84  if (s->droppable)
86 
87  skip_bits1(&s->gb); /* deblocking flag */
88  s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
89 
90  s->h263_plus = 0;
91 
92  s->unrestricted_mv = 1;
93  s->h263_long_vectors = 0;
94 
95  /* PEI */
96  if (skip_1stop_8data_bits(&s->gb) < 0)
97  return AVERROR_INVALIDDATA;
98 
99  s->f_code = 1;
100 
101  if (s->ehc_mode)
103 
104  if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
105  av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
107  s->h263_flv - 1, s->qscale, s->picture_number);
108  }
109 
111 
112  return 0;
113 }
114 
116  .name = "flv",
117  .long_name = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
118  .type = AVMEDIA_TYPE_VIDEO,
119  .id = AV_CODEC_ID_FLV1,
120  .priv_data_size = sizeof(MpegEncContext),
122  .close = ff_h263_decode_end,
124  .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
125  .max_lowres = 3,
126  .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
127  AV_PIX_FMT_NONE },
128 };