Libav
flvdec.c
Go to the documentation of this file.
1 /*
2  * FLV decoding.
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; 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 void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last)
29 {
30  int is11 = get_bits1(gb);
31  *last = get_bits1(gb);
32  *run = get_bits(gb, 6);
33  if (is11)
34  *level = get_sbits(gb, 11);
35  else
36  *level = get_sbits(gb, 7);
37 }
38 
40 {
41  int format, width, height;
42 
43  /* picture header */
44  if (get_bits_long(&s->gb, 17) != 1) {
45  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
46  return -1;
47  }
48  format = get_bits(&s->gb, 5);
49  if (format != 0 && format != 1) {
50  av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
51  return -1;
52  }
53  s->h263_flv = format + 1;
54  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
55  format = get_bits(&s->gb, 3);
56  switch (format) {
57  case 0:
58  width = get_bits(&s->gb, 8);
59  height = get_bits(&s->gb, 8);
60  break;
61  case 1:
62  width = get_bits(&s->gb, 16);
63  height = get_bits(&s->gb, 16);
64  break;
65  case 2:
66  width = 352;
67  height = 288;
68  break;
69  case 3:
70  width = 176;
71  height = 144;
72  break;
73  case 4:
74  width = 128;
75  height = 96;
76  break;
77  case 5:
78  width = 320;
79  height = 240;
80  break;
81  case 6:
82  width = 160;
83  height = 120;
84  break;
85  default:
86  width = height = 0;
87  break;
88  }
89  if (av_image_check_size(width, height, 0, s->avctx))
90  return -1;
91  s->width = width;
92  s->height = height;
93 
94  s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
96  if (s->droppable)
98 
99  skip_bits1(&s->gb); /* deblocking flag */
100  s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
101 
102  s->h263_plus = 0;
103 
104  s->unrestricted_mv = 1;
105  s->h263_long_vectors = 0;
106 
107  /* PEI */
108  while (get_bits1(&s->gb) != 0)
109  skip_bits(&s->gb, 8);
110  s->f_code = 1;
111 
112  if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
113  av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
115  s->h263_flv - 1, s->qscale, s->picture_number);
116  }
117 
119 
120  return 0;
121 }
122 
124  .name = "flv",
125  .long_name = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
126  .type = AVMEDIA_TYPE_VIDEO,
127  .id = AV_CODEC_ID_FLV1,
128  .priv_data_size = sizeof(MpegEncContext),
130  .close = ff_h263_decode_end,
133  .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
134  AV_PIX_FMT_NONE },
135 };
int picture_number
Definition: mpegvideo.h:122
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:183
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:228
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
mpegvideo header.
uint8_t run
Definition: svq3.c:203
AVCodec.
Definition: avcodec.h:3120
int qscale
QP.
Definition: mpegvideo.h:199
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:214
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideodata.c:27
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:2627
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:50
int h263_plus
H.263+ headers.
Definition: mpegvideo.h:104
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
AVCodec ff_flv_decoder
Definition: flvdec.c:123
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:215
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
GetBitContext gb
Definition: mpegvideo.h:431
int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:53
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:223
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:373
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:832
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
static int width
Definition: utils.c:156
int h263_flv
use flv H.263 header
Definition: mpegvideo.h:105
int debug
debug
Definition: avcodec.h:2626
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:95
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:267
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:292
const char * format
Definition: movenc.c:47
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:259
int f_code
forward MV resolution
Definition: mpegvideo.h:229
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:300
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:206
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:257
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:184
uint8_t level
Definition: svq3.c:204
void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last)
Definition: flvdec.c:28
int height
Definition: gxfenc.c:72
MpegEncContext.
Definition: mpegvideo.h:76
struct AVCodecContext * avctx
Definition: mpegvideo.h:93
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:582
int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:136
int chroma_qscale
chroma QP
Definition: mpegvideo.h:200
int ff_flv_decode_picture_header(MpegEncContext *s)
Definition: flvdec.c:39
int h263_long_vectors
use horrible H.263v1 long vector mode
Definition: mpegvideo.h:216
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838
Predicted.
Definition: avutil.h:261