Android StageFrightMediaScanner source code parsing

Source: Internet
Author: User

Android StageFrightMediaScanner source code parsing
1. Introduction

In Android, StageFrightMediaScanner processes multimedia files.
In addition, the supported multimedia file types are defined in StageFrightMediaScanner.
File Location
FrameworksavmedialibstagefrightStagefrightMediaScanner. cpp
Compilation target
Libstagefright. so

2. processFile

ProcessFile does not process any data. It mainly calls processFileInternal.
In addition, we can see that the beginFile and endFile methods of MediaScannerClient are called in processFile. In terms of time, google does not implement the beginFile and endFile methods.
(To be honest, Android5.0 is really bad, and many functions are not completely developed)

MediaScanResult StagefrightMediaScanner: processFile (const char * path, const char * mimeType, MediaScannerClient & client) {// MediaScannerClient is not implemented at all, so do not care about the client. setLocale (locale (); client. beginFile (); MediaScanResult result = processFileInternal (path, mimeType, client); client. endFile (); return result ;}
3. processFileInternal

ProcessFileInternal can be said to be the final node for MediaScanner to process multimedia files
In this function, you can call MediaMetadataRetriever to obtain multimedia information.
The procedure of calling MediaMetadataRetriever to obtain media file information is as follows:
(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
  
    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;}
  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.