opus work worked
This commit is contained in:
parent
6a92c34cd4
commit
33b07c6a20
@ -75,8 +75,9 @@ type RTSPClient struct {
|
|||||||
sps []byte
|
sps []byte
|
||||||
pps []byte
|
pps []byte
|
||||||
CodecData []av.CodecData
|
CodecData []av.CodecData
|
||||||
PCMTime time.Duration
|
AudioTimeLine time.Duration
|
||||||
AudioTimeScale int64
|
AudioTimeScale int64
|
||||||
|
audioCodec string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RTSPClientOptions struct {
|
type RTSPClientOptions struct {
|
||||||
@ -179,6 +180,7 @@ func Dial(options RTSPClientOptions) (*RTSPClient, error) {
|
|||||||
if CodecData != nil {
|
if CodecData != nil {
|
||||||
client.CodecData = append(client.CodecData, CodecData)
|
client.CodecData = append(client.CodecData, CodecData)
|
||||||
client.audioIDX = int8(len(client.CodecData) - 1)
|
client.audioIDX = int8(len(client.CodecData) - 1)
|
||||||
|
client.audioCodec = CodecData.Type().String()
|
||||||
if i2.TimeScale != 0 {
|
if i2.TimeScale != 0 {
|
||||||
client.AudioTimeScale = int64(i2.TimeScale)
|
client.AudioTimeScale = int64(i2.TimeScale)
|
||||||
}
|
}
|
||||||
@ -572,21 +574,20 @@ func (client *RTSPClient) RTPDemuxer(payloadRAW *[]byte) ([]*av.Packet, bool) {
|
|||||||
nalRaw, _ := h264parser.SplitNALUs(content[offset:end])
|
nalRaw, _ := h264parser.SplitNALUs(content[offset:end])
|
||||||
var retmap []*av.Packet
|
var retmap []*av.Packet
|
||||||
for _, nal := range nalRaw {
|
for _, nal := range nalRaw {
|
||||||
//basic
|
if client.audioCodec == av.PCM_MULAW.String() || client.audioCodec == av.PCM_ALAW.String() || client.audioCodec == av.PCM.String() {
|
||||||
//time.Duration(float32(timestamp)/float32(float32(client.AudioTimeScale)/float32(1000))) * time.Millisecond
|
client.AudioTimeLine += time.Duration(len(nal)) * time.Second / time.Duration(client.AudioTimeScale)
|
||||||
//pcm
|
} else if client.audioCodec == av.OPUS.String() {
|
||||||
//client.PCMTime += time.Duration(len(nal)) * time.Second / time.Duration(client.AudioTimeScale)
|
client.AudioTimeLine += time.Duration(20) * time.Millisecond
|
||||||
//opus
|
} else {
|
||||||
//client.PCMTime := time.Duration((sampleCount/48000)*1000) * time.Millisecond
|
client.AudioTimeLine = time.Duration(float32(timestamp)/float32(float32(client.AudioTimeScale)/float32(1000))) * time.Millisecond
|
||||||
//Need Add Opus And AAC
|
}
|
||||||
retmap = append(retmap, &av.Packet{
|
retmap = append(retmap, &av.Packet{
|
||||||
Data: append(binSize(len(nal)), nal...),
|
Data: append(binSize(len(nal)), nal...),
|
||||||
CompositionTime: time.Duration(1) * time.Millisecond,
|
CompositionTime: time.Duration(1) * time.Millisecond,
|
||||||
Idx: client.audioIDX,
|
Idx: client.audioIDX,
|
||||||
IsKeyFrame: false,
|
IsKeyFrame: false,
|
||||||
Time: time.Duration(float32(timestamp)/float32(float32(client.AudioTimeScale)/float32(1000))) * time.Millisecond,
|
Time: client.AudioTimeLine,
|
||||||
})
|
})
|
||||||
//log.Println("===>", time.Duration(float32(timestamp)/float32(float32(client.AudioTimeScale)/float32(1000)))*time.Millisecond)
|
|
||||||
}
|
}
|
||||||
if len(retmap) > 0 {
|
if len(retmap) > 0 {
|
||||||
return retmap, true
|
return retmap, true
|
||||||
|
@ -159,6 +159,11 @@ func (element *Muxer) WritePacket(pkt av.Packet) (err error) {
|
|||||||
if element.stop {
|
if element.stop {
|
||||||
return ErrorClientOffline
|
return ErrorClientOffline
|
||||||
}
|
}
|
||||||
|
//Wait client ICEConnectionStateConnected
|
||||||
|
if element.status == webrtc.ICEConnectionStateChecking {
|
||||||
|
WritePacketSuccess = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if element.status != webrtc.ICEConnectionStateConnected {
|
if element.status != webrtc.ICEConnectionStateConnected {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -176,8 +181,11 @@ func (element *Muxer) WritePacket(pkt av.Packet) (err error) {
|
|||||||
pkt.Data = pkt.Data[4:]
|
pkt.Data = pkt.Data[4:]
|
||||||
}
|
}
|
||||||
case av.PCM_MULAW:
|
case av.PCM_MULAW:
|
||||||
|
pkt.Data = pkt.Data[4:]
|
||||||
case av.PCM_ALAW:
|
case av.PCM_ALAW:
|
||||||
|
pkt.Data = pkt.Data[4:]
|
||||||
case av.OPUS:
|
case av.OPUS:
|
||||||
|
pkt.Data = pkt.Data[4:]
|
||||||
default:
|
default:
|
||||||
return ErrorCodecNotSupported
|
return ErrorCodecNotSupported
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user