OpenShot Library | libopenshot  0.7.0
CameraCaptureReader.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_CAMERACAPTUREREADER_H
14 #define OPENSHOT_CAMERACAPTUREREADER_H
15 
16 #include "AudioDevices.h"
17 #include "ScreenCaptureReader.h"
18 
19 #include <memory>
20 
21 namespace openshot
22 {
24  {
29  };
30 
32  {
34  std::string device = "/dev/video0";
35  int width = 1280;
36  int height = 720;
38  std::map<std::string, std::string> options;
39  };
40 
42  {
43  public:
44  explicit CameraCaptureReader(const CameraCaptureSettings& settings);
45  ~CameraCaptureReader() override;
46 
47  void Close() override;
48  CacheBase* GetCache() override { return NULL; };
49  std::shared_ptr<openshot::Frame> GetFrame(int64_t number) override;
50  bool IsOpen() override { return reader && reader->IsOpen(); };
51  std::string Name() override { return "CameraCaptureReader"; };
52  std::string Json() const override;
53  void SetJson(const std::string value) override;
54  Json::Value JsonValue() const override;
55  void SetJsonValue(const Json::Value root) override;
56  void Open() override;
57 
59  CameraCaptureSettings GetSettings() const { return settings; };
60  static bool IsBackendSupported(CameraCaptureBackend backend);
63 
64  private:
65  void ValidateSettings() const;
66  ScreenCaptureSettings ToDeviceSettings() const;
67  void RebuildReader();
68 
69  CameraCaptureSettings settings;
70  std::unique_ptr<ScreenCaptureReader> reader;
71  };
72 }
73 
74 #endif
openshot::CAMERA_CAPTURE_AUTO
@ CAMERA_CAPTURE_AUTO
Definition: CameraCaptureReader.h:25
openshot::CameraCaptureSettings::options
std::map< std::string, std::string > options
Definition: CameraCaptureReader.h:38
openshot::CameraCaptureReader::Open
void Open() override
Open the reader (and start consuming resources, such as images or video files)
Definition: CameraCaptureReader.cpp:273
openshot::AudioDeviceList
std::vector< std::pair< std::string, std::string > > AudioDeviceList
Definition: AudioDevices.h:42
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24
openshot::CameraCaptureReader::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t number) override
Definition: CameraCaptureReader.cpp:292
openshot::CameraCaptureReader::CameraCaptureReader
CameraCaptureReader(const CameraCaptureSettings &settings)
Definition: CameraCaptureReader.cpp:122
openshot::CaptureReaderStats
Definition: ScreenCaptureReader.h:54
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:30
openshot::ScreenCaptureSettings
Definition: ScreenCaptureReader.h:36
openshot::CameraCaptureReader::GetSettings
CameraCaptureSettings GetSettings() const
Definition: CameraCaptureReader.h:59
openshot::CameraCaptureSettings::device
std::string device
Definition: CameraCaptureReader.h:34
openshot::CameraCaptureReader::GetDeviceNames
static AudioDeviceList GetDeviceNames(CameraCaptureBackend backend=CAMERA_CAPTURE_AUTO)
Definition: CameraCaptureReader.cpp:165
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:34
openshot::CameraCaptureSettings::fps
openshot::Fraction fps
Definition: CameraCaptureReader.h:37
openshot::CAMERA_CAPTURE_WINDOWS_DSHOW
@ CAMERA_CAPTURE_WINDOWS_DSHOW
Definition: CameraCaptureReader.h:27
openshot::CameraCaptureReader::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: CameraCaptureReader.cpp:319
openshot::CameraCaptureReader::Name
std::string Name() override
Return the type name of the class.
Definition: CameraCaptureReader.h:51
openshot::CameraCaptureSettings::backend
CameraCaptureBackend backend
Definition: CameraCaptureReader.h:33
openshot::CameraCaptureReader::DefaultBackend
static CameraCaptureBackend DefaultBackend()
Definition: CameraCaptureReader.cpp:152
openshot::CameraCaptureSettings::height
int height
Definition: CameraCaptureReader.h:36
openshot::CameraCaptureReader::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: CameraCaptureReader.cpp:328
ScreenCaptureReader.h
Header file for live screen capture readers.
openshot::CameraCaptureReader::GetStats
openshot::CaptureReaderStats GetStats() const
Definition: CameraCaptureReader.cpp:287
openshot::CAMERA_CAPTURE_MAC_AVFOUNDATION
@ CAMERA_CAPTURE_MAC_AVFOUNDATION
Definition: CameraCaptureReader.h:28
openshot::CameraCaptureSettings
Definition: CameraCaptureReader.h:31
openshot::CameraCaptureReader::IsBackendSupported
static bool IsBackendSupported(CameraCaptureBackend backend)
Definition: CameraCaptureReader.cpp:138
openshot::CameraCaptureReader::~CameraCaptureReader
~CameraCaptureReader() override
Definition: CameraCaptureReader.cpp:133
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:75
openshot::CameraCaptureBackend
CameraCaptureBackend
Definition: CameraCaptureReader.h:23
openshot::CameraCaptureReader::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: CameraCaptureReader.cpp:302
openshot::CameraCaptureReader::IsOpen
bool IsOpen() override
Determine if reader is open or closed.
Definition: CameraCaptureReader.h:50
openshot::CAMERA_CAPTURE_V4L2
@ CAMERA_CAPTURE_V4L2
Definition: CameraCaptureReader.h:26
AudioDevices.h
Header file for Audio Device Info struct.
openshot::CameraCaptureSettings::width
int width
Definition: CameraCaptureReader.h:35
openshot::CameraCaptureReader::GetCache
CacheBase * GetCache() override
Get the cache object used by this reader (note: not all readers use cache)
Definition: CameraCaptureReader.h:48
openshot::CameraCaptureReader::Json
std::string Json() const override
Generate JSON string of this object.
Definition: CameraCaptureReader.cpp:297
openshot::CameraCaptureReader
Definition: CameraCaptureReader.h:41
openshot::CameraCaptureReader::Close
void Close() override
Close the reader (and any resources it was consuming)
Definition: CameraCaptureReader.cpp:280