8b74b7431806e080cf96b27c9166741a4deb7e1f
[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 #include "media/cast/transport/cast_transport_sender.h"
22 #include "media/filters/gpu_video_accelerator_factories.h"
23
24 namespace media {
25 class AudioBus;
26 class VideoFrame;
27 }
28
29 namespace media {
30 namespace cast {
31
32 // This Class is thread safe.
33 class FrameInput : public base::RefCountedThreadSafe<FrameInput> {
34  public:
35   // The video_frame must be valid until the callback is called.
36   // The callback is called from the main cast thread as soon as
37   // the encoder is done with the frame; it does not mean that the encoded frame
38   // has been sent out.
39   virtual void InsertRawVideoFrame(
40       const scoped_refptr<media::VideoFrame>& video_frame,
41       const base::TimeTicks& capture_time) = 0;
42
43   // The |audio_bus| must be valid until the |done_callback| is called.
44   // The callback is called from the main cast thread as soon as the encoder is
45   // done with |audio_bus|; it does not mean that the encoded data has been
46   // sent out.
47   virtual void InsertAudio(const AudioBus* audio_bus,
48                            const base::TimeTicks& recorded_time,
49                            const base::Closure& done_callback) = 0;
50
51  protected:
52   virtual ~FrameInput() {}
53
54  private:
55   friend class base::RefCountedThreadSafe<FrameInput>;
56 };
57
58 // This Class is thread safe.
59 // The provided PacketSender object will always be called form the main cast
60 // thread.
61 class CastSender {
62  public:
63   static CastSender* CreateCastSender(
64       scoped_refptr<CastEnvironment> cast_environment,
65       const AudioSenderConfig& audio_config,
66       const VideoSenderConfig& video_config,
67       const scoped_refptr<GpuVideoAcceleratorFactories>& gpu_factories,
68       transport::CastTransportSender* const transport_sender);
69   // TODO(pwestin): Add callback for status messages; initialized, errors etc.
70
71   virtual ~CastSender() {}
72
73   // All audio and video frames for the session should be inserted to this
74   // object.
75   // Can be called from any thread.
76   virtual scoped_refptr<FrameInput> frame_input() = 0;
77
78   // All RTCP packets for the session should be inserted to this object.
79   // Can be called from any thread.
80   virtual scoped_refptr<transport::PacketReceiver> packet_receiver() = 0;
81 };
82
83 }  // namespace cast
84 }  // namespace media
85
86 #endif  // MEDIA_CAST_CAST_SENDER_H_