Skip to content

Commit

Permalink
rename MPEG2Video into MPEG1Video, MPEG2Audio into MPEG1Audio
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Aug 5, 2023
1 parent 4e789ff commit e9c2a85
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 84 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ In RTSP, media streams are routed between server and clients by using RTP packet
|H265||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#H265)|:heavy_check_mark:|
|H264||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#H264)|:heavy_check_mark:|
|MPEG-4 Video (H263, Xvid)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG4VideoES)|:heavy_check_mark:|
|MPEG-2 Video||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG2Video)||
|MPEG-1/2 Video||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG1Video)||
|M-JPEG||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MJPEG)|:heavy_check_mark:|

### Audio
Expand All @@ -119,7 +119,7 @@ In RTSP, media streams are routed between server and clients by using RTP packet
|Vorbis||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#Vorbis)||
|MPEG-4 Audio (AAC)|Generic (RFC3640)|[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG4AudioGeneric)|:heavy_check_mark:|
|MPEG-4 Audio (AAC)|LATM (RFC6416)|[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG4AudioLATM)|:heavy_check_mark:|
|MPEG-1/2 Audio (MP3)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG2Audio)|:heavy_check_mark:|
|MPEG-1/2 Audio (MP3)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG1Audio)|:heavy_check_mark:|
|G726||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#G726)||
|G722||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#G722)|:heavy_check_mark:|
|G711 (PCMA, PCMU)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#G711)|:heavy_check_mark:|
Expand Down
4 changes: 2 additions & 2 deletions pkg/formats/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Unmarshal(mediaType string, payloadType uint8, rtpMap string, fmtp map[stri
return &MJPEG{}

case payloadType == 32:
return &MPEG2Video{}
return &MPEG1Video{}

case payloadType == 33:
return &MPEGTS{}
Expand Down Expand Up @@ -98,7 +98,7 @@ func Unmarshal(mediaType string, payloadType uint8, rtpMap string, fmtp map[stri
return &G726{}

case payloadType == 14:
return &MPEG2Audio{}
return &MPEG1Audio{}

case codec == "l8", codec == "l16", codec == "l24":
return &LPCM{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/formats/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ var casesFormat = []struct {
14,
"",
nil,
&MPEG2Audio{},
&MPEG1Audio{},
"",
nil,
},
Expand Down Expand Up @@ -573,12 +573,12 @@ var casesFormat = []struct {
nil,
},
{
"video mpeg2 video",
"video mpeg1 video",
"video",
32,
"",
nil,
&MPEG2Video{},
&MPEG1Video{},
"",
nil,
},
Expand Down
39 changes: 22 additions & 17 deletions pkg/formats/mpeg2_audio.go → pkg/formats/mpeg1_audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@ package formats //nolint:dupl
import (
"github.com/pion/rtp"

"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg2audio"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg1audio"
)

// MPEG2Audio is a RTP format for a MPEG-1/2 Audio codec.
// MPEG1Audio is a RTP format for a MPEG-1/2 Audio codec.
// Specification: https://datatracker.ietf.org/doc/html/rfc2250
type MPEG2Audio struct{}
type MPEG1Audio struct{}

func (f *MPEG2Audio) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error {
func (f *MPEG1Audio) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error {
return nil
}

// Codec implements Format.
func (f *MPEG2Audio) Codec() string {
func (f *MPEG1Audio) Codec() string {
return "MPEG-1/2 Audio"
}

// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEG2Audio) String() string {
func (f *MPEG1Audio) String() string {

Check warning on line 25 in pkg/formats/mpeg1_audio.go

View check run for this annotation

Codecov / codecov/patch

pkg/formats/mpeg1_audio.go#L25

Added line #L25 was not covered by tests
return f.Codec()
}

// ClockRate implements Format.
func (f *MPEG2Audio) ClockRate() int {
func (f *MPEG1Audio) ClockRate() int {
return 90000
}

// PayloadType implements Format.
func (f *MPEG2Audio) PayloadType() uint8 {
func (f *MPEG1Audio) PayloadType() uint8 {
return 14
}

// RTPMap implements Format.
func (f *MPEG2Audio) RTPMap() string {
func (f *MPEG1Audio) RTPMap() string {
return ""
}

// FMTP implements Format.
func (f *MPEG2Audio) FMTP() map[string]string {
func (f *MPEG1Audio) FMTP() map[string]string {
return nil
}

// PTSEqualsDTS implements Format.
func (f *MPEG2Audio) PTSEqualsDTS(*rtp.Packet) bool {
func (f *MPEG1Audio) PTSEqualsDTS(*rtp.Packet) bool {
return true
}

// CreateDecoder creates a decoder able to decode the content of the format.
//
// Deprecated: this has been replaced by CreateDecoder2() that can also return an error.
func (f *MPEG2Audio) CreateDecoder() *rtpmpeg2audio.Decoder {
func (f *MPEG1Audio) CreateDecoder() *rtpmpeg1audio.Decoder {

Check warning on line 57 in pkg/formats/mpeg1_audio.go

View check run for this annotation

Codecov / codecov/patch

pkg/formats/mpeg1_audio.go#L57

Added line #L57 was not covered by tests
d, _ := f.CreateDecoder2()
return d
}

// CreateDecoder2 creates a decoder able to decode the content of the format.
func (f *MPEG2Audio) CreateDecoder2() (*rtpmpeg2audio.Decoder, error) {
d := &rtpmpeg2audio.Decoder{}
func (f *MPEG1Audio) CreateDecoder2() (*rtpmpeg1audio.Decoder, error) {
d := &rtpmpeg1audio.Decoder{}

err := d.Init()
if err != nil {
Expand All @@ -74,14 +74,14 @@ func (f *MPEG2Audio) CreateDecoder2() (*rtpmpeg2audio.Decoder, error) {
// CreateEncoder creates an encoder able to encode the content of the format.
//
// Deprecated: this has been replaced by CreateEncoder2() that can also return an error.
func (f *MPEG2Audio) CreateEncoder() *rtpmpeg2audio.Encoder {
func (f *MPEG1Audio) CreateEncoder() *rtpmpeg1audio.Encoder {

Check warning on line 77 in pkg/formats/mpeg1_audio.go

View check run for this annotation

Codecov / codecov/patch

pkg/formats/mpeg1_audio.go#L77

Added line #L77 was not covered by tests
e, _ := f.CreateEncoder2()
return e
}

// CreateEncoder2 creates an encoder able to encode the content of the format.
func (f *MPEG2Audio) CreateEncoder2() (*rtpmpeg2audio.Encoder, error) {
e := &rtpmpeg2audio.Encoder{}
func (f *MPEG1Audio) CreateEncoder2() (*rtpmpeg1audio.Encoder, error) {
e := &rtpmpeg1audio.Encoder{}

err := e.Init()
if err != nil {
Expand All @@ -90,3 +90,8 @@ func (f *MPEG2Audio) CreateEncoder2() (*rtpmpeg2audio.Encoder, error) {

return e, nil
}

// MPEG2Audio is an alias for MPEG1Audio.
//
// Deprecated: replaced by MPEG1Audio.
type MPEG2Audio = MPEG1Audio
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestMPEG2AudioAttributes(t *testing.T) {
format := &MPEG2Audio{}
func TestMPEG1AudioAttributes(t *testing.T) {
format := &MPEG1Audio{}
require.Equal(t, "MPEG-1/2 Audio", format.Codec())
require.Equal(t, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
}

func TestMPEG2AudioDecEncoder(t *testing.T) {
format := &MPEG2Audio{}
func TestMPEG1AudioDecEncoder(t *testing.T) {
format := &MPEG1Audio{}

enc, err := format.CreateEncoder2()
require.NoError(t, err)
Expand Down
55 changes: 55 additions & 0 deletions pkg/formats/mpeg1_video.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package formats //nolint:dupl

import (
"github.com/pion/rtp"
)

// MPEG1Video is a RTP format for a MPEG-1/2 Video codec.
// Specification: https://datatracker.ietf.org/doc/html/rfc2250
type MPEG1Video struct{}

func (f *MPEG1Video) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error {
return nil
}

// Codec implements Format.
func (f *MPEG1Video) Codec() string {
return "MPEG-1/2 Video"
}

// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEG1Video) String() string {
return f.Codec()

Check warning on line 24 in pkg/formats/mpeg1_video.go

View check run for this annotation

Codecov / codecov/patch

pkg/formats/mpeg1_video.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

// ClockRate implements Format.
func (f *MPEG1Video) ClockRate() int {
return 90000
}

// PayloadType implements Format.
func (f *MPEG1Video) PayloadType() uint8 {
return 32
}

// RTPMap implements Format.
func (f *MPEG1Video) RTPMap() string {
return ""
}

// FMTP implements Format.
func (f *MPEG1Video) FMTP() map[string]string {
return nil
}

// PTSEqualsDTS implements Format.
func (f *MPEG1Video) PTSEqualsDTS(*rtp.Packet) bool {
return true
}

// MPEG2Video is an alias for MPEG1Video.
//
// Deprecated: replaced by MPEG1Video.
type MPEG2Video = MPEG1Video
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/require"
)

func TestMPEG2VideoAttributes(t *testing.T) {
format := &MPEG2Video{}
func TestMPEG1VideoAttributes(t *testing.T) {
format := &MPEG1Video{}
require.Equal(t, "MPEG-1/2 Video", format.Codec())
require.Equal(t, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
Expand Down
50 changes: 0 additions & 50 deletions pkg/formats/mpeg2_video.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rtpmpeg2audio
package rtpmpeg1audio

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rtpmpeg2audio
package rtpmpeg1audio

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rtpmpeg2audio
package rtpmpeg1audio

import (
"crypto/rand"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rtpmpeg2audio
package rtpmpeg1audio

import (
"testing"
Expand Down
2 changes: 2 additions & 0 deletions pkg/formats/rtpmpeg1audio/rtpmpeg1audio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package rtpmpeg1audio contains a RTP/MPEG-1/2 Audio decoder and encoder.
package rtpmpeg1audio
24 changes: 24 additions & 0 deletions pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
// Package rtpmpeg2audio contains a RTP/MPEG-1/2 Audio decoder and encoder.
package rtpmpeg2audio

import (
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg1audio"
)

// ErrMorePacketsNeeded is an alis for rtpmpeg1audio.ErrMorePacketsNeeded.
//
// Deprecated: replaced by rtpmpeg1audio.ErrMorePacketsNeeded.
var ErrMorePacketsNeeded = rtpmpeg1audio.ErrMorePacketsNeeded

// ErrNonStartingPacketAndNoPrevious is an alis for rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious.
//
// Deprecated: replaced by rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious.
var ErrNonStartingPacketAndNoPrevious = rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious

// Decoder is an alis for rtpmpeg1audio.Decoder.
//
// Deprecated: replaced by rtpmpeg1audio.Decoder.
type Decoder = rtpmpeg1audio.Decoder

// Encoder is an alis for rtpmpeg1audio.Encoder.
//
// Deprecated: replaced by rtpmpeg1audio.Encoder.
type Encoder = rtpmpeg1audio.Encoder

0 comments on commit e9c2a85

Please sign in to comment.