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