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

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 1823503002: Reland Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/media/engine/webrtcvideoengine2.h" 11 #include "webrtc/media/engine/webrtcvideoengine2.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <set> 14 #include <set>
15 #include <string> 15 #include <string>
16 16
17 #include "webrtc/base/buffer.h" 17 #include "webrtc/base/copyonwritebuffer.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/base/stringutils.h" 19 #include "webrtc/base/stringutils.h"
20 #include "webrtc/base/timeutils.h" 20 #include "webrtc/base/timeutils.h"
21 #include "webrtc/base/trace_event.h" 21 #include "webrtc/base/trace_event.h"
22 #include "webrtc/call.h" 22 #include "webrtc/call.h"
23 #include "webrtc/media/base/videocapturer.h" 23 #include "webrtc/media/base/videocapturer.h"
24 #include "webrtc/media/base/videorenderer.h" 24 #include "webrtc/media/base/videorenderer.h"
25 #include "webrtc/media/engine/constants.h" 25 #include "webrtc/media/engine/constants.h"
26 #include "webrtc/media/engine/simulcast.h" 26 #include "webrtc/media/engine/simulcast.h"
27 #include "webrtc/media/engine/webrtcmediaengine.h" 27 #include "webrtc/media/engine/webrtcmediaengine.h"
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 return false; 1293 return false;
1294 } 1294 }
1295 if (!kv->second->SetCapturer(capturer)) { 1295 if (!kv->second->SetCapturer(capturer)) {
1296 return false; 1296 return false;
1297 } 1297 }
1298 } 1298 }
1299 return true; 1299 return true;
1300 } 1300 }
1301 1301
1302 void WebRtcVideoChannel2::OnPacketReceived( 1302 void WebRtcVideoChannel2::OnPacketReceived(
1303 rtc::Buffer* packet, 1303 rtc::CopyOnWriteBuffer* packet,
1304 const rtc::PacketTime& packet_time) { 1304 const rtc::PacketTime& packet_time) {
1305 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 1305 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
1306 packet_time.not_before); 1306 packet_time.not_before);
1307 const webrtc::PacketReceiver::DeliveryStatus delivery_result = 1307 const webrtc::PacketReceiver::DeliveryStatus delivery_result =
1308 call_->Receiver()->DeliverPacket( 1308 call_->Receiver()->DeliverPacket(
1309 webrtc::MediaType::VIDEO, 1309 webrtc::MediaType::VIDEO,
1310 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), 1310 packet->cdata(), packet->size(),
1311 webrtc_packet_time); 1311 webrtc_packet_time);
1312 switch (delivery_result) { 1312 switch (delivery_result) {
1313 case webrtc::PacketReceiver::DELIVERY_OK: 1313 case webrtc::PacketReceiver::DELIVERY_OK:
1314 return; 1314 return;
1315 case webrtc::PacketReceiver::DELIVERY_PACKET_ERROR: 1315 case webrtc::PacketReceiver::DELIVERY_PACKET_ERROR:
1316 return; 1316 return;
1317 case webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC: 1317 case webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC:
1318 break; 1318 break;
1319 } 1319 }
1320 1320
1321 uint32_t ssrc = 0; 1321 uint32_t ssrc = 0;
1322 if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) { 1322 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) {
1323 return; 1323 return;
1324 } 1324 }
1325 1325
1326 int payload_type = 0; 1326 int payload_type = 0;
1327 if (!GetRtpPayloadType(packet->data(), packet->size(), &payload_type)) { 1327 if (!GetRtpPayloadType(packet->cdata(), packet->size(), &payload_type)) {
1328 return; 1328 return;
1329 } 1329 }
1330 1330
1331 // See if this payload_type is registered as one that usually gets its own 1331 // See if this payload_type is registered as one that usually gets its own
1332 // SSRC (RTX) or at least is safe to drop either way (ULPFEC). If it is, and 1332 // SSRC (RTX) or at least is safe to drop either way (ULPFEC). If it is, and
1333 // it wasn't handled above by DeliverPacket, that means we don't know what 1333 // it wasn't handled above by DeliverPacket, that means we don't know what
1334 // stream it associates with, and we shouldn't ever create an implicit channel 1334 // stream it associates with, and we shouldn't ever create an implicit channel
1335 // for these. 1335 // for these.
1336 for (auto& codec : recv_codecs_) { 1336 for (auto& codec : recv_codecs_) {
1337 if (payload_type == codec.rtx_payload_type || 1337 if (payload_type == codec.rtx_payload_type ||
1338 payload_type == codec.fec.red_rtx_payload_type || 1338 payload_type == codec.fec.red_rtx_payload_type ||
1339 payload_type == codec.fec.ulpfec_payload_type) { 1339 payload_type == codec.fec.ulpfec_payload_type) {
1340 return; 1340 return;
1341 } 1341 }
1342 } 1342 }
1343 1343
1344 switch (unsignalled_ssrc_handler_->OnUnsignalledSsrc(this, ssrc)) { 1344 switch (unsignalled_ssrc_handler_->OnUnsignalledSsrc(this, ssrc)) {
1345 case UnsignalledSsrcHandler::kDropPacket: 1345 case UnsignalledSsrcHandler::kDropPacket:
1346 return; 1346 return;
1347 case UnsignalledSsrcHandler::kDeliverPacket: 1347 case UnsignalledSsrcHandler::kDeliverPacket:
1348 break; 1348 break;
1349 } 1349 }
1350 1350
1351 if (call_->Receiver()->DeliverPacket( 1351 if (call_->Receiver()->DeliverPacket(
1352 webrtc::MediaType::VIDEO, 1352 webrtc::MediaType::VIDEO,
1353 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), 1353 packet->cdata(), packet->size(),
1354 webrtc_packet_time) != webrtc::PacketReceiver::DELIVERY_OK) { 1354 webrtc_packet_time) != webrtc::PacketReceiver::DELIVERY_OK) {
1355 LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery."; 1355 LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery.";
1356 return; 1356 return;
1357 } 1357 }
1358 } 1358 }
1359 1359
1360 void WebRtcVideoChannel2::OnRtcpReceived( 1360 void WebRtcVideoChannel2::OnRtcpReceived(
1361 rtc::Buffer* packet, 1361 rtc::CopyOnWriteBuffer* packet,
1362 const rtc::PacketTime& packet_time) { 1362 const rtc::PacketTime& packet_time) {
1363 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 1363 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
1364 packet_time.not_before); 1364 packet_time.not_before);
1365 // TODO(pbos): Check webrtc::PacketReceiver::DELIVERY_OK once we deliver 1365 // TODO(pbos): Check webrtc::PacketReceiver::DELIVERY_OK once we deliver
1366 // for both audio and video on the same path. Since BundleFilter doesn't 1366 // for both audio and video on the same path. Since BundleFilter doesn't
1367 // filter RTCP anymore incoming RTCP packets could've been going to audio (so 1367 // filter RTCP anymore incoming RTCP packets could've been going to audio (so
1368 // logging failures spam the log). 1368 // logging failures spam the log).
1369 call_->Receiver()->DeliverPacket( 1369 call_->Receiver()->DeliverPacket(
1370 webrtc::MediaType::VIDEO, 1370 webrtc::MediaType::VIDEO,
1371 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), 1371 packet->cdata(), packet->size(),
1372 webrtc_packet_time); 1372 webrtc_packet_time);
1373 } 1373 }
1374 1374
1375 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { 1375 void WebRtcVideoChannel2::OnReadyToSend(bool ready) {
1376 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); 1376 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready.");
1377 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); 1377 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown);
1378 } 1378 }
1379 1379
1380 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) { 1380 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) {
1381 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> " 1381 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> "
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 // due to lack of socket buffer space, although it's not yet clear what the 1417 // due to lack of socket buffer space, although it's not yet clear what the
1418 // ideal value should be. 1418 // ideal value should be.
1419 MediaChannel::SetOption(NetworkInterface::ST_RTP, 1419 MediaChannel::SetOption(NetworkInterface::ST_RTP,
1420 rtc::Socket::OPT_SNDBUF, 1420 rtc::Socket::OPT_SNDBUF,
1421 kVideoRtpBufferSize); 1421 kVideoRtpBufferSize);
1422 } 1422 }
1423 1423
1424 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, 1424 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data,
1425 size_t len, 1425 size_t len,
1426 const webrtc::PacketOptions& options) { 1426 const webrtc::PacketOptions& options) {
1427 rtc::Buffer packet(data, len, kMaxRtpPacketLen); 1427 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen);
1428 rtc::PacketOptions rtc_options; 1428 rtc::PacketOptions rtc_options;
1429 rtc_options.packet_id = options.packet_id; 1429 rtc_options.packet_id = options.packet_id;
1430 return MediaChannel::SendPacket(&packet, rtc_options); 1430 return MediaChannel::SendPacket(&packet, rtc_options);
1431 } 1431 }
1432 1432
1433 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { 1433 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) {
1434 rtc::Buffer packet(data, len, kMaxRtpPacketLen); 1434 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen);
1435 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions()); 1435 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions());
1436 } 1436 }
1437 1437
1438 void WebRtcVideoChannel2::StartAllSendStreams() { 1438 void WebRtcVideoChannel2::StartAllSendStreams() {
1439 rtc::CritScope stream_lock(&stream_crit_); 1439 rtc::CritScope stream_lock(&stream_crit_);
1440 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = 1440 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it =
1441 send_streams_.begin(); 1441 send_streams_.begin();
1442 it != send_streams_.end(); ++it) { 1442 it != send_streams_.end(); ++it) {
1443 it->second->Start(); 1443 it->second->Start();
1444 } 1444 }
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2566 rtx_mapping[video_codecs[i].codec.id] != 2566 rtx_mapping[video_codecs[i].codec.id] !=
2567 fec_settings.red_payload_type) { 2567 fec_settings.red_payload_type) {
2568 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2568 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2569 } 2569 }
2570 } 2570 }
2571 2571
2572 return video_codecs; 2572 return video_codecs;
2573 } 2573 }
2574 2574
2575 } // namespace cricket 2575 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698