-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hls muxer: support reading Opus tracks (#1338)
- Loading branch information
Showing
23 changed files
with
427 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aler9/gortsplib/v2/pkg/format" | ||
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtpsimpleaudio" | ||
"github.com/pion/rtp" | ||
) | ||
|
||
type dataOpus struct { | ||
rtpPackets []*rtp.Packet | ||
ntp time.Time | ||
pts time.Duration | ||
frame []byte | ||
} | ||
|
||
func (d *dataOpus) getRTPPackets() []*rtp.Packet { | ||
return d.rtpPackets | ||
} | ||
|
||
func (d *dataOpus) getNTP() time.Time { | ||
return d.ntp | ||
} | ||
|
||
type formatProcessorOpus struct { | ||
format *format.Opus | ||
encoder *rtpsimpleaudio.Encoder | ||
decoder *rtpsimpleaudio.Decoder | ||
} | ||
|
||
func newFormatProcessorOpus( | ||
forma *format.Opus, | ||
allocateEncoder bool, | ||
) (*formatProcessorOpus, error) { | ||
t := &formatProcessorOpus{ | ||
format: forma, | ||
} | ||
|
||
if allocateEncoder { | ||
t.encoder = forma.CreateEncoder() | ||
} | ||
|
||
return t, nil | ||
} | ||
|
||
func (t *formatProcessorOpus) process(dat data, hasNonRTSPReaders bool) error { //nolint:dupl | ||
tdata := dat.(*dataOpus) | ||
|
||
if tdata.rtpPackets != nil { | ||
pkt := tdata.rtpPackets[0] | ||
|
||
// remove padding | ||
pkt.Header.Padding = false | ||
pkt.PaddingSize = 0 | ||
|
||
if pkt.MarshalSize() > maxPacketSize { | ||
return fmt.Errorf("payload size (%d) is greater than maximum allowed (%d)", | ||
pkt.MarshalSize(), maxPacketSize) | ||
} | ||
|
||
// decode from RTP | ||
if hasNonRTSPReaders { | ||
if t.decoder == nil { | ||
t.decoder = t.format.CreateDecoder() | ||
} | ||
|
||
frame, pts, err := t.decoder.Decode(pkt) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tdata.frame = frame | ||
tdata.pts = pts | ||
} | ||
|
||
// route packet as is | ||
return nil | ||
} | ||
|
||
pkt, err := t.encoder.Encode(tdata.frame, tdata.pts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tdata.rtpPackets = []*rtp.Packet{pkt} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package core | ||
package core //nolint:dupl | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package core | ||
package core //nolint:dupl | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.