diff --git a/entry/src/main/cpp/capbilities/Demuxer.cpp b/entry/src/main/cpp/capbilities/Demuxer.cpp index f1aea33bec2821925b337988c32dea0ddf6f8cb3..705c4a7f336dbbf36cc2b62ebd292bbbac2503f3 100644 --- a/entry/src/main/cpp/capbilities/Demuxer.cpp +++ b/entry/src/main/cpp/capbilities/Demuxer.cpp @@ -21,18 +21,22 @@ Demuxer::~Demuxer() { Release(); } +// [Start OHAVSourceCreate] int32_t Demuxer::Create(SampleInfo &info) { if (info.isLocal) { + // From the local video scenario source = OH_AVSource_CreateWithFD(info.inputFd, info.inputFileOffset, info.inputFileSize); } else { + // From the local video scenario source = OH_AVSource_CreateWithURI(info.networkUri); } - + CHECK_AND_RETURN_RET_LOG(source != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create demuxer source failed, fd: %{public}d, offset: %{public}" PRId64 ", file size: %{public}" PRId64, info.inputFd, info.inputFileOffset, info.inputFileSize); demuxer = OH_AVDemuxer_CreateWithSource(source); + // [StartExclude OHAVSourceCreate] CHECK_AND_RETURN_RET_LOG(demuxer != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create demuxer failed"); auto sourceFormat = std::shared_ptr(OH_AVSource_GetSourceFormat(source), OH_AVFormat_Destroy); @@ -42,8 +46,11 @@ int32_t Demuxer::Create(SampleInfo &info) { CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Get video track info failed"); return AVCODEC_SAMPLE_ERR_OK; + // [EndExclude OHAVSourceCreate] } +// [End OHAVSourceCreate] +// [Start ReadSample] int32_t Demuxer::ReadSample(int32_t trackId, OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr) { CHECK_AND_RETURN_RET_LOG(demuxer != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Demuxer is null"); int32_t ret = OH_AVDemuxer_ReadSampleBuffer(demuxer, trackId, buffer); @@ -52,6 +59,7 @@ int32_t Demuxer::ReadSample(int32_t trackId, OH_AVBuffer *buffer, OH_AVCodecBuff CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "GetBufferAttr failed"); return AVCODEC_SAMPLE_ERR_OK; } +// [End ReadSample] int32_t Demuxer::Release() { if (demuxer != nullptr) { diff --git a/entry/src/main/cpp/capbilities/Muxer.cpp b/entry/src/main/cpp/capbilities/Muxer.cpp index a125ef56d40037d9ad6cf5421d5758db4c25a784..705b46bda2e54ffc5154de435d931526ce6c6ff9 100644 --- a/entry/src/main/cpp/capbilities/Muxer.cpp +++ b/entry/src/main/cpp/capbilities/Muxer.cpp @@ -80,6 +80,7 @@ int32_t Muxer::Start() { } // [End StartMuxer] +// [Start WriteSample] int32_t Muxer::WriteSample(int32_t trackId, OH_AVBuffer *buffer, OH_AVCodecBufferAttr &attr){ std::lock_guard lock(writeMutex_); @@ -93,6 +94,7 @@ int32_t Muxer::WriteSample(int32_t trackId, OH_AVBuffer *buffer, OH_AVCodecBuffe CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Write sample failed"); return AVCODEC_SAMPLE_ERR_OK; } +// [End WriteSample] int32_t Muxer::Release() { if (muxer_ != nullptr) { diff --git a/entry/src/main/cpp/common/SampleInfo.h b/entry/src/main/cpp/common/SampleInfo.h index e26bab8c83cfa6ba3688dbc2e9dfde808bd7316d..b51173aaf2b6b851bd46692af123aa4dc7e21425 100644 --- a/entry/src/main/cpp/common/SampleInfo.h +++ b/entry/src/main/cpp/common/SampleInfo.h @@ -77,6 +77,7 @@ struct SampleInfo { void *playDoneCallbackData = nullptr; }; +// [Start CodecBufferInfo] struct CodecBufferInfo { uint32_t bufferIndex = 0; uintptr_t *buffer = nullptr; @@ -91,6 +92,7 @@ struct CodecBufferInfo { OH_AVBuffer_GetBufferAttr(argBuffer, &attr); }; }; +// [End CodecBufferInfo] struct CodecUserData { public: diff --git a/entry/src/main/cpp/player/Player.cpp b/entry/src/main/cpp/player/Player.cpp index 4ab399565b1ba63e3188230f52ead21fb00d7fdf..ac1ffce0dfc91610c0966fcd2226b6789814b5a8 100644 --- a/entry/src/main/cpp/player/Player.cpp +++ b/entry/src/main/cpp/player/Player.cpp @@ -292,8 +292,6 @@ void Player::VideoDecOutputThread() { videoDecContext->outputFrameCount, bufferInfo.attr.size, bufferInfo.attr.flags, bufferInfo.attr.pts); lock.unlock(); // [Start unlock] - - // get audio render position int64_t framePosition = 0; int64_t timeStamp = 0; @@ -376,6 +374,7 @@ int64_t Player::GetCurrentTime() { return result; } +// [Start AudioDecInputThread] void Player::AudioDecInputThread() { while (true) { CHECK_AND_BREAK_LOG(isStarted, "Decoder input thread out"); @@ -400,6 +399,7 @@ void Player::AudioDecInputThread() { CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } } +// [End AudioDecInputThread] void Player::AudioDecOutputThread() { while (true) { diff --git a/entry/src/main/cpp/recorder/Recorder.cpp b/entry/src/main/cpp/recorder/Recorder.cpp index 39ee4bf51e9c4df16da9d167de13b0fe6f65909a..699936c821c45a667ba72abac8b7142e71a4d92c 100644 --- a/entry/src/main/cpp/recorder/Recorder.cpp +++ b/entry/src/main/cpp/recorder/Recorder.cpp @@ -20,11 +20,17 @@ #undef LOG_TAG #define LOG_TAG "recorder" +// [Start namespace] namespace { +// [StartExclude namespace] using namespace std::chrono_literals; +// [EndExclude namespace] constexpr int64_t MICROSECOND = 1000000; +// [StartExclude namespace] constexpr int32_t INPUT_FRAME_BYTES = 2 * 1024; -} // namespace +// [EndExclude namespace] +} +// [End namespace] Recorder::~Recorder() { StartRelease(); } @@ -63,6 +69,7 @@ int32_t Recorder::Init(SampleInfo &sampleInfo) { return AVCODEC_SAMPLE_ERR_OK; } +// [Start RecordStart] int32_t Recorder::Start() { std::lock_guard lock(mutex_); CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); @@ -97,8 +104,7 @@ int32_t Recorder::Start() { StartRelease(); return AVCODEC_SAMPLE_ERR_ERROR; } - - // 清空播放缓存队列 + if (audioEncContext_ != nullptr) { audioEncContext_->ClearCache(); } @@ -107,6 +113,7 @@ int32_t Recorder::Start() { AVCODEC_SAMPLE_LOGI("Succeed"); return AVCODEC_SAMPLE_ERR_OK; } +// [End RecordStart] // [Start EncOutputThread] void Recorder::EncOutputThread() { @@ -284,6 +291,7 @@ void Recorder::AudioEncInputThread() { } } +// [Start AudioEncOutputThread] void Recorder::AudioEncOutputThread() { while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); @@ -307,4 +315,5 @@ void Recorder::AudioEncOutputThread() { } AVCODEC_SAMPLE_LOGI("Exit, frame count: %{public}u", audioEncContext_->inputFrameCount); StartRelease(); -} \ No newline at end of file +} +// [End AudioEncOutputThread] \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/FileUtil.ets b/entry/src/main/ets/common/utils/FileUtil.ets index c0526820d7b4bc2e585d1ea177d0cfd01e36cd23..e71738b67506b354e888cfe24d0a5d06196dcaa2 100644 --- a/entry/src/main/ets/common/utils/FileUtil.ets +++ b/entry/src/main/ets/common/utils/FileUtil.ets @@ -35,6 +35,7 @@ export class FileUtil { return FileUtil.PhotoPicker; } + // [Start PhotoViewPicker] static async selectFileFromLocal(): Promise { try { let result = await FileUtil.getPhotoViewPicker().select({ @@ -42,7 +43,6 @@ export class FileUtil { maxSelectNumber: 1 }) let selectFilePath = result.photoUris[0]; - console.log('selectFileFromLocal-->2' + selectFilePath) if (!selectFilePath) { return undefined } @@ -51,6 +51,7 @@ export class FileUtil { return undefined; } } + // [End PhotoViewPicker] } @CustomDialog