Chromium Code Reviews| 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 <set> | |
| 9 | |
| 10 #include "media/mojo/interfaces/remoting.mojom.h" | |
| 11 #include "mojo/public/cpp/bindings/binding.h" | |
| 12 | |
| 13 namespace base { | |
|
miu
2016/10/25 04:21:27
Please remove this forward declaration and instead
xjz
2016/10/26 22:00:27
Done.
| |
| 14 class ThreadChecker; | |
| 15 } | |
| 16 | |
| 17 namespace media { | |
| 18 | |
| 19 enum RemotingSessionState { | |
| 20 // Remoting sink is not available. Can't start remoting. | |
| 21 SESSION_UNAVAILABLE, | |
| 22 // Remoting sink is available, Can start remoting. | |
| 23 SESSION_CAN_START, | |
| 24 // Starting a remoting session. | |
| 25 SESSION_STARTING, | |
| 26 // Remoting session is successively started. | |
| 27 SESSION_STARTED, | |
| 28 // Stopping the session. | |
| 29 SESSION_STOPPING, | |
| 30 // Remoting session is permanently stopped. This state indicates that the | |
| 31 // video stack cannot continue operation. For example, if a remoting session | |
| 32 // involving CDM content was stopped, there is no way to continue playback | |
| 33 // because the CDM is required but is no longer available. | |
| 34 SESSION_PERMANENTLY_STOPPED, | |
| 35 }; | |
| 36 | |
| 37 // Maintains a single remoting session for multiple clients. The session will | |
| 38 // start remoting when receiving the first request. Once remoting is started, | |
| 39 // it will be stopped when any of the following happens: | |
| 40 // 1) Receives the request from any client to stop remoting. | |
| 41 // 2) Remote sink is gone. | |
| 42 // 3) Any client requests to permanently terminated the session. | |
|
miu
2016/10/25 04:21:27
s/terminated/terminate/
xjz
2016/10/26 22:00:27
Done.
| |
| 43 // 4) All clients are destroyed. | |
| 44 class RemotingSourceImpl final | |
|
miu
2016/10/25 04:21:27
Another helpful thing to add to the class-level co
xjz
2016/10/26 22:00:27
Done.
| |
| 45 : public mojom::RemotingSource, | |
| 46 public base::RefCountedThreadSafe<RemotingSourceImpl> { | |
| 47 public: | |
| 48 RemotingSourceImpl(mojom::RemotingSourceRequest source_request, | |
| 49 mojom::RemoterPtr remoter); | |
| 50 | |
| 51 class Client { | |
|
miu
2016/10/25 04:21:27
style nit: Type declarations have to go at the top
xjz
2016/10/26 22:00:27
Done.
| |
| 52 public: | |
| 53 // Get notified whether the remoting session is successively started. | |
| 54 virtual void OnStarted(bool success) = 0; | |
| 55 // Get notified when session state changes. | |
| 56 virtual void OnSessionStateChanged() = 0; | |
| 57 }; | |
| 58 | |
| 59 // Get the current session state. | |
| 60 RemotingSessionState state() const { | |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 62 return state_; | |
| 63 } | |
| 64 | |
| 65 // RemotingSource implementations. | |
| 66 void OnSinkAvailable() override; | |
| 67 void OnSinkGone() override; | |
| 68 void OnStarted() override; | |
| 69 void OnStartFailed(mojom::RemotingStartFailReason reason) override; | |
| 70 void OnMessageFromSink(const std::vector<uint8_t>& message) override; | |
| 71 void OnStopped(mojom::RemotingStopReason reason) override; | |
| 72 | |
| 73 // Requests to start remoting. Will try start a remoting session if not | |
| 74 // started yet. |client| will get informed whether the session is | |
| 75 // successifully started throught OnStarted(). | |
| 76 void StartRemoting(Client* client); | |
| 77 | |
| 78 // Requests to stop the current remoting session if started. When the session | |
| 79 // is stopping, all clients will get notified. | |
| 80 void StopRemoting(Client* client); | |
| 81 | |
| 82 // Permanently terminates the current remoting session. | |
| 83 void ShutDown(); | |
| 84 | |
| 85 // Add/remove a client to/from |clients_|. | |
| 86 // Remoting session will be stopped if all clients are gone. | |
| 87 void AddClient(Client* client); | |
| 88 void RemoveClient(Client* client); | |
| 89 | |
| 90 private: | |
| 91 friend class base::RefCountedThreadSafe<RemotingSourceImpl>; | |
| 92 ~RemotingSourceImpl() override; | |
| 93 | |
| 94 // Updates the current session state and notifies all the clients if state | |
| 95 // changes. | |
| 96 void UpdateAndNotifyState(RemotingSessionState state); | |
| 97 | |
| 98 mojo::Binding<mojom::RemotingSource> binding_; | |
| 99 mojom::RemoterPtr remoter_; | |
|
miu
2016/10/25 04:21:27
const please
xjz
2016/10/26 22:00:27
Done.
| |
| 100 | |
| 101 // The current state. | |
| 102 RemotingSessionState state_ = RemotingSessionState::SESSION_UNAVAILABLE; | |
| 103 | |
| 104 // This is set to true when OnSinkAvailable() is called, and is reset when | |
| 105 // sink is gone. | |
| 106 bool is_sink_available_ = false; | |
|
miu
2016/10/25 04:21:27
You can remove this boolean. See comments in .cc f
xjz
2016/10/26 22:00:27
Done.
| |
| 107 | |
| 108 // Clients are added/removed to/from this list by calling Add/RemoveClient(). | |
| 109 std::set<Client*> clients_; | |
|
miu
2016/10/25 04:21:27
Use std::vector<Client*> instead (saves memory and
xjz
2016/10/26 22:00:27
Done.
| |
| 110 | |
| 111 // This is used to check all the methods are called on the current thread in | |
| 112 // debug builds. | |
| 113 base::ThreadChecker thread_checker_; | |
| 114 }; | |
| 115 | |
| 116 } // namespace media | |
| 117 | |
| 118 #endif // MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_ | |
| OLD | NEW |