Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / chrome / renderer / media / cast_receiver_session_delegate.cc
blob35099894f75366a90217c4abf882ca045ffaefee
1 // Copyright 2015 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 #include "chrome/renderer/media/cast_receiver_session_delegate.h"
7 #include "base/synchronization/waitable_event.h"
8 #include "base/values.h"
10 CastReceiverSessionDelegate::CastReceiverSessionDelegate()
11 : weak_factory_(this) {
13 CastReceiverSessionDelegate::~CastReceiverSessionDelegate() {}
15 void CastReceiverSessionDelegate::LogRawEvents(
16 const std::vector<media::cast::PacketEvent>& packet_events,
17 const std::vector<media::cast::FrameEvent>& frame_events) {
18 NOTREACHED();
21 void CastReceiverSessionDelegate::Start(
22 const media::cast::FrameReceiverConfig& audio_config,
23 const media::cast::FrameReceiverConfig& video_config,
24 const net::IPEndPoint& local_endpoint,
25 const net::IPEndPoint& remote_endpoint,
26 scoped_ptr<base::DictionaryValue> options,
27 const media::VideoCaptureFormat& format,
28 const ErrorCallback& error_callback) {
29 format_ = format;
30 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
31 CastSessionDelegateBase::StartUDP(local_endpoint,
32 remote_endpoint,
33 options.Pass(),
34 error_callback);
35 cast_receiver_ = media::cast::CastReceiver::Create(cast_environment_,
36 audio_config,
37 video_config,
38 cast_transport_.get());
39 on_audio_decoded_cb_ = base::Bind(
40 &CastReceiverSessionDelegate::OnDecodedAudioFrame,
41 weak_factory_.GetWeakPtr());
42 on_video_decoded_cb_ = base::Bind(
43 &CastReceiverSessionDelegate::OnDecodedVideoFrame,
44 weak_factory_.GetWeakPtr());
47 void CastReceiverSessionDelegate::ReceivePacket(
48 scoped_ptr<media::cast::Packet> packet) {
49 cast_receiver_->ReceivePacket(packet.Pass());
52 void CastReceiverSessionDelegate::StartAudio(
53 scoped_refptr<CastReceiverAudioValve> audio_valve) {
54 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
55 audio_valve_ = audio_valve;
56 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_);
59 void CastReceiverSessionDelegate::OnDecodedAudioFrame(
60 scoped_ptr<media::AudioBus> audio_bus,
61 const base::TimeTicks& playout_time,
62 bool is_continous) {
63 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
64 if (!audio_valve_)
65 return;
67 // We're on the IO thread, which doesn't allow blocking
68 // operations. Since we don't know what the Capture callback
69 // will do exactly, we need to jump to a different thread.
70 // Let's re-use the audio decoder thread.
71 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
72 cast_environment_->PostTask(
73 media::cast::CastEnvironment::AUDIO,
74 FROM_HERE,
75 base::Bind(&CastReceiverAudioValve::Capture,
76 audio_valve_,
77 base::Owned(audio_bus.release()),
78 (playout_time - now).InMilliseconds(),
79 1.0,
80 false));
81 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_);
84 void CastReceiverSessionDelegate::StartVideo(
85 content::VideoCaptureDeliverFrameCB video_callback) {
86 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
87 frame_callback_ = video_callback;
88 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_);
91 void CastReceiverSessionDelegate::StopVideo() {
92 frame_callback_ = content::VideoCaptureDeliverFrameCB();
95 void CastReceiverSessionDelegate::OnDecodedVideoFrame(
96 const scoped_refptr<media::VideoFrame>& video_frame,
97 const base::TimeTicks& playout_time,
98 bool is_continous) {
99 if (frame_callback_.is_null())
100 return;
101 frame_callback_.Run(video_frame, playout_time);
102 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_);