AVPKit
ICodec.cpp
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 #include "ICodec.h"
21 #include "Global.h"
22 #include "Codec.h"
23 
24 #include "FfmpegIncludes.h"
25 
26 namespace com { namespace avpkit { namespace core
27 {
28 
29  ICodec :: ICodec()
30  {
31  }
32 
33  ICodec :: ~ICodec()
34  {
35  }
36 
37  ICodec *
39  {
40  Global::init();
41  return Codec::findEncodingCodec(id, type);
42  }
43 
44  ICodec *
46  {
47  Global::init();
48  return Codec::findEncodingCodecByIntID(id);
49  }
50 
51  ICodec *
53  {
54  Global::init();
55  return Codec::findEncodingCodecByName(name);
56  }
57 
58  ICodec *
60  {
61  Global::init();
62  return Codec::findDecodingCodec(id, type);
63  }
64 
65  ICodec *
67  {
68  Global::init();
69  return Codec::findDecodingCodecByIntID(id);
70  }
71 
72  ICodec*
74  {
75  Global::init();
76  return Codec::findDecodingCodecByName(name);
77  }
78 
79  ICodec*
81  const char* shortName,
82  const char* url,
83  const char* mimeType,
84  ICodec::Type type)
85  {
86  Global::init();
87  return Codec::guessEncodingCodec(fmt, shortName, url, mimeType, type);
88  }
89 
90  int32_t
92  {
93  Global::init();
94  int32_t numInstalledCodecs = 0;
95  AVCodec * codec = 0;
96  while((codec = av_codec_next(codec))!=0)
97  ++numInstalledCodecs;
98  return numInstalledCodecs;
99  }
100 
101  ICodec*
103  {
104  Global::init();
105  if (index < 0)
106  return 0;
107 
108  AVCodec * codec = 0;
109  for(int32_t i = 0; (codec = av_codec_next(codec))!=0; i++)
110  {
111  if (i == index)
112  return Codec::make(codec);
113  }
114  return 0;
115  }
116 
117 }}}
static void init()
Internal Only.
Definition: Global.cpp:157
A "key" to an IStreamCoder that tells it how to encode or decode data.
Definition: ICodec.h:53
static ICodec * guessEncodingCodec(IContainerFormat *fmt, const char *shortName, const char *url, const char *mimeType, ICodec::Type type)
Ask us to guess an encoding codec based on the inputs passed in.
Definition: ICodec.cpp:80
static ICodec * findEncodingCodec(ICodec::ID id, const IPixelFormat::Type=IPixelFormat::NONE)
Find a codec that can be used for encoding or find a HW codec that can be used for encoding.
Definition: ICodec.cpp:38
static ICodec * findDecodingCodecByName(const char *id)
Find a codec that can be used for decoding.
Definition: ICodec.cpp:73
static ICodec * findEncodingCodecByIntID(int id)
Find a codec that can be used for encoding.
Definition: ICodec.cpp:45
static ICodec * findDecodingCodec(ICodec::ID id, const IPixelFormat::Type=IPixelFormat::NONE)
Find a codec that can be used for decoding or find a HW codec that can be used for decoding.
Definition: ICodec.cpp:59
static ICodec * findDecodingCodecByIntID(int id)
Find a codec that can be used for decoding.
Definition: ICodec.cpp:66
static int32_t getNumInstalledCodecs()
Get the number of installed codecs on this system.
Definition: ICodec.cpp:91
static ICodec * findEncodingCodecByName(const char *id)
Find a codec that can be used for encoding.
Definition: ICodec.cpp:52
ID
These are the codecs this library currently supports.
Definition: ICodec.h:61
static ICodec * getInstalledCodec(int32_t index)
Get the ICodec at the given index.
Definition: ICodec.cpp:102
Type
The different types of Codecs that can exist in the system.
Definition: ICodec.h:582
Specifies format information than can be used to configure an IContainer for input or output.
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...