]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libutvideo.cpp
sgidec: make compiler optimize away memcpy call in inner loop.
[ffmpeg] / libavcodec / libutvideo.cpp
index 3c78f45daf5ba4c47622e82d6f771bcff9b47cea..635720e976969f4d8b55f35ec1dd581b045a9810 100644 (file)
@@ -37,7 +37,7 @@ extern "C" {
 typedef struct {
     uint32_t version;
     uint32_t original_format;
-    uint32_t stripes;
+    uint32_t frameinfo_size;
     uint32_t flags;
 } UtVideoExtra;
 
@@ -52,9 +52,9 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
     UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
     UtVideoExtra info;
     int format;
+    int begin_ret;
 
-    if(avctx->extradata_size != 4*4)
-    {
+    if (avctx->extradata_size != 4*4) {
         av_log(avctx, AV_LOG_ERROR, "Extradata size mismatch.\n");
         return -1;
     }
@@ -62,45 +62,43 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
     /* 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);
 
     /* Pick format based on FOURCC */
-    switch(avctx->codec_tag)
-    {
-        case MKTAG('U', 'L', 'Y', '0'):
-            avctx->pix_fmt = PIX_FMT_YUV420P;
-            format = UTVF_YV12;
-            break;
-        case MKTAG('U', 'L', 'Y', '2'):
-            avctx->pix_fmt = PIX_FMT_YUYV422;
-            format = UTVF_YUY2;
-            break;
-        case MKTAG('U', 'L', 'R', 'G'):
-            avctx->pix_fmt = PIX_FMT_BGR24;
-            format = UTVF_RGB24_WIN;
-            break;
-        case MKTAG('U', 'L', 'R', 'A'):
-            avctx->pix_fmt = PIX_FMT_RGB32;
-            format = UTVF_RGB32_WIN;
-            break;
-        default:
-            av_log(avctx, AV_LOG_ERROR,
-                  "Not a Ut Video FOURCC: %X\n", avctx->codec_tag);
-            return -1;
+    switch (avctx->codec_tag) {
+    case MKTAG('U', 'L', 'Y', '0'):
+        avctx->pix_fmt = PIX_FMT_YUV420P;
+        format = UTVF_YV12;
+        break;
+    case MKTAG('U', 'L', 'Y', '2'):
+        avctx->pix_fmt = PIX_FMT_YUYV422;
+        format = UTVF_YUY2;
+        break;
+    case MKTAG('U', 'L', 'R', 'G'):
+        avctx->pix_fmt = PIX_FMT_BGR24;
+        format = UTVF_RGB24_WIN;
+        break;
+    case MKTAG('U', 'L', 'R', 'A'):
+        avctx->pix_fmt = PIX_FMT_RGB32;
+        format = UTVF_RGB32_WIN;
+        break;
+    default:
+        av_log(avctx, AV_LOG_ERROR,
+              "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));
 
-    if(utv->output == NULL)
-    {
+    if (utv->output == NULL) {
         av_log(avctx, AV_LOG_ERROR, "Unable to allocate output buffer.\n");
         return -1;
     }
 
-    /* Allocate the output frame  */
+    /* Allocate the output frame */
     avctx->coded_frame = avcodec_alloc_frame();
 
     /* Ut Video only supports 8-bit */
@@ -119,9 +117,16 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
     utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
 
     /* Initialize Decoding */
-    utv->codec->DecodeBegin(format, avctx->width, avctx->height,
+    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;
 }
 
@@ -130,7 +135,7 @@ static int utvideo_decode_frame(AVCodecContext *avctx, void *data,
 {
     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;
@@ -141,26 +146,25 @@ static int utvideo_decode_frame(AVCodecContext *avctx, void *data,
     utv->codec->DecodeFrame(utv->output, avpkt->data, true);
 
     /* Set the output data depending on the colorspace */
-    switch(avctx->pix_fmt)
-    {
-        case PIX_FMT_YUV420P:
-            pic->linesize[0] = w;
-            pic->linesize[1] = pic->linesize[2] = w / 2;
-            pic->data[0] = utv->output;
-            pic->data[2] = utv->output + (w * h);
-            pic->data[1] = pic->data[2] + (w * h / 4);
-            break;
-        case PIX_FMT_YUYV422:
-            pic->linesize[0] = w * 2;
-            pic->data[0] = utv->output;
-            break;
-        case PIX_FMT_BGR24:
-        case PIX_FMT_RGB32:
-            /* Make the linesize negative, since Ut Video uses bottom-up BGR */
-            pic->linesize[0] = -1 * w * (avctx->pix_fmt == PIX_FMT_BGR24 ? 3 : 4);
-            pic->data[0] = utv->output + utv->buf_size + pic->linesize[0];
-            break;
-     }
+    switch (avctx->pix_fmt) {
+    case PIX_FMT_YUV420P:
+        pic->linesize[0] = w;
+        pic->linesize[1] = pic->linesize[2] = w / 2;
+        pic->data[0] = utv->output;
+        pic->data[2] = utv->output + (w * h);
+        pic->data[1] = pic->data[2] + (w * h / 4);
+        break;
+    case PIX_FMT_YUYV422:
+        pic->linesize[0] = w * 2;
+        pic->data[0] = utv->output;
+        break;
+    case PIX_FMT_BGR24:
+    case PIX_FMT_RGB32:
+        /* Make the linesize negative, since Ut Video uses bottom-up BGR */
+        pic->linesize[0] = -1 * w * (avctx->pix_fmt == PIX_FMT_BGR24 ? 3 : 4);
+        pic->data[0] = utv->output + utv->buf_size + pic->linesize[0];
+        break;
+    }
 
     *data_size = sizeof(AVFrame);
     *(AVFrame *)data = *pic;
@@ -192,7 +196,7 @@ AVCodec ff_libutvideo_decoder = {
     NULL,
     utvideo_decode_close,
     utvideo_decode_frame,
-    CODEC_CAP_LOSSLESS,
+    NULL,
     NULL,
     NULL,
     NULL,