Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 if (enable && options) { | 1011 if (enable && options) { |
| 1012 VideoSendParameters new_params = send_params_; | 1012 VideoSendParameters new_params = send_params_; |
| 1013 new_params.options.SetAll(*options); | 1013 new_params.options.SetAll(*options); |
| 1014 SetSendParameters(send_params_); | 1014 SetSendParameters(send_params_); |
| 1015 } | 1015 } |
| 1016 return true; | 1016 return true; |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( | 1019 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
| 1020 const StreamParams& sp) const { | 1020 const StreamParams& sp) const { |
| 1021 for (uint32_t ssrc: sp.ssrcs) { | 1021 for (uint32_t ssrc : sp.ssrcs) { |
|
nisse-webrtc
2016/02/03 09:16:34
Unrelated change.
perkj_webrtc
2016/02/08 14:32:01
yes. git cl format, git cl lint.
| |
| 1022 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { | 1022 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
| 1023 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; | 1023 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; |
| 1024 return false; | 1024 return false; |
| 1025 } | 1025 } |
| 1026 } | 1026 } |
| 1027 return true; | 1027 return true; |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 bool WebRtcVideoChannel2::ValidateReceiveSsrcAvailability( | 1030 bool WebRtcVideoChannel2::ValidateReceiveSsrcAvailability( |
| 1031 const StreamParams& sp) const { | 1031 const StreamParams& sp) const { |
| 1032 for (uint32_t ssrc: sp.ssrcs) { | 1032 for (uint32_t ssrc : sp.ssrcs) { |
| 1033 if (receive_ssrcs_.find(ssrc) != receive_ssrcs_.end()) { | 1033 if (receive_ssrcs_.find(ssrc) != receive_ssrcs_.end()) { |
| 1034 LOG(LS_ERROR) << "Receive stream with SSRC '" << ssrc | 1034 LOG(LS_ERROR) << "Receive stream with SSRC '" << ssrc |
| 1035 << "' already exists."; | 1035 << "' already exists."; |
| 1036 return false; | 1036 return false; |
| 1037 } | 1037 } |
| 1038 } | 1038 } |
| 1039 return true; | 1039 return true; |
| 1040 } | 1040 } |
| 1041 | 1041 |
| 1042 bool WebRtcVideoChannel2::AddSendStream(const StreamParams& sp) { | 1042 bool WebRtcVideoChannel2::AddSendStream(const StreamParams& sp) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 { | 1328 { |
| 1329 rtc::CritScope stream_lock(&stream_crit_); | 1329 rtc::CritScope stream_lock(&stream_crit_); |
| 1330 if (send_streams_.find(ssrc) == send_streams_.end()) { | 1330 if (send_streams_.find(ssrc) == send_streams_.end()) { |
| 1331 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1331 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
| 1332 return false; | 1332 return false; |
| 1333 } | 1333 } |
| 1334 if (!send_streams_[ssrc]->SetCapturer(capturer)) { | 1334 if (!send_streams_[ssrc]->SetCapturer(capturer)) { |
| 1335 return false; | 1335 return false; |
| 1336 } | 1336 } |
| 1337 } | 1337 } |
| 1338 | |
| 1339 if (capturer) { | |
| 1340 capturer->SetApplyRotation(!ContainsHeaderExtension( | |
| 1341 send_rtp_extensions_, kRtpVideoRotationHeaderExtension)); | |
| 1342 } | |
| 1343 { | 1338 { |
| 1344 rtc::CritScope lock(&capturer_crit_); | 1339 rtc::CritScope lock(&capturer_crit_); |
| 1345 capturers_[ssrc] = capturer; | 1340 capturers_[ssrc] = capturer; |
| 1346 } | 1341 } |
| 1347 return true; | 1342 return true; |
| 1348 } | 1343 } |
| 1349 | 1344 |
| 1350 bool WebRtcVideoChannel2::SendIntraFrame() { | 1345 bool WebRtcVideoChannel2::SendIntraFrame() { |
| 1351 // TODO(pbos): Implement. | 1346 // TODO(pbos): Implement. |
| 1352 LOG(LS_VERBOSE) << "SendIntraFrame()."; | 1347 LOG(LS_VERBOSE) << "SendIntraFrame()."; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1616 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, | 1611 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, |
| 1617 (width + 1) / 2); | 1612 (width + 1) / 2); |
| 1618 memset(video_frame->buffer(webrtc::kYPlane), 16, | 1613 memset(video_frame->buffer(webrtc::kYPlane), 16, |
| 1619 video_frame->allocated_size(webrtc::kYPlane)); | 1614 video_frame->allocated_size(webrtc::kYPlane)); |
| 1620 memset(video_frame->buffer(webrtc::kUPlane), 128, | 1615 memset(video_frame->buffer(webrtc::kUPlane), 128, |
| 1621 video_frame->allocated_size(webrtc::kUPlane)); | 1616 video_frame->allocated_size(webrtc::kUPlane)); |
| 1622 memset(video_frame->buffer(webrtc::kVPlane), 128, | 1617 memset(video_frame->buffer(webrtc::kVPlane), 128, |
| 1623 video_frame->allocated_size(webrtc::kVPlane)); | 1618 video_frame->allocated_size(webrtc::kVPlane)); |
| 1624 } | 1619 } |
| 1625 | 1620 |
| 1626 void WebRtcVideoChannel2::WebRtcVideoSendStream::InputFrame( | 1621 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( |
| 1627 VideoCapturer* capturer, | 1622 const VideoFrame& frame) { |
| 1628 const VideoFrame* frame) { | 1623 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); |
| 1629 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::InputFrame"); | 1624 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, |
| 1630 webrtc::VideoFrame video_frame(frame->GetVideoFrameBuffer(), 0, 0, | 1625 frame.GetVideoRotation()); |
| 1631 frame->GetVideoRotation()); | |
| 1632 rtc::CritScope cs(&lock_); | 1626 rtc::CritScope cs(&lock_); |
| 1633 if (stream_ == NULL) { | 1627 if (stream_ == NULL) { |
| 1634 // Frame input before send codecs are configured, dropping frame. | 1628 // Frame input before send codecs are configured, dropping frame. |
| 1635 return; | 1629 return; |
| 1636 } | 1630 } |
| 1637 | 1631 |
| 1638 // Not sending, abort early to prevent expensive reconfigurations while | 1632 // Not sending, abort early to prevent expensive reconfigurations while |
| 1639 // setting up codecs etc. | 1633 // setting up codecs etc. |
| 1640 if (!sending_) | 1634 if (!sending_) |
| 1641 return; | 1635 return; |
| 1642 | 1636 |
| 1643 if (format_.width == 0) { // Dropping frames. | 1637 if (format_.width == 0) { // Dropping frames. |
| 1644 RTC_DCHECK(format_.height == 0); | 1638 RTC_DCHECK(format_.height == 0); |
| 1645 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; | 1639 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; |
| 1646 return; | 1640 return; |
| 1647 } | 1641 } |
| 1648 if (muted_) { | 1642 if (muted_) { |
| 1649 // Create a black frame to transmit instead. | 1643 // Create a black frame to transmit instead. |
| 1650 CreateBlackFrame(&video_frame, | 1644 CreateBlackFrame(&video_frame, static_cast<int>(frame.GetWidth()), |
| 1651 static_cast<int>(frame->GetWidth()), | 1645 static_cast<int>(frame.GetHeight())); |
| 1652 static_cast<int>(frame->GetHeight())); | |
| 1653 } | 1646 } |
| 1654 | 1647 |
| 1655 int64_t frame_delta_ms = frame->GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1648 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
| 1656 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1649 // frame->GetTimeStamp() is essentially a delta, align to webrtc time |
| 1657 if (first_frame_timestamp_ms_ == 0) { | 1650 if (first_frame_timestamp_ms_ == 0) { |
| 1658 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; | 1651 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; |
| 1659 } | 1652 } |
| 1660 | 1653 |
| 1661 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; | 1654 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
| 1662 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1655 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| 1663 // Reconfigure codec if necessary. | 1656 // Reconfigure codec if necessary. |
| 1664 SetDimensions( | 1657 SetDimensions(video_frame.width(), video_frame.height(), |
| 1665 video_frame.width(), video_frame.height(), capturer->IsScreencast()); | 1658 capturer_->IsScreencast()); |
| 1666 | 1659 |
| 1667 stream_->Input()->IncomingCapturedFrame(video_frame); | 1660 stream_->Input()->IncomingCapturedFrame(video_frame); |
| 1668 } | 1661 } |
| 1669 | 1662 |
| 1670 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( | 1663 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( |
| 1671 VideoCapturer* capturer) { | 1664 VideoCapturer* capturer) { |
| 1672 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); | 1665 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); |
| 1673 if (!DisconnectCapturer() && capturer == NULL) { | 1666 if (!DisconnectCapturer() && capturer == NULL) { |
| 1674 return false; | 1667 return false; |
| 1675 } | 1668 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1698 format_.interval / rtc::kNumNanosecsPerMillisec; | 1691 format_.interval / rtc::kNumNanosecsPerMillisec; |
| 1699 black_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1692 black_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| 1700 stream_->Input()->IncomingCapturedFrame(black_frame); | 1693 stream_->Input()->IncomingCapturedFrame(black_frame); |
| 1701 } | 1694 } |
| 1702 | 1695 |
| 1703 capturer_ = NULL; | 1696 capturer_ = NULL; |
| 1704 return true; | 1697 return true; |
| 1705 } | 1698 } |
| 1706 | 1699 |
| 1707 capturer_ = capturer; | 1700 capturer_ = capturer; |
| 1701 capturer_->AddSink(this, sink_capabilities_); | |
|
pthatcher1
2016/02/03 15:38:36
I think it would be better to add capabilities() t
perkj_webrtc
2016/02/08 14:32:01
PTAL. I think I have now changed this to be as we
| |
| 1708 } | 1702 } |
| 1709 // Lock cannot be held while connecting the capturer to prevent lock-order | |
| 1710 // violations. | |
| 1711 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); | |
| 1712 return true; | 1703 return true; |
| 1713 } | 1704 } |
| 1714 | 1705 |
| 1715 // TODO(pbos): Apply this on the VideoAdapter instead! | 1706 // TODO(pbos): Apply this on the VideoAdapter instead! |
| 1716 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( | 1707 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( |
| 1717 const VideoFormat& format) { | 1708 const VideoFormat& format) { |
| 1718 if ((format.width == 0 || format.height == 0) && | 1709 if ((format.width == 0 || format.height == 0) && |
| 1719 format.width != format.height) { | 1710 format.width != format.height) { |
| 1720 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " | 1711 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " |
| 1721 "both, 0x0 drops frames)."; | 1712 "both, 0x0 drops frames)."; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1749 rtc::CritScope cs(&lock_); | 1740 rtc::CritScope cs(&lock_); |
| 1750 if (capturer_ == NULL) | 1741 if (capturer_ == NULL) |
| 1751 return false; | 1742 return false; |
| 1752 | 1743 |
| 1753 if (capturer_->video_adapter() != nullptr) | 1744 if (capturer_->video_adapter() != nullptr) |
| 1754 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); | 1745 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); |
| 1755 | 1746 |
| 1756 capturer = capturer_; | 1747 capturer = capturer_; |
| 1757 capturer_ = NULL; | 1748 capturer_ = NULL; |
| 1758 } | 1749 } |
| 1759 capturer->SignalVideoFrame.disconnect(this); | 1750 capturer->RemoveSink(this); |
| 1760 return true; | 1751 return true; |
| 1761 } | 1752 } |
| 1762 | 1753 |
| 1763 const std::vector<uint32_t>& | 1754 const std::vector<uint32_t>& |
| 1764 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1755 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
| 1765 return ssrcs_; | 1756 return ssrcs_; |
| 1766 } | 1757 } |
| 1767 | 1758 |
| 1768 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1759 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
| 1769 const VideoOptions& options) { | 1760 const VideoOptions& options) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1891 rtc::CritScope cs(&lock_); | 1882 rtc::CritScope cs(&lock_); |
| 1892 // |recreate_stream| means construction-time parameters have changed and the | 1883 // |recreate_stream| means construction-time parameters have changed and the |
| 1893 // sending stream needs to be reset with the new config. | 1884 // sending stream needs to be reset with the new config. |
| 1894 bool recreate_stream = false; | 1885 bool recreate_stream = false; |
| 1895 if (params.rtcp_mode) { | 1886 if (params.rtcp_mode) { |
| 1896 parameters_.config.rtp.rtcp_mode = *params.rtcp_mode; | 1887 parameters_.config.rtp.rtcp_mode = *params.rtcp_mode; |
| 1897 recreate_stream = true; | 1888 recreate_stream = true; |
| 1898 } | 1889 } |
| 1899 if (params.rtp_header_extensions) { | 1890 if (params.rtp_header_extensions) { |
| 1900 parameters_.config.rtp.extensions = *params.rtp_header_extensions; | 1891 parameters_.config.rtp.extensions = *params.rtp_header_extensions; |
| 1892 sink_capabilities_.can_apply_rotation = ContainsHeaderExtension( | |
| 1893 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); | |
| 1901 if (capturer_) { | 1894 if (capturer_) { |
| 1902 capturer_->SetApplyRotation(!ContainsHeaderExtension( | 1895 capturer_->RemoveSink(this); |
| 1903 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension)); | 1896 capturer_->AddSink(this, sink_capabilities_); |
|
pthatcher1
2016/02/03 15:38:36
Why not just fire SignalCapabilitiesChanged()?
perkj_webrtc
2016/02/08 14:32:01
PTAL
| |
| 1904 } | 1897 } |
| 1905 recreate_stream = true; | 1898 recreate_stream = true; |
| 1906 } | 1899 } |
| 1907 if (params.max_bandwidth_bps) { | 1900 if (params.max_bandwidth_bps) { |
| 1908 // Max bitrate has changed, reconfigure encoder settings on the next frame | 1901 // Max bitrate has changed, reconfigure encoder settings on the next frame |
| 1909 // or stream recreation. | 1902 // or stream recreation. |
| 1910 parameters_.max_bitrate_bps = *params.max_bandwidth_bps; | 1903 parameters_.max_bitrate_bps = *params.max_bandwidth_bps; |
| 1911 pending_encoder_reconfiguration_ = true; | 1904 pending_encoder_reconfiguration_ = true; |
| 1912 } | 1905 } |
| 1913 // Set codecs and options. | 1906 // Set codecs and options. |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2605 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2598 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2606 } | 2599 } |
| 2607 } | 2600 } |
| 2608 | 2601 |
| 2609 return video_codecs; | 2602 return video_codecs; |
| 2610 } | 2603 } |
| 2611 | 2604 |
| 2612 } // namespace cricket | 2605 } // namespace cricket |
| 2613 | 2606 |
| 2614 #endif // HAVE_WEBRTC_VIDEO | 2607 #endif // HAVE_WEBRTC_VIDEO |
| OLD | NEW |