Files
openharmony_ci 1613839f03 !3331 merge 727gaojing into master
issue告警修复

Created-by: xuhy2
Commit-by: xuhy
Merged-by: openharmony_ci
Description: ### 一、内容说明(相关的Issue)



### 二、建议测试周期和提测地址  
  建议测试完成时间:xxxx.xx.xx  
  投产上线时间:xxxx.xx.xx  
  提测地址:CI环境/压测环境  
  测试账号:  

### 三、变更内容
  * 3.1 关联PR列表

  * 3.2 数据库和部署说明  
    1. 常规更新 
    2. 重启unicorn
    3. 重启sidekiq
    4. 迁移任务:是否有迁移任务,没有写 "无"
    5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无"

  * 3.4 其他技术优化内容(做了什么,变更了什么)
    - 重构了 xxxx 代码
    - xxxx 算法优化


  * 3.5 废弃通知(什么字段、方法弃用?)



  * 3.6  后向不兼容变更(是否有无法向后兼容的变更?)


  
### 四、研发自测点(自测哪些?冒烟用例全部自测?)
  自测测试结论:


### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)
  检查点:

| 需求名称 | 是否影响xx公共模块 | 是否需要xx功能 | 需求升级是否依赖其他子产品 |
|------|------------|----------|---------------|
| xxx  | 否          | 需要       | 不需要           |
|      |            |          |               |

  接口测试:

  性能测试:

  并发测试:

  其他:



See merge request: openharmony/multimedia_av_session!3331
2026-08-06 20:17:16 +08:00

587 lines
27 KiB
C++

