[英]Building Chromium for Android with Webrtc h264 support
我正在嘗試在 webrtc 中構建支持 h264 的 Chromium Android。 我的理解是以下 args.gn 文件應該做我想做的。
target_os = "android"
target_cpu = "arm64"
proprietary_codecs = true
ffmpeg_branding = "Chrome"
但是,當我在 Pixel 3 上安裝 APK 時,使用 chrome://inspect 從我的桌面進行調試並運行new RTCPeerConnection().createOffer({offerToReceiveVideo: true}).then(s => console.log(s.sdp))
我只看到 VP8 和 VP9 編解碼器。
還有什么我想念的嗎?
我最終不得不更改代碼以獲得我想要的行為。
設置這些構建標志會導致 GPU 進程對任何查詢回答“是的,我支持 H264 視頻解碼” https://cs.chromium.org/chromium/src/media/gpu/android/media_codec_video_decoder.cc?q=proprietary_codecs&sq =包裝:鉻&dr=C&l=154
然而,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,而不必弄亂第三方存儲庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.