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_BASE_CONSUMER_H
17e0e9324cSopenharmony_ci#define OHOS_SHARING_BASE_CONSUMER_H
18e0e9324cSopenharmony_ci
19e0e9324cSopenharmony_ci#include <functional>
20e0e9324cSopenharmony_ci#include <memory>
21e0e9324cSopenharmony_ci#include <cstdint>
22e0e9324cSopenharmony_ci#include <string>
23e0e9324cSopenharmony_ci#include "buffer_dispatcher.h"
24e0e9324cSopenharmony_ci#include "common/event_channel.h"
25e0e9324cSopenharmony_ci#include "common/identifier.h"
26e0e9324cSopenharmony_ci#include "common/object.h"
27e0e9324cSopenharmony_ci#include "event/handle_event_base.h"
28e0e9324cSopenharmony_ci#include "mediachannel/media_channel_def.h"
29e0e9324cSopenharmony_ci#include "utils/data_buffer.h"
30e0e9324cSopenharmony_ci
31e0e9324cSopenharmony_cinamespace OHOS {
32e0e9324cSopenharmony_cinamespace Sharing {
33e0e9324cSopenharmony_ci
34e0e9324cSopenharmony_ciclass DataBuffer;
35e0e9324cSopenharmony_ci
36e0e9324cSopenharmony_ciclass IConsumerListener {
37e0e9324cSopenharmony_cipublic:
38e0e9324cSopenharmony_ci    using Ptr = std::shared_ptr<IConsumerListener>;
39e0e9324cSopenharmony_ci
40e0e9324cSopenharmony_ci    virtual ~IConsumerListener() = default;
41e0e9324cSopenharmony_ci
42e0e9324cSopenharmony_ci    virtual void OnConsumerNotify(ProsumerStatusMsg::Ptr &statusMsg) = 0;
43e0e9324cSopenharmony_ci    virtual BufferDispatcher::Ptr GetDispatcher() = 0;
44e0e9324cSopenharmony_ci};
45e0e9324cSopenharmony_ci
46e0e9324cSopenharmony_ciclass BaseConsumer : public Object,
47e0e9324cSopenharmony_ci                     public HandleEventBase,
48e0e9324cSopenharmony_ci                     public IdentifierInfo {
49e0e9324cSopenharmony_cipublic:
50e0e9324cSopenharmony_ci    using Ptr = std::shared_ptr<BaseConsumer>;
51e0e9324cSopenharmony_ci
52e0e9324cSopenharmony_ci    BaseConsumer();
53e0e9324cSopenharmony_ci    virtual ~BaseConsumer();
54e0e9324cSopenharmony_ci
55e0e9324cSopenharmony_ci    virtual void SetSinkAgentId(uint32_t agentId);
56e0e9324cSopenharmony_ci    virtual void UpdateOperation(ProsumerStatusMsg::Ptr &statusMsg) = 0;
57e0e9324cSopenharmony_ci    void SetConsumerListener(std::weak_ptr<IConsumerListener> listener);
58e0e9324cSopenharmony_ci
59e0e9324cSopenharmony_ci    virtual bool IsPasued();
60e0e9324cSopenharmony_ci    virtual bool IsRunning();
61e0e9324cSopenharmony_ci    virtual bool IsCapture();
62e0e9324cSopenharmony_ci
63e0e9324cSopenharmony_ci    virtual int32_t Release() = 0;
64e0e9324cSopenharmony_ci    virtual uint32_t GetSinkAgentId();
65e0e9324cSopenharmony_ci
66e0e9324cSopenharmony_ci    virtual const AudioTrack &GetAudioTrack() const;
67e0e9324cSopenharmony_ci    virtual const VideoTrack &GetVideoTrack() const;
68e0e9324cSopenharmony_ci
69e0e9324cSopenharmony_ciprotected:
70e0e9324cSopenharmony_ci    void Notify(ProsumerStatusMsg::Ptr &statusMsg);
71e0e9324cSopenharmony_ci    void NotifyPrivateEvent(EventMsg::Ptr eventMsg);
72e0e9324cSopenharmony_ci
73e0e9324cSopenharmony_ciprotected:
74e0e9324cSopenharmony_ci    bool isInit_ = false;
75e0e9324cSopenharmony_ci    bool isPaused_ = false;
76e0e9324cSopenharmony_ci    bool isRunning_ = false;
77e0e9324cSopenharmony_ci    uint32_t sinkAgentId_ = INVALID_ID;
78e0e9324cSopenharmony_ci    std::weak_ptr<IConsumerListener> listener_;
79e0e9324cSopenharmony_ci
80e0e9324cSopenharmony_ci    AudioTrack audioTrack_;
81e0e9324cSopenharmony_ci    VideoTrack videoTrack_;
82e0e9324cSopenharmony_ci};
83e0e9324cSopenharmony_ci
84e0e9324cSopenharmony_ci} // namespace Sharing
85e0e9324cSopenharmony_ci} // namespace OHOS
86e0e9324cSopenharmony_ci#endif