gst-libs/gst/riff/riff-media.c: Reorder the audio formats a bit for clarity.
authorWim Taymans <wim.taymans@gmail.com>
Tue, 19 Sep 2006 10:23:03 +0000 (10:23 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Tue, 19 Sep 2006 10:23:03 +0000 (10:23 +0000)
Original commit message from CVS:
* gst-libs/gst/riff/riff-media.c: (gst_riff_create_audio_caps),
(gst_riff_create_audio_template_caps):
Reorder the audio formats a bit for clarity.
Detect and create caps for MSGSM and MSN (WAV49).
Fixes #356596.
* sys/xvimage/xvimagesink.c: (gst_xvimage_buffer_destroy),
(gst_xvimagesink_check_xshm_calls), (gst_xvimagesink_xvimage_new),
(gst_xvimagesink_get_xv_support), (gst_xvimagesink_show_frame):
Small cleanups, move error handling out of normal flow for clarity.

ChangeLog
gst-libs/gst/riff/riff-media.c
sys/xvimage/xvimagesink.c

index 32af8d7..1fab94d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-09-19  Wim Taymans  <wim@fluendo.com>
+
+       * gst-libs/gst/riff/riff-media.c: (gst_riff_create_audio_caps),
+       (gst_riff_create_audio_template_caps):
+       Reorder the audio formats a bit for clarity.
+       Detect and create caps for MSGSM and MSN (WAV49).
+       Fixes #356596.
+
+       * sys/xvimage/xvimagesink.c: (gst_xvimage_buffer_destroy),
+       (gst_xvimagesink_check_xshm_calls), (gst_xvimagesink_xvimage_new),
+       (gst_xvimagesink_get_xv_support), (gst_xvimagesink_show_frame):
+       Small cleanups, move error handling out of normal flow for clarity.
+
 2006-09-18  Stefan Kost,,,  <ensonic@users.sf.net>
 
        * docs/libs/gst-plugins-base-libs-docs.sgml:
index 4a8498a..12bdbca 100644 (file)
@@ -720,20 +720,6 @@ gst_riff_create_audio_caps (guint16 codec_id,
   gint channels_max = 2;
 
   switch (codec_id) {
-    case GST_RIFF_WAVE_FORMAT_MPEGL3:  /* mp3 */
-      caps = gst_caps_new_simple ("audio/mpeg",
-          "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
-      if (codec_name)
-        *codec_name = g_strdup ("MPEG-1 layer 3");
-      break;
-
-    case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */
-      caps = gst_caps_new_simple ("audio/mpeg",
-          "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
-      if (codec_name)
-        *codec_name = g_strdup ("MPEG-1 layer 2");
-      break;
-
     case GST_RIFF_WAVE_FORMAT_PCM:     /* PCM */
       if (strf != NULL) {
         gint ba = strf->blockalign;
@@ -793,6 +779,54 @@ gst_riff_create_audio_caps (guint16 codec_id,
       block_align = TRUE;
       break;
 
+    case GST_RIFF_WAVE_FORMAT_IBM_CVSD:
+      goto unknown;
+
+    case GST_RIFF_WAVE_FORMAT_ALAW:
+      if (strf != NULL) {
+        if (strf->size != 8) {
+          GST_WARNING ("invalid depth (%d) of alaw audio, overwriting.",
+              strf->size);
+          strf->size = 8;
+          strf->av_bps = 8;
+          strf->blockalign = strf->av_bps * strf->channels;
+        }
+        if (strf->av_bps == 0 || strf->blockalign == 0) {
+          GST_WARNING ("fixing av_bps (%d) and blockalign (%d) of alaw audio",
+              strf->av_bps, strf->blockalign);
+          strf->av_bps = strf->size;
+          strf->blockalign = strf->av_bps * strf->channels;
+        }
+      }
+      caps = gst_caps_new_simple ("audio/x-alaw", NULL);
+      if (codec_name)
+        *codec_name = g_strdup ("A-law audio");
+      break;
+
+    case GST_RIFF_WAVE_FORMAT_MULAW:
+      if (strf != NULL) {
+        if (strf->size != 8) {
+          GST_WARNING ("invalid depth (%d) of mulaw audio, overwriting.",
+              strf->size);
+          strf->size = 8;
+          strf->av_bps = 8;
+          strf->blockalign = strf->av_bps * strf->channels;
+        }
+        if (strf->av_bps == 0 || strf->blockalign == 0) {
+          GST_WARNING ("fixing av_bps (%d) and blockalign (%d) of mulaw audio",
+              strf->av_bps, strf->blockalign);
+          strf->av_bps = strf->size;
+          strf->blockalign = strf->av_bps * strf->channels;
+        }
+      }
+      caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
+      if (codec_name)
+        *codec_name = g_strdup ("Mu-law audio");
+      break;
+
+    case GST_RIFF_WAVE_FORMAT_OKI_ADPCM:
+      goto unknown;
+
     case GST_RIFF_WAVE_FORMAT_DVI_ADPCM:
       caps = gst_caps_new_simple ("audio/x-adpcm",
           "layout", G_TYPE_STRING, "dvi", NULL);
@@ -801,42 +835,25 @@ gst_riff_create_audio_caps (guint16 codec_id,
       block_align = TRUE;
       break;
 
-    case GST_RIFF_WAVE_FORMAT_MULAW:
-      if (strf != NULL && strf->size != 8) {
-        GST_WARNING ("invalid depth (%d) of mulaw audio, overwriting.",
-            strf->size);
-        strf->size = 8;
-        strf->av_bps = 8;
-        strf->blockalign = strf->av_bps * strf->channels;
-      }
-      if (strf != NULL && (strf->av_bps == 0 || strf->blockalign == 0)) {
-        GST_WARNING ("fixing av_bps (%d) and blockalign (%d) of mulaw audio",
-            strf->av_bps, strf->blockalign);
-        strf->av_bps = strf->size;
-        strf->blockalign = strf->av_bps * strf->channels;
-      }
-      caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
+    case GST_RIFF_WAVE_FORMAT_GSM610:
+    case GST_RIFF_WAVE_FORMAT_MSN:
+      caps = gst_caps_new_simple ("audio/ms-gsm", NULL);
       if (codec_name)
-        *codec_name = g_strdup ("Mu-law audio");
+        *codec_name = g_strdup ("MS GSM audio");
       break;
 
-    case GST_RIFF_WAVE_FORMAT_ALAW:
-      if (strf != NULL && strf->size != 8) {
-        GST_WARNING ("invalid depth (%d) of alaw audio, overwriting.",
-            strf->size);
-        strf->size = 8;
-        strf->av_bps = 8;
-        strf->blockalign = strf->av_bps * strf->channels;
-      }
-      if (strf != NULL && (strf->av_bps == 0 || strf->blockalign == 0)) {
-        GST_WARNING ("fixing av_bps (%d) and blockalign (%d) of alaw audio",
-            strf->av_bps, strf->blockalign);
-        strf->av_bps = strf->size;
-        strf->blockalign = strf->av_bps * strf->channels;
-      }
-      caps = gst_caps_new_simple ("audio/x-alaw", NULL);
+    case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */
+      caps = gst_caps_new_simple ("audio/mpeg",
+          "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
       if (codec_name)
-        *codec_name = g_strdup ("A-law audio");
+        *codec_name = g_strdup ("MPEG-1 layer 2");
+      break;
+
+    case GST_RIFF_WAVE_FORMAT_MPEGL3:  /* mp3 */
+      caps = gst_caps_new_simple ("audio/mpeg",
+          "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
+      if (codec_name)
+        *codec_name = g_strdup ("MPEG-1 layer 3");
       break;
 
     case GST_RIFF_WAVE_FORMAT_VORBIS1: /* ogg/vorbis mode 1 */
@@ -992,6 +1009,7 @@ gst_riff_create_audio_caps (guint16 codec_id,
       break;
     }
     default:
+    unknown:
       GST_WARNING ("Unknown audio tag 0x%04x", codec_id);
       return NULL;
   }
@@ -1129,6 +1147,7 @@ GstCaps *
 gst_riff_create_audio_template_caps (void)
 {
   static const guint16 tags[] = {
+    GST_RIFF_WAVE_FORMAT_GSM610,
     GST_RIFF_WAVE_FORMAT_MPEGL3,
     GST_RIFF_WAVE_FORMAT_MPEGL12,
     GST_RIFF_WAVE_FORMAT_PCM,
index d72fbe7..b7cca88 100644 (file)
@@ -246,7 +246,7 @@ gst_xvimage_buffer_destroy (GstXvImageBuffer * xvimage)
 #ifdef HAVE_XSHM
   if (xvimagesink->xcontext->use_xshm) {
     if (xvimage->SHMInfo.shmaddr != ((void *) -1)) {
-      GST_DEBUG_OBJECT (xvimagesink, "XServer ShmDetaching from 0x%x id 0x%x\n",
+      GST_DEBUG_OBJECT (xvimagesink, "XServer ShmDetaching from 0x%x id 0x%x",
           xvimage->SHMInfo.shmid, xvimage->SHMInfo.shmseg);
       XShmDetach (xvimagesink->xcontext->disp, &xvimage->SHMInfo);
       XSync (xvimagesink->xcontext->disp, FALSE);
@@ -463,7 +463,7 @@ gst_xvimagesink_check_xshm_calls (GstXContext * xcontext)
   /* Sync to ensure we see any errors we caused */
   XSync (xcontext->disp, FALSE);
 
-  GST_DEBUG ("XServer ShmAttached to 0x%x, id 0x%x\n", SHMInfo.shmid,
+  GST_DEBUG ("XServer ShmAttached to 0x%x, id 0x%x", SHMInfo.shmid,
       SHMInfo.shmseg);
 
   if (!error_caught) {
@@ -480,7 +480,7 @@ beach:
   XSetErrorHandler (handler);
 
   if (did_attach) {
-    GST_DEBUG ("XServer ShmDetaching from 0x%x id 0x%x\n",
+    GST_DEBUG ("XServer ShmDetaching from 0x%x id 0x%x",
         SHMInfo.shmid, SHMInfo.shmseg);
     XShmDetach (xcontext->disp, &SHMInfo);
     XSync (xcontext->disp, FALSE);
@@ -589,7 +589,7 @@ gst_xvimagesink_xvimage_new (GstXvImageSink * xvimagesink, GstCaps * caps)
     }
 
     XSync (xvimagesink->xcontext->disp, FALSE);
-    GST_DEBUG_OBJECT (xvimagesink, "XServer ShmAttached to 0x%x, id 0x%x\n",
+    GST_DEBUG_OBJECT (xvimagesink, "XServer ShmAttached to 0x%x, id 0x%x",
         xvimage->SHMInfo.shmid, xvimage->SHMInfo.shmseg);
   } else
 #endif /* HAVE_XSHM */
@@ -1115,21 +1115,13 @@ gst_xvimagesink_get_xv_support (GstXvImageSink * xvimagesink,
   g_return_val_if_fail (xcontext != NULL, NULL);
 
   /* First let's check that XVideo extension is available */
-  if (!XQueryExtension (xcontext->disp, "XVideo", &i, &i, &i)) {
-    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, SETTINGS,
-        ("Could not initialise Xv output"),
-        ("XVideo extension is not available"));
-    return NULL;
-  }
+  if (!XQueryExtension (xcontext->disp, "XVideo", &i, &i, &i))
+    goto no_extension;
 
   /* Then we get adaptors list */
   if (Success != XvQueryAdaptors (xcontext->disp, xcontext->root,
-          &nb_adaptors, &adaptors)) {
-    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, SETTINGS,
-        ("Could not initialise Xv output"),
-        ("Failed getting XV adaptors list"));
-    return NULL;
-  }
+          &nb_adaptors, &adaptors))
+    goto no_adaptors;
 
   xcontext->xv_port_id = 0;
 
@@ -1151,15 +1143,11 @@ gst_xvimagesink_get_xv_support (GstXvImageSink * xvimagesink,
 
     GST_DEBUG ("XV Adaptor %s with %ld ports", adaptors[i].name,
         adaptors[i].num_ports);
-
   }
   XvFreeAdaptorInfo (adaptors);
 
-  if (!xcontext->xv_port_id) {
-    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, BUSY,
-        ("Could not initialise Xv output"), ("No port available"));
-    return NULL;
-  }
+  if (!xcontext->xv_port_id)
+    goto no_port;
 
   /* Set XV_AUTOPAINT_COLORKEY and XV_DOUBLE_BUFFER and XV_COLORKEY */
   {
@@ -1334,15 +1322,40 @@ gst_xvimagesink_get_xv_support (GstXvImageSink * xvimagesink,
 
   GST_DEBUG ("Generated the following caps: %" GST_PTR_FORMAT, caps);
 
-  if (gst_caps_is_empty (caps)) {
+  if (gst_caps_is_empty (caps))
+    goto no_caps;
+
+  return caps;
+
+  /* ERRORS */
+no_extension:
+  {
+    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, SETTINGS,
+        ("Could not initialise Xv output"),
+        ("XVideo extension is not available"));
+    return NULL;
+  }
+no_adaptors:
+  {
+    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, SETTINGS,
+        ("Could not initialise Xv output"),
+        ("Failed getting XV adaptors list"));
+    return NULL;
+  }
+no_port:
+  {
+    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, BUSY,
+        ("Could not initialise Xv output"), ("No port available"));
+    return NULL;
+  }
+no_caps:
+  {
     gst_caps_unref (caps);
     XvUngrabPort (xcontext->disp, xcontext->xv_port_id, 0);
     GST_ELEMENT_ERROR (xvimagesink, STREAM, WRONG_TYPE, (NULL),
         ("No supported format found"));
     return NULL;
   }
-
-  return caps;
 }
 
 static gpointer
@@ -2007,19 +2020,10 @@ gst_xvimagesink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
           GST_BUFFER_CAPS (buf));
 
       if (!xvimagesink->xvimage)
-        /* The create method should have posted an informative error */
         goto no_image;
 
-      if (xvimagesink->xvimage->size < GST_BUFFER_SIZE (buf)) {
-        GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
-            ("Failed to create output image buffer of %dx%d pixels",
-                xvimagesink->xvimage->width, xvimagesink->xvimage->height),
-            ("XServer allocated buffer size did not match input buffer"));
-
-        gst_xvimage_buffer_destroy (xvimagesink->xvimage);
-        xvimagesink->xvimage = NULL;
-        goto no_image;
-      }
+      if (xvimagesink->xvimage->size < GST_BUFFER_SIZE (buf))
+        goto wrong_size;
     }
 
     memcpy (xvimagesink->xvimage->xvimage->data,
@@ -2028,7 +2032,6 @@ gst_xvimagesink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
 
     gst_xvimagesink_xvimage_put (xvimagesink, xvimagesink->xvimage);
   }
-
   return GST_FLOW_OK;
 
   /* ERRORS */
@@ -2036,6 +2039,18 @@ no_image:
   {
     /* No image available. That's very bad ! */
     GST_WARNING_OBJECT (xvimagesink, "could not create image");
+    /* The create method should have posted an informative error */
+    return GST_FLOW_ERROR;
+  }
+wrong_size:
+  {
+    /* we have a buffer but the size was not what we expected */
+    GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
+        ("Failed to create output image buffer of %dx%d pixels",
+            xvimagesink->xvimage->width, xvimagesink->xvimage->height),
+        ("XServer allocated buffer size did not match input buffer"));
+    gst_xvimage_buffer_destroy (xvimagesink->xvimage);
+    xvimagesink->xvimage = NULL;
     return GST_FLOW_ERROR;
   }
 }