Skip to content

Commit

Permalink
Update RTSP server filters
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 7, 2022
1 parent 78c5c70 commit 49f6233
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
23 changes: 17 additions & 6 deletions cmd/rtsp/rtsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,27 @@ func initMedias(conn *rtsp.Conn) {
for key, value := range conn.URL.Query() {
switch key {
case streamer.KindVideo, streamer.KindAudio:
for _, value := range value {
for _, name := range value {
name = strings.ToUpper(name)

// check aliases
switch name {
case "COPY":
name = "" // pass empty codecs list
case "MJPEG":
name = streamer.CodecJPEG
case "AAC":
name = streamer.CodecAAC
}

media := &streamer.Media{
Kind: key, Direction: streamer.DirectionRecvonly,
}

switch value {
case "", "copy": // pass empty codecs list
default:
codec := streamer.NewCodec(value)
media.Codecs = append(media.Codecs, codec)
// empty codecs match all codecs
if name != "" {
// empty clock rate and channels match any values
media.Codecs = []*streamer.Codec{{Name: name}}
}

conn.Medias = append(conn.Medias, media)
Expand Down
16 changes: 0 additions & 16 deletions pkg/streamer/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,6 @@ type Codec struct {
PayloadType uint8
}

func NewCodec(name string) *Codec {
name = strings.ToUpper(name)
switch name {
case CodecH264, CodecH265, CodecVP8, CodecVP9, CodecAV1, CodecJPEG:
return &Codec{Name: name, ClockRate: 90000}
case CodecPCMU, CodecPCMA:
return &Codec{Name: name, ClockRate: 8000}
case CodecOpus:
return &Codec{Name: name, ClockRate: 48000, Channels: 2}
case "MJPEG":
return &Codec{Name: CodecJPEG, ClockRate: 90000}
}

panic(fmt.Sprintf("unsupported codec: %s", name))
}

func (c *Codec) String() string {
s := fmt.Sprintf("%d %s/%d", c.PayloadType, c.Name, c.ClockRate)
if c.Channels > 0 {
Expand Down

0 comments on commit 49f6233

Please sign in to comment.