Browse code

libutvideo: Don't try and output original_format

The original format field in Ut Video's extradata
should not be used to determine the output format.
Cases can occur where the original format differs
from the actual current format, and thus should
not be used as the output format. Instead, rely
solely on the FOURCC.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Derek Buitenhuis authored on 2011/11/07 13:51:47
Showing 1 changed files
... ...
@@ -51,7 +51,7 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
51 51
 {
52 52
     UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
53 53
     UtVideoExtra info;
54
-    int defined_fourcc = 0;
54
+    int format;
55 55
 
56 56
     if(avctx->extradata_size != 4*4)
57 57
     {
... ...
@@ -65,55 +65,28 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
65 65
     info.stripes = AV_RL32(avctx->extradata + 8);
66 66
     info.flags = AV_RL32(avctx->extradata + 12);
67 67
 
68
-    /* Try to output the original format */
69
-    switch(UNFCC(info.original_format))
68
+    /* Pick format based on FOURCC */
69
+    switch(avctx->codec_tag)
70 70
     {
71
-        case UTVF_YV12:
71
+        case MKTAG('U', 'L', 'Y', '0'):
72 72
             avctx->pix_fmt = PIX_FMT_YUV420P;
73
+            format = UTVF_YV12;
73 74
             break;
74
-        case UTVF_YUY2:
75
-        case UTVF_YUYV:
76
-        case UTVF_YUNV:
75
+        case MKTAG('U', 'L', 'Y', '2'):
77 76
             avctx->pix_fmt = PIX_FMT_YUYV422;
77
+            format = UTVF_YUY2;
78 78
             break;
79
-        case UTVF_UYVY:
80
-        case UTVF_UYNV:
81
-            avctx->pix_fmt = PIX_FMT_UYVY422;
82
-            break;
83
-        case UTVF_RGB24_WIN:
79
+        case MKTAG('U', 'L', 'R', 'G'):
84 80
             avctx->pix_fmt = PIX_FMT_BGR24;
81
+            format = UTVF_RGB24_WIN;
85 82
             break;
86
-        case UTVF_RGB32_WIN:
83
+        case MKTAG('U', 'L', 'R', 'A'):
87 84
             avctx->pix_fmt = PIX_FMT_RGB32;
88
-            break;
89
-        case UTVF_ARGB32_WIN:
90
-            avctx->pix_fmt = PIX_FMT_ARGB;
91
-            break;
92
-        case 0:
93
-            /* Fall back on FOURCC */
94
-            switch(UNFCC(avctx->codec_tag))
95
-            {
96
-                case UTVF_ULY0:
97
-                    avctx->pix_fmt = PIX_FMT_YUV420P;
98
-                    defined_fourcc = UTVF_YV12;
99
-                    break;
100
-                case UTVF_ULY2:
101
-                    avctx->pix_fmt = PIX_FMT_YUYV422;
102
-                    defined_fourcc = UTVF_YUY2;
103
-                    break;
104
-                case UTVF_ULRG:
105
-                    avctx->pix_fmt = PIX_FMT_BGR24;
106
-                    defined_fourcc = UTVF_RGB24_WIN;
107
-                    break;
108
-                case UTVF_ULRA:
109
-                    avctx->pix_fmt = PIX_FMT_RGB32;
110
-                    defined_fourcc = UTVF_RGB32_WIN;
111
-                    break;
112
-            }
85
+            format = UTVF_RGB32_WIN;
113 86
             break;
114 87
         default:
115 88
             av_log(avctx, AV_LOG_ERROR,
116
-                  "Codec ExtraData is Corrupt or Invalid: %X\n", info.original_format);
89
+                  "Not a Ut Video FOURCC: %X\n", avctx->codec_tag);
117 90
             return -1;
118 91
     }
119 92
 
... ...
@@ -146,9 +119,8 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
146 146
     utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
147 147
 
148 148
     /* Initialize Decoding */
149
-    utv->codec->DecodeBegin(defined_fourcc ? defined_fourcc : UNFCC(info.original_format),
150
-                            avctx->width, avctx->height, CBGROSSWIDTH_WINDOWS, &info,
151
-                            sizeof(UtVideoExtra));
149
+    utv->codec->DecodeBegin(format, avctx->width, avctx->height,
150
+                            CBGROSSWIDTH_WINDOWS, &info, sizeof(UtVideoExtra));
152 151
 
153 152
     return 0;
154 153
 }