Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b8c58116 authored by quic_mqiu's avatar quic_mqiu Committed by Steve Kondik
Browse files

audio: ID3 tags of most chinese songs display messy

- ID3 coding format detect and convert issue
- Enhance the detect and convert function

Change-Id: Idf59dd100b8a01b65338a51109d752616abec81b
CRs-Fixed: 494956
parent f0569752
Loading
Loading
Loading
Loading
+81 −8
Original line number Original line Diff line number Diff line
@@ -14,6 +14,11 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


//#define LOG_NDEBUG 0
#define LOG_TAG "MediaScannerClient"

#include <utils/Log.h>

#include <media/mediascanner.h>
#include <media/mediascanner.h>


#include "StringArray.h"
#include "StringArray.h"
@@ -41,7 +46,11 @@ void MediaScannerClient::setLocale(const char* locale)
{
{
    if (!locale) return;
    if (!locale) return;


    if (!strncmp(locale, "ja", 2))
    if (!strncmp(locale, "en_US", 5))
        mLocaleEncoding = kEncodingUTF8;
    else if (!strncmp(locale, "es_US", 5) || !strncmp(locale, "de_DE", 5))
        mLocaleEncoding = kEncodingCP1252;
    else if (!strncmp(locale, "ja", 2))
        mLocaleEncoding = kEncodingShiftJIS;
        mLocaleEncoding = kEncodingShiftJIS;
    else if (!strncmp(locale, "ko", 2))
    else if (!strncmp(locale, "ko", 2))
        mLocaleEncoding = kEncodingEUCKR;
        mLocaleEncoding = kEncodingEUCKR;
@@ -54,6 +63,7 @@ void MediaScannerClient::setLocale(const char* locale)
            mLocaleEncoding = kEncodingBig5;
            mLocaleEncoding = kEncodingBig5;
        }
        }
    }
    }
    ALOGV("setLocale [%s], mLocaleEncoding [%u]", locale, mLocaleEncoding);
}
}


