Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / renderer / media / cast_session_delegate.h
blobfb0dd09793e166a92575d79ae3cc13b2ea7004ed
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,
63 scoped_ptr<base::DictionaryValue> options);
65 // After calling StartAudio() or StartVideo() encoding of that media will
66 // begin as soon as data is delivered to its sink, if the second method is
67 // called the first media will be restarted. It is strongly recommended not to
68 // deliver any data between calling the two methods.
69 // It's OK to call only one of the two methods.
70 // StartUDP must be called before these methods.
71 void StartAudio(const media::cast::AudioSenderConfig& config,
72 const AudioFrameInputAvailableCallback& callback,
73 const ErrorCallback& error_callback);
75 void StartVideo(const media::cast::VideoSenderConfig& config,
76 const VideoFrameInputAvailableCallback& callback,
77 const ErrorCallback& error_callback,
78 const media::cast::CreateVideoEncodeAcceleratorCallback&
79 create_vea_cb,
80 const media::cast::CreateVideoEncodeMemoryCallback&
81 create_video_encode_mem_cb);
83 void ToggleLogging(bool is_audio, bool enable);
84 void GetEventLogsAndReset(bool is_audio,
85 const std::string& extra_data, const EventLogsCallback& callback);
86 void GetStatsAndReset(bool is_audio, const StatsCallback& callback);
88 protected:
89 // Called to report back operational status changes. The first time this is
90 // called with STATUS_INITIALIZED will result in running the "frame input
91 // available" callback, to indicate the session is ready to accept incoming
92 // audio/video frames. If this is called with an error that has halted the
93 // session, the |error_callback| provided to StartXXX() will be run. This
94 // method may be called multiple times during the session to indicate codec
95 // re-initializations are taking place and/or runtime errors have occurred.
96 void OnOperationalStatusChange(
97 bool is_for_audio,
98 const ErrorCallback& error_callback,
99 media::cast::OperationalStatus result);
101 private:
102 void StatusNotificationCB(
103 media::cast::CastTransportStatus status);
105 // Adds logs collected from transport on browser side.
106 void LogRawEvents(const std::vector<media::cast::PacketEvent>& packet_events,
107 const std::vector<media::cast::FrameEvent>& frame_events);
109 base::ThreadChecker thread_checker_;
110 scoped_refptr<media::cast::CastEnvironment> cast_environment_;
111 scoped_ptr<media::cast::CastSender> cast_sender_;
112 scoped_ptr<media::cast::CastTransportSender> cast_transport_;
114 AudioFrameInputAvailableCallback audio_frame_input_available_callback_;
115 VideoFrameInputAvailableCallback video_frame_input_available_callback_;
117 scoped_ptr<media::cast::RawEventSubscriberBundle> event_subscribers_;
119 // Proxy to the IO message loop.
120 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
121 base::WeakPtrFactory<CastSessionDelegate> weak_factory_;
123 DISALLOW_COPY_AND_ASSIGN(CastSessionDelegate);
126 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_DELEGATE_H_