Shaka Player Embedded
media_player.h
Go to the documentation of this file.
1 // Copyright 2019 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_MEDIA_MEDIA_PLAYER_H_
16 #define SHAKA_EMBEDDED_MEDIA_MEDIA_PLAYER_H_
17 
18 #include <iostream>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "../eme/implementation.h"
24 #include "../macros.h"
25 #include "../utils.h"
26 #include "media_capabilities.h"
27 #include "media_track.h"
28 #include "streams.h"
29 #include "text_track.h"
30 
31 namespace shaka {
32 namespace media {
33 
48 enum class VideoReadyState : int8_t {
55  NotAttached = -1,
56 
58  HaveNothing = 0,
59 
61  HaveMetadata = 1,
62 
64  HaveCurrentData = 2,
65 
70  HaveFutureData = 3,
71 
77  HaveEnoughData = 4,
78 };
79 
80 std::string to_string(VideoReadyState state);
81 inline std::ostream& operator<<(std::ostream& os, VideoReadyState state) {
82  return os << to_string(state);
83 }
84 
91 enum class VideoPlaybackState : uint8_t {
93  Detached,
94 
97 
101  Paused,
102 
107  Seeking,
108 
113  Buffering,
114 
120 
122  Playing,
123 
129  Ended,
130 
135  Errored,
136 };
137 
138 std::string to_string(VideoPlaybackState state);
139 inline std::ostream& operator<<(std::ostream& os, VideoPlaybackState state) {
140  return os << to_string(state);
141 }
142 
150 
153 
156 };
157 
158 
185  public:
195  public:
197 
202  virtual void OnAddAudioTrack(std::shared_ptr<MediaTrack> track);
203 
208  virtual void OnRemoveAudioTrack(std::shared_ptr<MediaTrack> track);
209 
214  virtual void OnAddVideoTrack(std::shared_ptr<MediaTrack> track);
215 
220  virtual void OnRemoveVideoTrack(std::shared_ptr<MediaTrack> track);
221 
229  virtual void OnAddTextTrack(std::shared_ptr<TextTrack> track);
230 
235  virtual void OnRemoveTextTrack(std::shared_ptr<TextTrack> track);
236 
237 
239  virtual void OnReadyStateChanged(VideoReadyState old_state,
240  VideoReadyState new_state);
241 
243  virtual void OnPlaybackStateChanged(VideoPlaybackState old_state,
244  VideoPlaybackState new_state);
245 
247  virtual void OnPlaybackRateChanged(double old_rate, double new_rate);
248 
253  virtual void OnError(const std::string& error);
254 
260  virtual void OnAttachMse();
261 
266  virtual void OnAttachSource();
267 
269  virtual void OnDetach();
270 
271 
277  virtual void OnPlay();
278 
283  virtual void OnSeeking();
284 
290  virtual void OnWaitingForKey();
291 
292 
307  virtual void OnUserEvent(const std::string& name, void* user_data);
308  };
309 
311  class SHAKA_EXPORT ClientList final : public Client {
312  public:
313  ClientList();
314  ~ClientList() override;
315 
316  void AddClient(Client* client);
317  void RemoveClient(Client* client);
318 
319  void OnAddAudioTrack(std::shared_ptr<MediaTrack> track) override;
320  void OnRemoveAudioTrack(std::shared_ptr<MediaTrack> track) override;
321  void OnAddVideoTrack(std::shared_ptr<MediaTrack> track) override;
322  void OnRemoveVideoTrack(std::shared_ptr<MediaTrack> track) override;
323  void OnAddTextTrack(std::shared_ptr<TextTrack> track) override;
324  void OnRemoveTextTrack(std::shared_ptr<TextTrack> track) override;
325  void OnReadyStateChanged(VideoReadyState old_state,
326  VideoReadyState new_state) override;
327  void OnPlaybackStateChanged(VideoPlaybackState old_state,
328  VideoPlaybackState new_state) override;
329  void OnPlaybackRateChanged(double old_rate, double new_rate) override;
330  void OnError(const std::string& error) override;
331  void OnAttachMse() override;
332  void OnAttachSource() override;
333  void OnDetach() override;
334  void OnPlay() override;
335  void OnSeeking() override;
336  void OnWaitingForKey() override;
337 
338  void OnUserEvent(const std::string& name, void* user_data) override;
339 
340  private:
341  class Impl;
342  std::unique_ptr<Impl> impl_;
343  };
344 
346 
363  static void SetMediaPlayerForSupportChecks(const MediaPlayer* player);
364 
366  static const MediaPlayer* GetMediaPlayerForSupportChecks();
367 
368 
385  virtual MediaCapabilitiesInfo DecodingInfo(
386  const MediaDecodingConfiguration& config) const = 0;
387 
389  virtual VideoPlaybackQuality VideoPlaybackQuality() const = 0;
390 
396  virtual void AddClient(Client* client) const = 0;
397 
402  virtual void RemoveClient(Client* client) const = 0;
403 
409  virtual std::vector<BufferedRange> GetBuffered() const = 0;
410 
412  virtual VideoReadyState ReadyState() const = 0;
413 
415  virtual VideoPlaybackState PlaybackState() const = 0;
416 
418  virtual std::vector<std::shared_ptr<MediaTrack>> AudioTracks() = 0;
419 
421  virtual std::vector<std::shared_ptr<const MediaTrack>> AudioTracks()
422  const = 0;
423 
425  virtual std::vector<std::shared_ptr<MediaTrack>> VideoTracks() = 0;
426 
428  virtual std::vector<std::shared_ptr<const MediaTrack>> VideoTracks()
429  const = 0;
430 
432  virtual std::vector<std::shared_ptr<TextTrack>> TextTracks() = 0;
433 
435  virtual std::vector<std::shared_ptr<const TextTrack>> TextTracks() const = 0;
436 
446  virtual std::shared_ptr<TextTrack> AddTextTrack(
447  TextTrackKind kind, const std::string& label,
448  const std::string& language) = 0;
449 
450 
458  virtual bool SetVideoFillMode(VideoFillMode mode) = 0;
459 
461  virtual uint32_t Width() const = 0;
462 
464  virtual uint32_t Height() const = 0;
465 
467  virtual double Volume() const = 0;
468 
470  virtual void SetVolume(double volume) = 0;
471 
473  virtual bool Muted() const = 0;
474 
476  virtual void SetMuted(bool muted) = 0;
478 
479 
486  virtual void Play() = 0;
487 
493  virtual void Pause() = 0;
494 
496  virtual double CurrentTime() const = 0;
497 
504  virtual void SetCurrentTime(double time) = 0;
505 
507  virtual double Duration() const = 0;
508 
513  virtual void SetDuration(double duration) = 0;
514 
518  virtual double PlaybackRate() const = 0;
519 
524  virtual void SetPlaybackRate(double rate) = 0;
526 
527 
540  virtual bool AttachSource(const std::string& src) = 0;
541 
548  virtual bool AttachMse() = 0;
549 
562  virtual bool AddMseBuffer(const std::string& mime, bool is_video,
563  const ElementaryStream* stream) = 0;
564 
574  virtual void LoadedMetaData(double duration) = 0;
575 
580  virtual void MseEndOfStream() = 0;
581 
591  virtual bool SetEmeImplementation(const std::string& key_system,
592  eme::Implementation* implementation) = 0;
593 
598  virtual void Detach() = 0;
600 };
601 
602 } // namespace media
603 } // namespace shaka
604 
605 #endif // SHAKA_EMBEDDED_MEDIA_MEDIA_PLAYER_H_
#define SHAKA_EXPORT
Definition: macros.h:30
VideoFillMode
Definition: utils.h:41
const char * name
std::ostream & operator<<(std::ostream &os, PixelFormat format)
Definition: frames.cc:22
std::string to_string(VideoReadyState state)
Definition: media_player.cc:32
#define SHAKA_DECLARE_INTERFACE_METHODS(Type)
Definition: macros.h:55