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

Commit f211c095 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 7701

* changes:
  Clean up MP3Extractor code and fixes a bug that miscalculated the position of the header by a few bytes whenever we read in more data.
parents d8bb43bb 2e337a4e
Loading
Loading
Loading
Loading
+34 −29
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ static bool get_mp3_frame_size(

    if (bitrate_index == 0 || bitrate_index == 0x0f) {
        // Disallow "free" bitrate.

        LOGE("We disallow 'free' bitrate for now.");
        return false;
    }

@@ -174,7 +176,7 @@ static bool Resync(
    const size_t kMaxFrameSize = 4096;
    uint8_t *buffer = new uint8_t[kMaxFrameSize];
    
    off_t pos = *inout_pos;
    off_t pos = *inout_pos - kMaxFrameSize;
    size_t buffer_offset = kMaxFrameSize;
    size_t buffer_length = kMaxFrameSize;
    bool valid = false;
@@ -184,7 +186,7 @@ static bool Resync(
                break;
            }

            pos += buffer_length;
            pos += buffer_offset;

            if (pos >= *inout_pos + 128 * 1024) {
                // Don't scan forever.
@@ -217,8 +219,12 @@ static bool Resync(

        size_t frame_size;
        int sample_rate, num_channels, bitrate;
        if (get_mp3_frame_size(header, &frame_size,
        if (!get_mp3_frame_size(header, &frame_size,
                               &sample_rate, &num_channels, &bitrate)) {
            ++buffer_offset;
            continue;
        }

        LOGV("found possible 1st frame at %ld", pos + buffer_offset);

        // We found what looks like a valid frame,
@@ -253,7 +259,6 @@ static bool Resync(

            test_pos += test_frame_size;
        }
        }

        if (valid) {
            *inout_pos = pos + buffer_offset;