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 uint8_t *recoded;
00042 int i = 0, j = 0;
00043
00044 if (!avctx->width || !avctx->height)
00045 return -1;
00046
00047 recoded = av_mallocz(buf_size + 1024);
00048 if (!recoded)
00049 return -1;
00050
00051
00052 recoded[j++] = 0xFF;
00053 recoded[j++] = 0xD8;
00054
00055 memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
00056 memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
00057 memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
00058 j += sizeof(sp5x_data_dqt);
00059
00060 memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
00061 j += sizeof(sp5x_data_dht);
00062
00063 memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
00064 AV_WB16(recoded+j+5, avctx->coded_height);
00065 AV_WB16(recoded+j+7, avctx->coded_width);
00066 j += sizeof(sp5x_data_sof);
00067
00068 memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
00069 j += sizeof(sp5x_data_sos);
00070
00071 if(avctx->codec_id==AV_CODEC_ID_AMV)
00072 for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
00073 recoded[j++] = buf[i];
00074 else
00075 for (i = 14; i < buf_size && j < buf_size+1024-3; i++)
00076 {
00077 recoded[j++] = buf[i];
00078 if (buf[i] == 0xff)
00079 recoded[j++] = 0;
00080 }
00081
00082
00083 recoded[j++] = 0xFF;
00084 recoded[j++] = 0xD9;
00085
00086 av_init_packet(&avpkt_recoded);
00087 avpkt_recoded.data = recoded;
00088 avpkt_recoded.size = j;
00089 i = ff_mjpeg_decode_frame(avctx, data, data_size, &avpkt_recoded);
00090
00091 av_free(recoded);
00092
00093 return i < 0 ? i : avpkt->size;
00094 }
00095
00096 #if CONFIG_SP5X_DECODER
00097 AVCodec ff_sp5x_decoder = {
00098 .name = "sp5x",
00099 .type = AVMEDIA_TYPE_VIDEO,
00100 .id = AV_CODEC_ID_SP5X,
00101 .priv_data_size = sizeof(MJpegDecodeContext),
00102 .init = ff_mjpeg_decode_init,
00103 .close = ff_mjpeg_decode_end,
00104 .decode = sp5x_decode_frame,
00105 .capabilities = CODEC_CAP_DR1,
00106 .max_lowres = 3,
00107 .long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"),
00108 };
00109 #endif
00110 #if CONFIG_AMV_DECODER
00111 AVCodec ff_amv_decoder = {
00112 .name = "amv",
00113 .type = AVMEDIA_TYPE_VIDEO,
00114 .id = AV_CODEC_ID_AMV,
00115 .priv_data_size = sizeof(MJpegDecodeContext),
00116 .init = ff_mjpeg_decode_init,
00117 .close = ff_mjpeg_decode_end,
00118 .decode = sp5x_decode_frame,
00119 .long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
00120 };
00121 #endif