void MediaScannerClient::beginFile()
void MediaScannerClient::beginFile()
@@ -135,6 +145,9 @@ void MediaScannerClient::convertValues(uint32_t encoding)
        case kEncodingEUCKR:
        case kEncodingEUCKR:
            enc = "EUC-KR";
            enc = "EUC-KR";
            break;
            break;
        case kEncodingCP1252:
            enc = "windows-1252";
            break;
    }
    }


    if (enc) {
    if (enc) {
@@ -201,16 +214,76 @@ void MediaScannerClient::endFile()
{
{
    if (mLocaleEncoding != kEncodingNone) {
    if (mLocaleEncoding != kEncodingNone) {
        int size = mNames->size();
        int size = mNames->size();
        uint32_t encoding = kEncodingAll;


        int count = 0;
        int percent = 0;
        uint32_t encoding    = kEncodingAll;
        uint32_t tmpEncoding = kEncodingAll;
        uint32_t srcEncoding = kEncodingNone;
        // compute a bit mask containing all possible encodings
        // compute a bit mask containing all possible encodings
        for (int i = 0; i < mNames->size(); i++)
        for (int i = 0; i < mNames->size(); i++) {
            encoding &= possibleEncodings(mValues->getEntry(i));
            tmpEncoding = possibleEncodings(mValues->getEntry(i));
            // If no multibyte encoding is detected or GBK is the only possible multibyte encoding,
            // just ignore
            if( (kEncodingNone == tmpEncoding) || ((kEncodingGBK | kEncodingCP1252) == tmpEncoding) ) {
                continue;
            }

            if( kEncodingCP1252 == tmpEncoding ) {
                ++count;
                continue;
            }

            encoding &= tmpEncoding;
            ALOGV("value: %s, tmpEncoding: %x\n", mValues->getEntry(i), tmpEncoding);
        }

        if(size > 0) {
            percent = (count*100)/size;
        }

        if(percent >= 50) {
            ALOGV("Force kEncodingAll, percentage: %d\n", percent);
            encoding = kEncodingAll;
        }
        ALOGV("possibleEncodings: %x\n", encoding);

        /*
         **  Leave the highest encoding methodolgy in bit mask,
         **  EXCEPT:
         **     ASCII characters are detected.
         **     Locale encodings matches.
         **     GBK is one of the encodings.
         */
        while( kEncodingNone != encoding ) {
            // If bit mask contains all possible encodings,
            // that probably means ASCII char is detected.
            // Don't need convertion.
            if(kEncodingAll == encoding) {
                srcEncoding = kEncodingAll;
                break;
            }

            // Set locale native encoding, if it matches.
            if(encoding & mLocaleEncoding) {
                srcEncoding = mLocaleEncoding;
                break;
            }


        // if the locale encoding matches, then assume we have a native encoding.
            // Set GBK as preference, if GBK is one of the possible encodings.
        if (encoding & mLocaleEncoding)
            if(encoding & kEncodingGBK) {
            convertValues(mLocaleEncoding);
                srcEncoding = kEncodingGBK;
                break;
            }


            // Clear the lowest bit in bit mask and continue to loop
            srcEncoding = encoding;
            encoding &= (encoding - 1);
        }

        if( (kEncodingNone != srcEncoding) && (kEncodingAll != srcEncoding) ) {
            convertValues(srcEncoding);
        }
        // finally, push all name/value pairs to the client
        // finally, push all name/value pairs to the client
        for (int i = 0; i < mNames->size(); i++) {
        for (int i = 0; i < mNames->size(); i++) {
            status_t status = handleStringTag(mNames->getEntry(i), mValues->getEntry(i));
            status_t status = handleStringTag(mNames->getEntry(i), mValues->getEntry(i));
+2 −2
Original line number Original line Diff line number Diff line
@@ -868,9 +868,9 @@ static bool charMatchesEncoding(int ch, const CharRange* encodingRanges, int ran
extern uint32_t findPossibleEncodings(int ch)
extern uint32_t findPossibleEncodings(int ch)
{
{
    // ASCII matches everything
    // ASCII matches everything
    if (ch < 256) return kEncodingAll;
    if (ch < 128) return kEncodingAll;


    int result = kEncodingNone;
    int result = kEncodingCP1252;


    if (charMatchesEncoding(ch, kShiftJISRanges, ARRAY_SIZE(kShiftJISRanges)))
    if (charMatchesEncoding(ch, kShiftJISRanges, ARRAY_SIZE(kShiftJISRanges)))
        result |= kEncodingShiftJIS;
        result |= kEncodingShiftJIS;
+6 −3
Original line number Original line Diff line number Diff line
@@ -24,10 +24,13 @@ enum {
    kEncodingNone               = 0,
    kEncodingNone               = 0,
    kEncodingShiftJIS           = (1 << 0),
    kEncodingShiftJIS           = (1 << 0),
    kEncodingGBK                = (1 << 1),
    kEncodingGBK                = (1 << 1),
    kEncodingBig5               = (1 << 2),
    kEncodingEUCKR              = (1 << 2),
    kEncodingEUCKR              = (1 << 3),
    kEncodingBig5               = (1 << 3),
    kEncodingUTF8               = (1 << 4),
    kEncodingCP1252             = (1 << 5),


    kEncodingAll                = (kEncodingShiftJIS | kEncodingGBK | kEncodingBig5 | kEncodingEUCKR),
    kEncodingAll                = (kEncodingShiftJIS | kEncodingGBK | kEncodingEUCKR
                                   | kEncodingBig5 | kEncodingUTF8 | kEncodingCP1252),
};
};




+7 −0
Original line number Original line Diff line number Diff line
@@ -483,7 +483,14 @@ void StagefrightMetadataRetriever::parseMetaData() {
        const char *value;
        const char *value;
        if (meta->findCString(kMap[i].from, &value)) {
        if (meta->findCString(kMap[i].from, &value)) {
            mMetaData.add(kMap[i].to, String8(value));
            mMetaData.add(kMap[i].to, String8(value));
            continue;
        }
        }
        //For some wma clips, Artist info exists in Author bytes instead of Artist byte
        //Put the Author into Artist in this case
        if((kMap[i].from == kKeyArtist) &&
                meta->findCString(kKeyAuthor, &value))
            mMetaData.add(kMap[i].to, String8(value));

    }
    }


    const void *data;
    const void *data;