Skip to content

Commit

Permalink
make merged segment size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
lemondoglol committed Jan 30, 2023
1 parent e2ece2f commit dcdc9aa
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public int compareTo(Segment other) {
}

private static final int BUFFER_SIZE_BYTES = 128 * 1024;
private static final long MAX_MERGED_SEGMENT_START_TIME_DIFF_US = 20 * C.MICROS_PER_SECOND;
public static final long DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US = 20 * C.MICROS_PER_SECOND;
private static long MAX_MERGED_SEGMENT_START_TIME_DIFF_US = DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US;

private final DataSpec manifestDataSpec;
private final Parser<M> manifestParser;
Expand Down Expand Up @@ -107,7 +108,29 @@ public int compareTo(Segment other) {
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffUs max merged size for each segment duration
*/
public SegmentDownloader(
MediaItem mediaItem,
Parser<M> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor,
long maxMergedSegmentStartTimeDiffUs
) {
checkNotNull(mediaItem.localConfiguration);
this.manifestDataSpec = getCompressibleDataSpec(mediaItem.localConfiguration.uri);
this.manifestParser = manifestParser;
this.streamKeys = new ArrayList<>(mediaItem.localConfiguration.streamKeys);
this.cacheDataSourceFactory = cacheDataSourceFactory;
this.executor = executor;
cache = Assertions.checkNotNull(cacheDataSourceFactory.getCache());
cacheKeyFactory = cacheDataSourceFactory.getCacheKeyFactory();
priorityTaskManager = cacheDataSourceFactory.getUpstreamPriorityTaskManager();
activeRunnables = new ArrayList<>();
MAX_MERGED_SEGMENT_START_TIME_DIFF_US = maxMergedSegmentStartTimeDiffUs * C.MICROS_PER_SECOND;
}

@Deprecated
public SegmentDownloader(
MediaItem mediaItem,
Parser<M> manifestParser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public DashDownloader(MediaItem mediaItem, CacheDataSource.Factory cacheDataSour
*/
public DashDownloader(
MediaItem mediaItem, CacheDataSource.Factory cacheDataSourceFactory, Executor executor) {
this(mediaItem, new DashManifestParser(), cacheDataSourceFactory, executor);
this(mediaItem, new DashManifestParser(), cacheDataSourceFactory, executor, DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US);
}

/**
Expand All @@ -113,13 +113,32 @@ public DashDownloader(
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffUs max merged size for each segment duration
*/
public DashDownloader(
MediaItem mediaItem,
Parser<DashManifest> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor,
long maxMergedSegmentStartTimeDiffUs
) {
super(mediaItem, manifestParser, cacheDataSourceFactory, executor, maxMergedSegmentStartTimeDiffUs);
baseUrlExclusionList = new BaseUrlExclusionList();
}

@Deprecated
public DashDownloader(
MediaItem mediaItem,
Parser<DashManifest> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor) {
super(mediaItem, manifestParser, cacheDataSourceFactory, executor);
super(
mediaItem,
manifestParser,
cacheDataSourceFactory,
executor,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
baseUrlExclusionList = new BaseUrlExclusionList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ public HlsDownloader(MediaItem mediaItem, CacheDataSource.Factory cacheDataSourc
*/
public HlsDownloader(
MediaItem mediaItem, CacheDataSource.Factory cacheDataSourceFactory, Executor executor) {
this(mediaItem, new HlsPlaylistParser(), cacheDataSourceFactory, executor);
this(
mediaItem,
new HlsPlaylistParser(),
cacheDataSourceFactory,
executor,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}

/**
Expand All @@ -102,13 +108,37 @@ public HlsDownloader(
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffUs max merged size for each segment duration
*/
public HlsDownloader(
MediaItem mediaItem,
Parser<HlsPlaylist> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor,
long maxMergedSegmentStartTimeDiffUs
) {
super(
mediaItem,
manifestParser,
cacheDataSourceFactory,
executor,
maxMergedSegmentStartTimeDiffUs
);
}

@Deprecated
public HlsDownloader(
MediaItem mediaItem,
Parser<HlsPlaylist> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor) {
super(mediaItem, manifestParser, cacheDataSourceFactory, executor);
super(
mediaItem,
manifestParser,
cacheDataSourceFactory,
executor,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public SsDownloader(
.build(),
new SsManifestParser(),
cacheDataSourceFactory,
executor);
executor,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}

/**
Expand All @@ -106,13 +108,37 @@ public SsDownloader(
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffUs max merged size for each segment duration
*/
public SsDownloader(
MediaItem mediaItem,
Parser<SsManifest> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor,
long maxMergedSegmentStartTimeDiffUs
) {
super(
mediaItem,
manifestParser,
cacheDataSourceFactory,
executor,
maxMergedSegmentStartTimeDiffUs
);
}

@Deprecated
public SsDownloader(
MediaItem mediaItem,
Parser<SsManifest> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor) {
super(mediaItem, manifestParser, cacheDataSourceFactory, executor);
super(
mediaItem,
manifestParser,
cacheDataSourceFactory,
executor,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}

@Override
Expand Down

0 comments on commit dcdc9aa

Please sign in to comment.