annotate mjpega_dump_header_bsf.c @ 12123:750962dae4c9 libavcodec

Change qmax/qmin limits to 63 instead of 51. VP8 supports quantizers up to 63.
author darkshikari
date Sat, 10 Jul 2010 06:34:57 +0000
parents 7dd2a45249a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5039
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
1 /*
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
2 * MJPEG A dump header bitstream filter
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 8612
diff changeset
3 * Copyright (c) 2006 Baptiste Coudurier
5039
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
4 *
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
5 * This file is part of FFmpeg.
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
6 *
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
11 *
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
16 *
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
20 */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
21
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 8718
diff changeset
23 * @file
5039
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
24 * MJPEG A dump header bitstream filter
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
25 * modifies bitstream to be decoded by quicktime
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
26 */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
27
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
28 #include "avcodec.h"
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
29 #include "bytestream.h"
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
30 #include "mjpeg.h"
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
31
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
32
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
33 static int mjpega_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
34 uint8_t **poutbuf, int *poutbuf_size,
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
35 const uint8_t *buf, int buf_size, int keyframe)
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
36 {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
37 uint8_t *poutbufp;
8305
1408a8907da9 fix mjpega bitfilter when dht, dqt, sof0 are not ordered as expected, patch by Jay Freeman, saurik at saurik com
bcoudurier
parents: 5039
diff changeset
38 unsigned dqt = 0, dht = 0, sof0 = 0;
5039
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
39 int i;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
40
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
41 if (avctx->codec_id != CODEC_ID_MJPEG) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
42 av_log(avctx, AV_LOG_ERROR, "mjpega bitstream filter only applies to mjpeg codec\n");
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
43 return 0;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
44 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
45
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
46 *poutbuf_size = 0;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
47 *poutbuf = av_malloc(buf_size + 44 + FF_INPUT_BUFFER_PADDING_SIZE);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
48 poutbufp = *poutbuf;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
49 bytestream_put_byte(&poutbufp, 0xff);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
50 bytestream_put_byte(&poutbufp, SOI);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
51 bytestream_put_byte(&poutbufp, 0xff);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
52 bytestream_put_byte(&poutbufp, APP1);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
53 bytestream_put_be16(&poutbufp, 42); /* size */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
54 bytestream_put_be32(&poutbufp, 0);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
55 bytestream_put_buffer(&poutbufp, "mjpg", 4);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
56 bytestream_put_be32(&poutbufp, buf_size + 44); /* field size */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
57 bytestream_put_be32(&poutbufp, buf_size + 44); /* pad field size */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
58 bytestream_put_be32(&poutbufp, 0); /* next ptr */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
59
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
60 for (i = 0; i < buf_size - 1; i++) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
61 if (buf[i] == 0xff) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
62 switch (buf[i + 1]) {
8305
1408a8907da9 fix mjpega bitfilter when dht, dqt, sof0 are not ordered as expected, patch by Jay Freeman, saurik at saurik com
bcoudurier
parents: 5039
diff changeset
63 case DQT: dqt = i + 46; break;
1408a8907da9 fix mjpega bitfilter when dht, dqt, sof0 are not ordered as expected, patch by Jay Freeman, saurik at saurik com
bcoudurier
parents: 5039
diff changeset
64 case DHT: dht = i + 46; break;
1408a8907da9 fix mjpega bitfilter when dht, dqt, sof0 are not ordered as expected, patch by Jay Freeman, saurik at saurik com
bcoudurier
parents: 5039
diff changeset
65 case SOF0: sof0 = i + 46; break;
5039
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
66 case SOS:
8305
1408a8907da9 fix mjpega bitfilter when dht, dqt, sof0 are not ordered as expected, patch by Jay Freeman, saurik at saurik com
bcoudurier
parents: 5039
diff changeset
67 bytestream_put_be32(&poutbufp, dqt); /* quant off */
1408a8907da9 fix mjpega bitfilter when dht, dqt, sof0 are not ordered as expected, patch by Jay Freeman, saurik at saurik com
bcoudurier
parents: 5039
diff changeset
68 bytestream_put_be32(&poutbufp, dht); /* huff off */
1408a8907da9 fix mjpega bitfilter when dht, dqt, sof0 are not ordered as expected, patch by Jay Freeman, saurik at saurik com
bcoudurier
parents: 5039
diff changeset
69 bytestream_put_be32(&poutbufp, sof0); /* image off */
5039
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
70 bytestream_put_be32(&poutbufp, i + 46); /* scan off */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
71 bytestream_put_be32(&poutbufp, i + 46 + AV_RB16(buf + i + 2)); /* data off */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
72 bytestream_put_buffer(&poutbufp, buf + 2, buf_size - 2); /* skip already written SOI */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
73 *poutbuf_size = poutbufp - *poutbuf;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
74 return 1;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
75 case APP1:
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 8305
diff changeset
76 if (i + 8 < buf_size && AV_RL32(buf + i + 8) == AV_RL32("mjpg")) {
5039
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
77 av_log(avctx, AV_LOG_ERROR, "bitstream already formatted\n");
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
78 memcpy(*poutbuf, buf, buf_size);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
79 *poutbuf_size = buf_size;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
80 return 1;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
81 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
82 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
83 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
84 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
85 av_freep(poutbuf);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
86 av_log(avctx, AV_LOG_ERROR, "could not find SOS marker in bitstream\n");
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
87 return 0;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
88 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
89
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
90 AVBitStreamFilter mjpega_dump_header_bsf = {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
91 "mjpegadump",
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
92 0,
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
93 mjpega_dump_header,
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
94 };