Pepper_37_C++_interfaces
es_data_source_samsung.h
Go to the documentation of this file.
1 // Copyright 2015 The Chromium Authors. 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 "ppapi/c/samsung/ppb_media_data_source_samsung.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/resource.h"
11 #include "ppapi/cpp/samsung/media_data_source_samsung.h"
12 
13 /// @file
14 /// This file defines the types allowing user to feed the player with
15 /// Elementary Stream data.
16 ///
17 /// Part of Pepper Media Player interfaces (Samsung's extension).
18 namespace pp {
19 
20 class InstanceHandle;
21 
22 /// Interface representing common functionalities of elementary streams.
23 ///
24 /// Basic usage:
25 /// 1. Crate stream by calling <code>ESDataSource_Samsung.AddStream</code>
26 /// 2. Initialize buffer specific information (audio/video config)
27 /// 3. Call <code>InitializeDone</code>
28 /// 5. Attach Data Source to the player
29 /// 6. Appends Elementary Stream packets by calling <code>AppendPacket</code>
30 /// 7. Signalize end of stream (clip) by calling
31 /// <code>ESDataSource_Samsung.SetEndOfStream</code>
33  public:
36 
37  virtual ~ElementaryStream_Samsung();
38 
39  /// Retrieves stream type represented by this resource.
40  virtual PP_ElementaryStream_Type_Samsung GetStreamType() const = 0;
41 
42  /// Call this method to confirm new/updated buffer config. This method will
43  /// return PP_OK if set buffer config is valid or one of the error codes from
44  /// <code>pp_errors.h</code> otherwise.
45  ///
46  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
47  /// completion.
48  ///
49  /// @return PP_OK on success, otherwise an error code from
50  /// <code>pp_errors.h</code>.
51  /// Method returns <code>PP_ERROR_BADARGUMENT</code> when stream configuration
52  /// is invalid.
53  int32_t InitializeDone(
54  const CompletionCallback& callback);
55 
56  /// Appends Elementary Stream packet.
57  ///
58  /// Before appending any packet to the buffer, it must be properly configured
59  /// (see <code>InitializeDone</code>).
60  ///
61  /// @param[in] packet A <code>PP_ESPacket</code> containing Elementary Stream
62  /// packet data and metadata.
63  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
64  /// completion.
65  ///
66  /// @return PP_OK on success, otherwise an error code from
67  /// <code>pp_errors.h</code>.
68  /// Returns PP_ERROR_FAILED if InitializeDone() has not successfully
69  /// completed.
70  int32_t AppendPacket(
71  const PP_ESPacket& packet,
72  const CompletionCallback& callback);
73 
74  /// Appends Elementary Stream encrypted packet.
75  ///
76  /// Before appending any packet to the buffer, it must be properly configured
77  /// (see <code>InitializeDone</code>).
78  ///
79  /// @param[in] packet A <code>PP_ESPacket</code> containing Elementary Stream
80  /// packet data and metadata.
81  /// @param[in] encryption_info A <code>PP_ESPacketEncryptionInfo</code>
82  /// containing packet encryption description.
83  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
84  /// completion.
85  ///
86  /// @return PP_OK on success, otherwise an error code from
87  /// <code>pp_errors.h</code>.
88  /// Returns PP_ERROR_FAILED if InitializeDone() has not successfully
89  /// completed.
90  int32_t AppendEncryptedPacket(
91  const PP_ESPacket& packet,
92  const PP_ESPacketEncryptionInfo& encryption_info,
93  const CompletionCallback& callback);
94 
95  /// Flushes all appended, but not decoded or rendered packets to this buffer.
96  /// This method is usually called during seek operations.
97  ///
98  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
99  /// completion.
100  ///
101  /// @return PP_OK on success, otherwise an error code from
102  /// <code>pp_errors.h</code>.
103  /// Returns PP_ERROR_FAILED if InitializeDone() has not successfully
104  /// completed.
105  int32_t Flush(
106  const CompletionCallback& callback);
107 
108  /// Found DRM system initialization metadata. |type| describes type
109  /// of the initialization data |init_data| associated with the stream.
110  ///
111  /// @param[in] type_size A size of DRM specific |type| buffer
112  /// @param[in] type A buffer containing DRM system specific description of
113  /// type of an |init_data|.
114  /// @param[in] init_data_size A size of DRM specific |init_data| buffer
115  /// @param[in] init_data A buffer containing DRM system initialization data.
116  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
117  /// completion.
118  ///
119  /// @return PP_OK on success, otherwise an error code from
120  /// <code>pp_errors.h</code>.
121  int32_t SetDRMInitData(
122  uint32_t type_size,
123  const void* type,
124  uint32_t init_data_size,
125  const void* init_data,
126  const CompletionCallback& callback);
127 
128  protected:
130  explicit ElementaryStream_Samsung(PP_Resource resource);
131  explicit ElementaryStream_Samsung(const Resource& resource);
132  explicit ElementaryStream_Samsung(PassRef, PP_Resource resource);
133 };
134 
135 /// Interface representing an audio elementary stream and containing methods
136 /// to set audio codec specific configuration.
137 ///
138 /// All pending configuration changes/initialization must be confirmed
139 /// by call to <code>ElementaryStream_Samsung.InitializeDone</code>.
140 ///
141 /// All getters return last set configuration, which might be not confirmed yet.
143  public:
145  explicit AudioElementaryStream_Samsung(PP_Resource resource);
149  const AudioElementaryStream_Samsung& other);
150 
152 
153  /// Retrieves stream type represented by this resource,
154  /// in this case <code>PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_AUDIO</code>.
155  virtual PP_ElementaryStream_Type_Samsung GetStreamType() const;
156 
157  PP_AudioCodec_Type_Samsung GetAudioCodecType() const;
158  void SetAudioCodecType(PP_AudioCodec_Type_Samsung audio_codec);
159 
160  PP_AudioCodec_Profile_Samsung GetAudioCodecProfile() const;
161  void SetAudioCodecProfile(PP_AudioCodec_Profile_Samsung profile);
162 
163  PP_SampleFormat_Samsung GetSampleFormat() const;
164  void SetSampleFormat(PP_SampleFormat_Samsung sample_format);
165 
166  PP_ChannelLayout_Samsung GetChannelLayout() const;
167  void SetChannelLayout(PP_ChannelLayout_Samsung channel_layout);
168 
169  int32_t GetBitsPerChannel() const;
170  void SetBitsPerChannel(int32_t bits_per_channel);
171 
172  int32_t GetSamplesPerSecond() const;
173  void SetSamplesPerSecond(int32_t samples_per_second);
174 
175  /// Sets audio codec specific extra data. Those data are needed by audio codec
176  /// to initialize properly audio decoding.
177  ///
178  /// @param[in] extra_data_size Size in bytes of |extra_data| buffer.
179  /// @param[in] extra_data A pointer to the buffer containing audio codec
180  /// specific extra data.
181  void SetCodecExtraData(
182  uint32_t extra_data_size,
183  const void* extra_data);
184 };
185 
186 /// Interface representing an video elementary stream and containing methods
187 /// to set video codec specific configuration.
188 ///
189 /// All pending configuration changes/initialization must be confirmed
190 /// by call to <code>ElementaryStream_Samsung.InitializeDone</code>.
191 ///
192 /// All getters return last set configuration, which might be not confirmed yet.
194  public:
196  explicit VideoElementaryStream_Samsung(PP_Resource resource);
200  const VideoElementaryStream_Samsung& other);
201 
203 
204  /// Retrieves stream type represented by this resource,
205  /// in this case <code>PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_VIDEO</code>.
206  virtual PP_ElementaryStream_Type_Samsung GetStreamType() const;
207 
208  PP_VideoCodec_Type_Samsung GetVideoCodecType() const;
209  void SetVideoCodecType(PP_VideoCodec_Type_Samsung video_codec);
210 
211  PP_VideoCodec_Profile_Samsung GetVideoCodecProfile() const;
212  void SetVideoCodecProfile(PP_VideoCodec_Profile_Samsung video_codec);
213 
214  PP_VideoFrame_Format_Samsung GetVideoFrameFormat() const;
215  void SetVideoFrameFormat(PP_VideoFrame_Format_Samsung frame_format);
216 
217  /// Retrieves current video frame size in pixels.
218  PP_Size GetVideoFrameSize() const;
219 
220  /// Sets new video frame size in pixels.
221  void SetVideoFrameSize(const PP_Size& size);
222 
223  /// Retrieves current video frame rate as rational number represented by
224  /// fraction |numerator| / |denominator|.
225  ///
226  /// Both |numerator| and |denominator| must be non-null, otherwise no
227  /// information is retrieved.
228  void GetFrameRate(uint32_t* numerator, uint32_t* denominator) const;
229 
230  /// Sets new video frame rate as rational number represented by
231  /// fraction |numerator| / |denominator|.
232  ///
233  /// |denominator| must be positive (!= 0) otherwise no information is set.
234  void SetFrameRate(uint32_t numerator, uint32_t denominator);
235 
236  /// Sets video codec specific extra data. Those data are needed by video codec
237  /// to initialize properly video decoding.
238  ///
239  /// @param[in] extra_data_size Size in bytes of |extra_data| buffer.
240  /// @param[in] extra_data A pointer to the buffer containing video codec
241  /// specific extra data.
242  void SetCodecExtraData(
243  uint32_t extra_data_size,
244  const void* extra_data);
245 };
246 
247 /// Interface representing a text elementary stream and containing methods
248 /// to set text/subtitles specific configuration.
249 ///
250 /// All pending configuration changes/initialization must be confirmed
251 /// by call to <code>ElementaryStream_Samsung.InitializeDone</code>.
252 ///
253 /// All getters return last set configuration, which might be not confirmed yet.
255  public:
257  explicit TextElementaryStream_Samsung(PP_Resource resource);
261  const TextElementaryStream_Samsung& other);
262 
264 
265  /// Retrieves stream type represented by this resource,
266  /// in this case <code>PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_TEXT</code>.
267  virtual PP_ElementaryStream_Type_Samsung GetStreamType() const;
268 
269  PP_SubtitleType_Samsung GetSubtitleType() const;
270  void SetSubtitleType(PP_SubtitleType_Samsung type);
271 };
272 
273 /// Data source handling appends of Elementary Streams.
274 ///
275 /// It is a container for Elementary Streams (audio/video/...) and there can
276 /// be at 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  template<typename T>
328  int32_t AddStream(const CompletionCallbackWithOutput<T>& callback);
329 
330  /// Sets duration of the whole stream/container/clip.
331  ///
332  /// @param[in] duration A duration of played media.
333  /// @param[in] callback A <code>CompletionCallback</code> to be called
334  /// upon completion.
335  ///
336  /// @return PP_OK on success, otherwise an error code from
337  /// <code>pp_errors.h</code>.
338  int32_t SetDuration(
339  PP_TimeDelta duration,
340  const CompletionCallback& callback);
341 
342  /// Signalizes end of the whole stream/container/clip.
343  ///
344  ///
345  /// @param[in] callback A <code>CompletionCallback</code> to be called upon
346  /// completion.
347  ///
348  /// @return PP_OK on success, otherwise an error code from
349  /// <code>pp_errors.h</code>.
350  int32_t SetEndOfStream(
351  const CompletionCallback& callback);
352 
353  private:
354  /// Factory method which adds stream of given type to the data source.
355  ///
356  /// This data source can handle at most one buffer of given time, so calling
357  /// multiple times this method with the same buffer type will return the
358  /// same resource as all previous calls.
359  ///
360  /// @param[in] stream_type A <code>PP_ElementaryStream_Type_Samsung</code>
361  /// identifying the stream type which will be added.
362  /// @param[out] stream An added stream
363  /// @param[in] callback A <code>CompletionCallback</code>
364  /// to be called upon completion.
365  ///
366  /// @return PP_OK on success, otherwise an error code from
367  /// <code>pp_errors.h</code>.
368  int32_t AddStream(
369  PP_ElementaryStream_Type_Samsung stream_type,
370  PP_Resource* stream,
371  const CompletionCallback& callback);
372 };
373 
374 template<>
377  callback) {
378  return AddStream(PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_AUDIO,
379  callback.output(), callback);
380 }
381 
382 template<>
385  callback) {
386  return AddStream(PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_VIDEO,
387  callback.output(), callback);
388 }
389 
390 template<>
393  callback) {
394  return AddStream(PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_TEXT,
395  callback.output(), callback);
396 }
397 
398 } // namespace pp
399 
400 #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
TextElementaryStream_Samsung & operator=(const TextElementaryStream_Samsung &other)
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const =0
Retrieves stream type represented by this resource.
void SetBitsPerChannel(int32_t bits_per_channel)
int32_t GetSamplesPerSecond() const
int32_t SetDRMInitData(uint32_t type_size, const void *type, uint32_t init_data_size, const void *init_data, const CompletionCallback &callback)
int32_t AppendEncryptedPacket(const PP_ESPacket &packet, const PP_ESPacketEncryptionInfo &encryption_info, const CompletionCallback &callback)
int32_t SetDuration(PP_TimeDelta duration, const CompletionCallback &callback)
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const
void SetVideoCodecType(PP_VideoCodec_Type_Samsung video_codec)
ElementaryStream_Samsung & operator=(const ElementaryStream_Samsung &other)
void SetAudioCodecProfile(PP_AudioCodec_Profile_Samsung profile)
PP_VideoCodec_Profile_Samsung GetVideoCodecProfile() const
AudioElementaryStream_Samsung & operator=(const AudioElementaryStream_Samsung &other)
void SetChannelLayout(PP_ChannelLayout_Samsung channel_layout)
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)
VideoElementaryStream_Samsung & operator=(const VideoElementaryStream_Samsung &other)
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)
PP_SubtitleType_Samsung GetSubtitleType() const
void GetFrameRate(uint32_t *numerator, uint32_t *denominator) const
PP_SampleFormat_Samsung GetSampleFormat() const
void SetSubtitleType(PP_SubtitleType_Samsung type)
PP_Size GetVideoFrameSize() const
Retrieves current video frame size in pixels.
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
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const
void SetCodecExtraData(uint32_t extra_data_size, const void *extra_data)
int32_t InitializeDone(const CompletionCallback &callback)
int32_t Flush(const CompletionCallback &callback)
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const
A reference counted module resource.
Definition: resource.h:20
PP_ChannelLayout_Samsung GetChannelLayout() const
PP_AudioCodec_Profile_Samsung GetAudioCodecProfile() const
int32_t AddStream(const CompletionCallbackWithOutput< T > &callback)
ESDataSource_Samsung & operator=(const ESDataSource_Samsung &other)