Example of adding GStreamer into existing Swift project
- Install GStreamer framework system wide GStreamer binary installer can be found at: https://gstreamer.freedesktop.org/data/pkg/ios/
The GStreamer SDK installs itself in your home directory, so it is available only to the user that installed it. The SDK library is installed to ~/Library/Developer/GStreamer/iPhone.sdk. Inside this directory there is the GStreamer.framework that contains the libs, headers and resources.
-
Add
gst_ios_init.h
andgst_ios_init.m
files from this project. -
enable/disable plugins for your project in
gst_ios_init.h
file. -
Create a bridging header file and add code (if you have existing bridging header file then just add this line of code to it):
#import "gst_ios_init.h"
-
In the project's target setting
- add the bridging header file in Obective-C Bridging Header setting.
- In Header Search Path add
"$(HOME)/Library/Developer/GStreamer/iPhone.sdk/GStreamer.framework/Headers"
- In Framework search path add
"$(HOME)/Library/Developer/GStreamer/iPhone.sdk"
- In Other Linker Flags add
-lresolv
and-lc++
- In General settings of the target use "+" button in Frameworks, Libraries, and Embedded Content to add libraries:
- AssetsLibrary, AudioToolbox, AVFoundation, CoreAudio, CoreMedia, CoreVideo, VideoToolbox, Metal, libiconv.tbd
- GStreamer.framework. You can find it in "$(HOME)/Library/Developer/GStreamer/iPhone.sdk/"
- make sure all frameworks have settings "do not embed" selected
- Select libiconv.tbd in the Frameworks group in the Xcode project navigator and select all targets for that file in the File Inspector (menu on the right) in Target Membership section.
- In
application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions)
callgst_ios_init()
Great! Now you can use GStreamer in your project
- Add files from this project:
- GStreamerBackend.h
- GStreamerBackend.m
- GStreamerBackendDelegate.h
- GStreamerVideoViewController.swift
More info on GStreamerBackend* files here: https://gstreamer.freedesktop.org/documentation/tutorials/ios/link-against-gstreamer.html?gi-language=c
-
Add
#include "GStreamerBackend.h"
in the bridging header file -
To create a UIView with RTSP stream add these lines of code (e.g in
viewDidLoad
of your ViewController):
let videoViewController = GStreamerVideoViewController()
videoViewController.changeURI(uri)
view.addSubview(videoViewController.view)
videoViewController.view.translatesAutoresizingMaskIntoConstraints = false
videoViewController.view.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
videoViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
videoViewController.view.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
videoViewController.view.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
- Change the
uri
to any RTSP stream (for e.g. free stream rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov)