{"record":{"id":"ddc288019e3a06f2","repo":"pion/webrtc","slug":"invalid-channel-count","errorCode":null,"errorMessage":"invalid channel count","messagePattern":"invalid channel count","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggwriter/oggwriter.go","lineNumber":56,"sourceCode":"\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\ntype trackConfig struct {\n\tsampleRate        uint32","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggwriter/oggwriter.go#L38-L74","documentation":"errInvalidChannelCount is returned when parsing or validating Opus channel mapping data for multichannel streams: the mapping table is empty, longer than math.MaxUint8, or the stream count is not 1 where required. The library only supports channel configurations whose stream/coupled counts match a valid Opus channel mapping.","triggerScenarios":"Building channelMapping from an unsupported channel count (default case of the switch); calling validateChannelMappingLayout with an empty mapping, a mapping longer than 255 bytes, or streamCount != 1.","commonSituations":"Configuring an Opus track with an exotic channel count (e.g. 7.1 with an unsupported mapping family); passing a malformed OpusHead/ident header from an upstream demuxer; hand-built Opus headers in tests with wrong stream/coupled counts.","solutions":["Use a supported channel count (mono or stereo, or a supported multichannel mapping)","Ensure the OpusHead stream/coupled counts match the channel count and mapping table","Verify the mapping table length is between 1 and 255 bytes","Check upstream demuxing — the ident header may be corrupt"],"exampleFix":"// before\n// channels = 3 with mapping family 0 (invalid; family 0 implies <= 2 channels)\n// after\n// use channels = 2 with mapping family 0, or family 1 with a valid mapping table","handlingStrategy":"validation","validationCode":"func validChannelSetup(channels int, mappingFamily byte, streams, coupled uint8, order []byte) bool {\n    if channels <= 0 || channels > 255 || len(order) == 0 {\n        return false\n    }\n    if mappingFamily == 0 && channels > 2 {\n        return false\n    }\n    return int(streams+coupled) == channels\n}","typeGuard":null,"tryCatchPattern":"if err := validateChannelMappingLayout(streams, coupled, order); err != nil {\n    if strings.Contains(err.Error(), \"invalid channel count\") {\n        return nil, fmt.Errorf(\"unsupported channel setup: streams=%d coupled=%d\", streams, coupled)\n    }\n    return nil, err\n}","preventionTips":["Stick to mono/stereo (mapping family 0) unless you need multichannel","Cross-check streamCount + coupledCount against the channel count","Validate OpusHead headers before feeding them to the writer","Test exotic channel layouts against the library's supported mapping table first"],"tags":["opus","channels","validation","ogg"],"backgroundTag":"invalid-channel-config","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"}