!607 分布式音频音量监听修改VolumeEvent

Merge pull request !607 from zhanhang/hang_commit_volumeEvent
This commit is contained in:
openharmony_ci
2022-07-18 06:55:41 +00:00
committed by Gitee
12 changed files with 64 additions and 36 deletions
@@ -50,7 +50,7 @@ public:
* @param volumeLevel the volume level to be updated.
* @param isUpdateUi whether to update volume level in UI.
**/
void OnVolumeKeyEvent(AudioStreamType streamType, int volumeLevel, bool isUpdateUi) override;
void OnVolumeKeyEvent(VolumeEvent volumeEvent) override;
void SaveCallbackReference(const std::string &callbackName, napi_value callback);
private:
@@ -36,11 +36,11 @@ AudioVolumeKeyEventNapi::~AudioVolumeKeyEventNapi()
AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi::Destructor");
}
void AudioVolumeKeyEventNapi::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi)
void AudioVolumeKeyEventNapi::OnVolumeKeyEvent(VolumeEvent volumeEvent)
{
std::lock_guard<std::mutex> lock(mutex_);
AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: OnVolumeKeyEvent is called volumeLevel=%{public}d", volumeLevel);
AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: isUpdateUi is called isUpdateUi=%{public}d", isUpdateUi);
AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: OnVolumeKeyEvent is called volumeLevel=%{public}d", volumeEvent.volume);
AUDIO_DEBUG_LOG("AudioVolumeKeyEventNapi: isUpdateUi is called isUpdateUi=%{public}d", volumeEvent.updateUi);
if (audioVolumeKeyEventJsCallback_ == nullptr) {
AUDIO_DEBUG_LOG("AudioManagerCallbackNapi:No JS callback registered return");
return;
@@ -49,9 +49,11 @@ void AudioVolumeKeyEventNapi::OnVolumeKeyEvent(AudioStreamType streamType, int32
CHECK_AND_RETURN_LOG(cb != nullptr, "No memory");
cb->callback = audioVolumeKeyEventJsCallback_;
cb->callbackName = VOLUME_KEY_EVENT_CALLBACK_NAME;
cb->volumeEvent.volumeType = streamType;
cb->volumeEvent.volume = volumeLevel;
cb->volumeEvent.updateUi = isUpdateUi;
cb->volumeEvent.volumeType = volumeEvent.volumeType;
cb->volumeEvent.volume = volumeEvent.volume;
cb->volumeEvent.updateUi = volumeEvent.updateUi;
cb->volumeEvent.volumeGroupId = volumeEvent.volumeGroupId;
cb->volumeEvent.networkId = volumeEvent.networkId;
return OnJsCallbackVolumeEvent(cb);
}
@@ -439,6 +439,8 @@ struct VolumeEvent {
AudioStreamType volumeType;
int32_t volume;
bool updateUi;
int32_t volumeGroupId;
std::string networkId;
};
struct AudioParameters {
@@ -103,11 +103,9 @@ public:
/**
* @brief VolumeKeyEventCallback will be executed when hard volume key is pressed up/down
*
* @param streamType the stream type for which volume must be updated.
* @param volumeLevel the volume level to be updated.
* @param isUpdateUi whether to update volume level in UI.
* @param volumeEvent the volume event info.
**/
virtual void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) = 0;
virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0;
};
class AudioRingerModeCallback {
@@ -27,7 +27,7 @@ public:
virtual ~AudioVolumeKeyEventCallbackStub();
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option) override;
void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override;
void OnVolumeKeyEvent(VolumeEvent volumeEvent) override;
void SetOnVolumeKeyEventCallback(const std::weak_ptr<VolumeKeyEventCallback> &callback);
private:
@@ -26,7 +26,7 @@ namespace OHOS {
namespace AudioStandard {
class IAudioVolumeKeyEventCallback : public IRemoteBroker {
public:
virtual void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) = 0;
virtual void OnVolumeKeyEvent(VolumeEvent volumeEvent) = 0;
enum {
ON_VOLUME_KEY_EVENT = 0,
};
@@ -27,7 +27,7 @@ public:
explicit VolumeKeyEventCallbackListner(const sptr<IAudioVolumeKeyEventCallback> &listener);
virtual ~VolumeKeyEventCallbackListner();
DISALLOW_COPY_AND_MOVE(VolumeKeyEventCallbackListner);
void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override;
void OnVolumeKeyEvent(VolumeEvent volumeEvent) override;
private:
sptr<IAudioVolumeKeyEventCallback> listener_ = nullptr;
@@ -36,7 +36,7 @@ class AudioVolumeKeyEventCallbackProxy : public IRemoteProxy<IAudioVolumeKeyEven
public:
explicit AudioVolumeKeyEventCallbackProxy(const sptr<IRemoteObject> &impl);
virtual ~AudioVolumeKeyEventCallbackProxy() = default;
void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override;
void OnVolumeKeyEvent(VolumeEvent volumeEvent) override;
private:
static inline BrokerDelegator<AudioVolumeKeyEventCallbackProxy> delegator_;
};
@@ -36,10 +36,13 @@ int AudioVolumeKeyEventCallbackStub::OnRemoteRequest(
}
switch (code) {
case ON_VOLUME_KEY_EVENT: {
AudioStreamType streamType = static_cast<AudioStreamType>(data.ReadInt32());
int32_t volume = data.ReadInt32();
bool isUpdateUi = data.ReadBool();
OnVolumeKeyEvent(streamType, volume, isUpdateUi);
VolumeEvent volumeEvent;
volumeEvent.volumeType = static_cast<AudioStreamType>(data.ReadInt32());
volumeEvent.volume = data.ReadInt32();
volumeEvent.updateUi = data.ReadBool();
volumeEvent.volumeGroupId = data.ReadInt32();
volumeEvent.networkId = data.ReadString();
OnVolumeKeyEvent(volumeEvent);
reply.WriteInt32(0);
break;
}
@@ -51,13 +54,13 @@ int AudioVolumeKeyEventCallbackStub::OnRemoteRequest(
return 0;
}
void AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi)
void AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent(VolumeEvent volumeEvent)
{
AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent");
std::shared_ptr<VolumeKeyEventCallback> cb = callback_.lock();
if (cb != nullptr) {
AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent CALLBACK NOT NULL");
cb->OnVolumeKeyEvent(streamType, volumeLevel, isUpdateUi);
cb->OnVolumeKeyEvent(volumeEvent);
} else {
AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackStub::OnVolumeKeyEvent CALLBACK NULL");
}
@@ -166,7 +166,13 @@ void AudioPolicyServer::SubscribeKeyEvents()
}
AUDIO_DEBUG_LOG("AudioPolicyServer:: trigger volumeChangeCb clientPid : %{public}d", it->first);
volumeChangeCb->OnVolumeKeyEvent(streamInFocus, MIN_VOLUME_LEVEL, true);
VolumeEvent volumeEvent;
volumeEvent.volumeType = streamInFocus;
volumeEvent.volume = MIN_VOLUME_LEVEL;
volumeEvent.updateUi = true;
volumeEvent.volumeGroupId = 0;
volumeEvent.networkId = LOCAL_NETWORK_ID;
volumeChangeCb->OnVolumeKeyEvent(volumeEvent);
}
return;
}
@@ -194,7 +200,13 @@ void AudioPolicyServer::SubscribeKeyEvents()
}
AUDIO_DEBUG_LOG("AudioPolicyServer:: trigger volumeChangeCb clientPid : %{public}d", it->first);
volumeChangeCb->OnVolumeKeyEvent(streamInFocus, MAX_VOLUME_LEVEL, true);
VolumeEvent volumeEvent;
volumeEvent.volumeType = streamInFocus;
volumeEvent.volume = MAX_VOLUME_LEVEL;
volumeEvent.updateUi = true;
volumeEvent.volumeGroupId = 0;
volumeEvent.networkId = LOCAL_NETWORK_ID;
volumeChangeCb->OnVolumeKeyEvent(volumeEvent);
}
return;
}
@@ -258,7 +270,13 @@ int32_t AudioPolicyServer::SetStreamVolume(AudioStreamType streamType, float vol
}
AUDIO_DEBUG_LOG("AudioPolicyServer::SetStreamVolume trigger volumeChangeCb clientPid : %{public}d", it->first);
volumeChangeCb->OnVolumeKeyEvent(streamType, ConvertVolumeToInt(GetStreamVolume(streamType)), isUpdateUi);
VolumeEvent volumeEvent;
volumeEvent.volumeType = streamType;
volumeEvent.volume = ConvertVolumeToInt(GetStreamVolume(streamType));
volumeEvent.updateUi = isUpdateUi;
volumeEvent.volumeGroupId = 0;
volumeEvent.networkId = LOCAL_NETWORK_ID;
volumeChangeCb->OnVolumeKeyEvent(volumeEvent);
}
return ret;
@@ -20,8 +20,7 @@ namespace AudioStandard {
AudioVolumeKeyEventCallbackProxy::AudioVolumeKeyEventCallbackProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<IAudioVolumeKeyEventCallback>(impl) { }
void AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel,
bool isUpdateUi)
void AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent(VolumeEvent volumeEvent)
{
AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent");
MessageParcel data;
@@ -32,9 +31,11 @@ void AudioVolumeKeyEventCallbackProxy::OnVolumeKeyEvent(AudioStreamType streamTy
AUDIO_ERR_LOG("AudioVolumeKeyEventCallbackProxy: WriteInterfaceToken failed");
return;
}
data.WriteInt32(static_cast<int32_t>(streamType));
data.WriteInt32(volumeLevel);
data.WriteBool(isUpdateUi);
data.WriteInt32(static_cast<int32_t>(volumeEvent.volumeType));
data.WriteInt32(volumeEvent.volume);
data.WriteBool(volumeEvent.updateUi);
data.WriteInt32(volumeEvent.volumeGroupId);
data.WriteString(volumeEvent.networkId);
int error = Remote()->SendRequest(ON_VOLUME_KEY_EVENT, data, reply, option);
if (error != 0) {
AUDIO_DEBUG_LOG("Error while sending volume key event %{public}d", error);
@@ -53,11 +54,11 @@ VolumeKeyEventCallbackListner::~VolumeKeyEventCallbackListner()
AUDIO_DEBUG_LOG("VolumeKeyEventCallbackListner desctrutor");
}
void VolumeKeyEventCallbackListner::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi)
void VolumeKeyEventCallbackListner::OnVolumeKeyEvent(VolumeEvent volumeEvent)
{
AUDIO_DEBUG_LOG("AudioVolumeKeyEventCallbackProxy VolumeKeyEventCallbackListner");
if (listener_ != nullptr) {
listener_->OnVolumeKeyEvent(streamType, volumeLevel, isUpdateUi);
listener_->OnVolumeKeyEvent(volumeEvent);
}
}
} // namespace AudioStandard
@@ -34,7 +34,7 @@ public:
explicit ApplicationCallback(const std::string &testCaseName);
~ApplicationCallback() = default;
void OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi) override;
void OnVolumeKeyEvent(VolumeEvent volumeEvent) override;
private:
std::string testCaseName_;
@@ -36,6 +36,8 @@ namespace {
int32_t g_streamType(0);
int32_t g_volumeLevel(0);
bool g_isUpdateUi(false);
int32_t g_volumeGroupId(0);
std::string g_networkId(LOCAL_NETWORK_ID);
bool g_isCallbackReceived(false);
std::string g_callbackName("");
@@ -45,13 +47,15 @@ namespace {
ApplicationCallback::ApplicationCallback(const std::string &testCaseName) : testCaseName_(testCaseName) {}
void ApplicationCallback::OnVolumeKeyEvent(AudioStreamType streamType, int32_t volumeLevel, bool isUpdateUi)
void ApplicationCallback::OnVolumeKeyEvent(VolumeEvent volumeEvent)
{
g_isCallbackReceived = true;
g_streamType = streamType;
g_volumeLevel = volumeLevel;
g_streamType = volumeEvent.volumeType;
g_volumeLevel = volumeEvent.volume;
g_callbackName = testCaseName_;
g_isUpdateUi = isUpdateUi;
g_isUpdateUi = volumeEvent.updateUi;
g_volumeGroupId = volumeEvent.volumeGroupId;
g_networkId = volumeEvent.networkId;
g_condVar.notify_all();
}