Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1100)

Side by Side Diff: patches/to_upstream/05_vc1_bsfs.patch

Issue 789004: ffmpeg roll of source to mar 9 version... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/ffmpeg/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 Index: patched-ffmpeg-mt/libavcodec/allcodecs.c 1 Only in unpatched_ffmpeg-mt: ffmpeg-mt
2 =================================================================== 2 diff -rpu unpatched_ffmpeg-mt/libavcodec/Makefile ffmpeg-mt/libavcodec/Makefile
3 --- patched-ffmpeg-mt/libavcodec/allcodecs.c» (revision 39951) 3 --- unpatched_ffmpeg-mt/libavcodec/Makefile» 2010-03-11 17:46:30 -0800
4 +++ patched-ffmpeg-mt/libavcodec/allcodecs.c» (working copy) 4 +++ ffmpeg-mt/libavcodec/Makefile» 2010-03-11 19:12:19 -0800
5 @@ -382,9 +382,10 @@ 5 @@ -564,6 +564,14 @@ OBJS-$(CONFIG_VP3_PARSER) +
6 OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += aac_adtstoasc_bsf.o
7 OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
8 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF) += h264_mp4toannexb_bsf.o
9 +OBJS-$(CONFIG_MPEG4VIDEO_ES_BSF) += mpeg4video_es_bsf.o \
10 + mpeg4videoenc.o ituh263enc.o \
11 + mpegvideo_enc.o motion_est.o \
12 + ratecontrol.o mpeg12data.o \
13 + aandcttab.o jfdctfst.o \
14 + jfdctint.o faandct.o \
15 + mpeg4video_parser.o mpegvideo.o \
16 + error_resilience.o
17 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF) += imx_dump_header_bsf.o
18 OBJS-$(CONFIG_MJPEGA_DUMP_HEADER_BSF) += mjpega_dump_header_bsf.o
19 OBJS-$(CONFIG_MOV2TEXTSUB_BSF) += movsub_bsf.o
20 @@ -573,6 +581,9 @@ OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)
21 OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o
22 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o
23 OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o
24 +OBJS-$(CONFIG_VC1_ASFTORCV_BSF) += vc1_asftorcv_bsf.o
25 +OBJS-$(CONFIG_VC1_ASFTOANNEXG_BSF) += vc1_asftoannexg_bsf.o vc1.o \
26 + vc1data.o
27
28 # thread libraries
29 OBJS-$(HAVE_BEOSTHREADS) += beosthread.o
30 Only in ffmpeg-mt/libavcodec: Makefile~
31 diff -rpu unpatched_ffmpeg-mt/libavcodec/allcodecs.c ffmpeg-mt/libavcodec/allcod ecs.c
32 --- unpatched_ffmpeg-mt/libavcodec/allcodecs.c» 2010-03-11 17:46:29 -0800
33 +++ ffmpeg-mt/libavcodec/allcodecs.c» 2010-03-11 19:12:19 -0800
34 @@ -384,13 +384,15 @@ void avcodec_register_all(void)
35 REGISTER_BSF (AAC_ADTSTOASC, aac_adtstoasc);
36 REGISTER_BSF (DUMP_EXTRADATA, dump_extradata);
37 REGISTER_BSF (H264_MP4TOANNEXB, h264_mp4toannexb);
38 + REGISTER_BSF (MPEG4VIDEO_ES, mpeg4video_es);
39 REGISTER_BSF (IMX_DUMP_HEADER, imx_dump_header);
6 REGISTER_BSF (MJPEGA_DUMP_HEADER, mjpega_dump_header); 40 REGISTER_BSF (MJPEGA_DUMP_HEADER, mjpega_dump_header);
7 REGISTER_BSF (MP3_HEADER_COMPRESS, mp3_header_compress); 41 REGISTER_BSF (MP3_HEADER_COMPRESS, mp3_header_compress);
8 REGISTER_BSF (MP3_HEADER_DECOMPRESS, mp3_header_decompress); 42 REGISTER_BSF (MP3_HEADER_DECOMPRESS, mp3_header_decompress);
9 + REGISTER_BSF (VC1_ASFTORCV, vc1_asftorcv); 43 + REGISTER_BSF (VC1_ASFTORCV, vc1_asftorcv);
10 + REGISTER_BSF (VC1_ASFTOANNEXG, vc1_asftoannexg); 44 + REGISTER_BSF (VC1_ASFTOANNEXG, vc1_asftoannexg);
11 REGISTER_BSF (MOV2TEXTSUB, mov2textsub); 45 REGISTER_BSF (MOV2TEXTSUB, mov2textsub);
12 REGISTER_BSF (NOISE, noise); 46 REGISTER_BSF (NOISE, noise);
13 REGISTER_BSF (REMOVE_EXTRADATA, remove_extradata); 47 REGISTER_BSF (REMOVE_EXTRADATA, remove_extradata);
14 REGISTER_BSF (TEXT2MOVSUB, text2movsub); 48 REGISTER_BSF (TEXT2MOVSUB, text2movsub);
15 } 49 }
16 - 50 -
17 Index: patched-ffmpeg-mt/libavcodec/vc1_asftorcv_bsf.c 51 Only in ffmpeg-mt/libavcodec: allcodecs.c~
18 =================================================================== 52 diff -rpu unpatched_ffmpeg-mt/libavcodec/mpeg4video.h ffmpeg-mt/libavcodec/mpeg4 video.h
19 --- patched-ffmpeg-mt/libavcodec/vc1_asftorcv_bsf.c (revision 0) 53 --- unpatched_ffmpeg-mt/libavcodec/mpeg4video.h 2010-03-11 17:46:30 -0800
20 +++ patched-ffmpeg-mt/libavcodec/vc1_asftorcv_bsf.c (revision 0) 54 +++ ffmpeg-mt/libavcodec/mpeg4video.h 2010-03-11 19:12:02 -0800
21 @@ -0,0 +1,88 @@ 55 @@ -91,6 +91,9 @@ void mpeg4_encode_mb(MpegEncContext *s,
22 +/* 56 void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
23 + * copyright (c) 2010 Google Inc. 57 int dir);
24 + * 58 void ff_set_mpeg4_time(MpegEncContext * s);
25 + * This file is part of FFmpeg. 59 +void mpeg4_encode_gop_header(MpegEncContext * s);
26 + * 60 +void mpeg4_encode_visual_object_header(MpegEncContext * s);
27 + * FFmpeg is free software; you can redistribute it and/or 61 +void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number) ;
28 + * modify it under the terms of the GNU Lesser General Public 62 void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
29 + * License as published by the Free Software Foundation; either
30 + * version 2.1 of the License, or (at your option) any later version.
31 + *
32 + * FFmpeg is distributed in the hope that it will be useful,
33 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 + * Lesser General Public License for more details.
36 + *
37 + * You should have received a copy of the GNU Lesser General Public
38 + * License along with FFmpeg; if not, write to the Free Software
39 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
40 + */
41 +
42 +#include "avcodec.h"
43 +#include "bytestream.h"
44 +
45 +#define RCV_STREAM_HEADER_SIZE 36
46 +#define RCV_PICTURE_HEADER_SIZE 8
47 +
48 +typedef struct ASFTORCVBSFContext {
49 + int frames;
50 +} ASFTORCVBSFContext;
51 +
52 +static int asftorcv_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avct x, const char *args,
53 + uint8_t **poutbuf, int *poutbuf_size,
54 + const uint8_t *buf, int buf_size, int keyframe){
55 + ASFTORCVBSFContext* ctx = (ASFTORCVBSFContext*)bsfc->priv_data;
56 +
57 + if (avctx->codec_id != CODEC_ID_WMV3) {
58 + av_log(avctx, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
59 + return -1;
60 + }
61 +
62 + uint8_t* bs = NULL;
63 + if (!ctx->frames) {
64 + // Write the header if this is the first frame.
65 + *poutbuf = av_malloc(RCV_STREAM_HEADER_SIZE + RCV_PICTURE_HEADER_SIZE + buf_size);
66 + *poutbuf_size = RCV_STREAM_HEADER_SIZE + RCV_PICTURE_HEADER_SIZE + buf_ size;
67 + bs = *poutbuf;
68 +
69 + // The following structure of stream header comes from libavformat/vc1t estenc.c.
70 + bytestream_put_le24(&bs, 0); // Frame count. 0 for streaming.
71 + bytestream_put_byte(&bs, 0xC5);
72 + bytestream_put_le32(&bs, 4); // 4 bytes of extra data.
73 + bytestream_put_byte(&bs, avctx->extradata[0]);
74 + bytestream_put_byte(&bs, avctx->extradata[1]);
75 + bytestream_put_byte(&bs, avctx->extradata[2]);
76 + bytestream_put_byte(&bs, avctx->extradata[3]);
77 + bytestream_put_le32(&bs, avctx->height);
78 + bytestream_put_le32(&bs, avctx->width);
79 + bytestream_put_le32(&bs, 0xC);
80 + bytestream_put_le24(&bs, 0); // hrd_buffer
81 + bytestream_put_byte(&bs, 0x80); // level|cbr|res1
82 + bytestream_put_le32(&bs, 0); // hrd_rate
83 +
84 + // The following LE32 describes the frame rate. Since we don't care so fill
85 + // it with 0xFFFFFFFF which means variable framerate.
86 + // See: libavformat/vc1testenc.c
87 + bytestream_put_le32(&bs, 0xFFFFFFFF);
88 + } else {
89 + *poutbuf = av_malloc(RCV_PICTURE_HEADER_SIZE + buf_size);
90 + *poutbuf_size = RCV_PICTURE_HEADER_SIZE + buf_size;
91 + bs = *poutbuf;
92 + }
93 +
94 + // Write the picture header.
95 + bytestream_put_le32(&bs, buf_size | (keyframe ? 0x80000000 : 0));
96 +
97 + // The following LE32 describes the pts. Since we don't care so fill it wi th 0.
98 + bytestream_put_le32(&bs, 0);
99 + memcpy(bs, buf, buf_size);
100 +
101 + ++ctx->frames;
102 + return 0;
103 +}
104 +
105 +AVBitStreamFilter vc1_asftorcv_bsf = {
106 + "vc1_asftorcv",
107 + sizeof(ASFTORCVBSFContext),
108 + asftorcv_filter,
109 +};
110 Index: patched-ffmpeg-mt/libavcodec/vc1_asftoannexg_bsf.c
111 ===================================================================
112 --- patched-ffmpeg-mt/libavcodec/vc1_asftoannexg_bsf.c (revision 0)
113 +++ patched-ffmpeg-mt/libavcodec/vc1_asftoannexg_bsf.c (revision 0)
114 @@ -0,0 +1,182 @@
115 +/*
116 + * copyright (c) 2010 Google Inc.
117 + *
118 + * This file is part of FFmpeg.
119 + *
120 + * FFmpeg is free software; you can redistribute it and/or
121 + * modify it under the terms of the GNU Lesser General Public
122 + * License as published by the Free Software Foundation; either
123 + * version 2.1 of the License, or (at your option) any later version.
124 + *
125 + * FFmpeg is distributed in the hope that it will be useful,
126 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
127 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
128 + * Lesser General Public License for more details.
129 + *
130 + * You should have received a copy of the GNU Lesser General Public
131 + * License along with FFmpeg; if not, write to the Free Software
132 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
133 + */
134 +
135 +#include "avcodec.h"
136 +#include "bytestream.h"
137 +#include "vc1.h"
138 +
139 +// An arbitrary limit in bytes greater than the current bytes used.
140 +#define MAX_SEQ_HEADER_SIZE 50
141 +
142 +typedef struct ASFTOANNEXGBSFContext {
143 + int frames;
144 + uint8_t *seq_header;
145 + int seq_header_size;
146 + uint8_t *ep_header;
147 + int ep_header_size;
148 +} ASFTOANNEXGBSFContext;
149 +
150 +static int generate_sequence_header(VC1Context *v, ASFTOANNEXGBSFContext *ctx)
151 +{
152 + PutBitContext pb;
153 + ctx->seq_header = av_mallocz(MAX_SEQ_HEADER_SIZE);
154 + init_put_bits(&pb, ctx->seq_header, MAX_SEQ_HEADER_SIZE);
155 +
156 + put_bits(&pb, 32, VC1_CODE_SEQHDR); // start code
157 + put_bits(&pb, 2, PROFILE_ADVANCED); // profile
158 + put_bits(&pb, 3, v->level); // level
159 + put_bits(&pb, 2, v->chromaformat); // chromaformat
160 + put_bits(&pb, 3, v->frmrtq_postproc); // frmrtq postproc
161 + put_bits(&pb, 5, v->bitrtq_postproc); // bitrtq postproc
162 + put_bits(&pb, 1, v->postprocflag); // post proc flag
163 + put_bits(&pb, 12, (v->s.avctx->coded_width >> 1) - 1); // codec width
164 + put_bits(&pb, 12, (v->s.avctx->coded_height >> 1) - 1); // codec height
165 + put_bits(&pb, 1, v->broadcast); // broadcast
166 + put_bits(&pb, 1, v->interlace); // interlace
167 + put_bits(&pb, 1, v->tfcntrflag); // tfcntrflag
168 + put_bits(&pb, 1, v->finterpflag); // finterpflag
169 + put_bits(&pb, 1, 1); // reserved
170 + put_bits(&pb, 1, v->psf); // progressive segmented frame mode
171 + put_bits(&pb, 1, 1); // has display info
172 + put_bits(&pb, 14, v->s.avctx->width - 1); // width
173 + put_bits(&pb, 14, v->s.avctx->height - 1); // height
174 + put_bits(&pb, 1, 0); // no aspect ratio
175 + put_bits(&pb, 1, 1); // frame rate
176 + put_bits(&pb, 8, 3); // fake it to be 30fps, see vc1.c an d vc1data.c
177 + put_bits(&pb, 4, 1); // fake dr to be 1000, see vc1.c and vc1data.c
178 + put_bits(&pb, 1, 0); // no color info
179 + put_bits(&pb, 1, 0); // no hrd param
180 +
181 + align_put_bits(&pb);
182 + ctx->seq_header_size = (put_bits_count(&pb) + 7) >> 3;
183 + return 0;
184 +}
185 +
186 +static int decode_sequence_header(AVCodecContext *avctx, VC1Context *v, uint8_t *header, int header_size) {
187 + GetBitContext gb;
188 + uint8_t *buf = av_mallocz(header_size + FF_INPUT_BUFFER_PADDING_SIZE);
189 + int buf_size = vc1_unescape_buffer(header + 4, header_size - 4, buf);
190 + int ret;
191 + init_get_bits(&gb, buf, buf_size * 8);
192 + ret = vc1_decode_sequence_header(avctx, v, &gb);
193 + av_free(buf);
194 + return ret;
195 +}
196 +
197 +static int parse_extradata(AVCodecContext *avctx, ASFTOANNEXGBSFContext *ctx, u int8_t *extradata, int extradata_size) {
198 + const uint8_t *start = extradata;
199 + const uint8_t *end = extradata + extradata_size;
200 + const uint8_t *next;
201 + VC1Context vc1ctx;
202 + int size;
203 + int seq_ret;
204 +
205 + if(extradata_size < 16) {
206 + av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", extradata _size);
207 + return -1;
208 + }
209 +
210 + start = find_next_marker(start, end);
211 + next = start;
212 + for(; next < end; start = next){
213 + next = find_next_marker(start + 4, end);
214 + size = next - start;
215 + if(size <= 0) continue;
216 + switch(AV_RB32(start)){
217 + case VC1_CODE_SEQHDR:
218 + memset(&vc1ctx, 0, sizeof(VC1Context));
219 + vc1ctx.profile = PROFILE_ADVANCED;
220 + vc1ctx.s.avctx = avctx;
221 +
222 + seq_ret = decode_sequence_header(avctx, &vc1ctx, start, size) < 0 | |
223 + generate_sequence_header(&vc1ctx, ctx) < 0;
224 + if (seq_ret) {
225 + av_log(avctx, AV_LOG_ERROR, "Cannot regenerate sequence header\ n");
226 + return -1;
227 + }
228 + break;
229 + case VC1_CODE_ENTRYPOINT:
230 + ctx->ep_header = av_malloc(size);
231 + ctx->ep_header_size = size;
232 + memcpy(ctx->ep_header, start, size);
233 + break;
234 + default:
235 + break;
236 + }
237 + }
238 +
239 + if(!ctx->seq_header || !ctx->ep_header) {
240 + av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
241 + return -1;
242 + }
243 + return 0;
244 +}
245 +
246 +static int asftoannexg_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *a vctx, const char *args,
247 + uint8_t **poutbuf, int *poutbuf_size,
248 + const uint8_t *buf, int buf_size, int keyframe){
249 + ASFTOANNEXGBSFContext* ctx = (ASFTOANNEXGBSFContext*)bsfc->priv_data;
250 +
251 + if (avctx->codec_id != CODEC_ID_VC1) {
252 + av_log(avctx, AV_LOG_ERROR, "Only VC1 Advanced profile is accepted!\n") ;
253 + return -1;
254 + }
255 +
256 + if (!ctx->frames && parse_extradata(avctx, ctx, avctx->extradata, avctx->ex tradata_size) < 0) {
257 + av_log(avctx, AV_LOG_ERROR, "Cannot parse extra data!\n");
258 + return -1;
259 + }
260 +
261 + uint8_t* bs;
262 + if (keyframe) {
263 + // If this is the keyframe, need to put sequence header and entry point header.
264 + *poutbuf_size = ctx->seq_header_size + ctx->ep_header_size + 4 + buf_si ze;
265 + *poutbuf = av_malloc(*poutbuf_size);
266 + bs = *poutbuf;
267 +
268 + memcpy(bs, ctx->seq_header, ctx->seq_header_size);
269 + bs += ctx->seq_header_size;
270 + memcpy(bs, ctx->ep_header, ctx->ep_header_size);
271 + bs += ctx->ep_header_size;
272 + } else {
273 + *poutbuf_size = 4 + buf_size;
274 + *poutbuf = av_malloc(*poutbuf_size);
275 + bs = *poutbuf;
276 + }
277 +
278 + // Put the frame start code and frame data.
279 + bytestream_put_be32(&bs, VC1_CODE_FRAME);
280 + memcpy(bs, buf, buf_size);
281 + ++ctx->frames;
282 + return 0;
283 +}
284 +
285 +static void asftoannexg_close(AVBitStreamFilterContext *bsfc) {
286 + ASFTOANNEXGBSFContext *ctx = bsfc->priv_data;
287 + av_freep(&ctx->seq_header);
288 + av_freep(&ctx->ep_header);
289 +}
290 +
291 +AVBitStreamFilter vc1_asftoannexg_bsf = {
292 + "vc1_asftoannexg",
293 + sizeof(ASFTOANNEXGBSFContext),
294 + asftoannexg_filter,
295 + asftoannexg_close,
296 +};
297 Index: patched-ffmpeg-mt/libavcodec/Makefile
298 ===================================================================
299 --- patched-ffmpeg-mt/libavcodec/Makefile (revision 39951)
300 +++ patched-ffmpeg-mt/libavcodec/Makefile (working copy)
301 @@ -536,6 +536,9 @@
302 OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o
303 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o
304 OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o
305 +OBJS-$(CONFIG_VC1_ASFTORCV_BSF) += vc1_asftorcv_bsf.o
306 +OBJS-$(CONFIG_VC1_ASFTOANNEXG_BSF) += vc1_asftoannexg_bsf.o vc1.o \
307 + vc1data.o
308 63
309 # thread libraries 64 int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb);
310 OBJS-$(HAVE_BEOSTHREADS) += beosthread.o 65 Only in ffmpeg-mt/libavcodec: mpeg4video.h~
66 Only in ffmpeg-mt/libavcodec: mpeg4video_es_bsf.c
67 diff -rpu unpatched_ffmpeg-mt/libavcodec/mpeg4videoenc.c ffmpeg-mt/libavcodec/mp eg4videoenc.c
68 --- unpatched_ffmpeg-mt/libavcodec/mpeg4videoenc.c» 2010-03-11 17:46:30 -080 0
69 +++ ffmpeg-mt/libavcodec/mpeg4videoenc.c» 2010-03-11 19:12:02 -0800
70 @@ -872,7 +872,7 @@ void ff_set_mpeg4_time(MpegEncContext *
71 }
72 }
73
74 -static void mpeg4_encode_gop_header(MpegEncContext * s){
75 +void mpeg4_encode_gop_header(MpegEncContext * s){
76 int hours, minutes, seconds;
77 int64_t time;
78
79 @@ -902,7 +902,7 @@ static void mpeg4_encode_gop_header(Mpeg
80 ff_mpeg4_stuffing(&s->pb);
81 }
82
83 -static void mpeg4_encode_visual_object_header(MpegEncContext * s){
84 +void mpeg4_encode_visual_object_header(MpegEncContext * s){
85 int profile_and_level_indication;
86 int vo_ver_id;
87
88 @@ -947,7 +947,7 @@ static void mpeg4_encode_visual_object_h
89 ff_mpeg4_stuffing(&s->pb);
90 }
91
92 -static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_ number)
93 +void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number)
94 {
95 int vo_ver_id;
96
97 Only in ffmpeg-mt/libavcodec: vc1_asftoannexg_bsf.c
98 Only in ffmpeg-mt/libavcodec: vc1_asftorcv_bsf.c
99 diff -rpu unpatched_ffmpeg-mt/libavformat/mov.c ffmpeg-mt/libavformat/mov.c
100 --- unpatched_ffmpeg-mt/libavformat/mov.c» 2010-03-11 17:46:31 -0800
101 +++ ffmpeg-mt/libavformat/mov.c»2010-03-11 19:08:40 -0800
102 @@ -312,6 +312,8 @@ static int mov_read_dref(MOVContext *c,
103 MOVDref *dref = &sc->drefs[i];
104 uint32_t size = get_be32(pb);
105 int64_t next = url_ftell(pb) + size - 4;
106 + if (size < 8)
107 + return -1;
108
109 dref->type = get_le32(pb);
110 get_be32(pb); // version + flags
111 Only in ffmpeg-mt/libavformat: mov.c~
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698