Added muxer header option

This commit is contained in:
Quentin Renard
2025-01-24 15:01:06 +01:00
parent 2025e88729
commit 61df210b82

View File

@@ -20,6 +20,7 @@ type Muxer struct {
c *astikit.Chan
formatContext *astiav.FormatContext
eh *astiencoder.EventHandler
header map[string]string
o *sync.Once
p *pktPool
restamper PktRestamper
@@ -32,6 +33,7 @@ type Muxer struct {
type MuxerOptions struct {
Format *astiav.OutputFormat
FormatName string
Header map[string]string
Node astiencoder.NodeOptions
Restamper PktRestamper
URL string
@@ -47,6 +49,7 @@ func NewMuxer(o MuxerOptions, eh *astiencoder.EventHandler, c *astikit.Closer, s
m = &Muxer{
c: astikit.NewChan(astikit.ChanOptions{ProcessAll: true}),
eh: eh,
header: o.Header,
o: &sync.Once{},
restamper: o.Restamper,
}
@@ -150,9 +153,22 @@ func (m *Muxer) FormatContext() *astiav.FormatContext {
// Start starts the muxer
func (m *Muxer) Start(ctx context.Context, t astiencoder.CreateTaskFunc) {
m.BaseNode.Start(ctx, t, func(t *astikit.Task) {
// Create header dictionary
var d *astiav.Dictionary
if len(m.header) > 0 {
d = astiav.NewDictionary()
defer d.Free()
for k, v := range m.header {
if err := d.Set(k, v, astiav.NewDictionaryFlags()); err != nil {
emitError(m, m.eh, err, "setting header dictionary %s=%s", k, v)
return
}
}
}
// Make sure to write header once
var err error
m.o.Do(func() { err = m.formatContext.WriteHeader(nil) })
m.o.Do(func() { err = m.formatContext.WriteHeader(d) })
if err != nil {
emitError(m, m.eh, err, "writing header")
return