Native Player  1.0
url_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_URL_PLAYER_URL_PLAYER_CONTROLLER_H_
29 #define NATIVE_PLAYER_INC_PLAYER_URL_PLAYER_URL_PLAYER_CONTROLLER_H_
30 
31 #include <array>
32 #include <string>
33 #include <memory>
34 #include <vector>
35 
36 #include "nacl_player/media_player.h"
37 #include "nacl_player/media_data_source.h"
38 #include "ppapi/cpp/instance.h"
39 #include "ppapi/utility/threading/simple_thread.h"
40 #include "ppapi/utility/completion_callback_factory.h"
41 
45 
46 #include "common.h"
47 
49 
75 
77  public:
92  explicit UrlPlayerController(const pp::InstanceHandle& instance,
93  std::shared_ptr<Communication::MessageSender> message_sender)
94  : PlayerController(),
95  instance_(instance),
96  cc_factory_(this),
97  subtitles_visible_(true),
98  message_sender_(std::move(message_sender)),
99  state_(PlayerState::kUnitialized) {}
100 
104 
118  void InitPlayer(const std::string& url, const std::string& subtitle = {},
119  const std::string& encoding = {});
120 
121  void Play() override;
122  void Pause() override;
123  void Seek(Samsung::NaClPlayer::TimeTicks to_time) override;
124  void ChangeRepresentation(StreamType stream_type, int32_t id) override;
125  void SetViewRect(const Samsung::NaClPlayer::Rect& view_rect) override;
126  void PostTextTrackInfo() override;
127  void ChangeSubtitles(int32_t id) override;
128  void ChangeSubtitleVisibility() override;
129  PlayerState GetState() override;
130 
131  private:
138  void InitializeUrlPlayer(const std::string& content_container_url);
139 
140  void OnSetDisplayRect(int32_t /*result*/);
141 
142  void OnSeek(int32_t /*result*/);
143 
144  void OnChangeSubtitles(int32_t /*result*/, int32_t id);
145 
146  void OnChangeSubVisibility(int32_t /*result*/, bool show);
147 
148  void CleanPlayer();
149 
150  pp::InstanceHandle instance_;
151  std::unique_ptr<pp::SimpleThread> player_thread_;
152  pp::CompletionCallbackFactory<UrlPlayerController> cc_factory_;
153 
154  PlayerListeners listeners_;
155 
156  std::shared_ptr<Samsung::NaClPlayer::MediaDataSource> data_source_;
157  std::shared_ptr<Samsung::NaClPlayer::MediaPlayer> player_;
158  std::unique_ptr<Samsung::NaClPlayer::TextTrackInfo> text_track_;
159  std::vector<Samsung::NaClPlayer::TextTrackInfo> text_track_list_;
160  bool subtitles_visible_;
161 
162  std::shared_ptr<Communication::MessageSender> message_sender_;
163 
164  PlayerState state_;
165  Samsung::NaClPlayer::Rect view_rect_;
166 };
167 
168 #endif // NATIVE_PLAYER_INC_PLAYER_URL_PLAYER_URL_PLAYER_CONTROLLER_H_
StreamType
Definition: common.h:55
void PostTextTrackInfo() override
UrlPlayerController(const pp::InstanceHandle &instance, std::shared_ptr< Communication::MessageSender > message_sender)
It is a definition of the player controlling interface.
This file defines the PlayerController class.
void ChangeRepresentation(StreamType stream_type, int32_t id) override
This class controls NaCl Player in the playback from the URL scenario.
It aggregates implementation of all basic listeners required by NaClPlayer.
void InitPlayer(const std::string &url, const std::string &subtitle={}, const std::string &encoding={})
void Seek(Samsung::NaClPlayer::TimeTicks to_time) override
void Play() override
Orders the player to start/resume playback of the loaded content.
void SetViewRect(const Samsung::NaClPlayer::Rect &view_rect) override
void ChangeSubtitles(int32_t id) override
void ChangeSubtitleVisibility() override
Orders the player to start or stop generating events related to subtitles.
void InitializeUrlPlayer(const std::string &content_container_url)
This file defines a MessageSender class.
PlayerState GetState() override
void Pause() override
Orders the player to pause playback of the content.