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/weak_ptr.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 { | |
| 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 virtual ~InProcessReceiver(); | |
| 48 | |
| 49 // Convenience accessor to CastEnvironment. | |
| 50 CastEnvironment* cast_env() const { return cast_environment_.get(); } | |
|
hubbe
2014/03/04 22:42:26
Maybe return a scoped_refptr?
miu
2014/03/06 06:09:15
Done.
| |
| 51 | |
| 52 // Begin delivering any received audio/video frames to the OnXXXFrame() | |
| 53 // methods. | |
| 54 virtual void Start(); | |
| 55 | |
| 56 // Returns configurations with the most-commonly used values. These specify | |
| 57 // 48 kHz, 2-channel Opus-coded audio, and VP8-coded video. | |
| 58 static AudioReceiverConfig GetDefaultAudioConfig(); | |
|
hubbe
2014/03/04 22:42:26
I don't think these functions belong in this class
miu
2014/03/06 06:09:15
Done. Moved to a test utility module.
| |
| 59 static VideoReceiverConfig GetDefaultVideoConfig(); | |
| 60 | |
| 61 protected: | |
| 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 // Helper method to complete the initialization of components that must be | |
| 75 // constructed on the Cast MAIN thread. | |
| 76 void InitializeOnMainThread(const net::IPEndPoint& local_end_point, | |
| 77 const net::IPEndPoint& remote_end_point, | |
| 78 const AudioReceiverConfig& audio_config, | |
| 79 const VideoReceiverConfig& video_config); | |
| 80 | |
| 81 // Helper method that starts |transport_| receiving and requests the first | |
| 82 // audio/video frame. | |
| 83 void StartOnMainThread(); | |
| 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 int audio_sampling_frequency_; | |
| 95 scoped_ptr<transport::UdpTransport> transport_; | |
| 96 scoped_ptr<CastReceiver> cast_receiver_; | |
| 97 | |
| 98 // For shutdown safety, this member must be last: | |
| 99 base::WeakPtrFactory<InProcessReceiver> weak_factory_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(InProcessReceiver); | |
| 102 }; | |
| 103 | |
| 104 } // namespace cast | |
| 105 } // namespace media | |
| 106 | |
| 107 #endif // MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_ | |
| OLD | NEW |