OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/rtc_video_encoder.h" | 5 #include "content/renderer/media/rtc_video_encoder.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 DVLOG(1) << "InitEncode(): codecType=" << codec_settings->codecType | 733 DVLOG(1) << "InitEncode(): codecType=" << codec_settings->codecType |
734 << ", width=" << codec_settings->width | 734 << ", width=" << codec_settings->width |
735 << ", height=" << codec_settings->height | 735 << ", height=" << codec_settings->height |
736 << ", startBitrate=" << codec_settings->startBitrate; | 736 << ", startBitrate=" << codec_settings->startBitrate; |
737 DCHECK(!impl_.get()); | 737 DCHECK(!impl_.get()); |
738 | 738 |
739 impl_ = new Impl(gpu_factories_, video_codec_type_); | 739 impl_ = new Impl(gpu_factories_, video_codec_type_); |
740 const media::VideoCodecProfile profile = WebRTCVideoCodecToVideoCodecProfile( | 740 const media::VideoCodecProfile profile = WebRTCVideoCodecToVideoCodecProfile( |
741 impl_->video_codec_type(), codec_settings); | 741 impl_->video_codec_type(), codec_settings); |
742 | 742 |
743 base::WaitableEvent initialization_waiter(true, false); | 743 base::WaitableEvent initialization_waiter( |
| 744 base::WaitableEvent::ResetPolicy::MANUAL, |
| 745 base::WaitableEvent::InitialState::NOT_SIGNALED); |
744 int32_t initialization_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 746 int32_t initialization_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
745 gpu_task_runner_->PostTask( | 747 gpu_task_runner_->PostTask( |
746 FROM_HERE, | 748 FROM_HERE, |
747 base::Bind(&RTCVideoEncoder::Impl::CreateAndInitializeVEA, | 749 base::Bind(&RTCVideoEncoder::Impl::CreateAndInitializeVEA, |
748 impl_, | 750 impl_, |
749 gfx::Size(codec_settings->width, codec_settings->height), | 751 gfx::Size(codec_settings->width, codec_settings->height), |
750 codec_settings->startBitrate, | 752 codec_settings->startBitrate, |
751 profile, | 753 profile, |
752 &initialization_waiter, | 754 &initialization_waiter, |
753 &initialization_retval)); | 755 &initialization_retval)); |
754 | 756 |
755 // webrtc::VideoEncoder expects this call to be synchronous. | 757 // webrtc::VideoEncoder expects this call to be synchronous. |
756 initialization_waiter.Wait(); | 758 initialization_waiter.Wait(); |
757 RecordInitEncodeUMA(initialization_retval, profile); | 759 RecordInitEncodeUMA(initialization_retval, profile); |
758 return initialization_retval; | 760 return initialization_retval; |
759 } | 761 } |
760 | 762 |
761 int32_t RTCVideoEncoder::Encode( | 763 int32_t RTCVideoEncoder::Encode( |
762 const webrtc::VideoFrame& input_image, | 764 const webrtc::VideoFrame& input_image, |
763 const webrtc::CodecSpecificInfo* codec_specific_info, | 765 const webrtc::CodecSpecificInfo* codec_specific_info, |
764 const std::vector<webrtc::FrameType>* frame_types) { | 766 const std::vector<webrtc::FrameType>* frame_types) { |
765 DVLOG(3) << "Encode()"; | 767 DVLOG(3) << "Encode()"; |
766 if (!impl_.get()) { | 768 if (!impl_.get()) { |
767 DVLOG(3) << "Encoder is not initialized"; | 769 DVLOG(3) << "Encoder is not initialized"; |
768 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 770 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
769 } | 771 } |
770 | 772 |
771 const bool want_key_frame = frame_types && frame_types->size() && | 773 const bool want_key_frame = frame_types && frame_types->size() && |
772 frame_types->front() == webrtc::kVideoFrameKey; | 774 frame_types->front() == webrtc::kVideoFrameKey; |
773 base::WaitableEvent encode_waiter(true, false); | 775 base::WaitableEvent encode_waiter( |
| 776 base::WaitableEvent::ResetPolicy::MANUAL, |
| 777 base::WaitableEvent::InitialState::NOT_SIGNALED); |
774 int32_t encode_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 778 int32_t encode_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
775 gpu_task_runner_->PostTask( | 779 gpu_task_runner_->PostTask( |
776 FROM_HERE, | 780 FROM_HERE, |
777 base::Bind(&RTCVideoEncoder::Impl::Enqueue, | 781 base::Bind(&RTCVideoEncoder::Impl::Enqueue, |
778 impl_, | 782 impl_, |
779 &input_image, | 783 &input_image, |
780 want_key_frame, | 784 want_key_frame, |
781 &encode_waiter, | 785 &encode_waiter, |
782 &encode_retval)); | 786 &encode_retval)); |
783 | 787 |
784 // webrtc::VideoEncoder expects this call to be synchronous. | 788 // webrtc::VideoEncoder expects this call to be synchronous. |
785 encode_waiter.Wait(); | 789 encode_waiter.Wait(); |
786 DVLOG(3) << "Encode(): returning encode_retval=" << encode_retval; | 790 DVLOG(3) << "Encode(): returning encode_retval=" << encode_retval; |
787 return encode_retval; | 791 return encode_retval; |
788 } | 792 } |
789 | 793 |
790 int32_t RTCVideoEncoder::RegisterEncodeCompleteCallback( | 794 int32_t RTCVideoEncoder::RegisterEncodeCompleteCallback( |
791 webrtc::EncodedImageCallback* callback) { | 795 webrtc::EncodedImageCallback* callback) { |
792 DVLOG(3) << "RegisterEncodeCompleteCallback()"; | 796 DVLOG(3) << "RegisterEncodeCompleteCallback()"; |
793 if (!impl_.get()) { | 797 if (!impl_.get()) { |
794 DVLOG(3) << "Encoder is not initialized"; | 798 DVLOG(3) << "Encoder is not initialized"; |
795 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 799 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
796 } | 800 } |
797 | 801 |
798 base::WaitableEvent register_waiter(true, false); | 802 base::WaitableEvent register_waiter( |
| 803 base::WaitableEvent::ResetPolicy::MANUAL, |
| 804 base::WaitableEvent::InitialState::NOT_SIGNALED); |
799 int32_t register_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 805 int32_t register_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
800 gpu_task_runner_->PostTask( | 806 gpu_task_runner_->PostTask( |
801 FROM_HERE, | 807 FROM_HERE, |
802 base::Bind(&RTCVideoEncoder::Impl::RegisterEncodeCompleteCallback, impl_, | 808 base::Bind(&RTCVideoEncoder::Impl::RegisterEncodeCompleteCallback, impl_, |
803 ®ister_waiter, ®ister_retval, callback)); | 809 ®ister_waiter, ®ister_retval, callback)); |
804 register_waiter.Wait(); | 810 register_waiter.Wait(); |
805 return register_retval; | 811 return register_retval; |
806 } | 812 } |
807 | 813 |
808 int32_t RTCVideoEncoder::Release() { | 814 int32_t RTCVideoEncoder::Release() { |
809 DVLOG(3) << "Release()"; | 815 DVLOG(3) << "Release()"; |
810 if (!impl_.get()) | 816 if (!impl_.get()) |
811 return WEBRTC_VIDEO_CODEC_OK; | 817 return WEBRTC_VIDEO_CODEC_OK; |
812 | 818 |
813 base::WaitableEvent release_waiter(true, false); | 819 base::WaitableEvent release_waiter( |
| 820 base::WaitableEvent::ResetPolicy::MANUAL, |
| 821 base::WaitableEvent::InitialState::NOT_SIGNALED); |
814 gpu_task_runner_->PostTask( | 822 gpu_task_runner_->PostTask( |
815 FROM_HERE, | 823 FROM_HERE, |
816 base::Bind(&RTCVideoEncoder::Impl::Destroy, impl_, &release_waiter)); | 824 base::Bind(&RTCVideoEncoder::Impl::Destroy, impl_, &release_waiter)); |
817 release_waiter.Wait(); | 825 release_waiter.Wait(); |
818 impl_ = NULL; | 826 impl_ = NULL; |
819 return WEBRTC_VIDEO_CODEC_OK; | 827 return WEBRTC_VIDEO_CODEC_OK; |
820 } | 828 } |
821 | 829 |
822 int32_t RTCVideoEncoder::SetChannelParameters(uint32_t packet_loss, | 830 int32_t RTCVideoEncoder::SetChannelParameters(uint32_t packet_loss, |
823 int64_t rtt) { | 831 int64_t rtt) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 863 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
856 init_retval == WEBRTC_VIDEO_CODEC_OK); | 864 init_retval == WEBRTC_VIDEO_CODEC_OK); |
857 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 865 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
858 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 866 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
859 profile, | 867 profile, |
860 media::VIDEO_CODEC_PROFILE_MAX + 1); | 868 media::VIDEO_CODEC_PROFILE_MAX + 1); |
861 } | 869 } |
862 } | 870 } |
863 | 871 |
864 } // namespace content | 872 } // namespace content |
OLD | NEW |