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_MEDIA_CONTROLLER_H
17#define OHOS_SHARING_MEDIA_CONTROLLER_H
18
19#include <thread>
20#include "audio_play_controller.h"
21#include "common/event_channel.h"
22#include "mediachannel/buffer_dispatcher.h"
23#include "video_play_controller.h"
24
25
26namespace OHOS {
27namespace Sharing {
28
29class MediaChannel;
30
31class MediaController : public std::enable_shared_from_this<MediaController> {
32public:
33    using Ptr = std::shared_ptr<MediaController>;
34
35    explicit MediaController(uint32_t mediaChannelId);
36    virtual ~MediaController();
37
38    void SetMediaChannel(std::shared_ptr<MediaChannel> mediaChannel)
39    {
40        SHARING_LOGD("trace.");
41        mediaChannel_ = mediaChannel;
42    }
43
44public:
45    void Stop();
46    void Start();
47    void Release();
48    bool Init(AudioTrack audioTrack, VideoTrack videoTrack);
49
50    void RemoveSurface(uint64_t surfaceId);
51    bool AppendSurface(sptr<Surface> surface, SceneType sceneType);
52
53    void SetVolume(float volume);
54    void SetKeyMode(uint64_t surfaceId, bool mode);
55    void SetKeyRedirect(uint64_t surfaceId, bool keyRedirect);
56
57    void OnPlayControllerNotify(ProsumerStatusMsg::Ptr &statusMsg);
58
59private:
60    uint32_t mediachannelId_ = 0;
61    std::mutex playAudioMutex_;
62    std::mutex playVideoMutex_;
63    std::atomic_bool isPlaying_ = false;
64    std::weak_ptr<MediaChannel> mediaChannel_;
65    std::shared_ptr<AudioPlayController> audioPlayController_ = nullptr;
66    std::map<uint64_t, std::shared_ptr<VideoPlayController>> videoPlayerMap_;
67
68    AudioTrack audioTrack_;
69    VideoTrack videoTrack_;
70};
71
72} // namespace Sharing
73} // namespace OHOS
74#endif