avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
format.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 
6 #include "ffmpeg.h"
7 
8 #if AVCPP_HAS_AVFORMAT
9 
10 extern "C" {
11 #include "libavformat/avformat.h"
12 }
13 
14 namespace av {
15 
16 // AVFormat 59 will introduce `const` for all muxer/demuxer description operations
17 template<typename T>
18 using avcpp_format_const = typename std::conditional<
19  std::is_const<
20  typename std::remove_pointer<
21  decltype(AVFormatContext::iformat)
22  >::type
23  >::value, const T, T>::type;
24 
25 using FmtCodec = class Codec;
26 namespace internal {
27 bool codec_supported(const AVCodecTag *const *codecTag, const FmtCodec &codec);
28 bool codec_supported(const AVCodecTag *const *codecTag, AVCodecID codec_id);
29 } // ::internal
30 
31 template<typename T>
32 struct Format : public FFWrapperPtr<T>
33 {
35 
36  const char* name() const noexcept {
37  return RAW_GET(name, nullptr);
38  }
39 
40  const char* longName() const noexcept {
41  return RAW_GET(long_name, nullptr);
42  }
43 
44  int32_t flags() const noexcept {
45  return RAW_GET(flags, 0);
46  }
47 
48  bool isFlags(int32_t flags) const noexcept {
49  if (m_raw) {
50  return (m_raw->flags & flags);
51  }
52  return false;
53  }
54 
55  void setFormat(T* format) noexcept {
56  FFWrapperPtr<T>::reset(format);
57  }
58 
59  bool codecSupported(const class Codec &codec) const noexcept
60  {
61  if (!m_raw)
62  return false;
63  return internal::codec_supported(m_raw->codec_tag, codec);
64  }
65 
66  bool codecSupported(AVCodecID codec_id) const noexcept
67  {
68  if (!m_raw)
69  return false;
70  return internal::codec_supported(m_raw->codec_tag, codec_id);
71  }
72 
73 protected:
75 };
76 
77 class InputFormat : public Format<avcpp_format_const<AVInputFormat>>
78 {
79 public:
80  using Format<avcpp_format_const<AVInputFormat>>::Format;
81  using Format<avcpp_format_const<AVInputFormat>>::setFormat;
82 
83  InputFormat() = default;
84 
85  InputFormat(const std::string& name) noexcept;
86 
87  bool setFormat(const std::string& name) noexcept;
88 
89 };
90 
91 
92 class OutputFormat : public Format<avcpp_format_const<AVOutputFormat>>
93 {
94 public:
95  using Format<avcpp_format_const<AVOutputFormat>>::Format;
96  using Format<avcpp_format_const<AVOutputFormat>>::setFormat;
97 
98  OutputFormat() = default;
99 
100  OutputFormat(const std::string& name,
101  const std::string& url = std::string(),
102  const std::string& mime = std::string()) noexcept;
103 
104  bool setFormat(const std::string& name,
105  const std::string& url = std::string(),
106  const std::string& mime = std::string()) noexcept;
107 
108  AVCodecID defaultVideoCodecId() const noexcept;
109  AVCodecID defaultAudioCodecId() const noexcept;
110 };
111 
112 
113 OutputFormat guessOutputFormat(const std::string& name,
114  const std::string& url = std::string(),
115  const std::string& mime = std::string());
116 
117 } // namespace av
118 
119 #endif // if AVCPP_HAS_AVFORMAT
#define RAW_GET(field, def)
Definition: ffmpeg.h:47
Definition: audioresampler.cpp:8
Definition: averror.h:228
Definition: ffmpeg.h:22
void reset(T *raw=nullptr)
Definition: ffmpeg.h:29