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

Side by Side Diff: media/cast/test/utility/in_process_receiver.cc

Issue 184813009: Cast Streaming API end-to-end browser_test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed hubbe's comments, and fixed threading/shutdown issues. Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 "media/cast/test/utility/in_process_receiver.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/time/time.h"
9 #include "media/base/video_frame.h"
10 #include "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/cast_receiver.h"
13 #include "media/cast/transport/cast_transport_config.h"
14 #include "media/cast/transport/transport/udp_transport.h"
15
16 using media::cast::transport::CastTransportStatus;
17 using media::cast::transport::UdpTransport;
18
19 namespace media {
20 namespace cast {
21
22 InProcessReceiver::InProcessReceiver(
23 const scoped_refptr<CastEnvironment>& cast_environment,
24 const net::IPEndPoint& local_end_point,
25 const net::IPEndPoint& remote_end_point,
26 const AudioReceiverConfig& audio_config,
27 const VideoReceiverConfig& video_config)
28 : cast_environment_(cast_environment),
29 local_end_point_(local_end_point),
30 remote_end_point_(remote_end_point),
31 audio_config_(audio_config),
32 video_config_(video_config) {}
33
34 InProcessReceiver::~InProcessReceiver() {}
35
36 void InProcessReceiver::Start() {
37 cast_environment_->PostTask(
38 CastEnvironment::MAIN,
39 FROM_HERE,
40 base::Bind(&InProcessReceiver::StartOnMainThread, this));
41 }
42
43 void InProcessReceiver::StopSoon() {
44 cast_environment_->PostTask(
45 CastEnvironment::MAIN,
46 FROM_HERE,
47 base::Bind(&InProcessReceiver::StopOnMainThread, this));
48 }
49
50 void InProcessReceiver::UpdateCastTransportStatus(CastTransportStatus status) {
51 LOG_IF(ERROR, status == media::cast::transport::TRANSPORT_SOCKET_ERROR)
52 << "Transport socket error occurred. InProcessReceiver is likely dead.";
53 VLOG(1) << "CastTransportStatus is now " << status;
54 }
55
56 void InProcessReceiver::StartOnMainThread() {
57 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
58
59 DCHECK(!transport_ && !cast_receiver_);
60
61 transport_.reset(
62 new UdpTransport(NULL,
63 cast_environment_->GetTaskRunner(CastEnvironment::MAIN),
64 local_end_point_,
65 remote_end_point_,
66 base::Bind(&InProcessReceiver::UpdateCastTransportStatus,
67 base::Unretained(this))));
68 cast_receiver_.reset(CastReceiver::CreateCastReceiver(
69 cast_environment_, audio_config_, video_config_, transport_.get()));
70
71 // TODO(hubbe): Make the cast receiver do this automatically.
72 transport_->StartReceiving(cast_receiver_->packet_receiver());
73
74 PullNextAudioFrame();
75 PullNextVideoFrame();
76 }
77
78 void InProcessReceiver::StopOnMainThread() {
79 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
80
81 cast_receiver_.reset();
82 transport_.reset();
83 }
84
85 void InProcessReceiver::GotAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame,
86 const base::TimeTicks& playout_time) {
87 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
88 OnAudioFrame(audio_frame.Pass(), playout_time);
89 // TODO(miu): Put this back here: PullNextAudioFrame();
90 }
91
92 void InProcessReceiver::GotVideoFrame(
93 const scoped_refptr<VideoFrame>& video_frame,
94 const base::TimeTicks& render_time) {
95 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
96 OnVideoFrame(video_frame, render_time);
97 PullNextVideoFrame();
98 }
99
100 void InProcessReceiver::PullNextAudioFrame() {
101 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
102 if (!cast_receiver_)
103 return;
104 cast_receiver_->frame_receiver()->GetRawAudioFrame(
105 1 /* 10 ms of samples */,
106 audio_config_.frequency,
107 base::Bind(&InProcessReceiver::GotAudioFrame, this));
108 // TODO(miu): Fix audio decoder so that it never drops a request for the next
109 // frame of audio. Once fixed, remove this, and add PullNextAudioFrame() to
110 // the end of GotAudioFrame(), so that it behaves just like GotVideoFrame().
111 // http://crbug.com/347361
112 cast_environment_->PostDelayedTask(
113 CastEnvironment::MAIN,
114 FROM_HERE,
115 base::Bind(&InProcessReceiver::PullNextAudioFrame, this),
116 base::TimeDelta::FromMilliseconds(10));
117 }
118
119 void InProcessReceiver::PullNextVideoFrame() {
120 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
121 if (!cast_receiver_)
122 return;
123 cast_receiver_->frame_receiver()->GetRawVideoFrame(
124 base::Bind(&InProcessReceiver::GotVideoFrame, this));
125 }
126
127 } // namespace cast
128 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698