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:
76 };
77 
89 {
90  public:
91  MythCodecMap();
92  ~MythCodecMap();
93  static MythCodecMap *getInstance();
94  AVCodecContext *getCodecContext(const AVStream*,
95  const AVCodec *pCodec = nullptr, bool nullCodec = false);
96  AVCodecContext *hasCodecContext(const AVStream*);
97  void freeCodecContext(const AVStream*);
98  void freeAllCodecContexts();
99  protected:
100  QMap<const AVStream*, AVCodecContext*> streamMap;
101  QMutex mapLock;
102 };
103 
106 
107 
108 class MythAVCopyPrivate;
109 
115 {
116 public:
117  explicit MythAVCopy(bool USWC=true);
118  virtual ~MythAVCopy();
119 
120  int Copy(VideoFrame *dst, const VideoFrame *src);
129  int Copy(AVFrame *pic, const VideoFrame *frame,
130  unsigned char *buffer = nullptr,
131  AVPixelFormat fmt = AV_PIX_FMT_YUV420P);
137  int Copy(VideoFrame *frame, const AVFrame *pic,
138  AVPixelFormat fmt = AV_PIX_FMT_YUV420P);
139  int Copy(AVFrame *dst, AVPixelFormat dst_pix_fmt,
140  const AVFrame *src, AVPixelFormat pix_fmt,
141  int width, int height);
142 
143 private:
144  void FillFrame(VideoFrame *frame, const AVFrame *pic, int pitch,
145  int width, int height, AVPixelFormat pix_fmt);
146  MythAVCopy(const MythAVCopy &) = delete; // not copyable
147  MythAVCopy &operator=(const MythAVCopy &) = delete; // not copyable
149 };
150 
155 int MTV_PUBLIC AVPictureFill(AVFrame *pic, const VideoFrame *frame,
156  AVPixelFormat fmt = AV_PIX_FMT_NONE);
157 
164 
171 {
172 public:
173  MythPictureDeinterlacer(AVPixelFormat pixfmt, int width, int height, float ar = 1.0F);
175  // Will deinterlace src into dst. If EAGAIN is returned, more frames
176  // are needed to output a frame.
177  // To drain the deinterlacer, call Deinterlace with src = nullptr until you
178  // get no more frames. Once drained, you must call Flush() to start
179  // deinterlacing again.
180  int Deinterlace(AVFrame *dst, const AVFrame *src);
181  int DeinterlaceSingle(AVFrame *dst, const AVFrame *src);
182  // Flush and reset the deinterlacer.
183  int Flush();
184 private:
185  AVFilterGraph* m_filter_graph;
187  AVFilterContext* m_buffersink_ctx;
188  AVFilterContext* m_buffersrc_ctx;
189  AVPixelFormat m_pixfmt;
190  int m_width;
191  int m_height;
192  float m_ar;
193  bool m_errored;
194 };
195 #endif
QMutex mapLock
Definition: mythavutil.h:101
MTV_PUBLIC AVPixelFormat FrameTypeToPixelFormat(VideoFrameType type)
Convert VideoFrameType into FFmpeg's PixelFormat equivalent and vice-versa.
Definition: mythavutil.cpp:25
AVFrame * operator->() const
Definition: mythavutil.h:57
bool operator!() const
Definition: mythavutil.h:53
AVFrame * m_frame
Definition: mythavutil.h:75
struct AVFrame AVFrame
MythAVCopy Copy AVFrame<->frame, performing the required conversion if any.
Definition: mythavutil.h:114
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:65
enum FrameType_ VideoFrameType
MythAVFrame m_filter_frame
Definition: mythavutil.h:186
AVFilterContext * m_buffersrc_ctx
Definition: mythavutil.h:188
MTV_PUBLIC VideoFrameType PixelFormatToFrameType(AVPixelFormat fmt)
Definition: mythavutil.cpp:46
AVFilterContext * m_buffersink_ctx
Definition: mythavutil.h:187
#define MTV_PUBLIC
Definition: mythtvexp.h:15
MTV_PUBLIC MythCodecMap * gCodecMap
This global variable contains the MythCodecMap instance for the app.
Definition: mythavutil.cpp:380
MythAVCopyPrivate * d
Definition: mythavutil.h:148
MythAVFrame(void)
Definition: mythavutil.h:45
AVFilterGraph * m_filter_graph
Definition: mythavutil.h:185
MythPictureDeinterlacer simple deinterlacer based on FFmpeg's yadif filter.
Definition: mythavutil.h:170
AVPixelFormat m_pixfmt
Definition: mythavutil.h:189
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:88
MythAVFrame little utility class that act as a safe way to allocate an AVFrame which can then be allo...
Definition: mythavutil.h:42
QMap< const AVStream *, AVCodecContext * > streamMap
Definition: mythavutil.h:100