Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ | |
| 6 #define MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "media/cast/cast_config.h" | |
| 10 #include "media/cast/transport/cast_transport_config.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class TimeTicks; | |
| 14 } // namespace base | |
| 15 | |
| 16 namespace net { | |
| 17 class IPEndPoint; | |
| 18 } // namespace net | |
| 19 | |
| 20 namespace media { | |
| 21 | |
| 22 class VideoFrame; | |
| 23 | |
| 24 namespace cast { | |
| 25 | |
| 26 class CastEnvironment; | |
| 27 class CastReceiver; | |
| 28 | |
| 29 namespace transport { | |
| 30 class UdpTransport; | |
| 31 } // namespace transport | |
| 32 | |
| 33 // Common base functionality for an in-process Cast receiver. This is meant to | |
| 34 // be subclassed with the OnAudioFrame() and OnVideoFrame() methods implemented, | |
| 35 // so that the implementor can focus on what is to be done with the frames, | |
| 36 // rather than on the boilerplate "glue" code. | |
| 37 class InProcessReceiver : public base::RefCountedThreadSafe<InProcessReceiver> { | |
| 38 public: | |
| 39 // Construct a receiver with the given configuration. |remote_end_point| can | |
| 40 // be left empty, if the transport should automatically mate with the first | |
| 41 // remote sender it encounters. | |
| 42 InProcessReceiver(const scoped_refptr<CastEnvironment>& cast_environment, | |
| 43 const net::IPEndPoint& local_end_point, | |
| 44 const net::IPEndPoint& remote_end_point, | |
| 45 const AudioReceiverConfig& audio_config, | |
| 46 const VideoReceiverConfig& video_config); | |
| 47 | |
| 48 // Convenience accessor to CastEnvironment. | |
| 49 scoped_refptr<CastEnvironment> cast_env() const { return cast_environment_; } | |
| 50 | |
| 51 // Begin delivering any received audio/video frames to the OnXXXFrame() | |
| 52 // methods. | |
| 53 virtual void Start(); | |
| 54 | |
| 55 // Initiate shutdown, non-blocking. Frames may be delivered after this, but | |
| 56 // with the guarantee that the system will eventually shut down. | |
|
hubbe
2014/03/06 19:54:43
This raises some questions about when it is safe t
miu
2014/03/07 22:40:29
Re-worked this as discussed. InProcessReceiver is
| |
| 57 virtual void StopSoon(); | |
| 58 | |
| 59 protected: | |
| 60 virtual ~InProcessReceiver(); | |
| 61 | |
| 62 // To be implemented by subclasses. These are called on the Cast MAIN thread | |
| 63 // as each frame is received. | |
| 64 virtual void OnAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame, | |
| 65 const base::TimeTicks& playout_time) = 0; | |
| 66 virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | |
| 67 const base::TimeTicks& render_time) = 0; | |
| 68 | |
| 69 // Callback for the transport to notify of status changes. A default | |
| 70 // implementation is provided here that simply logs socket errors. | |
| 71 virtual void UpdateCastTransportStatus(transport::CastTransportStatus status); | |
| 72 | |
| 73 private: | |
| 74 friend class base::RefCountedThreadSafe<InProcessReceiver>; | |
| 75 | |
| 76 // Helper method that creates |transport_| and |cast_receiver_|, starts | |
| 77 // |transport_| receiving, and requests the first audio/video frame. | |
| 78 void StartOnMainThread(); | |
| 79 | |
| 80 // Destroys |transport_| and |cast_receiver_|. No further frames will be | |
| 81 // requested after this method returns, although there may be requests still | |
| 82 // in-flight in the task runner queues. | |
| 83 void StopOnMainThread(); | |
| 84 | |
| 85 // CastReceiver callbacks that receive a frame and then request another. | |
| 86 void GotAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame, | |
| 87 const base::TimeTicks& playout_time); | |
| 88 void GotVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | |
| 89 const base::TimeTicks& render_time); | |
| 90 void PullNextAudioFrame(); | |
| 91 void PullNextVideoFrame(); | |
| 92 | |
| 93 const scoped_refptr<CastEnvironment> cast_environment_; | |
| 94 const net::IPEndPoint local_end_point_; | |
| 95 const net::IPEndPoint remote_end_point_; | |
| 96 const AudioReceiverConfig audio_config_; | |
| 97 const VideoReceiverConfig video_config_; | |
| 98 | |
| 99 scoped_ptr<transport::UdpTransport> transport_; | |
| 100 scoped_ptr<CastReceiver> cast_receiver_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(InProcessReceiver); | |
| 103 }; | |
| 104 | |
| 105 } // namespace cast | |
| 106 } // namespace media | |
| 107 | |
| 108 #endif // MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ | |
| OLD | NEW |