Shaka Player Embedded
player.h
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_PLAYER_H_
16 #define SHAKA_EMBEDDED_PLAYER_H_
17 
18 #include <math.h>
19 
20 #include <memory>
21 #include <string>
22 #include <type_traits>
23 #include <vector>
24 
25 #include "async_results.h"
26 #include "error.h"
27 #include "js_manager.h"
28 #include "macros.h"
29 #include "manifest.h"
30 #include "media/media_player.h"
31 #include "net.h"
32 #include "player_externs.h"
33 #include "stats.h"
34 #include "track.h"
35 
36 namespace shaka {
37 
39 struct DefaultValueType final {};
40 
46 
53 class SHAKA_EXPORT Player final {
54  public:
59  class Client {
60  public:
62 
67  virtual void OnError(const Error& error);
68 
73  virtual void OnBuffering(bool is_buffering);
74  };
75 
80  Player(JsManager* engine);
81  Player(Player&&);
82  ~Player();
83 
84  Player& operator=(Player&&);
85 
87 
88 
89  enum class LogLevel : uint8_t {
90  // These have the same values as shaka.log.Level.
91  None = 0,
92  Error = 1,
93  Warning = 2,
94  Info = 3,
95  Debug = 4,
96  V1 = 5,
97  V2 = 6,
98  };
99 
107  static AsyncResults<void> SetLogLevel(JsManager* engine, LogLevel level);
108 
115  static AsyncResults<LogLevel> GetLogLevel(JsManager* engine);
116 
123  static AsyncResults<std::string> GetPlayerVersion(JsManager* engine);
124 
125 
136  AsyncResults<void> Initialize(Client* client,
137  media::MediaPlayer* player = nullptr);
138 
144  AsyncResults<void> Destroy();
145 
146 
148  AsyncResults<bool> IsAudioOnly() const;
149 
151  AsyncResults<bool> IsBuffering() const;
152 
154  AsyncResults<bool> IsInProgress() const;
155 
157  AsyncResults<bool> IsLive() const;
158 
160  AsyncResults<bool> IsTextTrackVisible() const;
161 
163  AsyncResults<bool> UsingEmbeddedTextTrack() const;
164 
165 
167  AsyncResults<optional<std::string>> AssetUri() const;
168 
174 
179  AsyncResults<std::vector<LanguageRole>> GetAudioLanguagesAndRoles() const;
180 
182  AsyncResults<BufferedInfo> GetBufferedInfo() const;
183 
188  AsyncResults<double> GetExpiration() const;
189 
191  AsyncResults<Stats> GetStats() const;
192 
198  AsyncResults<std::vector<Track>> GetTextTracks() const;
199 
205  AsyncResults<std::vector<Track>> GetVariantTracks() const;
206 
211  AsyncResults<std::vector<LanguageRole>> GetTextLanguagesAndRoles() const;
212 
217  AsyncResults<std::string> KeySystem() const;
218 
220  AsyncResults<BufferedRange> SeekRange() const;
221 
222 
233  AsyncResults<void> Load(const std::string& manifest_uri,
234  double start_time = NAN,
235  const std::string& mime_type = "");
236 
238  AsyncResults<void> Unload();
239 
241 
252  AsyncResults<bool> Configure(const std::string& name_path, DefaultValueType);
253  AsyncResults<bool> Configure(const std::string& name_path, bool value);
254  AsyncResults<bool> Configure(const std::string& name_path, double value);
255  AsyncResults<bool> Configure(const std::string& name_path,
256  const std::string& value);
257  template <typename T, typename = typename std::enable_if<
258  std::is_arithmetic<T>::value>::type>
259  AsyncResults<bool> Configure(const std::string& name_path, T value) {
260  // Since there are both bool and double overloads, any other number type
261  // will cause an ambiguous call. This disambiguates the calls.
262  return Configure(name_path, static_cast<double>(value));
263  }
264  AsyncResults<bool> Configure(const std::string& name_path,
265  const char* value) {
266  // For some reason, the compiler tries to use the bool overload over the
267  // std::string one when passing a char pointer.
268  return Configure(name_path, std::string(value));
269  }
271 
272 
274  AsyncResults<void> ResetConfiguration();
275 
279  AsyncResults<void> RetryStreaming();
280 
285  AsyncResults<void> SelectAudioLanguage(const std::string& language,
287 
292  AsyncResults<void> SelectEmbeddedTextTrack();
293 
298  AsyncResults<void> SelectTextLanguage(const std::string& language,
300 
301 
306  AsyncResults<void> SelectTextTrack(const Track& track);
307 
312  AsyncResults<void> SelectVariantTrack(const Track& track,
313  bool clear_buffer = false);
314 
320  AsyncResults<void> SetTextTrackVisibility(bool visibility);
321 
322 
324 
338  AsyncResults<bool> GetConfigurationBool(const std::string& name_path);
339  AsyncResults<double> GetConfigurationDouble(const std::string& name_path);
340  AsyncResults<std::string> GetConfigurationString(
341  const std::string& name_path);
343 
351  AsyncResults<Track> AddTextTrack(const std::string& uri,
352  const std::string& language,
353  const std::string& kind,
354  const std::string& mime,
355  const std::string& codec = "",
356  const std::string& label = "");
357 
364  AsyncResults<void> Attach(media::MediaPlayer* player);
365 
371  AsyncResults<void> Detach();
372 
373  /*
374  * Adds an object that is called when network requests happen. These are
375  * called in the order they are registered.
376  * @param filters The object that receives the calls.
377  */
378  void AddNetworkFilters(NetworkFilters* filters);
379 
381  void RemoveNetworkFilters(NetworkFilters* filters);
382 
384 
387  AsyncResults<bool> Configure(const std::string& name_path,
388  const std::vector<uint8_t>& data) {
389  return Configure(name_path, data.data(), data.size());
390  }
391  AsyncResults<bool> Configure(const std::string& name_path,
392  const uint8_t* data, size_t data_size);
394 
395  private:
396  friend class Storage;
397  void* GetRawJsValue();
398 
399  class Impl;
400  std::unique_ptr<Impl> impl_;
401 };
402 
403 } // namespace shaka
404 
405 #endif // SHAKA_EMBEDDED_PLAYER_H_
#define SHAKA_EXPORT
Definition: macros.h:30
AsyncResults< bool > Configure(const std::string &name_path, const std::vector< uint8_t > &data)
Definition: player.h:387
const nullopt_t nullopt
Definition: optional.cc:22
ExceptionCode type
AsyncResults< bool > Configure(const std::string &name_path, const char *value)
Definition: player.h:264
#define SHAKA_NON_COPYABLE_TYPE(Type)
Definition: macros.h:43
#define SHAKA_DECLARE_INTERFACE_METHODS(Type)
Definition: macros.h:55
AsyncResults< bool > Configure(const std::string &name_path, T value)
Definition: player.h:259
const DefaultValueType DefaultValue