[MPlayer-dev-eng] [PATCH] avoid code duplication for fourcc/extradata setting in demux_mkv.c

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed May 9 23:21:29 CEST 2007


Hello,
On Wed, May 09, 2007 at 11:58:35PM +0300, Uoti Urpala wrote:
> On Wed, 2007-05-09 at 22:04 +0200, Reimar Döffinger wrote:
> > I will reindent the MSGTR_MPDEMUX_MKV_UnknownCodecID block in a separate
> > commit.
> 
> Why? Just to litter the log with meaningless commits? The diff doesn't
> match it even if it's on the same level. And even if it was matched it
> still wouldn't be worth adding an extra commit.

That is your opinion, not mine and I don't intend to discuss this
subject, that has been done often enough you know my opinion.
Still, a somewhat cleaned-up patch. Might ease implementing some kind of
fallback if someone comes up with an idea for how to do one.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/demux_mkv.c
===================================================================
--- libmpdemux/demux_mkv.c	(revision 23280)
+++ libmpdemux/demux_mkv.c	(working copy)
@@ -1798,6 +1798,22 @@
     }
 }
 
+typedef struct {
+  char *id;
+  int fourcc;
+  int extradata;
+} videocodec_info_t;
+
+static const videocodec_info_t vinfo[] = {
+  { MKV_V_MPEG1,     mmioFOURCC('m', 'p', 'g', '1'), 0 },
+  { MKV_V_MPEG2,     mmioFOURCC('m', 'p', 'g', '2'), 0 },
+  { MKV_V_MPEG4_SP,  mmioFOURCC('m', 'p', '4', 'v'), 1 },
+  { MKV_V_MPEG4_ASP, mmioFOURCC('m', 'p', '4', 'v'), 1 },
+  { MKV_V_MPEG4_AP,  mmioFOURCC('m', 'p', '4', 'v'), 1 },
+  { MKV_V_MPEG4_AVC, mmioFOURCC('a', 'v', 'c', '1'), 1 },
+  { NULL, 0, 0 }
+};
+
 static int
 demux_mkv_open_video (demuxer_t *demuxer, mkv_track_t *track, int vid)
 {
@@ -1902,46 +1918,24 @@
 #endif /* USE_QTX_CODECS */
 
         }
-      else if (!strcmp(track->codec_id, MKV_V_MPEG1))
+      else
         {
-          bih->biCompression = mmioFOURCC('m', 'p', 'g', '1');
-          track->reorder_timecodes = !correct_pts;
-        }
-      else if (!strcmp(track->codec_id, MKV_V_MPEG2))
-        {
-          bih->biCompression = mmioFOURCC('m', 'p', 'g', '2');
-          track->reorder_timecodes = !correct_pts;
-        }
-      else if (!strcmp(track->codec_id, MKV_V_MPEG4_SP) ||
-               !strcmp(track->codec_id, MKV_V_MPEG4_ASP) ||
-               !strcmp(track->codec_id, MKV_V_MPEG4_AP))
-        {
-          bih->biCompression = mmioFOURCC('m', 'p', '4', 'v');
-          if (track->private_data && (track->private_size > 0))
+          const videocodec_info_t *vi = vinfo;
+          while (vi->id && strcmp(vi->id, track->codec_id)) vi++;
+          bih->biCompression = vi->fourcc;
+          if (vi->extradata && track->private_data && (track->private_size > 0))
             {
               bih->biSize += track->private_size;
               bih = realloc (bih, bih->biSize);
               memcpy (bih + 1, track->private_data, track->private_size);
             }
           track->reorder_timecodes = !correct_pts;
-        }
-      else if (!strcmp(track->codec_id, MKV_V_MPEG4_AVC))
-        {
-          bih->biCompression = mmioFOURCC('a', 'v', 'c', '1');
-          if (track->private_data && (track->private_size > 0))
-            {
-              bih->biSize += track->private_size;
-              bih = realloc (bih, bih->biSize);
-              memcpy (bih + 1, track->private_data, track->private_size);
-            }
-          track->reorder_timecodes = !correct_pts;
-        }
-      else
-        {
+          if (!vi->id) {
           mp_msg (MSGT_DEMUX,MSGL_WARN, MSGTR_MPDEMUX_MKV_UnknownCodecID,
                   track->codec_id, track->tnum);
           free(bih);
           return 1;
+          }
         }
     }
 


More information about the MPlayer-dev-eng mailing list