Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / media / cast_session_delegate.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 #ifndef CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_
6 #define CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_checker.h"
14 #include "base/time/default_tick_clock.h"
15 #include "media/cast/cast_config.h"
16 #include "media/cast/cast_sender.h"
17
18 namespace base {
19 class MessageLoopProxy;
20 }  // namespace base
21
22 namespace media {
23 class VideoFrame;
24
25 namespace cast {
26 class CastEnvironment;
27 class FrameInput;
28
29 namespace transport {
30 class CastTransportSender;
31 }  // namespace transport
32 }  // namespace cast
33 }  // namespace media
34
35 // This class hosts CastSender and connects it to audio/video frame input
36 // and network socket.
37 // This class is created on the render thread and destroyed on the IO
38 // thread. All methods are accessible only on the IO thread.
39 class CastSessionDelegate {
40  public:
41   typedef
42   base::Callback<void(const scoped_refptr<media::cast::FrameInput>&)>
43   FrameInputAvailableCallback;
44
45   CastSessionDelegate();
46   virtual ~CastSessionDelegate();
47
48   // After calling StartAudio() and StartVideo() with configuration encoding
49   // will begin.
50   void StartAudio(const media::cast::AudioSenderConfig& config,
51                   const FrameInputAvailableCallback& callback);
52   void StartVideo(const media::cast::VideoSenderConfig& config,
53                   const FrameInputAvailableCallback& callback);
54
55  private:
56   // Start encoding threads and configure CastSender. It is ready to accept
57   // audio/video frames after this call.
58   void StartSendingInternal();
59
60   base::ThreadChecker thread_checker_;
61   scoped_refptr<media::cast::CastEnvironment> cast_environment_;
62   scoped_ptr<media::cast::CastSender> cast_sender_;
63   scoped_ptr<media::cast::transport::CastTransportSender> cast_transport_;
64
65   // Utilities threads owned by this class. They are used by CastSender for
66   // encoding.
67   // TODO(hclam): See crbug.com/317006 for more details.
68   // This class shouldn't create and own threads.
69   base::Thread audio_encode_thread_;
70   base::Thread video_encode_thread_;
71
72   // Configuration for audio and video.
73   media::cast::AudioSenderConfig audio_config_;
74   media::cast::VideoSenderConfig video_config_;
75   bool audio_configured_;
76   bool video_configured_;
77   std::vector<FrameInputAvailableCallback> frame_input_available_callbacks_;
78
79   // Proxy to the IO message loop.
80   scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
81
82   DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate);
83 };
84
85 #endif  // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_