Android MediaScanner 总纲

1. MediaScanner HEAD

这里写图片描写叙述

2. 应用层 MediaProvider

packages\providers\MediaProvider
(1) MediaProvider
packages\providers\MediaProvider\MediaProvider.java
MediaProvider继承于ContentProvider,主要用于创建媒体库的数据库表.
具体内容请查阅怎样创建Provider.
MediaProvider中包涵一个BroadcastReceiver,用于监听SDCard挂载/卸载
(2) MediaReceiver
监听扫描事件, 调用MSS
Action :
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MEDIA_MOUNTED
scan volume MediaScannerService
else
scanFile filepath MediaScannerService
(3) MediaScannerService MSS
onStartCommand==>ServiceHandler==>scanFile
当我们调用startService的时候。假设相应的Service还未创建就会调用onCreate方 法===方法。

每次startService的时候就调用onStartCommand,所以ServiceHandler就在此发送消息了。

call: MediaScanner :: scanSingleFile, scanDirectories

3. JAVA 层

Call Stack : Google注解

/*
 * In summary:
 * Java MediaScannerService calls
 * Java MediaScanner scanDirectories, which calls
 * Java MediaScanner processDirectory (native method), which calls
 * native MediaScanner processDirectory, which calls
 * native MyMediaScannerClient scanFile, which calls
 * Java MyMediaScannerClient scanFile, which calls
 * Java MediaScannerClient doScanFile, which calls
 * Java MediaScanner processFile (native method), which calls
 * native MediaScanner processFile, which calls
 * native parseMP3, parseMP4, parseMidi, parseOgg or parseWMA, which calls
 * native MyMediaScanner handleStringTag, which calls
 * Java MyMediaScanner handleStringTag.
 * Once MediaScanner processFile returns, an entry is inserted in to the database.
 */

这里写图片描写叙述
(1) MediaScanner
frameworks/base/media/java/android/media/MediaScanner.java

Call JNI

    static {
        System.loadLibrary("media_jni");
        native_init();
    }

scanDirectories ⇒ jni processDirectory
scanSingleFile ==> MyMediaScannerClient.doScanFile
deal with image, audio, video ⇒ jni processFile

4. JNI层

(1) android_media_MediaScanner.cpp
frameworks\base\media\jni\android_media_MediaScanner.cpp
MediaScanner *mp = getNativeScanner_l(env, thiz);
mp->processDirectory(pathStr, myClient);
mp->processFile(pathStr, mimeTypeStr, myClient);

android_media_MediaScanner中比較重要的是MyMediaScannerClient类, 该类会被继续传究竟层,用于调用java层(MediaScanner.java)的 scanFile, handleStringTag, setMimeType

5. Server Proxyer

libmedia – libmedia.so
frameworks\av\media\libmedia\MediaScanner.cpp
处理具体的文件
假设是目录须要返回JAVA层中,採用scanFile处理

6. Server

frameworks\av\media\libstagefright\StagefrightMediaScanner.cpp
libstagefright.so
依据文件后缀推断可处理的文件
然后通过MediaMetadataRetriever获取视频的具体信息,
最后同过handleString一步一步向上传, 在MediaScannerService中把信息写入数据库.

posted @ 2017-08-17 15:28  wzjhoutai  阅读(202)  评论(0编辑  收藏  举报