Fix OpusWriter issues that break VLC

* Correctly calculate page CRC
Ogg uses slightly non-standard version of CRC, we are unable to
use the Go's version. You can see the details here[0], in summary
"direct algorithm, initial val and final XOR = 0,
generator polynomial=0x04c11db7"

[0] https://xiph.org/vorbis/doc/framing.html

* Properly set EOS value
Before we created a new page with an EOS. Instead seek backwards
and update the last page with valid Opus to have EOS header and
re-generate the CRC

* Only use 0 timestamp/granule for headers
Audio itself should start from 0

* Rename OpusWriter -> OggWriter
Ogg supports more then just Opus, renaming gives us the flexibility to
expand in the future.
This commit is contained in:
Sean DuBois
2019-08-15 15:56:16 -07:00
committed by Sean DuBois
parent 12efd3e258
commit 6209597312
6 changed files with 275 additions and 222 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/pion/webrtc/v2"
"github.com/pion/webrtc/v2/pkg/media"
"github.com/pion/webrtc/v2/pkg/media/ivfwriter"
"github.com/pion/webrtc/v2/pkg/media/opuswriter"
"github.com/pion/webrtc/v2/pkg/media/oggwriter"
"github.com/pion/webrtc/v2/examples/internal/signal"
)
@@ -68,7 +68,7 @@ func main() {
panic(err)
}
opusFile, err := opuswriter.New("output.opus", 48000, 2)
oggFile, err := oggwriter.New("output.ogg", 48000, 2)
if err != nil {
panic(err)
}
@@ -95,7 +95,7 @@ func main() {
codec := track.Codec()
if codec.Name == webrtc.Opus {
fmt.Println("Got Opus track, saving to disk as output.opus (48 kHz, 2 channels)")
saveToDisk(opusFile, track)
saveToDisk(oggFile, track)
} else if codec.Name == webrtc.VP8 {
fmt.Println("Got VP8 track, saving to disk as output.ivf")
saveToDisk(ivfFile, track)
@@ -112,7 +112,7 @@ func main() {
} else if connectionState == webrtc.ICEConnectionStateFailed ||
connectionState == webrtc.ICEConnectionStateDisconnected {
closeErr := opusFile.Close()
closeErr := oggFile.Close()
if closeErr != nil {
panic(closeErr)
}