summaryrefslogtreecommitdiffstats
path: root/mobile/android/exoplayer2/src/main/java/org/mozilla/thirdparty/com/google/android/exoplayer2/source/hls/HlsExtractorFactory.java
blob: 8f445f97ed7e35b322249bf1751a0a5b9d293859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2017 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
 *
 *      http://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 org.mozilla.thirdparty.com.google.android.exoplayer2.source.hls;

import android.net.Uri;
import androidx.annotation.Nullable;
import org.mozilla.thirdparty.com.google.android.exoplayer2.Format;
import org.mozilla.thirdparty.com.google.android.exoplayer2.extractor.Extractor;
import org.mozilla.thirdparty.com.google.android.exoplayer2.extractor.ExtractorInput;
import org.mozilla.thirdparty.com.google.android.exoplayer2.extractor.PositionHolder;
import org.mozilla.thirdparty.com.google.android.exoplayer2.util.TimestampAdjuster;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Factory for HLS media chunk extractors.
 */
public interface HlsExtractorFactory {

  /** Holds an {@link Extractor} and associated parameters. */
  final class Result {

    /** The created extractor; */
    public final Extractor extractor;
    /** Whether the segments for which {@link #extractor} is created are packed audio segments. */
    public final boolean isPackedAudioExtractor;
    /**
     * Whether {@link #extractor} may be reused for following continuous (no immediately preceding
     * discontinuities) segments of the same variant.
     */
    public final boolean isReusable;

    /**
     * Creates a result.
     *
     * @param extractor See {@link #extractor}.
     * @param isPackedAudioExtractor See {@link #isPackedAudioExtractor}.
     * @param isReusable See {@link #isReusable}.
     */
    public Result(Extractor extractor, boolean isPackedAudioExtractor, boolean isReusable) {
      this.extractor = extractor;
      this.isPackedAudioExtractor = isPackedAudioExtractor;
      this.isReusable = isReusable;
    }
  }

  HlsExtractorFactory DEFAULT = new DefaultHlsExtractorFactory();

  /**
   * Creates an {@link Extractor} for extracting HLS media chunks.
   *
   * @param previousExtractor A previously used {@link Extractor} which can be reused if the current
   *     chunk is a continuation of the previously extracted chunk, or null otherwise. It is the
   *     responsibility of implementers to only reuse extractors that are suited for reusage.
   * @param uri The URI of the media chunk.
   * @param format A {@link Format} associated with the chunk to extract.
   * @param muxedCaptionFormats List of muxed caption {@link Format}s. Null if no closed caption
   *     information is available in the master playlist.
   * @param timestampAdjuster Adjuster corresponding to the provided discontinuity sequence number.
   * @param responseHeaders The HTTP response headers associated with the media segment or
   *     initialization section to extract.
   * @param sniffingExtractorInput The first extractor input that will be passed to the returned
   *     extractor's {@link Extractor#read(ExtractorInput, PositionHolder)}. Must only be used to
   *     call {@link Extractor#sniff(ExtractorInput)}.
   * @return A {@link Result}.
   * @throws InterruptedException If the thread is interrupted while sniffing.
   * @throws IOException If an I/O error is encountered while sniffing.
   */
  Result createExtractor(
      @Nullable Extractor previousExtractor,
      Uri uri,
      Format format,
      @Nullable List<Format> muxedCaptionFormats,
      TimestampAdjuster timestampAdjuster,
      Map<String, List<String>> responseHeaders,
      ExtractorInput sniffingExtractorInput)
      throws InterruptedException, IOException;
}