• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include <string>
4 #include <memory>
5 #include <kms++/kms++.h>
6 
7 class VideoStreamer;
8 
9 class VideoDevice
10 {
11 public:
12 	struct VideoFrameSize {
13 		uint32_t min_w, max_w, step_w;
14 		uint32_t min_h, max_h, step_h;
15 	};
16 
17 	VideoDevice(const std::string& dev);
18 	VideoDevice(int fd);
19 	~VideoDevice();
20 
21 	VideoDevice(const VideoDevice& other) = delete;
22 	VideoDevice& operator=(const VideoDevice& other) = delete;
23 
24 	VideoStreamer* get_capture_streamer();
25 	VideoStreamer* get_output_streamer();
26 
27 	std::vector<std::tuple<uint32_t, uint32_t>> get_discrete_frame_sizes(kms::PixelFormat fmt);
28 	VideoFrameSize get_frame_sizes(kms::PixelFormat fmt);
29 
fd()30 	int fd() const { return m_fd; }
has_capture()31 	bool has_capture() const { return m_has_capture; }
has_output()32 	bool has_output() const { return m_has_output; }
has_m2m()33 	bool has_m2m() const { return m_has_m2m; }
34 
35 	static std::vector<std::string> get_capture_devices();
36 	static std::vector<std::string> get_m2m_devices();
37 
38 private:
39 	int m_fd;
40 
41 	bool m_has_capture;
42 	bool m_has_mplane_capture;
43 
44 	bool m_has_output;
45 	bool m_has_mplane_output;
46 
47 	bool m_has_m2m;
48 	bool m_has_mplane_m2m;
49 
50 	std::vector<kms::DumbFramebuffer*> m_capture_fbs;
51 	std::vector<kms::DumbFramebuffer*> m_output_fbs;
52 
53 	std::unique_ptr<VideoStreamer> m_capture_streamer;
54 	std::unique_ptr<VideoStreamer> m_output_streamer;
55 };
56 
57 class VideoStreamer
58 {
59 public:
60 	enum class StreamerType {
61 		CaptureSingle,
62 		CaptureMulti,
63 		OutputSingle,
64 		OutputMulti,
65 	};
66 
67 	VideoStreamer(int fd, StreamerType type);
68 
69 	std::vector<std::string> get_ports();
70 	void set_port(uint32_t index);
71 
72 	std::vector<kms::PixelFormat> get_formats();
73 	void set_format(kms::PixelFormat fmt, uint32_t width, uint32_t height);
74 	void get_selection(uint32_t& left, uint32_t& top, uint32_t& width, uint32_t& height);
75 	void set_selection(uint32_t& left, uint32_t& top, uint32_t& width, uint32_t& height);
76 	void set_queue_size(uint32_t queue_size);
77 	void queue(kms::DumbFramebuffer* fb);
78 	kms::DumbFramebuffer* dequeue();
79 	void stream_on();
80 	void stream_off();
81 
fd()82 	int fd() const { return m_fd; }
83 
84 private:
85 	int m_fd;
86 	StreamerType m_type;
87 	std::vector<kms::DumbFramebuffer*> m_fbs;
88 };
89