summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/mjpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libffmpeg/libavcodec/mjpeg.c')
-rw-r--r--src/libffmpeg/libavcodec/mjpeg.c160
1 files changed, 82 insertions, 78 deletions
diff --git a/src/libffmpeg/libavcodec/mjpeg.c b/src/libffmpeg/libavcodec/mjpeg.c
index 8df477afa..135066796 100644
--- a/src/libffmpeg/libavcodec/mjpeg.c
+++ b/src/libffmpeg/libavcodec/mjpeg.c
@@ -20,26 +20,31 @@
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi <alex@naxine.org>
*/
+
+/**
+ * @file mjpeg.c
+ * MJPEG encoder and decoder.
+ */
+
//#define DEBUG
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
-#include "xineutils.h"
/* use two quantizer tables (one for luminance and one for chrominance) */
/* not yet working */
#undef TWOMATRIXES
typedef struct MJpegContext {
- UINT8 huff_size_dc_luminance[12];
- UINT16 huff_code_dc_luminance[12];
- UINT8 huff_size_dc_chrominance[12];
- UINT16 huff_code_dc_chrominance[12];
-
- UINT8 huff_size_ac_luminance[256];
- UINT16 huff_code_ac_luminance[256];
- UINT8 huff_size_ac_chrominance[256];
- UINT16 huff_code_ac_chrominance[256];
+ uint8_t huff_size_dc_luminance[12];
+ uint16_t huff_code_dc_luminance[12];
+ uint8_t huff_size_dc_chrominance[12];
+ uint16_t huff_code_dc_chrominance[12];
+
+ uint8_t huff_size_ac_luminance[256];
+ uint16_t huff_code_ac_luminance[256];
+ uint8_t huff_size_ac_chrominance[256];
+ uint16_t huff_code_ac_chrominance[256];
} MJpegContext;
/* JPEG marker codes */
@@ -153,19 +158,19 @@ static const unsigned char std_chrominance_quant_tbl[64] = {
/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
/* IMPORTANT: these are only valid for 8-bit data precision! */
-static const UINT8 bits_dc_luminance[17] =
+static const uint8_t bits_dc_luminance[17] =
{ /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
-static const UINT8 val_dc_luminance[] =
+static const uint8_t val_dc_luminance[] =
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-static const UINT8 bits_dc_chrominance[17] =
+static const uint8_t bits_dc_chrominance[17] =
{ /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
-static const UINT8 val_dc_chrominance[] =
+static const uint8_t val_dc_chrominance[] =
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-static const UINT8 bits_ac_luminance[17] =
+static const uint8_t bits_ac_luminance[17] =
{ /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
-static const UINT8 val_ac_luminance[] =
+static const uint8_t val_ac_luminance[] =
{ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
@@ -189,10 +194,10 @@ static const UINT8 val_ac_luminance[] =
0xf9, 0xfa
};
-static const UINT8 bits_ac_chrominance[17] =
+static const uint8_t bits_ac_chrominance[17] =
{ /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
-static const UINT8 val_ac_chrominance[] =
+static const uint8_t val_ac_chrominance[] =
{ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
@@ -217,8 +222,8 @@ static const UINT8 val_ac_chrominance[] =
};
/* isn't this function nicer than the one in the libjpeg ? */
-static void build_huffman_codes(UINT8 *huff_size, UINT16 *huff_code,
- const UINT8 *bits_table, const UINT8 *val_table)
+static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
+ const uint8_t *bits_table, const uint8_t *val_table)
{
int i, j, k,nb, code, sym;
@@ -246,7 +251,6 @@ int mjpeg_init(MpegEncContext *s)
s->min_qcoeff=-1023;
s->max_qcoeff= 1023;
- s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x
/* build all the huffman tables */
build_huffman_codes(m->huff_size_dc_luminance,
@@ -283,7 +287,7 @@ static inline void put_marker(PutBitContext *p, int code)
/* table_class: 0 = DC coef, 1 = AC coefs */
static int put_huffman_table(MpegEncContext *s, int table_class, int table_id,
- const UINT8 *bits_table, const UINT8 *value_table)
+ const uint8_t *bits_table, const uint8_t *value_table)
{
PutBitContext *p = &s->pb;
int n, i;
@@ -307,7 +311,7 @@ static void jpeg_table_header(MpegEncContext *s)
{
PutBitContext *p = &s->pb;
int i, j, size;
- UINT8 *ptr;
+ uint8_t *ptr;
/* quant matrixes */
put_marker(p, DQT);
@@ -350,7 +354,7 @@ static void jpeg_put_comments(MpegEncContext *s)
{
PutBitContext *p = &s->pb;
int size;
- UINT8 *ptr;
+ uint8_t *ptr;
if (s->aspect_ratio_info)
{
@@ -387,15 +391,13 @@ static void jpeg_put_comments(MpegEncContext *s)
}
/* comment */
- if(!ff_bit_exact){
+ if(!(s->flags & CODEC_FLAG_BITEXACT)){
put_marker(p, COM);
flush_put_bits(p);
ptr = pbBufPtr(p);
put_bits(p, 16, 0); /* patched later */
-#define MJPEG_VERSION "FFmpeg" LIBAVCODEC_VERSION "b" LIBAVCODEC_BUILD_STR
- put_string(p, MJPEG_VERSION);
- size = strlen(MJPEG_VERSION)+3;
-#undef MJPEG_VERSION
+ put_string(p, LIBAVCODEC_IDENT);
+ size = strlen(LIBAVCODEC_IDENT)+3;
ptr[0] = size >> 8;
ptr[1] = size;
}
@@ -478,7 +480,7 @@ static void escape_FF(MpegEncContext *s, int start)
uint8_t *buf= s->pb.buf + start;
int align= (-(int)(buf))&3;
- XINE_ASSERT((size&7) == 0,"?");
+ assert((size&7) == 0);
size >>= 3;
ff_count=0;
@@ -534,7 +536,7 @@ void mjpeg_picture_trailer(MpegEncContext *s)
put_bits(&s->pb, pad,0xFF>>(8-pad));
flush_put_bits(&s->pb);
- XINE_ASSERT((s->header_bits&7)==0, "?");
+ assert((s->header_bits&7)==0);
escape_FF(s, s->header_bits>>3);
@@ -542,7 +544,7 @@ void mjpeg_picture_trailer(MpegEncContext *s)
}
static inline void mjpeg_encode_dc(MpegEncContext *s, int val,
- UINT8 *huff_size, UINT16 *huff_code)
+ uint8_t *huff_size, uint16_t *huff_code)
{
int mant, nbits;
@@ -573,8 +575,8 @@ static void encode_block(MpegEncContext *s, DCTELEM *block, int n)
int mant, nbits, code, i, j;
int component, dc, run, last_index, val;
MJpegContext *m = s->mjpeg_ctx;
- UINT8 *huff_size_ac;
- UINT16 *huff_code_ac;
+ uint8_t *huff_size_ac;
+ uint16_t *huff_code_ac;
/* DC coef */
component = (n <= 3 ? 0 : n - 4 + 1);
@@ -652,9 +654,9 @@ typedef struct MJpegDecodeContext {
int start_code; /* current start code */
int buffer_size;
- UINT8 *buffer;
+ uint8_t *buffer;
- INT16 quant_matrixes[4][64];
+ int16_t quant_matrixes[4][64];
VLC vlcs[2][4];
int org_width, org_height; /* size given at codec init */
@@ -670,11 +672,11 @@ typedef struct MJpegDecodeContext {
int h_max, v_max; /* maximum h and v counts */
int quant_index[4]; /* quant table index for each component */
int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
- UINT8 *current_picture[MAX_COMPONENTS]; /* picture structure */
+ uint8_t *current_picture[MAX_COMPONENTS]; /* picture structure */
int linesize[MAX_COMPONENTS];
DCTELEM block[64] __align8;
ScanTable scantable;
- void (*idct_put)(UINT8 *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
+ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
int restart_interval;
int restart_count;
@@ -685,11 +687,11 @@ typedef struct MJpegDecodeContext {
static int mjpeg_decode_dht(MJpegDecodeContext *s);
-static void build_vlc(VLC *vlc, const UINT8 *bits_table, const UINT8 *val_table,
+static void build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
int nb_codes)
{
- UINT8 huff_size[256];
- UINT16 huff_code[256];
+ uint8_t huff_size[256];
+ uint16_t huff_code[256];
memset(huff_size, 0, sizeof(huff_size));
build_huffman_codes(huff_size, huff_code, bits_table, val_table);
@@ -704,7 +706,7 @@ static int mjpeg_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
- /* ugly way to get the idct & scantable */
+ /* ugly way to get the idct & scantable FIXME */
memset(&s2, 0, sizeof(MpegEncContext));
s2.flags= avctx->flags;
s2.avctx= avctx;
@@ -714,7 +716,7 @@ static int mjpeg_decode_init(AVCodecContext *avctx)
if (MPV_common_init(&s2) < 0)
return -1;
s->scantable= s2.intra_scantable;
- s->idct_put= s2.idct_put;
+ s->idct_put= s2.dsp.idct_put;
MPV_common_end(&s2);
s->mpeg_enc_ctx_allocated = 0;
@@ -777,8 +779,8 @@ static int mjpeg_decode_dqt(MJpegDecodeContext *s)
static int mjpeg_decode_dht(MJpegDecodeContext *s)
{
int len, index, i, class, n, v, code_max;
- UINT8 bits_table[17];
- UINT8 val_table[256];
+ uint8_t bits_table[17];
+ uint8_t val_table[256];
len = get_bits(&s->gb, 16) - 2;
@@ -929,7 +931,7 @@ static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
int nbits, code, i, j, level;
int run, val;
VLC *ac_vlc;
- INT16 *quant_matrix;
+ int16_t *quant_matrix;
/* DC coef */
val = mjpeg_decode_dc(s, dc_index);
@@ -1072,7 +1074,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
for(mb_y = 0; mb_y < mb_height; mb_y++) {
for(mb_x = 0; mb_x < mb_width; mb_x++) {
for(i=0;i<nb_components;i++) {
- UINT8 *ptr;
+ uint8_t *ptr;
int x, y, c;
n = nb_blocks[i];
c = comp_index[i];
@@ -1263,31 +1265,33 @@ out:
static int mjpeg_decode_com(MJpegDecodeContext *s)
{
- int len, i;
- UINT8 *cbuf;
-
/* XXX: verify len field validity */
- len = get_bits(&s->gb, 16)-2;
- cbuf = av_malloc(len+1);
-
- for (i = 0; i < len; i++)
- cbuf[i] = get_bits(&s->gb, 8);
- if (cbuf[i-1] == '\n')
- cbuf[i-1] = 0;
- else
- cbuf[i] = 0;
-
- printf("mjpeg comment: '%s'\n", cbuf);
+ unsigned int len = get_bits(&s->gb, 16);
+ if (len >= 2 && len < 32768) {
+ /* XXX: any better upper bound */
+ uint8_t *cbuf = av_malloc(len - 1);
+ if (cbuf) {
+ int i;
+ for (i = 0; i < len - 2; i++)
+ cbuf[i] = get_bits(&s->gb, 8);
+ if (i > 0 && cbuf[i-1] == '\n')
+ cbuf[i-1] = 0;
+ else
+ cbuf[i] = 0;
+
+ printf("mjpeg comment: '%s'\n", cbuf);
+
+ /* buggy avid, it puts EOI only at every 10th frame */
+ if (!strcmp(cbuf, "AVID"))
+ {
+ s->buggy_avid = 1;
+ // if (s->first_picture)
+ // printf("mjpeg: workarounding buggy AVID\n");
+ }
- /* buggy avid, it puts EOI only at every 10th frame */
- if (!strcmp(cbuf, "AVID"))
- {
- s->buggy_avid = 1;
-// if (s->first_picture)
-// printf("mjpeg: workarounding buggy AVID\n");
+ av_free(cbuf);
+ }
}
-
- av_free(cbuf);
return 0;
}
@@ -1317,9 +1321,9 @@ static int valid_marker_list[] =
/* return the 8 bit start code value and update the search
state. Return -1 if no start code found */
-static int find_marker(UINT8 **pbuf_ptr, UINT8 *buf_end)
+static int find_marker(uint8_t **pbuf_ptr, uint8_t *buf_end)
{
- UINT8 *buf_ptr;
+ uint8_t *buf_ptr;
unsigned int v, v2;
int val;
#ifdef DEBUG
@@ -1349,10 +1353,10 @@ found:
static int mjpeg_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- UINT8 *buf, int buf_size)
+ uint8_t *buf, int buf_size)
{
MJpegDecodeContext *s = avctx->priv_data;
- UINT8 *buf_end, *buf_ptr;
+ uint8_t *buf_end, *buf_ptr;
int i, start_code;
AVPicture *picture = data;
@@ -1386,12 +1390,12 @@ static int mjpeg_decode_frame(AVCodecContext *avctx,
/* unescape buffer of SOS */
if (start_code == SOS)
{
- UINT8 *src = buf_ptr;
- UINT8 *dst = s->buffer;
+ uint8_t *src = buf_ptr;
+ uint8_t *dst = s->buffer;
while (src<buf_end)
{
- UINT8 x = *(src++);
+ uint8_t x = *(src++);
*(dst++) = x;
if (x == 0xff)
@@ -1526,10 +1530,10 @@ the_end:
static int mjpegb_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- UINT8 *buf, int buf_size)
+ uint8_t *buf, int buf_size)
{
MJpegDecodeContext *s = avctx->priv_data;
- UINT8 *buf_end, *buf_ptr;
+ uint8_t *buf_end, *buf_ptr;
int i;
AVPicture *picture = data;
GetBitContext hgb; /* for the header */