Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the omx encode cache small in PGUX #297

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion libcam/libcam/camview.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ static int my_encoder_status = 0;

static int is_wayland = 0; //是否是wayland的窗口管理器

static int is_pgux = 0; //是否是pugx

static uint8_t soundTakePhoto = 1;//拍照声音提示

static char status_message[80];
Expand Down Expand Up @@ -794,7 +796,8 @@ static void *encoder_loop(__attribute__((unused))void *data)
v4l2core_get_fps_num(my_vd),
v4l2core_get_fps_denom(my_vd),
channels,
samprate);
samprate,
get_pugx_status());

/*store external SPS and PPS data if needed*/
if(encoder_ctx->video_codec_ind == 0 && /*raw - direct input*/
Expand Down Expand Up @@ -1355,3 +1358,13 @@ int get_sound_of_takeing_photo()
{
return soundTakePhoto;
}

void set_pugx_status(int status)
{
is_pgux = status;
}

int get_pugx_status()
{
return is_pgux;
}
3 changes: 3 additions & 0 deletions libcam/libcam/camview.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ void set_takeing_photo_sound(uint8_t status);

int get_sound_of_takeing_photo(void);

void set_pugx_status(int status);

int get_pugx_status();

#ifdef __cplusplus
}
Expand Down
13 changes: 9 additions & 4 deletions libcam/libcam_encoder/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@
*
* returns: pointer to encoder video context (NULL on none)
*/
static encoder_video_context_t *encoder_video_init(encoder_context_t *encoder_ctx)
static encoder_video_context_t *encoder_video_init(encoder_context_t *encoder_ctx, int pgux)

Check warning on line 431 in libcam/libcam_encoder/encoder.c

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'encoder_ctx' can be declared with const
{
//assertions
assert(encoder_ctx != NULL);
Expand Down Expand Up @@ -581,7 +581,11 @@


if (video_defaults->gop_size > 0) {
video_codec_data->codec_context->gop_size = video_defaults->gop_size;
if (pgux == 1) {
video_codec_data->codec_context->gop_size = 3;
} else {
video_codec_data->codec_context->gop_size = video_defaults->gop_size;
}
} else {
video_codec_data->codec_context->gop_size = video_codec_data->codec_context->time_base.den;
}
Expand Down Expand Up @@ -1134,7 +1138,8 @@
int fps_num,
int fps_den,
int audio_channels,
int audio_samprate)
int audio_samprate,
int use_pugx_code)
{
encoder_context_t *encoder_ctx = calloc(1, sizeof(encoder_context_t));

Expand Down Expand Up @@ -1162,7 +1167,7 @@
/******************* video **********************/
encoder_video_init_vaapi(encoder_ctx);
if (HW_VAAPI_OK != is_vaapi) {
encoder_video_init(encoder_ctx);
encoder_video_init(encoder_ctx, use_pugx_code);
//hw_vaapi ng
}

Expand Down
3 changes: 2 additions & 1 deletion libcam/libcam_encoder/gviewencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ encoder_context_t *encoder_init(
int fps_num,
int fps_den,
int audio_channels,
int audio_samprate);
int audio_samprate,
int use_pugx_code);

