60
60
import com .google .android .exoplayer2 .source .dash .manifest .Period ;
61
61
import com .google .android .exoplayer2 .source .dash .manifest .Representation ;
62
62
import com .google .android .exoplayer2 .source .dash .manifest .UtcTimingElement ;
63
+ import com .google .android .exoplayer2 .text .DefaultSubtitleParserFactory ;
64
+ import com .google .android .exoplayer2 .text .SubtitleParser ;
63
65
import com .google .android .exoplayer2 .upstream .Allocator ;
64
66
import com .google .android .exoplayer2 .upstream .CmcdConfiguration ;
65
67
import com .google .android .exoplayer2 .upstream .DataSource ;
@@ -118,6 +120,7 @@ public static final class Factory implements MediaSourceFactory {
118
120
private DrmSessionManagerProvider drmSessionManagerProvider ;
119
121
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory ;
120
122
private LoadErrorHandlingPolicy loadErrorHandlingPolicy ;
123
+ @ Nullable private SubtitleParser .Factory subtitleParserFactory ;
121
124
private long fallbackTargetLiveOffsetMs ;
122
125
private long minLiveStartPositionUs ;
123
126
@ Nullable private ParsingLoadable .Parser <? extends DashManifest > manifestParser ;
@@ -202,6 +205,40 @@ public Factory setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandl
202
205
return this ;
203
206
}
204
207
208
+ /**
209
+ * Sets whether subtitles should be parsed as part of extraction (before the sample queue) or as
210
+ * part of rendering (after the sample queue). Defaults to false (i.e. subtitles will be parsed
211
+ * as part of rendering).
212
+ *
213
+ * <p>This method is experimental. Its default value may change, or it may be renamed or removed
214
+ * in a future release.
215
+ *
216
+ * <p>This method may only be used with {@link DefaultDashChunkSource.Factory}.
217
+ *
218
+ * @param parseSubtitlesDuringExtraction Whether to parse subtitles during extraction or
219
+ * rendering.
220
+ * @return This factory, for convenience.
221
+ */
222
+ // TODO: b/289916598 - Flip the default of this to true (probably wired up to a single method on
223
+ // DefaultMediaSourceFactory via the MediaSource.Factory interface).
224
+ public Factory experimentalParseSubtitlesDuringExtraction (
225
+ boolean parseSubtitlesDuringExtraction ) {
226
+ if (parseSubtitlesDuringExtraction ) {
227
+ if (subtitleParserFactory == null ) {
228
+ this .subtitleParserFactory = new DefaultSubtitleParserFactory ();
229
+ }
230
+ } else {
231
+ this .subtitleParserFactory = null ;
232
+ }
233
+ if (chunkSourceFactory instanceof DefaultDashChunkSource .Factory ) {
234
+ ((DefaultDashChunkSource .Factory ) chunkSourceFactory )
235
+ .setSubtitleParserFactory (subtitleParserFactory );
236
+ } else {
237
+ throw new IllegalStateException ();
238
+ }
239
+ return this ;
240
+ }
241
+
205
242
/**
206
243
* Sets the target {@link Player#getCurrentLiveOffset() offset for live streams} that is used if
207
244
* no value is defined in the {@link MediaItem} or the manifest.
@@ -321,6 +358,7 @@ public DashMediaSource createMediaSource(DashManifest manifest, MediaItem mediaI
321
358
cmcdConfiguration ,
322
359
drmSessionManagerProvider .get (mediaItem ),
323
360
loadErrorHandlingPolicy ,
361
+ subtitleParserFactory ,
324
362
fallbackTargetLiveOffsetMs ,
325
363
minLiveStartPositionUs );
326
364
}
@@ -359,6 +397,7 @@ public DashMediaSource createMediaSource(MediaItem mediaItem) {
359
397
cmcdConfiguration ,
360
398
drmSessionManagerProvider .get (mediaItem ),
361
399
loadErrorHandlingPolicy ,
400
+ subtitleParserFactory ,
362
401
fallbackTargetLiveOffsetMs ,
363
402
minLiveStartPositionUs );
364
403
}
@@ -417,6 +456,7 @@ public DashMediaSource createMediaSource(MediaItem mediaItem) {
417
456
private final Runnable simulateManifestRefreshRunnable ;
418
457
private final PlayerEmsgCallback playerEmsgCallback ;
419
458
private final LoaderErrorThrower manifestLoadErrorThrower ;
459
+ @ Nullable private final SubtitleParser .Factory subtitleParserFactory ;
420
460
421
461
private DataSource dataSource ;
422
462
private Loader loader ;
@@ -452,6 +492,7 @@ private DashMediaSource(
452
492
@ Nullable CmcdConfiguration cmcdConfiguration ,
453
493
DrmSessionManager drmSessionManager ,
454
494
LoadErrorHandlingPolicy loadErrorHandlingPolicy ,
495
+ @ Nullable SubtitleParser .Factory subtitleParserFactory ,
455
496
long fallbackTargetLiveOffsetMs ,
456
497
long minLiveStartPositionUs ) {
457
498
this .mediaItem = mediaItem ;
@@ -465,6 +506,7 @@ private DashMediaSource(
465
506
this .cmcdConfiguration = cmcdConfiguration ;
466
507
this .drmSessionManager = drmSessionManager ;
467
508
this .loadErrorHandlingPolicy = loadErrorHandlingPolicy ;
509
+ this .subtitleParserFactory = subtitleParserFactory ;
468
510
this .fallbackTargetLiveOffsetMs = fallbackTargetLiveOffsetMs ;
469
511
this .minLiveStartPositionUs = minLiveStartPositionUs ;
470
512
this .compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory ;
@@ -570,7 +612,8 @@ public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long star
570
612
allocator ,
571
613
compositeSequenceableLoaderFactory ,
572
614
playerEmsgCallback ,
573
- getPlayerId ());
615
+ getPlayerId (),
616
+ subtitleParserFactory );
574
617
periodsById .put (mediaPeriod .id , mediaPeriod );
575
618
return mediaPeriod ;
576
619
}
0 commit comments