00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avcodec.h"
00028 #include "mjpeg.h"
00029 #include "mjpegdec.h"
00030 #include "sp5x.h"
00031
00032
00033 static int sp5x_decode_frame(AVCodecContext *avctx,
00034 void *data, int *data_size,
00035 AVPacket *avpkt)
00036 {
00037 const uint8_t *buf = avpkt->data;
00038 int buf_size = avpkt->size;
00039 AVPacket avpkt_recoded;
00040 const int qscale = 5;
00041 const uint8_t *buf_ptr;
00042 uint8_t *recoded;
00043 int i = 0, j = 0;
00044
00045 if (!avctx->width || !avctx->height)
00046 return -1;
00047
00048 buf_ptr = buf;
00049
00050 recoded = av_mallocz(buf_size + 1024);
00051 if (!recoded)
00052 return -1;
00053
00054
00055 recoded[j++] = 0xFF;
00056 recoded[j++] = 0xD8;
00057
00058 memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
00059 memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
00060 memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
00061 j += sizeof(sp5x_data_dqt);
00062
00063 memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
00064 j += sizeof(sp5x_data_dht);
00065
00066 memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
00067 AV_WB16(recoded+j+5, avctx->coded_height);
00068 AV_WB16(recoded+j+7, avctx->coded_width);
00069 j += sizeof(sp5x_data_sof);
00070
00071 memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
00072 j += sizeof(sp5x_data_sos);
00073
00074 if(avctx->codec_id==CODEC_ID_AMV)
00075 for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
00076 recoded[j++] = buf[i];
00077 else
00078 for (i = 14; i < buf_size && j < buf_size+1024-2; i++)
00079 {
00080 recoded[j++] = buf[i];
00081 if (buf[i] == 0xff)
00082 recoded[j++] = 0;
00083 }
00084
00085
00086 recoded[j++] = 0xFF;
00087 recoded[j++] = 0xD9;
00088
00089 avctx->flags &= ~CODEC_FLAG_EMU_EDGE;
00090 av_init_packet(&avpkt_recoded);
00091 avpkt_recoded.data = recoded;
00092 avpkt_recoded.size = j;
00093 i = ff_mjpeg_decode_frame(avctx, data, data_size, &avpkt_recoded);
00094
00095 av_free(recoded);
00096
00097 return i;
00098 }
00099
00100 AVCodec ff_sp5x_decoder = {
00101 "sp5x",
00102 AVMEDIA_TYPE_VIDEO,
00103 CODEC_ID_SP5X,
00104 sizeof(MJpegDecodeContext),
00105 ff_mjpeg_decode_init,
00106 NULL,
00107 ff_mjpeg_decode_end,
00108 sp5x_decode_frame,
00109 CODEC_CAP_DR1,
00110 NULL,
00111 .max_lowres = 5,
00112 .long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"),
00113 };
00114
00115 AVCodec ff_amv_decoder = {
00116 "amv",
00117 AVMEDIA_TYPE_VIDEO,
00118 CODEC_ID_AMV,
00119 sizeof(MJpegDecodeContext),
00120 ff_mjpeg_decode_init,
00121 NULL,
00122 ff_mjpeg_decode_end,
00123 sp5x_decode_frame,
00124 CODEC_CAP_DR1,
00125 .long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
00126 };