SlideShare a Scribd company logo
Confidential
Media Playback Flow
Javid Hsu
Confidential
Outline
 MediaPlayer Subsystem
 Related Files
 MediaPlayer Frame of Playing Flow
─ StageFright and AwesomePlayer Relatin
─ AwesomePlayer Frame and Playing Flow
 Simple Playing Implement
Confidential
Binder
MediaPlayer Subsystem
Java
MediaPlayer
(frameworks/base/media/java/android/media)
libmedia_jni.so
JNI
libmedia.so
(frameworks/av/media/libmedia)
libmediaplayerservice.so
(frameworks/av/media/
libmediaplayerservice)
libstagefright.so
libstagefright_omx.so
libstagefright_soft_XXX.so
(codec)
(frameworks/av/media/
libstagefright/*)
(frameworks/base/media/jni)
libaudioflinger.so
(frameworks/av/services/
audioflinger)
libstagefrighthw.so
libOMXVideoEncoderXX.so
libOMXVideoDecoderXX.so
(vendor codec (hw codec))
Confidential
Related Files
libmedia_jni.so (frameworks/base/media/jni) libmedia.so (frameworks/av/media/libmedia)
Confidential
Related Files
libmediaplayerservice.so
(frameworks/av/media/libmediaplayerservice)
libstagefright.so
(frameworks/av/media/libstagefright)
Confidential
Related Files
libaudioflinger.so
(frameworks/av/services/audioflinger)
Confidential
MediaPlayer Frame of Playing Flow
 Stagefright and AwesomePlayer Relation
Confidential
MediaPlayer Frame of Playing Flow
Ref: http://blog.csdn.net/tx3344/article/details/8084912
SurfaceFlinger
AudioFlinger
 AwesomePlayer Frame and Playing Flow
Ref: http://blog.csdn.net/tx3344/article/details/8109185
Confidential
Simple Playing Implement
//For example:
//Simple Playing Implement:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();
Ref: http://developer.android.com/reference/android/media/MediaPlayer.html
 MediaPlayer State Diagram
Confidential
Simple Playing Implement
//For example:
//Simple Playing Implement:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepareAsync();
mp.start();
Confidential
New MediaPlayer
Applications
Applications Framework
• Initiation and Setup
Media Player
Application
android_media_MediaPlayer
MediaPlayer.java
android_media_MediaPlayer_native_init()
android_media_MediaPlayer_native_setup()
Static{
System.loadLibrary("media_jni");
native_init();
}
static void android_media_MediaPlayer_native_init (JNIEnv *env){
clazz = env->FindClass("android/media/MediaPlayer");
:
fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
"(Ljava/lang/Object;IIILjava/lang/Object;)V");
:
fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
:
}
static void android_media_MediaPlayer_native_setup (JNIEnv *env, jobject thiz, jobject weak_this)
{
:
sp<MediaPlayer> mp = new MediaPlayer();
// create new listener and give it to MediaPlayer
sp<JNIMediaPlayerListener> listener = new JNIMediaPlayerListener(env, thiz, weak_this);
mp->setListener(listener);
// Stow our new C++ MediaPlayer in an opaque field in the Java object.
setMediaPlayer(env, thiz, mp);
}
static sp<MediaPlayer> setMediaPlayer (JNIEnv* env, jobject thiz, …)
{
Mutex::Autolock l(sLock);
:
env->SetIntField(thiz, fields.context, (int)player.get());
:
}
Confidential
Simple Playing Implement
//For example:
//Simple Playing Implement:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepareAsync();
mp.start();
Confidential
Libraries
(libmedia.so)
MediaPlayer
player->setDataSource
IMediaPlayer
Media Player
Application
android_media_MediaPlayer
MediaPlayer.java
Applications
Applications Framework
MediaPlayerService::
Client
Media Set Data Source Flow (setDataSource)
 SetDataSource
 Using file type to choose
 setDataSource_pre(player_type
playerType)…..
 Using real player to set data source
setDataSource()
android_media_MediaPlayer_setDataSourceFD()
setDataSource()
status_t MediaPlayerService::Client::setDataSource(int fd, int64_t offset,
int64_t length)
{
:
player_type playerType = MediaPlayerFactory::getPlayerType(this,
fd,
offset,
length);
sp<MediaPlayerBase> p = setDataSource_pre(playerType);
if (p == NULL) {
return NO_INIT;
}
:
// now set data source
setDataSource_post(p, p->setDataSource(fd, offset, length));
return mStatus;
}
Confidential
Media Set Data Source Flow (setDataSource)
Get Player Type
Create Player
Instance
Player Set Data
Source
 Using file type to get player type
 get real player instance
• Load software and hardware codec
• Register default sniffers
• Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate,
onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and
onAudioTearDownEvent.
• setNotifyCallback
 Using real player to set data source
• new FileSource(fd, …) insert to MediaExtractor::Create()
─ Sniff DataSource and get mine type
─ Get extractor with mime type
• Separate video (sp<MediaSource> mVideoTrack) and
audio (sp<MediaSource> mVideoSource) track
Confidential
Media Set Data Source Flow (setDataSource)
 Using file type to get player type
 get real player instance
• Load software and hardware codec
• Register default sniffers
• Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate,
onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and
onAudioTearDownEvent.
• setNotifyCallback
 Using real player to set data source
• new FileSource(fd, …) insert to MediaExtractor::Create()
─ Sniff DataSource and get mine type
─ Get extractor with mime type
• Separate video (sp<MediaSource> mVideoTrack) and
audio (sp<MediaSource> mVideoSource) track
Get Player Type
Create Player
Instance
Player Set Data
Source
Confidential
Libraries
Media Set Data Source Flow (setDataSource)
Using file type to get player type
MediaPlayerFactory.cpp
-factory: IFactory*
-sFactoryMap
NuPlayerFactory
+createPlayer(): return new NuPlayerDriver
SonivoxPlayerFactory
+createPlayer(): return new MidiFile
TestPlayerFactory
+createPlayer(): return new TestPlayerStub
StagefrightPlayerFactory
+createPlayer(): return new StagefrightPlayer
(libmedia.so)
MediaPlayer
player->setDataSource
MediaPlayerFactory
IMediaPlayer
Media Player
Application
android_media_MediaPlayerMediaPlayer.java
Applications
Applications Framework
MediaPlayerService::
Client
a. playerType:getPlayerType()
MediaPlayerFactory:
StagefrightPlayerFactory
createPlayer()
return new StagefrightPlayer();
setDataSource()
android_media_MediaPlayer_setDataSourceFD()
setDataSource()
b. sp<MediaPlayerBase>:
createPlayer(playerType)
a. getPlayerType:
1. sFactoryMap add all player factory while MediaPlayerService
started.
2. scoreFactory function using compare file
to get corresponding player type:
a. NuPlayerFactory
if(!strncasecmp("http://", url, 7)
|| !strncasecmp("https://", url, 8)
|| !strncasecmp("file://", url, 7))
b. SonivoxPlayerFactory
if (!strncasecmp(url + start, FILE_EXTS[i], len))
static const char* const FILE_EXTS[] = { ".mid",
".midi",
".smf",
".xmf",
".mxmf",
".imy",
".rtttl",
".rtx",
".ota" };
c. StagefrightPlayerFactory
1. compare raw data header if is equal to 0x5367674f
2. Default Player Type
Confidential
Media Set Data Source Flow (setDataSource)
Get Player Type
 Using file type to get player type
 get real player instance
• Load software and hardware codec
• Register default sniffers
• Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate,
onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and
onAudioTearDownEvent.
• setNotifyCallback
 Using real player to set data source
• new FileSource(fd, …) insert to MediaExtractor::Create()
─ Sniff DataSource and get mine type
─ Get extractor with mime type
• Separate video (sp<MediaSource> mVideoTrack) and
audio (sp<MediaSource> mVideoSource) track
Get Player Type
Create Player
Instance
Player Set Data
Source
Confidential
Media Set Data Source Flow (setDataSource)
Media Player
Application
Applications
android_media_MediaPlayer
Applications Framework
MediaPlayer.java
Libraries
• Load software and hardware codec
StagefrightPlayerMediaPlayerFactory
new StagefrightPlayer()
connect()
OMXClient
OMX
OMXMaster
OMX()
mMaster(new OMXMaster)
Software CodecHardware Codec
SoftOMXPlugin
AwesomePlayer
new AwesomePlayer()
libstagefrighthw.so
Confidential
Media Set Data Source Flow (setDataSource)
Media Player
Application
Applications
android_media_MediaPlayer
Applications Framework
MediaPlayer.java
Libraries
StagefrightPlayerMediaPlayerFactory
new StagefrightPlayer()
RegisterDefaultSniffers()
AwesomePlayer
new AwesomePlayer()
RegisterSniffer_l(SnifferFunc func)
MPEG4Extractor.cpp
MP3Extractor.cpp
bool SniffMP3(...)
:
:
1. SniffMPEG4 <--> MPEG4Extractor
2. SniffMatroska <--> MatroskaExtractor
3. SniffOgg <--> OggExtractor
4. SniffWAV <--> WAVExtractor
5. SniffFLAC <--> FLACExtractor
6. SniffAMR <--> AMRExtractor
7. SniffMPEG2TS <--> MPEG2TSExtractor
8. SniffMP3 <--> MP3Extractor
9. SniffAAC <--> AACExtractor
10. SniffMPEG2PS <--> MPEG2PSExtractor
11. SniffWVM <--> WVMExtractor
12. SniffAVI <--> AVIExtractor
All Sniff register in gSniffers
(List<SnifferFunc> gSniffers)
bool SniffMPEG4(...)
typedef bool (*SnifferFunc)(
const sp<DataSource> &source, String8 *mimeType,
float *confidence, sp<AMessage> *meta);
DataSource
• Register default sniffers
FileSource
DataSource
- static List<SnifferFunc> gSniffers
+static sp<DataSource> CreateFromUR()
+static void RegisterDefaultSniffers()
+static void RegisterSniffer_l()
+typedef bool (*SnifferFunc)()
+bool sniff()
+bool getUInt16()
+bool getUInt64()
+virtual ssize_t readAt()
+virtual String8 getMIMEType() const()
HTTPBase NuCachedSource2
:
Confidential
Media Set Data Source Flow (setDataSource)
Media Player
Application
Applications
android_media_MediaPlayer
Applications Framework
MediaPlayer.java
Libraries
StagefrightPlayerMediaPlayerFactory
new StagefrightPlayer() new AwesomePlayer()
AwesomePlayer
mVideoEvent
= new AwesomeEvent(this, &AwesomePlayer::onVideoEvent);
mStreamDoneEvent
= new AwesomeEvent(this, &AwesomePlayer::onStreamDone);
mBufferingEvent
= new AwesomeEvent(this, &AwesomePlayer::onBufferingUpdate);
mVideoLagEvent
= new AwesomeEvent(this, &AwesomePlayer::onVideoLagUpdate);
mThumbnailEvent
= new AwesomeEvent(this, &AwesomePlayer::onThumbnailEvent);
• Create AwesomeEvents of onVideoEvent …
Ref: http://blog.csdn.net/tx3344/article/details/8053106
Confidential
Applications
Applications Framework
Libraries
• set Notify Callback (before new MediaPlayer()) : AP -> HAL
APP : setOn##Listener(m##Listener);
MediaPlayer.java : setOn##Listener(listener){mOn##Listener=listener}
Media Player
Application
android_media_MediaPlayer_native_init(){
:
fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
"(Ljava/lang/Object;IIILjava/lang/Object;)V");
:
}
android_media_MediaPlayer
MediaPlayer.java
Static{
System.loadLibrary("media_jni");
native_init();
}
Media Set Data Source Flow (setDataSource)
Confidential
android_media_MediaPlayerMediaPlayer.java
(libmedia.so)
MediaPlayer
android_media_MediaPlayer_native_setup()
• set Notify Callback (new MediaPlayer()) : HAL -> C++
Applications
Applications Framework
Libraries
Media Player
Application
new MediaPlayer()
setListener(const sp<MediaPlayerListener>&listener)
{mListener = listener;}
listener = new JNIMediaPlayerListener(env, thiz, weak_this);
Media Set Data Source Flow (setDataSource)
Confidential
Media Player
Application
android_media_MediaPlayerMediaPlayer.java
MediaPlayerService
(libmedia.so)
MediaPlayer
player->setDataSource
MediaPlayerService::
Client
IMediaPlayer
• set Notify Callback (setDataSource(…)) : client -> service
Applications
Applications Framework
sp<Client> c
= new Client( const sp<MediaPlayerService>& service, pid_t pid,
int32_t connId, const p<IMediaPlayerClient>& client,
int audioSessionId, uid_t uid)
{
:
mClient = client;
:
}
service->create(this, mAudioSessionId)
Libraries
setDataSource()
android_media_MediaPlayer_setDataSourceFD()
setDataSource()
Media Set Data Source Flow (setDataSource)
Confidential
Libraries
MediaPlayerFactory
a. player_type:getPlayerType()
b. sp<MediaPlayerBase>:createPlayer(playerType, this, notify)
MediaPlayerService::
Client
• set Notify Callback (setDataSource(…)) : service -> player
StagefrightPlayer:public MediaPlayerInterface:
public MediaPlayerBase
void setNotifyCallback( void* cookie, notify_callback_f notifyFunc)
{
Mutex::Autolock autoLock(mNotifyLock);
mCookie = cookie; mNotify = notifyFunc;
}
void sendEvent(int msg, int ext1=0, int ext2=0, const Parcel *obj=NULL)
{
Mutex::Autolock autoLock(mNotifyLock);
if (mNotify) mNotify(mCookie, msg, ext1, ext2, obj);
}

Media Set Data Source Flow (setDataSource)
Media Player
Application
Applications
android_media_MediaPlayer
Applications Framework
MediaPlayer.java

StagefrightPlayer AwesomePlayer
mPlayer(new AwesomePlayer)
mPlayer->setListener(this)
Confidential
Libraries
(libmedia.so)
MediaPlayer
IMediaPlayer
Media Player
Application
android_media_MediaPlayer::
JNIMediaPlayerListenerMediaPlayer.java
Applications
Applications Framework
MediaPlayerService::
Client
• set Notify Callback (setDataSource(…)) : send message
AwesomePlayer.cpp
notifyListener_l(int msg, int ext1, int ext2)
{
:
listener->sendEvent(msg, ext1, ext2);
:
}
StagefrightPlayer:
public MediaPlayerInterface:
public MediaPlayerBase
Notify(int msg, …)
sendEvent(int msg, …)
Notify(int msg, …)
Notify((int msg, …)
postEventFromNative(int what, …)
• Media Event Type:
Media Set Data Source Flow (setDataSource)
Confidential
Media Set Data Source Flow (setDataSource)
 Using file type to get player type
 get real player instance
• Load software and hardware codec
• Register default sniffers
• Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate,
onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and
onAudioTearDownEvent.
• setNotifyCallback
 Using real player to set data source
• new FileSource(fd, …) insert to MediaExtractor::Create()
─ Sniff DataSource and get mine type
─ Get extractor with mime type
• Separate video (sp<MediaSource> mVideoTrack) and
audio (sp<MediaSource> mVideoSource) track
Get Player TypeGet Player Type
Create Player
Instance
Player Set Data
Source
Confidential
Media Set Data Source Flow (setDataSource)
AwesomePlayer.cpp
setDataSource_l(dataSource)
MediaExtractor.cpp
Create(dataSource)
if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4)
|| !strcasecmp(mime, "audio/mp4")) {
ret = new MPEG4Extractor(source);
:
:
return ret;
DataSource.cpp
sniff(mimeType,…)
setDataSource_l(extractor)
extractor
 Using Real Player Set Data Source
• MediaExtractor::Create(const sp<DataSource> &source,...)
─ Sniff DataSource and get mine type
 Read at filesource
 Compabile ?
 Write mine type
─ Get extractor with mime type
Confidential
Media Set Data Source Flow (setDataSource)
─ Sniff DataSource and get mine type
 Read at filesource
 Compabile ?
 Write mine type
─ Get extractor with mime type
 Compabile ?
 Read at filesource: Ex: Golden Flower mp4
 Write mine type
Confidential
Media Set Data Source Flow (setDataSource)
 Using Real Player Set Data Source
• Separate video and audio track
Video track
Audio track
Confidential
Simple Playing Implement
//For example:
//Simple Playing Implement:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepareAsync();
mp.start();
Confidential
AwesomePlayer.cpp
status_t prepareAsync(){
return prepareAsync_l();
}
status_t prepareAsync_l(){
new AsyncPrepareEvent;
postEvent();
return OK;
}
onPrepareAsyncEvent()
 initVideoDecoder
 initAudioDecoder
 notifyVideoSize_l
 notifyListener_l
AwesomePlayer.cpp
status_t prepare(){
prepareAsync_l(…)
condition.wait(Mutex)
}
status_t prepareAsync_l(){
:
:
}
onPrepareAsyncEvent()
 initVideoDecoder
 initAudioDecoder
 condition.broadcast();
• prepare • prepareAsync
 prepare V.S. prepareAsync (AwesomePlayer)
Media Set Data Source Flow (setDataSource)
Confidential
Libraries
MediaPlayerService::
Client
(libmedia.so)
MediaPlayer
IMediaPlayer
Media Player
Application
android_media_MediaPlayerMediaPlayer.java
Applications
Applications Framework
Media Set Data Source Flow (setDataSource)
 prepareAsync
prepareAsync()
android_media_MediaPlayer_prepareAsync()
prepareAsync()
mPlayer->prepareAsync()
StagefrightPlayer
prepareAsync() prepareAsync()
AwesomePlayer
AwesomePlayer::
initVideoDecoder()
AwesomePlayer::
initAudioDecoder()
TimedEventQueue::
start()
Confidential
Media Set Data Source Flow (setDataSource)
 initVideoDecoder
• How to choose codec
AwesomePlayer
mVideoSource
initVideoDecoder()
findMatchingCodecs(mime, componentName, …)
MediaCodecList : cat /etc/media_codecs.xml
OMXCodec
create(…MetaData, MediaSource, …)
makeComponentInstance(name, callbacks…)
Load the corresponding module and register callback
functions.
Callback Function:
OMX_CALLBACKTYPE OMXNodeInstance::kCallbacks = {
&OnEvent, &OnEmptyBufferDone, &OnFillBufferDone
};
libstagefrighthw.so
Confidential
Media Set Data Source Flow (setDataSource)
 Video Playback Flow
Ref: http://www.cnblogs.com/shakin/p/4729534.html
Confidential
Simple Playing Implement
//For example:
//Simple Playing Implement:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepareAsync();
mp.start();
Confidential
Libraries
MediaPlayerService::
Client
(libmedia.so)
MediaPlayer
IMediaPlayer
Media Player
Application
android_media_MediaPlayer
MediaPlayer.java
Applications
Applications Framework
MediaPlay Start
 Start()
start()
android_media_MediaPlayer_start()
start()
mPlayer->start ()
StagefrightPlayer
start()
play()
AwesomePlayerAudioPlayer
start()
postVideoEvent_l()
AwesomePlayer::
onVideoEvent()
Confidential
Video Audio Synchronization
Playing point
Audio Samples
Video Samples
Start Point
The Time in AudioPlayer Real Playing
The Time in Audi Real Playing out
 Playback Time Line:
Playing point
latenessUs (VideoPlayer Lateness Time)
Confidential
The End

More Related Content

What's hot

Understanding open max il
Understanding open max ilUnderstanding open max il
Understanding open max il
Chethan Pchethan
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
Opersys inc.
 
Android audio system(audioplicy_service)
Android audio system(audioplicy_service)Android audio system(audioplicy_service)
Android audio system(audioplicy_service)
fefe7270
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia Framework
Opersys inc.
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
Emertxe Information Technologies Pvt Ltd
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
Emertxe Information Technologies Pvt Ltd
 
Android audio system(오디오 출력-트랙생성)
Android audio system(오디오 출력-트랙생성)Android audio system(오디오 출력-트랙생성)
Android audio system(오디오 출력-트랙생성)fefe7270
 
08 android multimedia_framework_overview
08 android multimedia_framework_overview08 android multimedia_framework_overview
08 android multimedia_framework_overview
Arjun Reddy
 
A practical guide to buildroot
A practical guide to buildrootA practical guide to buildroot
A practical guide to buildroot
Emertxe Information Technologies Pvt Ltd
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
Opersys inc.
 
Android audio system(audiopolicy_manager)
Android audio system(audiopolicy_manager)Android audio system(audiopolicy_manager)
Android audio system(audiopolicy_manager)fefe7270
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
Omkar Rane
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
Opersys inc.
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updates
Gary Bisson
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
Emertxe Information Technologies Pvt Ltd
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
Emertxe Information Technologies Pvt Ltd
 
linux device driver
linux device driverlinux device driver
linux device driver
Rahul Batra
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
Emertxe Information Technologies Pvt Ltd
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
National Cheng Kung University
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
Yu-Hsin Hung
 

What's hot (20)

Understanding open max il
Understanding open max ilUnderstanding open max il
Understanding open max il
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Android audio system(audioplicy_service)
Android audio system(audioplicy_service)Android audio system(audioplicy_service)
Android audio system(audioplicy_service)
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia Framework
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Android audio system(오디오 출력-트랙생성)
Android audio system(오디오 출력-트랙생성)Android audio system(오디오 출력-트랙생성)
Android audio system(오디오 출력-트랙생성)
 
08 android multimedia_framework_overview
08 android multimedia_framework_overview08 android multimedia_framework_overview
08 android multimedia_framework_overview
 
A practical guide to buildroot
A practical guide to buildrootA practical guide to buildroot
A practical guide to buildroot
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Android audio system(audiopolicy_manager)
Android audio system(audiopolicy_manager)Android audio system(audiopolicy_manager)
Android audio system(audiopolicy_manager)
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updates
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
linux device driver
linux device driverlinux device driver
linux device driver
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
 

Viewers also liked

A slightly deeper dive into Stagefright
A slightly deeper dive into StagefrightA slightly deeper dive into Stagefright
A slightly deeper dive into Stagefright
Alexy Joseph
 
Video Streaming
Video StreamingVideo Streaming
Video Streaming
University of Salford
 
Building an Android Scale Incident Response Process
Building an Android Scale Incident Response ProcessBuilding an Android Scale Incident Response Process
Building an Android Scale Incident Response Process
Priyanka Aash
 
Art of public speaking
Art of public speakingArt of public speaking
Art of public speaking
Imprint Training Center
 
Farewell, Stagefright bugs!
Farewell, Stagefright bugs!Farewell, Stagefright bugs!
Farewell, Stagefright bugs!
Tsukasa Oi
 
Stagefright (1)
Stagefright (1)Stagefright (1)
Stagefright (1)
Mamoon Ismail Khalid
 
Stagefright
StagefrightStagefright
Fuzzing the Media Framework in Android
Fuzzing the Media Framework in AndroidFuzzing the Media Framework in Android
Fuzzing the Media Framework in Android
E Hacking
 
Video Streaming - 4.ppt
Video Streaming - 4.pptVideo Streaming - 4.ppt
Video Streaming - 4.ppt
Videoguy
 
Streaming Media Protocols
Streaming Media ProtocolsStreaming Media Protocols
Streaming Media Protocols
sanjoysanyal
 
Streaming media presentation
Streaming media presentationStreaming media presentation
Streaming media presentation
Kyra Walton
 
Audio and Video streaming.ppt
Audio and Video streaming.pptAudio and Video streaming.ppt
Audio and Video streaming.ppt
Videoguy
 
Media Source Extensions
Media Source ExtensionsMedia Source Extensions
Media Source Extensions
FITC
 

Viewers also liked (13)

A slightly deeper dive into Stagefright
A slightly deeper dive into StagefrightA slightly deeper dive into Stagefright
A slightly deeper dive into Stagefright
 
Video Streaming
Video StreamingVideo Streaming
Video Streaming
 
Building an Android Scale Incident Response Process
Building an Android Scale Incident Response ProcessBuilding an Android Scale Incident Response Process
Building an Android Scale Incident Response Process
 
Art of public speaking
Art of public speakingArt of public speaking
Art of public speaking
 
Farewell, Stagefright bugs!
Farewell, Stagefright bugs!Farewell, Stagefright bugs!
Farewell, Stagefright bugs!
 
Stagefright (1)
Stagefright (1)Stagefright (1)
Stagefright (1)
 
Stagefright
StagefrightStagefright
Stagefright
 
Fuzzing the Media Framework in Android
Fuzzing the Media Framework in AndroidFuzzing the Media Framework in Android
Fuzzing the Media Framework in Android
 
Video Streaming - 4.ppt
Video Streaming - 4.pptVideo Streaming - 4.ppt
Video Streaming - 4.ppt
 
Streaming Media Protocols
Streaming Media ProtocolsStreaming Media Protocols
Streaming Media Protocols
 
Streaming media presentation
Streaming media presentationStreaming media presentation
Streaming media presentation
 
Audio and Video streaming.ppt
Audio and Video streaming.pptAudio and Video streaming.ppt
Audio and Video streaming.ppt
 
Media Source Extensions
Media Source ExtensionsMedia Source Extensions
Media Source Extensions
 

Similar to MediaPlayer Playing Flow

Windows Azure Media Services June 2013 update
Windows Azure Media Services June 2013 updateWindows Azure Media Services June 2013 update
Windows Azure Media Services June 2013 update
Mingfei Yan
 
yapi.js introduction (mopcon 2016 version)
yapi.js introduction (mopcon 2016 version)yapi.js introduction (mopcon 2016 version)
yapi.js introduction (mopcon 2016 version)
Jesse (Chien Chen) Chen
 
Lesson 4 hardware
Lesson 4   hardwareLesson 4   hardware
Lesson 4 hardware
mrcmorrison
 
Android media
Android mediaAndroid media
Android media
Krazy Koder
 
MIDP: Music and Sound
MIDP: Music and SoundMIDP: Music and Sound
MIDP: Music and Sound
Jussi Pohjolainen
 
IIS Smooth Streaming
IIS Smooth StreamingIIS Smooth Streaming
IIS Smooth Streaming
Hossein Sarshar
 
JAM316 - Native API Deep Dive: Multimedia Playback & Streaming
JAM316 - Native API Deep Dive: Multimedia Playback & StreamingJAM316 - Native API Deep Dive: Multimedia Playback & Streaming
JAM316 - Native API Deep Dive: Multimedia Playback & Streaming
Dr. Ranbijay Kumar
 
Developing rich multimedia applications with FI-WARE.
Developing rich multimedia applications with FI-WARE.Developing rich multimedia applications with FI-WARE.
Developing rich multimedia applications with FI-WARE.
Luis Lopez
 
MNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensicsMNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensics
MNCERT
 
Streaming Media over the Internet
Streaming Media over the InternetStreaming Media over the Internet
Streaming Media over the Internet
Videoguy
 
Standardize Your Flash with Adobe OSMF (0.9)
Standardize Your Flash with Adobe OSMF (0.9)Standardize Your Flash with Adobe OSMF (0.9)
Standardize Your Flash with Adobe OSMF (0.9)
rblank9
 
Lecture 4 - Data Acquisition1234_MH.pptx
Lecture 4 - Data Acquisition1234_MH.pptxLecture 4 - Data Acquisition1234_MH.pptx
Lecture 4 - Data Acquisition1234_MH.pptx
muhammadosama0121
 
Android Multimedia Support
Android Multimedia SupportAndroid Multimedia Support
Android Multimedia Support
Jussi Pohjolainen
 
Introduction to AV Foundation
Introduction to AV FoundationIntroduction to AV Foundation
Introduction to AV Foundation
Chris Adamson
 
Chapter 2.1 : Data Stream
Chapter 2.1 : Data StreamChapter 2.1 : Data Stream
Chapter 2.1 : Data Stream
Ministry of Higher Education
 
Multimedia on android
Multimedia on androidMultimedia on android
Multimedia on android
Ramesh Prasad
 
Audio and video streaming
Audio and video streamingAudio and video streaming
Audio and video streaming
Rohan Bhatkar
 
Exoplayer 2
Exoplayer  2Exoplayer  2
Exoplayer 2
TSE-JU LIN(Louis)
 
Introducing Android Media Player
Introducing Android Media PlayerIntroducing Android Media Player
Introducing Android Media Player
Arif Huda
 
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 -  Advanced Malware AnalysisReversing & Malware Analysis Training Part 9 -  Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
securityxploded
 

Similar to MediaPlayer Playing Flow (20)

Windows Azure Media Services June 2013 update
Windows Azure Media Services June 2013 updateWindows Azure Media Services June 2013 update
Windows Azure Media Services June 2013 update
 
yapi.js introduction (mopcon 2016 version)
yapi.js introduction (mopcon 2016 version)yapi.js introduction (mopcon 2016 version)
yapi.js introduction (mopcon 2016 version)
 
Lesson 4 hardware
Lesson 4   hardwareLesson 4   hardware
Lesson 4 hardware
 
Android media
Android mediaAndroid media
Android media
 
MIDP: Music and Sound
MIDP: Music and SoundMIDP: Music and Sound
MIDP: Music and Sound
 
IIS Smooth Streaming
IIS Smooth StreamingIIS Smooth Streaming
IIS Smooth Streaming
 
JAM316 - Native API Deep Dive: Multimedia Playback & Streaming
JAM316 - Native API Deep Dive: Multimedia Playback & StreamingJAM316 - Native API Deep Dive: Multimedia Playback & Streaming
JAM316 - Native API Deep Dive: Multimedia Playback & Streaming
 
Developing rich multimedia applications with FI-WARE.
Developing rich multimedia applications with FI-WARE.Developing rich multimedia applications with FI-WARE.
Developing rich multimedia applications with FI-WARE.
 
MNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensicsMNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensics
 
Streaming Media over the Internet
Streaming Media over the InternetStreaming Media over the Internet
Streaming Media over the Internet
 
Standardize Your Flash with Adobe OSMF (0.9)
Standardize Your Flash with Adobe OSMF (0.9)Standardize Your Flash with Adobe OSMF (0.9)
Standardize Your Flash with Adobe OSMF (0.9)
 
Lecture 4 - Data Acquisition1234_MH.pptx
Lecture 4 - Data Acquisition1234_MH.pptxLecture 4 - Data Acquisition1234_MH.pptx
Lecture 4 - Data Acquisition1234_MH.pptx
 
Android Multimedia Support
Android Multimedia SupportAndroid Multimedia Support
Android Multimedia Support
 
Introduction to AV Foundation
Introduction to AV FoundationIntroduction to AV Foundation
Introduction to AV Foundation
 
Chapter 2.1 : Data Stream
Chapter 2.1 : Data StreamChapter 2.1 : Data Stream
Chapter 2.1 : Data Stream
 
Multimedia on android
Multimedia on androidMultimedia on android
Multimedia on android
 
Audio and video streaming
Audio and video streamingAudio and video streaming
Audio and video streaming
 
Exoplayer 2
Exoplayer  2Exoplayer  2
Exoplayer 2
 
Introducing Android Media Player
Introducing Android Media PlayerIntroducing Android Media Player
Introducing Android Media Player
 
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 -  Advanced Malware AnalysisReversing & Malware Analysis Training Part 9 -  Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
 

Recently uploaded

Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 

Recently uploaded (20)

Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 

MediaPlayer Playing Flow

  • 2. Confidential Outline  MediaPlayer Subsystem  Related Files  MediaPlayer Frame of Playing Flow ─ StageFright and AwesomePlayer Relatin ─ AwesomePlayer Frame and Playing Flow  Simple Playing Implement
  • 7. Confidential MediaPlayer Frame of Playing Flow  Stagefright and AwesomePlayer Relation
  • 8. Confidential MediaPlayer Frame of Playing Flow Ref: http://blog.csdn.net/tx3344/article/details/8084912 SurfaceFlinger AudioFlinger  AwesomePlayer Frame and Playing Flow Ref: http://blog.csdn.net/tx3344/article/details/8109185
  • 9. Confidential Simple Playing Implement //For example: //Simple Playing Implement: MediaPlayer mp = new MediaPlayer(); mp.setDataSource(PATH_TO_FILE); mp.prepare(); mp.start(); Ref: http://developer.android.com/reference/android/media/MediaPlayer.html  MediaPlayer State Diagram
  • 10. Confidential Simple Playing Implement //For example: //Simple Playing Implement: MediaPlayer mp = new MediaPlayer(); mp.setDataSource(PATH_TO_FILE); mp.prepareAsync(); mp.start();
  • 11. Confidential New MediaPlayer Applications Applications Framework • Initiation and Setup Media Player Application android_media_MediaPlayer MediaPlayer.java android_media_MediaPlayer_native_init() android_media_MediaPlayer_native_setup() Static{ System.loadLibrary("media_jni"); native_init(); } static void android_media_MediaPlayer_native_init (JNIEnv *env){ clazz = env->FindClass("android/media/MediaPlayer"); : fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", "(Ljava/lang/Object;IIILjava/lang/Object;)V"); : fields.context = env->GetFieldID(clazz, "mNativeContext", "I"); : } static void android_media_MediaPlayer_native_setup (JNIEnv *env, jobject thiz, jobject weak_this) { : sp<MediaPlayer> mp = new MediaPlayer(); // create new listener and give it to MediaPlayer sp<JNIMediaPlayerListener> listener = new JNIMediaPlayerListener(env, thiz, weak_this); mp->setListener(listener); // Stow our new C++ MediaPlayer in an opaque field in the Java object. setMediaPlayer(env, thiz, mp); } static sp<MediaPlayer> setMediaPlayer (JNIEnv* env, jobject thiz, …) { Mutex::Autolock l(sLock); : env->SetIntField(thiz, fields.context, (int)player.get()); : }
  • 12. Confidential Simple Playing Implement //For example: //Simple Playing Implement: MediaPlayer mp = new MediaPlayer(); mp.setDataSource(PATH_TO_FILE); mp.prepareAsync(); mp.start();
  • 13. Confidential Libraries (libmedia.so) MediaPlayer player->setDataSource IMediaPlayer Media Player Application android_media_MediaPlayer MediaPlayer.java Applications Applications Framework MediaPlayerService:: Client Media Set Data Source Flow (setDataSource)  SetDataSource  Using file type to choose  setDataSource_pre(player_type playerType)…..  Using real player to set data source setDataSource() android_media_MediaPlayer_setDataSourceFD() setDataSource() status_t MediaPlayerService::Client::setDataSource(int fd, int64_t offset, int64_t length) { : player_type playerType = MediaPlayerFactory::getPlayerType(this, fd, offset, length); sp<MediaPlayerBase> p = setDataSource_pre(playerType); if (p == NULL) { return NO_INIT; } : // now set data source setDataSource_post(p, p->setDataSource(fd, offset, length)); return mStatus; }
  • 14. Confidential Media Set Data Source Flow (setDataSource) Get Player Type Create Player Instance Player Set Data Source  Using file type to get player type  get real player instance • Load software and hardware codec • Register default sniffers • Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate, onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and onAudioTearDownEvent. • setNotifyCallback  Using real player to set data source • new FileSource(fd, …) insert to MediaExtractor::Create() ─ Sniff DataSource and get mine type ─ Get extractor with mime type • Separate video (sp<MediaSource> mVideoTrack) and audio (sp<MediaSource> mVideoSource) track
  • 15. Confidential Media Set Data Source Flow (setDataSource)  Using file type to get player type  get real player instance • Load software and hardware codec • Register default sniffers • Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate, onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and onAudioTearDownEvent. • setNotifyCallback  Using real player to set data source • new FileSource(fd, …) insert to MediaExtractor::Create() ─ Sniff DataSource and get mine type ─ Get extractor with mime type • Separate video (sp<MediaSource> mVideoTrack) and audio (sp<MediaSource> mVideoSource) track Get Player Type Create Player Instance Player Set Data Source
  • 16. Confidential Libraries Media Set Data Source Flow (setDataSource) Using file type to get player type MediaPlayerFactory.cpp -factory: IFactory* -sFactoryMap NuPlayerFactory +createPlayer(): return new NuPlayerDriver SonivoxPlayerFactory +createPlayer(): return new MidiFile TestPlayerFactory +createPlayer(): return new TestPlayerStub StagefrightPlayerFactory +createPlayer(): return new StagefrightPlayer (libmedia.so) MediaPlayer player->setDataSource MediaPlayerFactory IMediaPlayer Media Player Application android_media_MediaPlayerMediaPlayer.java Applications Applications Framework MediaPlayerService:: Client a. playerType:getPlayerType() MediaPlayerFactory: StagefrightPlayerFactory createPlayer() return new StagefrightPlayer(); setDataSource() android_media_MediaPlayer_setDataSourceFD() setDataSource() b. sp<MediaPlayerBase>: createPlayer(playerType) a. getPlayerType: 1. sFactoryMap add all player factory while MediaPlayerService started. 2. scoreFactory function using compare file to get corresponding player type: a. NuPlayerFactory if(!strncasecmp("http://", url, 7) || !strncasecmp("https://", url, 8) || !strncasecmp("file://", url, 7)) b. SonivoxPlayerFactory if (!strncasecmp(url + start, FILE_EXTS[i], len)) static const char* const FILE_EXTS[] = { ".mid", ".midi", ".smf", ".xmf", ".mxmf", ".imy", ".rtttl", ".rtx", ".ota" }; c. StagefrightPlayerFactory 1. compare raw data header if is equal to 0x5367674f 2. Default Player Type
  • 17. Confidential Media Set Data Source Flow (setDataSource) Get Player Type  Using file type to get player type  get real player instance • Load software and hardware codec • Register default sniffers • Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate, onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and onAudioTearDownEvent. • setNotifyCallback  Using real player to set data source • new FileSource(fd, …) insert to MediaExtractor::Create() ─ Sniff DataSource and get mine type ─ Get extractor with mime type • Separate video (sp<MediaSource> mVideoTrack) and audio (sp<MediaSource> mVideoSource) track Get Player Type Create Player Instance Player Set Data Source
  • 18. Confidential Media Set Data Source Flow (setDataSource) Media Player Application Applications android_media_MediaPlayer Applications Framework MediaPlayer.java Libraries • Load software and hardware codec StagefrightPlayerMediaPlayerFactory new StagefrightPlayer() connect() OMXClient OMX OMXMaster OMX() mMaster(new OMXMaster) Software CodecHardware Codec SoftOMXPlugin AwesomePlayer new AwesomePlayer() libstagefrighthw.so
  • 19. Confidential Media Set Data Source Flow (setDataSource) Media Player Application Applications android_media_MediaPlayer Applications Framework MediaPlayer.java Libraries StagefrightPlayerMediaPlayerFactory new StagefrightPlayer() RegisterDefaultSniffers() AwesomePlayer new AwesomePlayer() RegisterSniffer_l(SnifferFunc func) MPEG4Extractor.cpp MP3Extractor.cpp bool SniffMP3(...) : : 1. SniffMPEG4 <--> MPEG4Extractor 2. SniffMatroska <--> MatroskaExtractor 3. SniffOgg <--> OggExtractor 4. SniffWAV <--> WAVExtractor 5. SniffFLAC <--> FLACExtractor 6. SniffAMR <--> AMRExtractor 7. SniffMPEG2TS <--> MPEG2TSExtractor 8. SniffMP3 <--> MP3Extractor 9. SniffAAC <--> AACExtractor 10. SniffMPEG2PS <--> MPEG2PSExtractor 11. SniffWVM <--> WVMExtractor 12. SniffAVI <--> AVIExtractor All Sniff register in gSniffers (List<SnifferFunc> gSniffers) bool SniffMPEG4(...) typedef bool (*SnifferFunc)( const sp<DataSource> &source, String8 *mimeType, float *confidence, sp<AMessage> *meta); DataSource • Register default sniffers FileSource DataSource - static List<SnifferFunc> gSniffers +static sp<DataSource> CreateFromUR() +static void RegisterDefaultSniffers() +static void RegisterSniffer_l() +typedef bool (*SnifferFunc)() +bool sniff() +bool getUInt16() +bool getUInt64() +virtual ssize_t readAt() +virtual String8 getMIMEType() const() HTTPBase NuCachedSource2 :
  • 20. Confidential Media Set Data Source Flow (setDataSource) Media Player Application Applications android_media_MediaPlayer Applications Framework MediaPlayer.java Libraries StagefrightPlayerMediaPlayerFactory new StagefrightPlayer() new AwesomePlayer() AwesomePlayer mVideoEvent = new AwesomeEvent(this, &AwesomePlayer::onVideoEvent); mStreamDoneEvent = new AwesomeEvent(this, &AwesomePlayer::onStreamDone); mBufferingEvent = new AwesomeEvent(this, &AwesomePlayer::onBufferingUpdate); mVideoLagEvent = new AwesomeEvent(this, &AwesomePlayer::onVideoLagUpdate); mThumbnailEvent = new AwesomeEvent(this, &AwesomePlayer::onThumbnailEvent); • Create AwesomeEvents of onVideoEvent … Ref: http://blog.csdn.net/tx3344/article/details/8053106
  • 21. Confidential Applications Applications Framework Libraries • set Notify Callback (before new MediaPlayer()) : AP -> HAL APP : setOn##Listener(m##Listener); MediaPlayer.java : setOn##Listener(listener){mOn##Listener=listener} Media Player Application android_media_MediaPlayer_native_init(){ : fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", "(Ljava/lang/Object;IIILjava/lang/Object;)V"); : } android_media_MediaPlayer MediaPlayer.java Static{ System.loadLibrary("media_jni"); native_init(); } Media Set Data Source Flow (setDataSource)
  • 22. Confidential android_media_MediaPlayerMediaPlayer.java (libmedia.so) MediaPlayer android_media_MediaPlayer_native_setup() • set Notify Callback (new MediaPlayer()) : HAL -> C++ Applications Applications Framework Libraries Media Player Application new MediaPlayer() setListener(const sp<MediaPlayerListener>&listener) {mListener = listener;} listener = new JNIMediaPlayerListener(env, thiz, weak_this); Media Set Data Source Flow (setDataSource)
  • 23. Confidential Media Player Application android_media_MediaPlayerMediaPlayer.java MediaPlayerService (libmedia.so) MediaPlayer player->setDataSource MediaPlayerService:: Client IMediaPlayer • set Notify Callback (setDataSource(…)) : client -> service Applications Applications Framework sp<Client> c = new Client( const sp<MediaPlayerService>& service, pid_t pid, int32_t connId, const p<IMediaPlayerClient>& client, int audioSessionId, uid_t uid) { : mClient = client; : } service->create(this, mAudioSessionId) Libraries setDataSource() android_media_MediaPlayer_setDataSourceFD() setDataSource() Media Set Data Source Flow (setDataSource)
  • 24. Confidential Libraries MediaPlayerFactory a. player_type:getPlayerType() b. sp<MediaPlayerBase>:createPlayer(playerType, this, notify) MediaPlayerService:: Client • set Notify Callback (setDataSource(…)) : service -> player StagefrightPlayer:public MediaPlayerInterface: public MediaPlayerBase void setNotifyCallback( void* cookie, notify_callback_f notifyFunc) { Mutex::Autolock autoLock(mNotifyLock); mCookie = cookie; mNotify = notifyFunc; } void sendEvent(int msg, int ext1=0, int ext2=0, const Parcel *obj=NULL) { Mutex::Autolock autoLock(mNotifyLock); if (mNotify) mNotify(mCookie, msg, ext1, ext2, obj); }  Media Set Data Source Flow (setDataSource) Media Player Application Applications android_media_MediaPlayer Applications Framework MediaPlayer.java  StagefrightPlayer AwesomePlayer mPlayer(new AwesomePlayer) mPlayer->setListener(this)
  • 25. Confidential Libraries (libmedia.so) MediaPlayer IMediaPlayer Media Player Application android_media_MediaPlayer:: JNIMediaPlayerListenerMediaPlayer.java Applications Applications Framework MediaPlayerService:: Client • set Notify Callback (setDataSource(…)) : send message AwesomePlayer.cpp notifyListener_l(int msg, int ext1, int ext2) { : listener->sendEvent(msg, ext1, ext2); : } StagefrightPlayer: public MediaPlayerInterface: public MediaPlayerBase Notify(int msg, …) sendEvent(int msg, …) Notify(int msg, …) Notify((int msg, …) postEventFromNative(int what, …) • Media Event Type: Media Set Data Source Flow (setDataSource)
  • 26. Confidential Media Set Data Source Flow (setDataSource)  Using file type to get player type  get real player instance • Load software and hardware codec • Register default sniffers • Create AwesomeEvents of onVideoEvent, onStreamDone, onBufferingUpdate, onVideoLagUpdate, onThumbnailEvent, onCheckAudioStatus and onAudioTearDownEvent. • setNotifyCallback  Using real player to set data source • new FileSource(fd, …) insert to MediaExtractor::Create() ─ Sniff DataSource and get mine type ─ Get extractor with mime type • Separate video (sp<MediaSource> mVideoTrack) and audio (sp<MediaSource> mVideoSource) track Get Player TypeGet Player Type Create Player Instance Player Set Data Source
  • 27. Confidential Media Set Data Source Flow (setDataSource) AwesomePlayer.cpp setDataSource_l(dataSource) MediaExtractor.cpp Create(dataSource) if (!strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4) || !strcasecmp(mime, "audio/mp4")) { ret = new MPEG4Extractor(source); : : return ret; DataSource.cpp sniff(mimeType,…) setDataSource_l(extractor) extractor  Using Real Player Set Data Source • MediaExtractor::Create(const sp<DataSource> &source,...) ─ Sniff DataSource and get mine type  Read at filesource  Compabile ?  Write mine type ─ Get extractor with mime type
  • 28. Confidential Media Set Data Source Flow (setDataSource) ─ Sniff DataSource and get mine type  Read at filesource  Compabile ?  Write mine type ─ Get extractor with mime type  Compabile ?  Read at filesource: Ex: Golden Flower mp4  Write mine type
  • 29. Confidential Media Set Data Source Flow (setDataSource)  Using Real Player Set Data Source • Separate video and audio track Video track Audio track
  • 30. Confidential Simple Playing Implement //For example: //Simple Playing Implement: MediaPlayer mp = new MediaPlayer(); mp.setDataSource(PATH_TO_FILE); mp.prepareAsync(); mp.start();
  • 31. Confidential AwesomePlayer.cpp status_t prepareAsync(){ return prepareAsync_l(); } status_t prepareAsync_l(){ new AsyncPrepareEvent; postEvent(); return OK; } onPrepareAsyncEvent()  initVideoDecoder  initAudioDecoder  notifyVideoSize_l  notifyListener_l AwesomePlayer.cpp status_t prepare(){ prepareAsync_l(…) condition.wait(Mutex) } status_t prepareAsync_l(){ : : } onPrepareAsyncEvent()  initVideoDecoder  initAudioDecoder  condition.broadcast(); • prepare • prepareAsync  prepare V.S. prepareAsync (AwesomePlayer) Media Set Data Source Flow (setDataSource)
  • 32. Confidential Libraries MediaPlayerService:: Client (libmedia.so) MediaPlayer IMediaPlayer Media Player Application android_media_MediaPlayerMediaPlayer.java Applications Applications Framework Media Set Data Source Flow (setDataSource)  prepareAsync prepareAsync() android_media_MediaPlayer_prepareAsync() prepareAsync() mPlayer->prepareAsync() StagefrightPlayer prepareAsync() prepareAsync() AwesomePlayer AwesomePlayer:: initVideoDecoder() AwesomePlayer:: initAudioDecoder() TimedEventQueue:: start()
  • 33. Confidential Media Set Data Source Flow (setDataSource)  initVideoDecoder • How to choose codec AwesomePlayer mVideoSource initVideoDecoder() findMatchingCodecs(mime, componentName, …) MediaCodecList : cat /etc/media_codecs.xml OMXCodec create(…MetaData, MediaSource, …) makeComponentInstance(name, callbacks…) Load the corresponding module and register callback functions. Callback Function: OMX_CALLBACKTYPE OMXNodeInstance::kCallbacks = { &OnEvent, &OnEmptyBufferDone, &OnFillBufferDone }; libstagefrighthw.so
  • 34. Confidential Media Set Data Source Flow (setDataSource)  Video Playback Flow Ref: http://www.cnblogs.com/shakin/p/4729534.html
  • 35. Confidential Simple Playing Implement //For example: //Simple Playing Implement: MediaPlayer mp = new MediaPlayer(); mp.setDataSource(PATH_TO_FILE); mp.prepareAsync(); mp.start();
  • 36. Confidential Libraries MediaPlayerService:: Client (libmedia.so) MediaPlayer IMediaPlayer Media Player Application android_media_MediaPlayer MediaPlayer.java Applications Applications Framework MediaPlay Start  Start() start() android_media_MediaPlayer_start() start() mPlayer->start () StagefrightPlayer start() play() AwesomePlayerAudioPlayer start() postVideoEvent_l() AwesomePlayer:: onVideoEvent()
  • 37. Confidential Video Audio Synchronization Playing point Audio Samples Video Samples Start Point The Time in AudioPlayer Real Playing The Time in Audi Real Playing out  Playback Time Line: Playing point latenessUs (VideoPlayer Lateness Time)