166f3657fSopenharmony_ci/* 266f3657fSopenharmony_ci * Copyright (C) 2022-2024 Huawei Device Co., Ltd. 366f3657fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 466f3657fSopenharmony_ci * you may not use this file except in compliance with the License. 566f3657fSopenharmony_ci * You may obtain a copy of the License at 666f3657fSopenharmony_ci * 766f3657fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 866f3657fSopenharmony_ci * 966f3657fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1066f3657fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1166f3657fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1266f3657fSopenharmony_ci * See the License for the specific language governing permissions and 1366f3657fSopenharmony_ci * limitations under the License. 1466f3657fSopenharmony_ci */ 1566f3657fSopenharmony_ci 1666f3657fSopenharmony_ci#include "decoder_demo.h" 1766f3657fSopenharmony_ci 1866f3657fSopenharmony_ci#include <iostream> 1966f3657fSopenharmony_ci#include <unistd.h> 2066f3657fSopenharmony_ci 2166f3657fSopenharmony_ci#include "avcodec_list.h" 2266f3657fSopenharmony_ci#include "securec.h" 2366f3657fSopenharmony_ci#include "wm_common.h" 2466f3657fSopenharmony_ci#include "window.h" 2566f3657fSopenharmony_ci#include "window_scene.h" 2666f3657fSopenharmony_ci#include "window_option.h" 2766f3657fSopenharmony_ci 2866f3657fSopenharmony_cistatic const int32_t ES_R[325] = { 2966f3657fSopenharmony_ci 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, 677, 3066f3657fSopenharmony_ci 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, 608, 431, 3166f3657fSopenharmony_ci 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, 355, 422, 467, 3266f3657fSopenharmony_ci 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, 487, 4404, 362, 378, 3366f3657fSopenharmony_ci 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, 369, 443, 406, 392, 4231, 3466f3657fSopenharmony_ci 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, 378, 355, 374, 484, 381, 373, 3566f3657fSopenharmony_ci 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, 315, 416, 383, 373, 381, 354, 383, 3666f3657fSopenharmony_ci 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, 326, 3439, 266, 324, 329, 353, 405, 303, 3766f3657fSopenharmony_ci 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, 367, 341, 276, 258, 3980, 246, 245, 259, 309, 3866f3657fSopenharmony_ci 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 3966f3657fSopenharmony_ci 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 4066f3657fSopenharmony_ci 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 4166f3657fSopenharmony_ci 368, 3810, 231, 212, 279, 289, 252, 303, 287, 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 4266f3657fSopenharmony_ci 317, 232, 348, 4077, 259, 222, 268, 235, 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 4366f3657fSopenharmony_ci 273, 301, 304, 253, 266, 3978, 228, 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 4466f3657fSopenharmony_ci}; 4566f3657fSopenharmony_ci 4666f3657fSopenharmony_cistatic const int32_t ES_W[183] = { 4766f3657fSopenharmony_ci 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, 4866f3657fSopenharmony_ci 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, 4966f3657fSopenharmony_ci 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, 5066f3657fSopenharmony_ci 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, 5166f3657fSopenharmony_ci 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, 5266f3657fSopenharmony_ci 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, 5366f3657fSopenharmony_ci 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, 5466f3657fSopenharmony_ci 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, 5566f3657fSopenharmony_ci 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, 5666f3657fSopenharmony_ci 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, 5766f3657fSopenharmony_ci 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 5866f3657fSopenharmony_ci}; 5966f3657fSopenharmony_ci 6066f3657fSopenharmony_ciusing namespace OHOS; 6166f3657fSopenharmony_ciusing namespace OHOS::MediaAVCodec; 6266f3657fSopenharmony_ciusing namespace std; 6366f3657fSopenharmony_cinamespace { 6466f3657fSopenharmony_ci constexpr uint32_t DEFAULT_FRAME_RATE = 30; 6566f3657fSopenharmony_ci constexpr uint32_t MAX_INPUT_BUFFER_SIZE = 30000; 6666f3657fSopenharmony_ci constexpr uint32_t FRAME_DURATION_US = 33000; 6766f3657fSopenharmony_ci constexpr uint32_t VIDEO_DATA_FORMAT_NV12 = 2; 6866f3657fSopenharmony_ci constexpr uint32_t VIDEO_DATA_FORMAT_RGBA = 5; 6966f3657fSopenharmony_ci constexpr uint32_t SLEEP_THREE_SECOND = 3; 7066f3657fSopenharmony_ci constexpr uint32_t INDEX_CONSTANT = 10000; 7166f3657fSopenharmony_ci const string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc"; 7266f3657fSopenharmony_ci const string CODEC_NAME_MPEG4 = "avenc_mpeg4"; 7366f3657fSopenharmony_ci} 7466f3657fSopenharmony_ci 7566f3657fSopenharmony_civoid VDecDemo::RunCase() 7666f3657fSopenharmony_ci{ 7766f3657fSopenharmony_ci CheckCodecType(); 7866f3657fSopenharmony_ci CreateVdec(); 7966f3657fSopenharmony_ci Media::Format format; 8066f3657fSopenharmony_ci format.PutIntValue("width", width_); 8166f3657fSopenharmony_ci format.PutIntValue("height", height_); 8266f3657fSopenharmony_ci if (isW) { 8366f3657fSopenharmony_ci format.PutIntValue("pixel_format", VIDEO_DATA_FORMAT_NV12); 8466f3657fSopenharmony_ci } else { 8566f3657fSopenharmony_ci format.PutIntValue("pixel_format", VIDEO_DATA_FORMAT_RGBA); 8666f3657fSopenharmony_ci } 8766f3657fSopenharmony_ci format.PutIntValue("frame_rate", DEFAULT_FRAME_RATE); 8866f3657fSopenharmony_ci format.PutIntValue("max_input_size", MAX_INPUT_BUFFER_SIZE); 8966f3657fSopenharmony_ci Configure(format); 9066f3657fSopenharmony_ci SetSurface(); 9166f3657fSopenharmony_ci Prepare(); 9266f3657fSopenharmony_ci Start(); 9366f3657fSopenharmony_ci sleep(SLEEP_THREE_SECOND); 9466f3657fSopenharmony_ci Stop(); 9566f3657fSopenharmony_ci Release(); 9666f3657fSopenharmony_ci} 9766f3657fSopenharmony_ci 9866f3657fSopenharmony_ciint32_t VDecDemo::CreateVdec() 9966f3657fSopenharmony_ci{ 10066f3657fSopenharmony_ci if (isW) { 10166f3657fSopenharmony_ci vdec_ = VideoDecoderFactory::CreateByMime("video/avc"); 10266f3657fSopenharmony_ci } else { 10366f3657fSopenharmony_ci vdec_ = VideoDecoderFactory::CreateByMime("video/mp4v-es"); 10466f3657fSopenharmony_ci } 10566f3657fSopenharmony_ci 10666f3657fSopenharmony_ci signal_ = make_shared<VDecSignal>(); 10766f3657fSopenharmony_ci cb_ = make_unique<VDecDemoCallback>(signal_); 10866f3657fSopenharmony_ci vdec_->SetCallback(cb_); 10966f3657fSopenharmony_ci return 0; 11066f3657fSopenharmony_ci} 11166f3657fSopenharmony_ci 11266f3657fSopenharmony_ciint32_t VDecDemo::Configure(const Media::Format &format) 11366f3657fSopenharmony_ci{ 11466f3657fSopenharmony_ci return vdec_->Configure(format); 11566f3657fSopenharmony_ci} 11666f3657fSopenharmony_ci 11766f3657fSopenharmony_ciint32_t VDecDemo::Prepare() 11866f3657fSopenharmony_ci{ 11966f3657fSopenharmony_ci return vdec_->Prepare(); 12066f3657fSopenharmony_ci} 12166f3657fSopenharmony_ci 12266f3657fSopenharmony_ciint32_t VDecDemo::Start() 12366f3657fSopenharmony_ci{ 12466f3657fSopenharmony_ci isRunning_.store(true); 12566f3657fSopenharmony_ci 12666f3657fSopenharmony_ci testFile_ = std::make_unique<std::ifstream>(); 12766f3657fSopenharmony_ci testFile_->open("/data/media/video.es", std::ios::in | std::ios::binary); 12866f3657fSopenharmony_ci 12966f3657fSopenharmony_ci inputLoop_ = make_unique<thread>(&VDecDemo::InputFunc, this); 13066f3657fSopenharmony_ci outputLoop_ = make_unique<thread>(&VDecDemo::OutputFunc, this); 13166f3657fSopenharmony_ci return vdec_->Start(); 13266f3657fSopenharmony_ci} 13366f3657fSopenharmony_ci 13466f3657fSopenharmony_ciint32_t VDecDemo::Stop() 13566f3657fSopenharmony_ci{ 13666f3657fSopenharmony_ci isRunning_.store(false); 13766f3657fSopenharmony_ci 13866f3657fSopenharmony_ci if (inputLoop_ != nullptr && inputLoop_->joinable()) { 13966f3657fSopenharmony_ci { 14066f3657fSopenharmony_ci unique_lock<mutex> inLock(signal_->inMutex_); 14166f3657fSopenharmony_ci signal_->inQueue_.push(INDEX_CONSTANT); 14266f3657fSopenharmony_ci signal_->inCond_.notify_all(); 14366f3657fSopenharmony_ci } 14466f3657fSopenharmony_ci inputLoop_->join(); 14566f3657fSopenharmony_ci inputLoop_.reset(); 14666f3657fSopenharmony_ci } 14766f3657fSopenharmony_ci 14866f3657fSopenharmony_ci if (outputLoop_ != nullptr && outputLoop_->joinable()) { 14966f3657fSopenharmony_ci { 15066f3657fSopenharmony_ci unique_lock<mutex> outLock(signal_->outMutex_); 15166f3657fSopenharmony_ci signal_->outQueue_.push(INDEX_CONSTANT); 15266f3657fSopenharmony_ci signal_->outCond_.notify_all(); 15366f3657fSopenharmony_ci } 15466f3657fSopenharmony_ci outputLoop_->join(); 15566f3657fSopenharmony_ci outputLoop_.reset(); 15666f3657fSopenharmony_ci } 15766f3657fSopenharmony_ci 15866f3657fSopenharmony_ci return vdec_->Stop(); 15966f3657fSopenharmony_ci} 16066f3657fSopenharmony_ci 16166f3657fSopenharmony_ciint32_t VDecDemo::Flush() 16266f3657fSopenharmony_ci{ 16366f3657fSopenharmony_ci return vdec_->Flush(); 16466f3657fSopenharmony_ci} 16566f3657fSopenharmony_ci 16666f3657fSopenharmony_ciint32_t VDecDemo::Reset() 16766f3657fSopenharmony_ci{ 16866f3657fSopenharmony_ci return vdec_->Reset(); 16966f3657fSopenharmony_ci} 17066f3657fSopenharmony_ci 17166f3657fSopenharmony_ciint32_t VDecDemo::Release() 17266f3657fSopenharmony_ci{ 17366f3657fSopenharmony_ci return vdec_->Release(); 17466f3657fSopenharmony_ci} 17566f3657fSopenharmony_ci 17666f3657fSopenharmony_civoid VDecDemo::SetOutputSurface(sptr<Surface> surface) 17766f3657fSopenharmony_ci{ 17866f3657fSopenharmony_ci surface_ = surface; 17966f3657fSopenharmony_ci} 18066f3657fSopenharmony_ci 18166f3657fSopenharmony_civoid VDecDemo::SetWindowSize(uint32_t width, uint32_t height) 18266f3657fSopenharmony_ci{ 18366f3657fSopenharmony_ci width_ = width; 18466f3657fSopenharmony_ci height_ = height; 18566f3657fSopenharmony_ci} 18666f3657fSopenharmony_ci 18766f3657fSopenharmony_ciint32_t VDecDemo::SetSurface() 18866f3657fSopenharmony_ci{ 18966f3657fSopenharmony_ci return vdec_->SetOutputSurface(surface_); 19066f3657fSopenharmony_ci} 19166f3657fSopenharmony_ci 19266f3657fSopenharmony_civoid VDecDemo::CheckCodecType() 19366f3657fSopenharmony_ci{ 19466f3657fSopenharmony_ci std::vector<std::string> localCodecArray; 19566f3657fSopenharmony_ci std::shared_ptr<MediaAVCodec::AVCodecList> codecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList(); 19666f3657fSopenharmony_ci const std::vector<std::string> encoderName = {std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC), 19766f3657fSopenharmony_ci std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)}; 19866f3657fSopenharmony_ci 19966f3657fSopenharmony_ci for (const auto &coder : encoderName) { 20066f3657fSopenharmony_ci MediaAVCodec::CapabilityData *capData = codecList->GetCapability(coder, true, 20166f3657fSopenharmony_ci MediaAVCodec::AVCodecCategory::AVCODEC_HARDWARE); 20266f3657fSopenharmony_ci std::string mimeType = capData->mimeType; 20366f3657fSopenharmony_ci localCodecArray.push_back(mimeType); 20466f3657fSopenharmony_ci } 20566f3657fSopenharmony_ci 20666f3657fSopenharmony_ci if (std::find(localCodecArray.begin(), localCodecArray.end(), 20766f3657fSopenharmony_ci CODEC_NAME_H264) != localCodecArray.end()) { 20866f3657fSopenharmony_ci cout << "device is W" << endl; 20966f3657fSopenharmony_ci isW = true; 21066f3657fSopenharmony_ci } else if (std::find(localCodecArray.begin(), localCodecArray.end(), 21166f3657fSopenharmony_ci CODEC_NAME_MPEG4) != localCodecArray.end()) { 21266f3657fSopenharmony_ci cout << "device is R" << endl; 21366f3657fSopenharmony_ci isW = false; 21466f3657fSopenharmony_ci } 21566f3657fSopenharmony_ci} 21666f3657fSopenharmony_ci 21766f3657fSopenharmony_ciconst int32_t* VDecDemo::GetFrameLen() 21866f3657fSopenharmony_ci{ 21966f3657fSopenharmony_ci const int32_t* frameLen = nullptr; 22066f3657fSopenharmony_ci if (isW) { 22166f3657fSopenharmony_ci frameLen = ES_W; 22266f3657fSopenharmony_ci defaultFrameCount_ = sizeof(ES_W) / sizeof(ES_W[0]); 22366f3657fSopenharmony_ci } else { 22466f3657fSopenharmony_ci frameLen = ES_R; 22566f3657fSopenharmony_ci defaultFrameCount_ = sizeof(ES_R) / sizeof(ES_R[0]); 22666f3657fSopenharmony_ci } 22766f3657fSopenharmony_ci return frameLen; 22866f3657fSopenharmony_ci} 22966f3657fSopenharmony_ci 23066f3657fSopenharmony_civoid VDecDemo::InputFunc() 23166f3657fSopenharmony_ci{ 23266f3657fSopenharmony_ci const int32_t *frameLen = GetFrameLen(); 23366f3657fSopenharmony_ci 23466f3657fSopenharmony_ci while (isRunning_.load()) { 23566f3657fSopenharmony_ci unique_lock<mutex> lock(signal_->inMutex_); 23666f3657fSopenharmony_ci signal_->inCond_.wait( 23766f3657fSopenharmony_ci lock, [this]() { return signal_->inQueue_.size() > 0 && signal_->availableInputBufferQueue_.size() > 0; }); 23866f3657fSopenharmony_ci 23966f3657fSopenharmony_ci if (!isRunning_.load()) { 24066f3657fSopenharmony_ci break; 24166f3657fSopenharmony_ci } 24266f3657fSopenharmony_ci 24366f3657fSopenharmony_ci uint32_t index = signal_->inQueue_.front(); 24466f3657fSopenharmony_ci std::shared_ptr<Media::AVSharedMemory> buffer = signal_->availableInputBufferQueue_.front(); 24566f3657fSopenharmony_ci 24666f3657fSopenharmony_ci char *fileBuffer = static_cast<char *>(malloc(sizeof(char) * (*frameLen) + 1)); 24766f3657fSopenharmony_ci if (fileBuffer == nullptr) { 24866f3657fSopenharmony_ci break; 24966f3657fSopenharmony_ci } 25066f3657fSopenharmony_ci 25166f3657fSopenharmony_ci (void)testFile_->read(fileBuffer, *frameLen); 25266f3657fSopenharmony_ci if (memcpy_s(buffer->GetBase(), buffer->GetSize(), fileBuffer, *frameLen) != EOK) { 25366f3657fSopenharmony_ci free(fileBuffer); 25466f3657fSopenharmony_ci cout << "Fatal: memcpy fail" << endl; 25566f3657fSopenharmony_ci break; 25666f3657fSopenharmony_ci } 25766f3657fSopenharmony_ci 25866f3657fSopenharmony_ci AVCodecBufferInfo info; 25966f3657fSopenharmony_ci info.size = *frameLen; 26066f3657fSopenharmony_ci info.offset = 0; 26166f3657fSopenharmony_ci info.presentationTimeUs = timeStamp_; 26266f3657fSopenharmony_ci 26366f3657fSopenharmony_ci int32_t ret = 0; 26466f3657fSopenharmony_ci if (isFirstFrame_) { 26566f3657fSopenharmony_ci ret = vdec_->QueueInputBuffer(index, info, AVCODEC_BUFFER_FLAG_CODEC_DATA); 26666f3657fSopenharmony_ci isFirstFrame_ = false; 26766f3657fSopenharmony_ci } else { 26866f3657fSopenharmony_ci ret = vdec_->QueueInputBuffer(index, info, AVCODEC_BUFFER_FLAG_NONE); 26966f3657fSopenharmony_ci } 27066f3657fSopenharmony_ci 27166f3657fSopenharmony_ci free(fileBuffer); 27266f3657fSopenharmony_ci frameLen++; 27366f3657fSopenharmony_ci timeStamp_ += FRAME_DURATION_US; 27466f3657fSopenharmony_ci signal_->inQueue_.pop(); 27566f3657fSopenharmony_ci signal_->availableInputBufferQueue_.pop(); 27666f3657fSopenharmony_ci 27766f3657fSopenharmony_ci frameCount_++; 27866f3657fSopenharmony_ci if (frameCount_ == defaultFrameCount_) { 27966f3657fSopenharmony_ci cout << "Finish decode, exit" << endl; 28066f3657fSopenharmony_ci break; 28166f3657fSopenharmony_ci } 28266f3657fSopenharmony_ci 28366f3657fSopenharmony_ci if (ret != 0) { 28466f3657fSopenharmony_ci cout << "Fatal error, exit" << endl; 28566f3657fSopenharmony_ci break; 28666f3657fSopenharmony_ci } 28766f3657fSopenharmony_ci } 28866f3657fSopenharmony_ci} 28966f3657fSopenharmony_ci 29066f3657fSopenharmony_civoid VDecDemo::OutputFunc() 29166f3657fSopenharmony_ci{ 29266f3657fSopenharmony_ci while (isRunning_.load()) { 29366f3657fSopenharmony_ci unique_lock<mutex> lock(signal_->outMutex_); 29466f3657fSopenharmony_ci signal_->outCond_.wait(lock, [this]() { return signal_->outQueue_.size() > 0; }); 29566f3657fSopenharmony_ci 29666f3657fSopenharmony_ci if (!isRunning_.load()) { 29766f3657fSopenharmony_ci break; 29866f3657fSopenharmony_ci } 29966f3657fSopenharmony_ci 30066f3657fSopenharmony_ci uint32_t index = signal_->outQueue_.front(); 30166f3657fSopenharmony_ci if (vdec_->ReleaseOutputBuffer(index, true) != 0) { 30266f3657fSopenharmony_ci cout << "Fatal: ReleaseOutputBuffer fail" << endl; 30366f3657fSopenharmony_ci break; 30466f3657fSopenharmony_ci } 30566f3657fSopenharmony_ci 30666f3657fSopenharmony_ci signal_->outQueue_.pop(); 30766f3657fSopenharmony_ci } 30866f3657fSopenharmony_ci} 30966f3657fSopenharmony_ci 31066f3657fSopenharmony_civoid VDecDemoCallback::OnError(AVCodecErrorType errorType, int32_t errorCode) 31166f3657fSopenharmony_ci{ 31266f3657fSopenharmony_ci cout << "Error received, errorType:" << errorType << " errorCode:" << errorCode << endl; 31366f3657fSopenharmony_ci} 31466f3657fSopenharmony_ci 31566f3657fSopenharmony_civoid VDecDemoCallback::OnOutputFormatChanged(const Media::Format &format) 31666f3657fSopenharmony_ci{ 31766f3657fSopenharmony_ci cout << "OnOutputFormatChanged received" << endl; 31866f3657fSopenharmony_ci} 31966f3657fSopenharmony_ci 32066f3657fSopenharmony_civoid VDecDemoCallback::OnInputBufferAvailable(uint32_t index, std::shared_ptr<Media::AVSharedMemory> buffer) 32166f3657fSopenharmony_ci{ 32266f3657fSopenharmony_ci cout << "OnInputBufferAvailable received, index:" << index << endl; 32366f3657fSopenharmony_ci unique_lock<mutex> lock(signal_->inMutex_); 32466f3657fSopenharmony_ci signal_->inQueue_.push(index); 32566f3657fSopenharmony_ci signal_->availableInputBufferQueue_.push(buffer); 32666f3657fSopenharmony_ci signal_->inCond_.notify_all(); 32766f3657fSopenharmony_ci} 32866f3657fSopenharmony_ci 32966f3657fSopenharmony_civoid VDecDemoCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, 33066f3657fSopenharmony_ci AVCodecBufferFlag flag, std::shared_ptr<Media::AVSharedMemory> buffer) 33166f3657fSopenharmony_ci{ 33266f3657fSopenharmony_ci cout << "OnOutputBufferAvailable received, index:" << index << endl; 33366f3657fSopenharmony_ci unique_lock<mutex> lock(signal_->outMutex_); 33466f3657fSopenharmony_ci signal_->outQueue_.push(index); 33566f3657fSopenharmony_ci signal_->outCond_.notify_all(); 33666f3657fSopenharmony_ci} 337