AVPKit
Codec.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #ifndef CODEC_H_
21 #define CODEC_H_
22 
23 #include <com/avpkit/core/ICodec.h>
24 #include <com/avpkit/core/IContainerFormat.h>
25 #include <com/avpkit/core/FfmpegIncludes.h>
26 
27 #include "PixelFormat.h"
28 
29 namespace com { namespace avpkit { namespace core
30 {
31 
32  class Codec : public ICodec
33  {
34  VS_JNIUTILS_REFCOUNTED_OBJECT_PRIVATE_MAKE(Codec)
35  public:
36  static Codec * make(const AVCodec *);
37  virtual const char * getName();
38  virtual int getIDAsInt();
39  virtual Type getType();
40  virtual ID getID()
41  {
42  // Warning; this might not be protable
43  ID retval = AV_CODEC_ID_NONE;
44  int id = getIDAsInt();
45 
46  // This cast is not defined in C++ when id is
47  // not in ID. That means if we're using a
48  // newer version of LIBAVCODEC this might
49  // give a bogus value for a Codec we don't
50  // know about.
51  retval = (ID)id;
52  if (id != (int) retval)
53  {
54  // we assume some back and forth conversion failed...
55  retval = AV_CODEC_ID_NONE;
56  }
57  return retval;
58  }
59 
60  // For calling from with C++, not Java.
61  const AVCodec * getAVCodec() { return mCodec; }
62 
63  static Codec *findEncodingCodec(const ICodec::ID, const IPixelFormat::Type=IPixelFormat::NONE);
64  static Codec *findEncodingCodecByIntID(const int);
65  static Codec *findEncodingCodecByName(const char*);
66 
67  static Codec *findDecodingCodec(const ICodec::ID, const IPixelFormat::Type=IPixelFormat::NONE);
68  static Codec *findDecodingCodecByIntID(const int);
69  static Codec *findDecodingCodecByName(const char*);
70 
71  static Codec *guessEncodingCodec(IContainerFormat* fmt,
72  const char *shortName, const char*url, const char*mime_type,
73  ICodec::Type type);
74 
75  virtual bool canDecode();
76  virtual bool canEncode();
77  virtual const char * getLongName();
78 
79  virtual int32_t getCapabilities();
80  virtual bool hasCapability(Capabilities flag);
81 
82  virtual int32_t getNumSupportedVideoFrameRates();
83  virtual IRational* getSupportedVideoFrameRate(int32_t index);
84 
85  virtual int32_t getNumSupportedVideoPixelFormats();
86  virtual IPixelFormat::Type getSupportedVideoPixelFormat(int32_t index);
87 
88  virtual int32_t getNumSupportedAudioSampleRates();
89  virtual int32_t getSupportedAudioSampleRate(int32_t index);
90 
91  virtual int32_t getNumSupportedAudioSampleFormats();
93 
94  virtual int32_t getNumSupportedAudioChannelLayouts();
95  virtual int64_t getSupportedAudioChannelLayout(int32_t index);
96 
97 
98 
99  virtual int32_t acquire();
100  virtual int32_t release();
101  public:
102  Codec();
103  virtual ~Codec();
104 
105  const AVCodec *mCodec;
106  };
107 
108 }}}
109 
110 #endif /*CODEC_H_*/
virtual bool hasCapability(Capabilities flag)
Convenience method to check individual capability flags.
Definition: Codec.cpp:265
virtual bool canEncode()
Can this codec be used for encoding?
Definition: Codec.cpp:188
virtual int32_t getNumSupportedAudioChannelLayouts()
Get the number of different audio channel layouts this codec supports for encoding.
Definition: Codec.cpp:385
virtual int32_t getNumSupportedVideoPixelFormats()
Get the number of supported video pixel formats this codec supports for encoding.
Definition: Codec.cpp:303
virtual IPixelFormat::Type getSupportedVideoPixelFormat(int32_t index)
Return the supported video pixel format at the given index.
Definition: Codec.cpp:317
virtual int32_t release()
Internal Only.
Definition: Codec.cpp:244
virtual IRational * getSupportedVideoFrameRate(int32_t index)
Return the supported frame rate at the given index.
Definition: Codec.cpp:287
virtual int64_t getSupportedAudioChannelLayout(int32_t index)
Get the supported audio channel layout at this index.
Definition: Codec.cpp:397
virtual int32_t getNumSupportedAudioSampleFormats()
Get the number of different audio sample formats this codec supports for encoding.
Definition: Codec.cpp:357
virtual int32_t acquire()
Internal Only.
Definition: Codec.cpp:236
virtual IAudioSamples::Format getSupportedAudioSampleFormat(int32_t index)
Get the supported sample format at this index.
Definition: Codec.cpp:370
virtual ID getID()
Get the ID of this codec as an enumeration.
Definition: Codec.h:40
virtual int32_t getCapabilities()
Get the capabilites flag from the codec.
Definition: Codec.cpp:258
virtual const char * getLongName()
Added for 1.17.
Definition: Codec.cpp:252
virtual int32_t getNumSupportedVideoFrameRates()
Get the number of frame rates this codec supports for encoding.
Definition: Codec.cpp:273
virtual const char * getName()
Get the name of the codec.
Definition: Codec.cpp:45
virtual int32_t getNumSupportedAudioSampleRates()
Get the number of different audio sample rates this codec supports for encoding.
Definition: Codec.cpp:331
virtual int32_t getSupportedAudioSampleRate(int32_t index)
Return the support audio sample rate at the given index.
Definition: Codec.cpp:343
virtual bool canDecode()
Can this codec be used for decoding?
Definition: Codec.cpp:182
virtual Type getType()
Get the type of this codec.
Definition: Codec.cpp:62
virtual int getIDAsInt()
Get the ID of this codec, as an integer.
Definition: Codec.cpp:53
Format
The format we use to represent audio.
Definition: IAudioSamples.h:46
A "key" to an IStreamCoder that tells it how to encode or decode data.
Definition: ICodec.h:53
Capabilities
Capability flags.
Definition: ICodec.h:729
ID
These are the codecs this library currently supports.
Definition: ICodec.h:61
Type
The different types of Codecs that can exist in the system.
Definition: ICodec.h:582
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...