Fix double unlock of slot mutex in user stops scneario
[platform/core/multimedia/libmm-sound.git] / server / plugin / wav / mm_sound_plugin_codec_wave.c
index 7174ca3..65ea459 100644 (file)
@@ -40,7 +40,7 @@
 typedef struct {
        int handle;
        int repeat_count;
-       int (*stop_cb)(int);
+       int (*stop_cb)(int, bool);
        char filename[MM_SOUND_MAX_FILENAME];
        int cb_param;
        char stream_type[MAX_STREAM_TYPE_LEN];
@@ -53,6 +53,8 @@ typedef struct {
        pa_sample_spec spec;
        SNDFILE *sf;
        SF_INFO si;
+
+       size_t written;
 } wave_info_t;
 
 static int _sound_prepare(wave_info_t *h)
@@ -225,7 +227,7 @@ static void _pa_stream_drain_complete_callback(pa_stream *s, int success, void *
 
        debug_msg("Invoke stop callback(%p, %d) of mgr_codec", h->stop_cb, h->cb_param);
        if (h->stop_cb)
-               h->stop_cb(h->cb_param);
+               h->stop_cb(h->cb_param, false);
 }
 
 static void _pa_stream_moved_callback(pa_stream *s, void *userdata)
@@ -248,6 +250,12 @@ static void _pa_stream_buffer_attr_callback(pa_stream *s, void *userdata)
        debug_msg("stream(%p)", s);
 }
 
+static void _pa_stream_started_callback(pa_stream *s, void *userdata)
+{
+       assert(s);
+       debug_msg("stream(%p)", s);
+}
+
 static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdata)
 {
        sf_count_t bytes = 0;
@@ -278,13 +286,15 @@ static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdat
        if ((bytes = sf_readf_short(h->sf, data, (sf_count_t)(data_length / frame_size))) > 0)
                bytes *= (sf_count_t)frame_size;
 
-       debug_msg("stream(%p) : === %"PRId64" / %zu ===", s, bytes, data_length);
+       debug_msg("stream(%p) : === %"PRId64" / %zu / %zu ===", s, bytes, data_length, h->written);
 
        if (bytes > 0)
                pa_stream_write(s, data, (size_t)bytes, NULL, 0, PA_SEEK_RELATIVE);
        else
                pa_stream_cancel_write(s);
 
+       h->written += bytes;
+
        /* If No more data, drain stream */
        if (bytes < (sf_count_t)data_length) {
                debug_msg("stream(%p) : End Of Stream", s);
@@ -403,6 +413,7 @@ static int _pa_stream_connect(wave_info_t *h)
        pa_stream_set_moved_callback(s, _pa_stream_moved_callback, h);
        pa_stream_set_underflow_callback(s, _pa_stream_underflow_callback, h);
        pa_stream_set_buffer_attr_callback(s, _pa_stream_buffer_attr_callback, h);
+       pa_stream_set_started_callback(s, _pa_stream_started_callback, h);
 
        ret = pa_stream_connect_playback(s, NULL, NULL,
                PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_START_CORKED,
@@ -579,7 +590,7 @@ static int _mm_sound_plug_codec_wave_play(MMHandleType handle)
 {
        wave_info_t *h = (wave_info_t *)handle;
 
-       debug_msg("Start handle(%p), stream(%p)", h, h->s);
+       debug_msg("Start handle(%p), stream(%p), written(%zu)", h, h->s, h->written);
        _pa_stream_uncork(h);
 
        return MM_ERROR_NONE;
@@ -598,7 +609,7 @@ static int _mm_sound_plug_codec_wave_stop(MMHandleType handle)
        _pa_stream_stop_disconnect(h);
 
        if (h->stop_cb)
-               h->stop_cb(h->cb_param);
+               h->stop_cb(h->cb_param, true);
 
        return MM_ERROR_NONE;
 }