Index: chrome/browser/media/router/media_controller.h |
diff --git a/chrome/browser/media/router/media_controller.h b/chrome/browser/media/router/media_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0515e19838d1a607d92eeda32092c575b543cafc |
--- /dev/null |
+++ b/chrome/browser/media/router/media_controller.h |
@@ -0,0 +1,139 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_CONTROLLER_H_ |
+#define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_CONTROLLER_H_ |
+ |
+#include "base/observer_list.h" |
+#include "base/values.h" |
+#include "chrome/browser/media/router/media_route_id.h" |
+ |
+namespace media_router { |
+ |
+// A summary of the current status of the media playing on a route that can be |
+// rendered for the user in the browser. |
+class MediaStatus { |
mark a. foltz
2015/02/27 05:48:10
This entire file is based on the assumption that t
Kevin M
2015/02/27 18:42:17
Done.
|
+ public: |
+ explicit MediaStatus(const MediaRouteId& media_route_id) : |
+ media_route_id_(media_route_id) {} |
+ |
+ ~MediaStatus() {} |
+ |
+ // The media route identifier. |
+ MediaRouteId media_route_id() const { return media_route_id_; } |
+ |
+ bool operator==(const MediaStatus& other) const { |
+ return media_route_id_ == other.media_route_id_; |
+ } |
+ |
+ bool operator!=(const MediaStatus& other) const { |
+ return !(*this == other); |
+ } |
+ |
+ // TODO(mfoltz): Fill in. |
+ |
+ private: |
+ MediaRouteId media_route_id_; |
+}; |
+ |
+// Possible media commands that may or may not be supported by a media route. |
+// The sink selection dialog should know how to render these. A bitfield is |
+// used to represent the commands enabled for a route so the values must be |
+// powers of two. |
+// |
+// NOTE: In the future, add commands like ENQUEUE, DEQUEUE, etc. if we want to |
+// control queueing functionality from the browser (or an app). |
+enum MediaCommand { |
+ MEDIA_COMMAND_PAUSE = 1, |
+ MEDIA_COMMAND_PLAY = 1 << 1, |
+ MEDIA_COMMAND_RESUME = 1 << 2, |
+ MEDIA_COMMAND_STOP = 1 << 3, |
+ MEDIA_COMMAND_NEXT = 1 << 4, |
+ MEDIA_COMMAND_PREVIOUS = 1 << 5, |
+ MEDIA_COMMAND_SEEK_ABSOLUTE = 1 << 6, |
+ MEDIA_COMMAND_SEEK_RELATIVE = 1 << 7, |
+ MEDIA_COMMAND_VOLUME_UP = 1 << 8, |
+ MEDIA_COMMAND_VOLUME_DOWN = 1 << 9, |
+ MEDIA_COMMAND_VOLUME_MUTE = 1 << 10, |
+ MEDIA_COMMAND_VOLUME_UNMUTE = 1 << 11 |
+}; |
+ |
+// Bitwise-OR of different MediaCommands. |
+typedef uint64 MediaControlsCapabilities; |
+ |
+// Allows the browser to control media associated with a media route. |
+// - Is this 1:1 with a MediaRoute or do we allow multiple controllers? |
+// - The MediaController will need a way to forward commands to the relevant |
+// MRP. Most likely, there will be a Delegate interface whose implementation |
+// will be provided by the MR. |
+class MediaController { |
+ public: |
+ explicit MediaController(const MediaRouteId& media_route_id); |
+ virtual ~MediaController(); |
+ |
+ // Interface for clients that wish to be notified of changes to media status |
+ // or the set of media controls. |
+ class Observer { |
+ public: |
+ // Called when the status of media playing on the route has changed. |
+ // |current_status| contains the last reported status for the route. |
+ virtual void OnMediaStatusChange( |
+ const MediaController* controller, |
+ const MediaStatus& current_status) = 0; |
+ // Called when the set of supported media controls for the route has |
+ // changed. |current_media_commands| contains the last reported media |
+ // controls for the route. |
+ virtual void OnMediaControlsCapabilitiesChange( |
+ const MediaController* controller, |
+ MediaControlsCapabilities current_capabilities) = 0; |
+ }; |
+ void AddObserver(MediaController::Observer* observer); |
+ void RemoveObserver(MediaController::Observer* observer); |
+ |
+ // The id of the media route being controlled. |
+ MediaRouteId media_route_id() const { return media_route_id_; } |
+ |
+ // Sends the media command to the MRP to control the media on the designated |
+ // route. TODO: Return an error code for client side errors, e.g. unsupported |
+ // command, route is closed, etc. |
+ virtual void Pause() = 0; |
+ virtual void Resume() = 0; |
+ virtual void Play() = 0; |
+ virtual void Stop() = 0; |
+ virtual void Next() = 0; |
+ virtual void Previous() = 0; |
+ // Seeks the media to a position relative to the current play position. |
+ // |seek_seconds| may be positive (to seek forward in the stream) or negative |
+ // (to seek backward). |
+ virtual void SeekRelative(double seek_seconds) = 0; |
+ // Seeks the media to an absolute position in the stream. |seek_seconds| must |
+ // be non-negative. Seeking to a position beyond the duration of the stream |
+ // is an error. |
+ virtual void SeekAbsolute(double seek_seconds) = 0; |
+ virtual void VolumeUp() = 0; |
+ virtual void VolumeDown() = 0; |
+ virtual void Mute() = 0; |
+ virtual void Unmute() = 0; |
+ |
+ // Returns true if the controller supports |command|, false otherwise. |
+ bool SupportsCommand(MediaCommand command) const; |
+ |
+ // Sets the new MediaStatus. This will notify the observers. |
+ void set_media_status(const MediaStatus& status); |
+ // Sets the new set of control capabilities. This will notify the observers. |
+ void set_media_controls_capabilities(MediaControlsCapabilities capabilities); |
+ |
+ // Maybe add a way for the browser to request media status. |
+ // Or cache the last known status here. |
+ private: |
+ MediaRouteId media_route_id_; |
+ MediaControlsCapabilities media_controls_capabilities_; |
+ MediaStatus media_status_; |
+ |
+ ObserverList<MediaController::Observer> observers_; |
+}; |
+ |
+} // namespace media_router |
+ |
+#endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_CONTROLLER_H_ |