mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2025-03-01 15:46:55 +00:00
parameter接口实现编译通过
Signed-off-by: linziming <linziming2@huawei.com> Change-Id: I6566c80df5692103c936df78b457a70c73cc3633
This commit is contained in:
parent
27afdca1bd
commit
74325dcbfa
@ -138,8 +138,6 @@ int32_t AVCodecVideoDecoderImpl::SetOutputSurface(sptr<Surface> surface)
|
||||
int32_t AVCodecVideoDecoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::MEMORY_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback of AVSharedMemory is invalid!");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->QueueInputBuffer(index, info, flag);
|
||||
@ -148,8 +146,6 @@ int32_t AVCodecVideoDecoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferI
|
||||
int32_t AVCodecVideoDecoderImpl::QueueInputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::BUFFER_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback of AVBuffer is invalid!");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->QueueInputBuffer(index);
|
||||
@ -166,8 +162,7 @@ int32_t AVCodecVideoDecoderImpl::GetOutputFormat(Format &format)
|
||||
int32_t AVCodecVideoDecoderImpl::ReleaseOutputBuffer(uint32_t index, bool render)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag != CallbackFlag::INVALID_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback is invalid!");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->ReleaseOutputBuffer(index, render);
|
||||
}
|
||||
@ -184,9 +179,6 @@ int32_t AVCodecVideoDecoderImpl::SetCallback(const std::shared_ptr<AVCodecCallba
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_INVALID_VAL, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::MEMORY_CALLBACK || cbFlag == CallbackFlag::INVALID_CALLBACK,
|
||||
AVCS_ERR_INVALID_STATE, "The callback of AVBuffer is already set!");
|
||||
cbFlag = CallbackFlag::MEMORY_CALLBACK;
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->SetCallback(callback);
|
||||
@ -196,9 +188,6 @@ int32_t AVCodecVideoDecoderImpl::SetCallback(const std::shared_ptr<MediaCodecCal
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_INVALID_VAL, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::BUFFER_CALLBACK || cbFlag == CallbackFlag::INVALID_CALLBACK,
|
||||
AVCS_ERR_INVALID_STATE, "The callback of AVSharedMemory is already set!");
|
||||
cbFlag = CallbackFlag::BUFFER_CALLBACK;
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->SetCallback(callback);
|
||||
|
@ -48,12 +48,6 @@ public:
|
||||
int32_t Init(AVCodecType type, bool isMimeType, const std::string &name);
|
||||
|
||||
private:
|
||||
enum class CallbackFlag : uint8_t {
|
||||
MEMORY_CALLBACK = 1,
|
||||
BUFFER_CALLBACK,
|
||||
INVALID_CALLBACK,
|
||||
};
|
||||
CallbackFlag cbFlag = CallbackFlag::INVALID_CALLBACK;
|
||||
std::shared_ptr<ICodecService> codecService_ = nullptr;
|
||||
};
|
||||
} // namespace MediaAVCodec
|
||||
|
@ -14,9 +14,9 @@
|
||||
*/
|
||||
|
||||
#include "avcodec_video_encoder_impl.h"
|
||||
#include "avcodec_trace.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "avcodec_log.h"
|
||||
#include "avcodec_trace.h"
|
||||
#include "i_avcodec_service.h"
|
||||
|
||||
namespace {
|
||||
@ -141,15 +141,12 @@ sptr<Surface> AVCodecVideoEncoderImpl::CreateInputSurface()
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, nullptr, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
surface_ = codecService_->CreateInputSurface();
|
||||
return surface_;
|
||||
return codecService_->CreateInputSurface();
|
||||
}
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::MEMORY_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback of AVSharedMemory is invalid!");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->QueueInputBuffer(index, info, flag);
|
||||
@ -158,13 +155,19 @@ int32_t AVCodecVideoEncoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferI
|
||||
int32_t AVCodecVideoEncoderImpl::QueueInputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::BUFFER_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback of AVBuffer is invalid!");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->QueueInputBuffer(index);
|
||||
}
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::QueueInputParameter(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->QueueInputParameter(index);
|
||||
}
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::GetOutputFormat(Format &format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
@ -176,8 +179,7 @@ int32_t AVCodecVideoEncoderImpl::GetOutputFormat(Format &format)
|
||||
int32_t AVCodecVideoEncoderImpl::ReleaseOutputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag != CallbackFlag::INVALID_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback is invalid!");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->ReleaseOutputBuffer(index);
|
||||
}
|
||||
@ -194,10 +196,6 @@ int32_t AVCodecVideoEncoderImpl::SetCallback(const std::shared_ptr<AVCodecCallba
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_INVALID_VAL, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::MEMORY_CALLBACK || cbFlag == CallbackFlag::INVALID_CALLBACK,
|
||||
AVCS_ERR_INVALID_STATE, "The callback of AVBuffer is already set!");
|
||||
cbFlag = CallbackFlag::MEMORY_CALLBACK;
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->SetCallback(callback);
|
||||
}
|
||||
@ -206,9 +204,15 @@ int32_t AVCodecVideoEncoderImpl::SetCallback(const std::shared_ptr<MediaCodecCal
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "service died");
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_INVALID_VAL, "callback is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(cbFlag == CallbackFlag::BUFFER_CALLBACK || cbFlag == CallbackFlag::INVALID_CALLBACK,
|
||||
AVCS_ERR_INVALID_STATE, "The callback of AVSharedMemory is already set!");
|
||||
cbFlag = CallbackFlag::BUFFER_CALLBACK;
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->SetCallback(callback);
|
||||
}
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, AVCS_ERR_INVALID_OPERATION, "service died");
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_INVALID_VAL, "callback is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
return codecService_->SetCallback(callback);
|
||||
|
@ -48,14 +48,7 @@ public:
|
||||
int32_t Init(AVCodecType type, bool isMimeType, const std::string &name);
|
||||
|
||||
private:
|
||||
enum class CallbackFlag : uint8_t {
|
||||
MEMORY_CALLBACK = 1,
|
||||
BUFFER_CALLBACK,
|
||||
INVALID_CALLBACK,
|
||||
};
|
||||
CallbackFlag cbFlag = CallbackFlag::INVALID_CALLBACK;
|
||||
std::shared_ptr<ICodecService> codecService_ = nullptr;
|
||||
sptr<Surface> surface_ = nullptr;
|
||||
};
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
||||
|
@ -62,8 +62,9 @@ struct VideoDecoderObject : public OH_AVCodec {
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVMemory>> inputMemoryMap_;
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVBuffer>> outputBufferMap_;
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVBuffer>> inputBufferMap_;
|
||||
std::shared_ptr<NativeVideoDecoderCallback> memoryCallback_ = nullptr;
|
||||
std::shared_ptr<VideoDecoderCallback> bufferCallback_ = nullptr;
|
||||
std::shared_ptr<NativeVideoDecoderCallback> callback_ = nullptr;
|
||||
bool isSetMemoryCallback_ = false;
|
||||
bool isSetBufferCallback_ = false;
|
||||
std::atomic<bool> isFlushing_ = false;
|
||||
std::atomic<bool> isFlushed_ = false;
|
||||
std::atomic<bool> isStop_ = false;
|
||||
@ -72,9 +73,13 @@ struct VideoDecoderObject : public OH_AVCodec {
|
||||
std::shared_mutex objListMutex_;
|
||||
};
|
||||
|
||||
class NativeVideoDecoderCallback : public AVCodecCallback {
|
||||
class NativeVideoDecoderCallback : public AVCodecCallback, public MediaCodecCallback {
|
||||
public:
|
||||
NativeVideoDecoderCallback(OH_AVCodec *codec, struct OH_AVCodecAsyncCallback cb, void *userData)
|
||||
: codec_(codec), asyncCallback_(cb), userData_(userData)
|
||||
{
|
||||
}
|
||||
NativeVideoDecoderCallback(OH_AVCodec *codec, struct OH_AVCodecCallback cb, void *userData)
|
||||
: codec_(codec), callback_(cb), userData_(userData)
|
||||
{
|
||||
}
|
||||
@ -86,9 +91,14 @@ public:
|
||||
(void)errorType;
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onError != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onError != nullptr || callback_.onError != nullptr, "Callback is nullptr");
|
||||
int32_t extErr = AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(errorCode));
|
||||
callback_.onError(codec_, extErr, userData_);
|
||||
if (asyncCallback_.onError != nullptr) {
|
||||
asyncCallback_.onError(codec_, extErr, userData_);
|
||||
} else if (callback_.onError != nullptr) {
|
||||
callback_.onError(codec_, extErr, userData_);
|
||||
}
|
||||
}
|
||||
|
||||
void OnOutputFormatChanged(const Format &format) override
|
||||
@ -96,9 +106,17 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onStreamChanged != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onStreamChanged != nullptr || callback_.onStreamChanged != nullptr,
|
||||
"Callback is nullptr");
|
||||
OHOS::sptr<OH_AVFormat> object = new (std::nothrow) OH_AVFormat(format);
|
||||
callback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
CHECK_AND_RETURN_LOG(object != nullptr, "OH_AVFormat create failed");
|
||||
// The object lifecycle is controlled by the current function stack
|
||||
if (asyncCallback_.onError != nullptr) {
|
||||
asyncCallback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
} else if (callback_.onError != nullptr) {
|
||||
callback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
}
|
||||
}
|
||||
|
||||
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) override
|
||||
@ -106,7 +124,8 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNeedInputData != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onNeedInputData != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoDecObj->videoDecoder_ != nullptr, "Video decoder is nullptr!");
|
||||
@ -118,7 +137,7 @@ public:
|
||||
}
|
||||
|
||||
OH_AVMemory *data = GetTransData(codec_, index, buffer, false);
|
||||
callback_.onNeedInputData(codec_, index, data, userData_);
|
||||
asyncCallback_.onNeedInputData(codec_, index, data, userData_);
|
||||
}
|
||||
|
||||
void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
|
||||
@ -127,7 +146,8 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNeedOutputData != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onNeedOutputData != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoDecObj->videoDecoder_ != nullptr, "Video decoder is nullptr!");
|
||||
@ -148,85 +168,7 @@ public:
|
||||
if (!((flag == AVCODEC_BUFFER_FLAG_CODEC_DATA) || (flag == AVCODEC_BUFFER_FLAG_EOS))) {
|
||||
AVCodecTrace::TraceEnd("OH::Frame", info.presentationTimeUs);
|
||||
}
|
||||
callback_.onNeedOutputData(codec_, index, data, &bufferAttr, userData_);
|
||||
}
|
||||
|
||||
void StopCallback()
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
codec_ = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
OH_AVMemory *GetTransData(struct OH_AVCodec *codec, uint32_t &index, std::shared_ptr<AVSharedMemory> &memory,
|
||||
bool isOutput)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, nullptr, "Codec magic error!");
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, nullptr, "Video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, nullptr, "Memory is nullptr, get buffer failed!");
|
||||
|
||||
auto &memoryMap = isOutput ? videoDecObj->outputMemoryMap_ : videoDecObj->inputMemoryMap_;
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(videoDecObj->objListMutex_);
|
||||
auto iter = memoryMap.find(index);
|
||||
if (iter != memoryMap.end() && iter->second->IsEqualMemory(memory)) {
|
||||
return reinterpret_cast<OH_AVMemory *>(iter->second.GetRefPtr());
|
||||
}
|
||||
}
|
||||
|
||||
OHOS::sptr<OH_AVMemory> object = new (std::nothrow) OH_AVMemory(memory);
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "AV memory create failed");
|
||||
|
||||
std::lock_guard<std::shared_mutex> lock(videoDecObj->objListMutex_);
|
||||
auto iterAndRet = memoryMap.emplace(index, object);
|
||||
if (!iterAndRet.second) {
|
||||
auto &temp = iterAndRet.first->second;
|
||||
temp->magic_ = MFMagic::MFMAGIC_UNKNOWN;
|
||||
temp->memory_ = nullptr;
|
||||
videoDecObj->tempList_.push(std::move(temp));
|
||||
iterAndRet.first->second = object;
|
||||
if (videoDecObj->tempList_.size() > MAX_TEMPNUM) {
|
||||
videoDecObj->tempList_.pop();
|
||||
}
|
||||
}
|
||||
return reinterpret_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
}
|
||||
|
||||
struct OH_AVCodec *codec_;
|
||||
struct OH_AVCodecAsyncCallback callback_;
|
||||
void *userData_;
|
||||
std::shared_mutex mutex_;
|
||||
};
|
||||
|
||||
class VideoDecoderCallback : public MediaCodecCallback {
|
||||
public:
|
||||
VideoDecoderCallback(OH_AVCodec *codec, struct OH_AVCodecCallback cb, void *userData)
|
||||
: codec_(codec), callback_(cb), userData_(userData)
|
||||
{
|
||||
}
|
||||
virtual ~VideoDecoderCallback() = default;
|
||||
|
||||
void OnError(AVCodecErrorType errorType, int32_t errorCode) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
(void)errorType;
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onError != nullptr, "Callback is nullptr");
|
||||
int32_t extErr = AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(errorCode));
|
||||
callback_.onError(codec_, extErr, userData_);
|
||||
}
|
||||
|
||||
void OnOutputFormatChanged(const Format &format) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onStreamChanged != nullptr, "Callback is nullptr");
|
||||
OHOS::sptr<OH_AVFormat> object = new (std::nothrow) OH_AVFormat(format);
|
||||
callback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
asyncCallback_.onNeedOutputData(codec_, index, data, &bufferAttr, userData_);
|
||||
}
|
||||
|
||||
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override
|
||||
@ -234,6 +176,7 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNeedInputBuffer != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec_);
|
||||
@ -254,6 +197,7 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNewOutputBuffer != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec_);
|
||||
@ -279,14 +223,41 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
OH_AVMemory *GetTransData(struct OH_AVCodec *codec, uint32_t &index, std::shared_ptr<AVSharedMemory> &memory,
|
||||
bool isOutput)
|
||||
{
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
auto &memoryMap = isOutput ? videoDecObj->outputMemoryMap_ : videoDecObj->inputMemoryMap_;
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(videoDecObj->objListMutex_);
|
||||
auto iter = memoryMap.find(index);
|
||||
if (iter != memoryMap.end() && iter->second->IsEqualMemory(memory)) {
|
||||
return reinterpret_cast<OH_AVMemory *>(iter->second.GetRefPtr());
|
||||
}
|
||||
}
|
||||
|
||||
OHOS::sptr<OH_AVMemory> object = new (std::nothrow) OH_AVMemory(memory);
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "AV memory create failed");
|
||||
|
||||
std::lock_guard<std::shared_mutex> lock(videoDecObj->objListMutex_);
|
||||
memoryMap[index] = object;
|
||||
auto iterAndRet = memoryMap.emplace(index, object);
|
||||
if (!iterAndRet.second) {
|
||||
auto &temp = iterAndRet.first->second;
|
||||
temp->magic_ = MFMagic::MFMAGIC_UNKNOWN;
|
||||
temp->memory_ = nullptr;
|
||||
videoDecObj->tempList_.push(std::move(temp));
|
||||
iterAndRet.first->second = object;
|
||||
if (videoDecObj->tempList_.size() > MAX_TEMPNUM) {
|
||||
videoDecObj->tempList_.pop();
|
||||
}
|
||||
}
|
||||
return reinterpret_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
}
|
||||
|
||||
OH_AVBuffer *GetTransData(struct OH_AVCodec *codec, uint32_t index, std::shared_ptr<AVBuffer> buffer, bool isOutput)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_DECODER, nullptr, "magic error!");
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, nullptr, "video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(buffer != nullptr, nullptr, "get buffer is nullptr!");
|
||||
auto &bufferMap = isOutput ? videoDecObj->outputBufferMap_ : videoDecObj->inputBufferMap_;
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(videoDecObj->objListMutex_);
|
||||
@ -315,6 +286,7 @@ private:
|
||||
}
|
||||
|
||||
struct OH_AVCodec *codec_;
|
||||
struct OH_AVCodecAsyncCallback asyncCallback_;
|
||||
struct OH_AVCodecCallback callback_;
|
||||
void *userData_;
|
||||
std::shared_mutex mutex_;
|
||||
@ -323,12 +295,12 @@ private:
|
||||
void VideoDecoderObject::ClearBufferList()
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(objListMutex_);
|
||||
if (bufferCallback_ != nullptr) {
|
||||
if (isSetBufferCallback_) {
|
||||
BufferToTempFunc(inputBufferMap_);
|
||||
BufferToTempFunc(outputBufferMap_);
|
||||
inputBufferMap_.clear();
|
||||
outputBufferMap_.clear();
|
||||
} else if (memoryCallback_ != nullptr) {
|
||||
} else if (isSetMemoryCallback_) {
|
||||
MemoryToTempFunc(inputMemoryMap_);
|
||||
MemoryToTempFunc(outputMemoryMap_);
|
||||
inputMemoryMap_.clear();
|
||||
@ -341,11 +313,10 @@ void VideoDecoderObject::ClearBufferList()
|
||||
|
||||
void VideoDecoderObject::StopCallback()
|
||||
{
|
||||
if (bufferCallback_ != nullptr) {
|
||||
bufferCallback_->StopCallback();
|
||||
} else if (memoryCallback_ != nullptr) {
|
||||
memoryCallback_->StopCallback();
|
||||
if (callback_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
callback_->StopCallback();
|
||||
}
|
||||
|
||||
void VideoDecoderObject::BufferToTempFunc(std::unordered_map<uint32_t, OHOS::sptr<OH_AVBuffer>> &tempMap)
|
||||
@ -562,7 +533,7 @@ OH_AVErrCode OH_VideoDecoder_PushInputData(struct OH_AVCodec *codec, uint32_t in
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "Video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->memoryCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->isSetMemoryCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVMemory is nullptr!");
|
||||
|
||||
if (!((attr.flags == AVCODEC_BUFFER_FLAG_CODEC_DATA) || (attr.flags == AVCODEC_BUFFER_FLAG_EOS))) {
|
||||
@ -592,7 +563,7 @@ OH_AVErrCode OH_VideoDecoder_PushInputBuffer(struct OH_AVCodec *codec, uint32_t
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->bufferCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->isSetBufferCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVBuffer is nullptr!");
|
||||
|
||||
{
|
||||
@ -643,7 +614,7 @@ OH_AVErrCode OH_VideoDecoder_RenderOutputData(struct OH_AVCodec *codec, uint32_t
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "Video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->memoryCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->isSetMemoryCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVMemory is nullptr!");
|
||||
|
||||
int32_t ret = videoDecObj->videoDecoder_->ReleaseOutputBuffer(index, true);
|
||||
@ -662,7 +633,7 @@ OH_AVErrCode OH_VideoDecoder_FreeOutputData(struct OH_AVCodec *codec, uint32_t i
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "Video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->memoryCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->isSetMemoryCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVMemory is nullptr!");
|
||||
|
||||
int32_t ret = videoDecObj->videoDecoder_->ReleaseOutputBuffer(index, false);
|
||||
@ -679,7 +650,7 @@ OH_AVErrCode OH_VideoDecoder_RenderOutputBuffer(struct OH_AVCodec *codec, uint32
|
||||
"Codec magic error!");
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "Video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->bufferCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->isSetBufferCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVBuffer is nullptr!");
|
||||
|
||||
int32_t ret = videoDecObj->videoDecoder_->ReleaseOutputBuffer(index, true);
|
||||
@ -698,7 +669,7 @@ OH_AVErrCode OH_VideoDecoder_FreeOutputBuffer(struct OH_AVCodec *codec, uint32_t
|
||||
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "Video decoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->bufferCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->isSetBufferCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVBuffer is nullptr!");
|
||||
|
||||
int32_t ret = videoDecObj->videoDecoder_->ReleaseOutputBuffer(index, false);
|
||||
@ -736,10 +707,12 @@ OH_AVErrCode OH_VideoDecoder_SetCallback(struct OH_AVCodec *codec, struct OH_AVC
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "Video decoder is nullptr!");
|
||||
|
||||
videoDecObj->memoryCallback_ = std::make_shared<NativeVideoDecoderCallback>(codec, callback, userData);
|
||||
int32_t ret = videoDecObj->videoDecoder_->SetCallback(videoDecObj->memoryCallback_);
|
||||
videoDecObj->callback_ = std::make_shared<NativeVideoDecoderCallback>(codec, callback, userData);
|
||||
int32_t ret =
|
||||
videoDecObj->videoDecoder_->SetCallback(std::static_pointer_cast<AVCodecCallback>(videoDecObj->callback_));
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(ret)),
|
||||
"Video decoder set callback failed!");
|
||||
videoDecObj->isSetMemoryCallback_ = true;
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
@ -757,10 +730,12 @@ OH_AVErrCode OH_VideoDecoder_RegisterCallback(struct OH_AVCodec *codec, struct O
|
||||
struct VideoDecoderObject *videoDecObj = reinterpret_cast<VideoDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "Video decoder is nullptr!");
|
||||
|
||||
videoDecObj->bufferCallback_ = std::make_shared<VideoDecoderCallback>(codec, callback, userData);
|
||||
int32_t ret = videoDecObj->videoDecoder_->SetCallback(videoDecObj->bufferCallback_);
|
||||
videoDecObj->callback_ = std::make_shared<NativeVideoDecoderCallback>(codec, callback, userData);
|
||||
int32_t ret =
|
||||
videoDecObj->videoDecoder_->SetCallback(std::static_pointer_cast<MediaCodecCallback>(videoDecObj->callback_));
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(ret)),
|
||||
"Video decoder set callback failed!");
|
||||
"Video decoder register callback failed!");
|
||||
videoDecObj->isSetBufferCallback_ = true;
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -49,17 +49,20 @@ struct VideoEncoderObject : public OH_AVCodec {
|
||||
|
||||
void ClearBufferList();
|
||||
void StopCallback();
|
||||
void FormatToTempFunc(std::unordered_map<uint32_t, OHOS::sptr<OH_AVFormat>> &tempMap);
|
||||
void BufferToTempFunc(std::unordered_map<uint32_t, OHOS::sptr<OH_AVBuffer>> &tempMap);
|
||||
void MemoryToTempFunc(std::unordered_map<uint32_t, OHOS::sptr<OH_AVMemory>> &tempMap);
|
||||
|
||||
const std::shared_ptr<AVCodecVideoEncoder> videoEncoder_;
|
||||
std::queue<OHOS::sptr<MFObjectMagic>> tempList_;
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVFormat>> inputFormatMap_;
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVMemory>> outputMemoryMap_;
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVMemory>> inputMemoryMap_;
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVBuffer>> outputBufferMap_;
|
||||
std::unordered_map<uint32_t, OHOS::sptr<OH_AVBuffer>> inputBufferMap_;
|
||||
std::shared_ptr<NativeVideoEncoderCallback> memoryCallback_ = nullptr;
|
||||
std::shared_ptr<VideoEncoderCallback> bufferCallback_ = nullptr;
|
||||
std::shared_ptr<NativeVideoEncoderCallback> callback_ = nullptr;
|
||||
bool isSetMemoryCallback_ = false;
|
||||
bool isSetBufferCallback_ = false;
|
||||
std::atomic<bool> isFlushing_ = false;
|
||||
std::atomic<bool> isFlushed_ = false;
|
||||
std::atomic<bool> isStop_ = false;
|
||||
@ -68,9 +71,21 @@ struct VideoEncoderObject : public OH_AVCodec {
|
||||
std::shared_mutex objListMutex_;
|
||||
};
|
||||
|
||||
class NativeVideoEncoderCallback : public AVCodecCallback {
|
||||
class NativeVideoEncoderCallback : public AVCodecCallback,
|
||||
public MediaCodecCallback,
|
||||
public MediaCodecParameterCallback {
|
||||
public:
|
||||
NativeVideoEncoderCallback(OH_AVCodec *codec, struct OH_AVCodecAsyncCallback cb, void *userData)
|
||||
: codec_(codec), asyncCallback_(cb), userData_(userData)
|
||||
{
|
||||
}
|
||||
|
||||
NativeVideoEncoderCallback(OH_AVCodec *codec, OH_VideoEncoder_OnNeedInputParameter onInputParameter, void *userData)
|
||||
: codec_(codec), onInputParameter_(onInputParameter), userData_(userData)
|
||||
{
|
||||
}
|
||||
|
||||
NativeVideoEncoderCallback(OH_AVCodec *codec, struct OH_AVCodecCallback cb, void *userData)
|
||||
: codec_(codec), callback_(cb), userData_(userData)
|
||||
{
|
||||
}
|
||||
@ -82,9 +97,14 @@ public:
|
||||
(void)errorType;
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onError != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onError != nullptr || callback_.onError != nullptr, "Callback is nullptr");
|
||||
int32_t extErr = AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(errorCode));
|
||||
callback_.onError(codec_, extErr, userData_);
|
||||
if (asyncCallback_.onError != nullptr) {
|
||||
asyncCallback_.onError(codec_, extErr, userData_);
|
||||
} else if (callback_.onError != nullptr) {
|
||||
callback_.onError(codec_, extErr, userData_);
|
||||
}
|
||||
}
|
||||
|
||||
void OnOutputFormatChanged(const Format &format) override
|
||||
@ -92,10 +112,17 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onStreamChanged != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onStreamChanged != nullptr || callback_.onStreamChanged != nullptr,
|
||||
"Callback is nullptr");
|
||||
OHOS::sptr<OH_AVFormat> object = new (std::nothrow) OH_AVFormat(format);
|
||||
CHECK_AND_RETURN_LOG(object != nullptr, "OH_AVFormat create failed");
|
||||
// The object lifecycle is controlled by the current function stack
|
||||
callback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
if (asyncCallback_.onError != nullptr) {
|
||||
asyncCallback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
} else if (callback_.onError != nullptr) {
|
||||
callback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
}
|
||||
}
|
||||
|
||||
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) override
|
||||
@ -103,7 +130,8 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNeedInputData != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onNeedInputData != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoEncObj->videoEncoder_ != nullptr, "Context video encoder is nullptr!");
|
||||
@ -117,7 +145,7 @@ public:
|
||||
if (!videoEncObj->isInputSurfaceMode_) {
|
||||
data = GetTransData(codec_, index, buffer, false);
|
||||
}
|
||||
callback_.onNeedInputData(codec_, index, data, userData_);
|
||||
asyncCallback_.onNeedInputData(codec_, index, data, userData_);
|
||||
}
|
||||
|
||||
void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
|
||||
@ -126,7 +154,8 @@ public:
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNeedOutputData != nullptr, "Callback is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(asyncCallback_.onNeedOutputData != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoEncObj->videoEncoder_ != nullptr, "Context video encoder is nullptr!");
|
||||
@ -145,7 +174,82 @@ public:
|
||||
if (!((flag == AVCODEC_BUFFER_FLAG_CODEC_DATA) || (flag == AVCODEC_BUFFER_FLAG_EOS))) {
|
||||
AVCodecTrace::TraceEnd("OH::Frame", info.presentationTimeUs);
|
||||
}
|
||||
callback_.onNeedOutputData(codec_, index, data, &bufferAttr, userData_);
|
||||
asyncCallback_.onNeedOutputData(codec_, index, data, &bufferAttr, userData_);
|
||||
}
|
||||
|
||||
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNeedInputBuffer != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoEncObj->videoEncoder_ != nullptr, "Context video encoder is nullptr!");
|
||||
|
||||
if (videoEncObj->isFlushing_.load() || videoEncObj->isFlushed_.load() || videoEncObj->isStop_.load() ||
|
||||
videoEncObj->isEOS_.load()) {
|
||||
AVCODEC_LOGD("At flush, eos or stop, no buffer available");
|
||||
return;
|
||||
}
|
||||
OH_AVBuffer *data = nullptr;
|
||||
if (!videoEncObj->isInputSurfaceMode_) {
|
||||
data = GetTransData(codec_, index, buffer, false);
|
||||
}
|
||||
callback_.onNeedInputBuffer(codec_, index, data, userData_);
|
||||
}
|
||||
|
||||
void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNewOutputBuffer != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoEncObj->videoEncoder_ != nullptr, "Video encoder is nullptr!");
|
||||
|
||||
if (videoEncObj->isFlushing_.load() || videoEncObj->isFlushed_.load() || videoEncObj->isStop_.load()) {
|
||||
AVCODEC_LOGD("At flush or stop, ignore");
|
||||
return;
|
||||
}
|
||||
OH_AVBuffer *data = nullptr;
|
||||
data = GetTransData(codec_, index, buffer, true);
|
||||
|
||||
if (!((buffer->flag_ == AVCODEC_BUFFER_FLAG_CODEC_DATA) || (buffer->flag_ == AVCODEC_BUFFER_FLAG_EOS))) {
|
||||
AVCodecTrace::TraceEnd("OH::Frame", buffer->pts_);
|
||||
}
|
||||
callback_.onNewOutputBuffer(codec_, index, data, userData_);
|
||||
}
|
||||
|
||||
void OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_LOG(codec_->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, "Codec magic error!");
|
||||
CHECK_AND_RETURN_LOG(onInputParameter_ != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoEncObj->videoEncoder_ != nullptr, "Video encoder is nullptr!");
|
||||
OHOS::sptr<OH_AVFormat> object = nullptr;
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> listLock(videoEncObj->objListMutex_);
|
||||
auto iter = videoEncObj->inputFormatMap_.find(index);
|
||||
if (iter != videoEncObj->inputFormatMap_.end() && iter->second->format_.GetMeta() == parameter->GetMeta()) {
|
||||
object = iter->second;
|
||||
} else {
|
||||
object = new (std::nothrow) OH_AVFormat();
|
||||
CHECK_AND_RETURN_LOG(object != nullptr, "OH_AVFormat create failed");
|
||||
object->format_ = std::move(*parameter);
|
||||
if (iter != videoEncObj->inputFormatMap_.end()) {
|
||||
iter->second = object;
|
||||
} else {
|
||||
videoEncObj->inputFormatMap_.emplace(index, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
onInputParameter_(codec_, index, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
}
|
||||
|
||||
void StopCallback()
|
||||
@ -154,16 +258,32 @@ public:
|
||||
codec_ = nullptr;
|
||||
}
|
||||
|
||||
void UpdateCallback(struct OH_AVCodecAsyncCallback cb, void *userData)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
userData_ = userData;
|
||||
asyncCallback_ = cb;
|
||||
}
|
||||
|
||||
void UpdateCallback(OH_VideoEncoder_OnNeedInputParameter onInputParameter, void *userData)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
userData_ = userData;
|
||||
onInputParameter_ = onInputParameter;
|
||||
}
|
||||
|
||||
void UpdateCallback(struct OH_AVCodecCallback cb, void *userData)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
userData_ = userData;
|
||||
callback_ = cb;
|
||||
}
|
||||
|
||||
private:
|
||||
OH_AVMemory *GetTransData(struct OH_AVCodec *codec, uint32_t &index, std::shared_ptr<AVSharedMemory> &memory,
|
||||
bool isOutput)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, nullptr, "Codec magic error!");
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, nullptr, "Video encoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, nullptr, "Memory is nullptr, get input buffer failed!");
|
||||
|
||||
auto &memoryMap = isOutput ? videoEncObj->outputMemoryMap_ : videoEncObj->inputMemoryMap_;
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(videoEncObj->objListMutex_);
|
||||
@ -191,100 +311,9 @@ private:
|
||||
return reinterpret_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
}
|
||||
|
||||
struct OH_AVCodec *codec_;
|
||||
struct OH_AVCodecAsyncCallback callback_;
|
||||
void *userData_;
|
||||
std::shared_mutex mutex_;
|
||||
};
|
||||
|
||||
class VideoEncoderCallback : public MediaCodecCallback {
|
||||
public:
|
||||
VideoEncoderCallback(OH_AVCodec *codec, struct OH_AVCodecCallback cb, void *userData)
|
||||
: codec_(codec), callback_(cb), userData_(userData)
|
||||
{
|
||||
}
|
||||
virtual ~VideoEncoderCallback() = default;
|
||||
|
||||
void OnError(AVCodecErrorType errorType, int32_t errorCode) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
(void)errorType;
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onError != nullptr, "Callback is nullptr");
|
||||
int32_t extErr = AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(errorCode));
|
||||
callback_.onError(codec_, extErr, userData_);
|
||||
}
|
||||
|
||||
void OnOutputFormatChanged(const Format &format) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onStreamChanged != nullptr, "Callback is nullptr");
|
||||
OHOS::sptr<OH_AVFormat> object = new (std::nothrow) OH_AVFormat(format);
|
||||
// The object lifecycle is controlled by the current function stack
|
||||
callback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
}
|
||||
|
||||
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNeedInputBuffer != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoEncObj->videoEncoder_ != nullptr, "Context video encoder is nullptr!");
|
||||
|
||||
if (videoEncObj->isFlushing_.load() || videoEncObj->isFlushed_.load() || videoEncObj->isStop_.load() ||
|
||||
videoEncObj->isEOS_.load()) {
|
||||
AVCODEC_LOGD("At flush, eos or stop, no buffer available");
|
||||
return;
|
||||
}
|
||||
OH_AVBuffer *data = nullptr;
|
||||
if (!videoEncObj->isInputSurfaceMode_) {
|
||||
data = GetTransData(codec_, index, buffer, false);
|
||||
}
|
||||
callback_.onNeedInputBuffer(codec_, index, data, userData_);
|
||||
}
|
||||
|
||||
void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_LOG(codec_ != nullptr, "Codec is nullptr");
|
||||
CHECK_AND_RETURN_LOG(callback_.onNewOutputBuffer != nullptr, "Callback is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(videoEncObj->videoEncoder_ != nullptr, "Video encoder is nullptr!");
|
||||
|
||||
if (videoEncObj->isFlushing_.load() || videoEncObj->isFlushed_.load() || videoEncObj->isStop_.load()) {
|
||||
AVCODEC_LOGD("At flush or stop, ignore");
|
||||
return;
|
||||
}
|
||||
OH_AVBuffer *data = nullptr;
|
||||
data = GetTransData(codec_, index, buffer, true);
|
||||
|
||||
if (!((buffer->flag_ == AVCODEC_BUFFER_FLAG_CODEC_DATA) || (buffer->flag_ == AVCODEC_BUFFER_FLAG_EOS))) {
|
||||
AVCodecTrace::TraceEnd("OH::Frame", buffer->pts_);
|
||||
}
|
||||
callback_.onNewOutputBuffer(codec_, index, data, userData_);
|
||||
}
|
||||
|
||||
void StopCallback()
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
codec_ = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
OH_AVBuffer *GetTransData(struct OH_AVCodec *codec, uint32_t index, std::shared_ptr<AVBuffer> buffer, bool isOutput)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, nullptr, "magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, nullptr, "videoEncoder_ is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(buffer != nullptr, nullptr, "get output buffer is nullptr!");
|
||||
auto &bufferMap = isOutput ? videoEncObj->outputBufferMap_ : videoEncObj->inputBufferMap_;
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(videoEncObj->objListMutex_);
|
||||
@ -313,7 +342,9 @@ private:
|
||||
}
|
||||
|
||||
struct OH_AVCodec *codec_;
|
||||
struct OH_AVCodecAsyncCallback asyncCallback_;
|
||||
struct OH_AVCodecCallback callback_;
|
||||
OH_VideoEncoder_OnNeedInputParameter onInputParameter_;
|
||||
void *userData_;
|
||||
std::shared_mutex mutex_;
|
||||
};
|
||||
@ -321,17 +352,21 @@ private:
|
||||
void VideoEncoderObject::ClearBufferList()
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(objListMutex_);
|
||||
if (bufferCallback_ != nullptr) {
|
||||
if (isSetBufferCallback_) {
|
||||
BufferToTempFunc(inputBufferMap_);
|
||||
BufferToTempFunc(outputBufferMap_);
|
||||
inputBufferMap_.clear();
|
||||
outputBufferMap_.clear();
|
||||
} else if (memoryCallback_ != nullptr) {
|
||||
} else if (isSetMemoryCallback_) {
|
||||
MemoryToTempFunc(inputMemoryMap_);
|
||||
MemoryToTempFunc(outputMemoryMap_);
|
||||
inputMemoryMap_.clear();
|
||||
outputMemoryMap_.clear();
|
||||
}
|
||||
if (inputFormatMap_.size() > 0) {
|
||||
FormatToTempFunc(inputFormatMap_);
|
||||
inputFormatMap_.clear();
|
||||
}
|
||||
while (tempList_.size() > MAX_TEMPNUM) {
|
||||
tempList_.pop();
|
||||
}
|
||||
@ -339,10 +374,25 @@ void VideoEncoderObject::ClearBufferList()
|
||||
|
||||
void VideoEncoderObject::StopCallback()
|
||||
{
|
||||
if (bufferCallback_ != nullptr) {
|
||||
bufferCallback_->StopCallback();
|
||||
} else if (memoryCallback_ != nullptr) {
|
||||
memoryCallback_->StopCallback();
|
||||
if (callback_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
callback_->StopCallback();
|
||||
}
|
||||
|
||||
void VideoEncoderObject::FormatToTempFunc(std::unordered_map<uint32_t, OHOS::sptr<OH_AVFormat>> &tempMap)
|
||||
{
|
||||
for (auto &val : tempMap) {
|
||||
val.second->magic_ = MFMagic::MFMAGIC_UNKNOWN;
|
||||
if (val.second->outString_ != nullptr) {
|
||||
free(val.second->outString_);
|
||||
val.second->outString_ = nullptr;
|
||||
}
|
||||
if (val.second->dumpInfo_ != nullptr) {
|
||||
free(val.second->dumpInfo_);
|
||||
val.second->dumpInfo_ = nullptr;
|
||||
}val.second->format_.GetMeta()->Clear();
|
||||
tempList_.push(std::move(val.second));
|
||||
}
|
||||
}
|
||||
|
||||
@ -579,7 +629,7 @@ OH_AVErrCode OH_VideoEncoder_FreeOutputData(struct OH_AVCodec *codec, uint32_t i
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->memoryCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->callback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVMemory is nullptr!");
|
||||
|
||||
int32_t ret = videoEncObj->videoEncoder_->ReleaseOutputBuffer(index);
|
||||
@ -597,7 +647,7 @@ OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(struct OH_AVCodec *codec, uint32_t
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->bufferCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->isSetBufferCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVBuffer is nullptr!");
|
||||
|
||||
int32_t ret = videoEncObj->videoEncoder_->ReleaseOutputBuffer(index);
|
||||
@ -651,10 +701,16 @@ OH_AVErrCode OH_VideoEncoder_SetCallback(struct OH_AVCodec *codec, struct OH_AVC
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
|
||||
videoEncObj->memoryCallback_ = std::make_shared<NativeVideoEncoderCallback>(codec, callback, userData);
|
||||
int32_t ret = videoEncObj->videoEncoder_->SetCallback(videoEncObj->memoryCallback_);
|
||||
if (videoEncObj->callback_ != nullptr) {
|
||||
videoEncObj->callback_->UpdateCallback(callback, userData);
|
||||
} else {
|
||||
videoEncObj->callback_ = std::make_shared<NativeVideoEncoderCallback>(codec, callback, userData);
|
||||
}
|
||||
int32_t ret =
|
||||
videoEncObj->videoEncoder_->SetCallback(std::static_pointer_cast<AVCodecCallback>(videoEncObj->callback_));
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(ret)),
|
||||
"Video encoder set callback failed!");
|
||||
videoEncObj->isSetMemoryCallback_ = true;
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
@ -670,10 +726,16 @@ OH_AVErrCode OH_VideoEncoder_RegisterCallback(struct OH_AVCodec *codec, struct O
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
|
||||
videoEncObj->bufferCallback_ = std::make_shared<VideoEncoderCallback>(codec, callback, userData);
|
||||
int32_t ret = videoEncObj->videoEncoder_->SetCallback(videoEncObj->bufferCallback_);
|
||||
if (videoEncObj->callback_ != nullptr) {
|
||||
videoEncObj->callback_->UpdateCallback(callback, userData);
|
||||
} else {
|
||||
videoEncObj->callback_ = std::make_shared<NativeVideoEncoderCallback>(codec, callback, userData);
|
||||
}
|
||||
int32_t ret =
|
||||
videoEncObj->videoEncoder_->SetCallback(std::static_pointer_cast<MediaCodecCallback>(videoEncObj->callback_));
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(ret)),
|
||||
"Video encoder set callback failed!");
|
||||
"Video encoder register callback failed!");
|
||||
videoEncObj->isSetBufferCallback_ = true;
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
@ -685,6 +747,19 @@ OH_AVErrCode OH_VideoEncoder_RegisterParameterCallback(OH_AVCodec *codec,
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(onInputParameter != nullptr, AV_ERR_INVALID_VAL, "Callback onInputParameter is nullptr");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
|
||||
if (videoEncObj->callback_ != nullptr) {
|
||||
videoEncObj->callback_->UpdateCallback(onInputParameter, userData);
|
||||
} else {
|
||||
videoEncObj->callback_ = std::make_shared<NativeVideoEncoderCallback>(codec, onInputParameter, userData);
|
||||
}
|
||||
int32_t ret = videoEncObj->videoEncoder_->SetCallback(
|
||||
std::static_pointer_cast<MediaCodecParameterCallback>(videoEncObj->callback_));
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(ret)),
|
||||
"Video encoder register parameter callback failed!");
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
@ -697,7 +772,7 @@ OH_AVErrCode OH_VideoEncoder_PushInputData(struct OH_AVCodec *codec, uint32_t in
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->memoryCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->callback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVMemory is nullptr!");
|
||||
|
||||
if (!((attr.flags == AVCODEC_BUFFER_FLAG_CODEC_DATA) || (attr.flags == AVCODEC_BUFFER_FLAG_EOS))) {
|
||||
@ -727,7 +802,7 @@ OH_AVErrCode OH_VideoEncoder_PushInputBuffer(struct OH_AVCodec *codec, uint32_t
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "videoEncoder_ is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->bufferCallback_ != nullptr, AV_ERR_INVALID_STATE,
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->isSetBufferCallback_, AV_ERR_INVALID_STATE,
|
||||
"The callback of OH_AVBuffer is nullptr!");
|
||||
|
||||
{
|
||||
@ -755,6 +830,13 @@ OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t inde
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "videoEncoder_ is nullptr!");
|
||||
|
||||
int32_t ret = videoEncObj->videoEncoder_->QueueInputParameter(index);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast<AVCodecServiceErrCode>(ret)),
|
||||
"videoEncoder QueueInputParameter failed!");
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -49,11 +49,13 @@ public:
|
||||
virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0;
|
||||
virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
|
||||
virtual int32_t QueueInputBuffer(uint32_t index) = 0;
|
||||
virtual int32_t QueueInputParameter(uint32_t index) = 0;
|
||||
virtual int32_t GetOutputFormat(Format &format) = 0;
|
||||
virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render = false) = 0;
|
||||
virtual int32_t SetParameter(const Format &format) = 0;
|
||||
virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) = 0;
|
||||
virtual int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) = 0;
|
||||
virtual int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback) = 0;
|
||||
virtual int32_t GetInputFormat(Format &format) = 0;
|
||||
virtual int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
|
||||
const bool svpFlag)
|
||||
|
@ -88,6 +88,7 @@ int32_t CodecClient::CreateListenerObject()
|
||||
|
||||
int32_t CodecClient::Init(AVCodecType type, bool isMimeType, const std::string &name, API_VERSION apiVersion)
|
||||
{
|
||||
(void)apiVersion;
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(codecProxy_ != nullptr, AVCS_ERR_NO_MEMORY, "Server not exist");
|
||||
|
||||
@ -113,6 +114,8 @@ int32_t CodecClient::Start()
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(codecProxy_ != nullptr, AVCS_ERR_NO_MEMORY, "Server not exist");
|
||||
CHECK_AND_RETURN_RET_LOG(codecMode_ != CODEC_SET_PARAMETER_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"Not get input surface.");
|
||||
|
||||
int32_t ret = codecProxy_->Start();
|
||||
if (ret == AVCS_ERR_OK) {
|
||||
@ -199,6 +202,7 @@ sptr<OHOS::Surface> CodecClient::CreateInputSurface()
|
||||
|
||||
auto ret = codecProxy_->CreateInputSurface();
|
||||
EXPECT_AND_LOGI(ret != nullptr, "Succeed");
|
||||
codecMode_ |= CODEC_SURFACE_MODE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -209,6 +213,7 @@ int32_t CodecClient::SetOutputSurface(sptr<Surface> surface)
|
||||
|
||||
int32_t ret = codecProxy_->SetOutputSurface(surface);
|
||||
EXPECT_AND_LOGI(ret == AVCS_ERR_OK, "Succeed");
|
||||
codecMode_ = CODEC_SURFACE_MODE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -216,6 +221,8 @@ int32_t CodecClient::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AV
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(codecProxy_ != nullptr, AVCS_ERR_NO_MEMORY, "Server not exist");
|
||||
CHECK_AND_RETURN_RET_LOG(callbackMode_ == MEMORY_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback of AVSharedMemory is invalid!");
|
||||
|
||||
int32_t ret = codecProxy_->QueueInputBuffer(index, info, flag);
|
||||
EXPECT_AND_LOGD(ret == AVCS_ERR_OK, "Succeed");
|
||||
@ -226,12 +233,25 @@ int32_t CodecClient::QueueInputBuffer(uint32_t index)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(codecProxy_ != nullptr, AVCS_ERR_NO_MEMORY, "Server not exist");
|
||||
CHECK_AND_RETURN_RET_LOG(callbackMode_ == BUFFER_CALLBACK, AVCS_ERR_INVALID_STATE,
|
||||
"The callback of AVBuffer is invalid!");
|
||||
|
||||
int32_t ret = codecProxy_->QueueInputBuffer(index);
|
||||
EXPECT_AND_LOGD(ret == AVCS_ERR_OK, "Succeed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CodecClient::QueueInputParameter(uint32_t index)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(codecProxy_ != nullptr, AVCS_ERR_NO_MEMORY, "Server not exist");
|
||||
CHECK_AND_RETURN_RET_LOG(codecMode_ == CODEC_SURFACE_MODE, AVCS_ERR_INVALID_STATE, "Is in invalid state!");
|
||||
|
||||
int32_t ret = codecProxy_->QueueInputParameter(index);
|
||||
EXPECT_AND_LOGD(ret == AVCS_ERR_OK, "Succeed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CodecClient::GetOutputFormat(Format &format)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
@ -259,6 +279,7 @@ int32_t CodecClient::ReleaseOutputBuffer(uint32_t index, bool render)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(codecProxy_ != nullptr, AVCS_ERR_NO_MEMORY, "Server not exist");
|
||||
CHECK_AND_RETURN_RET_LOG(callbackMode_ != INVALID_CALLBACK, AVCS_ERR_INVALID_STATE, "The callback is invalid!");
|
||||
|
||||
int32_t ret = codecProxy_->ReleaseOutputBuffer(index, render);
|
||||
EXPECT_AND_LOGD(ret == AVCS_ERR_OK, "Succeed");
|
||||
@ -280,6 +301,9 @@ int32_t CodecClient::SetCallback(const std::shared_ptr<AVCodecCallback> &callbac
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_NO_MEMORY, "Callback is nullptr.");
|
||||
CHECK_AND_RETURN_RET_LOG(listenerStub_ != nullptr, AVCS_ERR_NO_MEMORY, "Listener stub is nullptr.");
|
||||
CHECK_AND_RETURN_RET_LOG(callbackMode_ == MEMORY_CALLBACK || callbackMode_ == INVALID_CALLBACK,
|
||||
AVCS_ERR_INVALID_STATE, "The callback of AVBuffer is already set!");
|
||||
callbackMode_ = MEMORY_CALLBACK;
|
||||
|
||||
callback_ = callback;
|
||||
const std::shared_ptr<AVCodecCallback> &stubCallback = shared_from_this();
|
||||
@ -293,6 +317,9 @@ int32_t CodecClient::SetCallback(const std::shared_ptr<MediaCodecCallback> &call
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_NO_MEMORY, "Callback is nullptr.");
|
||||
CHECK_AND_RETURN_RET_LOG(listenerStub_ != nullptr, AVCS_ERR_NO_MEMORY, "Listener stub is nullptr.");
|
||||
CHECK_AND_RETURN_RET_LOG(callbackMode_ == BUFFER_CALLBACK || callbackMode_ == INVALID_CALLBACK,
|
||||
AVCS_ERR_INVALID_STATE, "The callback of AVSharedMemory is already set!");
|
||||
callbackMode_ = BUFFER_CALLBACK;
|
||||
|
||||
videoCallback_ = callback;
|
||||
const std::shared_ptr<MediaCodecCallback> &stubCallback = shared_from_this();
|
||||
@ -301,6 +328,20 @@ int32_t CodecClient::SetCallback(const std::shared_ptr<MediaCodecCallback> &call
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t CodecClient::SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr, AVCS_ERR_NO_MEMORY, "Callback is nullptr.");
|
||||
CHECK_AND_RETURN_RET_LOG(listenerStub_ != nullptr, AVCS_ERR_NO_MEMORY, "Listener stub is nullptr.");
|
||||
codecMode_ |= CODEC_SET_PARAMETER_CALLBACK;
|
||||
|
||||
paramCallback_ = callback;
|
||||
const std::shared_ptr<MediaCodecParameterCallback> &stubCallback = shared_from_this();
|
||||
listenerStub_->SetCallback(stubCallback);
|
||||
AVCODEC_LOGI("Parameter callback");
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t CodecClient::GetInputFormat(Format &format)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
@ -365,5 +406,9 @@ void CodecClient::OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuff
|
||||
videoCallback_->OnOutputBufferAvailable(index, buffer);
|
||||
}
|
||||
|
||||
void CodecClient::OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter)
|
||||
{
|
||||
paramCallback_->OnInputParameterAvailable(index, parameter);
|
||||
}
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
||||
|
@ -26,7 +26,7 @@ namespace MediaAVCodec {
|
||||
class CodecClientCallback;
|
||||
class CodecClient : public MediaCodecCallback,
|
||||
public AVCodecCallback,
|
||||
public AVCodecParameterCallback,
|
||||
public MediaCodecParameterCallback,
|
||||
public ICodecService,
|
||||
public std::enable_shared_from_this<CodecClient> {
|
||||
public:
|
||||
@ -47,13 +47,13 @@ public:
|
||||
int32_t SetOutputSurface(sptr<Surface> surface) override;
|
||||
int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
|
||||
int32_t QueueInputBuffer(uint32_t index) override;
|
||||
int32_t QueueInputParameter(uint32_t index);
|
||||
int32_t QueueInputParameter(uint32_t index) override;
|
||||
int32_t GetOutputFormat(Format &format) override;
|
||||
int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
|
||||
int32_t SetParameter(const Format &format) override;
|
||||
int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) override;
|
||||
int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) override;
|
||||
int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback);
|
||||
int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback) override;
|
||||
int32_t GetInputFormat(Format &format) override;
|
||||
#ifdef SUPPORT_DRM
|
||||
int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, const bool svpFlag) override;
|
||||
@ -68,17 +68,32 @@ public:
|
||||
std::shared_ptr<AVSharedMemory> buffer) override;
|
||||
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
|
||||
void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
|
||||
void OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter);
|
||||
void OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter) override;
|
||||
|
||||
private:
|
||||
int32_t CreateListenerObject();
|
||||
void UpdateGeneration();
|
||||
void WaitCallbackDone();
|
||||
typedef enum : int32_t {
|
||||
MEMORY_CALLBACK = 1,
|
||||
BUFFER_CALLBACK,
|
||||
INVALID_CALLBACK,
|
||||
} CallbackMode;
|
||||
|
||||
typedef enum : int32_t {
|
||||
CODEC_BUFFER_MODE = 0,
|
||||
CODEC_SURFACE_MODE = 1,
|
||||
CODEC_SET_PARAMETER_CALLBACK = 1 << 1,
|
||||
CODEC_SURFACE_MODE_WITH_SETPARAMETER = CODEC_SURFACE_MODE | CODEC_SET_PARAMETER_CALLBACK,
|
||||
} CodecMode;
|
||||
|
||||
int32_t callbackMode_ = INVALID_CALLBACK;
|
||||
int32_t codecMode_ = CODEC_BUFFER_MODE;
|
||||
sptr<IStandardCodecService> codecProxy_ = nullptr;
|
||||
sptr<CodecListenerStub> listenerStub_ = nullptr;
|
||||
std::shared_ptr<AVCodecCallback> callback_ = nullptr;
|
||||
std::shared_ptr<MediaCodecCallback> videoCallback_ = nullptr;
|
||||
std::shared_ptr<MediaCodecParameterCallback> paramCallback_ = nullptr;
|
||||
std::shared_mutex mutex_;
|
||||
std::atomic<bool> needUpdateGeneration = true;
|
||||
};
|
||||
|
@ -53,10 +53,7 @@ public:
|
||||
if (iter != caches_.end() && iter->second.lock() == buffer) {
|
||||
flag = CacheFlag::HIT_CACHE;
|
||||
parcel.WriteUint8(static_cast<uint8_t>(flag));
|
||||
if (isOutput_) {
|
||||
return buffer->WriteToMessageParcel(parcel);
|
||||
}
|
||||
return true;
|
||||
return buffer->WriteToMessageParcel(parcel);
|
||||
}
|
||||
|
||||
if (iter == caches_.end()) {
|
||||
@ -82,11 +79,6 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SetIsOutput(bool isOutput)
|
||||
{
|
||||
isOutput_ = isOutput;
|
||||
}
|
||||
|
||||
void ClearCaches()
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
@ -101,7 +93,6 @@ private:
|
||||
INVALIDATE_CACHE,
|
||||
};
|
||||
|
||||
bool isOutput_ = false;
|
||||
std::unordered_map<uint32_t, std::weak_ptr<AVBuffer>> caches_;
|
||||
};
|
||||
|
||||
@ -110,10 +101,8 @@ CodecListenerProxy::CodecListenerProxy(const sptr<IRemoteObject> &impl) : IRemot
|
||||
if (inputBufferCache_ == nullptr) {
|
||||
inputBufferCache_ = std::make_unique<CodecBufferCache>();
|
||||
}
|
||||
|
||||
if (outputBufferCache_ == nullptr) {
|
||||
outputBufferCache_ = std::make_unique<CodecBufferCache>();
|
||||
outputBufferCache_->SetIsOutput(true);
|
||||
}
|
||||
AVCODEC_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
|
||||
}
|
||||
@ -210,19 +199,19 @@ bool CodecListenerProxy::InputBufferInfoFromParcel(uint32_t index, AVCodecBuffer
|
||||
{
|
||||
std::shared_ptr<AVBuffer> buffer = inputBufferCache_->FindBufferFromIndex(index);
|
||||
CHECK_AND_RETURN_RET_LOG(buffer != nullptr, false, "Input buffer in cache is nullptr");
|
||||
info.presentationTimeUs = data.ReadInt64();
|
||||
info.offset = data.ReadInt32();
|
||||
info.size = data.ReadInt32();
|
||||
flag = static_cast<AVCodecBufferFlag>(data.ReadUint32());
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(buffer->meta_ != nullptr, false, "buffer meta is nullptr");
|
||||
if (buffer->memory_ == nullptr) {
|
||||
return buffer->meta_->FromParcel(data);
|
||||
}
|
||||
uint32_t flagTemp = 0;
|
||||
bool ret = data.ReadInt64(info.presentationTimeUs) && data.ReadInt32(info.offset) && data.ReadInt32(info.size) &&
|
||||
data.ReadUint32(flagTemp);
|
||||
flag = static_cast<AVCodecBufferFlag>(flagTemp);
|
||||
buffer->pts_ = info.presentationTimeUs;
|
||||
buffer->flag_ = flag;
|
||||
if (buffer->memory_ != nullptr) {
|
||||
buffer->memory_->SetOffset(info.offset);
|
||||
buffer->memory_->SetSize(info.size);
|
||||
}
|
||||
CHECK_AND_RETURN_RET_LOG(buffer->meta_ != nullptr, false, "buffer meta is nullptr");
|
||||
return buffer->meta_->FromParcel(data);
|
||||
buffer->memory_->SetOffset(info.offset);
|
||||
buffer->memory_->SetSize(info.size);
|
||||
return ret && buffer->meta_->FromParcel(data);
|
||||
}
|
||||
|
||||
void CodecListenerProxy::ClearListenerCache()
|
||||
|
@ -36,12 +36,25 @@ const std::map<OHOS::Media::MemoryType, std::string> MEMORYTYPE_MAP = {
|
||||
namespace OHOS {
|
||||
namespace MediaAVCodec {
|
||||
using namespace Media;
|
||||
typedef struct BufferElem {
|
||||
std::shared_ptr<AVSharedMemory> memory = nullptr;
|
||||
std::shared_ptr<AVBuffer> buffer = nullptr;
|
||||
std::shared_ptr<Format> format = nullptr;
|
||||
} BufferElem;
|
||||
|
||||
typedef enum : uint8_t {
|
||||
ELEM_GET_AVBUFFER,
|
||||
ELEM_GET_AVMEMORY,
|
||||
ELEM_GET_AVFORMAT,
|
||||
} UpdateFilter;
|
||||
|
||||
class CodecListenerStub::CodecBufferCache : public NoCopyable {
|
||||
public:
|
||||
CodecBufferCache() = default;
|
||||
~CodecBufferCache() = default;
|
||||
|
||||
void ReadFromParcel(uint32_t index, MessageParcel &parcel, std::shared_ptr<AVBuffer> &buffer)
|
||||
void ReadFromParcel(uint32_t index, MessageParcel &parcel, BufferElem &elem,
|
||||
const UpdateFilter filter = ELEM_GET_AVBUFFER)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
auto iter = caches_.find(index);
|
||||
@ -51,75 +64,17 @@ public:
|
||||
AVCODEC_LOGE("Mark hit cache, but can find the index's cache, index: %{public}u", index);
|
||||
return;
|
||||
}
|
||||
buffer = iter->second.buffer_;
|
||||
if (isOutput_) {
|
||||
bool isRead = buffer->ReadFromMessageParcel(parcel);
|
||||
CHECK_AND_RETURN_LOG(isRead, "Read buffer from parcel failed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (flag_ == CacheFlag::UPDATE_CACHE) {
|
||||
buffer = AVBuffer::CreateAVBuffer();
|
||||
CHECK_AND_RETURN_LOG(buffer != nullptr, "Read buffer from parcel failed");
|
||||
buffer->ReadFromMessageParcel(parcel);
|
||||
|
||||
if (iter == caches_.end()) {
|
||||
AVCODEC_LOGD("Add cache, index: %{public}u, type: %{public}s", index, GetMemoryTypeStr(buffer).c_str());
|
||||
BufferAndMemory bufferElem = {.buffer_ = buffer};
|
||||
caches_.emplace(index, bufferElem);
|
||||
} else {
|
||||
iter->second.buffer_ = buffer;
|
||||
AVCODEC_LOGD("Update cache, index: %{public}u, type: %{public}s", index,
|
||||
GetMemoryTypeStr(buffer).c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// invalidate cache flag_
|
||||
if (iter != caches_.end()) {
|
||||
caches_.erase(iter);
|
||||
}
|
||||
buffer = nullptr;
|
||||
AVCODEC_LOGD("Invalidate cache for index: %{public}u, flag: %{public}hhu", index, flag_);
|
||||
return;
|
||||
}
|
||||
|
||||
void ReadFromParcel(uint32_t index, MessageParcel &parcel, std::shared_ptr<AVBuffer> &buffer,
|
||||
std::shared_ptr<AVSharedMemory> &memory)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
auto iter = caches_.find(index);
|
||||
flag_ = static_cast<CacheFlag>(parcel.ReadUint8());
|
||||
if (flag_ == CacheFlag::HIT_CACHE) {
|
||||
if (iter == caches_.end()) {
|
||||
AVCODEC_LOGE("Mark hit cache, but can find the index's cache, index: %{public}u", index);
|
||||
return;
|
||||
}
|
||||
buffer = iter->second.buffer_;
|
||||
memory = iter->second.memory_;
|
||||
if (isOutput_) {
|
||||
bool isReadSuc = buffer->ReadFromMessageParcel(parcel);
|
||||
CHECK_AND_RETURN_LOG(isReadSuc, "Read buffer from parcel failed");
|
||||
ReadOutputMemory(buffer, memory);
|
||||
}
|
||||
elem = iter->second;
|
||||
HitFunction(elem, parcel, filter);
|
||||
return;
|
||||
}
|
||||
if (flag_ == CacheFlag::UPDATE_CACHE) {
|
||||
buffer = AVBuffer::CreateAVBuffer();
|
||||
bool isReadSuc = (buffer != nullptr) && buffer->ReadFromMessageParcel(parcel);
|
||||
CHECK_AND_RETURN_LOG(isReadSuc, "Create buffer from parcel failed");
|
||||
AVBufferToAVSharedMemory(buffer, memory);
|
||||
if (isOutput_) {
|
||||
ReadOutputMemory(buffer, memory);
|
||||
}
|
||||
UpdateFunction(elem, parcel, filter);
|
||||
if (iter == caches_.end()) {
|
||||
AVCODEC_LOGD("Add cache, index: %{public}u", index);
|
||||
BufferAndMemory bufferElem = {.memory_ = memory, .buffer_ = buffer};
|
||||
caches_.emplace(index, bufferElem);
|
||||
caches_.emplace(index, elem);
|
||||
} else {
|
||||
iter->second.buffer_ = buffer;
|
||||
iter->second.memory_ = memory;
|
||||
iter->second = elem;
|
||||
AVCODEC_LOGD("Update cache, index: %{public}u", index);
|
||||
}
|
||||
return;
|
||||
@ -128,24 +83,19 @@ public:
|
||||
if (iter != caches_.end()) {
|
||||
caches_.erase(iter);
|
||||
}
|
||||
buffer = nullptr;
|
||||
memory = nullptr;
|
||||
AVCODEC_LOGD("Invalidate cache for index: %{public}u, flag: %{public}hhu", index, flag_);
|
||||
return;
|
||||
}
|
||||
|
||||
void GetBufferElem(uint32_t index, std::shared_ptr<AVBuffer> &buffer, std::shared_ptr<AVSharedMemory> &memory)
|
||||
void GetBufferElem(uint32_t index, BufferElem &elem)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
auto iter = caches_.find(index);
|
||||
if (iter == caches_.end()) {
|
||||
buffer = nullptr;
|
||||
memory = nullptr;
|
||||
AVCODEC_LOGE("Get cache failed, index: %{public}u", index);
|
||||
return;
|
||||
}
|
||||
buffer = iter->second.buffer_;
|
||||
memory = iter->second.memory_;
|
||||
elem = iter->second;
|
||||
}
|
||||
|
||||
void ClearCaches()
|
||||
@ -206,19 +156,45 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void HitFunction(BufferElem &elem, MessageParcel &parcel, const UpdateFilter &filter)
|
||||
{
|
||||
if (!isOutput_ && filter == ELEM_GET_AVFORMAT) {
|
||||
bool isReadSuc = elem.buffer->ReadFromMessageParcel(parcel);
|
||||
CHECK_AND_RETURN_LOG(isReadSuc, "Read buffer from parcel failed");
|
||||
} else if (isOutput_) {
|
||||
bool isReadSuc = elem.buffer->ReadFromMessageParcel(parcel);
|
||||
CHECK_AND_RETURN_LOG(isReadSuc, "Read buffer from parcel failed");
|
||||
if (filter == ELEM_GET_AVMEMORY) {
|
||||
ReadOutputMemory(elem.buffer, elem.memory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateFunction(BufferElem &elem, MessageParcel &parcel, const UpdateFilter &filter)
|
||||
{
|
||||
elem.buffer = AVBuffer::CreateAVBuffer();
|
||||
bool isReadSuc = (elem.buffer != nullptr) && elem.buffer->ReadFromMessageParcel(parcel);
|
||||
CHECK_AND_RETURN_LOG(isReadSuc, "Create buffer from parcel failed");
|
||||
if (!isOutput_ && filter == ELEM_GET_AVFORMAT) {
|
||||
elem.format = std::make_shared<Format>();
|
||||
elem.format->SetMeta(std::move(elem.buffer->meta_));
|
||||
elem.buffer->meta_ = elem.format->GetMeta();
|
||||
} else if (filter == ELEM_GET_AVMEMORY) {
|
||||
AVBufferToAVSharedMemory(elem.buffer, elem.memory);
|
||||
if (isOutput_) {
|
||||
ReadOutputMemory(elem.buffer, elem.memory);
|
||||
}
|
||||
}
|
||||
}
|
||||
enum class CacheFlag : uint8_t {
|
||||
HIT_CACHE = 1,
|
||||
UPDATE_CACHE,
|
||||
INVALIDATE_CACHE,
|
||||
};
|
||||
typedef struct BufferAndMemory {
|
||||
std::shared_ptr<AVSharedMemory> memory_ = nullptr;
|
||||
std::shared_ptr<AVBuffer> buffer_ = nullptr;
|
||||
} BufferAndMemory;
|
||||
bool isOutput_ = false;
|
||||
CacheFlag flag_ = CacheFlag::INVALIDATE_CACHE;
|
||||
std::shared_mutex mutex_;
|
||||
std::unordered_map<uint32_t, BufferAndMemory> caches_;
|
||||
std::unordered_map<uint32_t, BufferElem> caches_;
|
||||
};
|
||||
|
||||
CodecListenerStub::CodecListenerStub()
|
||||
@ -250,8 +226,8 @@ int CodecListenerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa
|
||||
CHECK_AND_RETURN_RET_LOG(outputBufferCache_ != nullptr, AVCS_ERR_INVALID_OPERATION, "outputBufferCache is nullptr");
|
||||
|
||||
std::unique_lock<std::mutex> lock(syncMutex_, std::try_to_lock);
|
||||
CHECK_AND_RETURN_RET_LOG_LIMIT(lock.owns_lock() && CheckGeneration(data.ReadUint64()),
|
||||
AVCS_ERR_OK, LOG_FREQ, "abandon message");
|
||||
CHECK_AND_RETURN_RET_LOG_LIMIT(lock.owns_lock() && CheckGeneration(data.ReadUint64()), AVCS_ERR_OK, LOG_FREQ,
|
||||
"abandon message");
|
||||
threadId_ = std::this_thread::get_id();
|
||||
callbackIsDoing_ = true;
|
||||
switch (code) {
|
||||
@ -324,37 +300,38 @@ void CodecListenerStub::OnOutputBufferAvailable(uint32_t index, std::shared_ptr<
|
||||
|
||||
void CodecListenerStub::OnInputBufferAvailable(uint32_t index, MessageParcel &data)
|
||||
{
|
||||
std::shared_ptr<MediaCodecCallback> vCb = videoCallback_.lock();
|
||||
if (vCb != nullptr) {
|
||||
std::shared_ptr<AVBuffer> buffer = nullptr;
|
||||
inputBufferCache_->ReadFromParcel(index, data, buffer);
|
||||
vCb->OnInputBufferAvailable(index, buffer);
|
||||
BufferElem elem;
|
||||
std::shared_ptr<MediaCodecParameterCallback> pCb = paramCallback_.lock();
|
||||
if (pCb != nullptr) {
|
||||
inputBufferCache_->ReadFromParcel(index, data, elem, ELEM_GET_AVFORMAT);
|
||||
pCb->OnInputParameterAvailable(index, elem.format);
|
||||
elem.buffer->meta_ = elem.format->GetMeta();
|
||||
Finalize();
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaCodecCallback> vCb = videoCallback_.lock();
|
||||
std::shared_ptr<AVCodecCallback> cb = callback_.lock();
|
||||
if (cb != nullptr) {
|
||||
std::shared_ptr<AVBuffer> buffer = nullptr;
|
||||
std::shared_ptr<AVSharedMemory> memory = nullptr;
|
||||
inputBufferCache_->ReadFromParcel(index, data, buffer, memory);
|
||||
cb->OnInputBufferAvailable(index, memory);
|
||||
if (vCb != nullptr) {
|
||||
inputBufferCache_->ReadFromParcel(index, data, elem);
|
||||
vCb->OnInputBufferAvailable(index, elem.buffer);
|
||||
} else if (cb != nullptr) {
|
||||
inputBufferCache_->ReadFromParcel(index, data, elem, ELEM_GET_AVMEMORY);
|
||||
cb->OnInputBufferAvailable(index, elem.memory);
|
||||
}
|
||||
Finalize();
|
||||
}
|
||||
|
||||
void CodecListenerStub::OnOutputBufferAvailable(uint32_t index, MessageParcel &data)
|
||||
{
|
||||
BufferElem elem;
|
||||
std::shared_ptr<MediaCodecCallback> vCb = videoCallback_.lock();
|
||||
if (vCb != nullptr) {
|
||||
std::shared_ptr<AVBuffer> buffer = nullptr;
|
||||
outputBufferCache_->ReadFromParcel(index, data, buffer);
|
||||
vCb->OnOutputBufferAvailable(index, buffer);
|
||||
}
|
||||
|
||||
std::shared_ptr<AVCodecCallback> cb = callback_.lock();
|
||||
if (cb != nullptr) {
|
||||
std::shared_ptr<AVBuffer> buffer = nullptr;
|
||||
std::shared_ptr<AVSharedMemory> memory = nullptr;
|
||||
outputBufferCache_->ReadFromParcel(index, data, buffer, memory);
|
||||
if (vCb != nullptr) {
|
||||
outputBufferCache_->ReadFromParcel(index, data, elem);
|
||||
vCb->OnOutputBufferAvailable(index, elem.buffer);
|
||||
} else if (cb != nullptr) {
|
||||
outputBufferCache_->ReadFromParcel(index, data, elem, ELEM_GET_AVMEMORY);
|
||||
std::shared_ptr<AVBuffer> &buffer = elem.buffer;
|
||||
|
||||
AVCodecBufferInfo info;
|
||||
info.presentationTimeUs = buffer->pts_;
|
||||
@ -363,7 +340,7 @@ void CodecListenerStub::OnOutputBufferAvailable(uint32_t index, MessageParcel &d
|
||||
info.offset = buffer->memory_->GetOffset();
|
||||
info.size = buffer->memory_->GetSize();
|
||||
}
|
||||
cb->OnOutputBufferAvailable(index, info, flag, memory);
|
||||
cb->OnOutputBufferAvailable(index, info, flag, elem.memory);
|
||||
}
|
||||
Finalize();
|
||||
}
|
||||
@ -378,6 +355,11 @@ void CodecListenerStub::SetCallback(const std::shared_ptr<MediaCodecCallback> &c
|
||||
videoCallback_ = callback;
|
||||
}
|
||||
|
||||
void CodecListenerStub::SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback)
|
||||
{
|
||||
paramCallback_ = callback;
|
||||
}
|
||||
|
||||
void CodecListenerStub::WaitCallbackDone()
|
||||
{
|
||||
static std::hash<std::thread::id> hasher;
|
||||
@ -399,9 +381,10 @@ void CodecListenerStub::ClearListenerCache()
|
||||
bool CodecListenerStub::WriteInputMemoryToParcel(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
|
||||
MessageParcel &data)
|
||||
{
|
||||
std::shared_ptr<AVBuffer> buffer = nullptr;
|
||||
std::shared_ptr<AVSharedMemory> memory = nullptr;
|
||||
inputBufferCache_->GetBufferElem(index, buffer, memory);
|
||||
BufferElem elem;
|
||||
inputBufferCache_->GetBufferElem(index, elem);
|
||||
std::shared_ptr<AVBuffer> &buffer = elem.buffer;
|
||||
std::shared_ptr<AVSharedMemory> &memory = elem.memory;
|
||||
CHECK_AND_RETURN_RET_LOG(buffer != nullptr, false, "Get buffer is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, false, "Get memory is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(buffer->memory_ != nullptr, false, "Get buffer memory is nullptr");
|
||||
@ -416,9 +399,9 @@ bool CodecListenerStub::WriteInputMemoryToParcel(uint32_t index, AVCodecBufferIn
|
||||
|
||||
bool CodecListenerStub::WriteInputBufferToParcel(uint32_t index, MessageParcel &data)
|
||||
{
|
||||
std::shared_ptr<AVBuffer> buffer = nullptr;
|
||||
std::shared_ptr<AVSharedMemory> memory = nullptr;
|
||||
inputBufferCache_->GetBufferElem(index, buffer, memory);
|
||||
BufferElem elem;
|
||||
inputBufferCache_->GetBufferElem(index, elem);
|
||||
std::shared_ptr<AVBuffer> &buffer = elem.buffer;
|
||||
CHECK_AND_RETURN_RET_LOG(buffer != nullptr, false, "Get buffer is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(buffer->memory_ != nullptr, false, "Get buffer memory is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(buffer->meta_ != nullptr, false, "Get buffer meta is nullptr");
|
||||
@ -428,6 +411,15 @@ bool CodecListenerStub::WriteInputBufferToParcel(uint32_t index, MessageParcel &
|
||||
buffer->meta_->ToParcel(data);
|
||||
}
|
||||
|
||||
bool CodecListenerStub::WriteInputParameterToParcel(uint32_t index, MessageParcel &data)
|
||||
{
|
||||
BufferElem elem;
|
||||
inputBufferCache_->GetBufferElem(index, elem);
|
||||
CHECK_AND_RETURN_RET_LOG(elem.format != nullptr, false, "Get format is nullptr");
|
||||
|
||||
return elem.format->GetMeta()->ToParcel(data);
|
||||
}
|
||||
|
||||
bool CodecListenerStub::CheckGeneration(uint64_t messageGeneration) const
|
||||
{
|
||||
return messageGeneration >= GetGeneration();
|
||||
|
@ -35,13 +35,14 @@ public:
|
||||
void OnOutputFormatChanged(const Format &format) override;
|
||||
void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
|
||||
void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
|
||||
void OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter);
|
||||
|
||||
void SetCallback(const std::shared_ptr<AVCodecCallback> &callback);
|
||||
void SetCallback(const std::shared_ptr<MediaCodecCallback> &callback);
|
||||
void SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback);
|
||||
void WaitCallbackDone();
|
||||
|
||||
void ClearListenerCache();
|
||||
bool WriteInputParameterToParcel(uint32_t index, MessageParcel &data);
|
||||
bool WriteInputBufferToParcel(uint32_t index, MessageParcel &data);
|
||||
bool WriteInputMemoryToParcel(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag, MessageParcel &data);
|
||||
|
||||
@ -56,6 +57,7 @@ private:
|
||||
std::unique_ptr<CodecBufferCache> outputBufferCache_;
|
||||
std::weak_ptr<AVCodecCallback> callback_;
|
||||
std::weak_ptr<MediaCodecCallback> videoCallback_;
|
||||
std::weak_ptr<MediaCodecParameterCallback> paramCallback_;
|
||||
std::atomic<bool> callbackIsDoing_ { false };
|
||||
std::mutex syncMutex_;
|
||||
std::condition_variable syncCv_;
|
||||
|
@ -282,6 +282,27 @@ int32_t CodecServiceProxy::QueueInputBuffer(uint32_t index)
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t CodecServiceProxy::QueueInputParameter(uint32_t index)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
|
||||
CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
|
||||
|
||||
data.WriteUint32(index);
|
||||
|
||||
bool retWrite = static_cast<CodecListenerStub *>(listener_.GetRefPtr())->WriteInputParameterToParcel(index, data);
|
||||
CHECK_AND_RETURN_RET_LOG(retWrite == true, AVCS_ERR_INVALID_OPERATION, "Listener write data failed");
|
||||
|
||||
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::QUEUE_INPUT_BUFFER), data,
|
||||
reply, option);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t CodecServiceProxy::GetOutputFormat(Format &format)
|
||||
{
|
||||
MessageParcel data;
|
||||
@ -370,7 +391,7 @@ int32_t CodecServiceProxy::DestroyStub()
|
||||
|
||||
#ifdef SUPPORT_DRM
|
||||
int32_t CodecServiceProxy::SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
|
||||
const bool svpFlag)
|
||||
const bool svpFlag)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -386,9 +407,8 @@ int32_t CodecServiceProxy::SetDecryptConfig(const sptr<DrmStandard::IMediaKeySes
|
||||
CHECK_AND_RETURN_RET_LOG(status, AVCS_ERR_INVALID_OPERATION, "SetDecryptConfig WriteRemoteObject failed");
|
||||
data.WriteBool(svpFlag);
|
||||
|
||||
int32_t ret =
|
||||
Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_DECRYPT_CONFIG),
|
||||
data, reply, option);
|
||||
int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_DECRYPT_CONFIG), data,
|
||||
reply, option);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
|
||||
|
||||
return reply.ReadInt32();
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
int32_t SetOutputSurface(sptr<Surface> surface) override;
|
||||
int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
|
||||
int32_t QueueInputBuffer(uint32_t index) override;
|
||||
int32_t QueueInputParameter(uint32_t index);
|
||||
int32_t QueueInputParameter(uint32_t index) override;
|
||||
int32_t GetOutputFormat(Format &format) override;
|
||||
int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
|
||||
int32_t SetParameter(const Format &format) override;
|
||||
|
@ -318,7 +318,13 @@ int32_t CodecServiceStub::QueueInputBuffer(uint32_t index, AVCodecBufferInfo inf
|
||||
int32_t CodecServiceStub::QueueInputBuffer(uint32_t index)
|
||||
{
|
||||
(void)index;
|
||||
return AVCS_ERR_OK;
|
||||
return AVCS_ERR_UNSUPPORT;
|
||||
}
|
||||
|
||||
int32_t CodecServiceStub::QueueInputParameter(uint32_t index)
|
||||
{
|
||||
(void)index;
|
||||
return AVCS_ERR_UNSUPPORT;
|
||||
}
|
||||
|
||||
int32_t CodecServiceStub::GetOutputFormat(Format &format)
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
int32_t SetOutputSurface(sptr<Surface> surface) override;
|
||||
int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
|
||||
int32_t QueueInputBuffer(uint32_t index) override;
|
||||
int32_t QueueInputParameter(uint32_t index) override;
|
||||
int32_t GetOutputFormat(Format &format) override;
|
||||
int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
|
||||
int32_t SetParameter(const Format &format) override;
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0;
|
||||
virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
|
||||
virtual int32_t QueueInputBuffer(uint32_t index) = 0;
|
||||
virtual int32_t QueueInputParameter(uint32_t index) = 0;
|
||||
virtual int32_t GetOutputFormat(Format &format) = 0;
|
||||
virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render) = 0;
|
||||
virtual int32_t SetParameter(const Format &format) = 0;
|
||||
|
@ -408,7 +408,13 @@ int32_t CodecServer::QueueInputBufferIn(uint32_t index, AVCodecBufferInfo info,
|
||||
int32_t CodecServer::QueueInputBuffer(uint32_t index)
|
||||
{
|
||||
(void)index;
|
||||
return AVCS_ERR_OK;
|
||||
return AVCS_ERR_UNSUPPORT;
|
||||
}
|
||||
|
||||
int32_t CodecServer::QueueInputParameter(uint32_t index)
|
||||
{
|
||||
(void)index;
|
||||
return AVCS_ERR_UNSUPPORT;
|
||||
}
|
||||
|
||||
int32_t CodecServer::GetOutputFormat(Format &format)
|
||||
@ -479,6 +485,12 @@ int32_t CodecServer::SetCallback(const std::shared_ptr<MediaCodecCallback> &call
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t CodecServer::SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback)
|
||||
{
|
||||
(void)callback;
|
||||
return AVCS_ERR_UNSUPPORT;
|
||||
}
|
||||
|
||||
int32_t CodecServer::GetInputFormat(Format &format)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock(mutex_);
|
||||
|
@ -68,11 +68,13 @@ public:
|
||||
int32_t SetOutputSurface(sptr<Surface> surface) override;
|
||||
int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
|
||||
int32_t QueueInputBuffer(uint32_t index) override;
|
||||
int32_t QueueInputParameter(uint32_t index) override;
|
||||
int32_t GetOutputFormat(Format &format) override;
|
||||
int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
|
||||
int32_t SetParameter(const Format &format) override;
|
||||
int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) override;
|
||||
int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) override;
|
||||
int32_t SetCallback(const std::shared_ptr<MediaCodecParameterCallback> &callback) override;
|
||||
int32_t GetInputFormat(Format &format) override;
|
||||
#ifdef SUPPORT_DRM
|
||||
int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
|
||||
|
@ -24,6 +24,7 @@ namespace MediaAVCodec {
|
||||
class AVFormatInnerMock : public FormatMock {
|
||||
public:
|
||||
explicit AVFormatInnerMock(const Format &format) : format_(format) {}
|
||||
explicit AVFormatInnerMock(Format &&format) : format_(format) {}
|
||||
AVFormatInnerMock() = default;
|
||||
bool PutIntValue(const std::string_view &key, int32_t value) override;
|
||||
bool GetIntValue(const std::string_view &key, int32_t &value) override;
|
||||
|
@ -23,7 +23,7 @@ namespace OHOS {
|
||||
namespace MediaAVCodec {
|
||||
std::mutex VideoDecCapiMock::mutex_;
|
||||
std::map<OH_AVCodec *, std::shared_ptr<AVCodecCallbackMock>> VideoDecCapiMock::mockCbMap_;
|
||||
std::map<OH_AVCodec *, std::shared_ptr<VideoCodecCallbackMock>> VideoDecCapiMock::mockCbExtMap_;
|
||||
std::map<OH_AVCodec *, std::shared_ptr<MediaCodecCallbackMock>> VideoDecCapiMock::mockCbExtMap_;
|
||||
void VideoDecCapiMock::OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
@ -67,7 +67,7 @@ void VideoDecCapiMock::OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVM
|
||||
void VideoDecCapiMock::OnErrorExt(OH_AVCodec *codec, int32_t errorCode, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
mockCb->OnError(errorCode);
|
||||
}
|
||||
@ -76,7 +76,7 @@ void VideoDecCapiMock::OnErrorExt(OH_AVCodec *codec, int32_t errorCode, void *us
|
||||
void VideoDecCapiMock::OnStreamChangedExt(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
auto formatMock = std::make_shared<AVFormatCapiMock>(format);
|
||||
mockCb->OnStreamChanged(formatMock);
|
||||
@ -86,7 +86,7 @@ void VideoDecCapiMock::OnStreamChangedExt(OH_AVCodec *codec, OH_AVFormat *format
|
||||
void VideoDecCapiMock::OnNeedInputDataExt(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
std::shared_ptr<AVBufferMock> bufMock = data == nullptr ? nullptr : std::make_shared<AVBufferCapiMock>(data);
|
||||
mockCb->OnNeedInputData(index, bufMock);
|
||||
@ -96,7 +96,7 @@ void VideoDecCapiMock::OnNeedInputDataExt(OH_AVCodec *codec, uint32_t index, OH_
|
||||
void VideoDecCapiMock::OnNewOutputDataExt(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
std::shared_ptr<AVBufferMock> bufMock = data == nullptr ? nullptr : std::make_shared<AVBufferCapiMock>(data);
|
||||
mockCb->OnNewOutputData(index, bufMock);
|
||||
@ -112,7 +112,7 @@ std::shared_ptr<AVCodecCallbackMock> VideoDecCapiMock::GetCallback(OH_AVCodec *c
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<VideoCodecCallbackMock> VideoDecCapiMock::GetCallbackExt(OH_AVCodec *codec)
|
||||
std::shared_ptr<MediaCodecCallbackMock> VideoDecCapiMock::GetCallbackExt(OH_AVCodec *codec)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (mockCbExtMap_.find(codec) != mockCbExtMap_.end()) {
|
||||
@ -127,7 +127,7 @@ void VideoDecCapiMock::SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCal
|
||||
mockCbMap_[codec] = cb;
|
||||
}
|
||||
|
||||
void VideoDecCapiMock::SetCallback(OH_AVCodec *codec, std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
void VideoDecCapiMock::SetCallback(OH_AVCodec *codec, std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
mockCbExtMap_[codec] = cb;
|
||||
@ -147,19 +147,16 @@ void VideoDecCapiMock::DelCallback(OH_AVCodec *codec)
|
||||
|
||||
int32_t VideoDecCapiMock::SetCallback(std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
{
|
||||
if (cb != nullptr && codec_ != nullptr) {
|
||||
SetCallback(codec_, cb);
|
||||
struct OH_AVCodecAsyncCallback callback;
|
||||
callback.onError = VideoDecCapiMock::OnError;
|
||||
callback.onStreamChanged = VideoDecCapiMock::OnStreamChanged;
|
||||
callback.onNeedInputData = VideoDecCapiMock::OnNeedInputData;
|
||||
callback.onNeedOutputData = VideoDecCapiMock::OnNewOutputData;
|
||||
return OH_VideoDecoder_SetCallback(codec_, callback, NULL);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
SetCallback(codec_, cb);
|
||||
struct OH_AVCodecAsyncCallback callback;
|
||||
callback.onError = VideoDecCapiMock::OnError;
|
||||
callback.onStreamChanged = VideoDecCapiMock::OnStreamChanged;
|
||||
callback.onNeedInputData = VideoDecCapiMock::OnNeedInputData;
|
||||
callback.onNeedOutputData = VideoDecCapiMock::OnNewOutputData;
|
||||
return OH_VideoDecoder_SetCallback(codec_, callback, NULL);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
int32_t VideoDecCapiMock::SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
SetCallback(codec_, cb);
|
||||
struct OH_AVCodecCallback callback;
|
||||
@ -172,145 +169,101 @@ int32_t VideoDecCapiMock::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb
|
||||
|
||||
int32_t VideoDecCapiMock::SetOutputSurface(std::shared_ptr<SurfaceMock> surface)
|
||||
{
|
||||
if (codec_ != nullptr && surface != nullptr) {
|
||||
if (surface != nullptr) {
|
||||
auto surfaceMock = std::static_pointer_cast<SurfaceCapiMock>(surface);
|
||||
OHNativeWindow *nativeWindow = surfaceMock->GetSurface();
|
||||
if (nativeWindow != nullptr) {
|
||||
return OH_VideoDecoder_SetSurface(codec_, nativeWindow);
|
||||
}
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::Configure(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (codec_ != nullptr && format != nullptr) {
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
OH_AVFormat *avFormat = formatMock->GetFormat();
|
||||
if (avFormat != nullptr) {
|
||||
return OH_VideoDecoder_Configure(codec_, avFormat);
|
||||
}
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
OH_AVFormat *avFormat = formatMock->GetFormat();
|
||||
if (avFormat != nullptr) {
|
||||
return OH_VideoDecoder_Configure(codec_, avFormat);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::Start()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_Start(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_Start(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::Stop()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_Stop(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_Stop(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::Flush()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_Flush(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_Flush(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::Reset()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_Reset(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_Reset(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::Release()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
DelCallback(codec_);
|
||||
int32_t ret = OH_VideoDecoder_Destroy(codec_);
|
||||
codec_ = nullptr;
|
||||
return ret;
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
DelCallback(codec_);
|
||||
int32_t ret = OH_VideoDecoder_Destroy(codec_);
|
||||
codec_ = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<FormatMock> VideoDecCapiMock::GetOutputDescription()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
OH_AVFormat *format = OH_VideoDecoder_GetOutputDescription(codec_);
|
||||
return std::make_shared<AVFormatCapiMock>(format);
|
||||
}
|
||||
return nullptr;
|
||||
OH_AVFormat *format = OH_VideoDecoder_GetOutputDescription(codec_);
|
||||
return std::make_shared<AVFormatCapiMock>(format);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::SetParameter(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (codec_ != nullptr && format != nullptr) {
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
return OH_VideoDecoder_SetParameter(codec_, formatMock->GetFormat());
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
return OH_VideoDecoder_SetParameter(codec_, formatMock->GetFormat());
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_PushInputData(codec_, index, attr);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_PushInputData(codec_, index, attr);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::RenderOutputData(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_RenderOutputData(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_RenderOutputData(codec_, index);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::FreeOutputData(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_FreeOutputData(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_FreeOutputData(codec_, index);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::PushInputBuffer(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_PushInputBuffer(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_PushInputBuffer(codec_, index);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::RenderOutputBuffer(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_RenderOutputBuffer(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_RenderOutputBuffer(codec_, index);
|
||||
}
|
||||
|
||||
int32_t VideoDecCapiMock::FreeOutputBuffer(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoDecoder_FreeOutputBuffer(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoDecoder_FreeOutputBuffer(codec_, index);
|
||||
}
|
||||
|
||||
bool VideoDecCapiMock::IsValid()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
bool isValid = false;
|
||||
(void)OH_VideoDecoder_IsValid(codec_, &isValid);
|
||||
return isValid;
|
||||
}
|
||||
return false;
|
||||
bool isValid = false;
|
||||
(void)OH_VideoDecoder_IsValid(codec_, &isValid);
|
||||
return isValid;
|
||||
}
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
@ -30,7 +30,7 @@ public:
|
||||
explicit VideoDecCapiMock(OH_AVCodec *codec) : codec_(codec) {}
|
||||
~VideoDecCapiMock() = default;
|
||||
int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb) override;
|
||||
int32_t SetOutputSurface(std::shared_ptr<SurfaceMock> surface) override;
|
||||
int32_t Configure(std::shared_ptr<FormatMock> format) override;
|
||||
int32_t Start() override;
|
||||
@ -61,14 +61,14 @@ private:
|
||||
static void OnNewOutputDataExt(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData);
|
||||
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCallbackMock> cb);
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<VideoCodecCallbackMock> cb);
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<MediaCodecCallbackMock> cb);
|
||||
static void DelCallback(OH_AVCodec *codec);
|
||||
static std::shared_ptr<AVCodecCallbackMock> GetCallback(OH_AVCodec *codec);
|
||||
static std::shared_ptr<VideoCodecCallbackMock> GetCallbackExt(OH_AVCodec *codec);
|
||||
static std::shared_ptr<MediaCodecCallbackMock> GetCallbackExt(OH_AVCodec *codec);
|
||||
|
||||
static std::mutex mutex_;
|
||||
static std::map<OH_AVCodec *, std::shared_ptr<AVCodecCallbackMock>> mockCbMap_;
|
||||
static std::map<OH_AVCodec *, std::shared_ptr<VideoCodecCallbackMock>> mockCbExtMap_;
|
||||
static std::map<OH_AVCodec *, std::shared_ptr<MediaCodecCallbackMock>> mockCbExtMap_;
|
||||
OH_AVCodec *codec_ = nullptr;
|
||||
};
|
||||
} // namespace MediaAVCodec
|
||||
|
@ -26,7 +26,8 @@ namespace OHOS {
|
||||
namespace MediaAVCodec {
|
||||
std::mutex VideoEncCapiMock::mutex_;
|
||||
std::map<OH_AVCodec *, std::shared_ptr<AVCodecCallbackMock>> VideoEncCapiMock::mockCbMap_;
|
||||
std::map<OH_AVCodec *, std::shared_ptr<VideoCodecCallbackMock>> VideoEncCapiMock::mockCbExtMap_;
|
||||
std::map<OH_AVCodec *, std::shared_ptr<MediaCodecCallbackMock>> VideoEncCapiMock::mockCbExtMap_;
|
||||
std::map<OH_AVCodec *, std::shared_ptr<MediaCodecParameterCallbackMock>> VideoEncCapiMock::mockParamCbMap_;
|
||||
void VideoEncCapiMock::OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
@ -70,7 +71,7 @@ void VideoEncCapiMock::OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVM
|
||||
void VideoEncCapiMock::OnErrorExt(OH_AVCodec *codec, int32_t errorCode, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
mockCb->OnError(errorCode);
|
||||
}
|
||||
@ -79,7 +80,7 @@ void VideoEncCapiMock::OnErrorExt(OH_AVCodec *codec, int32_t errorCode, void *us
|
||||
void VideoEncCapiMock::OnStreamChangedExt(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
auto formatMock = std::make_shared<AVFormatCapiMock>(format);
|
||||
mockCb->OnStreamChanged(formatMock);
|
||||
@ -89,7 +90,7 @@ void VideoEncCapiMock::OnStreamChangedExt(OH_AVCodec *codec, OH_AVFormat *format
|
||||
void VideoEncCapiMock::OnNeedInputDataExt(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
std::shared_ptr<AVBufferMock> bufMock = data == nullptr ? nullptr : std::make_shared<AVBufferCapiMock>(data);
|
||||
mockCb->OnNeedInputData(index, bufMock);
|
||||
@ -99,13 +100,23 @@ void VideoEncCapiMock::OnNeedInputDataExt(OH_AVCodec *codec, uint32_t index, OH_
|
||||
void VideoEncCapiMock::OnNewOutputDataExt(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb = GetCallbackExt(codec);
|
||||
if (mockCb != nullptr) {
|
||||
std::shared_ptr<AVBufferMock> bufMock = data == nullptr ? nullptr : std::make_shared<AVBufferCapiMock>(data);
|
||||
mockCb->OnNewOutputData(index, bufMock);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoEncCapiMock::OnNeedInputParameter(OH_AVCodec *codec, uint32_t index, OH_AVFormat *parameter, void *userData)
|
||||
{
|
||||
(void)userData;
|
||||
std::shared_ptr<MediaCodecParameterCallbackMock> mockCb = GetParamCallback(codec);
|
||||
if (mockCb != nullptr) {
|
||||
auto formatMock = std::make_shared<AVFormatCapiMock>(parameter);
|
||||
mockCb->OnInputParameterAvailable(index, formatMock);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<AVCodecCallbackMock> VideoEncCapiMock::GetCallback(OH_AVCodec *codec)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@ -115,7 +126,7 @@ std::shared_ptr<AVCodecCallbackMock> VideoEncCapiMock::GetCallback(OH_AVCodec *c
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<VideoCodecCallbackMock> VideoEncCapiMock::GetCallbackExt(OH_AVCodec *codec)
|
||||
std::shared_ptr<MediaCodecCallbackMock> VideoEncCapiMock::GetCallbackExt(OH_AVCodec *codec)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (mockCbExtMap_.find(codec) != mockCbExtMap_.end()) {
|
||||
@ -124,18 +135,33 @@ std::shared_ptr<VideoCodecCallbackMock> VideoEncCapiMock::GetCallbackExt(OH_AVCo
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaCodecParameterCallbackMock> VideoEncCapiMock::GetParamCallback(OH_AVCodec *codec)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (mockParamCbMap_.find(codec) != mockParamCbMap_.end()) {
|
||||
return mockParamCbMap_.at(codec);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void VideoEncCapiMock::SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
mockCbMap_[codec] = cb;
|
||||
}
|
||||
|
||||
void VideoEncCapiMock::SetCallback(OH_AVCodec *codec, std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
void VideoEncCapiMock::SetCallback(OH_AVCodec *codec, std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
mockCbExtMap_[codec] = cb;
|
||||
}
|
||||
|
||||
void VideoEncCapiMock::SetCallback(OH_AVCodec *codec, std::shared_ptr<MediaCodecParameterCallbackMock> cb)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
mockParamCbMap_[codec] = cb;
|
||||
}
|
||||
|
||||
void VideoEncCapiMock::DelCallback(OH_AVCodec *codec)
|
||||
{
|
||||
auto it = mockCbMap_.find(codec);
|
||||
@ -159,10 +185,10 @@ int32_t VideoEncCapiMock::SetCallback(std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
callback.onNeedOutputData = VideoEncCapiMock::OnNewOutputData;
|
||||
return OH_VideoEncoder_SetCallback(codec_, callback, NULL);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return AV_ERR_UNKNOWN;
|
||||
};
|
||||
|
||||
int32_t VideoEncCapiMock::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
int32_t VideoEncCapiMock::SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
SetCallback(codec_, cb);
|
||||
struct OH_AVCodecCallback callback;
|
||||
@ -173,143 +199,112 @@ int32_t VideoEncCapiMock::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb
|
||||
return OH_VideoEncoder_RegisterCallback(codec_, callback, NULL);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::SetCallback(std::shared_ptr<MediaCodecParameterCallbackMock> cb)
|
||||
{
|
||||
SetCallback(codec_, cb);
|
||||
OH_VideoEncoder_OnNeedInputParameter callback = VideoEncCapiMock::OnNeedInputParameter;
|
||||
return OH_VideoEncoder_RegisterParameterCallback(codec_, callback, NULL);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::Configure(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (codec_ != nullptr && format != nullptr) {
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
OH_AVFormat *avFormat = formatMock->GetFormat();
|
||||
if (avFormat != nullptr) {
|
||||
return OH_VideoEncoder_Configure(codec_, avFormat);
|
||||
} else {
|
||||
cout << "VideoEncCapiMock::Configure: avFormat is null" << endl;
|
||||
}
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
OH_AVFormat *avFormat = formatMock->GetFormat();
|
||||
if (avFormat != nullptr) {
|
||||
return OH_VideoEncoder_Configure(codec_, avFormat);
|
||||
} else {
|
||||
cout << "VideoEncCapiMock::Configure: avFormat is null" << endl;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::Start()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_Start(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_Start(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::Stop()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_Stop(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_Stop(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::Flush()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_Flush(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_Flush(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::Reset()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_Reset(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_Reset(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::Release()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
DelCallback(codec_);
|
||||
int32_t ret = OH_VideoEncoder_Destroy(codec_);
|
||||
codec_ = nullptr;
|
||||
return ret;
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
DelCallback(codec_);
|
||||
int32_t ret = OH_VideoEncoder_Destroy(codec_);
|
||||
codec_ = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<FormatMock> VideoEncCapiMock::GetOutputDescription()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
OH_AVFormat *format = OH_VideoEncoder_GetOutputDescription(codec_);
|
||||
return std::make_shared<AVFormatCapiMock>(format);
|
||||
}
|
||||
return nullptr;
|
||||
OH_AVFormat *format = OH_VideoEncoder_GetOutputDescription(codec_);
|
||||
return std::make_shared<AVFormatCapiMock>(format);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::SetParameter(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (codec_ != nullptr && format != nullptr) {
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
return OH_VideoEncoder_SetParameter(codec_, formatMock->GetFormat());
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
auto formatMock = std::static_pointer_cast<AVFormatCapiMock>(format);
|
||||
return OH_VideoEncoder_SetParameter(codec_, formatMock->GetFormat());
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::FreeOutputData(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_FreeOutputData(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_FreeOutputData(codec_, index);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::NotifyEos()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_NotifyEndOfStream(codec_);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_NotifyEndOfStream(codec_);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_PushInputData(codec_, index, attr);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_PushInputData(codec_, index, attr);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::PushInputBuffer(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_PushInputBuffer(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_PushInputBuffer(codec_, index);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::PushInputParameter(uint32_t index)
|
||||
{
|
||||
return OH_VideoEncoder_PushInputParameter(codec_, index);
|
||||
}
|
||||
|
||||
int32_t VideoEncCapiMock::FreeOutputBuffer(uint32_t index)
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
return OH_VideoEncoder_FreeOutputBuffer(codec_, index);
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
return OH_VideoEncoder_FreeOutputBuffer(codec_, index);
|
||||
}
|
||||
|
||||
std::shared_ptr<SurfaceMock> VideoEncCapiMock::CreateInputSurface()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
OHNativeWindow *window;
|
||||
int32_t ret = OH_VideoEncoder_GetSurface(codec_, &window);
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, nullptr, "VideoEncCapiMock CreateInputSurface failed!");
|
||||
if (window != nullptr) {
|
||||
return std::make_shared<SurfaceCapiMock>(window);
|
||||
}
|
||||
OHNativeWindow *window;
|
||||
int32_t ret = OH_VideoEncoder_GetSurface(codec_, &window);
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, nullptr, "VideoEncCapiMock CreateInputSurface failed!");
|
||||
if (window != nullptr) {
|
||||
return std::make_shared<SurfaceCapiMock>(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool VideoEncCapiMock::IsValid()
|
||||
{
|
||||
if (codec_ != nullptr) {
|
||||
bool isValid = false;
|
||||
int32_t ret = OH_VideoEncoder_IsValid(codec_, &isValid);
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, false, "VideoEncCapiMock IsValid failed!");
|
||||
return isValid;
|
||||
}
|
||||
return false;
|
||||
bool isValid = false;
|
||||
int32_t ret = OH_VideoEncoder_IsValid(codec_, &isValid);
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, false, "VideoEncCapiMock IsValid failed!");
|
||||
return isValid;
|
||||
}
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
@ -28,7 +28,8 @@ class VideoEncCapiMock : public VideoEncMock {
|
||||
public:
|
||||
explicit VideoEncCapiMock(OH_AVCodec *codec) : codec_(codec) {}
|
||||
int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecParameterCallbackMock> cb) override;
|
||||
int32_t Configure(std::shared_ptr<FormatMock> format) override;
|
||||
int32_t Start() override;
|
||||
int32_t Stop() override;
|
||||
@ -41,6 +42,7 @@ public:
|
||||
int32_t NotifyEos() override;
|
||||
int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) override;
|
||||
int32_t PushInputBuffer(uint32_t index) override;
|
||||
int32_t PushInputParameter(uint32_t index) override;
|
||||
int32_t FreeOutputBuffer(uint32_t index) override;
|
||||
std::shared_ptr<SurfaceMock> CreateInputSurface() override;
|
||||
bool IsValid() override;
|
||||
@ -56,16 +58,20 @@ private:
|
||||
static void OnStreamChangedExt(OH_AVCodec *codec, OH_AVFormat *format, void *userData);
|
||||
static void OnNeedInputDataExt(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData);
|
||||
static void OnNewOutputDataExt(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData);
|
||||
static void OnNeedInputParameter(OH_AVCodec *codec, uint32_t index, OH_AVFormat *parameter, void *userData);
|
||||
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCallbackMock> cb);
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<VideoCodecCallbackMock> cb);
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<MediaCodecCallbackMock> cb);
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<MediaCodecParameterCallbackMock> cb);
|
||||
static void DelCallback(OH_AVCodec *codec);
|
||||
static std::shared_ptr<AVCodecCallbackMock> GetCallback(OH_AVCodec *codec);
|
||||
static std::shared_ptr<VideoCodecCallbackMock> GetCallbackExt(OH_AVCodec *codec);
|
||||
static std::shared_ptr<MediaCodecCallbackMock> GetCallbackExt(OH_AVCodec *codec);
|
||||
static std::shared_ptr<MediaCodecParameterCallbackMock> GetParamCallback(OH_AVCodec *codec);
|
||||
|
||||
static std::mutex mutex_;
|
||||
static std::map<OH_AVCodec *, std::shared_ptr<AVCodecCallbackMock>> mockCbMap_;
|
||||
static std::map<OH_AVCodec *, std::shared_ptr<VideoCodecCallbackMock>> mockCbExtMap_;
|
||||
static std::map<OH_AVCodec *, std::shared_ptr<MediaCodecCallbackMock>> mockCbExtMap_;
|
||||
static std::map<OH_AVCodec *, std::shared_ptr<MediaCodecParameterCallbackMock>> mockParamCbMap_;
|
||||
OH_AVCodec *codec_ = nullptr;
|
||||
};
|
||||
} // namespace MediaAVCodec
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MediaAVCodec {
|
||||
VideoDecCallbackExtMock::VideoDecCallbackExtMock(std::shared_ptr<VideoCodecCallbackMock> cb) : mockCb_(cb) {}
|
||||
VideoDecCallbackExtMock::VideoDecCallbackExtMock(std::shared_ptr<MediaCodecCallbackMock> cb) : mockCb_(cb) {}
|
||||
|
||||
void VideoDecCallbackExtMock::OnError(AVCodecErrorType errorType, int32_t errorCode)
|
||||
{
|
||||
@ -109,7 +109,7 @@ int32_t VideoDecInnerMock::SetCallback(std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoDecInnerMock::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
int32_t VideoDecInnerMock::SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
if (videoDec_ != nullptr) {
|
||||
std::shared_ptr<VideoDecCallbackExtMock> callback =
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
explicit VideoDecInnerMock(std::shared_ptr<AVCodecVideoDecoder> videoDec) : videoDec_(videoDec) {}
|
||||
~VideoDecInnerMock() = default;
|
||||
int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb) override;
|
||||
int32_t SetOutputSurface(std::shared_ptr<SurfaceMock> surface) override;
|
||||
int32_t Configure(std::shared_ptr<FormatMock> format) override;
|
||||
int32_t Start() override;
|
||||
@ -65,7 +65,7 @@ private:
|
||||
|
||||
class VideoDecCallbackExtMock : public MediaCodecCallback {
|
||||
public:
|
||||
explicit VideoDecCallbackExtMock(std::shared_ptr<VideoCodecCallbackMock> cb);
|
||||
explicit VideoDecCallbackExtMock(std::shared_ptr<MediaCodecCallbackMock> cb);
|
||||
~VideoDecCallbackExtMock() = default;
|
||||
void OnError(AVCodecErrorType errorType, int32_t errorCode) override;
|
||||
void OnOutputFormatChanged(const Format &format) override;
|
||||
@ -73,7 +73,7 @@ public:
|
||||
void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb_ = nullptr;
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb_ = nullptr;
|
||||
};
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MediaAVCodec {
|
||||
VideoEncCallbackExtMock::VideoEncCallbackExtMock(std::shared_ptr<VideoCodecCallbackMock> cb) : mockCb_(cb) {}
|
||||
VideoEncCallbackExtMock::VideoEncCallbackExtMock(std::shared_ptr<MediaCodecCallbackMock> cb) : mockCb_(cb) {}
|
||||
|
||||
void VideoEncCallbackExtMock::OnError(AVCodecErrorType errorType, int32_t errorCode)
|
||||
{
|
||||
@ -99,6 +99,19 @@ void VideoEncCallbackMock::OnOutputBufferAvailable(uint32_t index, AVCodecBuffer
|
||||
}
|
||||
}
|
||||
|
||||
VideoEncParamCallbackMock::VideoEncParamCallbackMock(std::shared_ptr<MediaCodecParameterCallbackMock> cb) : mockCb_(cb)
|
||||
{
|
||||
}
|
||||
|
||||
void VideoEncParamCallbackMock::OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter)
|
||||
{
|
||||
if (mockCb_ != nullptr) {
|
||||
auto formatMock = std::make_shared<AVFormatInnerMock>();
|
||||
formatMock->format_ = std::move(*parameter);
|
||||
mockCb_->OnInputParameterAvailable(index, formatMock);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t VideoEncInnerMock::SetCallback(std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
{
|
||||
if (videoEnc_ != nullptr) {
|
||||
@ -110,7 +123,7 @@ int32_t VideoEncInnerMock::SetCallback(std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoEncInnerMock::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
int32_t VideoEncInnerMock::SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
if (videoEnc_ != nullptr) {
|
||||
std::shared_ptr<VideoEncCallbackExtMock> callback =
|
||||
@ -120,6 +133,16 @@ int32_t VideoEncInnerMock::SetCallback(std::shared_ptr<VideoCodecCallbackMock> c
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoEncInnerMock::SetCallback(std::shared_ptr<MediaCodecParameterCallbackMock> cb)
|
||||
{
|
||||
if (videoEnc_ != nullptr) {
|
||||
std::shared_ptr<VideoEncParamCallbackMock> callback =
|
||||
cb == nullptr ? nullptr : std::make_shared<VideoEncParamCallbackMock>(cb);
|
||||
return videoEnc_->SetCallback(callback);
|
||||
}
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoEncInnerMock::Configure(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (videoEnc_ != nullptr) {
|
||||
@ -236,6 +259,14 @@ int32_t VideoEncInnerMock::PushInputBuffer(uint32_t index)
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoEncInnerMock::PushInputParameter(uint32_t index)
|
||||
{
|
||||
if (videoEnc_ != nullptr) {
|
||||
return videoEnc_->QueueInputParameter(index);
|
||||
}
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t VideoEncInnerMock::FreeOutputBuffer(uint32_t index)
|
||||
{
|
||||
if (videoEnc_ != nullptr) {
|
||||
|
@ -25,7 +25,8 @@ class VideoEncInnerMock : public VideoEncMock {
|
||||
public:
|
||||
explicit VideoEncInnerMock(std::shared_ptr<AVCodecVideoEncoder> videoEnc) : videoEnc_(videoEnc) {}
|
||||
int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb) override;
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecParameterCallbackMock> cb) override;
|
||||
int32_t Configure(std::shared_ptr<FormatMock> format) override;
|
||||
int32_t Start() override;
|
||||
int32_t Stop() override;
|
||||
@ -38,6 +39,7 @@ public:
|
||||
int32_t NotifyEos() override;
|
||||
int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) override;
|
||||
int32_t PushInputBuffer(uint32_t index) override;
|
||||
int32_t PushInputParameter(uint32_t index) override;
|
||||
int32_t FreeOutputBuffer(uint32_t index) override;
|
||||
std::shared_ptr<SurfaceMock> CreateInputSurface() override;
|
||||
bool IsValid() override;
|
||||
@ -62,7 +64,7 @@ private:
|
||||
|
||||
class VideoEncCallbackExtMock : public MediaCodecCallback {
|
||||
public:
|
||||
explicit VideoEncCallbackExtMock(std::shared_ptr<VideoCodecCallbackMock> cb);
|
||||
explicit VideoEncCallbackExtMock(std::shared_ptr<MediaCodecCallbackMock> cb);
|
||||
~VideoEncCallbackExtMock() = default;
|
||||
void OnError(AVCodecErrorType errorType, int32_t errorCode) override;
|
||||
void OnOutputFormatChanged(const Format &format) override;
|
||||
@ -70,7 +72,17 @@ public:
|
||||
void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VideoCodecCallbackMock> mockCb_ = nullptr;
|
||||
std::shared_ptr<MediaCodecCallbackMock> mockCb_ = nullptr;
|
||||
};
|
||||
|
||||
class VideoEncParamCallbackMock : public MediaCodecParameterCallback {
|
||||
public:
|
||||
explicit VideoEncParamCallbackMock(std::shared_ptr<MediaCodecParameterCallbackMock> cb);
|
||||
~VideoEncParamCallbackMock() = default;
|
||||
void OnInputParameterAvailable(uint32_t index, std::shared_ptr<Format> parameter) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<MediaCodecParameterCallbackMock> mockCb_ = nullptr;
|
||||
};
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
||||
|
@ -240,23 +240,27 @@ bool VideoDecSample::CreateVideoDecMockByName(const std::string &name)
|
||||
int32_t VideoDecSample::SetCallback(std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->SetCallback(cb);
|
||||
int32_t ret = videoDec_->SetCallback(cb);
|
||||
isAVBufferMode_ = ret != AV_ERR_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t VideoDecSample::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
int32_t VideoDecSample::SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->SetCallback(cb);
|
||||
int32_t ret = videoDec_->SetCallback(cb);
|
||||
isAVBufferMode_ = ret == AV_ERR_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t VideoDecSample::SetOutputSurface()
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
consumer_ = Surface::CreateSurfaceAsConsumer();
|
||||
@ -274,7 +278,7 @@ int32_t VideoDecSample::SetOutputSurface()
|
||||
int32_t VideoDecSample::Configure(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->Configure(format);
|
||||
}
|
||||
@ -282,25 +286,16 @@ int32_t VideoDecSample::Configure(std::shared_ptr<FormatMock> format)
|
||||
int32_t VideoDecSample::Start()
|
||||
{
|
||||
if (signal_ == nullptr || videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
PrepareInner();
|
||||
int32_t ret = videoDec_->Start();
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, ret, "Fatal: Start fail");
|
||||
RunInner();
|
||||
WaitForEos();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t VideoDecSample::StartBuffer()
|
||||
{
|
||||
if (signal_ == nullptr || videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
if (isAVBufferMode_) {
|
||||
RunInnerExt();
|
||||
} else {
|
||||
RunInner();
|
||||
}
|
||||
PrepareInner();
|
||||
int32_t ret = videoDec_->Start();
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, ret, "Fatal: Start fail");
|
||||
RunInnerExt();
|
||||
WaitForEos();
|
||||
return ret;
|
||||
}
|
||||
@ -309,7 +304,7 @@ int32_t VideoDecSample::Stop()
|
||||
{
|
||||
FlushInner();
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->Stop();
|
||||
}
|
||||
@ -318,7 +313,7 @@ int32_t VideoDecSample::Flush()
|
||||
{
|
||||
FlushInner();
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->Flush();
|
||||
}
|
||||
@ -327,7 +322,7 @@ int32_t VideoDecSample::Reset()
|
||||
{
|
||||
FlushInner();
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->Reset();
|
||||
}
|
||||
@ -336,7 +331,7 @@ int32_t VideoDecSample::Release()
|
||||
{
|
||||
FlushInner();
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->Release();
|
||||
}
|
||||
@ -352,7 +347,7 @@ std::shared_ptr<FormatMock> VideoDecSample::GetOutputDescription()
|
||||
int32_t VideoDecSample::SetParameter(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->SetParameter(format);
|
||||
}
|
||||
@ -360,7 +355,7 @@ int32_t VideoDecSample::SetParameter(std::shared_ptr<FormatMock> format)
|
||||
int32_t VideoDecSample::PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
frameInputCount_++;
|
||||
return videoDec_->PushInputData(index, attr);
|
||||
@ -369,7 +364,7 @@ int32_t VideoDecSample::PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr
|
||||
int32_t VideoDecSample::RenderOutputData(uint32_t index)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->RenderOutputData(index);
|
||||
}
|
||||
@ -377,7 +372,7 @@ int32_t VideoDecSample::RenderOutputData(uint32_t index)
|
||||
int32_t VideoDecSample::FreeOutputData(uint32_t index)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->FreeOutputData(index);
|
||||
}
|
||||
@ -385,7 +380,7 @@ int32_t VideoDecSample::FreeOutputData(uint32_t index)
|
||||
int32_t VideoDecSample::PushInputBuffer(uint32_t index)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
frameInputCount_++;
|
||||
return videoDec_->PushInputBuffer(index);
|
||||
@ -394,7 +389,7 @@ int32_t VideoDecSample::PushInputBuffer(uint32_t index)
|
||||
int32_t VideoDecSample::RenderOutputBuffer(uint32_t index)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->RenderOutputBuffer(index);
|
||||
}
|
||||
@ -402,7 +397,7 @@ int32_t VideoDecSample::RenderOutputBuffer(uint32_t index)
|
||||
int32_t VideoDecSample::FreeOutputBuffer(uint32_t index)
|
||||
{
|
||||
if (videoDec_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoDec_->FreeOutputBuffer(index);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ private:
|
||||
std::shared_ptr<VDecSignal> signal_ = nullptr;
|
||||
};
|
||||
|
||||
class VDecCallbackTestExt : public VideoCodecCallbackMock {
|
||||
class VDecCallbackTestExt : public MediaCodecCallbackMock {
|
||||
public:
|
||||
explicit VDecCallbackTestExt(std::shared_ptr<VDecSignal> signal);
|
||||
virtual ~VDecCallbackTestExt();
|
||||
@ -95,11 +95,10 @@ public:
|
||||
bool CreateVideoDecMockByName(const std::string &name);
|
||||
|
||||
int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb);
|
||||
int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb);
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb);
|
||||
int32_t SetOutputSurface();
|
||||
int32_t Configure(std::shared_ptr<FormatMock> format);
|
||||
int32_t Start();
|
||||
int32_t StartBuffer();
|
||||
int32_t Stop();
|
||||
int32_t Flush();
|
||||
int32_t Reset();
|
||||
@ -151,6 +150,7 @@ private:
|
||||
uint32_t datSize_ = 0;
|
||||
uint32_t frameInputCount_ = 0;
|
||||
uint32_t frameOutputCount_ = 0;
|
||||
bool isAVBufferMode_ = false;
|
||||
bool isSurfaceMode_ = false;
|
||||
bool isH264Stream_ = true; // true: H264; false: H265
|
||||
int64_t time_ = 0;
|
||||
|
@ -48,8 +48,7 @@ void VEncCallbackTest::OnError(int32_t errorCode)
|
||||
|
||||
void VEncCallbackTest::OnStreamChanged(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
(void)format;
|
||||
cout << "VEnc Format Changed" << endl;
|
||||
UNITTEST_INFO_LOG("format changed: %s", format->DumpInfo());
|
||||
}
|
||||
|
||||
void VEncCallbackTest::OnNeedInputData(uint32_t index, std::shared_ptr<AVMemoryMock> data)
|
||||
@ -97,8 +96,7 @@ void VEncCallbackTestExt::OnError(int32_t errorCode)
|
||||
|
||||
void VEncCallbackTestExt::OnStreamChanged(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
(void)format;
|
||||
cout << "VEnc Format Changed" << endl;
|
||||
UNITTEST_INFO_LOG("format changed: %s", format->DumpInfo());
|
||||
}
|
||||
|
||||
void VEncCallbackTestExt::OnNeedInputData(uint32_t index, std::shared_ptr<AVBufferMock> data)
|
||||
@ -129,6 +127,24 @@ void VEncCallbackTestExt::OnNewOutputData(uint32_t index, std::shared_ptr<AVBuff
|
||||
signal_->outCond_.notify_all();
|
||||
}
|
||||
|
||||
VEncParamCallbackTest::VEncParamCallbackTest(std::shared_ptr<VEncSignal> signal) : signal_(signal) {}
|
||||
|
||||
VEncParamCallbackTest::~VEncParamCallbackTest() {}
|
||||
|
||||
void VEncParamCallbackTest::OnInputParameterAvailable(uint32_t index, std::shared_ptr<FormatMock> parameter)
|
||||
{
|
||||
if (signal_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
unique_lock<mutex> lock(signal_->inMutex_);
|
||||
if (!signal_->isRunning_.load() && !signal_->isPreparing_.load()) {
|
||||
return;
|
||||
}
|
||||
signal_->inIndexQueue_.push(index);
|
||||
signal_->inFormatQueue_.push(parameter);
|
||||
signal_->inCond_.notify_all();
|
||||
}
|
||||
|
||||
VideoEncSample::VideoEncSample(std::shared_ptr<VEncSignal> signal)
|
||||
: signal_(signal), inPath_("/data/test/media/1280_720_nv.yuv"), nativeWindow_(nullptr)
|
||||
{
|
||||
@ -173,23 +189,37 @@ bool VideoEncSample::CreateVideoEncMockByName(const std::string &name)
|
||||
int32_t VideoEncSample::SetCallback(std::shared_ptr<AVCodecCallbackMock> cb)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->SetCallback(cb);
|
||||
int32_t ret = videoEnc_->SetCallback(cb);
|
||||
isAVBufferMode_ = ret != AV_ERR_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t VideoEncSample::SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb)
|
||||
int32_t VideoEncSample::SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->SetCallback(cb);
|
||||
int32_t ret = videoEnc_->SetCallback(cb);
|
||||
isAVBufferMode_ = ret == AV_ERR_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t VideoEncSample::SetCallback(std::shared_ptr<MediaCodecParameterCallbackMock> cb)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
int32_t ret = videoEnc_->SetCallback(cb);
|
||||
isSetParamCallback_ = ret == AV_ERR_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t VideoEncSample::Configure(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->Configure(format);
|
||||
}
|
||||
@ -197,25 +227,16 @@ int32_t VideoEncSample::Configure(std::shared_ptr<FormatMock> format)
|
||||
int32_t VideoEncSample::Start()
|
||||
{
|
||||
if (signal_ == nullptr || videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
PrepareInner();
|
||||
int32_t ret = videoEnc_->Start();
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, ret, "Fatal: Start fail");
|
||||
RunInner();
|
||||
WaitForEos();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t VideoEncSample::StartBuffer()
|
||||
{
|
||||
if (signal_ == nullptr || videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
if (isAVBufferMode_) {
|
||||
RunInnerExt();
|
||||
} else {
|
||||
RunInner();
|
||||
}
|
||||
PrepareInner();
|
||||
int32_t ret = videoEnc_->Start();
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, ret, "Fatal: Start fail");
|
||||
RunInnerExt();
|
||||
WaitForEos();
|
||||
return ret;
|
||||
}
|
||||
@ -223,7 +244,7 @@ int32_t VideoEncSample::StartBuffer()
|
||||
int32_t VideoEncSample::Stop()
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->Stop();
|
||||
}
|
||||
@ -231,7 +252,7 @@ int32_t VideoEncSample::Stop()
|
||||
int32_t VideoEncSample::Flush()
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->Flush();
|
||||
}
|
||||
@ -239,7 +260,7 @@ int32_t VideoEncSample::Flush()
|
||||
int32_t VideoEncSample::Reset()
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->Reset();
|
||||
}
|
||||
@ -247,7 +268,7 @@ int32_t VideoEncSample::Reset()
|
||||
int32_t VideoEncSample::Release()
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->Release();
|
||||
}
|
||||
@ -263,7 +284,7 @@ std::shared_ptr<FormatMock> VideoEncSample::GetOutputDescription()
|
||||
int32_t VideoEncSample::SetParameter(std::shared_ptr<FormatMock> format)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->SetParameter(format);
|
||||
}
|
||||
@ -271,7 +292,7 @@ int32_t VideoEncSample::SetParameter(std::shared_ptr<FormatMock> format)
|
||||
int32_t VideoEncSample::NotifyEos()
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->NotifyEos();
|
||||
}
|
||||
@ -279,7 +300,7 @@ int32_t VideoEncSample::NotifyEos()
|
||||
int32_t VideoEncSample::PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
frameInputCount_++;
|
||||
return videoEnc_->PushInputData(index, attr);
|
||||
@ -288,7 +309,7 @@ int32_t VideoEncSample::PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr
|
||||
int32_t VideoEncSample::FreeOutputData(uint32_t index)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->FreeOutputData(index);
|
||||
}
|
||||
@ -296,16 +317,24 @@ int32_t VideoEncSample::FreeOutputData(uint32_t index)
|
||||
int32_t VideoEncSample::PushInputBuffer(uint32_t index)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
frameInputCount_++;
|
||||
return videoEnc_->PushInputBuffer(index);
|
||||
}
|
||||
|
||||
int32_t VideoEncSample::PushInputParameter(uint32_t index)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->PushInputParameter(index);
|
||||
}
|
||||
|
||||
int32_t VideoEncSample::FreeOutputBuffer(uint32_t index)
|
||||
{
|
||||
if (videoEnc_ == nullptr) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
return videoEnc_->FreeOutputBuffer(index);
|
||||
}
|
||||
@ -402,6 +431,9 @@ void VideoEncSample::FlushInner()
|
||||
ASSERT_TRUE(inFile_->is_open());
|
||||
}
|
||||
}
|
||||
if (inputSurfaceLoop_ != nullptr && inputSurfaceLoop_->joinable()) {
|
||||
inputSurfaceLoop_->join();
|
||||
}
|
||||
if (outputLoop_ != nullptr && outputLoop_->joinable()) {
|
||||
unique_lock<mutex> lock(signal_->outMutex_);
|
||||
std::queue<uint32_t> tempIndex;
|
||||
@ -434,11 +466,13 @@ void VideoEncSample::RunInner()
|
||||
signal_->isPreparing_.store(false);
|
||||
signal_->isRunning_.store(true);
|
||||
if (isSurfaceMode_) {
|
||||
inputLoop_ = make_unique<thread>(&VideoEncSample::InputFuncSurface, this);
|
||||
inputSurfaceLoop_ = make_unique<thread>(&VideoEncSample::InputFuncSurface, this);
|
||||
inputLoop_ = isSetParamCallback_ ? make_unique<thread>(&VideoEncSample::InputParamLoopFunc, this) : nullptr;
|
||||
ASSERT_NE(inputSurfaceLoop_, nullptr);
|
||||
} else {
|
||||
inputLoop_ = make_unique<thread>(&VideoEncSample::InputLoopFunc, this);
|
||||
ASSERT_NE(inputLoop_, nullptr);
|
||||
}
|
||||
ASSERT_NE(inputLoop_, nullptr);
|
||||
signal_->inCond_.notify_all();
|
||||
|
||||
outputLoop_ = make_unique<thread>(&VideoEncSample::OutputLoopFunc, this);
|
||||
@ -454,11 +488,13 @@ void VideoEncSample::RunInnerExt()
|
||||
signal_->isPreparing_.store(false);
|
||||
signal_->isRunning_.store(true);
|
||||
if (isSurfaceMode_) {
|
||||
inputLoop_ = make_unique<thread>(&VideoEncSample::InputFuncSurface, this);
|
||||
inputSurfaceLoop_ = make_unique<thread>(&VideoEncSample::InputFuncSurface, this);
|
||||
inputLoop_ = isSetParamCallback_ ? make_unique<thread>(&VideoEncSample::InputParamLoopFunc, this) : nullptr;
|
||||
ASSERT_NE(inputSurfaceLoop_, nullptr);
|
||||
} else {
|
||||
inputLoop_ = make_unique<thread>(&VideoEncSample::InputLoopFuncExt, this);
|
||||
ASSERT_NE(inputLoop_, nullptr);
|
||||
}
|
||||
ASSERT_NE(inputLoop_, nullptr);
|
||||
signal_->inCond_.notify_all();
|
||||
|
||||
outputLoop_ = make_unique<thread>(&VideoEncSample::OutputLoopFuncExt, this);
|
||||
@ -500,6 +536,33 @@ void VideoEncSample::PrepareInner()
|
||||
time_ = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now()).time_since_epoch().count();
|
||||
}
|
||||
|
||||
void VideoEncSample::InputParamLoopFunc()
|
||||
{
|
||||
ASSERT_NE(signal_, nullptr);
|
||||
ASSERT_NE(videoEnc_, nullptr);
|
||||
frameInputCount_ = 0;
|
||||
isFirstFrame_ = true;
|
||||
while (signal_->isRunning_.load()) {
|
||||
unique_lock<mutex> lock(signal_->inMutex_);
|
||||
signal_->inCond_.wait(
|
||||
lock, [this]() { return (signal_->inIndexQueue_.size() > 0) || (!signal_->isRunning_.load()); });
|
||||
UNITTEST_CHECK_AND_BREAK_LOG(signal_->isRunning_.load(), "InputLoopFunc stop running");
|
||||
|
||||
int32_t index = signal_->inIndexQueue_.front();
|
||||
auto format = signal_->inFormatQueue_.front();
|
||||
UNITTEST_INFO_LOG("parameter: %s", format->DumpInfo());
|
||||
|
||||
format->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH_VENC);
|
||||
format->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT_VENC);
|
||||
format->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
|
||||
int32_t ret = PushInputParameter(index);
|
||||
UNITTEST_CHECK_AND_BREAK_LOG(ret == AV_ERR_OK, "Fatal: PushInputData fail, exit");
|
||||
|
||||
signal_->inIndexQueue_.pop();
|
||||
signal_->inFormatQueue_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
void VideoEncSample::InputLoopFunc()
|
||||
{
|
||||
ASSERT_NE(signal_, nullptr);
|
||||
@ -511,7 +574,6 @@ void VideoEncSample::InputLoopFunc()
|
||||
signal_->inCond_.wait(
|
||||
lock, [this]() { return (signal_->inIndexQueue_.size() > 0) || (!signal_->isRunning_.load()); });
|
||||
UNITTEST_CHECK_AND_BREAK_LOG(signal_->isRunning_.load(), "InputLoopFunc stop running");
|
||||
UNITTEST_CHECK_AND_BREAK_LOG(inFile_ != nullptr && inFile_->is_open(), "inFile_ is closed");
|
||||
|
||||
int32_t ret = InputLoopInner();
|
||||
UNITTEST_CHECK_AND_BREAK_LOG(ret == AV_ERR_OK, "PushInputData fail or eos, exit");
|
||||
@ -599,12 +661,12 @@ int32_t VideoEncSample::OutputLoopInner()
|
||||
auto buffer = signal_->outMemoryQueue_.front();
|
||||
|
||||
if (NEED_DUMP && attr.flags != AVCODEC_BUFFER_FLAG_EOS) {
|
||||
if (!outFile_->is_open()) {
|
||||
cout << "output data fail" << endl;
|
||||
} else {
|
||||
if (outFile_->is_open()) {
|
||||
UNITTEST_CHECK_AND_RETURN_RET_LOG(buffer != nullptr, AV_ERR_INVALID_VAL,
|
||||
"Fatal: GetOutputBuffer fail, exit");
|
||||
outFile_->write(reinterpret_cast<char *>(buffer->GetAddr()), attr.size);
|
||||
} else {
|
||||
UNITTEST_INFO_LOG("output data fail");
|
||||
}
|
||||
}
|
||||
ret = FreeOutputData(index);
|
||||
@ -667,10 +729,10 @@ int32_t VideoEncSample::OutputLoopInnerExt()
|
||||
struct OH_AVCodecBufferAttr attr;
|
||||
(void)buffer->GetBufferAttr(attr);
|
||||
if (NEED_DUMP && attr.flags != AVCODEC_BUFFER_FLAG_EOS) {
|
||||
if (!outFile_->is_open()) {
|
||||
cout << "output data fail" << endl;
|
||||
} else {
|
||||
if (outFile_->is_open()) {
|
||||
outFile_->write(reinterpret_cast<char *>(buffer->GetAddr()), attr.size);
|
||||
} else {
|
||||
UNITTEST_INFO_LOG("output data fail");
|
||||
}
|
||||
}
|
||||
ret = FreeOutputBuffer(index);
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
std::queue<std::shared_ptr<AVMemoryMock>> outMemoryQueue_;
|
||||
std::queue<std::shared_ptr<AVBufferMock>> inBufferQueue_;
|
||||
std::queue<std::shared_ptr<AVBufferMock>> outBufferQueue_;
|
||||
std::queue<std::shared_ptr<FormatMock>> inFormatQueue_;
|
||||
int32_t errorNum_ = 0;
|
||||
std::atomic<bool> isRunning_ = false;
|
||||
std::atomic<bool> isPreparing_ = true;
|
||||
@ -61,7 +62,7 @@ private:
|
||||
std::shared_ptr<VEncSignal> signal_ = nullptr;
|
||||
};
|
||||
|
||||
class VEncCallbackTestExt : public VideoCodecCallbackMock {
|
||||
class VEncCallbackTestExt : public MediaCodecCallbackMock {
|
||||
public:
|
||||
explicit VEncCallbackTestExt(std::shared_ptr<VEncSignal> signal);
|
||||
virtual ~VEncCallbackTestExt();
|
||||
@ -74,6 +75,16 @@ private:
|
||||
std::shared_ptr<VEncSignal> signal_ = nullptr;
|
||||
};
|
||||
|
||||
class VEncParamCallbackTest : public MediaCodecParameterCallbackMock {
|
||||
public:
|
||||
explicit VEncParamCallbackTest(std::shared_ptr<VEncSignal> signal);
|
||||
virtual ~VEncParamCallbackTest();
|
||||
void OnInputParameterAvailable(uint32_t index, std::shared_ptr<FormatMock> parameter) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VEncSignal> signal_ = nullptr;
|
||||
};
|
||||
|
||||
class VideoEncSample : public NoCopyable {
|
||||
public:
|
||||
explicit VideoEncSample(std::shared_ptr<VEncSignal> signal);
|
||||
@ -83,10 +94,10 @@ public:
|
||||
|
||||
int32_t Release();
|
||||
int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb);
|
||||
int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb);
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb);
|
||||
int32_t SetCallback(std::shared_ptr<MediaCodecParameterCallbackMock> cb);
|
||||
int32_t Configure(std::shared_ptr<FormatMock> format);
|
||||
int32_t Start();
|
||||
int32_t StartBuffer();
|
||||
int32_t Stop();
|
||||
int32_t Flush();
|
||||
int32_t Reset();
|
||||
@ -96,6 +107,7 @@ public:
|
||||
int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr);
|
||||
int32_t FreeOutputData(uint32_t index);
|
||||
int32_t PushInputBuffer(uint32_t index);
|
||||
int32_t PushInputParameter(uint32_t index);
|
||||
int32_t FreeOutputBuffer(uint32_t index);
|
||||
int32_t CreateInputSurface();
|
||||
bool IsValid();
|
||||
@ -114,6 +126,8 @@ private:
|
||||
int32_t ReadOneFrame();
|
||||
|
||||
void RunInner();
|
||||
void InputParamLoopFunc();
|
||||
|
||||
void OutputLoopFunc();
|
||||
void InputLoopFunc();
|
||||
int32_t OutputLoopInner();
|
||||
@ -129,15 +143,18 @@ private:
|
||||
std::unique_ptr<std::ofstream> outFile_;
|
||||
std::unique_ptr<std::thread> inputLoop_;
|
||||
std::unique_ptr<std::thread> outputLoop_;
|
||||
std::unique_ptr<std::thread> inputSurfaceLoop_;
|
||||
std::shared_ptr<VEncSignal> signal_ = nullptr;
|
||||
std::string inPath_;
|
||||
std::string outPath_;
|
||||
std::string outSurfacePath_;
|
||||
uint32_t frameInputCount_ = 0;
|
||||
uint32_t frameOutputCount_ = 0;
|
||||
bool isAVBufferMode_ = false;
|
||||
bool isFirstFrame_ = true;
|
||||
bool isSurfaceMode_ = false;
|
||||
bool isHdrVivid_ = false;
|
||||
bool isSetParamCallback_ = false;
|
||||
int64_t time_ = 0;
|
||||
sptr<Surface> consumer_ = nullptr;
|
||||
sptr<Surface> producer_ = nullptr;
|
||||
|
@ -44,21 +44,27 @@ public:
|
||||
virtual void OnNewOutputData(uint32_t index, std::shared_ptr<AVMemoryMock> data, OH_AVCodecBufferAttr attr) = 0;
|
||||
};
|
||||
|
||||
class VideoCodecCallbackMock : public NoCopyable {
|
||||
class MediaCodecCallbackMock : public NoCopyable {
|
||||
public:
|
||||
virtual ~VideoCodecCallbackMock() = default;
|
||||
virtual ~MediaCodecCallbackMock() = default;
|
||||
virtual void OnError(int32_t errorCode) = 0;
|
||||
virtual void OnStreamChanged(std::shared_ptr<FormatMock> format) = 0;
|
||||
virtual void OnNeedInputData(uint32_t index, std::shared_ptr<AVBufferMock> data) = 0;
|
||||
virtual void OnNewOutputData(uint32_t index, std::shared_ptr<AVBufferMock> data) = 0;
|
||||
};
|
||||
|
||||
class MediaCodecParameterCallbackMock : public NoCopyable {
|
||||
public:
|
||||
virtual ~MediaCodecParameterCallbackMock() = default;
|
||||
virtual void OnInputParameterAvailable(uint32_t index, std::shared_ptr<FormatMock> parameter) = 0;
|
||||
};
|
||||
|
||||
class VideoDecMock : public NoCopyable {
|
||||
public:
|
||||
virtual ~VideoDecMock() = default;
|
||||
virtual int32_t Release() = 0;
|
||||
virtual int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) = 0;
|
||||
virtual int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb) = 0;
|
||||
virtual int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb) = 0;
|
||||
virtual int32_t SetOutputSurface(std::shared_ptr<SurfaceMock> surface) = 0;
|
||||
virtual int32_t Configure(std::shared_ptr<FormatMock> format) = 0;
|
||||
virtual int32_t Start() = 0;
|
||||
@ -81,7 +87,8 @@ public:
|
||||
virtual ~VideoEncMock() = default;
|
||||
virtual int32_t Release() = 0;
|
||||
virtual int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) = 0;
|
||||
virtual int32_t SetCallback(std::shared_ptr<VideoCodecCallbackMock> cb) = 0;
|
||||
virtual int32_t SetCallback(std::shared_ptr<MediaCodecCallbackMock> cb) = 0;
|
||||
virtual int32_t SetCallback(std::shared_ptr<MediaCodecParameterCallbackMock> cb) = 0;
|
||||
virtual int32_t Configure(std::shared_ptr<FormatMock> format) = 0;
|
||||
virtual int32_t Start() = 0;
|
||||
virtual int32_t Stop() = 0;
|
||||
@ -93,6 +100,7 @@ public:
|
||||
virtual int32_t NotifyEos() = 0;
|
||||
virtual int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) = 0;
|
||||
virtual int32_t PushInputBuffer(uint32_t index) = 0;
|
||||
virtual int32_t PushInputParameter(uint32_t index) = 0;
|
||||
virtual int32_t FreeOutputBuffer(uint32_t index) = 0;
|
||||
virtual std::shared_ptr<SurfaceMock> CreateInputSurface() = 0;
|
||||
virtual bool IsValid() = 0;
|
||||
|
@ -277,7 +277,7 @@ void OutputBufferLoop(shared_ptr<VideoDecSignal> &signal)
|
||||
return !signal->isRunning_.load() || signal->isFlushing_.load() || signal->outQueue_.size() > 0;
|
||||
});
|
||||
if (signal->isFlushing_.load()) {
|
||||
signal->inCond_.wait(lock, [&signal]() { return !signal->isFlushing_.load(); });
|
||||
signal->outCond_.wait(lock, [&signal]() { return !signal->isFlushing_.load(); });
|
||||
continue;
|
||||
}
|
||||
if (!signal->isRunning_.load()) {
|
||||
@ -303,7 +303,7 @@ void OutputSurfaceLoop(shared_ptr<VideoDecSignal> &signal)
|
||||
return !signal->isRunning_.load() || signal->isFlushing_.load() || signal->outQueue_.size() > 0;
|
||||
});
|
||||
if (signal->isFlushing_.load()) {
|
||||
signal->inCond_.wait(lock, [&signal]() { return !signal->isFlushing_.load(); });
|
||||
signal->outCond_.wait(lock, [&signal]() { return !signal->isFlushing_.load(); });
|
||||
continue;
|
||||
}
|
||||
if (!signal->isRunning_.load()) {
|
||||
|
@ -217,7 +217,6 @@ void TEST_SUIT::CreateByNameWithParam(void)
|
||||
AVCodecCategory::AVCODEC_HARDWARE);
|
||||
break;
|
||||
case VCodecTestCode::HW_HEVC:
|
||||
case VCodecTestCode::HW_HDR:
|
||||
capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_HEVC.data(), false,
|
||||
AVCodecCategory::AVCODEC_HARDWARE);
|
||||
break;
|
||||
@ -235,7 +234,7 @@ void TEST_SUIT::PrepareSource(void)
|
||||
{
|
||||
VCodecTestCode param = static_cast<VCodecTestCode>(GetParam());
|
||||
std::string sourcePath = decSourcePathMap_.at(param);
|
||||
if (param == VCodecTestCode::HW_HEVC || param == VCodecTestCode::HW_HDR) {
|
||||
if (param == VCodecTestCode::HW_HEVC) {
|
||||
videoDec_->SetSourceType(false);
|
||||
}
|
||||
videoDec_->testParam_ = param;
|
||||
@ -256,7 +255,7 @@ void TEST_SUIT::SetFormatWithParam(void)
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, static_cast<int32_t>(VideoPixelFormat::NV12));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(, TEST_SUIT, testing::Values(HW_AVC, HW_HEVC, HW_HDR, SW_AVC));
|
||||
INSTANTIATE_TEST_SUITE_P(, TEST_SUIT, testing::Values(HW_AVC, HW_HEVC, SW_AVC));
|
||||
|
||||
/**
|
||||
* @tc.name: videoDecoder_multithread_create_001
|
||||
@ -659,7 +658,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_001, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
|
||||
@ -675,7 +673,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_002, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
@ -693,7 +690,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_003, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Flush());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
@ -711,7 +707,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_004, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
@ -725,7 +720,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_005, TestSize.Level1)
|
||||
{
|
||||
CreateByNameWithParam();
|
||||
PrepareSource();
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
|
||||
@ -740,10 +734,9 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_buffer_001, TestSize.Level1)
|
||||
CreateByNameWithParam();
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
videoDec_->needCheckSHA_ = GetParam() != VCodecTestCode::HW_HDR;
|
||||
videoDec_->needCheckSHA_ = true;
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -757,13 +750,12 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_buffer_002, TestSize.Level1)
|
||||
CreateByNameWithParam();
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
videoDec_->needCheckSHA_ = GetParam() != VCodecTestCode::HW_HDR;
|
||||
videoDec_->needCheckSHA_ = true;
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -777,13 +769,12 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_buffer_003, TestSize.Level1)
|
||||
CreateByNameWithParam();
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
videoDec_->needCheckSHA_ = GetParam() != VCodecTestCode::HW_HDR;
|
||||
videoDec_->needCheckSHA_ = true;
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Flush());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -796,8 +787,7 @@ HWTEST_P(TEST_SUIT, videoDecoder_start_buffer_004, TestSize.Level1)
|
||||
isAVBufferMode_ = true;
|
||||
CreateByNameWithParam();
|
||||
PrepareSource();
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -812,7 +802,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_stop_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
}
|
||||
@ -829,7 +818,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_stop_002, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Flush());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
@ -861,7 +849,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_flush_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Flush());
|
||||
}
|
||||
@ -878,7 +865,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_flush_002, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Release());
|
||||
@ -897,7 +883,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_reset_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Reset());
|
||||
@ -929,7 +914,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_reset_003, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Reset());
|
||||
}
|
||||
@ -946,7 +930,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_release_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Release());
|
||||
@ -964,7 +947,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_release_002, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Release());
|
||||
}
|
||||
@ -1023,7 +1005,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_setsurface_003, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
ASSERT_NE(AV_ERR_OK, videoDec_->SetOutputSurface());
|
||||
}
|
||||
@ -1041,8 +1022,7 @@ HWTEST_P(TEST_SUIT, videoDecoder_setsurface_buffer_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->SetOutputSurface());
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
}
|
||||
|
||||
@ -1058,8 +1038,7 @@ HWTEST_P(TEST_SUIT, videoDecoder_setsurface_buffer_002, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
ASSERT_NE(AV_ERR_OK, videoDec_->SetOutputSurface());
|
||||
}
|
||||
|
||||
@ -1078,7 +1057,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_abnormal_001, TestSize.Level1)
|
||||
|
||||
videoDec_->Configure(format_);
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Reset());
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->Flush());
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->Stop());
|
||||
@ -1093,7 +1071,6 @@ HWTEST_P(TEST_SUIT, videoDecoder_abnormal_002, TestSize.Level1)
|
||||
{
|
||||
CreateByNameWithParam();
|
||||
PrepareSource();
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_NE(AV_ERR_OK, videoDec_->Start());
|
||||
}
|
||||
|
||||
@ -1140,7 +1117,7 @@ HWTEST_P(TEST_SUIT, videoDecoder_setParameter_001, TestSize.Level1)
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, static_cast<int32_t>(VideoPixelFormat::YUV420P));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->SetParameter(format_));
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
@ -1165,7 +1142,7 @@ HWTEST_P(TEST_SUIT, videoDecoder_setParameter_002, TestSize.Level1)
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, -2); // invalid height size -2
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, static_cast<int32_t>(VideoPixelFormat::YUV420P));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->SetParameter(format_));
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
@ -1183,10 +1160,45 @@ HWTEST_P(TEST_SUIT, videoDecoder_getOutputDescription_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
format_ = videoDec_->GetOutputDescription();
|
||||
EXPECT_NE(nullptr, format_);
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoDecoder_hdr_function_001
|
||||
* @tc.desc: video decodec hdr function test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TEST_SUIT, videoDecoder_hdr_function_001, TestSize.Level1)
|
||||
{
|
||||
capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_HEVC.data(), false,
|
||||
AVCodecCategory::AVCODEC_HARDWARE);
|
||||
std::string codecName = capability_->GetName();
|
||||
std::cout << "CodecName: " << codecName << "\n";
|
||||
ASSERT_TRUE(CreateVideoCodecByName(codecName));
|
||||
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, static_cast<int32_t>(VideoPixelFormat::NV12));
|
||||
|
||||
VCodecTestCode param = VCodecTestCode::HW_HDR;
|
||||
std::string sourcePath = decSourcePathMap_.at(param);
|
||||
videoDec_->SetSourceType(false);
|
||||
videoDec_->testParam_ = param;
|
||||
std::cout << "SourcePath: " << sourcePath << std::endl;
|
||||
videoDec_->SetSource(sourcePath);
|
||||
const ::testing::TestInfo *testInfo_ = ::testing::UnitTest::GetInstance()->current_test_info();
|
||||
string prefix = "/data/test/media/";
|
||||
string fileName = testInfo_->name();
|
||||
auto check = [](char it) { return it == '/'; };
|
||||
(void)fileName.erase(std::remove_if(fileName.begin(), fileName.end(), check), fileName.end());
|
||||
videoDec_->SetOutPath(prefix + fileName);
|
||||
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoDec_->SetOutputSurface());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
|
||||
}
|
||||
} // namespace
|
@ -136,6 +136,7 @@ protected:
|
||||
std::shared_ptr<FormatMock> format_ = nullptr;
|
||||
std::shared_ptr<VEncCallbackTest> vencCallback_ = nullptr;
|
||||
std::shared_ptr<VEncCallbackTestExt> vencCallbackExt_ = nullptr;
|
||||
std::shared_ptr<VEncParamCallbackTest> vencParamCallback_ = nullptr;
|
||||
bool isAVBufferMode_ = false;
|
||||
#ifdef VIDEOENC_CAPI_UNIT_TEST
|
||||
OH_AVCodec *codec_ = nullptr;
|
||||
@ -161,6 +162,9 @@ void TEST_SUIT::SetUp(void)
|
||||
vencCallbackExt_ = std::make_shared<VEncCallbackTestExt>(vencSignal);
|
||||
ASSERT_NE(nullptr, vencCallbackExt_);
|
||||
|
||||
vencParamCallback_ = std::make_shared<VEncParamCallbackTest>(vencSignal);
|
||||
ASSERT_NE(nullptr, vencParamCallback_);
|
||||
|
||||
videoEnc_ = std::make_shared<VideoEncSample>(vencSignal);
|
||||
ASSERT_NE(nullptr, videoEnc_);
|
||||
|
||||
@ -214,7 +218,6 @@ void TEST_SUIT::CreateByNameWithParam(void)
|
||||
AVCodecCategory::AVCODEC_HARDWARE);
|
||||
break;
|
||||
case VCodecTestCode::HW_HEVC:
|
||||
case VCodecTestCode::HW_HDR:
|
||||
capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_HEVC.data(), true,
|
||||
AVCodecCategory::AVCODEC_HARDWARE);
|
||||
break;
|
||||
@ -244,11 +247,6 @@ void TEST_SUIT::SetFormatWithParam(void)
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
|
||||
if (GetParam() == HW_HDR) {
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PROFILE,
|
||||
static_cast<int32_t>(HEVCProfile::HEVC_PROFILE_MAIN_10));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_I_FRAME_INTERVAL, 100); // 100: i frame interval
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(, TEST_SUIT, testing::Values(HW_AVC, HW_HEVC));
|
||||
@ -354,6 +352,74 @@ HWTEST_F(TEST_SUIT, videoEncoder_setcallback_004, TestSize.Level1)
|
||||
ASSERT_NE(AV_ERR_OK, videoEnc_->SetCallback(vencCallback_));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_set_parametercallback_001
|
||||
* @tc.desc: video setcallback
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TEST_SUIT, videoEncoder_set_parametercallback_001, TestSize.Level1)
|
||||
{
|
||||
ASSERT_TRUE(videoEnc_->CreateVideoEncMockByName(g_vencName));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencParamCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencParamCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallback_));
|
||||
ASSERT_NE(AV_ERR_OK, videoEnc_->SetCallback(vencCallbackExt_));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_set_parametercallback_002
|
||||
* @tc.desc: video setcallback
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TEST_SUIT, videoEncoder_set_parametercallback_002, TestSize.Level1)
|
||||
{
|
||||
ASSERT_TRUE(videoEnc_->CreateVideoEncMockByName(g_vencName));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallbackExt_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallbackExt_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencParamCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencParamCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallbackExt_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencCallbackExt_));
|
||||
ASSERT_NE(AV_ERR_OK, videoEnc_->SetCallback(vencCallback_));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_set_parametercallback_003
|
||||
* @tc.desc: video setcallback
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TEST_SUIT, videoEncoder_set_parametercallback_003, TestSize.Level1)
|
||||
{
|
||||
ASSERT_TRUE(videoEnc_->CreateVideoEncMockByName(g_vencName));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
|
||||
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencParamCallback_));
|
||||
ASSERT_NE(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_set_parametercallback_004
|
||||
* @tc.desc: video setcallback
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TEST_SUIT, videoEncoder_set_parametercallback_004, TestSize.Level1)
|
||||
{
|
||||
ASSERT_TRUE(videoEnc_->CreateVideoEncMockByName(g_vencName));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
|
||||
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencParamCallback_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
ASSERT_NE(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
#ifdef VIDEOENC_CAPI_UNIT_TEST
|
||||
/**
|
||||
* @tc.name: videoEncoder_setcallback_invalid_001
|
||||
@ -518,7 +584,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_001, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
@ -533,8 +598,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_002, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
@ -551,8 +614,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_003, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Flush());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
@ -569,8 +630,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_004, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_NE(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
@ -584,7 +643,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_005, TestSize.Level1)
|
||||
{
|
||||
CreateByNameWithParam();
|
||||
PrepareSource();
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_NE(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
@ -600,8 +658,7 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_buffer_001, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -616,11 +673,9 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_buffer_002, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -635,11 +690,9 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_buffer_003, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Flush());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -652,8 +705,7 @@ HWTEST_P(TEST_SUIT, videoEncoder_start_buffer_004, TestSize.Level1)
|
||||
isAVBufferMode_ = true;
|
||||
CreateByNameWithParam();
|
||||
PrepareSource();
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_NE(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_NE(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -667,8 +719,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_stop_001, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
}
|
||||
@ -684,8 +734,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_stop_002, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Flush());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
@ -716,8 +764,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_flush_001, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Flush());
|
||||
}
|
||||
@ -733,8 +779,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_flush_002, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Release());
|
||||
@ -753,7 +797,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_reset_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Reset());
|
||||
@ -785,7 +828,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_reset_003, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Reset());
|
||||
}
|
||||
@ -802,7 +844,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_release_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Release());
|
||||
@ -820,7 +861,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_release_002, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Release());
|
||||
}
|
||||
@ -839,9 +879,25 @@ HWTEST_P(TEST_SUIT, videoEncoder_release_003, TestSize.Level1)
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Release());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_pushparameter_001
|
||||
* @tc.desc: video encodec setsurface
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_P(TEST_SUIT, videoEncoder_pushparameter_001, TestSize.Level1)
|
||||
{
|
||||
CreateByNameWithParam();
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->CreateInputSurface());
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->SetCallback(vencParamCallback_));
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_setsurface_001
|
||||
* @tc.desc: video decodec setsurface
|
||||
* @tc.desc: video encodec setsurface
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_P(TEST_SUIT, videoEncoder_setsurface_001, TestSize.Level1)
|
||||
@ -879,14 +935,13 @@ HWTEST_P(TEST_SUIT, videoEncoder_setsurface_003, TestSize.Level1)
|
||||
SetFormatWithParam();
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
ASSERT_NE(AV_ERR_OK, videoEnc_->CreateInputSurface());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_setsurface_buffer_001
|
||||
* @tc.desc: video decodec setsurface
|
||||
* @tc.desc: video encodec setsurface
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_P(TEST_SUIT, videoEncoder_setsurface_buffer_001, TestSize.Level1)
|
||||
@ -897,7 +952,7 @@ HWTEST_P(TEST_SUIT, videoEncoder_setsurface_buffer_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->CreateInputSurface());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
}
|
||||
|
||||
@ -914,8 +969,7 @@ HWTEST_P(TEST_SUIT, videoEncoder_setsurface_buffer_002, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->StartBuffer());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
ASSERT_NE(AV_ERR_OK, videoEnc_->CreateInputSurface());
|
||||
}
|
||||
|
||||
@ -948,7 +1002,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_abnormal_002, TestSize.Level1)
|
||||
{
|
||||
CreateByNameWithParam();
|
||||
PrepareSource();
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_NE(AV_ERR_OK, videoEnc_->Start());
|
||||
}
|
||||
|
||||
@ -996,7 +1049,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_setParameter_001, TestSize.Level1)
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, static_cast<int32_t>(VideoPixelFormat::YUV420P));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->SetParameter(format_));
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
@ -1022,7 +1074,6 @@ HWTEST_P(TEST_SUIT, videoEncoder_setParameter_002, TestSize.Level1)
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, static_cast<int32_t>(VideoPixelFormat::YUV420P));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->SetParameter(format_));
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
@ -1040,10 +1091,41 @@ HWTEST_P(TEST_SUIT, videoEncoder_getOutputDescription_001, TestSize.Level1)
|
||||
PrepareSource();
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
|
||||
UNITTEST_CHECK_AND_RETURN_LOG(GetParam() != VCodecTestCode::HW_HDR, "hdr not support buffer mode");
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
format_ = videoEnc_->GetOutputDescription();
|
||||
EXPECT_NE(nullptr, format_);
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: videoEncoder_hdr_function_001
|
||||
* @tc.desc: video encodec setsurface
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(TEST_SUIT, videoEncoder_hdr_function_001, TestSize.Level1)
|
||||
{
|
||||
capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_HEVC.data(), true,
|
||||
AVCodecCategory::AVCODEC_HARDWARE);
|
||||
std::string codecName = capability_->GetName();
|
||||
std::cout << "CodecName: " << codecName << "\n";
|
||||
ASSERT_TRUE(CreateVideoCodecByName(codecName));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT_VENC);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_PROFILE, static_cast<int32_t>(HEVCProfile::HEVC_PROFILE_MAIN_10));
|
||||
format_->PutIntValue(MediaDescriptionKey::MD_KEY_I_FRAME_INTERVAL, 100); // 100: i frame interval
|
||||
|
||||
const ::testing::TestInfo *testInfo_ = ::testing::UnitTest::GetInstance()->current_test_info();
|
||||
string prefix = "/data/test/media/";
|
||||
string fileName = testInfo_->name();
|
||||
auto check = [](char it) { return it == '/'; };
|
||||
(void)fileName.erase(std::remove_if(fileName.begin(), fileName.end(), check), fileName.end());
|
||||
videoEnc_->SetOutPath(prefix + fileName);
|
||||
videoEnc_->SetIsHdrVivid(true);
|
||||
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->Configure(format_));
|
||||
ASSERT_EQ(AV_ERR_OK, videoEnc_->CreateInputSurface());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Start());
|
||||
EXPECT_EQ(AV_ERR_OK, videoEnc_->Stop());
|
||||
}
|
||||
} // namespace
|
Loading…
x
Reference in New Issue
Block a user