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

Side by Side Diff: content/renderer/media/gpu/rtc_video_encoder.cc

Issue 2985263002: Reland of RTCVideoEncoder: Report H264 profile information to WebRTC (Closed)
Patch Set: Add default argument to SetDefaultVideoCodec Created 3 years, 4 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 // 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/gpu/rtc_video_encoder.h" 5 #include "content/renderer/media/gpu/rtc_video_encoder.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <deque> 9 #include <deque>
10 #include <memory> 10 #include <memory>
(...skipping 29 matching lines...) Expand all
40 struct RTCTimestamps { 40 struct RTCTimestamps {
41 RTCTimestamps(const base::TimeDelta& media_timestamp, int32_t rtp_timestamp) 41 RTCTimestamps(const base::TimeDelta& media_timestamp, int32_t rtp_timestamp)
42 : media_timestamp_(media_timestamp), rtp_timestamp(rtp_timestamp) {} 42 : media_timestamp_(media_timestamp), rtp_timestamp(rtp_timestamp) {}
43 const base::TimeDelta media_timestamp_; 43 const base::TimeDelta media_timestamp_;
44 const int32_t rtp_timestamp; 44 const int32_t rtp_timestamp;
45 45
46 private: 46 private:
47 DISALLOW_IMPLICIT_CONSTRUCTORS(RTCTimestamps); 47 DISALLOW_IMPLICIT_CONSTRUCTORS(RTCTimestamps);
48 }; 48 };
49 49
50 // Translate from webrtc::VideoCodecType and webrtc::VideoCodec to 50 webrtc::VideoCodecType ProfileToWebRtcVideoCodecType(
51 // media::VideoCodecProfile. 51 media::VideoCodecProfile profile) {
52 media::VideoCodecProfile WebRTCVideoCodecToVideoCodecProfile( 52 if (profile >= media::VP8PROFILE_MIN && profile <= media::VP8PROFILE_MAX) {
53 webrtc::VideoCodecType type, 53 return webrtc::kVideoCodecVP8;
54 const webrtc::VideoCodec* codec_settings) { 54 } else if (profile >= media::H264PROFILE_MIN &&
55 DCHECK_EQ(type, codec_settings->codecType); 55 profile <= media::H264PROFILE_MAX) {
56 switch (type) { 56 return webrtc::kVideoCodecH264;
57 case webrtc::kVideoCodecVP8:
58 return media::VP8PROFILE_ANY;
59 case webrtc::kVideoCodecVP9:
60 return media::VP9PROFILE_MIN;
61 case webrtc::kVideoCodecH264:
62 // TODO(magjed): WebRTC is only using Baseline profile for now. Update
63 // once http://crbug/webrtc/6337 is fixed.
64 return media::H264PROFILE_BASELINE;
65 default:
66 NOTREACHED() << "Unrecognized video codec type";
67 return media::VIDEO_CODEC_PROFILE_UNKNOWN;
68 } 57 }
58 NOTREACHED() << "Invalid profile " << GetProfileName(profile);
59 return webrtc::kVideoCodecUnknown;
69 } 60 }
70 61
71 // Populates struct webrtc::RTPFragmentationHeader for H264 codec. 62 // Populates struct webrtc::RTPFragmentationHeader for H264 codec.
72 // Each entry specifies the offset and length (excluding start code) of a NALU. 63 // Each entry specifies the offset and length (excluding start code) of a NALU.
73 // Returns true if successful. 64 // Returns true if successful.
74 bool GetRTPFragmentationHeaderH264(webrtc::RTPFragmentationHeader* header, 65 bool GetRTPFragmentationHeaderH264(webrtc::RTPFragmentationHeader* header,
75 const uint8_t* data, uint32_t length) { 66 const uint8_t* data, uint32_t length) {
76 media::H264Parser parser; 67 media::H264Parser parser;
77 parser.SetStream(data, length); 68 parser.SetStream(data, length);
78 69
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 if (result.error != webrtc::EncodedImageCallback::Result::OK) { 782 if (result.error != webrtc::EncodedImageCallback::Result::OK) {
792 DVLOG(2) 783 DVLOG(2)
793 << "ReturnEncodedImage(): webrtc::EncodedImageCallback::Result.error = " 784 << "ReturnEncodedImage(): webrtc::EncodedImageCallback::Result.error = "
794 << result.error; 785 << result.error;
795 } 786 }
796 787
797 UseOutputBitstreamBufferId(bitstream_buffer_id); 788 UseOutputBitstreamBufferId(bitstream_buffer_id);
798 } 789 }
799 790
800 RTCVideoEncoder::RTCVideoEncoder( 791 RTCVideoEncoder::RTCVideoEncoder(
801 webrtc::VideoCodecType type, 792 media::VideoCodecProfile profile,
802 media::GpuVideoAcceleratorFactories* gpu_factories) 793 media::GpuVideoAcceleratorFactories* gpu_factories)
803 : video_codec_type_(type), 794 : profile_(profile),
804 gpu_factories_(gpu_factories), 795 gpu_factories_(gpu_factories),
805 gpu_task_runner_(gpu_factories->GetTaskRunner()) { 796 gpu_task_runner_(gpu_factories->GetTaskRunner()) {
806 DVLOG(1) << __func__ << " codec type=" << type; 797 DVLOG(1) << "RTCVideoEncoder(): profile=" << GetProfileName(profile);
807 } 798 }
808 799
809 RTCVideoEncoder::~RTCVideoEncoder() { 800 RTCVideoEncoder::~RTCVideoEncoder() {
810 DVLOG(3) << __func__; 801 DVLOG(3) << __func__;
811 Release(); 802 Release();
812 DCHECK(!impl_.get()); 803 DCHECK(!impl_.get());
813 } 804 }
814 805
815 int32_t RTCVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings, 806 int32_t RTCVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings,
816 int32_t number_of_cores, 807 int32_t number_of_cores,
817 size_t max_payload_size) { 808 size_t max_payload_size) {
818 DVLOG(1) << __func__ << " codecType=" << codec_settings->codecType 809 DVLOG(1) << __func__ << " codecType=" << codec_settings->codecType
819 << ", width=" << codec_settings->width 810 << ", width=" << codec_settings->width
820 << ", height=" << codec_settings->height 811 << ", height=" << codec_settings->height
821 << ", startBitrate=" << codec_settings->startBitrate; 812 << ", startBitrate=" << codec_settings->startBitrate;
822 if (impl_) 813 if (impl_)
823 Release(); 814 Release();
824 815
825 impl_ = new Impl(gpu_factories_, video_codec_type_); 816 impl_ = new Impl(gpu_factories_, ProfileToWebRtcVideoCodecType(profile_));
826 const media::VideoCodecProfile profile = WebRTCVideoCodecToVideoCodecProfile(
827 impl_->video_codec_type(), codec_settings);
828 817
829 base::WaitableEvent initialization_waiter( 818 base::WaitableEvent initialization_waiter(
830 base::WaitableEvent::ResetPolicy::MANUAL, 819 base::WaitableEvent::ResetPolicy::MANUAL,
831 base::WaitableEvent::InitialState::NOT_SIGNALED); 820 base::WaitableEvent::InitialState::NOT_SIGNALED);
832 int32_t initialization_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED; 821 int32_t initialization_retval = WEBRTC_VIDEO_CODEC_UNINITIALIZED;
833 gpu_task_runner_->PostTask( 822 gpu_task_runner_->PostTask(
834 FROM_HERE, 823 FROM_HERE,
835 base::Bind(&RTCVideoEncoder::Impl::CreateAndInitializeVEA, 824 base::Bind(&RTCVideoEncoder::Impl::CreateAndInitializeVEA, impl_,
836 impl_,
837 gfx::Size(codec_settings->width, codec_settings->height), 825 gfx::Size(codec_settings->width, codec_settings->height),
838 codec_settings->startBitrate, 826 codec_settings->startBitrate, profile_, &initialization_waiter,
839 profile,
840 &initialization_waiter,
841 &initialization_retval)); 827 &initialization_retval));
842 828
843 // webrtc::VideoEncoder expects this call to be synchronous. 829 // webrtc::VideoEncoder expects this call to be synchronous.
844 initialization_waiter.Wait(); 830 initialization_waiter.Wait();
845 RecordInitEncodeUMA(initialization_retval, profile); 831 RecordInitEncodeUMA(initialization_retval, profile_);
846 return initialization_retval; 832 return initialization_retval;
847 } 833 }
848 834
849 int32_t RTCVideoEncoder::Encode( 835 int32_t RTCVideoEncoder::Encode(
850 const webrtc::VideoFrame& input_image, 836 const webrtc::VideoFrame& input_image,
851 const webrtc::CodecSpecificInfo* codec_specific_info, 837 const webrtc::CodecSpecificInfo* codec_specific_info,
852 const std::vector<webrtc::FrameType>* frame_types) { 838 const std::vector<webrtc::FrameType>* frame_types) {
853 DVLOG(3) << __func__; 839 DVLOG(3) << __func__;
854 if (!impl_.get()) { 840 if (!impl_.get()) {
855 DVLOG(3) << "Encoder is not initialized"; 841 DVLOG(3) << "Encoder is not initialized";
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 new_bit_rate, 927 new_bit_rate,
942 frame_rate)); 928 frame_rate));
943 return WEBRTC_VIDEO_CODEC_OK; 929 return WEBRTC_VIDEO_CODEC_OK;
944 } 930 }
945 931
946 bool RTCVideoEncoder::SupportsNativeHandle() const { 932 bool RTCVideoEncoder::SupportsNativeHandle() const {
947 return true; 933 return true;
948 } 934 }
949 935
950 } // namespace content 936 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/gpu/rtc_video_encoder.h ('k') | content/renderer/media/gpu/rtc_video_encoder_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698