Webrtc ios framework compilation and Webrtcios framework Compilation

Source: Internet
Author: User

Webrtc ios framework compilation and Webrtcios framework Compilation
1. WebRTC iOS framework Selection

Currently, two active open-source WebRTC implementations are available.

  • Google WebRTC:

Project address: https://code.google.com/p/webrtc/

  • Ericsson Research OpenWebRTC:

Project address: https://github.com/EricssonResearch/openwebrtc

In order to apply WebRTC video communication technology to students' practical projects, we chose Google's WebRTC project to build the iOS App development framework, this project is currently used in both Chrome and FireFox WebRTC support. then the problem arises. Since WebRTC is supported in the browser, why should we transplant and compile it to the iOS platform? Why can't we simply use webview? Yes, not yet! Apple has been severely slowed down in this regard. however, he has his awesome Facetime technology that allows video calls anytime, anywhere, but he is not open-source, so we can only covet it. so we should port WebRTC honestly. fortunately, Google's Chromium project developer has implemented a set of APIS for its WebRTC Objective-C.

However, it is ugly to say that it is better to integrate WebRTC from scratch into our App. It is a nightmare because the WebRTC project and the Chromium project have a certain relationship between dependencies, in addition, these projects are big cross-platform projects, and Google's Own compilation system is adopted, which is much more complicated than our daily IDE. if we need to get a WebRTC library or framework, we need to forget the high technologies such as Xcode IDE and Interface Builder, we need to switch to the terminal environment and use the black technology under the command line to conquer all this.

2. Start WebRTC source code download

Prerequisites:

  • I am using a Macbook with 8 GB memory and running OS X 10.9.5.
  • Install the latest git and subversions and make sure it works properly.
  • Xcode 6.1.1 and Command Line Tools.
  • Additional requirements from users in mainland China, fast VPN, or fast shadowsocks service. (FQ and set proxy for git, svn, and curl ).
2.1 create a compilation directory

Create a directory to store the project compilation tool and project code repository. Make sure that the disk space of the directory is at least 8 ~ 10G. Open the terminal tool of the system and go to Shell:

wuqiong: ~ apple $ mkdir -p $ HOME / opensource / webrtc_build /
2.2 Download Chromium's depot tool
Before executing the following command, please make sure that you have connected to the fast VPN and have FQ, or you have configured a valid socksFQ proxy for git separately.If you are not a problem, just let me not say.

wuqiong: ~ apple $ cd $ HOME / opensource / webrtc_build /
wuqiong: webrtc_build apple $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
This is a set of build tools used by Google to compile Chromium or WebRTC, and will also be used in our subsequent compilation process. For the convenience of the command line, we add the path of these tools to the system environment variable PATH:

wuqiong: webrtc_build apple $ echo "export PATH = $ PWD / depot_tools: $ PATH"> $ HOME / .bash_profile
Then you need to close the current terminal and restart one to make the environment variables set above take effect. Or execute the entry command in the current terminal to load and take effect in the current terminal:

wuqiong: webrtc_build apple $ source $ HOME / .bash_profile
2.3 Download the source code of WebRTC
Create a webtrtc subdirectory under our compilation working directory webrtc_build to store the code, please execute the following command:

wuqiong: webrtc_build apple $ mkdir webrtc
wuqiong: webrtc_build apple $ cd webrtc
After the above inspection work is correct, we need to start downloading a copy of the WebRTC project code warehouse to the local. Because of its large warehouse, it is necessary to download a total of 6G + things. So this step is very patient. And needs There is a stable and accessible Internet. Run the following command and then:

wuqiong: webrtc apple $ gclient config --name src http://webrtc.googlecode.com/svn/trunk
wuqiong: webrtc apple $ echo "target_os = ['ios']" >> .gclient
wuqiong: webrtc apple $ gclient sync --force
FQ quickly go to coffee, and slowly go to the sister. Come back after finishing things. If the above commands are all fine, we can go down and start compiling. (For the convenience of everyone, I have packaged the webrtc_build directory for backup , So that you can save a lot of code download time. The package file has 5G and is looking for a network disk to store, which will be announced later.)

2.4 Compile WebRTC.framework
At this step, the source code should have been downloaded. These source codes can be compiled into several platforms, OS X, Linux, Windows, Android, iOS, etc. Here we only need to compile the WebRTC of the iOS platform and make it into an iOS development framework . Here we can't use Xcode tools, because these projects don't support XCode at all. We need to do all this in the terminal command line environment!

First of all, for us to play black weapons, we need to create a script in the webrtc project code directory. This script is a one-click framework compilation script that I specially wrote to simplify the complexity of the command and improve the convenience of use. The script is today's core black technology. First create an empty file, and then grant execution permissions:

