Move UpdateManifest test from unit_tests into extensions_unittests.
[chromium-blink-merge.git] / media / cast / cast_sender.h
blob7c6891312b48132f90627b929d1beb5780ec2dd1
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.
6 //
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"
24 namespace gfx {
25 class Size;
28 namespace media {
29 class VideoFrame;
31 namespace cast {
32 class AudioSender;
33 class VideoSender;
35 class VideoFrameInput : public base::RefCountedThreadSafe<VideoFrameInput> {
36 public:
37 // Insert video frames into Cast sender. Frames will be encoded, packetized
38 // and sent to the network.
39 virtual void InsertRawVideoFrame(
40 const scoped_refptr<media::VideoFrame>& video_frame,
41 const base::TimeTicks& capture_time) = 0;
43 // Creates a |VideoFrame| optimized for the encoder. When available, these
44 // frames offer performance benefits, such as memory copy elimination. The
45 // format is guaranteed to be I420 or NV12.
47 // Not every encoder supports this method. Use |CanCreateOptimizedFrames| to
48 // determine if you can and should use this method.
50 // Even if |CanCreateOptimizedFrames| indicates support, there are transient
51 // conditions during a session where optimized frames cannot be provided. In
52 // this case, the caller must be able to account for a nullptr return value
53 // and instantiate its own media::VideoFrames.
54 virtual scoped_refptr<VideoFrame> MaybeCreateOptimizedFrame(
55 const gfx::Size& frame_size, base::TimeDelta timestamp) = 0;
57 // Returns true if the encoder supports creating optimized frames.
58 virtual bool CanCreateOptimizedFrames() const = 0;
60 protected:
61 virtual ~VideoFrameInput() {}
63 private:
64 friend class base::RefCountedThreadSafe<VideoFrameInput>;
67 class AudioFrameInput : public base::RefCountedThreadSafe<AudioFrameInput> {
68 public:
69 // Insert audio frames into Cast sender. Frames will be encoded, packetized
70 // and sent to the network.
71 virtual void InsertAudio(scoped_ptr<AudioBus> audio_bus,
72 const base::TimeTicks& recorded_time) = 0;
74 protected:
75 virtual ~AudioFrameInput() {}
77 private:
78 friend class base::RefCountedThreadSafe<AudioFrameInput>;
81 // All methods of CastSender must be called on the main thread.
82 // Provided CastTransportSender will also be called on the main thread.
83 class CastSender {
84 public:
85 static scoped_ptr<CastSender> Create(
86 scoped_refptr<CastEnvironment> cast_environment,
87 CastTransportSender* const transport_sender);
89 virtual ~CastSender() {}
91 // All video frames for the session should be inserted to this object.
92 virtual scoped_refptr<VideoFrameInput> video_frame_input() = 0;
94 // All audio frames for the session should be inserted to this object.
95 virtual scoped_refptr<AudioFrameInput> audio_frame_input() = 0;
97 // Initialize the audio stack. Must be called in order to send audio frames.
98 // |status_change_cb| will be run as operational status changes.
99 virtual void InitializeAudio(
100 const AudioSenderConfig& audio_config,
101 const StatusChangeCallback& status_change_cb) = 0;
103 // Initialize the video stack. Must be called in order to send video frames.
104 // |status_change_cb| will be run as operational status changes.
106 // TODO(miu): Remove the VEA-specific callbacks. http://crbug.com/454029
107 virtual void InitializeVideo(
108 const VideoSenderConfig& video_config,
109 const StatusChangeCallback& status_change_cb,
110 const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
111 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb) = 0;
113 // Change the target delay. This is only valid if the receiver
114 // supports the "adaptive_target_delay" rtp extension.
115 virtual void SetTargetPlayoutDelay(
116 base::TimeDelta new_target_playout_delay) = 0;
119 } // namespace cast
120 } // namespace media
122 #endif // MEDIA_CAST_CAST_SENDER_H_