OSDN Git Service

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