Critical Failure w/ Nvidia Decoder under Poor Network Conditions

We occasionally hit

GStreamer-Video-CRITICAL **: 19:06:37.727: gst_video_info_set_format_common: assertion ‘format != GST_VIDEO_FORMAT_UNKNOWN’ failed

when using the nvh264dec element under poor network conditions.

MORE CONTEXT:

We are able to reproduce the critical issue by explicitly simulating a poor network in our webRTC application:

iceMux, _ = udpMuxDegrade(iceMux, degradeSpec{
	dropIn:  0.05,
	dropOut: 0.05,
	latency: 100 * time.Millisecond,
	jitter:  200 * time.Millisecond,
})

We’re using rtpJitterBuffer and a capsfilter, but it appears that corrupt data pushed down throws a wrench into the pipeline.

Please observe this preview of how we are building the pipeline:

	/// jitter
	x.jitterbuffer, _ = gst.ElementMake(name+" jitter", "rtpjitterbuffer")
	x.jitterbuffer.Set("mode", gst.Enum(0))
	x.jitterbuffer.Set("do-lost", true)
	// Post messages about dropped packets
	x.jitterbuffer.Set("post-drop-messages", true)  
	x.jitterbuffer.Set("faststart-min-packets", uint(1))
	x.jitterbuffer.Set("latency", uint(150))
	// 62.5% of max-latency for quicker packet loss detection
	x.jitterbuffer.Set("max-dropout-time", uint(250))
	// Maximum time of misordered packets tolerated
	x.jitterbuffer.Set("max-misorder-time", uint(100))
	// Drop packets if they would exceed max-latency
	x.jitterbuffer.Set("drop-on-latency", true) 

	o = append(o, x.jitterbuffer)

	/// RTP depayload
	depayElem := gst.ElementType("rtp" + strings.ToLower(string(args.codec)) + "depay")
	depay, _ := gst.ElementMake(name+" depay", depayElem)
	o = append(o, depay)

	/// decode
	o = append(o, args.elemsMake(name)...)

// Input filter
filter := gst.FilterMake(name + " filter")
props := property{
{“profile”, “constrained-baseline”},
{“alignment”, “au”},
{“stream-format”, “byte-stream”},
{“width”, width},
{“height”, height},
}
capsSet(filter, structure{“video/x-h264”, props})
o = append(o, filter)

		// Parser
		parser, _ := gst.ElementMake(name+" parser", "h264parse")
		parser.Set("config-interval", int(-1))  // Force parser to add codec_data in-band
		o = append(o, parser)

		// Decoder
		dec, _ := gst.ElementMake(name+" codec", "nvh264dec")
		
		dec.Set("error-resilient", 1)  // Enable error resilience
		dec.Set("max-errors", -1)  // Don't give up on errors
		o = append(o, dec)

		// We'll remove the postcaps filter for now and let the decoder negotiate its output format

		// CUDA conversion and scaling
		if haveConvertScale {
			conv, _ := gst.ElementMake(name+" conv", "cudaconvertscale")
			conv.Set("cuda-memory-type", 0)  // 0 for CUDA memory
			o = append(o, conv)
		} else {
			conv, _ := gst.ElementMake(name+" conv", "cudaconvert")
			o = append(o, conv)

			scale, _ := gst.ElementMake(name+" scale", "cudascale")
			o = append(o, scale)
		}

		// Download to system memory
		download, _ := gst.ElementMake(name+" download", "cudadownload")
		o = append(o, download)

		// Add a caps filter after download to ensure correct output format
		outcaps := gst.FilterMake(name + " outcaps")
		outcapsProps := []property{
			{"format", "RGBA"},  // or whatever format you need
			{"width", width},
			{"height", height},
		}
		capsSet(outcaps, structure{"video/x-raw", outcapsProps})
		o = append(o, outcaps)

gst level 4 debug logs:

