public final class

SeiReader

extends java.lang.Object

 java.lang.Object

↳androidx.media3.extractor.ts.SeiReader

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-extractor', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-extractor
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-extractor:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Consumes SEI buffers, outputting contained CEA-608/708 messages to a TrackOutput.

Summary

Constructors
publicSeiReader(java.util.List<Format> closedCaptionFormats)

Methods
public voidconsume(long pesTimeUs, ParsableByteArray seiBuffer)

public voidcreateTracks(ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator)

public voidflush()

Immediately passes any 'buffered for re-ordering' messages to the outputs passed to the constructor, using CeaUtil.consume(long, ParsableByteArray, TrackOutput[]).

public voidsetReorderingQueueSize(int reorderingQueueSize)

Sets the maximum number of SEI buffers that need to be kept in order to re-order from decode to presentation order.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SeiReader(java.util.List<Format> closedCaptionFormats)

Parameters:

closedCaptionFormats: A list of formats for the closed caption channels to expose.

Methods

public void createTracks(ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator)

public void setReorderingQueueSize(int reorderingQueueSize)

Sets the maximum number of SEI buffers that need to be kept in order to re-order from decode to presentation order.

public void consume(long pesTimeUs, ParsableByteArray seiBuffer)

public void flush()

Immediately passes any 'buffered for re-ordering' messages to the outputs passed to the constructor, using CeaUtil.consume(long, ParsableByteArray, TrackOutput[]).

Source

/*
 * Copyright (C) 2016 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 androidx.media3.extractor.ts;

import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.container.ReorderingSeiMessageQueue;
import androidx.media3.extractor.CeaUtil;
import androidx.media3.extractor.ExtractorOutput;
import androidx.media3.extractor.TrackOutput;
import androidx.media3.extractor.ts.TsPayloadReader.TrackIdGenerator;
import java.util.List;

/** Consumes SEI buffers, outputting contained CEA-608/708 messages to a {@link TrackOutput}. */
@UnstableApi
public final class SeiReader {

  private final List<Format> closedCaptionFormats;
  private final TrackOutput[] outputs;
  private final ReorderingSeiMessageQueue reorderingSeiMessageQueue;

  /**
   * @param closedCaptionFormats A list of formats for the closed caption channels to expose.
   */
  public SeiReader(List<Format> closedCaptionFormats) {
    this.closedCaptionFormats = closedCaptionFormats;
    outputs = new TrackOutput[closedCaptionFormats.size()];
    reorderingSeiMessageQueue =
        new ReorderingSeiMessageQueue(
            ((presentationTimeUs, seiBuffer) ->
                CeaUtil.consume(presentationTimeUs, seiBuffer, outputs)));
  }

  public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
    for (int i = 0; i < outputs.length; i++) {
      idGenerator.generateNewId();
      TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
      Format channelFormat = closedCaptionFormats.get(i);
      @Nullable String channelMimeType = channelFormat.sampleMimeType;
      Assertions.checkArgument(
          MimeTypes.APPLICATION_CEA608.equals(channelMimeType)
              || MimeTypes.APPLICATION_CEA708.equals(channelMimeType),
          "Invalid closed caption MIME type provided: " + channelMimeType);
      String formatId = channelFormat.id != null ? channelFormat.id : idGenerator.getFormatId();
      output.format(
          new Format.Builder()
              .setId(formatId)
              .setSampleMimeType(channelMimeType)
              .setSelectionFlags(channelFormat.selectionFlags)
              .setLanguage(channelFormat.language)
              .setAccessibilityChannel(channelFormat.accessibilityChannel)
              .setInitializationData(channelFormat.initializationData)
              .build());
      outputs[i] = output;
    }
  }

  /**
   * Sets the maximum number of SEI buffers that need to be kept in order to re-order from decode to
   * presentation order.
   */
  public void setReorderingQueueSize(int reorderingQueueSize) {
    reorderingSeiMessageQueue.setMaxSize(reorderingQueueSize);
  }

  public void consume(long pesTimeUs, ParsableByteArray seiBuffer) {
    reorderingSeiMessageQueue.add(pesTimeUs, seiBuffer);
  }

  /**
   * Immediately passes any 'buffered for re-ordering' messages to the {@linkplain TrackOutput
   * outputs} passed to the constructor, using {@link CeaUtil#consume(long, ParsableByteArray,
   * TrackOutput[])}.
   */
  public void flush() {
    reorderingSeiMessageQueue.flush();
  }
}