Java Code Examples for com.google.android.exoplayer2.Format#createAudioContainerFormat()

The following examples show how to use com.google.android.exoplayer2.Format#createAudioContainerFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HlsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static Format deriveAudioFormat(
    Format variantFormat, Format mediaTagFormat, boolean isPrimaryTrackInVariant) {
  String codecs;
  int channelCount = Format.NO_VALUE;
  int selectionFlags = 0;
  String language = null;
  String label = null;
  if (mediaTagFormat != null) {
    codecs = mediaTagFormat.codecs;
    channelCount = mediaTagFormat.channelCount;
    selectionFlags = mediaTagFormat.selectionFlags;
    language = mediaTagFormat.language;
    label = mediaTagFormat.label;
  } else {
    codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_AUDIO);
    if (isPrimaryTrackInVariant) {
      channelCount = variantFormat.channelCount;
      selectionFlags = variantFormat.selectionFlags;
      language = variantFormat.label;
      label = variantFormat.label;
    }
  }
  String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
  int bitrate = isPrimaryTrackInVariant ? variantFormat.bitrate : Format.NO_VALUE;
  return Format.createAudioContainerFormat(
      variantFormat.id,
      label,
      variantFormat.containerMimeType,
      sampleMimeType,
      codecs,
      bitrate,
      channelCount,
      /* sampleRate= */ Format.NO_VALUE,
      /* initializationData= */ null,
      selectionFlags,
      language);
}
 
Example 2
Source File: HlsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static Format deriveAudioFormat(
    Format variantFormat, Format mediaTagFormat, boolean isPrimaryTrackInVariant) {
  String codecs;
  int channelCount = Format.NO_VALUE;
  int selectionFlags = 0;
  String language = null;
  String label = null;
  if (mediaTagFormat != null) {
    codecs = mediaTagFormat.codecs;
    channelCount = mediaTagFormat.channelCount;
    selectionFlags = mediaTagFormat.selectionFlags;
    language = mediaTagFormat.language;
    label = mediaTagFormat.label;
  } else {
    codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_AUDIO);
    if (isPrimaryTrackInVariant) {
      channelCount = variantFormat.channelCount;
      selectionFlags = variantFormat.selectionFlags;
      language = variantFormat.label;
      label = variantFormat.label;
    }
  }
  String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
  int bitrate = isPrimaryTrackInVariant ? variantFormat.bitrate : Format.NO_VALUE;
  return Format.createAudioContainerFormat(
      variantFormat.id,
      label,
      variantFormat.containerMimeType,
      sampleMimeType,
      codecs,
      bitrate,
      channelCount,
      /* sampleRate= */ Format.NO_VALUE,
      /* initializationData= */ null,
      selectionFlags,
      language);
}
 
Example 3
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
protected Format buildFormat(String id, String containerMimeType, int width, int height,
    float frameRate, int audioChannels, int audioSamplingRate, int bitrate, String language,
    @C.SelectionFlags int selectionFlags, List<SchemeValuePair> accessibilityDescriptors,
    String codecs) {
  String sampleMimeType = getSampleMimeType(containerMimeType, codecs);
  if (sampleMimeType != null) {
    if (MimeTypes.isVideo(sampleMimeType)) {
      return Format.createVideoContainerFormat(id, containerMimeType, sampleMimeType, codecs,
          bitrate, width, height, frameRate, null, selectionFlags);
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      return Format.createAudioContainerFormat(id, containerMimeType, sampleMimeType, codecs,
          bitrate, audioChannels, audioSamplingRate, null, selectionFlags, language);
    } else if (mimeTypeIsRawText(sampleMimeType)) {
      int accessibilityChannel;
      if (MimeTypes.APPLICATION_CEA608.equals(sampleMimeType)) {
        accessibilityChannel = parseCea608AccessibilityChannel(accessibilityDescriptors);
      } else if (MimeTypes.APPLICATION_CEA708.equals(sampleMimeType)) {
        accessibilityChannel = parseCea708AccessibilityChannel(accessibilityDescriptors);
      } else {
        accessibilityChannel = Format.NO_VALUE;
      }
      return Format.createTextContainerFormat(id, containerMimeType, sampleMimeType, codecs,
          bitrate, selectionFlags, language, accessibilityChannel);
    }
  }
  return Format.createContainerFormat(id, containerMimeType, sampleMimeType, codecs, bitrate,
      selectionFlags, language);
}
 
