Upstream version 5.34.104.0
[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 CastTransportSender object will always be called from the main
60 // cast thread.
61 //  At least one of AudioSenderConfig and VideoSenderConfig have to be provided.
62 class CastSender {
63  public:
64   static CastSender* CreateCastSender(
65       scoped_refptr<CastEnvironment> cast_environment,
66       const AudioSenderConfig* audio_config,
67       const VideoSenderConfig* video_config,
68       const scoped_refptr<GpuVideoAcceleratorFactories>& gpu_factories,
69       const CastInitializationCallback& cast_initialization,
70       transport::CastTransportSender* const transport_sender);
71
72   virtual ~CastSender() {}
73
74   // All audio and video frames for the session should be inserted to this
75   // object.
76   // Can be called from any thread.
77   virtual scoped_refptr<FrameInput> frame_input() = 0;
78
79   // All RTCP packets for the session should be inserted to this object.
80   // Can be called from any thread.
81   virtual transport::PacketReceiverCallback packet_receiver() = 0;
82 };
83
84 }  // namespace cast
85 }  // namespace media
86
87 #endif  // MEDIA_CAST_CAST_SENDER_H_