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 
20 struct AVFilterGraph;
21 struct AVFilterContext;
22 struct AVStream;
23 struct AVCodecContext;
24 
43 {
44 public:
46  {
47  m_frame = av_frame_alloc();
48  }
50  {
51  av_frame_free(&m_frame);
52  }
53  bool operator !() const
54  {
55  return m_frame == nullptr;
56  }
58  {
59  return m_frame;
60  }
61  AVFrame& operator*() const
62  {
63  return *m_frame;
64  }
65  operator AVFrame*() const
66  {
67  return m_frame;
68  }
69  operator const AVFrame*() const
70  {
71  return m_frame;
72  }
73 
74 private:
75  AVFrame *m_frame {nullptr};
76 };
77 
86 {
87  public:
88  MythCodecMap() = default;
89  ~MythCodecMap();
90  AVCodecContext *getCodecContext(const AVStream *stream,
91  const AVCodec *pCodec = nullptr, bool nullCodec = false);
92  AVCodecContext *hasCodecContext(const AVStream *stream);
93  void freeCodecContext(const AVStream *stream);
94  void freeAllCodecContexts();
95  protected:
96  QMap<const AVStream*, AVCodecContext*> m_streamMap;
97  QMutex m_mapLock {QMutex::Recursive};
98 };
99 
100 class MythAVCopyPrivate;
101 
107 {
108 public:
109  explicit MythAVCopy(bool USWC=true);
110  virtual ~MythAVCopy();
111  MythAVCopy(const MythAVCopy &) = delete; // not copyable
112  MythAVCopy &operator=(const MythAVCopy &) = delete; // not copyable
113 
114  int Copy(VideoFrame *dst, const VideoFrame *src);
123  int Copy(AVFrame *pic, const VideoFrame *frame,
124  unsigned char *buffer = nullptr,
125  AVPixelFormat fmt = AV_PIX_FMT_YUV420P);
131  int Copy(VideoFrame *frame, const AVFrame *pic,
132  AVPixelFormat fmt = AV_PIX_FMT_YUV420P);
133  int Copy(AVFrame *dst, AVPixelFormat dst_pix_fmt,
134  const AVFrame *src, AVPixelFormat pix_fmt,
135  int width, int height);
136 
137 private:
138  static void FillFrame(VideoFrame *frame, const AVFrame *pic, int pitch,
139  int width, int height, AVPixelFormat pix_fmt);
140  MythAVCopyPrivate *d {nullptr}; // NOLINT(readability-identifier-naming)
141 };
142 
147 int MTV_PUBLIC AVPictureFill(AVFrame *pic, const VideoFrame *frame,
148  AVPixelFormat fmt = AV_PIX_FMT_NONE);
149 
156 
159 MTV_PUBLIC QString DeinterlacerName(MythDeintType Deint, bool DoubleRate, VideoFrameType Format = FMT_NONE);
160 
162 
169 {
170 public:
171  MythPictureDeinterlacer(AVPixelFormat pixfmt, int width, int height, float ar = 1.0F);
173  // Will deinterlace src into dst. If EAGAIN is returned, more frames
174  // are needed to output a frame.
175  // To drain the deinterlacer, call Deinterlace with src = nullptr until you
176  // get no more frames. Once drained, you must call Flush() to start
177  // deinterlacing again.
178  int Deinterlace(AVFrame *dst, const AVFrame *src);
179  int DeinterlaceSingle(AVFrame *dst, const AVFrame *src);
180  // Flush and reset the deinterlacer.
181  int Flush();
182 private:
183  AVFilterGraph* m_filterGraph {nullptr};
185  AVFilterContext* m_bufferSinkCtx {nullptr};
186  AVFilterContext* m_bufferSrcCtx {nullptr};
187  AVPixelFormat m_pixfmt {AV_PIX_FMT_NONE};
188  int m_width {0};
189  int m_height {0};
190  float m_ar;
191  bool m_errored {false};
192 };
193 #endif
MythAVFrame m_filterFrame
Definition: mythavutil.h:184
MTV_PUBLIC AVPixelFormat FrameTypeToPixelFormat(VideoFrameType type)
Convert VideoFrameType into FFmpeg's PixelFormat equivalent and vice-versa.
Definition: mythavutil.cpp:24
MTV_PUBLIC QString DeinterlacerName(MythDeintType Deint, bool DoubleRate, VideoFrameType Format=FMT_NONE)
Return a user friendly description of the given deinterlacer.
Definition: mythavutil.cpp:114
AVFrame * operator->() const
Definition: mythavutil.h:57
bool operator!() const
Definition: mythavutil.h:53
AVFrame * m_frame
Definition: mythavutil.h:75
MTV_PUBLIC QString DeinterlacerPref(MythDeintType Deint)
Definition: mythavutil.cpp:182
MythAVCopy Copy AVFrame<->frame, performing the required conversion if any.
Definition: mythavutil.h:106
struct AVFrame AVFrame
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:196
VideoFrameType
Definition: mythframe.h:23
QMap< const AVStream *, AVCodecContext * > m_streamMap
Definition: mythavutil.h:96
MythDeintType
Definition: mythframe.h:120
MTV_PUBLIC VideoFrameType PixelFormatToFrameType(AVPixelFormat fmt)
Definition: mythavutil.cpp:68
#define MTV_PUBLIC
Definition: mythtvexp.h:15
static const uint16_t * d
MythAVFrame(void)
Definition: mythavutil.h:45
MythPictureDeinterlacer simple deinterlacer based on FFmpeg's yadif filter.
Definition: mythavutil.h:168
AVFrame & operator*() const
Definition: mythavutil.h:61
~MythAVFrame(void)
Definition: mythavutil.h:49
MythCodecMap Utility class that keeps pointers to an AVStream and its AVCodecContext.
Definition: mythavutil.h:85
MythAVFrame little utility class that act as a safe way to allocate an AVFrame which can then be allo...
Definition: mythavutil.h:42