update stopAll
This commit is contained in:
parent
e4c96e689b
commit
f7003f0993
@ -59,3 +59,14 @@ message UpdateParamsCommand {
|
|||||||
CommandHeader.Feedback header = 1;
|
CommandHeader.Feedback header = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message StopAllCommand {
|
||||||
|
message Request {
|
||||||
|
CommandHeader.Request header = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Feedback {
|
||||||
|
CommandHeader.Feedback header = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,4 +10,6 @@ service SystemService {
|
|||||||
rpc GetSystemStatus(GetSystemStatusCommand.Request) returns (GetSystemStatusCommand.Feedback) {}
|
rpc GetSystemStatus(GetSystemStatusCommand.Request) returns (GetSystemStatusCommand.Feedback) {}
|
||||||
|
|
||||||
rpc UpdateParams(UpdateParamsCommand.Request) returns (UpdateParamsCommand.Feedback) {}
|
rpc UpdateParams(UpdateParamsCommand.Request) returns (UpdateParamsCommand.Feedback) {}
|
||||||
|
|
||||||
|
rpc StopAll(StopAllCommand.Request) returns (StopAllCommand.Feedback) {}
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ void DeviceManager::stop() {
|
|||||||
for (auto& [id, variant] : devices_) {
|
for (auto& [id, variant] : devices_) {
|
||||||
std::visit([&](auto&& ptr) {
|
std::visit([&](auto&& ptr) {
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
ptr->stop(); // 调用各子类实现的 start()
|
ptr->stop(); // 调用各子类实现的 stop()
|
||||||
LOG(INFO) << "[DeviceManager]: Stop device " << id << " Success";
|
LOG(INFO) << "[DeviceManager]: Stop device " << id << " Success";
|
||||||
} else {
|
} else {
|
||||||
LOG(WARNING) << "[DeviceManager]: Null pointer for device " << id;
|
LOG(WARNING) << "[DeviceManager]: Null pointer for device " << id;
|
||||||
|
|||||||
@ -93,9 +93,12 @@ void ffmpegSpeaker::resetPlayState()
|
|||||||
|
|
||||||
void ffmpegSpeaker::stop() {
|
void ffmpegSpeaker::stop() {
|
||||||
|
|
||||||
state_.is_running = false;
|
{
|
||||||
state_.is_decoding = false;
|
lock_guard lock(mtx_);
|
||||||
state_.is_paused = false;
|
state_.is_running = false;
|
||||||
|
state_.is_decoding = false;
|
||||||
|
state_.is_paused = false;
|
||||||
|
}
|
||||||
// 等待线程结束
|
// 等待线程结束
|
||||||
if (decode_thread_ && decode_thread_->joinable()) {
|
if (decode_thread_ && decode_thread_->joinable()) {
|
||||||
decode_thread_->join();
|
decode_thread_->join();
|
||||||
@ -525,18 +528,17 @@ void ffmpegSpeaker::play_audio_() {
|
|||||||
|
|
||||||
void ffmpegSpeaker::updateParams(const std::pair<std::string, std::string>& param)
|
void ffmpegSpeaker::updateParams(const std::pair<std::string, std::string>& param)
|
||||||
{
|
{
|
||||||
std::lock_guard lock(mtx_);
|
|
||||||
try {
|
|
||||||
if (param.first == "sampleRate") {
|
|
||||||
sample_rate_ = stoi(param.second);
|
|
||||||
}
|
|
||||||
else if (param.first == "channels") {
|
|
||||||
channels_ = stoi(param.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
stop();
|
try {
|
||||||
init();
|
{
|
||||||
start();
|
std::lock_guard lock(mtx_);
|
||||||
|
if (param.first == "sampleRate") {
|
||||||
|
sample_rate_ = stoi(param.second);
|
||||||
|
}
|
||||||
|
else if (param.first == "channels") {
|
||||||
|
channels_ = stoi(param.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (exception &e) {
|
catch (exception &e) {
|
||||||
throw runtime_error(e.what());
|
throw runtime_error(e.what());
|
||||||
|
|||||||
@ -18,6 +18,7 @@ namespace cmvr::service
|
|||||||
grpc::Status GetSystemInfo(grpc::ServerContext* context, const api::GetSystemInfoCommand_Request* request, api::GetSystemInfoCommand_Feedback* response) override;
|
grpc::Status GetSystemInfo(grpc::ServerContext* context, const api::GetSystemInfoCommand_Request* request, api::GetSystemInfoCommand_Feedback* response) override;
|
||||||
grpc::Status GetSystemStatus(grpc::ServerContext* context, const api::GetSystemStatusCommand_Request* request, api::GetSystemStatusCommand_Feedback* response) override;
|
grpc::Status GetSystemStatus(grpc::ServerContext* context, const api::GetSystemStatusCommand_Request* request, api::GetSystemStatusCommand_Feedback* response) override;
|
||||||
grpc::Status UpdateParams(grpc::ServerContext* context, const cmvr::api::UpdateParamsCommand_Request* request, cmvr::api::UpdateParamsCommand_Feedback* response) override;
|
grpc::Status UpdateParams(grpc::ServerContext* context, const cmvr::api::UpdateParamsCommand_Request* request, cmvr::api::UpdateParamsCommand_Feedback* response) override;
|
||||||
|
grpc::Status StopAll(grpc::ServerContext* context, const cmvr::api::StopAllCommand_Request* request, cmvr::api::StopAllCommand_Feedback* response) override;
|
||||||
private:
|
private:
|
||||||
device::DeviceManager& dmgr_;
|
device::DeviceManager& dmgr_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -161,4 +161,21 @@ grpc::Status gRPCSystemServiceImpl::UpdateParams(grpc::ServerContext* context, c
|
|||||||
setCurrentTimestamp(response->mutable_header()->mutable_timestamp());
|
setCurrentTimestamp(response->mutable_header()->mutable_timestamp());
|
||||||
return grpc::Status::OK;
|
return grpc::Status::OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grpc::Status gRPCSystemServiceImpl::StopAll(grpc::ServerContext* context,
|
||||||
|
const cmvr::api::StopAllCommand_Request* request, cmvr::api::StopAllCommand_Feedback* response)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
dmgr_.stop();
|
||||||
|
response->mutable_header()->set_success(true);
|
||||||
|
setCurrentTimestamp(response->mutable_header()->mutable_timestamp());
|
||||||
|
return grpc::Status::OK;
|
||||||
|
}
|
||||||
|
catch (std::exception& e) {
|
||||||
|
response->mutable_header()->set_success(false);
|
||||||
|
response->mutable_header()->set_error_message(e.what());
|
||||||
|
setCurrentTimestamp(response->mutable_header()->mutable_timestamp());
|
||||||
|
return grpc::Status::OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user