From 635255c9a9a8868ab95f17acefb30d43727820c6 Mon Sep 17 00:00:00 2001 From: Ryan <865833921@qq.com> Date: Thu, 9 Oct 2025 19:54:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=BA=90=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/capbilities/Muxer.cpp | 2 ++ entry/src/main/cpp/capbilities/VideoEncoder.cpp | 4 +++- entry/src/main/cpp/sample/recorder/Recorder.cpp | 2 ++ entry/src/main/cpp/sample/recorder/RecorderNative.cpp | 2 ++ entry/src/main/ets/pages/Recorder.ets | 4 ++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/entry/src/main/cpp/capbilities/Muxer.cpp b/entry/src/main/cpp/capbilities/Muxer.cpp index 380228b..a125ef5 100644 --- a/entry/src/main/cpp/capbilities/Muxer.cpp +++ b/entry/src/main/cpp/capbilities/Muxer.cpp @@ -70,6 +70,7 @@ int32_t Muxer::Config(SampleInfo &sampleInfo) { } // [End format_path] +// [Start StartMuxer] int32_t Muxer::Start() { CHECK_AND_RETURN_RET_LOG(muxer_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Muxer is null"); @@ -77,6 +78,7 @@ int32_t Muxer::Start() { CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Start failed, ret: %{public}d", ret); return AVCODEC_SAMPLE_ERR_OK; } +// [End StartMuxer] int32_t Muxer::WriteSample(int32_t trackId, OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr){ std::lock_guard lock(writeMutex_); diff --git a/entry/src/main/cpp/capbilities/VideoEncoder.cpp b/entry/src/main/cpp/capbilities/VideoEncoder.cpp index 6384c06..5d9fc5e 100644 --- a/entry/src/main/cpp/capbilities/VideoEncoder.cpp +++ b/entry/src/main/cpp/capbilities/VideoEncoder.cpp @@ -160,9 +160,11 @@ int32_t VideoEncoder::Configure(const SampleInfo &sampleInfo) { // [End video_encoder_faq] // [End camera_AVCodec] +// [Start GetSurface] int32_t VideoEncoder::GetSurface(SampleInfo &sampleInfo) { int32_t ret = OH_VideoEncoder_GetSurface(encoder_, &sampleInfo.window); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, "Get surface failed, ret: %{public}d", ret); return AVCODEC_SAMPLE_ERR_OK; -} \ No newline at end of file +} +// [End GetSurface] \ No newline at end of file diff --git a/entry/src/main/cpp/sample/recorder/Recorder.cpp b/entry/src/main/cpp/sample/recorder/Recorder.cpp index 8b1418c..c5708b4 100644 --- a/entry/src/main/cpp/sample/recorder/Recorder.cpp +++ b/entry/src/main/cpp/sample/recorder/Recorder.cpp @@ -108,6 +108,7 @@ int32_t Recorder::Start() { return AVCODEC_SAMPLE_ERR_OK; } +// [Start EncOutputThread] void Recorder::EncOutputThread() { while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); @@ -141,6 +142,7 @@ void Recorder::EncOutputThread() { AVCODEC_SAMPLE_LOGI("Exit, frame count: %{public}u", encContext_->outputFrameCount); StartRelease(); } +// [End EncOutputThread] void Recorder::StartRelease() { if (releaseThread_ == nullptr) { diff --git a/entry/src/main/cpp/sample/recorder/RecorderNative.cpp b/entry/src/main/cpp/sample/recorder/RecorderNative.cpp index 9feea16..cd3d302 100644 --- a/entry/src/main/cpp/sample/recorder/RecorderNative.cpp +++ b/entry/src/main/cpp/sample/recorder/RecorderNative.cpp @@ -52,6 +52,7 @@ void SurfaceIdCallBack(AsyncCallbackInfo *asyncCallbackInfo, std::string surface asyncCallbackInfo->surfaceId = surfaceId; } +// [Start NativeInit] void NativeInit(napi_env env, void *data) { AsyncCallbackInfo *asyncCallbackInfo = static_cast(data); int32_t ret = Recorder::GetInstance().Init(asyncCallbackInfo->sampleInfo); @@ -67,6 +68,7 @@ void NativeInit(napi_env env, void *data) { asyncCallbackInfo->surfaceId = std::to_string(id); SurfaceIdCallBack(asyncCallbackInfo, asyncCallbackInfo->surfaceId); } +// [End NativeInit] napi_value RecorderNative::Init(napi_env env, napi_callback_info info) { SampleInfo sampleInfo; diff --git a/entry/src/main/ets/pages/Recorder.ets b/entry/src/main/ets/pages/Recorder.ets index edfe4cd..283c033 100644 --- a/entry/src/main/ets/pages/Recorder.ets +++ b/entry/src/main/ets/pages/Recorder.ets @@ -309,6 +309,7 @@ struct Recorder { // [EndExclude camera_conversation] } + // [Start add_output] // Add the encoder video stream to the session. try { videoSession.addOutput(encoderVideoOutput); @@ -318,6 +319,7 @@ struct Recorder { Logger.error(TAG, `Failed to add encoderVideoOutput. error: ${JSON.stringify(err)}`); // [EndExclude camera_conversation] } + // [End add_output] // Submit configuration information. try { @@ -345,6 +347,7 @@ struct Recorder { // [EndExclude camera_conversation] } + // [Start start_video_output] // Start the video output stream encoderVideoOutput.start((err: BusinessError) => { // [StartExclude camera_conversation] @@ -355,6 +358,7 @@ struct Recorder { Logger.info(TAG, 'Callback invoked to indicate the encoder video output start success.'); // [EndExclude camera_conversation] }); + // [Start start_video_output] // [End camera_conversation] } catch (error) { hilog.error(0x0000, TAG, `createRecorder catch error, code: ${error.code}, message: ${error.message}`); -- Gitee