mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 17:20:36 +00:00
Add a SurfaceView and tell native code about it. Still no sink though.
This commit is contained in:
parent
c4363559c8
commit
f7446956c9
4 changed files with 78 additions and 25 deletions
|
@ -19,6 +19,7 @@ include $(CLEAR_VARS)
|
|||
LOCAL_MODULE := tutorial-1
|
||||
LOCAL_SRC_FILES := tutorial-1.c
|
||||
LOCAL_SHARED_LIBRARIES := gstreamer_android
|
||||
LOCAL_LDLIBS := -landroid
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
GSTREAMER_PLUGINS = coreelements audiotestsrc videotestsrc ogg theora vorbis ffmpegcolorspace playback app audioconvert audiorate audioresample adder coreindexers gdp gio uridecodebin videorate videoscale typefindfunctions libvisual pango subparse
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <android/native_window.h>
|
||||
#include <android/native_window_jni.h>
|
||||
#include <gst/gst.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
@ -22,6 +24,7 @@ typedef struct _CustomData {
|
|||
jobject app;
|
||||
GstElement *pipeline;
|
||||
GMainLoop *main_loop;
|
||||
ANativeWindow *native_window;
|
||||
} CustomData;
|
||||
|
||||
static pthread_t gst_app_thread;
|
||||
|
@ -151,12 +154,32 @@ void gst_class_init (JNIEnv* env, jclass klass) {
|
|||
GST_DEBUG ("The MethodID for the setMessage method is %p", set_message_method_id);
|
||||
}
|
||||
|
||||
void gst_native_surface_init (JNIEnv *env, jobject thiz, jobject surface) {
|
||||
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
|
||||
GST_DEBUG ("Received surface %p", surface);
|
||||
if (data->native_window) {
|
||||
GST_DEBUG ("Releasing previous native window %p", data->native_window);
|
||||
ANativeWindow_release (data->native_window);
|
||||
}
|
||||
data->native_window = ANativeWindow_fromSurface(env, surface);
|
||||
GST_DEBUG ("Got Native Window %p", data->native_window);
|
||||
}
|
||||
|
||||
void gst_native_surface_finalize (JNIEnv *env, jobject thiz) {
|
||||
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
|
||||
GST_DEBUG ("Releasing Native Window %p", data->native_window);
|
||||
ANativeWindow_release (data->native_window);
|
||||
data->native_window = NULL;
|
||||
}
|
||||
|
||||
static JNINativeMethod native_methods[] = {
|
||||
{ "nativeInit", "()V", (void *) gst_native_init},
|
||||
{ "nativeFinalize", "()V", (void *) gst_native_finalize},
|
||||
{ "nativePlay", "()V", (void *) gst_native_play},
|
||||
{ "nativePause", "()V", (void *) gst_native_pause},
|
||||
{ "classInit", "()V", (void *) gst_class_init}
|
||||
{ "classInit", "()V", (void *) gst_class_init},
|
||||
{ "nativeSurfaceInit", "(Ljava/lang/Object;)V", (void *) gst_native_surface_init},
|
||||
{ "nativeSurfaceFinalize", "()V", (void *) gst_native_surface_finalize}
|
||||
};
|
||||
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
|
|
|
@ -31,4 +31,9 @@
|
|||
android:text="@string/button_stop" />
|
||||
</LinearLayout>
|
||||
|
||||
<SurfaceView
|
||||
android:id="@+id/surface_video"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
|
@ -18,18 +18,22 @@ package com.gst_sdk_tutorials.tutorial_1;
|
|||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.os.Bundle;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Tutorial1 extends Activity
|
||||
{
|
||||
public class Tutorial1 extends Activity implements SurfaceHolder.Callback {
|
||||
private native void nativeInit();
|
||||
private native void nativeFinalize();
|
||||
private native void nativePlay();
|
||||
private native void nativePause();
|
||||
private static native void classInit();
|
||||
private native void nativeSurfaceInit(Object surface);
|
||||
private native void nativeSurfaceFinalize();
|
||||
private long native_custom_data;
|
||||
|
||||
/* Called when the activity is first created.
|
||||
|
@ -40,40 +44,44 @@ public class Tutorial1 extends Activity
|
|||
|
||||
setContentView(R.layout.main);
|
||||
|
||||
ImageButton play = (ImageButton)this.findViewById(R.id.button_play);
|
||||
ImageButton play = (ImageButton) this.findViewById(R.id.button_play);
|
||||
play.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
nativePlay();
|
||||
}
|
||||
public void onClick(View v) {
|
||||
nativePlay();
|
||||
}
|
||||
});
|
||||
|
||||
ImageButton pause = (ImageButton)this.findViewById(R.id.button_stop);
|
||||
ImageButton pause = (ImageButton) this.findViewById(R.id.button_stop);
|
||||
pause.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
nativePause();
|
||||
}
|
||||
public void onClick(View v) {
|
||||
nativePause();
|
||||
}
|
||||
});
|
||||
|
||||
SurfaceView sv = (SurfaceView) this.findViewById(R.id.surface_video);
|
||||
SurfaceHolder sh = sv.getHolder();
|
||||
sh.addCallback(this);
|
||||
|
||||
nativeInit();
|
||||
}
|
||||
|
||||
protected void onDestroy () {
|
||||
nativeFinalize();
|
||||
super.onDestroy();
|
||||
protected void onDestroy() {
|
||||
nativeFinalize();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void setMessage (final String message) {
|
||||
final TextView tv = (TextView)this.findViewById(R.id.textview_message);
|
||||
Log.d ("GStreamer", "Received message " + message);
|
||||
try {
|
||||
runOnUiThread (new Runnable() {@Override public void run()
|
||||
private void setMessage(final String message) {
|
||||
final TextView tv = (TextView) this.findViewById(R.id.textview_message);
|
||||
Log.d("GStreamer", "Received message " + message);
|
||||
try {
|
||||
runOnUiThread (new Runnable() {public void run()
|
||||
{
|
||||
tv.setText (message);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tv.setText(message);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
|
@ -81,4 +89,20 @@ public class Tutorial1 extends Activity
|
|||
System.loadLibrary("tutorial-1");
|
||||
classInit();
|
||||
}
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
||||
int height) {
|
||||
Log.d("GStreamer", "Surface changed to format " + format + " width "
|
||||
+ width + " height " + height);
|
||||
nativeSurfaceInit (holder.getSurface());
|
||||
}
|
||||
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
Log.d("GStreamer", "Surface created: " + holder.getSurface());
|
||||
}
|
||||
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
Log.d("GStreamer", "Surface destroyed");
|
||||
nativeSurfaceFinalize ();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue