MythTV  master
mythavutil.h
Go to the documentation of this file.
1 //
2 // mythavutil.h
3 // MythTV
4 //
5 // Created by Jean-Yves Avenard on 7/06/2014.
6 // Copyright (c) 2014 Bubblestuff Pty Ltd. All rights reserved.
7 //
8 
9 #ifndef MythTV_mythavutil_h
10 #define MythTV_mythavutil_h
11 
12 #include "mythframe.h"
13 extern "C" {
14 #include "libavcodec/avcodec.h"
15 }
16 
17 #include <QMap>
18 #include <QMutex>
19 #include <QVector>
20 
21 struct AVFilterGraph;
22 struct AVFilterContext;
23 struct AVStream;
24 struct AVCodecContext;
25 
44 {
45 public:
47  {
48  m_frame = av_frame_alloc();
49  }
51  {
52  av_frame_free(&m_frame);
53  }
54  bool operator !() const
55  {
56  return m_frame == nullptr;
57  }
59  {
60  return m_frame;
61  }
62  AVFrame& operator*() const
63  {
64  return *m_frame;
65  }
66  operator AVFrame*() const
67  {
68  return m_frame;
69  }
70  operator const AVFrame*() const
71  {
72  return m_frame;
73  }
74 
75 private:
76  AVFrame *m_frame {nullptr};
77 };
78 
87 {
88  public:
89  MythCodecMap() = default;
90  ~MythCodecMap();
91  AVCodecContext *getCodecContext(const AVStream *stream,
92  const AVCodec *pCodec = nullptr, bool nullCodec = false);
93  AVCodecContext *hasCodecContext(const AVStream *stream);
94  void freeCodecContext(const AVStream *stream);
95  void freeAllCodecContexts();
96  protected:
97  QMap<const AVStream*, AVCodecContext*> m_streamMap;
98  QMutex m_mapLock {QMutex::Recursive};
99 };
100 
101 class MythAVCopyPrivate;
102 
108 {
109 public:
110  explicit MythAVCopy(bool USWC=true);
111  virtual ~MythAVCopy();
112  MythAVCopy(const MythAVCopy &) = delete; // not copyable
113  MythAVCopy &operator=(const MythAVCopy &) = delete; // not copyable
114 
115  int Copy(VideoFrame *dst, const VideoFrame *src);
124  int Copy(AVFrame *pic, const VideoFrame *frame,
125  unsigned char *buffer = nullptr,
126  AVPixelFormat fmt = AV_PIX_FMT_YUV420P);
132  int Copy(VideoFrame *frame, const AVFrame *pic,
133  AVPixelFormat fmt = AV_PIX_FMT_YUV420P);
134  int Copy(AVFrame *dst, AVPixelFormat dst_pix_fmt,
135  const AVFrame *src, AVPixelFormat pix_fmt,
136  int width, int height);
137 
138 private:
139  static void FillFrame(VideoFrame *frame, const AVFrame *pic, int pitch,
140  int width, int height, AVPixelFormat pix_fmt);
141  MythAVCopyPrivate *d {nullptr}; // NOLINT(readability-identifier-naming)
142 };
143 
148 int MTV_PUBLIC AVPictureFill(AVFrame *pic, const VideoFrame *frame,
149  AVPixelFormat fmt = AV_PIX_FMT_NONE);
150 
157 
160 MTV_PUBLIC QString DeinterlacerName(MythDeintType Deint, bool DoubleRate, VideoFrameType Format = FMT_NONE);
161 
163 
170 {
171 public:
172  MythPictureDeinterlacer(AVPixelFormat pixfmt, int width, int height, float ar = 1.0F);
174  // Will deinterlace src into dst. If EAGAIN is returned, more frames
175  // are needed to output a frame.
176  // To drain the deinterlacer, call Deinterlace with src = nullptr until you
177  // get no more frames. Once drained, you must call Flush() to start
178  // deinterlacing again.
179  int Deinterlace(AVFrame *dst, const AVFrame *src);
180  int DeinterlaceSingle(AVFrame *dst, const AVFrame *src);
181  // Flush and reset the deinterlacer.
182  int Flush();
183 private:
184  AVFilterGraph* m_filterGraph {nullptr};
186  AVFilterContext* m_bufferSinkCtx {nullptr};
187  AVFilterContext* m_bufferSrcCtx {nullptr};
188  AVPixelFormat m_pixfmt {AV_PIX_FMT_NONE};
189  int m_width {0};
190  int m_height {0};
191  float m_ar;
192  bool m_errored {false};
193 };
194 
195 
197 public:
198  // These are for All types
199  char m_codecType {' '}; // V=video, A=audio, S=subtitle
200  QString m_codecName;
201  int64_t m_duration {0};
202  // These are for Video only
203  int m_width {0};
204  int m_height {0};
205  float m_SampleAspectRatio {0.0};
206  // AV_FIELD_TT, //< Top coded_first, top displayed first
207  // AV_FIELD_BB, //< Bottom coded first, bottom displayed first
208  // AV_FIELD_TB, //< Top coded first, bottom displayed first
209  // AV_FIELD_BT, //< Bottom coded first, top displayed first
210  QString m_fieldOrder {"UN"}; // UNknown, PRogressive, TT, BB, TB, BT
211  float m_frameRate {0.0};
212  float m_avgFrameRate {0.0};
213  // This is for audio only
214  int m_channels {0};
215 };
216 
217 
218 /*
219 * Class to get stream info, used by service Video/GetStreamInfo
220 */
222 public:
223  MythStreamInfoList(QString filename);
224  int m_errorCode {0};
225  QString m_errorMsg;
226  QVector<MythStreamInfo> m_streamInfoList;
227 };
228 
229 #endif
MythStreamInfoList::m_errorMsg
QString m_errorMsg
Definition: mythavutil.h:225
MythAVFrame::operator*
AVFrame & operator*() const
Definition: mythavutil.h:62
MythStreamInfo::m_codecName
QString m_codecName
Definition: mythavutil.h:200
MythPictureDeinterlacer::m_ar
float m_ar
Definition: mythavutil.h:191
DeinterlacerPref
MTV_PUBLIC QString DeinterlacerPref(MythDeintType Deint)
Definition: mythavutil.cpp:183
MythPictureDeinterlacer
MythPictureDeinterlacer simple deinterlacer based on FFmpeg's yadif filter.
Definition: mythavutil.h:169
d
static const uint16_t * d
Definition: iso6937tables.cpp:1025
MythAVFrame
MythAVFrame little utility class that act as a safe way to allocate an AVFrame which can then be allo...
Definition: mythavutil.h:43
MythStreamInfo
Definition: mythavutil.h:196
MythStreamInfoList
Definition: mythavutil.h:221
DeinterlacerName
MTV_PUBLIC QString DeinterlacerName(MythDeintType Deint, bool DoubleRate, VideoFrameType Format=FMT_NONE)
Return a user friendly description of the given deinterlacer.
Definition: mythavutil.cpp:115
MythAVFrame::operator->
AVFrame * operator->() const
Definition: mythavutil.h:58
MythDate::Format
Format
Definition: mythdate.h:12
mythframe.h
VideoFrame
Definition: mythframe.h:137
MythAVFrame::operator!
bool operator!() const
Definition: mythavutil.h:54
FMT_NONE
@ FMT_NONE
Definition: mythframe.h:26
AVFrame
struct AVFrame AVFrame
Definition: BorderDetector.h:15
AVPictureFill
int MTV_PUBLIC AVPictureFill(AVFrame *pic, const VideoFrame *frame, AVPixelFormat fmt=AV_PIX_FMT_NONE)
AVPictureFill Initialise AVFrame pic with content from VideoFrame frame.
Definition: mythavutil.cpp:197
MythAVCopyPrivate
Definition: mythavutil.cpp:214
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
MythPictureDeinterlacer::m_filterFrame
MythAVFrame m_filterFrame
Definition: mythavutil.h:185
MythCodecMap
MythCodecMap Utility class that keeps pointers to an AVStream and its AVCodecContext.
Definition: mythavutil.h:86
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
MythAVFrame::~MythAVFrame
~MythAVFrame(void)
Definition: mythavutil.h:50
MythDeintType
MythDeintType
Definition: mythframe.h:121
PixelFormatToFrameType
MTV_PUBLIC VideoFrameType PixelFormatToFrameType(AVPixelFormat fmt)
Definition: mythavutil.cpp:69
MythAVCopy
MythAVCopy Copy AVFrame<->frame, performing the required conversion if any.
Definition: mythavutil.h:107
VideoFrameType
VideoFrameType
Definition: mythframe.h:24
MythAVFrame::MythAVFrame
MythAVFrame(void)
Definition: mythavutil.h:46
MythCodecMap::m_streamMap
QMap< const AVStream *, AVCodecContext * > m_streamMap
Definition: mythavutil.h:97
MythAVFrame::m_frame
AVFrame * m_frame
Definition: mythavutil.h:76
FrameTypeToPixelFormat
MTV_PUBLIC AVPixelFormat FrameTypeToPixelFormat(VideoFrameType type)
Convert VideoFrameType into FFmpeg's PixelFormat equivalent and vice-versa.
Definition: mythavutil.cpp:25
MythStreamInfoList::m_streamInfoList
QVector< MythStreamInfo > m_streamInfoList
Definition: mythavutil.h:226