annotate flvdec.c @ 11728:907ac02ef561 libavcodec

aacenc: Fix psy logic. Set band info before determining scalefactors. Use the look ahead for windowing decision.
author alexc
date Fri, 14 May 2010 16:49:11 +0000
parents 8a4984c5cacc
children c35d7bc64882
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10788
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
1 /*
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
2 * FLV decoding.
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
3 * This file is part of FFmpeg.
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
4 *
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
5 * FFmpeg is free software; you can redistribute it and/or
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
9 *
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
10 * FFmpeg is distributed in the hope that it will be useful,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
13 * Lesser General Public License for more details.
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
14 *
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
16 * License along with FFmpeg; if not, write to the Free Software
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
18 */
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
19
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
20 #include "mpegvideo.h"
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10790
diff changeset
21 #include "h263.h"
10790
145b62a1de1c flv.h should ideally be included in flvdec.c
michael
parents: 10788
diff changeset
22 #include "flv.h"
10788
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
23
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
24 void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
25 int is11 = get_bits1(gb);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
26 *last = get_bits1(gb);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
27 *run = get_bits(gb, 6);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
28 if(is11){
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
29 *level = get_sbits(gb, 11);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
30 } else {
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
31 *level = get_sbits(gb, 7);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
32 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
33 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
34
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
35 int ff_flv_decode_picture_header(MpegEncContext *s)
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
36 {
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
37 int format, width, height;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
38
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
39 /* picture header */
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
40 if (get_bits_long(&s->gb, 17) != 1) {
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
41 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
42 return -1;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
43 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
44 format = get_bits(&s->gb, 5);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
45 if (format != 0 && format != 1) {
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
46 av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
47 return -1;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
48 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
49 s->h263_flv = format+1;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
50 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
51 format = get_bits(&s->gb, 3);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
52 switch (format) {
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
53 case 0:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
54 width = get_bits(&s->gb, 8);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
55 height = get_bits(&s->gb, 8);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
56 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
57 case 1:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
58 width = get_bits(&s->gb, 16);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
59 height = get_bits(&s->gb, 16);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
60 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
61 case 2:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
62 width = 352;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
63 height = 288;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
64 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
65 case 3:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
66 width = 176;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
67 height = 144;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
68 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
69 case 4:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
70 width = 128;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
71 height = 96;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
72 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
73 case 5:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
74 width = 320;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
75 height = 240;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
76 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
77 case 6:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
78 width = 160;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
79 height = 120;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
80 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
81 default:
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
82 width = height = 0;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
83 break;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
84 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
85 if(avcodec_check_dimensions(s->avctx, width, height))
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
86 return -1;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
87 s->width = width;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
88 s->height = height;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
89
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
90 s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
91 s->dropable= s->pict_type > FF_P_TYPE;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
92 if (s->dropable)
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
93 s->pict_type = FF_P_TYPE;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
94
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
95 skip_bits1(&s->gb); /* deblocking flag */
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
96 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
97
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
98 s->h263_plus = 0;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
99
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
100 s->unrestricted_mv = 1;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
101 s->h263_long_vectors = 0;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
102
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
103 /* PEI */
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
104 while (get_bits1(&s->gb) != 0) {
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
105 skip_bits(&s->gb, 8);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
106 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
107 s->f_code = 1;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
108
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
109 if(s->avctx->debug & FF_DEBUG_PICT_INFO){
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
110 av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
111 s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number);
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
112 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
113
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
114 s->y_dc_scale_table=
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
115 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
116
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
117 return 0;
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
118 }
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
119
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
120 AVCodec flv_decoder = {
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
121 "flv",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10828
diff changeset
122 AVMEDIA_TYPE_VIDEO,
10788
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
123 CODEC_ID_FLV1,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
124 sizeof(MpegEncContext),
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
125 ff_h263_decode_init,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
126 NULL,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
127 ff_h263_decode_end,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
128 ff_h263_decode_frame,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
129 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
130 .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
131 .pix_fmts= ff_pixfmt_list_420,
0c8f9288b5e4 Split flv decoding out.
michael
parents:
diff changeset
132 };