diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/DelegatingSubtitleDecoder.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/DelegatingSubtitleDecoder.java new file mode 100644 index 0000000000..d6578f980e --- /dev/null +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/text/DelegatingSubtitleDecoder.java @@ -0,0 +1,138 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package androidx.media3.exoplayer.text; + +import androidx.annotation.Nullable; +import androidx.media3.common.C; +import androidx.media3.common.text.Cue; +import androidx.media3.common.util.Util; +import androidx.media3.extractor.text.CuesWithTiming; +import androidx.media3.extractor.text.SimpleSubtitleDecoder; +import androidx.media3.extractor.text.Subtitle; +import androidx.media3.extractor.text.SubtitleParser; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Ordering; +import java.util.List; + +/** + * Wrapper around a {@link SubtitleParser} that can be used instead of any current {@link + * SimpleSubtitleDecoder} subclass. The main {@link #decode(byte[], int, boolean)} method will be + * delegating the parsing of the data to the underlying {@link SubtitleParser} instance and its + * {@link SubtitleParser#parse(byte[], int, int)} implementation. + * + *
Functionally, once each XXXDecoder class is refactored to be a XXXParser that implements + * {@link SubtitleParser}, the following should be equivalent: + * + *
Or in the case with initialization data: + * + *
TODO(b/289983417): this will only be used in the old decoding flow (Decoder after SampleQueue)
+ * while we maintain dual architecture. Once we fully migrate to the pre-SampleQueue flow, it can be
+ * deprecated and later deleted.
+ */
+/* package */ final class DelegatingSubtitleDecoder extends SimpleSubtitleDecoder {
+
+ private static final Subtitle EMPTY = new SubtitleFromCuesWithTiming(ImmutableList.of());
+ private final SubtitleParser subtitleParser;
+
+ /* package */ DelegatingSubtitleDecoder(String name, SubtitleParser subtitleParser) {
+ super(name);
+ this.subtitleParser = subtitleParser;
+ }
+
+ @Override
+ protected Subtitle decode(byte[] data, int length, boolean reset) {
+ if (reset) {
+ subtitleParser.reset();
+ }
+ @Nullable List