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

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: Fix LoggingImplTest + REBASE 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
« no previous file with comments | « media/cast/test/utility/in_process_receiver.h ('k') | media/cast/test/utility/input_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 weak_factory_(this) {}
34
35 InProcessReceiver::~InProcessReceiver() {
36 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
37 }
38
39 void InProcessReceiver::Start() {
40 cast_environment_->PostTask(CastEnvironment::MAIN,
41 FROM_HERE,
42 base::Bind(&InProcessReceiver::StartOnMainThread,
43 base::Unretained(this)));
44 }
45
46 void InProcessReceiver::DestroySoon() {
47 cast_environment_->PostTask(
48 CastEnvironment::MAIN,
49 FROM_HERE,
50 base::Bind(&InProcessReceiver::WillDestroyReceiver, base::Owned(this)));
51 }
52
53 void InProcessReceiver::UpdateCastTransportStatus(CastTransportStatus status) {
54 LOG_IF(ERROR, status == media::cast::transport::TRANSPORT_SOCKET_ERROR)
55 << "Transport socket error occurred. InProcessReceiver is likely dead.";
56 VLOG(1) << "CastTransportStatus is now " << status;
57 }
58
59 void InProcessReceiver::StartOnMainThread() {
60 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
61
62 DCHECK(!transport_ && !cast_receiver_);
63 transport_.reset(
64 new UdpTransport(NULL,
65 cast_environment_->GetTaskRunner(CastEnvironment::MAIN),
66 local_end_point_,
67 remote_end_point_,
68 base::Bind(&InProcessReceiver::UpdateCastTransportStatus,
69 base::Unretained(this))));
70 cast_receiver_.reset(CastReceiver::CreateCastReceiver(
71 cast_environment_, audio_config_, video_config_, transport_.get()));
72
73 // TODO(hubbe): Make the cast receiver do this automatically.
74 transport_->StartReceiving(cast_receiver_->packet_receiver());
75
76 PullNextAudioFrame();
77 PullNextVideoFrame();
78 }
79
80 void InProcessReceiver::GotAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame,
81 const base::TimeTicks& playout_time) {
82 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
83 OnAudioFrame(audio_frame.Pass(), playout_time);
84 // TODO(miu): Put this back here: PullNextAudioFrame();
85 }
86
87 void InProcessReceiver::GotVideoFrame(
88 const scoped_refptr<VideoFrame>& video_frame,
89 const base::TimeTicks& render_time) {
90 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
91 OnVideoFrame(video_frame, render_time);
92 PullNextVideoFrame();
93 }
94
95 void InProcessReceiver::PullNextAudioFrame() {
96 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
97 cast_receiver_->frame_receiver()->GetRawAudioFrame(
98 1 /* 10 ms of samples */,
99 audio_config_.frequency,
100 base::Bind(&InProcessReceiver::GotAudioFrame,
101 weak_factory_.GetWeakPtr()));
102 // TODO(miu): Fix audio decoder so that it never drops a request for the next
103 // frame of audio. Once fixed, remove this, and add PullNextAudioFrame() to
104 // the end of GotAudioFrame(), so that it behaves just like GotVideoFrame().
105 // http://crbug.com/347361
106 cast_environment_->PostDelayedTask(
107 CastEnvironment::MAIN,
108 FROM_HERE,
109 base::Bind(&InProcessReceiver::PullNextAudioFrame,
110 weak_factory_.GetWeakPtr()),
111 base::TimeDelta::FromMilliseconds(10));
112 }
113
114 void InProcessReceiver::PullNextVideoFrame() {
115 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
116 cast_receiver_->frame_receiver()->GetRawVideoFrame(base::Bind(
117 &InProcessReceiver::GotVideoFrame, weak_factory_.GetWeakPtr()));
118 }
119
120 // static
121 void InProcessReceiver::WillDestroyReceiver(InProcessReceiver* receiver) {
122 DCHECK(receiver->cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
123 }
124
125 } // namespace cast
126 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/test/utility/in_process_receiver.h ('k') | media/cast/test/utility/input_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698