Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dfc69dee
authored
Apr 04, 2023
by
samrobinson
Committed by
Marc Baechinger
Apr 05, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use AudioFormat in SilentAudioGenerator.
PiperOrigin-RevId: 521790733
parent
da0324e7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
40 deletions
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AudioSamplePipeline.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/SilentAudioGenerator.java
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/SilentAudioGeneratorTest.java
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/TestUtil.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AudioSamplePipeline.java
View file @
dfc69dee
...
@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.transformer;
...
@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.transformer;
import
static
com
.
google
.
android
.
exoplayer2
.
decoder
.
DecoderInputBuffer
.
BUFFER_REPLACEMENT_MODE_DIRECT
;
import
static
com
.
google
.
android
.
exoplayer2
.
decoder
.
DecoderInputBuffer
.
BUFFER_REPLACEMENT_MODE_DIRECT
;
import
static
com
.
google
.
android
.
exoplayer2
.
decoder
.
DecoderInputBuffer
.
BUFFER_REPLACEMENT_MODE_DISABLED
;
import
static
com
.
google
.
android
.
exoplayer2
.
decoder
.
DecoderInputBuffer
.
BUFFER_REPLACEMENT_MODE_DISABLED
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
DefaultCodec
.
DEFAULT_PCM_ENCODING
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkArgument
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkState
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkState
;
import
static
java
.
lang
.
Math
.
min
;
import
static
java
.
lang
.
Math
.
min
;
...
@@ -71,7 +71,6 @@ import org.checkerframework.dataflow.qual.Pure;
...
@@ -71,7 +71,6 @@ import org.checkerframework.dataflow.qual.Pure;
throws
ExportException
{
throws
ExportException
{
super
(
firstAssetLoaderInputFormat
,
muxerWrapper
);
super
(
firstAssetLoaderInputFormat
,
muxerWrapper
);
silentAudioGenerator
=
new
SilentAudioGenerator
(
firstPipelineInputFormat
);
availableInputBuffers
=
new
ConcurrentLinkedDeque
<>();
availableInputBuffers
=
new
ConcurrentLinkedDeque
<>();
ByteBuffer
emptyBuffer
=
ByteBuffer
.
allocateDirect
(
0
).
order
(
ByteOrder
.
nativeOrder
());
ByteBuffer
emptyBuffer
=
ByteBuffer
.
allocateDirect
(
0
).
order
(
ByteOrder
.
nativeOrder
());
for
(
int
i
=
0
;
i
<
MAX_INPUT_BUFFER_COUNT
;
i
++)
{
for
(
int
i
=
0
;
i
<
MAX_INPUT_BUFFER_COUNT
;
i
++)
{
...
@@ -84,6 +83,15 @@ import org.checkerframework.dataflow.qual.Pure;
...
@@ -84,6 +83,15 @@ import org.checkerframework.dataflow.qual.Pure;
encoderInputBuffer
=
new
DecoderInputBuffer
(
BUFFER_REPLACEMENT_MODE_DISABLED
);
encoderInputBuffer
=
new
DecoderInputBuffer
(
BUFFER_REPLACEMENT_MODE_DISABLED
);
encoderOutputBuffer
=
new
DecoderInputBuffer
(
BUFFER_REPLACEMENT_MODE_DISABLED
);
encoderOutputBuffer
=
new
DecoderInputBuffer
(
BUFFER_REPLACEMENT_MODE_DISABLED
);
checkArgument
(
firstPipelineInputFormat
.
pcmEncoding
!=
Format
.
NO_VALUE
);
AudioFormat
inputAudioFormat
=
new
AudioFormat
(
firstPipelineInputFormat
.
sampleRate
,
firstPipelineInputFormat
.
channelCount
,
firstPipelineInputFormat
.
pcmEncoding
);
silentAudioGenerator
=
new
SilentAudioGenerator
(
inputAudioFormat
);
if
(
flattenForSlowMotion
&&
firstAssetLoaderInputFormat
.
metadata
!=
null
)
{
if
(
flattenForSlowMotion
&&
firstAssetLoaderInputFormat
.
metadata
!=
null
)
{
audioProcessors
=
audioProcessors
=
new
ImmutableList
.
Builder
<
AudioProcessor
>()
new
ImmutableList
.
Builder
<
AudioProcessor
>()
...
@@ -95,20 +103,12 @@ import org.checkerframework.dataflow.qual.Pure;
...
@@ -95,20 +103,12 @@ import org.checkerframework.dataflow.qual.Pure;
}
}
audioProcessingPipeline
=
new
AudioProcessingPipeline
(
audioProcessors
);
audioProcessingPipeline
=
new
AudioProcessingPipeline
(
audioProcessors
);
// TODO(b/267301878): Once decoder format propagated, remove setting default PCM encoding.
AudioFormat
pipelineInputAudioFormat
=
new
AudioFormat
(
firstPipelineInputFormat
.
sampleRate
,
firstPipelineInputFormat
.
channelCount
,
firstPipelineInputFormat
.
pcmEncoding
!=
Format
.
NO_VALUE
?
firstPipelineInputFormat
.
pcmEncoding
:
DEFAULT_PCM_ENCODING
);
try
{
try
{
encoderInputAudioFormat
=
audioProcessingPipeline
.
configure
(
pipelineI
nputAudioFormat
);
encoderInputAudioFormat
=
audioProcessingPipeline
.
configure
(
i
nputAudioFormat
);
}
catch
(
AudioProcessor
.
UnhandledAudioFormatException
unhandledAudioFormatException
)
{
}
catch
(
AudioProcessor
.
UnhandledAudioFormatException
unhandledAudioFormatException
)
{
throw
ExportException
.
createForAudioProcessing
(
throw
ExportException
.
createForAudioProcessing
(
unhandledAudioFormatException
,
pipelineI
nputAudioFormat
);
unhandledAudioFormatException
,
i
nputAudioFormat
);
}
}
audioProcessingPipeline
.
flush
();
audioProcessingPipeline
.
flush
();
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/SilentAudioGenerator.java
View file @
dfc69dee
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
package
com
.
google
.
android
.
exoplayer2
.
transformer
;
package
com
.
google
.
android
.
exoplayer2
.
transformer
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.
audio.AudioProcessor.Audio
Format
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.nio.ByteOrder
;
...
@@ -31,12 +31,9 @@ import java.util.concurrent.atomic.AtomicLong;
...
@@ -31,12 +31,9 @@ import java.util.concurrent.atomic.AtomicLong;
private
final
ByteBuffer
internalBuffer
;
private
final
ByteBuffer
internalBuffer
;
private
final
AtomicLong
remainingBytesToOutput
;
private
final
AtomicLong
remainingBytesToOutput
;
public
SilentAudioGenerator
(
Format
format
)
{
public
SilentAudioGenerator
(
Audio
Format
format
)
{
sampleRate
=
format
.
sampleRate
;
sampleRate
=
format
.
sampleRate
;
frameSize
=
frameSize
=
Util
.
getPcmFrameSize
(
format
.
encoding
,
format
.
channelCount
);
Util
.
getPcmFrameSize
(
format
.
pcmEncoding
==
Format
.
NO_VALUE
?
C
.
ENCODING_PCM_16BIT
:
format
.
pcmEncoding
,
format
.
channelCount
);
internalBuffer
=
internalBuffer
=
ByteBuffer
.
allocateDirect
(
DEFAULT_BUFFER_SIZE_FRAMES
*
frameSize
)
ByteBuffer
.
allocateDirect
(
DEFAULT_BUFFER_SIZE_FRAMES
*
frameSize
)
.
order
(
ByteOrder
.
nativeOrder
());
.
order
(
ByteOrder
.
nativeOrder
());
...
...
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/SilentAudioGeneratorTest.java
View file @
dfc69dee
...
@@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
...
@@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.
audio.AudioProcessor.Audio
Format
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -32,11 +32,7 @@ public class SilentAudioGeneratorTest {
...
@@ -32,11 +32,7 @@ public class SilentAudioGeneratorTest {
public
void
addSilenceOnce_numberOfBytesProduced_isCorrect
()
{
public
void
addSilenceOnce_numberOfBytesProduced_isCorrect
()
{
SilentAudioGenerator
generator
=
SilentAudioGenerator
generator
=
new
SilentAudioGenerator
(
new
SilentAudioGenerator
(
new
Format
.
Builder
()
new
AudioFormat
(
/* sampleRate= */
88_200
,
/* channelCount= */
6
,
C
.
ENCODING_PCM_16BIT
));
.
setSampleRate
(
88_200
)
.
setPcmEncoding
(
C
.
ENCODING_PCM_16BIT
)
.
setChannelCount
(
6
)
.
build
());
generator
.
addSilence
(
/* durationUs= */
3_000_000
);
generator
.
addSilence
(
/* durationUs= */
3_000_000
);
int
bytesOutput
=
drainGenerator
(
generator
);
int
bytesOutput
=
drainGenerator
(
generator
);
...
@@ -49,11 +45,7 @@ public class SilentAudioGeneratorTest {
...
@@ -49,11 +45,7 @@ public class SilentAudioGeneratorTest {
public
void
addSilenceTwice_numberOfBytesProduced_isCorrect
()
{
public
void
addSilenceTwice_numberOfBytesProduced_isCorrect
()
{
SilentAudioGenerator
generator
=
SilentAudioGenerator
generator
=
new
SilentAudioGenerator
(
new
SilentAudioGenerator
(
new
Format
.
Builder
()
new
AudioFormat
(
/* sampleRate= */
88_200
,
/* channelCount= */
6
,
C
.
ENCODING_PCM_16BIT
));
.
setSampleRate
(
88_200
)
.
setPcmEncoding
(
C
.
ENCODING_PCM_16BIT
)
.
setChannelCount
(
6
)
.
build
());
generator
.
addSilence
(
/* durationUs= */
3_000_000
);
generator
.
addSilence
(
/* durationUs= */
3_000_000
);
int
bytesOutput
=
drainGenerator
(
generator
);
int
bytesOutput
=
drainGenerator
(
generator
);
...
@@ -68,11 +60,8 @@ public class SilentAudioGeneratorTest {
...
@@ -68,11 +60,8 @@ public class SilentAudioGeneratorTest {
public
void
lastBufferProduced_isCorrectSize
()
{
public
void
lastBufferProduced_isCorrectSize
()
{
SilentAudioGenerator
generator
=
SilentAudioGenerator
generator
=
new
SilentAudioGenerator
(
new
SilentAudioGenerator
(
new
Format
.
Builder
()
new
AudioFormat
(
/* sampleRate= */
44_100
,
/* channelCount= */
2
,
C
.
ENCODING_PCM_16BIT
));
.
setSampleRate
(
44_100
)
.
setPcmEncoding
(
C
.
ENCODING_PCM_16BIT
)
.
setChannelCount
(
2
)
.
build
());
generator
.
addSilence
(
/* durationUs= */
1_000_000
);
generator
.
addSilence
(
/* durationUs= */
1_000_000
);
int
currentBufferSize
=
0
;
int
currentBufferSize
=
0
;
...
@@ -92,11 +81,7 @@ public class SilentAudioGeneratorTest {
...
@@ -92,11 +81,7 @@ public class SilentAudioGeneratorTest {
public
void
totalBytesLowerThanDefaultBufferSize_smallBufferProduced
()
{
public
void
totalBytesLowerThanDefaultBufferSize_smallBufferProduced
()
{
SilentAudioGenerator
generator
=
SilentAudioGenerator
generator
=
new
SilentAudioGenerator
(
new
SilentAudioGenerator
(
new
Format
.
Builder
()
new
AudioFormat
(
/* sampleRate= */
48_000
,
/* channelCount= */
2
,
C
.
ENCODING_PCM_16BIT
));
.
setSampleRate
(
48_000
)
.
setPcmEncoding
(
C
.
ENCODING_PCM_16BIT
)
.
setChannelCount
(
2
)
.
build
());
generator
.
addSilence
(
/* durationUs= */
5_000
);
generator
.
addSilence
(
/* durationUs= */
5_000
);
...
...
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/TestUtil.java
View file @
dfc69dee
...
@@ -115,7 +115,9 @@ public final class TestUtil {
...
@@ -115,7 +115,9 @@ public final class TestUtil {
.
setChannelCount
(
2
)
.
setChannelCount
(
2
)
.
build
();
.
build
();
try
{
try
{
listener
.
onTrackAdded
(
format
,
supportedOutputTypes
);
if
(
listener
.
onTrackAdded
(
format
,
supportedOutputTypes
))
{
format
=
format
.
buildUpon
().
setPcmEncoding
(
C
.
ENCODING_PCM_16BIT
).
build
();
}
SampleConsumer
sampleConsumer
=
listener
.
onOutputFormat
(
format
);
SampleConsumer
sampleConsumer
=
listener
.
onOutputFormat
(
format
);
if
(
sampleConsumerRef
!=
null
)
{
if
(
sampleConsumerRef
!=
null
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment