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