mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
CI: add astyle pre-commit hook
This commit is contained in:
@@ -57,8 +57,8 @@ CameraError CameraDevice::InitializeStreams()
|
||||
|
||||
// Find the closest allocated snapshot stream with resolution >= requested, or
|
||||
// closest possible
|
||||
bool CameraDevice::MatchClosestSnapshotParams(const VideoResolutionStruct & requested, VideoResolutionStruct & matchedResolution,
|
||||
ImageCodecEnum & matchedCodec)
|
||||
bool CameraDevice::MatchClosestSnapshotParams(const VideoResolutionStruct &requested, VideoResolutionStruct &matchedResolution,
|
||||
ImageCodecEnum &matchedCodec)
|
||||
{
|
||||
int64_t requestedPixels = static_cast<int64_t>(requested.width) * requested.height;
|
||||
int64_t bestDiff = std::numeric_limits<int64_t>::max();
|
||||
@@ -67,31 +67,27 @@ bool CameraDevice::MatchClosestSnapshotParams(const VideoResolutionStruct & requ
|
||||
const SnapshotStream * bestStream = nullptr;
|
||||
const SnapshotStream * bestGEQStream = nullptr;
|
||||
|
||||
for (const auto & stream : mSnapshotStreams)
|
||||
{
|
||||
for (const auto &stream : mSnapshotStreams) {
|
||||
int64_t streamPixels = static_cast<int64_t>(stream.snapshotStreamParams.minResolution.width) *
|
||||
stream.snapshotStreamParams.minResolution.height;
|
||||
stream.snapshotStreamParams.minResolution.height;
|
||||
int64_t diff = streamPixels - requestedPixels;
|
||||
int64_t absDiff = std::abs(diff);
|
||||
|
||||
// Candidate 1: First stream with resolution >= requested
|
||||
if (diff >= 0 && diff < bestGEQDiff)
|
||||
{
|
||||
if (diff >= 0 && diff < bestGEQDiff) {
|
||||
bestGEQDiff = diff;
|
||||
bestGEQStream = &stream;
|
||||
}
|
||||
|
||||
// Candidate 2: Closest stream (absolute difference)
|
||||
if (absDiff < bestDiff)
|
||||
{
|
||||
if (absDiff < bestDiff) {
|
||||
bestDiff = absDiff;
|
||||
bestStream = &stream;
|
||||
}
|
||||
}
|
||||
|
||||
const SnapshotStream * chosen = bestGEQStream ? bestGEQStream : bestStream;
|
||||
if (chosen)
|
||||
{
|
||||
if (chosen) {
|
||||
matchedResolution = chosen->snapshotStreamParams.minResolution;
|
||||
matchedCodec = chosen->snapshotStreamParams.imageCodec;
|
||||
return true;
|
||||
@@ -100,28 +96,23 @@ bool CameraDevice::MatchClosestSnapshotParams(const VideoResolutionStruct & requ
|
||||
}
|
||||
|
||||
CameraError CameraDevice::CaptureSnapshot(const chip::app::DataModel::Nullable<uint16_t> streamID,
|
||||
const VideoResolutionStruct & resolution, ImageSnapshot & outImageSnapshot)
|
||||
const VideoResolutionStruct &resolution, ImageSnapshot &outImageSnapshot)
|
||||
{
|
||||
VideoResolutionStruct matchedRes;
|
||||
ImageCodecEnum matchedCodec;
|
||||
|
||||
if (streamID.IsNull())
|
||||
{
|
||||
if (!MatchClosestSnapshotParams(resolution, matchedRes, matchedCodec))
|
||||
{
|
||||
if (streamID.IsNull()) {
|
||||
if (!MatchClosestSnapshotParams(resolution, matchedRes, matchedCodec)) {
|
||||
ChipLogError(Camera, "No matching snapshot stream found for requested resolution %ux%u", resolution.width,
|
||||
resolution.height);
|
||||
return CameraError::ERROR_CAPTURE_SNAPSHOT_FAILED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint16_t streamId = streamID.Value();
|
||||
auto it = std::find_if(mSnapshotStreams.begin(), mSnapshotStreams.end(), [streamId](const SnapshotStream & s) {
|
||||
return s.snapshotStreamParams.snapshotStreamID == streamId;
|
||||
});
|
||||
if (it == mSnapshotStreams.end())
|
||||
{
|
||||
if (it == mSnapshotStreams.end()) {
|
||||
ChipLogError(Camera, "Snapshot stream not found for stream ID %u", streamId);
|
||||
return CameraError::ERROR_CAPTURE_SNAPSHOT_FAILED;
|
||||
}
|
||||
@@ -152,17 +143,15 @@ CameraError CameraDevice::CaptureSnapshot(const chip::app::DataModel::Nullable<u
|
||||
}
|
||||
|
||||
// Allocate snapshot stream
|
||||
CameraError CameraDevice::AllocateSnapshotStream(const CameraAVStreamManagementDelegate::SnapshotStreamAllocateArgs & args,
|
||||
uint16_t & outStreamID)
|
||||
CameraError CameraDevice::AllocateSnapshotStream(const CameraAVStreamManagementDelegate::SnapshotStreamAllocateArgs &args,
|
||||
uint16_t &outStreamID)
|
||||
{
|
||||
|
||||
if (AddSnapshotStream(args, outStreamID))
|
||||
{
|
||||
if (AddSnapshotStream(args, outStreamID)) {
|
||||
auto it = std::find_if(mSnapshotStreams.begin(), mSnapshotStreams.end(), [outStreamID](const SnapshotStream & s) {
|
||||
return s.snapshotStreamParams.snapshotStreamID == outStreamID;
|
||||
});
|
||||
if (it == mSnapshotStreams.end())
|
||||
{
|
||||
if (it == mSnapshotStreams.end()) {
|
||||
ChipLogError(Camera, "Snapshot stream with ID %u not found", outStreamID);
|
||||
return CameraError::ERROR_RESOURCE_EXHAUSTED;
|
||||
}
|
||||
@@ -183,10 +172,11 @@ uint32_t CameraDevice::GetMaxEncodedPixelRate()
|
||||
return kMaxEncodedPixelRate;
|
||||
}
|
||||
|
||||
VideoSensorParamsStruct & CameraDevice::GetVideoSensorParams()
|
||||
VideoSensorParamsStruct &CameraDevice::GetVideoSensorParams()
|
||||
{
|
||||
static VideoSensorParamsStruct videoSensorParams = { kVideoSensorWidthPixels, kVideoSensorHeightPixels, kMaxVideoFrameRate,
|
||||
chip::Optional<uint16_t>(30) }; // Typical numbers for Pi camera.
|
||||
chip::Optional<uint16_t>(30)
|
||||
}; // Typical numbers for Pi camera.
|
||||
return videoSensorParams;
|
||||
}
|
||||
|
||||
@@ -225,17 +215,18 @@ bool CameraDevice::GetCameraSupportsImageControl()
|
||||
return false;
|
||||
}
|
||||
|
||||
VideoResolutionStruct & CameraDevice::GetMinViewport()
|
||||
VideoResolutionStruct &CameraDevice::GetMinViewport()
|
||||
{
|
||||
static VideoResolutionStruct minViewport = { kMinResolutionWidth, kMinResolutionHeight };
|
||||
return minViewport;
|
||||
}
|
||||
|
||||
std::vector<RateDistortionTradeOffStruct> & CameraDevice::GetRateDistortionTradeOffPoints()
|
||||
std::vector<RateDistortionTradeOffStruct> &CameraDevice::GetRateDistortionTradeOffPoints()
|
||||
{
|
||||
static std::vector<RateDistortionTradeOffStruct> rateDistTradeOffs = { {
|
||||
VideoCodecEnum::kH264, { kMinResolutionWidth, kMinResolutionHeight }, 10000 /* bitrate */
|
||||
} };
|
||||
VideoCodecEnum::kH264, { kMinResolutionWidth, kMinResolutionHeight }, 10000 /* bitrate */
|
||||
}
|
||||
};
|
||||
return rateDistTradeOffs;
|
||||
}
|
||||
|
||||
@@ -244,33 +235,37 @@ uint32_t CameraDevice::GetMaxContentBufferSize()
|
||||
return kMaxContentBufferSizeBytes;
|
||||
}
|
||||
|
||||
AudioCapabilitiesStruct & CameraDevice::GetMicrophoneCapabilities()
|
||||
AudioCapabilitiesStruct &CameraDevice::GetMicrophoneCapabilities()
|
||||
{
|
||||
static std::array<AudioCodecEnum, 2> audioCodecs = { AudioCodecEnum::kOpus, AudioCodecEnum::kAacLc };
|
||||
static std::array<uint32_t, 2> sampleRates = { 48000, 32000 }; // Sample rates in Hz
|
||||
static std::array<uint8_t, 2> bitDepths = { 24, 32 };
|
||||
static AudioCapabilitiesStruct audioCapabilities = { kMicrophoneMaxChannelCount, chip::Span<AudioCodecEnum>(audioCodecs),
|
||||
chip::Span<uint32_t>(sampleRates), chip::Span<uint8_t>(bitDepths) };
|
||||
chip::Span<uint32_t>(sampleRates), chip::Span<uint8_t>(bitDepths)
|
||||
};
|
||||
return audioCapabilities;
|
||||
}
|
||||
|
||||
AudioCapabilitiesStruct & CameraDevice::GetSpeakerCapabilities()
|
||||
AudioCapabilitiesStruct &CameraDevice::GetSpeakerCapabilities()
|
||||
{
|
||||
static std::array<AudioCodecEnum, 2> audioCodecs = { AudioCodecEnum::kOpus, AudioCodecEnum::kAacLc };
|
||||
static std::array<uint32_t, 2> sampleRates = { 48000, 32000 }; // Sample rates in Hz
|
||||
static std::array<uint8_t, 2> bitDepths = { 24, 32 };
|
||||
static AudioCapabilitiesStruct speakerCapabilities = { kSpeakerMaxChannelCount, chip::Span<AudioCodecEnum>(audioCodecs),
|
||||
chip::Span<uint32_t>(sampleRates), chip::Span<uint8_t>(bitDepths) };
|
||||
chip::Span<uint32_t>(sampleRates), chip::Span<uint8_t>(bitDepths)
|
||||
};
|
||||
return speakerCapabilities;
|
||||
}
|
||||
|
||||
std::vector<SnapshotCapabilitiesStruct> & CameraDevice::GetSnapshotCapabilities()
|
||||
std::vector<SnapshotCapabilitiesStruct> &CameraDevice::GetSnapshotCapabilities()
|
||||
{
|
||||
static std::vector<SnapshotCapabilitiesStruct> snapshotCapabilities = { { { kMinResolutionWidth, kMinResolutionHeight },
|
||||
kSnapshotStreamFrameRate,
|
||||
ImageCodecEnum::kJpeg,
|
||||
false,
|
||||
chip::MakeOptional(static_cast<bool>(false)) } };
|
||||
kSnapshotStreamFrameRate,
|
||||
ImageCodecEnum::kJpeg,
|
||||
false,
|
||||
chip::MakeOptional(static_cast<bool>(false))
|
||||
}
|
||||
};
|
||||
return snapshotCapabilities;
|
||||
}
|
||||
|
||||
@@ -313,21 +308,21 @@ CameraError CameraDevice::SetStreamUsagePriorities(std::vector<StreamUsageEnum>
|
||||
return CameraError::SUCCESS;
|
||||
}
|
||||
|
||||
std::vector<StreamUsageEnum> & CameraDevice::GetSupportedStreamUsages()
|
||||
std::vector<StreamUsageEnum> &CameraDevice::GetSupportedStreamUsages()
|
||||
{
|
||||
static std::vector<StreamUsageEnum> supportedStreamUsage = { StreamUsageEnum::kLiveView, StreamUsageEnum::kRecording };
|
||||
return supportedStreamUsage;
|
||||
}
|
||||
|
||||
CameraError CameraDevice::SetViewport(const chip::app::Clusters::Globals::Structs::ViewportStruct::Type & viewPort)
|
||||
CameraError CameraDevice::SetViewport(const chip::app::Clusters::Globals::Structs::ViewportStruct::Type &viewPort)
|
||||
{
|
||||
mViewport = viewPort;
|
||||
|
||||
return CameraError::SUCCESS;
|
||||
}
|
||||
|
||||
CameraError CameraDevice::SetViewport(VideoStream & stream,
|
||||
const chip::app::Clusters::Globals::Structs::ViewportStruct::Type & viewport)
|
||||
CameraError CameraDevice::SetViewport(VideoStream &stream,
|
||||
const chip::app::Clusters::Globals::Structs::ViewportStruct::Type &viewport)
|
||||
{
|
||||
ChipLogDetail(Camera, "Setting per stream viewport for stream %d.", stream.videoStreamParams.videoStreamID);
|
||||
ChipLogDetail(Camera, "New viewport. x1=%d, x2=%d, y1=%d, y2=%d.", viewport.x1, viewport.x2, viewport.y1, viewport.y2);
|
||||
@@ -432,66 +427,69 @@ void CameraDevice::InitializeVideoStreams()
|
||||
// Create a video stream with a max resolution of 720p and max frame rate of
|
||||
// 60 fps
|
||||
VideoStream videoStream1 = { {
|
||||
1 /* Id */,
|
||||
StreamUsageEnum::kLiveView /* StreamUsage */,
|
||||
VideoCodecEnum::kH264,
|
||||
kMinVideoFrameRate /* MinFrameRate */,
|
||||
k60fpsVideoFrameRate /* MaxFrameRate */,
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution */,
|
||||
{ k720pResolutionWidth, k720pResolutionHeight } /* MaxResolution */,
|
||||
kMinBitRateBps /* MinBitRate */,
|
||||
kMaxBitRateBps /* MaxBitRate */,
|
||||
kKeyFrameIntervalMsec /* KeyFrameInterval */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* WMark */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* OSD */,
|
||||
0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
{ mViewport.x1, mViewport.y1, mViewport.x2, mViewport.y2 },
|
||||
nullptr };
|
||||
1 /* Id */,
|
||||
StreamUsageEnum::kLiveView /* StreamUsage */,
|
||||
VideoCodecEnum::kH264,
|
||||
kMinVideoFrameRate /* MinFrameRate */,
|
||||
k60fpsVideoFrameRate /* MaxFrameRate */,
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution */,
|
||||
{ k720pResolutionWidth, k720pResolutionHeight } /* MaxResolution */,
|
||||
kMinBitRateBps /* MinBitRate */,
|
||||
kMaxBitRateBps /* MaxBitRate */,
|
||||
kKeyFrameIntervalMsec /* KeyFrameInterval */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* WMark */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* OSD */,
|
||||
0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
{ mViewport.x1, mViewport.y1, mViewport.x2, mViewport.y2 },
|
||||
nullptr
|
||||
};
|
||||
mVideoStreams.push_back(videoStream1);
|
||||
|
||||
// Create a video stream for the full range(fps, resolution, bitrate)
|
||||
// supported by the camera.
|
||||
VideoStream videoStream2 = { {
|
||||
2 /* Id */,
|
||||
StreamUsageEnum::kLiveView /* StreamUsage */,
|
||||
VideoCodecEnum::kH264,
|
||||
kMinVideoFrameRate /* MinFrameRate */,
|
||||
k60fpsVideoFrameRate /* MaxFrameRate */,
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution */,
|
||||
{ kMaxResolutionWidth, kMaxResolutionHeight } /* MaxResolution */,
|
||||
kMinBitRateBps /* MinBitRate */,
|
||||
kMaxBitRateBps /* MaxBitRate */,
|
||||
kKeyFrameIntervalMsec /* KeyFrameInterval */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* WMark */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* OSD */,
|
||||
0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
{ mViewport.x1, mViewport.y1, mViewport.x2, mViewport.y2 },
|
||||
nullptr };
|
||||
2 /* Id */,
|
||||
StreamUsageEnum::kLiveView /* StreamUsage */,
|
||||
VideoCodecEnum::kH264,
|
||||
kMinVideoFrameRate /* MinFrameRate */,
|
||||
k60fpsVideoFrameRate /* MaxFrameRate */,
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution */,
|
||||
{ kMaxResolutionWidth, kMaxResolutionHeight } /* MaxResolution */,
|
||||
kMinBitRateBps /* MinBitRate */,
|
||||
kMaxBitRateBps /* MaxBitRate */,
|
||||
kKeyFrameIntervalMsec /* KeyFrameInterval */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* WMark */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* OSD */,
|
||||
0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
{ mViewport.x1, mViewport.y1, mViewport.x2, mViewport.y2 },
|
||||
nullptr
|
||||
};
|
||||
|
||||
mVideoStreams.push_back(videoStream2);
|
||||
|
||||
VideoStream videoStream3 = { {
|
||||
3 /* Id */,
|
||||
StreamUsageEnum::kLiveView /* StreamUsage */,
|
||||
VideoCodecEnum::kH264,
|
||||
kMinVideoFrameRate /* MinFrameRate */,
|
||||
k60fpsVideoFrameRate /* MaxFrameRate */,
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution */,
|
||||
{ kMaxResolutionWidth, kMaxResolutionHeight } /* MaxResolution */,
|
||||
kMinBitRateBps /* MinBitRate */,
|
||||
kMaxBitRateBps /* MaxBitRate */,
|
||||
kKeyFrameIntervalMsec /* KeyFrameInterval */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* WMark */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* OSD */,
|
||||
0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
{ mViewport.x1, mViewport.y1, mViewport.x2, mViewport.y2 },
|
||||
nullptr };
|
||||
3 /* Id */,
|
||||
StreamUsageEnum::kLiveView /* StreamUsage */,
|
||||
VideoCodecEnum::kH264,
|
||||
kMinVideoFrameRate /* MinFrameRate */,
|
||||
k60fpsVideoFrameRate /* MaxFrameRate */,
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution */,
|
||||
{ kMaxResolutionWidth, kMaxResolutionHeight } /* MaxResolution */,
|
||||
kMinBitRateBps /* MinBitRate */,
|
||||
kMaxBitRateBps /* MaxBitRate */,
|
||||
kKeyFrameIntervalMsec /* KeyFrameInterval */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* WMark */,
|
||||
chip::MakeOptional(static_cast<bool>(false)) /* OSD */,
|
||||
0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
{ mViewport.x1, mViewport.y1, mViewport.x2, mViewport.y2 },
|
||||
nullptr
|
||||
};
|
||||
|
||||
mVideoStreams.push_back(videoStream3);
|
||||
}
|
||||
@@ -501,30 +499,33 @@ void CameraDevice::InitializeAudioStreams()
|
||||
|
||||
// Mono stream
|
||||
AudioStream monoStream = { {
|
||||
1 /* Id */, StreamUsageEnum::kLiveView, AudioCodecEnum::kOpus, 1 /* ChannelCount: Mono */,
|
||||
48000 /* SampleRate */, 20000 /* BitRate */, 24 /* BitDepth */, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr };
|
||||
1 /* Id */, StreamUsageEnum::kLiveView, AudioCodecEnum::kOpus, 1 /* ChannelCount: Mono */,
|
||||
48000 /* SampleRate */, 20000 /* BitRate */, 24 /* BitDepth */, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr
|
||||
};
|
||||
mAudioStreams.push_back(monoStream);
|
||||
|
||||
// Stereo stream
|
||||
AudioStream stereoStream = { {
|
||||
2 /* Id */, StreamUsageEnum::kLiveView, AudioCodecEnum::kOpus, 2 /* ChannelCount: Stereo */,
|
||||
48000 /* SampleRate */, 32000 /* BitRate */, 24 /* BitDepth */, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr };
|
||||
2 /* Id */, StreamUsageEnum::kLiveView, AudioCodecEnum::kOpus, 2 /* ChannelCount: Stereo */,
|
||||
48000 /* SampleRate */, 32000 /* BitRate */, 24 /* BitDepth */, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr
|
||||
};
|
||||
mAudioStreams.push_back(stereoStream);
|
||||
|
||||
// Max channel count stream (from spec constant)
|
||||
AudioStream maxChannelStream = { {
|
||||
3 /* Id */, StreamUsageEnum::kLiveView, AudioCodecEnum::kOpus,
|
||||
kMicrophoneMaxChannelCount /* Max from Spec */, 48000 /* SampleRate */,
|
||||
64000 /* BitRate */, 24 /* BitDepth */, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr };
|
||||
3 /* Id */, StreamUsageEnum::kLiveView, AudioCodecEnum::kOpus,
|
||||
kMicrophoneMaxChannelCount /* Max from Spec */, 48000 /* SampleRate */,
|
||||
64000 /* BitRate */, 24 /* BitDepth */, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr
|
||||
};
|
||||
mAudioStreams.push_back(maxChannelStream);
|
||||
}
|
||||
|
||||
@@ -534,19 +535,18 @@ void CameraDevice::InitializeSnapshotStreams()
|
||||
uint16_t streamId = kInvalidStreamID;
|
||||
AddSnapshotStream({ ImageCodecEnum::kJpeg,
|
||||
kSnapshotStreamFrameRate /* FrameRate */,
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution*/,
|
||||
{ kMaxResolutionWidth, kMaxResolutionHeight } /* MaxResolution */,
|
||||
90 /* Quality */ },
|
||||
streamId);
|
||||
{ kMinResolutionWidth, kMinResolutionHeight } /* MinResolution*/,
|
||||
{ kMaxResolutionWidth, kMaxResolutionHeight } /* MaxResolution */,
|
||||
90 /* Quality */ },
|
||||
streamId);
|
||||
}
|
||||
|
||||
bool CameraDevice::AddSnapshotStream(
|
||||
const CameraAVStreamManagementDelegate::SnapshotStreamAllocateArgs & snapshotStreamAllocateArgs, uint16_t & outStreamID)
|
||||
const CameraAVStreamManagementDelegate::SnapshotStreamAllocateArgs &snapshotStreamAllocateArgs, uint16_t &outStreamID)
|
||||
{
|
||||
constexpr uint16_t kMaxSnapshotStreams = std::numeric_limits<uint16_t>::max();
|
||||
|
||||
if (mSnapshotStreams.size() >= kMaxSnapshotStreams)
|
||||
{
|
||||
if (mSnapshotStreams.size() >= kMaxSnapshotStreams) {
|
||||
ChipLogError(Camera, "Maximum number of snapshot streams reached. Cannot allocate new one");
|
||||
return false;
|
||||
}
|
||||
@@ -556,30 +556,24 @@ bool CameraDevice::AddSnapshotStream(
|
||||
// the ID that was passed in. A valid streamID would be passed in when the
|
||||
// stream list is being constructed from the persisted list of allocated
|
||||
// streams that was loaded at Init()
|
||||
if (outStreamID == kInvalidStreamID)
|
||||
{
|
||||
for (const auto & s : mSnapshotStreams)
|
||||
{
|
||||
if (outStreamID == kInvalidStreamID) {
|
||||
for (const auto &s : mSnapshotStreams) {
|
||||
// Find the highest existing stream ID.
|
||||
if (s.snapshotStreamParams.snapshotStreamID > streamId)
|
||||
{
|
||||
if (s.snapshotStreamParams.snapshotStreamID > streamId) {
|
||||
streamId = s.snapshotStreamParams.snapshotStreamID;
|
||||
}
|
||||
}
|
||||
|
||||
// Find a unique stream id, starting from the last used one above,
|
||||
// incrementing and wrapping at 65535.
|
||||
for (uint16_t attempts = 0; attempts < kMaxSnapshotStreams; ++attempts)
|
||||
{
|
||||
for (uint16_t attempts = 0; attempts < kMaxSnapshotStreams; ++attempts) {
|
||||
auto found = std::find_if(mSnapshotStreams.begin(), mSnapshotStreams.end(), [streamId](const SnapshotStream & s) {
|
||||
return s.snapshotStreamParams.snapshotStreamID == streamId;
|
||||
});
|
||||
if (found == mSnapshotStreams.end())
|
||||
{
|
||||
if (found == mSnapshotStreams.end()) {
|
||||
break;
|
||||
}
|
||||
if (attempts == kMaxSnapshotStreams - 1)
|
||||
{
|
||||
if (attempts == kMaxSnapshotStreams - 1) {
|
||||
ChipLogError(Camera, "No available slot for stream allocation");
|
||||
return false;
|
||||
}
|
||||
@@ -587,39 +581,35 @@ bool CameraDevice::AddSnapshotStream(
|
||||
}
|
||||
|
||||
outStreamID = streamId;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Have a sanity check that the passed streamID does not already exist
|
||||
// in the list
|
||||
auto found = std::find_if(mSnapshotStreams.begin(), mSnapshotStreams.end(), [outStreamID](const SnapshotStream & s) {
|
||||
return s.snapshotStreamParams.snapshotStreamID == outStreamID;
|
||||
});
|
||||
|
||||
if (found == mSnapshotStreams.end())
|
||||
{
|
||||
if (found == mSnapshotStreams.end()) {
|
||||
streamId = outStreamID;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ChipLogError(Camera, "StreamID %d already exists in the available snapshot stream list", outStreamID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SnapshotStream snapshotStream = { {
|
||||
streamId, snapshotStreamAllocateArgs.imageCodec, snapshotStreamAllocateArgs.maxFrameRate,
|
||||
snapshotStreamAllocateArgs.minResolution, snapshotStreamAllocateArgs.maxResolution,
|
||||
snapshotStreamAllocateArgs.quality, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr };
|
||||
streamId, snapshotStreamAllocateArgs.imageCodec, snapshotStreamAllocateArgs.maxFrameRate,
|
||||
snapshotStreamAllocateArgs.minResolution, snapshotStreamAllocateArgs.maxResolution,
|
||||
snapshotStreamAllocateArgs.quality, 0 /* RefCount */
|
||||
},
|
||||
false,
|
||||
nullptr
|
||||
};
|
||||
|
||||
mSnapshotStreams.push_back(snapshotStream);
|
||||
return true;
|
||||
}
|
||||
|
||||
WebRTCTransportProvider::Delegate & CameraDevice::GetWebRTCProviderDelegate()
|
||||
WebRTCTransportProvider::Delegate &CameraDevice::GetWebRTCProviderDelegate()
|
||||
{
|
||||
return mWebRTCProviderManager;
|
||||
}
|
||||
@@ -629,12 +619,12 @@ void CameraDevice::SetWebRTCTransportProvider(WebRTCTransportProvider::WebRTCTra
|
||||
mWebRTCProviderManager.SetWebRTCTransportProvider(provider);
|
||||
}
|
||||
|
||||
CameraAVStreamManagementDelegate & CameraDevice::GetCameraAVStreamMgmtDelegate()
|
||||
CameraAVStreamManagementDelegate &CameraDevice::GetCameraAVStreamMgmtDelegate()
|
||||
{
|
||||
return mCameraAVStreamManager;
|
||||
}
|
||||
|
||||
CameraAVStreamController & CameraDevice::GetCameraAVStreamMgmtController()
|
||||
CameraAVStreamController &CameraDevice::GetCameraAVStreamMgmtController()
|
||||
{
|
||||
return mCameraAVStreamManager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user