Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
deepch committed Feb 1, 2024
1 parent 7a563b0 commit b84c19f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 10 deletions.
25 changes: 25 additions & 0 deletions example/test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"github.com/deepch/vdk/format/ts"
"log"
"os"
)

func main() {
f, _ := os.Open("edb9708f29b24ba9b175808d6b9df9c6541e25766d4a40209a8f903948b72f3f.ts")
m := ts.NewDemuxer(f)
var i int
for {
p, err := m.ReadPacket()
if err != nil {
return
}
if p.IsKeyFrame {
i = 0
}
log.Println(i, p.Time, p.Data[4:10], len(p.Data))
i++

}
}
13 changes: 9 additions & 4 deletions format/mp4f/muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mp4f
import (
"bufio"
"fmt"
"log"
"os"
"time"

Expand Down Expand Up @@ -238,14 +239,15 @@ func (self *Muxer) WriteTrailer() (err error) {
return
}

func (element *Muxer) WriteHeader(streams []av.CodecData) (err error) {
func (element *Muxer) WriteHeader(streams []av.CodecData) error {
element.streams = []*Stream{}
for _, stream := range streams {
if err = element.newStream(stream); err != nil {
return
if err := element.newStream(stream); err != nil {
log.Println("WriteHeader", err)
}
}
return

return nil
}

func (element *Muxer) GetInit(streams []av.CodecData) (string, []byte) {
Expand Down Expand Up @@ -285,6 +287,9 @@ func (element *Muxer) GetInit(streams []av.CodecData) (string, []byte) {
}

func (element *Muxer) WritePacket(pkt av.Packet, GOP bool) (bool, []byte, error) {
if pkt.Idx+1 > int8(len(element.streams)) {
return false, nil, nil
}
stream := element.streams[pkt.Idx]
if GOP {
ts := time.Duration(0)
Expand Down
43 changes: 38 additions & 5 deletions format/rtsp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const (
)

type Client struct {
DebugRtsp bool
DebugRtp bool
Headers []string
DebugRtsp bool
DebugRtp bool
DisableAudio bool
Headers []string

SkipErrRtpBlock bool

Expand Down Expand Up @@ -1076,12 +1077,44 @@ func (self *Stream) handleRtpPacket(packet []byte) (err error) {
err = fmt.Errorf("rtp: packet too short")
return
}
payloadOffset := 12 + int(packet[0]&0xf)*4

timestamp := binary.BigEndian.Uint32(packet[4:8])

/*
Test offset
*/
Padding := (packet[0]>>5)&1 == 1
Extension := (packet[0]>>4)&1 == 1
CSRCCnt := int(packet[0] & 0x0f)

RTPHeaderSize := 12

payloadOffset := RTPHeaderSize
end := len(packet)
if end-payloadOffset >= 4*CSRCCnt {
payloadOffset += 4 * CSRCCnt
}

if Extension && end-payloadOffset >= 4 {
extLen := 4 * int(binary.BigEndian.Uint16(packet[payloadOffset+2:]))
payloadOffset += 4
if end-payloadOffset >= extLen {
payloadOffset += extLen
}
}

if Padding && end-payloadOffset > 0 {
paddingLen := int(packet[end-1])
if end-payloadOffset >= paddingLen {
end -= paddingLen
}
}

if payloadOffset > len(packet) {
err = fmt.Errorf("rtp: packet too short")
return
}
timestamp := binary.BigEndian.Uint32(packet[4:8])

payload := packet[payloadOffset:]

/*
Expand Down
1 change: 1 addition & 0 deletions format/rtsp/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package rtsp
6 changes: 5 additions & 1 deletion format/ts/demuxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ func (self *Stream) payloadEnd() (n int, err error) {
b := make([]byte, 4+len(nalu))
pio.PutU32BE(b[0:4], uint32(len(nalu)))
copy(b[4:], nalu)
self.addPacket(b, time.Duration(0), (1000*time.Millisecond)/time.Duration(self.fps))
fps := self.fps
if self.fps == 0 {
fps = 25
}
self.addPacket(b, time.Duration(0), (1000*time.Millisecond)/time.Duration(fps))
n++
}
}
Expand Down

0 comments on commit b84c19f

Please sign in to comment.