Beispiel #1
0
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");
}
Beispiel #2
0
/* 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");
}
/* Instruct the native code to create its internal data structure, pipeline and thread */
static void gst_native_init (JNIEnv* env, jobject thiz) {
    CustomData *data = g_new0 (CustomData, 1);
    SET_CUSTOM_DATA (env, thiz, custom_data_field_id, data);
    GST_DEBUG_CATEGORY_INIT (debug_category, "tutorial-5", 0, "Android tutorial 5");
    gst_debug_set_threshold_for_name("tutorial-5", GST_LEVEL_DEBUG);
    GST_DEBUG ("Created CustomData at %p", data);
    data->app = (*env)->NewGlobalRef (env, thiz);
    GST_DEBUG ("Created GlobalRef for app object at %p", data->app);
    pthread_create (&gst_app_thread, NULL, &app_function, data);
}
Beispiel #4
0
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);
}
/* Instruct the native code to create its internal data structure, pipeline and thread */
static void gst_native_init (JNIEnv* env, jobject thiz) {
    //gst_init(NULL, NULL);
    CustomData *data = g_new0 (CustomData, 1);
    g_data = data;
    SET_CUSTOM_DATA (env, thiz, custom_data_field_id, data);
    GST_DEBUG_CATEGORY_INIT (debug_category, "evercam", 0, "Android evercam");
    gst_debug_set_threshold_for_name("evercam", GST_LEVEL_LOG);
    GST_DEBUG ("Created CustomData at %p", data);
    data->app = env->NewGlobalRef (thiz);
    GST_DEBUG ("Created GlobalRef for app object at %p", data->app);
    pthread_create (&gst_app_thread, NULL, &app_function, data);
    //app_function(data);
}
/* 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");
}
Beispiel #7
0
/* Instruct the native code to create its internal data structure, pipeline and thread */
void gst_native_init(JNIEnv* env, jobject thiz)
{
	pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
	CustomData *data = g_new0(CustomData, 1);
	data->last_seek_time = GST_CLOCK_TIME_NONE;
	SET_CUSTOM_DATA(env, thiz, custom_data_field_id, data);
	GPlayerDEBUG("Created CustomData at %p", data);
	data->app = (*env)->NewGlobalRef(env, thiz);
	GPlayerDEBUG("Created GlobalRef for app object at %p", data->app);
	data->mutex = mut;
	pthread_mutex_init(&data->mutex, NULL);
	pthread_mutex_unlock(&data->mutex);
	pthread_create(&gst_app_thread, NULL, &app_function, data);
	pthread_create(&data->gst_worker_thread, NULL, &gst_worker_cb, data);
	GPlayerDEBUG("Worker created... %p\n", data->gst_worker_thread);
}
Beispiel #8
0
/* Instruct the native code to create its internal data structure, pipeline and thread */
static void gst_native_init(JNIEnv* env, jobject thiz) {

	if (-1 == access("/storage/sdcard0/fifo9000", F_OK)) {
		int res = mkfifo("/storage/sdcard0/fifo9000", S_IRWXO);
		if (res != 0) {
			g_print("Error while creating a pipe (return:%d, errno:%d)", res,
					errno);
		}
	}
	else
	{

	}
	// Initialize mutex
	if (0 != pthread_mutex_init(&mutex, NULL)) {

		// Get the exception class
		jclass exceptionClazz = (*env)->FindClass(env,
				"java/lang/RuntimeException");
		// Throw exception
		(*env)->ThrowNew(env, exceptionClazz, "Unable to initialize mutex");

		g_print("pthread_mutex_init fail!");

	} else {

	}
	CustomData *data = g_new0(CustomData, 1);
	SET_CUSTOM_DATA(env, thiz, custom_data_field_id, data);
	GST_DEBUG_CATEGORY_INIT(debug_category, "tutorial-2", 0,
			"Android tutorial 2");
	gst_debug_set_threshold_for_name("tutorial-2", GST_LEVEL_DEBUG);
	GST_DEBUG("Created CustomData at %p", data);
	data->app = (*env)->NewGlobalRef(env, thiz);
	GST_DEBUG("Created GlobalRef for app object at %p", data->app);
	pthread_create(&gst_app_thread, NULL, &app_function, data);
}
Beispiel #9
0
static void
native_new (JNIEnv * env, jobject thiz)
{
  Player *player = g_new0 (Player, 1);

  player->renderer = gst_player_video_overlay_video_renderer_new (NULL);
  player->player = gst_player_new (player->renderer, NULL);
  SET_CUSTOM_DATA (env, thiz, native_player_field_id, player);
  player->java_player = (*env)->NewGlobalRef (env, thiz);

  g_signal_connect (player->player, "position-updated",
      G_CALLBACK (on_position_updated), player);
  g_signal_connect (player->player, "duration-changed",
      G_CALLBACK (on_duration_changed), player);
  g_signal_connect (player->player, "state-changed",
      G_CALLBACK (on_state_changed), player);
  g_signal_connect (player->player, "buffering",
      G_CALLBACK (on_buffering), player);
  g_signal_connect (player->player, "end-of-stream",
      G_CALLBACK (on_end_of_stream), player);
  g_signal_connect (player->player, "error", G_CALLBACK (on_error), player);
  g_signal_connect (player->player, "video-dimensions-changed",
      G_CALLBACK (on_video_dimensions_changed), player);
}