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
d4c0a051
authored
Apr 24, 2023
by
sheenachhabra
Committed by
Ian Baker
Apr 26, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Replace MediaFormat with Format class in muxer module
PiperOrigin-RevId: 526655859
parent
deb4ffd1
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
226 additions
and
53 deletions
library/common/src/main/java/com/google/android/exoplayer2/util/MediaFormatUtil.java
library/common/src/test/java/com/google/android/exoplayer2/util/MediaFormatUtilTest.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultCodec.java
testdata/src/test/assets/transformerdumps/mkv/sample_with_srt.mkv.dump
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.48000hz.dump
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.concatenated_with_high_pitch_and_no_video.dump
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.silence_then_audio.dump
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.silence_then_audio_with_effects.dump
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.silentaudio.dump
testdata/src/test/assets/transformerdumps/mp4/sample_18byte_nclx_colr.mp4.silentaudio.dump
testdata/src/test/assets/transformerdumps/mp4/sample_ac3.mp4.fallback.dump
testdata/src/test/assets/transformerdumps/mp4/sample_sef_slow_motion.mp4.dump
testdata/src/test/assets/transformerdumps/wav/sample.wav.aac.dump
library/common/src/main/java/com/google/android/exoplayer2/util/MediaFormatUtil.java
View file @
d4c0a051
...
@@ -24,6 +24,7 @@ import androidx.annotation.Nullable;
...
@@ -24,6 +24,7 @@ import androidx.annotation.Nullable;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.video.ColorInfo
;
import
com.google.android.exoplayer2.video.ColorInfo
;
import
com.google.common.collect.ImmutableList
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.List
;
import
java.util.List
;
...
@@ -63,6 +64,70 @@ public final class MediaFormatUtil {
...
@@ -63,6 +64,70 @@ public final class MediaFormatUtil {
private
static
final
int
MAX_POWER_OF_TWO_INT
=
1
<<
30
;
private
static
final
int
MAX_POWER_OF_TWO_INT
=
1
<<
30
;
/** Returns a {@link Format} representing the given {@link MediaFormat}. */
@SuppressLint
(
"InlinedApi"
)
// Inlined MediaFormat keys.
public
static
Format
createFormatFromMediaFormat
(
MediaFormat
mediaFormat
)
{
Format
.
Builder
formatBuilder
=
new
Format
.
Builder
()
.
setSampleMimeType
(
mediaFormat
.
getString
(
MediaFormat
.
KEY_MIME
))
.
setLanguage
(
mediaFormat
.
getString
(
MediaFormat
.
KEY_LANGUAGE
))
.
setPeakBitrate
(
getInteger
(
mediaFormat
,
KEY_MAX_BIT_RATE
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setAverageBitrate
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_BIT_RATE
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setCodecs
(
mediaFormat
.
getString
(
MediaFormat
.
KEY_CODECS_STRING
))
.
setFrameRate
(
getFrameRate
(
mediaFormat
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setWidth
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_WIDTH
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setHeight
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_HEIGHT
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setPixelWidthHeightRatio
(
getPixelWidthHeightRatio
(
mediaFormat
,
/* defaultValue= */
1.0f
))
.
setMaxInputSize
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_MAX_INPUT_SIZE
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setRotationDegrees
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_ROTATION
,
/* defaultValue= */
0
))
// TODO(b/278101856): Disallow invalid values after confirming.
.
setColorInfo
(
getColorInfo
(
mediaFormat
,
/* allowInvalidValues= */
true
))
.
setSampleRate
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_SAMPLE_RATE
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setChannelCount
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_CHANNEL_COUNT
,
/* defaultValue= */
Format
.
NO_VALUE
))
.
setPcmEncoding
(
getInteger
(
mediaFormat
,
MediaFormat
.
KEY_PCM_ENCODING
,
/* defaultValue= */
Format
.
NO_VALUE
));
ImmutableList
.
Builder
<
byte
[]>
csdBuffers
=
new
ImmutableList
.
Builder
<>();
int
csdIndex
=
0
;
while
(
true
)
{
@Nullable
ByteBuffer
csdByteBuffer
=
mediaFormat
.
getByteBuffer
(
"csd-"
+
csdIndex
);
if
(
csdByteBuffer
==
null
)
{
break
;
}
byte
[]
csdBufferData
=
new
byte
[
csdByteBuffer
.
remaining
()];
csdByteBuffer
.
get
(
csdBufferData
);
csdByteBuffer
.
rewind
();
csdBuffers
.
add
(
csdBufferData
);
csdIndex
++;
}
formatBuilder
.
setInitializationData
(
csdBuffers
.
build
());
return
formatBuilder
.
build
();
}
/**
/**
* Returns a {@link MediaFormat} representing the given ExoPlayer {@link Format}.
* Returns a {@link MediaFormat} representing the given ExoPlayer {@link Format}.
*
*
...
@@ -201,6 +266,13 @@ public final class MediaFormatUtil {
...
@@ -201,6 +266,13 @@ public final class MediaFormatUtil {
*/
*/
@Nullable
@Nullable
public
static
ColorInfo
getColorInfo
(
MediaFormat
mediaFormat
)
{
public
static
ColorInfo
getColorInfo
(
MediaFormat
mediaFormat
)
{
return
getColorInfo
(
mediaFormat
,
/* allowInvalidValues= */
false
);
}
// Internal methods.
@Nullable
private
static
ColorInfo
getColorInfo
(
MediaFormat
mediaFormat
,
boolean
allowInvalidValues
)
{
if
(
SDK_INT
<
24
)
{
if
(
SDK_INT
<
24
)
{
// MediaFormat KEY_COLOR_TRANSFER and other KEY_COLOR values available from API 24.
// MediaFormat KEY_COLOR_TRANSFER and other KEY_COLOR values available from API 24.
return
null
;
return
null
;
...
@@ -218,16 +290,19 @@ public final class MediaFormatUtil {
...
@@ -218,16 +290,19 @@ public final class MediaFormatUtil {
@Nullable
@Nullable
byte
[]
hdrStaticInfo
=
byte
[]
hdrStaticInfo
=
hdrStaticInfoByteBuffer
!=
null
?
getArray
(
hdrStaticInfoByteBuffer
)
:
null
;
hdrStaticInfoByteBuffer
!=
null
?
getArray
(
hdrStaticInfoByteBuffer
)
:
null
;
// Some devices may produce invalid values from MediaFormat#getInteger.
// See b/239435670 for more information.
if
(!
allowInvalidValues
)
{
if
(!
isValidColorSpace
(
colorSpace
))
{
// Some devices may produce invalid values from MediaFormat#getInteger.
colorSpace
=
Format
.
NO_VALUE
;
// See b/239435670 for more information.
}
if
(!
isValidColorSpace
(
colorSpace
))
{
if
(!
isValidColorRange
(
colorRange
))
{
colorSpace
=
Format
.
NO_VALUE
;
colorRange
=
Format
.
NO_VALUE
;
}
}
if
(!
isValidColorRange
(
colorRange
))
{
if
(!
isValidColorTransfer
(
colorTransfer
))
{
colorRange
=
Format
.
NO_VALUE
;
colorTransfer
=
Format
.
NO_VALUE
;
}
if
(!
isValidColorTransfer
(
colorTransfer
))
{
colorTransfer
=
Format
.
NO_VALUE
;
}
}
}
if
(
colorSpace
!=
Format
.
NO_VALUE
if
(
colorSpace
!=
Format
.
NO_VALUE
...
@@ -244,14 +319,45 @@ public final class MediaFormatUtil {
...
@@ -244,14 +319,45 @@ public final class MediaFormatUtil {
return
null
;
return
null
;
}
}
/** Supports {@link MediaFormat#getInteger(String, int)} for {@code API < 29}. */
public
static
int
getInteger
(
MediaFormat
mediaFormat
,
String
name
,
int
defaultValue
)
{
return
mediaFormat
.
containsKey
(
name
)
?
mediaFormat
.
getInteger
(
name
)
:
defaultValue
;
}
/** Supports {@link MediaFormat#getFloat(String, float)} for {@code API < 29}. */
public
static
float
getFloat
(
MediaFormat
mediaFormat
,
String
name
,
float
defaultValue
)
{
return
mediaFormat
.
containsKey
(
name
)
?
mediaFormat
.
getFloat
(
name
)
:
defaultValue
;
}
/**
/**
*
Provides the same functionality as {@link MediaFormat#getInteger(String, int)
}.
*
Returns the frame rate from a {@link MediaFormat
}.
*
*
* <p>
{@link MediaFormat#getInteger(String, int)} is only available from API 29. This convenience
* <p>
The {@link MediaFormat#KEY_FRAME_RATE} can have both integer and float value so it returns
*
method provides support on lower API versions
.
*
which ever value is set
.
*/
*/
public
static
int
getInteger
(
MediaFormat
mediaFormat
,
String
name
,
int
defaultValue
)
{
private
static
float
getFrameRate
(
MediaFormat
mediaFormat
,
float
defaultValue
)
{
return
mediaFormat
.
containsKey
(
name
)
?
mediaFormat
.
getInteger
(
name
)
:
defaultValue
;
float
frameRate
=
defaultValue
;
if
(
mediaFormat
.
containsKey
(
MediaFormat
.
KEY_FRAME_RATE
))
{
try
{
frameRate
=
mediaFormat
.
getFloat
(
MediaFormat
.
KEY_FRAME_RATE
);
}
catch
(
ClassCastException
ex
)
{
frameRate
=
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_FRAME_RATE
);
}
}
return
frameRate
;
}
/** Returns the ratio between a pixel's width and height for a {@link MediaFormat}. */
// Inlined MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH and MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT.
@SuppressLint
(
"InlinedApi"
)
private
static
float
getPixelWidthHeightRatio
(
MediaFormat
mediaFormat
,
float
defaultValue
)
{
if
(
mediaFormat
.
containsKey
(
MediaFormat
.
KEY_PIXEL_ASPECT_RATIO_WIDTH
)
&&
mediaFormat
.
containsKey
(
MediaFormat
.
KEY_PIXEL_ASPECT_RATIO_HEIGHT
))
{
return
(
float
)
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_PIXEL_ASPECT_RATIO_WIDTH
)
/
(
float
)
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_PIXEL_ASPECT_RATIO_HEIGHT
);
}
return
defaultValue
;
}
}
public
static
byte
[]
getArray
(
ByteBuffer
byteBuffer
)
{
public
static
byte
[]
getArray
(
ByteBuffer
byteBuffer
)
{
...
...
library/common/src/test/java/com/google/android/exoplayer2/util/MediaFormatUtilTest.java
View file @
d4c0a051
...
@@ -23,12 +23,96 @@ import com.google.android.exoplayer2.C;
...
@@ -23,12 +23,96 @@ import com.google.android.exoplayer2.C;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.video.ColorInfo
;
import
com.google.android.exoplayer2.video.ColorInfo
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
java.nio.ByteBuffer
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
/** Unit tests for {@link MediaFormatUtil}. */
/** Unit tests for {@link MediaFormatUtil}. */
@RunWith
(
AndroidJUnit4
.
class
)
@RunWith
(
AndroidJUnit4
.
class
)
public
class
MediaFormatUtilTest
{
public
class
MediaFormatUtilTest
{
@Test
public
void
createFormatFromMediaFormat_withEmptyMap_generatesExpectedFormat
()
{
Format
format
=
MediaFormatUtil
.
createFormatFromMediaFormat
(
new
MediaFormat
());
assertThat
(
format
.
sampleMimeType
).
isNull
();
assertThat
(
format
.
language
).
isNull
();
assertThat
(
format
.
peakBitrate
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
averageBitrate
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
codecs
).
isNull
();
assertThat
(
format
.
frameRate
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
width
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
height
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
pixelWidthHeightRatio
).
isEqualTo
(
1.0f
);
assertThat
(
format
.
maxInputSize
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
rotationDegrees
).
isEqualTo
(
0
);
assertThat
(
format
.
colorInfo
).
isNull
();
assertThat
(
format
.
sampleRate
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
channelCount
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
pcmEncoding
).
isEqualTo
(
Format
.
NO_VALUE
);
assertThat
(
format
.
initializationData
).
isEmpty
();
}
@Test
public
void
createFormatFromMediaFormat_withPopulatedMap_generatesExpectedFormat
()
{
MediaFormat
mediaFormat
=
new
MediaFormat
();
mediaFormat
.
setString
(
MediaFormat
.
KEY_MIME
,
MimeTypes
.
VIDEO_H264
);
mediaFormat
.
setString
(
MediaFormat
.
KEY_LANGUAGE
,
"eng"
);
mediaFormat
.
setInteger
(
MediaFormatUtil
.
KEY_MAX_BIT_RATE
,
128000
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_BIT_RATE
,
128000
);
mediaFormat
.
setString
(
MediaFormat
.
KEY_CODECS_STRING
,
"avc.123"
);
mediaFormat
.
setFloat
(
MediaFormat
.
KEY_FRAME_RATE
,
4
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_WIDTH
,
10
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_HEIGHT
,
8
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_PIXEL_ASPECT_RATIO_WIDTH
,
15
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_PIXEL_ASPECT_RATIO_HEIGHT
,
5
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_MAX_INPUT_SIZE
,
10
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_ROTATION
,
90
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_COLOR_STANDARD
,
C
.
COLOR_SPACE_BT601
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_COLOR_TRANSFER
,
C
.
COLOR_TRANSFER_HLG
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_COLOR_RANGE
,
C
.
COLOR_RANGE_FULL
);
mediaFormat
.
setByteBuffer
(
MediaFormat
.
KEY_HDR_STATIC_INFO
,
ByteBuffer
.
wrap
(
new
byte
[]
{
3
}));
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_SAMPLE_RATE
,
11
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_CHANNEL_COUNT
,
2
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_PCM_ENCODING
,
C
.
ENCODING_PCM_8BIT
);
mediaFormat
.
setByteBuffer
(
"csd-0"
,
ByteBuffer
.
wrap
(
new
byte
[]
{
7
}));
mediaFormat
.
setByteBuffer
(
"csd-1"
,
ByteBuffer
.
wrap
(
new
byte
[]
{
10
}));
Format
format
=
MediaFormatUtil
.
createFormatFromMediaFormat
(
mediaFormat
);
assertThat
(
format
.
sampleMimeType
).
isEqualTo
(
mediaFormat
.
getString
(
MediaFormat
.
KEY_MIME
));
// Format stores normalized language code.
assertThat
(
format
.
language
)
.
isEqualTo
(
Util
.
normalizeLanguageCode
(
mediaFormat
.
getString
(
MediaFormat
.
KEY_LANGUAGE
)));
assertThat
(
format
.
peakBitrate
)
.
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormatUtil
.
KEY_MAX_BIT_RATE
));
assertThat
(
format
.
averageBitrate
).
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_BIT_RATE
));
assertThat
(
format
.
codecs
).
isEqualTo
(
mediaFormat
.
getString
(
MediaFormat
.
KEY_CODECS_STRING
));
assertThat
(
format
.
frameRate
).
isEqualTo
(
mediaFormat
.
getFloat
(
MediaFormat
.
KEY_FRAME_RATE
));
assertThat
(
format
.
width
).
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_WIDTH
));
assertThat
(
format
.
height
).
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_HEIGHT
));
// Ratio of MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH (15) and
// MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT (5).
assertThat
(
format
.
pixelWidthHeightRatio
).
isEqualTo
(
3.0f
);
assertThat
(
format
.
maxInputSize
)
.
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_MAX_INPUT_SIZE
));
assertThat
(
format
.
rotationDegrees
).
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_ROTATION
));
assertThat
(
format
.
colorInfo
.
colorSpace
)
.
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_COLOR_STANDARD
));
assertThat
(
format
.
colorInfo
.
colorTransfer
)
.
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_COLOR_TRANSFER
));
assertThat
(
format
.
colorInfo
.
colorRange
)
.
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_COLOR_RANGE
));
assertThat
(
format
.
colorInfo
.
hdrStaticInfo
)
.
isEqualTo
(
mediaFormat
.
getByteBuffer
(
MediaFormat
.
KEY_HDR_STATIC_INFO
).
array
());
assertThat
(
format
.
sampleRate
).
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_SAMPLE_RATE
));
assertThat
(
format
.
channelCount
)
.
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_CHANNEL_COUNT
));
assertThat
(
format
.
pcmEncoding
).
isEqualTo
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_PCM_ENCODING
));
assertThat
(
format
.
initializationData
.
get
(
0
))
.
isEqualTo
(
mediaFormat
.
getByteBuffer
(
"csd-0"
).
array
());
assertThat
(
format
.
initializationData
.
get
(
1
))
.
isEqualTo
(
mediaFormat
.
getByteBuffer
(
"csd-1"
).
array
());
}
@Test
@Test
public
void
createMediaFormatFromFormat_withEmptyFormat_generatesExpectedEntries
()
{
public
void
createMediaFormatFromFormat_withEmptyFormat_generatesExpectedEntries
()
{
...
@@ -145,7 +229,7 @@ public class MediaFormatUtilTest {
...
@@ -145,7 +229,7 @@ public class MediaFormatUtilTest {
}
}
@Test
@Test
public
void
createMediaFormatFromFormat_withPcmEncoding_setsCustomPcmEncodingEntry
()
{
public
void
createMediaFormatFromFormat_with
Custom
PcmEncoding_setsCustomPcmEncodingEntry
()
{
Format
format
=
new
Format
.
Builder
().
setPcmEncoding
(
C
.
ENCODING_PCM_16BIT_BIG_ENDIAN
).
build
();
Format
format
=
new
Format
.
Builder
().
setPcmEncoding
(
C
.
ENCODING_PCM_16BIT_BIG_ENDIAN
).
build
();
MediaFormat
mediaFormat
=
MediaFormatUtil
.
createMediaFormatFromFormat
(
format
);
MediaFormat
mediaFormat
=
MediaFormatUtil
.
createMediaFormatFromFormat
(
format
);
assertThat
(
mediaFormat
.
getInteger
(
MediaFormatUtil
.
KEY_PCM_ENCODING_EXTENDED
))
assertThat
(
mediaFormat
.
getInteger
(
MediaFormatUtil
.
KEY_PCM_ENCODING_EXTENDED
))
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultCodec.java
View file @
d4c0a051
...
@@ -40,7 +40,6 @@ import com.google.android.exoplayer2.util.MediaFormatUtil;
...
@@ -40,7 +40,6 @@ import com.google.android.exoplayer2.util.MediaFormatUtil;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.TraceUtil
;
import
com.google.android.exoplayer2.util.TraceUtil
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.common.collect.ImmutableList
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
org.checkerframework.checker.initialization.qual.UnknownInitialization
;
import
org.checkerframework.checker.initialization.qual.UnknownInitialization
;
...
@@ -390,43 +389,17 @@ public final class DefaultCodec implements Codec {
...
@@ -390,43 +389,17 @@ public final class DefaultCodec implements Codec {
}
}
private
static
Format
convertToFormat
(
MediaFormat
mediaFormat
,
boolean
isDecoder
)
{
private
static
Format
convertToFormat
(
MediaFormat
mediaFormat
,
boolean
isDecoder
)
{
ImmutableList
.
Builder
<
byte
[]>
csdBuffers
=
new
ImmutableList
.
Builder
<>();
int
csdIndex
=
0
;
while
(
true
)
{
@Nullable
ByteBuffer
csdByteBuffer
=
mediaFormat
.
getByteBuffer
(
"csd-"
+
csdIndex
);
if
(
csdByteBuffer
==
null
)
{
break
;
}
byte
[]
csdBufferData
=
new
byte
[
csdByteBuffer
.
remaining
()];
csdByteBuffer
.
get
(
csdBufferData
);
csdBuffers
.
add
(
csdBufferData
);
csdIndex
++;
}
String
mimeType
=
mediaFormat
.
getString
(
MediaFormat
.
KEY_MIME
);
Format
.
Builder
formatBuilder
=
Format
.
Builder
formatBuilder
=
new
Format
.
Builder
().
setSampleMimeType
(
mimeType
).
setInitializationData
(
csdBuffers
.
build
());
MediaFormatUtil
.
createFormatFromMediaFormat
(
mediaFormat
).
buildUpon
();
if
(
MimeTypes
.
isVideo
(
mimeType
))
{
if
(
isDecoder
)
{
formatBuilder
// TODO(b/178685617): Restrict this to only set the PCM encoding for audio/raw once we have
.
setWidth
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_WIDTH
))
// a way to simulate more realistic codec input/output formats in tests.
.
setHeight
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_HEIGHT
))
.
setColorInfo
(
MediaFormatUtil
.
getColorInfo
(
mediaFormat
));
// With Robolectric, codecs do not actually encode/decode. The format of buffers is passed
}
else
if
(
MimeTypes
.
isAudio
(
mimeType
))
{
// through. However downstream components need to know the PCM encoding of the data being
formatBuilder
// output, so if a decoder is not outputting raw audio, we need to set the PCM
.
setChannelCount
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_CHANNEL_COUNT
))
// encoding to the default.
.
setSampleRate
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_SAMPLE_RATE
));
formatBuilder
.
setPcmEncoding
(
DEFAULT_PCM_ENCODING
);
if
(
SDK_INT
>=
24
&&
mediaFormat
.
containsKey
(
MediaFormat
.
KEY_PCM_ENCODING
))
{
formatBuilder
.
setPcmEncoding
(
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_PCM_ENCODING
));
}
else
if
(
isDecoder
)
{
// TODO(b/178685617): Restrict this to only set the PCM encoding for audio/raw once we have
// a way to simulate more realistic codec input/output formats in tests.
// With Robolectric, codecs do not actually encode/decode. The format of buffers is passed
// through. However downstream components need to know the PCM encoding of the data being
// output, so if a decoder is not outputting raw audio, we need to set the PCM
// encoding to the default.
formatBuilder
.
setPcmEncoding
(
DEFAULT_PCM_ENCODING
);
}
}
}
return
formatBuilder
.
build
();
return
formatBuilder
.
build
();
}
}
...
...
testdata/src/test/assets/transformerdumps/mkv/sample_with_srt.mkv.dump
View file @
d4c0a051
...
@@ -10,6 +10,7 @@ format 0:
...
@@ -10,6 +10,7 @@ format 0:
data = length 30, hash F6F3D010
data = length 30, hash F6F3D010
data = length 10, hash 7A0D0F2B
data = length 10, hash 7A0D0F2B
format 1:
format 1:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 1
channelCount = 1
sampleRate = 44100
sampleRate = 44100
...
...
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.48000hz.dump
View file @
d4c0a051
...
@@ -12,6 +12,7 @@ format 0:
...
@@ -12,6 +12,7 @@ format 0:
data = length 10, hash 7A0D0F2B
data = length 10, hash 7A0D0F2B
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
format 1:
format 1:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 1
channelCount = 1
sampleRate = 48000
sampleRate = 48000
...
...
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.concatenated_with_high_pitch_and_no_video.dump
View file @
d4c0a051
format 0:
format 0:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 1
channelCount = 1
sampleRate = 44100
sampleRate = 44100
...
...
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.silence_then_audio.dump
View file @
d4c0a051
...
@@ -12,6 +12,7 @@ format 0:
...
@@ -12,6 +12,7 @@ format 0:
data = length 10, hash 7A0D0F2B
data = length 10, hash 7A0D0F2B
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
format 1:
format 1:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 2
channelCount = 2
sampleRate = 44100
sampleRate = 44100
...
...
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.silence_then_audio_with_effects.dump
View file @
d4c0a051
...
@@ -12,6 +12,7 @@ format 0:
...
@@ -12,6 +12,7 @@ format 0:
data = length 10, hash 7A0D0F2B
data = length 10, hash 7A0D0F2B
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
format 1:
format 1:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 2
channelCount = 2
sampleRate = 44100
sampleRate = 44100
...
...
testdata/src/test/assets/transformerdumps/mp4/sample.mp4.silentaudio.dump
View file @
d4c0a051
...
@@ -12,6 +12,7 @@ format 0:
...
@@ -12,6 +12,7 @@ format 0:
data = length 10, hash 7A0D0F2B
data = length 10, hash 7A0D0F2B
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
container metadata = entries=[xyz: latitude=40.68, longitude=-74.5]
format 1:
format 1:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 2
channelCount = 2
sampleRate = 44100
sampleRate = 44100
...
...
testdata/src/test/assets/transformerdumps/mp4/sample_18byte_nclx_colr.mp4.silentaudio.dump
View file @
d4c0a051
...
@@ -15,6 +15,7 @@ format 0:
...
@@ -15,6 +15,7 @@ format 0:
data = length 29, hash 4746B5D9
data = length 29, hash 4746B5D9
data = length 10, hash 7A0D0F2B
data = length 10, hash 7A0D0F2B
format 1:
format 1:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 2
channelCount = 2
sampleRate = 44100
sampleRate = 44100
...
...
testdata/src/test/assets/transformerdumps/mp4/sample_ac3.mp4.fallback.dump
View file @
d4c0a051
format 0:
format 0:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 6
channelCount = 6
sampleRate = 48000
sampleRate = 48000
...
...
testdata/src/test/assets/transformerdumps/mp4/sample_sef_slow_motion.mp4.dump
View file @
d4c0a051
...
@@ -12,6 +12,7 @@ format 0:
...
@@ -12,6 +12,7 @@ format 0:
data = length 10, hash 7A0D0F2B
data = length 10, hash 7A0D0F2B
container metadata = entries=[mdta: key=com.android.capture.fps, value=43700000, smta: captureFrameRate=240.0, svcTemporalLayerCount=4, SlowMotion: segments=[Segment: startTimeMs=88, endTimeMs=879, speedDivisor=2, Segment: startTimeMs=1255, endTimeMs=1970, speedDivisor=8]]
container metadata = entries=[mdta: key=com.android.capture.fps, value=43700000, smta: captureFrameRate=240.0, svcTemporalLayerCount=4, SlowMotion: segments=[Segment: startTimeMs=88, endTimeMs=879, speedDivisor=2, Segment: startTimeMs=1255, endTimeMs=1970, speedDivisor=8]]
format 1:
format 1:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 2
channelCount = 2
sampleRate = 12000
sampleRate = 12000
...
...
testdata/src/test/assets/transformerdumps/wav/sample.wav.aac.dump
View file @
d4c0a051
format 0:
format 0:
averageBitrate = 131072
sampleMimeType = audio/mp4a-latm
sampleMimeType = audio/mp4a-latm
channelCount = 1
channelCount = 1
sampleRate = 44100
sampleRate = 44100
...
...
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