第五部分 OpenCore Player介绍
5.1 Player的组成
OpenCore的Player的编译文件是pvplayer/Android.mk,将生成动态库文件 libopencoreplayer.so。这个库包含了两方面的内容:一方是Player的engine(引擎),一方面是为Android构件的Player,这实际上是一个适配器(adapter)。engine的路径是engine/player;adapter的路径是android。
5.2 Player Engine部分
OpenCore的Player Engine具有清晰明确的接口。在这个接口之上,不同的系统可一个根据自己的情况实现不同Player。目录engines中的文件结构如下所示:
engines/player/
|-- Android.mk
|-- build
| |-- linux_nj
| |-- make
| `-- makefile.conf
|-- config
| `-- linux_nj
|-- include
| |-- pv_player_datasink.h
| |-- pv_player_datasinkfilename.h
| |-- pv_player_datasinkpvmfnode.h
| |-- pv_player_datasource.h
| |-- pv_player_datasourcepvmfnode.h
| |-- pv_player_datasourceurl.h
| |-- pv_player_events.h
| |-- pv_player_factory.h
| |-- pv_player_interface.h
| |-- pv_player_license_acquisition_interface.h
| |-- pv_player_registry_interface.h
| |-- pv_player_track_selection_interface.h
| `-- pv_player_types.h
|-- sample_app
| |-- Android.mk
| |-- build
| |-- sample_player_app_release.txt
| `-- src
|-- src
| |-- pv_player_datapath.cpp
| |-- pv_player_datapath.h
| |-- pv_player_engine.cpp
| |-- pv_player_engine.h
| |-- pv_player_factory.cpp
| |-- pv_player_node_registry.h
| `-- pv_player_sdkinfo.h
`-- test
|-- Android.mk
|-- build
|-- config
`-- src
在Player Engine的实现中,包含了编解码和流控制等功能,而输出的介质需要从外部设置进来。PVPlayerInterface定义的接口基本是按照操作顺序的,主要的接口如下所示:
PVCommandId AddDataSource(PVPlayerDataSource& aDataSource, const OsclAny* aContextData = NULL);
PVCommandId Init(const OsclAny* aContextData = NULL);
PVCommandId AddDataSink(PVPlayerDataSink& aDataSink, const OsclAny* aContextData = NULL);
PVCommandId Prepare(const OsclAny* aContextData = NULL);
PVCommandId Start(const OsclAny* aContextData = NULL);
PVCommandId Pause(const OsclAny* aContextData = NULL);
PVCommandId Resume(const OsclAny* aContextData = NULL);
PVCommandId Stop(const OsclAny* aContextData = NULL);
PVCommandId RemoveDataSink(PVPlayerDataSink& aDataSink, const OsclAny* aContextData = NULL);
PVCommandId Reset(const OsclAny* aContextData = NULL);
PVCommandId RemoveDataSource(PVPlayerDataSource& aDataSource, const OsclAny* aContextData = NULL);
这里面的DataSink可能包含Video的输出和Audio的输出两者部分。在pv_player_types.h文件中,定义了Player的状态机,以PVP_STATE_为开头,如下所示:
typedef enum
{
PVP_STATE_IDLE = 1,
PVP_STATE_INITIALIZED = 2,
PVP_STATE_PREPARED = 3,
PVP_STATE_STARTED = 4,
PVP_STATE_PAUSED = 5,
PVP_STATE_ERROR = 6
} PVPlayerState;
PVPlayerInterface 中的各个操作如果成功,可以更改Player的状态机:初始化的时候Player是PVP_STATE_IDLE状态,调用Init后,进入PVP_STATE_INITIALIZED状态;调用AddDataSink,进入PVP_STATE_PREPARED状态;调用Prepare后,进入PVP_STATE_PREPARED状态;调用start后进入PVP_STATE_STARTED状态,之后可以调用pause进入PVP_STATE_PAUSED状态。
PVP_STATE_STARTED和PVP_STATE_PAUSED状态是播放情况下的状态,可以使用start和pause函数在这两个状态中切换。在播放过程中,调用stop可以返回PVP_STATE_INITIALIZED状态,在调用RemoveDataSource返回PVP_STATE_IDLE状态。
5.3 Android Player部分
这个Android的Player的“适配器”需要调用OpenCore的Player Engine的接口,实现Android的媒体播放器的服务所需要接口,即最终实现一个PVPlayer,而PVPlayer实际上是继承了MediaPlayerInterface。在实现过程中,首先实现了一个PlayerDriver,然后再使用PVPlayer,PVPlayer通过调用PlayerDriver来完成具体的功能。对PVPlayerDriver的各种操作使用各种命令来完成,这些命令在playerdriver.h中进行的定义。
enum player_command_type {
PLAYER_QUIT = 1,
PLAYER_SETUP = 2,
PLAYER_SET_DATA_SOURCE = 3,
PLAYER_SET_VIDEO_SURFACE = 4,
PLAYER_SET_AUDIO_SINK = 5,
PLAYER_INIT = 6,
PLAYER_PREPARE = 7,
PLAYER_START = 8,
PLAYER_STOP = 9,
PLAYER_PAUSE = 10,
PLAYER_RESET = 11,
PLAYER_SET_LOOP = 12,
PLAYER_SEEK = 13,
PLAYER_GET_POSITION = 14,
PLAYER_GET_DURATION = 15,
PLAYER_GET_STATUS = 16,
PLAYER_REMOVE_DATA_SOURCE = 17,
PLAYER_CANCEL_ALL_COMMANDS = 18,
};
第六部分 OpenCore Author介绍
6.1 Android Author
android/author/
|-- Android.mk
|-- android_audio_input.cpp
|-- android_audio_input.h
|-- android_audio_input_threadsafe_callbacks.cpp
|-- android_audio_input_threadsafe_callbacks.h
|-- android_camera_input.cpp
|-- android_camera_input.h
|-- authordriver.cpp
|-- authordriver.h
`-- mediarecorder.cpp
6.2 author引擎
engines/author/
|-- Android.mk
|-- build
| |-- make
| `-- makefile
|-- include
| |-- pvauthorenginefactory.h
| `-- pvauthorengineinterface.h
|-- src
| |-- pvae_tuneables.h
| |-- pvaenodeutility.cpp
| |-- pvaenodeutility.h
| |-- pvauthorengine.cpp
| |-- pvauthorengine.h
| `-- single_core
`-- test
|-- Android.mk
|-- build
|-- config
|-- src
`-- test_input
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhandoushi1982/archive/2010/03/02/5337644.aspx