This commit is contained in:
Xavi Artigas 2012-10-29 12:10:36 +01:00
parent 73c3dbf35b
commit a67b8edbd9

View file

@ -25,22 +25,23 @@ GST_DEBUG_CATEGORY_STATIC (debug_category);
/* Structure to contain all our information, so we can pass it to callbacks */ /* Structure to contain all our information, so we can pass it to callbacks */
typedef struct _CustomData { typedef struct _CustomData {
jobject app; /* Application instance, used to call its methods. A global reference is kept. */ jobject app; /* Application instance, used to call its methods. A global reference is kept. */
GstElement *pipeline; /* The running pipeline */ GstElement *pipeline; /* The running pipeline */
GMainContext *context; /* GLib context used to run the main loop */ GMainContext *context; /* GLib context used to run the main loop */
GMainLoop *main_loop; /* GLib main loop */ GMainLoop *main_loop; /* GLib main loop */
gboolean initialized; /* To avoid informing the UI multiple times about the initialization */ gboolean initialized; /* To avoid informing the UI multiple times about the initialization */
ANativeWindow *native_window; /* The Android native window where video will be rendered */ ANativeWindow *native_window; /* The Android native window where video will be rendered */
GstState state, target_state; GstState state; /* Current pipeline state */
gint64 duration; GstState target_state; /* Desired pipeline state, to be set once buffering is complete */
gint64 desired_position; gint64 duration; /* Cached clip duration */
GstClockTime last_seek_time; gint64 desired_position; /* Position to seek to, once the pipeline is running */
gboolean is_live; GstClockTime last_seek_time; /* For seeking overflow prevention (throttling) */
gboolean is_live; /* Live streams do not use buffering */
} CustomData; } CustomData;
/* playbin2 flags */ /* playbin2 flags */
typedef enum { typedef enum {
GST_PLAY_FLAG_TEXT = (1 << 2) /* We want subtitle output */ GST_PLAY_FLAG_TEXT = (1 << 2) /* We want subtitle output */
} GstPlayFlags; } GstPlayFlags;
/* These global variables cache values which are not changing during execution */ /* These global variables cache values which are not changing during execution */
@ -106,6 +107,7 @@ static void set_ui_message (const gchar *message, CustomData *data) {
(*env)->DeleteLocalRef (env, jmessage); (*env)->DeleteLocalRef (env, jmessage);
} }
/* Tell the application what is the current position and clip duration */
static void set_current_ui_position (gint position, gint duration, CustomData *data) { static void set_current_ui_position (gint position, gint duration, CustomData *data) {
JNIEnv *env = get_jni_env (); JNIEnv *env = get_jni_env ();
(*env)->CallVoidMethod (env, data->app, set_current_position_method_id, position, duration); (*env)->CallVoidMethod (env, data->app, set_current_position_method_id, position, duration);
@ -115,6 +117,8 @@ static void set_current_ui_position (gint position, gint duration, CustomData *d
} }
} }
/* If we have pipeline and it is running, query the current position and clip duration and inform
* the application */
static gboolean refresh_ui (CustomData *data) { static gboolean refresh_ui (CustomData *data) {
GstFormat fmt = GST_FORMAT_TIME; GstFormat fmt = GST_FORMAT_TIME;
gint64 current = -1; gint64 current = -1;
@ -147,6 +151,8 @@ static gboolean delayed_seek_cb (CustomData *data) {
return FALSE; return FALSE;
} }
/* Perform seek, if we are not too close to the previous seek. Otherwise, schedule the seek for
* some time in the future. */
static void execute_seek (gint64 desired_position, CustomData *data) { static void execute_seek (gint64 desired_position, CustomData *data) {
gboolean res; gboolean res;
gint64 diff; gint64 diff;