- add sources.
[platform/framework/web/crosswalk.git] / src / media / cast / cast_sender.h
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 namespace cast {
24
25 // This Class is thread safe.
26 class FrameInput : public base::RefCountedThreadSafe<FrameInput> {
27  public:
28   // The video_frame must be valid until the callback is called.
29   // The callback is called from the main cast thread as soon as
30   // the encoder is done with the frame; it does not mean that the encoded frame
31   // has been sent out.
32   virtual void InsertRawVideoFrame(const I420VideoFrame* video_frame,
33                                    const base::TimeTicks& capture_time,
34                                    const base::Closure callback) = 0;
35
36   // The video_frame must be valid until the callback is called.
37   // The callback is called from the main cast thread as soon as
38   // the cast sender is done with the frame; it does not mean that the encoded
39   // frame has been sent out.
40   virtual void InsertCodedVideoFrame(const EncodedVideoFrame* video_frame,
41                                      const base::TimeTicks& capture_time,
42                                      const base::Closure callback) = 0;
43
44   // The audio_frame must be valid until the  callback is called.
45   // The callback is called from the main cast thread as soon as
46   // the encoder is done with the frame; it does not mean that the encoded frame
47   // has been sent out.
48   virtual void InsertRawAudioFrame(const PcmAudioFrame* audio_frame,
49                                    const base::TimeTicks& recorded_time,
50                                    const base::Closure callback) = 0;
51
52   // The audio_frame must be valid until the callback is called.
53   // The callback is called from the main cast thread as soon as
54   // the cast sender is done with the frame; it does not mean that the encoded
55   // frame has been sent out.
56   virtual void InsertCodedAudioFrame(const EncodedAudioFrame* audio_frame,
57                                      const base::TimeTicks& recorded_time,
58                                      const base::Closure callback) = 0;
59
60   static void DeleteAudioFrame(const PcmAudioFrame* frame);
61
62   static void DeleteVideoFrame(const I420VideoFrame* video_frame);
63
64  protected:
65   virtual ~FrameInput() {}
66
67  private:
68   friend class base::RefCountedThreadSafe<FrameInput>;
69 };
70
71 // This Class is thread safe.
72 // The provided PacketSender object will always be called form the main cast
73 // thread.
74 class CastSender {
75  public:
76   static CastSender* CreateCastSender(
77       scoped_refptr<CastEnvironment> cast_environment,
78       const AudioSenderConfig& audio_config,
79       const VideoSenderConfig& video_config,
80       VideoEncoderController* const video_encoder_controller,
81       PacketSender* const packet_sender);
82
83   virtual ~CastSender() {}
84
85   // All audio and video frames for the session should be inserted to this
86   // object.
87   // Can be called from any thread.
88   virtual scoped_refptr<FrameInput> frame_input() = 0;
89
90   // All RTCP packets for the session should be inserted to this object.
91   // Can be called from any thread.
92   virtual scoped_refptr<PacketReceiver> packet_receiver() = 0;
93 };
94
95 }  // namespace cast
96 }  // namespace media
97
98 #endif  // MEDIA_CAST_CAST_SENDER_H_