mirror of
https://gitee.com/openharmony/xts_dcts
synced 2024-11-23 07:39:59 +00:00
!646 【distributedhardware】【master】分布式音频可知可控和相机维护
Merge pull request !646 from bjliang/master
This commit is contained in:
commit
284e14726b
@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2022-2023 Huawei Device Co., Ltd.
|
# Copyright (C) 2022-2024 Huawei Device Co., Ltd.
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
@ -17,6 +17,7 @@ group("distributedhardware") {
|
|||||||
testonly = true
|
testonly = true
|
||||||
if (is_standard_system) {
|
if (is_standard_system) {
|
||||||
deps = [
|
deps = [
|
||||||
|
"distributedaudionewtest:SubDctsdisAudioNewTest",
|
||||||
"distributedaudiotest:SubDctsdisAudioTest",
|
"distributedaudiotest:SubDctsdisAudioTest",
|
||||||
"distributedcameratest:SubDctsdisCameraTest",
|
"distributedcameratest:SubDctsdisCameraTest",
|
||||||
"distributeddevicejstest:SubDctsdisDeviceJsTest",
|
"distributeddevicejstest:SubDctsdisDeviceJsTest",
|
||||||
|
101
distributedhardware/distributedaudionewtest/BUILD.gn
Normal file
101
distributedhardware/distributedaudionewtest/BUILD.gn
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
# Copyright (C) 2024 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.
|
||||||
|
|
||||||
|
base_root = "../../../../../"
|
||||||
|
import("$base_root/test/xts/tools/build/suite.gni")
|
||||||
|
|
||||||
|
module_output_path = "dcts/distributedhardware"
|
||||||
|
|
||||||
|
ohos_moduletest_suite("SubDctsdisAudioNewTest") {
|
||||||
|
module_out_path = module_output_path
|
||||||
|
include_dirs = [
|
||||||
|
"$base_root/drivers\peripheral\audio\interfaces\include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_hardware_fwk/common/log/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_hardware_fwk/utils/include/log",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/common/include",
|
||||||
|
"$base_root/foundation/multimedia/audio_framework/frameworks/native/audiopolicy/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_hardware_fwk/common/utils/include",
|
||||||
|
"$base_root/foundation/multimedia/audio_framework/interfaces/inner_api/native/audiocapturer/include",
|
||||||
|
"$base_root/foundation/multimedia/audio_framework/interfaces/inner_api/native/audiocommon/include",
|
||||||
|
"$base_root/foundation/multimedia/audio_framework/interfaces/inner_api/native/audiorenderer/include",
|
||||||
|
"$base_root/foundation/multimedia/audio_framework/interfaces/inner_api/native/audiomanager/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audioclient/micclient/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audioclient/spkclient/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiocontrol/controlsink/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audioprocessor/interface",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiotransport/interface",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiotransport/receiverengine/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiotransport/senderengine/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/interfaces/inner_kits/native_cpp/audio_sink/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/interfaces/inner_kits/native_cpp/audio_source/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiomanager/managersink/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiomanager/servicesink/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiomanager/test/unittest/managersink/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiomanager/test/unittest/servicesink/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/common/audiodata/include",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/common/audioeventcallback",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/common/audioparam",
|
||||||
|
"$base_root/foundation/communication/dsoftbus/dsoftbus_enhance/test/tool/softbus_tool/include",
|
||||||
|
"$base_root/base/security/access_token/interfaces/innerkits/token_setproc/include",
|
||||||
|
"$base_root/base/security/access_token/interfaces/innerkits/accesstoken/include",
|
||||||
|
"$base_root/foundation/communication/dsoftbus/interfaces/kits/bus_center",
|
||||||
|
"$base_root/third_party/cJSON",
|
||||||
|
]
|
||||||
|
|
||||||
|
sources = [
|
||||||
|
"daudio_automat_test.cpp",
|
||||||
|
"distributedaudiotest.cpp",
|
||||||
|
]
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
"$base_root/base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken",
|
||||||
|
"$base_root/base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc",
|
||||||
|
"$base_root/drivers/hdf_core/adapter/uhdf2/utils:libhdf_utils",
|
||||||
|
"$base_root/foundation/communication/dsoftbus/core/common:softbus_utils",
|
||||||
|
"$base_root/foundation/distributedhardware/distributed_audio/services/audiomanager/servicesink:distributed_audio_sink",
|
||||||
|
"$base_root/third_party/cJSON:cjson",
|
||||||
|
"$base_root/third_party/googletest:gmock",
|
||||||
|
"$base_root/third_party/googletest:gtest_main",
|
||||||
|
]
|
||||||
|
|
||||||
|
external_deps = [
|
||||||
|
"access_token:libaccesstoken_sdk",
|
||||||
|
"access_token:libnativetoken",
|
||||||
|
"access_token:libtoken_setproc",
|
||||||
|
"audio_framework:audio_capturer",
|
||||||
|
"audio_framework:audio_client",
|
||||||
|
"audio_framework:audio_renderer",
|
||||||
|
"c_utils:utils",
|
||||||
|
"distributed_hardware_fwk:distributedhardwareutils",
|
||||||
|
"drivers_interface_distributed_audio:libdaudio_proxy_1.0",
|
||||||
|
"dsoftbus:softbus_client",
|
||||||
|
"hdf_core:libhdf_utils",
|
||||||
|
"hilog:libhilog",
|
||||||
|
"hisysevent:libhisysevent",
|
||||||
|
"hitrace:hitrace_meter",
|
||||||
|
"ipc:ipc_core",
|
||||||
|
"safwk:system_ability_fwk",
|
||||||
|
"samgr:samgr_proxy",
|
||||||
|
]
|
||||||
|
|
||||||
|
defines = [
|
||||||
|
"HI_LOG_ENABLE",
|
||||||
|
"DH_LOG_TAG=\"SubDctsdisAudioNewTest\"",
|
||||||
|
"LOG_DOMAIN=0xD004100",
|
||||||
|
]
|
||||||
|
|
||||||
|
install_enable = true
|
||||||
|
install_images = [ chipset_base_dir ]
|
||||||
|
subsystem_name = "distributedhardware"
|
||||||
|
part_name = "distributed_audio"
|
||||||
|
}
|
22
distributedhardware/distributedaudionewtest/Test.json
Normal file
22
distributedhardware/distributedaudionewtest/Test.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"description": "Config for disCamera test cases",
|
||||||
|
"driver": {
|
||||||
|
"module-name": "SubDctsdisAudioNewTest",
|
||||||
|
"native-test-timeout": "120000",
|
||||||
|
"native-test-device-path": "/data/local/tmp",
|
||||||
|
"runtime-hint": "1s",
|
||||||
|
"type": "CppTest"
|
||||||
|
},
|
||||||
|
"kits": [
|
||||||
|
{
|
||||||
|
"post-push" : [
|
||||||
|
"chmod -R 777 /data/local/tmp/*"
|
||||||
|
],
|
||||||
|
"push": [
|
||||||
|
"SubDctsdisAudioNewTest->/data/local/tmp/SubDctsdisAudioNewTest"
|
||||||
|
],
|
||||||
|
"type": "PushKit"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,422 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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 <gtest/gtest.h>
|
||||||
|
#include "distributedaudiotest.h"
|
||||||
|
#include "audio_event.h"
|
||||||
|
#include "daudio_constants.h"
|
||||||
|
#include "daudio_errorcode.h"
|
||||||
|
#include "iservice_registry.h"
|
||||||
|
#include "daudio_sink_ipc_callback_proxy.h"
|
||||||
|
#include "daudio_sink_load_callback.h"
|
||||||
|
#define PRIVATE public
|
||||||
|
#define PROTECTED public
|
||||||
|
#include "daudio_sink_service.h"
|
||||||
|
#undef PROTECTED
|
||||||
|
#undef PRIVATE
|
||||||
|
|
||||||
|
using namespace testing::ext;
|
||||||
|
using namespace OHOS;
|
||||||
|
using namespace OHOS::DistributedHardware;
|
||||||
|
|
||||||
|
int32_t g_audioOk = 0;
|
||||||
|
int32_t g_audioDelay = 5;
|
||||||
|
std::string res = "true";
|
||||||
|
std::string g_testParams = "sink";
|
||||||
|
class DAudioAutomatTest : public testing::Test {
|
||||||
|
public:
|
||||||
|
static void SetUpTestCase(void);
|
||||||
|
static void TearDownTestCase(void);
|
||||||
|
void SetUp();
|
||||||
|
void TearDown();
|
||||||
|
DAudioAutomatTest();
|
||||||
|
std::shared_ptr<DAudioSinkService> sinkSrv_ = nullptr;
|
||||||
|
sptr<IRemoteObject> remoteObject_ = nullptr;
|
||||||
|
sptr<ISystemAbilityManager> samgr_ = nullptr;
|
||||||
|
};
|
||||||
|
void DAudioAutomatTest::SetUpTestCase(void)
|
||||||
|
{
|
||||||
|
int ret = InitTestDemo();
|
||||||
|
if (ret != g_audioOk) {
|
||||||
|
DHLOGI("demo test:InitTestDemo error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void DAudioAutomatTest::TearDownTestCase(void) {}
|
||||||
|
void DAudioAutomatTest::SetUp(void)
|
||||||
|
{
|
||||||
|
int32_t saId = 6666;
|
||||||
|
bool runOnCreate = true;
|
||||||
|
std::string params = "params";
|
||||||
|
samgr_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||||
|
if (samgr_ == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sptr<DAudioSinkLoadCallback> loadCallback(new DAudioSinkLoadCallback(params));
|
||||||
|
samgr_->LoadSystemAbility(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID, loadCallback);
|
||||||
|
remoteObject_ = samgr_->GetSystemAbility(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID);
|
||||||
|
if (remoteObject_ == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sinkSrv_ = std::make_shared<DAudioSinkService>(saId, runOnCreate);
|
||||||
|
}
|
||||||
|
void DAudioAutomatTest::TearDown(void)
|
||||||
|
{
|
||||||
|
if (samgr_ != nullptr) {
|
||||||
|
samgr_->UnloadSystemAbility(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID);
|
||||||
|
}
|
||||||
|
sinkSrv_ = nullptr;
|
||||||
|
}
|
||||||
|
DAudioAutomatTest::DAudioAutomatTest(void) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name FindAudioDevice()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0100
|
||||||
|
* @tc.desc Find Audio Device Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0100, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0100";
|
||||||
|
|
||||||
|
int32_t res = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, res) << "GetSyncOnlineDevices fail DCTS_0100";
|
||||||
|
|
||||||
|
res = sinkSrv_->PauseDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, res) << "PauseDistributedHardware fail DCTS_0100";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name OpenSpk()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0200
|
||||||
|
* @tc.desc Open Spk Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0200, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0200";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0200";
|
||||||
|
|
||||||
|
ref = sinkSrv_->ResumeDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "ResumeDistributedHardware fail DCTS_0200";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name StartRender()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0300
|
||||||
|
* @tc.desc Start Render Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0300, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0300";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0300";
|
||||||
|
|
||||||
|
ref = sinkSrv_->StopDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "StopDistributedHardware fail DCTS_0300";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name StopRender()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0400
|
||||||
|
* @tc.desc Stop Render Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0400, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0400";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0400";
|
||||||
|
|
||||||
|
ref = sinkSrv_->ResumeDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "ResumeDistributedHardware fail DCTS_0400";
|
||||||
|
|
||||||
|
ref = sinkSrv_->StopDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "StopDistributedHardware fail DCTS_0400";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name SetVolume()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0500
|
||||||
|
* @tc.desc Set Volume Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0500, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0500";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0500";
|
||||||
|
|
||||||
|
ref = sinkSrv_->ResumeDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "ResumeDistributedHardware fail DCTS_0500";
|
||||||
|
|
||||||
|
ref = sinkSrv_->PauseDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "PauseDistributedHardware fail DCTS_0500";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name GetVolume()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0600
|
||||||
|
* @tc.desc Get Volume Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0600, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0600";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0600";
|
||||||
|
|
||||||
|
ref = sinkSrv_->PauseDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "PauseDistributedHardware fail DCTS_0600";
|
||||||
|
|
||||||
|
ref = sinkSrv_->ResumeDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "ResumeDistributedHardware fail DCTS_0600";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name CloseSpk()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0700
|
||||||
|
* @tc.desc Close Spk Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0700, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0700";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0700";
|
||||||
|
|
||||||
|
ref = sinkSrv_->StopDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "StopDistributedHardware fail DCTS_0700";
|
||||||
|
|
||||||
|
ref = sinkSrv_->ResumeDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "ResumeDistributedHardware fail DCTS_0700";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name OpenMic()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0800
|
||||||
|
* @tc.desc Open Mic Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0800, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0800";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0800";
|
||||||
|
|
||||||
|
ref = sinkSrv_->PauseDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "PauseDistributedHardware fail DCTS_0800";
|
||||||
|
|
||||||
|
ref = sinkSrv_->StopDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "StopDistributedHardware fail DCTS_0800";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name StartCapture()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_0900
|
||||||
|
* @tc.desc Start Capture Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0900, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_0900";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_0900";
|
||||||
|
|
||||||
|
std::string finish = HandleAudioEvent(5);
|
||||||
|
EXPECT_EQ(res, finish) << "OpenMic fail DCTS_0900";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
ref = sinkSrv_->PauseDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "PauseDistributedHardware fail DCTS_0900";
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(7);
|
||||||
|
EXPECT_EQ(res, finish) << "StartCapture fail DCTS_0900";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
ref = sinkSrv_->ResumeDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "ResumeDistributedHardware fail DCTS_0900";
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(8);
|
||||||
|
EXPECT_EQ(res, finish) << "StopCapture fail DCTS_0900";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(6);
|
||||||
|
EXPECT_EQ(res, finish) << "CloseMic fail DCTS_0900";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name StopCapture()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_1000
|
||||||
|
* @tc.desc Stop Capture Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_1000, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(g_audioOk, ret) << "InitSink fail DCTS_1000";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "GetSyncOnlineDevices fail DCTS_1000";
|
||||||
|
|
||||||
|
std::string finish = HandleAudioEvent(5);
|
||||||
|
EXPECT_EQ(res, finish) << "OpenMic fail DCTS_1000";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(7);
|
||||||
|
EXPECT_EQ(res, finish) << "StartCapture fail DCTS_1000";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
ref = sinkSrv_->PauseDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "PauseDistributedHardware fail DCTS_1000";
|
||||||
|
|
||||||
|
ref = sinkSrv_->ResumeDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(g_audioOk, ref) << "ResumeDistributedHardware fail DCTS_1000";
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(8);
|
||||||
|
EXPECT_EQ(res, finish) << "StopCapture fail DCTS_1000";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(6);
|
||||||
|
EXPECT_EQ(res, finish) << "CloseMic fail DCTS_1000";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @tc.name CloseMic()
|
||||||
|
* @tc.number SUB_DH_DAudio_Dcts_1100
|
||||||
|
* @tc.desc Close Mic Test
|
||||||
|
* @tc.size MediumTest
|
||||||
|
* @tc.type Function
|
||||||
|
* @tc.level Level 1
|
||||||
|
*/
|
||||||
|
HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_1100, TestSize.Level1)
|
||||||
|
{
|
||||||
|
std::string g_networkId;
|
||||||
|
sptr<DAudioSinkIpcCallbackProxy> dAudioSinkIpcCallbackProxy(new DAudioSinkIpcCallbackProxy(remoteObject_));
|
||||||
|
int32_t ret = sinkSrv_->InitSink(g_testParams, dAudioSinkIpcCallbackProxy);
|
||||||
|
EXPECT_EQ(0, ret) << "InitSink fail DCTS_1100";
|
||||||
|
|
||||||
|
int32_t ref = GetSyncOnlineDevices(g_networkId);
|
||||||
|
EXPECT_EQ(0, ref) << "GetSyncOnlineDevices fail DCTS_1100";
|
||||||
|
|
||||||
|
std::string finish = HandleAudioEvent(5);
|
||||||
|
EXPECT_EQ(res, finish) << "OpenMic fail DCTS_1100";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(7);
|
||||||
|
EXPECT_EQ(res, finish) << "StartCapture fail DCTS_1100";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
|
||||||
|
ref = sinkSrv_->PauseDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(0, ref) << "PauseDistributedHardware fail DCTS_1100";
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(8);
|
||||||
|
EXPECT_EQ(res, finish) << "StopCapture fail DCTS_1100";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
finish = HandleAudioEvent(6);
|
||||||
|
EXPECT_EQ(res, finish) << "CloseMic fail DCTS_1100";
|
||||||
|
sleep(g_audioDelay);
|
||||||
|
|
||||||
|
ref = sinkSrv_->StopDistributedHardware(g_networkId);
|
||||||
|
EXPECT_EQ(0, ref) << "StopDistributedHardware fail DCTS_1100";
|
||||||
|
|
||||||
|
sinkSrv_->ReleaseSink();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,832 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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 <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <csignal>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <securec.h>
|
||||||
|
#include "unistd.h"
|
||||||
|
#include "distributedaudiotest.h"
|
||||||
|
#include "accesstoken_kit.h"
|
||||||
|
#include "nativetoken_kit.h"
|
||||||
|
|
||||||
|
using namespace OHOS::DistributedHardware;
|
||||||
|
using namespace OHOS::Security::AccessToken;
|
||||||
|
namespace {
|
||||||
|
static char const *PKG_NAME = "ohos.dsoftbus.tool";
|
||||||
|
}
|
||||||
|
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioAdapter;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioFormat;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortDirection;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioManager;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioRender;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCapture;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioCategory;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRouteNode;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRoute;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPin;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortType;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortRole;
|
||||||
|
using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioCallbackType;
|
||||||
|
int32_t g_volume = 5;
|
||||||
|
static int32_t ParamEventCallback(AudioExtParamKey key, const char *condition, const char *value, void *reserved,
|
||||||
|
void *cookie);
|
||||||
|
class AudioParamCallbackImpl final : public IAudioCallback {
|
||||||
|
public:
|
||||||
|
AudioParamCallbackImpl() {}
|
||||||
|
~AudioParamCallbackImpl() override {}
|
||||||
|
int32_t RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) override;
|
||||||
|
int32_t ParamCallback(AudioExtParamKey key, const std::string &condition, const std::string &value,
|
||||||
|
int8_t &reserved, int8_t cookie) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t AudioParamCallbackImpl::RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie)
|
||||||
|
{
|
||||||
|
(void) type;
|
||||||
|
(void) reserved;
|
||||||
|
(void) cookie;
|
||||||
|
return DH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t AudioParamCallbackImpl::ParamCallback(AudioExtParamKey key, const std::string &condition,
|
||||||
|
const std::string &value, int8_t &reserved, int8_t cookie)
|
||||||
|
{
|
||||||
|
(void) cookie;
|
||||||
|
void *cookies = nullptr;
|
||||||
|
ParamEventCallback(static_cast<::AudioExtParamKey>(key), condition.c_str(),
|
||||||
|
value.c_str(), static_cast<void *>(&reserved), cookies);
|
||||||
|
return DH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int32_t CMD_FIND = 9;
|
||||||
|
const int32_t CMD_OPEN_SPK = 1;
|
||||||
|
const int32_t CMD_CLOSE_SPK = 2;
|
||||||
|
const int32_t CMD_START_SPK = 3;
|
||||||
|
const int32_t CMD_STOP_SPK = 4;
|
||||||
|
const int32_t CMD_OPEN_MIC = 5;
|
||||||
|
const int32_t CMD_CLOSE_MIC = 6;
|
||||||
|
const int32_t CMD_START_MIC = 7;
|
||||||
|
const int32_t CMD_STOP_MIC = 8;
|
||||||
|
const int32_t CMD_SET_VOL = 11;
|
||||||
|
const int32_t CMD_GET_VOL = 12;
|
||||||
|
|
||||||
|
const char DEV_TYPE_SPK = '1';
|
||||||
|
const char DEV_TYPE_MIC = '2';
|
||||||
|
const char SPK_FILE_PATH[128] = "/data/test.wav";
|
||||||
|
const char MIC_FILE_PATH[128] = "/data/mic.pcm";
|
||||||
|
constexpr int32_t TYPE_OFFSET = 12;
|
||||||
|
constexpr int32_t AUDIO_SAMPLE_RATE = 48000;
|
||||||
|
constexpr int32_t VOLUME_MIN = 0;
|
||||||
|
constexpr int32_t VOLUME_MAX = 15;
|
||||||
|
constexpr int32_t RENDER_FRAME_SIZE = 3840;
|
||||||
|
constexpr int32_t RENDER_INTER_LEAVED = 1;
|
||||||
|
constexpr int32_t RENDER_STREAM_ID = 0;
|
||||||
|
constexpr int32_t RENDER_CHANNEL_MASK = 2;
|
||||||
|
constexpr int32_t CAPTURE_INTER_LEAVED = 1;
|
||||||
|
constexpr int32_t CAPTURE_STREAM_ID = 2;
|
||||||
|
constexpr int32_t CAPTURE_CHANNEL_MASK = 2;
|
||||||
|
constexpr int64_t AUDIO_FRAME_TIME_INTERFAL_DEFAULT = 21333;
|
||||||
|
|
||||||
|
static OHOS::sptr<IAudioManager> g_manager = nullptr;
|
||||||
|
static OHOS::sptr<IAudioAdapter> g_adapter = nullptr;
|
||||||
|
static OHOS::sptr<IAudioRender> g_render = nullptr;
|
||||||
|
static OHOS::sptr<IAudioCapture> g_capture = nullptr;
|
||||||
|
static std::vector<AudioAdapterDescriptor> g_devices;
|
||||||
|
static OHOS::sptr<IAudioCallback> g_callbackStub = nullptr;
|
||||||
|
static std::string g_devId = "";
|
||||||
|
|
||||||
|
static constexpr const char* PLAY_THREAD = "playThread";
|
||||||
|
static constexpr const char* CAPTURE_THREAD = "captureThread";
|
||||||
|
|
||||||
|
uint32_t g_renderId = 0;
|
||||||
|
uint32_t g_captureId = 0;
|
||||||
|
int32_t g_frameNum = 0;
|
||||||
|
int32_t g_frameIndex = 0;
|
||||||
|
int32_t g_micFrameNum = 0;
|
||||||
|
bool g_isInitRenderData = false;
|
||||||
|
static std::vector<uint8_t*> renderData;
|
||||||
|
|
||||||
|
static DeviceStatus g_spkStatus = DeviceStatus::DEVICE_IDLE;
|
||||||
|
static DeviceStatus g_micStatus = DeviceStatus::DEVICE_IDLE;
|
||||||
|
|
||||||
|
static std::thread g_playingThread;
|
||||||
|
static std::thread g_capingThread;
|
||||||
|
FILE *g_micFile = nullptr;
|
||||||
|
|
||||||
|
static int64_t GetNowTimeUs()
|
||||||
|
{
|
||||||
|
std::chrono::microseconds nowUs =
|
||||||
|
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||||
|
return nowUs.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t InitTestDemo()
|
||||||
|
{
|
||||||
|
std::cout << "**********************************************************************************" << std::endl;
|
||||||
|
DHLOGI("**********************************************************************************");
|
||||||
|
std::cout << "Distributed Audio Test Demo Bin v1.3." << std::endl;
|
||||||
|
std::cout << "**********************************************************************************" << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "Init distributed audio hdf service." << std::endl;
|
||||||
|
g_manager = IAudioManager::Get("daudio_primary_service", false);
|
||||||
|
if (g_manager == nullptr) {
|
||||||
|
std::cout << "Distributed audio manager is null, Please Check network!" << std::endl;
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
std::cout << "Load audio manager success." << std::endl;
|
||||||
|
FindAudioDevice();
|
||||||
|
if (g_devId.empty()) {
|
||||||
|
std::cout << "Cannot find distributed device. Please input 9 to query distribtued device." << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Find one distributed device: " << g_devId << std::endl;
|
||||||
|
}
|
||||||
|
return DH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FindAudioDevice()
|
||||||
|
{
|
||||||
|
if (g_manager == nullptr) {
|
||||||
|
std::cout << "Audio manager is null, Please Check network!" << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
int32_t ret = g_manager->GetAllAdapters(g_devices);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout << "Get audio devices failed!" << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
for (uint32_t index = 0; index < g_devices.size(); index++) {
|
||||||
|
const AudioAdapterDescriptor desc = g_devices[index];
|
||||||
|
if (index == 0) {
|
||||||
|
g_devId = desc.adapterName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void HandleDevError(const char *condition, const char *value)
|
||||||
|
{
|
||||||
|
if (condition[TYPE_OFFSET] == DEV_TYPE_SPK && g_spkStatus != DeviceStatus::DEVICE_IDLE) {
|
||||||
|
CloseSpk();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (condition[TYPE_OFFSET] == DEV_TYPE_MIC && g_micStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
CloseMic();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Receive abnormal event, Demo quit." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t ParamEventCallback(AudioExtParamKey key, const char *condition, const char *value, void *reserved,
|
||||||
|
void *cookie)
|
||||||
|
{
|
||||||
|
std::string val(value);
|
||||||
|
std::string con(condition);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "**********************************************************************************" << std::endl;
|
||||||
|
std::cout << "Event recived: " << key << std::endl;
|
||||||
|
std::cout << "Condition: " << con << std::endl;
|
||||||
|
std::cout << "Value: " << val << std::endl;
|
||||||
|
std::cout << "**********************************************************************************" << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
if (key == AudioExtParamKey::AUDIO_EXT_PARAM_KEY_STATUS && con.rfind("ERR_EVENT", 0) == 0) {
|
||||||
|
HandleDevError(condition, value);
|
||||||
|
}
|
||||||
|
return DH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t LoadSpkDev(const std::string &devId)
|
||||||
|
{
|
||||||
|
struct AudioAdapterDescriptor dev;
|
||||||
|
for (uint32_t index = 0; index < g_devices.size(); index++) {
|
||||||
|
struct AudioAdapterDescriptor desc = g_devices[index];
|
||||||
|
if (desc.adapterName == devId) {
|
||||||
|
dev = desc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dev.adapterName.data() == nullptr) {
|
||||||
|
std::cout << "Input device id is wrong." << std::endl;
|
||||||
|
FindAudioDevice();
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
if (g_manager == nullptr) {
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
if (g_adapter == nullptr) {
|
||||||
|
int32_t ret = g_manager->LoadAdapter(dev, g_adapter);
|
||||||
|
if (ret != DH_SUCCESS || g_adapter == nullptr) {
|
||||||
|
std::cout << "Load audio device failed, ret: " << ret << std::endl;
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OpenSpk(std::string devId)
|
||||||
|
{
|
||||||
|
if (g_spkStatus != DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Speaker device is already opened." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
if (LoadSpkDev(devId) != DH_SUCCESS) {
|
||||||
|
std::cout << "Load spk failed" << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
g_callbackStub = new AudioParamCallbackImpl();
|
||||||
|
int32_t ret = g_adapter->RegExtraParamObserver(g_callbackStub, 0);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout << "Register observer failed, ret: " << ret << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AudioDeviceDescriptor renderDesc;
|
||||||
|
renderDesc.pins = AudioPortPin::PIN_OUT_SPEAKER;
|
||||||
|
renderDesc.desc = "";
|
||||||
|
AudioSampleAttributes g_rattrs = {};
|
||||||
|
g_rattrs.type = AudioCategory::AUDIO_IN_MEDIA;
|
||||||
|
g_rattrs.interleaved = RENDER_INTER_LEAVED;
|
||||||
|
g_rattrs.streamId = RENDER_STREAM_ID;
|
||||||
|
g_rattrs.channelCount = RENDER_CHANNEL_MASK;
|
||||||
|
g_rattrs.sampleRate = AUDIO_SAMPLE_RATE;
|
||||||
|
g_rattrs.format = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT;
|
||||||
|
ret = g_adapter->CreateRender(renderDesc, g_rattrs, g_render, g_renderId);
|
||||||
|
if (ret != DH_SUCCESS || g_render == nullptr) {
|
||||||
|
std::cout << "Open SPK device failed, ret: " << ret << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
g_spkStatus = DeviceStatus::DEVICE_OPEN;
|
||||||
|
std::cout << "Open SPK device success." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteStreamWait(const int64_t &startTime)
|
||||||
|
{
|
||||||
|
int64_t endTime = GetNowTimeUs();
|
||||||
|
int64_t passTime = endTime - startTime;
|
||||||
|
|
||||||
|
if (passTime > AUDIO_FRAME_TIME_INTERFAL_DEFAULT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int64_t remainTime = AUDIO_FRAME_TIME_INTERFAL_DEFAULT - passTime;
|
||||||
|
std::this_thread::sleep_for(std::chrono::microseconds(remainTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Play()
|
||||||
|
{
|
||||||
|
if (g_render == nullptr) {
|
||||||
|
std::cout << "SPK device is null." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pthread_setname_np(pthread_self(), PLAY_THREAD) != DH_SUCCESS) {
|
||||||
|
std::cout << "Play thread setname failed." << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << "Playing thread started." << std::endl;
|
||||||
|
g_render->Start();
|
||||||
|
g_spkStatus = DeviceStatus::DEVICE_START;
|
||||||
|
|
||||||
|
uint64_t size = 0;
|
||||||
|
while (g_spkStatus == DeviceStatus::DEVICE_START) {
|
||||||
|
int64_t startTime = GetNowTimeUs();
|
||||||
|
|
||||||
|
std::vector<int8_t> frameHal(RENDER_FRAME_SIZE);
|
||||||
|
int32_t ret = memcpy_s(frameHal.data(), RENDER_FRAME_SIZE, renderData[g_frameIndex], RENDER_FRAME_SIZE);
|
||||||
|
if (ret != EOK) {
|
||||||
|
DHLOGE("Copy render frame failed, error code %{public}d.", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ret = g_render->RenderFrame(frameHal, size);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout<<"RenderFrame failed, index: "<< g_frameIndex << ", ret: " << ret << std::endl;
|
||||||
|
}
|
||||||
|
g_frameIndex++;
|
||||||
|
if (g_frameNum != 0 && g_frameIndex == g_frameNum) {
|
||||||
|
g_frameIndex = 0;
|
||||||
|
}
|
||||||
|
WriteStreamWait(startTime);
|
||||||
|
}
|
||||||
|
std::cout << "Playing thread stopped." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StartRender()
|
||||||
|
{
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Speaker device is not opened, start render failed." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_OPEN) {
|
||||||
|
WavHdr wavHeader;
|
||||||
|
size_t headerSize = sizeof(WavHdr);
|
||||||
|
if (!g_isInitRenderData) {
|
||||||
|
struct stat statbuf;
|
||||||
|
stat(SPK_FILE_PATH, &statbuf);
|
||||||
|
int32_t size = statbuf.st_size;
|
||||||
|
g_frameNum = (size - static_cast<int32_t>(headerSize)) / RENDER_FRAME_SIZE;
|
||||||
|
std::cout << "Audio file frame num: " << g_frameNum << std::endl;
|
||||||
|
for (int32_t j = 0; j < g_frameNum; j++) {
|
||||||
|
uint8_t *frame = new uint8_t[RENDER_FRAME_SIZE]();
|
||||||
|
renderData.push_back(frame);
|
||||||
|
}
|
||||||
|
g_isInitRenderData = true;
|
||||||
|
}
|
||||||
|
FILE *wavFile = fopen(SPK_FILE_PATH, "rb");
|
||||||
|
|
||||||
|
if (wavFile == nullptr) {
|
||||||
|
DHLOGE("open spk file path failed!");
|
||||||
|
std::cout << "open spk file path failed!" << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
fread(&wavHeader, 1, headerSize, wavFile);
|
||||||
|
for (int32_t i = 0; i < g_frameNum; i++) {
|
||||||
|
fread(renderData[i], 1, RENDER_FRAME_SIZE, wavFile);
|
||||||
|
}
|
||||||
|
fclose(wavFile);
|
||||||
|
g_frameIndex = 0;
|
||||||
|
g_playingThread = std::thread(Play);
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_START) {
|
||||||
|
std::cout << "Speaker device is started." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_STOP) {
|
||||||
|
g_playingThread = std::thread(Play);
|
||||||
|
}
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StopRender()
|
||||||
|
{
|
||||||
|
if (g_render == nullptr) {
|
||||||
|
std::cout << "SPK device is null." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Speaker device is not opened." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_OPEN) {
|
||||||
|
std::cout << "Speaker device is not started." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_STOP) {
|
||||||
|
std::cout << "Speaker device is already stoped." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
g_spkStatus = DeviceStatus::DEVICE_STOP;
|
||||||
|
if (g_playingThread.joinable()) {
|
||||||
|
g_playingThread.join();
|
||||||
|
}
|
||||||
|
g_render->Stop();
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CloseSpk()
|
||||||
|
{
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Speaker device is not opened." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_START) {
|
||||||
|
StopRender();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = g_adapter->DestroyRender(g_renderId);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout << "Close speaker failed" << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
g_manager->UnloadAdapter(g_devId);
|
||||||
|
g_adapter = nullptr;
|
||||||
|
}
|
||||||
|
g_spkStatus = DeviceStatus::DEVICE_IDLE;
|
||||||
|
|
||||||
|
if (g_isInitRenderData) {
|
||||||
|
for (auto &p : renderData) {
|
||||||
|
delete[] p;
|
||||||
|
}
|
||||||
|
renderData.clear();
|
||||||
|
g_isInitRenderData = false;
|
||||||
|
}
|
||||||
|
std::cout << "Close SPK device success." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t LoadMicDev(const std::string &devId)
|
||||||
|
{
|
||||||
|
struct AudioAdapterDescriptor dev;
|
||||||
|
for (uint32_t index = 0; index < g_devices.size(); index++) {
|
||||||
|
struct AudioAdapterDescriptor desc = g_devices[index];
|
||||||
|
if (desc.adapterName == devId) {
|
||||||
|
dev = desc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dev.adapterName.data() == nullptr) {
|
||||||
|
std::cout << "Input device id is wrong." << std::endl;
|
||||||
|
FindAudioDevice();
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
if (g_manager == nullptr) {
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
if (g_adapter == nullptr) {
|
||||||
|
int32_t ret = g_manager->LoadAdapter(dev, g_adapter);
|
||||||
|
if (ret != DH_SUCCESS || g_adapter == nullptr) {
|
||||||
|
std::cout << "Load audio device failed, ret: " << ret << std::endl;
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OpenMic(std::string devId)
|
||||||
|
{
|
||||||
|
if (g_micStatus != DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Mic device is already opened." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
if (LoadMicDev(devId) != DH_SUCCESS) {
|
||||||
|
std::cout << "Load audio device failed." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioDeviceDescriptor captureDesc;
|
||||||
|
captureDesc.pins = AudioPortPin::PIN_IN_MIC;
|
||||||
|
captureDesc.desc = "";
|
||||||
|
AudioSampleAttributes captureAttr;
|
||||||
|
captureAttr.type = AudioCategory::AUDIO_IN_MEDIA;
|
||||||
|
captureAttr.interleaved = CAPTURE_INTER_LEAVED;
|
||||||
|
captureAttr.streamId = CAPTURE_STREAM_ID;
|
||||||
|
captureAttr.channelCount = CAPTURE_CHANNEL_MASK;
|
||||||
|
captureAttr.sampleRate = AUDIO_SAMPLE_RATE;
|
||||||
|
captureAttr.format = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT;
|
||||||
|
int32_t ret = g_adapter->CreateCapture(captureDesc, captureAttr, g_capture, g_captureId);
|
||||||
|
if (ret != DH_SUCCESS || g_capture == nullptr) {
|
||||||
|
std::cout << "Open MIC device failed." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
g_micStatus = DeviceStatus::DEVICE_OPEN;
|
||||||
|
std::cout << "Open MIC device success." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ReadStreamWait(const int64_t &startTime)
|
||||||
|
{
|
||||||
|
int64_t endTime = GetNowTimeUs();
|
||||||
|
int32_t passTime = endTime - startTime;
|
||||||
|
|
||||||
|
if (passTime > AUDIO_FRAME_TIME_INTERFAL_DEFAULT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int64_t remainTime = AUDIO_FRAME_TIME_INTERFAL_DEFAULT - passTime;
|
||||||
|
std::this_thread::sleep_for(std::chrono::microseconds(remainTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Capture()
|
||||||
|
{
|
||||||
|
if (g_capture == nullptr) {
|
||||||
|
std::cout << "MIC device is null." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pthread_setname_np(pthread_self(), CAPTURE_THREAD) != DH_SUCCESS) {
|
||||||
|
std::cout << "Capture thread setname failed." << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << "Capturing thread started." << std::endl;
|
||||||
|
g_capture->Start();
|
||||||
|
g_micStatus = DeviceStatus::DEVICE_START;
|
||||||
|
|
||||||
|
uint64_t size = 0;
|
||||||
|
while (g_micStatus == DeviceStatus::DEVICE_START) {
|
||||||
|
std::vector<int8_t> data(RENDER_FRAME_SIZE);
|
||||||
|
int64_t startTime = GetNowTimeUs();
|
||||||
|
int32_t ret = g_capture->CaptureFrame(data, size);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout << "CaptureFrame failed, ret: " << ret << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t writeCnt = fwrite(data.data(), 1, RENDER_FRAME_SIZE, g_micFile);
|
||||||
|
if (static_cast<int32_t>(writeCnt) != RENDER_FRAME_SIZE) {
|
||||||
|
std::cout << "fwrite data failed." << std::endl;
|
||||||
|
}
|
||||||
|
g_micFrameNum++;
|
||||||
|
ReadStreamWait(startTime);
|
||||||
|
}
|
||||||
|
std::cout << "Capturing thread stopped." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StartCapture()
|
||||||
|
{
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Mic device is not opened, start capture failed." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_OPEN) {
|
||||||
|
g_micFile = fopen(MIC_FILE_PATH, "ab+");
|
||||||
|
if (g_micFile == nullptr) {
|
||||||
|
std::cout << "Open pcm file failed." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
g_capingThread = std::thread(Capture);
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_START) {
|
||||||
|
std::cout << "Mic device is already started." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_STOP) {
|
||||||
|
g_capingThread = std::thread(Capture);
|
||||||
|
}
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StopCapture()
|
||||||
|
{
|
||||||
|
if (g_capture == nullptr) {
|
||||||
|
std::cout << "MIC device is null." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Mic device is not opened." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_OPEN) {
|
||||||
|
std::cout << "Mic device is not started." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_STOP) {
|
||||||
|
std::cout << "Mic device is already started." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
g_micStatus = DeviceStatus::DEVICE_STOP;
|
||||||
|
if (g_capingThread.joinable()) {
|
||||||
|
g_capingThread.join();
|
||||||
|
}
|
||||||
|
g_capture->Stop();
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CloseMic()
|
||||||
|
{
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Mic device is not opened." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_micStatus == DeviceStatus::DEVICE_START) {
|
||||||
|
StopCapture();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = g_adapter->DestroyCapture(g_captureId);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout << "Close mic failed." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
g_manager->UnloadAdapter(g_devId);
|
||||||
|
g_adapter = nullptr;
|
||||||
|
}
|
||||||
|
if (g_micFile != nullptr) {
|
||||||
|
fclose(g_micFile);
|
||||||
|
g_micFile = nullptr;
|
||||||
|
}
|
||||||
|
g_micStatus = DeviceStatus::DEVICE_IDLE;
|
||||||
|
std::cout << "Close MIC device success." << std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SetVolume(int vol)
|
||||||
|
{
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Speaker is not opened, can not set volume." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
std::cout << "Please input volum to set [0,15]." << std::endl;
|
||||||
|
if (vol < VOLUME_MIN || vol > VOLUME_MAX) {
|
||||||
|
std::cout << "Volume is invalid." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
std::cout << "Set volume: " << vol << std::endl;
|
||||||
|
AudioExtParamKey key = AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME;
|
||||||
|
std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=1;AUDIO_VOLUME_TYPE=1;";
|
||||||
|
std::string volStr = std::to_string(vol);
|
||||||
|
int32_t ret = g_adapter->SetExtraParams(key, condition, volStr);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout << "Set volume failed" << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetVolume()
|
||||||
|
{
|
||||||
|
if (g_spkStatus == DeviceStatus::DEVICE_IDLE) {
|
||||||
|
std::cout << "Speaker is not opened, can not get volume." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
AudioExtParamKey key = AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME;
|
||||||
|
std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=1;AUDIO_VOLUME_TYPE=1;";
|
||||||
|
std::string vol;
|
||||||
|
int32_t ret = g_adapter->GetExtraParams(key, condition.c_str(), vol);
|
||||||
|
if (ret != DH_SUCCESS) {
|
||||||
|
std::cout << "Get Volume failed." << std::endl;
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
std::cout << "Get volume success. volume: " << vol <<std::endl;
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string HandleAudioEvent(int32_t cmd)
|
||||||
|
{
|
||||||
|
std::string res = "";
|
||||||
|
if (cmd == CMD_FIND) {
|
||||||
|
res = FindAudioDevice();
|
||||||
|
}
|
||||||
|
if (cmd == CMD_OPEN_SPK) {
|
||||||
|
res = OpenSpk(g_devId);
|
||||||
|
}
|
||||||
|
if (cmd == CMD_START_SPK) {
|
||||||
|
res = StartRender();
|
||||||
|
}
|
||||||
|
if (cmd == CMD_STOP_SPK) {
|
||||||
|
res = StopRender();
|
||||||
|
}
|
||||||
|
if (cmd == CMD_CLOSE_SPK) {
|
||||||
|
res = CloseSpk();
|
||||||
|
}
|
||||||
|
if (cmd == CMD_OPEN_MIC) {
|
||||||
|
res = OpenMic(g_devId);
|
||||||
|
}
|
||||||
|
if (cmd == CMD_START_MIC) {
|
||||||
|
res = StartCapture();
|
||||||
|
}
|
||||||
|
if (cmd == CMD_STOP_MIC) {
|
||||||
|
res = StopCapture();
|
||||||
|
}
|
||||||
|
if (cmd == CMD_CLOSE_MIC) {
|
||||||
|
res = CloseMic();
|
||||||
|
}
|
||||||
|
if (cmd == CMD_SET_VOL) {
|
||||||
|
res = SetVolume(g_volume);
|
||||||
|
}
|
||||||
|
if (cmd == CMD_GET_VOL) {
|
||||||
|
res = GetVolume();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t GetSyncOnlineDevices(std::string& netWorkId)
|
||||||
|
{
|
||||||
|
uint64_t tokenId;
|
||||||
|
const char *perms[2];
|
||||||
|
perms[0] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
|
||||||
|
perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
|
||||||
|
NativeTokenInfoParams infoInstance = {
|
||||||
|
.dcapsNum = 0,
|
||||||
|
.permsNum = 2,
|
||||||
|
.aclsNum = 0,
|
||||||
|
.dcaps = NULL,
|
||||||
|
.perms = perms,
|
||||||
|
.acls = NULL,
|
||||||
|
.processName = "camera_test_demo",
|
||||||
|
.aplStr = "system_core",
|
||||||
|
};
|
||||||
|
tokenId = GetAccessTokenId(&infoInstance);
|
||||||
|
SetSelfTokenID(tokenId);
|
||||||
|
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
||||||
|
|
||||||
|
NodeBasicInfo localNodeinfo;
|
||||||
|
NodeBasicInfo *remoteNodeInfo = nullptr;
|
||||||
|
int32_t infoNum = 0;
|
||||||
|
std::cout << "-----------Local Device Info------" << std::endl;
|
||||||
|
if (GetLocalNodeDeviceInfo(PKG_NAME, &localNodeinfo) != 0) {
|
||||||
|
printf("LnnGetLocalNodeInfo Fail!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
PrintNodeProperty(&localNodeinfo);
|
||||||
|
std::cout << "-------Remote Device info---------" << std::endl;
|
||||||
|
if (GetAllNodeDeviceInfo(PKG_NAME, &remoteNodeInfo, &infoNum) != 0) {
|
||||||
|
printf("GetAllNodeDeviceInfo Fail!\n");
|
||||||
|
return ERR_DH_AUDIO_FAILED;
|
||||||
|
}
|
||||||
|
std::cout << "Device Num = " << infoNum << std::endl;
|
||||||
|
for (int i = 0; i < infoNum; ++i) {
|
||||||
|
PrintNodeProperty(remoteNodeInfo + i, netWorkId);
|
||||||
|
}
|
||||||
|
FreeNodeInfo(remoteNodeInfo);
|
||||||
|
std::cout << "SoftBusDumpDeviceInfo complete!" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintNodeProperty(NodeBasicInfo *nodeInfo)
|
||||||
|
{
|
||||||
|
if (nodeInfo == nullptr) {
|
||||||
|
std::cout << "nodeInfo is nullptr" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("DeviceName = %s\n", nodeInfo->deviceName);
|
||||||
|
std::cout << "NetworkId = " << nodeInfo->networkId << std::endl;
|
||||||
|
|
||||||
|
NodeDeviceInfoKey key = NODE_KEY_UDID;
|
||||||
|
unsigned char udid[UDID_BUF_LEN] = {0};
|
||||||
|
if (GetNodeKeyInfo(PKG_NAME, nodeInfo->networkId, key, udid, UDID_BUF_LEN) != 0) {
|
||||||
|
std::cout << "GetNodeKeyInfo Fail!" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Udid = " << reinterpret_cast<char *>(udid) << std::endl;
|
||||||
|
}
|
||||||
|
key = NODE_KEY_UUID;
|
||||||
|
unsigned char uuid[UUID_BUF_LEN] = {0};
|
||||||
|
if (GetNodeKeyInfo(PKG_NAME, nodeInfo->networkId, key, uuid, UUID_BUF_LEN) != 0) {
|
||||||
|
printf("GetNodeKeyInfo Fail!\n");
|
||||||
|
} else {
|
||||||
|
std::cout << "uuid = " << reinterpret_cast<char *>(uuid) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintNodeProperty(NodeBasicInfo *nodeInfo, std::string& netWorkId)
|
||||||
|
{
|
||||||
|
if (nodeInfo == nullptr) {
|
||||||
|
std::cout << "nodeInfo is nullptr" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("DeviceName = %s\n", nodeInfo->deviceName);
|
||||||
|
netWorkId = nodeInfo->networkId;
|
||||||
|
std::cout << "NetworkId = " << nodeInfo->networkId << std::endl;
|
||||||
|
|
||||||
|
NodeDeviceInfoKey key = NODE_KEY_UDID;
|
||||||
|
unsigned char udid[UDID_BUF_LEN] = {0};
|
||||||
|
if (GetNodeKeyInfo(PKG_NAME, nodeInfo->networkId, key, udid, UDID_BUF_LEN) != 0) {
|
||||||
|
std::cout << "GetNodeKeyInfo Fail!" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Udid = " << reinterpret_cast<char *>(udid) << std::endl;
|
||||||
|
}
|
||||||
|
key = NODE_KEY_UUID;
|
||||||
|
unsigned char uuid[UUID_BUF_LEN] = {0};
|
||||||
|
if (GetNodeKeyInfo(PKG_NAME, nodeInfo->networkId, key, uuid, UUID_BUF_LEN) != 0) {
|
||||||
|
printf("GetNodeKeyInfo Fail!\n");
|
||||||
|
} else {
|
||||||
|
std::cout << "uuid = " << reinterpret_cast<char *>(uuid) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddPermission(void)
|
||||||
|
{
|
||||||
|
uint64_t tokenId;
|
||||||
|
const char *perms[2];
|
||||||
|
perms[0] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
|
||||||
|
perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
|
||||||
|
NativeTokenInfoParams infoTnstance = {
|
||||||
|
.dcapsNum = 0,
|
||||||
|
.permsNum = 2,
|
||||||
|
.aclsNum = 0,
|
||||||
|
.dcaps = NULL,
|
||||||
|
.perms = perms,
|
||||||
|
.acls = NULL,
|
||||||
|
.processName = "daudio_test_service",
|
||||||
|
.aplStr = "system_core",
|
||||||
|
};
|
||||||
|
tokenId = GetAccessTokenId(&infoTnstance);
|
||||||
|
SetSelfTokenID(tokenId);
|
||||||
|
}
|
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISTRIBUTED_AUDIO_TEST_H
|
||||||
|
#define DISTRIBUTED_AUDIO_TEST_H
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <v1_0/iaudio_adapter.h>
|
||||||
|
#include <v1_0/iaudio_manager.h>
|
||||||
|
#include <v1_0/iaudio_callback.h>
|
||||||
|
#include <v1_0/audio_types.h>
|
||||||
|
#include "distributed_hardware_log.h"
|
||||||
|
#include "softbus_bus_center.h"
|
||||||
|
#include "softbus_common.h"
|
||||||
|
#include "token_setproc.h"
|
||||||
|
|
||||||
|
enum class DeviceStatus : uint32_t {
|
||||||
|
DEVICE_IDLE = 0,
|
||||||
|
DEVICE_OPEN = 1,
|
||||||
|
DEVICE_START = 2,
|
||||||
|
DEVICE_STOP = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WAV_HEADER {
|
||||||
|
/* RIFF Chunk Descriptor */
|
||||||
|
uint8_t riff[4] = {'R', 'I', 'F', 'F'};
|
||||||
|
uint32_t chunkSize = 0;
|
||||||
|
uint8_t wave[4] = {'W', 'A', 'V', 'E'};
|
||||||
|
/* "fmt" sub-chunk */
|
||||||
|
uint8_t fmt[4] = {'f', 'm', 't', ' '};
|
||||||
|
uint32_t subchunk1Size = 16;
|
||||||
|
uint16_t audioFormat = 1;
|
||||||
|
uint16_t numOfChan = 2;
|
||||||
|
uint32_t samplesPerSec = 44100;
|
||||||
|
uint32_t bytesPerSec = 176400;
|
||||||
|
uint16_t blockAlign = 2;
|
||||||
|
uint16_t bitsPerSample = 16;
|
||||||
|
/* "data" sub-chunk */
|
||||||
|
uint8_t subchunk2ID[4] = {'d', 'a', 't', 'a'};
|
||||||
|
uint32_t subchunk2Size = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DAudioErrorCode {
|
||||||
|
DH_SUCCESS = 0,
|
||||||
|
ERR_DH_AUDIO_NULLPTR = -40000,
|
||||||
|
ERR_DH_AUDIO_FAILED = -40001,
|
||||||
|
ERR_DH_AUDIO_NOT_SUPPORT = -40002,
|
||||||
|
|
||||||
|
ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED = -40003,
|
||||||
|
ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED = -40004,
|
||||||
|
ERR_DH_AUDIO_SA_CALLBACK_NOT_FOUND = -40005,
|
||||||
|
ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN = -40006,
|
||||||
|
ERR_DH_AUDIO_SA_WAIT_TIMEOUT = -40007,
|
||||||
|
ERR_DH_AUDIO_SA_PARAM_INVALID = -40008,
|
||||||
|
ERR_DH_AUDIO_SA_DEVICE_NOT_EXIST = -40009,
|
||||||
|
ERR_DH_AUDIO_SA_PROXY_NOT_INIT = -40010,
|
||||||
|
ERR_DH_AUDIO_SA_LOAD_FAILED = -40011,
|
||||||
|
ERR_DH_AUDIO_SA_STATUS_ERR = -40012,
|
||||||
|
ERR_DH_AUDIO_NOT_FOUND_KEY = -40013,
|
||||||
|
ERR_DH_AUDIO_SA_DEVID_ILLEGAL = -40014,
|
||||||
|
ERR_DH_AUDIO_SA_PERMISSION_FAIED = -40015,
|
||||||
|
|
||||||
|
// trans error
|
||||||
|
ERR_DH_AUDIO_TRANS_ERROR = -40015,
|
||||||
|
ERR_DH_AUDIO_TRANS_ILLEGAL_OPERATION = -40016,
|
||||||
|
ERR_DH_AUDIO_TRANS_SESSION_NOT_OPEN = -40017,
|
||||||
|
|
||||||
|
// codec error
|
||||||
|
ERR_DH_AUDIO_BAD_VALUE = -42000,
|
||||||
|
ERR_DH_AUDIO_BAD_OPERATE = -42001,
|
||||||
|
ERR_DH_AUDIO_CODEC_CONFIG = -42002,
|
||||||
|
ERR_DH_AUDIO_CODEC_START = -42003,
|
||||||
|
ERR_DH_AUDIO_CODEC_STOP = -42004,
|
||||||
|
ERR_DH_AUDIO_CODEC_RELEASE = -42005,
|
||||||
|
ERR_DH_AUDIO_CODEC_INPUT = -42006,
|
||||||
|
|
||||||
|
// spk client error
|
||||||
|
ERR_DH_AUDIO_CLIENT_PARAM_ERROR = -43000,
|
||||||
|
ERR_DH_AUDIO_CLIENT_RENDER_CREATE_FAILED = -43001,
|
||||||
|
ERR_DH_AUDIO_CLIENT_RENDER_STARTUP_FAILURE = -43002,
|
||||||
|
ERR_DH_AUDIO_CLIENT_RENDER_STOP_FAILED = -43003,
|
||||||
|
ERR_DH_AUDIO_CLIENT_RENDER_RELEASE_FAILED = -43004,
|
||||||
|
ERR_DH_AUDIO_CLIENT_SET_VOLUME_FAILED = -43005,
|
||||||
|
ERR_DH_AUDIO_CLIENT_SET_MUTE_FAILED = -43006,
|
||||||
|
|
||||||
|
// mic client error
|
||||||
|
ERR_DH_AUDIO_CLIENT_CAPTURER_CREATE_FAILED = -43007,
|
||||||
|
ERR_DH_AUDIO_CLIENT_CAPTURER_START_FAILED = -43008,
|
||||||
|
|
||||||
|
// other error
|
||||||
|
ERR_DH_AUDIO_HDI_CALL_FAILED = -44000,
|
||||||
|
ERR_DH_AUDIO_HDI_INVALID_PARAM = -44001,
|
||||||
|
ERR_DH_AV_TRANS_CREATE_CHANNEL_FAILED = -44002,
|
||||||
|
ERR_DH_AUDIO_ACCESS_PERMISSION_CHECK_FAIL = -44003,
|
||||||
|
};
|
||||||
|
|
||||||
|
using WavHdr = struct WAV_HEADER;
|
||||||
|
int32_t InitTestDemo();
|
||||||
|
std::string FindAudioDevice();
|
||||||
|
std::string OpenSpk(std::string devId);
|
||||||
|
std::string StartRender();
|
||||||
|
std::string StopRender();
|
||||||
|
std::string CloseSpk();
|
||||||
|
std::string OpenMic(std::string devId);
|
||||||
|
std::string StartCapture();
|
||||||
|
std::string StopCapture();
|
||||||
|
std::string CloseMic();
|
||||||
|
std::string SetVolume(int vol);
|
||||||
|
std::string GetVolume();
|
||||||
|
std::string HandleAudioEvent(int32_t cmd);
|
||||||
|
int32_t GetSyncOnlineDevices(std::string& netWorkId);
|
||||||
|
void PrintNodeProperty(NodeBasicInfo *nodeInfo);
|
||||||
|
void PrintNodeProperty(NodeBasicInfo *nodeInfo, std::string& netWorkId);
|
||||||
|
void AddPermission(void);
|
||||||
|
#endif
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2022-2023 - 2023 Huawei Device Co., Ltd.
|
# Copyright (c) 2022-2023 - 2024 Huawei Device Co., Ltd.
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
@ -1407,9 +1407,9 @@ RetCode DcameraHdfDemo::GetExposureCompensationRange(std::shared_ptr<CameraAbili
|
|||||||
common_metadata_header_t* data = ability->get();
|
common_metadata_header_t* data = ability->get();
|
||||||
std::vector<int32_t> exposureCompensationRange;
|
std::vector<int32_t> exposureCompensationRange;
|
||||||
camera_metadata_item_t entry;
|
camera_metadata_item_t entry;
|
||||||
int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_AE_COMPENSATION_RANGE, &entry);
|
int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_AE_COMPENSATION_RANGE, &entry);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
DHLOGI("demo test: get OHOS_CONTROL_AE_COMPENSATION_RANGE error");
|
DHLOGI("demo test: get OHOS_ABILITY_AE_COMPENSATION_RANGE error");
|
||||||
return RC_ERROR;
|
return RC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1431,9 +1431,9 @@ RetCode DcameraHdfDemo::GetExposureCompensationSteps(std::shared_ptr<CameraAbili
|
|||||||
common_metadata_header_t* data = ability->get();
|
common_metadata_header_t* data = ability->get();
|
||||||
camera_rational_t exposureCompensationSteps;
|
camera_rational_t exposureCompensationSteps;
|
||||||
camera_metadata_item_t entry;
|
camera_metadata_item_t entry;
|
||||||
int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_CONTROL_AE_COMPENSATION_STEP, &entry);
|
int ret = OHOS::Camera::FindCameraMetadataItem(data, OHOS_ABILITY_AE_COMPENSATION_STEP, &entry);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
DHLOGI("demo test: get OHOS_CONTROL_AE_COMPENSATION_STEP error");
|
DHLOGI("demo test: get OHOS_ABILITY_AE_COMPENSATION_STEP error");
|
||||||
return RC_ERROR;
|
return RC_ERROR;
|
||||||
}
|
}
|
||||||
exposureCompensationSteps.numerator = entry.data.r->numerator;
|
exposureCompensationSteps.numerator = entry.data.r->numerator;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
Loading…
Reference in New Issue
Block a user