1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef TEST_CASE_COMMON_H 17 #define TEST_CASE_COMMON_H 18 #include <cstdint> 19 #include "i_renderer_stream.h" 20 #include "i_capturer_stream.h" 21 #include "audio_errors.h" 22 #include "hpae_info.h" 23 #include "hpae_msg_channel.h" 24 25 namespace OHOS { 26 namespace AudioStandard { 27 constexpr int OFFSET_BIT_24 = 3; 28 constexpr int BIT_DEPTH_TWO = 2; 29 constexpr int BIT_16 = 16; 30 constexpr int BIT_8 = 8; 31 constexpr float TEST_VALUE_PRESION = 0.001; 32 constexpr int TEST_FREAME_LEN = 125; 33 constexpr int TEST_SUB_FREAME_LEN = 50; 34 constexpr int TEST_LEN_LT_FOUR = 3; 35 36 #define DEFAULT_TEST_SINK_NAME "hdi_output" 37 #define DEFAULT_TEST_AUDIO_DEVICE_NAME "Speaker" 38 #define DEFAULT_TEST_DEVICE_CLASS "file_io" 39 #define DEFAULT_TEST_DEVICE_NETWORKID "LocalDevice" 40 41 class WriteFixedDataCb : public IStreamCallback, public std::enable_shared_from_this<WriteFixedDataCb> { 42 public: 43 int32_t OnStreamData(AudioCallBackStreamInfo& callBackStremInfo) override; 44 WriteFixedDataCb(AudioSampleFormat format)45 explicit WriteFixedDataCb(AudioSampleFormat format) : format_(format) 46 {} ~WriteFixedDataCb()47 virtual ~WriteFixedDataCb() 48 {} 49 50 private: 51 int32_t writeNum_ = 0; 52 AudioSampleFormat format_ = SAMPLE_F32LE; 53 }; 54 55 class WriteFixedValueCb : public IStreamCallback, public std::enable_shared_from_this<WriteFixedValueCb> { 56 public: 57 int32_t OnStreamData(AudioCallBackStreamInfo& callBackStremInfo) override; WriteFixedValueCb(AudioSampleFormat format,int32_t fixedValue)58 WriteFixedValueCb(AudioSampleFormat format, int32_t fixedValue) : format_(format), fixValue_(fixedValue) 59 {} ~WriteFixedValueCb()60 virtual ~WriteFixedValueCb() 61 {} 62 63 private: 64 AudioSampleFormat format_ = SAMPLE_F32LE; 65 int32_t fixValue_ = 0; 66 }; 67 68 class WriteIncDataCb : public IStreamCallback, public std::enable_shared_from_this<WriteIncDataCb> { 69 public: 70 int32_t OnStreamData(AudioCallBackStreamInfo& callBackStremInfo) override; WriteIncDataCb(AudioSampleFormat format)71 explicit WriteIncDataCb(AudioSampleFormat format) : format_(format) 72 {} ~WriteIncDataCb()73 virtual ~WriteIncDataCb() 74 {} 75 76 private: 77 int32_t writeNum_ = 0; 78 AudioSampleFormat format_ = SAMPLE_F32LE; 79 }; 80 81 class StatusChangeCb : public IStreamStatusCallback, public std::enable_shared_from_this<StatusChangeCb> { 82 public: 83 void OnStatusUpdate(IOperation operation, uint32_t streamIndex) override; 84 IStatus GetStatus(); 85 virtual ~StatusChangeCb() = default; 86 private: 87 IStatus status_; 88 }; 89 90 class ReadDataCb : public ICapturerStreamCallback, public std::enable_shared_from_this<ReadDataCb> { 91 public: 92 explicit ReadDataCb(const std::string &fileName); 93 virtual ~ReadDataCb(); 94 int32_t OnStreamData(AudioCallBackCapturerStreamInfo &callBackStreamInfo) override; 95 private: 96 FILE *testFile_ = nullptr; 97 }; 98 99 class NodeStatusCallback : public HPAE::INodeCallback, public std::enable_shared_from_this<NodeStatusCallback> { 100 public: 101 virtual ~NodeStatusCallback() = default; 102 }; 103 104 void TestCapturerSourceFrame(char *frame, uint64_t requestBytes, uint64_t &replyBytes); 105 } // namespace AudioStandard 106 } // namespace OHOS 107 #endif