Example 4
Source File: HlsMediaPeriod.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static Format deriveAudioFormat(
    Format variantFormat, @Nullable Format mediaTagFormat, boolean isPrimaryTrackInVariant) {
  String codecs;
  Metadata metadata;
  int channelCount = Format.NO_VALUE;
  int selectionFlags = 0;
  int roleFlags = 0;
  String language = null;
  String label = null;
  if (mediaTagFormat != null) {
    codecs = mediaTagFormat.codecs;
    metadata = mediaTagFormat.metadata;
    channelCount = mediaTagFormat.channelCount;
    selectionFlags = mediaTagFormat.selectionFlags;
    roleFlags = mediaTagFormat.roleFlags;
    language = mediaTagFormat.language;
    label = mediaTagFormat.label;
  } else {
    codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_AUDIO);
    metadata = variantFormat.metadata;
    if (isPrimaryTrackInVariant) {
      channelCount = variantFormat.channelCount;
      selectionFlags = variantFormat.selectionFlags;
      roleFlags = variantFormat.roleFlags;
      language = variantFormat.language;
      label = variantFormat.label;
    }
  }
  String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
  int bitrate = isPrimaryTrackInVariant ? variantFormat.bitrate : Format.NO_VALUE;
  return Format.createAudioContainerFormat(
      variantFormat.id,
      label,
      variantFormat.containerMimeType,
      sampleMimeType,
      codecs,
      metadata,
      bitrate,
      channelCount,
      /* sampleRate= */ Format.NO_VALUE,
      /* initializationData= */ null,
      selectionFlags,
      roleFlags,
      language);
}
 
Example 5
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
protected Format buildFormat(
    @Nullable String id,
    @Nullable String containerMimeType,
    int width,
    int height,
    float frameRate,
    int audioChannels,
    int audioSamplingRate,
    int bitrate,
    @Nullable String language,
    List<Descriptor> roleDescriptors,
    List<Descriptor> accessibilityDescriptors,
    @Nullable String codecs,
    List<Descriptor> supplementalProperties) {
  String sampleMimeType = getSampleMimeType(containerMimeType, codecs);
  @C.SelectionFlags int selectionFlags = parseSelectionFlagsFromRoleDescriptors(roleDescriptors);
  @C.RoleFlags int roleFlags = parseRoleFlagsFromRoleDescriptors(roleDescriptors);
  roleFlags |= parseRoleFlagsFromAccessibilityDescriptors(accessibilityDescriptors);
  if (sampleMimeType != null) {
    if (MimeTypes.AUDIO_E_AC3.equals(sampleMimeType)) {
      sampleMimeType = parseEac3SupplementalProperties(supplementalProperties);
    }
    if (MimeTypes.isVideo(sampleMimeType)) {
      return Format.createVideoContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          /* metadata= */ null,
          bitrate,
          width,
          height,
          frameRate,
          /* initializationData= */ null,
          selectionFlags,
          roleFlags);
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      return Format.createAudioContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          /* metadata= */ null,
          bitrate,
          audioChannels,
          audioSamplingRate,
          /* initializationData= */ null,
          selectionFlags,
          roleFlags,
          language);
    } else if (mimeTypeIsRawText(sampleMimeType)) {
      int accessibilityChannel;
      if (MimeTypes.APPLICATION_CEA608.equals(sampleMimeType)) {
        accessibilityChannel = parseCea608AccessibilityChannel(accessibilityDescriptors);
      } else if (MimeTypes.APPLICATION_CEA708.equals(sampleMimeType)) {
        accessibilityChannel = parseCea708AccessibilityChannel(accessibilityDescriptors);
      } else {
        accessibilityChannel = Format.NO_VALUE;
      }
      return Format.createTextContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          selectionFlags,
          roleFlags,
          language,
          accessibilityChannel);
    }
  }
  return Format.createContainerFormat(
      id,
      /* label= */ null,
      containerMimeType,
      sampleMimeType,
      codecs,
      bitrate,
      selectionFlags,
      roleFlags,
      language);
}
 
