Refactoring.
This commit is contained in:
parent
f640611620
commit
82521c8142
@ -2,11 +2,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
"writer/internal/config"
|
"writer/internal/config"
|
||||||
"writer/internal/procRTSP"
|
"writer/internal/procRTSP"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Profile.
|
||||||
|
go func() {
|
||||||
|
log.Println(http.ListenAndServe("localhost:6060", nil))
|
||||||
|
}()
|
||||||
|
|
||||||
// Parse camera links from YAML file into struct Cameras.
|
// Parse camera links from YAML file into struct Cameras.
|
||||||
c, err := config.ParseCamerasYAML()
|
c, err := config.ParseCamerasYAML()
|
||||||
if err != nil {
|
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.
|
// ProcRTSP process RTSP protocol and writes H264 and PCM flows into TS container.
|
||||||
func ProcRTSP(period int, URI string) error {
|
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 "/".
|
// Return the last part of the URI after "/".
|
||||||
cuttedURI := config.CutURI(URI)
|
cuttedURI := config.CutURI(URI)
|
||||||
|
|
||||||
@ -133,8 +139,6 @@ func ProcRTSP(period int, URI string) error {
|
|||||||
// Mpeg4AudioFormat: mpeg4AudioFormat,
|
// Mpeg4AudioFormat: mpeg4AudioFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(currentMpegtsMuxer.FileName)
|
|
||||||
|
|
||||||
err = currentMpegtsMuxer.Initialize()
|
err = currentMpegtsMuxer.Initialize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -158,13 +162,13 @@ func ProcRTSP(period int, URI string) error {
|
|||||||
// Process H264 flow and return PTS and AU.
|
// Process H264 flow and return PTS and AU.
|
||||||
pts, au, err := media.ProcH264(&c, h264Media, h264RTPDec, pkt)
|
pts, au, err := media.ProcH264(&c, h264Media, h264RTPDec, pkt)
|
||||||
if err != nil {
|
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.
|
// Encode the access unit into MPEG-TS.
|
||||||
err = currentMpegtsMuxer.WriteH264(au, pts)
|
err = currentMpegtsMuxer.WriteH264(au, pts)
|
||||||
if err != nil {
|
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:
|
case *format.G711:
|
||||||
|
@ -79,6 +79,7 @@ func (e *MpegtsMuxer) WriteH264(au [][]byte, pts int64) error {
|
|||||||
idrPresent := false
|
idrPresent := false
|
||||||
|
|
||||||
for _, nalu := range au {
|
for _, nalu := range au {
|
||||||
|
if len(nalu) != 0 {
|
||||||
typ := h264.NALUType(nalu[0] & 0x1F)
|
typ := h264.NALUType(nalu[0] & 0x1F)
|
||||||
switch typ {
|
switch typ {
|
||||||
case h264.NALUTypeSPS:
|
case h264.NALUTypeSPS:
|
||||||
@ -101,6 +102,7 @@ func (e *MpegtsMuxer) WriteH264(au [][]byte, pts int64) error {
|
|||||||
|
|
||||||
filteredAU = append(filteredAU, nalu)
|
filteredAU = append(filteredAU, nalu)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
au = filteredAU
|
au = filteredAU
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user