NaCl Player API
NaCl Player API Documentation
es_data_source.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 NACL_PLAYER_ES_DATA_SOURCE_H_
6 #define NACL_PLAYER_ES_DATA_SOURCE_H_
7 
8 #include <functional>
9 #include <memory>
10 #include <vector>
11 
12 #include "nacl_player/common.h"
13 #include "nacl_player/error_codes.h"
14 #include "nacl_player/media_common.h"
15 #include "nacl_player/media_codecs.h"
16 #include "nacl_player/media_data_source.h"
17 
18 
24 namespace Samsung {
25 namespace NaClPlayer {
26 
27 class ElementaryStreamListener;
28 
52  public:
53  ElementaryStream(const ElementaryStream& other);
54  ElementaryStream& operator=(const ElementaryStream& other);
55 
56  virtual ~ElementaryStream();
57 
59  virtual ElementaryStreamType GetStreamType() const = 0;
60 
75  int32_t InitializeDone(const std::function<void(int32_t)>& callback);
76 
83  int32_t InitializeDone();
84 
97  int32_t InitializeDone(
99  const std::function<void(int32_t)>& callback);
100 
108 
124  int32_t AppendPacket(
125  const ESPacket& packet,
126  const std::function<void(int32_t)>& callback);
127 
133  int32_t AppendPacket(const ESPacket& packet);
134 
152  int32_t AppendEncryptedPacket(
153  const ESPacket& packet,
154  const ESPacketEncryptionInfo& encryption_info,
155  const std::function<void(int32_t)>& callback);
156 
161  int32_t AppendEncryptedPacket(
162  const ESPacket& packet,
163  const ESPacketEncryptionInfo& encryption_info);
164 
193  int32_t AppendTrustZonePacket(
194  const ESPacket& packet,
195  const TrustZoneReference& handle,
196  const std::function<void(int32_t)>& callback);
197 
202  int32_t AppendTrustZonePacket(
203  const ESPacket& packet,
204  const TrustZoneReference& handle);
205 
215  int32_t Flush(const std::function<void(int32_t)>& callback);
216 
222  int32_t Flush();
223 
237  int32_t SetDRMInitData(
238  const std::string& type,
239  uint32_t init_data_size,
240  const void* init_data,
241  const std::function<void(int32_t)>& callback);
242 
247  int32_t SetDRMInitData(
248  const std::string& type,
249  uint32_t init_data_size,
250  const void* init_data);
251 
252  protected:
254 
255  class Impl;
256  virtual Impl* impl() = 0;
257 };
258 
267  public:
270  AudioElementaryStream& operator=(const AudioElementaryStream& other);
271 
272  virtual ~AudioElementaryStream();
273 
276  virtual ElementaryStreamType GetStreamType() const;
277 
279  AudioCodec_Type GetAudioCodecType() const;
280 
285  void SetAudioCodecType(AudioCodec_Type audio_codec);
286 
288  AudioCodec_Profile GetAudioCodecProfile() const;
289 
295  void SetAudioCodecProfile(AudioCodec_Profile profile);
296 
298  SampleFormat GetSampleFormat() const;
299 
305  void SetSampleFormat(SampleFormat sample_format);
306 
308  ChannelLayout GetChannelLayout() const;
309 
311  void SetChannelLayout(ChannelLayout channel_layout);
312 
315  int32_t GetBitsPerChannel() const;
316 
322  void SetBitsPerChannel(int32_t bits_per_channel);
323 
325  int32_t GetSamplesPerSecond() const;
326 
328  void SetSamplesPerSecond(int32_t samples_per_second);
329 
337  void SetCodecExtraData(
338  uint32_t extra_data_size,
339  const void* extra_data);
340 
341  protected:
342  ElementaryStream::Impl* impl();
343 
344  private:
345  class Impl;
346 
347  friend class ESDataSource;
348 
349  explicit AudioElementaryStream(std::unique_ptr<Impl> impl);
350 
351  std::unique_ptr<Impl> pimpl_;
352 };
353 
362  public:
365  VideoElementaryStream& operator=(const VideoElementaryStream& other);
366 
367  virtual ~VideoElementaryStream();
368 
371  virtual ElementaryStreamType GetStreamType() const;
372 
374  VideoCodec_Type GetVideoCodecType() const;
375 
380  void SetVideoCodecType(VideoCodec_Type video_codec);
381 
383  VideoCodec_Profile GetVideoCodecProfile() const;
384 
390  void SetVideoCodecProfile(VideoCodec_Profile video_codec);
391 
393  VideoFrame_Format GetVideoFrameFormat() const;
394 
400  void SetVideoFrameFormat(VideoFrame_Format frame_format);
401 
403  Size GetVideoFrameSize() const;
404 
406  void SetVideoFrameSize(const Size& size);
407 
409  Rational GetFrameRate() const;
410 
413  void SetFrameRate(const Rational& r);
414 
422  void SetCodecExtraData(
423  uint32_t extra_data_size,
424  const void* extra_data);
425 
426  protected:
427  ElementaryStream::Impl* impl();
428 
429  private:
430  class Impl;
431 
432  friend class ESDataSource;
433 
434  explicit VideoElementaryStream(std::unique_ptr<Impl> impl);
435 
436  std::unique_ptr<Impl> pimpl_;
437 };
438 
442 template <typename T>
444  static constexpr ElementaryStreamType kType =
446 };
447 
448 template <>
450  static constexpr ElementaryStreamType kType =
452 };
453 
454 template <>
456  static constexpr ElementaryStreamType kType =
458 };
459 
501  public:
502  ESDataSource();
503  ESDataSource(const ESDataSource& other);
504  ESDataSource& operator=(const ESDataSource& other);
505 
506  virtual ~ESDataSource();
507 
529  template<typename T>
530  int32_t AddStream(
531  const std::function<void(int32_t, const T&)>& callback,
532  ElementaryStreamListener* listener);
533 
540  template<typename T>
541  int32_t AddStream(
542  const std::function<void(int32_t, const T&)>& callback,
543  std::shared_ptr<ElementaryStreamListener> listener);
544 
557  template<typename T>
558  int32_t AddStream(T& stream,
559  ElementaryStreamListener* listener = nullptr);
560 
578  template<typename T>
579  int32_t AddStream(T& stream,
580  std::shared_ptr<ElementaryStreamListener> listener);
581 
582 
590  int32_t SetDuration(
591  TimeDelta duration,
592  const std::function<void(int32_t)>& callback);
593 
598  int32_t SetDuration(TimeDelta duration);
599 
606  int32_t SetEndOfStream(
607  const std::function<void(int32_t)>& callback);
608 
613  int32_t SetEndOfStream();
614 
615  protected:
616  MediaDataSource::Impl* impl() const;
617 
618  private:
621  template<typename T>
622  static void OnStreamAdded(
623  const std::function<void(int32_t, const T&)>& callback,
624  int32_t result, const ElementaryStream& stream);
625 
639  int32_t AddStream(
640  ElementaryStreamType stream_type,
641  ElementaryStreamListener* listener,
642  const std::function<void(int32_t, const ElementaryStream&)>& callback);
643 
657  int32_t AddStream(ElementaryStreamType stream_type, ElementaryStream& stream,
658  ElementaryStreamListener* listener);
659 
664  int32_t AddStream(
665  ElementaryStreamType stream_type,
666  std::shared_ptr<ElementaryStreamListener> listener,
667  const std::function<void(int32_t, const ElementaryStream&)>& callback);
668 
673  int32_t AddStream(ElementaryStreamType stream_type, ElementaryStream& stream,
674  std::shared_ptr<ElementaryStreamListener> listener);
675 
676  class Impl;
677  std::unique_ptr<Impl> pimpl_;
678 };
679 
680 template<typename T>
681 void ESDataSource::OnStreamAdded(
682  const std::function<void(int32_t, const T&)>& callback,
683  int32_t result, const ElementaryStream& stream) {
684  callback(result, static_cast<const T&>(stream));
685 }
686 
687 template<typename T>
688 inline int32_t ESDataSource::AddStream(
689  const std::function<void(int32_t, const T&)>& callback,
690  std::shared_ptr<ElementaryStreamListener> listener) {
691  typedef ElementaryStreamTraits<T> Traits;
692  static_assert(Traits::kType != ElementaryStreamType_Unknown,
693  "Invalid stream type.");
694  return AddStream(Traits::kType, listener,
695  [callback](int32_t result, const ElementaryStream& stream) {
696  ESDataSource::OnStreamAdded(callback, result, stream);});
697 }
698 
699 template<typename T>
700 inline int32_t ESDataSource::AddStream(
701  const std::function<void(int32_t, const T&)>& callback,
702  ElementaryStreamListener* listener) {
703  typedef ElementaryStreamTraits<T> Traits;
704  static_assert(Traits::kType != ElementaryStreamType_Unknown,
705  "Invalid stream type.");
706  return AddStream(Traits::kType, listener,
707  [callback](int32_t result, const ElementaryStream& stream) {
708  ESDataSource::OnStreamAdded(callback, result, stream);});
709 }
710 
711 template<typename T>
712 inline int32_t ESDataSource::AddStream(T& stream,
713  std::shared_ptr<ElementaryStreamListener> listener) {
714  typedef ElementaryStreamTraits<T> Traits;
715  static_assert(Traits::kType != ElementaryStreamType_Unknown,
716  "Invalid stream type.");
717  return AddStream(Traits::kType, stream, listener);
718 }
719 
720 template<typename T>
721 inline int32_t ESDataSource::AddStream(T& stream,
722  ElementaryStreamListener* listener) {
723  typedef ElementaryStreamTraits<T> Traits;
724  static_assert(Traits::kType != ElementaryStreamType_Unknown,
725  "Invalid stream type.");
726  return AddStream(Traits::kType, stream, listener);
727 }
728 
729 } // namespace NaClPlayer
730 } // namespace Samsung
731 
732 #endif // NACL_PLAYER_ES_DATA_SOURCE_H_
VideoFrame_Format
Enum describing video frames formats.
Definition: media_codecs.h:258
Structure describing TrustZone memory reference.
Definition: media_common.h:350
VideoCodec_Type
Enum describing video codecs type.
Definition: media_codecs.h:182
AudioCodec_Type
Enum describing audio codec types.
Definition: media_codecs.h:14
VideoCodec_Profile
Video stream profile.
Definition: media_codecs.h:203
AudioCodec_Profile
Enum describing Audio Codec Profiles.
Definition: media_codecs.h:40
Defines integral size of 2D rectangle.
Definition: common.h:42
int32_t AddStream(const std::function< void(int32_t, const T &)> &callback, ElementaryStreamListener *listener)
virtual ElementaryStreamType GetStreamType() const =0
Retrieves stream type represented by this resource.
SampleFormat
Enum describing Samples format.
Definition: media_codecs.h:63
Structure describing encrypted packet.
Definition: media_common.h:326
Listener for receiving elementary stream related events.
Unknown/Invalid Elementary Stream.
Definition: media_common.h:24
Represents a rational number.
Definition: common.h:94
int32_t SetDRMInitData(const std::string &type, uint32_t init_data_size, const void *init_data, const std::function< void(int32_t)> &callback)
int32_t AppendPacket(const ESPacket &packet, const std::function< void(int32_t)> &callback)
int32_t AppendEncryptedPacket(const ESPacket &packet, const ESPacketEncryptionInfo &encryption_info, const std::function< void(int32_t)> &callback)
double TimeDelta
difference of two timestamps in seconds
Definition: common.h:20
ChannelLayout
Lists the various representations of the ordering of audio channels.
Definition: media_codecs.h:89
int32_t AppendTrustZonePacket(const ESPacket &packet, const TrustZoneReference &handle, const std::function< void(int32_t)> &callback)