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.
5 #ifndef CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_
6 #define CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_
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"
19 class MessageLoopProxy;
26 class CastEnvironment;
30 class CastTransportSender;
31 } // namespace transport
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 {
42 base::Callback<void(const scoped_refptr<media::cast::FrameInput>&)>
43 FrameInputAvailableCallback;
45 CastSessionDelegate();
46 virtual ~CastSessionDelegate();
48 // After calling StartAudio() and StartVideo() with configuration encoding
50 void StartAudio(const media::cast::AudioSenderConfig& config,
51 const FrameInputAvailableCallback& callback);
52 void StartVideo(const media::cast::VideoSenderConfig& config,
53 const FrameInputAvailableCallback& callback);
56 // Start encoding threads and configure CastSender. It is ready to accept
57 // audio/video frames after this call.
58 void StartSendingInternal();
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_;
65 // Utilities threads owned by this class. They are used by CastSender for
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_;
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_;
79 // Proxy to the IO message loop.
80 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
82 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate);
85 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_