Rescale.hpp
1 #pragma once
2 
3 #include <Media/Libav.hpp>
4 #if SCORE_HAS_LIBAV
5 
6 #include <Video/FrameQueue.hpp>
7 #include <Video/VideoInterface.hpp>
8 
9 extern "C" {
10 struct SwsContext;
11 #include <libavcodec/avcodec.h>
12 #include <libavformat/avformat.h>
13 }
14 
15 #include <QDebug>
16 
17 #include <score_plugin_media_export.h>
18 namespace Video
19 {
20 class SCORE_PLUGIN_MEDIA_EXPORT Rescale
21 {
22 public:
23  operator bool() const noexcept { return m_rescale; }
24 
25  void open(const VideoMetadata& src);
26  void close();
27  void rescale(FrameQueue& m_frames, AVFramePointer& frame, ReadFrame& read);
28 
29 private:
30  const VideoMetadata* m_src{};
31  SwsContext* m_rescale{};
32  AVPixelFormat m_rescaleFormat{};
33 };
34 
35 struct SCORE_PLUGIN_MEDIA_EXPORT DecoderConfiguration
36 {
37  AVPixelFormat hardwareAcceleration{AV_PIX_FMT_NONE};
38  std::string decoder;
39  int threads{};
40  bool useAVCodec{true};
41  bool ignorePTS{false};
42 };
43 
44 struct SCORE_PLUGIN_MEDIA_EXPORT LibAVDecoder
45 {
46  ReadFrame enqueue_frame(const AVPacket* pkt) noexcept;
47  std::pair<AVBufferRef*, const AVCodec*> open_hwdec(const AVCodec&) noexcept;
48 
49  int init_codec_context(
50  const AVCodec* codec, AVBufferRef* hw_dev_ctx, const AVStream* stream,
51  std::function<void(AVCodecContext&)> setup);
52  bool open_codec_context(
53  VideoInterface& self, const AVStream* stream,
54  std::function<void(AVCodecContext&)> setup);
55  void init_scaler(VideoInterface& self) noexcept;
56  void load_packet_in_frame(const AVPacket& packet, AVFrame& frame);
57 
58  ReadFrame read_one_frame(AVPacket& packet);
59  ReadFrame read_one_frame_raw(AVPacket& packet);
60  ReadFrame read_one_frame_avcodec(AVPacket& packet);
61 
62  DecoderConfiguration m_conf;
63 
64  AVFormatContext* m_formatContext{};
65  AVStream* m_avstream{};
66  const AVCodec* m_codec{};
67  AVCodecContext* m_codecContext{};
68 
69  FrameQueue m_frames;
70  Rescale m_rescale;
71  bool m_finished{};
72 };
73 
74 }
75 #endif
Definition: Rescale.hpp:21
Definition: Rescale.hpp:36
Definition: FrameQueue.hpp:53
Definition: Rescale.hpp:45
Definition: VideoInterface.hpp:38
Definition: VideoInterface.hpp:31
Definition: VideoInterface.hpp:23