Skip to content

Commit

Permalink
Remove mPlaybackSpeed/mCurrentState/mCurrentInput
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinpan1 committed Aug 26, 2024
1 parent 83f63e6 commit 9f80e54
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 47 deletions.
23 changes: 10 additions & 13 deletions examples/chef/common/clusters/media-input/MediaInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ MediaInputManager::MediaInputManager(chip::EndpointId endpoint) : mEndpoint(endp
struct InputData inputData3(3, chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi, "HDMI 3",
"High-Definition Multimedia Interface");
mInputs.push_back(inputData3);

// Sync the attributes from attribute storage
Status status = Attributes::CurrentInput::Get(endpoint, &mCurrentInput);

if (Status::Success != status)
{
ChipLogError(Zcl, "Unable to save CurrentInput attribute, err:0x%x", to_underlying(status));
mCurrentInput = 1;
}
}

CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncoder & aEncoder)
Expand All @@ -62,12 +53,18 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode

uint8_t MediaInputManager::HandleGetCurrentInput()
{
return mCurrentInput;
uint8_t currentInput = 1;
Status status = Attributes::CurrentInput::Get(mEndpoint, &currentInput);
if (Status::Success != status)
{
ChipLogError(Zcl, "Unable to save CurrentInput attribute, err:0x%x", to_underlying(status));
}
return currentInput;
}

