# Path: vocto/port.py
# class Port(object):
# 
#     NONE = 0
# 
#     IN = 1
#     OUT = 2
# 
#     OFFSET_PREVIEW = 100
#     # core listening port
#     CORE_LISTENING = 9999
#     # input ports
#     SOURCES_IN = 10000
#     SOURCES_BACKGROUND = 16000
#     SOURCE_OVERLAY= 14000
#     SOURCES_BLANK = 17000
#     AUDIO_SOURCE_BLANK = 18000
#     # output ports
#     MIX_OUT = 11000
#     MIX_PREVIEW = MIX_OUT+OFFSET_PREVIEW
#     SOURCES_OUT = 13000
#     SOURCES_PREVIEW = SOURCES_OUT+OFFSET_PREVIEW
#     LIVE_OUT = 15000
#     LIVE_PREVIEW = LIVE_OUT+OFFSET_PREVIEW
# 
#     def __init__(self, name, source=None, audio=None, video=None):
#         self.name = name
#         self.source = source
#         self.audio = audio
#         self.video = video
#         self.update()
# 
#     def todict(self):
#         return {
#             'name': self.name,
#             'port': self.port,
#             'audio': self.audio,
#             'video': self.video,
#             'io': self.io,
#             'connections': self.connections
#         }
# 
#     def update(self):
#         if self.source:
#             self.port = self.source.port()
#             self.audio = self.source.audio_channels()
#             self.video = self.source.video_channels()
#             self.io = self.IN if self.source.is_input() else self.OUT
#             self.connections = self.source.num_connections()
# 
#     def from_str(_str):
#         p = Port(_str['name'])
#         p.port = _str['port']
#         p.audio = _str['audio']
#         p.video = _str['video']
#         p.io = _str['io']
#         p.connections = _str['connections']
#         return p
# 
#     def is_input(self):
#         return self.io == Port.IN
# 
#     def is_output(self):
#         return self.io == Port.OUT
# 
# Path: vocto/debug.py
# def gst_generate_dot(pipeline, name):
#     from lib.args import Args
#     dotfile = os.path.join(os.environ['GST_DEBUG_DUMP_DOT_DIR'], "%s.dot" % name)
#     log.debug("Generating DOT image of pipeline '{name}' into '{file}'".format(name=name, file=dotfile))
#     Gst.debug_bin_to_dot_file(pipeline, Gst.DebugGraphDetails(Args.gst_debug_details), name)
# 
# Path: vocto/pretty.py
# def pretty(pipe):
#     result = ""
#     for line in pipe.splitlines():
#         line = line.strip()
#         r = re.match(r'^(!\s.*)$', line)
#         if r:
#             result += "    " + r.group(1)
#         else:
#             r = re.match(r'^([\w\-_]*\s*\=\s*.*)$', line)
#             if r:
#                 result += "        " + r.group(1)
#             else:
#                 r = re.match(r'^(\))$', line)
#                 if r:
#                     result += r.group(1)
#                 else:
#                     r = re.match(r'^bin.\($', line)
#                     if r:
#                         result += line
#                     else:
#                         result += "    " + line
#         result += "\n"
#     return result


import logging
import re
import sys
from gi.repository import Gst
from lib.config import Config
from lib.sources import spawn_source
from lib.avrawoutput import AVRawOutput
from lib.avpreviewoutput import AVPreviewOutput
from lib.videomix import VideoMix
from lib.audiomix import AudioMix
from lib.blinder import Blinder
from lib.args import Args
from lib.clock import Clock
from vocto.port import Port
from vocto.debug import gst_generate_dot
from vocto.pretty import pretty
#!/usr/bin/env python3


# import library components

class Pipeline(object):
    """mixing, streaming and encoding pipeline constuction and control"""

    def __init__(self):
        self.log = logging.getLogger('Pipeline')
        # log capabilities
        self.log.info('Video-Caps configured to: %s', Config.getVideoCaps())
        self.log.info('Audio-Caps configured to: %s', Config.getAudioCaps())

        # get A/B sources from config
        sources = Config.getSources()
        if len(sources) < 1:
            raise RuntimeError("At least one AVSource must be configured!")

        # collect bins for all modules
        self.bins = []
        self.ports = []

        # create A/V sources
        self.log.info('Creating %u AVSources: %s', len(sources), sources)
        for idx, source_name in enumerate(sources):
            # count port and create source

