• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PLAYER_SERVICE_H
17 #define I_PLAYER_SERVICE_H
18 
19 #include "player.h"
20 #include "refbase.h"
21 
22 namespace OHOS {
23 namespace Media {
24 class IPlayerService {
25 public:
26     virtual ~IPlayerService() = default;
27 
28     /**
29      * @brief Sets the playback source for the player. The corresponding source can be local file url.
30      *
31      * @param url Indicates the playback source.
32      * @return Returns {@link MSERR_OK} if the url is set successfully; returns an error code defined
33      * in {@link media_errors.h} otherwise.
34      * @since 1.0
35      * @version 1.0
36      */
37     virtual int32_t SetSource(const std::string &url) = 0;
38     /**
39      * @brief Sets the playback media data source for the player.
40      *
41      * @param dataSrc Indicates the media data source. in {@link media_data_source.h}
42      * @return Returns {@link MSERR_OK} if the dataSrc is set successfully; returns an error code defined
43      * in {@link media_errors.h} otherwise.
44      * @since 1.0
45      * @version 1.0
46      */
47     virtual int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) = 0;
48     /**
49      * @brief Sets the playback media file descriptor source for the player.
50      *
51      * @param fd Indicates the file descriptor of media source.
52      * @param offset Indicates the offset of media source in file descriptor.
53      * @param size Indicates the size of media source.
54      * @return Returns {@link MSERR_OK} if the fd source is set successfully; returns an error code defined
55      * in {@link media_errors.h} otherwise.
56      * @since 1.0
57      * @version 1.0
58      */
59     virtual int32_t SetSource(int32_t fd, int64_t offset, int64_t size) = 0;
60     /**
61      * @brief Start playback.
62      *
63      * This function must be called after {@link Prepare}. If the player state is <b>Prepared</b>,
64      * this function is called to start playback.
65      *
66      * @return Returns {@link MSERR_OK} if the playback is started; otherwise returns an error code defined
67      * in {@link media_errors.h} otherwise.
68      * @since 1.0
69      * @version 1.0
70      */
71     virtual int32_t Play() = 0;
72 
73   /**
74      * @brief Prepares the playback environment and buffers media data.
75      *
76      * This function must be called after {@link SetSource}.
77      *
78      * @return Returns {@link MSERR_OK} if the playback is prepared; returns an error code defined
79      * in {@link media_errors.h} otherwise.
80      * @since 1.0
81      * @version 1.0
82      */
83     virtual int32_t Prepare() = 0;
84 
85     /**
86      * @brief Prepare the playback environment and buffers media data asynchronous.
87      *
88      * This function must be called after {@link SetSource}.
89      *
90      * @return Returns {@link MSERR_OK} if the playback is preparing; returns an error code defined
91      * in {@link media_errors.h} otherwise.
92      * @since 1.0
93      * @version 1.0
94      */
95     virtual int32_t PrepareAsync() = 0;
96 
97     /**
98      * @brief Pauses playback.
99      *
100      * @return Returns {@link MSERR_OK} if the playback is paused; returns an error code defined
101      * in {@link media_errors.h} otherwise.
102      * @since 1.0
103      * @version 1.0
104      */
105     virtual int32_t Pause() = 0;
106 
107     /**
108      * @brief Stop playback.
109      *
110      * @return Returns {@link MSERR_OK} if the playback is stopped; returns an error code defined
111      * in {@link media_errors.h} otherwise.
112      * @since 1.0
113      * @version 1.0
114      */
115     virtual int32_t Stop() = 0;
116 
117     /**
118      * @brief Restores the player to the initial state.
119      *
120      * After the function is called, add a playback source by calling {@link SetSource},
121      * call {@link Play} to start playback again after {@link Prepare} is called.
122      *
123      * @return Returns {@link MSERR_OK} if the playback is reset; returns an error code defined
124      * in {@link media_errors.h} otherwise.
125      * @since 1.0
126      * @version 1.0
127      */
128     virtual int32_t Reset() = 0;
129 
130     /**
131      * @brief Releases player resources async
132      *
133      * @return Returns {@link MSERR_OK} if the playback is released; returns an error code defined
134      * in {@link media_errors.h} otherwise.
135      * @since 1.0
136      * @version 1.0
137      */
138     virtual int32_t Release() = 0;
139 
140     /**
141      * @brief Releases player resources sync
142      *
143      * @return Returns {@link MSERR_OK} if the playback is released; returns an error code defined
144      * in {@link media_errors.h} otherwise.
145      * @since 1.0
146      * @version 1.0
147      */
ReleaseSync()148     virtual int32_t ReleaseSync()
149     {
150         return ERR_OK;
151     }
152 
153     /**
154      * @brief Sets the volume of the player.
155      *
156      * This function can be used during playback or pause. The value <b>0</b> indicates no sound,
157      * and <b>1</b> indicates the original volume. If no audio device is started or no audio
158      * stream exists, the value <b>-1</b> is returned.
159      *
160      * @param leftVolume Indicates the target volume of the left audio channel to set,
161      *        ranging from 0 to 1. each step is 0.01.
162      * @param rightVolume Indicates the target volume of the right audio channel to set,
163      *        ranging from 0 to 1. each step is 0.01.
164      * @return Returns {@link MSERR_OK} if the volume is set; returns an error code defined
165      * in {@link media_errors.h} otherwise.
166      * @since 1.0
167      * @version 1.0
168      */
169     virtual int32_t SetVolume(float leftVolume, float rightVolume) = 0;
170 
171     /**
172      * @brief Changes the playback position.
173      *
174      * This function can be used during play or pause.
175      *
176      * @param mSeconds Indicates the target playback position, accurate to second.
177      * @param mode Indicates the player seek mode. For details, see {@link PlayerSeekMode}.
178      * @return Returns {@link MSERR_OK} if the seek is done; returns an error code defined
179      * in {@link media_errors.h} otherwise.
180      * @since 1.0
181      * @version 1.0
182     */
183     virtual int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) = 0;
184 
185     /**
186      * @brief Obtains the playback position, accurate to millisecond.
187      *
188      * @param currentTime Indicates the playback position.
189      * @return Returns {@link MSERR_OK} if the current position is get; returns an error code defined
190      * in {@link media_errors.h} otherwise.
191      * @since 1.0
192      * @version 1.0
193      */
194     virtual int32_t GetCurrentTime(int32_t &currentTime) = 0;
195 
196     /**
197      * @brief Obtains the video track info, contains mimeType, bitRate, width, height, frameRata.
198      *
199      * @param video track info vec.
200      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
201      * in {@link media_errors.h} otherwise.
202      * @since 1.0
203      * @version 1.0
204      */
205     virtual int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) = 0;
206 
207     /**
208      * @brief Obtains the audio track info, contains mimeType, bitRate, sampleRate, channels, language.
209      *
210      * @param audio track info vec.
211      * @return Returns {@link MSERR_OK} if the track info is get; returns an error code defined
212      * in {@link media_errors.h} otherwise.
213      * @since 1.0
214      * @version 1.0
215      */
216     virtual int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) = 0;
217 
218     /**
219      * @brief get the video width.
220      *
221      * @return Returns width if success; else returns 0
222      * @since 1.0
223      * @version 1.0
224      */
225     virtual int32_t GetVideoWidth() = 0;
226 
227     /**
228      * @brief get the video height.
229      *
230      * @return Returns height if success; else returns 0
231      * @since 1.0
232      * @version 1.0
233      */
234     virtual int32_t GetVideoHeight() = 0;
235 
236     /**
237      * @brief Obtains the total duration of media files, accurate to milliseconds.
238      *
239      * @param duration Indicates the total duration of media files.
240      * @return Returns {@link MSERR_OK} if the current duration is get; returns an error code defined
241      * in {@link media_errors.h} otherwise.
242      * @since 1.0
243      * @version 1.0
244      */
245     virtual int32_t GetDuration(int32_t &duration) = 0;
246 
247     /**
248      * @brief set the player playback rate
249      *
250      * @param mode the rate mode {@link PlaybackRateMode} which can set.
251      * @return Returns {@link MSERR_OK} if the playback rate is set successfully; returns an error code defined
252      * in {@link media_errors.h} otherwise.
253      * @since 1.0
254      * @version 1.0
255      */
256     virtual int32_t SetPlaybackSpeed(PlaybackRateMode mode) = 0;
257 
258     /**
259      * @brief set the bit rate use for hls player
260      *
261      * @param bitRate the bit rate.
262      * @return Returns {@link MSERR_OK} if the bit rate is set successfully; returns an error code defined
263      * in {@link media_errors.h} otherwise.
264      * @since 1.0
265      * @version 1.0
266      */
267     virtual int32_t SelectBitRate(uint32_t bitRate) = 0;
268 
269     /**
270      * @brief get the current player playback rate
271      *
272      * @param mode the rate mode {@link PlaybackRateMode} which can get.
273      * @return Returns {@link MSERR_OK} if the current player playback rate is get; returns an error code defined
274      * in {@link media_errors.h} otherwise.
275      * @since 1.0
276      * @version 1.0
277      */
278     virtual int32_t GetPlaybackSpeed(PlaybackRateMode &mode) = 0;
279 
280 #ifdef SUPPORT_VIDEO
281     /**
282      * @brief Method to set the surface.
283      *
284      * @param surface pointer of the surface.
285      * @return Returns {@link MSERR_OK} if the surface is set; returns an error code defined
286      * in {@link media_errors.h} otherwise.
287      * @since 1.0
288      * @version 1.0
289      */
290     virtual int32_t SetVideoSurface(sptr<Surface> surface) = 0;
291 #endif
292 
293     /**
294      * @brief Checks whether the player is playing.
295      *
296      * @return Returns true if the playback is playing; false otherwise.
297      * @since 1.0
298      * @version 1.0
299      */
300     virtual bool IsPlaying() = 0;
301 
302     /**
303      * @brief Returns the value whether single looping is enabled or not .
304      *
305      * @return Returns true if the playback is single looping; false otherwise.
306      * @since 1.0
307      * @version 1.0
308      */
309     virtual bool IsLooping() = 0;
310 
311     /**
312      * @brief Enables single looping of the media playback.
313      *
314      * @return Returns {@link MSERR_OK} if the single looping is set; returns an error code defined
315      * in {@link media_errors.h} otherwise.
316      * @since 1.0
317      * @version 1.0
318      */
319     virtual int32_t SetLooping(bool loop) = 0;
320 
321     /**
322      * @brief Enables setting the renderer descriptor for the current media
323      *
324      * @return Returns {@link MSERR_OK} if the renderer descriptor is set; returns an error code defined
325      * in {@link media_errors.h} otherwise.
326      * @since 1.0
327      * @version 1.0
328      */
329     virtual int32_t SetParameter(const Format &param) = 0;
330 
331     /**
332      * @brief Method to set player callback.
333      *
334      * @param callback object pointer.
335      * @return Returns {@link MSERR_OK} if the playercallback is set; returns an error code defined
336      * in {@link media_errors.h} otherwise.
337      * @since 1.0
338      * @version 1.0
339      */
340     virtual int32_t SetPlayerCallback(const std::shared_ptr<PlayerCallback> &callback) = 0;
341 };
342 } // namespace Media
343 } // namespace OHOS
344 #endif // I_PLAYER_SERVICE_H
345