Pepper_47_C++_interfaces
es_data_source_samsung.cc
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 
6 
7 #include "ppapi/c/pp_errors.h"
12 
13 namespace pp {
14 
15 namespace {
16 
17 template <>
18 const char* interface_name<PPB_ElementaryStream_Samsung_1_0>() {
19  return PPB_ELEMENTARYSTREAM_SAMSUNG_INTERFACE_1_0;
20 }
21 
22 template <>
23 const char* interface_name<PPB_AudioElementaryStream_Samsung_1_0>() {
24  return PPB_AUDIOELEMENTARYSTREAM_SAMSUNG_INTERFACE_1_0;
25 }
26 
27 template <>
28 const char* interface_name<PPB_VideoElementaryStream_Samsung_1_0>() {
29  return PPB_VIDEOELEMENTARYSTREAM_SAMSUNG_INTERFACE_1_0;
30 }
31 
32 template <>
33 const char* interface_name<PPB_ESDataSource_Samsung_1_0>() {
34  return PPB_ESDATASOURCE_SAMSUNG_INTERFACE_1_0;
35 }
36 
37 void ElementaryStreamListenerWrapper_OnNeedData(int32_t max_bytes,
38  void* user_data) {
39  if (!user_data) return;
40 
41  ElementaryStreamListener_Samsung* listener =
42  static_cast<ElementaryStreamListener_Samsung*>(user_data);
43  listener->OnNeedData(max_bytes);
44 }
45 
46 void ElementaryStreamListenerWrapper_OnEnoughData(void* user_data) {
47  if (!user_data) return;
48 
49  ElementaryStreamListener_Samsung* listener =
50  static_cast<ElementaryStreamListener_Samsung*>(user_data);
51  listener->OnEnoughData();
52 }
53 
54 void ElementaryStreamListenerWrapper_OnSeekData(PP_TimeTicks new_position,
55  void* user_data) {
56  if (!user_data) return;
57 
58  ElementaryStreamListener_Samsung* listener =
59  static_cast<ElementaryStreamListener_Samsung*>(user_data);
60  listener->OnSeekData(new_position);
61 }
62 
63 const PPP_ElementaryStreamListener_Samsung_1_0* GetListenerWrapper() {
64  static const PPP_ElementaryStreamListener_Samsung_1_0 listener = {
65  &ElementaryStreamListenerWrapper_OnNeedData,
66  &ElementaryStreamListenerWrapper_OnEnoughData,
67  &ElementaryStreamListenerWrapper_OnSeekData
68  };
69  return &listener;
70 }
71 
72 } // namespace
73 
74 // ElementaryStream_Samsung implementation
75 
77  const ElementaryStream_Samsung& other)
78  : Resource(other) {
79 }
80 
82  const ElementaryStream_Samsung& other) {
83  Resource::operator=(other);
84  return *this;
85 }
86 
88 }
89 
91  const CompletionCallback& callback) {
92 
93  if (has_interface<PPB_ElementaryStream_Samsung_1_0>()) {
94  return get_interface<PPB_ElementaryStream_Samsung_1_0>()->
96  }
97 
98  return callback.MayForce(PP_ERROR_NOINTERFACE);
99 }
100 
102  const PP_ESPacket& packet,
103  const CompletionCallback& callback) {
104 
105  if (has_interface<PPB_ElementaryStream_Samsung_1_0>()) {
106  return get_interface<PPB_ElementaryStream_Samsung_1_0>()->AppendPacket(
107  pp_resource(), &packet, callback.pp_completion_callback());
108  }
109 
110  return callback.MayForce(PP_ERROR_NOINTERFACE);
111 }
112 
114  const PP_ESPacket& packet,
115  const PP_ESPacketEncryptionInfo& encryption_info,
116  const CompletionCallback& callback) {
117 
118  if (has_interface<PPB_ElementaryStream_Samsung_1_0>()) {
119  return get_interface<PPB_ElementaryStream_Samsung_1_0>()->
121  &packet,
122  &encryption_info,
123  callback.pp_completion_callback());
124  }
125 
126  return callback.MayForce(PP_ERROR_NOINTERFACE);
127 }
128 
130  if (has_interface<PPB_ElementaryStream_Samsung_1_0>()) {
131  return get_interface<PPB_ElementaryStream_Samsung_1_0>()->Flush(
132  pp_resource(), callback.pp_completion_callback());
133  }
134 
135  return callback.MayForce(PP_ERROR_NOINTERFACE);
136 }
137 
139  uint32_t type_size, const void* type,
140  uint32_t init_data_size, const void* init_data,
141  const CompletionCallback& callback) {
142 
143  if (has_interface<PPB_ElementaryStream_Samsung_1_0>()) {
144  std::string type_str(reinterpret_cast<const char*>(type), type_size);
145  return get_interface<PPB_ElementaryStream_Samsung_1_0>()->SetDRMInitData(
146  pp_resource(), type_str.c_str(), init_data_size, init_data,
147  callback.pp_completion_callback());
148  }
149 
150  return callback.MayForce(PP_ERROR_NOINTERFACE);
151 }
152 
154  const std::string& type,
155  uint32_t init_data_size, const void* init_data,
156  const CompletionCallback& callback) {
157 
158  if (has_interface<PPB_ElementaryStream_Samsung_1_0>()) {
159  return get_interface<PPB_ElementaryStream_Samsung_1_0>()->SetDRMInitData(
160  pp_resource(), type.c_str(), init_data_size, init_data,
161  callback.pp_completion_callback());
162  }
163 
164  return callback.MayForce(PP_ERROR_NOINTERFACE);
165 }
166 
168  : Resource() {
169 }
170 
172  : Resource(resource) {
173 }
174 
176  : Resource(resource) {
177 }
178 
180  PassRef, PP_Resource resource)
181  : Resource(PASS_REF, resource) {
182 }
183 
184 // AudioElementaryStream_Samsung implementation
185 
188 }
189 
191  PP_Resource resource)
192  : ElementaryStream_Samsung(resource) {
193 }
194 
196  PassRef, PP_Resource resource)
197  : ElementaryStream_Samsung(PASS_REF, resource) {
198 }
199 
201  const AudioElementaryStream_Samsung& other)
202  : ElementaryStream_Samsung(other) {
203 }
204 
206  const AudioElementaryStream_Samsung& other) {
208  return *this;
209 }
210 
212 }
213 
214 PP_ElementaryStream_Type_Samsung
216  return PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_AUDIO;
217 }
218 
219 PP_AudioCodec_Type_Samsung
221  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
222  return get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
224  }
225 
226  return PP_AUDIOCODEC_TYPE_SAMSUNG_UNKNOWN;
227 }
228 
230  PP_AudioCodec_Type_Samsung audio_codec) {
231  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
232  get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
233  SetAudioCodecType(pp_resource(), audio_codec);
234  }
235 }
236 
237 PP_AudioCodec_Profile_Samsung
239  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
240  return get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
242  }
243 
244  return PP_AUDIOCODEC_PROFILE_SAMSUNG_UNKNOWN;
245 }
246 
248  PP_AudioCodec_Profile_Samsung profile) {
249  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
250  get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
251  SetAudioCodecProfile(pp_resource(), profile);
252  }
253 }
254 
255 PP_SampleFormat_Samsung AudioElementaryStream_Samsung::GetSampleFormat() const {
256  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
257  return get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
259  }
260 
261  return PP_SAMPLEFORMAT_SAMSUNG_UNKNOWN;
262 }
263 
265  PP_SampleFormat_Samsung sample_format) {
266  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
267  get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
268  SetSampleFormat(pp_resource(), sample_format);
269  }
270 }
271 
272 PP_ChannelLayout_Samsung
274  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
275  return get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
277  }
278 
279  return PP_CHANNEL_LAYOUT_SAMSUNG_NONE;
280 }
281 
283  PP_ChannelLayout_Samsung channel_layout) {
284  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
285  get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
286  SetChannelLayout(pp_resource(), channel_layout);
287  }
288 }
289 
291  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
292  return get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
294  }
295 
296  return -1;
297 }
298 
300  int32_t bits_per_channel) {
301  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
302  get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
303  SetBitsPerChannel(pp_resource(), bits_per_channel);
304  }
305 }
306 
308  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
309  return get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
311  }
312 
313  return -1;
314 }
315 
317  int32_t samples_per_second) {
318  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
319  get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
320  SetSamplesPerSecond(pp_resource(), samples_per_second);
321  }
322 }
323 
325  uint32_t extra_data_size,
326  const void* extra_data) {
327  if (has_interface<PPB_AudioElementaryStream_Samsung_1_0>()) {
328  get_interface<PPB_AudioElementaryStream_Samsung_1_0>()->
329  SetCodecExtraData(pp_resource(), extra_data_size, extra_data);
330  }
331 }
332 
333 // VideoElementaryStream_Samsung implementation
334 
337 }
338 
340  PP_Resource resource)
341  : ElementaryStream_Samsung(resource) {
342 }
343 
345  PassRef, PP_Resource resource)
346  : ElementaryStream_Samsung(PASS_REF, resource) {
347 }
348 
350  const VideoElementaryStream_Samsung& other)
351  : ElementaryStream_Samsung(other) {
352 }
353 
355  const VideoElementaryStream_Samsung& other) {
357  return *this;
358 }
359 
361 }
362 
363 PP_ElementaryStream_Type_Samsung
365  return PP_ELEMENTARYSTREAM_TYPE_SAMSUNG_VIDEO;
366 }
367 
368 PP_VideoCodec_Type_Samsung
370  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
371  return get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
373  }
374 
375  return PP_VIDEOCODEC_TYPE_SAMSUNG_UNKNOWN;
376 }
377 
379  PP_VideoCodec_Type_Samsung video_codec) {
380  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
381  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
382  SetVideoCodecType(pp_resource(), video_codec);
383  }
384 }
385 
386 PP_VideoCodec_Profile_Samsung
388  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
389  return get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
391  }
392 
393  return PP_VIDEOCODEC_PROFILE_SAMSUNG_UNKNOWN;
394 }
395 
397  PP_VideoCodec_Profile_Samsung video_codec) {
398  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
399  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
400  SetVideoCodecProfile(pp_resource(), video_codec);
401  }
402 }
403 
404 PP_VideoFrame_Format_Samsung
406  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
407  return get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
409  }
410 
411  return PP_VIDEOFRAME_FORMAT_SAMSUNG_INVALID;
412 }
413 
415  PP_VideoFrame_Format_Samsung frame_format) {
416  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
417  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
418  SetVideoFrameFormat(pp_resource(), frame_format);
419  }
420 }
421 
423  PP_Size size = PP_MakeSize(-1, -1);
424  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
425  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
426  GetVideoFrameSize(pp_resource(), &size);
427  }
428 
429  return size;
430 }
431 
433  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
434  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
435  SetVideoFrameSize(pp_resource(), &size);
436  }
437 }
438 
440  uint32_t* numerator, uint32_t* denominator) const {
441  if (!numerator || !denominator) {
442  if (numerator) *numerator = 0;
443  if (denominator) *denominator = 0;
444  } else if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
445  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
446  GetFrameRate(pp_resource(), numerator, denominator);
447  } else {
448  *numerator = 0;
449  *denominator = 0;
450  }
451 }
452 
454  uint32_t numerator, uint32_t denominator) {
455  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
456  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
457  SetFrameRate(pp_resource(), numerator, denominator);
458  }
459 }
460 
462  uint32_t extra_data_size, const void* extra_data) {
463  if (has_interface<PPB_VideoElementaryStream_Samsung_1_0>()) {
464  get_interface<PPB_VideoElementaryStream_Samsung_1_0>()->
465  SetCodecExtraData(pp_resource(), extra_data_size, extra_data);
466  }
467 }
468 
469 // ESDataSource implementation
470 
472  if (has_interface<PPB_ESDataSource_Samsung_1_0>()) {
474  get_interface<PPB_ESDataSource_Samsung_1_0>()->Create(
475  instance.pp_instance()));
476  }
477 }
478 
480  : MediaDataSource_Samsung(other) {
481 }
482 
484  : MediaDataSource_Samsung(resource) {
485 }
486 
488  : MediaDataSource_Samsung(PASS_REF, resource) {
489 }
490 
492  const ESDataSource_Samsung& other) {
494  return *this;
495 }
496 
498 }
499 
501  const CompletionCallback& callback) {
502  if (has_interface<PPB_ESDataSource_Samsung_1_0>()) {
503  return get_interface<PPB_ESDataSource_Samsung_1_0>()->SetDuration(
504  pp_resource(), duration, callback.pp_completion_callback());
505  }
506 
507  return callback.MayForce(PP_ERROR_NOINTERFACE);
508 }
509 
511  const CompletionCallback& callback) {
512 
513  if (has_interface<PPB_ESDataSource_Samsung_1_0>()) {
514  return get_interface<PPB_ESDataSource_Samsung_1_0>()->SetEndOfStream(
515  pp_resource(), callback.pp_completion_callback());
516  }
517 
518  return callback.MayForce(PP_ERROR_NOINTERFACE);
519 }
520 
522  PP_ElementaryStream_Type_Samsung stream_type,
523  PP_Resource* stream,
525  const CompletionCallback& callback) {
526 
527  if (has_interface<PPB_ESDataSource_Samsung_1_0>()) {
528  return get_interface<PPB_ESDataSource_Samsung_1_0>()->AddStream(
529  pp_resource(), stream_type, GetListenerWrapper(), listener, stream,
530  callback.pp_completion_callback());
531  }
532 
533  return callback.MayForce(PP_ERROR_NOINTERFACE);
534 }
535 
536 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
int32_t AppendPacket(const PP_ESPacket &packet, const CompletionCallback &callback)
PP_VideoCodec_Type_Samsung GetVideoCodecType() const
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)
ESDataSource_Samsung & operator=(const ESDataSource_Samsung &other)
int32_t MayForce(int32_t result) const
const PP_CompletionCallback & pp_completion_callback() const
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_Resource pp_resource() const
Definition: resource.h:47
MediaDataSource_Samsung & operator=(const MediaDataSource_Samsung &other)
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)
PP_Instance pp_instance() const
A reference counted module resource.
Definition: resource.h:20
PP_ChannelLayout_Samsung GetChannelLayout() const
Resource & operator=(const Resource &other)
Definition: resource.cc:27
PP_AudioCodec_Profile_Samsung GetAudioCodecProfile() const
VideoElementaryStream_Samsung & operator=(const VideoElementaryStream_Samsung &other)
virtual PP_ElementaryStream_Type_Samsung GetStreamType() const