Example 6
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected Format buildFormat(
    String id,
    String label,
    String containerMimeType,
    int width,
    int height,
    float frameRate,
    int audioChannels,
    int audioSamplingRate,
    int bitrate,
    String language,
    @C.SelectionFlags int selectionFlags,
    List<Descriptor> accessibilityDescriptors,
    String codecs,
    List<Descriptor> supplementalProperties) {
  String sampleMimeType = getSampleMimeType(containerMimeType, codecs);
  if (sampleMimeType != null) {
    if (MimeTypes.AUDIO_E_AC3.equals(sampleMimeType)) {
      sampleMimeType = parseEac3SupplementalProperties(supplementalProperties);
    }
    if (MimeTypes.isVideo(sampleMimeType)) {
      return Format.createVideoContainerFormat(
          id,
          label,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          width,
          height,
          frameRate,
          /* initializationData= */ null,
          selectionFlags);
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      return Format.createAudioContainerFormat(
          id,
          label,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          audioChannels,
          audioSamplingRate,
          /* initializationData= */ null,
          selectionFlags,
          language);
    } else if (mimeTypeIsRawText(sampleMimeType)) {
      int accessibilityChannel;
      if (MimeTypes.APPLICATION_CEA608.equals(sampleMimeType)) {
        accessibilityChannel = parseCea608AccessibilityChannel(accessibilityDescriptors);
      } else if (MimeTypes.APPLICATION_CEA708.equals(sampleMimeType)) {
        accessibilityChannel = parseCea708AccessibilityChannel(accessibilityDescriptors);
      } else {
        accessibilityChannel = Format.NO_VALUE;
      }
      return Format.createTextContainerFormat(
          id,
          label,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          selectionFlags,
          language,
          accessibilityChannel);
    }
  }
  return Format.createContainerFormat(
      id, label, containerMimeType, sampleMimeType, codecs, bitrate, selectionFlags, language);
}
 
Example 7
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected Format buildFormat(
    String id,
    String label,
    String containerMimeType,
    int width,
    int height,
    float frameRate,
    int audioChannels,
    int audioSamplingRate,
    int bitrate,
    String language,
    @C.SelectionFlags int selectionFlags,
    List<Descriptor> accessibilityDescriptors,
    String codecs,
    List<Descriptor> supplementalProperties) {
  String sampleMimeType = getSampleMimeType(containerMimeType, codecs);
  if (sampleMimeType != null) {
    if (MimeTypes.AUDIO_E_AC3.equals(sampleMimeType)) {
      sampleMimeType = parseEac3SupplementalProperties(supplementalProperties);
    }
    if (MimeTypes.isVideo(sampleMimeType)) {
      return Format.createVideoContainerFormat(
          id,
          label,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          width,
          height,
          frameRate,
          /* initializationData= */ null,
          selectionFlags);
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      return Format.createAudioContainerFormat(
          id,
          label,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          audioChannels,
          audioSamplingRate,
          /* initializationData= */ null,
          selectionFlags,
          language);
    } else if (mimeTypeIsRawText(sampleMimeType)) {
      int accessibilityChannel;
      if (MimeTypes.APPLICATION_CEA608.equals(sampleMimeType)) {
        accessibilityChannel = parseCea608AccessibilityChannel(accessibilityDescriptors);
      } else if (MimeTypes.APPLICATION_CEA708.equals(sampleMimeType)) {
        accessibilityChannel = parseCea708AccessibilityChannel(accessibilityDescriptors);
      } else {
        accessibilityChannel = Format.NO_VALUE;
      }
      return Format.createTextContainerFormat(
          id,
          label,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          selectionFlags,
          language,
          accessibilityChannel);
    }
  }
  return Format.createContainerFormat(
      id, label, containerMimeType, sampleMimeType, codecs, bitrate, selectionFlags, language);
}
 
