{"record":{"id":"7fc8a5dc5121e822","repo":"pion/webrtc","slug":"rtp-packet-ssrc-does-not-match-ogg-track-ssrc","errorCode":null,"errorMessage":"RTP packet SSRC does not match Ogg track SSRC","messagePattern":"RTP packet SSRC does not match Ogg track SSRC","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggwriter/oggwriter.go","lineNumber":54,"sourceCode":"\tchannelMappingFamily255            = 255\n\tidPageSignature                    = \"OpusHead\"\n\tcommentPageSignature               = \"OpusTags\"\n\tdefaultVendor                      = \"pion\"\n\tpageHeaderSignature                = \"OggS\"\n\tpageHeaderSize                     = 27\n\tmaxOggPageSegments                 = 255\n\tnoGranulePosition                  = ^uint64(0)\n\tmaxUint32Length                    = uint64(1<<32 - 1)\n)\n\nvar (\n\terrFileNotOpened        = errors.New(\"file not opened\")\n\terrOutputNotOpened      = errors.New(\"output not opened\")\n\terrInvalidNilPacket     = errors.New(\"invalid nil packet\")\n\terrDuplicateTrackSSRC   = errors.New(\"duplicate Ogg track SSRC\")\n\terrDuplicateTrackSerial = errors.New(\"duplicate Ogg track serial\")\n\terrTracksStarted        = errors.New(\"cannot add Ogg tracks after writing has started\")\n\terrPacketSSRCMismatch   = errors.New(\"RTP packet SSRC does not match Ogg track SSRC\")\n\terrInvalidOpusPacket    = errors.New(\"invalid Opus packet\")\n\terrInvalidChannelCount  = errors.New(\"invalid channel count\")\n\terrInvalidChannelMap    = errors.New(\"invalid channel mapping\")\n\terrInvalidOpusTags      = errors.New(\"invalid OpusTags\")\n)\n\ntype pageRewriter interface {\n\tio.Seeker\n\tio.WriterAt\n}\n\ntype writerConfig struct {\n\tsampleRate     uint32\n\tchannelMapping channelMapping\n\tpageRewriter   pageRewriter\n\topusTags       OpusTags\n}\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggwriter/oggwriter.go#L36-L72","documentation":"errPacketSSRCMismatch is returned by Track.WriteRTP when the RTP packet's SSRC does not match the SSRC the track was created with. Each Ogg track is bound to exactly one RTP synchronization source, so routing packets from a different SSRC would mix streams and corrupt the Opus mapping. This is a per-track input validation error.","triggerScenarios":"Calling track.WriteRTP(packet) where packet.SSRC != track's ssrc — e.g. writing a packet with SSRC 2222 to a track created with NewTrack(1111, ...).","commonSituations":"Renegotiated RTP streams where the sender changed SSRC mid-session; forwarding packets from multiple peers into one track; a bug in a track-routing map keyed by the wrong field; a stream restart with a new random SSRC.","solutions":["Route each RTP packet to the track matching its SSRC (use a map[uint32]*Track)","Recreate the track with NewTrack(packet.SSRC) when the sender's SSRC legitimately changes","Verify SSRC values at setup match what the RTP session actually delivers"],"exampleFix":"// before\ntrack, _ := writer.NewTrack(1111, nil)\nerr := track.WriteRTP(pktWithSSRC(2222)) // mismatch\n// after\ntracks := map[uint32]*Track{}\ntrack, _ := writer.NewTrack(1111, nil)\ntracks[1111] = track\nerr := tracks[pkt.SSRC].WriteRTP(pkt)","handlingStrategy":"try-catch","validationCode":"func writeIfMine(t *Track, pkt *rtp.Packet) error {\n    if pkt.SSRC != t.SSRC() {\n        return fmt.Errorf(\"skip pkt ssrc=%d track ssrc=%d\", pkt.SSRC, t.SSRC())\n    }\n    return t.WriteRTP(pkt)\n}","typeGuard":null,"tryCatchPattern":"if err := track.WriteRTP(pkt); err != nil {\n    if strings.Contains(err.Error(), \"SSRC does not match\") {\n        // route to correct track or drop\n    }\n}","preventionTips":["Dispatch packets by SSRC through a map[uint32]Track","Handle SSRC changes (RTP renegotiation) by creating a new track","Log and drop foreign-SSRC packets instead of guessing","Verify SSRC configuration matches the actual RTP session"],"tags":["rtp","ssrc","ogg","media","mismatch"],"backgroundTag":"identifier-mismatch","analyzedSha":"8c25dc09fa9e7c09aac4309ead88093d760432b0","analyzedAt":"2026-09-03T21:56:56.182Z","contentChangedAt":"2026-09-03T21:56:56.182Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}