libavcodec/flvdec.c
Go to the documentation of this file.
1 /*
2  * FLV decoding.
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * FFmpeg is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with FFmpeg; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include "mpegvideo.h"
21 #include "h263.h"
22 #include "flv.h"
23 #include "libavutil/imgutils.h"
24 
25 void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){
26  int is11 = get_bits1(gb);
27  *last = get_bits1(gb);
28  *run = get_bits(gb, 6);
29  if(is11){
30  *level = get_sbits(gb, 11);
31  } else {
32  *level = get_sbits(gb, 7);
33  }
34 }
35 
37 {
38  int format, width, height;
39 
40  /* picture header */
41  if (get_bits_long(&s->gb, 17) != 1) {
42  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
43  return AVERROR_INVALIDDATA;
44  }
45  format = get_bits(&s->gb, 5);
46  if (format != 0 && format != 1) {
47  av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
48  return AVERROR_INVALIDDATA;
49  }
50  s->h263_flv = format+1;
51  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
52  format = get_bits(&s->gb, 3);
53  switch (format) {
54  case 0:
55  width = get_bits(&s->gb, 8);
56  height = get_bits(&s->gb, 8);
57  break;
58  case 1:
59  width = get_bits(&s->gb, 16);
60  height = get_bits(&s->gb, 16);
61  break;
62  case 2:
63  width = 352;
64  height = 288;
65  break;
66  case 3:
67  width = 176;
68  height = 144;
69  break;
70  case 4:
71  width = 128;
72  height = 96;
73  break;
74  case 5:
75  width = 320;
76  height = 240;
77  break;
78  case 6:
79  width = 160;
80  height = 120;
81  break;
82  default:
83  width = height = 0;
84  break;
85  }
86  if(av_image_check_size(width, height, 0, s->avctx))
87  return AVERROR(EINVAL);
88  s->width = width;
89  s->height = height;
90 
91  s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
93  if (s->droppable)
95 
96  skip_bits1(&s->gb); /* deblocking flag */
97  s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
98 
99  s->h263_plus = 0;
100 
101  s->unrestricted_mv = 1;
102  s->h263_long_vectors = 0;
103 
104  /* PEI */
105  while (get_bits1(&s->gb) != 0) {
106  skip_bits(&s->gb, 8);
107  }
108  s->f_code = 1;
109 
110  if(s->avctx->debug & FF_DEBUG_PICT_INFO){
111  av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
113  s->h263_flv - 1, s->qscale, s->picture_number);
114  }
115 
116  s->y_dc_scale_table=
118 
119  return 0;
120 }
121 
123  .name = "flv",
124  .type = AVMEDIA_TYPE_VIDEO,
125  .id = AV_CODEC_ID_FLV1,
126  .priv_data_size = sizeof(MpegEncContext),
130  .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
131  .max_lowres = 3,
132  .long_name = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
133  .pix_fmts = ff_pixfmt_list_420,
134 };
int picture_number
Definition: mpegvideo.h:275
const char * s
Definition: avisynth_c.h:668
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
struct MpegEncContext MpegEncContext
MpegEncContext.
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:351
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
mpegvideo header.
uint8_t run
Definition: svq3.c:136
int qscale
QP.
Definition: mpegvideo.h:369
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:225
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
enum AVPixelFormat ff_pixfmt_list_420[]
Definition: mpegvideo.c:127
int h263_plus
h263 plus headers
Definition: mpegvideo.h:254
AVCodec ff_flv_decoder
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:388
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
GetBitContext gb
Definition: mpegvideo.h:649
int ff_h263_decode_init(AVCodecContext *avctx)
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:231
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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
FIXME Range Coding of cr are level
Definition: snow.txt:367
static int width
Definition: tests/utils.c:158
int h263_flv
use flv h263 header
Definition: mpegvideo.h:255
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:245
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideo.c:72
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:273
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:298
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:265
int f_code
forward MV resolution
Definition: mpegvideo.h:395
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:306
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:377
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:352
#define FF_DEBUG_PICT_INFO
void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last)
MpegEncContext.
Definition: mpegvideo.h:241
struct AVCodecContext * avctx
Definition: mpegvideo.h:243
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
int ff_h263_decode_end(AVCodecContext *avctx)
int chroma_qscale
chroma QP
Definition: mpegvideo.h:370
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
int ff_flv_decode_picture_header(MpegEncContext *s)
int h263_long_vectors
use horrible h263v1 long vector mode
Definition: mpegvideo.h:389
Predicted.
Definition: avutil.h:217