Native Player  1.0
es_dash_player_controller.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 Tomasz Borkowski
24 // Michal Murgrabia
25 //
26 // ----------------------------------------------------------------------------
27 
28 #ifndef NATIVE_PLAYER_INC_PLAYER_ES_DASH_PLAYER_ES_DASH_PLAYER_CONTROLLER_H_
29 #define NATIVE_PLAYER_INC_PLAYER_ES_DASH_PLAYER_ES_DASH_PLAYER_CONTROLLER_H_
30 
31 #include <array>
32 #include <memory>
33 #include <string>
34 #include <vector>
35 
36 #include "nacl_player/es_data_source.h"
37 #include "nacl_player/media_data_source.h"
38 #include "nacl_player/media_player.h"
39 #include "ppapi/cpp/instance.h"
40 #include "ppapi/utility/completion_callback_factory.h"
41 #include "ppapi/utility/threading/simple_thread.h"
42 
43 #include "common.h"
44 #include "dash/dash_manifest.h"
49 
52 
82 
84  public std::enable_shared_from_this<PlayerController> {
85  public:
99  EsDashPlayerController(const pp::InstanceHandle& instance,
100  std::shared_ptr<Communication::MessageSender> message_sender)
101  : PlayerController(),
102  instance_(instance),
103  cc_factory_(this),
104  subtitles_visible_(true),
105  message_sender_(message_sender),
106  state_(PlayerState::kUnitialized) {}
107 
110  ~EsDashPlayerController() override {};
111 
132  void InitPlayer(const std::string& url, const std::string& subtitle = {},
133  const std::string& encoding = {});
134 
135  // Overloaded methods defined by PlayerController, don't have to be commented
136  void Play() override;
137  void Pause() override;
138  void Seek(Samsung::NaClPlayer::TimeTicks to_time) override;
139  void ChangeRepresentation(StreamType stream_type, int32_t id) override;
140  void SetViewRect(const Samsung::NaClPlayer::Rect& view_rect) override;
141  void PostTextTrackInfo() override;
142  void ChangeSubtitles(int32_t id) override;
143  void ChangeSubtitleVisibility() override;
144  PlayerState GetState() override;
145 
146  private:
155  void UpdateStreamsBuffer(int32_t /*result*/);
156 
164  void OnStreamConfigured(StreamType type);
165 
169 
170  void OnChangeRepresentation(int32_t /*result*/, StreamType type, int32_t id);
171 
180  void InitializeSubtitles(const std::string& subtitle,
181  const std::string& encoding);
182 
189  void InitializeDash(const std::string& mpd_file_path);
190 
195  void InitializeStreams(int32_t);
196 
197  void InitializeVideoStream(Samsung::NaClPlayer::DRMType /*drm_type*/);
198 
199  void InitializeAudioStream(Samsung::NaClPlayer::DRMType /*drm_type*/);
200 
201  void OnSetDisplayRect(int32_t /*result*/);
202 
203  void OnSeek(int32_t /*result*/);
204 
205  void OnChangeSubtitles(int32_t /*result*/, int32_t id);
206 
207  void OnChangeSubVisibility(int32_t /*result*/, bool show);
208 
209  void CleanPlayer();
210 
211  pp::InstanceHandle instance_;
212  std::unique_ptr<pp::SimpleThread> player_thread_;
213  pp::CompletionCallbackFactory<EsDashPlayerController> cc_factory_;
214 
215  PlayerListeners listeners_;
216 
217  std::shared_ptr<Samsung::NaClPlayer::ESDataSource> data_source_;
218  std::shared_ptr<Samsung::NaClPlayer::MediaPlayer> player_;
219  std::unique_ptr<Samsung::NaClPlayer::TextTrackInfo> text_track_;
220  std::vector<Samsung::NaClPlayer::TextTrackInfo> text_track_list_;
221  bool subtitles_visible_;
222 
223  std::shared_ptr<Communication::MessageSender> message_sender_;
224 
225  PlayerState state_;
226  Samsung::NaClPlayer::Rect view_rect_;
227 
228  std::unique_ptr<DashManifest> dash_parser_;
229  std::array<std::shared_ptr<StreamManager>,
230  static_cast<int32_t>(StreamType::MaxStreamTypes)> streams_;
231  std::vector<VideoStream> video_representations_;
232  std::vector<AudioStream> audio_representations_;
233 };
234 
235 #endif // NATIVE_PLAYER_INC_PLAYER_ES_DASH_PLAYER_ES_DASH_PLAYER_CONTROLLER_H_
StreamType
Definition: common.h:55
void ChangeRepresentation(StreamType stream_type, int32_t id) override
It is a definition of the player controlling interface.
This file defines the PlayerController class.
void OnStreamConfigured(StreamType type)
This file defines the StreamManager class.
It aggregates implementation of all basic listeners required by NaClPlayer.
This class controls NaCl Player in the elementary stream playback scenario with DASH support...
void InitializeDash(const std::string &mpd_file_path)
void Play() override
Orders the player to start/resume playback of the loaded content.
void ChangeSubtitles(int32_t id) override
void InitializeStreams(int32_t)
void Pause() override
Orders the player to pause playback of the content.
void UpdateStreamsBuffer(int32_t)
EsDashPlayerController(const pp::InstanceHandle &instance, std::shared_ptr< Communication::MessageSender > message_sender)
PlayerState GetState() override
This file defines DashManifest class.
void PostTextTrackInfo() override
void InitializeSubtitles(const std::string &subtitle, const std::string &encoding)
This file defines a MessageSender class.
void ChangeSubtitleVisibility() override
Orders the player to start or stop generating events related to subtitles.
void SetViewRect(const Samsung::NaClPlayer::Rect &view_rect) override
void InitPlayer(const std::string &url, const std::string &subtitle={}, const std::string &encoding={})
void Seek(Samsung::NaClPlayer::TimeTicks to_time) override