My first experience with Qt - SynchronizedPlayer

My first experience with Qt - SynchronizedPlayer

I took a “Multimedia Technology” course at university which included the creation of a multimedia project. I previously had an idea during the COVID-19 quarantine to create a platform that allows multiple people to watch videos remotely synchronized, so I pitched the idea to the professor and he accepted my subject.

The first approach, as of the instructions of the course, was to use GStreamer and C++. I like C++ so I took that opportunity. I started researching GStreamer and its synchronization opportunities. I also started researching for a GUI library that supports GStreamer. I wanted the application to be cross-platform so I quickly found myself researching Qt. I’ve known Qt as a GUI toolkit mainly from the Linux world, but while reading through the documentation I realized it was much more than that! It can handle almost everything, including multimedia and networking which was perfect for me, so I ditched GStreamer and decided to write everything in Qt.

One of the core concepts of Qt that I quickly became friendly with is Signals and Slots, basically a way for objects (and especially GUI elements) to communicate without callbacks. Any object that inherits from QObject can have signals and slots. Slots are normal member functions that can be connected to a Signal. When that Signal is emitted the connected Slot is called. Signals can pass any number of arguments to Slots they are connected to (as long as their signatures match). This mechanism proved itself very useful when working with different elements of the GUI like dialog windows.

As of networking, I used Qt’s implementation of TCP sockets for the chat feature and the synchronization messages and the implementation of UDP sockets for the transfer of audio data. I used a TCP connected client list to know which UDP sockets are connecting/disconnecting and/or still listening.

The main player was based on QMediaPlayer. It had everything I needed like the signals positionChanged and bufferProgressChanged, so I connected those signals to slots that sent messages through TCP to the server with the current position of the playback and the server forwarded those messages to all the other connected clients. I left a 200ms window of acceptable delay between clients to accommodate for network ping issues.

The final GUI looked like this:

Screenshot

There’s still work to be done but, for the time being, I’m pleased with my first experience with Qt.

SynchronizedPlayer Github Repository

Vasilis Vlasopoulos

Vasilis Vlasopoulos

dev/sec/sre

comments powered by Disqus