tst_playbin.qml 5.46 KB
Newer Older
Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.0
import QtMultimedia 5.0
import QtGstreamerExtras 5.12
import QtTest 1.0

Item {
    id: top

Val Doroshchuk's avatar
Val Doroshchuk committed
37 38
    property string srcMp4: "../../qgstreamerplaybin/testdata/colors.mp4"
    property string srcText: "../../qgstreamerplaybin/testdata/text.srt"
Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
39 40 41 42 43 44 45 46 47 48 49 50 51

    VideoOutput {
        id: video
        source: player
    }

    MediaPlayer {
        id: player
        autoPlay: true
        loops: Audio.Infinite
        source: srcMp4
    }

Val Doroshchuk's avatar
Val Doroshchuk committed
52
    Playbin {
Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
53 54 55
        id: control
        source: player
        textUri: srcText
56 57 58 59 60 61 62
        videoSink: "xvimagesink pixel-aspect-ratio=\"1/2\""
    }

    SignalSpy {
        id: spyVideoSink
        target: control
        signalName: "videoSinkChanged"
Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    }

    SignalSpy {
        id: spyShowText
        target: control
        signalName: "showTextChanged"
    }

    SignalSpy {
        id: spyTextUri
        target: control
        signalName: "textUriChanged"
    }

    SignalSpy {
        id: spyTextFont
        target: control
        signalName: "textFontChanged"
    }

    SignalSpy {
        id: spyAudioStreamsCount
        target: control
        signalName: "audioStreamsCountChanged"
    }

    SignalSpy {
        id: spyVideoStreamsCount
        target: control
        signalName: "videoStreamsCountChanged"
    }

    SignalSpy {
        id: spyTextStreamsCount
        target: control
        signalName: "textStreamsCountChanged"
    }

    SignalSpy {
        id: spyTextStream
        target: control
        signalName: "onTextStreamChanged"
    }

    SignalSpy {
        id: spyTextStreamProperties
        target: control
        signalName: "onTextStreamPropertiesChanged"
    }

    function basename(str) {
        return (str.slice(str.lastIndexOf("/") + 1))
    }

    TestCase {
        name: "GstreamerPlayerControl"

        function initTestCase() {
            compare(control.source, player)
        }

124 125 126 127 128
        function test_videoSink() {
            compare(spyVideoSink.count, 1);
            compare(control.videoSink, "xvimagesink pixel-aspect-ratio=\"1/2\"")
        }

Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
        function test_showText() {
            spyShowText.clear()
            verify(control.showText)
            control.showText = true
            compare(spyShowText.count, 0);
            verify(control.showText)
            control.showText = false
            compare(spyShowText.count, 1);
            verify(!control.showText)
        }

        function test_textUri() {
            spyTextUri.clear();
            control.showText = false
            control.textUri = "dummy"
            verify(control.showText)
            compare(spyTextUri.count, 1)
            control.textUri = srcText
            compare(spyTextUri.count, 2)
            compare(basename(control.textUri.toString()), basename(srcText.toString()))
        }

        function test_textFont() {
            compare(spyTextFont.count, 0)
            compare(control.textFont, "")
            control.textFont = "Sans, 18"
            compare(spyTextFont.count, 1)
            compare(control.textFont, "Sans, 18")
        }

        function test_audioStreams() {
            tryCompare(control, "audioStreamsCount", 1, 3000)
            verify(spyAudioStreamsCount.count > 0)
        }

        function test_videoStreams() {
            tryCompare(control, "videoStreamsCount", 1, 3000)
            verify(spyVideoStreamsCount.count > 0)
        }

        function test_textStreams() {
            tryCompare(control, "textStreamsCount", 3, 3000)
            verify(spyTextStreamsCount.count > 0)
        }

        function test_setTextStream() {
            spyTextStream.clear()
Val Doroshchuk's avatar
test  
Val Doroshchuk committed
176
            control.textStream = 0
Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
177
            compare(control.textStream, 0)
Val Doroshchuk's avatar
test  
Val Doroshchuk committed
178
            compare(spyTextStream.count, 1)
Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
179 180
            control.textStream = 1
            compare(control.textStream, 1)
Val Doroshchuk's avatar
test  
Val Doroshchuk committed
181
            compare(spyTextStream.count, 2)
Val Doroshchuk's avatar
Init  
Val Doroshchuk committed
182 183 184 185 186 187 188 189 190 191 192 193
        }

        function test_textStreamProperties() {
            tryVerify(function(){
                return control.textStreamsCount > 1 && control.textStreamProperties(1)["Language"] == "en";
            }, 3000)
            compare(control.textStreamProperties(0)["Language"], undefined)
            compare(control.textStreamProperties(2)["Language"], "no")
            verify(spyTextStreamProperties.count > 0)
        }
    }
}