Chromium Code Reviews| Index: content/renderer/media/gpu/rtc_video_encoder.cc |
| diff --git a/content/renderer/media/gpu/rtc_video_encoder.cc b/content/renderer/media/gpu/rtc_video_encoder.cc |
| index 4c42938e2a4bef07048703ba1fb759c6d4448135..a97240ba12660bbc96586e89d2e377494f095189 100644 |
| --- a/content/renderer/media/gpu/rtc_video_encoder.cc |
| +++ b/content/renderer/media/gpu/rtc_video_encoder.cc |
| @@ -32,25 +32,6 @@ namespace content { |
| namespace { |
| -// Translate from webrtc::VideoCodecType and webrtc::VideoCodec to |
| -// media::VideoCodecProfile. |
| -media::VideoCodecProfile WebRTCVideoCodecToVideoCodecProfile( |
| - webrtc::VideoCodecType type, |
| - const webrtc::VideoCodec* codec_settings) { |
| - DCHECK_EQ(type, codec_settings->codecType); |
| - switch (type) { |
| - case webrtc::kVideoCodecVP8: |
| - return media::VP8PROFILE_ANY; |
| - case webrtc::kVideoCodecH264: |
| - // TODO(magjed): WebRTC is only using Baseline profile for now. Update |
| - // once http://crbug/webrtc/6337 is fixed. |
| - return media::H264PROFILE_BASELINE; |
| - default: |
| - NOTREACHED() << "Unrecognized video codec type"; |
| - return media::VIDEO_CODEC_PROFILE_UNKNOWN; |
| - } |
| -} |
| - |
| // Populates struct webrtc::RTPFragmentationHeader for H264 codec. |
| // Each entry specifies the offset and length (excluding start code) of a NALU. |
| // Returns true if successful. |
| @@ -98,7 +79,7 @@ class RTCVideoEncoder::Impl |
| public base::RefCountedThreadSafe<RTCVideoEncoder::Impl> { |
| public: |
| Impl(media::GpuVideoAcceleratorFactories* gpu_factories, |
| - webrtc::VideoCodecType video_codec_type); |
| + const media::VideoCodecProfile& profile); |
| // Create the VEA and call Initialize() on it. Called once per instantiation, |
| // and then the instance is bound forevermore to whichever thread made the |
| @@ -137,8 +118,6 @@ class RTCVideoEncoder::Impl |
| // Return the status of Impl. One of WEBRTC_VIDEO_CODEC_XXX value. |
| int32_t GetStatus() const; |
| - webrtc::VideoCodecType video_codec_type() { return video_codec_type_; } |
| - |
| // media::VideoEncodeAccelerator::Client implementation. |
| void RequireBitstreamBuffers(unsigned int input_count, |
| const gfx::Size& input_coded_size, |
| @@ -238,7 +217,7 @@ class RTCVideoEncoder::Impl |
| webrtc::EncodedImageCallback* encoded_image_callback_; |
| // The video codec type, as reported to WebRTC. |
| - const webrtc::VideoCodecType video_codec_type_; |
| + const media::VideoCodecProfile profile_; |
| // Protect |status_|. |status_| is read or written on |gpu_task_runner_| in |
| // Impl. It can be read in RTCVideoEncoder on other threads. |
| @@ -253,8 +232,9 @@ class RTCVideoEncoder::Impl |
| DISALLOW_COPY_AND_ASSIGN(Impl); |
| }; |
| -RTCVideoEncoder::Impl::Impl(media::GpuVideoAcceleratorFactories* gpu_factories, |
| - webrtc::VideoCodecType video_codec_type) |
| +RTCVideoEncoder::Impl::Impl( |
| + media::GpuVideoAcceleratorFactories* gpu_factories, |
| + const media::VideoCodecProfile& profile) |
| : gpu_factories_(gpu_factories), |
| async_waiter_(NULL), |
| async_retval_(NULL), |
| @@ -262,7 +242,7 @@ RTCVideoEncoder::Impl::Impl(media::GpuVideoAcceleratorFactories* gpu_factories, |
| input_next_frame_keyframe_(false), |
| output_buffers_free_count_(0), |
| encoded_image_callback_(nullptr), |
| - video_codec_type_(video_codec_type), |
| + profile_(profile), |
| status_(WEBRTC_VIDEO_CODEC_UNINITIALIZED) { |
| thread_checker_.DetachFromThread(); |
| // Picture ID should start on a random number. |
| @@ -681,38 +661,34 @@ void RTCVideoEncoder::Impl::ReturnEncodedImage( |
| if (!encoded_image_callback_) |
| return; |
| - webrtc::RTPFragmentationHeader header; |
| - memset(&header, 0, sizeof(header)); |
| - switch (video_codec_type_) { |
| - case webrtc::kVideoCodecVP8: |
| - // Generate a header describing a single fragment. |
| - header.VerifyAndAllocateFragmentationHeader(1); |
| - header.fragmentationOffset[0] = 0; |
| - header.fragmentationLength[0] = image._length; |
| - header.fragmentationPlType[0] = 0; |
| - header.fragmentationTimeDiff[0] = 0; |
| - break; |
| - case webrtc::kVideoCodecH264: |
| - if (!GetRTPFragmentationHeaderH264(&header, image._buffer, |
| - image._length)) { |
| - DLOG(ERROR) << "Failed to get RTP fragmentation header for H264"; |
| - NotifyError( |
| - (media::VideoEncodeAccelerator::Error)WEBRTC_VIDEO_CODEC_ERROR); |
| - return; |
| - } |
| - break; |
| - default: |
| - NOTREACHED() << "Invalid video codec type"; |
| - return; |
| - } |
| - |
| webrtc::CodecSpecificInfo info; |
| + webrtc::RTPFragmentationHeader header; |
| memset(&info, 0, sizeof(info)); |
| - info.codecType = video_codec_type_; |
| - if (video_codec_type_ == webrtc::kVideoCodecVP8) { |
| + memset(&header, 0, sizeof(header)); |
| + if (profile_ >= media::VP8PROFILE_MIN && profile_ <= media::VP8PROFILE_MAX) { |
|
Pawel Osciak
2016/11/17 07:30:05
I think we can store just media::VideoCodec in Imp
magjed_chromium
2016/11/17 13:08:03
Done. I kept it as a webrtc::VideoCodecType in Imp
|
| + // Generate a header describing a single fragment. |
| + header.VerifyAndAllocateFragmentationHeader(1); |
| + header.fragmentationOffset[0] = 0; |
| + header.fragmentationLength[0] = image._length; |
| + header.fragmentationPlType[0] = 0; |
| + header.fragmentationTimeDiff[0] = 0; |
| + |
| + info.codecType = webrtc::kVideoCodecVP8; |
| info.codecSpecific.VP8.pictureId = picture_id; |
| info.codecSpecific.VP8.tl0PicIdx = -1; |
| info.codecSpecific.VP8.keyIdx = -1; |
| + } else if (profile_ >= media::H264PROFILE_MIN && |
| + profile_ <= media::H264PROFILE_MAX) { |
| + info.codecType = webrtc::kVideoCodecH264; |
| + if (!GetRTPFragmentationHeaderH264(&header, image._buffer, image._length)) { |
| + DLOG(ERROR) << "Failed to get RTP fragmentation header for H264"; |
| + NotifyError( |
| + (media::VideoEncodeAccelerator::Error)WEBRTC_VIDEO_CODEC_ERROR); |
| + return; |
| + } |
| + } else { |
| + NOTREACHED() << "Invalid video codec type"; |
| + return; |
| } |
| const auto result = |
| @@ -727,12 +703,12 @@ void RTCVideoEncoder::Impl::ReturnEncodedImage( |
| } |
| RTCVideoEncoder::RTCVideoEncoder( |
| - webrtc::VideoCodecType type, |
| + const media::VideoCodecProfile& profile, |
| media::GpuVideoAcceleratorFactories* gpu_factories) |
| - : video_codec_type_(type), |
| + : profile_(profile), |
| gpu_factories_(gpu_factories), |
| gpu_task_runner_(gpu_factories->GetTaskRunner()) { |
| - DVLOG(1) << "RTCVideoEncoder(): codec type=" << type; |
| + DVLOG(1) << "RTCVideoEncoder(): profile=" << GetProfileName(profile); |
| } |
| RTCVideoEncoder::~RTCVideoEncoder() { |
| @@ -753,9 +729,7 @@ int32_t RTCVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings, |
| Release(); |
| } |
| - impl_ = new Impl(gpu_factories_, video_codec_type_); |
| - const media::VideoCodecProfile profile = WebRTCVideoCodecToVideoCodecProfile( |
| - impl_->video_codec_type(), codec_settings); |
| + impl_ = new Impl(gpu_factories_, profile_); |
| base::WaitableEvent initialization_waiter( |
| base::WaitableEvent::ResetPolicy::MANUAL, |
| @@ -767,13 +741,13 @@ int32_t RTCVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings, |
| impl_, |
| gfx::Size(codec_settings->width, codec_settings->height), |
| codec_settings->startBitrate, |
| - profile, |
| + profile_, |
| &initialization_waiter, |
| &initialization_retval)); |
| // webrtc::VideoEncoder expects this call to be synchronous. |
| initialization_waiter.Wait(); |
| - RecordInitEncodeUMA(initialization_retval, profile); |
| + RecordInitEncodeUMA(initialization_retval, profile_); |
| return initialization_retval; |
| } |