changeset 6198:8551432b011a libavformat

mxfdec: Improve parsing of the PixelLayout item
author thardin
date Wed, 30 Jun 2010 07:55:05 +0000
parents d81e41261983
children fa244b4fe683
files mxf.c mxf.h mxfdec.c
diffstat 3 files changed, 62 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mxf.c	Mon Jun 28 21:02:16 2010 +0000
+++ b/mxf.c	Wed Jun 30 07:55:05 2010 +0000
@@ -51,3 +51,44 @@
   //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 }, 15,    CODEC_ID_DOLBY_E }, /* Dolby-E */
     { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },  0,       CODEC_ID_NONE },
 };
+
+const MXFPixelLayout ff_mxf_pixel_layouts[] = {
+    /**
+     * See SMPTE 377M E.2.46
+     *
+     * Note: Only RGB, palette based and "abnormal" YUV pixel formats like 4:2:2:4 go here.
+     *       For regular YUV, use CDCIPictureEssenceDescriptor.
+     *
+     * Note: Do not use these for encoding descriptors for little-endian formats until we
+     *       get samples or official word from SMPTE on how/if those can be encoded.
+     */
+    {PIX_FMT_ABGR,    {'A', 8,  'B', 8,  'G', 8, 'R', 8                 }},
+    {PIX_FMT_ARGB,    {'A', 8,  'R', 8,  'G', 8, 'B', 8                 }},
+    {PIX_FMT_BGR24,   {'B', 8,  'G', 8,  'R', 8                         }},
+    {PIX_FMT_BGRA,    {'B', 8,  'G', 8,  'R', 8, 'A', 8                 }},
+    {PIX_FMT_RGB24,   {'R', 8,  'G', 8,  'B', 8                         }},
+    {PIX_FMT_RGB444BE,{'F', 4,  'R', 4,  'G', 4, 'B', 4                 }},
+    {PIX_FMT_RGB48BE, {'R', 8,  'r', 8,  'G', 8, 'g', 8, 'B', 8, 'b', 8 }},
+    {PIX_FMT_RGB48BE, {'R', 16, 'G', 16, 'B', 16                        }},
+    {PIX_FMT_RGB48LE, {'r', 8,  'R', 8,  'g', 8, 'G', 8, 'b', 8, 'B', 8 }},
+    {PIX_FMT_RGB555BE,{'F', 1,  'R', 5,  'G', 5, 'B', 5                 }},
+    {PIX_FMT_RGB565BE,{'R', 5,  'G', 6,  'B', 5                         }},
+    {PIX_FMT_RGBA,    {'R', 8,  'G', 8,  'B', 8, 'A', 8                 }},
+    {PIX_FMT_PAL8,    {'P', 8                                           }},
+};
+
+static const int num_pixel_layouts = sizeof(ff_mxf_pixel_layouts) / sizeof(*ff_mxf_pixel_layouts);
+
+int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum PixelFormat *pix_fmt)
+{
+    int x;
+
+    for(x = 0; x < num_pixel_layouts; x++) {
+        if (!memcmp(pixel_layout, ff_mxf_pixel_layouts[x].data, 16)) {
+            *pix_fmt = ff_mxf_pixel_layouts[x].pix_fmt;
+            return 0;
+        }
+    }
+
+    return -1;
+}
--- a/mxf.h	Mon Jun 28 21:02:16 2010 +0000
+++ b/mxf.h	Wed Jun 30 07:55:05 2010 +0000
@@ -61,6 +61,15 @@
 extern const MXFCodecUL ff_mxf_data_definition_uls[];
 extern const MXFCodecUL ff_mxf_codec_uls[];
 
+typedef struct {
+    enum PixelFormat pix_fmt;
+    const char data[16];
+} MXFPixelLayout;
+
+extern const MXFPixelLayout ff_mxf_pixel_layouts[];
+
+int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum PixelFormat *pix_fmt);
+
 #ifdef DEBUG
 #define PRINT_KEY(pc, s, x) dprintf(pc, "%s %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", s, \
                              (x)[0], (x)[1], (x)[2], (x)[3], (x)[4], (x)[5], (x)[6], (x)[7], (x)[8], (x)[9], (x)[10], (x)[11], (x)[12], (x)[13], (x)[14], (x)[15])
--- a/mxfdec.c	Mon Jun 28 21:02:16 2010 +0000
+++ b/mxfdec.c	Wed Jun 30 07:55:05 2010 +0000
@@ -101,6 +101,7 @@
     int linked_track_id;
     uint8_t *extradata;
     int extradata_size;
+    enum PixelFormat pix_fmt;
 } MXFDescriptor;
 
 typedef struct {
@@ -520,25 +521,21 @@
 
 static void mxf_read_pixel_layout(ByteIOContext *pb, MXFDescriptor *descriptor)
 {
-    int code;
+    int code, value, ofs = 0;
+    char layout[16] = {};
 
     do {
         code = get_byte(pb);
+        value = get_byte(pb);
         dprintf(NULL, "pixel layout: code %#x\n", code);
-        switch (code) {
-        case 0x52: /* R */
-            descriptor->bits_per_sample += get_byte(pb);
-            break;
-        case 0x47: /* G */
-            descriptor->bits_per_sample += get_byte(pb);
-            break;
-        case 0x42: /* B */
-            descriptor->bits_per_sample += get_byte(pb);
-            break;
-        default:
-            get_byte(pb);
+
+        if (ofs < 16) {
+            layout[ofs++] = code;
+            layout[ofs++] = value;
         }
     } while (code != 0); /* SMPTE 377M E.2.46 */
+
+    ff_mxf_decode_pixel_layout(layout, &descriptor->pix_fmt);
 }
 
 static int mxf_read_generic_descriptor(MXFDescriptor *descriptor, ByteIOContext *pb, int tag, int size, UID uid)
@@ -801,7 +798,8 @@
                 st->codec->codec_id = container_ul->id;
             st->codec->width = descriptor->width;
             st->codec->height = descriptor->height;
-            st->codec->bits_per_coded_sample = descriptor->bits_per_sample; /* Uncompressed */
+            if (st->codec->codec_id == CODEC_ID_RAWVIDEO)
+                st->codec->pix_fmt = descriptor->pix_fmt;
             st->need_parsing = AVSTREAM_PARSE_HEADERS;
         } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
             container_ul = mxf_get_codec_ul(mxf_essence_container_uls, essence_container_ul);