mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 10:22:19 +00:00
Update package text with Quality structure
This commit is contained in:
parent
34200afaed
commit
d03d4fed40
@ -8,10 +8,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gitlab.crans.org/nounous/ghostream/stream"
|
"gitlab.crans.org/nounous/ghostream/messaging"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options holds text package configuration
|
// Options holds text package configuration
|
||||||
@ -23,45 +21,46 @@ type Options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init text transcoder
|
// Init text transcoder
|
||||||
func Init(streams map[string]*stream.Stream, cfg *Options) {
|
func Init(streams *messaging.Streams, cfg *Options) {
|
||||||
if !cfg.Enabled {
|
if !cfg.Enabled {
|
||||||
// Text transcode is not enabled, ignore
|
// Text transcode is not enabled, ignore
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regulary check existing streams
|
// Subscribe to new stream event
|
||||||
for {
|
event := make(chan string, 8)
|
||||||
for sourceName, sourceStream := range streams {
|
streams.Subscribe(event)
|
||||||
if strings.Contains(sourceName, "@") {
|
|
||||||
// Not a source stream, pass
|
// For each new stream
|
||||||
continue
|
for name := range event {
|
||||||
|
// Get stream
|
||||||
|
stream, err := streams.Get(name)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to get stream '%s'", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the transcoded stream does not already exist
|
// Get specific quality
|
||||||
name := sourceName + "@text"
|
// FIXME: make it possible to forward other qualities
|
||||||
_, ok := streams[name]
|
qualityName := "source"
|
||||||
if ok {
|
quality, err := stream.GetQuality(qualityName)
|
||||||
// Stream is already transcoded
|
if err != nil {
|
||||||
continue
|
log.Printf("Failed to get quality '%s'", qualityName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start conversion
|
// Create new text quality
|
||||||
log.Printf("Starting text transcode '%s'", name)
|
outputQuality, err := stream.CreateQuality("text")
|
||||||
st := stream.New()
|
if err != nil {
|
||||||
streams[name] = st
|
log.Printf("Failed to create quality 'text': %s", err)
|
||||||
|
|
||||||
go transcode(sourceStream, st, cfg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regulary pull stream list,
|
// Start forwarding
|
||||||
// it may be better to tweak the messaging system
|
log.Printf("Starting text transcoder for '%s' quality '%s'", name, qualityName)
|
||||||
// to get an event on a new stream.
|
go transcode(quality, outputQuality, cfg)
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert video to ANSI text
|
// Convert video to ANSI text
|
||||||
func transcode(input, output *stream.Stream, cfg *Options) {
|
func transcode(input, output *messaging.Quality, cfg *Options) {
|
||||||
// Start ffmpeg to transcode video to rawvideo
|
// Start ffmpeg to transcode video to rawvideo
|
||||||
videoInput := make(chan []byte, 1024)
|
videoInput := make(chan []byte, 1024)
|
||||||
input.Register(videoInput)
|
input.Register(videoInput)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
package transcoder
|
package transcoder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitlab.crans.org/nounous/ghostream/stream"
|
"gitlab.crans.org/nounous/ghostream/messaging"
|
||||||
"gitlab.crans.org/nounous/ghostream/transcoder/text"
|
"gitlab.crans.org/nounous/ghostream/transcoder/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,6 +12,6 @@ type Options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init all transcoders
|
// Init all transcoders
|
||||||
func Init(streams map[string]*stream.Stream, cfg *Options) {
|
func Init(streams *messaging.Streams, cfg *Options) {
|
||||||
go text.Init(streams, &cfg.Text)
|
go text.Init(streams, &cfg.Text)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user