mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
rename MJPEG label into M-JPEG
This commit is contained in:
@@ -46,7 +46,7 @@ Features:
|
|||||||
* Generate RTCP sender reports
|
* Generate RTCP sender reports
|
||||||
* Utilities
|
* Utilities
|
||||||
* Encode/decode format-specific frames into/from RTP packets. The following formats are supported:
|
* Encode/decode format-specific frames into/from RTP packets. The following formats are supported:
|
||||||
* Video: H264, H265, MJPEG, VP8, VP9
|
* Video: H264, H265, M-JPEG, VP8, VP9
|
||||||
* Audio: G711 (PCMA, PCMU), G722, LPCM, MPEG4 Audio (AAC), Opus
|
* Audio: G711 (PCMA, PCMU), G722, LPCM, MPEG4 Audio (AAC), Opus
|
||||||
* Parse RTSP elements: requests, responses, SDP
|
* Parse RTSP elements: requests, responses, SDP
|
||||||
* Parse H264 elements and formats: Annex-B, AVCC, anti-competition, DTS
|
* Parse H264 elements and formats: Annex-B, AVCC, anti-competition, DTS
|
||||||
|
@@ -11,19 +11,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// This example shows how to
|
// This example shows how to
|
||||||
// 1. generate RTP/MJPEG packets with GStreamer
|
// 1. generate RTP/M-JPEG packets with GStreamer
|
||||||
// 2. connect to a RTSP server, announce an MJPEG media
|
// 2. connect to a RTSP server, announce a M-JPEG media
|
||||||
// 3. route the packets from GStreamer to the server
|
// 3. route the packets from GStreamer to the server
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// open a listener to receive RTP/MJPEG packets
|
// open a listener to receive RTP/M-JPEG packets
|
||||||
pc, err := net.ListenPacket("udp", "localhost:9000")
|
pc, err := net.ListenPacket("udp", "localhost:9000")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer pc.Close()
|
defer pc.Close()
|
||||||
|
|
||||||
log.Println("Waiting for a RTP/MJPEG stream on UDP port 9000 - you can send one with GStreamer:\n" +
|
log.Println("Waiting for a RTP/M-JPEG stream on UDP port 9000 - you can send one with GStreamer:\n" +
|
||||||
"gst-launch-1.0 videotestsrc ! video/x-raw,width=1920,height=1080,format=I420" +
|
"gst-launch-1.0 videotestsrc ! video/x-raw,width=1920,height=1080,format=I420" +
|
||||||
" ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=9000")
|
" ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=9000")
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Println("stream connected")
|
log.Println("stream connected")
|
||||||
|
|
||||||
// create a media that contains a MJPEG format
|
// create a media that contains a M-JPEG format
|
||||||
medias := media.Medias{&media.Media{
|
medias := media.Medias{&media.Media{
|
||||||
Type: media.TypeVideo,
|
Type: media.TypeVideo,
|
||||||
Formats: []format.Format{&format.MJPEG{}},
|
Formats: []format.Format{&format.MJPEG{}},
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
// This example shows how to
|
// This example shows how to
|
||||||
// 1. connect to a RTSP server
|
// 1. connect to a RTSP server
|
||||||
// 2. check if there's a MJPEG media
|
// 2. check if there's a M-JPEG media
|
||||||
// 3. get JPEG images of that media
|
// 3. get JPEG images of that media
|
||||||
// 4. decode JPEG images into raw images
|
// 4. decode JPEG images into raw images
|
||||||
|
|
||||||
@@ -40,14 +40,14 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the MJPEG media and format
|
// find the M-JPEG media and format
|
||||||
var forma *format.MJPEG
|
var forma *format.MJPEG
|
||||||
medi := medias.FindFormat(&forma)
|
medi := medias.FindFormat(&forma)
|
||||||
if medi == nil {
|
if medi == nil {
|
||||||
panic("media not found")
|
panic("media not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup RTP/MJPEG->MJPEG decoder
|
// setup RTP/M-JPEG->M-JPEG decoder
|
||||||
rtpDec := forma.CreateDecoder()
|
rtpDec := forma.CreateDecoder()
|
||||||
|
|
||||||
// setup the chosen media only
|
// setup the chosen media only
|
||||||
|
@@ -11,7 +11,7 @@ type MJPEG struct{}
|
|||||||
|
|
||||||
// String implements Format.
|
// String implements Format.
|
||||||
func (t *MJPEG) String() string {
|
func (t *MJPEG) String() string {
|
||||||
return "MJPEG"
|
return "M-JPEG"
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClockRate implements Format.
|
// ClockRate implements Format.
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestMJPEGAttributes(t *testing.T) {
|
func TestMJPEGAttributes(t *testing.T) {
|
||||||
format := &MJPEG{}
|
format := &MJPEG{}
|
||||||
require.Equal(t, "MJPEG", format.String())
|
require.Equal(t, "M-JPEG", format.String())
|
||||||
require.Equal(t, 90000, format.ClockRate())
|
require.Equal(t, 90000, format.ClockRate())
|
||||||
require.Equal(t, uint8(26), format.PayloadType())
|
require.Equal(t, uint8(26), format.PayloadType())
|
||||||
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
|
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
|
||||||
|
@@ -94,7 +94,7 @@ var chmAcSymbols = []byte{ //nolint:dupl
|
|||||||
0xf9, 0xfa,
|
0xf9, 0xfa,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decoder is a RTP/MJPEG decoder.
|
// Decoder is a RTP/M-JPEG decoder.
|
||||||
type Decoder struct {
|
type Decoder struct {
|
||||||
timeDecoder *rtptimedec.Decoder
|
timeDecoder *rtptimedec.Decoder
|
||||||
firstPacketReceived bool
|
firstPacketReceived bool
|
||||||
@@ -109,7 +109,7 @@ func (d *Decoder) Init() {
|
|||||||
d.timeDecoder = rtptimedec.New(rtpClockRate)
|
d.timeDecoder = rtptimedec.New(rtpClockRate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode decodes an image from a RTP/MJPEG packet.
|
// Decode decodes an image from a RTP/M-JPEG packet.
|
||||||
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) {
|
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) {
|
||||||
byts := pkt.Payload
|
byts := pkt.Payload
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ func randUint32() uint32 {
|
|||||||
return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
|
return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encoder is a RTP/MJPEG encoder.
|
// Encoder is a RTP/M-JPEG encoder.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
// SSRC of packets (optional).
|
// SSRC of packets (optional).
|
||||||
// It defaults to a random value.
|
// It defaults to a random value.
|
||||||
@@ -68,7 +68,7 @@ func (e *Encoder) encodeTimestamp(ts time.Duration) uint32 {
|
|||||||
return *e.InitialTimestamp + uint32(ts.Seconds()*rtpClockRate)
|
return *e.InitialTimestamp + uint32(ts.Seconds()*rtpClockRate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode encodes an image into RTP/MJPEG packets.
|
// Encode encodes an image into RTP/M-JPEG packets.
|
||||||
func (e *Encoder) Encode(image []byte, pts time.Duration) ([]*rtp.Packet, error) {
|
func (e *Encoder) Encode(image []byte, pts time.Duration) ([]*rtp.Packet, error) {
|
||||||
l := len(image)
|
l := len(image)
|
||||||
if l < 2 || image[0] != 0xFF || image[1] != jpeg.MarkerStartOfImage {
|
if l < 2 || image[0] != 0xFF || image[1] != jpeg.MarkerStartOfImage {
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
// Package headers contains RTP/MJPEG headers.
|
// Package headers contains RTP/M-JPEG headers.
|
||||||
package headers
|
package headers
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Package rtpmjpeg contains a RTP/MJPEG decoder and encoder.
|
// Package rtpmjpeg contains a RTP/M-JPEG decoder and encoder.
|
||||||
package rtpmjpeg
|
package rtpmjpeg
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Reference in New Issue
Block a user