<commit_before># -*- Mode: Python; test-case-name: flumotion.muxers.mpegts.mpegts -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2009,2010 Fluendo, S.L. (www.fluendo.com).
# All rights reserved.
# flumotion-fragmented-streaming - Flumotion Advanced fragmented streaming

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

import sys

import gst
from twisted.internet import reactor

from flumotion.component import feedcomponent
from flumotion.component.component import moods
from flumotion.common import gstreamer, messages, documentation
from flumotion.common.i18n import N_, gettexter
from flumotion.component.consumers.applestreamer import mpegtssegmenter

T_ = gettexter()


class MPEGTS(feedcomponent.MuxerComponent):
    checkTimestamp = True

    """
    The mpegts-muxer component muxes a video and an audio stream into an
    MPEG-TS stream and copies the keyframes' OFFSET_END, increased by one for
    each keyframe, to the outgoing mpegts buffers for synchronisation purpose.

    At the muxer level,the synchronisation is done increasing the buffer offset
    for each keyframe and writting it to the outgoing MPEG-TS packet marked as
    keyframes. If the video encoder uses the OFFSET_END as a counter for
    keyframes, we use this value, otherwhise we use an internal counter
    increased on each video keyframe.

    If the muxed stream contains video,mpegtsmux will unset the delta unit flag
    for the output MPEG-TS buffers containing a video keyframe and we only need
    to rewrite the offset of these buffers.

    If the muxed stream only contains audio, we need to mark all the audio
    buffers as delta unit and unset this flag for the first audio buffer after
    the video keyframe. NB: this will only works if mpegtsmux also takes in
    count audio stream for detecting non delta unit"""

    def do_check(self):
        exists = gstreamer.element_factory_exists('mpegtsmux')
        if not exists:
            m = messages.Error(T_(N_(
                        "%s is missing. Make sure your %s "
                        "installation is complete."),
                        'mpegtsmux', 'mpegtsmux'))
            documentation.messageAddGStreamerInstall(m)
            self.debug(m)
            self.addMessage(m)
            return

        v = gstreamer.get_plugin_version('mpegtsmux')
        # The mpegtsmuxer does not use the delta unit flag to mark keyframes
        # until gst-plugin-bad-0.10.18. Patched versions in the platform
        # will be numberer using minor=10 to check if the plugin has been
        # patched
        if v <= (0, 10, 17, 0) and v[3] != 11:
            m = messages.Warning(
                T_(N_("Versions up to and including %s of the '%s' "
                      "GStreamer plug-in are not suitable for "
                      "fragmented streaming.\n"),
                      '0.10.17', 'mpegtsmux'))
            self.addMessage(m)

    def get_muxer_string(self, properties):
        muxer = 'mpegtsmux name=muxer pat-interval=%d pmt-interval=%d '\
            '! flumpegtssegmenter keyframes-per-segment=1'\
            % (sys.maxint, sys.maxint)
        return muxer

    def do_pipeline_playing(self):
        # The component must stay 'waiking' until it receives at least<commit_msg>mpegts.py: warn if mpegtsmux is missing<commit_after># -*- Mode: Python; test-case-name: flumotion.muxers.mpegts.mpegts -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2009,2010 <NAME>. (www.fluendo.com).
# All rights reserved.
# flumotion-fragmented-streaming - Flumotion Advanced fragmented streaming

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

import sys

import gst
from twisted.internet import reactor

from flumotion.component import feedcomponent
from flumotion.component.component import moods
from flumotion.common import gstreamer, messages, documentation
from flumotion.common.i18n import N_, gettexter
from flumotion.component.consumers.applestreamer import mpegtssegmenter

T_ = gettexter()


class MPEGTS(feedcomponent.MuxerComponent):
    checkTimestamp = True

    """
    The mpegts-muxer component muxes a video and an audio stream into an
    MPEG-TS stream and copies the keyframes' OFFSET_END, increased by one for
    each keyframe, to the outgoing mpegts buffers for synchronisation purpose.

    At the muxer level,the synchronisation is done increasing the buffer offset
    for each keyframe and writting it to the outgoing MPEG-TS packet marked as
    keyframes. If the video encoder uses the OFFSET_END as a counter for
    keyframes, we use this value, otherwhise we use an internal counter
    increased on each video keyframe.

    If the muxed stream contains video,mpegtsmux will unset the delta unit flag
    for the output MPEG-TS buffers containing a video keyframe and we only need
    to rewrite the offset of these buffers.

    If the muxed stream only contains audio, we need to mark all the audio
    buffers as delta unit and unset this flag for the first audio buffer after
    the video keyframe. NB: this will only works if mpegtsmux also takes in
    count audio stream for detecting non delta unit"""

    def do_check(self):
        exists = gstreamer.element_factory_exists('mpegtsmux')
        if not exists:
            m = messages.Error(T_(N_(
                        "%s is missing. Make sure your %s "
                        "installation is complete."),
                        'mpegtsmux', 'mpegtsmux'))
            documentation.messageAddGStreamerInstall(m)
            self.debug(m)
            self.addMessage(m)
            return

        v = gstreamer.get_plugin_version('mpegtsmux')
        # The mpegtsmuxer does not use the delta unit flag to mark keyframes
        # until gst-plugin-bad-0.10.18. Patched versions in the platform
        # will be numberer using minor=10 to check if the plugin has been
        # patched
        if v is None:
            m = messages.Warning(T_(N_("GStreamer mpegtsmux not found")))
            self.addMessage(m)
        elif v <= (0, 10, 17, 0) and v[3] != 11:
            m = messages.Warning(
                T_(N_("Versions up to and including %s of the '%s' "
                      "GStreamer plug-in are not suitable for "
                      "fragmented streaming.\n"),
                      '0.10.17', 'mpegtsmux'))
            self.addMessage(m)

    def get_muxer_string(self, properties):
        muxer = 'mpegtsmux name=muxer pat-interval=%d pmt-interval=%d '\
            '! flumpegtssegmenter keyframes-per-segment=1'\
            % (sys.maxint, sys.maxint)
        return muxer

    def do_pipeline_playing(self):
        # The component must stay 'waiking' until it receives at least
{'fraction_non_alphanumeric': 0.0678801149582592, 'fraction_numerical': 0.00957985493362529, 'mean_word_length': 2.7865284974093263, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4728979', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2017, 'n_words': 787}