typedef struct {
uint32_t version;
uint32_t original_format;
- uint32_t stripes;
+ uint32_t frameinfo_size;
uint32_t flags;
} UtVideoExtra;
typedef struct {
CCodec *codec;
- unsigned int buf_size;
uint8_t *output;
} UtVideoContext;
{
UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
UtVideoExtra info;
- int defined_fourcc = 0;
+ int format;
+ int begin_ret;
+ unsigned int buf_size;
if(avctx->extradata_size != 4*4)
{
/* Read extradata */
info.version = AV_RL32(avctx->extradata);
info.original_format = AV_RL32(avctx->extradata + 4);
- info.stripes = AV_RL32(avctx->extradata + 8);
+ info.frameinfo_size = AV_RL32(avctx->extradata + 8);
info.flags = AV_RL32(avctx->extradata + 12);
- /* Try to output the original format */
- switch(UNFCC(info.original_format))
+ /* Pick format based on FOURCC */
+ switch(avctx->codec_tag)
{
- case UTVF_YV12:
+ case MKTAG('U', 'L', 'Y', '0'):
avctx->pix_fmt = PIX_FMT_YUV420P;
+ format = UTVF_YV12;
break;
- case UTVF_YUY2:
- case UTVF_YUYV:
- case UTVF_YUNV:
+ case MKTAG('U', 'L', 'Y', '2'):
avctx->pix_fmt = PIX_FMT_YUYV422;
+ format = UTVF_YUY2;
break;
- case UTVF_UYVY:
- case UTVF_UYNV:
- avctx->pix_fmt = PIX_FMT_UYVY422;
- break;
- case UTVF_RGB24_WIN:
+ case MKTAG('U', 'L', 'R', 'G'):
avctx->pix_fmt = PIX_FMT_BGR24;
+ format = UTVF_RGB24_WIN;
break;
- case UTVF_RGB32_WIN:
+ case MKTAG('U', 'L', 'R', 'A'):
avctx->pix_fmt = PIX_FMT_RGB32;
- break;
- case UTVF_ARGB32_WIN:
- avctx->pix_fmt = PIX_FMT_ARGB;
- break;
- case 0:
- /* Fall back on FOURCC */
- switch(UNFCC(avctx->codec_tag))
- {
- case UTVF_ULY0:
- avctx->pix_fmt = PIX_FMT_YUV420P;
- defined_fourcc = UTVF_YV12;
- break;
- case UTVF_ULY2:
- avctx->pix_fmt = PIX_FMT_YUYV422;
- defined_fourcc = UTVF_YUY2;
- break;
- case UTVF_ULRG:
- avctx->pix_fmt = PIX_FMT_BGR24;
- defined_fourcc = UTVF_RGB24_WIN;
- break;
- case UTVF_ULRA:
- avctx->pix_fmt = PIX_FMT_RGB32;
- defined_fourcc = UTVF_RGB32_WIN;
- break;
- }
+ format = UTVF_RGB32_WIN;
break;
default:
av_log(avctx, AV_LOG_ERROR,
- "Codec ExtraData is Corrupt or Invalid: %X\n", info.original_format);
+ "Not a Ut Video FOURCC: %X\n", avctx->codec_tag);
return -1;
}
/* Only allocate the buffer once */
- utv->buf_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
- utv->output = (uint8_t *)av_malloc(utv->buf_size * sizeof(uint8_t));
+ buf_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+ utv->output = (uint8_t *)av_malloc(buf_size * sizeof(uint8_t));
if(utv->output == NULL)
{
return -1;
}
- /* Allocate the output frame */
+ /* Allocate the output frame */
avctx->coded_frame = avcodec_alloc_frame();
/* Ut Video only supports 8-bit */
utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
/* Initialize Decoding */
- utv->codec->DecodeBegin(defined_fourcc ? defined_fourcc : UNFCC(info.original_format),
- avctx->width, avctx->height, CBGROSSWIDTH_WINDOWS, &info,
- sizeof(UtVideoExtra));
+ begin_ret = utv->codec->DecodeBegin(format, avctx->width, avctx->height,
+ CBGROSSWIDTH_WINDOWS, &info, sizeof(UtVideoExtra));
+
+ /* Check to see if the decoder initlized properly */
+ if(begin_ret != 0)
+ {
+ av_log(avctx, AV_LOG_ERROR,
+ "Could not initialize decoder: %d\n", begin_ret);
+ return -1;
+ }
return 0;
}
{
UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
AVFrame *pic = avctx->coded_frame;
- unsigned int w = avctx->width, h = avctx->height;
+ int w = avctx->width, h = avctx->height;
/* Set flags */
pic->reference = 0;
pic->data[1] = pic->data[2] + (w * h / 4);
break;
case PIX_FMT_YUYV422:
- case PIX_FMT_UYVY422:
pic->linesize[0] = w * 2;
pic->data[0] = utv->output;
break;
}
AVCodec ff_libutvideo_decoder = {
- "utvideo",
+ "libutvideo",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_UTVIDEO,
sizeof(UtVideoContext),
NULL,
utvideo_decode_close,
utvideo_decode_frame,
- CODEC_CAP_LOSSLESS,
+ NULL,
NULL,
NULL,
NULL,