!3012 能力查询修复data未判空问题

Merge pull request !3012 from 杨小雨/master
This commit is contained in:
openharmony_ci 2024-08-21 06:02:12 +00:00 committed by Gitee
commit af5321b2e3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 121 additions and 3 deletions

View File

@ -66,6 +66,7 @@ const std::map<int32_t, LevelParams> MPEG4_SIMPLE_PARAMS_MAP = {
VideoCaps::VideoCaps(CapabilityData *capabilityData) : data_(capabilityData)
{
CHECK_AND_RETURN_LOG(capabilityData != nullptr, "capabilityData is null");
InitParams();
LoadLevelParams();
AVCODEC_LOGD("VideoCaps:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
@ -78,6 +79,7 @@ VideoCaps::~VideoCaps()
std::shared_ptr<AVCodecInfo> VideoCaps::GetCodecInfo()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, nullptr, "data is null");
std::shared_ptr<AVCodecInfo> codecInfo = std::make_shared<AVCodecInfo>(data_);
CHECK_AND_RETURN_RET_LOG(codecInfo != nullptr, nullptr, "create codecInfo failed");
@ -86,11 +88,13 @@ std::shared_ptr<AVCodecInfo> VideoCaps::GetCodecInfo()
Range VideoCaps::GetSupportedBitrate()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->bitrate;
}
std::vector<int32_t> VideoCaps::GetSupportedFormats()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> pixFormat = data_->pixFormat;
CHECK_AND_RETURN_RET_LOG(pixFormat.size() != 0, pixFormat, "GetSupportedFormats failed: format is null");
return pixFormat;
@ -98,26 +102,31 @@ std::vector<int32_t> VideoCaps::GetSupportedFormats()
int32_t VideoCaps::GetSupportedHeightAlignment()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, 1, "data is null");
return data_->alignment.height;
}
int32_t VideoCaps::GetSupportedWidthAlignment()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, 1, "data is null");
return data_->alignment.width;
}
Range VideoCaps::GetSupportedWidth()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->width;
}
Range VideoCaps::GetSupportedHeight()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->height;
}
std::vector<int32_t> VideoCaps::GetSupportedProfiles()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> profiles = data_->profiles;
CHECK_AND_RETURN_RET_LOG(profiles.size() != 0, profiles, "GetSupportedProfiles failed: profiles is null");
return profiles;
@ -125,17 +134,20 @@ std::vector<int32_t> VideoCaps::GetSupportedProfiles()
std::vector<int32_t> VideoCaps::GetSupportedLevels()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> levels;
return levels;
}
Range VideoCaps::GetSupportedEncodeQuality()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->encodeQuality;
}
bool VideoCaps::IsSizeSupported(int32_t width, int32_t height)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, false, "data is null");
UpdateParams();
if (width <= 0 || height <= 0) {
return false;
@ -160,6 +172,7 @@ bool VideoCaps::IsSizeSupported(int32_t width, int32_t height)
Range VideoCaps::GetVideoWidthRangeForHeight(int32_t height)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
if (height < data_->height.minVal || height > data_->height.maxVal) {
return Range(0, 0);
}
@ -181,6 +194,7 @@ Range VideoCaps::GetVideoWidthRangeForHeight(int32_t height)
Range VideoCaps::GetVideoHeightRangeForWidth(int32_t width)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
if (width < data_->width.minVal || width > data_->width.maxVal) {
return Range(0, 0);
}
@ -202,11 +216,13 @@ Range VideoCaps::GetVideoHeightRangeForWidth(int32_t width)
Range VideoCaps::GetSupportedFrameRate()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->frameRate;
}
Range VideoCaps::GetSupportedFrameRatesFor(int32_t width, int32_t height)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
if (!IsSizeSupported(width, height)) {
AVCODEC_LOGD("The %{public}s can not support of:%{public}d * %{public}d", data_->codecName.c_str(), width,
height);
@ -423,6 +439,7 @@ int32_t VideoCaps::DivCeil(const int32_t &dividend, const int32_t &divisor)
bool VideoCaps::IsSizeAndRateSupported(int32_t width, int32_t height, double frameRate)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, false, "data is null");
if (!IsSizeSupported(width, height)) {
AVCODEC_LOGD("The %{public}s can not support of:%{public}d * %{public}d", data_->codecName.c_str(), width,
height);
@ -438,6 +455,7 @@ bool VideoCaps::IsSizeAndRateSupported(int32_t width, int32_t height, double fra
Range VideoCaps::GetPreferredFrameRate(int32_t width, int32_t height)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
Range range;
if (!IsSizeSupported(width, height)) {
AVCODEC_LOGD("The %{public}s can not support of:%{public}d * %{public}d", data_->codecName.c_str(), width,
@ -486,6 +504,7 @@ ImgSize VideoCaps::MatchClosestSize(const ImgSize &imgSize)
std::vector<int32_t> VideoCaps::GetSupportedBitrateMode()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> bitrateMode = data_->bitrateMode;
CHECK_AND_RETURN_RET_LOG(bitrateMode.size() != 0, bitrateMode, "GetSupportedBitrateMode failed: get null");
return bitrateMode;
@ -493,17 +512,20 @@ std::vector<int32_t> VideoCaps::GetSupportedBitrateMode()
Range VideoCaps::GetSupportedQuality()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
Range quality;
return quality;
}
Range VideoCaps::GetSupportedComplexity()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->complexity;
}
bool VideoCaps::IsSupportDynamicIframe()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, false, "data is null");
return false;
}
@ -519,6 +541,7 @@ AudioCaps::~AudioCaps()
std::shared_ptr<AVCodecInfo> AudioCaps::GetCodecInfo()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, nullptr, "data is null");
std::shared_ptr<AVCodecInfo> codecInfo = std::make_shared<AVCodecInfo>(data_);
CHECK_AND_RETURN_RET_LOG(codecInfo != nullptr, nullptr, "create codecInfo failed");
return codecInfo;
@ -526,16 +549,19 @@ std::shared_ptr<AVCodecInfo> AudioCaps::GetCodecInfo()
Range AudioCaps::GetSupportedBitrate()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->bitrate;
}
Range AudioCaps::GetSupportedChannel()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->channels;
}
std::vector<int32_t> AudioCaps::GetSupportedFormats()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> bitDepth = data_->bitDepth;
CHECK_AND_RETURN_RET_LOG(bitDepth.size() != 0, bitDepth, "GetSupportedFormats failed: format is null");
return bitDepth;
@ -543,6 +569,7 @@ std::vector<int32_t> AudioCaps::GetSupportedFormats()
std::vector<int32_t> AudioCaps::GetSupportedSampleRates()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> sampleRate = data_->sampleRate;
CHECK_AND_RETURN_RET_LOG(sampleRate.size() != 0, sampleRate, "GetSupportedSampleRates failed: sampleRate is null");
return sampleRate;
@ -550,6 +577,7 @@ std::vector<int32_t> AudioCaps::GetSupportedSampleRates()
std::vector<int32_t> AudioCaps::GetSupportedProfiles()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> profiles = data_->profiles;
CHECK_AND_RETURN_RET_LOG(profiles.size() != 0, profiles, "GetSupportedProfiles failed: profiles is null");
return profiles;
@ -557,12 +585,14 @@ std::vector<int32_t> AudioCaps::GetSupportedProfiles()
std::vector<int32_t> AudioCaps::GetSupportedLevels()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, std::vector<int32_t>(), "data is null");
std::vector<int32_t> empty;
return empty;
}
Range AudioCaps::GetSupportedComplexity()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, Range(), "data is null");
return data_->complexity;
}
@ -578,6 +608,7 @@ AVCodecInfo::~AVCodecInfo()
std::string AVCodecInfo::GetName()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, "", "data is null");
std::string name = data_->codecName;
CHECK_AND_RETURN_RET_LOG(name != "", "", "get codec name is null");
return name;
@ -585,6 +616,7 @@ std::string AVCodecInfo::GetName()
AVCodecType AVCodecInfo::GetType()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, AVCODEC_TYPE_NONE, "data is null");
AVCodecType codecType = AVCodecType(data_->codecType);
CHECK_AND_RETURN_RET_LOG(codecType != AVCODEC_TYPE_NONE, AVCODEC_TYPE_NONE, "can not find codec type");
return codecType;
@ -592,6 +624,7 @@ AVCodecType AVCodecInfo::GetType()
std::string AVCodecInfo::GetMimeType()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, "", "data is null");
std::string mimeType = data_->mimeType;
CHECK_AND_RETURN_RET_LOG(mimeType != "", "", "get mimeType is null");
return mimeType;
@ -599,26 +632,32 @@ std::string AVCodecInfo::GetMimeType()
bool AVCodecInfo::IsHardwareAccelerated()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, false, "data is null");
return data_->isVendor;
}
int32_t AVCodecInfo::GetMaxSupportedInstances()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, 0, "data is null");
return data_->maxInstance;
}
bool AVCodecInfo::IsSoftwareOnly()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, false, "data is null");
return !data_->isVendor;
}
bool AVCodecInfo::IsVendor()
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, false, "data is null");
return data_->isVendor;
}
std::map<int32_t, std::vector<int32_t>> AVCodecInfo::GetSupportedLevelsForProfile()
{
std::map<int32_t, std::vector<int32_t>> empty = std::map<int32_t, std::vector<int32_t>>();
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, empty, "data is null");
return data_->profileLevelsMap;
}
@ -630,6 +669,7 @@ bool AVCodecInfo::IsFeatureValid(AVCapabilityFeature feature)
bool AVCodecInfo::IsFeatureSupported(AVCapabilityFeature feature)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, false, "data is null");
CHECK_AND_RETURN_RET_LOG(IsFeatureValid(feature), false,
"Varified feature failed: feature %{public}d is invalid", feature);
return data_->featuresMap.count(static_cast<int32_t>(feature)) != 0;
@ -637,6 +677,7 @@ bool AVCodecInfo::IsFeatureSupported(AVCapabilityFeature feature)
int32_t AVCodecInfo::GetFeatureProperties(AVCapabilityFeature feature, Format &format)
{
CHECK_AND_RETURN_RET_LOG(data_ != nullptr, AVCS_ERR_INVALID_VAL, "data is null");
CHECK_AND_RETURN_RET_LOG(IsFeatureValid(feature), AVCS_ERR_INVALID_VAL,
"Get feature properties failed: invalid feature %{public}d", feature);
auto itr = data_->featuresMap.find(static_cast<int32_t>(feature));

View File

@ -369,7 +369,9 @@ void FFmpegDemuxerPlugin::ParserFirstDts()
bool isEnd = false;
bool isFirst = true;
while (!isEnd) {
std::unique_lock<std::mutex> sLock(syncMutex_);
int ffmpegRet = av_read_frame(parserRefFormatContext_.get(), pkt);
sLock.unlock();
if (ffmpegRet < 0) {
av_packet_unref(pkt);
av_packet_free(&pkt);
@ -421,7 +423,7 @@ Status FFmpegDemuxerPlugin::ParserRefInit()
if (stream->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
stream->discard = AVDISCARD_ALL;
} else {
parserRefVideoStreamIdx_ = trackIndex;
parserRefVideoStreamIdx_ = static_cast<uint32_t>(trackIndex);
}
}
FALSE_RETURN_V_MSG_E(parserRefVideoStreamIdx_ >= 0, Status::ERROR_UNKNOWN, "Can not find video stream.");

View File

@ -93,6 +93,7 @@ const std::map<std::string, std::string> CAPABILITY_ENCODER_HARD_NAME = {
const std::string DEFAULT_AUDIO_MIME = std::string(CodecMimeType::AUDIO_AAC);
const std::string DEFAULT_VIDEO_MIME = std::string(CodecMimeType::VIDEO_AVC);
const std::string DEFAULT_UNSUPPORTED_MIME = std::string(CodecMimeType::IMAGE_PNG);
constexpr int32_t MAX_SURPPORT_ACODEC = 16;
constexpr int32_t MAX_SURPPORT_VCODEC = 64;

View File

@ -707,4 +707,78 @@ HWTEST_F(CodecListUnitTest, CodecList_AreProfileAndLevelSupported_002, TestSize.
EXPECT_FALSE(capability_->AreProfileAndLevelSupported(ERROR_VIDEO_AVC_PROFILE, DEFAULT_LEVEL));
// case 3, negative param
EXPECT_FALSE(capability_->AreProfileAndLevelSupported(ERROR_VIDEO_AVC_PROFILE, ERROR_LEVEL));
}
/**
* @tc.name: CodecList_UNSUPPORTED_MIME_001
* @tc.desc: CodecList use unsupprted mime
* @tc.type: FUNC
*/
HWTEST_F(CodecListUnitTest, CodecList_UNSUPPORTED_MIME_001, TestSize.Level1)
{
capability_ = CodecListMockFactory::GetCapabilityByCategory(
DEFAULT_UNSUPPORTED_MIME, false, ::AVCodecCategory::AVCODEC_NONE);
if (capability_ != nullptr) {
EXPECT_EQ(capability_->GetName(), "");
EXPECT_EQ(capability_->IsHardware(), false);
EXPECT_EQ(capability_->IsEncoderBitrateModeSupported(OH_BitrateMode::BITRATE_MODE_CBR), false);
EXPECT_EQ(capability_->IsVideoSizeSupported(DEFAULT_WIDTH, DEFAULT_HEIGHT), false);
EXPECT_EQ(capability_->AreVideoSizeAndFrameRateSupported(
DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FRAMERATE), false);
EXPECT_EQ(capability_->AreProfileAndLevelSupported(DEFAULT_VIDEO_AVC_PROFILE, DEFAULT_LEVEL), false);
EXPECT_EQ(capability_->GetMaxSupportedInstances(), 0);
EXPECT_EQ(capability_->GetVideoWidthAlignment(), 1);
EXPECT_EQ(capability_->GetVideoHeightAlignment(), 1);
std::vector<int32_t> sampleRates = capability_->GetAudioSupportedSampleRates();
EXPECT_EQ(sampleRates.size(), 0);
std::vector<int32_t> profiles = capability_->GetSupportedProfiles();
EXPECT_EQ(profiles.size(), 0);
std::vector<int32_t> pixFormats = capability_->GetVideoSupportedPixelFormats();
EXPECT_EQ(pixFormats.size(), 0);
std::vector<int32_t> levels = capability_->GetSupportedLevelsForProfile(DEFAULT_VIDEO_AVC_PROFILE);
EXPECT_EQ(levels.size(), 0);
}
}
/**
* @tc.name: CodecList_UNSUPPORTED_MIME_002
* @tc.desc: CodecList use unsupprted mime
* @tc.type: FUNC
*/
HWTEST_F(CodecListUnitTest, CodecList_UNSUPPORTED_MIME_002, TestSize.Level1)
{
capability_ = CodecListMockFactory::GetCapabilityByCategory(
DEFAULT_UNSUPPORTED_MIME, false, AVCodecCategory::AVCODEC_SOFTWARE);
if (capability_ != nullptr) {
Range range = capability_->GetEncoderBitrateRange();
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetEncoderQualityRange();
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetEncoderComplexityRange();
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetAudioChannelsRange();
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetVideoWidthRangeForHeight(DEFAULT_HEIGHT);
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetVideoHeightRangeForWidth(DEFAULT_WIDTH);
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetVideoWidthRange();
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetVideoHeightRange();
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetVideoFrameRateRange();
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
range = capability_->GetVideoFrameRateRangeForSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
EXPECT_EQ(0, range.minVal);
EXPECT_EQ(0, range.maxVal);
}
}

View File

@ -223,7 +223,7 @@ std::vector<int32_t> CodecListInnerMock::GetVideoSupportedPixelFormats()
std::vector<int32_t> CodecListInnerMock::GetSupportedProfiles()
{
if (codeclist_ != nullptr) {
if (codeclist_ != nullptr && capabilityData_ != nullptr) {
std::vector<int32_t> ret;
if (capabilityData_->codecType == AVCODEC_TYPE_VIDEO_ENCODER ||
capabilityData_->codecType == AVCODEC_TYPE_VIDEO_DECODER) {
@ -237,7 +237,7 @@ std::vector<int32_t> CodecListInnerMock::GetSupportedProfiles()
std::sort(ret.begin(), ret.end());
return ret;
}
std::cout << "codeclist_ is nullptr" << std::endl;
std::cout << "codeclist_ or capabilityData_ is nullptr" << std::endl;
return std::vector<int32_t>();
}