/*
* Copyright (c) 2023-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "avcast_controller_proxy.h"
#include "avcast_controller_callback_client.h"
#include "avsession_errors.h"
#include "avsession_log.h"
#include "avsession_trace.h"
#include "media_info_holder.h"
#include "surface_utils.h"
#include "stream_dfx_manager.h"
#include "audio_errors.h"
namespace OHOS::AVSession {
AVCastControllerProxy::AVCastControllerProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<IAVCastController>(impl)
{
SLOGD("AVCastControllerProxy construct");
}
AVCastControllerProxy::~AVCastControllerProxy()
{
std::lock_guard<std::recursive_mutex> lock(controllerProxyLock_);
SLOGI("AVCastControllerProxy destroy");
isDestroy_ = true;
Destroy();
}
int32_t AVCastControllerProxy::SendCustomData(const AAFwk::WantParams& data)
{
AVSESSION_TRACE_SYNC_START("AVCastControllerProxy::SendCustomData");
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(parcel.WriteParcelable(&data), ERR_MARSHALLING, "write data failed");
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_SEND_CUSTOM_DATA, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::SendControlCommand(const AVCastControlCommand& cmd)
{
std::lock_guard<std::recursive_mutex> lock(controllerProxyLock_);
AVSESSION_TRACE_SYNC_START("AVCastControllerProxy::SendControlCommand");
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(cmd.IsValid(), ERR_COMMAND_NOT_SUPPORT,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_COMMAND_NOT_SUPPORT_CAST_SET, "command not valid", false),
"command not valid");
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(parcel.WriteParcelable(&cmd), ERR_MARSHALLING, "write cmd failed");
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_SEND_CONTROL_COMMAND, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::Start(const AVQueueItem& avQueueItem)
{
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
MessageParcel parcel;
parcel.SetMaxCapacity(defaultIpcCapacity);
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(avQueueItem.GetDescription() != nullptr, ERR_INVALID_PARAM,
"description is nullptr");
CHECK_AND_RETURN_RET_LOG(parcel.WriteParcelable(&avQueueItem), ERR_UNMARSHALLING, "Write avQueueItem failed");
int32_t startFd = avQueueItem.GetDescription()->GetFdSrc().fd_;
CHECK_AND_RETURN_RET_LOG(parcel.WriteFileDescriptor(startFd < 0 ? 0 : startFd),
ERR_UNMARSHALLING, "Write avQueueItem failed");
SLOGI("Start received fd %{public}d", avQueueItem.GetDescription()->GetFdSrc().fd_);
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_START, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::Prepare(const AVQueueItem& avQueueItem)
{
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
MessageParcel parcel;
parcel.SetMaxCapacity(defaultIpcCapacity);
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(avQueueItem.GetDescription() != nullptr, ERR_INVALID_PARAM,
"description is nullptr");
CHECK_AND_RETURN_RET_LOG(parcel.WriteParcelable(&avQueueItem), ERR_UNMARSHALLING, "Write avQueueItem failed");
if (avQueueItem.GetDescription()->GetFdSrc().fd_ <= 0) {
parcel.WriteBool(false);
} else {
parcel.WriteBool(true);
CHECK_AND_RETURN_RET_LOG(parcel.WriteFileDescriptor(avQueueItem.GetDescription()->GetFdSrc().fd_),
ERR_UNMARSHALLING, "Write avQueueItem failed");
}
SLOGI("Prepare received fd %{public}d", avQueueItem.GetDescription()->GetFdSrc().fd_);
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_PREPARE, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::GetDuration(int32_t& duration)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_GET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_DURATION, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
int32_t tempDuration = 0;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(tempDuration), ERR_UNMARSHALLING, "read string failed");
duration = tempDuration;
}
return ret;
}
int32_t AVCastControllerProxy::GetCastAVPlaybackState(AVPlaybackState& state)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()),
AVSESSION_ERROR, "write interface token failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_CAST_AV_PLAYBACK_STATE, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
sptr<AVPlaybackState> state_ = reply.ReadParcelable<AVPlaybackState>();
CHECK_AND_RETURN_RET_LOG(state_ != nullptr, ERR_UNMARSHALLING, "read AVPlaybackState failed");
state = *state_;
}
return ret;
}
int32_t AVCastControllerProxy::GetSupportedDecoders(std::vector<std::string>& decoderTypes)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()),
AVSESSION_ERROR, "write interface token failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_SUPPORT_DECODER, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
CHECK_AND_RETURN_RET_LOG(reply.ReadStringVector(&decoderTypes), ERR_UNMARSHALLING, "read StringVector failed");
}
return ret;
}
int32_t AVCastControllerProxy::GetRecommendedResolutionLevel(std::string& decoderType, ResolutionLevel& resolutionLevel)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(parcel.WriteString(decoderType), ERR_MARSHALLING, "write filter failed");
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_GET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_RECOMMEND_RESOLUTION_LEVEL, parcel, reply,
option) == 0, ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
int32_t resolutionLevelInt = -1;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(resolutionLevelInt), ERR_UNMARSHALLING, "read int32 failed");
resolutionLevel = static_cast<ResolutionLevel>(resolutionLevelInt);
}
return ret;
}
int32_t AVCastControllerProxy::GetSupportedHdrCapabilities(std::vector<HDRFormat>& hdrFormats)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()),
AVSESSION_ERROR, "write interface token failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_SUPPORT_HDR_CAPABILITIES, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
std::vector<int32_t> hdrFormatsInt;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32Vector(&hdrFormatsInt), ERR_UNMARSHALLING, "read int32 failed");
for (auto it = hdrFormatsInt.begin(); it != hdrFormatsInt.end(); it++) {
CHECK_AND_CONTINUE(*it >= static_cast<int32_t>(HDRFormat::NONE) &&
*it <= static_cast<int32_t>(HDRFormat::IMAGE_HDR_ISO_SINGLE));
hdrFormats.emplace_back(static_cast<HDRFormat>(*it));
}
}
return ret;
}
int32_t AVCastControllerProxy::GetSupportedPlaySpeeds(std::vector<float>& playSpeeds)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()),
AVSESSION_ERROR, "write interface token failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_SUPPORT_PLAY_SPEED, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
CHECK_AND_RETURN_RET_LOG(reply.ReadFloatVector(&playSpeeds), ERR_UNMARSHALLING, "read float failed");
}
return ret;
}
int32_t AVCastControllerProxy::GetCurrentItem(AVQueueItem& currentItem)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()),
AVSESSION_ERROR, "write interface token failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
reply.SetMaxCapacity(defaultIpcCapacity);
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_CURRENT_ITEM, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
sptr<AVQueueItem> currentItem_ = reply.ReadParcelable<AVQueueItem>();
CHECK_AND_RETURN_RET_LOG(currentItem_ != nullptr, ERR_UNMARSHALLING, "read AVQueueItem failed");
currentItem = *currentItem_;
}
return ret;
}
int32_t AVCastControllerProxy::GetValidCommands(std::vector<int32_t>& cmds)
{
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_GET, "controller is destroy", false),
"controller is destroy");
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()),
ERR_MARSHALLING, "write interface token failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_GET_VALID_COMMANDS, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
if (ret == AVSESSION_SUCCESS) {
CHECK_AND_RETURN_RET_LOG(reply.ReadInt32Vector(&cmds), ERR_UNMARSHALLING, "read int32 vector failed");
}
return ret;
}
int32_t AVCastControllerProxy::SetDisplaySurface(std::string& surfaceId)
{
AVSESSION_TRACE_SYNC_START("AVCastControllerProxy::SetDisplaySurface");
errno = 0;
uint64_t surfaceUniqueId = static_cast<uint64_t>(std::strtoll(surfaceId.c_str(), nullptr, 10));
if (errno == ERANGE) {
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_INVALID_PARAM_CAST_SET, "surfaceId conversion error", false);
return ERR_INVALID_PARAM;
}
sptr<Surface> surface = SurfaceUtils::GetInstance()->GetSurface(surfaceUniqueId);
if (!surface) {
SLOGE("surface is null, surface uniqueId %{public}llu", (unsigned long long)surfaceUniqueId);
return AVSESSION_ERROR;
}
sptr<IBufferProducer> producer = surface->GetProducer();
if (!producer) {
SLOGE("producer is null");
return AVSESSION_ERROR;
}
MessageParcel parcel;
MessageParcel reply;
MessageOption option;
if (!parcel.WriteInterfaceToken(GetDescriptor())) {
SLOGE("Failed to write the interface token");
return AVSESSION_ERROR;
}
if (!parcel.WriteRemoteObject(producer->AsObject())) {
SLOGE("Failed to write surface producer");
return AVSESSION_ERROR;
}
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_SET_DISPLAY_SURFACE, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::ProcessMediaKeyResponse(const std::string& assetId, const std::vector<uint8_t>& response)
{
AVSESSION_TRACE_SYNC_START("AVCastControllerProxy::ProcessMediaKeyResponse");
MessageParcel parcel;
MessageParcel reply;
MessageOption option;
auto len = response.size();
if (len > parcel.GetDataCapacity()) {
SLOGD("ProcessMediaKeyResponse SetDataCapacity totalSize: %{public}d", static_cast<int>(len));
parcel.SetMaxCapacity(len + len);
parcel.SetDataCapacity(len);
}
if (!parcel.WriteInterfaceToken(GetDescriptor())) {
SLOGE("Failed to write the interface token");
return AVSESSION_ERROR;
}
if (!parcel.WriteString(assetId)) {
SLOGE("Failed to write assetId");
return AVSESSION_ERROR;
}
if (!parcel.WriteInt32(response.size())) {
SLOGE("Failed to write response size");
return AVSESSION_ERROR;
}
if (len != 0) {
if (!parcel.WriteBuffer(response.data(), len)) {
SLOGE("AVCastControllerProxy ProcessMediaKeyResponse write response failed");
return IPC_PROXY_ERR;
}
}
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "Remote() return nullptr");
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_PROVIDE_KEY_RESPONSE, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::SetCastPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter)
{
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(parcel.WriteString(filter.to_string()), ERR_MARSHALLING, "write filter failed");
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_SET_CAST_PLAYBACK_FILTER, parcel, reply,
option) == 0, ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::AddAvailableCommand(const int32_t cmd)
{
SLOGI("add available command in");
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
CHECK_AND_RETURN_RET_LOG(cmd > AVCastControlCommand::CAST_CONTROL_CMD_INVALID, AVSESSION_ERROR, "invalid cmd");
CHECK_AND_RETURN_RET_LOG(cmd < AVCastControlCommand::CAST_CONTROL_CMD_MAX, AVSESSION_ERROR, "invalid cmd");
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(parcel.WriteInt32(cmd),
ERR_MARSHALLING, "write valid command failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ADD_AVAILABLE_COMMAND, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::RemoveAvailableCommand(const int32_t cmd)
{
SLOGI("remove available command in");
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
CHECK_AND_RETURN_RET_LOG(cmd > AVCastControlCommand::CAST_CONTROL_CMD_INVALID, AVSESSION_ERROR, "invalid cmd");
CHECK_AND_RETURN_RET_LOG(cmd < AVCastControlCommand::CAST_CONTROL_CMD_MAX, AVSESSION_ERROR, "invalid cmd");
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(parcel.WriteInt32(cmd),
ERR_MARSHALLING, "write valid command failed");
auto remote = Remote();
CHECK_AND_RETURN_RET_LOG(remote != nullptr, AVSESSION_ERROR, "get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_REMOVE_AVAILABLE_COMMAND, parcel,
reply, option) == 0, AVSESSION_ERROR, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::RegisterCallback(const std::shared_ptr<AVCastControllerCallback>& callback)
{
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
sptr<AVCastControllerCallbackClient> callback_;
callback_ = new(std::nothrow) AVCastControllerCallbackClient(callback);
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(callback_ != nullptr, ERR_NO_MEMORY,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_NO_MEMORY_CAST_SET, "new AVCastControllerCallbackClient failed", false),
"new AVCastControllerCallbackClient failed");
return RegisterCallbackInner(callback_);
}
int32_t AVCastControllerProxy::RegisterCallbackInner(const sptr<IRemoteObject>& callback)
{
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
CHECK_AND_RETURN_RET_LOG(parcel.WriteRemoteObject(callback), ERR_MARSHALLING,
"write remote object failed");
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_REGISTER_CALLBACK, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
int32_t AVCastControllerProxy::Destroy()
{
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(!isDestroy_.load(), ERR_CONTROLLER_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_CONTROLLER_NOT_EXIST_CAST_SET, "controller is destroy", false),
"controller is destroy");
MessageParcel parcel;
CHECK_AND_RETURN_RET_LOG(parcel.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
"write interface token failed");
auto remote = Remote();
CHECK_AND_CALL_FUNC_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST,
AudioStandard::StreamDfxManager::GetInstance().SendAudioErrorEvent(static_cast<int32_t>(getuid()),
AudioStandard::AVSESSION_CONTROL_SERVICE_NOT_EXIST_CAST_SET, "get remote service failed", false),
"get remote service failed");
MessageParcel reply;
MessageOption option;
CHECK_AND_RETURN_RET_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_DESTROY, parcel, reply, option) == 0,
ERR_IPC_SEND_REQUEST, "send request failed");
isDestroy_.store(true);
int32_t ret = AVSESSION_ERROR;
return reply.ReadInt32(ret) ? ret : AVSESSION_ERROR;
}
}