fix codec and track
This commit is contained in:
parent
292592fcb5
commit
fccce247d0
16
av/av.go
16
av/av.go
@ -1,4 +1,3 @@
|
||||
|
||||
// Package av defines basic interfaces and data structures of container demux/mux and audio encode/decode.
|
||||
package av
|
||||
|
||||
@ -196,7 +195,7 @@ type PacketWriter interface {
|
||||
}
|
||||
|
||||
type PacketReader interface {
|
||||
ReadPacket() (Packet,error)
|
||||
ReadPacket() (Packet, error)
|
||||
}
|
||||
|
||||
// Muxer describes the steps of writing compressed audio/video packets into container formats like MP4/FLV/MPEG-TS.
|
||||
@ -294,12 +293,12 @@ type AudioEncoder interface {
|
||||
CodecData() (AudioCodecData, error) // encoder's codec data can put into container
|
||||
Encode(AudioFrame) ([][]byte, error) // encode raw audio frame into compressed pakcet(s)
|
||||
Close() // close encoder, free cgo contexts
|
||||
SetSampleRate(int) (error) // set encoder sample rate
|
||||
SetChannelLayout(ChannelLayout) (error) // set encoder channel layout
|
||||
SetSampleFormat(SampleFormat) (error) // set encoder sample format
|
||||
SetBitrate(int) (error) // set encoder bitrate
|
||||
SetOption(string,interface{}) (error) // encoder setopt, in ffmpeg is av_opt_set_dict()
|
||||
GetOption(string,interface{}) (error) // encoder getopt
|
||||
SetSampleRate(int) error // set encoder sample rate
|
||||
SetChannelLayout(ChannelLayout) error // set encoder channel layout
|
||||
SetSampleFormat(SampleFormat) error // set encoder sample format
|
||||
SetBitrate(int) error // set encoder bitrate
|
||||
SetOption(string, interface{}) error // encoder setopt, in ffmpeg is av_opt_set_dict()
|
||||
GetOption(string, interface{}) error // encoder getopt
|
||||
}
|
||||
|
||||
// AudioDecoder can decode compressed audio packets into raw audio frame.
|
||||
@ -313,4 +312,3 @@ type AudioDecoder interface {
|
||||
type AudioResampler interface {
|
||||
Resample(AudioFrame) (AudioFrame, error) // convert raw audio frames
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ func Dial(options RTSPClientOptions) (*RTSPClient, error) {
|
||||
if (i2.AVType != VIDEO && i2.AVType != AUDIO) || (client.options.DisableAudio && i2.AVType == AUDIO) {
|
||||
continue
|
||||
}
|
||||
err = client.request(SETUP, map[string]string{"Transport": "RTP/AVP/TCP;unicast;interleaved=" + strconv.Itoa(ch) + "-" + strconv.Itoa(ch+1)}, client.control+i2.Control, false, false)
|
||||
err = client.request(SETUP, map[string]string{"Transport": "RTP/AVP/TCP;unicast;interleaved=" + strconv.Itoa(ch) + "-" + strconv.Itoa(ch+1)}, client.ControlTrack(i2.Control), false, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -150,6 +150,13 @@ func Dial(options RTSPClientOptions) (*RTSPClient, error) {
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (client *RTSPClient) ControlTrack(track string) string {
|
||||
if strings.Contains(track, "rtsp://") {
|
||||
return track
|
||||
}
|
||||
return client.control + track
|
||||
}
|
||||
|
||||
func (client *RTSPClient) startStream() {
|
||||
defer func() {
|
||||
client.Signals <- SignalStreamRTPStop
|
||||
@ -469,7 +476,6 @@ func (client *RTSPClient) RTPDemuxer(payloadRAW *[]byte) ([]*av.Packet, bool) {
|
||||
switch {
|
||||
case naluType >= 1 && naluType <= 5:
|
||||
client.Println("Fix Stream IDX")
|
||||
|
||||
retmap = append(retmap, &av.Packet{
|
||||
Data: append(binSize(len(nal)), nal...),
|
||||
CompositionTime: time.Duration(1) * time.Millisecond,
|
||||
@ -527,7 +533,7 @@ func (client *RTSPClient) RTPDemuxer(payloadRAW *[]byte) ([]*av.Packet, bool) {
|
||||
func (client *RTSPClient) CodecUpdateSPS(val []byte) {
|
||||
if bytes.Compare(val, client.sps) != 0 {
|
||||
if len(client.sps) > 0 && len(client.pps) > 0 {
|
||||
codecData, err := h264parser.NewCodecDataFromSPSAndPPS(client.sps, client.pps)
|
||||
codecData, err := h264parser.NewCodecDataFromSPSAndPPS(val, client.pps)
|
||||
if err != nil {
|
||||
client.Println("Parse Codec Data Error", err)
|
||||
return
|
||||
@ -550,7 +556,7 @@ func (client *RTSPClient) CodecUpdateSPS(val []byte) {
|
||||
func (client *RTSPClient) CodecUpdatePPS(val []byte) {
|
||||
if bytes.Compare(val, client.pps) != 0 {
|
||||
if len(client.sps) > 0 && len(client.pps) > 0 {
|
||||
codecData, err := h264parser.NewCodecDataFromSPSAndPPS(client.sps, client.pps)
|
||||
codecData, err := h264parser.NewCodecDataFromSPSAndPPS(client.sps, val)
|
||||
if err != nil {
|
||||
client.Println("Parse Codec Data Error", err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user