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