分布式屏幕dcts用例适配新avcodec接口

Signed-off-by: pwx1285814 <panzhi9@huawei.com>
Change-Id: I95eed1a9effe8eb2b65c72b5df4dbaeeaf7f6d84
Signed-off-by: pwx1285814 <panzhi9@huawei.com>
This commit is contained in:
pwx1285814 2024-03-24 15:36:14 +08:00
parent 5a55e3e243
commit d2bc9f9743
4 changed files with 37 additions and 33 deletions

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022-2023 Huawei Device Co., Ltd.
# Copyright (C) 2022-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -41,8 +41,6 @@ ohos_moduletest_suite("SubDctsdisScreenTest") {
"$base_root/foundation/communication/dsoftbus/interfaces/kits/common",
]
include_dirs += [ "$base_root/foundation/multimedia/player_framework/interfaces/inner_api/native" ]
sources = [
"decoder_demo.cpp",
"dsreen_automat_test.cpp",
@ -74,12 +72,13 @@ ohos_moduletest_suite("SubDctsdisScreenTest") {
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"av_codec:av_codec_client",
"c_utils:utils",
"dsoftbus:softbus_client",
"graphic_2d:librender_service_client",
"graphic_surface:surface",
"hilog:libhilog",
"player_framework:media_client",
"media_foundation:media_foundation",
"samgr:samgr_proxy",
"window_manager:libdm",
"window_manager:libwm",

View File

@ -58,10 +58,10 @@ static const int32_t ES_W[183] = {
};
using namespace OHOS;
using namespace OHOS::Media;
using namespace OHOS::MediaAVCodec;
using namespace std;
namespace {
constexpr uint32_t DEFAULT_FRAME_RATE = 30;
constexpr double DEFAULT_FRAME_RATE = 30.0;
constexpr uint32_t MAX_INPUT_BUFFER_SIZE = 30000;
constexpr uint32_t FRAME_DURATION_US = 33000;
constexpr uint32_t VIDEO_DATA_FORMAT_NV12 = 2;
@ -76,7 +76,7 @@ void VDecDemo::RunCase()
{
CheckCodecType();
CreateVdec();
Format format;
Media::Format format;
format.PutIntValue("width", width_);
format.PutIntValue("height", height_);
if (isW) {
@ -84,7 +84,7 @@ void VDecDemo::RunCase()
} else {
format.PutIntValue("pixel_format", VIDEO_DATA_FORMAT_RGBA);
}
format.PutIntValue("frame_rate", DEFAULT_FRAME_RATE);
format.PutDoubleValue("frame_rate", DEFAULT_FRAME_RATE);
format.PutIntValue("max_input_size", MAX_INPUT_BUFFER_SIZE);
Configure(format);
SetSurface();
@ -109,7 +109,7 @@ int32_t VDecDemo::CreateVdec()
return 0;
}
int32_t VDecDemo::Configure(const Format &format)
int32_t VDecDemo::Configure(const Media::Format &format)
{
return vdec_->Configure(format);
}
@ -192,11 +192,14 @@ int32_t VDecDemo::SetSurface()
void VDecDemo::CheckCodecType()
{
std::vector<std::string> localCodecArray;
std::shared_ptr<Media::AVCodecList> codecList = Media::AVCodecListFactory::CreateAVCodecList();
std::vector<std::shared_ptr<Media::VideoCaps>> caps = codecList->GetVideoEncoderCaps();
for (const auto &cap : caps) {
std::shared_ptr<Media::AVCodecInfo> codecInfo = cap->GetCodecInfo();
localCodecArray.push_back(codecInfo->GetName());
std::shared_ptr<MediaAVCodec::AVCodecList> codecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList();
const std::vector<std::string> encoderName = {std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC),
std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)};
for (const auto &coder : encoderName) {
MediaAVCodec::CapabilityData *capData = codecList->GetCapability(coder, true,
MediaAVCodec::AVCodecCategory::AVCODEC_HARDWARE);
std::string mimeType = capData->mimeType;
localCodecArray.push_back(mimeType);
}
if (std::find(localCodecArray.begin(), localCodecArray.end(),
@ -227,20 +230,17 @@ void VDecDemo::InputFunc()
{
const int32_t *frameLen = GetFrameLen();
while (true) {
if (!isRunning_.load()) {
break;
}
while (isRunning_.load()) {
unique_lock<mutex> lock(signal_->inMutex_);
signal_->inCond_.wait(lock, [this]() { return signal_->inQueue_.size() > 0; });
signal_->inCond_.wait(
lock, [this]() { return signal_->inQueue_.size() > 0 && signal_->availableInputBufferQueue_.size() > 0; });
if (!isRunning_.load()) {
break;
}
uint32_t index = signal_->inQueue_.front();
auto buffer = vdec_->GetInputBuffer(index);
std::shared_ptr<Media::AVSharedMemory> buffer = signal_->availableInputBufferQueue_.front();
if(buffer == nullptr) {
break;
}
@ -274,6 +274,7 @@ void VDecDemo::InputFunc()
frameLen++;
timeStamp_ += FRAME_DURATION_US;
signal_->inQueue_.pop();
signal_->availableInputBufferQueue_.pop();
frameCount_++;
if (frameCount_ == defaultFrameCount_) {
@ -313,20 +314,22 @@ void VDecDemoCallback::OnError(AVCodecErrorType errorType, int32_t errorCode)
DHLOGI("Error received, errorType: %{public}d, errorCode: %{public}d", errorType, errorCode);
}
void VDecDemoCallback::OnOutputFormatChanged(const Format &format)
void VDecDemoCallback::OnOutputFormatChanged(const Media::Format &format)
{
DHLOGI("OnOutputFormatChanged received");
}
void VDecDemoCallback::OnInputBufferAvailable(uint32_t index)
void VDecDemoCallback::OnInputBufferAvailable(uint32_t index, std::shared_ptr<Media::AVSharedMemory> buffer)
{
DHLOGI("OnInputBufferAvailable received, index: %{public}d", index);
unique_lock<mutex> lock(signal_->inMutex_);
signal_->inQueue_.push(index);
signal_->availableInputBufferQueue_.push(buffer);
signal_->inCond_.notify_all();
}
void VDecDemoCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag)
void VDecDemoCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
std::shared_ptr<Media::AVSharedMemory> buffer)
{
DHLOGI("OnOutputBufferAvailable received, index: %{public}d", index);
unique_lock<mutex> lock(signal_->outMutex_);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -27,7 +27,7 @@
#include "distributed_hardware_log.h"
namespace OHOS {
namespace Media {
namespace MediaAVCodec {
class VDecSignal {
public:
std::mutex inMutex_;
@ -36,6 +36,7 @@ public:
std::condition_variable outCond_;
std::queue<uint32_t> inQueue_;
std::queue<uint32_t> outQueue_;
std::queue<std::shared_ptr<Media::AVSharedMemory>> availableInputBufferQueue_;
};
class VDecDemoCallback : public AVCodecCallback, public NoCopyable {
@ -44,9 +45,10 @@ public:
virtual ~VDecDemoCallback() = default;
void OnError(AVCodecErrorType errorType, int32_t errorCode) override;
void OnOutputFormatChanged(const Format &format) override;
void OnInputBufferAvailable(uint32_t index) override;
void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
void OnOutputFormatChanged(const Media::Format &format) override;
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<Media::AVSharedMemory> buffer) override;
void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
std::shared_ptr<Media::AVSharedMemory> buffer) override;
private:
std::shared_ptr<VDecSignal> signal_;
@ -62,7 +64,7 @@ public:
private:
int32_t CreateVdec();
int32_t Configure(const Format &format);
int32_t Configure(const Media::Format &format);
int32_t Prepare();
int32_t Start();
int32_t Stop();
@ -82,7 +84,7 @@ private:
std::unique_ptr<std::ifstream> testFile_;
std::unique_ptr<std::thread> inputLoop_;
std::unique_ptr<std::thread> outputLoop_;
std::shared_ptr<Media::AVCodecVideoDecoder> vdec_;
std::shared_ptr<MediaAVCodec::AVCodecVideoDecoder> vdec_;
std::shared_ptr<VDecSignal> signal_;
std::shared_ptr<VDecDemoCallback> cb_;
bool isFirstFrame_ = true;
@ -91,7 +93,7 @@ private:
uint32_t frameCount_ = 0;
uint32_t defaultFrameCount_ = 0;
};
} // namespace Media
} // namespace MediaAVCodec
} // namespace OHOS
int StartMirror(int mode);

View File

@ -44,7 +44,7 @@ using namespace std;
using namespace OHOS;
using namespace OHOS::DistributedHardware;
using namespace OHOS::Rosen;
using namespace OHOS::Media;
using namespace OHOS::MediaAVCodec;
using namespace OHOS::Security::AccessToken;
namespace {