producer simulcast ssrc mixed up / race condition ?

yes browser app using last version of mediasoup-client

I’m currently suspecting RTC::RtpStreamRecv* Producer::GetRtpStream(RTC::RtpPacket* packet) also overrides its internal producer ssrc map. Possible ?

No. The Producer only gets RTP packets after Producer look up in RtpListener.getProducer(packet), and that’s what my PR fixes.

Please check transport.dump() to see the ssrc / mid / rid tables.

Also, verify that Producer 1 and Producer 2 generated by your app have different mid values.

2025-11-21T12:28:46.687Z:
{
    "event": "init",
    "producerId": "ab767618-ba4f-47ec-9229-19045844b9af",
    "producerMid": "5",
    "transportDump": {
        "id": "d7c378b4-5a9c-4e19-9154-e9739eb64231",
        "producerIds": [
            "ab767618-ba4f-47ec-9229-19045844b9af"
        ],
        "rtpListener": {
            "ssrcTable": [],
            "midTable": [
                {
                    "key": "5",
                    "value": "ab767618-ba4f-47ec-9229-19045844b9af"
                }
            ],
            "ridTable": [
                {
                    "key": "r2",
                    "value": "ab767618-ba4f-47ec-9229-19045844b9af"
                },
                {
                    "key": "r1",
                    "value": "ab767618-ba4f-47ec-9229-19045844b9af"
                },
                {
                    "key": "r0",
                    "value": "ab767618-ba4f-47ec-9229-19045844b9af"
                }
            ]
        }
    },
    "producerDump": {
        "id": "ab767618-ba4f-47ec-9229-19045844b9af",
        "kind": "video",
        "type": "simulcast",
        "rtpParameters": {
            "mid": "5",
            "codecs": [
                {
                    "mimeType": "video/VP8",
                    "payloadType": 96,
                    "clockRate": 90000,
                    "parameters": {},
                    "rtcpFeedback": [
                        {
                            "type": "goog-remb"
                        },
                        {
                            "type": "transport-cc"
                        },
                        {
                            "type": "ccm",
                            "parameter": "fir"
                        },
                        {
                            "type": "nack"
                        },
                        {
                            "type": "nack",
                            "parameter": "pli"
                        }
                    ]
                },
                {
                    "mimeType": "video/rtx",
                    "payloadType": 97,
                    "clockRate": 90000,
                    "parameters": {
                        "apt": 96
                    },
                    "rtcpFeedback": []
                }
            ],
            "headerExtensions": [
                {
                    "uri": "urn:ietf:params:rtp-hdrext:sdes:mid",
                    "id": 9,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",
                    "id": 10,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id",
                    "id": 11,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
                    "id": 2,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
                    "id": 4,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension",
                    "id": 13,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "urn:3gpp:video-orientation",
                    "id": 3,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "urn:ietf:params:rtp-hdrext:toffset",
                    "id": 1,
                    "encrypt": false,
                    "parameters": {}
                },
                {
                    "uri": "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay",
                    "id": 5,
                    "encrypt": false,
                    "parameters": {}
                }
            ],
            "encodings": [
                {
                    "rid": "r0",
                    "codecPayloadType": 96,
                    "dtx": false,
                    "scalabilityMode": "L1T3"
                },
                {
                    "rid": "r1",
                    "codecPayloadType": 96,
                    "dtx": false,
                    "scalabilityMode": "L1T3"
                },
                {
                    "rid": "r2",
                    "codecPayloadType": 96,
                    "dtx": false,
                    "scalabilityMode": "L1T3"
                }
            ],
            "rtcp": {
                "cname": "40bcb745",
                "reducedSize": true
            }
        },
        "rtpMapping": {
            "codecs": [
                {
                    "payloadType": 97,
                    "mappedPayloadType": 100
                },
                {
                    "payloadType": 96,
                    "mappedPayloadType": 125
                }
            ],
            "encodings": [
                {
                    "rid": "",
                    "ssrc": null,
                    "scalabilityMode": null,
                    "mappedSsrc": 354348319
                },
                {
                    "rid": "",
                    "ssrc": null,
                    "scalabilityMode": null,
                    "mappedSsrc": 354348320
                },
                {
                    "rid": "",
                    "ssrc": null,
                    "scalabilityMode": null,
                    "mappedSsrc": 354348321
                }
            ]
        },
        "traceEventTypes": [
            "rtp"
        ],
        "paused": false
    }
}

