1 // Copyright 2013 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 // This is the main interface for the cast sender. All configuration are done 6 // at creation. 7 // 8 // The FrameInput and PacketReciever interfaces should normally be accessed from 9 // the IO thread. However they are allowed to be called from any thread. 10 11 #ifndef MEDIA_CAST_CAST_SENDER_H_ 12 #define MEDIA_CAST_CAST_SENDER_H_ 13 14 #include "base/basictypes.h" 15 #include "base/callback.h" 16 #include "base/memory/ref_counted.h" 17 #include "base/time/tick_clock.h" 18 #include "base/time/time.h" 19 #include "media/cast/cast_config.h" 20 #include "media/cast/cast_environment.h" 21 22 namespace media { 23 class AudioBus; 24 class VideoFrame; 25 } 26 27 namespace media { 28 namespace cast { 29 30 // This Class is thread safe. 31 class FrameInput : public base::RefCountedThreadSafe<FrameInput> { 32 public: 33 // The video_frame must be valid until the callback is called. 34 // The callback is called from the main cast thread as soon as 35 // the encoder is done with the frame; it does not mean that the encoded frame 36 // has been sent out. 37 virtual void InsertRawVideoFrame( 38 const scoped_refptr<media::VideoFrame>& video_frame, 39 const base::TimeTicks& capture_time) = 0; 40 41 // The video_frame must be valid until the callback is called. 42 // The callback is called from the main cast thread as soon as 43 // the cast sender is done with the frame; it does not mean that the encoded 44 // frame has been sent out. 45 virtual void InsertCodedVideoFrame(const EncodedVideoFrame* video_frame, 46 const base::TimeTicks& capture_time, 47 const base::Closure callback) = 0; 48 49 // The |audio_bus| must be valid until the |done_callback| is called. 50 // The callback is called from the main cast thread as soon as the encoder is 51 // done with |audio_bus|; it does not mean that the encoded data has been 52 // sent out. 53 virtual void InsertAudio(const AudioBus* audio_bus, 54 const base::TimeTicks& recorded_time, 55 const base::Closure& done_callback) = 0; 56 57 // The audio_frame must be valid until the callback is called. 58 // The callback is called from the main cast thread as soon as 59 // the cast sender is done with the frame; it does not mean that the encoded 60 // frame has been sent out. 61 virtual void InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame, 62 const base::TimeTicks& recorded_time, 63 const base::Closure callback) = 0; 64 65 protected: 66 virtual ~FrameInput() {} 67 68 private: 69 friend class base::RefCountedThreadSafe<FrameInput>; 70 }; 71 72 // This Class is thread safe. 73 // The provided PacketSender object will always be called form the main cast 74 // thread. 75 class CastSender { 76 public: 77 static CastSender* CreateCastSender( 78 scoped_refptr<CastEnvironment> cast_environment, 79 const AudioSenderConfig& audio_config, 80 const VideoSenderConfig& video_config, 81 VideoEncoderController* const video_encoder_controller, 82 PacketSender* const packet_sender); 83 84 virtual ~CastSender() {} 85 86 // All audio and video frames for the session should be inserted to this 87 // object. 88 // Can be called from any thread. 89 virtual scoped_refptr<FrameInput> frame_input() = 0; 90 91 // All RTCP packets for the session should be inserted to this object. 92 // Can be called from any thread. 93 virtual scoped_refptr<PacketReceiver> packet_receiver() = 0; 94 }; 95 96 } // namespace cast 97 } // namespace media 98 99 #endif // MEDIA_CAST_CAST_SENDER_H_ 100