Make sure to not go out of the target state due to buffering messages

E.g. go to PLAYING although we're only requested to PAUSED
This commit is contained in:
Sebastian Dröge 2012-09-26 13:46:47 +02:00
parent 3e795c9a19
commit 6184907bbf

View file

@ -26,7 +26,7 @@ typedef struct _CustomData {
GstElement *pipeline; GstElement *pipeline;
GMainLoop *main_loop; GMainLoop *main_loop;
ANativeWindow *native_window; ANativeWindow *native_window;
gboolean state; GstState state, target_state;
gint64 position; gint64 position;
gint64 duration; gint64 duration;
GstElement *vsink; GstElement *vsink;
@ -142,12 +142,14 @@ static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
g_free (debug_info); g_free (debug_info);
set_ui_message (message_string, data); set_ui_message (message_string, data);
g_free (message_string); g_free (message_string);
data->target_state = GST_STATE_NULL;
gst_element_set_state (data->pipeline, GST_STATE_NULL); gst_element_set_state (data->pipeline, GST_STATE_NULL);
} }
static void eos_cb (GstBus *bus, GstMessage *msg, CustomData *data) { static void eos_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
set_ui_message (GST_MESSAGE_TYPE_NAME (msg), data); set_ui_message (GST_MESSAGE_TYPE_NAME (msg), data);
refresh_ui (data); refresh_ui (data);
data->target_state = GST_STATE_PAUSED;
data->is_live = (gst_element_set_state (data->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL); data->is_live = (gst_element_set_state (data->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
execute_seek (0, data); execute_seek (0, data);
} }
@ -163,16 +165,18 @@ static void buffering_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
return; return;
gst_message_parse_buffering (msg, &percent); gst_message_parse_buffering (msg, &percent);
if (percent < 100) if (percent < 100 && data->target_state >= GST_STATE_PAUSED)
gst_element_set_state (data->pipeline, GST_STATE_PAUSED); gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
else else if (data->target_state >= GST_STATE_PLAYING)
gst_element_set_state (data->pipeline, GST_STATE_PLAYING); gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
} }
static void clock_lost_cb (GstBus *bus, GstMessage *msg, CustomData *data) { static void clock_lost_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
if (data->target_state >= GST_STATE_PLAYING) {
gst_element_set_state (data->pipeline, GST_STATE_PAUSED); gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
gst_element_set_state (data->pipeline, GST_STATE_PLAYING); gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
} }
}
static void state_changed_cb (GstBus *bus, GstMessage *msg, CustomData *data) { static void state_changed_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
JNIEnv *env = get_jni_env (); JNIEnv *env = get_jni_env ();
@ -267,6 +271,7 @@ static void *app_function (void *userdata) {
/* Free resources */ /* Free resources */
g_main_context_unref (context); g_main_context_unref (context);
data->target_state = GST_STATE_NULL;
gst_element_set_state (data->pipeline, GST_STATE_NULL); gst_element_set_state (data->pipeline, GST_STATE_NULL);
gst_object_unref (data->vsink); gst_object_unref (data->vsink);
gst_object_unref (data->pipeline); gst_object_unref (data->pipeline);
@ -307,6 +312,7 @@ void gst_native_play (JNIEnv* env, jobject thiz) {
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
if (!data) return; if (!data) return;
GST_DEBUG ("Setting state to PLAYING"); GST_DEBUG ("Setting state to PLAYING");
data->target_state = GST_STATE_PLAYING;
data->is_live = (gst_element_set_state (data->pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_NO_PREROLL); data->is_live = (gst_element_set_state (data->pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_NO_PREROLL);
} }
@ -314,6 +320,7 @@ void gst_native_pause (JNIEnv* env, jobject thiz) {
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
if (!data) return; if (!data) return;
GST_DEBUG ("Setting state to PAUSED"); GST_DEBUG ("Setting state to PAUSED");
data->target_state = GST_STATE_PAUSED;
data->is_live = (gst_element_set_state (data->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL); data->is_live = (gst_element_set_state (data->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
} }