Loading...
Searching...
No Matches
CameraInput.hpp
1#pragma once
2#include <Media/Libav.hpp>
3#if SCORE_HAS_LIBAV
4
5#include <Video/ExternalInput.hpp>
6#include <Video/FrameQueue.hpp>
7#include <Video/Rescale.hpp>
8
9extern "C" {
10#include <libavformat/avformat.h>
11#include <libswscale/swscale.h>
12}
13
14#include <ossia/detail/lockfree_queue.hpp>
15
16#include <score_plugin_media_export.h>
17
18#include <atomic>
19#include <string>
20#include <thread>
21namespace Video
22{
23
24class SCORE_PLUGIN_MEDIA_EXPORT CameraInput final
25 : public ExternalInput
26 , public LibAVDecoder
27{
28public:
29 CameraInput() noexcept;
30 ~CameraInput() noexcept;
31
32 bool load(
33 const std::string& inputDevice, const std::string& format, int w, int h,
34 double fps, int codec, int pixelfmt) noexcept;
35
36 bool start() noexcept override;
37 void stop() noexcept override;
38
39 AVFrame* dequeue_frame() noexcept override;
40 void release_frame(AVFrame* frame) noexcept override;
41
42private:
43 void buffer_thread() noexcept;
44 void close_file() noexcept;
45 AVFrame* read_frame_impl() noexcept;
46 bool open_stream() noexcept;
47 void close_stream() noexcept;
48 ReadFrame read_one_frame(AVFramePointer frame, AVPacket& packet);
49
50 static const constexpr int frames_to_buffer = 1;
51
52 AVCodecID m_requestedCodec{AV_CODEC_ID_NONE};
53 AVPixelFormat m_requestedPixfmt{AV_PIX_FMT_NONE};
54
55 std::thread m_thread;
56
57 std::string m_inputKind;
58 std::string m_inputDevice;
59
60 std::atomic_bool m_running{};
61};
62
63}
64#endif
Definition CameraInput.hpp:27
Definition ExternalInput.hpp:11
Definition Rescale.hpp:45
Definition VideoInterface.hpp:44