• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.android.tv.tuner.exoplayer2;
17 
18 import android.support.annotation.Nullable;
19 
20 import com.google.android.exoplayer2.source.BaseMediaSource;
21 import com.google.android.exoplayer2.source.MediaPeriod;
22 import com.google.android.exoplayer2.source.MediaSource;
23 import com.google.android.exoplayer2.source.SinglePeriodTimeline;
24 import com.google.android.exoplayer2.upstream.Allocator;
25 import com.google.android.exoplayer2.upstream.TransferListener;
26 import com.google.android.exoplayer2.util.Assertions;
27 
28 /** {@link MediaSource} that extracts sample data using a {@link SampleExtractor}. */
29 
30 public final class MpegTsMediaSource extends BaseMediaSource {
31 
32     private static final String TAG = "MpegTsMediaSource";
33 
34     private final SampleExtractor mSampleExtractor;
35 
36     /**
37      * Creates a new sample source that extracts samples using {@code mSampleExtractor}.
38      *
39      * @param sampleExtractor a sample extractor for accessing media samples
40      */
MpegTsMediaSource(SampleExtractor sampleExtractor)41     public MpegTsMediaSource(SampleExtractor sampleExtractor) {
42         mSampleExtractor = Assertions.checkNotNull(sampleExtractor);
43     }
44 
45     @Override
prepareSourceInternal(@ullable TransferListener mediaTransferListener)46     protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
47         refreshSourceInfo(new SinglePeriodTimeline(0, false, false), null);
48     }
49 
50     @Override
releaseSourceInternal()51     protected void releaseSourceInternal() {
52         // Do nothing
53     }
54 
55     @Override
maybeThrowSourceInfoRefreshError()56     public void maybeThrowSourceInfoRefreshError() {
57         // Do nothing
58     }
59 
60     @Override
createPeriod( MediaPeriodId id, Allocator allocator, long startPositionUs)61     public MpegTsMediaPeriod createPeriod(
62             MediaPeriodId id,
63             Allocator allocator,
64             long startPositionUs) {
65         return new MpegTsMediaPeriod(mSampleExtractor);
66     }
67 
68     @Override
releasePeriod(MediaPeriod mediaPeriod)69     public void releasePeriod(MediaPeriod mediaPeriod) {
70         ((MpegTsMediaPeriod) mediaPeriod).release();
71     }
72 }
73