Added nil checking for the h264Format and g711Format.

This commit is contained in:
Сергей Петров 2025-03-11 12:26:20 +05:00
parent 670e27f9c4
commit 333a51f633
2 changed files with 15 additions and 7 deletions

View File

@ -11,7 +11,7 @@ import (
"log" "log"
) )
// CheckG711Format finds the H264 media and format. // CheckG711Format finds the G711 media and format.
func CheckG711Format(desc *description.Session) (*format.G711, *description.Media, error) { func CheckG711Format(desc *description.Session) (*format.G711, *description.Media, error) {
var g711Format *format.G711 var g711Format *format.G711
g711Media := desc.FindFormat(&g711Format) g711Media := desc.FindFormat(&g711Format)

View File

@ -7,6 +7,8 @@ import (
"github.com/bluenviron/gortsplib/v4/pkg/base" "github.com/bluenviron/gortsplib/v4/pkg/base"
"github.com/bluenviron/gortsplib/v4/pkg/description" "github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format" "github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/format/rtph264"
"github.com/bluenviron/gortsplib/v4/pkg/format/rtplpcm"
"github.com/pion/rtp" "github.com/pion/rtp"
_ "github.com/zaf/g711" _ "github.com/zaf/g711"
"log" "log"
@ -18,6 +20,8 @@ import (
var ( var (
resolutions = []string{"1280x720"} resolutions = []string{"1280x720"}
h264RTPDec *rtph264.Decoder
g711RTPDec *rtplpcm.Decoder
) )
// ProcRTSP process RTSP protocol and writes H264 and PCM flows into TS container. // ProcRTSP process RTSP protocol and writes H264 and PCM flows into TS container.
@ -70,16 +74,20 @@ func ProcRTSP(period int, URI string) error {
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// Create RTP -> H264 decoder. // Create RTP -> H264 decoder.
h264RTPDec, err := h264Format.CreateDecoder() if h264Format != nil {
h264RTPDec, err = h264Format.CreateDecoder()
if err != nil { if err != nil {
return fmt.Errorf("create H264 decoder error: %w", err) return fmt.Errorf("create H264 decoder error: %w", err)
} }
}
// Create RTP -> H264 decoder. // Create RTP -> H264 decoder.
g711RTPDec, err := g711Format.CreateDecoder() if g711Format != nil {
g711RTPDec, err = g711Format.CreateDecoder()
if err != nil { if err != nil {
return fmt.Errorf("create G711 decoder error: %w", err) return fmt.Errorf("create G711 decoder error: %w", err)
} }
}
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////