FFmpeg
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 #include "mpegvideodata.h"
27 
29 {
30  int format, width, height;
31 
32  /* picture header */
33  if (get_bits_long(&s->gb, 17) != 1) {
34  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
35  return AVERROR_INVALIDDATA;
36  }
37  format = get_bits(&s->gb, 5);
38  if (format != 0 && format != 1) {
39  av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
40  return AVERROR_INVALIDDATA;
41  }
42  s->h263_flv = format + 1;
43  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
44  format = get_bits(&s->gb, 3);
45  switch (format) {
46  case 0:
47  width = get_bits(&s->gb, 8);
48  height = get_bits(&s->gb, 8);
49  break;
50  case 1:
51  width = get_bits(&s->gb, 16);
52  height = get_bits(&s->gb, 16);
53  break;
54  case 2:
55  width = 352;
56  height = 288;
57  break;
58  case 3:
59  width = 176;
60  height = 144;
61  break;
62  case 4:
63  width = 128;
64  height = 96;
65  break;
66  case 5:
67  width = 320;
68  height = 240;
69  break;
70  case 6:
71  width = 160;
72  height = 120;
73  break;
74  default:
75  width = height = 0;
76  break;
77  }
78  if (av_image_check_size(width, height, 0, s->avctx))
79  return AVERROR(EINVAL);
80  s->width = width;
81  s->height = height;
82 
83  s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
84  s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
85  if (s->droppable)
86  s->pict_type = AV_PICTURE_TYPE_P;
87 
88  skip_bits1(&s->gb); /* deblocking flag */
89  s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
90 
91  s->h263_plus = 0;
92 
93  s->unrestricted_mv = 1;
94  s->h263_long_vectors = 0;
95 
96  /* PEI */
97  if (skip_1stop_8data_bits(&s->gb) < 0)
98  return AVERROR_INVALIDDATA;
99 
100  s->f_code = 1;
101 
102  if (s->ehc_mode)
103  s->avctx->sample_aspect_ratio= (AVRational){1,2};
104 
105  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  s->y_dc_scale_table = s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
112 
113  return 0;
114 }
115 
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),
123  .close = ff_h263_decode_end,
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 };
AVCodec
AVCodec.
Definition: avcodec.h:3481
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_mpeg1_dc_scale_table
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideodata.c:34
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:546
mpegvideo.h
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:2651
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
flv.h
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: internal.h:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:257
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
ff_flv_decode_picture_header
int ff_flv_decode_picture_header(MpegEncContext *s)
Definition: flvdec.c:28
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:981
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
height
#define height
mpegvideodata.h
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:538
av_get_picture_type_char
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:88
ff_h263_decode_init
int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:68
ff_h263_decode_end
int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:155
AVCodec::name
const char * name
Name of the codec implementation.
Definition: avcodec.h:3488
skip_1stop_8data_bits
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:854
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ff_h263_decode_frame
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:421
imgutils.h
AV_CODEC_CAP_DRAW_HORIZ_BAND
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:975
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_flv_decoder
AVCodec ff_flv_decoder
Definition: flvdec.c:116
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:282
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: avcodec.h:239
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:81
h263.h