MythTV  master
mythcodeccontext.h
Go to the documentation of this file.
1 // Copyright (c) 2017 MythTV Developers <mythtv-dev@mythtv.org>
3 //
4 // This is part of MythTV (https://www.mythtv.org)
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 //
24 
25 
26 #ifndef MYTHCODECONTEXT_H
27 #define MYTHCODECONTEXT_H
28 
29 // Qt
30 #include <QMutex>
31 #include <QStringList>
32 #include <QAtomicInt>
33 
34 // MythTV
35 #include "mythtvexp.h"
36 #include "mythcodecid.h"
37 #include "mythframe.h"
38 #include "decoderbase.h"
39 
40 extern "C" {
41 #include "libavcodec/avcodec.h"
42 #include "libavformat/avformat.h"
43 }
44 
45 using CreateHWDecoder = int (*)(AVCodecContext *Context);
46 
47 class MythOpenGLInterop;
49 
51 {
52  public:
54  {
55  NoProfile = 0,
99  VC1,
117  AV1Professional
118  };
119 
120  explicit MythCodecContext(DecoderBase *Parent, MythCodecID CodecID);
121  virtual ~MythCodecContext() = default;
122 
123  static MythCodecContext* CreateContext (DecoderBase *Parent, MythCodecID Codec);
124  static void GetDecoders (RenderOptions &Opts);
125  static QStringList GetDecoderDescription(void);
126  static MythCodecID FindDecoder (const QString &Decoder, AVStream *Stream,
127  AVCodecContext **Context, AVCodec **Codec);
128  static int GetBuffer (struct AVCodecContext *Context, AVFrame *Frame, int Flags);
129  static bool GetBuffer2 (struct AVCodecContext *Context, VideoFrame *Frame,
130  AVFrame *AvFrame, int Flags);
131  static int InitialiseDecoder (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
132  static int InitialiseDecoder2 (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
133  static void ReleaseBuffer (void *Opaque, uint8_t *Data);
134  static void FramesContextFinished (AVHWFramesContext *Context);
135  static void DeviceContextFinished (AVHWDeviceContext *Context);
136  static void CreateDecoderCallback (void *Wait, void *Context, void *Callback);
137  static AVBufferRef* CreateDevice (AVHWDeviceType Type, MythOpenGLInterop *Interop, const QString &Device = QString());
138  static bool IsUnsupportedProfile (AVCodecContext *Context);
139  static QString GetProfileDescription (CodecProfile Profile, QSize Size);
140  static CodecProfile FFmpegToMythProfile(AVCodecID CodecID, int Profile);
141 
142  virtual void InitVideoCodec (AVCodecContext *Context,
143  bool SelectedStream, bool &DirectRendering);
144  virtual int HwDecoderInit (AVCodecContext */*Context*/) { return 0; }
145  virtual bool RetrieveFrame (AVCodecContext */*Context*/, VideoFrame */*Frame*/, AVFrame */*AvFrame*/) { return false; }
146  virtual int FilteredReceiveFrame (AVCodecContext *Context, AVFrame *Frame);
147  virtual void SetDeinterlacing (AVCodecContext */*Context*/, VideoDisplayProfile */*Profile*/, bool /*DoubleRate*/) {}
148  virtual void PostProcessFrame (AVCodecContext */*Context*/, VideoFrame */*Frame*/) {}
149  virtual bool IsDeinterlacing (bool &/*DoubleRate*/, bool /*StreamChange*/ = false) { return false; }
150  virtual void SetDecoderOptions (AVCodecContext */*Context*/, AVCodec */*Codec*/) { }
151  virtual bool DecoderWillResetOnFlush (void) { return false; }
152  virtual bool DecoderWillResetOnAspect(void) { return false; }
153  virtual bool DecoderNeedsReset (AVCodecContext */*Context*/) { return m_resetRequired; }
154 
155  protected:
156  virtual bool RetrieveHWFrame (VideoFrame* Frame, AVFrame* AvFrame);
157  static void DestroyInterop (MythOpenGLInterop *Interop);
158  static void NewHardwareFramesContext(void);
159  static QAtomicInt s_hwFramesContextCount;
160 
161  DecoderBase* m_parent { nullptr };
162  MythCodecID m_codecID { kCodec_NONE };
163  bool m_resetRequired { false };
164 };
165 
166 #endif // MYTHCODECCONTEXT_H
int(*)(AVCodecContext *Context) CreateHWDecoder
virtual bool DecoderWillResetOnAspect(void)
QHash< QString, Action * > Context
Definition: action.h:77
virtual void PostProcessFrame(AVCodecContext *, VideoFrame *)
virtual bool DecoderNeedsReset(AVCodecContext *)
MythCodecID
Definition: mythcodecid.h:10
virtual void SetDecoderOptions(AVCodecContext *, AVCodec *)
struct AVFrame AVFrame
A device containing images (ie. USB stick, CD, storage group etc)
#define MTV_PUBLIC
Definition: mythtvexp.h:15
virtual bool DecoderWillResetOnFlush(void)
static QAtomicInt s_hwFramesContextCount
virtual int HwDecoderInit(AVCodecContext *)
virtual bool IsDeinterlacing(bool &, bool=false)
virtual bool RetrieveFrame(AVCodecContext *, VideoFrame *, AVFrame *)
virtual void SetDeinterlacing(AVCodecContext *, VideoDisplayProfile *, bool)