Loading...
Searching...
No Matches
Rescale.hpp
1#pragma once
2
3#include <Media/Libav.hpp>
4#if SCORE_HAS_LIBAV
5
7#include <Video/FrameQueue.hpp>
8#include <Video/VideoInterface.hpp>
9
10extern "C" {
11struct SwsContext;
12#include <libavcodec/avcodec.h>
13#include <libavformat/avformat.h>
14}
15
16#include <QDebug>
17
18#include <score_plugin_media_export.h>
19
20#include <atomic>
21namespace Video
22{
23class SCORE_PLUGIN_MEDIA_EXPORT Rescale
24{
25public:
26 Rescale() = default;
27 ~Rescale();
28 Rescale(const Rescale&) = delete;
29 Rescale(Rescale&&) = delete;
30 Rescale& operator=(const Rescale&) = delete;
31 Rescale& operator=(Rescale&&) = delete;
32
33 operator bool() const noexcept { return m_rescale; }
34
35 void open(const VideoMetadata& src);
36 void close();
37 void rescale(FrameQueue& m_frames, AVFramePointer& frame, ReadFrame& read);
38
39private:
40 const VideoMetadata* m_src{};
41 SwsContext* m_rescale{};
42 AVPixelFormat m_rescaleFormat{};
43 int m_srcWidth{};
44 int m_srcHeight{};
45};
46
47struct SCORE_PLUGIN_MEDIA_EXPORT DecoderConfiguration
48{
49 AVPixelFormat hardwareAcceleration{AV_PIX_FMT_NONE};
50 std::string decoder;
52 int threads{};
53 DecodeUseCase useCase{DecodeUseCase::Playback};
54 int graphicsApi{}; // score::gfx::GraphicsApi (avoid header dependency)
55 uint32_t gpuVendorId{}; // PCI vendor ID of the render GPU (0 = unknown)
56 bool useAVCodec{true};
57 bool ignorePTS{false};
58};
59
60struct SCORE_PLUGIN_MEDIA_EXPORT LibAVDecoder
61{
62 ReadFrame enqueue_frame(const AVPacket* pkt) noexcept;
63 std::pair<AVBufferRef*, const AVCodec*> open_hwdec(const AVCodec&) noexcept;
64
65 int init_codec_context(
66 const AVCodec* codec, AVBufferRef* hw_dev_ctx, const AVStream* stream,
67 std::function<void(AVCodecContext&)> setup);
68 bool open_codec_context(
69 VideoInterface& self, const AVStream* stream,
70 std::function<void(AVCodecContext&)> setup);
71 void init_scaler(VideoInterface& self) noexcept;
72 void load_packet_in_frame(const AVPacket& packet, AVFrame& frame);
73
74 ReadFrame read_one_frame(AVPacket& packet);
75 ReadFrame read_one_frame_raw(AVPacket& packet);
76 ReadFrame read_one_frame_avcodec(AVPacket& packet);
77
79
80 AVFormatContext* m_formatContext{};
81 AVStream* m_avstream{};
82 const AVCodec* m_codec{};
83 AVCodecContext* m_codecContext{};
84
85 FrameQueue m_frames;
86 Rescale m_rescale;
87 MissingTimestamps m_missingTimestamps;
90 int64_t m_ptsLead{};
98 int64_t m_skipBefore{AV_NOPTS_VALUE};
100 AVFrame* m_skipCandidate{};
104 int64_t m_skipLandingPts{AV_NOPTS_VALUE};
105 void landSkip(AVFrame* f) noexcept;
107 void dropSkipCandidate() noexcept;
109 ReadFrame takeSkipCandidate() noexcept;
111 std::atomic_bool m_finished{};
112};
113
114}
115#endif
Which of libavcodec's threading models a decoder runs, and how wide.
DecodeUseCase
What consumes the decoded frames, which sets how much delay is acceptable.
Definition DecoderThreading.hpp:36
Definition Rescale.hpp:24
STL namespace.
Definition Rescale.hpp:48
Definition FrameQueue.hpp:53
Definition Rescale.hpp:61
Definition VideoInterface.hpp:124
Definition VideoInterface.hpp:109
Definition VideoInterface.hpp:91
Definition VideoInterface.hpp:73