AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ICodec.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_CODEC_ICODEC_HPP_
2 #define _AV_TRANSCODER_CODEC_ICODEC_HPP_
3 
6 
7 extern "C" {
8 #include <libavcodec/avcodec.h>
9 }
10 
11 #include <string>
12 
13 namespace avtranscoder
14 {
15 
16 /**
17  * @brief Define if a codec is for encoding or decoding.
18  */
20 {
23 };
24 
25 class AvExport ICodec
26 {
27 private:
28  ICodec(const ICodec& iCodec);
29  ICodec& operator=(const ICodec& iCodec);
30 
31 public:
32  ICodec(const ECodecType type, const std::string& codecName);
33  ICodec(const ECodecType type, const AVCodecID codecId);
34  ICodec(const ECodecType type, AVCodecContext& avCodecContext);
35 
36  virtual ~ICodec() = 0;
37 
38  /// Initialize the codec context.
39  void openCodec();
40 
41  std::string getCodecName() const;
42  AVCodecID getCodecId() const;
43  ECodecType getCodecType() const { return _type; }
44  int getLatency() const;
45 
46  OptionArray getOptions(); ///< Get options as array
47 #ifndef SWIG
48  OptionMap& getOptionsMap() { return _options; } ///< Get options as map
49 #endif
50  Option& getOption(const std::string& optionName) { return _options.at(optionName); }
51 
52 #ifndef SWIG
53  AVCodecContext& getAVCodecContext() { return *_avCodecContext; }
54  const AVCodecContext& getAVCodecContext() const { return *_avCodecContext; }
55  AVCodec& getAVCodec() { return *_avCodec; }
56  const AVCodec& getAVCodec() const { return *_avCodec; }
57 #endif
58 
59 private:
60  void setCodec(const ECodecType type, const std::string& codecName);
61  void setCodec(const ECodecType type, const AVCodecID codecId);
62  void allocateContext();
63  void loadCodecOptions();
64 
65 protected:
66  AVCodecContext* _avCodecContext; ///< Full codec instance description (has ownership)
67  AVCodec* _avCodec; ///< Codec abstract description
68  const bool _isCodecContextAllocated; ///< Is the AVCodecContext allocated by the class
69 
71 
73 };
74 }
75 
76 #endif
#define AVCodecID
Definition: common.hpp:45
OptionMap _options
Definition: ICodec.hpp:72
std::map< std::string, Option > OptionMap
Key: option name / value: option.
Definition: Option.hpp:119
std::vector< Option > OptionArray
Definition: Option.hpp:118
AVCodecContext * _avCodecContext
Full codec instance description (has ownership)
Definition: ICodec.hpp:66
Option & getOption(const std::string &optionName)
Definition: ICodec.hpp:50
AVCodec * _avCodec
Codec abstract description.
Definition: ICodec.hpp:67
const AVCodec & getAVCodec() const
Definition: ICodec.hpp:56
Wrapper of AVOption. Get its type to know what the option is about: Int, Double, Ratio, Choice... Parse its array of options to get the potential childs (Choice and Group).
Definition: Option.hpp:36
ECodecType
Define if a codec is for encoding or decoding.
Definition: ICodec.hpp:19
ECodecType _type
Definition: ICodec.hpp:70
const bool _isCodecContextAllocated
Is the AVCodecContext allocated by the class.
Definition: ICodec.hpp:68
AVCodecContext & getAVCodecContext()
Definition: ICodec.hpp:53
ECodecType getCodecType() const
Definition: ICodec.hpp:43
OptionMap & getOptionsMap()
Get options as map.
Definition: ICodec.hpp:48
AVCodec & getAVCodec()
Definition: ICodec.hpp:55
const AVCodecContext & getAVCodecContext() const
Definition: ICodec.hpp:54