Gallery: Add animation when zooming pictures.
[chromium-blink-merge.git] / chrome / renderer / media / cast_session_delegate.h
blob81235450817d24b44aa54000d18e99d125231fd2
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_
8 #include <map>
9 #include <vector>
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"
22 namespace base {
23 class BinaryValue;
24 class DictionaryValue;
25 class MessageLoopProxy;
26 } // namespace base
28 namespace media {
29 class VideoFrame;
31 namespace cast {
32 class CastEnvironment;
33 class FrameInput;
34 class RawEventSubscriberBundle;
36 namespace transport {
37 class CastTransportSender;
38 } // namespace transport
39 } // namespace cast
40 } // namespace media
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 {
47 public:
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&
78 create_vea_cb,
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);
87 protected:
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;
94 private:
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);
101 base::ThreadChecker thread_checker_;
102 scoped_refptr<media::cast::CastEnvironment> cast_environment_;
103 scoped_ptr<media::cast::CastSender> cast_sender_;
104 scoped_ptr<media::cast::CastTransportSender> cast_transport_;
106 AudioFrameInputAvailableCallback audio_frame_input_available_callback_;
107 VideoFrameInputAvailableCallback video_frame_input_available_callback_;
109 scoped_ptr<media::cast::RawEventSubscriberBundle> event_subscribers_;
111 // Proxy to the IO message loop.
112 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
113 base::WeakPtrFactory<CastSessionDelegate> weak_factory_;
115 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate);
118 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_