Loading...
Searching...
No Matches
VideoInterface.hpp
1#pragma once
2#include <Media/Libav.hpp>
3#include <Video/VideoEnums.hpp>
5#if SCORE_HAS_LIBAV
6#include <score_plugin_media_export.h>
7extern "C" {
8#include <libavcodec/codec_id.h>
9#include <libavutil/pixfmt.h>
10#include <libavcodec/version.h>
11#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 3, 100)
12#if __has_include(<libavutil/mastering_display_metadata.h>)
13#include <libavutil/mastering_display_metadata.h>
14#endif
15#endif
16struct AVFrame;
17struct AVCodecContext;
18struct AVPacket;
19}
20#include <memory>
21#include <string>
22
23namespace Video
24{
25
26struct SCORE_PLUGIN_MEDIA_EXPORT ImageFormat
27{
28 // From ffmpeg
29 int width{};
30 int height{};
31 AVPixelFormat pixel_format = AVPixelFormat(-1);
32
33 // For hardware-accelerated formats (AV_PIX_FMT_DRM_PRIME, VAAPI,
34 // CUDA, etc.) where `pixel_format` is an opaque HW tag, this carries
35 // the underlying SW pixel format that the descriptor / surface wraps
36 AVPixelFormat hwaccel_sw_format = AVPixelFormat(-1);
37
43 VideoPixelFormat native_format = VideoPixelFormat::Unknown;
44
45 AVColorRange color_range = AVColorRange(-1);
46 AVColorPrimaries color_primaries = AVColorPrimaries(-1);
47 AVColorTransferCharacteristic color_trc = AVColorTransferCharacteristic(-1);
48 AVColorSpace color_space = AVColorSpace(-1);
49 AVChromaLocation chroma_location = AVChromaLocation(-1);
50
51#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 3, 100)
52 AVMasteringDisplayMetadata mastering_display{};
53 std::optional<AVContentLightMetadata> content_light{};
54#endif
55
59 Interlacing interlacing = ::Video::Interlacing::None;
60
61 // Set by the user
62 OutputFormat output_format = ::Video::OutputFormat::SDR;
63 Tonemap tonemap = ::Video::Tonemap::Auto;
64 Deinterlace deinterlace = ::Video::Deinterlace::Weave;
65};
66
67struct SCORE_PLUGIN_MEDIA_EXPORT VideoMetadata : ImageFormat
68{
69 std::string filePath;
70 AVCodecID codec_id = AV_CODEC_ID_NONE;
71 double fps{};
72 bool realTime{};
73 double flicks_per_dts{};
74 double dts_per_flicks{};
75};
76
77struct SCORE_PLUGIN_MEDIA_EXPORT VideoInterface : VideoMetadata
78{
79 virtual ~VideoInterface();
80 virtual AVFrame* dequeue_frame() noexcept = 0;
81 virtual void release_frame(AVFrame* frame) noexcept = 0;
82};
83
84struct SCORE_PLUGIN_MEDIA_EXPORT ReadFrame
85{
86 AVFrame* frame{};
87 int error{};
88};
89struct SCORE_PLUGIN_MEDIA_EXPORT FreeAVFrame
90{
91 void operator()(AVFrame* f) const noexcept;
92};
93
94using AVFramePointer = std::unique_ptr<AVFrame, FreeAVFrame>;
95
96ReadFrame receiveVideoFrame(
97 AVCodecContext* codecContext, AVFrame* frame, bool ignorePts);
98}
99#endif
Vendor-neutral pixel format vocabulary + descriptive metadata.
VideoPixelFormat
Definition VideoPixelFormat.hpp:235
Definition VideoInterface.hpp:90
Definition VideoInterface.hpp:27
Definition VideoInterface.hpp:85
Definition VideoInterface.hpp:78
Definition VideoInterface.hpp:68