Skip to content

Commit b117f5d

Browse files
committed
Start the video stream using the parameters from the allocated stream
1 parent 6e50acf commit b117f5d

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

examples/camera-app/camera-common/include/camera-device-interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class CameraDeviceInterface
166166
virtual CameraError CaptureSnapshot(const chip::app::DataModel::Nullable<uint16_t> streamID,
167167
const VideoResolutionStruct & resolution, ImageSnapshot & outImageSnapshot) = 0;
168168
// Start video stream
169-
virtual CameraError StartVideoStream(uint16_t streamID) = 0;
169+
virtual CameraError StartVideoStream(const VideoStreamStruct & allocatedStream) = 0;
170170

171171
// Stop video stream
172172
virtual CameraError StopVideoStream(uint16_t streamID) = 0;

examples/camera-app/linux/include/camera-device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class CameraDevice : public CameraDeviceInterface, public CameraDeviceInterface:
107107
CameraError CaptureSnapshot(const chip::app::DataModel::Nullable<uint16_t> streamID, const VideoResolutionStruct & resolution,
108108
ImageSnapshot & outImageSnapshot) override;
109109

110-
CameraError StartVideoStream(uint16_t streamID) override;
110+
CameraError StartVideoStream(const VideoStreamStruct & allocatedStream) override;
111111

112112
// Stop video stream
113113
CameraError StopVideoStream(uint16_t streamID) override;

examples/camera-app/linux/include/clusters/camera-avstream-mgmt/camera-av-stream-manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class CameraAVStreamManager : public CameraAVStreamMgmtDelegate, public CameraAV
5555

5656
Protocols::InteractionModel::Status SnapshotStreamDeallocate(const uint16_t streamID) override;
5757

58+
void OnVideoStreamAllocated(const VideoStreamStruct & allocatedStream) override;
59+
5860
void OnStreamUsagePrioritiesChanged() override;
5961

6062
void OnAttributeChanged(AttributeId attributeId) override;

examples/camera-app/linux/src/camera-device.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,21 +624,21 @@ CameraError CameraDevice::CaptureSnapshot(const chip::app::DataModel::Nullable<u
624624
return CameraError::SUCCESS;
625625
}
626626

627-
CameraError CameraDevice::StartVideoStream(uint16_t streamID)
627+
CameraError CameraDevice::StartVideoStream(const VideoStreamStruct & allocatedStream)
628628
{
629-
auto it = std::find_if(mVideoStreams.begin(), mVideoStreams.end(),
630-
[streamID](const VideoStream & s) { return s.videoStreamParams.videoStreamID == streamID; });
629+
uint16_t streamID = allocatedStream.videoStreamID;
630+
auto it = std::find_if(mVideoStreams.begin(), mVideoStreams.end(),
631+
[streamID](const VideoStream & s) { return s.videoStreamParams.videoStreamID == streamID; });
631632

632633
if (it == mVideoStreams.end())
633634
{
634635
return CameraError::ERROR_VIDEO_STREAM_START_FAILED;
635636
}
636637

637-
// Create Gstreamer video pipeline
638-
CameraError error = CameraError::SUCCESS;
639-
GstElement * videoPipeline =
640-
CreateVideoPipeline(mVideoDevicePath, it->videoStreamParams.minResolution.width, it->videoStreamParams.minResolution.height,
641-
it->videoStreamParams.minFrameRate, error);
638+
// Create Gstreamer video pipeline using the final allocated stream parameters
639+
CameraError error = CameraError::SUCCESS;
640+
GstElement * videoPipeline = CreateVideoPipeline(mVideoDevicePath, allocatedStream.minResolution.width,
641+
allocatedStream.minResolution.height, allocatedStream.minFrameRate, error);
642642
if (videoPipeline == nullptr)
643643
{
644644
ChipLogError(Camera, "Failed to create video pipeline.");
@@ -656,8 +656,9 @@ CameraError CameraDevice::StartVideoStream(uint16_t streamID)
656656
gst_object_unref(appsink);
657657
}
658658

659-
ChipLogProgress(Camera, "Starting video stream (id=%u): %u×%u @ %ufps", streamID, it->videoStreamParams.minResolution.width,
660-
it->videoStreamParams.minResolution.height, it->videoStreamParams.minFrameRate);
659+
ChipLogProgress(Camera, "Starting video stream (id=%u): %u×%u @ %ufps", streamID, allocatedStream.maxResolution.width,
660+
ChipLogProgress(Camera, "Starting video stream (id=%u): %u×%u @ %ufps", streamID, allocatedStream.minResolution.width,
661+
allocatedStream.minResolution.height, allocatedStream.minFrameRate);
661662

662663
// Start the pipeline
663664
ChipLogProgress(Camera, "Requesting PLAYING …");

examples/camera-app/linux/src/clusters/camera-avstream-mgmt/camera-av-stream-manager.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,13 @@ Protocols::InteractionModel::Status CameraAVStreamManager::VideoStreamAllocate(c
127127
if (!stream.isAllocated)
128128
{
129129
stream.isAllocated = true;
130-
131-
// Start the video stream from HAL for serving.
132-
mCameraDeviceHAL->GetCameraHALInterface().StartVideoStream(outStreamID);
133-
134130
// Set the default viewport on the newly allocated stream
135131
mCameraDeviceHAL->GetCameraHALInterface().SetViewport(stream,
136132
mCameraDeviceHAL->GetCameraHALInterface().GetViewport());
137133

138134
// Inform DPTZ that there's an allocated stream
139135
mCameraDeviceHAL->GetCameraAVSettingsUserLevelMgmtDelegate().VideoStreamAllocated(outStreamID);
140136

141-
// Set the current frame rate attribute from HAL once stream has started
142-
GetCameraAVStreamMgmtServer()->SetCurrentFrameRate(mCameraDeviceHAL->GetCameraHALInterface().GetCurrentFrameRate());
143-
144137
return Status::Success;
145138
}
146139
else
@@ -155,6 +148,15 @@ Protocols::InteractionModel::Status CameraAVStreamManager::VideoStreamAllocate(c
155148
return Status::DynamicConstraintError;
156149
}
157150

151+
void CameraAVStreamManager::OnVideoStreamAllocated(const VideoStreamStruct & allocatedStream)
152+
{
153+
// Start the video stream using the final allocated parameters
154+
mCameraDeviceHAL->GetCameraHALInterface().StartVideoStream(allocatedStream);
155+
156+
// Set the current frame rate attribute from HAL once stream has started
157+
GetCameraAVStreamMgmtServer()->SetCurrentFrameRate(mCameraDeviceHAL->GetCameraHALInterface().GetCurrentFrameRate());
158+
}
159+
158160
Protocols::InteractionModel::Status CameraAVStreamManager::VideoStreamModify(const uint16_t streamID,
159161
const chip::Optional<bool> waterMarkEnabled,
160162
const chip::Optional<bool> osdEnabled)

src/app/clusters/camera-av-stream-management-server/camera-av-stream-management-server.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,9 @@ void CameraAVStreamMgmtServer::HandleVideoStreamAllocate(HandlerContext & ctx,
18041804

18051805
response.videoStreamID = videoStreamID;
18061806
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
1807+
1808+
// Call delegate with the final allocated stream parameters
1809+
mDelegate.OnVideoStreamAllocated(videoStreamArgs);
18071810
}
18081811
else
18091812
{

src/app/clusters/camera-av-stream-management-server/camera-av-stream-management-server.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ class CameraAVStreamMgmtDelegate
107107
virtual Protocols::InteractionModel::Status VideoStreamAllocate(const VideoStreamStruct & allocateArgs,
108108
uint16_t & outStreamID) = 0;
109109

110+
/**
111+
* @brief Called after the server has finalized video stream allocation and narrowed parameters.
112+
* This is where the actual video stream should be started using the final allocated parameters.
113+
*
114+
* @param allocatedStream The finalized video stream with narrowed parameters from the server.
115+
*/
116+
virtual void OnVideoStreamAllocated(const VideoStreamStruct & allocatedStream) = 0;
117+
110118
/**
111119
* @brief Handle Command Delegate for Video stream modification.
112120
*

0 commit comments

Comments
 (0)