• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.exoplayer2.text;
17 
18 import androidx.annotation.Nullable;
19 import com.google.android.exoplayer2.Format;
20 import com.google.android.exoplayer2.decoder.OutputBuffer;
21 import com.google.android.exoplayer2.util.Assertions;
22 import java.util.List;
23 
24 /**
25  * Base class for {@link SubtitleDecoder} output buffers.
26  */
27 public abstract class SubtitleOutputBuffer extends OutputBuffer implements Subtitle {
28 
29   @Nullable private Subtitle subtitle;
30   private long subsampleOffsetUs;
31 
32   /**
33    * Sets the content of the output buffer, consisting of a {@link Subtitle} and associated
34    * metadata.
35    *
36    * @param timeUs The time of the start of the subtitle in microseconds.
37    * @param subtitle The subtitle.
38    * @param subsampleOffsetUs An offset that must be added to the subtitle's event times, or
39    *     {@link Format#OFFSET_SAMPLE_RELATIVE} if {@code timeUs} should be added.
40    */
setContent(long timeUs, Subtitle subtitle, long subsampleOffsetUs)41   public void setContent(long timeUs, Subtitle subtitle, long subsampleOffsetUs) {
42     this.timeUs = timeUs;
43     this.subtitle = subtitle;
44     this.subsampleOffsetUs = subsampleOffsetUs == Format.OFFSET_SAMPLE_RELATIVE ? this.timeUs
45         : subsampleOffsetUs;
46   }
47 
48   @Override
getEventTimeCount()49   public int getEventTimeCount() {
50     return Assertions.checkNotNull(subtitle).getEventTimeCount();
51   }
52 
53   @Override
getEventTime(int index)54   public long getEventTime(int index) {
55     return Assertions.checkNotNull(subtitle).getEventTime(index) + subsampleOffsetUs;
56   }
57 
58   @Override
getNextEventTimeIndex(long timeUs)59   public int getNextEventTimeIndex(long timeUs) {
60     return Assertions.checkNotNull(subtitle).getNextEventTimeIndex(timeUs - subsampleOffsetUs);
61   }
62 
63   @Override
getCues(long timeUs)64   public List<Cue> getCues(long timeUs) {
65     return Assertions.checkNotNull(subtitle).getCues(timeUs - subsampleOffsetUs);
66   }
67 
68   @Override
clear()69   public void clear() {
70     super.clear();
71     subtitle = null;
72   }
73 
74 }
75