Example 8
Source File: HlsMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static Format deriveAudioFormat(
    Format variantFormat, Format mediaTagFormat, boolean isPrimaryTrackInVariant) {
  String codecs;
  Metadata metadata;
  int channelCount = Format.NO_VALUE;
  int selectionFlags = 0;
  int roleFlags = 0;
  String language = null;
  String label = null;
  if (mediaTagFormat != null) {
    codecs = mediaTagFormat.codecs;
    metadata = mediaTagFormat.metadata;
    channelCount = mediaTagFormat.channelCount;
    selectionFlags = mediaTagFormat.selectionFlags;
    roleFlags = mediaTagFormat.roleFlags;
    language = mediaTagFormat.language;
    label = mediaTagFormat.label;
  } else {
    codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_AUDIO);
    metadata = variantFormat.metadata;
    if (isPrimaryTrackInVariant) {
      channelCount = variantFormat.channelCount;
      selectionFlags = variantFormat.selectionFlags;
      roleFlags = variantFormat.roleFlags;
      language = variantFormat.language;
      label = variantFormat.label;
    }
  }
  String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
  int bitrate = isPrimaryTrackInVariant ? variantFormat.bitrate : Format.NO_VALUE;
  return Format.createAudioContainerFormat(
      variantFormat.id,
      label,
      variantFormat.containerMimeType,
      sampleMimeType,
      codecs,
      metadata,
      bitrate,
      channelCount,
      /* sampleRate= */ Format.NO_VALUE,
      /* initializationData= */ null,
      selectionFlags,
      roleFlags,
      language);
}
 
Example 9
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
protected Format buildFormat(
    String id,
    String containerMimeType,
    int width,
    int height,
    float frameRate,
    int audioChannels,
    int audioSamplingRate,
    int bitrate,
    String language,
    List<Descriptor> roleDescriptors,
    List<Descriptor> accessibilityDescriptors,
    String codecs,
    List<Descriptor> supplementalProperties) {
  String sampleMimeType = getSampleMimeType(containerMimeType, codecs);
  @C.SelectionFlags int selectionFlags = parseSelectionFlagsFromRoleDescriptors(roleDescriptors);
  @C.RoleFlags int roleFlags = parseRoleFlagsFromRoleDescriptors(roleDescriptors);
  roleFlags |= parseRoleFlagsFromAccessibilityDescriptors(accessibilityDescriptors);
  if (sampleMimeType != null) {
    if (MimeTypes.AUDIO_E_AC3.equals(sampleMimeType)) {
      sampleMimeType = parseEac3SupplementalProperties(supplementalProperties);
    }
    if (MimeTypes.isVideo(sampleMimeType)) {
      return Format.createVideoContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          /* metadata= */ null,
          bitrate,
          width,
          height,
          frameRate,
          /* initializationData= */ null,
          selectionFlags,
          roleFlags);
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      return Format.createAudioContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          /* metadata= */ null,
          bitrate,
          audioChannels,
          audioSamplingRate,
          /* initializationData= */ null,
          selectionFlags,
          roleFlags,
          language);
    } else if (mimeTypeIsRawText(sampleMimeType)) {
      int accessibilityChannel;
      if (MimeTypes.APPLICATION_CEA608.equals(sampleMimeType)) {
        accessibilityChannel = parseCea608AccessibilityChannel(accessibilityDescriptors);
      } else if (MimeTypes.APPLICATION_CEA708.equals(sampleMimeType)) {
        accessibilityChannel = parseCea708AccessibilityChannel(accessibilityDescriptors);
      } else {
        accessibilityChannel = Format.NO_VALUE;
      }
      return Format.createTextContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          selectionFlags,
          roleFlags,
          language,
          accessibilityChannel);
    }
  }
  return Format.createContainerFormat(
      id,
      /* label= */ null,
      containerMimeType,
      sampleMimeType,
      codecs,
      bitrate,
      selectionFlags,
      roleFlags,
      language);
}
 