2025-11-21T12:28:46.719Z:
{
	"event": "producer.score",
	"producerId": "ab767618-ba4f-47ec-9229-19045844b9af",
	"score": [
		{
			"encodingIdx": 1,
			"ssrc": 2680559914,
			"rid": "r1",
			"score": 10
		}
	],
	"producerMid": "5",
	"transportDump": {
		"id": "d7c378b4-5a9c-4e19-9154-e9739eb64231",
		"producerIds": [
			"ab767618-ba4f-47ec-9229-19045844b9af"
		],
		"rtpListener": {
			"ssrcTable": [
				{
					"key": 2680559914,
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				}
			],
			"midTable": [
				{
					"key": "5",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				}
			],
			"ridTable": [
				{
					"key": "r2",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				},
				{
					"key": "r1",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				},
				{
					"key": "r0",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				}
			]
		}
	},
	"producerDump": {
		"id": "ab767618-ba4f-47ec-9229-19045844b9af",
		"kind": "video",
		"type": "simulcast",
		"rtpParameters": {
			"mid": "5",
			"codecs": [
				{
					"mimeType": "video/VP8",
					"payloadType": 96,
					"clockRate": 90000,
					"parameters": {},
					"rtcpFeedback": [
						{
							"type": "goog-remb"
						},
						{
							"type": "transport-cc"
						},
						{
							"type": "ccm",
							"parameter": "fir"
						},
						{
							"type": "nack"
						},
						{
							"type": "nack",
							"parameter": "pli"
						}
					]
				},
				{
					"mimeType": "video/rtx",
					"payloadType": 97,
					"clockRate": 90000,
					"parameters": {
						"apt": 96
					},
					"rtcpFeedback": []
				}
			],
			"headerExtensions": [
				{
					"uri": "urn:ietf:params:rtp-hdrext:sdes:mid",
					"id": 9,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",
					"id": 10,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id",
					"id": 11,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
					"id": 2,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
					"id": 4,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension",
					"id": 13,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:3gpp:video-orientation",
					"id": 3,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:ietf:params:rtp-hdrext:toffset",
					"id": 1,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay",
					"id": 5,
					"encrypt": false,
					"parameters": {}
				}
			],
			"encodings": [
				{
					"rid": "r0",
					"codecPayloadType": 96,
					"dtx": false,
					"scalabilityMode": "L1T3"
				},
				{
					"rid": "r1",
					"codecPayloadType": 96,
					"dtx": false,
					"scalabilityMode": "L1T3"
				},
				{
					"rid": "r2",
					"codecPayloadType": 96,
					"dtx": false,
					"scalabilityMode": "L1T3"
				}
			],
			"rtcp": {
				"cname": "40bcb745",
				"reducedSize": true
			}
		},
		"rtpMapping": {
			"codecs": [
				{
					"payloadType": 97,
					"mappedPayloadType": 100
				},
				{
					"payloadType": 96,
					"mappedPayloadType": 125
				}
			],
			"encodings": [
				{
					"rid": "",
					"ssrc": null,
					"scalabilityMode": null,
					"mappedSsrc": 354348319
				},
				{
					"rid": "",
					"ssrc": null,
					"scalabilityMode": null,
					"mappedSsrc": 354348320
				},
				{
					"rid": "",
					"ssrc": null,
					"scalabilityMode": null,
					"mappedSsrc": 354348321
				}
			]
		},
		"rtpStreams": [
			{
				"params": {
					"encodingIdx": 1,
					"ssrc": 2680559914,
					"payloadType": 96,
					"mimeType": "video/VP8",
					"clockRate": 90000,
					"rid": "r1",
					"cname": "40bcb745",
					"rtxSsrc": null,
					"rtxPayloadType": null,
					"useNack": true,
					"usePli": true,
					"useFir": true,
					"useInBandFec": false,
					"useDtx": false,
					"spatialLayers": 1,
					"temporalLayers": 3
				},
				"score": 10,
				"rtxStream": null
			}
		],
		"traceEventTypes": [
			"rtp"
		],
		"paused": false
	}
}

