From 1c4d79835a79f5e9d4fa753b0aae2295ee29850f Mon Sep 17 00:00:00 2001 From: Xavi Artigas Date: Mon, 22 Oct 2012 12:14:21 +0200 Subject: [PATCH] Remove runtime detection of media size as it causes the layout to be recalculated once a frame has already been shown, and it looks ugly. A different solution will be tried for future tutorials. --- .../tutorials/android-tutorial-3/jni/tutorial-3.c | 35 +--------------------- .../tutorial_3/GStreamerSurfaceView.java | 2 +- .../gst_sdk_tutorials/tutorial_3/Tutorial3.java | 12 -------- 3 files changed, 2 insertions(+), 47 deletions(-) diff --git a/gst-sdk/tutorials/android-tutorial-3/jni/tutorial-3.c b/gst-sdk/tutorials/android-tutorial-3/jni/tutorial-3.c index c16b297..2416962 100644 --- a/gst-sdk/tutorials/android-tutorial-3/jni/tutorial-3.c +++ b/gst-sdk/tutorials/android-tutorial-3/jni/tutorial-3.c @@ -41,7 +41,6 @@ static JavaVM *java_vm; static jfieldID custom_data_field_id; static jmethodID set_message_method_id; static jmethodID on_gstreamer_initialized_method_id; -static jmethodID on_media_size_changed_method_id; /* * Private methods @@ -123,31 +122,6 @@ static void state_changed_cb (GstBus *bus, GstMessage *msg, CustomData *data) { } } -/* Called when Pad Caps change on the video sink */ -static void caps_cb (GstPad *pad, GParamSpec *pspec, CustomData *data) { - JNIEnv *env = get_jni_env (); - GstVideoFormat fmt; - int width; - int height; - GstCaps *caps; - - caps = gst_pad_get_negotiated_caps (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 changed to %dx%d", 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); -} - /* 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) { @@ -170,7 +144,6 @@ static void *app_function (void *userdata) { CustomData *data = (CustomData *)userdata; GSource *bus_source; GError *error = NULL; - GstPad *video_sink_pad; GST_DEBUG ("Creating pipeline in CustomData at %p", data); @@ -196,10 +169,6 @@ static void *app_function (void *userdata) { GST_ERROR ("Could not retrieve video sink"); return NULL; } - /* We want to be notified when the Caps on the video sink's Pad change */ - video_sink_pad = gst_element_get_static_pad (data->video_sink, "sink"); - g_signal_connect (G_OBJECT (video_sink_pad), "notify::caps", (GCallback)caps_cb, data); - gst_object_unref (video_sink_pad); if (data->native_window) { GST_DEBUG ("Native window already received, notifying the pipeline about it."); @@ -288,10 +257,8 @@ static jboolean gst_native_class_init (JNIEnv* env, jclass klass) { custom_data_field_id = (*env)->GetFieldID (env, klass, "native_custom_data", "J"); set_message_method_id = (*env)->GetMethodID (env, klass, "setMessage", "(Ljava/lang/String;)V"); on_gstreamer_initialized_method_id = (*env)->GetMethodID (env, klass, "onGStreamerInitialized", "()V"); - on_media_size_changed_method_id = (*env)->GetMethodID (env, klass, "onMediaSizeChanged", "(II)V"); - if (!custom_data_field_id || !set_message_method_id || !on_gstreamer_initialized_method_id || - !on_media_size_changed_method_id) { + if (!custom_data_field_id || !set_message_method_id || !on_gstreamer_initialized_method_id) { /* We emit this message through the Android log instead of the GStreamer log because the later * has not been initialized yet. */ diff --git a/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/GStreamerSurfaceView.java b/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/GStreamerSurfaceView.java index 7bb1dd2..c6ec456 100644 --- a/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/GStreamerSurfaceView.java +++ b/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/GStreamerSurfaceView.java @@ -8,7 +8,7 @@ import android.view.View; // A simple SurfaceView whose width and height is set from the outside public class GStreamerSurfaceView extends SurfaceView { - public int media_width = 320; // Default values, only really meaningful for the layout editor in Eclipse + public int media_width = 320; public int media_height = 240; // Mandatory constructors, they do not do much diff --git a/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/Tutorial3.java b/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/Tutorial3.java index 95e1356..a36c800 100644 --- a/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/Tutorial3.java +++ b/gst-sdk/tutorials/android-tutorial-3/src/com/gst_sdk_tutorials/tutorial_3/Tutorial3.java @@ -118,18 +118,6 @@ public class Tutorial3 extends Activity implements SurfaceHolder.Callback { }); } - private void onMediaSizeChanged (int width, int height) { - Log.i ("GStreamer", "Media size changed to " + width + "x" + height); - final GStreamerSurfaceView gsv = (GStreamerSurfaceView) this.findViewById(R.id.surface_video); - gsv.media_width = width; - gsv.media_height = height; - runOnUiThread(new Runnable() { - public void run() { - gsv.requestLayout(); - } - }); - } - static { System.loadLibrary("gstreamer_android"); System.loadLibrary("tutorial-3"); -- 2.7.4