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

Commit a8120ea3 authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "To make SniffMP3() more concrete so that we can remove false-positve...

Merge "To make SniffMP3() more concrete so that we can remove false-positve responses from MPEG-PS streams."
parents 0e1e5223 983ab88e
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -52,7 +52,10 @@ static bool Resync(
        *post_id3_pos = 0;
    }

    bool resync_from_head = false;
    if (*inout_pos == 0) {
        resync_from_head = true;

        // Skip an optional ID3 header if syncing at the very beginning
        // of the datasource.

@@ -137,23 +140,21 @@ static bool Resync(

        uint32_t header = U32_AT(tmp);

        if (match_header != 0 && (header & kMask) != (match_header & kMask)) {
            ++pos;
            ++tmp;
            --remainingBytes;
            continue;
        }

        size_t frame_size;
        int sample_rate, num_channels, bitrate;
        if (!GetMPEGAudioFrameSize(
                    header, &frame_size,
                    &sample_rate, &num_channels, &bitrate)) {
        if ((match_header != 0 && (header & kMask) != (match_header & kMask))
                || !GetMPEGAudioFrameSize(header, &frame_size)) {
            if (resync_from_head) {
                // This isn't a valid mp3 file because it failed to detect
                // a header while a valid mp3 file should have a valid
                // header here.
                break;
            } else {
                ++pos;
                ++tmp;
                --remainingBytes;
                continue;
            }
        }

        LOGV("found possible 1st frame at %lld (header = 0x%08x)", pos, header);