Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement QtMultimedia Multimedia Module in Qt6

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to implement QtMultimedia multimedia module in Qt6. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

I. Preface

The first beta of Qt 6.2 has just been released and a new Qt multimedia module has been added to a number of other new add-ons. Qt Multimedia is a module that has undergone some considerable changes in Qt 6.

In many ways, it is a new API and implementation, even though we re-use some of the code in Qt 5.15. Although we tried to maintain as much source code compatibility as possible between Qt 5 and Qt 6 for most of our modules, we had to make a lot of changes here to make API and implementation suitable for the future, and ultimately decided to target API for the best rather than maximum compatibility.

If you have been using Qt Multimedia in Qt 5, you need to make changes to your implementation. Will try to guide you through the biggest changes, while looking at the API and internal structure.

II. Objectives

Qt multimedia in Qt 5 has a fairly loosely defined scope. Different backends have different support for different parts of API, and parts of API itself are not easy to use across platforms.

For Qt 6, we try to narrow it down to some extent and focus on developing a consistent set of features that apply to all supported platforms. We haven't achieved this goal yet, but we hope to fill most of the implementation gaps with the release of Qt 6.2.0.

As far as we know, these features cover most of the use cases in which our users used Qt multimedia in the past. Our goal is to focus on those core use cases first and make sure they work consistently on all our platforms before using the new functional extension module.

The main use cases that we want to support in Qt 6.2 are:

Audio and video playback

Audio and video recording (from cameras and microphones)

Low-level (PCM-based) audio and audio decoding

Integration with Qt Quick and widgets

Use hardware acceleration as much as possible

III. Internal structural changes

Qt multimedia in Qt 5 has a complex plug-in-based architecture, using multiple plug-ins to implement different front-end functions. A complete multimedia back-end implementation will contain no less than 4 plug-ins. The backend API used to implement these plug-ins is public, and it is difficult to adjust and improve the functionality of these backends.

The built architecture is very difficult to maintain and develop modules. In Qt6 we chose to significantly simplify this process and remove the plug-in infrastructure. Now select the backend at compile time and compile it into a shared library in Qt Multimedia. Now there is only one back-end API that covers all the multimedia, eliminating the problem of artificially splitting multiple backends in Qt 5. Finally, we chose to make the back-end API private so that we could easily adjust and extend it in the future.

When this is done, we can take a closer look at the API and interfaces required by the platform-related back-end code. We have managed to reduce the number of class sets required to implement the multimedia backend from 40 to 15, and reduce the number of pure virtual methods, providing backup implementations for many unnecessary functions.

The new back-end API somewhat mimics the QPA architecture we used for window system integration in Qt Gui, and the new QPlatformMediaIntegration class now does serve as a general entry point and factory class to instantiate platform-related back-end objects. In most cases, our goal now is to establish an one-to-one relationship between the class in the public API and the class that implements the function. Therefore, the public QMediaPlayer API has a QPlatformMediaPlayer class that implements platform-related functionality.

With these changes, we can also remove a lot of code that duplicates between the front end and the back end, and avoid a large number of call transfers between them. With this, we can also move many cross-platform features and validation to shared, platform-independent parts of the code.

All in all, this greatly simplifies our code base and greatly reduces the code size without losing a lot of functionality. Qt Multimedia in 5.15 has about 140.000 lines of code, while we are currently reduced to about 74.000 lines of code in Qt 6.

IV. Supported backend

In Qt 6, we also re-examined the backend of support and reduced it to a set that we thought we could support in the future. For example, in Qt 5, we have three completely different back-end implementations on Windows, using DirectShow, WMF, and a separate WMF-based WinRT implementation.

Qt 6.3 plans to support QNX. We may also use low-level audio on WebAssembly in time in 6. 2. In addition, we still have code to support low-level audio on Linux using PulseAudio or ALSA, but we haven't tested or supported this code yet. Depending on the requirements, we may bring them back in a future version.

In Qt 6, the currently supported collections are:

Linux, using GStreamer

MacOS and iOS using AVFoundation

Windows using WMF

Android using MediaPlayer and Camera Java API

5. Public API interface

The public API of Qt Multimedia consists of five large functional blocks. Three of these blocks already exist in Qt 5, but the API in these blocks has changed significantly. The function blocks are:

Device discovery

Low-level audio

Play and decode

Capture and record

Video output pipeline

When doing the new API, we also hope to have a unified API between C++ and QML. This allows us to remove a large amount of code that simply wraps C++ API and exposes it to QML in a slightly different way. For most public C++ classes, there is now a corresponding QML entry with the same name. So QMediaPlayer and, for example, a project with the same API as a C + + class with the corresponding QML MediaPlayer.

(1) equipment discovery

Let's start with device discovery. The new QMediaDevices class is designed to provide you with information about available audio and video devices. It will allow you to list available audio inputs (usually microphones), audio outputs (speakers and headphones), and cameras. You can retrieve the default device, and the class notifies you of any changes to the configuration, for example, when the user connects to an external headset.

QMediaDevices devices;connect (& devices, & QMediaDevices::audioInputsChanged, [] () {qDebug ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report