diff --git a/engine/include/pipeline/filters/source/audio_capture/audio_capture_filter.h b/engine/include/pipeline/filters/source/audio_capture/audio_capture_filter.h index d38dbd9ecae1102bb910e42b76b0e9d4385bf861..772e3ac669decd4830c69710a9f75d0cbd5a5513 100644 --- a/engine/include/pipeline/filters/source/audio_capture/audio_capture_filter.h +++ b/engine/include/pipeline/filters/source/audio_capture/audio_capture_filter.h @@ -50,7 +50,13 @@ public: ErrorCode SendEos(); private: void InitPorts() override; + + ErrorCode ConfigureAudioSampleRate(const std::shared_ptr& audioMeta); + ErrorCode ConfigureAudioChannels(const std::shared_ptr& audioMeta); + ErrorCode ConfigureAudioBitRate(const std::shared_ptr& audioMeta); + ErrorCode ConfigureSampleFormat(const std::shared_ptr& audioMeta); ErrorCode InitAndConfigWithMeta(const std::shared_ptr& audioMeta); + void ReadLoop(); ErrorCode CreatePlugin(const std::shared_ptr& info, const std::string& name, Plugin::PluginManager& manager); diff --git a/engine/pipeline/filters/source/audio_capture/audio_capture_filter.cpp b/engine/pipeline/filters/source/audio_capture/audio_capture_filter.cpp index cc3950ad778c86f21af1415cbc3369bb8ce1975b..840c68727d5d89bf8450edcf0caba147389bda92 100644 --- a/engine/pipeline/filters/source/audio_capture/audio_capture_filter.cpp +++ b/engine/pipeline/filters/source/audio_capture/audio_capture_filter.cpp @@ -76,39 +76,74 @@ void AudioCaptureFilter::SetAppInfoParams() } } -ErrorCode AudioCaptureFilter::InitAndConfigWithMeta(const std::shared_ptr& audioMeta) +ErrorCode AudioCaptureFilter::ConfigureAudioSampleRate(const std::shared_ptr& audioMeta) +{ + uint32_t sampleRate = 0; + ErrorCode errorCode = ErrorCode::SUCCESS; + if (audioMeta->Get(sampleRate)) { + MEDIA_LOG_I("configure plugin with sample rate " PUBLIC_LOG_U32, sampleRate); + bufferCalibration_->SetParam(Tag::AUDIO_SAMPLE_RATE, sampleRate); + errorCode = TranslatePluginStatus(plugin_->SetParameter(Tag::AUDIO_SAMPLE_RATE, sampleRate)); + } + return errorCode; +} + +ErrorCode AudioCaptureFilter::ConfigureAudioChannels(const std::shared_ptr &audioMeta) +{ + uint32_t channels = 0; + ErrorCode errorCode = ErrorCode::SUCCESS; + if (audioMeta->Get(channels)) { + MEDIA_LOG_I("configure plugin with channel " PUBLIC_LOG_U32, channels); + bufferCalibration_->SetParam(Tag::AUDIO_CHANNELS, channels); + errorCode = TranslatePluginStatus(plugin_->SetParameter(Tag::AUDIO_CHANNELS, channelNum_)); + } + return errorCode; +} + +ErrorCode AudioCaptureFilter::ConfigureAudioBitRate(const std::shared_ptr &audioMeta) { - MEDIA_LOG_D("IN"); - SetAppInfoParams(); - ErrorCode err = TranslatePluginStatus(plugin_->Init()); - FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); - plugin_->SetCallback(this); - pluginAllocator_ = plugin_->GetAllocator(); - uint32_t tmp = 0; - if (audioMeta->Get(tmp)) { - MEDIA_LOG_I("configure plugin with sample rate " PUBLIC_LOG_U32, tmp); - bufferCalibration_->SetParam(Tag::AUDIO_SAMPLE_RATE, tmp); - err = TranslatePluginStatus(plugin_->SetParameter(Tag::AUDIO_SAMPLE_RATE, tmp)); - FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); - } - if (audioMeta->Get(tmp)) { - MEDIA_LOG_I("configure plugin with channel " PUBLIC_LOG_U32, tmp); - bufferCalibration_->SetParam(Tag::AUDIO_CHANNELS, tmp); - err = TranslatePluginStatus(plugin_->SetParameter(Tag::AUDIO_CHANNELS, channelNum_)); - FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); - } int64_t bitRate = 0; + ErrorCode errorCode = ErrorCode::SUCCESS; if (audioMeta->Get(bitRate)) { MEDIA_LOG_I("configure plugin with bitrate " PUBLIC_LOG_D64, bitRate); - err = TranslatePluginStatus(plugin_->SetParameter(Tag::MEDIA_BITRATE, bitRate)); - FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); + errorCode = TranslatePluginStatus(plugin_->SetParameter(Tag::MEDIA_BITRATE, bitRate)); } + return errorCode; +} + +ErrorCode AudioCaptureFilter::ConfigureSampleFormat(const std::shared_ptr &audioMeta) +{ Plugin::AudioSampleFormat sampleFormat = Plugin::AudioSampleFormat::S16; + ErrorCode errorCode = ErrorCode::SUCCESS; if (audioMeta->Get(sampleFormat)) { bufferCalibration_->SetParam(Tag::AUDIO_SAMPLE_FORMAT, sampleFormat); MEDIA_LOG_I("configure plugin with sampleFormat " PUBLIC_LOG_S, Plugin::GetAudSampleFmtNameStr(sampleFormat)); - return TranslatePluginStatus(plugin_->SetParameter(Tag::AUDIO_SAMPLE_FORMAT, sampleFormat)); + errorCode = TranslatePluginStatus(plugin_->SetParameter(Tag::AUDIO_SAMPLE_FORMAT, sampleFormat)); } + return errorCode; +} + +ErrorCode AudioCaptureFilter::InitAndConfigWithMeta(const std::shared_ptr& audioMeta) +{ + MEDIA_LOG_D("IN"); + SetAppInfoParams(); + ErrorCode err = TranslatePluginStatus(plugin_->Init()); + FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); + plugin_->SetCallback(this); + pluginAllocator_ = plugin_->GetAllocator(); + + err = ConfigureAudioSampleRate(audioMeta); + FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); + + err = ConfigureAudioChannels(audioMeta); + FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); + + err = ConfigureAudioBitRate(audioMeta); + FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); + + err = ConfigureSampleFormat(audioMeta); + FALSE_RETURN_V(err == ErrorCode::SUCCESS, err); + return ErrorCode::SUCCESS; } @@ -530,6 +565,7 @@ void AudioCaptureFilter::SendBuffer(const std::shared_ptr& buffer) outPorts_[0]->PushData(buffer, -1); } } + } // namespace Pipeline } // namespace Media } // namespace OHOS