# Path: vocto/port.py
# class Port(object):
# 
#     NONE = 0
# 
#     IN = 1
#     OUT = 2
# 
#     OFFSET_PREVIEW = 100
#     # core listening port
#     CORE_LISTENING = 9999
#     # input ports
#     SOURCES_IN = 10000
#     SOURCES_BACKGROUND = 16000
#     SOURCE_OVERLAY= 14000
#     SOURCES_BLANK = 17000
#     AUDIO_SOURCE_BLANK = 18000
#     # output ports
#     MIX_OUT = 11000
#     MIX_PREVIEW = MIX_OUT+OFFSET_PREVIEW
#     SOURCES_OUT = 13000
#     SOURCES_PREVIEW = SOURCES_OUT+OFFSET_PREVIEW
#     LIVE_OUT = 15000
#     LIVE_PREVIEW = LIVE_OUT+OFFSET_PREVIEW
# 
#     def __init__(self, name, source=None, audio=None, video=None):
#         self.name = name
#         self.source = source
#         self.audio = audio
#         self.video = video
#         self.update()
# 
#     def todict(self):
#         return {
#             'name': self.name,
#             'port': self.port,
#             'audio': self.audio,
#             'video': self.video,
#             'io': self.io,
#             'connections': self.connections
#         }
# 
#     def update(self):
#         if self.source:
#             self.port = self.source.port()
#             self.audio = self.source.audio_channels()
#             self.video = self.source.video_channels()
#             self.io = self.IN if self.source.is_input() else self.OUT
#             self.connections = self.source.num_connections()
# 
#     def from_str(_str):
#         p = Port(_str['name'])
#         p.port = _str['port']
#         p.audio = _str['audio']
#         p.video = _str['video']
#         p.io = _str['io']
#         p.connections = _str['connections']
#         return p
# 
#     def is_input(self):
#         return self.io == Port.IN
# 
#     def is_output(self):
#         return self.io == Port.OUT
# 
# Path: vocto/debug.py
# def gst_generate_dot(pipeline, name):
#     from lib.args import Args
#     dotfile = os.path.join(os.environ['GST_DEBUG_DUMP_DOT_DIR'], "%s.dot" % name)
#     log.debug("Generating DOT image of pipeline '{name}' into '{file}'".format(name=name, file=dotfile))
#     Gst.debug_bin_to_dot_file(pipeline, Gst.DebugGraphDetails(Args.gst_debug_details), name)
# 
# Path: vocto/pretty.py
# def pretty(pipe):
#     result = ""
#     for line in pipe.splitlines():
#         line = line.strip()
#         r = re.match(r'^(!\s.*)$', line)
#         if r:
#             result += "    " + r.group(1)
#         else:
#             r = re.match(r'^([\w\-_]*\s*\=\s*.*)$', line)
#             if r:
#                 result += "        " + r.group(1)
#             else:
#                 r = re.match(r'^(\))$', line)
#                 if r:
#                     result += r.group(1)
#                 else:
#                     r = re.match(r'^bin.\($', line)
#                     if r:
#                         result += line
#                     else:
#                         result += "    " + line
#         result += "\n"
#     return result


# Path: voctocore/lib/pipeline.py
import logging
import re
import sys
from gi.repository import Gst
from lib.config import Config
from lib.sources import spawn_source
from lib.avrawoutput import AVRawOutput
from lib.avpreviewoutput import AVPreviewOutput
from lib.videomix import VideoMix
from lib.audiomix import AudioMix
from lib.blinder import Blinder
from lib.args import Args
from lib.clock import Clock
from vocto.port import Port
from vocto.debug import gst_generate_dot
from vocto.pretty import pretty

#!/usr/bin/env python3


# import library components

class Pipeline(object):
    """mixing, streaming and encoding pipeline constuction and control"""

    def __init__(self):
        self.log = logging.getLogger('Pipeline')
        # log capabilities
        self.log.info('Video-Caps configured to: %s', Config.getVideoCaps())
        self.log.info('Audio-Caps configured to: %s', Config.getAudioCaps())

        # get A/B sources from config
        sources = Config.getSources()
        if len(sources) < 1:
            raise RuntimeError("At least one AVSource must be configured!")

        # collect bins for all modules
        self.bins = []
        self.ports = []

        # create A/V sources
        self.log.info('Creating %u AVSources: %s', len(sources), sources)
        for idx, source_name in enumerate(sources):
            # count port and create source

            source = spawn_source(source_name, Port.SOURCES_IN + idx)