2025-11-21T12:28:46.719Z:
{
	"event": "producer.trace.rtp",
	"producerId": "ab767618-ba4f-47ec-9229-19045844b9af",
	"trace": {
		"type": "rtp",
		"timestamp": 256081728,
		"direction": "in",
		"info": {
			"isRtx": false,
			"rtpPacket": {
				"isKeyFrame": false,
				"mid": "4",
				"rid": "r1",
				"rrid": "r1",
				"spatialLayer": 0,
				"ssrc": 2680559914
			}
		}
	}
}

2025-11-21T12:28:46.739Z:
{
	"event": "producer.score",
	"producerId": "ab767618-ba4f-47ec-9229-19045844b9af",
	"score": [
		{
			"encodingIdx": 0,
			"ssrc": 2447196065,
			"rid": "r0",
			"score": 10
		},
		{
			"encodingIdx": 1,
			"ssrc": 2680559914,
			"rid": "r1",
			"score": 10
		}
	],
	"producerMid": "5",
	"transportDump": {
		"id": "d7c378b4-5a9c-4e19-9154-e9739eb64231",
		"producerIds": [
			"ab767618-ba4f-47ec-9229-19045844b9af"
		],
		"rtpListener": {
			"ssrcTable": [
				{
					"key": 2447196065,
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				},
				{
					"key": 2680559914,
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				}
			],
			"midTable": [
				{
					"key": "5",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				}
			],
			"ridTable": [
				{
					"key": "r2",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				},
				{
					"key": "r1",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				},
				{
					"key": "r0",
					"value": "ab767618-ba4f-47ec-9229-19045844b9af"
				}
			]
		}
	},
	"producerDump": {
		"id": "ab767618-ba4f-47ec-9229-19045844b9af",
		"kind": "video",
		"type": "simulcast",
		"rtpParameters": {
			"mid": "5",
			"codecs": [
				{
					"mimeType": "video/VP8",
					"payloadType": 96,
					"clockRate": 90000,
					"parameters": {},
					"rtcpFeedback": [
						{
							"type": "goog-remb"
						},
						{
							"type": "transport-cc"
						},
						{
							"type": "ccm",
							"parameter": "fir"
						},
						{
							"type": "nack"
						},
						{
							"type": "nack",
							"parameter": "pli"
						}
					]
				},
				{
					"mimeType": "video/rtx",
					"payloadType": 97,
					"clockRate": 90000,
					"parameters": {
						"apt": 96
					},
					"rtcpFeedback": []
				}
			],
			"headerExtensions": [
				{
					"uri": "urn:ietf:params:rtp-hdrext:sdes:mid",
					"id": 9,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",
					"id": 10,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id",
					"id": 11,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
					"id": 2,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
					"id": 4,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension",
					"id": 13,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:3gpp:video-orientation",
					"id": 3,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "urn:ietf:params:rtp-hdrext:toffset",
					"id": 1,
					"encrypt": false,
					"parameters": {}
				},
				{
					"uri": "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay",
					"id": 5,
					"encrypt": false,
					"parameters": {}
				}
			],
			"encodings": [
				{
					"rid": "r0",
					"codecPayloadType": 96,
					"dtx": false,
					"scalabilityMode": "L1T3"
				},
				{
					"rid": "r1",
					"codecPayloadType": 96,
					"dtx": false,
					"scalabilityMode": "L1T3"
				},
				{
					"rid": "r2",
					"codecPayloadType": 96,
					"dtx": false,
					"scalabilityMode": "L1T3"
				}
			],
			"rtcp": {
				"cname": "40bcb745",
				"reducedSize": true
			}
		},
		"rtpMapping": {
			"codecs": [
				{
					"payloadType": 97,
					"mappedPayloadType": 100
				},
				{
					"payloadType": 96,
					"mappedPayloadType": 125
				}
			],
			"encodings": [
				{
					"rid": "",
					"ssrc": null,
					"scalabilityMode": null,
					"mappedSsrc": 354348319
				},
				{
					"rid": "",
					"ssrc": null,
					"scalabilityMode": null,
					"mappedSsrc": 354348320
				},
				{
					"rid": "",
					"ssrc": null,
					"scalabilityMode": null,
					"mappedSsrc": 354348321
				}
			]
		},
		"rtpStreams": [
			{
				"params": {
					"encodingIdx": 0,
					"ssrc": 2447196065,
					"payloadType": 96,
					"mimeType": "video/VP8",
					"clockRate": 90000,
					"rid": "r0",
					"cname": "40bcb745",
					"rtxSsrc": null,
					"rtxPayloadType": null,
					"useNack": true,
					"usePli": true,
					"useFir": true,
					"useInBandFec": false,
					"useDtx": false,
					"spatialLayers": 1,
					"temporalLayers": 3
				},
				"score": 10,
				"rtxStream": null
			},
			{
				"params": {
					"encodingIdx": 1,
					"ssrc": 2680559914,
					"payloadType": 96,
					"mimeType": "video/VP8",
					"clockRate": 90000,
					"rid": "r1",
					"cname": "40bcb745",
					"rtxSsrc": null,
					"rtxPayloadType": null,
					"useNack": true,
					"usePli": true,
					"useFir": true,
					"useInBandFec": false,
					"useDtx": false,
					"spatialLayers": 1,
					"temporalLayers": 3
				},
				"score": 10,
				"rtxStream": null
			}
		],
		"traceEventTypes": [
			"rtp"
		],
		"paused": false
	}
}

