Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/media/router/media_controller.h

Issue 949293004: Add media router common classes and unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chunkier CL Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 CHROME_BROWSER_MEDIA_ROUTER_MEDIA_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_CONTROLLER_H_
7
8 #include "base/observer_list.h"
9 #include "base/values.h"
10 #include "chrome/browser/media/router/media_route_id.h"
11
12 namespace media_router {
13
14 // A summary of the current status of the media playing on a route that can be
15 // rendered for the user in the browser.
16 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.
17 public:
18 explicit MediaStatus(const MediaRouteId& media_route_id) :
19 media_route_id_(media_route_id) {}
20
21 ~MediaStatus() {}
22
23 // The media route identifier.
24 MediaRouteId media_route_id() const { return media_route_id_; }
25
26 bool operator==(const MediaStatus& other) const {
27 return media_route_id_ == other.media_route_id_;
28 }
29
30 bool operator!=(const MediaStatus& other) const {
31 return !(*this == other);
32 }
33
34 // TODO(mfoltz): Fill in.
35
36 private:
37 MediaRouteId media_route_id_;
38 };
39
40 // Possible media commands that may or may not be supported by a media route.
41 // The sink selection dialog should know how to render these. A bitfield is
42 // used to represent the commands enabled for a route so the values must be
43 // powers of two.
44 //
45 // NOTE: In the future, add commands like ENQUEUE, DEQUEUE, etc. if we want to
46 // control queueing functionality from the browser (or an app).
47 enum MediaCommand {
48 MEDIA_COMMAND_PAUSE = 1,
49 MEDIA_COMMAND_PLAY = 1 << 1,
50 MEDIA_COMMAND_RESUME = 1 << 2,
51 MEDIA_COMMAND_STOP = 1 << 3,
52 MEDIA_COMMAND_NEXT = 1 << 4,
53 MEDIA_COMMAND_PREVIOUS = 1 << 5,
54 MEDIA_COMMAND_SEEK_ABSOLUTE = 1 << 6,
55 MEDIA_COMMAND_SEEK_RELATIVE = 1 << 7,
56 MEDIA_COMMAND_VOLUME_UP = 1 << 8,
57 MEDIA_COMMAND_VOLUME_DOWN = 1 << 9,
58 MEDIA_COMMAND_VOLUME_MUTE = 1 << 10,
59 MEDIA_COMMAND_VOLUME_UNMUTE = 1 << 11
60 };
61
62 // Bitwise-OR of different MediaCommands.
63 typedef uint64 MediaControlsCapabilities;
64
65 // Allows the browser to control media associated with a media route.
66 // - Is this 1:1 with a MediaRoute or do we allow multiple controllers?
67 // - The MediaController will need a way to forward commands to the relevant
68 // MRP. Most likely, there will be a Delegate interface whose implementation
69 // will be provided by the MR.
70 class MediaController {
71 public:
72 explicit MediaController(const MediaRouteId& media_route_id);
73 virtual ~MediaController();
74
75 // Interface for clients that wish to be notified of changes to media status
76 // or the set of media controls.
77 class Observer {
78 public:
79 // Called when the status of media playing on the route has changed.
80 // |current_status| contains the last reported status for the route.
81 virtual void OnMediaStatusChange(
82 const MediaController* controller,
83 const MediaStatus& current_status) = 0;
84 // Called when the set of supported media controls for the route has
85 // changed. |current_media_commands| contains the last reported media
86 // controls for the route.
87 virtual void OnMediaControlsCapabilitiesChange(
88 const MediaController* controller,
89 MediaControlsCapabilities current_capabilities) = 0;
90 };
91 void AddObserver(MediaController::Observer* observer);
92 void RemoveObserver(MediaController::Observer* observer);
93
94 // The id of the media route being controlled.
95 MediaRouteId media_route_id() const { return media_route_id_; }
96
97 // Sends the media command to the MRP to control the media on the designated
98 // route. TODO: Return an error code for client side errors, e.g. unsupported
99 // command, route is closed, etc.
100 virtual void Pause() = 0;
101 virtual void Resume() = 0;
102 virtual void Play() = 0;
103 virtual void Stop() = 0;
104 virtual void Next() = 0;
105 virtual void Previous() = 0;
106 // Seeks the media to a position relative to the current play position.
107 // |seek_seconds| may be positive (to seek forward in the stream) or negative
108 // (to seek backward).
109 virtual void SeekRelative(double seek_seconds) = 0;
110 // Seeks the media to an absolute position in the stream. |seek_seconds| must
111 // be non-negative. Seeking to a position beyond the duration of the stream
112 // is an error.
113 virtual void SeekAbsolute(double seek_seconds) = 0;
114 virtual void VolumeUp() = 0;
115 virtual void VolumeDown() = 0;
116 virtual void Mute() = 0;
117 virtual void Unmute() = 0;
118
119 // Returns true if the controller supports |command|, false otherwise.
120 bool SupportsCommand(MediaCommand command) const;
121
122 // Sets the new MediaStatus. This will notify the observers.
123 void set_media_status(const MediaStatus& status);
124 // Sets the new set of control capabilities. This will notify the observers.
125 void set_media_controls_capabilities(MediaControlsCapabilities capabilities);
126
127 // Maybe add a way for the browser to request media status.
128 // Or cache the last known status here.
129 private:
130 MediaRouteId media_route_id_;
131 MediaControlsCapabilities media_controls_capabilities_;
132 MediaStatus media_status_;
133
134 ObserverList<MediaController::Observer> observers_;
135 };
136
137 } // namespace media_router
138
139 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698