Article Directory
Recommend a free public course of Zero Voice Academy. I personally think the teacher taught it well, so I would like to share it with you: Linux, Nginx, ZeroMQ, MySQL, Redis, fastdfs, MongoDB, ZK, streaming media, CDN, P2P, K8S, Docker, TCP/IP , Coroutine, DPDK and other technical content, learn immediately
Recently, I am working on Qt Android-related applications. Let me record and build an Android development environment.
This chapter mainly implements the Qt Android development environment.
Build the development environment
The Android development environment is built, and it is currently built under the windows and linux environments. The following describes the construction of the two environments. The Qt version I use is Qt5.15.2, which needs to be downloaded online.
Download address https://download.qt.io/official_releases/online_installers/Here
, I downloaded qt-unified-windows-x86-online.exe and qt-unified-linux-x64-online.run
Windows development environment construction
Install and build an android development environment under windows
Qt online installation
First, you need to download the online installation tool, qt-unified-windows-x86-online.exe downloaded above, double-click to open the software
Here you need to register an account on the Qt official website. Login account
The following steps follow the default until the following interface appears, be sure to select android
and then continue until the installation is complete.
Qt Android development environment construction
After the above Android is completed, open the Qt development environment, through Tools->Options->Device->android. As shown below
You need to install jdk. I have already installed it here. I won’t introduce too much here. You can configure it on Baidu and jdk by yourself.
Next, install the Android SDK and NDK
SDK. You need to click the browse button first, choose where you want to install your SDK, and then click Set Up SDK, just follow the default.
android_openssl, select the installation folder and click the Download OpenSSL button to download it. It may not be downloaded due to network reasons. You can download it at the Baidu network disk address below.
> The following
is the interface development environment after the installation and configuration is completed
Download from Baidu Cloud:
Link: https://pan.baidu.com/s/1l2Z7IZOOxJ44ekv2jw_LyQ
Extraction code:
You can download it directly from rf2s, unzip it, and set the relevant directory. up.
Linux development environment construction
In the linux development environment, I choose the centos7.6 version, which is convenient for transplanting linux-related projects.
First, double-click the downloaded qt-unified-linux-x64-online.run to open it.
The front is the same as the installation
. Here, after the installation, it is found that Qt Creator cannot be opened, and it is found that there is a problem with the environment. The solution here is to install another QtCreater. After several tests, it was found that the version of QtCreater qt-creator-opensource-linux-x86_64-4.13.3.run is OK, because it needs to download the Android development environment, other versions may not be downloaded.
Download address: https://download.qt.io/archive/qtcreator/4.13/4.13.3/qt-creator-opensource-linux-x86_64-4.13.3.run
Here, the installation configuration is consistent with windows
development test
For the development environment, choose Android Qt 5.15.2 Clang Multi-Abi.
simple test
Develop and introduce third-party libraries
Here, use the vlc development environment to
first download the vlc Android development library: https://mirrors.aliyun.com/videolan/vlc-android/3.4.3/
Change the downloaded apk to zip, unzip it, and
get the libvlc.so file. You can use vlc normally.
Test the vlc part of the code
#include "widget.h"
#include <QApplication>
#include <vlc/vlc.h>
#include <QDebug>
#include <QMutex>
#include "main.h"
struct Context {
QMutex mutex;
uchar *pixels;
};
CIns* CIns::m_ins = nullptr;
static void *lock(void *opaque, void **planes)
{
struct Context *ctx = (struct Context *)opaque;
ctx->mutex.lock();
// 告诉 VLC 将解码的数据放到缓冲区中
*planes = ctx->pixels;
return nullptr;
}
// 获取 argb 图片并保存到文件中
static void unlock(void *opaque, void *picture, void *const *planes)
{
Q_UNUSED(picture);
struct Context *ctx = (struct Context *)opaque;
unsigned char *data = static_cast<unsigned char *>(*planes);
static int frameCount = 1;
QImage image(data, 512, 288, QImage::Format_ARGB32);
// image.save(QString("frame_%1.png").arg(frameCount++));
emit CIns::Ins()->SigImage(image);
ctx->mutex.unlock();
}
static void display(void *opaque, void *picture)
{
Q_UNUSED(picture);
(void)opaque;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
QObject::connect(CIns::Ins(), &CIns::SigImage, &w, &Widget::SlotImage);
const char* const vlc_args[] = {
"--demux=h264",
"--ipv4",
"--no-prefer-system-codecs",
"--rtsp-caching=300",
"--network-caching=500", //网络额外缓存值 (ms)
"--rtsp-frame-buffer-size=10000000",
"--rtsp-tcp", //RTSP采用TCP传输方式
};
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
struct Context ctx;
ctx.pixels = new uchar[512 * 288 * 4];
memset(ctx.pixels, 0, 512 * 288 * 4);
//libvlc_time_t length;
/* Load the VLC engine */
inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
QString strUrl = "rtsp://wowzaec2demo.streamlock.net/vod/mp4";
m = libvlc_media_new_location (inst, strUrl.toStdString().c_str());
mp = libvlc_media_player_new_from_media (m);
// libvlc_media_player_set_hwnd(mp, (void *)wgt.winId());
// 设置回调,用于提取帧或者在界面上显示。
libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
libvlc_video_set_format(mp, "RGBA", 512, 288, 512 * 4);
libvlc_media_release (m);
libvlc_media_player_play (mp);
int ret = a.exec();
libvlc_media_player_stop (mp);
// Free the media_player
libvlc_media_player_release (mp);
libvlc_release (inst);
return ret;
Test vlc playback
Complete code address:
Link: https://pan.baidu.com/s/1m9X3zvPqNEaTPlGhnWR1VQ
Extraction code: gok4
reference documents
Configure the Android development environment of Qt5.12.3
Qt5.14.2 Add third-party libraries (.a, .so) to the Android project
android development cmake compile the common way of introducing third-party libraries