Libav
flvdec.c
Go to the documentation of this file.
1 /*
2  * FLV decoding.
3  * This file is part of Libav.
4  *
5  * Libav 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  * Libav 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 Libav; 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 {
27  int is11 = get_bits1(gb);
28  *last = get_bits1(gb);
29  *run = get_bits(gb, 6);
30  if (is11) {
31  *level = get_sbits(gb, 11);
32  } else {
33  *level = get_sbits(gb, 7);
34  }
35 }
36 
38 {
39  int format, width, height;
40 
41  /* picture header */
42  if (get_bits_long(&s->gb, 17) != 1) {
43  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
44  return -1;
45  }
46  format = get_bits(&s->gb, 5);
47  if (format != 0 && format != 1) {
48  av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
49  return -1;
50  }
51  s->h263_flv = format + 1;
52  s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
53  format = get_bits(&s->gb, 3);
54  switch (format) {
55  case 0:
56  width = get_bits(&s->gb, 8);
57  height = get_bits(&s->gb, 8);
58  break;
59  case 1:
60  width = get_bits(&s->gb, 16);
61  height = get_bits(&s->gb, 16);
62  break;
63  case 2:
64  width = 352;
65  height = 288;
66  break;
67  case 3:
68  width = 176;
69  height = 144;
70  break;
71  case 4:
72  width = 128;
73  height = 96;
74  break;
75  case 5:
76  width = 320;
77  height = 240;
78  break;
79  case 6:
80  width = 160;
81  height = 120;
82  break;
83  default:
84  width = height = 0;
85  break;
86  }
87  if (av_image_check_size(width, height, 0, s->avctx))
88  return -1;
89  s->width = width;
90  s->height = height;
91 
92  s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
94  if (s->droppable)
96 
97  skip_bits1(&s->gb); /* deblocking flag */
98  s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
99 
100  s->h263_plus = 0;
101 
102  s->unrestricted_mv = 1;
103  s->h263_long_vectors = 0;
104 
105  /* PEI */
106  while (get_bits1(&s->gb) != 0)
107  skip_bits(&s->gb, 8);
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 
117 
118  return 0;
119 }
120 
122  .name = "flv",
123  .long_name = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
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  .pix_fmts = (const enum AVPixelFormat[]) {
134  },
135 };
int picture_number
Definition: mpegvideo.h:253
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:314
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
mpegvideo header.
uint8_t run
Definition: svq3.c:146
AVCodec.
Definition: avcodec.h:2812
int qscale
QP.
Definition: mpegvideo.h:332
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:226
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:2379
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
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:43
int h263_plus
h263 plus headers
Definition: mpegvideo.h:232
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
AVCodec ff_flv_decoder
Definition: flvdec.c:121
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:348
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
GetBitContext gb
Definition: mpegvideo.h:558
int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:43
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:222
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:365
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:678
static int width
Definition: utils.c:156
int h263_flv
use flv h263 header
Definition: mpegvideo.h:233
int debug
debug
Definition: avcodec.h:2378
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:223
const uint8_t ff_mpeg1_dc_scale_table[128]
Definition: mpegvideo.c:55
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:296
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:263
int f_code
forward MV resolution
Definition: mpegvideo.h:362
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:304
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:339
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:315
uint8_t level
Definition: svq3.c:147
void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last)
Definition: flvdec.c:25
int height
Definition: gxfenc.c:72
MpegEncContext.
Definition: mpegvideo.h:204
struct AVCodecContext * avctx
Definition: mpegvideo.h:221
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:129
int chroma_qscale
chroma QP
Definition: mpegvideo.h:333
int ff_flv_decode_picture_header(MpegEncContext *s)
Definition: flvdec.c:37
int h263_long_vectors
use horrible h263v1 long vector mode
Definition: mpegvideo.h:349
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
Predicted.
Definition: avutil.h:254