Java Code Examples for com.google.android.exoplayer.util.MimeTypes#AUDIO_AAC

The following examples show how to use com.google.android.exoplayer.util.MimeTypes#AUDIO_AAC . 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: SmoothStreamingManifestParser.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
private static String fourCCToMimeType(String fourCC) {
  if (fourCC.equalsIgnoreCase("H264") || fourCC.equalsIgnoreCase("X264")
      || fourCC.equalsIgnoreCase("AVC1") || fourCC.equalsIgnoreCase("DAVC")) {
    return MimeTypes.VIDEO_H264;
  } else if (fourCC.equalsIgnoreCase("AAC") || fourCC.equalsIgnoreCase("AACL")
      || fourCC.equalsIgnoreCase("AACH") || fourCC.equalsIgnoreCase("AACP")) {
    return MimeTypes.AUDIO_AAC;
  } else if (fourCC.equalsIgnoreCase("TTML")) {
    return MimeTypes.APPLICATION_TTML;
  }
  return null;
}
 
Example 2
Source File: CommonMp4AtomParsers.java    From Exoplayer_VLC with Apache License 2.0 4 votes vote down vote up
private static Pair<MediaFormat, TrackEncryptionBox> parseAudioSampleEntry(
    ParsableByteArray parent, int atomType, int position, int size) {
  parent.setPosition(position + Mp4Util.ATOM_HEADER_SIZE);
  parent.skip(16);
  int channelCount = parent.readUnsignedShort();
  int sampleSize = parent.readUnsignedShort();
  parent.skip(4);
  int sampleRate = parent.readUnsignedFixedPoint1616();
  int bitrate = MediaFormat.NO_VALUE;

  byte[] initializationData = null;
  TrackEncryptionBox trackEncryptionBox = null;
  int childPosition = parent.getPosition();
  while (childPosition - position < size) {
    parent.setPosition(childPosition);
    int childStartPosition = parent.getPosition();
    int childAtomSize = parent.readInt();
    Assertions.checkArgument(childAtomSize > 0, "childAtomSize should be positive");
    int childAtomType = parent.readInt();
    if (atomType == Atom.TYPE_mp4a || atomType == Atom.TYPE_enca) {
      if (childAtomType == Atom.TYPE_esds) {
        initializationData = parseEsdsFromParent(parent, childStartPosition);
        // TODO: Do we really need to do this? See [Internal: b/10903778]
        // Update sampleRate and channelCount from the AudioSpecificConfig initialization data.
        Pair<Integer, Integer> audioSpecificConfig =
            CodecSpecificDataUtil.parseAudioSpecificConfig(initializationData);
        sampleRate = audioSpecificConfig.first;
        channelCount = audioSpecificConfig.second;
      } else if (childAtomType == Atom.TYPE_sinf) {
        trackEncryptionBox = parseSinfFromParent(parent, childStartPosition, childAtomSize);
      }
    } else if (atomType == Atom.TYPE_ac_3 && childAtomType == Atom.TYPE_dac3) {
      // TODO: Choose the right AC-3 track based on the contents of dac3/dec3.
      Ac3Format ac3Format =
          parseAc3SpecificBoxFromParent(parent, childStartPosition);
      if (ac3Format != null) {
        sampleRate = ac3Format.sampleRate;
        channelCount = ac3Format.channelCount;
        bitrate = ac3Format.bitrate;
      }

      // TODO: Add support for encrypted AC-3.
      trackEncryptionBox = null;
    } else if (atomType == Atom.TYPE_ec_3 && childAtomType == Atom.TYPE_dec3) {
      sampleRate = parseEc3SpecificBoxFromParent(parent, childStartPosition);
      trackEncryptionBox = null;
    }
    childPosition += childAtomSize;
  }

  String mimeType;
  if (atomType == Atom.TYPE_ac_3) {
    mimeType = MimeTypes.AUDIO_AC3;
  } else if (atomType == Atom.TYPE_ec_3) {
    mimeType = MimeTypes.AUDIO_EC3;
  } else {
    mimeType = MimeTypes.AUDIO_AAC;
  }

  MediaFormat format = MediaFormat.createAudioFormat(
      mimeType, sampleSize, channelCount, sampleRate, bitrate,
      initializationData == null ? null : Collections.singletonList(initializationData));
  return Pair.create(format, trackEncryptionBox);
}
 
Example 3
Source File: SmoothStreamingManifestParser.java    From Exoplayer_VLC with Apache License 2.0 4 votes vote down vote up
@Override
public void parseStartTag(XmlPullParser parser) throws ParserException {
  int type = (Integer) getNormalizedAttribute(KEY_TYPE);
  content = null;
  String value;

  index = parseInt(parser, KEY_INDEX, -1);
  bitrate = parseRequiredInt(parser, KEY_BITRATE);
  nalUnitLengthField = parseInt(parser, KEY_NAL_UNIT_LENGTH_FIELD, 4);

  if (type == StreamElement.TYPE_VIDEO) {
    maxHeight = parseRequiredInt(parser, KEY_MAX_HEIGHT);
    maxWidth = parseRequiredInt(parser, KEY_MAX_WIDTH);
    mimeType = fourCCToMimeType(parseRequiredString(parser, KEY_FOUR_CC));
  } else {
    maxHeight = -1;
    maxWidth = -1;
    String fourCC = parser.getAttributeValue(null, KEY_FOUR_CC);
    // If fourCC is missing and the stream type is audio, we assume AAC.
    mimeType = fourCC != null ? fourCCToMimeType(fourCC)
        : type == StreamElement.TYPE_AUDIO ? MimeTypes.AUDIO_AAC : null;
  }

  if (type == StreamElement.TYPE_AUDIO) {
    samplingRate = parseRequiredInt(parser, KEY_SAMPLING_RATE);
    channels = parseRequiredInt(parser, KEY_CHANNELS);
    bitPerSample = parseRequiredInt(parser, KEY_BITS_PER_SAMPLE);
    packetSize = parseRequiredInt(parser, KEY_PACKET_SIZE);
    audioTag = parseRequiredInt(parser, KEY_AUDIO_TAG);
  } else {
    samplingRate = -1;
    channels = -1;
    bitPerSample = -1;
    packetSize = -1;
    audioTag = -1;
  }

  value = parser.getAttributeValue(null, KEY_CODEC_PRIVATE_DATA);
  if (value != null && value.length() > 0) {
    byte[] codecPrivateData = hexStringToByteArray(value);
    byte[][] split = CodecSpecificDataUtil.splitNalUnits(codecPrivateData);
    if (split == null) {
      csd.add(codecPrivateData);
    } else {
      for (int i = 0; i < split.length; i++) {
        Pair<Integer, Integer> spsParameters = CodecSpecificDataUtil.parseSpsNalUnit(split[i]);
        if (spsParameters != null) {
          profile = spsParameters.first;
          level = spsParameters.second;
        }
        csd.add(split[i]);
      }
    }
  }
}