1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_BASE_MEDIA_OBSERVER_H_ 6 #define MEDIA_BASE_MEDIA_OBSERVER_H_ 7 8 #include "media/base/pipeline_metadata.h" 9 #include "url/gurl.h" 10 11 namespace media { 12 13 class MEDIA_EXPORT MediaObserverClient { 14 public: 15 // Reasons to switch to local renderer from using remote renderer. 16 enum class ReasonToSwitchToLocal { 17 NORMAL, // Remoting is disabled or media no longer occupies the viewport. 18 POOR_PLAYBACK_QUALITY, // Playback quality is poor. 19 PIPELINE_ERROR, // Error occurred. 20 ROUTE_TERMINATED, // No longer show the media on remote screen. 21 }; 22 ~MediaObserverClient()23 virtual ~MediaObserverClient() {} 24 25 // Requests to restart the media pipeline and create a new renderer as soon as 26 // possible. When switching to remote renderer, all the optimizations that 27 // might suspend the media pipeline should be disabled. 28 // |remote_device_friendly_name| can be empty if the remote device is unknown. 29 virtual void SwitchToRemoteRenderer( 30 const std::string& remote_device_friendly_name) = 0; 31 32 // Requests to switch to local renderer. According to |reason|, a text message 33 // may be displayed to explain why the switch occurred. 34 virtual void SwitchToLocalRenderer(ReasonToSwitchToLocal reason) = 0; 35 36 // Reports the latest compatibility state of the element's source for remote 37 // playback. 38 virtual void UpdateRemotePlaybackCompatibility(bool is_compatible) = 0; 39 40 // Gets the number of video frames decoded so far from the media pipeline. 41 // All the counts keep increasing and will not be reset during seek. 42 virtual unsigned DecodedFrameCount() const = 0; 43 44 // Gets the media duration in seconds. Returns 45 // |std::numeric_limits<double>::infinity()| for an infinite stream duration. 46 // TODO(xjz): Use base::TimeDelta for media duration (crbug.com/773911). 47 virtual double Duration() const = 0; 48 }; 49 50 // This class is an observer of media player events. 51 class MEDIA_EXPORT MediaObserver { 52 public: 53 MediaObserver(); 54 virtual ~MediaObserver(); 55 56 // Called when the media element starts/stops being the dominant visible 57 // content. OnBecameDominantVisibleContent(bool is_dominant)58 virtual void OnBecameDominantVisibleContent(bool is_dominant) {} 59 60 // Called after demuxer is initialized. 61 virtual void OnMetadataChanged(const PipelineMetadata& metadata) = 0; 62 63 // Called to indicate whether the site requests that remote playback be 64 // disabled. The "disabled" naming corresponds with the 65 // "disableRemotePlayback" media element attribute, as described in the 66 // Remote Playback API spec: https://w3c.github.io/remote-playback 67 virtual void OnRemotePlaybackDisabled(bool disabled) = 0; 68 69 // Called on Android, whenever we detect that we are playing back HLS. 70 virtual void OnHlsManifestDetected() = 0; 71 72 // Called when the media is playing/paused. 73 virtual void OnPlaying() = 0; 74 virtual void OnPaused() = 0; 75 76 // Called when the data source is asynchronously initialized. 77 virtual void OnDataSourceInitialized(const GURL& url_after_redirects) = 0; 78 79 // Set the MediaObserverClient. May be called with nullptr to disconnect the 80 // the client from the observer. 81 virtual void SetClient(MediaObserverClient* client) = 0; 82 }; 83 84 } // namespace media 85 86 #endif // MEDIA_BASE_MEDIA_OBSERVER_H_ 87