android大牛MrJing 活动中心

项目正在进展中。

我现在已经有一些资料。有兴趣的同志加入我们。留下脚步。

此文章会不断更新。

参考资料:

流媒体:

视频服务器在目前视频领域中的应用,主要是利用网络视频服务器构建远程监控系统。基于网络视频服务器的多通道数字传播技术,具有传统的模拟视频输出系统无可比拟的诸多优势。但要使网络视频监控得到普及还有待于解决以下问题:尽快提高视频压缩的技术水平,目前先进的压缩标准H.264可以部分解决视频质量和网络带宽占用这个矛盾。

  H.264/AVC标准是一种高性能的视频编解码技术,相比以前的标准,具有更高的压缩率、高质量图像、容错功能、并有很强的网络适应性。

  随着Android技术的迅猛发展和日趋成熟,其开放性、便携性、良好的兼容性、无缝结合网络通信等特点将使Android操作系统在未来工业领域中有广泛的应用。

Android 系统整体架构:

我们先看一下多媒体框架在整个Android系统所处的位置

从框架图可以看出Media Framework处于Libraries这一层,这层的Library不是用Java实现,一般是C/C++实现,它们通过Java的JNI方式调用。

多媒体架构:

基于第三方PacketVideo公司的OpenCORE platform来实现

支持所有通用的音频,视频,静态图像格式

CODEC(编解码器)使用OpenMAX 1L interface接口进行扩展,可以方便得支持hardware / software codec plug-ins

支持的格式包括:MPEG4、H.264、MP3、AAC、AMR、JPG、PNG、GIF等。

lOpen Core多媒体框架有一套通用可扩展的接口针对第三方的多媒体遍解码器,输入,输出设备等等。

l多媒体文件的播放,下载,包括3GPP, MPEG-4,AAC and MP3 containers

l流媒体文件的下载,实时播放,包括:3GPP, HTTP and RTSP/RTP

l动态视频和静态图像的编码,解码,例如:MPEG-4, H.263 and AVC (H.264), JPEG

l语音编码格式:AMR-NB and AMR-WB

l音乐编码格式:MP3, AAC, AAC+

l视频和图像格式:3GPP, MPEG-4 and JPEG

l视频会议:基于H324-M standard

图中用黄线圈出的是Media Framework

Open Core介绍:

Open Core是Android多媒体框架的核心,所有Android平台的音视频采集,播放的操作都是通过它来实现。它也被称为PV(Packet Video), Packet Video是一家专门提供多媒体解决方案的公司。

通过Open Core程序员可以方便快速的开发出想要的多媒体应用程序,,例如:音视频的采集,回放,视频会议,实时的流媒体播放等等应用。

Open Core框架

代码结构:

Open Core的代码在Android代码的External/Opencore目录中。这个目录是OpenCore的根目录,其中包含的子目录如下所示:

android:这里面是一个上层的库,它实现了一个为Android使用的音视频采集,播放的接口,和DRM数字版权管理的接口实现。

baselibs:包含数据结构和线程安全等内容的底层库

codecs_v2:音视频的编解码器,基于OpenMAX实现

engines:核心部分,多媒体引擎的实现

extern_libs_v2:包含了khronos的OpenMAX的头文件

fileformats:文件格式的解析(parser)工具

nodes:提供一些PVMF的NODE,主要是编解码和文件解析方面的。

oscl:操作系统兼容库

pvmi:输入输出控制的抽象接口

protocols:主要是与网络相关的RTSP、RTP、HTTP等协议的相关内容

pvcommon:pvcommon库文件的Android.mk文件,没有源文件。

pvplayer:pvplayer库文件的Android.mk文件,没有源文件。

pvauthor:pvauthor库文件的Android.mk文件,没有源文件。

tools_v2:编译工具以及一些可注册的模块。

Open Core上层代码结构

