Android StageFrightMediaScanner源代码解析
16lz
2021-01-23
1. 简介
Android中在StageFrightMediaScanner实现对多媒体文件的处理。
此外在StageFrightMediaScanner定义了支持的多媒体文件类型。
文件位置
frameworks\av\media\libstagefright\StagefrightMediaScanner.cpp
编译目标
libstagefright.so
2. processFile
processFile并没有做什么处理,主要是调用processFileInternal。
另外可以看到在processFile中调用MediaScannerClient的beginFile和endFile方法,时间上google并没有实现beginFile和endFile方法。
(说实话Android5.0 真的很烂,很多功能根本就没有开发完全)
MediaScanResult StagefrightMediaScanner::processFile( const char *path, const char *mimeType, MediaScannerClient &client) { //MediaScannerClient根本就没有实现,所以不用关心 client.setLocale(locale()); client.beginFile(); MediaScanResult result = processFileInternal(path, mimeType, client); client.endFile(); return result;}
3. processFileInternal
processFileInternal可以说是MediaScanner处理多媒体文件最终节点
在此函数中通过调用MediaMetadataRetriever获取多媒体信息。
调用MediaMetadataRetriever获取媒体文件信息过程如下:
(1) MediaMetadataRetriever.setDataSource(file)
(2) MediaMetadataRetriever.extractMetadata(key)
MediaScanResult StagefrightMediaScanner::processFileInternal( const char *path, const char * /* mimeType */, MediaScannerClient &client) { const char *extension = strrchr(path, '.'); ///check file type if (!extension) { return MEDIA_SCAN_RESULT_SKIPPED; } if (!FileHasAcceptableExtension(extension)) { return MEDIA_SCAN_RESULT_SKIPPED; } //---------------------------------------- ///Init & setDataSource MediaMetadataRetriever sp<MediaMetadataRetriever> mRetriever(new MediaMetadataRetriever); int fd = open(path, O_RDONLY | O_LARGEFILE); status_t status; if (fd < 0) { // couldn't open it locally, maybe the media server can? status = mRetriever->setDataSource(NULL /* httpService */, path); } else { status = mRetriever->setDataSource(fd, 0, 0x7ffffffffffffffL); close(fd); } //---------------------------------------- ///get MIMETYPE const char *value; if ((value = mRetriever->extractMetadata( METADATA_KEY_MIMETYPE)) != NULL) { status = client.setMimeType(value); if (status) { return MEDIA_SCAN_RESULT_ERROR; } } //---------------------------------------- ......... ///get metadata for (size_t i = 0; i < kNumEntries; ++i) { const char *value; if ((value = mRetriever->extractMetadata(kKeyMap[i].key)) != NULL) { status = client.addStringTag(kKeyMap[i].tag, value); if (status != OK) { return MEDIA_SCAN_RESULT_ERROR; } } } return MEDIA_SCAN_RESULT_OK;}
更多相关文章
- Android: /cache中的文件是怎么消失的
- Android APK文件结构 完整打包编译的流程 APK安装过程 详解
- Android读取xxx.properties配置文件中文出现乱码解决方法
- Android Studio(九):引用jar及so文件
- Android——4.2.2 文件系统文件夹分析
- [置顶] Android上传文件到Web服务器,PHP接收文件(二)
- Android国际化资源 文件夹命名规范
- Android安装apk文件并适配Android 7.0详解
- Android 列表数据写入到本地Excel文件(包括图片)