Merge pull request #8397 from equeim:avc-codecs

PiperOrigin-RevId: 350105847
This commit is contained in:
Ian Baker 2021-01-05 12:00:21 +00:00
commit a9a150a1d3
68 changed files with 92 additions and 5 deletions

View File

@ -39,6 +39,9 @@
([#8349](https://github.com/google/ExoPlayer/issues/8349))
* Add `DefaultHttpDataSource.Factory` and deprecate
`DefaultHttpDataSourceFactory`.
* Populate codecs string for H.264/AVC in MP4, Matroska and FLV streams to
allow decoder capability checks based on codec profile/level
([#8393](https://github.com/google/ExoPlayer/issues/8393)).
* Track selection:
* Add option to specify multiple preferred audio or text languages.
* Forward `Timeline` and `MediaPeriodId` to `TrackSelection.Factory`.

View File

@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.video;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.util.CodecSpecificDataUtil;
@ -34,13 +35,14 @@ public final class AvcConfig {
public final int width;
public final int height;
public final float pixelWidthAspectRatio;
@Nullable public final String codecs;
/**
* Parses AVC configuration data.
*
* @param data A {@link ParsableByteArray}, whose position is set to the start of the AVC
* configuration data to parse.
* @return A parsed representation of the HEVC configuration data.
* @return A parsed representation of the AVC configuration data.
* @throws ParserException If an error occurred parsing the data.
*/
public static AvcConfig parse(ParsableByteArray data) throws ParserException {
@ -63,6 +65,7 @@ public final class AvcConfig {
int width = Format.NO_VALUE;
int height = Format.NO_VALUE;
float pixelWidthAspectRatio = 1;
@Nullable String codecs = null;
if (numSequenceParameterSets > 0) {
byte[] sps = initializationData.get(0);
SpsData spsData = NalUnitUtil.parseSpsNalUnit(initializationData.get(0),
@ -70,21 +73,36 @@ public final class AvcConfig {
width = spsData.width;
height = spsData.height;
pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
codecs =
CodecSpecificDataUtil.buildAvcCodecString(
spsData.profileIdc, spsData.constraintsFlagsAndReservedZero2Bits, spsData.levelIdc);
}
return new AvcConfig(initializationData, nalUnitLengthFieldLength, width, height,
pixelWidthAspectRatio);
return new AvcConfig(
initializationData,
nalUnitLengthFieldLength,
width,
height,
pixelWidthAspectRatio,
codecs);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParserException("Error parsing AVC config", e);
}
}
private AvcConfig(List<byte[]> initializationData, int nalUnitLengthFieldLength,
int width, int height, float pixelWidthAspectRatio) {
private AvcConfig(
List<byte[]> initializationData,
int nalUnitLengthFieldLength,
int width,
int height,
float pixelWidthAspectRatio,
@Nullable String codecs) {
this.initializationData = initializationData;
this.nalUnitLengthFieldLength = nalUnitLengthFieldLength;
this.width = width;
this.height = height;
this.pixelWidthAspectRatio = pixelWidthAspectRatio;
this.codecs = codecs;
}
private static byte[] buildNalUnitForChild(ParsableByteArray data) {

View File

@ -93,6 +93,7 @@ import com.google.android.exoplayer2.video.AvcConfig;
Format format =
new Format.Builder()
.setSampleMimeType(MimeTypes.VIDEO_H264)
.setCodecs(avcConfig.codecs)
.setWidth(avcConfig.width)
.setHeight(avcConfig.height)
.setPixelWidthHeightRatio(avcConfig.pixelWidthAspectRatio)

View File

@ -2086,6 +2086,7 @@ public class MatroskaExtractor implements Extractor {
AvcConfig avcConfig = AvcConfig.parse(new ParsableByteArray(getCodecPrivate(codecId)));
initializationData = avcConfig.initializationData;
nalUnitLengthFieldLength = avcConfig.nalUnitLengthFieldLength;
codecs = avcConfig.codecs;
break;
case CODEC_ID_H265:
mimeType = MimeTypes.VIDEO_H265;

View File

@ -1058,6 +1058,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
if (!pixelWidthHeightRatioFromPasp) {
pixelWidthHeightRatio = avcConfig.pixelWidthAspectRatio;
}
codecs = avcConfig.codecs;
} else if (childAtomType == Atom.TYPE_hvcC) {
Assertions.checkState(mimeType == null);
mimeType = MimeTypes.VIDEO_H265;

View File

@ -11,6 +11,7 @@ track 9:
sample count = 71
format 0:
sampleMimeType = video/avc
codecs = avc1.64000C
width = 320
height = 180
initializationData:

View File

@ -11,6 +11,7 @@ track 9:
sample count = 47
format 0:
sampleMimeType = video/avc
codecs = avc1.64000C
width = 320
height = 180
initializationData:

View File

@ -11,6 +11,7 @@ track 9:
sample count = 23
format 0:
sampleMimeType = video/avc
codecs = avc1.64000C
width = 320
height = 180
initializationData:

View File

@ -11,6 +11,7 @@ track 9:
sample count = 23
format 0:
sampleMimeType = video/avc
codecs = avc1.64000C
width = 320
height = 180
initializationData:

View File

@ -11,6 +11,7 @@ track 9:
sample count = 71
format 0:
sampleMimeType = video/avc
codecs = avc1.64000C
width = 320
height = 180
initializationData:

View File

@ -198,6 +198,7 @@ track 9:
sample count = 30
format 0:
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
initializationData:

View File

@ -198,6 +198,7 @@ track 9:
sample count = 30
format 0:
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
initializationData:

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
rotationDegrees = 90

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
rotationDegrees = 90

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
rotationDegrees = 90

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
rotationDegrees = 90

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
rotationDegrees = 90

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 1:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640034
width = 1080
height = 720
selectionFlags = 1

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640033
maxInputSize = 34686
width = 1280
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640033
maxInputSize = 34686
width = 1280
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640033
maxInputSize = 34686
width = 1280
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640033
maxInputSize = 34686
width = 1280
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.640033
maxInputSize = 34686
width = 1280
height = 720

View File

@ -9,6 +9,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -9,6 +9,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -9,6 +9,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -9,6 +9,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -12,6 +12,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
maxInputSize = 36722
width = 1080
height = 720

View File

@ -9,6 +9,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData:

View File

@ -9,6 +9,7 @@ track 0:
format 0:
id = 1
sampleMimeType = video/avc
codecs = avc1.64001F
width = 1080
height = 720
initializationData: