Presentation is loading. Please wait.

Presentation is loading. Please wait.

GStreamer SDK Android Workshop Xavi Artigas

Similar presentations


Presentation on theme: "GStreamer SDK Android Workshop Xavi Artigas"— Presentation transcript:

1 GStreamer SDK Android Workshop Xavi Artigas xartigas@fluendo.com

2 2 Workshop Objective Learn how to make a media player on Android using GStreamer

3 3 What is GStreamer? Open-source library for constructing graphs of media-handling elements Multiplatform Each element is a plugin, for added extensibility

4 4 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

5 5 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

6 6 The GStreamer SDK Documentation Installation instructions Tutorials –Basic tutorials –Playback tutorials –Android tutorials –iOS tutorials Deployment instructions YOU ARE HERE

7 7 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

8 Install the GStreamer SDK

9 9 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

10 Import Tutorial 4 into eclipse

11 11 Import tutorial 4 into Eclipse I.File » New » Project… » Android Project from Existing Code II.Select tutorial 4 folder /share/gst-sdk/tutorials III.Right-click » Android Tools » Add native support IV.Build & Run

12 Build your own Media Player Step 1: Link against GStreamer

13 13 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

14 14 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!

15 15 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

16 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 Media Player 1: Link against GStreamer

17 Build your own Media Player Step 2: A running pipeline

18 18 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

19 19 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()

20 20 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: audiotestsrcaudioconvertaudioresampleautoaudiosink

21 II.Add two Play and Pause buttons to the UI Set them to be initially disabled 21 Media Player 2: A running pipeline

22 22 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

23 23 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

24 Build your own Media Player Step 3: Video!

25 25 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

26 26 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

27 27 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: videotestsrcwarptvffmpegcolorspaceautovideosink

28 II.Add a SurfaceView to the UI 28 Media Player 3: Video!

29 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!

30 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 Media Player 3: Video!

31 Build your own Media Player Step 4: A basic player

32 32 Media Player 4: A basic player We are going to: Play any media from an arbitrary URI

33 33 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 ”

34 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

35 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

36 IV.AndroidManifest.xml: Request INTERNET access permission android.permission.INTERNET 36 Media Player 4: A basic player


Download ppt "GStreamer SDK Android Workshop Xavi Artigas"

Similar presentations


Ads by Google