mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
move time as first argument in rtcpreceiver, rtcpsender, rtpaac, rtph264
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/aler9/gortsplib/pkg/base"
|
"github.com/aler9/gortsplib/pkg/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RtcpReceiver allows to generate RTCP receiver reports.
|
// RtcpReceiver is a utility to generate RTCP receiver reports.
|
||||||
type RtcpReceiver struct {
|
type RtcpReceiver struct {
|
||||||
receiverSSRC uint32
|
receiverSSRC uint32
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
|
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/aler9/gortsplib/pkg/base"
|
"github.com/aler9/gortsplib/pkg/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RtcpSender allows to generate RTCP sender reports.
|
// RtcpSender is a utility to generate RTCP sender reports.
|
||||||
type RtcpSender struct {
|
type RtcpSender struct {
|
||||||
clockRate float64
|
clockRate float64
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
|
@@ -37,16 +37,16 @@ func NewEncoder(payloadType uint8, clockRate int) (*Encoder, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write encodes an AAC frame into RTP/AAC packets.
|
// Write encodes an AAC frame into RTP/AAC packets.
|
||||||
func (e *Encoder) Write(data []byte, timestamp time.Duration) ([][]byte, error) {
|
func (e *Encoder) Write(ts time.Duration, data []byte) ([][]byte, error) {
|
||||||
if e.started == 0 {
|
if e.started == 0 {
|
||||||
e.started = timestamp
|
e.started = ts
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) > rtpPayloadMaxSize {
|
if len(data) > rtpPayloadMaxSize {
|
||||||
return nil, fmt.Errorf("data is too big")
|
return nil, fmt.Errorf("data is too big")
|
||||||
}
|
}
|
||||||
|
|
||||||
rtpTs := e.initialTs + uint32((timestamp-e.started).Seconds()*e.clockRate)
|
rtpTs := e.initialTs + uint32((ts-e.started).Seconds()*e.clockRate)
|
||||||
|
|
||||||
// 13 bits payload size
|
// 13 bits payload size
|
||||||
// 3 bits AU-Index(-delta)
|
// 3 bits AU-Index(-delta)
|
||||||
|
@@ -32,7 +32,7 @@ func NewEncoder(payloadType uint8) (*Encoder, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write encodes NALUs into RTP/H264 packets.
|
// Write encodes NALUs into RTP/H264 packets.
|
||||||
func (e *Encoder) Write(nalus [][]byte, ts time.Duration) ([][]byte, error) {
|
func (e *Encoder) Write(ts time.Duration, nalus [][]byte) ([][]byte, error) {
|
||||||
if e.started == 0 {
|
if e.started == 0 {
|
||||||
e.started = ts
|
e.started = ts
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ func (e *Encoder) Write(nalus [][]byte, ts time.Duration) ([][]byte, error) {
|
|||||||
var frames [][]byte
|
var frames [][]byte
|
||||||
|
|
||||||
for i, nalu := range nalus {
|
for i, nalu := range nalus {
|
||||||
naluFrames, err := e.writeNALU(nalu, rtpTime, (i == len(nalus)-1))
|
naluFrames, err := e.writeNALU(rtpTime, nalu, (i == len(nalus)-1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -53,17 +53,17 @@ func (e *Encoder) Write(nalus [][]byte, ts time.Duration) ([][]byte, error) {
|
|||||||
return frames, nil
|
return frames, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Encoder) writeNALU(nalu []byte, rtpTime uint32, isFinal bool) ([][]byte, error) {
|
func (e *Encoder) writeNALU(rtpTime uint32, nalu []byte, isFinal bool) ([][]byte, error) {
|
||||||
// if the NALU fits into a single RTP packet, use a single NALU payload
|
// if the NALU fits into a single RTP packet, use a single NALU payload
|
||||||
if len(nalu) < rtpPayloadMaxSize {
|
if len(nalu) < rtpPayloadMaxSize {
|
||||||
return e.writeSingle(nalu, rtpTime, isFinal)
|
return e.writeSingle(rtpTime, nalu, isFinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, split the NALU into multiple fragmentation payloads
|
// otherwise, split the NALU into multiple fragmentation payloads
|
||||||
return e.writeFragmented(nalu, rtpTime, isFinal)
|
return e.writeFragmented(rtpTime, nalu, isFinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Encoder) writeSingle(nalu []byte, rtpTime uint32, isFinal bool) ([][]byte, error) {
|
func (e *Encoder) writeSingle(rtpTime uint32, nalu []byte, isFinal bool) ([][]byte, error) {
|
||||||
rpkt := rtp.Packet{
|
rpkt := rtp.Packet{
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
Version: rtpVersion,
|
Version: rtpVersion,
|
||||||
@@ -88,7 +88,7 @@ func (e *Encoder) writeSingle(nalu []byte, rtpTime uint32, isFinal bool) ([][]by
|
|||||||
return [][]byte{frame}, nil
|
return [][]byte{frame}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Encoder) writeFragmented(nalu []byte, rtpTime uint32, isFinal bool) ([][]byte, error) {
|
func (e *Encoder) writeFragmented(rtpTime uint32, nalu []byte, isFinal bool) ([][]byte, error) {
|
||||||
// use only FU-A, not FU-B, since we always use non-interleaved mode
|
// use only FU-A, not FU-B, since we always use non-interleaved mode
|
||||||
// (packetization-mode=1)
|
// (packetization-mode=1)
|
||||||
frameCount := (len(nalu) - 1) / (rtpPayloadMaxSize - 2)
|
frameCount := (len(nalu) - 1) / (rtpPayloadMaxSize - 2)
|
||||||
|
Reference in New Issue
Block a user