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
{
41 typedef base::Callback
<void(const scoped_refptr
<media::cast::FrameInput
>&)>
42 FrameInputAvailableCallback
;
44 CastSessionDelegate();
45 virtual ~CastSessionDelegate();
47 // After calling StartAudio() or StartVideo() encoding of that media will
48 // begin as soon as data is delivered to its sink, if the second method is
49 // called the first media will be restarted. It is strongly recommended not to
50 // deliver any data between calling the two methods.
51 // It's OK to call only one of the two methods.
52 void StartAudio(const media::cast::AudioSenderConfig
& config
,
53 const FrameInputAvailableCallback
& callback
);
54 void StartVideo(const media::cast::VideoSenderConfig
& config
,
55 const FrameInputAvailableCallback
& callback
);
56 void StartUDP(const net::IPEndPoint
& local_endpoint
,
57 const net::IPEndPoint
& remote_endpoint
);
60 // Callback with the result of the initialization.
61 // If this callback is called with STATUS_INITIALIZED it will report back
62 // to the sinks that it's ready to accept incoming audio / video frames.
63 void InitializationResult(media::cast::CastInitializationStatus result
) const;
66 // Start encoding threads and initialize the CastEnvironment.
69 // Configure CastSender. It is ready to accept audio / video frames after
70 // receiving a successful call to InitializationResult.
71 void StartSendingInternal();
73 void StatusNotificationCB(
74 media::cast::transport::CastTransportStatus status
);
76 base::ThreadChecker thread_checker_
;
77 scoped_refptr
<media::cast::CastEnvironment
> cast_environment_
;
78 scoped_ptr
<media::cast::CastSender
> cast_sender_
;
79 scoped_ptr
<media::cast::transport::CastTransportSender
> cast_transport_
;
81 // Utilities threads owned by this class. They are used by CastSender for
83 // TODO(hclam): See crbug.com/317006 for more details.
84 // This class shouldn't create and own threads.
85 base::Thread audio_encode_thread_
;
86 base::Thread video_encode_thread_
;
88 // Configuration for audio and video.
89 scoped_ptr
<media::cast::AudioSenderConfig
> audio_config_
;
90 scoped_ptr
<media::cast::VideoSenderConfig
> video_config_
;
92 FrameInputAvailableCallback audio_frame_input_available_callback_
;
93 FrameInputAvailableCallback video_frame_input_available_callback_
;
95 net::IPEndPoint local_endpoint_
;
96 net::IPEndPoint remote_endpoint_
;
97 bool transport_configured_
;
99 // Proxy to the IO message loop.
100 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_proxy_
;
102 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate
);
105 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_