diff --git a/libcam/libcam/camview.c b/libcam/libcam/camview.c index 993cee87..45687bdd 100644 --- a/libcam/libcam/camview.c +++ b/libcam/libcam/camview.c @@ -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]; @@ -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*/ @@ -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; +} diff --git a/libcam/libcam/camview.h b/libcam/libcam/camview.h index 191a6b56..5efd5b6a 100644 --- a/libcam/libcam/camview.h +++ b/libcam/libcam/camview.h @@ -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 } diff --git a/libcam/libcam_encoder/encoder.c b/libcam/libcam_encoder/encoder.c index 6eedd66b..e6ff475e 100644 --- a/libcam/libcam_encoder/encoder.c +++ b/libcam/libcam_encoder/encoder.c @@ -428,7 +428,7 @@ static void encoder_set_raw_video_input( * * 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) { //assertions assert(encoder_ctx != NULL); @@ -581,7 +581,11 @@ static encoder_video_context_t *encoder_video_init(encoder_context_t *encoder_ct 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; } @@ -1134,7 +1138,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) { encoder_context_t *encoder_ctx = calloc(1, sizeof(encoder_context_t)); @@ -1162,7 +1167,7 @@ encoder_context_t *encoder_init( /******************* 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 } diff --git a/libcam/libcam_encoder/gviewencoder.h b/libcam/libcam_encoder/gviewencoder.h index 47038c68..714b33b3 100644 --- a/libcam/libcam_encoder/gviewencoder.h +++ b/libcam/libcam_encoder/gviewencoder.h @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3311075..e3b66cde 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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() diff --git a/src/assets/org.deepin.camera.encode.json b/src/assets/org.deepin.camera.encode.json new file mode 100644 index 00000000..d506051e --- /dev/null +++ b/src/assets/org.deepin.camera.encode.json @@ -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" + } + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3f0941e4..5fc4984f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,8 +3,7 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -extern "C" -{ +extern "C" { #include "camview.h" } #include "mainwindow.h" @@ -13,8 +12,11 @@ extern "C" #include "acobjectlist.h" #include "dbus_adpator.h" -extern "C" -{ +#ifdef DTKCORE_CLASS_DConfigFile +#include +#endif + +extern "C" { #include } @@ -38,7 +40,6 @@ extern "C" DWIDGET_USE_NAMESPACE - //判断是否采用wayland显示服务器 static bool CheckWayland() { @@ -55,11 +56,11 @@ static bool CheckWayland() 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]; @@ -68,9 +69,9 @@ static bool CheckFFmpegEnv() } 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(libavcodec.resolve("avcodec_find_encoder")); @@ -113,14 +114,50 @@ int main(int argc, char *argv[]) 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; +#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(); @@ -129,7 +166,7 @@ int main(int argc, char *argv[]) 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__