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 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
31 #include <QRecursiveMutex>
32 #endif
33 #include <QStringList>
34 #include <QAtomicInt>
35 
36 // MythTV
37 #include "libmythtv/mythcodecid.h"
38 #include "libmythtv/mythframe.h"
40 #include "libmythtv/mythtvexp.h"
41 
42 #include "decoderbase.h"
43 
44 extern "C" {
45 #include "libavcodec/avcodec.h"
46 #include "libavformat/avformat.h"
47 }
48 
49 using CreateHWDecoder = int (*)(AVCodecContext *Context);
50 
51 class MythPlayerUI;
52 class MythVideoProfile;
53 
55 {
56  public:
58  {
59  NoProfile = 0,
123  MJPEG
124  };
125 
126  explicit MythCodecContext(DecoderBase *Parent, MythCodecID CodecID);
127  virtual ~MythCodecContext() = default;
128 
129  static MythCodecContext* CreateContext (DecoderBase *Parent, MythCodecID Codec);
130  static void GetDecoders (RenderOptions &Opts, bool Reinit = false);
131  static QStringList GetDecoderDescription(void);
132  static MythCodecID FindDecoder (const QString &Decoder, AVStream *Stream,
133  AVCodecContext **Context, const AVCodec **Codec);
134  static int GetBuffer (struct AVCodecContext *Context, AVFrame *Frame, int Flags);
135  static bool GetBuffer2 (struct AVCodecContext *Context, MythVideoFrame *Frame,
136  AVFrame *AvFrame, int Flags);
137  static int InitialiseDecoder (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
138  static int InitialiseDecoder2 (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
139  static void ReleaseBuffer (void *Opaque, uint8_t *Data);
140  static void FramesContextFinished (AVHWFramesContext *Context);
141  static void DeviceContextFinished (AVHWDeviceContext *Context);
142  static void CreateDecoderCallback (void *Wait, void *Context, void *Callback);
143  static MythPlayerUI* GetPlayerUI (AVCodecContext* Context);
144  static bool FrameTypeIsSupported (AVCodecContext* Context, VideoFrameType Format);
145  static AVBufferRef* CreateDevice (AVHWDeviceType Type, MythInteropGPU* Interop, const QString& Device = QString());
146  static bool IsUnsupportedProfile (AVCodecContext *Context);
147  static QString GetProfileDescription (CodecProfile Profile, QSize Size,
148  VideoFrameType Format = FMT_NONE, uint ColorDepth = 0);
149  static CodecProfile FFmpegToMythProfile(AVCodecID CodecID, int Profile);
150 
151  virtual void InitVideoCodec (AVCodecContext *Context,
152  bool SelectedStream, bool &DirectRendering);
153  virtual int HwDecoderInit (AVCodecContext */*Context*/) { return 0; }
154  virtual bool RetrieveFrame (AVCodecContext */*Context*/, MythVideoFrame */*Frame*/, AVFrame */*AvFrame*/) { return false; }
155  virtual int FilteredReceiveFrame (AVCodecContext *Context, AVFrame *Frame);
156  virtual void SetDeinterlacing (AVCodecContext */*Context*/, MythVideoProfile */*Profile*/, bool /*DoubleRate*/) {}
157  virtual void PostProcessFrame (AVCodecContext */*Context*/, MythVideoFrame */*Frame*/) {}
158  virtual bool IsDeinterlacing (bool &/*DoubleRate*/, bool /*StreamChange*/ = false) { return false; }
159  virtual void SetDecoderOptions (AVCodecContext */*Context*/, const AVCodec */*Codec*/) { }
160  virtual bool DecoderWillResetOnFlush (void) { return false; }
161  virtual bool DecoderWillResetOnAspect(void) { return false; }
162  virtual bool DecoderNeedsReset (AVCodecContext */*Context*/) { return m_resetRequired; }
163 
164  protected:
165  virtual bool RetrieveHWFrame (MythVideoFrame* Frame, AVFrame* AvFrame);
166  static void DestroyInterop (MythInteropGPU* Interop);
167  static void NewHardwareFramesContext(void);
168  static QAtomicInt s_hwFramesContextCount;
169 
170  DecoderBase* m_parent { nullptr };
171  MythCodecID m_codecID { kCodec_NONE };
172  bool m_resetRequired { false };
173 };
174 
175 #endif
MythCodecContext::VP9_3
@ VP9_3
Definition: mythcodeccontext.h:114
MythCodecContext::VC1Simple
@ VC1Simple
Definition: mythcodeccontext.h:105
MythCodecContext::MPEG4Simple
@ MPEG4Simple
Definition: mythcodeccontext.h:69
MythCodecContext::H264Baseline
@ H264Baseline
Definition: mythcodeccontext.h:87
MythCodecContext::MPEG2Simple
@ MPEG2Simple
Definition: mythcodeccontext.h:62
MythCodecContext::VC1Advanced
@ VC1Advanced
Definition: mythcodeccontext.h:108
MythCodecContext::s_hwFramesContextCount
static QAtomicInt s_hwFramesContextCount
Definition: mythcodeccontext.h:168
MythCodecContext::VP9_1
@ VP9_1
Definition: mythcodeccontext.h:112
MythCodecContext::VP9_0
@ VP9_0
Definition: mythcodeccontext.h:111
MythCodecContext::HEVCMain10
@ HEVCMain10
Definition: mythcodeccontext.h:99
kCodec_NONE
@ kCodec_NONE
Definition: mythcodecid.h:14
MythCodecContext::MPEG4AdvancedSimple
@ MPEG4AdvancedSimple
Definition: mythcodeccontext.h:84
MythCodecContext::SetDecoderOptions
virtual void SetDecoderOptions(AVCodecContext *, const AVCodec *)
Definition: mythcodeccontext.h:159
CreateHWDecoder
int(*)(AVCodecContext *Context) CreateHWDecoder
Definition: mythcodeccontext.h:49
MythCodecContext::CodecProfile
CodecProfile
Definition: mythcodeccontext.h:57
mythtvexp.h
Frame
Definition: zmdefines.h:93
MythCodecContext::MPEG4ScaleableTexture
@ MPEG4ScaleableTexture
Definition: mythcodeccontext.h:74
MythCodecContext::HEVCRext
@ HEVCRext
Definition: mythcodeccontext.h:101
MythCodecContext::VC1Main
@ VC1Main
Definition: mythcodeccontext.h:106
MythDate::Format
Format
Definition: mythdate.h:15
MythCodecContext::AV1High
@ AV1High
Definition: mythcodeccontext.h:121
MythCodecContext::DecoderWillResetOnFlush
virtual bool DecoderWillResetOnFlush(void)
Definition: mythcodeccontext.h:160
mythframe.h
MythCodecContext::VP9_3HDRPlus
@ VP9_3HDRPlus
Definition: mythcodeccontext.h:118
MythCodecContext::MPEG4Main
@ MPEG4Main
Definition: mythcodeccontext.h:72
Device
A device containing images (ie. USB stick, CD, storage group etc)
Definition: imagemanager.cpp:35
MythCodecContext::VP9_2
@ VP9_2
Definition: mythcodeccontext.h:113
MythCodecContext::MPEG4AdvancedCore
@ MPEG4AdvancedCore
Definition: mythcodeccontext.h:81
MythCodecContext::HEVCMainStill
@ HEVCMainStill
Definition: mythcodeccontext.h:100
MythCodecContext::DecoderWillResetOnAspect
virtual bool DecoderWillResetOnAspect(void)
Definition: mythcodeccontext.h:161
MythCodecContext::H264Extended
@ H264Extended
Definition: mythcodeccontext.h:93
MythCodecContext::H264ConstrainedBaseline
@ H264ConstrainedBaseline
Definition: mythcodeccontext.h:88
MythCodecContext::VP9_2HDRPlus
@ VP9_2HDRPlus
Definition: mythcodeccontext.h:116
MythCodecContext::VC1Complex
@ VC1Complex
Definition: mythcodeccontext.h:107
MythVideoProfile
Definition: mythvideoprofile.h:87
FMT_NONE
@ FMT_NONE
Definition: mythframe.h:22
MythCodecContext::MPEG4AdvancedCoding
@ MPEG4AdvancedCoding
Definition: mythcodeccontext.h:80
MythCodecID
MythCodecID
Definition: mythcodecid.h:10
AVFrame
struct AVFrame AVFrame
Definition: BorderDetector.h:15
MythCodecContext::MPEG4SimpleScaleable
@ MPEG4SimpleScaleable
Definition: mythcodeccontext.h:70
MythPlayerUI
Definition: mythplayerui.h:10
mythinteropgpu.h
Decoder
Definition: decoder.h:70
MythCodecContext::MPEG2High
@ MPEG2High
Definition: mythcodeccontext.h:65
MythCodecContext::MPEG2422
@ MPEG2422
Definition: mythcodeccontext.h:64
RenderOptions
Definition: mythvideoprofile.h:45
MythCodecContext::MPEG4CoreScaleable
@ MPEG4CoreScaleable
Definition: mythcodeccontext.h:79
MythCodecContext::SetDeinterlacing
virtual void SetDeinterlacing(AVCodecContext *, MythVideoProfile *, bool)
Definition: mythcodeccontext.h:156
MythCodecContext::PostProcessFrame
virtual void PostProcessFrame(AVCodecContext *, MythVideoFrame *)
Definition: mythcodeccontext.h:157
MythCodecContext::H264MainExtended
@ H264MainExtended
Definition: mythcodeccontext.h:90
MythCodecContext::MPEG2SNR
@ MPEG2SNR
Definition: mythcodeccontext.h:67
MythCodecContext::MPEG4AdvancedScaleableTexture
@ MPEG4AdvancedScaleableTexture
Definition: mythcodeccontext.h:82
MythCodecContext::IsDeinterlacing
virtual bool IsDeinterlacing(bool &, bool=false)
Definition: mythcodeccontext.h:158
MythCodecContext::VP9
@ VP9
Definition: mythcodeccontext.h:110
MythCodecContext::H264Main
@ H264Main
Definition: mythcodeccontext.h:89
MythCodecContext::H264High422
@ H264High422
Definition: mythcodeccontext.h:94
MythCodecContext::DecoderNeedsReset
virtual bool DecoderNeedsReset(AVCodecContext *)
Definition: mythcodeccontext.h:162
MythCodecContext::AV1Professional
@ AV1Professional
Definition: mythcodeccontext.h:122
mythcodecid.h
MythCodecContext::MPEG4SimpleStudio
@ MPEG4SimpleStudio
Definition: mythcodeccontext.h:83
MythCodecContext::HEVCMain10HDRPlus
@ HEVCMain10HDRPlus
Definition: mythcodeccontext.h:103
MythCodecContext::MPEG4
@ MPEG4
Definition: mythcodeccontext.h:68
MythCodecContext::MPEG1
@ MPEG1
Definition: mythcodeccontext.h:60
MythCodecContext::HEVC
@ HEVC
Definition: mythcodeccontext.h:97
MythCodecContext::HwDecoderInit
virtual int HwDecoderInit(AVCodecContext *)
Definition: mythcodeccontext.h:153
MythCodecContext::AV1
@ AV1
Definition: mythcodeccontext.h:119
MythCodecContext::H263
@ H263
Definition: mythcodeccontext.h:85
uint
unsigned int uint
Definition: compat.h:81
MythCodecContext::MPEG4SimpleFace
@ MPEG4SimpleFace
Definition: mythcodeccontext.h:75
MythCodecContext::MPEG2Spatial
@ MPEG2Spatial
Definition: mythcodeccontext.h:66
MythCodecContext::MPEG2
@ MPEG2
Definition: mythcodeccontext.h:61
MythCodecContext::VP9_3HDR
@ VP9_3HDR
Definition: mythcodeccontext.h:117
MythCodecContext::H264High444
@ H264High444
Definition: mythcodeccontext.h:95
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
MythCodecContext::HEVCMain10HDR
@ HEVCMain10HDR
Definition: mythcodeccontext.h:102
MythCodecContext::MPEG4NBit
@ MPEG4NBit
Definition: mythcodeccontext.h:73
MythCodecContext::RetrieveFrame
virtual bool RetrieveFrame(AVCodecContext *, MythVideoFrame *, AVFrame *)
Definition: mythcodeccontext.h:154
MythCodecContext::MPEG2Main
@ MPEG2Main
Definition: mythcodeccontext.h:63
MythCodecContext::VC1
@ VC1
Definition: mythcodeccontext.h:104
decoderbase.h
MythCodecContext::MPEG4BasicAnimated
@ MPEG4BasicAnimated
Definition: mythcodeccontext.h:76
MythCodecContext::AV1Main
@ AV1Main
Definition: mythcodeccontext.h:120
MythCodecContext::MPEG4Hybrid
@ MPEG4Hybrid
Definition: mythcodeccontext.h:77
MythCodecContext
Definition: mythcodeccontext.h:54
VideoFrameType
VideoFrameType
Definition: mythframe.h:20
MythCodecContext::H264High
@ H264High
Definition: mythcodeccontext.h:91
MythCodecContext::VP9_2HDR
@ VP9_2HDR
Definition: mythcodeccontext.h:115
MythCodecContext::MPEG4AdvancedRT
@ MPEG4AdvancedRT
Definition: mythcodeccontext.h:78
MythVideoFrame
Definition: mythframe.h:88
MythCodecContext::MPEG4Core
@ MPEG4Core
Definition: mythcodeccontext.h:71
MythCodecContext::H264ConstrainedHigh
@ H264ConstrainedHigh
Definition: mythcodeccontext.h:96
MythCodecContext::HEVCMain
@ HEVCMain
Definition: mythcodeccontext.h:98
DecoderBase
Definition: decoderbase.h:120
MythCodecContext::VP8
@ VP8
Definition: mythcodeccontext.h:109
MythCodecContext::H264High10
@ H264High10
Definition: mythcodeccontext.h:92
MythInteropGPU
Definition: mythinteropgpu.h:20
MythCodecContext::H264
@ H264
Definition: mythcodeccontext.h:86