MythTV  master
mythnvdeccontext.h
Go to the documentation of this file.
1 #ifndef MYTHNVDECCONTEXT_H
2 #define MYTHNVDECCONTEXT_H
3 
4 // Qt
5 #include <QSize>
6 
7 // MythTV
8 #include "mythframe.h"
9 #include "mythcodecid.h"
10 #include "mythcodeccontext.h"
11 
12 // FFmpeg
13 extern "C" {
14 #include "libavutil/pixfmt.h"
15 #include "libavutil/hwcontext.h"
16 #include "libavcodec/avcodec.h"
17 #include "libavutil/pixdesc.h"
18 #include <ffnvcodec/dynlink_cuda.h>
19 #include <ffnvcodec/dynlink_cuviddec.h>
20 }
21 
22 // Std
23 #include <vector>
24 
26 {
27  public:
28  MythNVDECContext(DecoderBase *Parent, MythCodecID CodecID);
29  ~MythNVDECContext() override;
30  void InitVideoCodec (AVCodecContext *Context, bool SelectedStream, bool &DirectRendering) override;
31  int HwDecoderInit (AVCodecContext *Context) override;
32  bool RetrieveFrame (AVCodecContext *Context, MythVideoFrame *Frame, AVFrame *AvFrame) override;
33  void SetDeinterlacing (AVCodecContext *Context,
34  MythVideoProfile *Profile, bool DoubleRate) override;
35  void PostProcessFrame (AVCodecContext *Context, MythVideoFrame *Frame) override;
36  bool IsDeinterlacing (bool &DoubleRate, bool StreamChange = false) override;
37  bool DecoderWillResetOnFlush (void) override;
38  static MythCodecID GetSupportedCodec (AVCodecContext **CodecContext,
39  const AVCodec **Codec,
40  const QString &Decoder,
41  AVStream *Stream,
42  uint StreamType);
43  static enum AVPixelFormat GetFormat (AVCodecContext *Context, const AVPixelFormat *PixFmt);
44  static bool GetBuffer (AVCodecContext *Context, MythVideoFrame *Frame,
45  AVFrame *AvFrame, int Flags);
46  static int InitialiseDecoder (AVCodecContext *Context);
47  static bool HaveNVDEC (bool Reinit = false);
48  static void GetDecoderList (QStringList &Decoders);
49 
50  private:
52  {
53  public:
54  MythNVDECCaps(cudaVideoCodec Codec, uint Depth, cudaVideoChromaFormat Format,
55  QSize Minimum, QSize Maximum, uint MacroBlocks);
56  bool Supports(cudaVideoCodec Codec, cudaVideoChromaFormat Format, uint Depth,
57  int Width, int Height) const;
58 
61  cudaVideoCodec m_codec { cudaVideoCodec_NumCodecs };
62  uint m_depth { 0 };
63  cudaVideoChromaFormat m_format { cudaVideoChromaFormat_Monochrome };
64  QSize m_minimum;
65  QSize m_maximum;
67  };
68 
69  private:
70  void InitFramesContext(AVCodecContext *Context);
71  AVBufferRef* m_framesContext { nullptr };
72 
73  static const std::vector<MythNVDECCaps>& GetProfiles(void);
75  bool m_deinterlacer2x { false };
76 };
77 
78 #endif // MYTHNVDECCONTEXT_H
MythNVDECContext::m_deinterlacer2x
bool m_deinterlacer2x
Definition: mythnvdeccontext.h:75
MythNVDECContext::MythNVDECCaps::m_depth
uint m_depth
Definition: mythnvdeccontext.h:62
MythNVDECContext::InitialiseDecoder
static int InitialiseDecoder(AVCodecContext *Context)
Definition: mythnvdeccontext.cpp:142
MythNVDECContext::PostProcessFrame
void PostProcessFrame(AVCodecContext *Context, MythVideoFrame *Frame) override
Definition: mythnvdeccontext.cpp:335
MythNVDECContext::MythNVDECCaps::m_minimum
QSize m_minimum
Definition: mythnvdeccontext.h:64
MythNVDECContext::RetrieveFrame
bool RetrieveFrame(AVCodecContext *Context, MythVideoFrame *Frame, AVFrame *AvFrame) override
Definition: mythnvdeccontext.cpp:385
MythNVDECContext::~MythNVDECContext
~MythNVDECContext() override
Definition: mythnvdeccontext.cpp:31
MythCodecID
MythCodecID
Definition: mythcodecid.h:11
Frame
Definition: zmdefines.h:102
MythNVDECContext::GetBuffer
static bool GetBuffer(AVCodecContext *Context, MythVideoFrame *Frame, AVFrame *AvFrame, int Flags)
Convert AVFrame data to MythFrame.
Definition: mythnvdeccontext.cpp:401
MythDate::Format
Format
Definition: mythdate.h:15
MythNVDECContext::GetFormat
static enum AVPixelFormat GetFormat(AVCodecContext *Context, const AVPixelFormat *PixFmt)
Definition: mythnvdeccontext.cpp:365
FMT_NONE
@ FMT_NONE
Definition: mythframe.h:21
mythframe.h
MythNVDECContext::GetDecoderList
static void GetDecoderList(QStringList &Decoders)
Definition: mythnvdeccontext.cpp:557
MythNVDECContext::MythNVDECCaps::Supports
bool Supports(cudaVideoCodec Codec, cudaVideoChromaFormat Format, uint Depth, int Width, int Height) const
Definition: mythnvdeccontext.cpp:497
MythDeintType
MythDeintType
Definition: mythframe.h:66
MythVideoProfile
Definition: mythvideoprofile.h:83
MythNVDECContext::InitVideoCodec
void InitVideoCodec(AVCodecContext *Context, bool SelectedStream, bool &DirectRendering) override
Definition: mythnvdeccontext.cpp:197
MythNVDECContext::MythNVDECCaps
Definition: mythnvdeccontext.h:51
MythNVDECContext::GetProfiles
static const std::vector< MythNVDECCaps > & GetProfiles(void)
Definition: mythnvdeccontext.cpp:571
MythCodecContext::NoProfile
@ NoProfile
Definition: mythcodeccontext.h:57
AVFrame
struct AVFrame AVFrame
Definition: BorderDetector.h:15
Decoder
Definition: decoder.h:70
MythNVDECContext::m_deinterlacer
MythDeintType m_deinterlacer
Definition: mythnvdeccontext.h:74
MythNVDECContext
Definition: mythnvdeccontext.h:25
MythNVDECContext::MythNVDECCaps::m_format
cudaVideoChromaFormat m_format
Definition: mythnvdeccontext.h:63
VideoFrameType
VideoFrameType
Definition: mythframe.h:19
mythcodecid.h
MythNVDECContext::DecoderWillResetOnFlush
bool DecoderWillResetOnFlush(void) override
Definition: mythnvdeccontext.cpp:349
DEINT_NONE
@ DEINT_NONE
Definition: mythframe.h:68
MythNVDECContext::MythNVDECCaps::m_maximum
QSize m_maximum
Definition: mythnvdeccontext.h:65
MythCodecContext::CodecProfile
CodecProfile
Definition: mythcodeccontext.h:55
MythNVDECContext::SetDeinterlacing
void SetDeinterlacing(AVCodecContext *Context, MythVideoProfile *Profile, bool DoubleRate) override
Enable NVDEC/CUDA deinterlacing if necessary.
Definition: mythnvdeccontext.cpp:235
MythNVDECContext::MythNVDECCaps::m_macroBlocks
uint m_macroBlocks
Definition: mythnvdeccontext.h:66
MythNVDECContext::HaveNVDEC
static bool HaveNVDEC(bool Reinit=false)
Definition: mythnvdeccontext.cpp:520
MythNVDECContext::HwDecoderInit
int HwDecoderInit(AVCodecContext *Context) override
Definition: mythnvdeccontext.cpp:209
MythNVDECContext::InitFramesContext
void InitFramesContext(AVCodecContext *Context)
Definition: mythnvdeccontext.cpp:642
MythNVDECContext::MythNVDECCaps::m_profile
MythCodecContext::CodecProfile m_profile
Definition: mythnvdeccontext.h:59
MythNVDECContext::MythNVDECCaps::m_codec
cudaVideoCodec m_codec
Definition: mythnvdeccontext.h:61
MythNVDECContext::MythNVDECCaps::MythNVDECCaps
MythNVDECCaps(cudaVideoCodec Codec, uint Depth, cudaVideoChromaFormat Format, QSize Minimum, QSize Maximum, uint MacroBlocks)
Definition: mythnvdeccontext.cpp:456
MythNVDECContext::IsDeinterlacing
bool IsDeinterlacing(bool &DoubleRate, bool StreamChange=false) override
Definition: mythnvdeccontext.cpp:354
mythcodeccontext.h
MythCodecContext
Definition: mythcodeccontext.h:52
MythVideoFrame
Definition: mythframe.h:87
MythNVDECContext::m_framesContext
AVBufferRef * m_framesContext
Definition: mythnvdeccontext.h:71
MythNVDECContext::MythNVDECContext
MythNVDECContext(DecoderBase *Parent, MythCodecID CodecID)
Definition: mythnvdeccontext.cpp:26
DecoderBase
Definition: decoderbase.h:121
uint
unsigned int uint
Definition: freesurround.h:24
MythNVDECContext::GetSupportedCodec
static MythCodecID GetSupportedCodec(AVCodecContext **CodecContext, const AVCodec **Codec, const QString &Decoder, AVStream *Stream, uint StreamType)
Determine whether NVDEC decoding is supported for this codec.
Definition: mythnvdeccontext.cpp:41
MythNVDECContext::MythNVDECCaps::m_type
VideoFrameType m_type
Definition: mythnvdeccontext.h:60