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_
11 #include "base/basictypes.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread.h"
16 #include "base/threading/thread_checker.h"
17 #include "base/time/default_tick_clock.h"
18 #include "media/cast/cast_config.h"
19 #include "media/cast/cast_sender.h"
20 #include "media/cast/logging/logging_defines.h"
24 class DictionaryValue;
25 class MessageLoopProxy;
32 class CastEnvironment;
34 class RawEventSubscriberBundle;
37 class CastTransportSender;
38 } // namespace transport
42 // This class hosts CastSender and connects it to audio/video frame input
43 // and network socket.
44 // This class is created on the render thread and destroyed on the IO
45 // thread. All methods are accessible only on the IO thread.
46 class CastSessionDelegate {
48 typedef base::Callback<void(const scoped_refptr<
49 media::cast::AudioFrameInput>&)> AudioFrameInputAvailableCallback;
50 typedef base::Callback<void(const scoped_refptr<
51 media::cast::VideoFrameInput>&)> VideoFrameInputAvailableCallback;
52 typedef base::Callback<void(scoped_ptr<base::BinaryValue>)> EventLogsCallback;
53 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> StatsCallback;
54 typedef base::Callback<void(const std::string&)> ErrorCallback;
56 CastSessionDelegate();
57 virtual ~CastSessionDelegate();
59 // This will start the session by configuring and creating the Cast transport
60 // and the Cast sender.
61 // Must be called before initialization of audio or video.
62 void StartUDP(const net::IPEndPoint& remote_endpoint);
64 // After calling StartAudio() or StartVideo() encoding of that media will
65 // begin as soon as data is delivered to its sink, if the second method is
66 // called the first media will be restarted. It is strongly recommended not to
67 // deliver any data between calling the two methods.
68 // It's OK to call only one of the two methods.
69 // StartUDP must be called before these methods.
70 void StartAudio(const media::cast::AudioSenderConfig& config,
71 const AudioFrameInputAvailableCallback& callback,
72 const ErrorCallback& error_callback);
74 void StartVideo(const media::cast::VideoSenderConfig& config,
75 const VideoFrameInputAvailableCallback& callback,
76 const ErrorCallback& error_callback,
77 const media::cast::CreateVideoEncodeAcceleratorCallback&
79 const media::cast::CreateVideoEncodeMemoryCallback&
80 create_video_encode_mem_cb);
82 void ToggleLogging(bool is_audio, bool enable);
83 void GetEventLogsAndReset(bool is_audio,
84 const std::string& extra_data, const EventLogsCallback& callback);
85 void GetStatsAndReset(bool is_audio, const StatsCallback& callback);
88 // Callback with the result of the initialization.
89 // If this callback is called with STATUS_INITIALIZED it will report back
90 // to the sinks that it's ready to accept incoming audio / video frames.
91 void InitializationResultCB(
92 media::cast::CastInitializationStatus result) const;
95 void StatusNotificationCB(
96 media::cast::CastTransportStatus status);
98 // Adds logs collected from transport on browser side.
99 void LogRawEvents(const std::vector<media::cast::PacketEvent>& packet_events,
100 const std::vector<media::cast::FrameEvent>& frame_events);
102 base::ThreadChecker thread_checker_;
103 scoped_refptr<media::cast::CastEnvironment> cast_environment_;
104 scoped_ptr<media::cast::CastSender> cast_sender_;
105 scoped_ptr<media::cast::CastTransportSender> cast_transport_;
107 AudioFrameInputAvailableCallback audio_frame_input_available_callback_;
108 VideoFrameInputAvailableCallback video_frame_input_available_callback_;
110 scoped_ptr<media::cast::RawEventSubscriberBundle> event_subscribers_;
112 // Proxy to the IO message loop.
113 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
114 base::WeakPtrFactory<CastSessionDelegate> weak_factory_;
116 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate);
119 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_