OLD | NEW |
---|---|
(Empty) | |
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_REMOTING_REMOTING_SOURCE_IMPL_H_ | |
6 #define MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/threading/thread_checker.h" | |
11 #include "media/mojo/interfaces/remoting.mojom.h" | |
12 #include "mojo/public/cpp/bindings/binding.h" | |
13 | |
14 namespace media { | |
15 | |
16 enum RemotingSessionState { | |
17 // Remoting sink is not available. Can't start remoting. | |
18 SESSION_UNAVAILABLE, | |
19 // Remoting sink is available, Can start remoting. | |
20 SESSION_CAN_START, | |
21 // Starting a remoting session. | |
22 SESSION_STARTING, | |
xhwang
2016/11/01 08:21:29
if "starting a remoting session" failed, what stat
xjz
2016/11/01 21:55:54
It could be either SESSION_UNAVAILABLE, or SESSION
| |
23 // Remoting session is successively started. | |
24 SESSION_STARTED, | |
25 // Stopping the session. | |
26 SESSION_STOPPING, | |
xhwang
2016/11/01 08:21:30
Can we get back to STARTED after STOPPING?
More g
xjz
2016/11/01 21:55:53
Done.
| |
27 // Remoting session is permanently stopped. This state indicates that the | |
28 // video stack cannot continue operation. For example, if a remoting session | |
29 // involving CDM content was stopped, there is no way to continue playback | |
30 // because the CDM is required but is no longer available. | |
31 SESSION_PERMANENTLY_STOPPED, | |
32 }; | |
33 | |
34 // Maintains a single remoting session for multiple clients. The session will | |
35 // start remoting when receiving the first request. Once remoting is started, | |
36 // it will be stopped when any of the following happens: | |
37 // 1) Receives the request from any client to stop remoting. | |
38 // 2) Remote sink is gone. | |
39 // 3) Any client requests to permanently terminate the session. | |
40 // 4) All clients are destroyed. | |
41 // | |
42 // This class is ref-counted because, in some cases, an instance will have | |
43 // shared ownership between RemotingRendererController and | |
44 // RemotingCdmController. | |
45 class RemotingSourceImpl final | |
46 : public mojom::RemotingSource, | |
47 public base::RefCountedThreadSafe<RemotingSourceImpl> { | |
48 public: | |
49 class Client { | |
50 public: | |
51 // Get notified whether the remoting session is successively started. | |
52 virtual void OnStarted(bool success) = 0; | |
53 // Get notified when session state changes. | |
54 virtual void OnSessionStateChanged() = 0; | |
55 }; | |
56 | |
57 RemotingSourceImpl(mojom::RemotingSourceRequest source_request, | |
58 mojom::RemoterPtr remoter); | |
59 | |
60 // Get the current session state. | |
61 RemotingSessionState state() const { | |
62 DCHECK(thread_checker_.CalledOnValidThread()); | |
63 return state_; | |
64 } | |
65 | |
66 // RemotingSource implementations. | |
67 void OnSinkAvailable() override; | |
68 void OnSinkGone() override; | |
69 void OnStarted() override; | |
70 void OnStartFailed(mojom::RemotingStartFailReason reason) override; | |
71 void OnMessageFromSink(const std::vector<uint8_t>& message) override; | |
72 void OnStopped(mojom::RemotingStopReason reason) override; | |
73 | |
74 // Requests to start remoting. Will try start a remoting session if not | |
75 // started yet. |client| will get informed whether the session is | |
76 // successifully started throught OnStarted(). | |
77 void StartRemoting(Client* client); | |
78 | |
79 // Requests to stop the current remoting session if started. When the session | |
80 // is stopping, all clients will get notified. | |
81 void StopRemoting(Client* client); | |
82 | |
83 // Permanently terminates the current remoting session. | |
84 void Shutdown(); | |
85 | |
86 // Add/remove a client to/from |clients_|. | |
87 // Remoting session will be stopped if all clients are gone. | |
88 void AddClient(Client* client); | |
xhwang
2016/11/01 08:21:29
It's odd that a Client can be added here, but is a
xhwang
2016/11/01 08:21:29
Who owns the |client|? Maybe worth commenting that
xjz
2016/11/01 21:55:53
This class doesn't own the clients. Added comment.
xjz
2016/11/01 21:55:53
Clients can only be added/removed through the Add/
xhwang
2016/11/02 06:47:05
This is not documented (and is a bit confusing)...
xjz
2016/11/02 17:38:11
Added comments. In StopRemoting() case, |client| i
| |
89 void RemoveClient(Client* client); | |
90 | |
91 private: | |
92 friend class base::RefCountedThreadSafe<RemotingSourceImpl>; | |
93 ~RemotingSourceImpl() override; | |
94 | |
95 // Updates the current session state and notifies all the clients if state | |
96 // changes. | |
97 void UpdateAndNotifyState(RemotingSessionState state); | |
98 | |
99 const mojo::Binding<mojom::RemotingSource> binding_; | |
100 const mojom::RemoterPtr remoter_; | |
101 | |
102 // The current state. | |
103 RemotingSessionState state_ = RemotingSessionState::SESSION_UNAVAILABLE; | |
104 | |
105 // Clients are added/removed to/from this list by calling Add/RemoveClient(). | |
106 std::vector<Client*> clients_; | |
107 | |
108 // This is used to check all the methods are called on the current thread in | |
109 // debug builds. | |
110 base::ThreadChecker thread_checker_; | |
111 }; | |
112 | |
113 } // namespace media | |
114 | |
115 #endif // MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_ | |
OLD | NEW |