Pepper_42_C++_interfaces
media_player_samsung.h
Go to the documentation of this file.
1 // Copyright (c) 2016 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PPAPI_CPP_SAMSUNG_MEDIA_PLAYER_SAMSUNG_H_
6 #define PPAPI_CPP_SAMSUNG_MEDIA_PLAYER_SAMSUNG_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "ppapi/c/samsung/ppb_media_player_samsung.h"
12 #include "ppapi/cpp/completion_callback.h"
13 #include "ppapi/cpp/resource.h"
14 
15 /// @file
16 /// This file defines the <code>MediaPlayer_Samsung</code> type, which provides
17 /// multimedia streaming and playback control capabilities.
18 ///
19 /// Part of Pepper Media Player interfaces (Samsung's extension).
20 namespace pp {
21 
22 class InstanceHandle;
23 class MediaDataSource_Samsung;
24 
25 /// <code>MediaPlayer_Samsung</code> is type allowing application
26 /// to control playback state, inquire about playback state.
27 /// It's also responsible for assigning data source which will feed player
28 /// with media data.
29 ///
30 /// Assumptions:
31 /// - Video is displayed in area of embed/object element of HTML page
32 /// in which plugin is embedded.
33 /// - Video and graphics from module can be displayed simultaneously.
34 /// (see <code>PPB_Instance.BindGraphics</code>). Application must
35 /// set proper CSS style for embed element with NaCl application
36 /// (mostly transparent background).
37 class MediaPlayer_Samsung : public Resource {
38  public:
40  explicit MediaPlayer_Samsung(const InstanceHandle& instance);
42 
44 
45  virtual ~MediaPlayer_Samsung();
46 
47  /// Attaches given <code>MediaDataSource_Samsung</code> to the player.
48  ///
49  /// You can pass a <code>NULL</code> resource as buffer to detach currently
50  /// attached data source. Reattaching data source will return
51  /// <code>PP_OK</code> and do nothing.
52  ///
53  /// Attaching data source to the player will cause:
54  /// 1. Detaching currently attached data source
55  /// 2. Performing initialization of newly bound data source (this step
56  /// is specific to data source which is being bound).
57  ///
58  /// @param[in] data_source A <code>MediaDataSource_Samsung</code>
59  /// identifying data source to be attached to the player.
60  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
61  /// completion.
62  ///
63  /// @return PP_OK on success, otherwise an error code from
64  /// <code>pp_errors.h</code>.
65  int32_t AttachDataSource(
66  const MediaDataSource_Samsung& data_source,
67  const CompletionCallback& callback);
68 
69  /* Playback control */
70 
71  /// Requests to start playback of media from data source attached to the
72  /// media player.
73  ///
74  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
75  /// completion.
76  ///
77  /// @return PP_OK on success, otherwise an error code from
78  /// <code>pp_errors.h</code>. Meaning of errors:
79  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
80  /// to the media player.
81  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
82  /// supported by attached data source.
83  int32_t Play(const CompletionCallback& callback);
84 
85  /// Requests to pause playback of media from data source attached to the
86  /// media player.
87  ///
88  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
89  /// completion.
90  ///
91  /// @return PP_OK on success, otherwise an error code from
92  /// <code>pp_errors.h</code>. Meaning of errors:
93  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
94  /// to the media player.
95  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
96  /// supported by attached data source.
97  int32_t Pause(const CompletionCallback& callback);
98 
99  /// Requests to stop playback of media from data source attached to the
100  /// media player.
101  ///
102  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
103  /// completion.
104  ///
105  /// @return PP_OK on success, otherwise an error code from
106  /// <code>pp_errors.h</code>. Meaning of errors:
107  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
108  /// to the media player.
109  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
110  /// supported by attached data source.
111  int32_t Stop(const CompletionCallback& callback);
112 
113  /// Requests to seek media from attached data source to the given time stamp.
114  ///
115  /// @param[in] time A time stamp from begging of the clip to from which
116  /// playback should be resumed.
117  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
118  /// completion.
119  ///
120  /// @return PP_OK on success, otherwise an error code from
121  /// <code>pp_errors.h</code>. Meaning of errors:
122  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
123  /// to the media player.
124  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
125  /// supported by attached data source.
126  int32_t Seek(PP_TimeTicks time, const CompletionCallback& callback);
127 
128  /// Sets playback rate, pass:
129  /// |rate| == 1.0 to mark normal playback
130  /// 0.0 < |rate| < 1.0 to mark speeds slower than normal
131  /// |rate| > 1.0 to mark speeds faster than normal
132  ///
133  /// @param[in] rate A rate of the playback.
134  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
135  /// completion.
136  ///
137  /// @return PP_OK on success, otherwise an error code from
138  /// <code>pp_errors.h</code>. Meaning of errors:
139  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
140  /// to the media player.
141  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
142  /// supported by attached data source.
143  int32_t SetPlaybackRate(double rate, const CompletionCallback& callback);
144 
145  /* Playback time info */
146 
147  /// Retrieves duration of the media played from attached data source.
148  ///
149  /// @param[in] callback A <code>CompletionCallbackWitOutput</code>
150  /// to be called upon completion with retrieved duration of the media.
151  ///
152  /// @return PP_OK on success, otherwise an error code from
153  /// <code>pp_errors.h</code>. Meaning of errors:
154  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
155  /// to the media player.
156  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
157  /// supported by attached data source (e.g. live content playback).
158  int32_t GetDuration(
160 
161  /// Retrieves current time/position of the media played from attached
162  /// data source.
163  ///
164  /// This operation can be performed only for media player in
165  /// <code>PP_MEDIAPLAYERSTATE_PLAYING</code> or
166  /// <code>PP_MEDIAPLAYERSTATE_PAUSED</code> states.
167  ///
168  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
169  /// called upon completion with retrieved current time.
170  ///
171  /// @return PP_OK on success, otherwise an error code from
172  /// <code>pp_errors.h</code>. Meaning of errors:
173  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
174  /// to the media player.
175  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if data can't be retrieved
176  /// due to invalid player state.
177  int32_t GetCurrentTime(
179 
180  /* Playback state info */
181 
182  /// Retrieves current state the media player.
183  ///
184  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
185  /// called upon completion with retrieved player state.
186  ///
187  /// @return PP_OK on success, otherwise an error code from
188  /// <code>pp_errors.h</code>.
189  int32_t GetPlayerState(
191 
192  /* Tracks info */
193 
194  /// Retrieves information of current video track from the media played from
195  /// attached data source.
196  ///
197  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
198  /// called upon completion with retrieved video track information.
199  ///
200  /// @return PP_OK on success, otherwise an error code from
201  /// <code>pp_errors.h</code>. Meaning of errors:
202  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
203  /// to the media player.
204  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if no video track is available
205  /// in media played from attached data source.
206  int32_t GetCurrentVideoTrackInfo(
208 
209  typedef std::vector<PP_VideoTrackInfo> VideoTracksList;
210 
211  /// Retrieves information of all video tracks from the media played from
212  /// attached data source.
213  ///
214  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
215  /// called upon completion with list of video tracks available in currently
216  /// attached data source. List will be empty if media played form attached
217  /// data source doesn't have any video tracks.
218  ///
219  /// @return If >= 0, the number of the tracks is returned, otherwise an
220  /// error code from <code>pp_errors.h</code>. Meaning of errors:
221  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
222  /// to the media player.
223  int32_t GetVideoTracksList(
225 
226  /// Retrieves information of current audio track from the media played from
227  /// attached data source.
228  ///
229  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
230  /// called upon completion with retrieved audio track information.
231  ///
232  /// @return PP_OK on success, otherwise an error code from
233  /// <code>pp_errors.h</code>. Meaning of errors:
234  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
235  /// to the media player.
236  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if no video track is available
237  /// in media played from attached data source.
238  int32_t GetCurrentAudioTrackInfo(
240 
241  typedef std::vector<PP_AudioTrackInfo> AudioTracksList;
242 
243  /// Retrieves information of all audio tracks from the media played from
244  /// attached data source.
245  ///
246  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
247  /// called upon completion with list of audio tracks available in currently
248  /// attached data source. List will be empty if media played form attached
249  /// data source doesn't have any audio tracks.
250  ///
251  /// @return If >= 0, the number of the tracks is returned, otherwise an
252  /// error code from <code>pp_errors.h</code>. Meaning of errors:
253  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
254  /// to the media player.
255  int32_t GetAudioTracksList(
257 
258  /// Retrieves information of current text/subtitles track from the media
259  /// played from attached data source.
260  ///
261  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
262  /// called upon completion with retrieved text/subtitles track information.
263  ///
264  /// @return PP_OK on success, otherwise an error code from
265  /// <code>pp_errors.h</code>. Meaning of errors:
266  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
267  /// to the media player.
268  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if no video track is available
269  /// in media played from attached data source.
270  int32_t GetCurrentTextTrackInfo(
272 
273  typedef std::vector<PP_TextTrackInfo> TextTracksList;
274 
275  /// Retrieves information of all text/subtitles tracks from the media played
276  /// from attached data source.
277  ///
278  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
279  /// called upon completion with list of text/subtitles tracks available
280  /// in currently attached data source. List will be empty if media played
281  /// form attached data source doesn't have any text/subtitles tracks.
282  ///
283  /// @return If >= 0, the number of the tracks is returned, otherwise an
284  /// error code from <code>pp_errors.h</code>. Meaning of errors:
285  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
286  /// to the media player.
287  int32_t GetTextTracksList(
289 
290  /// Selects a track for the given stream type to be activated for media
291  /// played from the attached data source.
292  ///
293  /// Remarks:
294  /// If activated track is a text track, it will be automatically activated and
295  /// therefore it's subtitles will be delivered as events to the
296  /// <code>SubtitleListener_Samsung</code>.
297  ///
298  /// @param[in] track_type A type of the stream for which activate track.
299  /// @param[in] track_index An index of the track which has to be activated.
300  /// Valid track index can be obtained from one of PP_*TrackInfo structures
301  /// returned by corresponding call to Get*TracksInfo.
302  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
303  /// completion.
304  ///
305  /// @return PP_OK on success, otherwise an error code from
306  /// <code>pp_errors.h</code>. Meaning of errors:
307  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
308  /// to the media player or passed |track_type| or |track_index| are
309  /// not valid.
310  int32_t SelectTrack(
311  PP_ElementaryStream_Type_Samsung track_type,
312  uint32_t track_index,
313  const CompletionCallback& callback);
314 
315  /* Subtitles control */
316 
317  /// Adds external subtitles.
318  /// Returns <code>PP_OK/code> in case of success and writes added text track
319  /// information to |subtitles| param. After that newly added subtitles will be
320  /// activated and <code>SubtitleListener_Samsung</code> will be notified about
321  /// it's texts at the time those texts should be shown.
322  ///
323  /// Please note that player is responsible only for subtitle file parsing. No
324  /// subtitles are displayed by the player. Application can use
325  /// <code>SubtitleListener_Samsung</code> to get subtitle texts at correct
326  /// playback times and display them manually.
327  ///
328  /// Constraints:
329  /// Ability to add external subtitles after attaching data source is
330  /// implementation dependent. If it is impossible to add external subtitles
331  /// after data source is attached, this method will fail with
332  /// <code>PP_ERROR_NOTSUPPORTED</code> error code. Therefore this method is
333  /// guaranteed to succeed only before data source is attached. ///
334  /// @param[in] file_path A path of the subtitles.
335  /// @param[in] encoding Subtitle encoding. May be empty string, which will
336  /// cause subtitles to be interpreted as UTF-8 text.
337  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
338  /// called upon completion with added subtitles information.
339  ///
340  /// @return PP_OK on success, otherwise an error code from
341  /// <code>pp_errors.h</code>. Meaning of errors:
342  /// - <code>PP_ERROR_FILENOTFOUND</code> - if provided file_path is invalid.
343  /// - <code>PP_ERROR_BADARGUMENT</code> - if provided encoding is invalid.
344  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if method was called after
345  /// attaching a data source and such operation is not supported on the
346  /// current implementation.
347  int32_t AddExternalSubtitles(
348  const std::string& file_path,
349  const std::string& encoding,
351 
352  /// Sets subtitles (text stream) <code>SubtitleListener</code>
353  /// event emission delay regarding to the current media time.
354  ///
355  /// @param[in] delay A delay to be set.
356  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
357  /// completion.
358  ///
359  /// @return PP_OK on success, otherwise an error code from
360  /// <code>pp_errors.h</code>. Meaning of errors:
361  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
362  /// to the media player.
363  int32_t SetSubtitlesDelay(
364  PP_TimeDelta delay,
365  const CompletionCallback& callback);
366 
367  /* Other - player control */
368 
369  /// Sets display region in which video will be displayed. Passed position
370  /// is relative to the embed/object element of WebPage associated with given
371  /// plugin.
372  ///
373  /// @param[in] rect Video region in which video will be displayed.
374  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
375  /// completion.
376  ///
377  /// @return PP_OK on success, otherwise an error code from
378  /// <code>pp_errors.h</code>.
379  int32_t SetDisplayRect(
380  const PP_Rect& rect,
381  const CompletionCallback& callback);
382 
383  /* DRM Related */
384 
385  /// Calls DRM system specific operation.
386  ///
387  /// @param[in] drm_type A DRM system to be used
388  /// @param[in] drm_operation A DRM specific operation to be performed.
389  /// @param[in] drm_data_size A size of data buffer passed to DRM system.
390  /// @param[in] drm_data A data buffer passed to DRM system.
391  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
392  /// completion.
393  ///
394  /// @return PP_OK on success, otherwise an error code from
395  /// <code>pp_errors.h</code>. Meaning of errors:
396  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
397  /// to the media player.
398  int32_t SetDRMSpecificData(
399  PP_MediaPlayerDRMType drm_type,
400  PP_MediaPlayerDRMOperation drm_operation,
401  uint32_t drm_data_size,
402  const void* drm_data,
403  const CompletionCallback& callback);
404 };
405 
406 } // namespace pp
407 
408 #endif // PPAPI_CPP_SAMSUNG_MEDIA_PLAYER_SAMSUNG_H_
std::vector< PP_VideoTrackInfo > VideoTracksList
int32_t SelectTrack(PP_ElementaryStream_Type_Samsung track_type, uint32_t track_index, const CompletionCallback &callback)
int32_t GetDuration(const CompletionCallbackWithOutput< PP_TimeDelta > &callback)
int32_t AddExternalSubtitles(const std::string &file_path, const std::string &encoding, const CompletionCallbackWithOutput< PP_TextTrackInfo > &callback)
int32_t Pause(const CompletionCallback &callback)
int32_t GetCurrentTextTrackInfo(const CompletionCallbackWithOutput< PP_TextTrackInfo > &callback)
int32_t GetCurrentVideoTrackInfo(const CompletionCallbackWithOutput< PP_VideoTrackInfo > &callback)
MediaPlayer_Samsung & operator=(const MediaPlayer_Samsung &other)
virtual ~MediaPlayer_Samsung()
int32_t GetPlayerState(const CompletionCallbackWithOutput< PP_MediaPlayerState > &callback)
std::vector< PP_AudioTrackInfo > AudioTracksList
int32_t AttachDataSource(const MediaDataSource_Samsung &data_source, const CompletionCallback &callback)
int32_t Stop(const CompletionCallback &callback)
int32_t Play(const CompletionCallback &callback)
int32_t GetTextTracksList(const CompletionCallbackWithOutput< TextTracksList > &callback)
int32_t SetDisplayRect(const PP_Rect &rect, const CompletionCallback &callback)
std::vector< PP_TextTrackInfo > TextTracksList
int32_t Seek(PP_TimeTicks time, const CompletionCallback &callback)
int32_t SetSubtitlesDelay(PP_TimeDelta delay, const CompletionCallback &callback)
int32_t GetVideoTracksList(const CompletionCallbackWithOutput< VideoTracksList > &callback)
int32_t GetAudioTracksList(const CompletionCallbackWithOutput< AudioTracksList > &callback)
int32_t SetPlaybackRate(double rate, const CompletionCallback &callback)
A reference counted module resource.
Definition: resource.h:20
int32_t GetCurrentAudioTrackInfo(const CompletionCallbackWithOutput< PP_AudioTrackInfo > &callback)
int32_t SetDRMSpecificData(PP_MediaPlayerDRMType drm_type, PP_MediaPlayerDRMOperation drm_operation, uint32_t drm_data_size, const void *drm_data, const CompletionCallback &callback)
int32_t GetCurrentTime(const CompletionCallbackWithOutput< PP_TimeTicks > &callback)