mirror of
				https://github.com/pion/webrtc.git
				synced 2025-11-01 03:04:06 +08:00 
			
		
		
		
	Finish RTCRtpReceiver and RTCRtpSender
Allow sending of media via ORTC, examples will be added in the future. But for now all of this state has been pulled out of RTCPeerConnection Resolves #312
This commit is contained in:
		
							
								
								
									
										55
									
								
								rtctrack.go
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								rtctrack.go
									
									
									
									
									
								
							| @@ -1,22 +1,71 @@ | ||||
| package webrtc | ||||
|  | ||||
| import ( | ||||
| 	"crypto/rand" | ||||
| 	"encoding/binary" | ||||
|  | ||||
| 	"github.com/pions/webrtc/pkg/media" | ||||
| 	"github.com/pions/webrtc/pkg/rtcp" | ||||
| 	"github.com/pions/webrtc/pkg/rtp" | ||||
| 	"github.com/pkg/errors" | ||||
| ) | ||||
|  | ||||
| // RTCTrack represents a track that is communicated | ||||
| type RTCTrack struct { | ||||
| 	isRawRTP bool | ||||
|  | ||||
| 	ID          string | ||||
| 	PayloadType uint8 | ||||
| 	Kind        RTCRtpCodecType | ||||
| 	Label       string | ||||
| 	Ssrc        uint32 | ||||
| 	Codec       *RTCRtpCodec | ||||
|  | ||||
| 	Packets     <-chan *rtp.Packet | ||||
| 	RTCPPackets <-chan rtcp.Packet | ||||
| 	Samples     chan<- media.RTCSample | ||||
| 	RawRTP      chan<- *rtp.Packet | ||||
| 	isRawRTP    bool | ||||
|  | ||||
| 	Samples chan<- media.RTCSample | ||||
| 	RawRTP  chan<- *rtp.Packet | ||||
| } | ||||
|  | ||||
| // NewRawRTPTrack initializes a new *RTCTrack configured to accept raw *rtp.Packet | ||||
| // | ||||
| // NB: If the source RTP stream is being broadcast to multiple tracks, each track | ||||
| // must receive its own copies of the source packets in order to avoid packet corruption. | ||||
| func NewRawRTPTrack(payloadType uint8, ssrc uint32, id, label string) (*RTCTrack, error) { | ||||
| 	if ssrc == 0 { | ||||
| 		return nil, errors.New("SSRC supplied to NewRawRTPTrack() must be non-zero") | ||||
| 	} | ||||
|  | ||||
| 	return &RTCTrack{ | ||||
| 		isRawRTP: true, | ||||
|  | ||||
| 		ID:          id, | ||||
| 		PayloadType: payloadType, | ||||
| 		Label:       label, | ||||
| 		Ssrc:        ssrc, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // NewRTCSampleTrack initializes a new *RTCTrack configured to accept media.RTCSample | ||||
| func NewRTCSampleTrack(payloadType uint8, id, label string, codec *RTCRtpCodec) (*RTCTrack, error) { | ||||
| 	if codec == nil { | ||||
| 		return nil, errors.New("codec supplied to NewRTCSampleTrack() must not be nil") | ||||
| 	} | ||||
|  | ||||
| 	buf := make([]byte, 4) | ||||
| 	if _, err := rand.Read(buf); err != nil { | ||||
| 		return nil, errors.New("failed to generate random value") | ||||
| 	} | ||||
|  | ||||
| 	return &RTCTrack{ | ||||
| 		isRawRTP: false, | ||||
|  | ||||
| 		ID:          id, | ||||
| 		PayloadType: payloadType, | ||||
| 		Kind:        codec.Type, | ||||
| 		Label:       label, | ||||
| 		Ssrc:        binary.LittleEndian.Uint32(buf), | ||||
| 		Codec:       codec, | ||||
| 	}, nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sean DuBois
					Sean DuBois