stream use video_id in logs.

This commit is contained in:
Miroslav Šedivý 2021-08-28 20:15:54 +02:00
parent b2ae808233
commit 8bb77166e8
3 changed files with 17 additions and 8 deletions

View File

@ -76,7 +76,7 @@ func (manager *BroacastManagerCtx) createPipeline() error {
pipelineStr := strings.Replace(manager.pipelineStr, "{url}", manager.url, 1) pipelineStr := strings.Replace(manager.pipelineStr, "{url}", manager.url, 1)
manager.logger.Info(). manager.logger.Info().
Str("str", pipelineStr). Str("src", pipelineStr).
Msgf("starting pipeline") Msgf("starting pipeline")
manager.pipeline, err = gst.CreatePipeline(pipelineStr) manager.pipeline, err = gst.CreatePipeline(pipelineStr)

View File

@ -57,7 +57,7 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
} }
videos := map[string]*StreamManagerCtx{} videos := map[string]*StreamManagerCtx{}
for key, cnf := range config.VideoPipelines { for video_id, cnf := range config.VideoPipelines {
pipelineConf := cnf pipelineConf := cnf
createPipeline := func() string { createPipeline := func() string {
@ -69,7 +69,7 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
pipeline, err := pipelineConf.GetPipeline(*screen) pipeline, err := pipelineConf.GetPipeline(*screen)
if err != nil { if err != nil {
logger.Panic().Err(err). logger.Panic().Err(err).
Str("video_id", key). Str("video_id", video_id).
Msg("unable to get video pipeline") Msg("unable to get video pipeline")
} }
@ -82,12 +82,12 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
// trigger function to catch evaluation errors at startup // trigger function to catch evaluation errors at startup
pipeline := createPipeline() pipeline := createPipeline()
logger.Info(). logger.Info().
Str("video_id", key). Str("video_id", video_id).
Str("pipeline", pipeline). Str("pipeline", pipeline).
Msg("syntax check for video stream pipeline passed") Msg("syntax check for video stream pipeline passed")
// append to videos // append to videos
videos[key] = streamNew(config.VideoCodec, createPipeline) videos[video_id] = streamNew(config.VideoCodec, createPipeline, video_id)
} }
return &CaptureManagerCtx{ return &CaptureManagerCtx{
@ -109,7 +109,7 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
"! %s "+ "! %s "+
"! appsink name=appsink", config.AudioDevice, config.AudioCodec.Pipeline, "! appsink name=appsink", config.AudioDevice, config.AudioCodec.Pipeline,
) )
}), }, "audio"),
videos: videos, videos: videos,
videoIDs: config.VideoIDs, videoIDs: config.VideoIDs,
} }

View File

@ -27,9 +27,14 @@ type StreamManagerCtx struct {
started bool started bool
} }
func streamNew(codec codec.RTPCodec, pipelineStr func() string) *StreamManagerCtx { func streamNew(codec codec.RTPCodec, pipelineStr func() string, video_id string) *StreamManagerCtx {
logger := log.With().
Str("module", "capture").
Str("submodule", "stream").
Str("video_id", video_id).Logger()
manager := &StreamManagerCtx{ manager := &StreamManagerCtx{
logger: log.With().Str("module", "capture").Str("submodule", "stream").Logger(), logger: logger,
codec: codec, codec: codec,
pipelineStr: pipelineStr, pipelineStr: pipelineStr,
listeners: map[uintptr]*func(sample types.Sample){}, listeners: map[uintptr]*func(sample types.Sample){},
@ -85,6 +90,7 @@ func (manager *StreamManagerCtx) AddListener(listener *func(sample types.Sample)
if listener != nil { if listener != nil {
ptr := reflect.ValueOf(listener).Pointer() ptr := reflect.ValueOf(listener).Pointer()
manager.listeners[ptr] = listener manager.listeners[ptr] = listener
manager.logger.Debug().Interface("ptr", ptr).Msgf("adding listener")
} }
} }
@ -95,6 +101,7 @@ func (manager *StreamManagerCtx) RemoveListener(listener *func(sample types.Samp
if listener != nil { if listener != nil {
ptr := reflect.ValueOf(listener).Pointer() ptr := reflect.ValueOf(listener).Pointer()
delete(manager.listeners, ptr) delete(manager.listeners, ptr)
manager.logger.Debug().Interface("ptr", ptr).Msgf("removing listener")
} }
} }
@ -114,6 +121,7 @@ func (manager *StreamManagerCtx) Start() error {
return err return err
} }
manager.logger.Info().Msgf("start")
manager.started = true manager.started = true
return nil return nil
} }
@ -122,6 +130,7 @@ func (manager *StreamManagerCtx) Stop() {
manager.mu.Lock() manager.mu.Lock()
defer manager.mu.Unlock() defer manager.mu.Unlock()
manager.logger.Info().Msgf("stop")
manager.started = false manager.started = false
manager.destroyPipeline() manager.destroyPipeline()
} }