AlexxIT/go2rtc · error

miss: read media

Error message

miss: read media: %w

What it means

ReadPacket reads a media packet from the camera connection; any transport-level read failure is wrapped as 'miss: read media: %w'. The wrapped cause tells you whether it was a network drop, timeout, or protocol error.

Solutions

  1. Check the wrapped cause (errors.Unwrap / %w chain) to identify the transport failure
  2. Reconnect and create a new Client, then resume ReadPacket
  3. Add retry logic around ReadPacket with backoff for transient network drops
  4. Verify camera network stability (signal strength, firewall keepalives)

Example fix

// before
pkt, err := client.ReadPacket() // panics user on transient drop
if err != nil { return err }
// after
pkt, err := client.ReadPacket()
if err != nil {
    client = reconnectWithBackoff()
    pkt, err = client.ReadPacket()
}
Defensive patterns

Strategy: retry

Try / catch

pkt, err := client.ReadPacket()
if err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) && netErr.Timeout() {
        client = reconnect(ctx)
        pkt, err = client.ReadPacket()
    }
}

Prevention

When it happens

Trigger: Calling Client.ReadPacket while the underlying conn.ReadPacket fails — camera disconnected, network timeout, TUTK/CS2 session dropped.

Common situations: Camera losing Wi-Fi during streaming; camera rebooting mid-stream; NAT/firewall dropping the long-lived media connection; TUTK P2P session expiry.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/d55be6862ee95d42. Report an issue: GitHub.

Appendix: source

Thrown at pkg/xiaomi/miss/client.go:227

}

// SpeakerCodec if the camera model has a non-standard two-way codec.
func (c *Client) SpeakerCodec() uint32 {
	switch c.model {
	case ModelDafang, ModelXiaofang, "isa.camera.hlc6":
		return codecPCM
	case "chuangmi.camera.72ac1":
		return codecOPUS
	}
	return 0
}

const hdrSize = 32

func (c *Client) ReadPacket() (*Packet, error) {
	hdr, payload, err := c.Conn.ReadPacket()
	if err != nil {
		return nil, fmt.Errorf("miss: read media: %w", err)
	}

	if len(hdr) < hdrSize {
		return nil, fmt.Errorf("miss: packet header too small")
	}

	payload, err = crypto.Decode(payload, c.key)
	if err != nil {
		return nil, err
	}

	pkt := &Packet{
		CodecID:  binary.LittleEndian.Uint32(hdr[4:]),
		Sequence: binary.LittleEndian.Uint32(hdr[8:]),
		Flags:    binary.LittleEndian.Uint32(hdr[12:]),
		Payload:  payload,
	}

View on GitHub (pinned to c245815e75)