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