32
32
import androidx .media3 .common .DrmInitData ;
33
33
import androidx .media3 .common .DrmInitData .SchemeData ;
34
34
import androidx .media3 .common .Format ;
35
+ import androidx .media3 .common .Metadata ;
35
36
import androidx .media3 .common .MimeTypes ;
36
37
import androidx .media3 .common .ParserException ;
37
38
import androidx .media3 .common .util .Log ;
@@ -499,7 +500,7 @@ public void init(ExtractorOutput output) {
499
500
/* duration= */ 0 ,
500
501
/* size= */ 0 ,
501
502
/* flags= */ 0 ),
502
- getContainerMimeType ( sideloadedTrack .format ) );
503
+ sideloadedTrack .format );
503
504
trackBundles .put (0 , bundle );
504
505
extractorOutput .endTracks ();
505
506
}
@@ -743,11 +744,27 @@ private void onMoovContainerAtomRead(ContainerBox moov) throws ParserException {
743
744
}
744
745
}
745
746
747
+ @ Nullable Metadata mdtaMetadata = null ;
748
+ @ Nullable Mp4Box .ContainerBox meta = moov .getContainerBoxOfType (Mp4Box .TYPE_meta );
749
+ if (meta != null ) {
750
+ mdtaMetadata = BoxParser .parseMdtaFromMeta (meta );
751
+ }
752
+ GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder ();
753
+ @ Nullable Metadata udtaMetadata = null ;
754
+ @ Nullable Mp4Box .LeafBox udta = moov .getLeafBoxOfType (Mp4Box .TYPE_udta );
755
+ if (udta != null ) {
756
+ udtaMetadata = BoxParser .parseUdta (udta );
757
+ gaplessInfoHolder .setFromMetadata (udtaMetadata );
758
+ }
759
+ Metadata mvhdMetadata =
760
+ new Metadata (
761
+ BoxParser .parseMvhd (checkNotNull (moov .getLeafBoxOfType (Mp4Box .TYPE_mvhd )).data ));
762
+
746
763
// Construction of tracks and sample tables.
747
764
List <TrackSampleTable > sampleTables =
748
765
parseTraks (
749
766
moov ,
750
- new GaplessInfoHolder () ,
767
+ gaplessInfoHolder ,
751
768
duration ,
752
769
drmInitData ,
753
770
/* ignoreEditLists= */ (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS ) != 0 ,
@@ -763,12 +780,22 @@ private void onMoovContainerAtomRead(ContainerBox moov) throws ParserException {
763
780
Track track = sampleTable .track ;
764
781
TrackOutput output = extractorOutput .track (i , track .type );
765
782
output .durationUs (track .durationUs );
783
+ Format .Builder formatBuilder = track .format .buildUpon ();
784
+ formatBuilder .setContainerMimeType (containerMimeType );
785
+ MetadataUtil .setFormatGaplessInfo (track .type , gaplessInfoHolder , formatBuilder );
786
+ MetadataUtil .setFormatMetadata (
787
+ track .type ,
788
+ mdtaMetadata ,
789
+ formatBuilder ,
790
+ track .format .metadata ,
791
+ udtaMetadata ,
792
+ mvhdMetadata );
766
793
TrackBundle trackBundle =
767
794
new TrackBundle (
768
795
output ,
769
796
sampleTable ,
770
797
getDefaultSampleValues (defaultSampleValuesArray , track .id ),
771
- containerMimeType );
798
+ formatBuilder . build () );
772
799
trackBundles .put (track .id , trackBundle );
773
800
durationUs = max (durationUs , track .durationUs );
774
801
}
@@ -1900,7 +1927,9 @@ private static boolean shouldParseLeafAtom(int atom) {
1900
1927
|| atom == Mp4Box .TYPE_sgpd
1901
1928
|| atom == Mp4Box .TYPE_elst
1902
1929
|| atom == Mp4Box .TYPE_mehd
1903
- || atom == Mp4Box .TYPE_emsg ;
1930
+ || atom == Mp4Box .TYPE_emsg
1931
+ || atom == Mp4Box .TYPE_udta
1932
+ || atom == Mp4Box .TYPE_ilst ;
1904
1933
}
1905
1934
1906
1935
/** Returns whether the extractor should decode a container atom with type {@code atom}. */
@@ -1913,7 +1942,8 @@ private static boolean shouldParseContainerAtom(int atom) {
1913
1942
|| atom == Mp4Box .TYPE_moof
1914
1943
|| atom == Mp4Box .TYPE_traf
1915
1944
|| atom == Mp4Box .TYPE_mvex
1916
- || atom == Mp4Box .TYPE_edts ;
1945
+ || atom == Mp4Box .TYPE_edts
1946
+ || atom == Mp4Box .TYPE_meta ;
1917
1947
}
1918
1948
1919
1949
/** Holds data corresponding to a metadata sample. */
@@ -1946,7 +1976,7 @@ private static final class TrackBundle {
1946
1976
public int currentTrackRunIndex ;
1947
1977
public int firstSampleToOutputIndex ;
1948
1978
1949
- private final String containerMimeType ;
1979
+ private final Format baseFormat ;
1950
1980
private final ParsableByteArray encryptionSignalByte ;
1951
1981
private final ParsableByteArray defaultInitializationVector ;
1952
1982
@@ -1956,11 +1986,11 @@ public TrackBundle(
1956
1986
TrackOutput output ,
1957
1987
TrackSampleTable moovSampleTable ,
1958
1988
DefaultSampleValues defaultSampleValues ,
1959
- String containerMimeType ) {
1989
+ Format baseFormat ) {
1960
1990
this .output = output ;
1961
1991
this .moovSampleTable = moovSampleTable ;
1962
1992
this .defaultSampleValues = defaultSampleValues ;
1963
- this .containerMimeType = containerMimeType ;
1993
+ this .baseFormat = baseFormat ;
1964
1994
fragment = new TrackFragment ();
1965
1995
scratch = new ParsableByteArray ();
1966
1996
encryptionSignalByte = new ParsableByteArray (1 );
@@ -1971,9 +2001,7 @@ public TrackBundle(
1971
2001
public void reset (TrackSampleTable moovSampleTable , DefaultSampleValues defaultSampleValues ) {
1972
2002
this .moovSampleTable = moovSampleTable ;
1973
2003
this .defaultSampleValues = defaultSampleValues ;
1974
- Format format =
1975
- moovSampleTable .track .format .buildUpon ().setContainerMimeType (containerMimeType ).build ();
1976
- output .format (format );
2004
+ output .format (baseFormat );
1977
2005
resetFragmentInfo ();
1978
2006
}
1979
2007
@@ -1984,14 +2012,7 @@ public void updateDrmInitData(DrmInitData drmInitData) {
1984
2012
castNonNull (fragment .header ).sampleDescriptionIndex );
1985
2013
@ Nullable String schemeType = encryptionBox != null ? encryptionBox .schemeType : null ;
1986
2014
DrmInitData updatedDrmInitData = drmInitData .copyWithSchemeType (schemeType );
1987
- Format format =
1988
- moovSampleTable
1989
- .track
1990
- .format
1991
- .buildUpon ()
1992
- .setContainerMimeType (containerMimeType )
1993
- .setDrmInitData (updatedDrmInitData )
1994
- .build ();
2015
+ Format format = baseFormat .buildUpon ().setDrmInitData (updatedDrmInitData ).build ();
1995
2016
output .format (format );
1996
2017
}
1997
2018
0 commit comments