mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
refactor rempte manager - start pipeline only once.
This commit is contained in:
parent
7d5df0346e
commit
96e99955fc
@ -48,13 +48,18 @@ func (manager *RemoteManager) AudioCodec() string {
|
|||||||
func (manager *RemoteManager) Start() {
|
func (manager *RemoteManager) Start() {
|
||||||
xorg.Display(manager.config.Display)
|
xorg.Display(manager.config.Display)
|
||||||
|
|
||||||
|
manager.logger.Info().
|
||||||
|
Str("screen_resolution", fmt.Sprintf("%dx%d@%d", manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate)).
|
||||||
|
Msgf("Setting screen resolution...")
|
||||||
|
|
||||||
if !xorg.ValidScreenSize(manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate) {
|
if !xorg.ValidScreenSize(manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate) {
|
||||||
manager.logger.Warn().Msgf("invalid screen option %dx%d@%d", manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate)
|
manager.logger.Warn().Msgf("invalid screen option %dx%d@%d", manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate)
|
||||||
} else if err := xorg.ChangeScreenSize(manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate); err != nil {
|
} else if err := xorg.ChangeScreenSize(manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate); err != nil {
|
||||||
manager.logger.Warn().Err(err).Msg("unable to change screen size")
|
manager.logger.Warn().Err(err).Msg("unable to change screen size")
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.createPipelines()
|
manager.createVideoPipeline()
|
||||||
|
manager.createAudioPipeline()
|
||||||
manager.broadcast.Start()
|
manager.broadcast.Start()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -101,17 +106,7 @@ func (manager *RemoteManager) OnAudioFrame(listener func(sample types.Sample)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (manager *RemoteManager) StartStream() {
|
func (manager *RemoteManager) StartStream() {
|
||||||
manager.createPipelines()
|
manager.logger.Info().Msgf("Pipelines starting...")
|
||||||
|
|
||||||
manager.logger.Info().
|
|
||||||
Str("video_display", manager.config.Display).
|
|
||||||
Str("video_codec", manager.config.VideoCodec).
|
|
||||||
Str("audio_device", manager.config.Device).
|
|
||||||
Str("audio_codec", manager.config.AudioCodec).
|
|
||||||
Str("audio_pipeline_src", manager.audio.Src).
|
|
||||||
Str("video_pipeline_src", manager.video.Src).
|
|
||||||
Str("screen_resolution", fmt.Sprintf("%dx%d@%d", manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate)).
|
|
||||||
Msgf("Pipelines starting...")
|
|
||||||
|
|
||||||
manager.video.Start()
|
manager.video.Start()
|
||||||
manager.audio.Start()
|
manager.audio.Start()
|
||||||
@ -120,6 +115,7 @@ func (manager *RemoteManager) StartStream() {
|
|||||||
|
|
||||||
func (manager *RemoteManager) StopStream() {
|
func (manager *RemoteManager) StopStream() {
|
||||||
manager.logger.Info().Msgf("Pipelines shutting down...")
|
manager.logger.Info().Msgf("Pipelines shutting down...")
|
||||||
|
|
||||||
manager.video.Stop()
|
manager.video.Stop()
|
||||||
manager.audio.Stop()
|
manager.audio.Stop()
|
||||||
manager.streaming = false
|
manager.streaming = false
|
||||||
@ -129,22 +125,41 @@ func (manager *RemoteManager) Streaming() bool {
|
|||||||
return manager.streaming
|
return manager.streaming
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *RemoteManager) createPipelines() {
|
func (manager *RemoteManager) createVideoPipeline() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
manager.logger.Info().
|
||||||
|
Str("video_codec", manager.config.VideoCodec).
|
||||||
|
Str("video_display", manager.config.Display).
|
||||||
|
Str("video_params", manager.config.VideoParams).
|
||||||
|
Msgf("Creating video pipeline...")
|
||||||
|
|
||||||
manager.video, err = gst.CreateAppPipeline(
|
manager.video, err = gst.CreateAppPipeline(
|
||||||
manager.config.VideoCodec,
|
manager.config.VideoCodec,
|
||||||
manager.config.Display,
|
manager.config.Display,
|
||||||
manager.config.VideoParams,
|
manager.config.VideoParams,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manager.logger.Panic().Err(err).Msg("unable to create video pipeline")
|
manager.logger.Panic().Err(err).Msg("unable to create video pipeline")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (manager *RemoteManager) createAudioPipeline() {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
manager.logger.Info().
|
||||||
|
Str("audio_codec", manager.config.AudioCodec).
|
||||||
|
Str("audio_display", manager.config.Device).
|
||||||
|
Str("audio_params", manager.config.AudioParams).
|
||||||
|
Msgf("Creating audio pipeline...")
|
||||||
|
|
||||||
manager.audio, err = gst.CreateAppPipeline(
|
manager.audio, err = gst.CreateAppPipeline(
|
||||||
manager.config.AudioCodec,
|
manager.config.AudioCodec,
|
||||||
manager.config.Device,
|
manager.config.Device,
|
||||||
manager.config.AudioParams,
|
manager.config.AudioParams,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manager.logger.Panic().Err(err).Msg("unable to create audio pipeline")
|
manager.logger.Panic().Err(err).Msg("unable to create audio pipeline")
|
||||||
}
|
}
|
||||||
@ -169,16 +184,7 @@ func (manager *RemoteManager) ChangeResolution(width int, height int, rate int)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
manager.createVideoPipeline()
|
||||||
manager.video, err = gst.CreateAppPipeline(
|
|
||||||
manager.config.VideoCodec,
|
|
||||||
manager.config.Display,
|
|
||||||
manager.config.VideoParams,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
manager.logger.Panic().Err(err).Msg("unable to create new video pipeline")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user