]> git.sesse.net Git - ffmpeg/blob - libavcodec/flvdec.c
flv: K&R formatting cosmetics
[ffmpeg] / libavcodec / flvdec.c
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
27 void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last)
28 {
29     int is11 = get_bits1(gb);
30     *last = get_bits1(gb);
31     *run  = get_bits(gb, 6);
32     if (is11)
33         *level = get_sbits(gb, 11);
34     else
35         *level = get_sbits(gb, 7);
36 }
37
38 int ff_flv_decode_picture_header(MpegEncContext *s)
39 {
40     int format, width, height;
41
42     /* picture header */
43     if (get_bits_long(&s->gb, 17) != 1) {
44         av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
45         return -1;
46     }
47     format = get_bits(&s->gb, 5);
48     if (format != 0 && format != 1) {
49         av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
50         return -1;
51     }
52     s->h263_flv       = format + 1;
53     s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
54     format            = get_bits(&s->gb, 3);
55     switch (format) {
56     case 0:
57         width  = get_bits(&s->gb, 8);
58         height = get_bits(&s->gb, 8);
59         break;
60     case 1:
61         width  = get_bits(&s->gb, 16);
62         height = get_bits(&s->gb, 16);
63         break;
64     case 2:
65         width  = 352;
66         height = 288;
67         break;
68     case 3:
69         width  = 176;
70         height = 144;
71         break;
72     case 4:
73         width  = 128;
74         height = 96;
75         break;
76     case 5:
77         width  = 320;
78         height = 240;
79         break;
80     case 6:
81         width  = 160;
82         height = 120;
83         break;
84     default:
85         width = height = 0;
86         break;
87     }
88     if (av_image_check_size(width, height, 0, s->avctx))
89         return -1;
90     s->width  = width;
91     s->height = height;
92
93     s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
94     s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
95     if (s->droppable)
96         s->pict_type = AV_PICTURE_TYPE_P;
97
98     skip_bits1(&s->gb); /* deblocking flag */
99     s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
100
101     s->h263_plus = 0;
102
103     s->unrestricted_mv   = 1;
104     s->h263_long_vectors = 0;
105
106     /* PEI */
107     while (get_bits1(&s->gb) != 0)
108         skip_bits(&s->gb, 8);
109     s->f_code = 1;
110
111     if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
112         av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
113                s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
114                s->h263_flv - 1, s->qscale, s->picture_number);
115     }
116
117     s->y_dc_scale_table = s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
118
119     return 0;
120 }
121
122 AVCodec ff_flv_decoder = {
123     .name           = "flv",
124     .long_name      = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
125     .type           = AVMEDIA_TYPE_VIDEO,
126     .id             = AV_CODEC_ID_FLV1,
127     .priv_data_size = sizeof(MpegEncContext),
128     .init           = ff_h263_decode_init,
129     .close          = ff_h263_decode_end,
130     .decode         = ff_h263_decode_frame,
131     .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
132     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
133                                                      AV_PIX_FMT_NONE },
134 };