mirror of https://bitbucket.org/ausocean/av.git
Creating the files I need for repacketisation
This commit is contained in:
parent
bc7962b240
commit
24658ed1aa
|
@ -0,0 +1,6 @@
|
||||||
|
package packet
|
||||||
|
|
||||||
|
|
||||||
|
type MpegTsPacket struct {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package packet
|
||||||
|
|
||||||
|
type RtpToTsConverter interface {
|
||||||
|
New() *rtpToTsConverter
|
||||||
|
}
|
||||||
|
|
||||||
|
type rtpToTsConverter struct {
|
||||||
|
TsOutChan <-chan MpegTsPacket
|
||||||
|
RtpInChan chan<- RtpPacket
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() c *rtpToTsConverter {
|
||||||
|
c = new(rtpToTsConverter)
|
||||||
|
c.TsOutChan = make(chan, MpegTsPacket)
|
||||||
|
c.RtpInChan = make(chan, RtpPacket)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c* RtpToTsConverter) convert() {
|
||||||
|
|
||||||
|
}
|
|
@ -29,11 +29,11 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISE
|
||||||
OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package rtp
|
package packet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -43,26 +43,28 @@ const (
|
||||||
const (
|
const (
|
||||||
hasRtpPadding = 1 << 5
|
hasRtpPadding = 1 << 5
|
||||||
hasRtpExt = 1 << 4
|
hasRtpExt = 1 << 4
|
||||||
|
hasMarker = 1 << 7
|
||||||
)
|
)
|
||||||
|
|
||||||
type RtpPacket struct {
|
type RtpPacket struct {
|
||||||
Version byte
|
Version byte
|
||||||
Padding bool
|
Padding bool
|
||||||
Ext bool
|
Ext bool
|
||||||
|
CC byte
|
||||||
Marker bool
|
Marker bool
|
||||||
PayloadType byte
|
PayloadType byte
|
||||||
SequenceNumber uint
|
SequenceNumber uint
|
||||||
Timestamp uint
|
Timestamp uint
|
||||||
SyncSource uint
|
SyncSource uint
|
||||||
CSRC []uint
|
CSRC []uint
|
||||||
ExtHeader uint
|
ExtHeader uint
|
||||||
ExtData []byte
|
ExtData []byte
|
||||||
Payload []byte
|
Payload []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
Rtp net.PacketConn
|
Rtp net.PacketConn
|
||||||
Rtcp net.PacketConn
|
Rtcp net.PacketConn
|
||||||
RtpChan <-chan RtpPacket
|
RtpChan <-chan RtpPacket
|
||||||
RtcpChan <-chan []byte
|
RtcpChan <-chan []byte
|
||||||
rtpChan chan<- RtpPacket
|
rtpChan chan<- RtpPacket
|
||||||
|
@ -122,23 +124,22 @@ func (s *Session) HandleRtcpConn(conn net.PacketConn) {
|
||||||
func (s *Session) handleRtp(buf []byte) {
|
func (s *Session) handleRtp(buf []byte) {
|
||||||
fmt.Println(buf)
|
fmt.Println(buf)
|
||||||
packet := RtpPacket{
|
packet := RtpPacket{
|
||||||
Version: (buf[0] & 0xC0)>>6,
|
Version: (buf[0] & 0xC0) >> 6,
|
||||||
Padding: buf[0]&hasRtpPadding != 0,
|
Padding: buf[0]&hasRtpPadding != 0,
|
||||||
Ext: buf[0]&hasRtpExt != 0,
|
Ext: buf[0]&hasRtpExt != 0,
|
||||||
Marker: buf[1]&1 != 0,
|
CC: buf[0] & 0x0F,
|
||||||
PayloadType: buf[1] >> 1,
|
Marker: buf[1]&hasMarker != 0,
|
||||||
|
PayloadType: buf[1] & 0x7F,
|
||||||
SequenceNumber: toUint(buf[2:4]),
|
SequenceNumber: toUint(buf[2:4]),
|
||||||
Timestamp: toUint(buf[4:8]),
|
Timestamp: toUint(buf[4:8]),
|
||||||
SyncSource: toUint(buf[8:12]),
|
SyncSource: toUint(buf[8:12]),
|
||||||
CSRC: make([]uint, buf[0]>>4),
|
CSRC: make([]uint, buf[0]&0x0F),
|
||||||
}
|
}
|
||||||
|
|
||||||
if packet.Version != RTP_VERSION {
|
if packet.Version != RTP_VERSION {
|
||||||
fmt.Printf("Packet version: %v", packet.Version)
|
|
||||||
panic("Unsupported version")
|
panic("Unsupported version")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
i := 12
|
i := 12
|
||||||
|
|
||||||
for j := range packet.CSRC {
|
for j := range packet.CSRC {
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"../rtp"
|
"../packet"
|
||||||
|
|
||||||
"github.com/beatgammit/rtsp"
|
"github.com/beatgammit/rtsp"
|
||||||
)
|
)
|
||||||
|
@ -18,108 +18,87 @@ func init() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const sampleRequest = `OPTIONS rtsp://example.com/media.mp4 RTSP/1.0
|
|
||||||
CSeq: 1
|
|
||||||
Require: implicit-play
|
|
||||||
Proxy-Require: gzipped-messages
|
|
||||||
|
|
||||||
`
|
|
||||||
|
|
||||||
const sampleResponse = `RTSP/1.0 200 OK
|
|
||||||
CSeq: 1
|
|
||||||
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE
|
|
||||||
|
|
||||||
`
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(flag.Args()) >= 1 {
|
if len(flag.Args()) >= 1 {
|
||||||
rtspUrl := flag.Args()[0]
|
rtspUrl := flag.Args()[0]
|
||||||
rtpUrl := flag.Args()[1]
|
rtpUrl := flag.Args()[1]
|
||||||
|
|
||||||
sess := rtsp.NewSession()
|
sess := rtsp.NewSession()
|
||||||
res, err := sess.Options(rtspUrl)
|
res, err := sess.Options(rtspUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
fmt.Println("Options:")
|
fmt.Println("Options:")
|
||||||
fmt.Println(res)
|
fmt.Println(res)
|
||||||
|
|
||||||
res, err = sess.Describe(rtspUrl)
|
res, err = sess.Describe(rtspUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
fmt.Println("Describe:")
|
fmt.Println("Describe:")
|
||||||
fmt.Println(res)
|
fmt.Println(res)
|
||||||
|
|
||||||
p, err := rtsp.ParseSdp(&io.LimitedReader{R: res.Body, N: res.ContentLength})
|
p, err := rtsp.ParseSdp(&io.LimitedReader{R: res.Body, N: res.ContentLength})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Printf("%+v", p)
|
log.Printf("%+v", p)
|
||||||
|
|
||||||
fmt.Println("Setting up!")
|
fmt.Println("Setting up!")
|
||||||
rtpPort, rtcpPort := 17300, 17319
|
rtpPort, rtcpPort := 17300, 17319
|
||||||
res, err = sess.Setup(rtpUrl, fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", rtpPort, rtcpPort))
|
res, err = sess.Setup(rtpUrl, fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", rtpPort, rtcpPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Println(res)
|
log.Println(res)
|
||||||
|
|
||||||
fmt.Println("Playing !")
|
fmt.Println("Playing !")
|
||||||
res, err = sess.Play(rtspUrl, res.Header.Get("Session"))
|
res, err = sess.Play(rtspUrl, res.Header.Get("Session"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
log.Println(res)
|
log.Println(res)
|
||||||
|
|
||||||
// create udp connection for rtp stuff
|
// create udp connection for rtp stuff
|
||||||
rtpLaddr, err := net.ResolveUDPAddr("udp","192.168.0.109:17300")
|
rtpLaddr, err := net.ResolveUDPAddr("udp", "192.168.0.109:17300")
|
||||||
if err != nil {fmt.Println("Local rtp addr not set!")}
|
if err != nil {
|
||||||
rtpAddr, err := net.ResolveUDPAddr("udp","192.168.0.50:17300")
|
fmt.Println("Local rtp addr not set!")
|
||||||
if err != nil { fmt.Println( "Resolving rtp address didn't work!")}
|
}
|
||||||
rtpConn, err := net.DialUDP("udp",rtpLaddr,rtpAddr)
|
rtpAddr, err := net.ResolveUDPAddr("udp", "192.168.0.50:17300")
|
||||||
if err != nil {fmt.Println("Rtp dial didn't work!")}
|
if err != nil {
|
||||||
|
fmt.Println("Resolving rtp address didn't work!")
|
||||||
|
}
|
||||||
|
rtpConn, err := net.DialUDP("udp", rtpLaddr, rtpAddr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Rtp dial didn't work!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create udp connection for rtcp stuff
|
||||||
|
rtcpLaddr, err := net.ResolveUDPAddr("udp", "192.168.0.109:17319")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Local ")
|
||||||
|
}
|
||||||
|
rtcpAddr, err := net.ResolveUDPAddr("udp", "192.168.0.50:17301")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("resolving rtcp address didn't work!")
|
||||||
|
}
|
||||||
|
rtcpConn, err := net.DialUDP("udp", rtcpLaddr, rtcpAddr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Rtcp dial didnt't work!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// let's create a session that will store useful stuff from the connections
|
||||||
|
rtpSession := rtp.New(rtpConn, rtcpConn)
|
||||||
|
|
||||||
|
|
||||||
// Create udp connection for rtcp stuff
|
// Loop here until we get something in the channels
|
||||||
rtcpLaddr, err := net.ResolveUDPAddr("udp","192.168.0.109:17319")
|
for {
|
||||||
if err != nil {fmt.Println("Local ")}
|
fmt.Printf("Length of rtpChan: %v\n", len(rtpSession.RtpChan))
|
||||||
rtcpAddr, err := net.ResolveUDPAddr("udp","192.168.0.50:17301")
|
time.Sleep(1 * time.Second)
|
||||||
if err != nil {fmt.Println("resolving rtcp address didn't work!")}
|
select {
|
||||||
rtcpConn, err := net.DialUDP("udp",rtcpLaddr, rtcpAddr)
|
case rtpPacket := <-rtpSession.RtpChan:
|
||||||
if err != nil {fmt.Println("Rtcp dial didnt't work!")}
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
// let's create a session that will store useful stuff from the connections
|
}
|
||||||
rtpSession := rtp.New(rtpConn,rtcpConn)
|
|
||||||
|
|
||||||
// Loop here until we get something in the channels
|
|
||||||
for{
|
|
||||||
fmt.Printf("Length of rtpChan: %v\n", len(rtpSession.RtpChan))
|
|
||||||
time.Sleep(1*time.Second )
|
|
||||||
select{
|
|
||||||
case rtpPacket := <-rtpSession.RtpChan:
|
|
||||||
fmt.Println(rtpPacket)
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
r, err := rtsp.ReadRequest(bytes.NewBufferString(sampleRequest))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := rtsp.ReadResponse(bytes.NewBufferString(sampleResponse))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue