xbmc
DVDVideoCodecFFmpeg.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "cores/VideoPlayer/DVDCodecs/DVDCodecs.h"
12 #include "cores/VideoPlayer/DVDStreamInfo.h"
13 #include "DVDVideoCodec.h"
14 #include "DVDVideoPPFFmpeg.h"
15 #include <string>
16 #include <vector>
17 
18 extern "C" {
19 #include <libavfilter/avfilter.h>
20 #include <libavcodec/avcodec.h>
21 #include <libavformat/avformat.h>
22 #include <libavutil/avutil.h>
23 #include <libswscale/swscale.h>
24 #include <libpostproc/postprocess.h>
25 }
26 
28 
30 {
31 public:
32  explicit CDVDVideoCodecFFmpeg(CProcessInfo &processInfo);
33  ~CDVDVideoCodecFFmpeg() override;
34  bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) override;
35  bool AddData(const DemuxPacket &packet) override;
36  void Reset() override;
37  void Reopen() override;
38  CDVDVideoCodec::VCReturn GetPicture(VideoPicture* pVideoPicture) override;
39  const char* GetName() override { return m_name.c_str(); }; // m_name is never changed after open
40  unsigned GetConvergeCount() override;
41  unsigned GetAllowedReferences() override;
42  bool GetCodecStats(double &pts, int &droppedFrames, int &skippedPics) override;
43  void SetCodecControl(int flags) override;
44 
45  IHardwareDecoder* GetHWAccel() override;
46  bool GetPictureCommon(VideoPicture* pVideoPicture) override;
47 
48 protected:
49  void Dispose();
50  static enum AVPixelFormat GetFormat(struct AVCodecContext * avctx, const AVPixelFormat * fmt);
51 
52  int FilterOpen(const std::string& filters, bool scale);
53  void FilterClose();
54  CDVDVideoCodec::VCReturn FilterProcess(AVFrame* frame);
55  void SetFilters();
56  void UpdateName();
57  bool SetPictureParams(VideoPicture* pVideoPicture);
58 
59  bool HasHardware() { return m_pHardware != nullptr; }
60  void SetHardware(IHardwareDecoder *hardware);
61 
62  AVFrame* m_pFrame = nullptr;;
63  AVFrame* m_pDecodedFrame = nullptr;;
64  AVCodecContext* m_pCodecContext = nullptr;;
65  std::shared_ptr<CVideoBufferPoolFFmpeg> m_videoBufferPool;
66 
67  std::string m_filters;
68  std::string m_filters_next;
69  AVFilterGraph* m_pFilterGraph = nullptr;
70  AVFilterContext* m_pFilterIn = nullptr;
71  AVFilterContext* m_pFilterOut = nullptr;;
72  AVFrame* m_pFilterFrame = nullptr;;
73  bool m_filterEof = false;
74  bool m_eof = false;
75 
76  CDVDVideoPPFFmpeg m_postProc;
77 
78  int m_iPictureWidth = 0;
79  int m_iPictureHeight = 0;
80  int m_iScreenWidth = 0;
81  int m_iScreenHeight = 0;
82  int m_iOrientation = 0;// orientation of the video in degrees counter clockwise
83 
84  std::string m_name;
85  int m_decoderState;
86  IHardwareDecoder *m_pHardware = nullptr;
87  int m_iLastKeyframe = 0;
88  double m_dts = DVD_NOPTS_VALUE;
89  bool m_started = false;
90  bool m_startedInput = false;
91  std::vector<AVPixelFormat> m_formats;
92  double m_decoderPts = DVD_NOPTS_VALUE;
93  int m_skippedDeint = 0;
94  int m_droppedFrames = 0;
95  bool m_requestSkipDeint = false;
96  int m_codecControlFlags = 0;
97  bool m_interlaced = false;
98  double m_DAR = 1.0;
99  CDVDStreamInfo m_hints;
100  CDVDCodecOptions m_options;
101 
103  {
104  CDropControl();
105  void Reset(bool init);
106  void Process(int64_t pts, bool drop);
107 
108  int64_t m_lastPTS;
109  int64_t m_diffPTS;
110  int m_count;
111  enum
112  {
113  INIT,
114  VALID
115  } m_state;
116  } m_dropCtrl;
117 };
unsigned GetConvergeCount() override
How many packets should player remember, so codec can recover should something cause it to flush outs...
Definition: DVDVideoCodecFFmpeg.cpp:1319
Definition: DVDStreamInfo.h:25
void SetCodecControl(int flags) override
Codec can be informed by player with the following flags:
Definition: DVDVideoCodecFFmpeg.cpp:1354
Definition: DVDCodecs.h:23
Definition: DVDVideoCodec.h:245
bool GetPictureCommon(VideoPicture *pVideoPicture) override
Definition: DVDVideoCodecFFmpeg.cpp:958
const char * GetName() override
should return codecs name
Definition: DVDVideoCodecFFmpeg.h:39
Definition: DVDVideoCodecFFmpeg.h:102
bool AddData(const DemuxPacket &packet) override
add data, decoder has to consume the entire packet returns true if the packet was consumed or if resu...
Definition: DVDVideoCodecFFmpeg.cpp:571
Definition: DVDVideoCodec.h:261
Definition: DVDVideoCodecFFmpeg.cpp:123
void Reopen() override
Re-open the decoder.
Definition: DVDVideoCodecFFmpeg.cpp:949
Definition: ProcessInfo.h:26
void Reset() override
Reset the decoder.
Definition: DVDVideoCodecFFmpeg.cpp:928
Definition: DVDVideoCodecFFmpeg.h:29
Definition: DVDVideoCodec.h:36
Definition: DemuxPacket.h:22
bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) override
Open the decoder, returns true on success Decoders not capable of running multiple instances should r...
Definition: DVDVideoCodecFFmpeg.cpp:321
unsigned GetAllowedReferences() override
Number of references to old pictures that are allowed to be retained when calling decode on the next ...
Definition: DVDVideoCodecFFmpeg.cpp:1324
Definition: DVDVideoPPFFmpeg.h:17
CDVDVideoCodec::VCReturn GetPicture(VideoPicture *pVideoPicture) override
GetPicture controls decoding.
Definition: DVDVideoCodecFFmpeg.cpp:649
Definition: DVDVideoCodec.h:107
bool GetCodecStats(double &pts, int &droppedFrames, int &skippedPics) override
For calculation of dropping requirements player asks for some information.
Definition: DVDVideoCodecFFmpeg.cpp:1332