Commit a5e1819d authored by kenkangxgwe's avatar kenkangxgwe Committed by Commit Bot

[Cast] Add ListPostprocessors Req/Res to get builtin processors

Bug: b/173015334
Test: run Tongol on device and check available processors.
Change-Id: I4acfe6b02c364a6b2e57d91d76c7bb58f98f47c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533554Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Commit-Queue: Mingyu Kang <kenkangxgwe@google.com>
Cr-Commit-Position: refs/heads/master@{#827430}
parent 482b6a1c
......@@ -70,6 +70,17 @@ void ControlConnection::SetVolumeLimit(AudioContentType type,
}
}
void ControlConnection::ListPostprocessors(
ListPostprocessorsCallback callback) {
list_postprocessors_callbacks_.push_back(std::move(callback));
if (!socket_) {
return;
}
Generic proto;
proto.mutable_list_postprocessors();
socket_->SendProto(proto);
}
void ControlConnection::ConfigurePostprocessor(std::string postprocessor_name,
std::string config) {
SendPostprocessorMessage(postprocessor_name, config);
......@@ -169,6 +180,12 @@ void ControlConnection::OnConnected(std::unique_ptr<MixerSocket> socket) {
SendPostprocessorMessage(item.first, item.second);
}
if (!list_postprocessors_callbacks_.empty()) {
Generic message;
message.mutable_list_postprocessors();
socket_->SendProto(message);
}
if (connect_callback_) {
connect_callback_.Run();
}
......@@ -184,6 +201,18 @@ bool ControlConnection::HandleMetadata(const Generic& message) {
stream_count_callback_.Run(message.stream_count().primary(),
message.stream_count().sfx());
}
if (message.has_postprocessor_list()) {
std::vector<std::string> post_processors;
for (const auto& post_processor :
message.postprocessor_list().postprocessors()) {
post_processors.push_back(post_processor);
}
while (!list_postprocessors_callbacks_.empty()) {
std::move(list_postprocessors_callbacks_.front()).Run(post_processors);
list_postprocessors_callbacks_.pop_front();
}
}
return true;
}
......
......@@ -5,6 +5,7 @@
#ifndef CHROMECAST_MEDIA_AUDIO_MIXER_SERVICE_CONTROL_CONNECTION_H_
#define CHROMECAST_MEDIA_AUDIO_MIXER_SERVICE_CONTROL_CONNECTION_H_
#include <list>
#include <memory>
#include <string>
......@@ -31,6 +32,10 @@ class ControlConnection : public MixerConnection, public MixerSocket::Delegate {
using StreamCountCallback =
base::RepeatingCallback<void(int primary_streams, int sfx_streams)>;
// Callback that handles ListPostProcessors response.
using ListPostprocessorsCallback =
base::OnceCallback<void(const std::vector<std::string>&)>;
ControlConnection();
~ControlConnection() override;
......@@ -50,6 +55,9 @@ class ControlConnection : public MixerConnection, public MixerSocket::Delegate {
// Sets the maximum effective volume multiplier for a given content type.
void SetVolumeLimit(AudioContentType type, float max_volume_multiplier);
// Returns a set of registered builtin post-processors.
void ListPostprocessors(ListPostprocessorsCallback callback);
// Sends arbitrary config data to a specific postprocessor. Config is saved
// for each unique |name| and will be resent if the mixer disconnects and then
// reconnects. If the |postprocessor_name| contains a '?', that character and
......@@ -96,6 +104,8 @@ class ControlConnection : public MixerConnection, public MixerSocket::Delegate {
base::flat_map<std::string, std::string> postprocessor_config_;
StreamCountCallback stream_count_callback_;
// Uses std::list to trigger callbacks in FIFO order.
std::list<ListPostprocessorsCallback> list_postprocessors_callbacks_;
int num_output_channels_ = 0;
DISALLOW_COPY_AND_ASSIGN(ControlConnection);
......
......@@ -40,6 +40,10 @@ void MixerControl::ConfigurePostprocessor(std::string postprocessor_name,
std::move(postprocessor_name), std::move(config));
}
void MixerControl::ListPostprocessors(ListPostprocessorsCallback callback) {
control_.Post(FROM_HERE, &ControlConnection::ListPostprocessors,
std::move(callback));
}
void MixerControl::ReloadPostprocessors() {
control_.Post(FROM_HERE, &ControlConnection::ReloadPostprocessors);
}
......
......@@ -19,6 +19,9 @@ class ControlConnection;
// Threadsafe process-wide mixer control.
class MixerControl {
public:
using ListPostprocessorsCallback =
base::OnceCallback<void(const std::vector<std::string>&)>;
// Returns the mixer control instance for this process, or nullptr if the
// mixer is not present on this system.
static MixerControl* Get();
......@@ -27,6 +30,9 @@ class MixerControl {
void ConfigurePostprocessor(std::string postprocessor_name,
std::string config);
// Sends the request to get the builtin postprocessors and run the callback.
void ListPostprocessors(ListPostprocessorsCallback callback);
// Instructs the mixer to reload postprocessors based on the config file.
void ReloadPostprocessors();
......
......@@ -188,6 +188,13 @@ message SetVolumeLimit {
optional float max_volume_multiplier = 2;
}
// Asks the mixer to return a list of registered builtin post processors.
message ListPostprocessors {}
message PostprocessorList{
repeated string postprocessors = 1;
}
// Sends arbitrary config data to a specific postprocessor.
message ConfigurePostprocessor {
optional string name = 1;
......@@ -259,4 +266,6 @@ message Generic {
optional StreamInterruption stream_interruption = 22;
optional SetAudioClockRate set_audio_clock_rate = 23;
optional MixerUnderrun mixer_underrun = 24;
optional ListPostprocessors list_postprocessors = 25;
optional PostprocessorList postprocessor_list = 26;
}
......@@ -15,6 +15,7 @@
#include "chromecast/media/cma/backend/mixer/loopback_handler.h"
#include "chromecast/media/cma/backend/mixer/mixer_input_connection.h"
#include "chromecast/media/cma/backend/mixer/mixer_loopback_connection.h"
#include "chromecast/media/cma/backend/mixer/post_processor_registry.h"
#include "chromecast/media/cma/backend/mixer/stream_mixer.h"
namespace chromecast {
......@@ -68,6 +69,9 @@ class MixerServiceReceiver::ControlConnection
message.set_device_volume().content_type()),
message.set_device_volume().volume_multiplier());
}
if (message.has_list_postprocessors()) {
OnListPostprocessors();
}
if (message.has_configure_postprocessor()) {
mixer_->SetPostProcessorConfig(
message.configure_postprocessor().name(),
......@@ -99,6 +103,15 @@ class MixerServiceReceiver::ControlConnection
return true;
}
void OnListPostprocessors() {
mixer_service::Generic message;
auto* postprocessor_list = message.mutable_postprocessor_list();
for (const auto& library_pair : PostProcessorRegistry::Get()->Libraries()) {
postprocessor_list->add_postprocessors(library_pair.first);
}
socket_->SendProto(message);
}
void OnConnectionError() override {
receiver_->RemoveControlConnection(this);
}
......
......@@ -45,6 +45,11 @@ class PostProcessorRegistry {
const std::string& config,
int channels);
// Returns a map of registered libraries and their create functions.
const base::flat_map<std::string, CreateFunction>& Libraries() const {
return creators_;
}
private:
base::flat_map<std::string /* library_name */, CreateFunction> creators_;
};
......
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