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