拿掉無用的seek to功能
This commit is contained in:
parent
3e6d7e9e1c
commit
62503432b0
@ -16,5 +16,5 @@
|
|||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_16_PREVIEW" project-jdk-name="16" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="16" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
||||||
@ -24,13 +24,8 @@ GST_DEBUG_CATEGORY_STATIC (debug_category);
|
|||||||
# define SET_CUSTOM_DATA(env, thiz, fieldID, data) (*env)->SetLongField (env, thiz, fieldID, (jlong)(jint)data)
|
# define SET_CUSTOM_DATA(env, thiz, fieldID, data) (*env)->SetLongField (env, thiz, fieldID, (jlong)(jint)data)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Do not allow seeks to be performed closer than this distance. It is visually useless, and will probably
|
|
||||||
* confuse some demuxers. */
|
|
||||||
#define SEEK_MIN_DELAY (500 * GST_MSECOND)
|
|
||||||
|
|
||||||
/* 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 */
|
||||||
@ -39,15 +34,11 @@ typedef struct _CustomData
|
|||||||
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; /* Current pipeline state */
|
GstState state; /* Current pipeline state */
|
||||||
GstState target_state; /* Desired pipeline state, to be set once buffering is complete */
|
GstState target_state; /* Desired pipeline state, to be set once buffering is complete */
|
||||||
gint64 duration; /* Cached clip duration */
|
|
||||||
gint64 desired_position; /* Position to seek to, once the pipeline is running */
|
|
||||||
GstClockTime last_seek_time; /* For seeking overflow prevention (throttling) */
|
|
||||||
gboolean is_live; /* Live streams do not use buffering */
|
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;
|
||||||
|
|
||||||
@ -57,7 +48,6 @@ static pthread_key_t current_jni_env;
|
|||||||
static JavaVM *java_vm;
|
static JavaVM *java_vm;
|
||||||
static jfieldID custom_data_field_id;
|
static jfieldID custom_data_field_id;
|
||||||
static jmethodID set_message_method_id;
|
static jmethodID set_message_method_id;
|
||||||
static jmethodID set_current_position_method_id;
|
|
||||||
static jmethodID on_gstreamer_initialized_method_id;
|
static jmethodID on_gstreamer_initialized_method_id;
|
||||||
static jmethodID on_media_size_changed_method_id;
|
static jmethodID on_media_size_changed_method_id;
|
||||||
|
|
||||||
@ -66,16 +56,16 @@ static jmethodID on_media_size_changed_method_id;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Register this thread with the VM */
|
/* Register this thread with the VM */
|
||||||
static JNIEnv *attach_current_thread (void){
|
static JNIEnv *attach_current_thread(void) {
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
JavaVMAttachArgs args;
|
JavaVMAttachArgs args;
|
||||||
|
|
||||||
GST_DEBUG ("Attaching thread %p", g_thread_self ());
|
GST_DEBUG ("Attaching thread %p", g_thread_self());
|
||||||
args.version = JNI_VERSION_1_4;
|
args.version = JNI_VERSION_1_4;
|
||||||
args.name = NULL;
|
args.name = NULL;
|
||||||
args.group = NULL;
|
args.group = NULL;
|
||||||
|
|
||||||
if ((*java_vm)->AttachCurrentThread (java_vm, &env, &args) < 0) {
|
if ((*java_vm)->AttachCurrentThread(java_vm, &env, &args) < 0) {
|
||||||
GST_ERROR ("Failed to attach current thread");
|
GST_ERROR ("Failed to attach current thread");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -84,233 +74,132 @@ static JNIEnv *attach_current_thread (void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Unregister this thread from the VM */
|
/* Unregister this thread from the VM */
|
||||||
static void detach_current_thread (void *env) {
|
static void detach_current_thread(void *env) {
|
||||||
GST_DEBUG ("Detaching thread %p", g_thread_self ());
|
GST_DEBUG ("Detaching thread %p", g_thread_self());
|
||||||
(*java_vm)->DetachCurrentThread (java_vm);
|
(*java_vm)->DetachCurrentThread(java_vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve the JNI environment for this thread */
|
/* Retrieve the JNI environment for this thread */
|
||||||
static JNIEnv *get_jni_env (void) {
|
static JNIEnv *get_jni_env(void) {
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
|
|
||||||
if ((env = pthread_getspecific (current_jni_env)) == NULL) {
|
if ((env = pthread_getspecific(current_jni_env)) == NULL) {
|
||||||
env = attach_current_thread ();
|
env = attach_current_thread();
|
||||||
pthread_setspecific (current_jni_env, env);
|
pthread_setspecific(current_jni_env, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Change the content of the UI's TextView */
|
/* Change the content of the UI's TextView */
|
||||||
static void set_ui_message (const gchar * message, CustomData * data) {
|
static void set_ui_message(const gchar *message, CustomData *data) {
|
||||||
JNIEnv *env = get_jni_env ();
|
JNIEnv *env = get_jni_env();
|
||||||
GST_DEBUG ("Setting message to: %s", message);
|
GST_DEBUG ("Setting message to: %s", message);
|
||||||
jstring jmessage = (*env)->NewStringUTF (env, message);
|
jstring jmessage = (*env)->NewStringUTF(env, message);
|
||||||
(*env)->CallVoidMethod (env, data->app, set_message_method_id, jmessage);
|
(*env)->CallVoidMethod(env, data->app, set_message_method_id, jmessage);
|
||||||
if ((*env)->ExceptionCheck (env)) {
|
if ((*env)->ExceptionCheck(env)) {
|
||||||
GST_ERROR ("Failed to call Java method");
|
GST_ERROR ("Failed to call Java method");
|
||||||
(*env)->ExceptionClear (env);
|
(*env)->ExceptionClear(env);
|
||||||
}
|
}
|
||||||
(*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) {
|
|
||||||
JNIEnv *env = get_jni_env ();
|
|
||||||
(*env)->CallVoidMethod (env, data->app, set_current_position_method_id,
|
|
||||||
position, duration);
|
|
||||||
if ((*env)->ExceptionCheck (env)) {
|
|
||||||
GST_ERROR ("Failed to call Java method");
|
|
||||||
(*env)->ExceptionClear (env);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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) {
|
|
||||||
gint64 current = -1;
|
|
||||||
gint64 position;
|
|
||||||
|
|
||||||
/* We do not want to update anything unless we have a working pipeline in the PAUSED or PLAYING state */
|
|
||||||
if (!data || !data->pipeline || data->state < GST_STATE_PAUSED)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
/* If we didn't know it yet, query the stream duration */
|
|
||||||
if (!GST_CLOCK_TIME_IS_VALID (data->duration)) {
|
|
||||||
if (!gst_element_query_duration (data->pipeline, GST_FORMAT_TIME,
|
|
||||||
&data->duration)) {
|
|
||||||
/*GST_WARNING
|
|
||||||
("Could not query current duration (normal for still pictures)");*/
|
|
||||||
data->duration = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gst_element_query_position (data->pipeline, GST_FORMAT_TIME, &position)) {
|
|
||||||
/*GST_WARNING
|
|
||||||
("Could not query current position (normal for still pictures)");*/
|
|
||||||
position = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Java expects these values in milliseconds, and GStreamer provides nanoseconds */
|
|
||||||
set_current_ui_position (position / GST_MSECOND, data->duration / GST_MSECOND,
|
|
||||||
data);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Forward declaration for the delayed seek callback */
|
|
||||||
static gboolean delayed_seek_cb (CustomData * data);
|
|
||||||
|
|
||||||
/* 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) {
|
|
||||||
gint64 diff;
|
|
||||||
|
|
||||||
if (desired_position == GST_CLOCK_TIME_NONE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
diff = gst_util_get_timestamp () - data->last_seek_time;
|
|
||||||
|
|
||||||
if (GST_CLOCK_TIME_IS_VALID (data->last_seek_time) && diff < SEEK_MIN_DELAY) {
|
|
||||||
/* The previous seek was too close, delay this one */
|
|
||||||
GSource *timeout_source;
|
|
||||||
|
|
||||||
if (data->desired_position == GST_CLOCK_TIME_NONE) {
|
|
||||||
/* There was no previous seek scheduled. Setup a timer for some time in the future */
|
|
||||||
timeout_source =
|
|
||||||
g_timeout_source_new ((SEEK_MIN_DELAY - diff) / GST_MSECOND);
|
|
||||||
g_source_set_callback (timeout_source, (GSourceFunc) delayed_seek_cb,
|
|
||||||
data, NULL);
|
|
||||||
g_source_attach (timeout_source, data->context);
|
|
||||||
g_source_unref (timeout_source);
|
|
||||||
}
|
|
||||||
/* Update the desired seek position. If multiple petitions are received before it is time
|
|
||||||
* to perform a seek, only the last one is remembered. */
|
|
||||||
data->desired_position = desired_position;
|
|
||||||
GST_DEBUG ("Throttling seek to %" GST_TIME_FORMAT ", will be in %"
|
|
||||||
GST_TIME_FORMAT, GST_TIME_ARGS (desired_position),
|
|
||||||
GST_TIME_ARGS (SEEK_MIN_DELAY - diff));
|
|
||||||
} else {
|
|
||||||
/* Perform the seek now */
|
|
||||||
GST_DEBUG ("Seeking to %" GST_TIME_FORMAT,
|
|
||||||
GST_TIME_ARGS (desired_position));
|
|
||||||
data->last_seek_time = gst_util_get_timestamp ();
|
|
||||||
gst_element_seek_simple (data->pipeline, GST_FORMAT_TIME,
|
|
||||||
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, desired_position);
|
|
||||||
data->desired_position = GST_CLOCK_TIME_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Delayed seek callback. This gets called by the timer setup in the above function. */
|
|
||||||
static gboolean delayed_seek_cb (CustomData * data) {
|
|
||||||
GST_DEBUG ("Doing delayed seek to %" GST_TIME_FORMAT,
|
|
||||||
GST_TIME_ARGS (data->desired_position));
|
|
||||||
execute_seek (data->desired_position, data);
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve errors from the bus and show them on the UI */
|
/* Retrieve errors from the bus and show them on the UI */
|
||||||
static void error_cb (GstBus * bus, GstMessage * msg, CustomData * data) {
|
static void error_cb(GstBus *bus, GstMessage *msg, CustomData *data) {
|
||||||
GError *err;
|
GError *err;
|
||||||
gchar *debug_info;
|
gchar *debug_info;
|
||||||
gchar *message_string;
|
gchar *message_string;
|
||||||
|
|
||||||
gst_message_parse_error (msg, &err, &debug_info);
|
gst_message_parse_error(msg, &err, &debug_info);
|
||||||
message_string =
|
message_string =
|
||||||
g_strdup_printf ("Error received from element %s: %s",
|
g_strdup_printf("Error received from element %s: %s",
|
||||||
GST_OBJECT_NAME (msg->src), err->message);
|
GST_OBJECT_NAME (msg->src), err->message);
|
||||||
g_clear_error (&err);
|
g_clear_error(&err);
|
||||||
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;
|
data->target_state = GST_STATE_NULL;
|
||||||
gst_element_set_state (data->pipeline, GST_STATE_NULL);
|
gst_element_set_state(data->pipeline, GST_STATE_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called when the End Of the Stream is reached. Just move to the beginning of the media and pause. */
|
/* Called when the End Of the Stream is reached. Just move to the beginning of the media and pause. */
|
||||||
static void eos_cb (GstBus * bus, GstMessage * msg, CustomData * data) {
|
static void eos_cb(GstBus *bus, GstMessage *msg, CustomData *data) {
|
||||||
data->target_state = GST_STATE_PAUSED;
|
data->target_state = GST_STATE_PAUSED;
|
||||||
data->is_live |=
|
data->is_live |= (gst_element_set_state(data->pipeline,
|
||||||
(gst_element_set_state (data->pipeline,
|
|
||||||
GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
|
GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
|
||||||
execute_seek (0, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called when the duration of the media changes. Just mark it as unknown, so we re-query it in the next UI refresh. */
|
|
||||||
static void duration_cb (GstBus * bus, GstMessage * msg, CustomData * data) {
|
|
||||||
data->duration = GST_CLOCK_TIME_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called when buffering messages are received. We inform the UI about the current buffering level and
|
/* Called when buffering messages are received. We inform the UI about the current buffering level and
|
||||||
* keep the pipeline paused until 100% buffering is reached. At that point, set the desired state. */
|
* keep the pipeline paused until 100% buffering is reached. At that point, set the desired state. */
|
||||||
static void buffering_cb (GstBus * bus, GstMessage * msg, CustomData * data) {
|
static void buffering_cb(GstBus *bus, GstMessage *msg, CustomData *data) {
|
||||||
gint percent;
|
gint percent;
|
||||||
|
|
||||||
if (data->is_live)
|
if (data->is_live)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gst_message_parse_buffering (msg, &percent);
|
gst_message_parse_buffering(msg, &percent);
|
||||||
if (percent < 100 && data->target_state >= GST_STATE_PAUSED) {
|
if (percent < 100 && data->target_state >= GST_STATE_PAUSED) {
|
||||||
gchar *message_string = g_strdup_printf ("Buffering %d%%", percent);
|
gchar *message_string = g_strdup_printf("Buffering %d%%", percent);
|
||||||
gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
|
gst_element_set_state(data->pipeline, GST_STATE_PAUSED);
|
||||||
set_ui_message (message_string, data);
|
set_ui_message(message_string, data);
|
||||||
g_free (message_string);
|
g_free(message_string);
|
||||||
} else if (data->target_state >= GST_STATE_PLAYING) {
|
} 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);
|
||||||
} else if (data->target_state >= GST_STATE_PAUSED) {
|
} else if (data->target_state >= GST_STATE_PAUSED) {
|
||||||
set_ui_message ("Buffering complete", data);
|
set_ui_message("Buffering complete", data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called when the clock is lost */
|
/* Called when the clock is lost */
|
||||||
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Retrieve the video sink's Caps and tell the application about the media size */
|
/* Retrieve the video sink's Caps and tell the application about the media size */
|
||||||
static void check_media_size (CustomData * data) {
|
static void check_media_size(CustomData *data) {
|
||||||
JNIEnv *env = get_jni_env ();
|
JNIEnv *env = get_jni_env();
|
||||||
GstElement *video_sink;
|
GstElement *video_sink;
|
||||||
GstPad *video_sink_pad;
|
GstPad *video_sink_pad;
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
|
|
||||||
/* Retrieve the Caps at the entrance of the video sink */
|
/* Retrieve the Caps at the entrance of the video sink */
|
||||||
g_object_get (data->pipeline, "video-sink", &video_sink, NULL);
|
g_object_get(data->pipeline, "video-sink", &video_sink, NULL);
|
||||||
video_sink_pad = gst_element_get_static_pad (video_sink, "sink");
|
video_sink_pad = gst_element_get_static_pad(video_sink, "sink");
|
||||||
caps = gst_pad_get_current_caps (video_sink_pad);
|
caps = gst_pad_get_current_caps(video_sink_pad);
|
||||||
|
|
||||||
if (gst_video_info_from_caps (&info, caps)) {
|
if (gst_video_info_from_caps(&info, caps)) {
|
||||||
info.width = info.width * info.par_n / info.par_d;
|
info.width = info.width * info.par_n / info.par_d;
|
||||||
GST_DEBUG ("Media size is %dx%d, notifying application", info.width,
|
GST_DEBUG ("Media size is %dx%d, notifying application", info.width,
|
||||||
info.height);
|
info.height);
|
||||||
|
|
||||||
(*env)->CallVoidMethod (env, data->app, on_media_size_changed_method_id,
|
(*env)->CallVoidMethod(env, data->app, on_media_size_changed_method_id,
|
||||||
(jint) info.width, (jint) info.height);
|
(jint) info.width, (jint) info.height);
|
||||||
if ((*env)->ExceptionCheck (env)) {
|
if ((*env)->ExceptionCheck(env)) {
|
||||||
GST_ERROR ("Failed to call Java method");
|
GST_ERROR ("Failed to call Java method");
|
||||||
(*env)->ExceptionClear (env);
|
(*env)->ExceptionClear(env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref(caps);
|
||||||
gst_object_unref (video_sink_pad);
|
gst_object_unref(video_sink_pad);
|
||||||
gst_object_unref (video_sink);
|
gst_object_unref(video_sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Notify UI about pipeline state changes */
|
/* Notify UI about pipeline state changes */
|
||||||
static void state_changed_cb (GstBus * bus, GstMessage * msg, CustomData * data) {
|
static void state_changed_cb(GstBus *bus, GstMessage *msg, CustomData *data) {
|
||||||
GstState old_state, new_state, pending_state;
|
GstState old_state, new_state, pending_state;
|
||||||
gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
|
gst_message_parse_state_changed(msg, &old_state, &new_state, &pending_state);
|
||||||
/* Only pay attention to messages coming from the pipeline, not its children */
|
/* Only pay attention to messages coming from the pipeline, not its children */
|
||||||
if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data->pipeline)) {
|
if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data->pipeline)) {
|
||||||
data->state = new_state;
|
data->state = new_state;
|
||||||
gchar *message = g_strdup_printf ("State changed to %s",
|
gchar *message = g_strdup_printf("State changed to %s",
|
||||||
gst_element_state_get_name (new_state));
|
gst_element_state_get_name(new_state));
|
||||||
set_ui_message (message, data);
|
set_ui_message(message, data);
|
||||||
g_free (message);
|
g_free(message);
|
||||||
|
|
||||||
if (new_state == GST_STATE_NULL || new_state == GST_STATE_READY)
|
if (new_state == GST_STATE_NULL || new_state == GST_STATE_READY)
|
||||||
data->is_live = FALSE;
|
data->is_live = FALSE;
|
||||||
@ -318,39 +207,35 @@ static void state_changed_cb (GstBus * bus, GstMessage * msg, CustomData * data)
|
|||||||
/* The Ready to Paused state change is particularly interesting: */
|
/* The Ready to Paused state change is particularly interesting: */
|
||||||
if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
|
if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
|
||||||
/* By now the sink already knows the media size */
|
/* By now the sink already knows the media size */
|
||||||
check_media_size (data);
|
check_media_size(data);
|
||||||
|
|
||||||
/* If there was a scheduled seek, perform it now that we have moved to the Paused state */
|
|
||||||
if (GST_CLOCK_TIME_IS_VALID (data->desired_position))
|
|
||||||
execute_seek (data->desired_position, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if all conditions are met to report GStreamer as initialized.
|
/* Check if all conditions are met to report GStreamer as initialized.
|
||||||
* These conditions will change depending on the application */
|
* These conditions will change depending on the application */
|
||||||
static void check_initialization_complete (CustomData * data) {
|
static void check_initialization_complete(CustomData *data) {
|
||||||
JNIEnv *env = get_jni_env ();
|
JNIEnv *env = get_jni_env();
|
||||||
if (!data->initialized && data->native_window && data->main_loop) {
|
if (!data->initialized && data->native_window && data->main_loop) {
|
||||||
GST_DEBUG
|
GST_DEBUG
|
||||||
("Initialization complete, notifying application. native_window:%p main_loop:%p",
|
("Initialization complete, notifying application. native_window:%p main_loop:%p",
|
||||||
data->native_window, data->main_loop);
|
data->native_window, data->main_loop);
|
||||||
|
|
||||||
/* The main loop is running and we received a native window, inform the sink about it */
|
/* The main loop is running and we received a native window, inform the sink about it */
|
||||||
gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->pipeline),
|
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY (data->pipeline),
|
||||||
(guintptr) data->native_window);
|
(guintptr) data->native_window);
|
||||||
|
|
||||||
(*env)->CallVoidMethod (env, data->app, on_gstreamer_initialized_method_id);
|
(*env)->CallVoidMethod(env, data->app, on_gstreamer_initialized_method_id);
|
||||||
if ((*env)->ExceptionCheck (env)) {
|
if ((*env)->ExceptionCheck(env)) {
|
||||||
GST_ERROR ("Failed to call Java method");
|
GST_ERROR ("Failed to call Java method");
|
||||||
(*env)->ExceptionClear (env);
|
(*env)->ExceptionClear(env);
|
||||||
}
|
}
|
||||||
data->initialized = TRUE;
|
data->initialized = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Main method for the native code. This is executed on its own thread. */
|
/* Main method for the native code. This is executed on its own thread. */
|
||||||
static void *app_function (void *userdata) {
|
static void *app_function(void *userdata) {
|
||||||
JavaVMAttachArgs args;
|
JavaVMAttachArgs args;
|
||||||
GstBus *bus;
|
GstBus *bus;
|
||||||
CustomData *data = (CustomData *) userdata;
|
CustomData *data = (CustomData *) userdata;
|
||||||
@ -362,70 +247,62 @@ static void *app_function (void *userdata) {
|
|||||||
GST_DEBUG ("Creating pipeline in CustomData at %p", data);
|
GST_DEBUG ("Creating pipeline in CustomData at %p", data);
|
||||||
|
|
||||||
/* Create our own GLib Main Context and make it the default one */
|
/* Create our own GLib Main Context and make it the default one */
|
||||||
data->context = g_main_context_new ();
|
data->context = g_main_context_new();
|
||||||
g_main_context_push_thread_default (data->context);
|
g_main_context_push_thread_default(data->context);
|
||||||
|
|
||||||
/* Build pipeline */
|
/* Build pipeline */
|
||||||
data->pipeline = gst_parse_launch ("playbin", &error);
|
data->pipeline = gst_parse_launch("playbin", &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
gchar *message =
|
gchar *message =
|
||||||
g_strdup_printf ("Unable to build pipeline: %s", error->message);
|
g_strdup_printf("Unable to build pipeline: %s", error->message);
|
||||||
g_clear_error (&error);
|
g_clear_error(&error);
|
||||||
set_ui_message (message, data);
|
set_ui_message(message, data);
|
||||||
g_free (message);
|
g_free(message);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable subtitles */
|
/* Disable subtitles */
|
||||||
g_object_get (data->pipeline, "flags", &flags, NULL);
|
g_object_get(data->pipeline, "flags", &flags, NULL);
|
||||||
flags &= ~GST_PLAY_FLAG_TEXT;
|
flags &= ~GST_PLAY_FLAG_TEXT;
|
||||||
g_object_set (data->pipeline, "flags", flags, NULL);
|
g_object_set(data->pipeline, "flags", flags, NULL);
|
||||||
|
|
||||||
/* Set the pipeline to READY, so it can already accept a window handle, if we have one */
|
/* Set the pipeline to READY, so it can already accept a window handle, if we have one */
|
||||||
data->target_state = GST_STATE_READY;
|
data->target_state = GST_STATE_READY;
|
||||||
gst_element_set_state (data->pipeline, GST_STATE_READY);
|
gst_element_set_state(data->pipeline, GST_STATE_READY);
|
||||||
|
|
||||||
/* Instruct the bus to emit signals for each received message, and connect to the interesting signals */
|
/* Instruct the bus to emit signals for each received message, and connect to the interesting signals */
|
||||||
bus = gst_element_get_bus (data->pipeline);
|
bus = gst_element_get_bus(data->pipeline);
|
||||||
bus_source = gst_bus_create_watch (bus);
|
bus_source = gst_bus_create_watch(bus);
|
||||||
g_source_set_callback (bus_source, (GSourceFunc) gst_bus_async_signal_func,
|
g_source_set_callback(bus_source, (GSourceFunc) gst_bus_async_signal_func,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
g_source_attach (bus_source, data->context);
|
g_source_attach(bus_source, data->context);
|
||||||
g_source_unref (bus_source);
|
g_source_unref(bus_source);
|
||||||
g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,
|
g_signal_connect (G_OBJECT(bus), "message::error", (GCallback) error_cb,
|
||||||
data);
|
data);
|
||||||
g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb, data);
|
g_signal_connect (G_OBJECT(bus), "message::eos", (GCallback) eos_cb, data);
|
||||||
g_signal_connect (G_OBJECT (bus), "message::state-changed",
|
g_signal_connect (G_OBJECT(bus), "message::state-changed",
|
||||||
(GCallback) state_changed_cb, data);
|
(GCallback) state_changed_cb, data);
|
||||||
g_signal_connect (G_OBJECT (bus), "message::duration",
|
g_signal_connect (G_OBJECT(bus), "message::buffering",
|
||||||
(GCallback) duration_cb, data);
|
|
||||||
g_signal_connect (G_OBJECT (bus), "message::buffering",
|
|
||||||
(GCallback) buffering_cb, data);
|
(GCallback) buffering_cb, data);
|
||||||
g_signal_connect (G_OBJECT (bus), "message::clock-lost",
|
g_signal_connect (G_OBJECT(bus), "message::clock-lost",
|
||||||
(GCallback) clock_lost_cb, data);
|
(GCallback) clock_lost_cb, data);
|
||||||
gst_object_unref (bus);
|
gst_object_unref(bus);
|
||||||
|
|
||||||
/* Register a function that GLib will call 4 times per second */
|
|
||||||
timeout_source = g_timeout_source_new (250);
|
|
||||||
g_source_set_callback (timeout_source, (GSourceFunc) refresh_ui, data, NULL);
|
|
||||||
g_source_attach (timeout_source, data->context);
|
|
||||||
g_source_unref (timeout_source);
|
|
||||||
|
|
||||||
/* Create a GLib Main Loop and set it to run */
|
/* Create a GLib Main Loop and set it to run */
|
||||||
GST_DEBUG ("Entering main loop... (CustomData:%p)", data);
|
GST_DEBUG ("Entering main loop... (CustomData:%p)", data);
|
||||||
data->main_loop = g_main_loop_new (data->context, FALSE);
|
data->main_loop = g_main_loop_new(data->context, FALSE);
|
||||||
check_initialization_complete (data);
|
check_initialization_complete(data);
|
||||||
g_main_loop_run (data->main_loop);
|
g_main_loop_run(data->main_loop);
|
||||||
GST_DEBUG ("Exited main loop");
|
GST_DEBUG ("Exited main loop");
|
||||||
g_main_loop_unref (data->main_loop);
|
g_main_loop_unref(data->main_loop);
|
||||||
data->main_loop = NULL;
|
data->main_loop = NULL;
|
||||||
|
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
g_main_context_pop_thread_default (data->context);
|
g_main_context_pop_thread_default(data->context);
|
||||||
g_main_context_unref (data->context);
|
g_main_context_unref(data->context);
|
||||||
data->target_state = GST_STATE_NULL;
|
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->pipeline);
|
gst_object_unref(data->pipeline);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -435,135 +312,109 @@ static void *app_function (void *userdata) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Instruct the native code to create its internal data structure, pipeline and thread */
|
/* Instruct the native code to create its internal data structure, pipeline and thread */
|
||||||
static void gst_native_init (JNIEnv * env, jobject thiz) {
|
static void gst_native_init(JNIEnv *env, jobject thiz) {
|
||||||
CustomData *data = g_new0 (CustomData, 1);
|
CustomData *data = g_new0 (CustomData, 1);
|
||||||
data->desired_position = GST_CLOCK_TIME_NONE;
|
|
||||||
data->last_seek_time = GST_CLOCK_TIME_NONE;
|
|
||||||
SET_CUSTOM_DATA (env, thiz, custom_data_field_id, data);
|
SET_CUSTOM_DATA (env, thiz, custom_data_field_id, data);
|
||||||
GST_DEBUG_CATEGORY_INIT (debug_category, "player", 0,
|
GST_DEBUG_CATEGORY_INIT (debug_category, "player", 0,
|
||||||
"Android tutorial 5");
|
"Android tutorial 5");
|
||||||
gst_debug_set_threshold_for_name ("player", GST_LEVEL_DEBUG);
|
gst_debug_set_threshold_for_name("player", GST_LEVEL_DEBUG);
|
||||||
GST_DEBUG ("Created CustomData at %p", data);
|
GST_DEBUG ("Created CustomData at %p", data);
|
||||||
data->app = (*env)->NewGlobalRef (env, thiz);
|
data->app = (*env)->NewGlobalRef(env, thiz);
|
||||||
GST_DEBUG ("Created GlobalRef for app object at %p", data->app);
|
GST_DEBUG ("Created GlobalRef for app object at %p", data->app);
|
||||||
pthread_create (&gst_app_thread, NULL, &app_function, data);
|
pthread_create(&gst_app_thread, NULL, &app_function, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Quit the main loop, remove the native thread and free resources */
|
/* Quit the main loop, remove the native thread and free resources */
|
||||||
static void gst_native_finalize (JNIEnv * env, jobject thiz) {
|
static void gst_native_finalize(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)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
GST_DEBUG ("Quitting main loop...");
|
GST_DEBUG ("Quitting main loop...");
|
||||||
g_main_loop_quit (data->main_loop);
|
g_main_loop_quit(data->main_loop);
|
||||||
GST_DEBUG ("Waiting for thread to finish...");
|
GST_DEBUG ("Waiting for thread to finish...");
|
||||||
pthread_join (gst_app_thread, NULL);
|
pthread_join(gst_app_thread, NULL);
|
||||||
GST_DEBUG ("Deleting GlobalRef for app object at %p", data->app);
|
GST_DEBUG ("Deleting GlobalRef for app object at %p", data->app);
|
||||||
(*env)->DeleteGlobalRef (env, data->app);
|
(*env)->DeleteGlobalRef(env, data->app);
|
||||||
GST_DEBUG ("Freeing CustomData at %p", data);
|
GST_DEBUG ("Freeing CustomData at %p", data);
|
||||||
g_free (data);
|
g_free(data);
|
||||||
SET_CUSTOM_DATA (env, thiz, custom_data_field_id, NULL);
|
SET_CUSTOM_DATA (env, thiz, custom_data_field_id, NULL);
|
||||||
GST_DEBUG ("Done finalizing");
|
GST_DEBUG ("Done finalizing");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set playbin2's URI */
|
/* Set playbin2's URI */
|
||||||
void gst_native_set_uri (JNIEnv * env, jobject thiz, jstring uri) {
|
void gst_native_set_uri(JNIEnv *env, jobject thiz, jstring uri) {
|
||||||
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
|
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
|
||||||
if (!data || !data->pipeline)
|
if (!data || !data->pipeline)
|
||||||
return;
|
return;
|
||||||
const gchar *char_uri = (*env)->GetStringUTFChars (env, uri, NULL);
|
const gchar *char_uri = (*env)->GetStringUTFChars(env, uri, NULL);
|
||||||
GST_DEBUG ("Setting URI to %s", char_uri);
|
GST_DEBUG ("Setting URI to %s", char_uri);
|
||||||
if (data->target_state >= GST_STATE_READY)
|
if (data->target_state >= GST_STATE_READY)
|
||||||
gst_element_set_state (data->pipeline, GST_STATE_READY);
|
gst_element_set_state(data->pipeline, GST_STATE_READY);
|
||||||
g_object_set (data->pipeline, "uri", char_uri, NULL);
|
g_object_set(data->pipeline, "uri", char_uri, NULL);
|
||||||
(*env)->ReleaseStringUTFChars (env, uri, char_uri);
|
(*env)->ReleaseStringUTFChars(env, uri, char_uri);
|
||||||
data->duration = GST_CLOCK_TIME_NONE;
|
|
||||||
data->is_live |=
|
data->is_live |=
|
||||||
(gst_element_set_state (data->pipeline,
|
(gst_element_set_state(data->pipeline, data->target_state) == GST_STATE_CHANGE_NO_PREROLL);
|
||||||
data->target_state) == GST_STATE_CHANGE_NO_PREROLL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set pipeline to PLAYING state */
|
/* Set pipeline to PLAYING state */
|
||||||
static void gst_native_play (JNIEnv * env, jobject thiz) {
|
static 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)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
GST_DEBUG ("Setting state to PLAYING");
|
GST_DEBUG ("Setting state to PLAYING");
|
||||||
data->target_state = GST_STATE_PLAYING;
|
data->target_state = GST_STATE_PLAYING;
|
||||||
data->is_live |=
|
data->is_live |= (gst_element_set_state(data->pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_NO_PREROLL);
|
||||||
(gst_element_set_state (data->pipeline,
|
|
||||||
GST_STATE_PLAYING) == GST_STATE_CHANGE_NO_PREROLL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set pipeline to PAUSED state */
|
/* Set pipeline to PAUSED state */
|
||||||
static void gst_native_pause (JNIEnv * env, jobject thiz) {
|
static 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)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
GST_DEBUG ("Setting state to PAUSED");
|
GST_DEBUG ("Setting state to PAUSED");
|
||||||
data->target_state = GST_STATE_PAUSED;
|
data->target_state = GST_STATE_PAUSED;
|
||||||
data->is_live |=
|
data->is_live |=(gst_element_set_state(data->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
|
||||||
(gst_element_set_state (data->pipeline,
|
|
||||||
GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Instruct the pipeline to seek to a different position */
|
|
||||||
void gst_native_set_position (JNIEnv * env, jobject thiz, int milliseconds) {
|
|
||||||
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
|
|
||||||
if (!data)
|
|
||||||
return;
|
|
||||||
gint64 desired_position = (gint64) (milliseconds * GST_MSECOND);
|
|
||||||
if (data->state >= GST_STATE_PAUSED) {
|
|
||||||
execute_seek (desired_position, data);
|
|
||||||
} else {
|
|
||||||
GST_DEBUG ("Scheduling seek to %" GST_TIME_FORMAT " for later",
|
|
||||||
GST_TIME_ARGS (desired_position));
|
|
||||||
data->desired_position = desired_position;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Static class initializer: retrieve method and field IDs */
|
/* Static class initializer: retrieve method and field IDs */
|
||||||
static jboolean gst_native_class_init (JNIEnv * env, jclass klass) {
|
static jboolean gst_native_class_init(JNIEnv *env, jclass klass) {
|
||||||
custom_data_field_id =
|
custom_data_field_id =
|
||||||
(*env)->GetFieldID (env, klass, "native_custom_data", "J");
|
(*env)->GetFieldID(env, klass, "native_custom_data", "J");
|
||||||
set_message_method_id =
|
set_message_method_id =
|
||||||
(*env)->GetMethodID (env, klass, "setMessage", "(Ljava/lang/String;)V");
|
(*env)->GetMethodID(env, klass, "setMessage", "(Ljava/lang/String;)V");
|
||||||
set_current_position_method_id =
|
|
||||||
(*env)->GetMethodID (env, klass, "setCurrentPosition", "(II)V");
|
|
||||||
on_gstreamer_initialized_method_id =
|
on_gstreamer_initialized_method_id =
|
||||||
(*env)->GetMethodID (env, klass, "onGStreamerInitialized", "()V");
|
(*env)->GetMethodID(env, klass, "onGStreamerInitialized", "()V");
|
||||||
on_media_size_changed_method_id =
|
on_media_size_changed_method_id =
|
||||||
(*env)->GetMethodID (env, klass, "onMediaSizeChanged", "(II)V");
|
(*env)->GetMethodID(env, klass, "onMediaSizeChanged", "(II)V");
|
||||||
|
|
||||||
if (!custom_data_field_id || !set_message_method_id
|
if (!custom_data_field_id || !set_message_method_id
|
||||||
|| !on_gstreamer_initialized_method_id || !on_media_size_changed_method_id
|
|| !on_gstreamer_initialized_method_id || !on_media_size_changed_method_id) {
|
||||||
|| !set_current_position_method_id) {
|
|
||||||
/* We emit this message through the Android log instead of the GStreamer log because the later
|
/* We emit this message through the Android log instead of the GStreamer log because the later
|
||||||
* has not been initialized yet.
|
* has not been initialized yet.
|
||||||
*/
|
*/
|
||||||
__android_log_print (ANDROID_LOG_ERROR, "tutorial-4",
|
__android_log_print(ANDROID_LOG_ERROR, "tutorial-4",
|
||||||
"The calling class does not implement all necessary interface methods");
|
"The calling class does not implement all necessary interface methods");
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gst_native_surface_init (JNIEnv * env, jobject thiz, jobject surface) {
|
static void gst_native_surface_init(JNIEnv *env, jobject thiz, jobject surface) {
|
||||||
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
|
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
|
||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
ANativeWindow *new_native_window = ANativeWindow_fromSurface (env, surface);
|
ANativeWindow *new_native_window = ANativeWindow_fromSurface(env, surface);
|
||||||
GST_DEBUG ("Received surface %p (native window %p)", surface,
|
GST_DEBUG ("Received surface %p (native window %p)", surface,
|
||||||
new_native_window);
|
new_native_window);
|
||||||
|
|
||||||
if (data->native_window) {
|
if (data->native_window) {
|
||||||
ANativeWindow_release (data->native_window);
|
ANativeWindow_release(data->native_window);
|
||||||
if (data->native_window == new_native_window) {
|
if (data->native_window == new_native_window) {
|
||||||
GST_DEBUG ("New native window is the same as the previous one %p",
|
GST_DEBUG ("New native window is the same as the previous one %p",
|
||||||
data->native_window);
|
data->native_window);
|
||||||
if (data->pipeline) {
|
if (data->pipeline) {
|
||||||
gst_video_overlay_expose (GST_VIDEO_OVERLAY (data->pipeline));
|
gst_video_overlay_expose(GST_VIDEO_OVERLAY (data->pipeline));
|
||||||
gst_video_overlay_expose (GST_VIDEO_OVERLAY (data->pipeline));
|
gst_video_overlay_expose(GST_VIDEO_OVERLAY (data->pipeline));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -573,22 +424,22 @@ static void gst_native_surface_init (JNIEnv * env, jobject thiz, jobject surface
|
|||||||
}
|
}
|
||||||
data->native_window = new_native_window;
|
data->native_window = new_native_window;
|
||||||
|
|
||||||
check_initialization_complete (data);
|
check_initialization_complete(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gst_native_surface_finalize (JNIEnv * env, jobject thiz) {
|
static void gst_native_surface_finalize(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)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
GST_DEBUG ("Releasing Native Window %p", data->native_window);
|
GST_DEBUG ("Releasing Native Window %p", data->native_window);
|
||||||
|
|
||||||
if (data->pipeline) {
|
if (data->pipeline) {
|
||||||
gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->pipeline),
|
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY (data->pipeline),
|
||||||
(guintptr) NULL);
|
(guintptr) NULL);
|
||||||
gst_element_set_state (data->pipeline, GST_STATE_READY);
|
gst_element_set_state(data->pipeline, GST_STATE_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
ANativeWindow_release (data->native_window);
|
ANativeWindow_release(data->native_window);
|
||||||
data->native_window = NULL;
|
data->native_window = NULL;
|
||||||
data->initialized = FALSE;
|
data->initialized = FALSE;
|
||||||
}
|
}
|
||||||
@ -600,7 +451,6 @@ static JNINativeMethod native_methods[] = {
|
|||||||
{"nativeSetUri", "(Ljava/lang/String;)V", (void *) gst_native_set_uri},
|
{"nativeSetUri", "(Ljava/lang/String;)V", (void *) gst_native_set_uri},
|
||||||
{"nativePlay", "()V", (void *) gst_native_play},
|
{"nativePlay", "()V", (void *) gst_native_play},
|
||||||
{"nativePause", "()V", (void *) gst_native_pause},
|
{"nativePause", "()V", (void *) gst_native_pause},
|
||||||
{"nativeSetPosition", "(I)V", (void *) gst_native_set_position},
|
|
||||||
{"nativeSurfaceInit", "(Ljava/lang/Object;)V",
|
{"nativeSurfaceInit", "(Ljava/lang/Object;)V",
|
||||||
(void *) gst_native_surface_init},
|
(void *) gst_native_surface_init},
|
||||||
{"nativeSurfaceFinalize", "()V", (void *) gst_native_surface_finalize},
|
{"nativeSurfaceFinalize", "()V", (void *) gst_native_surface_finalize},
|
||||||
@ -608,22 +458,21 @@ static JNINativeMethod native_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Library initializer */
|
/* Library initializer */
|
||||||
jint JNI_OnLoad (JavaVM * vm, void *reserved) {
|
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||||
JNIEnv *env = NULL;
|
JNIEnv *env = NULL;
|
||||||
|
|
||||||
java_vm = vm;
|
java_vm = vm;
|
||||||
|
|
||||||
if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_4) != JNI_OK) {
|
if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_4) != JNI_OK) {
|
||||||
__android_log_print (ANDROID_LOG_ERROR, "player",
|
__android_log_print(ANDROID_LOG_ERROR, "player",
|
||||||
"Could not retrieve JNIEnv");
|
"Could not retrieve JNIEnv");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
jclass klass = (*env)->FindClass (env,
|
jclass klass = (*env)->FindClass(env, "com/hisharp/gstreamer_player/GstLibrary");
|
||||||
"com/hisharp/gstreamer_player/GstLibrary");
|
(*env)->RegisterNatives(env, klass, native_methods,
|
||||||
(*env)->RegisterNatives (env, klass, native_methods,
|
|
||||||
G_N_ELEMENTS (native_methods));
|
G_N_ELEMENTS (native_methods));
|
||||||
|
|
||||||
pthread_key_create (¤t_jni_env, detach_current_thread);
|
pthread_key_create(¤t_jni_env, detach_current_thread);
|
||||||
|
|
||||||
return JNI_VERSION_1_4;
|
return JNI_VERSION_1_4;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user