Skip to content

Commit

Permalink
Fix Android ContentLauncher and MediaPlayback (#22711)
Browse files Browse the repository at this point in the history
* Fix 22710

* Fix media playback tests on android

* address feedback

* Restyle Fix null pointer in Android ContentLauncher search query used in TC-CONTENTLAUNCHER-10.3 (#22712)

* Restyled by whitespace

* Restyled by google-java-format

Co-authored-by: Restyled.io <[email protected]>

* fix build

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Dec 6, 2023
1 parent 47ee5dd commit 6a9909a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
40 changes: 36 additions & 4 deletions examples/tv-app/android/java/MediaPlaybackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ uint64_t MediaPlaybackManager::HandleGetDuration()

float MediaPlaybackManager::HandleGetPlaybackSpeed()
{
uint64_t ret = HandleMediaRequestGetAttribute(MEDIA_PLAYBACK_ATTRIBUTE_SPEED);
return static_cast<float>(ret) / 10000.0f;
long ret = HandleMediaRequestGetLongAttribute(MEDIA_PLAYBACK_ATTRIBUTE_SPEED);
return static_cast<float>(ret);
}

uint64_t MediaPlaybackManager::HandleGetSeekRangeStart()
Expand Down Expand Up @@ -220,6 +220,38 @@ uint64_t MediaPlaybackManager::HandleMediaRequestGetAttribute(MediaPlaybackReque
return ret;
}

long MediaPlaybackManager::HandleMediaRequestGetLongAttribute(MediaPlaybackRequestAttribute attribute)
{
long ret = 0;
jlong jAttributeValue = -1;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();

ChipLogProgress(Zcl, "Received MediaPlaybackManager::HandleMediaRequestGetLongAttribute:%d", attribute);
VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetAttributeMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

jAttributeValue = env->CallLongMethod(mMediaPlaybackManagerObject, mGetAttributeMethod, static_cast<jint>(attribute));
if (env->ExceptionCheck())
{
ChipLogError(AppServer, "Java exception in MediaPlaybackManager::GetAttribute");
env->ExceptionDescribe();
env->ExceptionClear();
goto exit;
}

ret = static_cast<long>(jAttributeValue);

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "MediaPlaybackManager::GetAttribute status error: %s", err.AsString());
}

return ret;
}

Commands::PlaybackResponse::Type MediaPlaybackManager::HandleMediaRequest(MediaPlaybackRequest mediaPlaybackRequest,
uint64_t deltaPositionMilliseconds)

Expand Down Expand Up @@ -287,8 +319,8 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder
jclass inputClass = env->GetObjectClass(positionObj);
jfieldID positionId = env->GetFieldID(inputClass, "position", "J");
jfieldID updatedAtId = env->GetFieldID(inputClass, "updatedAt", "J");
response.position = Nullable<uint64_t>(static_cast<uint64_t>(env->GetIntField(positionObj, positionId)));
response.updatedAt = static_cast<uint64_t>(env->GetIntField(positionObj, updatedAtId));
response.position = Nullable<uint64_t>(static_cast<uint64_t>(env->GetLongField(positionObj, positionId)));
response.updatedAt = static_cast<uint64_t>(env->GetLongField(positionObj, updatedAtId));
}

exit:
Expand Down
1 change: 1 addition & 0 deletions examples/tv-app/android/java/MediaPlaybackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class MediaPlaybackManager : public MediaPlaybackDelegate
jmethodID mGetPositionMethod = nullptr;

uint64_t HandleMediaRequestGetAttribute(MediaPlaybackRequestAttribute attribute);
long HandleMediaRequestGetLongAttribute(MediaPlaybackRequestAttribute attribute);
chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type
HandleMediaRequest(MediaPlaybackRequest mediaPlaybackRequest, uint64_t deltaPositionMilliseconds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ public ContentLaunchResponse launchContent(
Log.d(TAG, "launchContent:" + data + " autoplay=" + autoplay + " at " + endpoint);

boolean found = false;
for (ContentLaunchEntry entry : entries) {
for (ContentLaunchSearchParameter parameter : entry.parameters) {
for (ContentLaunchSearchParameter query : search) {
if (query.type == parameter.type && query.data.equals(parameter.data)) {
Log.d(TAG, " TEST CASE found match=" + entry.name);
found = true;
if ((entries != null) && (search != null)) {
for (ContentLaunchEntry entry : entries) {
if (entry.parameters == null) {
continue;
}
for (ContentLaunchSearchParameter parameter : entry.parameters) {
for (ContentLaunchSearchParameter query : search) {
if (query.type == parameter.type && query.data.equals(parameter.data)) {
Log.d(TAG, " TEST CASE found match=" + entry.name);
found = true;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,19 @@ public long getAttributes(int attributesId) {
return playbackDuration;

case ATTRIBUTE_PLAYBACK_SPEED:
Log.d(TAG, "getAttributes SampledPosition PlaybackSpeed at " + endpoint);
Log.d(
TAG,
"getAttributes SampledPosition PlaybackSpeed " + playbackSpeed + " at " + endpoint);
return playbackSpeed;

case ATTRIBUTE_PLAYBACK_SEEK_RANGE_END:
Log.d(TAG, "getAttributes SampledPosition SeekRangeEnd at " + endpoint);
Log.d(
TAG,
"getAttributes SampledPosition SeekRangeEnd " + playbackDuration + " at " + endpoint);
return playbackDuration;

case ATTRIBUTE_PLAYBACK_SEEK_RANGE_START:
Log.d(TAG, "getAttributes SampledPosition SeekRangeStart at " + endpoint);
Log.d(TAG, "getAttributes SampledPosition SeekRangeStart " + startTime + " at " + endpoint);
return startTime;
}

Expand Down Expand Up @@ -124,7 +128,7 @@ public int request(int cmd, long parameter) {
}
playbackState = PLAYBACK_STATE_PLAYING;
playbackSpeed =
(playbackSpeed >= 0 ? -1 : Math.min(playbackSpeed * 2, playbackMaxRewindSpeed));
(playbackSpeed >= 0 ? -1 : Math.max(playbackSpeed * 2, playbackMaxRewindSpeed));

return RESPONSE_STATUS_SUCCESS;

Expand All @@ -135,7 +139,7 @@ public int request(int cmd, long parameter) {
}
playbackState = PLAYBACK_STATE_PLAYING;
playbackSpeed =
(playbackSpeed <= 0 ? 1 : Math.max(playbackSpeed * 2, playbackMaxForwardSpeed));
(playbackSpeed <= 0 ? 1 : Math.min(playbackSpeed * 2, playbackMaxForwardSpeed));

return RESPONSE_STATUS_SUCCESS;

Expand Down Expand Up @@ -176,6 +180,7 @@ public int request(int cmd, long parameter) {

@Override
public MediaPlaybackPosition getPosition() {
Log.d(TAG, "getPosition " + playbackPosition);
return new MediaPlaybackPosition(playbackPosition);
}
}

0 comments on commit 6a9909a

Please sign in to comment.