From: Vyacheslav Valkovoy Date: Wed, 21 Oct 2015 11:22:44 +0000 (+0300) Subject: Implemented get_play_position() API X-Git-Tag: submit/tizen/20151208.020949~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8811104af25c2e1f679dba324b07930503d9c39;p=platform%2Fcore%2Fapi%2Fmediastreamer.git Implemented get_play_position() API Change-Id: Iba9256a1ec98d54f8b5ebbef3e07be7e74bed610 Signed-off-by: Vyacheslav Valkovoy --- diff --git a/include/media_streamer_priv.h b/include/media_streamer_priv.h index d7df7d0..6fcae1d 100755 --- a/include/media_streamer_priv.h +++ b/include/media_streamer_priv.h @@ -108,6 +108,13 @@ typedef struct { /* Private functions definition */ +/** + * @brief Gets the play position of Media streamer element. + * + * @since_tizen 3.0 + */ +int __ms_get_position(media_streamer_s *ms_streamer, int *time); + /** * @brief Seeks Media streamer element to the pointed position. * diff --git a/src/media_streamer.c b/src/media_streamer.c index 902a9e4..09c3a5d 100755 --- a/src/media_streamer.c +++ b/src/media_streamer.c @@ -471,8 +471,12 @@ int media_streamer_stop(media_streamer_h streamer) g_mutex_lock(&ms_streamer->mutex_lock); - ret = __ms_state_change(ms_streamer, MEDIA_STREAMER_STATE_PAUSED); - /* TODO: do seek to 0 position. */ + ret = __ms_streamer_seek(streamer, 0, FALSE); + + if (ret != MEDIA_STREAMER_ERROR_NONE) + ms_error("Error while putting media streamer to zero playing position"); + else + ret = __ms_state_change(ms_streamer, MEDIA_STREAMER_STATE_PAUSED); g_mutex_unlock(&ms_streamer->mutex_lock); @@ -517,7 +521,16 @@ int media_streamer_get_play_position(media_streamer_h streamer, int *time) media_streamer_s *ms_streamer = (media_streamer_s *) streamer; ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); - return MEDIA_STREAMER_ERROR_NONE; + ms_retvm_if(ms_streamer->state < MEDIA_STREAMER_STATE_READY || ms_streamer->state > MEDIA_STREAMER_STATE_PAUSED, MEDIA_STREAMER_ERROR_INVALID_STATE, "The media streamer state is not in the appropriate state"); + + int ret = MEDIA_STREAMER_ERROR_NONE; + g_mutex_lock(&ms_streamer->mutex_lock); + + ret = __ms_get_position(streamer, time); + + g_mutex_unlock(&ms_streamer->mutex_lock); + + return ret; } int media_streamer_node_push_packet(media_streamer_node_h src, media_packet_h packet) diff --git a/src/media_streamer_gst.c b/src/media_streamer_gst.c index d6ac506..db48298 100755 --- a/src/media_streamer_gst.c +++ b/src/media_streamer_gst.c @@ -369,23 +369,37 @@ GstElement *__ms_bin_find_element_by_klass(GstElement * sink_bin, GstElement * p while (GST_ITERATOR_OK == gst_iterator_next(sink_pad_iterator, &sink_pad_value)) { GstPad *sink_pad = (GstPad *) g_value_get_object(&sink_pad_value); - /* Check if sink pad of found element is unlinked */ + /* If sink pad of found element is unlinked, */ + /* next mediastreamer element is found unlinked element. */ if (!gst_pad_is_linked(sink_pad)) { unlinked_sink_pad_found = TRUE; linked_sink_element = NULL; } else { - /* Check if src pad of previous element is linked to sink pad of found element */ - src_pad_iterator = gst_element_iterate_src_pads(previous_elem); - while (GST_ITERATOR_OK == gst_iterator_next(src_pad_iterator, &src_pad_value)) { - GstPad *src_pad = (GstPad *) g_value_get_object(&src_pad_value); - if (src_pad == gst_pad_get_peer(sink_pad)) - linked_sink_element = found_element; + if (previous_elem) { + + /* If previous element is set, */ + /* check if src pad of previous element is linked to sink pad of found element */ + src_pad_iterator = gst_element_iterate_src_pads(previous_elem); + while (GST_ITERATOR_OK == gst_iterator_next(src_pad_iterator, &src_pad_value)) { + GstPad *src_pad = (GstPad *) g_value_get_object(&src_pad_value); + + /* If pads are linked to each other, */ + /* Next mediastreamer element will be found linked element */ + GstPad *peer_pad = gst_pad_get_peer(sink_pad); + if (src_pad == peer_pad) + linked_sink_element = found_element; + MS_SAFE_UNREF(peer_pad); + g_value_reset(&src_pad_value); + } + g_value_unset(&src_pad_value); + gst_iterator_free(src_pad_iterator); + } else { - g_value_reset(&src_pad_value); + /* Previous element is not set. */ + /* Next mediastreamer element will be found linked element */ + linked_sink_element = found_element; } - g_value_unset(&src_pad_value); - gst_iterator_free(src_pad_iterator); } g_value_reset(&sink_pad_value); } @@ -393,7 +407,6 @@ GstElement *__ms_bin_find_element_by_klass(GstElement * sink_bin, GstElement * p g_value_unset(&sink_pad_value); gst_iterator_free(sink_pad_iterator); - /* Check if found element has unlinked sink pad, then return the found element */ if (unlinked_sink_pad_found) { if (bin_name == NULL || g_strrstr(GST_ELEMENT_NAME(found_element), bin_name)) { found = TRUE; @@ -405,8 +418,8 @@ GstElement *__ms_bin_find_element_by_klass(GstElement * sink_bin, GstElement * p g_value_reset(&element_value); } - /* If found element is of the needed class but has been linked previously by user, - we return this found element for further connection */ + /* If found element is of the needed plugin class but has been linked previously by user, */ + /* we return this found element for further connection */ if (linked_sink_element && (bin_name == NULL || g_strrstr(GST_ELEMENT_NAME(linked_sink_element), bin_name))) { found_element = linked_sink_element; found = TRUE; @@ -560,7 +573,7 @@ GstElement *__ms_combine_next_element(GstElement * previous_element, const gchar parent_element = (GstElement *) gst_element_get_parent(previous_element); - /*Look for node created by user */ + /* Look for node created by user */ if (next_elem_klass_name) found_element = __ms_bin_find_element_by_klass(parent_element, previous_element, next_elem_klass_name, next_elem_bin_name); @@ -593,7 +606,7 @@ GstElement *__ms_combine_next_element(GstElement * previous_element, const gchar MS_SAFE_UNREF(src_pad); } - /*Add created element */ + /* Add created element */ if (found_element) { if (__ms_bin_add_element(parent_element, found_element, FALSE)) { gst_element_sync_state_with_parent(found_element); diff --git a/src/media_streamer_priv.c b/src/media_streamer_priv.c index ab3588e..436be54 100644 --- a/src/media_streamer_priv.c +++ b/src/media_streamer_priv.c @@ -80,7 +80,24 @@ int __ms_create(media_streamer_s * ms_streamer) return __ms_pipeline_create(ms_streamer); } -int __ms_streamer_seek(media_streamer_s * ms_streamer, int g_time, bool flag) +int __ms_get_position(media_streamer_s *ms_streamer, int *time) +{ + ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + + gint64 current = -1; + + if (!gst_element_query_position(ms_streamer->pipeline, GST_FORMAT_TIME, ¤t)) { + ms_error("Could not query current position."); + return MEDIA_STREAMER_ERROR_INVALID_OPERATION; + } else { + *time = (int)(((GstClockTime)(current)) / GST_MSECOND); + ms_info("Media streamer queried position at [%d] msec successfully.", *time); + } + + return MEDIA_STREAMER_ERROR_NONE; +} + +int __ms_streamer_seek(media_streamer_s *ms_streamer, int g_time, bool flag) { ms_retvm_if(ms_streamer == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "Handle is NULL"); @@ -98,7 +115,7 @@ int __ms_streamer_seek(media_streamer_s * ms_streamer, int g_time, bool flag) ms_streamer->is_seeking = TRUE; } - ms_info("Media streamer pipeline seeked successfully."); + ms_info("Media streamer pipeline seeked successfully to [%d] position", g_time); return MEDIA_STREAMER_ERROR_NONE; } diff --git a/test/media_streamer_test.c b/test/media_streamer_test.c index fa16d13..1dc45b9 100755 --- a/test/media_streamer_test.c +++ b/test/media_streamer_test.c @@ -81,7 +81,6 @@ typedef enum { #define DEFAULT_SEEK_POS 0 #define MSEC_MULTIPLIER 1000 - #define VIDEO_PORT 5000 #define AUDIO_PORT 6000 @@ -124,6 +123,13 @@ static void streamer_error_cb(media_streamer_h streamer, static void streamer_seek_cb(void *user_data) { g_print("Media Streamer seeked to required position \n"); + + int current_time = 0; + + media_streamer_get_play_position(current_media_streamer, ¤t_time); + + g_print("Current play position [%02d:%02d:%03d] \n", current_time/(1000*60), + (current_time/1000)%60, current_time%1000); } static void _create(media_streamer_h *streamer) @@ -530,9 +536,9 @@ static void _create_rtp_client(media_streamer_node_h rtp_bin) media_streamer_node_add(current_media_streamer, video_sink); /*====================Linking Video Client=========================== */ - media_streamer_node_link(video_depay, "src", video_dec, "sink"); - media_streamer_node_link(video_dec, "src", video_conv, "sink"); - media_streamer_node_link(video_conv, "src", video_sink, "sink"); + media_streamer_node_link(video_depay, "src", video_dec, "sink"); + media_streamer_node_link(video_dec, "src", video_conv, "sink"); + media_streamer_node_link(video_conv, "src", video_sink, "sink"); g_print("== success client video part \n"); } @@ -614,7 +620,7 @@ static void buffer_status_cb(media_streamer_node_h node, static int count = 0; - /* Try send only 10 packets*/ + /* Try send only 10 packets */ if (status == MEDIA_STREAMER_CUSTOM_BUFFER_UNDERRUN && count < 10) { g_print("Buffer status cb got underflow\n"); @@ -791,7 +797,7 @@ static void display_playing_scenario_select_menu(void) g_print("----------------------------------------------------\n"); g_print("\n"); g_print("Please select Playing Scenario mode\n"); - g_print("By default will be used [%d] mode\n", g_scenario_mode); + g_print("By default will be used [%d] mode\n", g_scenario_mode); g_print("1. VideoFile playing \n"); g_print("2. VideoFile + SubtitleFile playing \n"); g_print("3. HTTP Source playing \n"); @@ -1089,7 +1095,6 @@ void _interpret_playing_scenario_menu(char *cmd) g_sub_menu_state = SUBMENU_STATE_UNKNOWN; } - void _interpret_scenario_menu(char *cmd) { int len = strlen(cmd); @@ -1139,7 +1144,7 @@ void _interpret_scenario_menu(char *cmd) g_sub_menu_state = SUBMENU_STATE_GETTING_VIDEOFILE_URI; } else if (g_menu_preset == PRESET_RTP_CLIENT) { create_formats(); - media_streamer_node_h rtp_bin = _create_rtp(VIDEO_PORT, AUDIO_PORT, TRUE); + _create_rtp(VIDEO_PORT, AUDIO_PORT, TRUE); g_sub_menu_state = SUBMENU_STATE_UNKNOWN; } } @@ -1224,7 +1229,6 @@ void _interpret_getting_uri_menu(char *cmd) } } else { if (g_scenario_mode == SCENARIO_MODE_FILE_STREAM_VIDEO_AUDIO) { - media_streamer_node_h rtp_bin = NULL; create_formats(); _create_file_streaming(); _create_rtp(VIDEO_PORT, AUDIO_PORT, FALSE);