| OLD | NEW |
| 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 #ifdef HAVE_WEBRTC_VIDEO |
| 11 #include "webrtc/media/webrtc/webrtcvideoengine2.h" | 12 #include "webrtc/media/webrtc/webrtcvideoengine2.h" |
| 12 | 13 |
| 13 #include <algorithm> | 14 #include <algorithm> |
| 14 #include <set> | 15 #include <set> |
| 15 #include <string> | 16 #include <string> |
| 16 | 17 |
| 17 #include "webrtc/base/buffer.h" | 18 #include "webrtc/base/buffer.h" |
| 18 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 19 #include "webrtc/base/stringutils.h" | 20 #include "webrtc/base/stringutils.h" |
| 20 #include "webrtc/base/timeutils.h" | 21 #include "webrtc/base/timeutils.h" |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 if (enable && options) { | 963 if (enable && options) { |
| 963 VideoSendParameters new_params = send_params_; | 964 VideoSendParameters new_params = send_params_; |
| 964 new_params.options.SetAll(*options); | 965 new_params.options.SetAll(*options); |
| 965 SetSendParameters(send_params_); | 966 SetSendParameters(send_params_); |
| 966 } | 967 } |
| 967 return true; | 968 return true; |
| 968 } | 969 } |
| 969 | 970 |
| 970 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( | 971 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
| 971 const StreamParams& sp) const { | 972 const StreamParams& sp) const { |
| 972 for (uint32_t ssrc : sp.ssrcs) { | 973 for (uint32_t ssrc: sp.ssrcs) { |
| 973 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { | 974 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
| 974 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; | 975 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; |
| 975 return false; | 976 return false; |
| 976 } | 977 } |
| 977 } | 978 } |
| 978 return true; | 979 return true; |
| 979 } | 980 } |
| 980 | 981 |
| 981 bool WebRtcVideoChannel2::ValidateReceiveSsrcAvailability( | 982 bool WebRtcVideoChannel2::ValidateReceiveSsrcAvailability( |
| 982 const StreamParams& sp) const { | 983 const StreamParams& sp) const { |
| 983 for (uint32_t ssrc : sp.ssrcs) { | 984 for (uint32_t ssrc: sp.ssrcs) { |
| 984 if (receive_ssrcs_.find(ssrc) != receive_ssrcs_.end()) { | 985 if (receive_ssrcs_.find(ssrc) != receive_ssrcs_.end()) { |
| 985 LOG(LS_ERROR) << "Receive stream with SSRC '" << ssrc | 986 LOG(LS_ERROR) << "Receive stream with SSRC '" << ssrc |
| 986 << "' already exists."; | 987 << "' already exists."; |
| 987 return false; | 988 return false; |
| 988 } | 989 } |
| 989 } | 990 } |
| 990 return true; | 991 return true; |
| 991 } | 992 } |
| 992 | 993 |
| 993 bool WebRtcVideoChannel2::AddSendStream(const StreamParams& sp) { | 994 bool WebRtcVideoChannel2::AddSendStream(const StreamParams& sp) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 { | 1280 { |
| 1280 rtc::CritScope stream_lock(&stream_crit_); | 1281 rtc::CritScope stream_lock(&stream_crit_); |
| 1281 if (send_streams_.find(ssrc) == send_streams_.end()) { | 1282 if (send_streams_.find(ssrc) == send_streams_.end()) { |
| 1282 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1283 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
| 1283 return false; | 1284 return false; |
| 1284 } | 1285 } |
| 1285 if (!send_streams_[ssrc]->SetCapturer(capturer)) { | 1286 if (!send_streams_[ssrc]->SetCapturer(capturer)) { |
| 1286 return false; | 1287 return false; |
| 1287 } | 1288 } |
| 1288 } | 1289 } |
| 1290 |
| 1291 if (capturer) { |
| 1292 capturer->SetApplyRotation(!ContainsHeaderExtension( |
| 1293 send_rtp_extensions_, kRtpVideoRotationHeaderExtension)); |
| 1294 } |
| 1289 { | 1295 { |
| 1290 rtc::CritScope lock(&capturer_crit_); | 1296 rtc::CritScope lock(&capturer_crit_); |
| 1291 capturers_[ssrc] = capturer; | 1297 capturers_[ssrc] = capturer; |
| 1292 } | 1298 } |
| 1293 return true; | 1299 return true; |
| 1294 } | 1300 } |
| 1295 | 1301 |
| 1296 void WebRtcVideoChannel2::OnPacketReceived( | 1302 void WebRtcVideoChannel2::OnPacketReceived( |
| 1297 rtc::Buffer* packet, | 1303 rtc::Buffer* packet, |
| 1298 const rtc::PacketTime& packet_time) { | 1304 const rtc::PacketTime& packet_time) { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, | 1548 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, |
| 1543 (width + 1) / 2); | 1549 (width + 1) / 2); |
| 1544 memset(video_frame->buffer(webrtc::kYPlane), 16, | 1550 memset(video_frame->buffer(webrtc::kYPlane), 16, |
| 1545 video_frame->allocated_size(webrtc::kYPlane)); | 1551 video_frame->allocated_size(webrtc::kYPlane)); |
| 1546 memset(video_frame->buffer(webrtc::kUPlane), 128, | 1552 memset(video_frame->buffer(webrtc::kUPlane), 128, |
| 1547 video_frame->allocated_size(webrtc::kUPlane)); | 1553 video_frame->allocated_size(webrtc::kUPlane)); |
| 1548 memset(video_frame->buffer(webrtc::kVPlane), 128, | 1554 memset(video_frame->buffer(webrtc::kVPlane), 128, |
| 1549 video_frame->allocated_size(webrtc::kVPlane)); | 1555 video_frame->allocated_size(webrtc::kVPlane)); |
| 1550 } | 1556 } |
| 1551 | 1557 |
| 1552 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( | 1558 void WebRtcVideoChannel2::WebRtcVideoSendStream::InputFrame( |
| 1553 const VideoFrame& frame) { | 1559 VideoCapturer* capturer, |
| 1554 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); | 1560 const VideoFrame* frame) { |
| 1555 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, | 1561 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::InputFrame"); |
| 1556 frame.GetVideoRotation()); | 1562 webrtc::VideoFrame video_frame(frame->GetVideoFrameBuffer(), 0, 0, |
| 1563 frame->GetVideoRotation()); |
| 1557 rtc::CritScope cs(&lock_); | 1564 rtc::CritScope cs(&lock_); |
| 1558 if (stream_ == NULL) { | 1565 if (stream_ == NULL) { |
| 1559 // Frame input before send codecs are configured, dropping frame. | 1566 // Frame input before send codecs are configured, dropping frame. |
| 1560 return; | 1567 return; |
| 1561 } | 1568 } |
| 1562 | 1569 |
| 1563 // Not sending, abort early to prevent expensive reconfigurations while | 1570 // Not sending, abort early to prevent expensive reconfigurations while |
| 1564 // setting up codecs etc. | 1571 // setting up codecs etc. |
| 1565 if (!sending_) | 1572 if (!sending_) |
| 1566 return; | 1573 return; |
| 1567 | 1574 |
| 1568 if (muted_) { | 1575 if (muted_) { |
| 1569 // Create a black frame to transmit instead. | 1576 // Create a black frame to transmit instead. |
| 1570 CreateBlackFrame(&video_frame, static_cast<int>(frame.GetWidth()), | 1577 CreateBlackFrame(&video_frame, |
| 1571 static_cast<int>(frame.GetHeight())); | 1578 static_cast<int>(frame->GetWidth()), |
| 1579 static_cast<int>(frame->GetHeight())); |
| 1572 } | 1580 } |
| 1573 | 1581 |
| 1574 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1582 int64_t frame_delta_ms = frame->GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
| 1575 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1583 // frame->GetTimeStamp() is essentially a delta, align to webrtc time |
| 1576 if (first_frame_timestamp_ms_ == 0) { | 1584 if (first_frame_timestamp_ms_ == 0) { |
| 1577 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; | 1585 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; |
| 1578 } | 1586 } |
| 1579 | 1587 |
| 1580 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; | 1588 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
| 1581 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1589 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| 1582 // Reconfigure codec if necessary. | 1590 // Reconfigure codec if necessary. |
| 1583 SetDimensions(video_frame.width(), video_frame.height(), | 1591 SetDimensions( |
| 1584 capturer_->IsScreencast()); | 1592 video_frame.width(), video_frame.height(), capturer->IsScreencast()); |
| 1585 | 1593 |
| 1586 stream_->Input()->IncomingCapturedFrame(video_frame); | 1594 stream_->Input()->IncomingCapturedFrame(video_frame); |
| 1587 } | 1595 } |
| 1588 | 1596 |
| 1589 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( | 1597 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( |
| 1590 VideoCapturer* capturer) { | 1598 VideoCapturer* capturer) { |
| 1591 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); | 1599 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); |
| 1592 if (!DisconnectCapturer() && capturer == NULL) { | 1600 if (!DisconnectCapturer() && capturer == NULL) { |
| 1593 return false; | 1601 return false; |
| 1594 } | 1602 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1616 last_frame_timestamp_ms_ += 1; | 1624 last_frame_timestamp_ms_ += 1; |
| 1617 black_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1625 black_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| 1618 stream_->Input()->IncomingCapturedFrame(black_frame); | 1626 stream_->Input()->IncomingCapturedFrame(black_frame); |
| 1619 } | 1627 } |
| 1620 | 1628 |
| 1621 capturer_ = NULL; | 1629 capturer_ = NULL; |
| 1622 return true; | 1630 return true; |
| 1623 } | 1631 } |
| 1624 | 1632 |
| 1625 capturer_ = capturer; | 1633 capturer_ = capturer; |
| 1626 capturer_->AddOrUpdateSink(this, sink_wants_); | |
| 1627 } | 1634 } |
| 1635 // Lock cannot be held while connecting the capturer to prevent lock-order |
| 1636 // violations. |
| 1637 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); |
| 1628 return true; | 1638 return true; |
| 1629 } | 1639 } |
| 1630 | 1640 |
| 1631 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { | 1641 void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { |
| 1632 rtc::CritScope cs(&lock_); | 1642 rtc::CritScope cs(&lock_); |
| 1633 muted_ = mute; | 1643 muted_ = mute; |
| 1634 } | 1644 } |
| 1635 | 1645 |
| 1636 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { | 1646 bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { |
| 1637 cricket::VideoCapturer* capturer; | 1647 cricket::VideoCapturer* capturer; |
| 1638 { | 1648 { |
| 1639 rtc::CritScope cs(&lock_); | 1649 rtc::CritScope cs(&lock_); |
| 1640 if (capturer_ == NULL) | 1650 if (capturer_ == NULL) |
| 1641 return false; | 1651 return false; |
| 1642 | 1652 |
| 1643 if (capturer_->video_adapter() != nullptr) | 1653 if (capturer_->video_adapter() != nullptr) |
| 1644 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); | 1654 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); |
| 1645 | 1655 |
| 1646 capturer = capturer_; | 1656 capturer = capturer_; |
| 1647 capturer_ = NULL; | 1657 capturer_ = NULL; |
| 1648 } | 1658 } |
| 1649 capturer->RemoveSink(this); | 1659 capturer->SignalVideoFrame.disconnect(this); |
| 1650 | |
| 1651 return true; | 1660 return true; |
| 1652 } | 1661 } |
| 1653 | 1662 |
| 1654 const std::vector<uint32_t>& | 1663 const std::vector<uint32_t>& |
| 1655 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1664 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
| 1656 return ssrcs_; | 1665 return ssrcs_; |
| 1657 } | 1666 } |
| 1658 | 1667 |
| 1659 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1668 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
| 1660 const VideoOptions& options) { | 1669 const VideoOptions& options) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 rtc::CritScope cs(&lock_); | 1787 rtc::CritScope cs(&lock_); |
| 1779 // |recreate_stream| means construction-time parameters have changed and the | 1788 // |recreate_stream| means construction-time parameters have changed and the |
| 1780 // sending stream needs to be reset with the new config. | 1789 // sending stream needs to be reset with the new config. |
| 1781 bool recreate_stream = false; | 1790 bool recreate_stream = false; |
| 1782 if (params.rtcp_mode) { | 1791 if (params.rtcp_mode) { |
| 1783 parameters_.config.rtp.rtcp_mode = *params.rtcp_mode; | 1792 parameters_.config.rtp.rtcp_mode = *params.rtcp_mode; |
| 1784 recreate_stream = true; | 1793 recreate_stream = true; |
| 1785 } | 1794 } |
| 1786 if (params.rtp_header_extensions) { | 1795 if (params.rtp_header_extensions) { |
| 1787 parameters_.config.rtp.extensions = *params.rtp_header_extensions; | 1796 parameters_.config.rtp.extensions = *params.rtp_header_extensions; |
| 1788 sink_wants_.rotation_applied = !ContainsHeaderExtension( | |
| 1789 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); | |
| 1790 if (capturer_) { | 1797 if (capturer_) { |
| 1791 capturer_->AddOrUpdateSink(this, sink_wants_); | 1798 capturer_->SetApplyRotation(!ContainsHeaderExtension( |
| 1799 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension)); |
| 1792 } | 1800 } |
| 1793 recreate_stream = true; | 1801 recreate_stream = true; |
| 1794 } | 1802 } |
| 1795 if (params.max_bandwidth_bps) { | 1803 if (params.max_bandwidth_bps) { |
| 1796 // Max bitrate has changed, reconfigure encoder settings on the next frame | 1804 // Max bitrate has changed, reconfigure encoder settings on the next frame |
| 1797 // or stream recreation. | 1805 // or stream recreation. |
| 1798 parameters_.max_bitrate_bps = *params.max_bandwidth_bps; | 1806 parameters_.max_bitrate_bps = *params.max_bandwidth_bps; |
| 1799 pending_encoder_reconfiguration_ = true; | 1807 pending_encoder_reconfiguration_ = true; |
| 1800 } | 1808 } |
| 1801 // Set codecs and options. | 1809 // Set codecs and options. |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2490 rtx_mapping[video_codecs[i].codec.id] != | 2498 rtx_mapping[video_codecs[i].codec.id] != |
| 2491 fec_settings.red_payload_type) { | 2499 fec_settings.red_payload_type) { |
| 2492 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2500 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2493 } | 2501 } |
| 2494 } | 2502 } |
| 2495 | 2503 |
| 2496 return video_codecs; | 2504 return video_codecs; |
| 2497 } | 2505 } |
| 2498 | 2506 |
| 2499 } // namespace cricket | 2507 } // namespace cricket |
| 2508 |
| 2509 #endif // HAVE_WEBRTC_VIDEO |
| OLD | NEW |