bool MediaInputManager::HandleSelectInput(const uint8_t index)
{
if (mCurrentInput == index)
if (HandleGetCurrentInput() == index)
{
ChipLogProgress(Zcl, "CurrentInput is same as new value: %u", index);
return true;
Expand All @@ -76,7 +73,6 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)
{
if (inputData.index == index)
{
mCurrentInput = index;
// Sync the CurrentInput to attribute storage while reporting changes
Status status = chip::app::Clusters::MediaInput::Attributes::CurrentInput::Set(mEndpoint, index);
if (Status::Success != status)
Expand All @@ -92,11 +88,12 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)

bool MediaInputManager::HandleShowInputStatus()
{
uint8_t currentInput = HandleGetCurrentInput();
ChipLogProgress(Zcl, " MediaInputManager::HandleShowInputStatus()");
for (auto const & inputData : mInputs)
{
ChipLogProgress(Zcl, " [%d] type=%d selected=%d name=%s desc=%s", inputData.index,
static_cast<uint16_t>(inputData.inputType), (mCurrentInput == inputData.index ? 1 : 0),
static_cast<uint16_t>(inputData.inputType), (currentInput == inputData.index ? 1 : 0),
inputData.name.c_str(), inputData.description.c_str());
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class MediaInputManager : public chip::app::Clusters::MediaInput::Delegate

protected:
chip::EndpointId mEndpoint;
uint8_t mCurrentInput;
std::vector<InputData> mInputs;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,16 @@ using chip::app::AttributeValueEncoder;
using chip::app::CommandResponseHelper;
using chip::Protocols::InteractionModel::Status;

MediaPlaybackManager::MediaPlaybackManager(chip::EndpointId endpoint) : mEndpoint(endpoint)
PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState()
{
// Sync the attributes from attribute storage
Status status = Attributes::CurrentState::Get(endpoint, &mCurrentState);
if (Status::Success != status)
{
ChipLogError(Zcl, "Unable to save CurrentStage attribute, err:0x%x", to_underlying(status));
mCurrentState = chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying;
}
PlaybackStateEnum currentState = PlaybackStateEnum::kPlaying;

status = Attributes::PlaybackSpeed::Get(endpoint, &mPlaybackSpeed);
Status status = Attributes::CurrentState::Get(mEndpoint, &currentState);
if (Status::Success != status)
{
ChipLogError(Zcl, "Unable to save PlaybackSpeed attribute, err:0x%x", to_underlying(status));
mPlaybackSpeed = 1.0;
ChipLogError(Zcl, "Unable to save CurrentStage attribute, err:0x%x", to_underlying(status));
}
};

PlaybackStateEnum MediaPlaybackManager::HandleGetCurrentState()
{
return mCurrentState;
return currentState;
}

uint64_t MediaPlaybackManager::HandleGetStartTime()
Expand All @@ -73,7 +62,14 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder

float MediaPlaybackManager::HandleGetPlaybackSpeed()
{
return mPlaybackSpeed;
float playbackSpeed = 1.0;

Status status = Attributes::PlaybackSpeed::Get(mEndpoint, &playbackSpeed);
if (Status::Success != status)
{
ChipLogError(Zcl, "Unable to save PlaybackSpeed attribute, err:0x%x", to_underlying(status));
}
return playbackSpeed;
}

uint64_t MediaPlaybackManager::HandleGetSeekRangeStart()
Expand Down Expand Up @@ -120,8 +116,6 @@ CHIP_ERROR MediaPlaybackManager::HandleGetAvailableTextTracks(AttributeValueEnco

CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState(chip::app::Clusters::MediaPlayback::PlaybackStateEnum currentState)
{
mCurrentState = currentState;

Status status = Attributes::CurrentState::Set(mEndpoint, currentState);

if (Status::Success != status)
Expand All @@ -134,8 +128,6 @@ CHIP_ERROR MediaPlaybackManager::HandleSetCurrentState(chip::app::Clusters::Medi

CHIP_ERROR MediaPlaybackManager::HandleSetPlaybackSpeed(float playbackSpeed)
{
mPlaybackSpeed = playbackSpeed;

Status status = Attributes::PlaybackSpeed::Set(mEndpoint, playbackSpeed);

if (Status::Success != status)
Expand Down Expand Up @@ -183,7 +175,9 @@ void MediaPlaybackManager::HandleStop(CommandResponseHelper<Commands::PlaybackRe
void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
const chip::Optional<bool> & audioAdvanceUnmuted)
{
if (mPlaybackSpeed == kPlaybackMaxForwardSpeed)
float playbackSpeed = HandleGetPlaybackSpeed();

if (playbackSpeed == kPlaybackMaxForwardSpeed)
{
// if already at max speed, return error
Commands::PlaybackResponse::Type response;
Expand All @@ -194,10 +188,10 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::Pla
}

HandleSetCurrentState(PlaybackStateEnum::kPlaying);
float playbackSpeed = (mPlaybackSpeed <= 0 ? 1 : mPlaybackSpeed * 2);
// Normalize to correct range
playbackSpeed = (playbackSpeed <= 0 ? 1 : playbackSpeed * 2);
if (playbackSpeed > kPlaybackMaxForwardSpeed)
{
// don't exceed max speed
playbackSpeed = kPlaybackMaxForwardSpeed;
}
HandleSetPlaybackSpeed(playbackSpeed);
Expand All @@ -223,7 +217,9 @@ void MediaPlaybackManager::HandlePrevious(CommandResponseHelper<Commands::Playba
void MediaPlaybackManager::HandleRewind(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper,
const chip::Optional<bool> & audioAdvanceUnmuted)
{
if (mPlaybackSpeed == kPlaybackMaxRewindSpeed)
float playbackSpeed = HandleGetPlaybackSpeed();

if (playbackSpeed == kPlaybackMaxRewindSpeed)
{
// if already at max speed in reverse, return error
Commands::PlaybackResponse::Type response;
Expand All @@ -234,10 +230,10 @@ void MediaPlaybackManager::HandleRewind(CommandResponseHelper<Commands::Playback
}

HandleSetCurrentState(PlaybackStateEnum::kPlaying);
float playbackSpeed = (mPlaybackSpeed >= 0 ? -1 : mPlaybackSpeed * 2);
// Normalize to correct range
playbackSpeed = (playbackSpeed >= 0 ? -1 : playbackSpeed * 2);
if (playbackSpeed < kPlaybackMaxRewindSpeed)
{
// don't exceed max rewind speed
playbackSpeed = kPlaybackMaxRewindSpeed;
}
HandleSetPlaybackSpeed(playbackSpeed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate
using Feature = chip::app::Clusters::MediaPlayback::Feature;

public:
MediaPlaybackManager(chip::EndpointId endpoint);
MediaPlaybackManager(chip::EndpointId endpoint):mEndpoint(endpoint) {};

chip::app::Clusters::MediaPlayback::PlaybackStateEnum HandleGetCurrentState() override;
uint64_t HandleGetStartTime() override;
Expand Down Expand Up @@ -74,8 +74,6 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate
chip::EndpointId mEndpoint;
// NOTE: it does not make sense to have default state of playing with a speed of 0, but
// the CI test cases expect these values, and need to be fixed.
chip::app::Clusters::MediaPlayback::PlaybackStateEnum mCurrentState =
chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying;
PlaybackPositionType mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };
TrackType mActiveAudioTrack = { chip::CharSpan("activeAudioTrackId_0", 20),
chip::app::DataModel::Nullable<TrackAttributesType>(
Expand Down Expand Up @@ -107,7 +105,6 @@ class MediaPlaybackManager : public chip::app::Clusters::MediaPlayback::Delegate
chip::Optional<chip::app::DataModel::Nullable<chip::CharSpan>>(
{ chip::app::DataModel::MakeNullable(chip::CharSpan("displayName2", 12)) }) }) }
};
float mPlaybackSpeed = 1.0;
uint64_t mStartTime = 0;
// Magic number for testing.
uint64_t mDuration = 80000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2596,7 +2596,7 @@ endpoint 1 {
ram attribute startTime default = 0x00;
ram attribute duration default = 0;
callback attribute sampledPosition;
ram attribute playbackSpeed default = 0;
ram attribute playbackSpeed default = 1.0;
ram attribute seekRangeEnd;
ram attribute seekRangeStart;
callback attribute generatedCommandList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"defaultValue": "1.0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down

0 comments on commit 9f80e54

Please sign in to comment.