Example 10
Source File: HlsMediaPeriod.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private static Format deriveAudioFormat(
    Format variantFormat, Format mediaTagFormat, boolean isPrimaryTrackInVariant) {
  String codecs;
  Metadata metadata;
  int channelCount = Format.NO_VALUE;
  int selectionFlags = 0;
  int roleFlags = 0;
  String language = null;
  String label = null;
  if (mediaTagFormat != null) {
    codecs = mediaTagFormat.codecs;
    metadata = mediaTagFormat.metadata;
    channelCount = mediaTagFormat.channelCount;
    selectionFlags = mediaTagFormat.selectionFlags;
    roleFlags = mediaTagFormat.roleFlags;
    language = mediaTagFormat.language;
    label = mediaTagFormat.label;
  } else {
    codecs = Util.getCodecsOfType(variantFormat.codecs, C.TRACK_TYPE_AUDIO);
    metadata = variantFormat.metadata;
    if (isPrimaryTrackInVariant) {
      channelCount = variantFormat.channelCount;
      selectionFlags = variantFormat.selectionFlags;
      roleFlags = variantFormat.roleFlags;
      language = variantFormat.language;
      label = variantFormat.label;
    }
  }
  String sampleMimeType = MimeTypes.getMediaMimeType(codecs);
  int bitrate = isPrimaryTrackInVariant ? variantFormat.bitrate : Format.NO_VALUE;
  return Format.createAudioContainerFormat(
      variantFormat.id,
      label,
      variantFormat.containerMimeType,
      sampleMimeType,
      codecs,
      metadata,
      bitrate,
      channelCount,
      /* sampleRate= */ Format.NO_VALUE,
      /* initializationData= */ null,
      selectionFlags,
      roleFlags,
      language);
}
 
Example 11
Source File: DashManifestParser.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
protected Format buildFormat(
    String id,
    String containerMimeType,
    int width,
    int height,
    float frameRate,
    int audioChannels,
    int audioSamplingRate,
    int bitrate,
    String language,
    List<Descriptor> roleDescriptors,
    List<Descriptor> accessibilityDescriptors,
    String codecs,
    List<Descriptor> supplementalProperties) {
  String sampleMimeType = getSampleMimeType(containerMimeType, codecs);
  @C.SelectionFlags int selectionFlags = parseSelectionFlagsFromRoleDescriptors(roleDescriptors);
  @C.RoleFlags int roleFlags = parseRoleFlagsFromRoleDescriptors(roleDescriptors);
  roleFlags |= parseRoleFlagsFromAccessibilityDescriptors(accessibilityDescriptors);
  if (sampleMimeType != null) {
    if (MimeTypes.AUDIO_E_AC3.equals(sampleMimeType)) {
      sampleMimeType = parseEac3SupplementalProperties(supplementalProperties);
    }
    if (MimeTypes.isVideo(sampleMimeType)) {
      return Format.createVideoContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          /* metadata= */ null,
          bitrate,
          width,
          height,
          frameRate,
          /* initializationData= */ null,
          selectionFlags,
          roleFlags);
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      return Format.createAudioContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          /* metadata= */ null,
          bitrate,
          audioChannels,
          audioSamplingRate,
          /* initializationData= */ null,
          selectionFlags,
          roleFlags,
          language);
    } else if (mimeTypeIsRawText(sampleMimeType)) {
      int accessibilityChannel;
      if (MimeTypes.APPLICATION_CEA608.equals(sampleMimeType)) {
        accessibilityChannel = parseCea608AccessibilityChannel(accessibilityDescriptors);
      } else if (MimeTypes.APPLICATION_CEA708.equals(sampleMimeType)) {
        accessibilityChannel = parseCea708AccessibilityChannel(accessibilityDescriptors);
      } else {
        accessibilityChannel = Format.NO_VALUE;
      }
      return Format.createTextContainerFormat(
          id,
          /* label= */ null,
          containerMimeType,
          sampleMimeType,
          codecs,
          bitrate,
          selectionFlags,
          roleFlags,
          language,
          accessibilityChannel);
    }
  }
  return Format.createContainerFormat(
      id,
      /* label= */ null,
      containerMimeType,
      sampleMimeType,
      codecs,
      bitrate,
      selectionFlags,
      roleFlags,
      language);
}