Files
upstream-pion-webrtc/pkg/media/rtpdump/writer.go
upstream-mirror 8acb1a3a29
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s
snapshot of https://github.com/pion/webrtc.git (main, 2026-09-15; blobs > 131072B omitted)
2026-09-15 20:06:07 +05:00

55 lines
1.0 KiB
Go

// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package rtpdump
import (
"fmt"
"io"
"sync"
)
// Writer writes the RTPDump file format.
type Writer struct {
writerMu sync.Mutex
writer io.Writer
}
// NewWriter makes a new Writer and immediately writes the given Header
// to begin the file.
func NewWriter(w io.Writer, hdr Header) (*Writer, error) {
preamble := fmt.Sprintf(
"#!rtpplay1.0 %s/%d\n",
hdr.Source.To4().String(),
hdr.Port)
if _, err := w.Write([]byte(preamble)); err != nil {
return nil, err
}
hData, err := hdr.Marshal()
if err != nil {
return nil, err
}
if _, err := w.Write(hData); err != nil {
return nil, err
}
return &Writer{writer: w}, nil
}
// WritePacket writes a Packet to the output.
func (w *Writer) WritePacket(p Packet) error {
w.writerMu.Lock()
defer w.writerMu.Unlock()
data, err := p.Marshal()
if err != nil {
return err
}
if _, err := w.writer.Write(data); err != nil {
return err
}
return nil
}