mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
add TrackJPEG
This commit is contained in:
10
track.go
10
track.go
@@ -61,17 +61,21 @@ func newTrackFromMediaDescription(md *psdp.MediaDescription) (Track, error) {
|
||||
|
||||
switch {
|
||||
case md.MediaName.Media == "video":
|
||||
if rtpmapPart1 == "H264/90000" {
|
||||
switch {
|
||||
case len(md.MediaName.Formats) == 1 && md.MediaName.Formats[0] == "26":
|
||||
return newTrackJPEGFromMediaDescription(control)
|
||||
|
||||
case rtpmapPart1 == "H264/90000":
|
||||
return newTrackH264FromMediaDescription(control, payloadType, md)
|
||||
}
|
||||
|
||||
case md.MediaName.Media == "audio":
|
||||
switch {
|
||||
case len(md.MediaName.Formats) == 1 && md.MediaName.Formats[0] == "0":
|
||||
return newTrackPCMUFromMediaDescription(control, rtpmapPart1, md)
|
||||
return newTrackPCMUFromMediaDescription(control, rtpmapPart1)
|
||||
|
||||
case len(md.MediaName.Formats) == 1 && md.MediaName.Formats[0] == "8":
|
||||
return newTrackPCMAFromMediaDescription(control, rtpmapPart1, md)
|
||||
return newTrackPCMAFromMediaDescription(control, rtpmapPart1)
|
||||
|
||||
case strings.HasPrefix(strings.ToLower(rtpmapPart1), "mpeg4-generic/"):
|
||||
return newTrackAACFromMediaDescription(control, payloadType, md)
|
||||
|
57
track_jpeg.go
Normal file
57
track_jpeg.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package gortsplib //nolint:dupl
|
||||
|
||||
import (
|
||||
psdp "github.com/pion/sdp/v3"
|
||||
)
|
||||
|
||||
// TrackJPEG is a JPEG track.
|
||||
type TrackJPEG struct {
|
||||
trackBase
|
||||
}
|
||||
|
||||
// NewTrackJPEG allocates a TrackJPEG.
|
||||
func NewTrackJPEG() *TrackJPEG {
|
||||
return &TrackJPEG{}
|
||||
}
|
||||
|
||||
func newTrackJPEGFromMediaDescription(
|
||||
control string) (*TrackJPEG, error,
|
||||
) {
|
||||
return &TrackJPEG{
|
||||
trackBase: trackBase{
|
||||
control: control,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ClockRate returns the track clock rate.
|
||||
func (t *TrackJPEG) ClockRate() int {
|
||||
return 90000
|
||||
}
|
||||
|
||||
func (t *TrackJPEG) clone() Track {
|
||||
return &TrackJPEG{
|
||||
trackBase: t.trackBase,
|
||||
}
|
||||
}
|
||||
|
||||
// MediaDescription returns the track media description in SDP format.
|
||||
func (t *TrackJPEG) MediaDescription() *psdp.MediaDescription {
|
||||
return &psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"26"},
|
||||
},
|
||||
Attributes: []psdp.Attribute{
|
||||
{
|
||||
Key: "rtpmap",
|
||||
Value: "26 JPEG/90000",
|
||||
},
|
||||
{
|
||||
Key: "control",
|
||||
Value: t.control,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
@@ -19,8 +19,7 @@ func NewTrackPCMA() *TrackPCMA {
|
||||
|
||||
func newTrackPCMAFromMediaDescription(
|
||||
control string,
|
||||
rtpmapPart1 string,
|
||||
md *psdp.MediaDescription) (*TrackPCMA, error,
|
||||
rtpmapPart1 string) (*TrackPCMA, error,
|
||||
) {
|
||||
tmp := strings.Split(rtpmapPart1, "/")
|
||||
if len(tmp) >= 3 && tmp[2] != "1" {
|
||||
|
@@ -19,8 +19,7 @@ func NewTrackPCMU() *TrackPCMU {
|
||||
|
||||
func newTrackPCMUFromMediaDescription(
|
||||
control string,
|
||||
rtpmapPart1 string,
|
||||
md *psdp.MediaDescription) (*TrackPCMU, error,
|
||||
rtpmapPart1 string) (*TrackPCMU, error,
|
||||
) {
|
||||
tmp := strings.Split(rtpmapPart1, "/")
|
||||
if len(tmp) >= 3 && tmp[2] != "1" {
|
||||
|
@@ -31,7 +31,6 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "audio",
|
||||
Port: psdp.RangedPort{Value: 49170},
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"0"},
|
||||
},
|
||||
@@ -192,6 +191,17 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
||||
channelCount: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
"jpeg",
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"26"},
|
||||
},
|
||||
},
|
||||
&TrackJPEG{},
|
||||
},
|
||||
{
|
||||
"h264",
|
||||
&psdp.MediaDescription{
|
||||
@@ -343,7 +353,6 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
||||
&psdp.MediaDescription{
|
||||
MediaName: psdp.MediaName{
|
||||
Media: "video",
|
||||
Port: psdp.RangedPort{Value: 0},
|
||||
Protos: []string{"RTP", "AVP"},
|
||||
Formats: []string{"98", "96"},
|
||||
},
|
||||
|
Reference in New Issue
Block a user