From ef5281488b41485c01bbd588070bd81c376e9f14 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 4 Dec 2015 13:51:13 +0100 Subject: [PATCH] gst1: Fix buffer.pts not being set if 0 --- mopidy/audio/utils.py | 4 ++-- tests/audio/test_utils.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mopidy/audio/utils.py b/mopidy/audio/utils.py index cc312b73..0f7f1957 100644 --- a/mopidy/audio/utils.py +++ b/mopidy/audio/utils.py @@ -29,9 +29,9 @@ def create_buffer(data, capabilites=None, timestamp=None, duration=None): ``capabilites`` argument is no longer in use """ buffer_ = Gst.Buffer.new_wrapped(data) - if timestamp: + if timestamp is not None: buffer_.pts = timestamp - if duration: + if duration is not None: buffer_.duration = duration return buffer_ diff --git a/tests/audio/test_utils.py b/tests/audio/test_utils.py index 0b497dad..d3e81ef2 100644 --- a/tests/audio/test_utils.py +++ b/tests/audio/test_utils.py @@ -3,10 +3,27 @@ from __future__ import absolute_import, unicode_literals import datetime import unittest +import gi +gi.require_version('Gst', '1.0') +from gi.repository import Gst + +import pytest + from mopidy.audio import utils from mopidy.models import Album, Artist, Track +class TestCreateBuffer(object): + + def test_creates_buffer(self): + buf = utils.create_buffer(b'123', timestamp=0, duration=1000000) + + assert isinstance(buf, Gst.Buffer) + assert buf.pts == 0 + assert buf.duration == 1000000 + assert buf.get_size() == len(b'123') + + # TODO: keep ids without name? # TODO: current test is trying to test everything at once with a complete tags # set, instead we might want to try with a minimal one making testing easier.