我最终不得不更改代码以获得我想要的行为。
设置这些构建标志会导致 GPU 进程对任何查询 https://cs.chromium.org/chromium/src/media/gpu/android/media_codec_video_decoder.cc?q=proprietary_codecs&sq=package:chromium&dr=C&l=154 回答“是的,我支持 H264 视频解码”
然而,webrtc 对支持的编解码器的定义来自这个函数,它只是轮询编码器支持的格式。 https://webrtc.googlesource.com/src/+/refs/heads/master/media/engine/webrtc_video_engine.cc#142。所以看起来虽然我的 Pixel 3 支持 H264 解码,但它不支持编码,因此 webrtc 认为它是不受支持的格式。有趣的是,在完全相同的设备上运行的 Chrome 确实支持 webrtc H264。
我只是想接收 H264 视频,所以我编辑了这个函数,为 Chrome 支持的每种 H264 格式添加一个 webrtc::SdpVideoFormat。
+static void AddH264Formats(std::vector<webrtc::SdpVideoFormat>& formats) {
+ webrtc::SdpVideoFormat h264Format(kH264CodecName, {
+ {cricket::kH264FmtpLevelAsymmetryAllowed, "1"}});
+
+ h264Format.parameters[cricket::kH264FmtpProfileLevelId] = "42001f";
+ h264Format.parameters[cricket::kH264FmtpPacketizationMode] = "1";
+ if(std::find(formats.begin(), formats.end(), h264Format) == formats.end()) {
+ formats.push_back(h264Format);
+ }
+ h264Format.parameters[cricket::kH264FmtpPacketizationMode] = "0";
+ if(std::find(formats.begin(), formats.end(), h264Format) == formats.end()) {
+ formats.push_back(h264Format);
+ }
+
+ h264Format.parameters[cricket::kH264FmtpProfileLevelId] = "42e01f";
+ h264Format.parameters[cricket::kH264FmtpPacketizationMode] = "1";
+ if(std::find(formats.begin(), formats.end(), h264Format) == formats.end()) {
+ formats.push_back(h264Format);
+ }
+ h264Format.parameters[cricket::kH264FmtpPacketizationMode] = "0";
+ if(std::find(formats.begin(), formats.end(), h264Format) == formats.end()) {
+ formats.push_back(h264Format);
+ }
+
+ h264Format.parameters[cricket::kH264FmtpProfileLevelId] = "4d0032";
+ h264Format.parameters[cricket::kH264FmtpPacketizationMode] = "1";
+ if(std::find(formats.begin(), formats.end(), h264Format) == formats.end()) {
+ formats.push_back(h264Format);
+ }
+ h264Format.parameters[cricket::kH264FmtpPacketizationMode] = "0";
+ if(std::find(formats.begin(), formats.end(), h264Format) == formats.end()) {
+ formats.push_back(h264Format);
+ }
+}
+
std::vector<VideoCodec> AssignPayloadTypesAndDefaultCodecs(
const webrtc::VideoEncoderFactory* encoder_factory) {
- return encoder_factory ? AssignPayloadTypesAndDefaultCodecs(
- encoder_factory->GetSupportedFormats())
- : std::vector<VideoCodec>();
+ auto formats = encoder_factory->GetSupportedFormats();
+ AddH264Formats(formats);
+
+ return AssignPayloadTypesAndDefaultCodecs(formats);
}
我想我可以编辑 GpuVideoAcceleratorFactoriesImpl::GetVideoEncodeAcceleratorSupportedProfiles,而不是编辑 webrtc 代码。以这种方式编辑 GpuVideoAcceleratorFactoriesImpl 可能不太正确,但它允许我分叉 Chromium 而不必弄乱第三方存储库。