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

Side by Side Diff: media/cast/cast_sender_impl.cc

Issue 387933005: Cast: Refactor RTCP handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 5 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/cast_sender_impl.h ('k') | media/cast/cast_testing.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/cast_sender_impl.h" 5 #include "media/cast/cast_sender_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "media/base/video_frame.h" 11 #include "media/base/video_frame.h"
12 #include "media/cast/net/rtcp/rtcp_receiver.h"
12 13
13 namespace media { 14 namespace media {
14 namespace cast { 15 namespace cast {
15 16
16 // The LocalVideoFrameInput class posts all incoming video frames to the main 17 // The LocalVideoFrameInput class posts all incoming video frames to the main
17 // cast thread for processing. 18 // cast thread for processing.
18 class LocalVideoFrameInput : public VideoFrameInput { 19 class LocalVideoFrameInput : public VideoFrameInput {
19 public: 20 public:
20 LocalVideoFrameInput(scoped_refptr<CastEnvironment> cast_environment, 21 LocalVideoFrameInput(scoped_refptr<CastEnvironment> cast_environment,
21 base::WeakPtr<VideoSender> video_sender) 22 base::WeakPtr<VideoSender> video_sender)
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 video_frame_input_ = 136 video_frame_input_ =
136 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr()); 137 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr());
137 } 138 }
138 cast_initialization_cb.Run(status); 139 cast_initialization_cb.Run(status);
139 } 140 }
140 141
141 CastSenderImpl::~CastSenderImpl() { 142 CastSenderImpl::~CastSenderImpl() {
142 VLOG(1) << "CastSenderImpl@" << this << "::~CastSenderImpl()"; 143 VLOG(1) << "CastSenderImpl@" << this << "::~CastSenderImpl()";
143 } 144 }
144 145
145 // ReceivedPacket handle the incoming packets to the cast sender
146 // it's only expected to receive RTCP feedback packets from the remote cast
147 // receiver. The class verifies that that it is a RTCP packet and based on the
148 // SSRC of the incoming packet route the packet to the correct sender; audio or
149 // video.
150 //
151 // Definition of SSRC as defined in RFC 3550.
152 // Synchronization source (SSRC): The source of a stream of RTP
153 // packets, identified by a 32-bit numeric SSRC identifier carried in
154 // the RTP header so as not to be dependent upon the network address.
155 // All packets from a synchronization source form part of the same
156 // timing and sequence number space, so a receiver groups packets by
157 // synchronization source for playback. Examples of synchronization
158 // sources include the sender of a stream of packets derived from a
159 // signal source such as a microphone or a camera, or an RTP mixer
160 // (see below). A synchronization source may change its data format,
161 // e.g., audio encoding, over time. The SSRC identifier is a
162 // randomly chosen value meant to be globally unique within a
163 // particular RTP session (see Section 8). A participant need not
164 // use the same SSRC identifier for all the RTP sessions in a
165 // multimedia session; the binding of the SSRC identifiers is
166 // provided through RTCP (see Section 6.5.1). If a participant
167 // generates multiple streams in one RTP session, for example from
168 // separate video cameras, each MUST be identified as a different
169 // SSRC.
170 void CastSenderImpl::ReceivedPacket(scoped_ptr<Packet> packet) {
171 DCHECK(cast_environment_);
172 size_t length = packet->size();
173 const uint8_t* data = &packet->front();
174 if (!Rtcp::IsRtcpPacket(data, length)) {
175 VLOG(1) << "CastSenderImpl@" << this << "::ReceivedPacket() -- "
176 << "Received an invalid (non-RTCP?) packet in the cast sender.";
177 return;
178 }
179 uint32 ssrc_of_sender = Rtcp::GetSsrcOfSender(data, length);
180 if (ssrc_of_sender == ssrc_of_audio_sender_) {
181 if (!audio_sender_) {
182 NOTREACHED();
183 return;
184 }
185 cast_environment_->PostTask(CastEnvironment::MAIN,
186 FROM_HERE,
187 base::Bind(&AudioSender::IncomingRtcpPacket,
188 audio_sender_->AsWeakPtr(),
189 base::Passed(&packet)));
190 } else if (ssrc_of_sender == ssrc_of_video_sender_) {
191 if (!video_sender_) {
192 NOTREACHED();
193 return;
194 }
195 cast_environment_->PostTask(CastEnvironment::MAIN,
196 FROM_HERE,
197 base::Bind(&VideoSender::IncomingRtcpPacket,
198 video_sender_->AsWeakPtr(),
199 base::Passed(&packet)));
200 } else {
201 VLOG(1) << "CastSenderImpl@" << this << "::ReceivedPacket() -- "
202 << "Received a RTCP packet with a non matching sender SSRC "
203 << ssrc_of_sender;
204 }
205 }
206
207 scoped_refptr<AudioFrameInput> CastSenderImpl::audio_frame_input() { 146 scoped_refptr<AudioFrameInput> CastSenderImpl::audio_frame_input() {
208 return audio_frame_input_; 147 return audio_frame_input_;
209 } 148 }
210 149
211 scoped_refptr<VideoFrameInput> CastSenderImpl::video_frame_input() { 150 scoped_refptr<VideoFrameInput> CastSenderImpl::video_frame_input() {
212 return video_frame_input_; 151 return video_frame_input_;
213 } 152 }
214 153
215 PacketReceiverCallback CastSenderImpl::packet_receiver() {
216 return base::Bind(&CastSenderImpl::ReceivedPacket,
217 weak_factory_.GetWeakPtr());
218 }
219
220 } // namespace cast 154 } // namespace cast
221 } // namespace media 155 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/cast_sender_impl.h ('k') | media/cast/cast_testing.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698