annotate mjpega_dump_header_bsf.c @ 7909:9fd3f57e4c16 libavcodec

Add support for 1-bit, 4-bit, 8-bit and some 16-bit raw BMP
author kostya
date Tue, 23 Sep 2008 08:38:32 +0000
parents 325557621708
children 1408a8907da9
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
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
3 * Copyright (c) 2006 Baptiste Coudurier.
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 /**
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
23 * @file mjpega_dump_header_bsf.c
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;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
38 int i;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
39
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
40 if (avctx->codec_id != CODEC_ID_MJPEG) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
41 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
42 return 0;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
43 }
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 *poutbuf_size = 0;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
46 *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
47 poutbufp = *poutbuf;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
48 bytestream_put_byte(&poutbufp, 0xff);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
49 bytestream_put_byte(&poutbufp, SOI);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
50 bytestream_put_byte(&poutbufp, 0xff);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
51 bytestream_put_byte(&poutbufp, APP1);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
52 bytestream_put_be16(&poutbufp, 42); /* size */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
53 bytestream_put_be32(&poutbufp, 0);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
54 bytestream_put_buffer(&poutbufp, "mjpg", 4);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
55 bytestream_put_be32(&poutbufp, buf_size + 44); /* field size */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
56 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
57 bytestream_put_be32(&poutbufp, 0); /* next ptr */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
58
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
59 for (i = 0; i < buf_size - 1; i++) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
60 if (buf[i] == 0xff) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
61 switch (buf[i + 1]) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
62 case DQT: /* quant off */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
63 case DHT: /* huff off */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
64 case SOF0: /* image off */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
65 bytestream_put_be32(&poutbufp, i + 46);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
66 break;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
67 case SOS:
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
68 bytestream_put_be32(&poutbufp, i + 46); /* scan off */
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
69 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
70 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
71 *poutbuf_size = poutbufp - *poutbuf;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
72 return 1;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
73 case APP1:
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
74 if (i + 8 < buf_size && AV_RL32(buf + i + 8) == ff_get_fourcc("mjpg")) {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
75 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
76 memcpy(*poutbuf, buf, buf_size);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
77 *poutbuf_size = buf_size;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
78 return 1;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
79 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
80 }
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 av_freep(poutbuf);
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
84 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
85 return 0;
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
86 }
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
87
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
88 AVBitStreamFilter mjpega_dump_header_bsf = {
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
89 "mjpegadump",
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
90 0,
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
91 mjpega_dump_header,
325557621708 move mjpega_dump_header bitstream filter in its own file
aurel
parents:
diff changeset
92 };