1 /* 2 * Copyright (c) 2021-2022 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 AUDIO_INTERRUPT_TEST_H 17 #define AUDIO_INTERRUPT_TEST_H 18 19 #include <cstdint> 20 #include <cstdio> 21 #include <thread> 22 #include <memory> 23 #include "audio_info.h" 24 #include "audio_renderer.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 class AudioInterruptTest : public AudioRendererCallback, public std::enable_shared_from_this<AudioInterruptTest> { 29 public: GetPtr()30 std::shared_ptr<AudioInterruptTest> GetPtr() 31 { 32 return shared_from_this(); 33 } 34 35 int32_t TestPlayback(); 36 void OnInterrupt(const InterruptEvent &interruptEvent) override; 37 void OnStateChange(const RendererState state, const StateChangeCmdType __attribute__((unused)) cmdType) override; 38 void SaveStreamInfo(ContentType contentType, StreamUsage streamUsage); 39 FILE *wavFile_ = nullptr; 40 private: 41 bool InitRender(); 42 bool StartRender(); 43 bool GetBufferLen(size_t &bufferLen) const; 44 void WriteBuffer(); 45 AudioSampleFormat GetSampleFormat(int32_t wavSampleFormat); 46 47 std::unique_ptr<AudioRenderer> audioRenderer_ = nullptr; 48 bool isRenderPaused_ = false; 49 bool isStopInProgress_ = false; 50 bool isRenderStopped_ = false; 51 bool isRenderingCompleted_ = false; 52 std::unique_ptr<std::thread> writeThread_ = nullptr; 53 ContentType contentType_ = ContentType::CONTENT_TYPE_MUSIC; 54 StreamUsage streamUsage_ = StreamUsage::STREAM_USAGE_MEDIA; 55 }; 56 } // namespace AudioStandard 57 } // namespace OHOS 58 #endif // AUDIO_INTERRUPT_TEST_H 59