2025-11-21T12:28:46.739Z:
{
	"event": "producer.trace.rtp",
	"producerId": "ab767618-ba4f-47ec-9229-19045844b9af",
	"trace": {
		"type": "rtp",
		"timestamp": 256081748,
		"direction": "in",
		"info": {
			"isRtx": false,
			"rtpPacket": {
				"isKeyFrame": false,
				"mid": "4",
				"rid": "r0",
				"rrid": "r0",
				"spatialLayer": 0,
				"ssrc": 2447196065
			}
		}
	}
}



Transport ssrc table is filled with previous closed producer (mid=4) and rtp packets of new producer (mid=5) are ignored. “ab767618-ba4f-47ec-9229-19045844b9af” is the last producer, the one that should handle mid=5 packets.

Btw I see that producerDump.rtpStreams contains an incorrect ssrc (previous mid=4), and there is no mid value in it

Ok, various things here:

  1. Please pull my PR branch again (I’ve updated it), enable “rtp” in the logTags in your createWorker() and run your app, and let me know if you get these new warning logs.
  2. Also pay attention to these new (temporal) logs that will be printed when inserting an entry in the SSRC table based on the MID or RID of the received RTP packet.
  3. You said 3 comments above that you see Producer “score” event with wrong ssrcs. Please add periodic logs about it.
  4. I would also appreciate that in your scenario and logs you add the creation of the previous Producer and its closure, and dumps and so on in between.

More things:

From what I see, the only issue is that, for whatever reason, the Producer “rtp” trace event is fired with wrong info. It contains info about a RTP packet that has the expected ssrc 2447196065 or 2680559914 (which correspond to the “r0” and “r1” encodings of the alive Producer with mid “5”), however the “rtp” trace event contains mid “4”.

The thing here is that the Producer “rtp” trace event literally reads mid, rid and ssrc from the RTP packet. It doesn’t report the “current mid, rids or ssrcs of the Producer”. So what you see is what it happens: For whatever reason mediasoup is receiving a RTP packet with ssrc 2447196065 or 2680559914 (so it’s identified as Producer 1) but such a packet has an incorrect mid “4” instead of “5”. I cannot explain it.

Hi,

It looks like I was using the prebuilt worker :face_without_mouth:
I added the flag MEDIASOUP_SKIP_WORKER_PREBUILT_DOWNLOAD but unfortunately now the build fails with this error :
ERROR: Subproject libuv is buildable: NO

meson.build:246:13: ERROR: Subproject exists but has no meson.build file.

It’s built on image node:lts with build-essential python3-pip installed, any idea ?

Run “make clean-all” and then “make-clean-pip” or something like that on worker/ directory and try again.

And use “MEDIASOUP_DEV=true npm install mediasoup”.

Ok I finally managed to build.
I had to set the flag MEDIASOUP_LOCAL_DEV and I added cleanWorkerArtifacts(); before buildWorker(); in npm-scripts.js .
It now works correctly on my app as well thanks to your fix

Great. Thanks for confirming.

Released in mediasoup 3.19.12

Great ! Thank you for your time and fix