OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ | 5 #ifndef MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ |
6 #define MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ | 6 #define MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
13 #include "media/cast/cast_config.h" | 14 #include "media/cast/cast_config.h" |
14 #include "media/cast/net/cast_transport.h" | 15 #include "media/cast/net/cast_transport.h" |
15 #include "media/cast/net/cast_transport_config.h" | 16 #include "media/cast/net/cast_transport_config.h" |
16 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 class TimeTicks; | 20 class TimeTicks; |
20 class WaitableEvent; | 21 class WaitableEvent; |
(...skipping 20 matching lines...) Expand all Loading... |
41 // rather than on the boilerplate "glue" code. | 42 // rather than on the boilerplate "glue" code. |
42 class InProcessReceiver { | 43 class InProcessReceiver { |
43 public: | 44 public: |
44 class TransportClient : public CastTransport::Client { | 45 class TransportClient : public CastTransport::Client { |
45 public: | 46 public: |
46 explicit TransportClient(InProcessReceiver* in_process_receiver) | 47 explicit TransportClient(InProcessReceiver* in_process_receiver) |
47 : in_process_receiver_(in_process_receiver) {} | 48 : in_process_receiver_(in_process_receiver) {} |
48 | 49 |
49 void OnStatusChanged(CastTransportStatus status) final; | 50 void OnStatusChanged(CastTransportStatus status) final; |
50 void OnLoggingEventsReceived( | 51 void OnLoggingEventsReceived( |
51 scoped_ptr<std::vector<FrameEvent>> frame_events, | 52 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
52 scoped_ptr<std::vector<PacketEvent>> packet_events) final {} | 53 std::unique_ptr<std::vector<PacketEvent>> packet_events) final {} |
53 void ProcessRtpPacket(scoped_ptr<Packet> packet) final; | 54 void ProcessRtpPacket(std::unique_ptr<Packet> packet) final; |
54 | 55 |
55 private: | 56 private: |
56 InProcessReceiver* in_process_receiver_; | 57 InProcessReceiver* in_process_receiver_; |
57 | 58 |
58 DISALLOW_COPY_AND_ASSIGN(TransportClient); | 59 DISALLOW_COPY_AND_ASSIGN(TransportClient); |
59 }; | 60 }; |
60 | 61 |
61 // Construct a receiver with the given configuration. |remote_end_point| can | 62 // Construct a receiver with the given configuration. |remote_end_point| can |
62 // be left empty, if the transport should automatically mate with the first | 63 // be left empty, if the transport should automatically mate with the first |
63 // remote sender it encounters. | 64 // remote sender it encounters. |
(...skipping 14 matching lines...) Expand all Loading... |
78 // methods. | 79 // methods. |
79 virtual void Start(); | 80 virtual void Start(); |
80 | 81 |
81 // Destroy the sub-compontents of this class. | 82 // Destroy the sub-compontents of this class. |
82 // After this call, it is safe to destroy this object on any thread. | 83 // After this call, it is safe to destroy this object on any thread. |
83 virtual void Stop(); | 84 virtual void Stop(); |
84 | 85 |
85 protected: | 86 protected: |
86 // To be implemented by subclasses. These are called on the Cast MAIN thread | 87 // To be implemented by subclasses. These are called on the Cast MAIN thread |
87 // as each frame is received. | 88 // as each frame is received. |
88 virtual void OnAudioFrame(scoped_ptr<AudioBus> audio_frame, | 89 virtual void OnAudioFrame(std::unique_ptr<AudioBus> audio_frame, |
89 const base::TimeTicks& playout_time, | 90 const base::TimeTicks& playout_time, |
90 bool is_continuous) = 0; | 91 bool is_continuous) = 0; |
91 virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | 92 virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, |
92 const base::TimeTicks& playout_time, | 93 const base::TimeTicks& playout_time, |
93 bool is_continuous) = 0; | 94 bool is_continuous) = 0; |
94 | 95 |
95 // Helper method that creates |transport_| and |cast_receiver_|, starts | 96 // Helper method that creates |transport_| and |cast_receiver_|, starts |
96 // |transport_| receiving, and requests the first audio/video frame. | 97 // |transport_| receiving, and requests the first audio/video frame. |
97 // Subclasses may final to provide additional start-up functionality. | 98 // Subclasses may final to provide additional start-up functionality. |
98 virtual void StartOnMainThread(); | 99 virtual void StartOnMainThread(); |
99 | 100 |
100 // Helper method that destroys |transport_| and |cast_receiver_|. | 101 // Helper method that destroys |transport_| and |cast_receiver_|. |
101 // Subclasses may final to provide additional start-up functionality. | 102 // Subclasses may final to provide additional start-up functionality. |
102 virtual void StopOnMainThread(base::WaitableEvent* event); | 103 virtual void StopOnMainThread(base::WaitableEvent* event); |
103 | 104 |
104 // Callback for the transport to notify of status changes. A default | 105 // Callback for the transport to notify of status changes. A default |
105 // implementation is provided here that simply logs socket errors. | 106 // implementation is provided here that simply logs socket errors. |
106 virtual void UpdateCastTransportStatus(CastTransportStatus status); | 107 virtual void UpdateCastTransportStatus(CastTransportStatus status); |
107 | 108 |
108 private: | 109 private: |
109 friend class base::RefCountedThreadSafe<InProcessReceiver>; | 110 friend class base::RefCountedThreadSafe<InProcessReceiver>; |
110 | 111 |
111 // CastReceiver callbacks that receive a frame and then request another. See | 112 // CastReceiver callbacks that receive a frame and then request another. See |
112 // comments for the callbacks defined in src/media/cast/cast_receiver.h for | 113 // comments for the callbacks defined in src/media/cast/cast_receiver.h for |
113 // argument description and semantics. | 114 // argument description and semantics. |
114 void GotAudioFrame(scoped_ptr<AudioBus> audio_frame, | 115 void GotAudioFrame(std::unique_ptr<AudioBus> audio_frame, |
115 const base::TimeTicks& playout_time, | 116 const base::TimeTicks& playout_time, |
116 bool is_continuous); | 117 bool is_continuous); |
117 void GotVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | 118 void GotVideoFrame(const scoped_refptr<VideoFrame>& video_frame, |
118 const base::TimeTicks& playout_time, | 119 const base::TimeTicks& playout_time, |
119 bool is_continuous); | 120 bool is_continuous); |
120 void PullNextAudioFrame(); | 121 void PullNextAudioFrame(); |
121 void PullNextVideoFrame(); | 122 void PullNextVideoFrame(); |
122 | 123 |
123 void ReceivePacket(scoped_ptr<Packet> packet); | 124 void ReceivePacket(std::unique_ptr<Packet> packet); |
124 | 125 |
125 const scoped_refptr<CastEnvironment> cast_environment_; | 126 const scoped_refptr<CastEnvironment> cast_environment_; |
126 const net::IPEndPoint local_end_point_; | 127 const net::IPEndPoint local_end_point_; |
127 const net::IPEndPoint remote_end_point_; | 128 const net::IPEndPoint remote_end_point_; |
128 const FrameReceiverConfig audio_config_; | 129 const FrameReceiverConfig audio_config_; |
129 const FrameReceiverConfig video_config_; | 130 const FrameReceiverConfig video_config_; |
130 | 131 |
131 scoped_ptr<CastTransport> transport_; | 132 std::unique_ptr<CastTransport> transport_; |
132 scoped_ptr<CastReceiver> cast_receiver_; | 133 std::unique_ptr<CastReceiver> cast_receiver_; |
133 | 134 |
134 // NOTE: Weak pointers must be invalidated before all other member variables. | 135 // NOTE: Weak pointers must be invalidated before all other member variables. |
135 base::WeakPtrFactory<InProcessReceiver> weak_factory_; | 136 base::WeakPtrFactory<InProcessReceiver> weak_factory_; |
136 | 137 |
137 DISALLOW_COPY_AND_ASSIGN(InProcessReceiver); | 138 DISALLOW_COPY_AND_ASSIGN(InProcessReceiver); |
138 }; | 139 }; |
139 | 140 |
140 } // namespace cast | 141 } // namespace cast |
141 } // namespace media | 142 } // namespace media |
142 | 143 |
143 #endif // MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ | 144 #endif // MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ |
OLD | NEW |