/* Retrieve the video sink's Caps and tell the application about the media size */ static void check_media_size (CustomData *data) { JNIEnv *env = get_jni_env (); GstElement *video_sink; GstPad *video_sink_pad; GstCaps *caps; GstVideoFormat fmt; int width; int height; /* Retrieve the Caps at the entrance of the video sink */ g_object_get (data->pipeline, "video-sink", &video_sink, NULL); video_sink_pad = gst_element_get_static_pad (video_sink, "sink"); caps = gst_pad_get_negotiated_caps (video_sink_pad); if (gst_video_format_parse_caps(caps, &fmt, &width, &height)) { int par_n, par_d; if (gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d)) { width = width * par_n / par_d; } GST_DEBUG ("Media size is %dx%d, notifying application", width, height); (*env)->CallVoidMethod (env, data->app, on_media_size_changed_method_id, (jint)width, (jint)height); if ((*env)->ExceptionCheck (env)) { GST_ERROR ("Failed to call Java method"); (*env)->ExceptionClear (env); } } gst_caps_unref(caps); gst_object_unref (video_sink_pad); gst_object_unref(video_sink); }
void free_data(CustomData* data) { if (data == NULL) { GPlayerDEBUG("NULL data at %p", pthread_self()); return; } JNIEnv *env = get_jni_env(); gst_element_set_state(data->pipeline, GST_STATE_NULL); GPlayerDEBUG("Quitting main loop... %p", data->main_loop); g_main_loop_quit(data->main_loop); g_main_loop_unref(data->main_loop); data->main_loop = NULL; GPlayerDEBUG("Waiting for thread to finish..."); pthread_join(gst_app_thread, NULL); pthread_kill(data->gst_worker_thread, SIGILL); pthread_join(data->gst_worker_thread, NULL); pthread_mutex_lock(&data->mutex); GPlayerDEBUG("Freeing CustomData at %p", data); SET_CUSTOM_DATA(env, data->app, custom_data_field_id, NULL); GPlayerDEBUG("Deleting GlobalRef for app object at %p", data->app); (*env)->DeleteGlobalRef(env, data->app); pthread_mutex_unlock(&data->mutex); pthread_mutex_destroy(&data->mutex); g_free(data); GPlayerDEBUG("Done finalizing"); }
/* 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); } }
static void handle_sample_failed() { JNIEnv *env = get_jni_env (); env->CallVoidMethod (g_data->app, on_request_sample_failed_method_id); if (env->ExceptionCheck ()) { GST_ERROR ("Failed to call Java method"); env->ExceptionClear (); } }
void gplayer_notify_init_complete(CustomData *data) { JNIEnv *env = get_jni_env(); GPlayerDEBUG("Sending Init Complete Event"); (*env)->CallVoidMethod(env, data->app, gplayer_initialized_method_id, time); if ((*env)->ExceptionCheck(env)) { GST_ERROR("Failed to call Java method"); (*env)->ExceptionClear(env); } }
void gplayer_notify_time(CustomData *data, int time) { JNIEnv *env = get_jni_env(); GPlayerDEBUG("Sending Time Event"); (*env)->CallVoidMethod(env, data->app, gplayer_notify_time_id, time); if ((*env)->ExceptionCheck(env)) { GST_ERROR("Failed to call Java method"); (*env)->ExceptionClear(env); } }
void gplayer_metadata_update(CustomData *data, const gchar *metadata) { JNIEnv *env = get_jni_env(); GPlayerDEBUG("Sending Metadata Event"); (*env)->CallVoidMethod(env, data->app, gplayer_metadata_method_id, ((*env)->NewStringUTF(env, metadata))); if ((*env)->ExceptionCheck(env)) { GST_ERROR("Failed to call Java method"); (*env)->ExceptionClear(env); } }
void gplayer_prepare_complete(CustomData *data) { JNIEnv *env = get_jni_env(); GPlayerDEBUG("Sending Prepare Complete Event"); (*env)->CallVoidMethod(env, data->app, gplayer_prepared_method_id, NULL); if ((*env)->ExceptionCheck(env)) { GST_ERROR("Failed to call Java method"); (*env)->ExceptionClear(env); } }
void gplayer_playback_running(CustomData *data) { JNIEnv *env = get_jni_env(); GPlayerDEBUG("Sending Playback Running Event"); (*env)->CallVoidMethod(env, data->app, gplayer_playback_running_id, NULL); if ((*env)->ExceptionCheck(env)) { GST_ERROR("Failed to call Java method"); (*env)->ExceptionClear(env); } }
void gplayer_error(const gint message, CustomData *data) { JNIEnv *env = get_jni_env(); GPlayerDEBUG("Sending error code: %i", message); (*env)->CallVoidMethod(env, data->app, gplayer_error_id, message); if ((*env)->ExceptionCheck(env)) { GST_ERROR("Failed to call Java method"); (*env)->ExceptionClear(env); } }
/* Change the content of the UI's TextView */ static void set_ui_message (const gchar *message, CustomData *data) { JNIEnv *env = get_jni_env (); GST_DEBUG ("Setting message to: %s", message); jstring jmessage = (*env)->NewStringUTF(env, message); (*env)->CallVoidMethod (env, data->app, set_message_method_id, jmessage); if ((*env)->ExceptionCheck (env)) { GST_ERROR ("Failed to call Java method"); (*env)->ExceptionClear (env); } (*env)->DeleteLocalRef (env, jmessage); }
static void handle_sample_ready (unsigned char *d, size_t size) { JNIEnv *env = get_jni_env (); jbyteArray array = env->NewByteArray(size); env->SetByteArrayRegion(array, 0, size, reinterpret_cast<const jbyte*> (d)); env->CallVoidMethod (g_data->app, on_request_sample_seccess_method_id, array, size); if (env->ExceptionCheck ()) { GST_ERROR ("Failed to call Java method"); env->ExceptionClear (); } }
static void on_end_of_stream (GstPlayer * unused, Player * player) { JNIEnv *env = get_jni_env (); (*env)->CallVoidMethod (env, player->java_player, on_end_of_stream_method_id); if ((*env)->ExceptionCheck (env)) { (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); } }
/* * Java Bindings */ static void on_position_updated (GstPlayer * unused, GstClockTime position, Player * player) { JNIEnv *env = get_jni_env (); (*env)->CallVoidMethod (env, player->java_player, on_position_updated_method_id, position); if ((*env)->ExceptionCheck (env)) { (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); } }
static void on_buffering (GstPlayer * unused, gint percent, Player * player) { JNIEnv *env = get_jni_env (); (*env)->CallVoidMethod (env, player->java_player, on_buffering_method_id, percent); if ((*env)->ExceptionCheck (env)) { (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); } }
static void on_state_changed (GstPlayer * unused, GstPlayerState state, Player * player) { JNIEnv *env = get_jni_env (); (*env)->CallVoidMethod (env, player->java_player, on_state_changed_method_id, state); if ((*env)->ExceptionCheck (env)) { (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); } }
// handle video channel setup static void handle_stream_loaded() { CustomData *data = g_data; if (!data) return; JNIEnv *env = get_jni_env (); env->CallVoidMethod (data->app, on_stream_loaded_method_id); if (env->ExceptionCheck ()) { GST_ERROR ("Failed to call Java method"); env->ExceptionClear (); } }
static void on_video_dimensions_changed (GstPlayer * unused, gint width, gint height, Player * player) { JNIEnv *env = get_jni_env (); (*env)->CallVoidMethod (env, player->java_player, on_video_dimensions_changed_method_id, width, height); if ((*env)->ExceptionCheck (env)) { (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); } }
static void size_changed (GstMediaPlayer * player, gint width, gint height, gpointer user_data) { CustomData *data = (CustomData *) user_data; JNIEnv *env = get_jni_env (); (*env)->CallVoidMethod (env, data->app, on_media_size_changed_method_id, NATIVEP_TO_J (data), (jint) width, (jint) height); if ((*env)->ExceptionCheck (env)) { GST_ERROR ("Failed to call Java method"); (*env)->ExceptionClear (env); } }
static void new_position (GstMediaPlayer * player, gint position, gint duration, gpointer user_data) { CustomData *data = (CustomData *) user_data; JNIEnv *env = get_jni_env (); (*env)->CallVoidMethod (env, data->app, set_current_position_method_id, NATIVEP_TO_J (data), position, duration); if ((*env)->ExceptionCheck (env)) { GST_ERROR ("Failed to call Java method"); (*env)->ExceptionClear (env); } }
/* Check if all conditions are met to report GStreamer as initialized. * These conditions will change depending on the application */ static void check_initialization_complete(CustomData *data) { JNIEnv *env = get_jni_env(); if (!data->initialized && data->main_loop) { GST_DEBUG( "Initialization complete, notifying application. main_loop:%p", data->main_loop); (*env)->CallVoidMethod(env, data->app, on_gstreamer_initialized_method_id); if ((*env)->ExceptionCheck(env)) { GST_ERROR("Failed to call Java method"); (*env)->ExceptionClear(env); } data->initialized = TRUE; } }
/* Check if all conditions are met to report GStreamer as initialized. * These conditions will change depending on the application */ static void check_initialization_complete (CustomData *data) { JNIEnv *env = get_jni_env (); if (!data->initialized && data->native_window && data->main_loop) { GST_DEBUG ("Initialization complete, notifying application. native_window:%p main_loop:%p", data->native_window, data->main_loop); /* 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->video_sink), (guintptr)data->native_window); (*env)->CallVoidMethod (env, data->app, on_gstreamer_initialized_method_id); if ((*env)->ExceptionCheck (env)) { GST_ERROR ("Failed to call Java method"); (*env)->ExceptionClear (env); } data->initialized = TRUE; } }
static void on_error (GstPlayer * unused, GError * err, Player * player) { JNIEnv *env = get_jni_env (); jstring error_msg; error_msg = (*env)->NewStringUTF (env, err->message); (*env)->CallVoidMethod (env, player->java_player, on_error_method_id, err->code, error_msg); if ((*env)->ExceptionCheck (env)) { (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); } (*env)->DeleteLocalRef (env, error_msg); }
static void error (GstMediaPlayer * player, gchar * error, gpointer user_data) { CustomData *data = (CustomData *) user_data; JNIEnv *env = get_jni_env (); jstring jmessage; GST_DEBUG ("Setting error to: %s", error); jmessage = (*env)->NewStringUTF (env, error); (*env)->CallVoidMethod (env, data->app, set_error_method_id, NATIVEP_TO_J (data), jmessage); if ((*env)->ExceptionCheck (env)) { GST_ERROR ("Failed to call Java method"); (*env)->ExceptionClear (env); } (*env)->DeleteLocalRef (env, jmessage); }