unified-1 | 0:02:03.665873222 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 112 will be dropped
unified-1 | 0:02:03.665925692 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 112 will be dropped
unified-1 | 0:02:03.665947357 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 194 will be dropped
unified-1 | 0:02:03.695861541 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 188 will be dropped
unified-1 | 0:02:03.700408568 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30628, pts 0:00:02.400000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.713343305 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:03.745405260 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 141 will be dropped
unified-1 | 0:02:03.745473899 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 169 will be dropped
unified-1 | 0:02:03.745501925 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 182 will be dropped
unified-1 | 0:02:03.775204352 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30630, pts 0:00:02.440000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.775252423 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30631, pts 0:00:02.460000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.835950291 7 0x7388ac002060 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<video decoder 2 jitter> Add Lost timer for #10988, pts 0:00:02.252000000, duration 0:00:00.076000000, offset +0:00:00.200000000
unified-1 | 0:02:03.856038646 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 224 will be dropped
unified-1 | 0:02:03.856102519 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 430 will be dropped
unified-1 | 0:02:03.880047997 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:03.898050006 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30634, pts 0:00:02.520000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.898085520 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30635, pts 0:00:02.540000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.898097988 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30636, pts 0:00:02.560000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.913337173 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:03.923571338 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30638, pts 0:00:02.600000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.923609247 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30639, pts 0:00:02.620000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.923627440 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30640, pts 0:00:02.640000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:03.946681761 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:03.979989848 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.013342004 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.020346234 7 0x7388804d5300 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 359 will be dropped
unified-1 | 0:02:04.046667360 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.080053180 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.080903623 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30643, pts 0:00:02.700000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:04.080951524 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30644, pts 0:00:02.720000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:04.080974326 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30645, pts 0:00:02.740000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:04.098882832 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30647, pts 0:00:02.780000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:04.113354037 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.123471153 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30649, pts 0:00:02.820000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:04.146660772 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.180009905 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.213325897 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.246667422 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.257293722 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30652, pts 0:00:02.880000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:04.257339167 7 0x7388b800e700 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2777:gst_rtp_jitter_buffer_handle_missing_packets:<audio decoder 2 jitter> Add Lost timer for #30653, pts 0:00:02.900000000, duration 0:00:00.020000000, offset +0:00:00.200000000
unified-1 | 0:02:04.279999545 7 0x7388b800e460 INFO appsink gstappsink.c:1150:gst_app_sink_render_list:<video encoder 2 output> chaining each group in list as a merged buffer
unified-1 | 0:02:04.291466023 7 0x7388ac002060 INFO rtpjitterbuffer gstrtpjitterbuffer.c:2697:gst_rtp_jitter_buffer_handle_missing_packets:<video decoder 2 jitter> lost event for 1 packet(s) (#10991->#10991) for duration 0:00:00.312000000
unified-1 | 0:02:04.291880059 7 0x7388804d5300 INFO videodecoder gstvideodecoder.c:1298:gst_video_decoder_negotiate_default_caps:<video decoder 2 codec> Chose default caps video/x-raw(memory:CUDAMemory), width=(int)640, height=(int)480, framerate=(fraction)0/1, format=(string)NV12 for initial gap
unified-1 |
unified-1 | (space:7): GStreamer-Video-CRITICAL **: 02:36:07.088: gst_video_info_set_format_common: assertion ‘format != GST_VIDEO_FORMAT_UNKNOWN’ failed

@seungha you’re guidance here would be greatly appreciated!

I’ve tried several things to no avail :confused:

We didn’t have a h264parser before, so I added that and now we see several warnings before the critical failure:

unified-1 | 0:00:21.521172402 7 0x7dce640054c0 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 5 Slice IDR, Size: 2700 will be dropped
unified-1 | 0:00:21.521214831 7 0x7dce640054c0 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 155 will be dropped
unified-1 | 0:00:21.521247433 7 0x7dce640054c0 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 390 will be dropped
unified-1 | 0:00:21.521266215 7 0x7dce640054c0 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 310 will be dropped
unified-1 | 0:00:21.549144365 7 0x7dce640054c0 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 165 will be dropped

… skipped for brevity …

unified-1 | 0:00:30.100433994 7 0x7dce640054c0 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 178 will be dropped
unified-1 | 0:00:30.100458478 7 0x7dce640054c0 WARN h264parse gsth264parse.c:1523:gst_h264_parse_handle_frame:<video decoder 2 parser> broken/invalid nal Type: 1 Slice, Size: 101 will be dropped