Exemple #1
0
def make_test_life_stream(feedback_dir: str) -> TestLifeStream:
    stream = TestLifeStream()
    stream._feedback_dir = feedback_dir
    stream.input = Urls(urls=[Url(id=Url.generate_id())])
    stream.output = Urls(
        urls=[Url(id=Url.generate_id(), uri=constants.DEFAULT_TEST_URL)])
    return stream
Exemple #2
0
def make_catchup_stream(feedback_dir: str,
                        timeshift_dir: str) -> CatchupStream:
    stream = CatchupStream()
    stream._feedback_dir = feedback_dir
    stream._timeshift_dir = timeshift_dir
    stream.input = Urls(urls=[Url(id=Url.generate_id())])
    return stream
Exemple #3
0
def make_timeshift_recorder_stream(
        feedback_dir: str, timeshift_dir: str) -> TimeshiftRecorderStream:
    stream = TimeshiftRecorderStream()
    stream._feedback_dir = feedback_dir
    stream._timeshift_dir = timeshift_dir
    stream.input = Urls(urls=[Url(id=Url.generate_id())])
    return stream
Exemple #4
0
    def get_data(self) -> Urls:
        urls = Urls()
        for url in self.data['urls']:
            urls.urls.append(Url(url['id'], url['uri']))

        return urls
Exemple #5
0
class Stream(EmbeddedDocument):
    meta = {'allow_inheritance': True, 'auto_create_index': True}

    id = ObjectIdField(required=True,
                       default=ObjectId,
                       unique=True,
                       primary_key=True)
    name = StringField(default=DEFAULT_STREAM_NAME,
                       max_length=MAX_STREAM_NAME_LENGTH,
                       min_length=MIN_STREAM_NAME_LENGTH,
                       required=True)
    created_date = DateTimeField(default=datetime.now)  # for inner use
    log_level = IntField(default=constants.StreamLogLevel.LOG_LEVEL_INFO,
                         required=True)

    input = EmbeddedDocumentField(Urls, default=Urls())
    output = EmbeddedDocumentField(Urls, default=Urls())
    have_video = BooleanField(default=constants.DEFAULT_HAVE_VIDEO,
                              required=True)
    have_audio = BooleanField(default=constants.DEFAULT_HAVE_AUDIO,
                              required=True)
    audio_select = IntField(default=constants.INVALID_AUDIO_SELECT,
                            required=True)
    loop = BooleanField(default=constants.DEFAULT_LOOP, required=True)
    restart_attempts = IntField(default=constants.DEFAULT_RESTART_ATTEMPTS,
                                required=True)
    auto_exit_time = IntField(default=constants.DEFAULT_AUTO_EXIT_TIME,
                              required=True)

    # runtime
    _status = constants.StreamStatus.NEW
    _cpu = 0.0
    _timestamp = 0
    _rss = 0
    _loop_start_time = 0
    _restarts = 0
    _start_time = 0
    _input_streams = str()
    _output_streams = str()
    _feedback_dir = str()

    def __init__(self, *args, **kwargs):
        super(Stream, self).__init__(*args, **kwargs)

    def set_feedback_dir(self, feedback_dir):
        self._feedback_dir = feedback_dir

    def reset(self):
        self._status = constants.StreamStatus.NEW
        self._cpu = 0.0
        self._timestamp = 0
        self._rss = 0
        self._loop_start_time = 0
        self._restarts = 0
        self._start_time = 0
        self._input_streams = str()
        self._output_streams = str()

    def update_runtime_fields(self, params: dict):
        assert self.get_id() == params[StreamFields.ID]
        assert self.get_type() == params[StreamFields.TYPE]
        self._status = constants.StreamStatus(params[StreamFields.STATUS])
        self._cpu = params[StreamFields.CPU]
        self._timestamp = params[StreamFields.TIMESTAMP]
        self._rss = params[StreamFields.RSS]
        self._loop_start_time = params[StreamFields.LOOP_START_TIME]
        self._restarts = params[StreamFields.RESTARTS]
        self._start_time = params[StreamFields.START_TIME]
        self._input_streams = params[StreamFields.INPUT_STREAMS]
        self._output_streams = params[StreamFields.OUTPUT_STREAMS]

    def to_front(self) -> dict:
        return {
            StreamFields.NAME: self.name,
            StreamFields.ID: self.get_id(),
            StreamFields.TYPE: self.get_type(),
            StreamFields.STATUS: self._status,
            StreamFields.CPU: self._cpu,
            StreamFields.TIMESTAMP: self._timestamp,
            StreamFields.RSS: self._rss,
            StreamFields.LOOP_START_TIME: self._loop_start_time,
            StreamFields.RESTARTS: self._restarts,
            StreamFields.START_TIME: self._start_time,
            StreamFields.INPUT_STREAMS: self._input_streams,
            StreamFields.OUTPUT_STREAMS: self._output_streams
        }

    def config(self) -> dict:
        conf = {
            ID_FIELD: self.get_id(),  # required
            TYPE_FIELD: self.get_type(),  # required
            FEEDBACK_DIR_FIELD: self.generate_feedback_dir(),  # required
            LOG_LEVEL_FIELD: self.get_log_level(),
            AUTO_EXIT_TIME_FIELD: self.get_auto_exit_time(),
            LOOP_FIELD: self.get_loop(),
            HAVE_VIDEO_FIELD: self.get_have_video(),  # required
            HAVE_AUDIO_FIELD: self.get_have_audio(),  # required
            RESTART_ATTEMPTS_FIELD: self.get_restart_attempts(),
            INPUT_FIELD:
            self.input.to_mongo(),  # required empty in timeshift_player
            OUTPUT_FIELD:
            self.output.to_mongo()  # required empty in timeshift_record
        }

        audio_select = self.get_audio_select()
        if audio_select != constants.INVALID_AUDIO_SELECT:
            conf[AUDIO_SELECT_FIELD] = audio_select
        return conf

    def generate_feedback_dir(self):
        return '{0}/{1}/{2}'.format(self._feedback_dir, self.get_type(),
                                    self.get_id())

    def get_log_level(self):
        return self.log_level

    def get_audio_select(self):
        return self.audio_select

    def get_have_video(self):
        return self.have_video

    def get_have_audio(self):
        return self.have_audio

    def get_id(self):
        return str(self.id)

    def get_type(self):
        raise NotImplementedError('subclasses must override get_type()!')

    def get_loop(self):
        return self.loop

    def get_restart_attempts(self):
        return self.restart_attempts

    def get_auto_exit_time(self):
        return self.auto_exit_time
Exemple #6
0
def make_timeshift_player_stream(feedback_dir: str) -> TimeshiftPlayerStream:
    stream = TimeshiftPlayerStream()
    stream._feedback_dir = feedback_dir
    stream.input = Urls(urls=[Url(id=Url.generate_id())])
    stream.output = Urls(urls=[Url(id=Url.generate_id())])
    return stream
Exemple #7
0
def make_encode_stream(feedback_dir: str) -> EncodeStream:
    stream = EncodeStream()
    stream._feedback_dir = feedback_dir
    stream.input = Urls(urls=[Url(id=Url.generate_id())])
    stream.output = Urls(urls=[Url(id=Url.generate_id())])
    return stream
Exemple #8
0
def make_relay_stream(feedback_dir: str) -> RelayStream:
    stream = RelayStream()
    stream._feedback_dir = feedback_dir
    stream.input = Urls(urls=[Url(id=Url.generate_id())])
    stream.output = Urls(urls=[Url(id=Url.generate_id())])
    return stream