`
Coding.Ghost
  • 浏览: 19833 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

android Media process

阅读更多

Android Media Scanner Process
[First written by Steve Guo, please keep the mark if forwarding.]

Here is the overall picture.

android.process.media
MediaScannerReceiver is started when any ACTION_BOOT_COMPLETED, ACTION_MEDIA_MOUNTED or ACTION_MEDIA_SCANNER_SCAN_FILE intent is sent out. Because it may cost a lot of time to parse meta-data information of media files, MediaScannerReceiver will start MediaScannerService. MediaScannerService calls a utility class MediaScanner to do the real work. MediaScannerReceiver maintains two kinds of scan directories: One is internal volume which points to $(ANDROID_ROOT)/media. Another is external volume which points to $(EXTERNAL_STORAGE).

The scan and parse work lies in both JAVA and C++ layer. JAVA layer is the starter. To scan the whole directory, MediaScanner does the following steps.

1. JAVA layer initialize

In this step, it will open different database according to whether the dir is internal or external volume.

2. JAVA layer prescan

It first clears file and play list cache entries, then generates new file and play list cache entries according to query result from MediaProvider.

3. C++ layer processDirectory

It enumerates all files and sub-dirs in a specific dir(If a sub-dir contains a .nomedia hidden file, it won’t be enumerated.). For each enumerated file, it judges whether the file is supported according to file extension. If the file extension is supported, then C++ layer will call back to JAVA layer scanFile. The file extension which will be scanned is listed in MediaFile.java. Here is the list.

/* Audio */
addFileType("MP3", FILE_TYPE_MP3, "audio/mpeg");
addFileType("M4A", FILE_TYPE_M4A, "audio/mp4");
addFileType("WAV", FILE_TYPE_WAV, "audio/x-wav");
addFileType("AMR", FILE_TYPE_AMR, "audio/amr");
addFileType("AWB", FILE_TYPE_AWB, "audio/amr-wb");
addFileType("WMA", FILE_TYPE_WMA, "audio/x-ms-wma");
addFileType("OGG", FILE_TYPE_OGG, "application/ogg");
addFileType("MID", FILE_TYPE_MID, "audio/midi");
addFileType("XMF", FILE_TYPE_MID, "audio/midi");
addFileType("RTTTL", FILE_TYPE_MID, "audio/midi");
addFileType("SMF", FILE_TYPE_SMF, "audio/sp-midi");
addFileType("IMY", FILE_TYPE_IMY, "audio/imelody");


/* Video */

addFileType("MP4", FILE_TYPE_MP4, "video/mp4");
addFileType("M4V", FILE_TYPE_M4V, "video/mp4");
addFileType("3GP", FILE_TYPE_3GPP, "video/3gpp");
addFileType("3GPP", FILE_TYPE_3GPP, "video/3gpp");
addFileType("3G2", FILE_TYPE_3GPP2, "video/3gpp2");
addFileType("3GPP2", FILE_TYPE_3GPP2, "video/3gpp2");
addFileType("WMV", FILE_TYPE_WMV, "video/x-ms-wmv");


/* Image */

addFileType("JPG", FILE_TYPE_JPEG, "image/jpeg");
addFileType("JPEG", FILE_TYPE_JPEG, "image/jpeg");
addFileType("GIF", FILE_TYPE_GIF, "image/gif");
addFileType("PNG", FILE_TYPE_PNG, "image/png");
addFileType("BMP", FILE_TYPE_BMP, "image/x-ms-bmp");
addFileType("WBMP", FILE_TYPE_WBMP, "image/vnd.wap.wbmp");


/* Audio Play List */

addFileType("M3U", FILE_TYPE_M3U, "audio/x-mpegurl");
addFileType("PLS", FILE_TYPE_PLS, "audio/x-scpls");
addFileType("WPL", FILE_TYPE_WPL, "application/vnd.ms-wpl");


4. JAVA layer scanFile

a) JAVA layer beginFile

First it ignores some special files for MacOS and Windows Media Player. Then it looks whether the file has been in the cache entry, if so, it will check whether the file’s last modification time is changed. Finally it returns the result whether the file needs to be processed further. If no need, the following two steps won’t be executed.

b) C++ layer scanFile

Not all the files will be delivered to let C++ layer parse meta-data. Only the following file types will be parsed. Pay attention here, image files are not handled here.

if (mFileType == MediaFile.FILE_TYPE_MP3 ||mFileType == MediaFile.FILE_TYPE_MP4 ||
mFileType == MediaFile.FILE_TYPE_M4A ||mFileType == MediaFile.FILE_TYPE_3GPP ||
mFileType == MediaFile.FILE_TYPE_3GPP2 ||mFileType == MediaFile.FILE_TYPE_OGG ||
mFileType == MediaFile.FILE_TYPE_MID ||mFileType == MediaFile.FILE_TYPE_WMA) {
......
}

 
For each parsed meta-data information, C++ layer will call back to JAVA layer handleStringTag. JAVA layer will record the name/value information.

c) JAVA layer endFile

Finally JAVA layer updates the corresponding database table provided by MeidaProvider according to the values parsed at the previous step.

5. JAVA layer postScan

Until now, all the files have been scanned, it finally checks the file and play list cache entry to see whether all items still existed in the file system. If have any empty entry, then delete it from database. So that it can keep some kinds of consistence between database and file system.

Other application can know when the scan operation starts and ends through receiving ACTION_MEDIA_SCANNER_STARTED and ACTION_MEDIA_SCANNER_FINISHED intents sent from MediaScannerService.

 

分享到:
评论

相关推荐

    Android Media Scanner Process

    ype("SMF", FILE_TYPE_MID, "audio/spm"); addFileType("IMY", FILE_TYPE_MID, "audio/imy"); addFileType("MXMF", FILE_TYPE_MID, "audio/midi"); addFileType("RM", FILE_TYPE_RMI, "audio/x-pn-realaudio-plugin...

    Android Launch Process(安卓系统启动过程)

    例如,它会启动`ServiceManager`、`MediaServer`等守护进程。 - **启动zygote进程**:与普通Linux系统不同的是,Android会在`init`进程的基础上启动一个特殊的进程——zygote。 #### 四、zygote进程的作用 1. **...

    android Media分析

    5. **process_media_player_call()**: 这个函数处理从Java层调用原生函数的返回结果,根据status_t判断是否成功,如有错误则发送错误消息到Java层。 **原生(Library)层** 在原生库层,`MediaPlayer`对象处理实际...

    Talking about Android process

    - `mediaserver`: 处理多媒体服务,如音频、视频编码解码,以及相机等。 - `installd`: 安装服务,处理APK的安装和权限设置。 4. **System Server Process(系统服务器进程)** - `system_server`是Android系统...

    Android SDK build-tools 26.0.2.zip

    **Android SDK build-tools 26.0.2.zip** 是一个专门为Android开发者设计的重要工具集,主要用于构建Android应用程序。这个压缩包包含了构建过程中所需的多种工具,这些工具在Android Studio或其他命令行工具中被...

    android MediaProvider和MediaScanner详解

    首先,从AndroidManifest.xml文件的分析可知,MediaProvider被注册在android.process.media进程中,并且它具有android.media这个sharedUserId。这意味着MediaProvider运行在一个特定的系统进程以及安全域中,这个...

    android-stagefright处理httplivestreaming缓冲机制

    首先,Proxy进程创建一个BpMediaPlayerService对象,通过IPC(Inter-Process Communication)与Native进程中的BnMediaPlayerService交互。在Native进程内部,MediaPlayerService对象接收并处理这些请求,如...

    Android 资料又一包

    Android Media Scanner Process.pdf Talking about Android process.pdf Android Initialization Process.pdf surfaceflinger.pdf Android Build System by google.pdf auug97.pdf Android 图形系统.pdf 如何在...

    android binder

    Android的Binder机制是其Inter-Process Communication(IPC)的核心组成部分,它提供了一种进程间数据交换与控制的手段,使得不同进程间的对象能够相互操作,实现了Android系统中各组件的交互与通信。 #### 二、...

    android sources

    3. **System Core**:这是 Android 系统的核心组件,包括 IPC(Inter-Process Communication)、JNI(Java Native Interface)、I/O 管理等。例如,`libcore` 和 `bionic` 分别是 Dalvik VM 和 C 库的实现。 4. **...

    Android学习笔记--Binder

    Binder是Android系统中的核心组件,它是Android系统实现进程间通信(IPC,Inter-Process Communication)的主要方式。Binder机制允许不同进程的组件之间进行数据交换和功能调用,就像它们在同一进程中一样,实现了...

    深入理解Android卷1全

    10.2.3 android.process.media媒体扫描工作的流程总结 / 471 10.3 MediaScanner分析 / 472 10.3.1 Java层分析 / 472 10.3.2 JNI层分析 / 476 10.3.3 PVMediaScanner分析 / 479 10.3.4 关于MediaScanner的总结 / 485 ...

    android系统启动原理

    这些服务包括zygote(Android应用的父进程)、system_server(系统服务框架)、media_server(多媒体服务)等。其中,zygote进程非常重要,因为它孵化出所有Android应用程序,并且负责管理Dalvik或ART虚拟机。 接...

    android系统深入浅出binder机制分析

    Binder机制是Android平台实现跨进程通信(Inter-Process Communication,IPC)的关键技术,它不仅为系统提供了高效稳定的通信框架,而且是众多系统服务如MediaService、ActivityManagerService等得以正常运作的基础...

    Android-AndroidRemoteController是一个远程控制第三方音乐播放器的项目

    3. **媒体控制器(MediaSession and MediaController)**:Android提供MediaSession API来创建一个媒体控制器,它允许应用模拟硬件媒体按钮的功能。通过MediaSession,应用可以注册媒体按钮事件,并使用...

Global site tag (gtag.js) - Google Analytics