1e0e9324cSopenharmony_ci/*
2e0e9324cSopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3e0e9324cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0e9324cSopenharmony_ci * you may not use this file except in compliance with the License.
5e0e9324cSopenharmony_ci * You may obtain a copy of the License at
6e0e9324cSopenharmony_ci *
7e0e9324cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0e9324cSopenharmony_ci *
9e0e9324cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0e9324cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0e9324cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0e9324cSopenharmony_ci * See the License for the specific language governing permissions and
13e0e9324cSopenharmony_ci * limitations under the License.
14e0e9324cSopenharmony_ci */
15e0e9324cSopenharmony_ci
16e0e9324cSopenharmony_ci#ifndef OHOS_SHARING_MEDIA_CHANNEL_H
17e0e9324cSopenharmony_ci#define OHOS_SHARING_MEDIA_CHANNEL_H
18e0e9324cSopenharmony_ci
19e0e9324cSopenharmony_ci#include <memory>
20e0e9324cSopenharmony_ci#include <unordered_map>
21e0e9324cSopenharmony_ci#include "base_channel.h"
22e0e9324cSopenharmony_ci#include "base_consumer.h"
23e0e9324cSopenharmony_ci#include "common/event_comm.h"
24e0e9324cSopenharmony_ci#include "media_controller.h"
25e0e9324cSopenharmony_ci
26e0e9324cSopenharmony_cinamespace OHOS {
27e0e9324cSopenharmony_cinamespace Sharing {
28e0e9324cSopenharmony_ci
29e0e9324cSopenharmony_cienum MediaChannelNotifyStatus {
30e0e9324cSopenharmony_ci    NOTIFY_VIDEO_STOP,
31e0e9324cSopenharmony_ci};
32e0e9324cSopenharmony_ci
33e0e9324cSopenharmony_ciclass IMediaChannelListener {
34e0e9324cSopenharmony_cipublic:
35e0e9324cSopenharmony_ci    virtual ~IMediaChannelListener() = default;
36e0e9324cSopenharmony_ci
37e0e9324cSopenharmony_ci    virtual void OnMediaChannelNotify(MediaChannelNotifyStatus status) = 0;
38e0e9324cSopenharmony_ci};
39e0e9324cSopenharmony_ci
40e0e9324cSopenharmony_ciclass MediaChannel : public IProducerListener,
41e0e9324cSopenharmony_ci                     public IConsumerListener,
42e0e9324cSopenharmony_ci                     public BufferDispatcherListener,
43e0e9324cSopenharmony_ci                     public BaseChannel,
44e0e9324cSopenharmony_ci                     public std::enable_shared_from_this<MediaChannel> {
45e0e9324cSopenharmony_cipublic:
46e0e9324cSopenharmony_ci    using Ptr = std::shared_ptr<MediaChannel>;
47e0e9324cSopenharmony_ci
48e0e9324cSopenharmony_ci    MediaChannel();
49e0e9324cSopenharmony_ci    ~MediaChannel() override;
50e0e9324cSopenharmony_ci
51e0e9324cSopenharmony_ci    void OnWriteTimeout() override;
52e0e9324cSopenharmony_ci    void SetContextId(uint32_t contextId)
53e0e9324cSopenharmony_ci    {
54e0e9324cSopenharmony_ci        SHARING_LOGD("trace.");
55e0e9324cSopenharmony_ci        srcContextId_ = contextId;
56e0e9324cSopenharmony_ci    }
57e0e9324cSopenharmony_ci
58e0e9324cSopenharmony_ci    BufferDispatcher::Ptr GetDispatcher() override
59e0e9324cSopenharmony_ci    {
60e0e9324cSopenharmony_ci        MEDIA_LOGD("trace.");
61e0e9324cSopenharmony_ci        return dispatcher_;
62e0e9324cSopenharmony_ci    }
63e0e9324cSopenharmony_ci
64e0e9324cSopenharmony_cipublic:
65e0e9324cSopenharmony_ci    uint32_t GetSinkAgentId();
66e0e9324cSopenharmony_ci    uint32_t CreateProducer(std::string &className) override;
67e0e9324cSopenharmony_ci
68e0e9324cSopenharmony_ci    int32_t Release();
69e0e9324cSopenharmony_ci    int32_t HandleEvent(SharingEvent &event) override;
70e0e9324cSopenharmony_ci
71e0e9324cSopenharmony_ci    void OnMediaControllerNotify(ProsumerStatusMsg::Ptr &statusMsg);
72e0e9324cSopenharmony_ci    void OnProducerNotify(ProsumerStatusMsg::Ptr &statusMsg) override;
73e0e9324cSopenharmony_ci    void OnConsumerNotify(ProsumerStatusMsg::Ptr &statusMsg) override;
74e0e9324cSopenharmony_ci    void SendAgentEvent(ProsumerStatusMsg::Ptr &msg, EventType eventType);
75e0e9324cSopenharmony_ci    void SetMediaChannelListener(std::weak_ptr<IMediaChannelListener> listener);
76e0e9324cSopenharmony_ci
77e0e9324cSopenharmony_ci    SharingErrorCode CreateConsumer(std::string &className) override;
78e0e9324cSopenharmony_ci
79e0e9324cSopenharmony_ciprivate:
80e0e9324cSopenharmony_ci    SharingErrorCode HandleStopConsumer(SharingEvent &event);
81e0e9324cSopenharmony_ci    SharingErrorCode HandleStartConsumer(SharingEvent &event);
82e0e9324cSopenharmony_ci    SharingErrorCode HandlePauseConsumer(SharingEvent &event);
83e0e9324cSopenharmony_ci    SharingErrorCode HandleCreateConsumer(SharingEvent &event);
84e0e9324cSopenharmony_ci    SharingErrorCode HandleResumeConsumer(SharingEvent &event);
85e0e9324cSopenharmony_ci    SharingErrorCode HandleDestroyConsumer(SharingEvent &event);
86e0e9324cSopenharmony_ci
87e0e9324cSopenharmony_ci    SharingErrorCode HandleStopProducer(SharingEvent &event);
88e0e9324cSopenharmony_ci    SharingErrorCode HandlePauseProducer(SharingEvent &event);
89e0e9324cSopenharmony_ci    SharingErrorCode HandleStartProducer(SharingEvent &event);
90e0e9324cSopenharmony_ci    SharingErrorCode HandleCreateProducer(SharingEvent &event);
91e0e9324cSopenharmony_ci    SharingErrorCode HandleResumeProducer(SharingEvent &event);
92e0e9324cSopenharmony_ci    SharingErrorCode HandleDestroyProducer(SharingEvent &event);
93e0e9324cSopenharmony_ci
94e0e9324cSopenharmony_ci    SharingErrorCode InitPlayController();
95e0e9324cSopenharmony_ci    SharingErrorCode HandleStopPlay(SharingEvent &event);
96e0e9324cSopenharmony_ci    SharingErrorCode HandleSetVolume(SharingEvent &event);
97e0e9324cSopenharmony_ci    SharingErrorCode HandleStartPlay(SharingEvent &event);
98e0e9324cSopenharmony_ci    SharingErrorCode HandleSetSceneType(SharingEvent &event);
99e0e9324cSopenharmony_ci    SharingErrorCode HandleAppendSurface(SharingEvent &event);
100e0e9324cSopenharmony_ci    SharingErrorCode HandleRemoveSurface(SharingEvent &event);
101e0e9324cSopenharmony_ci    SharingErrorCode HandleSetKeyRedirect(SharingEvent &event);
102e0e9324cSopenharmony_ci
103e0e9324cSopenharmony_ciprivate:
104e0e9324cSopenharmony_ci    uint32_t srcContextId_ = INVALID_ID;
105e0e9324cSopenharmony_ci
106e0e9324cSopenharmony_ci    std::mutex mutex_;
107e0e9324cSopenharmony_ci    std::weak_ptr<IMediaChannelListener> listener_;
108e0e9324cSopenharmony_ci
109e0e9324cSopenharmony_ci    BufferDispatcher::Ptr dispatcher_ = nullptr;
110e0e9324cSopenharmony_ci    MediaController::Ptr playController_ = nullptr;
111e0e9324cSopenharmony_ci};
112e0e9324cSopenharmony_ci
113e0e9324cSopenharmony_ci} // namespace Sharing
114e0e9324cSopenharmony_ci} // namespace OHOS
115e0e9324cSopenharmony_ci#endif