Pepper_47_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"
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:
39  /// An enum that controls binding Media Player to pp::Instance in the
40  /// constructor. See descriptions of <code>MediaPlayer_Samsung(
41  /// const InstanceHandle& instance)</code> and <code>MediaPlayer_Samsung(
42  /// const InstanceHandle& instance, DoNotBindToInstance)</code>.
44 
46 
47  /// Creates a player bound to pp::Instance.
48  explicit MediaPlayer_Samsung(const InstanceHandle& instance);
49 
50  /// Creates a player not bound to pp::Instance. It can be useful when the
51  /// player is used with other graphic resources that need to be bound to
52  /// pp::Instance. See <code>PPB_Instance::BindGraphics</code>
53  /// and <code>MediaPlayer_Samsung::BindToInstance</code>.
55 
57 
59 
60  virtual ~MediaPlayer_Samsung();
61 
62  /// Binds this resource to the pp::Instance as the current display surface.
63  /// It is like <code>PPB_Instance::BindGraphics</code> for media
64  /// player resource. Normally, when the constructor is called without
65  /// DoNotBindToInstance, there is no need to call this method.
66  bool BindToInstance(const InstanceHandle& instance);
67 
68  /// Attaches given <code>MediaDataSource_Samsung</code> to the player.
69  ///
70  /// You can pass a <code>NULL</code> resource as buffer to detach currently
71  /// attached data source. Reattaching data source will return
72  /// <code>PP_OK</code> and do nothing.
73  ///
74  /// Attaching data source to the player will cause:
75  /// 1. Detaching currently attached data source
76  /// 2. Performing initialization of newly bound data source (this step
77  /// is specific to data source which is being bound).
78  ///
79  /// @param[in] data_source A <code>MediaDataSource_Samsung</code>
80  /// identifying data source to be attached to the player.
81  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
82  /// completion.
83  ///
84  /// @return PP_OK on success, otherwise an error code from
85  /// <code>pp_errors.h</code>.
87  const MediaDataSource_Samsung& data_source,
88  const CompletionCallback& callback);
89 
90  /* Playback control */
91 
92  /// Requests to start playback of media from data source attached to the
93  /// media player.
94  ///
95  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
96  /// completion.
97  ///
98  /// @return PP_OK on success, otherwise an error code from
99  /// <code>pp_errors.h</code>. Meaning of errors:
100  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
101  /// to the media player.
102  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
103  /// supported by attached data source.
104  int32_t Play(const CompletionCallback& callback);
105 
106  /// Requests to pause playback of media from data source attached to the
107  /// media player.
108  ///
109  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
110  /// completion.
111  ///
112  /// @return PP_OK on success, otherwise an error code from
113  /// <code>pp_errors.h</code>. Meaning of errors:
114  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
115  /// to the media player.
116  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
117  /// supported by attached data source.
118  int32_t Pause(const CompletionCallback& callback);
119 
120  /// Requests to stop playback of media from data source attached to the
121  /// media player.
122  ///
123  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
124  /// completion.
125  ///
126  /// @return PP_OK on success, otherwise an error code from
127  /// <code>pp_errors.h</code>. Meaning of errors:
128  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
129  /// to the media player.
130  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
131  /// supported by attached data source.
132  int32_t Stop(const CompletionCallback& callback);
133 
134  /// Requests to seek media from attached data source to the given time stamp.
135  /// After calling Seek new packets should be sent to the player. Only after
136  /// receiving a number of packets the player can complete a seek operation and
137  /// run a callback.
138  ///
139  /// @param[in] time A time stamp from begging of the clip to from which
140  /// playback should be resumed.
141  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
142  /// completion.
143  ///
144  /// @return PP_OK on success, otherwise an error code from
145  /// <code>pp_errors.h</code>. Meaning of errors:
146  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
147  /// to the media player.
148  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
149  /// supported by attached data source.
150  int32_t Seek(PP_TimeTicks time, const CompletionCallback& callback);
151 
152  /// Sets playback rate, pass:
153  /// |rate| == 1.0 to mark normal playback
154  /// 0.0 < |rate| < 1.0 to mark speeds slower than normal
155  /// |rate| > 1.0 to mark speeds faster than normal
156  ///
157  /// @param[in] rate A rate of the playback.
158  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
159  /// completion.
160  ///
161  /// @return PP_OK on success, otherwise an error code from
162  /// <code>pp_errors.h</code>. Meaning of errors:
163  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
164  /// to the media player.
165  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
166  /// supported by attached data source.
167  int32_t SetPlaybackRate(double rate, const CompletionCallback& callback);
168 
169  /* Playback time info */
170 
171  /// Retrieves duration of the media played from attached data source.
172  ///
173  /// @param[in] callback A <code>CompletionCallbackWitOutput</code>
174  /// to be called upon completion with retrieved duration of the media.
175  ///
176  /// @return PP_OK on success, otherwise an error code from
177  /// <code>pp_errors.h</code>. Meaning of errors:
178  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
179  /// to the media player.
180  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if given operation is not
181  /// supported by attached data source (e.g. live content playback).
184 
185  /// Retrieves current time/position of the media played from attached
186  /// data source.
187  ///
188  /// This operation can be performed only for media player in
189  /// <code>PP_MEDIAPLAYERSTATE_PLAYING</code> or
190  /// <code>PP_MEDIAPLAYERSTATE_PAUSED</code> states.
191  ///
192  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
193  /// called upon completion with retrieved current time.
194  ///
195  /// @return PP_OK on success, otherwise an error code from
196  /// <code>pp_errors.h</code>. Meaning of errors:
197  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
198  /// to the media player.
199  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if data can't be retrieved
200  /// due to invalid player state.
203 
204  /* Playback state info */
205 
206  /// Retrieves current state the media player.
207  ///
208  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
209  /// called upon completion with retrieved player state.
210  ///
211  /// @return PP_OK on success, otherwise an error code from
212  /// <code>pp_errors.h</code>.
215 
216  /* Tracks info */
217 
218  /// Retrieves information of current video track from the media played from
219  /// attached data source.
220  ///
221  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
222  /// called upon completion with retrieved video track information.
223  ///
224  /// @return PP_OK on success, otherwise an error code from
225  /// <code>pp_errors.h</code>. Meaning of errors:
226  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
227  /// to the media player.
228  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if no video track is available
229  /// in media played from attached data source.
232 
233  typedef std::vector<PP_VideoTrackInfo> VideoTracksList;
234 
235  /// Retrieves information of all video tracks from the media played from
236  /// attached data source.
237  ///
238  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
239  /// called upon completion with list of video tracks available in currently
240  /// attached data source. List will be empty if media played form attached
241  /// data source doesn't have any video tracks.
242  ///
243  /// @return If >= 0, the number of the tracks is returned, otherwise an
244  /// error code from <code>pp_errors.h</code>. Meaning of errors:
245  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
246  /// to the media player.
249 
250  /// Retrieves information of current audio track from the media played from
251  /// attached data source.
252  ///
253  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
254  /// called upon completion with retrieved audio track information.
255  ///
256  /// @return PP_OK on success, otherwise an error code from
257  /// <code>pp_errors.h</code>. Meaning of errors:
258  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
259  /// to the media player.
260  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if no video track is available
261  /// in media played from attached data source.
264 
265  typedef std::vector<PP_AudioTrackInfo> AudioTracksList;
266 
267  /// Retrieves information of all audio tracks from the media played from
268  /// attached data source.
269  ///
270  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
271  /// called upon completion with list of audio tracks available in currently
272  /// attached data source. List will be empty if media played form attached
273  /// data source doesn't have any audio tracks.
274  ///
275  /// @return If >= 0, the number of the tracks is returned, otherwise an
276  /// error code from <code>pp_errors.h</code>. Meaning of errors:
277  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
278  /// to the media player.
281 
282  /// Retrieves information of current text/subtitles track from the media
283  /// played from attached data source.
284  ///
285  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
286  /// called upon completion with retrieved text/subtitles track information.
287  ///
288  /// @return PP_OK on success, otherwise an error code from
289  /// <code>pp_errors.h</code>. Meaning of errors:
290  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
291  /// to the media player.
292  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if no video track is available
293  /// in media played from attached data source.
296 
297  typedef std::vector<PP_TextTrackInfo> TextTracksList;
298 
299  /// Retrieves information of all text/subtitles tracks from the media played
300  /// from attached data source.
301  ///
302  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
303  /// called upon completion with list of text/subtitles tracks available
304  /// in currently attached data source. List will be empty if media played
305  /// form attached data source doesn't have any text/subtitles tracks.
306  ///
307  /// @return If >= 0, the number of the tracks is returned, otherwise an
308  /// error code from <code>pp_errors.h</code>. Meaning of errors:
309  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
310  /// to the media player.
313 
314  /// Selects a track for the given stream type to be activated for media
315  /// played from the attached data source.
316  ///
317  /// Remarks:
318  /// If activated track is a text track, it will be automatically activated and
319  /// therefore it's subtitles will be delivered as events to the
320  /// <code>SubtitleListener_Samsung</code>.
321  ///
322  /// Constraints:
323  /// An ability to handle multiple video tracks at a time is not guaranteed to
324  /// be supported on all platforms, therefore calling this method with a
325  /// <code>PP_ElementaryStream_Type_Samsung_VIDEO</code> as a stream type may
326  /// result with a <code>PP_ERROR_NOTSUPPORTED</code> error code.
327  ///
328  /// @param[in] track_type A type of the stream for which activate track.
329  /// @param[in] track_index An index of the track which has to be activated.
330  /// Valid track index can be obtained from one of PP_*TrackInfo structures
331  /// returned by corresponding call to Get*TracksInfo.
332  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
333  /// completion.
334  ///
335  /// @return PP_OK on success, otherwise an error code from
336  /// <code>pp_errors.h</code>. Meaning of errors:
337  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
338  /// to the media player or passed |track_type| or |track_index| are
339  /// not valid.
340  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if called with
341  /// <code>PP_ElementaryStream_Type_Samsung_VIDEO</code> on a platform that
342  /// supports only one video track at a time.
344  PP_ElementaryStream_Type_Samsung track_type,
345  uint32_t track_index,
346  const CompletionCallback& callback);
347 
348  /* Subtitles control */
349 
350  /// Adds external subtitles.
351  /// Returns <code>PP_OK/code> in case of success and writes added text track
352  /// information to |subtitles| param. After that newly added subtitles will be
353  /// activated and <code>SubtitleListener_Samsung</code> will be notified about
354  /// it's texts at the time those texts should be shown.
355  ///
356  /// Please note that player is responsible only for subtitle file parsing. No
357  /// subtitles are displayed by the player. Application can use
358  /// <code>SubtitleListener_Samsung</code> to get subtitle texts at correct
359  /// playback times and display them manually.
360  ///
361  /// Constraints:
362  /// Ability to add external subtitles after attaching data source is
363  /// implementation dependent. If it is impossible to add external subtitles
364  /// after data source is attached, this method will fail with
365  /// <code>PP_ERROR_NOTSUPPORTED</code> error code. Therefore this method is
366  /// guaranteed to succeed only before data source is attached.
367  ///
368  /// @param[in] file_path A path of the subtitles.
369  /// @param[in] encoding Subtitle encoding. May be empty string, which will
370  /// cause subtitles to be interpreted as UTF-8 text.
371  /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
372  /// called upon completion with added subtitles information.
373  ///
374  /// @return PP_OK on success, otherwise an error code from
375  /// <code>pp_errors.h</code>. Meaning of errors:
376  /// - <code>PP_ERROR_FILENOTFOUND</code> - if provided file_path is invalid.
377  /// - <code>PP_ERROR_BADARGUMENT</code> - if provided encoding is invalid.
378  /// - <code>PP_ERROR_NOTSUPPORTED</code> - if method was called after
379  /// attaching a data source and such operation is not supported on the
380  /// current implementation.
382  const std::string& file_path,
383  const std::string& encoding,
385 
386  /// Sets subtitles (text stream) <code>SubtitleListener</code>
387  /// event emission delay regarding to the current media time.
388  ///
389  /// @param[in] delay A delay to be set.
390  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
391  /// completion.
392  ///
393  /// @return PP_OK on success, otherwise an error code from
394  /// <code>pp_errors.h</code>. Meaning of errors:
395  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
396  /// to the media player.
398  PP_TimeDelta delay,
399  const CompletionCallback& callback);
400 
401  /* Other - player control */
402 
403  /// Sets display region in which video will be displayed. Passed position
404  /// is relative to the embed/object element of WebPage associated with given
405  /// plugin.
406  ///
407  /// @param[in] rect Video region in which video will be displayed.
408  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
409  /// completion.
410  ///
411  /// @return PP_OK on success, otherwise an error code from
412  /// <code>pp_errors.h</code>.
414  const PP_Rect& rect,
415  const CompletionCallback& callback);
416 
417  /* DRM Related */
418 
419  /// Calls DRM system specific operation.
420  ///
421  /// @param[in] drm_type A DRM system to be used
422  /// @param[in] drm_operation A DRM specific operation to be performed.
423  /// @param[in] drm_data_size A size of data buffer passed to DRM system.
424  /// @param[in] drm_data A data buffer passed to DRM system.
425  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
426  /// completion.
427  ///
428  /// @return PP_OK on success, otherwise an error code from
429  /// <code>pp_errors.h</code>. Meaning of errors:
430  /// - <code>PP_ERROR_BADARGUMENT</code> - if no data source is connected
431  /// to the media player.
433  PP_MediaPlayerDRMType drm_type,
434  PP_MediaPlayerDRMOperation drm_operation,
435  uint32_t drm_data_size,
436  const void* drm_data,
437  const CompletionCallback& callback);
438 };
439 
440 } // namespace pp
441 
442 #endif // PPAPI_CPP_SAMSUNG_MEDIA_PLAYER_SAMSUNG_H_
MediaPlayer_Samsung & operator=(const MediaPlayer_Samsung &other)
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)
bool BindToInstance(const InstanceHandle &instance)
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)