Hardcode libopus output frequency to 48000Hz

Issue: #3080

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162746202
This commit is contained in:
olly 2017-07-21 08:58:34 -07:00 committed by Oliver Woodman
parent cdfe57833d
commit 4436e94ba8
2 changed files with 26 additions and 1 deletions

View file

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.ext.opus;
import android.os.Handler;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.audio.AudioProcessor;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
@ -32,6 +33,8 @@ public final class LibopusAudioRenderer extends SimpleDecoderAudioRenderer {
private static final int NUM_BUFFERS = 16;
private static final int INITIAL_INPUT_BUFFER_SIZE = 960 * 6;
private OpusDecoder decoder;
public LibopusAudioRenderer() {
this(null, null);
}
@ -69,8 +72,16 @@ public final class LibopusAudioRenderer extends SimpleDecoderAudioRenderer {
@Override
protected OpusDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
throws OpusDecoderException {
return new OpusDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE,
decoder = new OpusDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE,
format.initializationData, mediaCrypto);
return decoder;
}
@Override
protected Format getOutputFormat() {
return Format.createAudioSampleFormat(null, MimeTypes.AUDIO_RAW, null, Format.NO_VALUE,
Format.NO_VALUE, decoder.getChannelCount(), decoder.getSampleRate(), C.ENCODING_PCM_16BIT,
null, null, 0, null);
}
}

View file

@ -197,6 +197,20 @@ import java.util.List;
opusClose(nativeDecoderContext);
}
/**
* Returns the channel count of output audio.
*/
public int getChannelCount() {
return channelCount;
}
/**
* Returns the sample rate of output audio.
*/
public int getSampleRate() {
return SAMPLE_RATE;
}
private static int nsToSamples(long ns) {
return (int) (ns * SAMPLE_RATE / 1000000000);
}