mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2025-03-02 21:27:40 +00:00
Merge branch 'master' of https://gitee.com/jiang-chunli/multimedia_av_codec
Signed-off-by: jiangchunli <jiangchunli1@huawei.com>
This commit is contained in:
commit
2f0e2bf18e
@ -56,13 +56,14 @@
|
||||
"safwk",
|
||||
"samgr",
|
||||
"window_manager",
|
||||
"histreamer",
|
||||
"media_foundation",
|
||||
"audio_framework",
|
||||
"drm_framework"
|
||||
],
|
||||
"third_party": [
|
||||
"bounds_checking_function",
|
||||
"ffmpeg"
|
||||
"ffmpeg",
|
||||
"curl"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
|
@ -32,7 +32,7 @@ av_codec_sanitize = {
|
||||
debug = false
|
||||
}
|
||||
av_codec_root_dir = "//foundation/multimedia/av_codec"
|
||||
media_foundation_root_dir = "//foundation/multimedia/histreamer"
|
||||
media_foundation_root_dir = "//foundation/multimedia/media_foundation"
|
||||
audio_framework_root_dir = "//foundation/multimedia/audio_framework"
|
||||
graphic_2d_root_dir = "//foundation/graphic/graphic_2d"
|
||||
c_utils_root_dir = "//commonlibrary/c_utils"
|
||||
|
@ -322,8 +322,8 @@ ohos_shared_library("av_codec_client") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
|
@ -71,10 +71,10 @@ ohos_shared_library("av_codec_service_dfx") {
|
||||
"hicollie:libhicollie",
|
||||
"hidumper:lib_dump_usage",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
|
@ -63,9 +63,9 @@ ohos_static_library("av_codec_codec_base") {
|
||||
external_deps = [
|
||||
"graphic_2d:surface",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
|
@ -101,9 +101,9 @@ ohos_static_library("av_codec_audio_ffmpeg_codec") {
|
||||
"c_utils:utils",
|
||||
"graphic_2d:surface",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
|
@ -57,9 +57,9 @@ ohos_static_library("av_codec_video_ffmpeg_codec") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
|
@ -74,8 +74,8 @@ ohos_shared_library("hcodec") {
|
||||
"graphic_2d:sync_fence",
|
||||
"hdf_core:libhdi",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
}
|
||||
|
@ -52,9 +52,9 @@ ohos_static_library("av_codec_engine_common") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
|
@ -64,6 +64,7 @@ ohos_shared_library("av_codec_media_engine_filters") {
|
||||
"audio_decoder_filter.cpp",
|
||||
"audio_encoder_filter.cpp",
|
||||
"audio_sink_filter.cpp",
|
||||
"codec_capability_adapter.cpp",
|
||||
"decoder_surface_filter.cpp",
|
||||
"demuxer_filter.cpp",
|
||||
"muxer_filter.cpp",
|
||||
@ -86,8 +87,8 @@ ohos_shared_library("av_codec_media_engine_filters") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -210,6 +210,7 @@ Status AudioDecoderFilter::OnLinked(StreamType inType, const std::shared_ptr<Met
|
||||
meta_ = meta;
|
||||
std::string mime;
|
||||
meta_->GetData(Tag::MIME_TYPE, mime);
|
||||
meta->SetData(Tag::AUDIO_SAMPLE_FORMAT, Plugins::SAMPLE_S16LE);
|
||||
SetParameter(meta);
|
||||
mediaCodec_->Init(mime, false);
|
||||
mediaCodec_->Configure(meta);
|
||||
|
@ -119,7 +119,11 @@ Status DemuxerFilter::Prepare()
|
||||
StreamType streamType;
|
||||
MEDIA_LOG_I("streamType is %{public}d", static_cast<int32_t>(mediaType));
|
||||
if (mediaType == MediaType::AUDIO) {
|
||||
streamType = StreamType::STREAMTYPE_ENCODED_AUDIO;
|
||||
if (mime == std::string(MimeType::AUDIO_RAW)) {
|
||||
streamType = StreamType::STREAMTYPE_RAW_AUDIO;
|
||||
} else {
|
||||
streamType = StreamType::STREAMTYPE_ENCODED_AUDIO;
|
||||
}
|
||||
} else if (mediaType == MediaType::VIDEO) {
|
||||
streamType = StreamType::STREAMTYPE_ENCODED_VIDEO;
|
||||
} else {
|
||||
@ -159,14 +163,12 @@ Status DemuxerFilter::Stop()
|
||||
Status DemuxerFilter::Pause()
|
||||
{
|
||||
MEDIA_LOG_I("Pause called");
|
||||
Filter::Pause();
|
||||
return demuxer_->Stop();
|
||||
}
|
||||
|
||||
Status DemuxerFilter::Resume()
|
||||
{
|
||||
MEDIA_LOG_I("Resume called");
|
||||
Filter::Resume();
|
||||
return demuxer_->Start();
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "meta/format.h"
|
||||
#include "media_description.h"
|
||||
|
||||
constexpr uint32_t TIME_OUT_MS = 100;
|
||||
constexpr uint32_t TIME_OUT_MS = 1000;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -165,6 +165,7 @@ Status SurfaceEncoderAdapter::Start()
|
||||
{
|
||||
MEDIA_LOG_I("Start");
|
||||
int32_t ret;
|
||||
isThreadExit_ = false;
|
||||
if (releaseBufferTask_) {
|
||||
releaseBufferTask_->Start();
|
||||
}
|
||||
@ -187,8 +188,10 @@ Status SurfaceEncoderAdapter::Stop()
|
||||
MEDIA_LOG_I("Stop time: " PUBLIC_LOG_D64, stopTime_);
|
||||
|
||||
std::unique_lock<std::mutex> lock(stopMutex_);
|
||||
stopCondition_.wait(lock);
|
||||
stopCondition_.wait_for(lock, std::chrono::milliseconds(TIME_OUT_MS));
|
||||
if (releaseBufferTask_) {
|
||||
isThreadExit_ = true;
|
||||
releaseBufferCondition_.notify_all();
|
||||
releaseBufferTask_->Stop();
|
||||
MEDIA_LOG_I("releaseBufferTask_ Stop");
|
||||
}
|
||||
@ -318,8 +321,10 @@ void SurfaceEncoderAdapter::OnOutputBufferAvailable(uint32_t index, std::shared_
|
||||
emptyOutputBuffer->pts_ = buffer->pts_ - startBufferTime_ - totalPauseTime_;
|
||||
emptyOutputBuffer->flag_ = buffer->flag_;
|
||||
outputBufferQueueProducer_->PushBuffer(emptyOutputBuffer, true);
|
||||
std::unique_lock<std::mutex> lock(releaseBufferMutex_);
|
||||
releaseBufferIndex_ = index;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(releaseBufferMutex_);
|
||||
indexs_.push_back(index);
|
||||
}
|
||||
releaseBufferCondition_.notify_all();
|
||||
MEDIA_LOG_I("OnOutputBufferAvailable end");
|
||||
}
|
||||
@ -327,9 +332,23 @@ void SurfaceEncoderAdapter::OnOutputBufferAvailable(uint32_t index, std::shared_
|
||||
void SurfaceEncoderAdapter::ReleaseBuffer()
|
||||
{
|
||||
MEDIA_LOG_I("ReleaseBuffer");
|
||||
std::unique_lock<std::mutex> lock(releaseBufferMutex_);
|
||||
releaseBufferCondition_.wait(lock);
|
||||
codecServer_->ReleaseOutputBuffer(releaseBufferIndex_, false);
|
||||
while (true) {
|
||||
if (isThreadExit_) {
|
||||
MEDIA_LOG_I("Exit ReleaseBuffer thread.");
|
||||
break;
|
||||
}
|
||||
std::vector<uint32_t> indexs;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(releaseBufferMutex_);
|
||||
releaseBufferCondition_.wait(lock);
|
||||
indexs = indexs_;
|
||||
indexs_.clear();
|
||||
}
|
||||
for (auto &index : indexs) {
|
||||
codecServer_->ReleaseOutputBuffer(index, false);
|
||||
}
|
||||
}
|
||||
MEDIA_LOG_I("ReleaseBuffer end");
|
||||
}
|
||||
} // namespace MEDIA
|
||||
} // namespace OHOS
|
@ -77,7 +77,8 @@ private:
|
||||
std::shared_ptr<Task> releaseBufferTask_{nullptr};
|
||||
std::mutex releaseBufferMutex_;
|
||||
std::condition_variable releaseBufferCondition_;
|
||||
std::atomic<int32_t> releaseBufferIndex_;
|
||||
std::vector<uint32_t> indexs_;
|
||||
std::atomic<bool> isThreadExit_ = true;
|
||||
|
||||
std::mutex stopMutex_;
|
||||
std::condition_variable stopCondition_;
|
||||
|
@ -91,8 +91,8 @@ ohos_shared_library("av_codec_media_engine_modules") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -504,7 +504,7 @@ Status MediaDemuxer::InnerReadSample(uint32_t trackId, std::shared_ptr<AVBuffer>
|
||||
|
||||
void MediaDemuxer::ReadLoop(uint32_t trackId)
|
||||
{
|
||||
std::string threadReadName = "DemuxerReadLoop" + std::to_string(trackId);
|
||||
std::string threadReadName = "DemuxerRLoop" + std::to_string(trackId);
|
||||
MEDIA_LOG_I("Enter [" PUBLIC_LOG_S "] read thread.", threadReadName.c_str());
|
||||
pthread_setname_np(pthread_self(), threadReadName.c_str());
|
||||
for (;;) {
|
||||
|
@ -70,7 +70,8 @@ TypeFinder::TypeFinder()
|
||||
task_(nullptr),
|
||||
checkRange_(),
|
||||
peekRange_(),
|
||||
typeFound_()
|
||||
typeFound_(),
|
||||
sniffData_(nullptr)
|
||||
{
|
||||
MEDIA_LOG_D("TypeFinder ctor called...");
|
||||
}
|
||||
@ -145,6 +146,14 @@ Status TypeFinder::ReadAt(int64_t offset, std::shared_ptr<Buffer>& buffer, size_
|
||||
PUBLIC_LOG_D64, !buffer, expectedLen, offset);
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (sniffNeeded_ && sniffData_ != nullptr) {
|
||||
auto memory = sniffData_->GetMemory();
|
||||
if (memory != nullptr && memory->GetSize() > 0) {
|
||||
MEDIA_LOG_I("Has sniff data already.");
|
||||
buffer->GetMemory()->Write(memory->GetReadOnlyData(), memory->GetSize(), 0);
|
||||
return Status::OK;
|
||||
}
|
||||
}
|
||||
const int maxTryTimes = 3;
|
||||
int i = 0;
|
||||
while (!checkRange_(offset, expectedLen) && (i++ < maxTryTimes)) {
|
||||
@ -155,6 +164,19 @@ Status TypeFinder::ReadAt(int64_t offset, std::shared_ptr<Buffer>& buffer, size_
|
||||
return Status::ERROR_NOT_ENOUGH_DATA;
|
||||
}
|
||||
FALSE_LOG_MSG(peekRange_(static_cast<uint64_t>(offset), expectedLen, buffer), "peekRange failed.");
|
||||
|
||||
if (sniffNeeded_ && sniffData_ == nullptr) {
|
||||
auto memory = buffer->GetMemory();
|
||||
if (memory != nullptr) {
|
||||
MEDIA_LOG_I("Write sniffData_ start.");
|
||||
sniffData_ = Buffer::CreateDefaultBuffer(memory->GetSize());
|
||||
if (sniffData_ != nullptr && sniffData_->GetMemory() != nullptr) {
|
||||
sniffData_->GetMemory()->Write(memory->GetReadOnlyData(), memory->GetSize(), 0);
|
||||
} else {
|
||||
MEDIA_LOG_E("Write sniffData_ failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,7 @@ private:
|
||||
std::function<bool(uint64_t, size_t)> checkRange_;
|
||||
std::function<bool(uint64_t, size_t, std::shared_ptr<Buffer>&)> peekRange_;
|
||||
std::function<void(std::string)> typeFound_;
|
||||
std::shared_ptr<Buffer> sniffData_;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -55,8 +55,12 @@ int32_t MediaCodec::Init(const std::string &mime, bool isEncoder)
|
||||
codecPlugin_ = CreatePlugin(mime, type);
|
||||
if (codecPlugin_ != nullptr) {
|
||||
MEDIA_LOG_I("codecPlugin_->Init()");
|
||||
codecPlugin_->Init();
|
||||
auto ret = codecPlugin_->Init();
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "pluign init failed");
|
||||
state_ = CodecState::INITIALIZED;
|
||||
} else {
|
||||
MEDIA_LOG_I("createPlugin failed");
|
||||
return (int32_t)Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
return (int32_t)Status::OK;
|
||||
}
|
||||
@ -74,10 +78,10 @@ int32_t MediaCodec::Init(const std::string &name)
|
||||
}
|
||||
FALSE_RETURN_V(type != Plugins::PluginType::INVALID_TYPE, (int32_t)Status::ERROR_INVALID_PARAMETER);
|
||||
auto plugin = Plugins::PluginManager::Instance().CreatePlugin(name, type);
|
||||
FALSE_RETURN_V(plugin != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER);
|
||||
FALSE_RETURN_V_MSG_E(plugin != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "create pluign failed");
|
||||
codecPlugin_ = std::reinterpret_pointer_cast<Plugins::CodecPlugin>(plugin);
|
||||
Status ret = codecPlugin_->Init();
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)Status::ERROR_INVALID_PARAMETER, "info is nullptr");
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)Status::ERROR_INVALID_PARAMETER, "pluign init failed");
|
||||
state_ = CodecState::INITIALIZED;
|
||||
return (int32_t)Status::OK;
|
||||
}
|
||||
@ -141,6 +145,8 @@ int32_t MediaCodec::SetCodecCallback(const std::shared_ptr<CodecCallback> &codec
|
||||
AutoLock lock(stateMutex_);
|
||||
FALSE_RETURN_V(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED,
|
||||
(int32_t)Status::ERROR_INVALID_STATE);
|
||||
FALSE_RETURN_V_MSG_E(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER,
|
||||
"codecCallback is nullptr");
|
||||
codecCallback_ = codecCallback;
|
||||
auto ret = codecPlugin_->SetDataCallback(this);
|
||||
FALSE_RETURN_V(ret == Status::OK, (int32_t)ret);
|
||||
@ -211,10 +217,7 @@ int32_t MediaCodec::Start()
|
||||
FALSE_RETURN_V(state_ == CodecState::PREPARED || state_ == CodecState::FLUSHED,
|
||||
(int32_t)Status::ERROR_INVALID_STATE);
|
||||
auto ret = codecPlugin_->Start();
|
||||
if (ret != Status::OK) {
|
||||
MEDIA_LOG_E("Start, ret = %{public}d", (int32_t)ret);
|
||||
return (int32_t)ret;
|
||||
}
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin start failed");
|
||||
state_ = CodecState::RUNNING;
|
||||
return (int32_t)ret;
|
||||
}
|
||||
@ -226,9 +229,7 @@ int32_t MediaCodec::Stop()
|
||||
FALSE_RETURN_V(state_ == CodecState::RUNNING || state_ == CodecState::END_OF_STREAM ||
|
||||
state_ == CodecState::FLUSHED, (int32_t)Status::ERROR_INVALID_STATE);
|
||||
auto ret = codecPlugin_->Stop();
|
||||
if (ret != Status::OK) {
|
||||
return (int32_t)ret;
|
||||
}
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin stop failed");
|
||||
state_ = CodecState::PREPARED;
|
||||
return (int32_t)ret;
|
||||
}
|
||||
@ -240,9 +241,7 @@ int32_t MediaCodec::Flush()
|
||||
FALSE_RETURN_V(state_ == CodecState::RUNNING || state_ == CodecState::END_OF_STREAM,
|
||||
(int32_t)Status::ERROR_INVALID_STATE);
|
||||
auto ret = codecPlugin_->Flush();
|
||||
if (ret != Status::OK) {
|
||||
return (int32_t)ret;
|
||||
}
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin flush failed");
|
||||
state_ = CodecState::FLUSHED;
|
||||
return (int32_t)ret;
|
||||
}
|
||||
@ -252,9 +251,7 @@ int32_t MediaCodec::Reset()
|
||||
AutoLock lock(stateMutex_);
|
||||
FALSE_RETURN_V(state_ == CodecState::UNINITIALIZED, (int32_t)Status::OK);
|
||||
auto ret = codecPlugin_->Reset();
|
||||
if (ret != Status::OK) {
|
||||
return (int32_t)ret;
|
||||
}
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin reset failed");
|
||||
state_ = CodecState::INITIALIZED;
|
||||
return (int32_t)ret;
|
||||
}
|
||||
@ -264,9 +261,7 @@ int32_t MediaCodec::Release()
|
||||
AutoLock lock(stateMutex_);
|
||||
FALSE_RETURN_V(state_ == CodecState::UNINITIALIZED, (int32_t)Status::OK);
|
||||
auto ret = codecPlugin_->Release();
|
||||
if (ret != Status::OK) {
|
||||
return (int32_t)ret;
|
||||
}
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin release failed");
|
||||
state_ = CodecState::UNINITIALIZED;
|
||||
return (int32_t)ret;
|
||||
}
|
||||
@ -283,10 +278,12 @@ int32_t MediaCodec::NotifyEos()
|
||||
int32_t MediaCodec::SetParameter(const std::shared_ptr<Meta> ¶meter)
|
||||
{
|
||||
AutoLock lock(stateMutex_);
|
||||
FALSE_RETURN_V(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER);
|
||||
FALSE_RETURN_V(state_ != CodecState::UNINITIALIZED && state_ != CodecState::INITIALIZED &&
|
||||
state_ != CodecState::PREPARED, (int32_t)Status::ERROR_INVALID_STATE);
|
||||
codecPlugin_->SetParameter(parameter);
|
||||
return (int32_t)Status::OK;
|
||||
auto ret = codecPlugin_->SetParameter(parameter);
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin set parameter failed");
|
||||
return (int32_t)ret;
|
||||
}
|
||||
|
||||
int32_t MediaCodec::GetOutputFormat(std::shared_ptr<Meta> ¶meter)
|
||||
@ -295,8 +292,10 @@ int32_t MediaCodec::GetOutputFormat(std::shared_ptr<Meta> ¶meter)
|
||||
FALSE_RETURN_V(state_ == CodecState::PREPARED || state_ == CodecState::CONFIGURED || state_ == CodecState::RUNNING,
|
||||
(int32_t)Status::ERROR_INVALID_STATE);
|
||||
FALSE_RETURN_V(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE);
|
||||
codecPlugin_->GetParameter(parameter);
|
||||
return (int32_t)Status::OK;
|
||||
FALSE_RETURN_V(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER);
|
||||
auto ret = codecPlugin_->GetParameter(parameter);
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin get parameter failed");
|
||||
return (int32_t)ret;
|
||||
}
|
||||
|
||||
Status MediaCodec::AttachBufffer()
|
||||
@ -313,10 +312,7 @@ Status MediaCodec::AttachBufffer()
|
||||
std::shared_ptr<Meta> inputBufferConfig = std::make_shared<Meta>();
|
||||
FALSE_RETURN_V_MSG_E(codecPlugin_ != nullptr, Status::ERROR_UNKNOWN, "codecPlugin_ is nullptr");
|
||||
auto ret = codecPlugin_->GetParameter(inputBufferConfig);
|
||||
if (ret != Status::OK) {
|
||||
MEDIA_LOG_E("GetParameter failed");
|
||||
return ret;
|
||||
}
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "attachBufffer failed, plugin get param error");
|
||||
int32_t capacity = 0;
|
||||
FALSE_RETURN_V_MSG_E(inputBufferConfig != nullptr, Status::ERROR_UNKNOWN,
|
||||
"inputBufferConfig is nullptr");
|
||||
@ -342,12 +338,9 @@ Status MediaCodec::AttachBufffer()
|
||||
int32_t MediaCodec::PrepareInputBufferQueue()
|
||||
{
|
||||
std::vector<std::shared_ptr<AVBuffer>> inputBuffers;
|
||||
auto ret = codecPlugin_->GetInputBuffers(inputBuffers);
|
||||
FALSE_RETURN_V_MSG_E(codecPlugin_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "codecPlugin_ is nullptr");
|
||||
if (ret != Status::OK) {
|
||||
MEDIA_LOG_E("GetInputBuffers failed");
|
||||
return (int32_t)ret;
|
||||
}
|
||||
auto ret = codecPlugin_->GetInputBuffers(inputBuffers);
|
||||
FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "pluign getInputBuffers failed");
|
||||
if (inputBuffers.empty()) {
|
||||
ret = AttachBufffer();
|
||||
if (ret != Status::OK) {
|
||||
|
@ -67,6 +67,7 @@ AudioCaptureModule::AudioCaptureModule()
|
||||
|
||||
AudioCaptureModule::~AudioCaptureModule()
|
||||
{
|
||||
audioCapturer_->RemoveAudioCapturerInfoChangeCallback(audioCapturerInfoChangeCallback_);
|
||||
DoDeinit();
|
||||
}
|
||||
|
||||
@ -385,7 +386,8 @@ Status AudioCaptureModule::SetAudioCapturerInfoChangeCallback(
|
||||
if (audioCapturer_ == nullptr) {
|
||||
return Status::ERROR_WRONG_STATE;
|
||||
}
|
||||
int32_t ret = audioCapturer_->SetAudioCapturerInfoChangeCallback(callback);
|
||||
audioCapturerInfoChangeCallback_ = callback;
|
||||
int32_t ret = audioCapturer_->SetAudioCapturerInfoChangeCallback(audioCapturerInfoChangeCallback_);
|
||||
if (ret != (int32_t)Status::OK) {
|
||||
MEDIA_LOG_E("SetAudioCapturerInfoChangeCallback fail error code: %{public}d", ret);
|
||||
return Status::ERROR_UNKNOWN;
|
||||
|
@ -66,6 +66,7 @@ private:
|
||||
|
||||
Mutex captureMutex_ {};
|
||||
std::unique_ptr<OHOS::AudioStandard::AudioCapturer> audioCapturer_ {nullptr};
|
||||
std::shared_ptr<AudioStandard::AudioCapturerInfoChangeCallback> audioCapturerInfoChangeCallback_{nullptr};
|
||||
AudioStandard::AudioCapturerParams capturerParams_ {};
|
||||
std::shared_ptr<AudioCaptureModuleCallback> audioCaptureModuleCallback_ {nullptr};
|
||||
int64_t bitRate_ {0};
|
||||
|
@ -25,5 +25,6 @@ group("av_codec_media_engine_plugins") {
|
||||
"sink:media_plugin_AudioServerSink",
|
||||
"source:media_plugin_DataStreamSource",
|
||||
"source:media_plugin_FileFdSource",
|
||||
"source/http_source:media_plugin_HttpSource",
|
||||
]
|
||||
}
|
||||
|
@ -85,8 +85,8 @@ ohos_shared_library("media_plugin_FFmpegAudioDecoders") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -158,8 +158,8 @@ bool FFmpegAACDecoderPlugin::CheckAdts(const std::shared_ptr<Meta> &format)
|
||||
|
||||
bool FFmpegAACDecoderPlugin::CheckSampleFormat(const std::shared_ptr<Meta> &format)
|
||||
{
|
||||
int32_t sampleFormat;
|
||||
if (!format->GetData(Tag::AUDIO_SAMPLE_FORMAT, sampleFormat)) {
|
||||
AudioSampleFormat sampleFormat;
|
||||
if (!format->Get<Tag::AUDIO_SAMPLE_FORMAT>(sampleFormat)) {
|
||||
AVCODEC_LOGW("Sample format missing, set to default f32le");
|
||||
if (channels_ != 1) {
|
||||
basePlugin->EnableResample(DEFAULT_FFMPEG_SAMPLE_FORMAT);
|
||||
@ -168,14 +168,14 @@ bool FFmpegAACDecoderPlugin::CheckSampleFormat(const std::shared_ptr<Meta> &form
|
||||
}
|
||||
|
||||
if (std::find(supportedSampleFormats.begin(), supportedSampleFormats.end(),
|
||||
static_cast<OHOS::MediaAVCodec::AudioSampleFormat>(sampleFormat)) == supportedSampleFormats.end()) {
|
||||
sampleFormat) == supportedSampleFormats.end()) {
|
||||
AVCODEC_LOGE("Output sample format not support");
|
||||
return false;
|
||||
}
|
||||
if (channels_ == 1 && sampleFormat == AudioSampleFormat::SAMPLE_F32LE) {
|
||||
return true;
|
||||
}
|
||||
auto destFmt = FFMpegConverter::ConvertOHAudioFormatToFFMpeg(static_cast<AudioSampleFormat>(sampleFormat));
|
||||
auto destFmt = FFMpegConverter::ConvertOHAudioFormatToFFMpeg(sampleFormat);
|
||||
if (destFmt == AV_SAMPLE_FMT_NONE) {
|
||||
AVCODEC_LOGE("Convert format failed, avSampleFormat not found");
|
||||
return false;
|
||||
|
@ -39,6 +39,7 @@ FfmpegBaseDecoder::FfmpegBaseDecoder()
|
||||
avCodecContext_(nullptr),
|
||||
cachedFrame_(nullptr),
|
||||
avPacket_(nullptr),
|
||||
format_(nullptr),
|
||||
needResample_(false),
|
||||
destFmt_(AV_SAMPLE_FMT_NONE),
|
||||
ouputFile("/data/test/media/outputVorbis.pcm", std::ios::binary)
|
||||
@ -298,25 +299,31 @@ Status FfmpegBaseDecoder::AllocateContext(const std::string &name)
|
||||
|
||||
Status FfmpegBaseDecoder::InitContext(const std::shared_ptr<Meta> &format)
|
||||
{
|
||||
format_ = format;
|
||||
format_->GetData(Tag::AUDIO_CHANNEL_COUNT, avCodecContext_->channels);
|
||||
if (format == nullptr) {
|
||||
AVCODEC_LOGI("format is nullptr");
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
format->GetData(Tag::AUDIO_CHANNEL_COUNT, avCodecContext_->channels);
|
||||
if (avCodecContext_->channels <= 0) {
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
format_->GetData(Tag::AUDIO_SAMPLE_RATE, avCodecContext_->sample_rate);
|
||||
format->GetData(Tag::AUDIO_SAMPLE_RATE, avCodecContext_->sample_rate);
|
||||
if (avCodecContext_->sample_rate <= 0) {
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
format_->GetData(Tag::MEDIA_BITRATE, avCodecContext_->bit_rate);
|
||||
format_->GetData(Tag::AUDIO_MAX_INPUT_SIZE, maxInputSize_);
|
||||
format->GetData(Tag::MEDIA_BITRATE, avCodecContext_->bit_rate);
|
||||
format->GetData(Tag::AUDIO_MAX_INPUT_SIZE, maxInputSize_);
|
||||
|
||||
if (format_->GetData(Tag::MEDIA_CODEC_CONFIG, config_data)) {
|
||||
if (format->GetData(Tag::MEDIA_CODEC_CONFIG, config_data)) {
|
||||
AVCODEC_LOGI("Set codec config data size:%{public}zu", config_data.size());
|
||||
avCodecContext_->extradata = config_data.data();
|
||||
avCodecContext_->extradata_size = config_data.size();
|
||||
hasExtra_ = true;
|
||||
}
|
||||
|
||||
if (format_ == nullptr) {
|
||||
format_ = std::make_shared<Meta>();
|
||||
}
|
||||
*format_ = *format;
|
||||
avCodecContext_->sample_fmt = AV_SAMPLE_FMT_S16;
|
||||
avCodecContext_->request_sample_fmt = avCodecContext_->sample_fmt;
|
||||
avCodecContext_->workaround_bugs =
|
||||
|
@ -154,8 +154,8 @@ Status FFmpegVorbisDecoderPlugin::Release()
|
||||
|
||||
bool FFmpegVorbisDecoderPlugin::CheckSampleFormat(const std::shared_ptr<Meta> &format)
|
||||
{
|
||||
int32_t sampleFormat;
|
||||
if (!format->GetData(Tag::AUDIO_SAMPLE_FORMAT, sampleFormat)) {
|
||||
AudioSampleFormat sampleFormat;
|
||||
if (!format->Get<Tag::AUDIO_SAMPLE_FORMAT>(sampleFormat)) {
|
||||
AVCODEC_LOGW("Sample format missing, set to default f32le");
|
||||
if (channels_ != 1) {
|
||||
basePlugin->EnableResample(DEFAULT_FFMPEG_SAMPLE_FORMAT);
|
||||
@ -164,14 +164,14 @@ bool FFmpegVorbisDecoderPlugin::CheckSampleFormat(const std::shared_ptr<Meta> &f
|
||||
}
|
||||
|
||||
if (std::find(supportedSampleFormats.begin(), supportedSampleFormats.end(),
|
||||
static_cast<OHOS::MediaAVCodec::AudioSampleFormat>(sampleFormat)) == supportedSampleFormats.end()) {
|
||||
sampleFormat) == supportedSampleFormats.end()) {
|
||||
AVCODEC_LOGE("Output sample format not support");
|
||||
return false;
|
||||
}
|
||||
if (channels_ == 1 && sampleFormat == AudioSampleFormat::SAMPLE_F32LE) {
|
||||
return true;
|
||||
}
|
||||
auto destFmt = FFMpegConverter::ConvertOHAudioFormatToFFMpeg(static_cast<AudioSampleFormat>(sampleFormat));
|
||||
auto destFmt = FFMpegConverter::ConvertOHAudioFormatToFFMpeg(sampleFormat);
|
||||
if (destFmt == AV_SAMPLE_FMT_NONE) {
|
||||
AVCODEC_LOGE("Convert format failed, avSampleFormat not found");
|
||||
return false;
|
||||
|
@ -77,8 +77,8 @@ ohos_shared_library("media_plugin_FFmpegAudioEncoders") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -70,6 +70,7 @@ FFmpegAACEncoderPlugin::FFmpegAACEncoderPlugin(std::string name)
|
||||
prevPts_(0),
|
||||
resample_(nullptr),
|
||||
srcFmt_(AVSampleFormat::AV_SAMPLE_FMT_NONE),
|
||||
bitRate_(0),
|
||||
maxInputSize_(-1),
|
||||
maxOutputSize_(-1)
|
||||
{
|
||||
@ -505,52 +506,47 @@ bool FFmpegAACEncoderPlugin::CheckResample() const
|
||||
|
||||
Status FFmpegAACEncoderPlugin::GetMetaData(const std::shared_ptr<Meta> &meta)
|
||||
{
|
||||
Status ret = Status::OK;
|
||||
int32_t type;
|
||||
if (meta->Find(Tag::AUDIO_AAC_IS_ADTS) != meta->end()) {
|
||||
meta->Get<Tag::AUDIO_AAC_IS_ADTS>(type);
|
||||
if (meta->Get<Tag::AUDIO_AAC_IS_ADTS>(type)) {
|
||||
aacName_ = (type == 1 ? "aac" : "aac_latm");
|
||||
}
|
||||
if (meta->Find(Tag::AUDIO_CHANNEL_COUNT) != meta->end()) {
|
||||
meta->Get<Tag::AUDIO_CHANNEL_COUNT>(channels_);
|
||||
if (meta->Get<Tag::AUDIO_CHANNEL_COUNT>(channels_)) {
|
||||
if (channels_ < MIN_CHANNELS || channels_ > MAX_CHANNELS) {
|
||||
MEDIA_LOG_E("AUDIO_CHANNEL_COUNT error");
|
||||
ret = Status::ERROR_INVALID_PARAMETER;
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
MEDIA_LOG_E("no AUDIO_CHANNEL_COUNT");
|
||||
ret = Status::ERROR_INVALID_PARAMETER;
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (meta->Find(Tag::AUDIO_SAMPLE_RATE) != meta->end()) {
|
||||
meta->Get<Tag::AUDIO_SAMPLE_RATE>(sampleRate_);
|
||||
} else {
|
||||
if (!meta->Get<Tag::AUDIO_SAMPLE_RATE>(sampleRate_)) {
|
||||
MEDIA_LOG_E("no AUDIO_SAMPLE_RATE");
|
||||
ret = Status::ERROR_INVALID_PARAMETER;
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (meta->Find(Tag::AUDIO_SAMPLE_FORMAT) != meta->end()) {
|
||||
meta->Get<Tag::AUDIO_SAMPLE_FORMAT>(audioSampleFormat_);
|
||||
if (!meta->Get<Tag::MEDIA_BITRATE>(bitRate_)) {
|
||||
MEDIA_LOG_E("no MEDIA_BITRATE");
|
||||
}
|
||||
if (meta->Get<Tag::AUDIO_SAMPLE_FORMAT>(audioSampleFormat_)) {
|
||||
MEDIA_LOG_D("AUDIO_SAMPLE_FORMAT found, srcFmt:%{public}d", audioSampleFormat_);
|
||||
} else {
|
||||
MEDIA_LOG_E("no AUDIO_SAMPLE_FORMAT");
|
||||
ret = Status::ERROR_INVALID_PARAMETER;
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (meta->Find(Tag::AUDIO_MAX_INPUT_SIZE) != meta->end()) {
|
||||
meta->Get<Tag::AUDIO_MAX_INPUT_SIZE>(maxInputSize_);
|
||||
MEDIA_LOG_I("SetParameter maxInputSize_: %{public}d", maxInputSize_);
|
||||
if (meta->Get<Tag::AUDIO_MAX_INPUT_SIZE>(maxInputSize_)) {
|
||||
MEDIA_LOG_I("maxInputSize: %{public}d", maxInputSize_);
|
||||
}
|
||||
if (meta->Find(Tag::AUDIO_CHANNEL_LAYOUT) != meta->end()) {
|
||||
meta->Get<Tag::AUDIO_CHANNEL_LAYOUT>(srcLayout_);
|
||||
if (meta->Get<Tag::AUDIO_CHANNEL_LAYOUT>(srcLayout_)) {
|
||||
srcLayout_ = static_cast<AudioChannelLayout>(FFMpegConverter::ConvertOHAudioChannelLayoutToFFMpeg(srcLayout_));
|
||||
} else {
|
||||
auto iter = channelLayoutMap.find(channels_);
|
||||
if (iter == channelLayoutMap.end()) {
|
||||
MEDIA_LOG_E("channel layout not found, channels: %{public}d", channels_);
|
||||
ret = Status::ERROR_UNKNOWN;
|
||||
return Status::ERROR_UNKNOWN;
|
||||
} else {
|
||||
srcLayout_ = static_cast<AudioChannelLayout>(iter->second);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status FFmpegAACEncoderPlugin::SetParameter(const std::shared_ptr<Meta> &meta)
|
||||
|
@ -49,6 +49,8 @@ static std::map<AVMediaType, MediaType> g_convertFfmpegTrackType = {
|
||||
};
|
||||
|
||||
static std::map<AVCodecID, std::string_view> g_codecIdToMime = {
|
||||
{AV_CODEC_ID_MP1, MimeType::AUDIO_MPEG},
|
||||
{AV_CODEC_ID_MP2, MimeType::AUDIO_MPEG},
|
||||
{AV_CODEC_ID_MP3, MimeType::AUDIO_MPEG},
|
||||
{AV_CODEC_ID_FLAC, MimeType::AUDIO_FLAC},
|
||||
{AV_CODEC_ID_AAC, MimeType::AUDIO_AAC},
|
||||
|
@ -71,8 +71,8 @@ ohos_shared_library("media_plugin_AudioServerSink") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -756,7 +756,7 @@ int32_t AudioServerSinkPlugin::WriteAudioVivid(const std::shared_ptr<OHOS::Media
|
||||
auto pcmBufferSize = mem->GetSize();
|
||||
auto meta = inputBuffer->meta_;
|
||||
std::vector<uint8_t> metaData;
|
||||
meta->GetData(Tag::AUDIO_VIVID_METADATA, metaData);
|
||||
meta->GetData(Tag::OH_MD_KEY_AUDIO_VIVID_METADATA, metaData);
|
||||
FALSE_RETURN_V(audioRenderer_ != nullptr, -1);
|
||||
return audioRenderer_->Write(pcmBuffer, pcmBufferSize, metaData.data(), metaData.size());
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ ohos_shared_library("media_plugin_FileFdSource") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
@ -96,8 +96,8 @@ ohos_shared_library("media_plugin_DataStreamSource") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -134,7 +134,11 @@ Status DataStreamSourcePlugin::Read(std::shared_ptr<Plugins::Buffer>& buffer, ui
|
||||
return Status::END_OF_STREAM;
|
||||
}
|
||||
offset_ += realLen;
|
||||
buffer = WrapAVSharedMemory(memory, realLen);
|
||||
if (buffer && buffer->GetMemory()) {
|
||||
buffer->GetMemory()->Write(memory->GetBase(), realLen, 0);
|
||||
} else {
|
||||
buffer = WrapAVSharedMemory(memory, realLen);
|
||||
}
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
|
@ -76,8 +76,8 @@ ohos_shared_library("media_plugin_HttpSource") {
|
||||
"c_utils:utils",
|
||||
"graphic_2d:surface",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -19,10 +19,11 @@
|
||||
#include "http_curl_client.h"
|
||||
#include "osal/utils/steady_clock.h"
|
||||
#include "securec.h"
|
||||
#include "common/plugin_time.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
namespace {
|
||||
constexpr int PER_REQUEST_SIZE = 48 * 1024 * 10;
|
||||
@ -117,6 +118,19 @@ double DownloadRequest::GetDuration()
|
||||
return duration_;
|
||||
}
|
||||
|
||||
void DownloadRequest::SetStartTimePos(int64_t startTimePos)
|
||||
{
|
||||
startTimePos_ = startTimePos;
|
||||
if (startTimePos_ > 0) {
|
||||
shouldSaveData_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadRequest::SetDownloadDoneCb(DownloadDoneCbFunc downloadDoneCallback)
|
||||
{
|
||||
downloadDoneCallback_ = downloadDoneCallback;
|
||||
}
|
||||
|
||||
Downloader::Downloader(std::string name) noexcept : name_(std::move(name))
|
||||
{
|
||||
shouldStartNextRequest = true;
|
||||
@ -140,7 +154,6 @@ Downloader::~Downloader()
|
||||
bool Downloader::Download(const std::shared_ptr<DownloadRequest>& request, int32_t waitMs)
|
||||
{
|
||||
MEDIA_LOG_I("In");
|
||||
AutoLock lock(operatorMutex_);
|
||||
requestQue_->SetActive(true);
|
||||
if (waitMs == -1) { // wait until push success
|
||||
requestQue_->Push(request);
|
||||
@ -263,7 +276,7 @@ bool Downloader::BeginDownload()
|
||||
|
||||
client_->Open(url);
|
||||
|
||||
currentRequest_->requestSize_ = 1;
|
||||
currentRequest_->requestSize_ = 2; // 2
|
||||
currentRequest_->startPos_ = 0;
|
||||
currentRequest_->isEos_ = false;
|
||||
currentRequest_->retryTimes_ = 0;
|
||||
@ -288,8 +301,8 @@ void Downloader::HttpDownloadLoop()
|
||||
FALSE_RETURN_W(currentRequest_ != nullptr);
|
||||
NetworkClientErrorCode clientCode = NetworkClientErrorCode::ERROR_OK;
|
||||
NetworkServerErrorCode serverCode = 0;
|
||||
long startPos = currentRequest_->startPos_;
|
||||
if (currentRequest_->requestWholeFile_) {
|
||||
int64_t startPos = currentRequest_->startPos_;
|
||||
if (currentRequest_->requestWholeFile_ && currentRequest_->shouldSaveData_) {
|
||||
startPos = -1;
|
||||
}
|
||||
Status ret = client_->RequestData(startPos, currentRequest_->requestSize_,
|
||||
@ -322,6 +335,9 @@ void Downloader::HandleRetOK()
|
||||
task_->PauseAsync();
|
||||
}
|
||||
shouldStartNextRequest = true;
|
||||
if (currentRequest_->downloadDoneCallback_) {
|
||||
currentRequest_->downloadDoneCallback_(currentRequest_->GetUrl());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (currentRequest_->headerInfo_.fileContentLen == 0 && remaining <= 0) {
|
||||
@ -331,6 +347,9 @@ void Downloader::HandleRetOK()
|
||||
task_->PauseAsync();
|
||||
}
|
||||
shouldStartNextRequest = true;
|
||||
if (currentRequest_->downloadDoneCallback_) {
|
||||
currentRequest_->downloadDoneCallback_(currentRequest_->GetUrl());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (remaining < PER_REQUEST_SIZE) {
|
||||
@ -348,6 +367,19 @@ size_t Downloader::RxBodyData(void* buffer, size_t size, size_t nitems, void* us
|
||||
}
|
||||
HeaderInfo* header = &(mediaDownloader->currentRequest_->headerInfo_);
|
||||
size_t dataLen = size * nitems;
|
||||
if (!mediaDownloader->currentRequest_->shouldSaveData_) {
|
||||
int64_t hstTime;
|
||||
Plugins::Sec2HstTime(mediaDownloader->currentRequest_->GetDuration(), hstTime);
|
||||
int64_t startTimePos = mediaDownloader->currentRequest_->startTimePos_;
|
||||
int64_t contenLen = header->fileContentLen;
|
||||
int64_t startPos = contenLen * startTimePos / (Plugins::HstTime2Ns(hstTime));
|
||||
mediaDownloader->currentRequest_->startPos_ = startPos;
|
||||
mediaDownloader->currentRequest_->shouldSaveData_ = true;
|
||||
mediaDownloader->currentRequest_->requestWholeFile_ = false;
|
||||
mediaDownloader->currentRequest_->requestSize_ = PER_REQUEST_SIZE;
|
||||
mediaDownloader->currentRequest_->startTimePos_ = 0;
|
||||
return dataLen;
|
||||
}
|
||||
if (header->fileContentLen == 0) {
|
||||
if (header->contentLen > 0) {
|
||||
MEDIA_LOG_W("Unsupported range, use content length as content file length");
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
enum struct DownloadStatus {
|
||||
PARTTAL_DOWNLOAD,
|
||||
@ -64,6 +64,7 @@ class Downloader;
|
||||
class DownloadRequest;
|
||||
using StatusCallbackFunc = std::function<void(DownloadStatus, std::shared_ptr<Downloader>&,
|
||||
std::shared_ptr<DownloadRequest>&)>;
|
||||
using DownloadDoneCbFunc = std::function<void(std::string)>;
|
||||
|
||||
class DownloadRequest {
|
||||
public:
|
||||
@ -89,7 +90,8 @@ public:
|
||||
bool IsClosed() const;
|
||||
void Close();
|
||||
double GetDuration();
|
||||
|
||||
void SetStartTimePos(int64_t startTimePos);
|
||||
void SetDownloadDoneCb(DownloadDoneCbFunc downloadDoneCallback);
|
||||
private:
|
||||
void WaitHeaderUpdated() const;
|
||||
|
||||
@ -97,19 +99,21 @@ private:
|
||||
double duration_;
|
||||
DataSaveFunc saveData_;
|
||||
StatusCallbackFunc statusCallback_;
|
||||
DownloadDoneCbFunc downloadDoneCallback_;
|
||||
|
||||
HeaderInfo headerInfo_;
|
||||
|
||||
bool isHeaderUpdated {false};
|
||||
bool isEos_ {false}; // file download finished
|
||||
int64_t startPos_;
|
||||
int64_t startPos_ {0};
|
||||
int64_t startTimePos_ {0};
|
||||
bool isDownloading_;
|
||||
bool requestWholeFile_ {false};
|
||||
int requestSize_;
|
||||
int retryTimes_ {0};
|
||||
NetworkClientErrorCode clientError_ {NetworkClientErrorCode::ERROR_OK};
|
||||
NetworkServerErrorCode serverError_ {0};
|
||||
|
||||
bool shouldSaveData_ {true};
|
||||
friend class Downloader;
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
HttpCurlClient::HttpCurlClient(RxHeader headCallback, RxBody bodyCallback, void *userParam)
|
||||
: rxHeader_(headCallback), rxBody_(bodyCallback), userParam_(userParam)
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class HttpCurlClient : public NetworkClient {
|
||||
public:
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class NetworkClient {
|
||||
public:
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
using RxBody = size_t(*)(void* buffer, size_t size, size_t nitems, void* userParam);
|
||||
using RxHeader = size_t(*)(void* buffer, size_t size, size_t nitems, void* userParam);
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
namespace {
|
||||
constexpr int RING_BUFFER_SIZE = 5 * 48 * 1024;
|
||||
@ -35,9 +35,6 @@ HlsMediaDownloader::HlsMediaDownloader() noexcept
|
||||
buffer_->Init();
|
||||
|
||||
downloader_ = std::make_shared<Downloader>("hlsMedia");
|
||||
downloadTask_ = std::make_shared<Task>(std::string("FragmentDownload"));
|
||||
downloadTask_->RegisterJob([this] { FragmentDownloadLoop(); });
|
||||
|
||||
playList_ = std::make_shared<BlockingQueue<PlayInfo>>("PlayList", 50); // 50
|
||||
|
||||
dataSave_ = [this] (uint8_t*&& data, uint32_t&& len) {
|
||||
@ -48,31 +45,24 @@ HlsMediaDownloader::HlsMediaDownloader() noexcept
|
||||
playListDownloader_->SetPlayListCallback(this);
|
||||
}
|
||||
|
||||
void HlsMediaDownloader::FragmentDownloadLoop()
|
||||
{
|
||||
auto playInfo = playList_->Pop();
|
||||
std::string url = playInfo.url_;
|
||||
if (url.empty()) { // when monitor pause, playList_ set active false, it's empty
|
||||
OSAL::SleepFor(10); // 10
|
||||
return;
|
||||
}
|
||||
if (!fragmentDownloadStart[url]) {
|
||||
fragmentDownloadStart[url] = true;
|
||||
PutRequestIntoDownloader(playInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void HlsMediaDownloader::PutRequestIntoDownloader(const PlayInfo& playInfo)
|
||||
{
|
||||
auto realStatusCallback = [this] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
|
||||
std::shared_ptr<DownloadRequest>& request) {
|
||||
statusCallback_(status, downloader_, std::forward<decltype(request)>(request));
|
||||
};
|
||||
auto downloadDoneCallback = [this] (std::string url) {
|
||||
UpdateDownloadFinished(url);
|
||||
};
|
||||
// TO DO: If the fragment file is too large, should not requestWholeFile.
|
||||
downloadRequest_ = std::make_shared<DownloadRequest>(playInfo.url_, playInfo.duration_,
|
||||
dataSave_, realStatusCallback, true);
|
||||
downloadRequest_ = std::make_shared<DownloadRequest>(playInfo.url_, playInfo.duration_, dataSave_,
|
||||
realStatusCallback, true);
|
||||
// push request to back queue for seek
|
||||
backPlayList_.push_back(downloadRequest_);
|
||||
fragmentDownloadStart[playInfo.url_] = true;
|
||||
int64_t startTimePos = playInfo.startTimePos_;
|
||||
curUrl_ = playInfo.url_;
|
||||
downloadRequest_->SetDownloadDoneCb(downloadDoneCallback);
|
||||
downloadRequest_->SetStartTimePos(startTimePos);
|
||||
downloader_->Download(downloadRequest_, -1); // -1
|
||||
downloader_->Start();
|
||||
}
|
||||
@ -80,7 +70,6 @@ void HlsMediaDownloader::PutRequestIntoDownloader(const PlayInfo& playInfo)
|
||||
bool HlsMediaDownloader::Open(const std::string& url)
|
||||
{
|
||||
playListDownloader_->Open(url);
|
||||
downloadTask_->Start();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -88,7 +77,6 @@ void HlsMediaDownloader::Close(bool isAsync)
|
||||
{
|
||||
buffer_->SetActive(false);
|
||||
playList_->SetActive(false);
|
||||
downloadTask_->Stop();
|
||||
playListDownloader_->Close();
|
||||
downloader_->Stop();
|
||||
}
|
||||
@ -99,7 +87,6 @@ void HlsMediaDownloader::Pause()
|
||||
buffer_->SetActive(false, cleanData);
|
||||
playList_->SetActive(false, cleanData);
|
||||
playListDownloader_->Pause();
|
||||
downloadTask_->Pause();
|
||||
downloader_->Pause();
|
||||
}
|
||||
|
||||
@ -108,7 +95,6 @@ void HlsMediaDownloader::Resume()
|
||||
buffer_->SetActive(true);
|
||||
playList_->SetActive(true);
|
||||
playListDownloader_->Resume();
|
||||
downloadTask_->Start();
|
||||
downloader_->Resume();
|
||||
}
|
||||
|
||||
@ -162,7 +148,30 @@ void HlsMediaDownloader::SetCallback(Callback* cb)
|
||||
void HlsMediaDownloader::OnPlayListChanged(const std::vector<PlayInfo>& playList)
|
||||
{
|
||||
for (auto& fragment : playList) {
|
||||
playList_->Push(fragment);
|
||||
auto ret = std::find_if(backPlayList_.begin(), backPlayList_.end(), [&](PlayInfo playInfo) {
|
||||
return playInfo.url_ == fragment.url_;
|
||||
});
|
||||
if (ret == backPlayList_.end()) {
|
||||
backPlayList_.push_back(fragment);
|
||||
}
|
||||
if (isSelectingBitrate_) {
|
||||
if (curUrl_ == fragment.url_) {
|
||||
isSelectingBitrate_ = false;
|
||||
fragmentDownloadStart[fragment.url_] = true;
|
||||
} else {
|
||||
fragmentDownloadStart[fragment.url_] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!fragmentDownloadStart[fragment.url_]) {
|
||||
playList_->Push(fragment);
|
||||
}
|
||||
}
|
||||
if (!isDownloadStarted_ && !playList_->Empty()) {
|
||||
auto playInfo = playList_->Pop();
|
||||
std::string url = playInfo.url_;
|
||||
isDownloadStarted_ = true;
|
||||
PutRequestIntoDownloader(playInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,9 +202,6 @@ bool HlsMediaDownloader::SelectBitRate(uint32_t bitRate)
|
||||
if (playListDownloader_->IsBitrateSame(bitRate)) {
|
||||
return 0;
|
||||
}
|
||||
buffer_->Clear(); // First clear buffer, avoid no available buffer then task pause never exit.
|
||||
downloader_->Stop();
|
||||
buffer_->Clear();
|
||||
playListDownloader_->Stop();
|
||||
|
||||
// clear request queue
|
||||
@ -206,8 +212,8 @@ bool HlsMediaDownloader::SelectBitRate(uint32_t bitRate)
|
||||
|
||||
// switch to des bitrate
|
||||
playListDownloader_->SelectBitRate(bitRate);
|
||||
downloader_->Start();
|
||||
playListDownloader_->Start();
|
||||
isSelectingBitrate_ = true;
|
||||
playListDownloader_->UpdateManifest();
|
||||
return 1;
|
||||
}
|
||||
@ -215,21 +221,40 @@ bool HlsMediaDownloader::SelectBitRate(uint32_t bitRate)
|
||||
void HlsMediaDownloader::FindSeekRequest(int64_t offset)
|
||||
{
|
||||
int64_t totalDuration = 0;
|
||||
isDownloadStarted_ = false;
|
||||
playList_->Clear();
|
||||
for (const auto &item : backPlayList_) {
|
||||
int64_t hstTime;
|
||||
Plugin::Sec2HstTime(item->GetDuration(), hstTime);
|
||||
totalDuration += Plugin::HstTime2Ns(hstTime);
|
||||
Plugins::Sec2HstTime(item.duration_, hstTime);
|
||||
totalDuration += Plugins::HstTime2Ns(hstTime);
|
||||
if (offset < totalDuration) {
|
||||
PlayInfo playInfo;
|
||||
playInfo.url_ = item->GetUrl();
|
||||
playInfo.duration_ = item->GetDuration();
|
||||
MEDIA_LOG_I("Find url_" PUBLIC_LOG_S " totalDuration " PUBLIC_LOG_D64,
|
||||
playInfo.url_.c_str(), totalDuration);
|
||||
PutRequestIntoDownloader(playInfo);
|
||||
playInfo.url_ = item.url_;
|
||||
playInfo.duration_ = item.duration_;
|
||||
int64_t startTimePos = 0;
|
||||
int64_t lastTotalDuration = totalDuration - hstTime;
|
||||
if (lastTotalDuration < offset) {
|
||||
startTimePos = offset - lastTotalDuration;
|
||||
}
|
||||
playInfo.startTimePos_ = startTimePos;
|
||||
if (!isDownloadStarted_) {
|
||||
isDownloadStarted_ = true;
|
||||
PutRequestIntoDownloader(playInfo);
|
||||
} else {
|
||||
playList_->Push(playInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HlsMediaDownloader::UpdateDownloadFinished(std::string url)
|
||||
{
|
||||
// get cur request file size
|
||||
if (!playList_->Empty()) {
|
||||
auto playInfo = playList_->Pop();
|
||||
PutRequestIntoDownloader(playInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class HlsMediaDownloader : public MediaDownloader, public PlayListChangeCallback {
|
||||
public:
|
||||
@ -45,11 +45,11 @@ public:
|
||||
std::vector<uint32_t> GetBitRates() override;
|
||||
bool SelectBitRate(uint32_t bitRate) override;
|
||||
void FindSeekRequest(int64_t offset);
|
||||
void PutRequestIntoDownloader(const PlayInfo& playInfo);
|
||||
void PutRequestIntoDownloader(const PlayInfo& palyInfo);
|
||||
void UpdateDownloadFinished(std::string url);
|
||||
|
||||
private:
|
||||
bool SaveData(uint8_t* data, uint32_t len);
|
||||
void FragmentDownloadLoop();
|
||||
|
||||
private:
|
||||
std::shared_ptr<RingBuffer> buffer_;
|
||||
@ -63,10 +63,12 @@ private:
|
||||
|
||||
std::shared_ptr<PlayListDownloader> playListDownloader_;
|
||||
|
||||
std::shared_ptr<Task> downloadTask_;
|
||||
std::shared_ptr<BlockingQueue<PlayInfo>> playList_;
|
||||
std::map<std::string, bool> fragmentDownloadStart;
|
||||
std::deque<std::shared_ptr<DownloadRequest>> backPlayList_;
|
||||
std::deque<PlayInfo> backPlayList_;
|
||||
bool isSelectingBitrate_ {false};
|
||||
bool isDownloadStarted_ {false};
|
||||
std::string curUrl_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
void HlsPlayListDownloader::PlayListUpdateLoop()
|
||||
{
|
||||
@ -59,8 +59,8 @@ int64_t HlsPlayListDownloader::GetDuration() const
|
||||
return 0;
|
||||
}
|
||||
int64_t hstTime;
|
||||
Plugin::Sec2HstTime(master_->duration_, hstTime);
|
||||
return master_->bLive_ ? -1.0 : (Plugin::HstTime2Ns(hstTime)); // -1.0
|
||||
Plugins::Sec2HstTime(master_->duration_, hstTime);
|
||||
return master_->bLive_ ? -1.0 : (Plugins::HstTime2Ns(hstTime)); // -1.0
|
||||
}
|
||||
|
||||
Seekable HlsPlayListDownloader::GetSeekable() const
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class HlsPlayListDownloader : public PlayListDownloader {
|
||||
public:
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
struct {
|
||||
const char* name;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class Attribute {
|
||||
public:
|
||||
@ -55,25 +55,25 @@ enum struct HlsTag : uint32_t {
|
||||
SECTION_VALUES_LIST_START = static_cast<uint8_t>(HlsTagSection::VALUES_LIST) << 16U, // values list tag
|
||||
|
||||
EXTXDISCONTINUITY = SECTION_REGULAR_START,
|
||||
EXTXENDLIST = SECTION_REGULAR_START + 1,
|
||||
EXTXIFRAMESONLY = SECTION_REGULAR_START + 2,
|
||||
EXTXENDLIST,
|
||||
EXTXIFRAMESONLY,
|
||||
|
||||
URI = SECTION_SINGLE_VALUE_START,
|
||||
EXTXVERSION = SECTION_SINGLE_VALUE_START + 1,
|
||||
EXTXBYTERANGE = SECTION_SINGLE_VALUE_START + 2,
|
||||
EXTXPROGRAMDATETIME = SECTION_SINGLE_VALUE_START + 3,
|
||||
EXTXTARGETDURATION = SECTION_SINGLE_VALUE_START + 4,
|
||||
EXTXMEDIASEQUENCE = SECTION_SINGLE_VALUE_START + 5,
|
||||
EXTXDISCONTINUITYSEQUENCE = SECTION_SINGLE_VALUE_START + 6,
|
||||
EXTXPLAYLISTTYPE = SECTION_SINGLE_VALUE_START + 7,
|
||||
EXTXVERSION,
|
||||
EXTXBYTERANGE,
|
||||
EXTXPROGRAMDATETIME,
|
||||
EXTXTARGETDURATION,
|
||||
EXTXMEDIASEQUENCE,
|
||||
EXTXDISCONTINUITYSEQUENCE,
|
||||
EXTXPLAYLISTTYPE,
|
||||
|
||||
EXTXKEY = SECTION_ATTRIBUTES_START,
|
||||
EXTXMAP = SECTION_ATTRIBUTES_START + 1,
|
||||
EXTXMEDIA = SECTION_ATTRIBUTES_START + 2,
|
||||
EXTXSTART = SECTION_ATTRIBUTES_START + 3,
|
||||
EXTXSTREAMINF = SECTION_ATTRIBUTES_START + 4,
|
||||
EXTXIFRAMESTREAMINF = SECTION_ATTRIBUTES_START + 5,
|
||||
EXTXSESSIONKEY = SECTION_ATTRIBUTES_START + 6,
|
||||
EXTXMAP,
|
||||
EXTXMEDIA,
|
||||
EXTXSTART,
|
||||
EXTXSTREAMINF,
|
||||
EXTXIFRAMESTREAMINF,
|
||||
EXTXSESSIONKEY,
|
||||
|
||||
EXTINF = SECTION_VALUES_LIST_START,
|
||||
};
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
namespace {
|
||||
bool StrHasPrefix(std::string& str, const std::string& prefix)
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
enum class M3U8MediaType : int32_t {
|
||||
M3U8_MEDIA_TYPE_INVALID = -1,
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
PlayListDownloader::PlayListDownloader()
|
||||
{
|
||||
|
@ -21,11 +21,12 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
struct PlayInfo {
|
||||
std::string url_;
|
||||
double duration_;
|
||||
int64_t startTimePos_ {0};
|
||||
};
|
||||
struct PlayListChangeCallback {
|
||||
virtual ~PlayListChangeCallback() = default;
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
namespace {
|
||||
#ifdef OHOS_LITE
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class HttpMediaDownloader : public MediaDownloader {
|
||||
public:
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
namespace {
|
||||
constexpr int DEFAULT_BUFFER_SIZE = 200 * 1024;
|
||||
@ -109,13 +109,13 @@ Status HttpSourcePlugin::Stop()
|
||||
|
||||
#undef ERROR_INVALID_PARAMETER
|
||||
|
||||
Status HttpSourcePlugin::GetParameter(std::shared_ptr<Meta> meta)
|
||||
Status HttpSourcePlugin::GetParameter(std::shared_ptr<Meta> &meta)
|
||||
{
|
||||
MEDIA_LOG_I("GetParameter enter.");
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status HttpSourcePlugin::SetParameter(std::shared_ptr<Meta> meta)
|
||||
Status HttpSourcePlugin::SetParameter(const std::shared_ptr<Meta> &meta)
|
||||
{
|
||||
MEDIA_LOG_I("SetParameter enter.");
|
||||
meta->GetData(Tag::BUFFERING_SIZE, bufferSize_);
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class HttpSourcePlugin : public SourcePlugin {
|
||||
public:
|
||||
@ -35,8 +35,8 @@ public:
|
||||
Status Reset() override;
|
||||
Status Start() override;
|
||||
Status Stop() override;
|
||||
Status GetParameter(std::shared_ptr<Meta> meta) override;
|
||||
Status SetParameter(std::shared_ptr<Meta> meta) override;
|
||||
Status GetParameter(std::shared_ptr<Meta> &meta) override;
|
||||
Status SetParameter(const std::shared_ptr<Meta> &meta) override;
|
||||
Status SetCallback(Callback* cb) override;
|
||||
Status SetSource(std::shared_ptr<MediaSource> source) override;
|
||||
Status Read(std::shared_ptr<Buffer>& buffer, uint64_t offset, size_t expectedLen) override;
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
class MediaDownloader {
|
||||
public:
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
namespace {
|
||||
constexpr int RETRY_TIMES_TO_REPORT_ERROR = 5;
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
namespace Plugins {
|
||||
namespace HttpPlugin {
|
||||
struct RetryRequest {
|
||||
std::shared_ptr<DownloadRequest> request;
|
||||
|
@ -156,8 +156,8 @@ ohos_shared_library("av_codec_service") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
|
||||
|
@ -32,8 +32,8 @@ ohos_fuzztest("DemuxerFuzzTest") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
deps = [
|
||||
|
@ -48,8 +48,8 @@ ohos_fuzztest("EncoderConfigureFuzzTest") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
deps = [
|
||||
|
@ -47,8 +47,8 @@ ohos_fuzztest("EncoderSetParameterFuzzTest") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
deps = [
|
||||
|
@ -48,8 +48,8 @@ ohos_fuzztest("SwdecoderConfigureFuzzTest") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
deps = [
|
||||
|
@ -47,8 +47,8 @@ ohos_fuzztest("SwdecoderResourceFuzzTest") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
deps = [
|
||||
|
@ -47,8 +47,8 @@ ohos_fuzztest("SwdecoderSetParameterFuzzTest") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
deps = [
|
||||
|
@ -83,8 +83,8 @@ ohos_unittest("audio_decoder_module_test") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
resource_config_file =
|
||||
|
@ -83,8 +83,8 @@ ohos_unittest("audio_encoder_module_test") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
resource_config_file =
|
||||
|
@ -79,8 +79,8 @@ ohos_unittest("encoder_native_module_test") {
|
||||
"graphic_2d:librender_service_client",
|
||||
"graphic_2d:surface",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
|
@ -83,8 +83,8 @@ ohos_unittest("hwdecoder_native_module_test") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
resource_config_file =
|
||||
|
@ -83,8 +83,8 @@ ohos_unittest("swdecoder_native_module_test") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
resource_config_file =
|
||||
|
@ -113,8 +113,8 @@ ohos_executable("av_codec_demo") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
|
@ -65,6 +65,9 @@ constexpr string_view INPUT_AMRWB_FILE_PATH = "/data/test/media/voice_amrwb_2385
|
||||
constexpr string_view OUTPUT_AMRWB_PCM_FILE_PATH = "/data/test/media/voice_amrwb_23850.pcm";
|
||||
constexpr string_view INPUT_G711MU_FILE_PATH = "/data/test/media/g711mu_8kHz.dat";
|
||||
constexpr string_view OUTPUT_G711MU_PCM_FILE_PATH = "/data/test/media/g711mu_8kHz_decode.pcm";
|
||||
constexpr string_view INPUT_OPUS_FILE_PATH = "/data/test/media/voice_opus.dat";
|
||||
constexpr string_view OUTPUT_OPUS_PCM_FILE_PATH = "/data/test/media/opus_decode.pcm";
|
||||
constexpr string_view OPUS_SO_FILE_PATH = "/system/lib64/libav_codec_ext_base.z.so";
|
||||
} // namespace
|
||||
|
||||
namespace OHOS {
|
||||
@ -77,7 +80,8 @@ enum class AudioBufferFormatType : int32_t {
|
||||
TYPE_AMRNB = 4,
|
||||
TYPE_AMRWB = 5,
|
||||
TYPE_G711MU = 6,
|
||||
TYPE_MAX = 7,
|
||||
TYPE_OPUS = 7,
|
||||
TYPE_MAX = 8,
|
||||
};
|
||||
|
||||
class AudioCodecBufferSignal {
|
||||
@ -141,6 +145,7 @@ public:
|
||||
void InputFunc();
|
||||
void OutputFunc();
|
||||
int32_t CreateCodecFunc(AudioBufferFormatType audioType);
|
||||
int32_t CheckSoFunc();
|
||||
void HandleInputEOS(const uint32_t index);
|
||||
int32_t Configure(AudioBufferFormatType audioType);
|
||||
int32_t Start();
|
||||
@ -158,6 +163,7 @@ protected:
|
||||
bool isFirstFrame_ = true;
|
||||
uint32_t frameCount_ = 0;
|
||||
std::ifstream inputFile_;
|
||||
std::unique_ptr<std::ifstream> soFile_;
|
||||
std::ofstream pcmOutputFile_;
|
||||
};
|
||||
|
||||
@ -404,6 +410,9 @@ int32_t AudioDecoderBufferCapiUnitTest::InitFile(AudioBufferFormatType audioType
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
|
||||
inputFile_.open(INPUT_G711MU_FILE_PATH, std::ios::binary);
|
||||
pcmOutputFile_.open(OUTPUT_G711MU_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
|
||||
inputFile_.open(INPUT_OPUS_FILE_PATH, std::ios::binary);
|
||||
pcmOutputFile_.open(OUTPUT_OPUS_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
|
||||
} else {
|
||||
cout << "Fatal: audio format type not support" << endl;
|
||||
return OH_AVErrCode::AV_ERR_UNKNOWN;
|
||||
@ -436,6 +445,8 @@ int32_t AudioDecoderBufferCapiUnitTest::CreateCodecFunc(AudioBufferFormatType au
|
||||
audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRNB_NAME).data());
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
|
||||
audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_G711MU_NAME).data());
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
|
||||
audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_OPUS_NAME).data());
|
||||
} else {
|
||||
cout << "audio name not support" << endl;
|
||||
return OH_AVErrCode::AV_ERR_UNKNOWN;
|
||||
@ -468,14 +479,14 @@ int32_t AudioDecoderBufferCapiUnitTest::Configure(AudioBufferFormatType audioTyp
|
||||
cout << "Fatal: create format failed" << endl;
|
||||
return OH_AVErrCode::AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t channelCount = CHANNEL_COUNT;
|
||||
int32_t sampleRate = DEFAULT_SAMPLE_RATE;
|
||||
if (audioType == AudioBufferFormatType::TYPE_AAC) {
|
||||
OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
|
||||
OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
OH_BitsPerSample::SAMPLE_S16LE);
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_AMRNB || audioType == AudioBufferFormatType::TYPE_G711MU) {
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_AMRNB || audioType == AudioBufferFormatType::TYPE_G711MU ||
|
||||
audioType == AudioBufferFormatType::TYPE_OPUS) {
|
||||
channelCount = 1;
|
||||
sampleRate = AMRNB_SAMPLE_RATE;
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_AMRWB) {
|
||||
@ -490,7 +501,6 @@ int32_t AudioDecoderBufferCapiUnitTest::Configure(AudioBufferFormatType audioTyp
|
||||
if (audioType == AudioBufferFormatType::TYPE_VORBIS) {
|
||||
OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
OH_BitsPerSample::SAMPLE_S16LE);
|
||||
// extradata for vorbis
|
||||
int64_t extradataSize;
|
||||
if (!inputFile_.is_open()) {
|
||||
cout << "Fatal: file is not open" << endl;
|
||||
@ -501,7 +511,6 @@ int32_t AudioDecoderBufferCapiUnitTest::Configure(AudioBufferFormatType audioTyp
|
||||
cout << "Fatal: read extradataSize bytes error" << endl;
|
||||
return OH_AVErrCode::AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
char buffer[extradataSize];
|
||||
inputFile_.read(buffer, extradataSize);
|
||||
if (inputFile_.gcount() != extradataSize) {
|
||||
@ -511,10 +520,20 @@ int32_t AudioDecoderBufferCapiUnitTest::Configure(AudioBufferFormatType audioTyp
|
||||
OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
|
||||
extradataSize);
|
||||
}
|
||||
|
||||
return OH_AudioCodec_Configure(audioDec_, format_);
|
||||
}
|
||||
|
||||
int32_t AudioDecoderBufferCapiUnitTest::CheckSoFunc()
|
||||
{
|
||||
soFile_ = std::make_unique<std::ifstream>(OPUS_SO_FILE_PATH, std::ios::binary);
|
||||
if (!soFile_->is_open()) {
|
||||
cout << "Fatal: Open so file failed" << endl;
|
||||
return false;
|
||||
}
|
||||
soFile_->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_CreateByMime_01, TestSize.Level1)
|
||||
{
|
||||
audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_MPEG.data(), false);
|
||||
@ -1843,5 +1862,334 @@ HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_ReleaseOutputBuffer_
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_CreateByMime_01, TestSize.Level1)
|
||||
{
|
||||
audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_G711MU.data(), false);
|
||||
EXPECT_NE(nullptr, audioDec_);
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_CreateByName_01, TestSize.Level1)
|
||||
{
|
||||
audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_G711MU_NAME).data());
|
||||
EXPECT_NE(nullptr, audioDec_);
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Configure_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_SetParameter_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_SetParameter_02, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Start_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Start_02, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Stop_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
sleep(1);
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Flush_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_02, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_03, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Destroy_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Destroy_02, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_GetOutputFormat_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
|
||||
EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_IsValid_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
bool isValid = false;
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Prepare_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_PushInputData_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
|
||||
// case0 传参异常
|
||||
const uint32_t index = 1024;
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_ReleaseOutputBuffer_01, TestSize.Level1)
|
||||
{
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
|
||||
// case0 传参异常
|
||||
const uint32_t index = 1024;
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_CreateByMime_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_OPUS.data(), false);
|
||||
EXPECT_NE(nullptr, audioDec_);
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_CreateByName_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_OPUS_NAME).data());
|
||||
EXPECT_NE(nullptr, audioDec_);
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Configure_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_SetParameter_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Stop_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
sleep(1);
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Flush_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
|
||||
{
|
||||
unique_lock<mutex> lock(signal_->startMutex_);
|
||||
signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Reset_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_GetOutputFormat_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
|
||||
|
||||
EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_IsValid_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
bool isValid = false;
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
|
||||
Release();
|
||||
}
|
||||
|
||||
HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Prepare_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
|
||||
Release();
|
||||
}
|
||||
}
|
||||
}
|
@ -48,6 +48,9 @@ namespace {
|
||||
constexpr uint32_t CHANNEL_COUNT = 2;
|
||||
constexpr uint32_t ABNORMAL_CHANNEL_COUNT = 10;
|
||||
constexpr uint32_t SAMPLE_RATE = 44100;
|
||||
constexpr uint32_t OPUS_SAMPLE_RATE = 48000;
|
||||
constexpr uint32_t CHANNEL_1CHAN_COUNT = 1;
|
||||
constexpr uint32_t SAMPLE_RATE_8K = 8000;
|
||||
constexpr uint32_t ABNORMAL_SAMPLE_RATE = 9999999;
|
||||
constexpr uint32_t BITS_RATE = 261000;
|
||||
constexpr int32_t ABNORMAL_BITS_RATE = -1;
|
||||
@ -67,6 +70,11 @@ constexpr string_view FLAC_INPUT_FILE_PATH = "/data/test/media/flac_2c_44100hz_2
|
||||
constexpr string_view FLAC_OUTPUT_FILE_PATH = "/data/test/media/encoderTest.flac";
|
||||
constexpr string_view AAC_INPUT_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k.pcm";
|
||||
constexpr string_view AAC_OUTPUT_FILE_PATH = "/data/test/media/aac_2c_44100hz_encode.aac";
|
||||
constexpr string_view G711MU_INPUT_FILE_PATH = "/data/test/media/g711mu_8kHz_10s.pcm";
|
||||
constexpr string_view G711MU_OUTPUT_FILE_PATH = "/data/test/media/g711mu_8kHz_10s_afterEncode.raw";
|
||||
constexpr string_view OPUS_INPUT_FILE_PATH = "/data/test/media/flac_2c_44100hz_261k.pcm";
|
||||
constexpr string_view OPUS_OUTPUT_FILE_PATH = "/data/test/media/encoderTest.opus";
|
||||
constexpr string_view OPUS_SO_FILE_PATH = "/system/lib64/libav_codec_ext_base.z.so";
|
||||
} // namespace
|
||||
|
||||
namespace OHOS {
|
||||
@ -78,7 +86,9 @@ enum class AudioBufferFormatType : int32_t {
|
||||
TYPE_VORBIS = 3,
|
||||
TYPE_AMRNB = 4,
|
||||
TYPE_AMRWB = 5,
|
||||
TYPE_MAX = 6,
|
||||
TYPE_G711MU = 6,
|
||||
TYPE_OPUS = 7,
|
||||
TYPE_MAX = 8,
|
||||
};
|
||||
|
||||
class AudioCodecBufferSignal {
|
||||
@ -152,6 +162,7 @@ public:
|
||||
int32_t GetFrameBytes();
|
||||
int32_t InitFile(AudioBufferFormatType audioType);
|
||||
int32_t CreateCodecFunc(AudioBufferFormatType audioType);
|
||||
int32_t CheckSoFunc();
|
||||
int32_t Configure();
|
||||
int32_t Start();
|
||||
int32_t Stop();
|
||||
@ -168,6 +179,7 @@ protected:
|
||||
bool isFirstFrame_ = true;
|
||||
std::unique_ptr<std::ifstream> inputFile_;
|
||||
std::unique_ptr<std::ofstream> outputFile_;
|
||||
std::unique_ptr<std::ifstream> soFile_;
|
||||
int32_t fileSize_ = 0;
|
||||
uint32_t frameBytes_ = FLAC_DEFAULT_FRAME_BYTES; // default for flac
|
||||
};
|
||||
@ -347,11 +359,18 @@ int32_t AudioEncoderBufferCapiUnitTest::InitFile(AudioBufferFormatType audioType
|
||||
fileSize_ = GetFileSize(AAC_INPUT_FILE_PATH.data());
|
||||
inputFile_ = std::make_unique<std::ifstream>(AAC_INPUT_FILE_PATH, std::ios::binary);
|
||||
outputFile_ = std::make_unique<std::ofstream>(AAC_OUTPUT_FILE_PATH, std::ios::binary);
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
|
||||
fileSize_ = GetFileSize(G711MU_INPUT_FILE_PATH.data());
|
||||
inputFile_ = std::make_unique<std::ifstream>(G711MU_INPUT_FILE_PATH, std::ios::binary);
|
||||
outputFile_ = std::make_unique<std::ofstream>(G711MU_OUTPUT_FILE_PATH, std::ios::binary);
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
|
||||
fileSize_ = GetFileSize(AAC_INPUT_FILE_PATH.data());
|
||||
inputFile_ = std::make_unique<std::ifstream>(OPUS_INPUT_FILE_PATH, std::ios::binary);
|
||||
outputFile_ = std::make_unique<std::ofstream>(OPUS_OUTPUT_FILE_PATH, std::ios::binary);
|
||||
} else {
|
||||
cout << "audio name not support" << endl;
|
||||
return OH_AVErrCode::AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (!inputFile_->is_open()) {
|
||||
cout << "Fatal: open input file failed" << endl;
|
||||
return OH_AVErrCode::AV_ERR_UNKNOWN;
|
||||
@ -369,6 +388,10 @@ int32_t AudioEncoderBufferCapiUnitTest::CreateCodecFunc(AudioBufferFormatType au
|
||||
audioEnc_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_ENCODER_FLAC_NAME).data());
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_AAC) {
|
||||
audioEnc_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_ENCODER_AAC_NAME).data());
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
|
||||
audioEnc_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_ENCODER_G711MU_NAME).data());
|
||||
} else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
|
||||
audioEnc_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_ENCODER_OPUS_NAME).data());
|
||||
} else {
|
||||
cout << "audio name not support" << endl;
|
||||
return OH_AVErrCode::AV_ERR_UNKNOWN;
|
||||
@ -500,6 +523,17 @@ int32_t AudioEncoderBufferCapiUnitTest::Stop()
|
||||
return OH_AudioCodec_Stop(audioEnc_);
|
||||
}
|
||||
|
||||
int32_t AudioEncoderBufferCapiUnitTest::CheckSoFunc()
|
||||
{
|
||||
soFile_ = std::make_unique<std::ifstream>(OPUS_SO_FILE_PATH, std::ios::binary);
|
||||
if (!soFile_->is_open()) {
|
||||
cout << "Fatal: Open so file failed" << endl;
|
||||
return false;
|
||||
}
|
||||
soFile_->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, audioEncoder_CreateByName_01, TestSize.Level1)
|
||||
{
|
||||
audioEnc_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_ENCODER_AAC_NAME).data());
|
||||
@ -796,5 +830,181 @@ HWTEST_F(AudioEncoderBufferCapiUnitTest, aacCheckChannelLayout, TestSize.Level1)
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, g711muCheckChannelCount, TestSize.Level1)
|
||||
{
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE_8K);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // missing channel count
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ILLEGAL_CHANNEL_COUNT);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // illegal channel count
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_1CHAN_COUNT);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // normal channel count
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, g711muCheckSampleFormat, TestSize.Level1)
|
||||
{
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_1CHAN_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE_8K);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // missing sample format
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_U8);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // illegal sample format
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // normal sample format
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, g711muCheckSampleRate, TestSize.Level1)
|
||||
{
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_1CHAN_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // missing sample rate
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ILLEGAL_SAMPLE_RATE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // illegal sample rate
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE_8K);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // normal sample rate
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, opusCheckChannelCount, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), OPUS_SAMPLE_RATE);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // missing channel count
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ILLEGAL_CHANNEL_COUNT);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // illegal channel count
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // normal channel count
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, opusCheckSampleFormat, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), OPUS_SAMPLE_RATE);
|
||||
OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // missing sample format
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_U8);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // illegal sample format
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // normal sample format
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, opusCheckSampleRate, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // missing sample rate
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ILLEGAL_SAMPLE_RATE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // illegal sample rate
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioEnc_));
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), OPUS_SAMPLE_RATE);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // normal sample rate
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, opusCheckChannelLayout, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), OPUS_SAMPLE_RATE);
|
||||
OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE);
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // channel mismatch channel_layout
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioEncoderBufferCapiUnitTest, opusGetOutputDescription_01, TestSize.Level1)
|
||||
{
|
||||
if (!CheckSoFunc()) {
|
||||
return;
|
||||
}
|
||||
CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS);
|
||||
format = OH_AVFormat_Create();
|
||||
EXPECT_NE(nullptr, format);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
|
||||
AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), OPUS_SAMPLE_RATE);
|
||||
OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format)); // channel mismatch channel_layout
|
||||
|
||||
EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioEnc_));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
}
|
||||
}
|
@ -84,11 +84,11 @@ ohos_static_library("av_codec_capi_unit_test") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
@ -161,11 +161,11 @@ ohos_source_set("av_codec_inner_unit_test") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include <memory>
|
||||
#include "surface.h"
|
||||
#include "wm/window.h" // foundation/window/window_manager/interfaces/innerkits/
|
||||
#include "native_avbuffer.h" // foundation/multimedia/histreamer/interface/kits/c
|
||||
#include "buffer/avbuffer.h" // foundation/multimedia/histreamer/interface/inner_api
|
||||
#include "native_avbuffer.h" // foundation/multimedia/media_foundation/interface/kits/c
|
||||
#include "buffer/avbuffer.h" // foundation/multimedia/media_foundation/interface/inner_api
|
||||
#include "native_avcodec_base.h" // foundation/multimedia/av_codec/interfaces/kits/c/
|
||||
#include "command_parser.h"
|
||||
#include "start_code_detector.h"
|
||||
|
@ -82,8 +82,8 @@ ohos_unittest("hcodec_list_unit_test") {
|
||||
"graphic_2d:surface",
|
||||
"hdf_core:libhdi",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
}
|
||||
|
||||
@ -101,8 +101,8 @@ ohos_unittest("hencoder_buffer_unit_test") {
|
||||
"graphic_2d:surface",
|
||||
"graphic_2d:sync_fence",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"init:libbegetutil",
|
||||
"media_foundation:media_foundation",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
|
@ -133,6 +133,7 @@
|
||||
<option name="shell" value="mkdir -p /data/test/media"/>
|
||||
<option name="push" value="audio_res/aac_2c_44100hz_199k.pcm -> /data/test/media" src="res"/>
|
||||
<option name="push" value="audio_res/flac_2c_44100hz_261k.pcm -> /data/test/media" src="res"/>
|
||||
<option name="push" value="audio_res/g711mu_8kHz_10s.pcm -> /data/test/media" src="res"/>
|
||||
<option name="shell" value="restorecon /data/test/media"/>
|
||||
</preparer>
|
||||
</target>
|
||||
@ -141,6 +142,7 @@
|
||||
<option name="shell" value="mkdir -p /data/test/media"/>
|
||||
<option name="push" value="audio_res/aac_2c_44100hz_199k.pcm -> /data/test/media" src="res"/>
|
||||
<option name="push" value="audio_res/flac_2c_44100hz_261k.pcm -> /data/test/media" src="res"/>
|
||||
<option name="push" value="audio_res/g711mu_8kHz_10s.pcm -> /data/test/media" src="res"/>
|
||||
<option name="shell" value="restorecon /data/test/media"/>
|
||||
</preparer>
|
||||
</target>
|
||||
|
@ -70,9 +70,9 @@ ohos_source_set("video_sample") {
|
||||
"c_utils:utils",
|
||||
"graphic_2d:surface",
|
||||
"hilog:libhilog",
|
||||
"media_foundation:media_foundation",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
|
Loading…
x
Reference in New Issue
Block a user