Commit d890cfae authored by Michael Sun's avatar Michael Sun Committed by Commit Bot

CRAS: Add multiple DBUS methods to support Bluetooth media player

CRAS registered a media player with the Chrome OS Bluetooth stack
(BlueZ) following the Bluetooth AVRCP (Audio/Video Remote Control
Profile). The media player is capable of providing media status, track
information, metadata, and etc to the remote Bluetooth device.

This patch (as a part of more changes) adds new functions to support
Playback Status, Player Identity, and Player Position information flow
to the lower level through DBUS.

BUG=b:147365563

Cq-Depend: chromium:2067192
Change-Id: Ib6255a455d97200ba1c7ee2fadb6905f5a6b46d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069273
Commit-Queue: Jenny Zhang <jennyz@chromium.org>
Auto-Submit: Michael Sun <michaelfsun@google.com>
Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744071}
parent 6398d1c3
......@@ -325,6 +325,36 @@ class CrasAudioClientImpl : public CrasAudioClient {
base::DoNothing());
}
void SetPlayerPlaybackStatus(const std::string& playback_status) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerPlaybackStatus);
dbus::MessageWriter writer(&method_call);
writer.AppendString(playback_status);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetPlayerIdentity(const std::string& identity) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerIdentity);
dbus::MessageWriter writer(&method_call);
writer.AppendString(identity);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetPlayerPosition(const int64_t& position) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerPosition);
dbus::MessageWriter writer(&method_call);
writer.AppendInt64(position);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) override {
cras_proxy_->WaitForServiceToBeAvailable(std::move(callback));
......
......@@ -163,6 +163,18 @@ class COMPONENT_EXPORT(DBUS_AUDIO) CrasAudioClient {
int32_t channels,
const std::vector<double>& mixer) = 0;
// Sets the player playback status. Possible status are "Playing", "Paused" or
// "Stopped".
virtual void SetPlayerPlaybackStatus(const std::string& playback_status) = 0;
// Sets the player identity. Identity is a human readable title for the source
// of the media player. This could be the name of the app or the name of the
// site playing media.
virtual void SetPlayerIdentity(const std::string& playback_identity) = 0;
// Sets the current track position for the player in microseconds
virtual void SetPlayerPosition(const int64_t& position) = 0;
// Runs the callback as soon as the service becomes available.
virtual void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) = 0;
......
......@@ -164,6 +164,23 @@ void ExpectUint64AndBoolArguments(uint64_t expected_uint64,
EXPECT_FALSE(reader->HasMoreData());
}
// Expect the reader to have a string.
void ExpectStringArgument(std::string expected_string,
dbus::MessageReader* reader) {
std::string value;
ASSERT_TRUE(reader->PopString(&value));
EXPECT_EQ(expected_string, value);
EXPECT_FALSE(reader->HasMoreData());
}
// Expect the reader to have a int64_t.
void ExpectInt64Argument(int64_t expected_int64, dbus::MessageReader* reader) {
int64_t value;
ASSERT_TRUE(reader->PopInt64(&value));
EXPECT_EQ(expected_int64, value);
EXPECT_FALSE(reader->HasMoreData());
}
void WriteNodesToResponse(const AudioNodeList& node_list,
dbus::MessageWriter* writer) {
dbus::MessageWriter sub_writer(nullptr);
......@@ -1110,4 +1127,52 @@ TEST_F(CrasAudioClientTest, SetGlobalOutputChannelRemix) {
base::RunLoop().RunUntilIdle();
}
TEST_F(CrasAudioClientTest, SetPlayerPlaybackStatus) {
const std::string kStatus = "paused";
// Create response.
std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
// Set expectations.
PrepareForMethodCall(cras::kSetPlayerPlaybackStatus,
base::BindRepeating(&ExpectStringArgument, kStatus),
response.get());
// Call method.
client()->SetPlayerPlaybackStatus(kStatus);
// Run the message loop.
base::RunLoop().RunUntilIdle();
}
TEST_F(CrasAudioClientTest, SetPlayerIdentity) {
const std::string kIdentity = "Chrome Player";
// Create response.
std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
// Set expectations.
PrepareForMethodCall(cras::kSetPlayerIdentity,
base::BindRepeating(&ExpectStringArgument, kIdentity),
response.get());
// Call method.
client()->SetPlayerIdentity(kIdentity);
// Run the message loop.
base::RunLoop().RunUntilIdle();
}
TEST_F(CrasAudioClientTest, SetPlayerPosition) {
const int64_t kPosition = 2020224;
// Create response.
std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
// Set expectations.
PrepareForMethodCall(cras::kSetPlayerPosition,
base::BindRepeating(&ExpectInt64Argument, kPosition),
response.get());
// Call method.
client()->SetPlayerPosition(kPosition);
// Run the message loop.
base::RunLoop().RunUntilIdle();
}
} // namespace chromeos
......@@ -212,6 +212,14 @@ void FakeCrasAudioClient::SetGlobalOutputChannelRemix(
int32_t channels,
const std::vector<double>& mixer) {}
void FakeCrasAudioClient::SetPlayerPlaybackStatus(
const std::string& playback_status) {}
void FakeCrasAudioClient::SetPlayerIdentity(
const std::string& playback_identity) {}
void FakeCrasAudioClient::SetPlayerPosition(const int64_t& position) {}
void FakeCrasAudioClient::AddActiveOutputNode(uint64_t node_id) {
for (size_t i = 0; i < node_list_.size(); ++i) {
if (node_list_[i].id == node_id)
......
......@@ -51,6 +51,9 @@ class COMPONENT_EXPORT(DBUS_AUDIO) FakeCrasAudioClient
void SwapLeftRight(uint64_t node_id, bool swap) override;
void SetGlobalOutputChannelRemix(int32_t channels,
const std::vector<double>& mixer) override;
void SetPlayerPlaybackStatus(const std::string& playback_status) override;
void SetPlayerIdentity(const std::string& playback_identity) override;
void SetPlayerPosition(const int64_t& position) override;
void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment