Implementation of opuswriter

- Implemented a common "Writer" interface
- Made IVFWriter compliant to the new interface
- Implemented an OGG Opus writer
- Updated the save-file example
- Updated janus-gateway/streaming example
- Wrote a few unit tests for opus-writer
- Wrote a few unit tests for ivf-writer
- Fixed filenames
- Improved API to allow tests using an io.Writer
This commit is contained in:
Antoine Baché
2019-02-26 00:19:07 -08:00
committed by Antoine Baché
parent 6fd4ee67f4
commit 07e5c4e07e
7 changed files with 576 additions and 40 deletions

View File

@@ -6,13 +6,33 @@ import (
"github.com/pions/rtcp"
"github.com/pions/webrtc"
"github.com/pions/webrtc/pkg/media"
"github.com/pions/webrtc/pkg/media/ivfwriter"
"github.com/pions/webrtc/pkg/media/opuswriter"
"github.com/pions/webrtc/examples/internal/signal"
)
func main() {
func saveToDisk(i media.Writer, track *webrtc.Track) {
defer func() {
if err := i.Close(); err != nil {
panic(err)
}
}()
for {
packet, err := track.ReadRTP()
if err != nil {
panic(err)
}
if err := i.AddPacket(packet); err != nil {
panic(err)
}
}
}
func main() {
// Create a MediaEngine object to configure the supported codec
m := webrtc.MediaEngine{}
@@ -49,31 +69,28 @@ func main() {
go func() {
ticker := time.NewTicker(time.Second * 3)
for range ticker.C {
err := peerConnection.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC()})
if err != nil {
fmt.Println(err)
errSend := peerConnection.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC()})
if errSend != nil {
fmt.Println(errSend)
}
}
}()
if track.Codec().Name == webrtc.VP8 {
codec := track.Codec()
if codec.Name == webrtc.Opus {
fmt.Println("Got Opus track, saving to disk as output.opus")
i, err := opuswriter.New("output.opus", codec.ClockRate, codec.Channels)
if err != nil {
panic(err)
}
saveToDisk(i, track)
} else if codec.Name == webrtc.VP8 {
fmt.Println("Got VP8 track, saving to disk as output.ivf")
i, err := ivfwriter.New("output.ivf")
if err != nil {
panic(err)
}
for {
packet, err := track.ReadRTP()
if err != nil {
panic(err)
}
err = i.AddPacket(packet)
if err != nil {
panic(err)
}
}
saveToDisk(i, track)
}
})