Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Side by Side Diff: chrome/renderer/media/cast_receiver_session_delegate.cc

Issue 883293005: Cast: Basic cast_receiver API for chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/renderer/media/cast_receiver_session_delegate.h"
6
7 #include "base/synchronization/waitable_event.h"
8 #include "base/values.h"
9
10 CastReceiverSessionDelegate::CastReceiverSessionDelegate()
11 : weak_factory_(this) {
12 }
13 CastReceiverSessionDelegate::~CastReceiverSessionDelegate() {}
14
15 void CastReceiverSessionDelegate::LogRawEvents(
16 const std::vector<media::cast::PacketEvent>& packet_events,
17 const std::vector<media::cast::FrameEvent>& frame_events) {
18 NOTREACHED();
19 }
20
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 format_ = format;
29 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
30 CastSessionDelegateBase::StartUDP(local_endpoint,
31 remote_endpoint,
32 options.Pass());
33 cast_receiver_ = media::cast::CastReceiver::Create(cast_environment_,
34 audio_config,
35 video_config,
36 cast_transport_.get());
37 on_audio_decoded_cb_ = base::Bind(
38 &CastReceiverSessionDelegate::OnDecodedAudioFrame,
39 weak_factory_.GetWeakPtr());
40 on_video_decoded_cb_ = base::Bind(
41 &CastReceiverSessionDelegate::OnDecodedVideoFrame,
42 weak_factory_.GetWeakPtr());
43 }
44
45 void CastReceiverSessionDelegate::StartAudio(
46 scoped_refptr<CastReceiverAudioValve> audio_valve) {
47 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
48 audio_valve_ = audio_valve;
49 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_);
50 }
51
52 void CastReceiverSessionDelegate::OnDecodedAudioFrame(
53 scoped_ptr<media::AudioBus> audio_bus,
54 const base::TimeTicks& playout_time,
55 bool is_continous) {
56 if (!audio_valve_)
miu 2015/02/11 02:52:50 Please add: DCHECK(io_message_loop_proxy_->Belo
hubbe 2015/02/11 22:38:17 Done.
57 return;
58
59 // We're on the IO thread, which doesn't allow blocking
60 // operations. Since we don't know what the Capture callback
61 // will do exactly, we need to jump to a different thread.
62 // Let's re-use the audio decoder thread.
63 base::TimeTicks now = cast_environment_->Clock()->NowTicks();
64 cast_environment_->PostTask(
65 media::cast::CastEnvironment::AUDIO,
66 FROM_HERE,
67 base::Bind(&CastReceiverAudioValve::Capture,
68 audio_valve_,
69 base::Owned(audio_bus.release()),
70 (playout_time - now).InMilliseconds(),
71 1.0,
72 false));
73 cast_receiver_->RequestDecodedAudioFrame(on_audio_decoded_cb_);
74 }
75
76 void CastReceiverSessionDelegate::StartVideo(
77 content::VideoCaptureDeliverFrameCB video_callback) {
78 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
79 frame_callback_ = video_callback;
80 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_);
81 }
82
83 void CastReceiverSessionDelegate::StopVideo() {
84 frame_callback_ = content::VideoCaptureDeliverFrameCB();
85 }
86
87 void CastReceiverSessionDelegate::OnDecodedVideoFrame(
88 const scoped_refptr<media::VideoFrame>& video_frame,
89 const base::TimeTicks& playout_time,
90 bool is_continous) {
91 if (frame_callback_.is_null())
92 return;
93 frame_callback_.Run(video_frame, format_, playout_time);
94 cast_receiver_->RequestDecodedVideoFrame(on_video_decoded_cb_);
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698