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.
5 // This is the main interface for the cast sender.
7 // The AudioFrameInput, VideoFrameInput and PacketReciever interfaces should
8 // be accessed from the main thread.
10 #ifndef MEDIA_CAST_CAST_SENDER_H_
11 #define MEDIA_CAST_CAST_SENDER_H_
13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/time/tick_clock.h"
18 #include "base/time/time.h"
19 #include "media/base/audio_bus.h"
20 #include "media/cast/cast_config.h"
21 #include "media/cast/cast_environment.h"
22 #include "media/cast/net/cast_transport_sender.h"
31 class VideoFrameInput
: public base::RefCountedThreadSafe
<VideoFrameInput
> {
33 // Insert video frames into Cast sender. Frames will be encoded, packetized
34 // and sent to the network.
35 virtual void InsertRawVideoFrame(
36 const scoped_refptr
<media::VideoFrame
>& video_frame
,
37 const base::TimeTicks
& capture_time
) = 0;
39 // Creates a |VideoFrame| optimized for the encoder. When available, these
40 // frames offer performance benefits, such as memory copy elimination. The
41 // format is guaranteed to be I420 or NV12.
43 // Not every encoder supports this method. Use |ShouldCreateOptimizedFrame|
44 // to determine if you can and should use this method. Calling
45 // this method when |ShouldCreateOptimizedFrame| is false will CHECK.
46 virtual scoped_refptr
<VideoFrame
> CreateOptimizedFrame(
47 base::TimeDelta timestamp
) = 0;
49 // Returns true if the encoder supports creating optimized frames.
50 virtual bool SupportsCreateOptimizedFrame() const = 0;
53 virtual ~VideoFrameInput() {}
56 friend class base::RefCountedThreadSafe
<VideoFrameInput
>;
59 class AudioFrameInput
: public base::RefCountedThreadSafe
<AudioFrameInput
> {
61 // Insert audio frames into Cast sender. Frames will be encoded, packetized
62 // and sent to the network.
63 virtual void InsertAudio(scoped_ptr
<AudioBus
> audio_bus
,
64 const base::TimeTicks
& recorded_time
) = 0;
67 virtual ~AudioFrameInput() {}
70 friend class base::RefCountedThreadSafe
<AudioFrameInput
>;
73 // All methods of CastSender must be called on the main thread.
74 // Provided CastTransportSender will also be called on the main thread.
77 static scoped_ptr
<CastSender
> Create(
78 scoped_refptr
<CastEnvironment
> cast_environment
,
79 CastTransportSender
* const transport_sender
);
81 virtual ~CastSender() {}
83 // All video frames for the session should be inserted to this object.
84 virtual scoped_refptr
<VideoFrameInput
> video_frame_input() = 0;
86 // All audio frames for the session should be inserted to this object.
87 virtual scoped_refptr
<AudioFrameInput
> audio_frame_input() = 0;
89 // Initialize the audio stack. Must be called in order to send audio frames.
90 // Status of the initialization will be returned on cast_initialization_cb.
91 virtual void InitializeAudio(
92 const AudioSenderConfig
& audio_config
,
93 const CastInitializationCallback
& cast_initialization_cb
) = 0;
95 // Initialize the video stack. Must be called in order to send video frames.
96 // Status of the initialization will be returned on cast_initialization_cb.
97 virtual void InitializeVideo(
98 const VideoSenderConfig
& video_config
,
99 const CastInitializationCallback
& cast_initialization_cb
,
100 const CreateVideoEncodeAcceleratorCallback
& create_vea_cb
,
101 const CreateVideoEncodeMemoryCallback
& create_video_encode_mem_cb
) = 0;
103 // Change the target delay. This is only valid if the receiver
104 // supports the "adaptive_target_delay" rtp extension.
105 virtual void SetTargetPlayoutDelay(
106 base::TimeDelta new_target_playout_delay
) = 0;
112 #endif // MEDIA_CAST_CAST_SENDER_H_