Skip to content

Commit

Permalink
Make CameraAVStreamMgmt handle list attributes inside cluster server …
Browse files Browse the repository at this point in the history
…implementation.
  • Loading branch information
pidarped committed Dec 9, 2024
1 parent a2f9d95 commit cf60e68
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,89 +105,44 @@ CameraAVStreamMgmtServer::ReadAndEncodeRateDistortionTradeOffPoints(const Attrib
{
CHIP_ERROR err = CHIP_NO_ERROR;

// Tell the delegate the read is starting..
ReturnErrorOnFailure(mDelegate.StartRateDistortionTradeOffPointsRead());

for (uint8_t i = 0; true; i++)
for (const auto& rateDistortionTradeOffPoints : mRateDistortionTradeOffPointsList)
{
Structs::RateDistortionTradeOffPointsStruct::Type rateDistortionTradeOffPoints;

err = mDelegate.GetRateDistortionTradeOffPointByIndex(i, rateDistortionTradeOffPoints);
SuccessOrExit(err);

err = encoder.Encode(rateDistortionTradeOffPoints);
SuccessOrExit(err);
}

exit:
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
{
// Convert end of list to CHIP_NO_ERROR
err = CHIP_NO_ERROR;
}

// Tell the delegate the read is complete
err = mDelegate.EndRateDistortionTradeOffPointsRead();
return err;
}

CHIP_ERROR CameraAVStreamMgmtServer::ReadAndEncodeSupportedSnapshotParams(const AttributeValueEncoder::ListEncodeHelper & encoder)
{
CHIP_ERROR err = CHIP_NO_ERROR;

// Tell the delegate the read is starting..
ReturnErrorOnFailure(mDelegate.StartSupportedSnapshotParamsRead());

for (uint8_t i = 0; true; i++)
for (const auto& snapshotParams : mSupportedSnapshotParamsList)
{
Structs::SnapshotParamsStruct::Type supportedSnapshotParams;

err = mDelegate.GetSupportedSnapshotParamByIndex(i, supportedSnapshotParams);
SuccessOrExit(err);

err = encoder.Encode(supportedSnapshotParams);
err = encoder.Encode(snapshotParams);
SuccessOrExit(err);
}

exit:
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
{
// Convert end of list to CHIP_NO_ERROR
err = CHIP_NO_ERROR;
}

// Tell the delegate the read is complete
err = mDelegate.EndSupportedSnapshotParamsRead();
return err;
}

CHIP_ERROR CameraAVStreamMgmtServer::ReadAndEncodeFabricsUsingCamera(const AttributeValueEncoder::ListEncodeHelper & encoder)
{
CHIP_ERROR err = CHIP_NO_ERROR;

// Tell the delegate the read is starting..
ReturnErrorOnFailure(mDelegate.StartFabricsUsingCameraRead());

for (uint8_t i = 0; true; i++)
for (const auto& fabricIndex : mFabricsUsingCamera)
{
chip::FabricIndex fabricIndex;

err = mDelegate.GetFabricUsingCameraByIndex(i, fabricIndex);
SuccessOrExit(err);

err = encoder.Encode(fabricIndex);
SuccessOrExit(err);
}

exit:
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
{
// Convert end of list to CHIP_NO_ERROR
err = CHIP_NO_ERROR;
}

// Tell the delegate the read is complete
err = mDelegate.EndFabricsUsingCameraRead();
return err;
}

Expand Down Expand Up @@ -286,29 +241,15 @@ CameraAVStreamMgmtServer::ReadAndEncodeRankedVideoStreamPrioritiesList(const Att
{
CHIP_ERROR err = CHIP_NO_ERROR;

// Tell the delegate the read is starting..
ReturnErrorOnFailure(mDelegate.StartRankedVideoStreamPrioritiesListRead());

for (uint8_t i = 0; true; i++)
for (uint8_t i = 0; i < kNumOfStreamTypes; i++)
{
detail::StreamTypeEnum streamType;

err = mDelegate.GetRankedVideoStreamPrioritiesListByIndex(i, streamType);
SuccessOrExit(err);

err = encoder.Encode(streamType);
err = encoder.Encode(mRankedVideoStreamPriorities[i]);
SuccessOrExit(err);
}

exit:
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
{
// Convert end of list to CHIP_NO_ERROR
err = CHIP_NO_ERROR;
}

// Tell the delegate the read is complete
err = mDelegate.EndRankedVideoStreamPrioritiesListRead();
return err;
}

Expand Down Expand Up @@ -1104,6 +1045,11 @@ void CameraAVStreamMgmtServer::LoadPersistentAttributes()
}

// TODO: Load allocated streams and ranked priorities list
// Load AllocatedVideoStreams

// Load AllocatedAudioStreams

// Load AllocatedSnapshotStreams

// Load SoftRecordingPrivacyModeEnabled
bool softRecordingPrivacyModeEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ using SnapshotParamsStruct = Structs::SnapshotParamsStruct::Type;
using VideoResolutionStruct = Structs::VideoResolutionStruct::Type;
using ViewportStruct = Structs::ViewportStruct::Type;

using VideoStreamList = chip::app::DataModel::List<VideoStreamStruct>;
using AudioStreamList = chip::app::DataModel::List<AudioStreamStruct>;
using SnapshotStreamList = chip::app::DataModel::List<SnapshotStreamStruct>;

constexpr uint8_t kMaxSpeakerLevel = 254;
constexpr uint8_t kMaxMicrophoneLevel = 254;
constexpr uint16_t kMaxImageRotationDegrees = 359;

constexpr size_t kViewportStructMaxSerializedSize =
TLV::EstimateStructOverhead(sizeof(uint16_t) * 4);

constexpr uint8_t kNumOfStreamTypes = 4;

class CameraAVStreamMgmtServer;

/** @brief
Expand Down Expand Up @@ -136,18 +142,6 @@ class CameraAVStreamMgmtDelegate
virtual CHIP_ERROR GetAllocatedSnapshotStreamByIndex(uint8_t, Structs::SnapshotStreamStruct::Type &) = 0;
virtual CHIP_ERROR EndAllocatedSnapshotStreamsRead() = 0;

virtual CHIP_ERROR StartRateDistortionTradeOffPointsRead() = 0;
virtual CHIP_ERROR GetRateDistortionTradeOffPointByIndex(uint8_t, Structs::RateDistortionTradeOffPointsStruct::Type &) = 0;
virtual CHIP_ERROR EndRateDistortionTradeOffPointsRead() = 0;

virtual CHIP_ERROR StartSupportedSnapshotParamsRead() = 0;
virtual CHIP_ERROR GetSupportedSnapshotParamByIndex(uint8_t, Structs::SnapshotParamsStruct::Type &) = 0;
virtual CHIP_ERROR EndSupportedSnapshotParamsRead() = 0;

virtual CHIP_ERROR StartFabricsUsingCameraRead() = 0;
virtual CHIP_ERROR GetFabricUsingCameraByIndex(uint8_t, chip::FabricIndex &) = 0;
virtual CHIP_ERROR EndFabricsUsingCameraRead() = 0;

virtual CHIP_ERROR StartRankedVideoStreamPrioritiesListRead() = 0;
virtual CHIP_ERROR GetRankedVideoStreamPrioritiesListByIndex(uint8_t, StreamTypeEnum &) = 0;
virtual CHIP_ERROR EndRankedVideoStreamPrioritiesListRead() = 0;
Expand Down Expand Up @@ -276,6 +270,49 @@ class CameraAVStreamMgmtServer : public CommandHandlerInterface, public Attribut

EndpointId GetEndpointId() { return AttributeAccessInterface::GetEndpointId().Value(); }

CHIP_ERROR AddToFabricsUsingCamera(chip::FabricIndex aFabricIndex)
{
mFabricsUsingCamera.insert(aFabricIndex);
return CHIP_NO_ERROR;
}

CHIP_ERROR RemoveFromFabricsUsingCamera(chip::FabricIndex aFabricIndex)
{
mFabricsUsingCamera.erase(aFabricIndex);
return CHIP_NO_ERROR;
}

CHIP_ERROR AddToRateDistortionTradeOffPointsList(Structs::RateDistortionTradeOffPointsStruct::Type aRateDistortionTradeOffPoints)
{
mRateDistortionTradeOffPointsList.push_back(aRateDistortionTradeOffPoints);

return CHIP_NO_ERROR;
}

CHIP_ERROR ClearRateDistortionTradeOffPointsList()
{
mRateDistortionTradeOffPointsList.clear();
return CHIP_NO_ERROR;
}

CHIP_ERROR AddToSupportedSnapshotParamssList(Structs::SnapshotParamsStruct::Type aSupportedSnapshotParams)
{
mSupportedSnapshotParamsList.push_back(aSupportedSnapshotParams);

return CHIP_NO_ERROR;
}

CHIP_ERROR ClearSnapshotParamsList()
{
mSupportedSnapshotParamsList.clear();
return CHIP_NO_ERROR;
}

CHIP_ERROR SetRankedVideoStreamPriorities(const uint8_t newPriorities[kNumOfStreamTypes])
{
std::copy(newPriorities, newPriorities + kNumOfStreamTypes, mRankedVideoStreamPriorities);
return CHIP_NO_ERROR;
}
private:
CameraAVStreamMgmtDelegate & mDelegate;
EndpointId mEndpointId;
Expand Down Expand Up @@ -321,6 +358,15 @@ class CameraAVStreamMgmtServer : public CommandHandlerInterface, public Attribut
bool mStatusLightEnabled = false;
Globals::ThreeLevelAutoEnum mStatusLightBrightness;

// Managed lists
std::unordered_set<chip::FabricIndex> mFabricsUsingCamera;

std::vector<Structs::RateDistortionTradeOffPointsStruct::Type> mRateDistortionTradeOffPointsList;

std::vector<Structs::SnapshotParamsStruct::Type> mSupportedSnapshotParamsList;

uint8_t mRankedVideoStreamPriorities[kNumOfStreamTypes];

/**
* IM-level implementation of read
* @return appropriately mapped CHIP_ERROR if applicable
Expand Down

0 comments on commit cf60e68

Please sign in to comment.