20
20
#include " camera-device-interface.h"
21
21
#include " chime-manager.h"
22
22
#include " camera-av-stream-manager.h"
23
- #include " camera-hal.h"
24
23
#include < protocols/interaction_model/StatusCode.h>
25
24
25
+ #include < gst/gst.h>
26
+ #define VIDEO_STREAM_GST_DEST_PORT 5000
27
+ #define AUDIO_STREAM_GST_DEST_PORT 5001
28
+
26
29
namespace Camera {
27
30
28
- class CameraDevice : public CameraDeviceInterface
29
- // public CameraHAL::CameraHALInterface
31
+ constexpr uint8_t kMaxVideoStreams = 10 ; // Maximum number of pre-allocated streams
32
+ constexpr uint16_t kInvalidStreamID = 65500 ;
33
+
34
+ struct VideoStream
35
+ {
36
+ uint16_t id; // Stream ID
37
+ bool isAllocated; // Flag to indicate if the stream is allocated
38
+ chip::app::Clusters::CameraAvStreamManagement::VideoCodecEnum codec; // Codec information (e.g., "H.264", "HEVC")
39
+ VideoResolutionStruct videoRes;
40
+ uint16_t frameRate; // frame rate
41
+ GstElement * videoPipeline;
42
+ };
43
+
44
+ struct AudioStream
45
+ {
46
+ uint16_t id; // Stream ID
47
+ bool isAllocated; // Flag to indicate if the stream is allocated
48
+ chip::app::Clusters::CameraAvStreamManagement::AudioCodecEnum codec; // Codec information (e.g., "OPUS", "AACLC")
49
+ uint8_t channelCount; // channel count
50
+ GstElement * audioPipeline;
51
+ };
52
+
53
+ struct SnapshotStream
54
+ {
55
+ uint16_t id; // Stream ID
56
+ bool isAllocated; // Flag to indicate if the stream is allocated
57
+ chip::app::Clusters::CameraAvStreamManagement::ImageCodecEnum codec; // Codec information (e.g., "JPEG")
58
+ VideoResolutionStruct videoRes;
59
+ uint8_t quality; // Quality
60
+ GstElement * snapshotPipeline;
61
+ };
62
+
63
+ class CameraDevice : public CameraDeviceInterface ,
64
+ public CameraDeviceInterface::CameraHALInterface
30
65
{
31
66
public:
32
67
68
+ ~CameraDevice ();
69
+
33
70
static CameraDevice & GetInstance ()
34
71
{
35
72
static CameraDevice sCameraDevice ;
@@ -39,9 +76,74 @@ class CameraDevice : public CameraDeviceInterface
39
76
chip::app::Clusters::ChimeDelegate & GetChimeDelegate ();
40
77
chip::app::Clusters::CameraAvStreamManagement::CameraAVStreamMgmtDelegate & GetCameraAVStreamMgmtDelegate ();
41
78
79
+ CameraDeviceInterface::CameraHALInterface & GetCameraHALInterface () { return *this ; }
80
+
81
+ // HAL interface impl
82
+ CameraError InitializeCameraDevice ();
83
+
84
+ CameraError InitializeStreams ();
85
+
86
+ CameraError VideoStreamAllocate (const VideoStreamStruct & allocateArgs, uint16_t & outStreamID);
87
+
88
+ CameraError VideoStreamDeallocate (const uint16_t streamID);
89
+
90
+ CameraError AudioStreamAllocate (const AudioStreamStruct & allocateArgs, uint16_t & outStreamID);
91
+
92
+ CameraError AudioStreamDeallocate (const uint16_t streamID);
93
+
94
+ CameraError SnapshotStreamAllocate (const SnapshotStreamStruct & allocateArgs, uint16_t & outStreamID);
95
+
96
+ CameraError SnapshotStreamDeallocate (const uint16_t streamID);
97
+
98
+ CameraError CaptureSnapshot (const uint16_t streamID, const VideoResolutionStruct & resolution,
99
+ ImageSnapshot & outImageSnapshot);
100
+
101
+ CameraError StartVideoStream (uint16_t streamID);
102
+
103
+ // Stop video stream
104
+ CameraError StopVideoStream (uint16_t streamID);
105
+
106
+ // Start audio stream
107
+ CameraError StartAudioStream (uint16_t streamID);
108
+
109
+ // Stop audio stream
110
+ CameraError StopAudioStream (uint16_t streamID);
111
+
112
+ // Start snapshot stream
113
+ CameraError StartSnapshotStream (uint16_t streamID);
114
+
115
+ // Stop snapshot stream
116
+ CameraError StopSnapshotStream (uint16_t streamID);
117
+
118
+ VideoSensorParamsStruct & GetVideoSensorParams ();
119
+
120
+ bool GetNightVisionCapable ();
121
+
122
+ VideoResolutionStruct & GetMinViewport ();
123
+
124
+ uint8_t GetMaxConcurrentVideoEncoders ();
125
+
126
+ uint32_t GetMaxEncodedPixelRate ();
127
+
128
+ uint16_t GetFrameRate ();
129
+
130
+ void SetHDRMode (bool hdrMode);
131
+
42
132
private:
43
133
CameraDevice ();
44
134
135
+ int videoDeviceFd = -1 ;
136
+ std::vector<VideoStream> videoStreams; // Vector to hold available video streams
137
+ std::vector<AudioStream> audioStreams; // Vector to hold available audio streams
138
+ std::vector<SnapshotStream> snapshotStreams; // Vector to hold available snapshot streams
139
+
140
+ void InitializeVideoStreams ();
141
+ void InitializeAudioStreams ();
142
+ void InitializeSnapshotStreams ();
143
+
144
+ GstElement * CreatePipeline (const std::string & pipelineString, CameraError& error);
145
+ CameraError SetV4l2Control (int controlId, int value);
146
+
45
147
// Various cluster server delegates
46
148
ChimeManager mChimeManager ;
47
149
0 commit comments