OpenShot Library | libopenshot 1.1.1
ScreenCaptureReader.h
Go to the documentation of this file.
1
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
25namespace openshot
26{
28 {
34 };
35
37 {
39 std::string display;
40 int x = 0;
41 int y = 0;
42 int width = 1280;
43 int height = 720;
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;
51 std::map<std::string, std::string> options;
52 };
53
55 {
56 bool is_open = false;
57 int64_t frames_read = 0;
59 double duration = 0.0;
60 };
61
63 {
64 public:
65#ifndef SWIG
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;
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
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);
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
Header file for FFmpegUtilities.
Header file for ReaderBase class.
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:35
This class represents a fraction.
Definition: Fraction.h:30
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:76
virtual openshot::CaptureReaderStats GetStats() const =0
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
void SetJson(const std::string value) override
Load JSON string into this object.
bool IsOpen() override
Determine if reader is open or closed.
void RequestClose()
Signal FFmpeg capture reads to stop; the opening thread must call Close().
openshot::CaptureReaderStats GetStats() const
std::string Name() override
Return the type name of the class.
void Close() override
Close the reader (and any resources it was consuming)
static ScreenCaptureBackend DefaultBackend()
static bool IsBackendSupported(ScreenCaptureBackend backend)
ScreenCaptureReader(const ScreenCaptureSettings &settings)
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
void AddSystemAudio(std::shared_ptr< openshot::Frame > frame, int64_t output_frame_number)
Json::Value JsonValue() const override
Generate Json::Value for this object.
std::shared_ptr< openshot::Frame > GetFrame(int64_t number) override
ScreenCaptureSettings GetSettings() const
std::string Json() const override
Generate JSON string of this object.
void Open() override
Open the reader (and start consuming resources, such as images or video files)
CacheBase * GetCache() override
Get the cache object used by this reader (note: not all readers use cache)
static bool IsSystemAudioSupported(ScreenCaptureBackend backend)
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24
@ SCREEN_CAPTURE_MAC_AVFOUNDATION
@ SCREEN_CAPTURE_WINDOWS_GDI
std::map< std::string, std::string > options