diff options
author | fiaxh <git@lightrise.org> | 2021-12-23 00:44:51 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2021-12-23 00:46:58 +0100 |
commit | d02c5bc55d4325de308a592e8980139aa0634215 (patch) | |
tree | 9cb91f86056dd29f863bd8e54580cccc625af60e /plugins/rtp/src/codec_util.vala | |
parent | 1378224444b1862ac95783ac2bae7d25a0a8862d (diff) | |
parent | f0c7dd0682fec8d72c644d8e54896de7bdc40ddb (diff) | |
download | dino-d02c5bc55d4325de308a592e8980139aa0634215.tar.gz dino-d02c5bc55d4325de308a592e8980139aa0634215.zip |
Merge branch groupcalls
Diffstat (limited to 'plugins/rtp/src/codec_util.vala')
-rw-r--r-- | plugins/rtp/src/codec_util.vala | 88 |
1 files changed, 73 insertions, 15 deletions
diff --git a/plugins/rtp/src/codec_util.vala b/plugins/rtp/src/codec_util.vala index 417dc4be..6fb5e7aa 100644 --- a/plugins/rtp/src/codec_util.vala +++ b/plugins/rtp/src/codec_util.vala @@ -97,7 +97,7 @@ public class Dino.Plugins.Rtp.CodecUtil { case "h264": return new string[] {/*"msdkh264enc", */"vaapih264enc", "x264enc"}; case "vp9": - return new string[] {/*"msdkvp9enc", */"vaapivp9enc" /*, "vp9enc" */}; + return new string[] {/*"msdkvp9enc", */"vaapivp9enc", "vp9enc"}; case "vp8": return new string[] {/*"msdkvp8enc", */"vaapivp8enc", "vp8enc"}; } @@ -140,13 +140,16 @@ public class Dino.Plugins.Rtp.CodecUtil { public static string? get_encode_args(string media, string codec, string encode, JingleRtp.PayloadType? payload_type) { // H264 if (encode == "msdkh264enc") return @" rate-control=vbr"; - if (encode == "vaapih264enc") return @" tune=low-power"; - if (encode == "x264enc") return @" byte-stream=1 profile=baseline speed-preset=ultrafast tune=zerolatency"; + if (encode == "vaapih264enc") return @" rate-control=vbr tune=low-power"; + if (encode == "x264enc") return @" byte-stream=1 speed-preset=ultrafast tune=zerolatency bframes=0 cabac=false dct8x8=false"; // VP8 - if (encode == "msdkvp8enc") return " rate-control=vbr"; - if (encode == "vaapivp8enc") return " rate-control=vbr"; - if (encode == "vp8enc") return " deadline=1 error-resilient=1"; + if (encode == "vaapivp8enc" || encode == "msdkvp8enc") return " rate-control=vbr target-percentage=90"; + if (encode == "vp8enc") return " deadline=1 error-resilient=3 lag-in-frames=0 resize-allowed=true threads=8 dropframe-threshold=30 end-usage=vbr cpu-used=4"; + + // VP9 + if (encode == "msdkvp9enc" || encode == "vaapivp9enc") return " rate-control=vbr target-percentage=90"; + if (encode == "vp9enc") return " deadline=1 error-resilient=3 lag-in-frames=0 resize-allowed=true threads=8 dropframe-threshold=30 end-usage=vbr cpu-used=4"; // OPUS if (encode == "opusenc") { @@ -159,7 +162,8 @@ public class Dino.Plugins.Rtp.CodecUtil { public static string? get_encode_suffix(string media, string codec, string encode, JingleRtp.PayloadType? payload_type) { // H264 - if (media == "video" && codec == "h264") return " ! video/x-h264,profile=constrained-baseline ! h264parse"; + if (media == "video" && codec == "h264") return " ! capsfilter caps=video/x-h264,profile=constrained-baseline ! h264parse"; + if (media == "video" && codec == "vp8" && encode == "vp8enc") return " ! capsfilter caps=video/x-vp8,profile=(string)1"; return null; } @@ -171,26 +175,43 @@ public class Dino.Plugins.Rtp.CodecUtil { if (encode_name == null) return 0; Gst.Element encode = encode_bin.get_by_name(@"$(encode_bin.name)_encode"); - bitrate = uint.min(2048000, bitrate); - switch (encode_name) { case "msdkh264enc": case "vaapih264enc": case "x264enc": + case "msdkvp9enc": + case "vaapivp9enc": case "msdkvp8enc": case "vaapivp8enc": bitrate = uint.min(2048000, bitrate); encode.set("bitrate", bitrate); return bitrate; + case "vp9enc": case "vp8enc": bitrate = uint.min(2147483, bitrate); - encode.set("target-bitrate", bitrate * 1000); + encode.set("target-bitrate", bitrate * 1024); return bitrate; } return 0; } + public void update_rescale_caps(Gst.Element encode_element, Gst.Caps caps) { + Gst.Bin? encode_bin = encode_element as Gst.Bin; + if (encode_bin == null) return; + Gst.Element rescale_caps = encode_bin.get_by_name(@"$(encode_bin.name)_rescale_caps"); + rescale_caps.set("caps", caps); + } + + public Gst.Caps? get_rescale_caps(Gst.Element encode_element) { + Gst.Bin? encode_bin = encode_element as Gst.Bin; + if (encode_bin == null) return null; + Gst.Element rescale_caps = encode_bin.get_by_name(@"$(encode_bin.name)_rescale_caps"); + Gst.Caps caps; + rescale_caps.get("caps", out caps); + return caps; + } + public static string? get_decode_prefix(string media, string codec, string decode, JingleRtp.PayloadType? payload_type) { return null; } @@ -198,6 +219,7 @@ public class Dino.Plugins.Rtp.CodecUtil { public static string? get_decode_args(string media, string codec, string decode, JingleRtp.PayloadType? payload_type) { if (decode == "opusdec" && payload_type != null && payload_type.parameters.has("useinbandfec", "1")) return " use-inband-fec=true"; if (decode == "vaapivp9dec" || decode == "vaapivp8dec" || decode == "vaapih264dec") return " max-errors=100"; + if (decode == "vp8dec" || decode == "vp9dec") return " threads=8"; return null; } @@ -242,6 +264,7 @@ public class Dino.Plugins.Rtp.CodecUtil { } public string? get_decode_element_name(string media, string? codec) { + if (codec == "vp9") return null; // Temporary unsupport VP9 if (get_depay_element_name(media, codec) == null) return null; foreach (string candidate in get_decode_candidates(media, codec)) { if (is_element_supported(candidate)) return candidate; @@ -270,7 +293,7 @@ public class Dino.Plugins.Rtp.CodecUtil { string decode_suffix = get_decode_suffix(media, codec, decode, payload_type) ?? ""; string depay_args = get_depay_args(media, codec, decode, payload_type) ?? ""; string resample = media == "audio" ? @" ! audioresample name=$(base_name)_resample" : ""; - return @"$depay$depay_args name=$(base_name)_rtp_depay ! $decode_prefix$decode$decode_args name=$(base_name)_$(codec)_decode$decode_suffix ! $(media)convert name=$(base_name)_convert$resample"; + return @"queue ! $depay$depay_args name=$(base_name)_rtp_depay ! $decode_prefix$decode$decode_args name=$(base_name)_$(codec)_decode$decode_suffix ! $(media)convert name=$(base_name)_convert$resample"; } public Gst.Element? get_decode_bin(string media, JingleRtp.PayloadType payload_type, string? name = null) { @@ -285,16 +308,29 @@ public class Dino.Plugins.Rtp.CodecUtil { } public string? get_encode_bin_description(string media, string? codec, JingleRtp.PayloadType? payload_type, string? element_name = null, string? name = null) { + string? desc1 = get_encode_bin_without_payloader_description(media, codec, payload_type, element_name, name); + string? desc2 = get_payloader_bin_description(media, codec, payload_type, name); + return @"$desc1 ! $desc2"; + } + + public string? get_payloader_bin_description(string media, string? codec, JingleRtp.PayloadType? payload_type, string? name = null) { if (codec == null) return null; string base_name = name ?? @"encode_$(codec)_$(Random.next_int())"; string? pay = get_pay_element_name(media, codec); + if (pay == null) return null; + return @"$pay pt=$(payload_type != null ? payload_type.id : 96) name=$(base_name)_rtp_pay"; + } + + public string? get_encode_bin_without_payloader_description(string media, string? codec, JingleRtp.PayloadType? payload_type, string? element_name = null, string? name = null) { + if (codec == null) return null; + string base_name = name ?? @"encode_$(codec)_$(Random.next_int())"; string? encode = element_name ?? get_encode_element_name(media, codec); - if (pay == null || encode == null) return null; + if (encode == null) return null; string encode_prefix = get_encode_prefix(media, codec, encode, payload_type) ?? ""; string encode_args = get_encode_args(media, codec, encode, payload_type) ?? ""; string encode_suffix = get_encode_suffix(media, codec, encode, payload_type) ?? ""; - string resample = media == "audio" ? @" ! audioresample name=$(base_name)_resample" : ""; - return @"$(media)convert name=$(base_name)_convert$resample ! $encode_prefix$encode$encode_args name=$(base_name)_encode$encode_suffix ! $pay pt=$(payload_type != null ? payload_type.id : 96) name=$(base_name)_rtp_pay"; + string rescale = media == "audio" ? @" ! audioresample name=$(base_name)_resample" : @" ! videoscale name=$(base_name)_rescale ! capsfilter name=$(base_name)_rescale_caps"; + return @"$(media)convert name=$(base_name)_convert$rescale ! queue ! $encode_prefix$encode$encode_args name=$(base_name)_encode$encode_suffix"; } public Gst.Element? get_encode_bin(string media, JingleRtp.PayloadType payload_type, string? name = null) { @@ -308,4 +344,26 @@ public class Dino.Plugins.Rtp.CodecUtil { return bin; } -}
\ No newline at end of file + public Gst.Element? get_encode_bin_without_payloader(string media, JingleRtp.PayloadType payload_type, string? name = null) { + string? codec = get_codec_from_payload(media, payload_type); + string base_name = name ?? @"encode_$(codec)_$(Random.next_int())"; + string? desc = get_encode_bin_without_payloader_description(media, codec, payload_type, null, base_name); + if (desc == null) return null; + debug("Pipeline to encode %s %s without payloader: %s", media, codec, desc); + Gst.Element bin = Gst.parse_bin_from_description(desc, true); + bin.name = name; + return bin; + } + + public Gst.Element? get_payloader_bin(string media, JingleRtp.PayloadType payload_type, string? name = null) { + string? codec = get_codec_from_payload(media, payload_type); + string base_name = name ?? @"encode_$(codec)_$(Random.next_int())"; + string? desc = get_payloader_bin_description(media, codec, payload_type, base_name); + if (desc == null) return null; + debug("Pipeline to payload %s %s: %s", media, codec, desc); + Gst.Element bin = Gst.parse_bin_from_description(desc, true); + bin.name = name; + return bin; + } + +} |