Pepper_47_C++_interfaces
es_data_source_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_ES_DATA_SOURCE_SAMSUNG_H_
6 #define PPAPI_CPP_SAMSUNG_ES_DATA_SOURCE_SAMSUNG_H_
7 
8 #include <string>
9 
10 #include "ppapi/c/samsung/ppb_media_data_source_samsung.h"
12 #include "ppapi/cpp/resource.h"
14 
15 /// @file
16 /// This file defines the types allowing user to feed the player with
17 /// Elementary Stream data.
18 ///
19 /// Part of Pepper Media Player interfaces (Samsung's extension).
20 namespace pp {
21 
22 class ElementaryStreamListener_Samsung;
23 class InstanceHandle;
24 
25 /// Interface representing common functionalities of elementary streams.
26 ///
27 /// Basic usage:
28 /// 1. Crate stream by calling <code>ESDataSource_Samsung.AddStream</code>
29 /// 2. Initialize buffer specific information (audio/video config)
30 /// 3. Call <code>InitializeDone</code>
31 /// 5. Attach Data Source to the player
32 /// 6. Appends Elementary Stream packets by calling <code>AppendPacket</code>
33 /// 7. Signalize end of stream (clip) by calling
34 /// <code>ESDataSource_Samsung.SetEndOfStream</code>
36  public:
39 
40  virtual ~ElementaryStream_Samsung();
41 
42  /// Retrieves stream type represented by this resource.
43  virtual PP_ElementaryStream_Type_Samsung GetStreamType() const = 0;
44 
45  /// Call this method to confirm new/updated buffer config. This method will
46  /// return PP_OK if set buffer config is valid or one of the error codes from
47  /// <code>pp_errors.h</code> otherwise.
48  ///
49  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
50  /// completion.
51  ///
52  /// @return PP_OK on success, otherwise an error code from
53  /// <code>pp_errors.h</code>.
54  /// Method returns <code>PP_ERROR_BADARGUMENT</code> when stream configuration
55  /// is invalid.
57  const CompletionCallback& callback);
58 
59  /// Appends Elementary Stream packet.
60  ///
61  /// Before appending any packet to the buffer, it must be properly configured
62  /// (see <code>InitializeDone</code>).
63  ///
64  /// @param[in] packet A <code>PP_ESPacket</code> containing Elementary Stream
65  /// packet data and metadata.
66  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
67  /// completion.
68  ///
69  /// @return PP_OK on success, otherwise an error code from
70  /// <code>pp_errors.h</code>.
71  /// Returns PP_ERROR_FAILED if InitializeDone() has not successfully
72  /// completed.
74  const PP_ESPacket& packet,
75  const CompletionCallback& callback);
76 
77  /// Appends Elementary Stream encrypted packet.
78  ///
79  /// Before appending any packet to the buffer, it must be properly configured
80  /// (see <code>InitializeDone</code>).
81  ///
82  /// @param[in] packet A <code>PP_ESPacket</code> containing Elementary Stream
83  /// packet data and metadata.
84  /// @param[in] encryption_info A <code>PP_ESPacketEncryptionInfo</code>
85  /// containing packet encryption description.
86  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
87  /// completion.
88  ///
89  /// @return PP_OK on success, otherwise an error code from
90  /// <code>pp_errors.h</code>.
91  /// Returns PP_ERROR_FAILED if InitializeDone() has not successfully
92  /// completed.
94  const PP_ESPacket& packet,
95  const PP_ESPacketEncryptionInfo& encryption_info,
96  const CompletionCallback& callback);
97 
98  /// Flushes all appended, but not decoded or rendered packets to this buffer.
99  /// This method is usually called during seek operations.
100  ///
101  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
102  /// completion.
103  ///
104  /// @return PP_OK on success, otherwise an error code from
105  /// <code>pp_errors.h</code>.
106  /// Returns PP_ERROR_FAILED if InitializeDone() has not successfully
107  /// completed.
108  int32_t Flush(
109  const CompletionCallback& callback);
110 
111  /// Found DRM system initialization metadata. |type| describes type
112  /// of the initialization data |init_data| associated with the stream.
113  ///
114  /// @param[in] type_size A size of DRM specific |type| buffer
115  /// @param[in] type A buffer containing DRM system specific description of
116  /// type of an |init_data|.
117  /// @param[in] init_data_size A size of DRM specific |init_data| buffer
118  /// @param[in] init_data A buffer containing DRM system initialization data.
119  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
120  /// completion.
121  ///
122  /// @return PP_OK on success, otherwise an error code from
123  /// <code>pp_errors.h</code>.
125  uint32_t type_size,
126  const void* type,
127  uint32_t init_data_size,
128  const void* init_data,
129  const CompletionCallback& callback);
130 
131 
132  /// Found DRM system initialization metadata. |type| describes type
133  /// of the initialization data |init_data| associated with the stream.
134  ///
135  /// @param[in] type A string describing type of an |init_data|.
136  /// Examples:
137  /// - "cenc:pssh" - |init_data| will contain PSSH box as
138  /// described by Common Encryption specifiacation
139  /// - "mspr:pro" - |init_data| will contain Microsoft
140  /// PlayReady Object Header (PRO).
141  /// @param[in] init_data_size A size of DRM specific |init_data| buffer
142  /// @param[in] init_data A buffer containing DRM system initialization data.
143  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
144  /// completion.
145  ///
146  /// @return PP_OK on success, otherwise an error code from
147  /// <code>pp_errors.h</code>.
149  const std::string& type,
150  uint32_t init_data_size,
151  const void* init_data,
152  const CompletionCallback& callback);
153 
154  protected:
156  explicit ElementaryStream_Samsung(PP_Resource resource);
157  explicit ElementaryStream_Samsung(const Resource& resource);
158  explicit ElementaryStream_Samsung(PassRef, PP_Resource resource);
159 };
160 
161 /// Interface representing an audio elementary stream and containing methods
162 /// to set audio codec specific configuration.
163 ///
164 /// All pending configuration changes/initialization must be confirmed
165 /// by call to <code>ElementaryStream_Samsung.InitializeDone</code>.
166 ///
167 /// All getters return last set configuration, which might be not confirmed yet.
169  public:
171  explicit AudioElementaryStream_Samsung(PP_Resource resource);
175  const AudioElementaryStream_Samsung& other);
176 
178 
179  /// Retrieves stream type represented by this resource,
180  /// in this case <code>PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_AUDIO</code>.
181  virtual PP_ElementaryStream_Type_Samsung GetStreamType() const;
182 
183  PP_AudioCodec_Type_Samsung GetAudioCodecType() const;
184  void SetAudioCodecType(PP_AudioCodec_Type_Samsung audio_codec);
185 
186  PP_AudioCodec_Profile_Samsung GetAudioCodecProfile() const;
187  void SetAudioCodecProfile(PP_AudioCodec_Profile_Samsung profile);
188 
189  PP_SampleFormat_Samsung GetSampleFormat() const;
190  void SetSampleFormat(PP_SampleFormat_Samsung sample_format);
191 
192  PP_ChannelLayout_Samsung GetChannelLayout() const;
193  void SetChannelLayout(PP_ChannelLayout_Samsung channel_layout);
194 
195  int32_t GetBitsPerChannel() const;
196  void SetBitsPerChannel(int32_t bits_per_channel);
197 
199  void SetSamplesPerSecond(int32_t samples_per_second);
200 
201  /// Sets audio codec specific extra data. Those data are needed by audio codec
202  /// to initialize properly audio decoding.
203  ///
204  /// @param[in] extra_data_size Size in bytes of |extra_data| buffer.
205  /// @param[in] extra_data A pointer to the buffer containing audio codec
206  /// specific extra data.
207  void SetCodecExtraData(
208  uint32_t extra_data_size,
209  const void* extra_data);
210 };
211 
212 /// Interface representing an video elementary stream and containing methods
213 /// to set video codec specific configuration.
214 ///
215 /// All pending configuration changes/initialization must be confirmed
216 /// by call to <code>ElementaryStream_Samsung.InitializeDone</code>.
217 ///
218 /// All getters return last set configuration, which might be not confirmed yet.
220  public:
222  explicit VideoElementaryStream_Samsung(PP_Resource resource);
226  const VideoElementaryStream_Samsung& other);
227 
229 
230  /// Retrieves stream type represented by this resource,
231  /// in this case <code>PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_VIDEO</code>.
232  virtual PP_ElementaryStream_Type_Samsung GetStreamType() const;
233 
234  PP_VideoCodec_Type_Samsung GetVideoCodecType() const;
235  void SetVideoCodecType(PP_VideoCodec_Type_Samsung video_codec);
236 
237  PP_VideoCodec_Profile_Samsung GetVideoCodecProfile() const;
238  void SetVideoCodecProfile(PP_VideoCodec_Profile_Samsung video_codec);
239 
240  PP_VideoFrame_Format_Samsung GetVideoFrameFormat() const;
241  void SetVideoFrameFormat(PP_VideoFrame_Format_Samsung frame_format);
242 
243  /// Retrieves current video frame size in pixels.
244  PP_Size GetVideoFrameSize() const;
245 
246  /// Sets new video frame size in pixels.
247  void SetVideoFrameSize(const PP_Size& size);
248 
249  /// Retrieves current video frame rate as rational number represented by
250  /// fraction |numerator| / |denominator|.
251  ///
252  /// Both |numerator| and |denominator| must be non-null, otherwise no
253  /// information is retrieved.
254  void GetFrameRate(uint32_t* numerator, uint32_t* denominator) const;
255 
256  /// Sets new video frame rate as rational number represented by
257  /// fraction |numerator| / |denominator|.
258  ///
259  /// |denominator| must be positive (!= 0) otherwise no information is set.
260  void SetFrameRate(uint32_t numerator, uint32_t denominator);
261 
262  /// Sets video codec specific extra data. Those data are needed by video codec
263  /// to initialize properly video decoding.
264  ///
265  /// @param[in] extra_data_size Size in bytes of |extra_data| buffer.
266  /// @param[in] extra_data A pointer to the buffer containing video codec
267  /// specific extra data.
268  void SetCodecExtraData(
269  uint32_t extra_data_size,
270  const void* extra_data);
271 };
272 
273 /// Data source handling appends of Elementary Streams.
274 ///
275 /// It is a container for Elementary Streams (audio/video) and there can be at
276 /// most one stream of given type (see
277 /// <code>PP_ElementaryStream_Type_Samsung</code>).
278 /// Basic usage (playback of clip containing audio and video):
279 /// 1. Create ESDataSource_Samsung object.
280 /// 2. Add audio stream using <code>AddStream<T><code> with argument being
281 /// callback accepting <code>AudioElementryStream_Samsung</code>.
282 /// 3. Configure audio stream, by setting codec, sampling rate, channels and
283 /// other necessary information.
284 /// 4. Call <code>ElementaryStream_Samsung.InitializeDone</code> to confirm
285 /// the configuration
286 /// 2. Add video stream using <code>AddStream<T><code> with argument being
287 /// callback accepting <code>VideoElementryStream_Samsung</code>.
288 /// 6. Configure video stream, by setting codec, frame rate, resolution and
289 /// other necessary information.
290 /// 7. Call <code>ElementaryStream_Samsung.InitializeDone</code> to confirm
291 /// the configuration.
292 /// 8. Attach data source to the player by calling
293 /// <code>MediaPlayer_Samsung.AttachMediaSource</code>.
294 /// 9. Download and append Elementary Stream audio and video packets
295 /// by calling <code>ElementaryStream._SamsungAppendPacket</code>
296 /// 10. Signalize end of stream (clip) by calling <code>SetEndOfStream</code>
297 /// 11. Detach data source from the player by calling
298 /// <code>MediaPlayer_Samsung.AttachMediaSource</code> with
299 /// <code>NULL</code> object/resource.
301  public:
302  explicit ESDataSource_Samsung(const InstanceHandle& instance);
303 
305 
306  explicit ESDataSource_Samsung(PP_Resource resource);
308 
310 
311  virtual ~ESDataSource_Samsung();
312 
313  /// Factory method which adds stream of given type to the data source.
314  ///
315  /// Type T must be one of concrete types inheriting form
316  /// <code>ElementaryStream_Samsung</code>
317  ///
318  /// This data source can handle at most one buffer of given time, so calling
319  /// multiple times this method with the same buffer type will return the
320  /// same resource as all previous calls.
321  ///
322  /// @param[in] callback A <code>CompletionCallbackWithOutput</code>
323  /// to be called upon completion with added elementary stream.
324  ///
325  /// @return PP_OK on success, otherwise an error code from
326  /// <code>pp_errors.h</code>.
327  /// FIXME: remove listener default value once all related components will be
328  /// updated to use new ElementaryStreamListener_Samsung listener.
329  template<typename T>
331  ElementaryStreamListener_Samsung* listener = NULL);
332 
333  /// Sets duration of the whole stream/container/clip.
334  ///
335  /// @param[in] duration A duration of played media.
336  /// @param[in] callback A <code>CompletionCallback</code> to be called
337  /// upon completion.
338  ///
339  /// @return PP_OK on success, otherwise an error code from
340  /// <code>pp_errors.h</code>.
342  PP_TimeDelta duration,
343  const CompletionCallback& callback);
344 
345  /// Signalizes end of the whole stream/container/clip.
346  ///
347  ///
348  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
349  /// completion.
350  ///
351  /// @return PP_OK on success, otherwise an error code from
352  /// <code>pp_errors.h</code>.
354  const CompletionCallback& callback);
355 
356  private:
357  /// Factory method which adds stream of given type to the data source.
358  ///
359  /// This data source can handle at most one buffer of given time, so calling
360  /// multiple times this method with the same buffer type will return the
361  /// same resource as all previous calls.
362  ///
363  /// @param[in] stream_type A <code>PP_ElementaryStream_Type_Samsung</code>
364  /// identifying the stream type which will be added.
365  /// @param[out] stream An added stream
366  /// @param[in] callback A <code>CompletionCallback</code>
367  /// to be called upon completion.
368  ///
369  /// @return PP_OK on success, otherwise an error code from
370  /// <code>pp_errors.h</code>.
372  PP_ElementaryStream_Type_Samsung stream_type,
373  PP_Resource* stream,
375  const CompletionCallback& callback);
376 };
377 
378 /// Type traits of the stream type T.
379 ///
380 /// kType will be PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_UNKNOWN if T is not a valid
381 /// stream type.
382 template <typename T>
384  static const PP_ElementaryStream_Type_Samsung kType =
385  PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_UNKNOWN;
386 };
387 
388 template <>
390  static const PP_ElementaryStream_Type_Samsung kType =
391  PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_VIDEO;
392 };
393 
394 template <>
396  static const PP_ElementaryStream_Type_Samsung kType =
397  PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_AUDIO;
398 };
399 
400 #if __cplusplus >= 201103L
401 #define PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT(expr, msg) \
402  static_assert(expr, msg)
403 #else
404 #define PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT_CONCAT(a, b) a ## b
405 
406 #define PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT_MAKE_NAME(prefix, line) \
407  PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT_CONCAT(prefix, line)
408 
409 #define PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT_VAR \
410  PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT_MAKE_NAME(\
411  pp_media_player_static_assert_var_, __LINE__)
412 
413 #define PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT(expr, msg) do { \
414  typedef int static_assert_check[(expr) ? 1 : -1]; \
415  static_assert_check PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT_VAR = { 1 }; \
416 } while (0)
417 #endif
418 
419 template<typename T>
421  const CompletionCallbackWithOutput<T>& callback,
423  typedef ElementaryStreamTraits_Samsung<T> Traits;
425  Traits::kType != PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_UNKNOWN,
426  "Bad stream type!");
427  return AddStream(Traits::kType, callback.output(), listener, callback);
428 }
429 
430 } // namespace pp
431 
432 #endif // PPAPI_CPP_SAMSUNG_ES_DATA_SOURCE_SAMSUNG_H_
int32_t AppendPacket(const PP_ESPacket &packet, const CompletionCallback &callback)
PP_VideoCodec_Type_Samsung GetVideoCodecType() const
static const PP_ElementaryStream_Type_Samsung kType
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const =0
Retrieves stream type represented by this resource.
void SetBitsPerChannel(int32_t bits_per_channel)
int32_t SetDRMInitData(uint32_t type_size, const void *type, uint32_t init_data_size, const void *init_data, const CompletionCallback &callback)
#define PP_MEDIA_PLAYER_SAMSUNG_STATIC_ASSERT(expr, msg)
ESDataSource_Samsung & operator=(const ESDataSource_Samsung &other)
int32_t AppendEncryptedPacket(const PP_ESPacket &packet, const PP_ESPacketEncryptionInfo &encryption_info, const CompletionCallback &callback)
int32_t SetDuration(PP_TimeDelta duration, const CompletionCallback &callback)
void SetVideoCodecType(PP_VideoCodec_Type_Samsung video_codec)
Listener for receiving elementary stream related events.
void SetAudioCodecProfile(PP_AudioCodec_Profile_Samsung profile)
PP_VideoCodec_Profile_Samsung GetVideoCodecProfile() const
void SetChannelLayout(PP_ChannelLayout_Samsung channel_layout)
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const
void SetSamplesPerSecond(int32_t samples_per_second)
void SetSampleFormat(PP_SampleFormat_Samsung sample_format)
void SetVideoFrameSize(const PP_Size &size)
Sets new video frame size in pixels.
PassRef
Definition: pass_ref.h:17
void SetFrameRate(uint32_t numerator, uint32_t denominator)
ESDataSource_Samsung(const InstanceHandle &instance)
void SetVideoCodecProfile(PP_VideoCodec_Profile_Samsung video_codec)
PP_AudioCodec_Type_Samsung GetAudioCodecType() const
void SetCodecExtraData(uint32_t extra_data_size, const void *extra_data)
void GetFrameRate(uint32_t *numerator, uint32_t *denominator) const
PP_SampleFormat_Samsung GetSampleFormat() const
PP_Size GetVideoFrameSize() const
Retrieves current video frame size in pixels.
ElementaryStream_Samsung & operator=(const ElementaryStream_Samsung &other)
void SetVideoFrameFormat(PP_VideoFrame_Format_Samsung frame_format)
void SetAudioCodecType(PP_AudioCodec_Type_Samsung audio_codec)
int32_t SetEndOfStream(const CompletionCallback &callback)
PP_VideoFrame_Format_Samsung GetVideoFrameFormat() const
AudioElementaryStream_Samsung & operator=(const AudioElementaryStream_Samsung &other)
int32_t AddStream(const CompletionCallbackWithOutput< T > &callback, ElementaryStreamListener_Samsung *listener=NULL)
void SetCodecExtraData(uint32_t extra_data_size, const void *extra_data)
int32_t InitializeDone(const CompletionCallback &callback)
int32_t Flush(const CompletionCallback &callback)
A reference counted module resource.
Definition: resource.h:20
PP_ChannelLayout_Samsung GetChannelLayout() const
PP_AudioCodec_Profile_Samsung GetAudioCodecProfile() const
VideoElementaryStream_Samsung & operator=(const VideoElementaryStream_Samsung &other)
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const