mirror of
				https://gitlab.crans.org/nounous/ghostream.git
				synced 2025-11-04 15:42:26 +01:00 
			
		
		
		
	Update package text with Quality structure
This commit is contained in:
		@@ -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
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Check that the transcoded stream does not already exist
 | 
						// For each new stream
 | 
				
			||||||
			name := sourceName + "@text"
 | 
						for name := range event {
 | 
				
			||||||
			_, ok := streams[name]
 | 
							// Get stream
 | 
				
			||||||
			if ok {
 | 
							stream, err := streams.Get(name)
 | 
				
			||||||
				// Stream is already transcoded
 | 
							if err != nil {
 | 
				
			||||||
				continue
 | 
								log.Printf("Failed to get stream '%s'", name)
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Start conversion
 | 
					 | 
				
			||||||
			log.Printf("Starting text transcode '%s'", name)
 | 
					 | 
				
			||||||
			st := stream.New()
 | 
					 | 
				
			||||||
			streams[name] = st
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			go transcode(sourceStream, st, cfg)
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Regulary pull stream list,
 | 
							// Get specific quality
 | 
				
			||||||
		// it may be better to tweak the messaging system
 | 
							// FIXME: make it possible to forward other qualities
 | 
				
			||||||
		// to get an event on a new stream.
 | 
							qualityName := "source"
 | 
				
			||||||
		time.Sleep(time.Second)
 | 
							quality, err := stream.GetQuality(qualityName)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								log.Printf("Failed to get quality '%s'", qualityName)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Create new text quality
 | 
				
			||||||
 | 
							outputQuality, err := stream.CreateQuality("text")
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								log.Printf("Failed to create quality 'text': %s", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Start forwarding
 | 
				
			||||||
 | 
							log.Printf("Starting text transcoder for '%s' quality '%s'", name, qualityName)
 | 
				
			||||||
 | 
							go transcode(quality, outputQuality, cfg)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user