Native Player  1.0
stream_demuxer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 //
3 // Copyright (c) 2016, Samsung Electronics Co., Ltd
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
20 // , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 //
23 // @author Jacob Tarasiewicz
24 //
25 // ----------------------------------------------------------------------------
26 
27 #ifndef SRC_PLAYER_ES_DASH_PLAYER_DEMUXER_STREAM_DEMUXER_H_
28 #define SRC_PLAYER_ES_DASH_PLAYER_DEMUXER_STREAM_DEMUXER_H_
29 
30 #include <functional>
31 #include <string>
32 #include <vector>
33 
34 #include "ppapi/c/pp_stdint.h"
35 #include "ppapi/cpp/instance.h"
36 #include "nacl_player/common.h"
37 #include "nacl_player/media_common.h"
38 #include "nacl_player/media_codecs.h"
39 
44 
49 struct AudioConfig {
52  Samsung::NaClPlayer::AudioCodec_Type codec_type;
53 
57  Samsung::NaClPlayer::AudioCodec_Profile codec_profile;
58 
61  Samsung::NaClPlayer::SampleFormat sample_format;
62 
65  Samsung::NaClPlayer::ChannelLayout channel_layout;
66 
71 
74 
77  std::vector<uint8_t> extra_data;
78 
82  bool operator==(const AudioConfig& config) const {
83  return ((bits_per_channel == config.bits_per_channel) &&
84  (channel_layout == config.channel_layout) &&
85  (codec_profile == config.codec_profile) &&
86  (codec_type == config.codec_type) &&
87  (extra_data == config.extra_data) &&
88  (sample_format == config.sample_format) &&
89  (samples_per_second == config.samples_per_second));
90  }
91 };
92 
97 struct VideoConfig {
100  Samsung::NaClPlayer::VideoCodec_Type codec_type;
101 
105  Samsung::NaClPlayer::VideoCodec_Profile codec_profile;
106 
109  Samsung::NaClPlayer::VideoFrame_Format frame_format;
110 
114  Samsung::NaClPlayer::Size size;
115 
119  Samsung::NaClPlayer::Rational frame_rate;
120 
123  std::vector<uint8_t> extra_data;
124 
128  bool operator==(const VideoConfig& config) const {
129  return ((codec_profile == config.codec_profile) &&
130  (codec_type == config.codec_type) &&
131  (extra_data == config.extra_data) &&
132  (frame_format == config.frame_format));
133  }
134 };
135 
145  public:
149  enum Type { kUnknown = -1, kAudio = 0, kVideo = 1 };
150 
156  enum Message {
157  kError = -1,
158  kInitialized = 0,
159  kFlushed = 1,
160  kClosed = 2,
162  kAudioPkt = 4,
163  kVideoPkt = 5,
164  };
165 
173  static std::unique_ptr<StreamDemuxer> Create(
174  const pp::InstanceHandle& instance, Type type);
175 
178 
180  virtual ~StreamDemuxer() {}
181 
193  virtual bool Init(
194  const std::function<
195  void(Message, std::unique_ptr<ElementaryStreamPacket>)>& callback,
196  pp::MessageLoop callback_dispatcher) = 0;
197 
201  virtual void Flush() = 0;
202 
211  virtual void Parse(const std::vector<uint8_t>& data) = 0;
212 
221  virtual bool SetAudioConfigListener(
222  const std::function<void(const AudioConfig&)>& callback) = 0;
223 
233  virtual bool SetVideoConfigListener(
234  const std::function<void(const VideoConfig&)>& callback) = 0;
235 
243  virtual bool SetDRMInitDataListener(const std::function<
244  void(const std::string& type, const std::vector<uint8_t>& init_data)>&
245  callback) = 0;
246 
249  virtual void SetTimestamp(Samsung::NaClPlayer::TimeTicks) = 0;
250 
253  virtual void Close() = 0;
254 };
255 
256 #endif // NATIVE_PLAYER_SRC_DEMUXER_STREAM_DEMUXER_H_
This file defines the ElementaryStreamPacket.
Structure describing Elementary Audio Stream configuration.
virtual ~StreamDemuxer()
Destroys StreamDemuxer object.
const Samsung::NaClPlayer::TimeTicks kEndOfStream
Definition: common.h:61
An interface for demuxing modules. This interface provides methods used to parse data of media contai...
Samsung::NaClPlayer::AudioCodec_Profile codec_profile
Samsung::NaClPlayer::VideoCodec_Profile codec_profile
Samsung::NaClPlayer::VideoCodec_Type codec_type
Samsung::NaClPlayer::VideoFrame_Format frame_format
Samsung::NaClPlayer::Size size
int32_t bits_per_channel
Samsung::NaClPlayer::AudioCodec_Type codec_type
Samsung::NaClPlayer::Rational frame_rate
Structure describing Elementary Video Stream configuration.
std::vector< uint8_t > extra_data
bool operator==(const AudioConfig &config) const
Samsung::NaClPlayer::SampleFormat sample_format
bool operator==(const VideoConfig &config) const
int32_t samples_per_second
Describes audio samples per second in [Hz] like 44100, 22050, etc.
Samsung::NaClPlayer::ChannelLayout channel_layout
StreamDemuxer()
Constructs an empty StreamDemuxer.
std::vector< uint8_t > extra_data