JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
CodecID.java
Go to the documentation of this file.
1/**
2 * Copyright 2024 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.util.av;
29
30/**
31 * FFmpeg/libAV analog {@code AVCodecID}.
32 * <p>
33 * Use {@link CodecID#fromFFmpeg(int)} to convert from FFmpeg's {@code AVCodecID}
34 * and {@link CodecID#toFFmpeg(CodecID) vice versa.
35 * </p>
36 */
37public enum CodecID {
39
40 //
41 // Video Codecs
42 //
43
45 MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
179 /** Also IFF_BYTERUN1 */
217 /** Also H265 */
241 /** Also H266 {@value} */
243
244 Y41P, // = 0x8000,
313
314 //
315 // Various PCM "codecs"
316 //
317
318 PCM_S16LE, // = 0x10000,
355
356 //
357 // Various ADPCM codecs
358 //
359
360 ADPCM_IMA_QT, // = 0x11000,
412
413 /* AMR */
414 AMR_NB, // = 0x12000,
416
417 /* RealAudio codecs*/
418 RA_144, // = 0x13000,
420
421 //
422 // Various DPCM codecs
423 //
424
425 ROQ_DPCM, // = 0x14000,
434
435 //
436 // Audio Codecs
437 //
438
439 MP2, // = 0x15000,
440 MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
457 GSM, ///< as in Berlin toast format
469 GSM_MS, /* as found in WAV */
542
543 //
544 // Subtitle Codecs
545 //
546 DVD_SUB, // = 0x17000,
548 TEXT, ///< raw UTF-8 text
572
573 COUNT ///< number of codec IDs in this list
575
576 /**
577 * Converts given FFmpeg {@code AVCodecID} to {@link CodecID} or {@code CodecID#NONE} if not matched.
578 */
579 public static CodecID fromFFmpeg(final int ffmpegID) {
580 final int ordinal;
581 if( ffmpegID >= 0x17000 ) {
582 ordinal = ffmpegID - 0x17000 + DVD_SUB.ordinal();
583 } else if( ffmpegID >= 0x15000 ) {
584 ordinal = ffmpegID - 0x15000 + MP2.ordinal();
585 } else if( ffmpegID >= 0x14000 ) {
586 ordinal = ffmpegID - 0x14000 + ROQ_DPCM.ordinal();
587 } else if( ffmpegID >= 0x13000 ) {
588 ordinal = ffmpegID - 0x13000 + RA_144.ordinal();
589 } else if( ffmpegID >= 0x12000 ) {
590 ordinal = ffmpegID - 0x12000 + AMR_NB.ordinal();
591 } else if( ffmpegID >= 0x11000 ) {
592 ordinal = ffmpegID - 0x11000 + ADPCM_IMA_QT.ordinal();
593 } else if( ffmpegID >= 0x10000 ) {
594 ordinal = ffmpegID - 0x10000 + PCM_S16LE.ordinal();
595 } else if( ffmpegID >= 0x8000 ) {
596 ordinal = ffmpegID - 0x8000 + Y41P.ordinal();
597 } else {
598 ordinal = ffmpegID;
599 }
600
601 /**
602 Y41P, // = 0x8000,
603 PCM_S16LE = 0x10000,
604 ADPCM_IMA_QT = 0x11000,
605 AMR_NB = 0x12000,
606 RA_144 = 0x13000,
607 ROQ_DPCM = 0x14000,
608 MP2 = 0x15000,
609 DVD_SUBTITLE = 0x17000,
610 */
611
612 final CodecID[] all = CodecID.values();
613 if( 0 <= ordinal && ordinal < all.length ) {
614 return all[ordinal];
615 }
616 return CodecID.NONE;
617 }
618
619 /** Converts given {@link CodecID} value into FFmpeg {@code AVCodecID} */
620 public static int toFFmpeg(final CodecID id) {
621 final int ordinal = id.ordinal();
622 final int ffmpegID;
623 if( ordinal >= DVD_SUB.ordinal() ) {
624 ffmpegID = ordinal - DVD_SUB.ordinal() + 0x17000;
625 } else if( ordinal >= MP2.ordinal() ) {
626 ffmpegID = ordinal - MP2.ordinal() + 0x15000;
627 } else if( ordinal >= ROQ_DPCM.ordinal() ) {
628 ffmpegID = ordinal - ROQ_DPCM.ordinal() + 0x14000;
629 } else if( ordinal >= RA_144.ordinal() ) {
630 ffmpegID = ordinal - RA_144.ordinal() + 0x13000;
631 } else if( ordinal >= AMR_NB.ordinal() ) {
632 ffmpegID = ordinal - AMR_NB.ordinal() + 0x12000;
633 } else if( ordinal >= ADPCM_IMA_QT.ordinal() ) {
634 ffmpegID = ordinal - ADPCM_IMA_QT.ordinal() + 0x11000;
635 } else if( ordinal >= PCM_S16LE.ordinal() ) {
636 ffmpegID = ordinal - PCM_S16LE.ordinal() + 0x10000;
637 } else if( ordinal >= Y41P.ordinal() ) {
638 ffmpegID = ordinal - Y41P.ordinal() + 0x8000;
639 } else {
640 ffmpegID = ordinal;
641 }
642 return ffmpegID;
643 }
644
645 /** Returns {@code true} if given {@link CodecID} refers to a video codec */
646 public static boolean isVideoCodec(final CodecID id) {
647 return MPEG1VIDEO.ordinal() <= id.ordinal() && id.ordinal() < PCM_S16LE.ordinal();
648 }
649 /** Returns {@code true} if given {@link CodecID} refers to an audio PCM codec */
650 public static boolean isAudioPCMCodec(final CodecID id) {
651 return PCM_S16LE.ordinal() <= id.ordinal() && id.ordinal() < MP2.ordinal();
652 }
653 /**
654 * Returns {@code true} if given {@link CodecID} refers to an audio codec.
655 * @param id the {@link CodecID}
656 * @param includePCM pass {@code true} to include {@link #isAudioPCMCodec(CodecID)}
657 */
658 public static boolean isAudioCodec(final CodecID id, final boolean includePCM) {
659 return includePCM && PCM_S16LE.ordinal() <= id.ordinal() && id.ordinal() < DVD_SUB.ordinal() ||
660 MP2.ordinal() <= id.ordinal() && id.ordinal() < DVD_SUB.ordinal();
661 }
662 /** Returns {@code true} if given {@link CodecID} refers to a subtitle codec */
663 public static boolean isSubtitleCodec(final CodecID id) {
664 return DVD_SUB.ordinal() <= id.ordinal() && id.ordinal() < COUNT.ordinal();
665 }
666}
667
FFmpeg/libAV analog AVCodecID.
Definition: CodecID.java:37
static boolean isAudioPCMCodec(final CodecID id)
Returns true if given CodecID refers to an audio PCM codec.
Definition: CodecID.java:650
MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: CodecID.java:440
GSM
as in Berlin toast format
Definition: CodecID.java:457
static int toFFmpeg(final CodecID id)
Converts given CodecID value into FFmpeg AVCodecID
Definition: CodecID.java:620
static CodecID fromFFmpeg(final int ffmpegID)
Converts given FFmpeg AVCodecID to CodecID or CodecID#NONE if not matched.
Definition: CodecID.java:579
MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: CodecID.java:45
static boolean isSubtitleCodec(final CodecID id)
Returns true if given CodecID refers to a subtitle codec.
Definition: CodecID.java:663
static boolean isVideoCodec(final CodecID id)
Returns true if given CodecID refers to a video codec.
Definition: CodecID.java:646
static boolean isAudioCodec(final CodecID id, final boolean includePCM)
Returns true if given CodecID refers to an audio codec.
Definition: CodecID.java:658