1 /*
2  * Copyright (c) 2020-2021 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 PLAYER_SINK_MANAGER_H
17 #define PLAYER_SINK_MANAGER_H
18 
19 #include <memory>
20 #include <vector>
21 #include "player_sink_type.h"
22 #include "player_define.h"
23 #include "player_audio_sink.h"
24 #include "player_video_sink.h"
25 #include <string>
26 
27 using namespace std;
28 
29 namespace OHOS {
30 namespace Media {
31 struct SyncInfo {
32     int32_t syncId;
33     std::shared_ptr<PlayerSync> sync;
34 };
35 
36 struct AudioSinkInfo {
37     int32_t trackId;
38     std::shared_ptr<AudioSink> sink;
39 };
40 
41 struct VideoSinkInfo {
42     int32_t trackId;
43     std::shared_ptr<VideoSink> sink;
44 };
45 
46 struct SinkInfo {
47     SinkType sinkType;
48     int32_t trackId;
49     union {
50         AudioSinkInfo vidSink;
51         AudioSinkInfo audSink;
52     } param;
53 };
54 
55 class SinkManager {
56 friend VideoSink;
57 friend AudioSink;
58 
59 public:
60     SinkManager();
61     ~SinkManager();
62     int32_t AddNewSink(SinkAttr &attr);
63     int32_t Start(void);
64     int32_t Stop(void);
65     int32_t Flush(void);
66     int32_t Reset(void);
67     int32_t Pause(void);
68     int32_t Resume(void);
69     int32_t SetSpeed(float speed, TplayDirect  tplayDirect);
70     int32_t GetSpeed(float &speed, TplayDirect  &tplayDirect);
71     int32_t RenderFrame(PlayerBufferInfo &frame, CodecType type);
72     int32_t SetVolume(float left, float right);
73     int32_t GetVolume(float &left, float &right);
74     int32_t SetParam(const char *key, dataType type, void* value);
75     int32_t GetParam(const char *key, dataType *type, void** value, int32_t *size);
76     void SetRenderMode(RenderMode mode);
77     int32_t RegisterCallBack(PlayEventCallback &callback);
78     int32_t GetStatus(PlayerStreamInfo &info);
79     void RenderEos(bool isAudio);
80     int DequeReleaseFrame(bool audioSink, PlayerBufferInfo &frame);
81     void GetRenderPosition(int64_t &position);
82     void SetAudioStreamType(int32_t &type);
83 
84 private:
85     int32_t Tplay(float speed, TplayDirect  tplayDirect);
86     int32_t TplayToNormal(void);
87 
88     float speed_;
89     TplayDirect  direction_;
90     float leftVolume_;
91     float rightVolume_;
92     bool paused_;
93     bool started_;
94     bool pauseAfterPlay_;
95     int32_t audioSinkNum_;
96     int32_t videoSinkNum_;
97     std::shared_ptr<PlayerSync> sync_;
98     AudioSinkInfo audioSinkInfo_[MAX_PIPELINE_SINK_NUM];
99     VideoSinkInfo videoSinkInfo_[MAX_PIPELINE_SINK_NUM];
100     PlayEventCallback callBack_;
101     bool recieveAudioEos_;
102     bool recieveVideoEos_;
103 };
104 }  // namespace Media
105 }  // namespace OHOS
106 
107 #endif  // PLAYER_SINK_MANAGER_H
108