GstSDK-Congo Android Workshop

Report
GStreamer SDK
Android Workshop
Xavi Artigas
[email protected]
Workshop Objective
Learn how to make a
media player on Android
using GStreamer
2
What is GStreamer?
• Open-source library for constructing graphs of
media-handling elements
• Multiplatform
• Each element is a plugin, for added extensibility
3
What is GStreamer?
• General enough to allow media playback,
streaming, non-linear video editing…
• Has been around for more than 10 years
• Used by several open-source and commercial
applications
4
What is the GStreamer SDK?
• Aims at simplifying the adoption of GStreamer
• Pre-packaged, ready-to-use, for different
platforms
• Sticks to one particular version of GStreamer
• Documentation!
http://docs.gstreamer.com
5
The GStreamer SDK Documentation
• Installation instructions
• Tutorials
– Basic tutorials
– Playback tutorials
– Android tutorials
YOU ARE HERE
– iOS tutorials
• Deployment instructions
6
Workshop outline
1. Install the GStreamer SDK
2. Import Tutorial 4 into eclipse. Build. Run.
3. Build your own Media Player, step by step
–
Create a new Android project and copy selected bits
of code from the tutorials
7
Install the GStreamer SDK
Install the GStreamer SDK
I. Go to docs.gstreamer.com » Download » Android
II. Download the zip or tarball, unpack
III. Set GSTREAMER_SDK_ROOT_ANDROID:
• At the system level:
• System environment variables (Windows)
• .bashrc or .profile files (Linux and Mac)
• Or in Eclipse:
• Window » Preferences » C/C++ » Build » Build Variables
9
Import Tutorial 4 into eclipse
Import tutorial 4 into Eclipse
I. File » New » Project…
» Android Project from Existing Code
II. Select tutorial 4 folder
<GST_SDK_HOME>/share/gst-sdk/tutorials
III. Right-click » Android Tools » Add native support
IV.Build & Run
11
Build your own Media Player
Step 1:
Link against GStreamer
Media Player 1: Link against GStreamer
We are going to:
•
Create a new Android application
•
Add JNI support
•
Add GStreamer to the mix
•
Display the GStreamer version in the
UI
13
Media Player 1: Link against GStreamer
I. File » New » Project…
•
Android Application Project
•
Name it, choose any target API level > 9
•
Create a blank activity for it
II. Right-click » Android Tools » Add native
support
•
Rename the JNI .cpp file to .c
III. JNI file: Copy contents of Tutorial 1
•
Pay attention to your Activity class name!
14
Media Player 1: Link against GStreamer
IV. Java file:
•
Import com.gstreamer.GStreamer
•
Add a static class initializer that calls:
System.loadlibrary(“gstreamer_android”);
System.loadlibrary(“your_jni_class_name”);
•
Call GStreamer.init(this) in onCreate
•
Declare nativeGetGStreamerInfo method
private native String nativeGetGStreamerInfo()
•
Call it and assign the returned string to the
TextView in the UI
15
Media Player 1: Link against GStreamer
V.
Android.mk
•
Copy contents of tutorial 1
•
This will remain almost the same for all tutorials
•
Change these lines to match your JNI class name:
LOCAL_MODULE := tutorial-1
LOCAL_SRC_FILES := tutorial-1.c
VI. Build & Run
16
Build your own Media Player
Step 2:
A running pipeline
Media Player 2: A running pipeline
We are going to:
•
Create a thread from JNI to handle GStreamer
•
Store all data needed by JNI code in a JNI
struct
•
Keep the pointer in the Java class
•
Call from Java to JNI and vice versa
18
Media Player 2: A running pipeline
I. JNI file: Replace with contents of Tutorial 2
Search & replace the string “tutorial”
Interesting points:
•
CustomData
•
JNI_OnLoad()
•
gst_native_init()
•
app_function()
•
check_initialization_complete()
•
gst_native_play() and gst_native_pause()
•
error_cb() and state_changed_cb()
19
Media Player 2: A running pipeline
A quick note on the used GStreamer pipeline:
gst_parse_launch("audiotestsrc ! audioconvert !
audioresample ! autoaudiosink", &error);
The above line creates the following pipeline:
audiotestsrc
audioconvert
audioresample
autoaudiosink
20
Media Player 2: A running pipeline
II.
Add two Play and Pause buttons to the UI
•
Set them to be initially disabled
21
Media Player 2: A running pipeline
III. Java file: Copy interesting bits from Tutorial 2
• Native method declarations & Static class initializer
• Call nativePlay and nativePause when buttons are
pressed
• Call nativeInit at the end of onCreate
• Call nativeFinalize at the beginning of onDestroy
• Create a method with this signature:
private void onGStreamerInitialized()
In it, enable the UI buttons from the UI thread
• Create a method with this signature:
private void setMessage(final String msg)
In it, set the TextView message from the UI thread
22
Media Player 2: A running pipeline
IV. Android.mk
• Simply replace:
GSTREAMER_PLUGINS := coreelements
by:
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE)
$(GSTREAMER_PLUGINS_SYS)
V.
Build & Run
23
Build your own Media Player
Step 3:
Video!
Media Player 3: Video!
We are going to:
•
Add a video surface to the UI
•
Tell GStreamer to use it
•
Use a pipeline that produces
video
25
Media Player 3: Video!
I. JNI file: Copy interesting bits from Tutorial 3
• List of #include’s
• Add video_sink and native_window to CustomData
• check_initialization_complete()
• app_function()
•
Call to gst_parse_launch()
•
Call to gst_bin_get_by_interface()
• gst_native_surface_init()
• gst_native_surface_finalize()
• Add new methods to the native_methods array
26
Media Player 3: Video!
A quick note on the used GStreamer pipeline:
gst_parse_launch("videotestsrc ! warptv !
ffmpegcolorspace ! autovideosink", &error);
The above line creates the following pipeline:
videotestsrc
warptv
ffmpegcolorspace
autovideosink
27
Media Player 3: Video!
II.
Add a SurfaceView to the UI
28
Media Player 3: Video!
III. Java file: Copy interesting bits from Tutorial 3
• Implement SurfaceHolder.Callback interface
• Add new native methods nativeSurfaceInit and
nativeSurfaceFinalize
• Add this to onCreate:
SurfaceView sv = (SurfaceView)findViewById (R.id.video);
SurfaceHolder sh = sv.getHolder();
sh.addCallback (this);
• Copy the SurfaceHolder callbacks:
• surfaceChanged()
• surfaceCreated()
• surfaceDestroyed()
29
Media Player 3: Video!
IV. Android.mk
• Add a new plugin: $(GSTREAMER_PLUGINS_EFFECTS)
• A new library (after the shared libraries line):
LOCAL_LDLIBS := -llog -landroid
• And some GStreamer extra libraries (after the plugins line):
GSTREAMER_EXTRA_DEPS := gstreamer-interfaces-0.10
gstreamer-video-0.10
V.
Build & Run
30
Build your own Media Player
Step 4:
A basic player
Media Player 4: A basic player
We are going to:
•
Play any media from an arbitrary
URI
32
Media Player 4: A basic player
I. JNI file: Copy interesting bits from Tutorial 4
• gst_native_set_uri()
• Add it to the native_methods array
• Replace the pipeline description in app_func simply with
“playbin2”
33
Media Player 4: A basic player
II. Java file: Copy interesting bits from Tutorial 4
• Add new native method:
private native void nativeSetUri (String uri);
• Call it in onGStreamerInitialized()
34
Media Player 4: A basic player
III. Android.mk:
• Add new plugins:
• $(GSTREAMER_PLUGINS_PLAYBACK)
• $(GSTREAMER_PLUGINS_CODECS)
• $(GSTREAMER_PLUGINS_NET)
• Additional plugins (use with caution):
• $(GSTREAMER_PLUGINS_CODECS_RESTRICTED)
35
Media Player 4: A basic player
IV. AndroidManifest.xml:
• Request INTERNET access
permission
• android.permission.INTERNET
36

similar documents