Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/rtc_video_encoder_factory.h" | |
| 6 | |
| 7 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | |
| 8 #include "content/renderer/media/rtc_video_encoder.h" | |
| 9 #include "media/filters/gpu_video_accelerator_factories.h" | |
| 10 #include "media/video/video_encode_accelerator.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Translate from media::VideoEncodeAccelerator::SupportedProfile to | |
| 17 // cricket::WebRtcVideoEncoderFactory::VideoCodec | |
| 18 cricket::WebRtcVideoEncoderFactory::VideoCodec GVEAToWebRTCCodec( | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
s/GVEA/VEA/
sheu
2013/08/02 01:27:49
Done.
| |
| 19 const media::VideoEncodeAccelerator::SupportedProfile& profile) { | |
| 20 webrtc::VideoCodecType type = webrtc::kVideoCodecUnknown; | |
| 21 std::string name; | |
| 22 int width = 0, height = 0, fps = 0; | |
| 23 | |
| 24 if (profile.profile >= media::VP8PROFILE_MIN && | |
| 25 profile.profile <= media::VP8PROFILE_MAX) { | |
| 26 type = webrtc::kVideoCodecVP8; | |
| 27 name = std::string("VP8"); | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
here and elsewhere, the explicit std::string() is
sheu
2013/08/02 01:27:49
Done.
| |
| 28 } else if (profile.profile >= media::H264PROFILE_MIN && | |
| 29 profile.profile <= media::H264PROFILE_MAX) { | |
| 30 type = webrtc::kVideoCodecGeneric; | |
| 31 name = std::string("CAST1"); | |
| 32 } | |
| 33 | |
| 34 if (type != webrtc::kVideoCodecUnknown) { | |
| 35 width = profile.max_resolution.width(); | |
| 36 height = profile.max_resolution.height(); | |
| 37 DCHECK_EQ(profile.max_framerate.denominator, 1U); | |
| 38 fps = profile.max_framerate.numerator; | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
DCHECK_EQ(denominator, 1);
or handle the division.
sheu
2013/08/02 01:27:49
The DCHECK is above, maybe not where you'd expect.
| |
| 39 } | |
| 40 | |
| 41 return cricket::WebRtcVideoEncoderFactory::VideoCodec( | |
| 42 type, name, width, height, fps); | |
| 43 } | |
| 44 | |
| 45 // Translate from cricket::WebRtcVideoEncoderFactory::VideoCodec to | |
| 46 // media::VideoCodecProfile. Pick a default profile for each codec type. | |
| 47 media::VideoCodecProfile WebRTCCodecToVideoCodecProfile( | |
| 48 webrtc::VideoCodecType type) { | |
| 49 switch (type) { | |
| 50 case webrtc::kVideoCodecVP8: | |
| 51 return media::VP8PROFILE_MAIN; | |
| 52 case webrtc::kVideoCodecGeneric: | |
| 53 return media::H264PROFILE_MAIN; | |
| 54 default: | |
| 55 return media::VIDEO_CODEC_PROFILE_UNKNOWN; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 } // anonymous namespace | |
| 60 | |
| 61 RTCVideoEncoderFactory::RTCVideoEncoderFactory( | |
| 62 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) | |
| 63 : gpu_factories_(gpu_factories) { | |
| 64 // Query media::VideoEncodeAccelerator (statically) for our supported codecs. | |
| 65 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = | |
| 66 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles(); | |
| 67 for (size_t i = 0; i < profiles.size(); ++i) { | |
| 68 VideoCodec codec = GVEAToWebRTCCodec(profiles[i]); | |
| 69 if (codec.type != webrtc::kVideoCodecUnknown) | |
| 70 codecs_.push_back(codec); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} | |
| 75 | |
| 76 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( | |
| 77 webrtc::VideoCodecType type) { | |
| 78 bool found = false; | |
| 79 for (size_t i = 0; i < codecs_.size(); ++i) { | |
| 80 if (codecs_[i].type == type) { | |
| 81 found = true; | |
| 82 break; | |
| 83 } | |
| 84 } | |
| 85 if (!found) | |
| 86 return NULL; | |
| 87 // GpuVideoAcceleratorFactories is not thread safe. It cannot be shared | |
| 88 // by different decoders. Since we aren't running on the child thread and | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
s/decoders/encoders/
sheu
2013/08/02 01:27:49
Done.
| |
| 89 // cannot create a new factory, clone one instead. | |
| 90 return new RTCVideoEncoder(WebRTCCodecToVideoCodecProfile(type), | |
| 91 gpu_factories_->Clone()); | |
| 92 } | |
| 93 | |
| 94 void RTCVideoEncoderFactory::AddObserver(Observer* observer) { | |
| 95 // No-op: our codec list is populated on installation. | |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
Yeah, I doubt this is going to fly...
sheu
2013/08/02 01:27:49
It does quite nicely.
According to the interface
| |
| 96 } | |
| 97 | |
| 98 void RTCVideoEncoderFactory::RemoveObserver(Observer* observer) {} | |
| 99 | |
| 100 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& | |
| 101 RTCVideoEncoderFactory::codecs() const { | |
| 102 return codecs_; | |
| 103 } | |
| 104 | |
| 105 void RTCVideoEncoderFactory::DestroyVideoEncoder( | |
| 106 webrtc::VideoEncoder* encoder) { | |
| 107 delete encoder; | |
| 108 } | |
| 109 | |
| 110 } // namespace content | |
| OLD | NEW |