• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 OHOS_SHARING_AUDIO_PLAY_CONTROLLER_H
17 #define OHOS_SHARING_AUDIO_PLAY_CONTROLLER_H
18 
19 #include <thread>
20 #include "buffer_dispatcher.h"
21 #include "common/event_comm.h"
22 #include "mediaplayer/include/audio_player.h"
23 
24 
25 namespace OHOS {
26 namespace Sharing {
27 
28 class AudioPlayController {
29 public:
30     explicit AudioPlayController(uint32_t mediaChannelId);
31     ~AudioPlayController();
32 
33     void Release();
34     void SetVolume(float volume);
35     void Stop(BufferDispatcher::Ptr &dispatcher);
36     void DropOneFrame();
37     bool Init(AudioTrack &audioTrack);
38     bool Start(BufferDispatcher::Ptr &dispatcher);
39     int64_t GetAudioDecoderTimestamp();
40 
41 protected:
42     void StopAudioThread();
43     void AudioPlayThread();
44     void StartAudioThread();
45 
46 private:
47     uint32_t mediachannelId_ = 0;
48     std::atomic_bool isAudioRunning_ = false;
49     std::shared_ptr<AudioPlayer> audioPlayer_ = nullptr;
50     std::shared_ptr<std::thread> audioPlayThread_ = nullptr;
51     std::shared_ptr<BufferReceiver> bufferReceiver_ = nullptr;
52 };
53 
54 } // namespace Sharing
55 } // namespace OHOS
56 #endif