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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | 8 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
10 #include "content/renderer/media/rtc_video_encoder.h" | 10 #include "content/renderer/media/rtc_video_encoder.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 if (cmd_line->HasSwitch(switches::kEnableWebRtcHWH264Encoding)) { | 37 if (cmd_line->HasSwitch(switches::kEnableWebRtcHWH264Encoding)) { |
38 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 38 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
39 webrtc::kVideoCodecH264, "H264", width, height, fps)); | 39 webrtc::kVideoCodecH264, "H264", width, height, fps)); |
40 } | 40 } |
41 // TODO(hshi): remove the generic codec type after CASTv1 deprecation. | 41 // TODO(hshi): remove the generic codec type after CASTv1 deprecation. |
42 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 42 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
43 webrtc::kVideoCodecGeneric, "CAST1", width, height, fps)); | 43 webrtc::kVideoCodecGeneric, "CAST1", width, height, fps)); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 // Translate from cricket::WebRtcVideoEncoderFactory::VideoCodec to | |
48 // media::VideoCodecProfile. Pick a default profile for each codec type. | |
49 media::VideoCodecProfile WebRTCCodecToVideoCodecProfile( | |
50 webrtc::VideoCodecType type) { | |
51 switch (type) { | |
52 case webrtc::kVideoCodecVP8: | |
53 return media::VP8PROFILE_ANY; | |
54 case webrtc::kVideoCodecH264: | |
55 case webrtc::kVideoCodecGeneric: | |
56 return media::H264PROFILE_MAIN; | |
57 default: | |
58 return media::VIDEO_CODEC_PROFILE_UNKNOWN; | |
59 } | |
60 } | |
61 | |
62 } // anonymous namespace | 47 } // anonymous namespace |
63 | 48 |
64 RTCVideoEncoderFactory::RTCVideoEncoderFactory( | 49 RTCVideoEncoderFactory::RTCVideoEncoderFactory( |
65 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) | 50 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) |
66 : gpu_factories_(gpu_factories) { | 51 : gpu_factories_(gpu_factories) { |
67 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = | 52 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = |
68 gpu_factories_->GetVideoEncodeAcceleratorSupportedProfiles(); | 53 gpu_factories_->GetVideoEncodeAcceleratorSupportedProfiles(); |
69 for (size_t i = 0; i < profiles.size(); ++i) | 54 for (size_t i = 0; i < profiles.size(); ++i) |
70 VEAToWebRTCCodecs(&codecs_, profiles[i]); | 55 VEAToWebRTCCodecs(&codecs_, profiles[i]); |
71 } | 56 } |
72 | 57 |
73 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} | 58 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} |
74 | 59 |
60 // Translate from webrtc::VideoCodecType and webrtc::VideoCodec to | |
61 // media::VideoCodecProfile. | |
62 // static | |
63 media::VideoCodecProfile RTCVideoEncoderFactory::GetCodecProfile( | |
64 webrtc::VideoCodecType type, const webrtc::VideoCodec* codec_settings) { | |
65 DCHECK_EQ(type, codec_settings->codecType); | |
66 switch (type) { | |
67 case webrtc::kVideoCodecVP8: | |
68 return media::VP8PROFILE_ANY; | |
69 case webrtc::kVideoCodecH264: { | |
70 switch (codec_settings->codecSpecific.H264.profile) { | |
71 case webrtc::kProfileBase: | |
72 return media::H264PROFILE_BASELINE; | |
73 case webrtc::kProfileMain: | |
74 return media::H264PROFILE_MAIN; | |
75 default: | |
Pawel Osciak
2014/10/25 01:23:04
There are only two cases and we are handling both.
hshi1
2014/10/25 01:36:51
Done.
| |
76 NOTREACHED() << "Unrecognized H264 video codec profile"; | |
77 return media::VIDEO_CODEC_PROFILE_UNKNOWN; | |
78 } | |
79 } | |
80 case webrtc::kVideoCodecGeneric: | |
81 return media::H264PROFILE_MAIN; | |
82 default: | |
83 NOTREACHED() << "Unrecognized video codec type"; | |
84 return media::VIDEO_CODEC_PROFILE_UNKNOWN; | |
85 } | |
86 } | |
87 | |
75 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( | 88 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( |
76 webrtc::VideoCodecType type) { | 89 webrtc::VideoCodecType type) { |
77 bool found = false; | 90 bool found = false; |
78 for (size_t i = 0; i < codecs_.size(); ++i) { | 91 for (size_t i = 0; i < codecs_.size(); ++i) { |
79 if (codecs_[i].type == type) { | 92 if (codecs_[i].type == type) { |
80 found = true; | 93 found = true; |
81 break; | 94 break; |
82 } | 95 } |
83 } | 96 } |
84 if (!found) | 97 if (!found) |
85 return NULL; | 98 return NULL; |
86 return new RTCVideoEncoder( | 99 return new RTCVideoEncoder(type, gpu_factories_); |
87 type, WebRTCCodecToVideoCodecProfile(type), gpu_factories_); | |
88 } | 100 } |
89 | 101 |
90 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& | 102 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& |
91 RTCVideoEncoderFactory::codecs() const { | 103 RTCVideoEncoderFactory::codecs() const { |
92 return codecs_; | 104 return codecs_; |
93 } | 105 } |
94 | 106 |
95 void RTCVideoEncoderFactory::DestroyVideoEncoder( | 107 void RTCVideoEncoderFactory::DestroyVideoEncoder( |
96 webrtc::VideoEncoder* encoder) { | 108 webrtc::VideoEncoder* encoder) { |
97 delete encoder; | 109 delete encoder; |
98 } | 110 } |
99 | 111 |
100 } // namespace content | 112 } // namespace content |
OLD | NEW |