1 package org.freedesktop.gstreamer.vulkan;
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.util.Log;
6 import android.view.SurfaceHolder;
7 import android.view.SurfaceView;
8 import android.view.View;
9 import android.view.View.OnClickListener;
10 import android.widget.ImageButton;
11 import android.widget.TextView;
12 import android.widget.Toast;
14 import org.freedesktop.gstreamer.GStreamer;
15 import org.freedesktop.gstreamer.vulkan.vulkan_1.R;
17 public class Vulkan1 extends Activity implements SurfaceHolder.Callback {
18 private native void nativeInit(); // Initialize native code, build pipeline, etc
19 private native void nativeFinalize(); // Destroy pipeline and shutdown native code
20 private native void nativePlay(); // Set pipeline to PLAYING
21 private native void nativePause(); // Set pipeline to PAUSED
22 private static native boolean nativeClassInit(); // Initialize native class: cache Method IDs for callbacks
23 private native void nativeSurfaceInit(Object surface);
24 private native void nativeSurfaceFinalize();
25 private long native_custom_data; // Native code will use this to keep private data
27 private boolean is_playing_desired; // Whether the user asked to go to PLAYING
29 // Called when the activity is first created.
31 public void onCreate(Bundle savedInstanceState)
33 super.onCreate(savedInstanceState);
35 // Initialize GStreamer and warn if it fails
38 } catch (Exception e) {
39 Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
44 setContentView(R.layout.main);
46 ImageButton play = (ImageButton) this.findViewById(R.id.button_play);
47 play.setOnClickListener(new OnClickListener() {
48 public void onClick(View v) {
49 is_playing_desired = true;
54 ImageButton pause = (ImageButton) this.findViewById(R.id.button_stop);
55 pause.setOnClickListener(new OnClickListener() {
56 public void onClick(View v) {
57 is_playing_desired = false;
62 SurfaceView sv = (SurfaceView) this.findViewById(R.id.surface_video);
63 SurfaceHolder sh = sv.getHolder();
66 if (savedInstanceState != null) {
67 is_playing_desired = savedInstanceState.getBoolean("playing");
68 Log.i ("GStreamer", "Activity created. Saved state is playing:" + is_playing_desired);
70 is_playing_desired = false;
71 Log.i ("GStreamer", "Activity created. There is no saved state, playing: false");
74 // Start with disabled buttons, until native code is initialized
75 this.findViewById(R.id.button_play).setEnabled(false);
76 this.findViewById(R.id.button_stop).setEnabled(false);
81 protected void onSaveInstanceState (Bundle outState) {
82 Log.d ("GStreamer", "Saving state, playing:" + is_playing_desired);
83 outState.putBoolean("playing", is_playing_desired);
86 protected void onDestroy() {
91 // Called from native code. This sets the content of the TextView from the UI thread.
92 private void setMessage(final String message) {
93 final TextView tv = (TextView) this.findViewById(R.id.textview_message);
94 runOnUiThread (new Runnable() {
101 // Called from native code. Native code calls this once it has created its pipeline and
102 // the main loop is running, so it is ready to accept commands.
103 private void onGStreamerInitialized () {
104 Log.i ("GStreamer", "Gst initialized. Restoring state, playing:" + is_playing_desired);
105 // Restore previous playing state
106 if (is_playing_desired) {
112 // Re-enable buttons, now that GStreamer is initialized
113 final Activity activity = this;
114 runOnUiThread(new Runnable() {
116 activity.findViewById(R.id.button_play).setEnabled(true);
117 activity.findViewById(R.id.button_stop).setEnabled(true);
123 System.loadLibrary("gstreamer_android");
124 System.loadLibrary("vulkan-1");
128 public void surfaceChanged(SurfaceHolder holder, int format, int width,
130 Log.d("GStreamer", "Surface changed to format " + format + " width "
131 + width + " height " + height);
132 nativeSurfaceInit (holder.getSurface());
135 public void surfaceCreated(SurfaceHolder holder) {
136 Log.d("GStreamer", "Surface created: " + holder.getSurface());
139 public void surfaceDestroyed(SurfaceHolder holder) {
140 Log.d("GStreamer", "Surface destroyed");
141 nativeSurfaceFinalize ();