[pulse] update pcm dump code for current gstreamer version 55/159755/1
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 3 Nov 2017 05:09:54 +0000 (14:09 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 13 Nov 2017 04:28:27 +0000 (04:28 +0000)
Change-Id: I9b3412a51d6e70af55428cc1d48fb9cd34ffca28
(cherry picked from commit 845df59ecd044bd38143f7a253cb88cd76b7b193)

ext/pulse/pulsesink.c
ext/pulse/pulsesink.h
ext/pulse/pulsesrc.c
ext/pulse/pulsesrc.h

index 30fd393..0a1d911 100644 (file)
@@ -971,8 +971,8 @@ gst_pulseringbuffer_acquire (GstAudioRingBuffer * buf,
     GDateTime *time = g_date_time_new_now_local();
 
     suffix = g_date_time_format(time, "%m%d_%H%M%S");
-    dump_path = g_strdup_printf("%s_%dch_%dhz_%s.pcm", GST_PULSESINK_DUMP_INPUT_PATH_PREFIX, pbuf->channels, spec->rate, suffix);
-
+    dump_path = g_strdup_printf("%s%dch_%dhz_%s.pcm", GST_PULSESINK_DUMP_INPUT_PATH_PREFIX, pbuf->channels, spec->info.rate, suffix);
+    GST_WARNING_OBJECT(psink, "pulse-sink dumping enabled: dump path [%s]", dump_path);
     psink->dump_fd_input = fopen(dump_path, "w+");
 
     g_free(suffix);
@@ -1938,16 +1938,21 @@ gst_pulsesink_payload (GstAudioBaseSink * sink, GstBuffer * buf)
 }
 
 #if defined(__TIZEN__) && defined(PCM_DUMP_ENABLE)
-static gboolean
-gst_pulsesink_pad_dump_handler (GstPad *pad, GstBuffer *buffer, gpointer data)
+static GstPadProbeReturn
+gst_pulsesink_pad_dump_probe (GstPad * pad, GstPadProbeInfo * info, gpointer data)
 {
   GstPulseSink *psink = GST_PULSESINK_CAST (data);
-  int ret = -1;
-
-  if (psink->dump_fd_input)
-    ret = fwrite(GST_BUFFER_DATA(buffer), 1, GST_BUFFER_SIZE(buffer), psink->dump_fd_input);
-
-  return !!ret;
+  size_t written = 0;
+  GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
+  GstMapInfo in_map;
+  if (psink->dump_fd_input) {
+    gst_buffer_map(buffer, &in_map, GST_MAP_READ);
+    written = fwrite(in_map.data, 1, in_map.size, psink->dump_fd_input);
+    if (written != in_map.size)
+      GST_WARNING("failed to write!!! ferror=%d", ferror(psink->dump_fd_input));
+    gst_buffer_unmap(buffer, &in_map);
+  }
+  return GST_PAD_PROBE_OK;
 }
 #endif /* __TIZEN__ && PCM_DUMP_ENABLE */
 
@@ -2470,7 +2475,7 @@ gst_pulsesink_init (GstPulseSink * pulsesink)
   if (pulsesink->need_dump_input) {
     sinkpad = gst_element_get_static_pad((GstElement *)pulsesink, "sink");
     if (sinkpad) {
-      gst_pad_add_buffer_probe (sinkpad, G_CALLBACK (gst_pulsesink_pad_dump_handler), pulsesink);
+      gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BUFFER, gst_pulsesink_pad_dump_probe, pulsesink, NULL);
       gst_object_unref (GST_OBJECT(sinkpad));
     }
   }
index ce9f438..aa17588 100644 (file)
 #include "config.h"
 #endif
 
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+#include <stdio.h>
+#endif
+#endif
+
 #include <gst/gst.h>
 #include <gst/audio/audio.h>
 #include <gst/audio/gstaudiosink.h>
index ee8b572..2ab5e46 100644 (file)
 #include "pulsesrc.h"
 #include "pulseutil.h"
 
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+#include <vconf.h>
+#endif
+#endif
+
 GST_DEBUG_CATEGORY_EXTERN (pulse_debug);
 #define GST_CAT_DEFAULT pulse_debug
 
@@ -84,6 +90,14 @@ enum
   PROP_LAST
 };
 
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+#define GST_PULSESRC_DUMP_VCONF_KEY            "memory/private/sound/pcm_dump"
+#define GST_PULSESRC_DUMP_OUTPUT_PATH_PREFIX   "/tmp/dump_pulsesrc_out"
+#define GST_PULSESRC_DUMP_OUTPUT_FLAG          0x00200000U
+#endif
+#endif
+
 static void gst_pulsesrc_destroy_stream (GstPulseSrc * pulsesrc);
 static void gst_pulsesrc_destroy_context (GstPulseSrc * pulsesrc);
 
