Refactoring.

This commit is contained in:
Сергей Петров 2025-03-14 12:21:51 +05:00
parent f640611620
commit 82521c8142
3 changed files with 33 additions and 20 deletions

View File

@ -2,11 +2,18 @@ package main
import (
"log"
"net/http"
_ "net/http/pprof"
"writer/internal/config"
"writer/internal/procRTSP"
)
func main() {
// Profile.
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// Parse camera links from YAML file into struct Cameras.
c, err := config.ParseCamerasYAML()
if err != nil {

View File

@ -46,6 +46,12 @@ func StartWriter(period int, URI string) error {
// ProcRTSP process RTSP protocol and writes H264 and PCM flows into TS container.
func ProcRTSP(period int, URI string) error {
defer func() {
if r := recover(); r != nil {
fmt.Println("Поймана паника:", r)
}
}()
// Return the last part of the URI after "/".
cuttedURI := config.CutURI(URI)
@ -133,8 +139,6 @@ func ProcRTSP(period int, URI string) error {
// Mpeg4AudioFormat: mpeg4AudioFormat,
}
fmt.Println(currentMpegtsMuxer.FileName)
err = currentMpegtsMuxer.Initialize()
if err != nil {
panic(err)
@ -158,13 +162,13 @@ func ProcRTSP(period int, URI string) error {
// Process H264 flow and return PTS and AU.
pts, au, err := media.ProcH264(&c, h264Media, h264RTPDec, pkt)
if err != nil {
log.Printf("%s: process H264 error: %s\n", cuttedURI, err)
//log.Printf("%s: process H264 error: %s\n", cuttedURI, err)
}
// Encode the access unit into MPEG-TS.
err = currentMpegtsMuxer.WriteH264(au, pts)
if err != nil {
log.Printf("%s: writing H264 packet: %s\n", cuttedURI, err)
//log.Printf("%s: writing H264 packet: %s\n", cuttedURI, err)
}
case *format.G711:

View File

@ -79,6 +79,7 @@ func (e *MpegtsMuxer) WriteH264(au [][]byte, pts int64) error {
idrPresent := false
for _, nalu := range au {
if len(nalu) != 0 {
typ := h264.NALUType(nalu[0] & 0x1F)
switch typ {
case h264.NALUTypeSPS:
@ -101,6 +102,7 @@ func (e *MpegtsMuxer) WriteH264(au [][]byte, pts int64) error {
filteredAU = append(filteredAU, nalu)
}
}
au = filteredAU