MythTV  master
mythavutil.h
Go to the documentation of this file.
1 #ifndef MYTHAVUTIL_H
2 #define MYTHAVUTIL_H
3 
4 // Qt
5 #include <QMap>
6 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
7 #include <QMutex>
8 #else
9 #include <QRecursiveMutex>
10 #endif
11 #include <QVector>
12 
13 // FFmpeg
14 extern "C" {
15 #include "libavcodec/avcodec.h"
16 
17 #include "libavutil/buffer.h"
18 }
19 
20 // MythTV
22 #include "libmythtv/mythframe.h"
23 #include "libmythui/mythhdr.h"
24 
25 struct SwsContext;
26 struct AVStream;
27 struct AVCodecContext;
28 
30 {
31  public:
32  MythCodecMap() = default;
33  ~MythCodecMap();
34  AVCodecContext* GetCodecContext(const AVStream* Stream,
35  const AVCodec* Codec = nullptr,
36  bool NullCodec = false);
37  AVCodecContext* FindCodecContext(const AVStream* Stream);
38  void FreeCodecContext(const AVStream* Stream);
39  void FreeAllContexts();
40 
41  private:
42  QMap<const AVStream*, AVCodecContext*> m_streamMap;
43 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
44  QMutex m_mapLock { QMutex::Recursive };
45 #else
46  QRecursiveMutex m_mapLock;
47 #endif
48 };
49 
51 {
52  public:
53  MythAVCopy() = default;
54  ~MythAVCopy();
55  int Copy(AVFrame* To, const MythVideoFrame* From, unsigned char* Buffer,
56  AVPixelFormat Fmt = AV_PIX_FMT_YUV420P);
57  int Copy(AVFrame* To, AVPixelFormat ToFmt, const AVFrame* From, AVPixelFormat FromFmt,
58  int Width, int Height);
59 
60  private:
61  Q_DISABLE_COPY(MythAVCopy)
62  int SizeData(int Width, int Height, AVPixelFormat Fmt);
63 
64  AVPixelFormat m_format { AV_PIX_FMT_NONE };
65  SwsContext* m_swsctx { nullptr };
66  int m_width { 0 };
67  int m_height { 0 };
68  int m_size { 0 };
69 };
70 
72 {
73  public:
74  static void DeinterlaceAVFrame(AVFrame* Frame);
75  static int FillAVFrame(AVFrame* Frame, const MythVideoFrame* From, AVPixelFormat Fmt = AV_PIX_FMT_NONE);
76  static AVPixelFormat FrameTypeToPixelFormat(VideoFrameType Type);
77  static VideoFrameType PixelFormatToFrameType(AVPixelFormat Fmt);
78  static MythHDR::HDRType FFmpegTransferToHDRType(int Transfer);
79 };
80 
82 public:
83  // These are for All types
84  char m_codecType {' '}; // V=video, A=audio, S=subtitle
85  QString m_codecName;
86  int64_t m_duration {0};
87  // These are for Video only
88  int m_width {0};
89  int m_height {0};
90  float m_SampleAspectRatio {0.0};
91  // AV_FIELD_TT, //< Top coded_first, top displayed first
92  // AV_FIELD_BB, //< Bottom coded first, bottom displayed first
93  // AV_FIELD_TB, //< Top coded first, bottom displayed first
94  // AV_FIELD_BT, //< Bottom coded first, top displayed first
95  QString m_fieldOrder {"UN"}; // UNknown, PRogressive, TT, BB, TB, BT
96  float m_frameRate {0.0};
97  float m_avgFrameRate {0.0};
98  // This is for audio only
99  int m_channels {0};
100 };
101 
102 
103 /*
104 * Class to get stream info, used by service Video/GetStreamInfo
105 */
107 public:
108  explicit MythStreamInfoList(const QString& filename);
109  int m_errorCode {0};
110  QString m_errorMsg;
111  QVector<MythStreamInfo> m_streamInfoList;
112 };
113 
122  public:
126  explicit MythAVBufferRef(AVBufferRef* buf) : m_buffer(av_buffer_ref(buf))
127  {
128  if (!m_buffer)
129  {
130  LOG(VB_GENERAL, LOG_ERR, "av_buffer_ref() failed to allocate memory.");
131  }
132  }
134  {
135  if (has_buffer())
136  {
137  av_buffer_unref(&m_buffer);
138  }
139  }
140 
141  bool has_buffer() { return m_buffer != nullptr; }
142 
143  const uint8_t* data() { return m_buffer->data; }
144  size_t size() { return m_buffer->size; }
145  private:
146  AVBufferRef* m_buffer {nullptr};
147 };
148 
149 
150 #endif
MythStreamInfoList::m_errorMsg
QString m_errorMsg
Definition: mythavutil.h:110
MythStreamInfo::m_codecName
QString m_codecName
Definition: mythavutil.h:85
MythAVBufferRef::has_buffer
bool has_buffer()
Definition: mythavutil.h:141
Frame
Definition: zmdefines.h:93
MythStreamInfo
Definition: mythavutil.h:81
MythStreamInfoList
Definition: mythavutil.h:106
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
mythframe.h
AVFrame
struct AVFrame AVFrame
Definition: BorderDetector.h:15
mythlogging.h
MythAVBufferRef::MythAVBufferRef
MythAVBufferRef(AVBufferRef *buf)
Definition: mythavutil.h:126
MythAVBufferRef
C++ wrapper for AVBufferRef.
Definition: mythavutil.h:121
MythAVBufferRef::~MythAVBufferRef
~MythAVBufferRef()
Definition: mythavutil.h:133
MythAVUtil
Definition: mythavutil.h:71
MythCodecMap
Definition: mythavutil.h:29
mythhdr.h
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
Buffer
Definition: MythExternControl.h:36
MythAVCopy
Definition: mythavutil.h:50
MythAVBufferRef::data
const uint8_t * data()
Definition: mythavutil.h:143
VideoFrameType
VideoFrameType
Definition: mythframe.h:20
MythCodecMap::m_streamMap
QMap< const AVStream *, AVCodecContext * > m_streamMap
Definition: mythavutil.h:42
MythAVBufferRef::size
size_t size()
Definition: mythavutil.h:144
MythVideoFrame
Definition: mythframe.h:88
build_compdb.filename
filename
Definition: build_compdb.py:21
MythHDR::HDRType
HDRType
Definition: mythhdr.h:36
MythCodecMap::m_mapLock
QRecursiveMutex m_mapLock
Definition: mythavutil.h:46
MythStreamInfoList::m_streamInfoList
QVector< MythStreamInfo > m_streamInfoList
Definition: mythavutil.h:111