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

Side by Side Diff: media/remoting/remoting_source_impl.h

Issue 2457563002: Media Remoting: Add remoting control logic for encrypted contents. (Closed)
Patch Set: Rebase Only. Created 4 years, 1 month 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 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,
23 // Remoting session is successively started.
24 SESSION_STARTED,
25 // Stopping the session.
26 SESSION_STOPPING,
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);
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698