+#ifdef TIZEN_PCM_DUMP
+static void pa_sink_write_pcm_dump(pa_sink *s, pa_memchunk *chunk)
+{
+ char *dump_time = NULL, *dump_path_surfix = NULL;
+ const char *s_device_api_str, *card_name_str, *device_idx_str;
+ struct timeval now;
+ struct tm tm;
+ char datetime[7];
+
+ /* open file for dump pcm */
+ if (s->core->pcm_dump & PA_PCM_DUMP_SINK && !s->pcm_dump_fp && s->state == PA_SINK_RUNNING) {
+ pa_gettimeofday(&now);
+ localtime_r(&now.tv_sec, &tm);
+ memset(&datetime[0], 0x00, sizeof(datetime));
+ strftime(&datetime[0], sizeof(datetime), "%H%M%S", &tm);
+ dump_time = pa_sprintf_malloc("%s.%03ld", &datetime[0], now.tv_usec / 1000);
+
+ if ((s_device_api_str = pa_proplist_gets(s->proplist, PA_PROP_DEVICE_API))) {
+ if (pa_streq(s_device_api_str, "alsa")) {
+ card_name_str = pa_proplist_gets(s->proplist, "alsa.card_name");
+ device_idx_str = pa_proplist_gets(s->proplist, "alsa.device");
+ dump_path_surfix = pa_sprintf_malloc("%s.%s", pa_strnull(card_name_str), pa_strnull(device_idx_str));
+ } else {
+ dump_path_surfix = pa_sprintf_malloc("%s", s_device_api_str);
+ }
+ } else {
+ dump_path_surfix = pa_sprintf_malloc("%s", s->name);
+ }
+
+ s->dump_path = pa_sprintf_malloc("%s_%s_pa-sink%d-%s_%dch_%d.raw", PA_PCM_DUMP_PATH_PREFIX, pa_strempty(dump_time),
+ s->index, pa_strempty(dump_path_surfix), s->sample_spec.channels, s->sample_spec.rate);
+ if (s->dump_path) {
+ s->pcm_dump_fp = fopen(s->dump_path, "w");
+ if (!s->pcm_dump_fp)
+ pa_log_warn("%s open failed", s->dump_path);
+ else
+ pa_log_info("%s opened", s->dump_path);
+ }
+ pa_xfree(dump_time);
+ pa_xfree(dump_path_surfix);
+ /* close file for dump pcm when config is changed */
+ } else if (~s->core->pcm_dump & PA_PCM_DUMP_SINK && s->pcm_dump_fp) {
+ fclose(s->pcm_dump_fp);
+ pa_log_info("%s closed", s->dump_path);
+ pa_xfree(s->dump_path);
+ s->pcm_dump_fp = NULL;
+ }
+
+ /* dump pcm */
+ if (s->pcm_dump_fp) {
+ void *ptr = NULL;
+
+ ptr = pa_memblock_acquire(chunk->memblock);
+ if (ptr)
+ fwrite((uint8_t *)ptr + chunk->index, 1, chunk->length, s->pcm_dump_fp);
+ else
+ pa_log_warn("pa_memblock_acquire is failed. ptr is NULL");
+
+ pa_memblock_release(chunk->memblock);
+ }
+}
+#endif
+