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

Unified Diff: media/remoting/remoting_source_impl.h

Issue 2406483002: WIP - Add EME (Closed)
Patch Set: Rebase. Split RemotingSourceImpl. Addressed comments. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: media/remoting/remoting_source_impl.h
diff --git a/media/remoting/remoting_source_impl.h b/media/remoting/remoting_source_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..e2ec5e82443299932f2d279ef895a5f88f110830
--- /dev/null
+++ b/media/remoting/remoting_source_impl.h
@@ -0,0 +1,118 @@
+// Copyright 2016 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 MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_
+#define MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_
+
+#include <set>
+
+#include "media/mojo/interfaces/remoting.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace base {
miu 2016/10/25 04:21:27 Please remove this forward declaration and instead
xjz 2016/10/26 22:00:27 Done.
+class ThreadChecker;
+}
+
+namespace media {
+
+enum RemotingSessionState {
+ // Remoting sink is not available. Can't start remoting.
+ SESSION_UNAVAILABLE,
+ // Remoting sink is available, Can start remoting.
+ SESSION_CAN_START,
+ // Starting a remoting session.
+ SESSION_STARTING,
+ // Remoting session is successively started.
+ SESSION_STARTED,
+ // Stopping the session.
+ SESSION_STOPPING,
+ // Remoting session is permanently stopped. This state indicates that the
+ // video stack cannot continue operation. For example, if a remoting session
+ // involving CDM content was stopped, there is no way to continue playback
+ // because the CDM is required but is no longer available.
+ SESSION_PERMANENTLY_STOPPED,
+};
+
+// Maintains a single remoting session for multiple clients. The session will
+// start remoting when receiving the first request. Once remoting is started,
+// it will be stopped when any of the following happens:
+// 1) Receives the request from any client to stop remoting.
+// 2) Remote sink is gone.
+// 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.
+// 4) All clients are destroyed.
+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.
+ : public mojom::RemotingSource,
+ public base::RefCountedThreadSafe<RemotingSourceImpl> {
+ public:
+ RemotingSourceImpl(mojom::RemotingSourceRequest source_request,
+ mojom::RemoterPtr remoter);
+
+ 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.
+ public:
+ // Get notified whether the remoting session is successively started.
+ virtual void OnStarted(bool success) = 0;
+ // Get notified when session state changes.
+ virtual void OnSessionStateChanged() = 0;
+ };
+
+ // Get the current session state.
+ RemotingSessionState state() const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return state_;
+ }
+
+ // RemotingSource implementations.
+ void OnSinkAvailable() override;
+ void OnSinkGone() override;
+ void OnStarted() override;
+ void OnStartFailed(mojom::RemotingStartFailReason reason) override;
+ void OnMessageFromSink(const std::vector<uint8_t>& message) override;
+ void OnStopped(mojom::RemotingStopReason reason) override;
+
+ // Requests to start remoting. Will try start a remoting session if not
+ // started yet. |client| will get informed whether the session is
+ // successifully started throught OnStarted().
+ void StartRemoting(Client* client);
+
+ // Requests to stop the current remoting session if started. When the session
+ // is stopping, all clients will get notified.
+ void StopRemoting(Client* client);
+
+ // Permanently terminates the current remoting session.
+ void ShutDown();
+
+ // Add/remove a client to/from |clients_|.
+ // Remoting session will be stopped if all clients are gone.
+ void AddClient(Client* client);
+ void RemoveClient(Client* client);
+
+ private:
+ friend class base::RefCountedThreadSafe<RemotingSourceImpl>;
+ ~RemotingSourceImpl() override;
+
+ // Updates the current session state and notifies all the clients if state
+ // changes.
+ void UpdateAndNotifyState(RemotingSessionState state);
+
+ mojo::Binding<mojom::RemotingSource> binding_;
+ mojom::RemoterPtr remoter_;
miu 2016/10/25 04:21:27 const please
xjz 2016/10/26 22:00:27 Done.
+
+ // The current state.
+ RemotingSessionState state_ = RemotingSessionState::SESSION_UNAVAILABLE;
+
+ // This is set to true when OnSinkAvailable() is called, and is reset when
+ // sink is gone.
+ 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.
+
+ // Clients are added/removed to/from this list by calling Add/RemoveClient().
+ 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.
+
+ // This is used to check all the methods are called on the current thread in
+ // debug builds.
+ base::ThreadChecker thread_checker_;
+};
+
+} // namespace media
+
+#endif // MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698