MimeTypes { public static @Nullable String getMediaMimeType(@Nullable String codec) { if (codec == null) { return null; } codec = Util.toLowerInvariant(codec.trim()); if (codec.startsWith("avc1") || codec.startsWith("avc3")) { return MimeTypes.VIDEO_H264; } else if (codec.startsWith("hev1") || codec.startsWith("hvc1")) { return MimeTypes.VIDEO_H265; } else if (codec.startsWith("dvav") || codec.startsWith("dva1") || codec.startsWith("dvhe") || codec.startsWith("dvh1")) { return MimeTypes.VIDEO_DOLBY_VISION; } else if (codec.startsWith("av01")) { return MimeTypes.VIDEO_AV1; } else if (codec.startsWith("vp9") || codec.startsWith("vp09")) { return MimeTypes.VIDEO_VP9; } else if (codec.startsWith("vp8") || codec.startsWith("vp08")) { return MimeTypes.VIDEO_VP8; } else if (codec.startsWith("mp4a")) { String mimeType = null; if (codec.startsWith("mp4a.")) { String objectTypeString = codec.substring(5); if (objectTypeString.length() >= 2) { try { String objectTypeHexString = Util.toUpperInvariant(objectTypeString.substring(0, 2)); int objectTypeInt = Integer.parseInt(objectTypeHexString, 16); mimeType = getMimeTypeFromMp4ObjectType(objectTypeInt); } catch (NumberFormatException ignored) { } } } return mimeType == null ? MimeTypes.AUDIO_AAC : mimeType; } else if (codec.startsWith("ac-3") || codec.startsWith("dac3")) { return MimeTypes.AUDIO_AC3; } else if (codec.startsWith("ec-3") || codec.startsWith("dec3")) { return MimeTypes.AUDIO_E_AC3; } else if (codec.startsWith("ec+3")) { return MimeTypes.AUDIO_E_AC3_JOC; } else if (codec.startsWith("ac-4") || codec.startsWith("dac4")) { return MimeTypes.AUDIO_AC4; } else if (codec.startsWith("dtsc") || codec.startsWith("dtse")) { return MimeTypes.AUDIO_DTS; } else if (codec.startsWith("dtsh") || codec.startsWith("dtsl")) { return MimeTypes.AUDIO_DTS_HD; } else if (codec.startsWith("opus")) { return MimeTypes.AUDIO_OPUS; } else if (codec.startsWith("vorbis")) { return MimeTypes.AUDIO_VORBIS; } else if (codec.startsWith("flac")) { return MimeTypes.AUDIO_FLAC; } else { return getCustomMimeTypeForCodec(codec); } } private  MimeTypes(); static void registerCustomMimeType(String mimeType, String codecPrefix, int trackType); static boolean isAudio(@Nullable String mimeType); static boolean isVideo(@Nullable String mimeType); static boolean isText(@Nullable String mimeType); static boolean isApplication(@Nullable String mimeType); static boolean allSamplesAreSyncSamples(@Nullable String mimeType); static @Nullable String getVideoMediaMimeType(@Nullable String codecs); static @Nullable String getAudioMediaMimeType(@Nullable String codecs); static @Nullable String getMediaMimeType(@Nullable String codec); @Nullable static String getMimeTypeFromMp4ObjectType(int objectType); static int getTrackType(@Nullable String mimeType); static @C.Encoding int getEncoding(String mimeType); static int getTrackTypeOfCodec(String codec); static final String BASE_TYPE_VIDEO; static final String BASE_TYPE_AUDIO; static final String BASE_TYPE_TEXT; static final String BASE_TYPE_APPLICATION; static final String VIDEO_MP4; static final String VIDEO_WEBM; static final String VIDEO_H263; static final String VIDEO_H264; static final String VIDEO_H265; static final String VIDEO_VP8; static final String VIDEO_VP9; static final String VIDEO_AV1; static final String VIDEO_MP4V; static final String VIDEO_MPEG; static final String VIDEO_MPEG2; static final String VIDEO_VC1; static final String VIDEO_DIVX; static final String VIDEO_DOLBY_VISION; static final String VIDEO_UNKNOWN; static final String AUDIO_MP4; static final String AUDIO_AAC; static final String AUDIO_WEBM; static final String AUDIO_MPEG; static final String AUDIO_MPEG_L1; static final String AUDIO_MPEG_L2; static final String AUDIO_RAW; static final String AUDIO_ALAW; static final String AUDIO_MLAW; static final String AUDIO_AC3; static final String AUDIO_E_AC3; static final String AUDIO_E_AC3_JOC; static final String AUDIO_AC4; static final String AUDIO_CUSTOM_EC3; static final String AUDIO_TRUEHD; static final String AUDIO_DTS; static final String AUDIO_DTS_HD; static final String AUDIO_DTS_EXPRESS; static final String AUDIO_VORBIS; static final String AUDIO_OPUS; static final String AUDIO_AMR_NB; static final String AUDIO_AMR_WB; static final String AUDIO_FLAC; static final String AUDIO_ALAC; static final String AUDIO_MSGSM; static final String AUDIO_UNKNOWN; static final String TEXT_VTT; static final String TEXT_SSA; static final String APPLICATION_MP4; static final String APPLICATION_WEBM; static final String APPLICATION_MPD; static final String APPLICATION_M3U8; static final String APPLICATION_SS; static final String APPLICATION_ID3; static final String APPLICATION_CEA608; static final String APPLICATION_CEA708; static final String APPLICATION_SUBRIP; static final String APPLICATION_TTML; static final String APPLICATION_TX3G; static final String APPLICATION_MP4VTT; static final String APPLICATION_MP4CEA608; static final String APPLICATION_RAWCC; static final String APPLICATION_VOBSUB; static final String APPLICATION_PGS; static final String APPLICATION_SCTE35; static final String APPLICATION_CAMERA_MOTION; static final String APPLICATION_EMSG; static final String APPLICATION_DVBSUBS; static final String APPLICATION_EXIF; static final String APPLICATION_ICY; }
@Test public void testGetMediaMimeType_fromValidCodecs_returnsCorrectMimeType() { assertThat(MimeTypes.getMediaMimeType("avc1")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("avc1.42E01E")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("avc1.42E01F")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("avc1.4D401F")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("avc1.4D4028")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("avc1.640028")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("avc1.640029")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("avc3")).isEqualTo(MimeTypes.VIDEO_H264); assertThat(MimeTypes.getMediaMimeType("hev1")).isEqualTo(MimeTypes.VIDEO_H265); assertThat(MimeTypes.getMediaMimeType("hvc1")).isEqualTo(MimeTypes.VIDEO_H265); assertThat(MimeTypes.getMediaMimeType("vp08")).isEqualTo(MimeTypes.VIDEO_VP8); assertThat(MimeTypes.getMediaMimeType("vp8")).isEqualTo(MimeTypes.VIDEO_VP8); assertThat(MimeTypes.getMediaMimeType("vp09")).isEqualTo(MimeTypes.VIDEO_VP9); assertThat(MimeTypes.getMediaMimeType("vp9")).isEqualTo(MimeTypes.VIDEO_VP9); assertThat(MimeTypes.getMediaMimeType("ac-3")).isEqualTo(MimeTypes.AUDIO_AC3); assertThat(MimeTypes.getMediaMimeType("dac3")).isEqualTo(MimeTypes.AUDIO_AC3); assertThat(MimeTypes.getMediaMimeType("dec3")).isEqualTo(MimeTypes.AUDIO_E_AC3); assertThat(MimeTypes.getMediaMimeType("ec-3")).isEqualTo(MimeTypes.AUDIO_E_AC3); assertThat(MimeTypes.getMediaMimeType("ec+3")).isEqualTo(MimeTypes.AUDIO_E_AC3_JOC); assertThat(MimeTypes.getMediaMimeType("dtsc")).isEqualTo(MimeTypes.AUDIO_DTS); assertThat(MimeTypes.getMediaMimeType("dtse")).isEqualTo(MimeTypes.AUDIO_DTS); assertThat(MimeTypes.getMediaMimeType("dtsh")).isEqualTo(MimeTypes.AUDIO_DTS_HD); assertThat(MimeTypes.getMediaMimeType("dtsl")).isEqualTo(MimeTypes.AUDIO_DTS_HD); assertThat(MimeTypes.getMediaMimeType("opus")).isEqualTo(MimeTypes.AUDIO_OPUS); assertThat(MimeTypes.getMediaMimeType("vorbis")).isEqualTo(MimeTypes.AUDIO_VORBIS); assertThat(MimeTypes.getMediaMimeType("mp4a")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.40.02")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.40.05")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.40.2")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.40.5")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.40.29")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.66")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.67")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.68")).isEqualTo(MimeTypes.AUDIO_AAC); assertThat(MimeTypes.getMediaMimeType("mp4a.69")).isEqualTo(MimeTypes.AUDIO_MPEG); assertThat(MimeTypes.getMediaMimeType("mp4a.6B")).isEqualTo(MimeTypes.AUDIO_MPEG); assertThat(MimeTypes.getMediaMimeType("mp4a.a5")).isEqualTo(MimeTypes.AUDIO_AC3); assertThat(MimeTypes.getMediaMimeType("mp4a.A5")).isEqualTo(MimeTypes.AUDIO_AC3); assertThat(MimeTypes.getMediaMimeType("mp4a.a6")).isEqualTo(MimeTypes.AUDIO_E_AC3); assertThat(MimeTypes.getMediaMimeType("mp4a.A6")).isEqualTo(MimeTypes.AUDIO_E_AC3); assertThat(MimeTypes.getMediaMimeType("mp4a.A9")).isEqualTo(MimeTypes.AUDIO_DTS); assertThat(MimeTypes.getMediaMimeType("mp4a.AC")).isEqualTo(MimeTypes.AUDIO_DTS); assertThat(MimeTypes.getMediaMimeType("mp4a.AA")).isEqualTo(MimeTypes.AUDIO_DTS_HD); assertThat(MimeTypes.getMediaMimeType("mp4a.AB")).isEqualTo(MimeTypes.AUDIO_DTS_HD); assertThat(MimeTypes.getMediaMimeType("mp4a.AD")).isEqualTo(MimeTypes.AUDIO_OPUS); }