forked from yapingcat/gomedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathogg-demuxer_test.go
56 lines (51 loc) · 1.84 KB
/
ogg-demuxer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ogg
import (
"fmt"
"os"
"testing"
"github.com/yapingcat/gomedia/go-codec"
)
func TestDemuxer_Input(t *testing.T) {
t.Run("ogg demux", func(t *testing.T) {
demuxer := NewDemuxer()
demuxer.OnPacket = func(streamId uint32, granule uint64, packet []byte, lost int) {
//fmt.Printf("onpacket sid:%d granule:%d package len:%d lost:%d\n", streamId, granule, len(packet), lost)
}
getAudioParam := false
getVideoParam := false
demuxer.OnFrame = func(streamId uint32, cid codec.CodecID, frame []byte, pts, dts uint64, lost int) {
if cid == codec.CODECID_AUDIO_OPUS {
param := demuxer.GetAudioParam()
if param != nil && !getAudioParam {
fmt.Println(param)
getAudioParam = true
}
fmt.Printf("opus frame:sid[%d] frame len:[%d] pts:[%d] dts:[%d] lost:%d\n", streamId, len(frame), pts, dts, lost)
} else if cid == codec.CODECID_VIDEO_VP8 {
param := demuxer.GetVideoParam()
if param != nil && !getVideoParam {
fmt.Println(param)
getVideoParam = true
}
fmt.Printf("vp8 frame:sid[%d] frame len:[%d] pts:[%d] dts:[%d] lost:%d\n", streamId, len(frame), pts, dts, lost)
}
}
demuxer.OnPage = func(page *oggPage) {
// PrintPage(page)
}
oggfile, _ := os.Open("test.ogg")
buf := make([]byte, 4096)
for {
n, err := oggfile.Read(buf)
if err != nil {
fmt.Println(err)
break
}
//fmt.Printf("read buf %d\n", n)
err = demuxer.Input(buf[0:n])
if err != nil {
fmt.Println(err)
}
}
})
}