@@ -262,9 +276,36 @@ gst_pulsesrc_class_init (GstPulseSrcClass * klass)
 #endif /* __TIZEN__ */
 }
 
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+static GstPadProbeReturn
+gst_pulsesrc_pad_dump_probe (GstPad *pad, GstPadProbeInfo * info, gpointer data)
+{
+  GstPulseSrc *pulsesrc =  GST_PULSESRC_CAST (data);
+  size_t written = 0;
+  GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
+  GstMapInfo in_map;
+  if (pulsesrc->dump_fd_output) {
+    gst_buffer_map(buffer, &in_map, GST_MAP_READ);
+    written = fwrite(in_map.data, 1, in_map.size, pulsesrc->dump_fd_output);
+    if (written != in_map.size)
+      GST_WARNING("failed to write!!! ferror=%d", ferror(pulsesrc->dump_fd_output));
+    gst_buffer_unmap(buffer, &in_map);
+  }
+  return GST_PAD_PROBE_OK;
+}
+#endif
+#endif
+
 static void
 gst_pulsesrc_init (GstPulseSrc * pulsesrc)
 {
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+  GstPad *srcpad = NULL;
+  int vconf_dump = 0;
+#endif
+#endif
   pulsesrc->server = NULL;
   pulsesrc->device = NULL;
   pulsesrc->client_name = gst_pulse_client_name ();
@@ -298,8 +339,19 @@ gst_pulsesrc_init (GstPulseSrc * pulsesrc)
   pulsesrc->latency = g_strdup (DEFAULT_AUDIO_LATENCY);
   pulsesrc->proplist = pa_proplist_new();
   pa_proplist_sets(pulsesrc->proplist, PA_PROP_MEDIA_TIZEN_AUDIO_LATENCY, pulsesrc->latency);
-#endif /* __TIZEN__ */
 
+#ifdef PCM_DUMP_ENABLE
+  if (vconf_get_int(GST_PULSESRC_DUMP_VCONF_KEY, &vconf_dump)) {
+    GST_WARNING("vconf_get_int %s failed", GST_PULSESRC_DUMP_VCONF_KEY);
+  }
+  pulsesrc->need_dump_output = vconf_dump & GST_PULSESRC_DUMP_OUTPUT_FLAG ? TRUE : FALSE;
+  pulsesrc->dump_fd_output = NULL;
+  if (pulsesrc->need_dump_output) {
+    srcpad = gst_element_get_static_pad((GstElement *)pulsesrc, "src");
+    gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BUFFER, gst_pulsesrc_pad_dump_probe, pulsesrc, NULL);
+  }
+#endif /* PCM_DUMP_ENABLE */
+#endif /* __TIZEN__ */
   /* this should be the default but it isn't yet */
   gst_audio_base_src_set_slave_method (GST_AUDIO_BASE_SRC (pulsesrc),
       GST_AUDIO_BASE_SRC_SLAVE_SKEW);
@@ -1103,7 +1155,14 @@ gst_pulsesrc_close (GstAudioSrc * asrc)
   pa_threaded_mainloop_lock (pulsesrc->mainloop);
   gst_pulsesrc_destroy_context (pulsesrc);
   pa_threaded_mainloop_unlock (pulsesrc->mainloop);
-
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+  if (pulsesrc->dump_fd_output) {
+    fclose(pulsesrc->dump_fd_output);
+    pulsesrc->dump_fd_output = NULL;
+  }
+#endif
+#endif
   return TRUE;
 }
 
@@ -1618,6 +1677,27 @@ gst_pulsesrc_prepare (GstAudioSrc * asrc, GstAudioRingBufferSpec * spec)
     gst_pulsesrc_set_stream_volume (pulsesrc, pulsesrc->volume);
     pulsesrc->volume_set = FALSE;
   }
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+  if (pulsesrc->need_dump_output) {
+    char *suffix , *dump_path;
+    GDateTime *time = NULL;
+    if (pulsesrc->dump_fd_output) {
+        fclose(pulsesrc->dump_fd_output);
+        pulsesrc->dump_fd_output = NULL;
+    }
+    time = g_date_time_new_now_local();
+    suffix = g_date_time_format(time, "%m%d_%H%M%S");
+    dump_path = g_strdup_printf("%s_%dch_%dhz_%s.pcm", GST_PULSESRC_DUMP_OUTPUT_PATH_PREFIX, pulsesrc->sample_spec.channels, pulsesrc->sample_spec.rate, suffix);
+    GST_WARNING_OBJECT(asrc,"pulse-source dumping enabled: dump path [%s]", dump_path);
+    pulsesrc->dump_fd_output = fopen(dump_path, "w+");
+
+    g_free(suffix);
+    g_free(dump_path);
+    g_date_time_unref(time);
+  }
+#endif /* PCM_DUMP_ENABLE */
+#endif
 
   /* get the actual buffering properties now */
   actual = pa_stream_get_buffer_attr (pulsesrc->stream);
index b88a0fa..a2335cc 100644 (file)
 #include <pulse/pulseaudio.h>
 #include <pulse/thread-mainloop.h>
 
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+#include <stdio.h>
+#endif
+#endif
+
 G_BEGIN_DECLS
 
 #define GST_TYPE_PULSESRC \
@@ -88,6 +94,13 @@ struct _GstPulseSrc
 
   GstStructure *properties;
   pa_proplist *proplist;
+
+#ifdef __TIZEN__
+#ifdef PCM_DUMP_ENABLE
+  gint need_dump_output;
+  FILE *dump_fd_output;
+#endif
+#endif
 };
 
 struct _GstPulseSrcClass