1 / 36

GStreamer SDK Android Workshop

GStreamer SDK Android Workshop. Xavi Artigas xartigas@fluendo.com. Workshop Objective. Learn how to make a media player on Android using GStreamer. What is GStreamer?. Open-source library for constructing graphs of media-handling elements Multiplatform

Download Presentation

GStreamer SDK Android Workshop

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GStreamer SDKAndroid Workshop Xavi Artigas xartigas@fluendo.com

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

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

  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. 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. The GStreamer SDK Documentation • Installation instructions • Tutorials • Basic tutorials • Playback tutorials • Android tutorials • iOS tutorials • Deployment instructions YOU ARE HERE

  7. Workshop outline • Install the GStreamer SDK • Import Tutorial 4 into eclipse. Build. Run. • 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. Install the GStreamer SDK Go to docs.gstreamer.com» Download » Android Download the zip or tarball, unpack 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. Import tutorial 4 into Eclipse File » New » Project… »Android Project from Existing Code Select tutorial 4 folder <GST_SDK_HOME>/share/gst-sdk/tutorials Right-click » Android Tools » Add native support Build & Run

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

  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 13

  14. Media Player 1: Link against GStreamer File » New » Project… Android Application Project Name it, choose any target API level > 9 Create a blank activity for it Right-click » Android Tools » Add native support Rename the JNI .cpp file to .c JNI file: Copy contents of Tutorial 1 Pay attention to your Activity class name!

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

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

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

  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 18

  19. Media Player 2: A running pipeline JNI file: Replace with contents of Tutorial 2Search & 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

  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: audiotestsrc audioconvert audioresample autoaudiosink 20

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

  22. Media Player 2: A running pipeline 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

  23. Media Player 2: A running pipeline Android.mk Simply replace: GSTREAMER_PLUGINS := coreelements by: include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_SYS) Build & Run 23

  24. Build your own Media Player Step 3: Video!

  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 25

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

  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: videotestsrc warptv ffmpegcolorspace autovideosink 27

  28. Add a SurfaceViewto the UI Media Player 3: Video! 28

  29. Java file: Copy interesting bits from Tutorial 3 Implement SurfaceHolder.Callback interface Add new native methods nativeSurfaceInit and nativeSurfaceFinalize Add this to onCreate: SurfaceViewsv = (SurfaceView)findViewById (R.id.video); SurfaceHoldersh = sv.getHolder(); sh.addCallback (this); Copy the SurfaceHolder callbacks: surfaceChanged() surfaceCreated() surfaceDestroyed() Media Player 3: Video! 29

  30. 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 Build & Run Media Player 3: Video! 30

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

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

  33. Media Player 4: A basic player JNI file: Copy interesting bits from Tutorial 4 gst_native_set_uri() Add it to the native_methodsarray Replace the pipeline description in app_funcsimply with “playbin2” 33

  34. Java file: Copy interesting bits from Tutorial 4 Add new native method: private native void nativeSetUri (String uri); Call it in onGStreamerInitialized() Media Player 4: A basic player 34

  35. Android.mk: Add new plugins: $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) Additional plugins (use with caution): $(GSTREAMER_PLUGINS_CODECS_RESTRICTED) Media Player 4: A basic player 35

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

More Related