1 /*
2  * Copyright (C) 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 I_MEDIA_SERVICE_H
17 #define I_MEDIA_SERVICE_H
18 
19 #include <memory>
20 #ifdef SUPPORT_RECORDER
21 #include "i_recorder_service.h"
22 #include "i_recorder_profiles_service.h"
23 #endif
24 #ifdef SUPPORT_TRANSCODER
25 #include "i_transcoder_service.h"
26 #endif
27 #ifdef SUPPORT_PLAYER
28 #include "i_player_service.h"
29 #endif
30 #ifdef SUPPORT_METADATA
31 #include "i_avmetadatahelper_service.h"
32 #endif
33 #ifdef SUPPORT_SCREEN_CAPTURE
34 #include "i_screen_capture_service.h"
35 #include "i_screen_capture_monitor_service.h"
36 #include "i_screen_capture_controller.h"
37 #endif
38 #include "i_standard_monitor_service.h"
39 
40 namespace OHOS {
41 namespace Media {
42 class IMediaService {
43 public:
44     virtual ~IMediaService() = default;
45 
46 #ifdef SUPPORT_RECORDER
47     /**
48      * @brief Create a recorder service.
49      *
50      * All recorder functions must be created and obtained first.
51      *
52      * @return Returns a valid pointer if the setting is successful;
53      * @since 1.0
54      * @version 1.0
55      */
56     virtual std::shared_ptr<IRecorderService> CreateRecorderService() = 0;
57 
58     /**
59      * @brief Destroy a recorder service.
60      *
61      * call the API to destroy the recorder service.
62      *
63      * @param pointer to the recorder service.
64      * @return Returns a valid pointer if the setting is successful;
65      * @since 1.0
66      * @version 1.0
67      */
68     virtual int32_t DestroyRecorderService(std::shared_ptr<IRecorderService> recorder) = 0;
69 
70     /**
71      * @brief Create a mediaprofile service.
72      *
73      * All player functions must be created and obtained first.
74      *
75      * @return Returns a valid pointer if the setting is successful;
76      * @since 3.2
77      * @version 3.2
78      */
79     virtual std::shared_ptr<IRecorderProfilesService> CreateRecorderProfilesService() = 0;
80 
81     /**
82      * @brief Destroy a mediaprofile service.
83      *
84      * call the API to destroy the mediaprofile service.
85      *
86      * @param pointer to the mediaprofile service.
87      * @return Returns a valid pointer if the setting is successful;
88      * @since 3.2
89      * @version 3.2
90      */
91     virtual int32_t DestroyMediaProfileService(std::shared_ptr<IRecorderProfilesService> recorderProfiles) = 0;
92 #endif
93 
94 #ifdef SUPPORT_TRANSCODER
95     virtual std::shared_ptr<ITransCoderService> CreateTransCoderService() = 0;
96     virtual int32_t DestroyTransCoderService(std::shared_ptr<ITransCoderService> transCoder) = 0;
97 #endif
98 
99 #ifdef SUPPORT_PLAYER
100     /**
101      * @brief Create a player service.
102      *
103      * All player functions must be created and obtained first.
104      *
105      * @return Returns a valid pointer if the setting is successful;
106      * @since 1.0
107      * @version 1.0
108      */
109     virtual std::shared_ptr<IPlayerService> CreatePlayerService() = 0;
110 
111     /**
112      * @brief Destroy a player service.
113      *
114      * call the API to destroy the player service.
115      *
116      * @param pointer to the player service.
117      * @return Returns a valid pointer if the setting is successful;
118      * @since 1.0
119      * @version 1.0
120      */
121     virtual int32_t DestroyPlayerService(std::shared_ptr<IPlayerService> player) = 0;
122 #endif
123 
124 #ifdef SUPPORT_METADATA
125     /**
126      * @brief Create an avmetadatahelper service.
127      *
128      * All player functions must be created and obtained first.
129      *
130      * @return Returns a valid pointer if the setting is successful;
131      * @since 1.0
132      * @version 1.0
133      */
134     virtual std::shared_ptr<IAVMetadataHelperService> CreateAVMetadataHelperService() = 0;
135 
136     /**
137      * @brief Destroy a avmetadatahelper service.
138      *
139      * call the API to destroy the avmetadatahelper service.
140      *
141      * @param pointer to the avmetadatahelper service.
142      * @return Returns a valid pointer if the setting is successful;
143      * @since 1.0
144      * @version 1.0
145      */
146     virtual int32_t DestroyAVMetadataHelperService(std::shared_ptr<IAVMetadataHelperService> avMetadataHelper) = 0;
147 #endif
148 
149 #ifdef SUPPORT_SCREEN_CAPTURE
150     /**
151      * @brief Create an screenCaptureHelper service.
152      *
153      * All player functions must be created and obtained first.
154      *
155      * @return Returns a valid pointer if the setting is successful;
156      * @since 1.0
157      * @version 1.0
158      */
159     virtual std::shared_ptr<IScreenCaptureService> CreateScreenCaptureService() = 0;
160 
161     /**
162      * @brief Destroy a screenCaptureHelper service.
163      *
164      * call the API to destroy the screenCaptureHelper service.
165      *
166      * @param pointer to the screenCaptureHelper service.
167      * @return Returns a valid pointer if the setting is successful;
168      * @since 1.0
169      * @version 1.0
170      */
171     virtual int32_t DestroyScreenCaptureService(std::shared_ptr<IScreenCaptureService> screenCaptureHelper) = 0;
172 
173     /**
174      * @brief Create an screenCaptureMonitor service.
175      *
176      * @return Returns a valid pointer if the setting is successful;
177      * @since 1.0
178      * @version 1.0
179      */
180     virtual std::shared_ptr<IScreenCaptureMonitorService> CreateScreenCaptureMonitorService() = 0;
181 
182     /**
183      * @brief Destroy a screenCaptureMonitor service.
184      *
185      * call the API to destroy the screenCaptureMonitor service.
186      *
187      * @param pointer to the screenCaptureMonitor service.
188      * @return Returns a valid pointer if the setting is successful;
189      * @since 1.0
190      * @version 1.0
191      */
192     virtual int32_t DestroyScreenCaptureMonitorService(
193         std::shared_ptr<IScreenCaptureMonitorService> screenCaptureMonitor) = 0;
194 
195     /**
196      * @brief Create an ScreenCaptureControllerClient service.
197      *
198      * All player functions must be created and obtained first.
199      *
200      * @return Returns a valid pointer if the setting is successful;
201      * @since 1.0
202      * @version 1.0
203      */
204     virtual std::shared_ptr<IScreenCaptureController> CreateScreenCaptureControllerClient() = 0;
205 
206     /**
207      * @brief Destroy a ScreenCaptureControllerClient service.
208      *
209      * call the API to destroy the ScreenCaptureControllerClient service.
210      *
211      * @param pointer to the ScreenCaptureControllerClient service.
212      * @return Returns a valid pointer if the setting is successful;
213      * @since 1.0
214      * @version 1.0
215      */
216     virtual int32_t DestroyScreenCaptureControllerClient(std::shared_ptr<IScreenCaptureController> controller) = 0;
217 #endif
218 
219     /**
220      * @brief Get an monitor proxy.
221      *
222      * To communicate with the server monitor, you must first obtain the monitor proxy.
223      *
224      * @return Returns a valid pointer if the setting is successful;
225      * @since 1.0
226      * @version 1.0
227      */
228     virtual sptr<IStandardMonitorService> GetMonitorProxy() = 0;
229 };
230 
231 class __attribute__((visibility("default"))) MediaServiceFactory {
232 public:
233     /**
234      * @brief IMediaService singleton
235      *
236      * Create Recorder Service and Player Service Through the Media Service.
237      *
238      * @return Returns IMediaService singleton;
239      * @since 1.0
240      * @version 1.0
241      */
242     static IMediaService &GetInstance();
243 private:
244     MediaServiceFactory() = delete;
245     ~MediaServiceFactory() = delete;
246 };
247 } // namespace Media
248 } // namespace OHOS
249 #endif // I_MEDIA_SERVICE_H
250