在实际开发中我们并不会过多的研究Open Core的实现,Android提供了上层的Media API给开发人员使用,MediaPlayer和MediaRecorder

Android Media APIs

lThe Android platform is capable of playing both audio and video media. It is also capable of playing media contained in the resources for an application, or a standalone file in the filesystem, or even streaming media over a data connection. Playback is achieved through theandroid.media.MediaPlayer class.

lThe Android platform can also record audio. Video recording capabilities are coming in the future. This is achieved through theandroid.media.MediaRecorder class.

Media Player

提供的基本接口如下:

Public Methods

staticMediaPlayercreate(Context context,Uri uri)

Convenience method to create a MediaPlayer for a given Uri.

intgetCurrentPosition()

Gets the current playback position.

intgetDuration()

Gets the duration of the file.

intgetVideoHeight()

Returns the height of the video.

intgetVideoWidth()

Returns the width of the video.

booleanisPlaying()

Checks whether the MediaPlayer is playing.

voidpause()

Pauses playback.

voidprepare()

Prepares the player for playback, synchronously.

voidprepareAsync()

Prepares the player for playback, asynchronously.

voidrelease()

Releases resources associated with this MediaPlayer object.

voidreset()

Resets the MediaPlayer to its uninitialized state.

voidseekTo(int msec)

Seeks to specified time position.

voidsetAudioStreamType(int streamtype)

Sets the audio stream type for this MediaPlayer.

voidsetDataSource(String path)

Sets the data source (file-path or http/rtsp URL) to use.

voidsetDisplay(SurfaceHolder sh)

Sets the SurfaceHolder to use for displaying the video portion of the media.

voidsetVolume(float leftVolume, float rightVolume)

Sets the volume on this player.

voidstart()

Starts or resumes playback.

voidstop()

Stops playback after playback has been stopped or paused.

我们可以看出MediaPlayer类提供了一个多媒体播放器的基本操作,播放,暂停,停止,设置音量等等。

简单的例子:

Playing a File

MediaPlayer mp = new MediaPlayer();

mp.setDataSource(PATH_TO_FILE);

mp.prepare();

mp.start();

Playing a Raw Resource

MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);

mp.start();

Media Recorder

提供的基本接口如下:

Public Method:

voidprepare()

Prepares the recorder to begin capturing and encoding data.

voidrelease()

Releases resources associated with this MediaRecorder object.

voidreset()

Restarts the MediaRecorder to its idle state.

voidsetAudioEncoder(int audio_encoder)

Sets the audio encoder to be used for recording.

voidsetAudioSource(int audio_source)

Sets the audio source to be used for recording.

voidsetOutputFile(String path)

Sets the path of the output file to be produced.

voidsetOutputFormat(int output_format)

Sets the format of the output file produced during recording.

voidsetPreviewDisplay(Surface sv)

Sets a Surface to show a preview of recorded media (video).

voidstart()

Begins capturing and encoding data to the file specified with setOutputFile().

voidstop()

Stops recording.

简单的例子:

Example:

MediaRecorder recorder = new MediaRecorder();

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

recorder.setOutputFile(PATH_NAME);

recorder.prepare();

recorder.start(); // Recording is now started … recorder.stop();

recorder.reset(); // You can reuse the object by going back to

setAudioSource() step

recorder.release(); // Now the object cannot be reused

整体的结构如下图所示:

lMediaPlayer JNI

代码位置 /frameworks/base/media/jni

lMediaPlayer (Native)

代码位置 /frameworks/base/media/libmedia

lMediaPlayerService (Server)

代码位置 /frameworks/base/media/libmediaplayerservice

lMediaPlayerService Host Process

代码位置 /frameworks/base/media/mediaserver/main_mediaserver.cpp

lPVPlayer

代码位置 /external/opencore/android/

实际调用过程如下图所示:

请让我们从容面对这离别之后的离别。

android大牛MrJing 活动中心

相关文章:

你感兴趣的文章:

标签云: