xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #1370: audio-use-timestamp-plugin.patch

File audio-use-timestamp-plugin.patch, 3.2 KB (added by Antoine Martin, 4 years ago)

use the timestamp plugin to get a real monotonic absolute timestamp we can also use for video frames

  • xpra/sound/src.py

     
    1111from xpra.util import csv, envint, envbool, AtomicInteger
    1212from xpra.sound.sound_pipeline import SoundPipeline
    1313from xpra.gtk_common.gobject_util import n_arg_signal, gobject
    14 from xpra.sound.gstreamer_util import get_source_plugins, plugin_str, get_encoder_elements, get_encoder_default_options, normv, get_encoders, get_queue_time, \
     14from xpra.sound.gstreamer_util import get_source_plugins, plugin_str, get_encoder_elements, get_encoder_default_options, normv, get_encoders, get_queue_time, has_plugins, \
    1515                                MP3, CODEC_ORDER, MUXER_DEFAULT_OPTIONS, ENCODER_NEEDS_AUDIOCONVERT, SOURCE_NEEDS_AUDIOCONVERT, MS_TO_NS, GST_QUEUE_LEAK_DOWNSTREAM
    1616from xpra.net.compression import compressed_wrapper
    1717from xpra.scripts.config import InitExit
     
    7575        self.sink = None
    7676        self.src = None
    7777        self.src_type = src_type
     78        self.timestamp = None
    7879        self.pending_metadata = []
    7980        self.buffer_latency = True
    8081        self.jitter_queue = None
     
    8485        source_str = plugin_str(src_type, src_options)
    8586        #FIXME: this is ugly and relies on the fact that we don't pass any codec options to work!
    8687        pipeline_els = [source_str]
     88        log.info("has plugin(timestamp)=%s", has_plugins("timestamp"))
     89        if has_plugins("timestamp"):
     90            pipeline_els.append("timestamp name=timestamp")
    8791        if SOURCE_QUEUE_TIME>0:
    8892            queue_el = ["queue",
    8993                        "name=queue",
     
    105109        pipeline_els.append(APPSINK)
    106110        if not self.setup_pipeline_and_bus(pipeline_els):
    107111            return
     112        self.timestamp = self.pipeline.get_by_name("timestamp")
    108113        self.volume = self.pipeline.get_by_name("volume")
    109114        self.sink = self.pipeline.get_by_name("sink")
    110115        if SOURCE_QUEUE_TIME>0:
     
    198203        data = buf.extract_dup(0, size)
    199204        pts = normv(buf.pts)
    200205        duration = normv(buf.duration)
     206        metadata = {
     207            "timestamp"  : pts,
     208            "duration"   : duration,
     209            }
     210        if self.timestamp:
     211            delta = self.timestamp.get_property("delta")
     212            ts = pts+delta
     213            now = monotonic_time()
     214            latency = int(1000000000*now)-ts
     215            #log.info("emit_buffer: delta=%i, pts=%i, ts=%s, time=%s, latency=%ims", delta, pts, ts, now, (latency//1000000))
     216            metadata.update({
     217                "ts"        : ts,
     218                "latency"   : latency,
     219                })
    201220        if pts==-1 and duration==-1 and BUNDLE_METADATA and len(self.pending_metadata)<10:
    202221            self.pending_metadata.append(data)
    203222            return 0
    204         return self._emit_buffer(data, {
    205                                        "timestamp"  : pts,
    206                                        "duration"   : duration,
    207                                        })
     223        return self._emit_buffer(data, metadata)
    208224
    209225    def _emit_buffer(self, data, metadata={}):
    210226        if self.stream_compressor and data: