问题描述
检查源$ C $下的MediaPlayer
(),在的start()
的方法是这样的:
Checking the source code for MediaPlayer
(link), the start()
method looks like this:
public void start() throws IllegalStateException {
stayAwake(true);
_start();
}
和 _start()
的方法是这样的:
private native void _start() throws IllegalStateException;
检查本机 _start()
办法(的)(称为的start()
,但如果它不能被称为 _start()
因为本机调用被命名为 _start()
):
Checking the native _start()
method (link) (called start()
but should it not be called _start()
because of the native call was named _start()
?):
status_t MediaPlayer::start()
{
ALOGV("start");
Mutex::Autolock _l(mLock);
if (mCurrentState & MEDIA_PLAYER_STARTED)
return NO_ERROR;
if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED |
MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) {
mPlayer->setLooping(mLoop);
mPlayer->setVolume(mLeftVolume, mRightVolume);
mPlayer->setAuxEffectSendLevel(mSendLevel);
mCurrentState = MEDIA_PLAYER_STARTED;
status_t ret = mPlayer->start();
if (ret != NO_ERROR) {
mCurrentState = MEDIA_PLAYER_STATE_ERROR;
} else {
if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) {
ALOGV("playback completed immediately following start()");
}
}
return ret;
}
ALOGE("start called in state %d", mCurrentState);
return INVALID_OPERATION;
}
在哪里数据读?我想检查与RTSP如何Android的工作,但我无法找出它加载数据。我想知道如果它使用象FFmpeg的或其他执行某些库。
Where is the data read? I wanted to check how Android work with RTSP but I could not find out where it loads the data. I wanted to know if it uses some library like FFMpeg or some other implementation.
编辑:
为什么这个必要code使用JNI的?
Why was this code necessary to use JNI for?
推荐答案
所有的以下路径引用的src /框架/基/.
All of the following paths reference src/frameworks/base/.
在媒体/ JNI / android_media_MediaPlayer.cpp你会发现JNI code转发该Java方法调用底层的本地框架。你可以看到 gMethods []
阵列和 AndroidRuntime :: registerNativeMethods
的底部附近调用的名称映射文件。你可以阅读更多有关注册的本地方法使用JNI的,但是这并不是真正有趣的部分。
In media/jni/android_media_MediaPlayer.cpp you will find the JNI code that forwards the Java method call to the underlying native framework. You can see the name mapping in the gMethods[]
array and the AndroidRuntime::registerNativeMethods
call near the bottom of the file. You can read more about registering native methods with JNI here, but that's not really the interesting part.
目前这个阶段,我们在Java 的MediaPlayer
的天然对应。在大多数情况下,它不会做什么有趣的事,无论是。它结合了 MediaPlayerService
到的IBinder
交易。该 MediaPlayerService
创建的实际的基础上,介质类型本土球员,并维护客户端(MediaPlayerService <$ C C $> ::客户端),以方便与本机的MediaPlayer
,从而气泡的东西备份到Java通信。你可以看到这一切发生在以下文件(如果你有兴趣):
At this stage we are in the native counterpart of the Java MediaPlayer
. For the most part, it doesn't do anything interesting, either. It binds to the MediaPlayerService
through IBinder
transactions. The MediaPlayerService
creates the actual native player based on the type of media, and maintains a client (MediaPlayerService::Client
) to facilitate communication with the native MediaPlayer
, which in turn bubbles things back up to Java. You can see all this happen in the following files (if you're interested):
媒体/ libmedia / mediaplayer.cpp, 媒体/ libmedia / IMediaPlayer.cpp, 媒体/ libmedia / IMediaPlayerClient.cpp, 媒体/ libmedia / IMediaPlayerService.cpp, 媒体/ libmediaplayerservice / MediaPlayerService.cpp
头文件libmedia在包括/媒体/ libmedia /.
Header files for libmedia are in include/media/libmedia/.
现在到了真正有趣的部分,这是部分球员。在MediaServicePlayer.cpp有几个 getPlayerType
中的方法决定哪些球员实例。有Stagefright框架(AwesomePlayer和NuPlayer)和MIDI Sonivox球员。对于RTSP,NuPlayer是你会得到什么。你可以找到一个胶层媒体/ libmediaplayerservice / nuplayer /和所有的真正来源$ C $ c在媒体/ libstagefright /和媒体/ libstagefright / RTSP /.
Now to the really interesting part, which are the component players. In MediaServicePlayer.cpp there are a couple of getPlayerType
methods that decide what player to instantiate. There's Stagefright framework (AwesomePlayer and NuPlayer) and Sonivox player for MIDI. For RTSP, NuPlayer is what you'll get. You can find a glue layer in media/libmediaplayerservice/nuplayer/ and all the real source code in media/libstagefright/ and media/libstagefright/rtsp/.
这篇关于如何通过检查本地code Android的MediaPlayer的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!