1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 04:32:19 +00:00

Update package text with Quality structure

This commit is contained in:
Alexandre Iooss 2020-10-19 19:52:24 +02:00
parent 34200afaed
commit d03d4fed40
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
2 changed files with 31 additions and 32 deletions

View File

@ -8,10 +8,8 @@ import (
"io"
"log"
"os/exec"
"strings"
"time"
"gitlab.crans.org/nounous/ghostream/stream"
"gitlab.crans.org/nounous/ghostream/messaging"
)
// Options holds text package configuration
@ -23,45 +21,46 @@ type Options struct {
}
// Init text transcoder
func Init(streams map[string]*stream.Stream, cfg *Options) {
func Init(streams *messaging.Streams, cfg *Options) {
if !cfg.Enabled {
// Text transcode is not enabled, ignore
return
}
// Regulary check existing streams
for {
for sourceName, sourceStream := range streams {
if strings.Contains(sourceName, "@") {
// Not a source stream, pass
continue
// Subscribe to new stream event
event := make(chan string, 8)
streams.Subscribe(event)
// For each new stream
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
name := sourceName + "@text"
_, ok := streams[name]
if ok {
// Stream is already transcoded
continue
// Get specific quality
// FIXME: make it possible to forward other qualities
qualityName := "source"
quality, err := stream.GetQuality(qualityName)
if err != nil {
log.Printf("Failed to get quality '%s'", qualityName)
}
// Start conversion
log.Printf("Starting text transcode '%s'", name)
st := stream.New()
streams[name] = st
go transcode(sourceStream, st, cfg)
// Create new text quality
outputQuality, err := stream.CreateQuality("text")
if err != nil {
log.Printf("Failed to create quality 'text': %s", err)
}
// Regulary pull stream list,
// it may be better to tweak the messaging system
// to get an event on a new stream.
time.Sleep(time.Second)
// Start forwarding
log.Printf("Starting text transcoder for '%s' quality '%s'", name, qualityName)
go transcode(quality, outputQuality, cfg)
}
}
// 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
videoInput := make(chan []byte, 1024)
input.Register(videoInput)

View File

@ -2,7 +2,7 @@
package transcoder
import (
"gitlab.crans.org/nounous/ghostream/stream"
"gitlab.crans.org/nounous/ghostream/messaging"
"gitlab.crans.org/nounous/ghostream/transcoder/text"
)
@ -12,6 +12,6 @@ type Options struct {
}
// 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)
}