wuqiong: webrtc apple $ touch build_webrtc.sh
wuqiong: webrtc apple $ chmod + x build_webrtc.sh
Then use an editor to open the script file you just created, paste the following script into it, save it and close it:

  1 #! / Bin / bash
  2 # Script to build WebRTC.framework for iOS
  3 # Copyright (C) 2015 Camp David Education-All Rights Reserved
  4 # Last revised 28/1/2015
  5 #
  6
  7 function build_iossim_ia32 () {
  8 echo "*** building WebRTC for the ia32 iOS simulator";
  9 export GYP_GENERATORS = "ninja";
 10 export GYP_DEFINES = "build_with_libjingle = 1 build_with_chromium = 0 libjingle_objc = 1 OS = ios target_arch = ia32";
 11 export GYP_GENERATOR_FLAGS = "$ GYP_GENERATOR_FLAGS output_dir = out_ios_ia32";
 12 export GYP_CROSSCOMPILE = 1;
 13 pushd src;
 14 gclient runhooks;
 15 ninja -C out_ios_ia32 / Release-iphonesimulator iossim AppRTCDemo;
 16
 17 echo "*** creating iOS ia32 libraries";
 18 pushd out_ios_ia32 / Release-iphonesimulator /;
 19 rm -f libapprtc_signaling.a;
 20 popd;
 21 mkdir -p out_ios_ia32 / libs;
 22 libtool -static -o out_ios_ia32 / libs / libWebRTC-ia32.a out_ios_ia32 / Release-iphonesimulator / lib * .a;
 23 strip -S -x -o out_ios_ia32 / libs / libWebRTC.a -r out_ios_ia32 / libs / libWebRTC-ia32.a;
 24 rm -f out_ios_ia32 / libs / libWebRTC-ia32.a;
 25 echo "*** result: $ PWD / out_ios_ia32 / libs / libWebRTC.a";
 26
 27 popd;
 28}
 29
 30 function build_iossim_x86_64 () {
 31 echo "*** building WebRTC for the x86_64 iOS simulator";
 32 export GYP_GENERATORS = "ninja";
 33 export GYP_DEFINES = "build_with_libjingle = 1 build_with_chromium = 0 libjingle_objc = 1 OS = ios target_arch = x64 target_subarch = arm64";
 34 export GYP_GENERATOR_FLAGS = "$ GYP_GENERATOR_FLAGS output_dir = out_ios_x86_64";
 35 export GYP_CROSSCOMPILE = 1;
 36 pushd src;
 37 gclient runhooks;
 38 ninja -C out_ios_x86_64 / Release-iphonesimulator iossim AppRTCDemo;
 39
 40 echo "*** creating iOS x86_64 libraries";
 41 pushd out_ios_x86_64 / Release-iphonesimulator /;
 42 rm -f libapprtc_signaling.a;
 43 popd;
 44 mkdir -p out_ios_x86_64 / libs;
 45 libtool -static -o out_ios_x86_64 / libs / libWebRTC-x86_64.a out_ios_x86_64 / Release-iphonesimulator / lib * .a;
 46 strip -S -x -o out_ios_x86_64 / libs / libWebRTC.a -r out_ios_x86_64 / libs / libWebRTC-x86_64.a;
 47 echo "*** result: $ PWD / out_ios_x86_64 / libs / libWebRTC.a";
 48
 49 popd;
 50}
 51
 52 function build_iosdevice_armv7 () {
 53 echo "*** building WebRTC for armv7 iOS devices";
 54 export GYP_GENERATORS = "ninja";
 55 export GYP_DEFINES = "build_with_libjingle = 1 build_with_chromium = 0 libjingle_objc = 1 OS = ios target_arch = armv7";
 56 export GYP_GENERATOR_FLAGS = "$ GYP_GENERATOR_FLAGS output_dir = out_ios_armv7";
 57 export GYP_CROSSCOMPILE = 1;
 58 pushd src;
 59 gclient runhooks;
 60 ninja -C out_ios_armv7 / Release-iphoneos AppRTCDemo;
 61
 62 echo "*** creating iOS armv7 libraries";
 63 pushd out_ios_armv7 / Release-iphoneos /;
 64 rm -f libapprtc_signaling.a;
 65 popd;
 66 mkdir -p out_ios_armv7 / libs;
 67 libtool -static -o out_ios_armv7 / libs / libWebRTC-armv7.a out_ios_armv7 / Release-iphoneos / lib * .a;
 68 strip -S -x -o out_ios_armv7 / libs / libWebRTC.a -r out_ios_armv7 / libs / libWebRTC-armv7.a;
 69 echo "*** result: $ PWD / out_ios_armv7 / libs / libWebRTC.a";
 70
 71 popd;
 72}
 73
 74 function build_iosdevice_arm64 () {
 75 echo "*** building WebRTC for arm64 iOS devices";
 76 export GYP_GENERATORS = "ninja";
 77 export GYP_DEFINES = "build_with_libjingle = 1 build_with_chromium = 0 libjingle_objc = 1 OS = iostarget_arch = arm64 target_subarch = arm64 ";
 78 export GYP_GENERATOR_FLAGS = "$ GYP_GENERATOR_FLAGS output_dir = out_ios_arm64";
 79 export GYP_CROSSCOMPILE = 1;
 80 pushd src;
 81 gclient runhooks;
 82 ninja -C out_ios_arm64 / Release-iphoneos AppRTCDemo;
 83
 84 echo "*** creating iOS arm64 libraries";
 85 pushd out_ios_arm64 / Release-iphoneos /;
 86 rm -f libapprtc_signaling.a;
 87 popd;
 88 mkdir -p out_ios_arm64 / libs;
 89 libtool -static -o out_ios_arm64 / libs / libWebRTC-arm64.a out_ios_arm64 / Release-iphoneos / lib * .a;
 90 strip -S -x -o out_ios_arm64 / libs / libWebRTC.a -r out_ios_arm64 / libs / libWebRTC-arm64.a;
 91 echo "*** result: $ PWD / out_ios_arm64 / libs / libWebRTC.a";
 92
 93 popd;
 94}
 95
 96 function combine_libs ()
 97 {
 98 echo "*** combining libraries";
 99 lipo -create src / out_ios_ia32 / libs / libWebRTC.a \
100 src / out_ios_x86_64 / libs / libWebRTC.a \
101 src / out_ios_armv7 / libs / libWebRTC.a \
102 src / out_ios_arm64 / libs / libWebRTC.a \
103 -output libWebRTC.a;
104 echo "The public headers are located in $ PWD / src / talk / app / webrtc / objc / public / *. H";
105}
106
107 function create_framework () {
108 echo "*** creating WebRTC.framework";
109 rm -rf WebRTC.framework;
110 mkdir -p WebRTC.framework / Versions / A / Headers;
111 cp ./src/talk/app/webrtc/objc/public/*.h WebRTC.framework / Versions / A / Headers;
112 cp libWebRTC.a WebRTC.framework / Versions / A / WebRTC;
113
114 pushd WebRTC.framework / Versions;
115 ln -sfh A Current;
116 popd;
117 pushd WebRTC.framework;
118 ln -sfh Versions / Current / Headers Headers;
119 ln -sfh Versions / Current / WebRTC WebRTC;
120 popd;
121}
122
123 function clean ()
124 {
125 echo "*** cleaning";
126 pushd src;
127 rm -rf out_ios_arm64 out_ios_armv7 out_ios_ia32 out_ios_x86_64;
128 popd;
129 echo "*** all cleaned";
130}
131
132 function update ()
133 {
134 gclient sync --force
135 pushd src
136 svn info | grep Revision> ../svn_rev.txt
137 popd
138}
139
140 function build_all () {
141 build_iossim_ia32 && build_iossim_x86_64 && \
142 build_iosdevice_armv7 && build_iosdevice_arm64 && \
143 combine_libs && create_framework;
144}
145
146 function run_simulator_ia32 () {
147 echo "*** running webrtc appdemo on ia32 iOS simulator";
148 src / out_ios_ia32 / Release-iphonesimulator / iossim src / out_ios_ia32 / Release-iphonesimulator / AppRTCDemo.app;
149}
150
151 function run_simulator_x86_64 () {
152 echo "*** running webrtc appdemo on x86_64 iOS simulator";
153 src / out_ios_x86_64 / Release-iphonesimulator / iossim -d 'iPhone 6' -s '8.1' src / out_ios_x86_64 / Release-iphonesimulator / AppRTCDemo.app;
154}
155
156 function run_on_device_armv7 () {
157 echo "*** launching on armv7 iOS device";
158 ideviceinstaller -i src / out_ios_armv7 / Release-iphoneos / AppRTCDemo.app;
159 echo "*** launch complete";
160}
161
162 function run_on_device_arm64 () {
163 echo "*** launching on arm64 iOS device";
164 ideviceinstaller -i src / out_ios_arm64 / Release-iphoneos / AppRTCDemo.app;
165 echo "*** launch complete";
166}
167
168 #Run the Shell function specified by the first parameter in the command line parameters
169 $ @
In addition to compiling the AppRTCDemo application that comes with the WebRTC project, this compilation script can also compile WebRTC.framework.

Execute the following command to compile everything we need:

wuqiong: webrtc apple $ ./build_webrtc.sh build_all
After the above command is completed, the WebRTC framework we need is in the current directory. You can use the ls command to view it:

wuqiong: webrtc apple $ ls
WebRTC.framework build_webrtc.sh libWebRTC.a src
wuqiong: webrtc apple $
The first WebRTC.framework is the framework we need! At this point, our compilation task is completed! Isn't that ... it's that simple? Isn't it super cumbersome to say? Haha, the installation is over. The tedious parts have been encapsulated Now you are in the shell script. If you are interested, you can research this script.

2.5 WebRTC.framework dependencies.
If the project uses the framework, then the following libraries and frameworks need to be added to the project's Build Phases when compiling:

libstdc ++. 6.dylib
libsqlite3.dylib
libc ++. dylib
libicucore.dylib
Security.framework
CFNetwork.framework
GLKit.framework
AudioToolbox.framework
AVFoundation.framework
CoreAudio.framework
CoreMedia.framework
CoreVideo.framework
CoreGraphics.framework
OpenGLES.framework
QuartzCore.framework
important hint
At present, Google's official code has a stackoverflow problem of VP8 video encoding on the ARMv7 platform, which will directly cause the program to crash. For more details and to obtain patches, please contact Camp David Education.

This document is organized by Changsha Camp David Education.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.