/*
* initialization of the file muxer
Expand Down
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,13 @@ set(APPSHAREDIR ${CMAKE_INSTALL_DATADIR}/${TARGET_NAME})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/translations
DESTINATION ${APPSHAREDIR}
FILES_MATCHING PATTERN "*.qm")

#hw机型增加DConfig配置
set(APPID org.deepin.camera)
set(configFile ${PROJECT_SOURCE_DIR}/assets/org.deepin.camera.encode.json)
if (DEFINED DSG_DATA_DIR)
message("-- DConfig is supported by DTK")
dconfig_meta_files(APPID ${APPID} FILES ${configFile})
else()
install(FILES ${configFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/dsg/configs/org.deepin.camera/)
endif()
16 changes: 16 additions & 0 deletions src/assets/org.deepin.camera.encode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"mp4EncodeMode": {
"value": 0,
"serial": 0,
"flags": ["global"],
"name": "pugx mp4 code mode",
"name[zh_CN]": "特殊编码模式",
"description": "pugx mp4 code mode",
"permissions": "readwrite",
"visibility": "private"
}
}
}
61 changes: 49 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

extern "C"
{
extern "C" {
#include "camview.h"
}
#include "mainwindow.h"
Expand All @@ -13,8 +12,11 @@
#include "acobjectlist.h"
#include "dbus_adpator.h"

extern "C"
{
#ifdef DTKCORE_CLASS_DConfigFile
#include <DConfig>
#endif

extern "C" {
#include <libimagevisualresult/visualresult.h>
}

Expand All @@ -38,7 +40,6 @@

DWIDGET_USE_NAMESPACE


//判断是否采用wayland显示服务器
static bool CheckWayland()
{
Expand All @@ -55,11 +56,11 @@
static bool CheckFFmpegEnv()
{
QDir dir;
QString path = QLibraryInfo::location(QLibraryInfo::LibrariesPath);
QString path = QLibraryInfo::location(QLibraryInfo::LibrariesPath);
dir.setPath(path);
QStringList list = dir.entryList(QStringList() << (QString("libavcodec") + "*"), QDir::NoDotAndDotDot | QDir::Files);
QString libName = nullptr;
QRegExp re("libavcodec.so.*"); //Sometimes libavcodec.so may not exist, so find it through regular expression.
QRegExp re("libavcodec.so.*"); //Sometimes libavcodec.so may not exist, so find it through regular expression.
for (int i = 0; i < list.count(); i++) {
if (re.exactMatch(list[i])) {
libName = list[i];
Expand All @@ -68,9 +69,9 @@
}

if (libName != nullptr) {
QLibrary libavcodec; //检查编码器是否存在
QLibrary libavcodec; //检查编码器是否存在
libavcodec.setFileName(libName);
qDebug() << "Whether the libavcodec is loaded successfully: "<< libavcodec.load();
qDebug() << "Whether the libavcodec is loaded successfully: " << libavcodec.load();
typedef AVCodec *(*p_avcodec_find_encoder)(enum AVCodecID id);
p_avcodec_find_encoder m_avcodec_find_encoder = nullptr;
m_avcodec_find_encoder = reinterpret_cast<p_avcodec_find_encoder>(libavcodec.resolve("avcodec_find_encoder"));
Expand Down Expand Up @@ -113,14 +114,50 @@
setenv("XDG_CURRENT_DESKTOP", "Deepin", 1);
}

if (bWayland) {
if (bWayland) {
//默认走xdgv6,该库没有维护了,因此需要添加该代码
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "kwayland-shell");
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGLES);
format.setDefaultFormat(format);
set_wayland_status(1);
}

int mp4Encode = -1;

Check warning on line 125 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
#ifdef DTKCORE_CLASS_DConfigFile
//需要查询是否对PGUX设置MP4编码缓存特殊处理
DConfig *dconfig = DConfig::create("org.deepin.camera", "org.deepin.camera.encode");
if (dconfig && dconfig->isValid() && dconfig->keyList().contains("mp4EncodeMode")) {
mp4Encode = dconfig->value("mp4EncodeMode").toInt();
set_pugx_status(mp4Encode);
}
#endif
qInfo() << "mp4EncodeMode value is:" << get_pugx_status();
if (mp4Encode == -1) {
//判断是否是pgux
QStringList options;
options << QString(QStringLiteral("-c"));
options << QString(QStringLiteral("dmidecode -s system-product-name|awk '{print $NF}'"));
QProcess process;
process.start(QString(QStringLiteral("bash")), options);
process.waitForFinished();
process.waitForReadyRead();
QByteArray tempArray = process.readAllStandardOutput();
char *charTemp = tempArray.data();
QString str_output = QString(QLatin1String(charTemp));
process.close();

if (str_output.contains("PGUX", Qt::CaseInsensitive)) {
mp4Encode = 1;
qDebug() << "this is PGUX";
} else {
mp4Encode = 0;
}
qInfo() << "process find mp4EncodeMode value is:" << get_pugx_status();
}

set_pugx_status(mp4Encode);
qInfo() << "last mp4EncodeMode value is:" << get_pugx_status();
}

QTime time;
time.start();
Expand All @@ -129,7 +166,7 @@
qDebug() << QString("initFilters cost %1 ms").arg(time.elapsed());

CApplication a(argc, argv);
// gst_init(&argc, &argv);
//gst_init(&argc, &argv);

qApp->setObjectName("deepin-camera");
#ifndef __mips__
Expand Down
Loading