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) {
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 * ,MediaScannerClient &client) {
const char *extension = strrchr(path,
'.');
if (!extension) {
return MEDIA_SCAN_RESULT_SKIPPED;}
if (!FileHasAcceptableExtension(extension)) {
return MEDIA_SCAN_RESULT_SKIPPED;}sp<MediaMetadataRetriever> mRetriever(
new MediaMetadataRetriever);
int fd = open(path, O_RDONLY | O_LARGEFILE);status_t status;
if (fd <
0) {status = mRetriever->setDataSource(NULL , path);}
else {status = mRetriever->setDataSource(fd,
0,
0x7ffffffffffffffL);close(fd);}
const char *
value;
if ((
value = mRetriever->extractMetadata(METADATA_KEY_MIMETYPE)) != NULL) {status = client.setMimeType(
value);
if (status) {
return MEDIA_SCAN_RESULT_ERROR;}}.........
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;
}
轉載于:https://www.cnblogs.com/yfceshi/p/7365750.html
總結
以上是生活随笔為你收集整理的Android StageFrightMediaScanner源码解析的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。