understanding the android media framework

本文详细阐述了Android多媒体框架的构建基础,包括核心组件、依赖关系及其实现方式。深入理解多媒体库如OpenCORE、vorbis和sonivox的作用,以及它们如何通过一致的接口为各种服务提供支持,使得多媒体处理变得更加透明和高效。通过展示多媒体框架类层次结构简化版,揭示了关键类及其在不同模块中的实现细节,如libmedia、libmediaplayerservice和libmedia_jni等。同时,文章强调了Android应用与媒体服务器进程之间的分离,以及通过Binder IPC机制进行通信的机制。最后,解释了为什么MediaPlayer类不提供使用内存流作为源的API,这是由于内存流的数据空间与媒体服务器进程不直接共享。
android media framework is built on top of a set of media libraries, including  OpenCORE vorbis  and sonivox. So one of goal of android media framework is to provide a consistent interface for all services provided by underlying libraries and make them transparent to users.

The figure below shows the dependency relationships between libraries of the media framework.

android_media_lib_dep

In this figure, green components are media libraries, yellow components are android internal libraries, grey components are external libraries, and the light blue class is the java consumer of the media framework. Except for android.media.MediaPlayer class, all components are implemented in c or c++.

The core of the media framework is composed of libmedia, libmediaplayerservice and libmedia_jni. Their codes reside in frameworks/base/media folder.

libmedia defines the inheritance hierarchy and base interfaces. It’s the base library.

libmedia_jni is the shim between java application and native library. First, it implements the JNIspecification so that it can be used by java application. Second, it implements the facade patternfor the convenience of caller.

libmediaplayerservice implements some of concrete players and the media service which will manage player instances.


The figure below shows the class hierarchy.android_media_classes

This is a simplified version of the class hierarchy. Only some core classes are included. Classes in blue are defined in libmedia, classes in green are defined in libmediaplayerservice, classes in light yellow are defined in binder, which implements the IPC on android. And classes in grey are defined in other libs.

Note the BpInterface and BnInterface are template classes. Any instantiation of them also inherit the template argument INTERFACE as well.

In the class hierarchy diagram, though listed as a separate module, binder is actually implemented inside libutils component whose source code locate at /frameworks/base/libs/utils folder.


An interesting thing to note is in android, the application that intends to show the media content and the player that actually renders the media content run in different process. The red line in the sequence diagram below shows the boundary of two processes.

android_media_sequence

The figure shows three most common operations, creating a new player, setting datasource and playing. The last MediaPlayerBase object is the interface that MediaPlayerService::Client object uses to refer to the concrete player instance. The concrete player can be VorbisPlayer, PVPlayer, or any other player, depending on the type of the media to be played.

When an application creates a android.media.MediaPlayer object, it’s actually holding a proxywhich can be used to manipulate the concrete player resides in the mediaserver process. During the whole procedure, two process communicates with Binder IPC mechanism.


Having knowledge above, it’s not difficult to understand why MediaPlayer doesn’t provide an API to use memory stream as source. Because the memory manipulated by the stream is in the address space of the application, and it’s not directly accessible by the mediaserver process.

References:

Google I/O, Mastering the Android Media Framework

android media framework uml diagram

### 书籍内容概述 《Understanding the Linux Kernel》第三版是一本深入探讨Linux内核内部工作机制的权威书籍[^1]。该书由Daniel P. Bovet和Marco Cesati撰写,出版于2005年11月。书中详细描述了Linux内核的关键组成部分,包括进程管理、内存管理、文件系统、I/O子系统以及中断处理等。此书适用于希望深入了解Linux操作系统内部原理的读者,尤其是对内核开发感兴趣的开发者和技术人员。 以下是该书的主要章节及其涵盖的内容: - **进程管理**:介绍进程的创建、调度、同步以及信号处理机制。 - **内存管理**:讲解虚拟内存的实现、页表结构、交换机制以及内存映射。 - **文件系统**:分析Linux文件系统的架构,包括VFS层、块设备管理和具体文件系统的实现。 - **I/O子系统**:描述字符设备和块设备的驱动程序模型,以及与硬件交互的方式。 - **中断和异常处理**:解释中断控制器的工作原理、中断处理程序的设计以及异常处理流程。 ### 获取书籍或学习资料的方法 对于希望获取《Understanding the Linux Kernel》第三版的用户,可以通过以下途径寻找书籍或相关资源: 1. **在线书店**:亚马逊(Amazon)、京东、当当网等大型在线书店通常提供纸质版或电子版的购买选项。 2. **图书馆**:许多大学或公共图书馆可能收藏了该书,可以借阅以节省成本。 3. **数字资源平台**:如Google Books或Safari Books Online可能提供部分章节预览或完整电子版订阅服务。 4. **开源社区**:Linux内核源代码目录下的`Documentation`文件夹中包含大量技术文档[^1],这些文档可以作为辅助学习材料,帮助理解内核设计。 5. **在线学习网站**:例如LWN.net或Kernel.org提供了丰富的内核开发教程和文章,能够补充书籍中的知识点。 ### 示例代码片段 以下是一个简单的内核模块示例,展示了如何编写一个基本的Linux内核模块并打印日志信息: ```c #include <linux/module.h> #include <linux/kernel.h> static int __init hello_init(void) { printk(KERN_INFO "Hello, this is a basic kernel module!\n"); return 0; } static void __exit hello_exit(void) { printk(KERN_INFO "Goodbye, removing the kernel module.\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Example Author"); MODULE_DESCRIPTION("A Simple Hello World Kernel Module"); ``` 上述代码可用于实践书中关于内核模块加载和卸载的知识点。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值