From dde325b056f147f0421b58971d9580ec4a915e4b Mon Sep 17 00:00:00 2001 From: lxowalle Date: Sat, 17 Jan 2026 12:13:33 +0800 Subject: [PATCH] * set app_camera default resolution to 1080p , fix app_photo play audio coredump --- .../vision/port/maixcam2/maix_video_maixcam2.cpp | 4 ++-- projects/app_camera/main/app/app.cpp | 11 +++++++++++ projects/app_photos/main/app/app.cpp | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/components/vision/port/maixcam2/maix_video_maixcam2.cpp b/components/vision/port/maixcam2/maix_video_maixcam2.cpp index c67a8df3..b8b7d149 100644 --- a/components/vision/port/maixcam2/maix_video_maixcam2.cpp +++ b/components/vision/port/maixcam2/maix_video_maixcam2.cpp @@ -1161,8 +1161,8 @@ namespace maix::video err::check_null_raise(audio_frame = av_frame_alloc(), "Could not allocate audio frame"); err::check_null_raise(swr_ctx = swr_alloc(), "Could not allocate resampler context"); #if CONFIG_FFMPEG_VERSION_MAJOR == 6 && CONFIG_FFMPEG_VERSION_MINOR == 1 && CONFIG_FFMPEG_VERSION_PATCH == 1 - av_opt_set_chlayout(swr_ctx, "in_channel_layout", &audio_codec_ctx->ch_layout, 0); - av_opt_set_chlayout(swr_ctx, "out_channel_layout", &audio_codec_ctx->ch_layout, 0); + av_opt_set_chlayout(swr_ctx, "in_chlayout", &audio_codec_ctx->ch_layout, 0); + av_opt_set_chlayout(swr_ctx, "out_chlayout", &audio_codec_ctx->ch_layout, 0); resample_channels = audio_codec_ctx->ch_layout.nb_channels; #else av_opt_set_int(swr_ctx, "in_channel_layout", audio_codec_ctx->channel_layout, 0); diff --git a/projects/app_camera/main/app/app.cpp b/projects/app_camera/main/app/app.cpp index 0efb955d..417ad455 100644 --- a/projects/app_camera/main/app/app.cpp +++ b/projects/app_camera/main/app/app.cpp @@ -234,10 +234,21 @@ int app_pre_init(void) { auto sensor_size = camera::get_sensor_size(); __config_camera_resolution_list(&priv.ui_camera_cfg, sensor_size[0], sensor_size[1]); +#if PLATFORM_MAIXCAM2 + auto cam2_w = sensor_size[0]; + auto cam2_h = sensor_size[1]; + cam2_w = max(min(cam2_w, 1920), 0); + cam2_h = max(min(cam2_h, 1080), 0); + auto index = __get_camera_resolution_index(&priv.ui_camera_cfg, cam2_w, cam2_h); + priv.camera_resolution_w = cam2_w; + priv.camera_resolution_h = cam2_h; + priv.resolution_index = index; // 0: 2560x1440; 1: 1920x1080; 2: 1280x720; 3: 640x480 +#else auto index = __get_camera_resolution_index(&priv.ui_camera_cfg, sensor_size[0], sensor_size[1]); priv.camera_resolution_w = sensor_size[0]; priv.camera_resolution_h = sensor_size[1]; priv.resolution_index = index; // 0: 2560x1440; 1: 1920x1080; 2: 1280x720; 3: 640x480 +#endif priv.encoder_bitrate = 3 * 1000 * 1000; priv.camera_fps = 30; priv.audio_en = true; diff --git a/projects/app_photos/main/app/app.cpp b/projects/app_photos/main/app/app.cpp index 8f1ba3eb..e75b8601 100644 --- a/projects/app_photos/main/app/app.cpp +++ b/projects/app_photos/main/app/app.cpp @@ -989,7 +989,7 @@ _retry: int channel = priv.decoder->audio_channels(); audio::Format format = priv.decoder->audio_format(); log::info("audio_sample_rate:%d audio_format:%d audio_channels:%d", sample_rate, channel, format); - priv.audio_player = new audio::Player("", sample_rate, format, channel); + priv.audio_player = new audio::Player("", sample_rate, format, channel, false); err::check_null_raise(priv.audio_player, "Audio player init failed!"); } @@ -1050,7 +1050,7 @@ static void play_video(void) int channel = priv.decoder->audio_channels(); audio::Format format = priv.decoder->audio_format(); log::info("audio_sample_rate:%d audio_format:%d audio_channels:%d", sample_rate, channel, format); - priv.audio_player = new audio::Player("", sample_rate, format, channel); + priv.audio_player = new audio::Player("", sample_rate, format, channel, false); err::check_null_raise(priv.audio_player, "Audio player init failed!"); } } @@ -1127,6 +1127,7 @@ static void play_video(void) } // log::info("playback video use %lld ms, video list size:%d", time::ticks_ms() - t, priv.video_list->size()); + // t = time::ticks_ms(); while (priv.audio_list->size() > 0) { video::Context *audio_ctx = *priv.audio_list->begin(); if (audio_ctx) {