h264: simplify calls to ff_er_add_slice().
[FFMpeg-mirror/mplayer-patches.git] / libavcodec / flvdec.c
blob3640d2984717f621066a13275f1328da4cf4d524
1 /*
2 * FLV decoding.
3 * This file is part of Libav.
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.
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.
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
20 #include "mpegvideo.h"
21 #include "h263.h"
22 #include "flv.h"
23 #include "libavutil/imgutils.h"
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);
36 int ff_flv_decode_picture_header(MpegEncContext *s)
38 int format, width, height;
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 -1;
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 -1;
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;
86 if(av_image_check_size(width, height, 0, s->avctx))
87 return -1;
88 s->width = width;
89 s->height = height;
91 s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
92 s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
93 if (s->droppable)
94 s->pict_type = AV_PICTURE_TYPE_P;
96 skip_bits1(&s->gb); /* deblocking flag */
97 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
99 s->h263_plus = 0;
101 s->unrestricted_mv = 1;
102 s->h263_long_vectors = 0;
104 /* PEI */
105 while (get_bits1(&s->gb) != 0) {
106 skip_bits(&s->gb, 8);
108 s->f_code = 1;
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",
112 s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
113 s->h263_flv - 1, s->qscale, s->picture_number);
116 s->y_dc_scale_table=
117 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
119 return 0;
122 AVCodec ff_flv_decoder = {
123 .name = "flv",
124 .type = AVMEDIA_TYPE_VIDEO,
125 .id = AV_CODEC_ID_FLV1,
126 .priv_data_size = sizeof(MpegEncContext),
127 .init = ff_h263_decode_init,
128 .close = ff_h263_decode_end,
129 .decode = ff_h263_decode_frame,
130 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
131 .long_name = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
132 .pix_fmts = ff_pixfmt_list_420,