pion/webrtc · error

codec is already set

Error message

codec is already set

What it means

Returned by the WithCodec option when it is applied to a writer whose codec was already configured. NewWith applies each Option once during construction, so this fires when WithCodec is supplied more than once (e.g. NewWith(buf, WithCodec(mimeTypeAV1), WithCodec(mimeTypeAV1))). Only one codec may be set per writer.

Source

Thrown at pkg/media/ivfwriter/ivfwriter.go:22

// WithCodec configures if IVFWriter is writing AV1 or VP8 packets to disk.
func WithCodec(mimeType string) Option {
	return func(i *IVFWriter) error {
		if i.codec != codecUnset {
			return errCodecAlreadySet
		}

		switch mimeType {
		case mimeTypeVP8:
			i.codec = codecVP8
		case mimeTypeVP9:
			i.codec = codecVP9
		case mimeTypeAV1:
			i.codec = codecAV1
		default:
			return errNoSuchCodec
		}
		return nil
	}
}

View on GitHub (pinned to 8c25dc09fa)

Solutions

  1. Pass WithCodec only once in the NewWith option list
  2. Remove duplicate WithCodec options; a single call with the desired mime type is enough
  3. If codec may be chosen conditionally, build the options slice with at most one WithCodec entry
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/media/ivfwriter/ivfwriter.go:22 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pion/webrtc@8c25dc09fa (2026-09-03). Data as JSON: /api/errors/68e0ec0a97894720. Report an issue: GitHub.