/* Set playbin's URI */ void gst_native_set_uri (JNIEnv* env, jobject thiz, jstring uri, jint timeout) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); const char *char_uri = env->GetStringUTFChars (uri, NULL); data->player->setTcpTimeout(timeout); data->player->setUri(char_uri); env->ReleaseStringUTFChars (uri, char_uri); }
/* Quit the main loop, remove the native thread and free resources */ static void gst_native_finalize(JNIEnv* env, jobject thiz) { // Destory mutex if (0 != pthread_mutex_destroy(&mutex)) { // Get the exception class jclass exceptionClazz = (*env)->FindClass(env, "java/lang/RuntimeException"); // Throw exception (*env)->ThrowNew(env, exceptionClazz, "Unable to destroy mutex"); g_print("pthread_mutex_destroy fail!"); } CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; GST_DEBUG("Quitting main loop..."); g_main_loop_quit(data->main_loop); GST_DEBUG("Waiting for thread to finish..."); pthread_join(gst_app_thread, NULL); GST_DEBUG("Deleting GlobalRef for app object at %p", data->app); (*env)->DeleteGlobalRef(env, data->app); GST_DEBUG("Freeing CustomData at %p", data); g_free(data); SET_CUSTOM_DATA(env, thiz, custom_data_field_id, NULL); GST_DEBUG("Done finalizing"); }
/* Set pipeline to PAUSED state */ static void gst_native_pause(JNIEnv* env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; GST_DEBUG("Setting state to PAUSED"); gst_element_set_state(data->pipeline, GST_STATE_PAUSED); }
/* Set pipeline to PAUSED state */ static void gst_native_pause (JNIEnv* env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; 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); }
/* Set pipeline to PLAYING state */ static void gst_native_play(JNIEnv* env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) { g_print("data is null!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); return; } GST_DEBUG("Setting state to PLAYING"); g_print("data is Setting state to PLAYING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); GstStateChangeReturn ret; ret = gst_element_set_state(data->pipeline, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { g_print("Unable to set the pipeline to the playing state.\n"); return; } else if (ret == GST_STATE_CHANGE_NO_PREROLL) { g_print(" data.is_live = TRUE.\n"); } else if (ret == GST_STATE_CHANGE_SUCCESS) { g_print(" GST_STATE_CHANGE_SUCCESS.\n"); } g_print("rest is %d", ret); iEnd = 0; }
static void native_stop (JNIEnv * env, jobject thiz) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); if (!player) return; gst_player_stop (player->player); }
static void native_seek (JNIEnv * env, jobject thiz, jlong position) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); if (!player) return; gst_player_seek (player->player, position); }
static void native_set_mute (JNIEnv * env, jobject thiz, jboolean mute) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); if (!player) return; g_object_set (player->player, "mute", mute, NULL); }
static void native_set_volume (JNIEnv * env, jobject thiz, jdouble volume) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); if (!player) return; g_object_set (player->player, "volume", volume, NULL); }
/* 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; } }
/* Set playbin's URI */ void gst_native_request_sample (JNIEnv* env, jobject thiz, jstring format) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; const char *fmt = env->GetStringUTFChars (format, NULL); data->player->requestSample(fmt); env->ReleaseStringUTFChars (format, fmt); }
/* Set playbin2's URI */ void gst_native_set_uri (JNIEnv* env, jobject thiz, jstring uri) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data || !data->pipeline) return; const jbyte *char_uri = (*env)->GetStringUTFChars (env, uri, NULL); GST_DEBUG ("Setting URI to %s", char_uri); if (data->target_state >= GST_STATE_READY) gst_element_set_state (data->pipeline, GST_STATE_READY); g_object_set(data->pipeline, "uri", char_uri, NULL); (*env)->ReleaseStringUTFChars (env, uri, char_uri); data->duration = GST_CLOCK_TIME_NONE; data->is_live = (gst_element_set_state (data->pipeline, data->target_state) == GST_STATE_CHANGE_NO_PREROLL); }
static void gst_native_surface_init (JNIEnv *env, jobject thiz, jobject surface) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; ANativeWindow *new_native_window = ANativeWindow_fromSurface(env, surface); GST_DEBUG ("Received surface %p (native window %p)", surface, new_native_window); data->player->releaseSurface(); data->player->setSurface(new_native_window); if (!new_native_window) handle_stream_loading_error(); }
static jboolean native_get_mute (JNIEnv * env, jobject thiz) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); jboolean mute; if (!player) return FALSE; g_object_get (player->player, "mute", &mute, NULL); return mute; }
static jdouble native_get_volume (JNIEnv * env, jobject thiz) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); jdouble volume; if (!player) return 1.0; g_object_get (player->player, "volume", &volume, NULL); return volume; }
static jlong native_get_duration (JNIEnv * env, jobject thiz) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); jlong duration; if (!player) return -1; g_object_get (player->player, "duration", &duration, NULL); return duration; }
static void native_set_uri (JNIEnv * env, jobject thiz, jobject uri) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); const gchar *uri_str; if (!player) return; uri_str = (*env)->GetStringUTFChars (env, uri, NULL); g_object_set (player->player, "uri", uri_str, NULL); (*env)->ReleaseStringUTFChars (env, uri, uri_str); }
static void native_free (JNIEnv * env, jobject thiz) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); if (!player) return; g_object_unref (player->player); (*env)->DeleteGlobalRef (env, player->java_player); g_free (player); SET_CUSTOM_DATA (env, thiz, native_player_field_id, NULL); }
static void gst_native_surface_finalize (JNIEnv *env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; GST_DEBUG ("Releasing Native Window %p", data->native_window); if (data->video_sink) { gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->video_sink), (guintptr)NULL); gst_element_set_state (data->pipeline, GST_STATE_READY); } ANativeWindow_release (data->native_window); data->native_window = NULL; data->initialized = FALSE; }
/* Quit the main loop, remove the native thread and free resources */ static void gst_native_finalize (JNIEnv* env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; GST_DEBUG ("Quitting main loop..."); g_main_loop_quit (data->main_loop); GST_DEBUG ("Waiting for thread to finish..."); pthread_join (gst_app_thread, NULL); GST_DEBUG ("Deleting GlobalRef for app object at %p", data->app); (*env)->DeleteGlobalRef (env, data->app); GST_DEBUG ("Freeing CustomData at %p", data); g_free (data); SET_CUSTOM_DATA (env, thiz, custom_data_field_id, NULL); GST_DEBUG ("Done finalizing"); }
static jobject native_get_uri (JNIEnv * env, jobject thiz) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); jobject uri; gchar *uri_str; if (!player) return NULL; g_object_get (player->player, "uri", &uri_str, NULL); uri = (*env)->NewStringUTF (env, uri_str); g_free (uri_str); return uri; }
static void native_set_surface (JNIEnv * env, jobject thiz, jobject surface) { Player *player = GET_CUSTOM_DATA (env, thiz, native_player_field_id); ANativeWindow *new_native_window; if (!player) return; new_native_window = surface ? ANativeWindow_fromSurface (env, surface) : NULL; GST_DEBUG ("Received surface %p (native window %p)", surface, new_native_window); if (player->native_window) { ANativeWindow_release (player->native_window); } player->native_window = new_native_window; gst_player_video_overlay_video_renderer_set_window_handle (GST_PLAYER_VIDEO_OVERLAY_VIDEO_RENDERER (player->renderer), (gpointer) new_native_window); }
static void gst_native_surface_init (JNIEnv *env, jobject thiz, jobject surface) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; ANativeWindow *new_native_window = ANativeWindow_fromSurface(env, surface); GST_DEBUG ("Received surface %p (native window %p)", surface, new_native_window); if (data->native_window) { ANativeWindow_release (data->native_window); if (data->native_window == new_native_window) { GST_DEBUG ("New native window is the same as the previous one %p", data->native_window); if (data->video_sink) { gst_video_overlay_expose(GST_VIDEO_OVERLAY (data->video_sink)); gst_video_overlay_expose(GST_VIDEO_OVERLAY (data->video_sink)); } return; } else { GST_DEBUG ("Released previous native window %p", data->native_window); data->initialized = FALSE; } } data->native_window = new_native_window; check_initialization_complete (data); }
/* Quit the main loop, remove the native thread and free resources */ void gst_native_finalize(JNIEnv* env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA(env, thiz, custom_data_field_id); GPlayerDEBUG("gst_native_finalize() %p", data); free_data(data); }
static void gst_native_surface_finalize (JNIEnv *env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; data->player->stop(); }
static void gst_native_expose(JNIEnv *env, jobject thiz) { CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id); if (!data) return; LOGD("Expose"); data->player->expose(); }