Refactoring.
This commit is contained in:
parent
f640611620
commit
82521c8142
@ -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 {
|
||||
|
@ -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:
|
||||
|
@ -79,27 +79,29 @@ func (e *MpegtsMuxer) WriteH264(au [][]byte, pts int64) error {
|
||||
idrPresent := false
|
||||
|
||||
for _, nalu := range au {
|
||||
typ := h264.NALUType(nalu[0] & 0x1F)
|
||||
switch typ {
|
||||
case h264.NALUTypeSPS:
|
||||
e.H264Format.SPS = nalu
|
||||
continue
|
||||
if len(nalu) != 0 {
|
||||
typ := h264.NALUType(nalu[0] & 0x1F)
|
||||
switch typ {
|
||||
case h264.NALUTypeSPS:
|
||||
e.H264Format.SPS = nalu
|
||||
continue
|
||||
|
||||
case h264.NALUTypePPS:
|
||||
e.H264Format.PPS = nalu
|
||||
continue
|
||||
case h264.NALUTypePPS:
|
||||
e.H264Format.PPS = nalu
|
||||
continue
|
||||
|
||||
case h264.NALUTypeAccessUnitDelimiter:
|
||||
continue
|
||||
case h264.NALUTypeAccessUnitDelimiter:
|
||||
continue
|
||||
|
||||
case h264.NALUTypeIDR:
|
||||
idrPresent = true
|
||||
case h264.NALUTypeIDR:
|
||||
idrPresent = true
|
||||
|
||||
case h264.NALUTypeNonIDR:
|
||||
nonIDRPresent = true
|
||||
case h264.NALUTypeNonIDR:
|
||||
nonIDRPresent = true
|
||||
}
|
||||
|
||||
filteredAU = append(filteredAU, nalu)
|
||||
}
|
||||
|
||||
filteredAU = append(filteredAU, nalu)
|
||||
}
|
||||
|
||||
au = filteredAU
|
||||
|
Loading…
x
Reference in New Issue
Block a user