mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 12:41:05 +00:00
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.
This commit is contained in:
parent
b0e6a3ba73
commit
1c4d79835a
3 changed files with 2 additions and 47 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue