Android Multimedia Framework

43,297 views 40 slides Aug 15, 2012
Slide 1
Slide 1 of 40
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40

About This Presentation

This slide shows how the StageFright framework works on the Android.


Slide Content

Android Multimedia
Framework

on Jelly Bean

Author: Picker

Introduction to OpenMAX

Platform Media Framework

PD penMAX (IL peines mt conventos
Audio Video

Media Engines - CPUs, DSP, Hardware Accelerators etc.

independently from the other layers

OpenMAX layers can be none together or

Resource from Khronos::OpenMAX

Application Application

Application

Multimedia Framework / Middleware

E
System Media Driver

OpenMAX Integration Layer

Component Component Component
Interface Interface Interface

Codec

OpenMAX Development Layer

DL Primitives DL Primitives

Resource from Khronos::OpenMAX

from
Multimedia Framework

to
OpenMAX

Application Application

Application

Multimedia Framework / Middleware

E
System Media Driver

OpenMAX Integration Layer

Component Component Component
Interface Interface Interface

Codec

OpenMAX Development Layer

DL Primitives DL Primitives

Resource from Khronos::OpenMAX

Application Application
Application
Multimedia Framework / Middleware
| E
OpenMAX Integration Layer
Component Component Component |
Interface Interface Interface !
Codec Codec E
|
for cet of compen ie —— |
OpenMAX Development Layer
DL Primitives DL Primitives

Resource from Khronos::OpenMAX

Go through the OpenMAX

Operating System

APPLICATIONS

Se ae eee .__ AN

APPLICATION FRAMEWORK

Manager Manager Providers System Manager

Manager

LIBRARIES ANDROID RUNTIME

Surface Media 3 e T EN

Manager Framework Libraries

Dalvik Virtua

OpenGL|ES FreeType
Machine

LINUX KERNEL

Display Camera Bluetooth Flash Memory Binder (IPC)
Driver Driver Driver Driver Driver

USB Keypad WiFi Audio Power
Driver Driver Driver Drivers Management

The simple stack architecture

Developer API (MediaPlayer)

EventHandler SurfaceHolder

Big picture of the StageFright

StageFright Framework
TimedEventQueue| OMXCodec | OMXClient

Renderer == DO EEE —]

AudioPlayer MediaExtractor

The Simple Workflow

Applications
Media Player
Application
Application Framework
Mediaplayer ————>_android_media_MediaPlayer
Libraries
(mediaplayer.cpp)__ Mediaplayerservice —> StageFrightPlayer
M layer |
AwesomePlayer
AudioPlayer MediaExtractor OMXCodec TimedEvent Queue — AwesomeLocalRenderer
MPEGAEXtractor omx SoftwareRenderer

;

ColorConverter

The StageFright Workflow

2. Get the Audio Track &
Video Track.

Developer API (MediaPlayer)

1. Create an extractor for the Media File.

5. Decoded video data

AwesomeRenderer

4. Return the decoded data

5. Sync the audio &
video time

Y

TimedQueueEvent

3. Put the media source into the codec

5. Decoded audio data

AudioPlayer

Path of All the Components

Path of the Source Files

APPLICATI
frameworks/base/media/java/android/media

APPLICATION FRAMEW

frameworks/base/media/jni

LIBRARIES ANDROID RUNTIME

frameworks/av/media/libmedia
frameworks/av/media/libmediaplayerservice

frameworks/av/media/libstagefright

LINUX KERNEL

Big Picture

Class Diagram

Il

High-Level Applications Framework

Applications Framewarl

+ Mediaplayer (MediaPlayerClien

[reeibatasourced frequent

+ Mediatiayertiort

[leretibranegy + |
H Ea
a
+ android. media MediaPlayer rentransact (sequential ‘FaetiediaPlayerSenieed troquet

[vaetOatasouree)) (eequentialy
prepared) (sequential
[+astart0 {sequential

be = edapTeyarservee,
[Forester] (sequential)
Fseidatasocen Teee een DE
‘Toervideosuracetesture() (sequential) get OM {sequential
prepareasyned tsequertal}
status 10 (sequential FastDatasoureen Teequertaly

start {sequent

TEMER GAS {prepared secuen

Hs Estan {sequential

+prepareñsircl (sequent
Ranas pool ÉsotLoopng fsoquertal)
‘Ssetvalomed) sequentaly

ER
= WaciaPrayarseniee FAUODUpUE
‘eeibataSoureel) ear
+ Client | FrerestePlayert (sequently
Ésotoatasource) fsoquential
DOUTE estan (sequently

LEE TE ETUI

Il

+ Riatwewndowa] [7 SufareTeurechent

StageF right Framework

ad

ce Cocos FestgeureeO fsequenta
stan (coqueta + Mediasours
SevetTed [sequental

[#paus00 (soquortia)
resume {sequential

amen fia

0530 raqueta

atada

F Re] [EA] [VE
ended Gener PEGAR E

rs ocean

ee: |

Tr pc il RL

A ]

asivatasourced Tauern AL LENS
Fonade sale)

repare) fesquerta)
Biss) troquet F0 raqueta
Éprepareñaynet) {sequential}

“Stand teequential}
Stpestudeotvert 10 {cequential)

nee indus

Frodo
A st0p0 (sequential)
postEvend (sequen

amic FORE

Freannea Teequertan)
+ dacomectí [sequential

a a

e
+ Hediatodeetat

geimstancel (eequentany
Éinécodecsyname0 {sequential
indcodecéyrpe0 (sequential)
-getsuppertedtypest) {eequentialy

EL

FaRemoreoMe
[+miocalona

+getomxd {sequentialy
J} +lsiiiodost) (sequential)
+senccommando) (sequential)
+sotParamotart) (sequential)
L+getParametent) {sequential}

om

FOMINodein sance

-lisiNodest) feequertial)
4+senccommand,) (sequential)
“+getParameter() {sequential}

OpenMAX Interface | =

-=AddVendorPlugin) {sequential b
+addPlugind (sequential)
/+makeComponentinstanceO {sequertial}

OPI + SoROWICompanent
[-makecomponentnstance0 (sequential) HB Handied) (sequential
+ dostroyComponentinstance() (sequential)

SimplesoROMicomponent

‘FonwessageRaceived) (sequently

ade

= SORMPEGA] E AGE

Four Steps for Playing the Media File

Step 1: MediaPlayer mp = new MediaPlayer();
Step 2: mp.setDataSource(mediaPath);

Step 3: mp.prepare();

Step 4: mp.start();

reset)

E —

prepareAsyncQ,

onEiror(),


OnPreparedlistene onPrepared)

prepareAsync)

Looping — true &&
playback completes

seekTo(/pause()

Looping — false &&
onCompletion() invoked on

stopQ \\ OnCompletionlist

stan)
(note: fim beginning)

seckTo()

How to set the data source?

The workflow of the setDataSource

Media Player
Application

setDataSource()

Application Framework

MediaPlayer android_media_ MediaPlayer

setDataSource()

setDataSource()

a j mom) |

create) setDataSource() setDataSource()

Return the type of the MediaExtractor Get the Track and MetaData

Create the extractor

The sequence flow of the setDataSource

seDataSourceo | OnBrrorListener ESC D

prepare Async()

OnPreparedListener. onPreparedO

prepareAsync()

Looping = true &&
playback completes

ho, seckTo(/fpause()

Looping — false &&
onCompletion() invoked on

stop. \ OnCompletionlist

start)
(note: lpm beginning)

seckTo()

How to prepare to play?

The workflow of the prepare

Media Player
Application

prepare()

Application Framework

MediaPlayer android_media_MediaPlayer

prepare()

prepareAsync()

Create the AwesomeEvent for

preparing the synchronization postEvent()

The sequence flow of the prepare

Meda

Peer gemir Ame OS

setvideosutaceTedtured. |

prepareñsynct)

seDataSourceQ | OnBrrorListener u)

prepareAsync()

OnPreparedListener.onPreparedQ)

Looping = true &&
playback completes

bo seckToOfpause)

Looping = false &&

onCompletion( invoked on
OnCompletionList an

(note: beginning)

seekToQ

How to start the playing?

The workflow of the start

Media Player
Application

MediaPlayer

Application Framework

android| media_MediaPlayer

postVideoEvent_I()

The sequence flow of the start

mea

pare

Ar

tat

Fern
>

Synchronization Architecture of StageFright

Em Ea

Synchronization Flow of StageFright

5. onVideoLagUpdate.
Call the postVideoLagEvent_I() to

3. onVideoEvent handle the delay.

1. Call the start) to
start audio player

2. Synchronize playing.
Catch the timing of the video & audio

Y

| TimedQueueEvent

AudioPlayer

2. in the fillBuffer(), the memepy() will be
called in order to copy the data buffer
for renderer

4, Call the postVideoEvent( for rendering

The Synchronization Formula of StageFright

sizedone
mFrameSize )
mSampleRate

mNumF ramesP layed +

mPositionTimeRealsUs =( Xx 1000000

mTimeSourceDeltaUs =mPositionTimeRealUs —mPositionTimeMediaUs
nowUs= RealTimeUs— mTimeSourceDeltaUs

latenessUs= now Us — timeUs

mPositionTimeRealsUs: the time in real playing
mPositionTimeMediaUs: the time which is defined in the media source

The Synchronization Conditions

Conditions of latenessUs
1. > 5000001!

2. >40000
3. <-10000 1750 if (latenessUs > 5000001!
1751 && mAudioPlayer != NULL
1752 && mAudioPlayer->getMediaTimeMapping(
1753 &realTimeUs, &mediaTimeUs)) {
1757 mVideoBuffer->release();
1758 mVideoBuffer = NULL;
1763 postVideoEvent_10);
1764 return;
1765 }
1767 if (latenessUs > 40000) {
1768 // We're more than 40ms late. 1793 if (latenessUs < -10000) {
à 1794 II We're more than 10ms early.
ee Te aire 1795 postVideoEvent_I(10000);
mydeoBuflen= d 1796 return;
1787 2007
1788 postVideoEvent_I();
1789 return;

1791s}

Conclusion

*Easy for maintaining rather than OpenCore
eSupport Software/Hardware Codecs
-Unstable Product
«Rough Mechanisms
° Create the NuPlayer for playing the
multimedia streaming