Commit 7aae5805 by eguven Committed by Oliver Woodman

Added Mp3ExtractorTest and modified Mp3Extractor to pass the test.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123640738
parent 5a4d82c7
No preview for this file type
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer.extractor.mp3;
import com.google.android.exoplayer.extractor.Extractor;
import com.google.android.exoplayer.testutil.TestUtil;
import android.test.InstrumentationTestCase;
/**
* Unit test for {@link Mp3Extractor}.
*/
public final class Mp3ExtractorTest extends InstrumentationTestCase {
public void testMp3Sample() throws Exception {
TestUtil.assertOutput(new TestUtil.ExtractorFactory() {
@Override
public Extractor create() {
return new Mp3Extractor();
}
}, "mp3/bear.mp3", getInstrumentation());
}
}
......@@ -123,7 +123,7 @@ public final class Mp3Extractor implements Extractor {
return RESULT_END_OF_INPUT;
}
if (seeker == null) {
setupSeeker(input);
seeker = setupSeeker(input);
extractorOutput.seekMap(seeker);
trackOutput.format(Format.createAudioSampleFormat(null, synchronizedHeader.mimeType,
Format.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, synchronizedHeader.channels,
......@@ -263,17 +263,18 @@ public final class Mp3Extractor implements Extractor {
}
/**
* Sets {@link #seeker} to seek using metadata read from {@code input}, which should provide data
* from the start of the first frame in the stream. On returning, the input's position will be set
* to the start of the first frame of audio.
* Returns a {@link Seeker} to seek using metadata read from {@code input}, which should provide
* data from the start of the first frame in the stream. On returning, the input's position will
* be set to the start of the first frame of audio.
*
* @param input The {@link ExtractorInput} from which to read.
* @throws IOException Thrown if there was an error reading from the stream. Not expected if the
* next two frames were already peeked during synchronization.
* @throws InterruptedException Thrown if reading from the stream was interrupted. Not expected if
* the next two frames were already peeked during synchronization.
* @return a {@link Seeker}.
*/
private void setupSeeker(ExtractorInput input) throws IOException, InterruptedException {
private Seeker setupSeeker(ExtractorInput input) throws IOException, InterruptedException {
// Read the first frame which may contain a Xing or VBRI header with seeking metadata.
ParsableByteArray frame = new ParsableByteArray(synchronizedHeader.frameSize);
input.peekFully(frame.data, 0, synchronizedHeader.frameSize);
......@@ -287,6 +288,7 @@ public final class Mp3Extractor implements Extractor {
: (synchronizedHeader.channels != 1 ? 21 : 13); // MPEG 2 or 2.5
frame.setPosition(xingBase);
int headerData = frame.readInt();
Seeker seeker = null;
if (headerData == XING_HEADER || headerData == INFO_HEADER) {
seeker = XingSeeker.create(synchronizedHeader, frame, position, length);
if (seeker != null && !gaplessInfoHolder.hasGaplessInfo()) {
......@@ -317,6 +319,8 @@ public final class Mp3Extractor implements Extractor {
MpegAudioHeader.populateHeader(scratch.readInt(), synchronizedHeader);
seeker = new ConstantBitrateSeeker(input.getPosition(), synchronizedHeader.bitrate, length);
}
return seeker;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment