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

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

Issue 1655793003: Make cricket::VideoCapturer implement VideoSourceInterface (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding VideoSourceInterface and letting cricket::VideoCapturer implement it Created 4 years, 10 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 * 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 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 return false; 1009 return false;
1010 } 1010 }
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 rtc::VideoSinkInterface<cricket::VideoFrame>* WebRtcVideoChannel2::GetSink(
1020 uint32_t ssrc) {
1021 rtc::CritScope stream_lock(&stream_crit_);
1022 if (send_streams_.find(ssrc) == send_streams_.end()) {
1023 return NULL;
1024 }
1025 return send_streams_[ssrc];
1026 }
1027
1019 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( 1028 bool WebRtcVideoChannel2::ValidateSendSsrcAvailability(
1020 const StreamParams& sp) const { 1029 const StreamParams& sp) const {
1021 for (uint32_t ssrc: sp.ssrcs) { 1030 for (uint32_t ssrc: sp.ssrcs) {
1022 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { 1031 if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) {
1023 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; 1032 LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists.";
1024 return false; 1033 return false;
1025 } 1034 }
1026 } 1035 }
1027 return true; 1036 return true;
1028 } 1037 }
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, 1625 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2,
1617 (width + 1) / 2); 1626 (width + 1) / 2);
1618 memset(video_frame->buffer(webrtc::kYPlane), 16, 1627 memset(video_frame->buffer(webrtc::kYPlane), 16,
1619 video_frame->allocated_size(webrtc::kYPlane)); 1628 video_frame->allocated_size(webrtc::kYPlane));
1620 memset(video_frame->buffer(webrtc::kUPlane), 128, 1629 memset(video_frame->buffer(webrtc::kUPlane), 128,
1621 video_frame->allocated_size(webrtc::kUPlane)); 1630 video_frame->allocated_size(webrtc::kUPlane));
1622 memset(video_frame->buffer(webrtc::kVPlane), 128, 1631 memset(video_frame->buffer(webrtc::kVPlane), 128,
1623 video_frame->allocated_size(webrtc::kVPlane)); 1632 video_frame->allocated_size(webrtc::kVPlane));
1624 } 1633 }
1625 1634
1626 void WebRtcVideoChannel2::WebRtcVideoSendStream::InputFrame( 1635 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame(
1627 VideoCapturer* capturer, 1636 const cricket::VideoFrame& frame) {
1628 const VideoFrame* frame) { 1637 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame");
1629 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::InputFrame"); 1638 webrtc::VideoFrame video_frame(frame.GetVideoFrameBuffer(), 0, 0,
1630 webrtc::VideoFrame video_frame(frame->GetVideoFrameBuffer(), 0, 0, 1639 frame.GetVideoRotation());
1631 frame->GetVideoRotation());
1632 rtc::CritScope cs(&lock_); 1640 rtc::CritScope cs(&lock_);
1633 if (stream_ == NULL) { 1641 if (stream_ == NULL) {
1634 // Frame input before send codecs are configured, dropping frame. 1642 // Frame input before send codecs are configured, dropping frame.
1635 return; 1643 return;
1636 } 1644 }
1637 1645
1638 // Not sending, abort early to prevent expensive reconfigurations while 1646 // Not sending, abort early to prevent expensive reconfigurations while
1639 // setting up codecs etc. 1647 // setting up codecs etc.
1640 if (!sending_) 1648 if (!sending_)
1641 return; 1649 return;
1642 1650
1643 if (format_.width == 0) { // Dropping frames. 1651 if (format_.width == 0) { // Dropping frames.
1644 RTC_DCHECK(format_.height == 0); 1652 RTC_DCHECK(format_.height == 0);
1645 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; 1653 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame.";
1646 return; 1654 return;
1647 } 1655 }
1648 if (muted_) {
1649 // Create a black frame to transmit instead.
1650 CreateBlackFrame(&video_frame,
1651 static_cast<int>(frame->GetWidth()),
1652 static_cast<int>(frame->GetHeight()));
1653 }
pthatcher 2016/02/01 18:40:54 It can't be muted any more?
perkj_webrtc 2016/02/02 16:24:00 Muted as was moved to the track enabled/disabled b
1654 1656
1655 int64_t frame_delta_ms = frame->GetTimeStamp() / rtc::kNumNanosecsPerMillisec; 1657 int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec;
1656 // frame->GetTimeStamp() is essentially a delta, align to webrtc time 1658 // frame.GetTimeStamp() is essentially a delta, align to webrtc time
1657 if (first_frame_timestamp_ms_ == 0) { 1659 if (first_frame_timestamp_ms_ == 0) {
1658 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms; 1660 first_frame_timestamp_ms_ = rtc::Time() - frame_delta_ms;
1659 } 1661 }
1660 1662
1661 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; 1663 last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms;
1662 video_frame.set_render_time_ms(last_frame_timestamp_ms_); 1664 video_frame.set_render_time_ms(last_frame_timestamp_ms_);
1663 // Reconfigure codec if necessary. 1665 // Reconfigure codec if necessary.
1664 SetDimensions( 1666 SetDimensions(
1665 video_frame.width(), video_frame.height(), capturer->IsScreencast()); 1667 video_frame.width(), video_frame.height(), is_screencast_);
1666 1668
1667 stream_->Input()->IncomingCapturedFrame(video_frame); 1669 stream_->Input()->IncomingCapturedFrame(video_frame);
1668 } 1670 }
1669 1671
1670 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( 1672 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer(
1671 VideoCapturer* capturer) { 1673 VideoCapturer* capturer) {
1672 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); 1674 TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer");
1673 if (!DisconnectCapturer() && capturer == NULL) { 1675 if (!DisconnectCapturer() && capturer == NULL) {
1674 return false; 1676 return false;
1675 } 1677 }
(...skipping 22 matching lines...) Expand all
1698 format_.interval / rtc::kNumNanosecsPerMillisec; 1700 format_.interval / rtc::kNumNanosecsPerMillisec;
1699 black_frame.set_render_time_ms(last_frame_timestamp_ms_); 1701 black_frame.set_render_time_ms(last_frame_timestamp_ms_);
1700 stream_->Input()->IncomingCapturedFrame(black_frame); 1702 stream_->Input()->IncomingCapturedFrame(black_frame);
1701 } 1703 }
1702 1704
1703 capturer_ = NULL; 1705 capturer_ = NULL;
1704 return true; 1706 return true;
1705 } 1707 }
1706 1708
1707 capturer_ = capturer; 1709 capturer_ = capturer;
1710 is_screencast_ = capturer_ ? capturer_->IsScreencast() : false;
1708 } 1711 }
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; 1712 return true;
1713 } 1713 }
1714 1714
1715 // TODO(pbos): Apply this on the VideoAdapter instead! 1715 // TODO(pbos): Apply this on the VideoAdapter instead!
1716 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( 1716 bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat(
1717 const VideoFormat& format) { 1717 const VideoFormat& format) {
1718 if ((format.width == 0 || format.height == 0) && 1718 if ((format.width == 0 || format.height == 0) &&
1719 format.width != format.height) { 1719 format.width != format.height) {
1720 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " 1720 LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not "
1721 "both, 0x0 drops frames)."; 1721 "both, 0x0 drops frames).";
(...skipping 27 matching lines...) Expand all
1749 rtc::CritScope cs(&lock_); 1749 rtc::CritScope cs(&lock_);
1750 if (capturer_ == NULL) 1750 if (capturer_ == NULL)
1751 return false; 1751 return false;
1752 1752
1753 if (capturer_->video_adapter() != nullptr) 1753 if (capturer_->video_adapter() != nullptr)
1754 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); 1754 old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes();
1755 1755
1756 capturer = capturer_; 1756 capturer = capturer_;
1757 capturer_ = NULL; 1757 capturer_ = NULL;
1758 } 1758 }
1759 capturer->SignalVideoFrame.disconnect(this);
1760 return true; 1759 return true;
1761 } 1760 }
1762 1761
1763 const std::vector<uint32_t>& 1762 const std::vector<uint32_t>&
1764 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { 1763 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const {
1765 return ssrcs_; 1764 return ssrcs_;
1766 } 1765 }
1767 1766
1768 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( 1767 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions(
1769 const VideoOptions& options) { 1768 const VideoOptions& options) {
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2604 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2606 } 2605 }
2607 } 2606 }
2608 2607
2609 return video_codecs; 2608 return video_codecs;
2610 } 2609 }
2611 2610
2612 } // namespace cricket 2611 } // namespace cricket
2613 2612
2614 #endif // HAVE_WEBRTC_VIDEO 2613 #endif // HAVE_WEBRTC_VIDEO
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698