| 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_factory.h" | 5 #include "content/renderer/media/rtc_video_encoder_factory.h" |
| 6 | 6 |
| 7 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | 7 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
| 8 #include "content/renderer/media/rtc_video_encoder.h" | 8 #include "content/renderer/media/rtc_video_encoder.h" |
| 9 #include "media/filters/gpu_video_accelerator_factories.h" | 9 #include "media/filters/gpu_video_accelerator_factories.h" |
| 10 #include "media/video/video_encode_accelerator.h" | 10 #include "media/video/video_encode_accelerator.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Translate from media::VideoEncodeAccelerator::SupportedProfile to | 16 // Translate from media::VideoEncodeAccelerator::SupportedProfile to |
| 17 // cricket::WebRtcVideoEncoderFactory::VideoCodec | 17 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec |
| 18 cricket::WebRtcVideoEncoderFactory::VideoCodec VEAToWebRTCCodec( | 18 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec> VEAToWebRTCCodecs( |
| 19 const media::VideoEncodeAccelerator::SupportedProfile& profile) { | 19 const media::VideoEncodeAccelerator::SupportedProfile& profile) { |
| 20 webrtc::VideoCodecType type = webrtc::kVideoCodecUnknown; | 20 int width = profile.max_resolution.width(); |
| 21 std::string name; | 21 int height = profile.max_resolution.height(); |
| 22 int width = 0, height = 0, fps = 0; | 22 int fps = profile.max_framerate.numerator; |
| 23 DCHECK_EQ(profile.max_framerate.denominator, 1U); |
| 23 | 24 |
| 25 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec> codecs; |
| 24 if (profile.profile >= media::VP8PROFILE_MIN && | 26 if (profile.profile >= media::VP8PROFILE_MIN && |
| 25 profile.profile <= media::VP8PROFILE_MAX) { | 27 profile.profile <= media::VP8PROFILE_MAX) { |
| 26 type = webrtc::kVideoCodecVP8; | 28 codecs.push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 27 name = "VP8"; | 29 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); |
| 28 } else if (profile.profile >= media::H264PROFILE_MIN && | 30 } else if (profile.profile >= media::H264PROFILE_MIN && |
| 29 profile.profile <= media::H264PROFILE_MAX) { | 31 profile.profile <= media::H264PROFILE_MAX) { |
| 30 type = webrtc::kVideoCodecGeneric; | 32 codecs.push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 31 name = "CAST1"; | 33 webrtc::kVideoCodecGeneric, "CAST1", width, height, fps)); |
| 34 codecs.push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 35 webrtc::kVideoCodecH264, "H264", width, height, fps)); |
| 32 } | 36 } |
| 33 | 37 |
| 34 if (type != webrtc::kVideoCodecUnknown) { | 38 return codecs; |
| 35 width = profile.max_resolution.width(); | |
| 36 height = profile.max_resolution.height(); | |
| 37 fps = profile.max_framerate.numerator; | |
| 38 DCHECK_EQ(profile.max_framerate.denominator, 1U); | |
| 39 } | |
| 40 | |
| 41 return cricket::WebRtcVideoEncoderFactory::VideoCodec( | |
| 42 type, name, width, height, fps); | |
| 43 } | 39 } |
| 44 | 40 |
| 45 // Translate from cricket::WebRtcVideoEncoderFactory::VideoCodec to | 41 // Translate from cricket::WebRtcVideoEncoderFactory::VideoCodec to |
| 46 // media::VideoCodecProfile. Pick a default profile for each codec type. | 42 // media::VideoCodecProfile. Pick a default profile for each codec type. |
| 47 media::VideoCodecProfile WebRTCCodecToVideoCodecProfile( | 43 media::VideoCodecProfile WebRTCCodecToVideoCodecProfile( |
| 48 webrtc::VideoCodecType type) { | 44 webrtc::VideoCodecType type) { |
| 49 switch (type) { | 45 switch (type) { |
| 50 case webrtc::kVideoCodecVP8: | 46 case webrtc::kVideoCodecVP8: |
| 51 return media::VP8PROFILE_MAIN; | 47 return media::VP8PROFILE_MAIN; |
| 48 case webrtc::kVideoCodecH264: |
| 52 case webrtc::kVideoCodecGeneric: | 49 case webrtc::kVideoCodecGeneric: |
| 53 return media::H264PROFILE_MAIN; | 50 return media::H264PROFILE_MAIN; |
| 54 default: | 51 default: |
| 55 return media::VIDEO_CODEC_PROFILE_UNKNOWN; | 52 return media::VIDEO_CODEC_PROFILE_UNKNOWN; |
| 56 } | 53 } |
| 57 } | 54 } |
| 58 | 55 |
| 59 } // anonymous namespace | 56 } // anonymous namespace |
| 60 | 57 |
| 61 RTCVideoEncoderFactory::RTCVideoEncoderFactory( | 58 RTCVideoEncoderFactory::RTCVideoEncoderFactory( |
| 62 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) | 59 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) |
| 63 : gpu_factories_(gpu_factories) { | 60 : gpu_factories_(gpu_factories) { |
| 64 // Query media::VideoEncodeAccelerator (statically) for our supported codecs. | 61 // Query media::VideoEncodeAccelerator (statically) for our supported codecs. |
| 65 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = | 62 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = |
| 66 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles(); | 63 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles(); |
| 67 for (size_t i = 0; i < profiles.size(); ++i) { | 64 for (size_t i = 0; i < profiles.size(); ++i) { |
| 68 VideoCodec codec = VEAToWebRTCCodec(profiles[i]); | 65 std::vector<VideoCodec> codecs = VEAToWebRTCCodecs(profiles[i]); |
| 69 if (codec.type != webrtc::kVideoCodecUnknown) | 66 codecs_.insert(codecs_.end(), codecs.begin(), codecs.end()); |
| 70 codecs_.push_back(codec); | |
| 71 } | 67 } |
| 72 } | 68 } |
| 73 | 69 |
| 74 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} | 70 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} |
| 75 | 71 |
| 76 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( | 72 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( |
| 77 webrtc::VideoCodecType type) { | 73 webrtc::VideoCodecType type) { |
| 78 bool found = false; | 74 bool found = false; |
| 79 for (size_t i = 0; i < codecs_.size(); ++i) { | 75 for (size_t i = 0; i < codecs_.size(); ++i) { |
| 80 if (codecs_[i].type == type) { | 76 if (codecs_[i].type == type) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 98 RTCVideoEncoderFactory::codecs() const { | 94 RTCVideoEncoderFactory::codecs() const { |
| 99 return codecs_; | 95 return codecs_; |
| 100 } | 96 } |
| 101 | 97 |
| 102 void RTCVideoEncoderFactory::DestroyVideoEncoder( | 98 void RTCVideoEncoderFactory::DestroyVideoEncoder( |
| 103 webrtc::VideoEncoder* encoder) { | 99 webrtc::VideoEncoder* encoder) { |
| 104 delete encoder; | 100 delete encoder; |
| 105 } | 101 } |
| 106 | 102 |
| 107 } // namespace content | 103 } // namespace content |
| OLD | NEW |