MythTV master
mythcodeccontext.h
Go to the documentation of this file.
1
2// 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 <QRecursiveMutex>
31#include <QStringList>
32#include <QAtomicInt>
33
34// MythTV
36#include "libmythtv/mythframe.h"
38#include "libmythtv/mythtvexp.h"
39
40#include "decoderbase.h"
41
42extern "C" {
43#include "libavcodec/avcodec.h"
44#include "libavformat/avformat.h"
45}
46
47using CreateHWDecoder = int (*)(AVCodecContext *Context);
48
49class MythPlayerUI;
51
53{
54 public:
55 enum CodecProfile : std::uint8_t
56 {
57 NoProfile = 0,
121 MJPEG
122 };
123
124 explicit MythCodecContext(DecoderBase *Parent, MythCodecID CodecID);
125 virtual ~MythCodecContext() = default;
126
127 static MythCodecContext* CreateContext (DecoderBase *Parent, MythCodecID Codec);
128 static void GetDecoders (RenderOptions &Opts, bool Reinit = false);
129 static QStringList GetDecoderDescription(void);
130 static MythCodecID FindDecoder (const QString &Decoder, AVStream *Stream,
131 AVCodecContext **Context, const AVCodec **Codec);
132 static int GetBuffer (struct AVCodecContext *Context, AVFrame *Frame, int Flags);
133 static bool GetBuffer2 (struct AVCodecContext *Context, MythVideoFrame *Frame,
134 AVFrame *AvFrame, int Flags);
135 static int InitialiseDecoder (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
136 static int InitialiseDecoder2 (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
137 static void ReleaseBuffer (void *Opaque, uint8_t *Data);
138 static void FramesContextFinished (AVHWFramesContext *Context);
139 static void DeviceContextFinished (AVHWDeviceContext *Context);
140 static void CreateDecoderCallback (void *Wait, void *Context, void *Callback);
141 static MythPlayerUI* GetPlayerUI (AVCodecContext* Context);
142 static bool FrameTypeIsSupported (AVCodecContext* Context, VideoFrameType Format);
143 static AVBufferRef* CreateDevice (AVHWDeviceType Type, MythInteropGPU* Interop, const QString& Device = QString());
144 static bool IsUnsupportedProfile (AVCodecContext *Context);
145 static QString GetProfileDescription (CodecProfile Profile, QSize Size,
146 VideoFrameType Format = FMT_NONE, uint ColorDepth = 0);
147 static CodecProfile FFmpegToMythProfile(AVCodecID CodecID, int Profile);
148
149 virtual void InitVideoCodec (AVCodecContext *Context,
150 bool SelectedStream, bool &DirectRendering);
151 virtual int HwDecoderInit (AVCodecContext */*Context*/) { return 0; }
152 virtual bool RetrieveFrame (AVCodecContext */*Context*/, MythVideoFrame */*Frame*/, AVFrame */*AvFrame*/) { return false; }
153 virtual int FilteredReceiveFrame (AVCodecContext *Context, AVFrame *Frame);
154 virtual void SetDeinterlacing (AVCodecContext */*Context*/, MythVideoProfile */*Profile*/, bool /*DoubleRate*/) {}
155 virtual void PostProcessFrame (AVCodecContext */*Context*/, MythVideoFrame */*Frame*/) {}
156 virtual bool IsDeinterlacing (bool &/*DoubleRate*/, bool /*StreamChange*/ = false) { return false; }
157 virtual void SetDecoderOptions (AVCodecContext */*Context*/, const AVCodec */*Codec*/) { }
158 virtual bool DecoderWillResetOnFlush (void) { return false; }
159 virtual bool DecoderWillResetOnAspect(void) { return false; }
160 virtual bool DecoderNeedsReset (AVCodecContext */*Context*/) { return m_resetRequired; }
161
162 protected:
163 virtual bool RetrieveHWFrame (MythVideoFrame* Frame, AVFrame* AvFrame);
164 static void DestroyInterop (MythInteropGPU* Interop);
165 static void NewHardwareFramesContext(void);
166 static QAtomicInt s_hwFramesContextCount;
167
168 DecoderBase* m_parent { nullptr };
170 bool m_resetRequired { false };
171};
172
173#endif
AVFrame AVFrame
A device containing images (ie. USB stick, CD, storage group etc)
virtual void SetDeinterlacing(AVCodecContext *, MythVideoProfile *, bool)
virtual void PostProcessFrame(AVCodecContext *, MythVideoFrame *)
virtual int HwDecoderInit(AVCodecContext *)
virtual ~MythCodecContext()=default
virtual bool IsDeinterlacing(bool &, bool=false)
static QAtomicInt s_hwFramesContextCount
virtual bool DecoderNeedsReset(AVCodecContext *)
virtual bool RetrieveFrame(AVCodecContext *, MythVideoFrame *, AVFrame *)
virtual void SetDecoderOptions(AVCodecContext *, const AVCodec *)
virtual bool DecoderWillResetOnAspect(void)
virtual bool DecoderWillResetOnFlush(void)
unsigned int uint
Definition: freesurround.h:24
int(*)(AVCodecContext *Context) CreateHWDecoder
MythCodecID
Definition: mythcodecid.h:14
@ kCodec_NONE
Definition: mythcodecid.h:17
VideoFrameType
Definition: mythframe.h:20
@ FMT_NONE
Definition: mythframe.h:21
#define MTV_PUBLIC
Definition: mythtvexp.h:15