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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 if (!MuteStream(ssrc, !enable)) { | 922 if (!MuteStream(ssrc, !enable)) { |
| 923 return false; | 923 return false; |
| 924 } | 924 } |
| 925 if (enable && options) { | 925 if (enable && options) { |
| 926 return SetOptions(*options); | 926 return SetOptions(*options); |
| 927 } else { | 927 } else { |
| 928 return true; | 928 return true; |
| 929 } | 929 } |
| 930 } | 930 } |
| 931 | 931 |
| 932 rtc::VideoSinkInterface<cricket::VideoFrame>* WebRtcVideoChannel2::GetSink( | |
| 933 uint32_t ssrc) { | |
| 934 rtc::CritScope stream_lock(&stream_crit_); | |
| 935 if (send_streams_.find(ssrc) == send_streams_.end()) { | |
| 936 return NULL; | |
| 937 } | |
| 938 return send_streams_[ssrc]; | |
| 939 } | |
| 940 | |
| 932 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( | 941 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
| 933 const StreamParams& sp) const { | 942 const StreamParams& sp) const { |
| 934 for (uint32_t ssrc: sp.ssrcs) { | 943 for (uint32_t ssrc: sp.ssrcs) { |
| 935 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { | 944 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
| 936 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; | 945 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; |
| 937 return false; | 946 return false; |
| 938 } | 947 } |
| 939 } | 948 } |
| 940 return true; | 949 return true; |
| 941 } | 950 } |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1633 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, | 1642 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, |
| 1634 (width + 1) / 2); | 1643 (width + 1) / 2); |
| 1635 memset(video_frame->buffer(webrtc::kYPlane), 16, | 1644 memset(video_frame->buffer(webrtc::kYPlane), 16, |
| 1636 video_frame->allocated_size(webrtc::kYPlane)); | 1645 video_frame->allocated_size(webrtc::kYPlane)); |
| 1637 memset(video_frame->buffer(webrtc::kUPlane), 128, | 1646 memset(video_frame->buffer(webrtc::kUPlane), 128, |
| 1638 video_frame->allocated_size(webrtc::kUPlane)); | 1647 video_frame->allocated_size(webrtc::kUPlane)); |
| 1639 memset(video_frame->buffer(webrtc::kVPlane), 128, | 1648 memset(video_frame->buffer(webrtc::kVPlane), 128, |
| 1640 video_frame->allocated_size(webrtc::kVPlane)); | 1649 video_frame->allocated_size(webrtc::kVPlane)); |
| 1641 } | 1650 } |
| 1642 | 1651 |
| 1643 void WebRtcVideoChannel2::WebRtcVideoSendStream::InputFrame( | 1652 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( |
| 1644 VideoCapturer* capturer, | 1653 const cricket::VideoFrame& frame) { |
| 1645 const VideoFrame* frame) { | 1654 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); |
| 1646 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::InputFrame"); | 1655 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0, |
| 1647 webrtc::VideoFrame video_frame(frame->GetVideoFrameBuffer(), 0, 0, | 1656 frame.GetVideoRotation()); |
| 1648 frame->GetVideoRotation()); | |
| 1649 rtc::CritScope cs(&lock_); | 1657 rtc::CritScope cs(&lock_); |
| 1650 if (stream_ == NULL) { | 1658 if (stream_ == NULL) { |
| 1651 // Frame input before send codecs are configured, dropping frame. | 1659 // Frame input before send codecs are configured, dropping frame. |
| 1652 return; | 1660 return; |
| 1653 } | 1661 } |
| 1654 | 1662 |
| 1655 // Not sending, abort early to prevent expensive reconfigurations while | 1663 // Not sending, abort early to prevent expensive reconfigurations while |
| 1656 // setting up codecs etc. | 1664 // setting up codecs etc. |
| 1657 if (!sending_) | 1665 if (!sending_) |
| 1658 return; | 1666 return; |
| 1659 | 1667 |
| 1660 if (format_.width == 0) { // Dropping frames. | 1668 if (format_.width == 0) { // Dropping frames. |
| 1661 RTC_DCHECK(format_.height == 0); | 1669 RTC_DCHECK(format_.height == 0); |
| 1662 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; | 1670 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; |
| 1663 return; | 1671 return; |
| 1664 } | 1672 } |
| 1665 if (muted_) { | |
| 1666 // Create a black frame to transmit instead. | |
| 1667 CreateBlackFrame(&video_frame, | |
| 1668 static_cast<int>(frame->GetWidth()), | |
| 1669 static_cast<int>(frame->GetHeight())); | |
| 1670 } | |
| 1671 | 1673 |
| 1672 int64_t frame_delta_ms = frame->GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 1674 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |
| 1673 // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 1675 // frame.GetTimeStamp() is essentially a delta, align to webrtc time |
| 1674 if (first_frame_timestamp_ms_ == 0) { | 1676 if (first_frame_timestamp_ms_ == 0) { |
| 1675 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; | 1677 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; |
| 1676 } | 1678 } |
| 1677 | 1679 |
| 1678 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; | 1680 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
| 1679 video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1681 video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| 1680 // Reconfigure codec if necessary. | 1682 // Reconfigure codec if necessary. |
| 1681 SetDimensions( | 1683 SetDimensions( |
| 1682 video_frame.width(), video_frame.height(), capturer->IsScreencast()); | 1684 // TODO(nisse): Get screencast flag from video options. |
|
perkj_webrtc
2016/01/26 15:40:56
capturer_->IsScreencast() for the time beeing. cas
nisse-webrtc
2016/01/28 08:24:54
I'm adding an is_screencast_ member, set by SetCap
| |
| 1685 video_frame.width(), video_frame.height(), false /* is_screencast */); | |
| 1683 | 1686 |
| 1684 stream_->Input()->IncomingCapturedFrame(video_frame); | 1687 stream_->Input()->IncomingCapturedFrame(video_frame); |
| 1685 } | 1688 } |
| 1686 | 1689 |
| 1687 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( | 1690 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( |
| 1688 VideoCapturer* capturer) { | 1691 VideoCapturer* capturer) { |
| 1689 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); | 1692 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); |
| 1690 if (!DisconnectCapturer() && capturer == NULL) { | 1693 if (!DisconnectCapturer() && capturer == NULL) { |
| 1691 return false; | 1694 return false; |
| 1692 } | 1695 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1716 black_frame.set_render_time_ms(last_frame_timestamp_ms_); | 1719 black_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| 1717 stream_->Input()->IncomingCapturedFrame(black_frame); | 1720 stream_->Input()->IncomingCapturedFrame(black_frame); |
| 1718 } | 1721 } |
| 1719 | 1722 |
| 1720 capturer_ = NULL; | 1723 capturer_ = NULL; |
| 1721 return true; | 1724 return true; |
| 1722 } | 1725 } |
| 1723 | 1726 |
| 1724 capturer_ = capturer; | 1727 capturer_ = capturer; |
| 1725 } | 1728 } |
| 1726 // Lock cannot be held while connecting the capturer to prevent lock-order | |
| 1727 // violations. | |
| 1728 capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); | |
| 1729 return true; | 1729 return true; |
| 1730 } | 1730 } |
| 1731 | 1731 |
| 1732 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( | 1732 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( |
| 1733 const VideoFormat& format) { | 1733 const VideoFormat& format) { |
| 1734 if ((format.width == 0 || format.height == 0) && | 1734 if ((format.width == 0 || format.height == 0) && |
| 1735 format.width != format.height) { | 1735 format.width != format.height) { |
| 1736 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " | 1736 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " |
| 1737 "both, 0x0 drops frames)."; | 1737 "both, 0x0 drops frames)."; |
| 1738 return false; | 1738 return false; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1765 rtc::CritScope cs(&lock_); | 1765 rtc::CritScope cs(&lock_); |
| 1766 if (capturer_ == NULL) | 1766 if (capturer_ == NULL) |
| 1767 return false; | 1767 return false; |
| 1768 | 1768 |
| 1769 if (capturer_->video_adapter() != nullptr) | 1769 if (capturer_->video_adapter() != nullptr) |
| 1770 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); | 1770 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); |
| 1771 | 1771 |
| 1772 capturer = capturer_; | 1772 capturer = capturer_; |
| 1773 capturer_ = NULL; | 1773 capturer_ = NULL; |
| 1774 } | 1774 } |
| 1775 capturer->SignalVideoFrame.disconnect(this); | |
| 1776 return true; | 1775 return true; |
| 1777 } | 1776 } |
| 1778 | 1777 |
| 1779 const std::vector<uint32_t>& | 1778 const std::vector<uint32_t>& |
| 1780 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1779 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
| 1781 return ssrcs_; | 1780 return ssrcs_; |
| 1782 } | 1781 } |
| 1783 | 1782 |
| 1784 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetApplyRotation( | 1783 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetApplyRotation( |
| 1785 bool apply_rotation) { | 1784 bool apply_rotation) { |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2626 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2625 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2627 } | 2626 } |
| 2628 } | 2627 } |
| 2629 | 2628 |
| 2630 return video_codecs; | 2629 return video_codecs; |
| 2631 } | 2630 } |
| 2632 | 2631 |
| 2633 } // namespace cricket | 2632 } // namespace cricket |
| 2634 | 2633 |
| 2635 #endif // HAVE_WEBRTC_VIDEO | 2634 #endif // HAVE_WEBRTC_VIDEO |
| OLD | NEW |