Project

General

Profile

WIPVideo » History » Version 41

Saúl Ibarra Corretgé, 02/13/2015 10:08 AM

1 40 Saúl Ibarra Corretgé
h1. Video Support
2 1 Saúl Ibarra Corretgé
3
4
h2. Dependencies
5
6
The following dependencies are required to build PJSIP with video support (including H264)
7
8
* ffmpeg (libavformat, libswscale, libavcodec, libavutil)
9
* libx264
10
11
Versions I have tried:
12
13 41 Saúl Ibarra Corretgé
* ffmpeg 2.5.3
14
* libx264 (snapshot-20141218-2245)
15 1 Saúl Ibarra Corretgé
16 20 Saúl Ibarra Corretgé
h2. Installing dependencies (Debian / Ubuntu systems)
17
18
The situation here is a bit sad. Both Debian and Ubuntu ship with libav instead of FFmpeg, but libraries are called the same. PJSIP had to be patched in order to properly work with libav, and the patch as not yet been included upstream.
19 1 Saúl Ibarra Corretgé
20 20 Saúl Ibarra Corretgé
On Debian, when the Debian-Multimedia repositories are used (quite common) you get FFmpeg and not libav. Oh the joy!
21
22
Installing dependencies on Debian:
23
24
<pre>
25 34 Saúl Ibarra Corretgé
apt-get install libv4l-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libx264-dev libavcodec-extra
26 1 Saúl Ibarra Corretgé
</pre>
27 20 Saúl Ibarra Corretgé
28
If using the Debian-Multimedia repositories, do not install libavcodec-extra.
29
30
Installing dependencies on Ubuntu:
31
32
<pre>
33 39 Saúl Ibarra Corretgé
apt-get install libv4l-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libx264-dev libavcodec-extra
34 20 Saúl Ibarra Corretgé
</pre>
35 1 Saúl Ibarra Corretgé
36 20 Saúl Ibarra Corretgé
*Note on H.264 support*: In order to have H.264 support, FFmpeg (or libav) need to be compiled with support for it. The standard packages don't, hence the need for installing the libavcodec-extra packages.
37 21 Saúl Ibarra Corretgé
38 41 Saúl Ibarra Corretgé
h2. Manually compiling dependencies (for OSX)
39 1 Saúl Ibarra Corretgé
40 3 Saúl Ibarra Corretgé
All dependencies will be compiled to a directory in the user's HOME directory:
41 1 Saúl Ibarra Corretgé
42 3 Saúl Ibarra Corretgé
<pre>
43 41 Saúl Ibarra Corretgé
export SIPSIMPLE_FFMPEG_PATH=$HOME/work/ag-projects/video/local
44 3 Saúl Ibarra Corretgé
</pre>
45
46 41 Saúl Ibarra Corretgé
NOTE: yasm is required in order to enable asm optimizations. It does not come preinstalled on OSX, so it has to be manually installed. (brew install yasn will do)
47 36 Saúl Ibarra Corretgé
48 3 Saúl Ibarra Corretgé
h3. libx264
49 37 Saúl Ibarra Corretgé
50 3 Saúl Ibarra Corretgé
51 1 Saúl Ibarra Corretgé
<pre>
52 41 Saúl Ibarra Corretgé
./configure --enable-shared --disable-avs --disable-lavf --disable-ffms --disable-gpac --prefix=$SIPSIMPLE_FFMPEG_PATH
53 1 Saúl Ibarra Corretgé
make
54 8 Saúl Ibarra Corretgé
make install
55 37 Saúl Ibarra Corretgé
</pre>
56 1 Saúl Ibarra Corretgé
57 3 Saúl Ibarra Corretgé
h3. ffmpeg
58
59 35 Saúl Ibarra Corretgé
<pre>
60
# Some exports
61 41 Saúl Ibarra Corretgé
export PKG_CONFIG_PATH=$SIPSIMPLE_FFMPEG_PATH/lib/pkgconfig
62 35 Saúl Ibarra Corretgé
63 41 Saúl Ibarra Corretgé
./configure --enable-shared --disable-static --enable-memalign-hack --enable-gpl --enable-libx264 --prefix=$SIPSIMPLE_FFMPEG_PATH --extra-cflags="`pkg-config --cflags x264`" --extra-ldflags="`pkg-config --libs x264`"
64 4 Saúl Ibarra Corretgé
make
65
make install
66
</pre>
67 12 Saúl Ibarra Corretgé
68 41 Saúl Ibarra Corretgé
h2. API
69 34 Saúl Ibarra Corretgé
70 13 Saúl Ibarra Corretgé
API for video components is based on 2 different types of video capable entities:
71
72
* VideoProducer: a source for video data, for example a video camera or a remote video stream
73
* VideoConsumer: a sink or destination for video data, for example a video rendering window
74
75
h3. Data flow
76
77
Data flow works in _pull_ fashion, that is, a producer doesn't start to produce data until there is a consumer which will consume it.
78
79
h3. VideoProducer
80
81
Produces video data. 
82
83
Internal API:
84
85 1 Saúl Ibarra Corretgé
* _add_consumer: attach a consumer, called by the consumer
86 13 Saúl Ibarra Corretgé
* _remove_consumer: detach a consumer from a producer, called by the consumer
87
88
89 18 Saúl Ibarra Corretgé
Public API:
90 1 Saúl Ibarra Corretgé
91
* start: start producing video as soon as a consumer is attached
92 18 Saúl Ibarra Corretgé
* stop: immediately stop producing data
93
* close: remove all consumers and stop producing video data (also deallocate all C structures)
94 29 Saúl Ibarra Corretgé
* producer_port: pointer to the pjmedia_port object
95 14 Saúl Ibarra Corretgé
96
h3. VideoConsumer
97
98
Consumes video data.
99
100
Public API:
101
102
* producer: (r/w property) attach this consumer to a producer, in order to render the video data generated by the producer. If set to None, it's detached
103 24 Saúl Ibarra Corretgé
* consumer_port: pointer to the pjmedia_port object
104 14 Saúl Ibarra Corretgé
* close: detach from producer and free all resources (also deallocate all C structures)
105 30 Saúl Ibarra Corretgé
106 15 Saúl Ibarra Corretgé
h3. Producer and consumer objects
107
108
* VideoDevice: Producer, acquires video from a user camera.
109
* VideoWindow: Consumer, renders video in an SDL window. Extra methods: show/hide. Properties: native_handle, size.
110
111
* LocalVideoStream: Consumer, takes video from a VideoDevice and sends it to the remote party.
112
* RemoteVideoStream: Producer, produces video sent by the remote party.
113
114
These are just theoretical objects, won't be implemented in the first go.
115
116 1 Saúl Ibarra Corretgé
* VideoFileWriter: Consumer, saves incoming video data to a video file.
117 17 Saúl Ibarra Corretgé
* VideoFilePlayer: Producer, produces video data out of a video file.
118 15 Saúl Ibarra Corretgé
119
* VideoMixer: Producer/Consumer, consumes video from multiple sources and produces aggregated video data.
120
121 16 Saúl Ibarra Corretgé
NOTE: pjsip does have a AVI file player, which also seems to support audio. (this could be used to stream a movie, for example)
122 34 Saúl Ibarra Corretgé
123 23 Saúl Ibarra Corretgé
h2. H264
124
125
Information about H264 profiles:
126
127
* http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Levels
128
* https://supportforums.cisco.com/blog/149561/video-telepresence-sip-h264-profile-level-id
129 28 Saúl Ibarra Corretgé
130
h2. OpenH264 implementation
131
132
PJSIP has an initial version of a wrapper for Cisco's OpenH264 implementation (http://www.openh264.org/). http://trac.pjsip.org/repos/changeset?reponame=&old=4815%40%2F&new=4815%40%2F
133
134 41 Saúl Ibarra Corretgé
OpenH264 seems to implement SVC, which is better than AVC. In practice it didn't outperform libx264 and it only implements the constrained baseline profile, so it was discarded.