OpenShot Library | libopenshot
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
ScreenCaptureReader.h
Go to the documentation of this file.
1
8
9
// Copyright (c) 2008-2026 OpenShot Studios, LLC
10
//
11
// SPDX-License-Identifier: LGPL-3.0-or-later
12
13
#ifndef OPENSHOT_SCREENCAPTUREREADER_H
14
#define OPENSHOT_SCREENCAPTUREREADER_H
15
16
#include "
ReaderBase.h
"
17
18
#include <atomic>
19
#include <map>
20
#include <memory>
21
#include <string>
22
23
#include "
FFmpegUtilities.h
"
24
25
namespace
openshot
26
{
27
enum
ScreenCaptureBackend
28
{
29
SCREEN_CAPTURE_AUTO
= 0,
30
SCREEN_CAPTURE_X11
= 1,
31
SCREEN_CAPTURE_WAYLAND
= 2,
32
SCREEN_CAPTURE_WINDOWS_GDI
= 3,
33
SCREEN_CAPTURE_MAC_AVFOUNDATION
= 4
34
};
35
36
struct
ScreenCaptureSettings
37
{
38
ScreenCaptureBackend
backend
=
SCREEN_CAPTURE_AUTO
;
39
std::string
display
;
40
int
x
= 0;
41
int
y
= 0;
42
int
width
= 1280;
43
int
height
= 720;
44
openshot::Fraction
fps
=
openshot::Fraction
(30, 1);
45
bool
include_cursor
=
true
;
46
bool
show_region
=
false
;
47
bool
capture_audio
=
false
;
48
std::string
audio_device
;
49
int
audio_sample_rate
= 48000;
50
int
audio_channels
= 2;
51
std::map<std::string, std::string>
options
;
52
};
53
54
struct
CaptureReaderStats
55
{
56
bool
is_open
=
false
;
57
int64_t
frames_read
= 0;
58
int
dropped_packets
= 0;
59
double
duration
= 0.0;
60
};
61
62
class
ScreenCaptureReader
:
public
ReaderBase
63
{
64
public
:
65
#ifndef SWIG
66
class
CaptureBackendReader
67
{
68
public
:
69
virtual
~CaptureBackendReader
() =
default
;
70
virtual
void
Open
() = 0;
71
virtual
void
Close
() = 0;
72
virtual
bool
IsOpen
()
const
= 0;
73
virtual
std::shared_ptr<openshot::Frame>
GetFrame
(int64_t number) = 0;
74
virtual
openshot::CaptureReaderStats
GetStats
()
const
= 0;
75
};
76
#endif
77
78
explicit
ScreenCaptureReader
(
const
ScreenCaptureSettings
& settings);
79
~ScreenCaptureReader
()
override
;
80
81
void
Close
()
override
;
83
void
RequestClose
();
84
CacheBase
*
GetCache
()
override
{
return
NULL; };
85
std::shared_ptr<openshot::Frame>
GetFrame
(int64_t number)
override
;
86
bool
IsOpen
()
override
;
87
std::string
Name
()
override
{
return
"ScreenCaptureReader"
; };
88
std::string
Json
()
const override
;
89
void
SetJson
(
const
std::string value)
override
;
90
Json::Value
JsonValue
()
const override
;
91
void
SetJsonValue
(
const
Json::Value root)
override
;
92
void
Open
()
override
;
93
94
openshot::CaptureReaderStats
GetStats
()
const
;
95
void
AddSystemAudio
(std::shared_ptr<openshot::Frame> frame, int64_t output_frame_number);
96
void
ResetSystemAudio
();
97
ScreenCaptureSettings
GetSettings
()
const
{
return
settings; };
98
static
bool
IsBackendSupported
(
ScreenCaptureBackend
backend);
99
static
bool
IsSystemAudioSupported
(
ScreenCaptureBackend
backend);
100
static
ScreenCaptureBackend
DefaultBackend
();
101
102
private
:
103
void
ValidateSettings()
const
;
104
void
OpenDevice();
105
void
OpenDecoder();
106
std::string InputFormatName()
const
;
107
std::string InputName()
const
;
108
std::shared_ptr<openshot::Frame> DecodeNextFrame(int64_t number);
109
bool
UsesFFmpegDevice()
const
;
110
bool
UsesWaylandPortal()
const
;
111
void
PopulateInfo();
112
113
ScreenCaptureSettings
settings;
114
#ifndef SWIG
115
std::unique_ptr<CaptureBackendReader> backend_reader;
116
// The Wayland backend is a runtime-loaded module. Keep it loaded until its
117
// reader is destroyed, since the reader's vtable lives in that module.
118
void
* backend_module =
nullptr
;
119
#endif
120
bool
is_open;
121
int
video_stream;
122
int64_t frames_read;
123
int
dropped_packets;
124
AVFormatContext* format_context;
125
AVCodecContext* codec_context;
126
AVFrame* source_frame;
127
AVFrame* rgba_frame;
128
AVPacket* packet;
129
SwsContext* sws_context;
130
std::atomic<bool> close_requested;
131
bool
manual_system_audio =
false
;
132
#ifndef SWIG
133
class
SystemAudioCapture;
134
std::unique_ptr<SystemAudioCapture> system_audio;
135
#endif
136
};
137
}
138
139
#endif
FFmpegUtilities.h
Header file for FFmpegUtilities.
ReaderBase.h
Header file for ReaderBase class.
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition
CacheBase.h:35
openshot::Fraction
This class represents a fraction.
Definition
Fraction.h:30
openshot::ReaderBase::ReaderBase
ReaderBase()
Constructor for the base reader, where many things are initialized.
Definition
ReaderBase.cpp:27
openshot::ScreenCaptureReader::CaptureBackendReader
Definition
ScreenCaptureReader.h:67
openshot::ScreenCaptureReader::CaptureBackendReader::GetStats
virtual openshot::CaptureReaderStats GetStats() const =0
openshot::ScreenCaptureReader::CaptureBackendReader::Open
virtual void Open()=0
openshot::ScreenCaptureReader::CaptureBackendReader::GetFrame
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
openshot::ScreenCaptureReader::CaptureBackendReader::Close
virtual void Close()=0
openshot::ScreenCaptureReader::CaptureBackendReader::~CaptureBackendReader
virtual ~CaptureBackendReader()=default
openshot::ScreenCaptureReader::CaptureBackendReader::IsOpen
virtual bool IsOpen() const =0
openshot::ScreenCaptureReader::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition
ScreenCaptureReader.cpp:1293
openshot::ScreenCaptureReader::IsOpen
bool IsOpen() override
Determine if reader is open or closed.
Definition
ScreenCaptureReader.cpp:695
openshot::ScreenCaptureReader::~ScreenCaptureReader
~ScreenCaptureReader() override
Definition
ScreenCaptureReader.cpp:683
openshot::ScreenCaptureReader::RequestClose
void RequestClose()
Signal FFmpeg capture reads to stop; the opening thread must call Close().
Definition
ScreenCaptureReader.cpp:1205
openshot::ScreenCaptureReader::GetStats
openshot::CaptureReaderStats GetStats() const
Definition
ScreenCaptureReader.cpp:1249
openshot::ScreenCaptureReader::Name
std::string Name() override
Return the type name of the class.
Definition
ScreenCaptureReader.h:87
openshot::ScreenCaptureReader::Close
void Close() override
Close the reader (and any resources it was consuming).
Definition
ScreenCaptureReader.cpp:1210
openshot::ScreenCaptureReader::DefaultBackend
static ScreenCaptureBackend DefaultBackend()
Definition
ScreenCaptureReader.cpp:740
openshot::ScreenCaptureReader::IsBackendSupported
static bool IsBackendSupported(ScreenCaptureBackend backend)
Definition
ScreenCaptureReader.cpp:701
openshot::ScreenCaptureReader::ScreenCaptureReader
ScreenCaptureReader(const ScreenCaptureSettings &settings)
Definition
ScreenCaptureReader.cpp:621
openshot::ScreenCaptureReader::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition
ScreenCaptureReader.cpp:1302
openshot::ScreenCaptureReader::AddSystemAudio
void AddSystemAudio(std::shared_ptr< openshot::Frame > frame, int64_t output_frame_number)
Definition
ScreenCaptureReader.cpp:1066
openshot::ScreenCaptureReader::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition
ScreenCaptureReader.cpp:1268
openshot::ScreenCaptureReader::ResetSystemAudio
void ResetSystemAudio()
Definition
ScreenCaptureReader.cpp:1073
openshot::ScreenCaptureReader::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t number) override
Definition
ScreenCaptureReader.cpp:1046
openshot::ScreenCaptureReader::GetSettings
ScreenCaptureSettings GetSettings() const
Definition
ScreenCaptureReader.h:97
openshot::ScreenCaptureReader::Json
std::string Json() const override
Generate JSON string of this object.
Definition
ScreenCaptureReader.cpp:1263
openshot::ScreenCaptureReader::Open
void Open() override
Open the reader (and start consuming resources, such as images or video files).
Definition
ScreenCaptureReader.cpp:873
openshot::ScreenCaptureReader::GetCache
CacheBase * GetCache() override
Get the cache object used by this reader (note: not all readers use cache).
Definition
ScreenCaptureReader.h:84
openshot::ScreenCaptureReader::IsSystemAudioSupported
static bool IsSystemAudioSupported(ScreenCaptureBackend backend)
Definition
ScreenCaptureReader.cpp:723
openshot
This namespace is the default namespace for all code in the openshot library.
Definition
AnimatedCurve.h:24
openshot::ScreenCaptureBackend
ScreenCaptureBackend
Definition
ScreenCaptureReader.h:28
openshot::SCREEN_CAPTURE_AUTO
@ SCREEN_CAPTURE_AUTO
Definition
ScreenCaptureReader.h:29
openshot::SCREEN_CAPTURE_MAC_AVFOUNDATION
@ SCREEN_CAPTURE_MAC_AVFOUNDATION
Definition
ScreenCaptureReader.h:33
openshot::SCREEN_CAPTURE_WAYLAND
@ SCREEN_CAPTURE_WAYLAND
Definition
ScreenCaptureReader.h:31
openshot::SCREEN_CAPTURE_X11
@ SCREEN_CAPTURE_X11
Definition
ScreenCaptureReader.h:30
openshot::SCREEN_CAPTURE_WINDOWS_GDI
@ SCREEN_CAPTURE_WINDOWS_GDI
Definition
ScreenCaptureReader.h:32
openshot::CaptureReaderStats
Definition
ScreenCaptureReader.h:55
openshot::CaptureReaderStats::duration
double duration
Definition
ScreenCaptureReader.h:59
openshot::CaptureReaderStats::frames_read
int64_t frames_read
Definition
ScreenCaptureReader.h:57
openshot::CaptureReaderStats::dropped_packets
int dropped_packets
Definition
ScreenCaptureReader.h:58
openshot::CaptureReaderStats::is_open
bool is_open
Definition
ScreenCaptureReader.h:56
openshot::ScreenCaptureSettings
Definition
ScreenCaptureReader.h:37
openshot::ScreenCaptureSettings::audio_device
std::string audio_device
Definition
ScreenCaptureReader.h:48
openshot::ScreenCaptureSettings::options
std::map< std::string, std::string > options
Definition
ScreenCaptureReader.h:51
openshot::ScreenCaptureSettings::include_cursor
bool include_cursor
Definition
ScreenCaptureReader.h:45
openshot::ScreenCaptureSettings::capture_audio
bool capture_audio
Definition
ScreenCaptureReader.h:47
openshot::ScreenCaptureSettings::fps
openshot::Fraction fps
Definition
ScreenCaptureReader.h:44
openshot::ScreenCaptureSettings::backend
ScreenCaptureBackend backend
Definition
ScreenCaptureReader.h:38
openshot::ScreenCaptureSettings::height
int height
Definition
ScreenCaptureReader.h:43
openshot::ScreenCaptureSettings::x
int x
Definition
ScreenCaptureReader.h:40
openshot::ScreenCaptureSettings::audio_sample_rate
int audio_sample_rate
Definition
ScreenCaptureReader.h:49
openshot::ScreenCaptureSettings::width
int width
Definition
ScreenCaptureReader.h:42
openshot::ScreenCaptureSettings::show_region
bool show_region
Definition
ScreenCaptureReader.h:46
openshot::ScreenCaptureSettings::audio_channels
int audio_channels
Definition
ScreenCaptureReader.h:50
openshot::ScreenCaptureSettings::y
int y
Definition
ScreenCaptureReader.h:41
openshot::ScreenCaptureSettings::display
std::string display
Definition
ScreenCaptureReader.h:39
ScreenCaptureReader.h
Generated by
1.17.0