From 5b4369558851f422b8f1bb13e3fbeb0e6b183572 Mon Sep 17 00:00:00 2001 From: sulav Date: Mon, 26 Jul 2021 10:16:32 +0530 Subject: [PATCH] Remove obsolete phase-1 code Signed-off-by: sulav --- .../audiocapturer/include/audio_encoder.h | 109 ------- .../audiocapturer/include/audio_source.h | 117 -------- .../audiocapturer/src/audio_capturer.cpp | 80 ----- .../audiocapturer/src/audio_capturer_impl.cpp | 209 ------------- .../audiocapturer/src/audio_encoder.cpp | 275 ------------------ .../audiocapturer/src/audio_source.cpp | 216 -------------- ohos.build | 10 - 7 files changed, 1016 deletions(-) delete mode 100755 frameworks/innerkitsimpl/audiocapturer/include/audio_encoder.h delete mode 100755 frameworks/innerkitsimpl/audiocapturer/include/audio_source.h delete mode 100755 frameworks/innerkitsimpl/audiocapturer/src/audio_capturer.cpp delete mode 100755 frameworks/innerkitsimpl/audiocapturer/src/audio_capturer_impl.cpp delete mode 100755 frameworks/innerkitsimpl/audiocapturer/src/audio_encoder.cpp delete mode 100755 frameworks/innerkitsimpl/audiocapturer/src/audio_source.cpp diff --git a/frameworks/innerkitsimpl/audiocapturer/include/audio_encoder.h b/frameworks/innerkitsimpl/audiocapturer/include/audio_encoder.h deleted file mode 100755 index 4c0a2b832e..0000000000 --- a/frameworks/innerkitsimpl/audiocapturer/include/audio_encoder.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_ENCODER_H -#define AUDIO_ENCODER_H - -#include -#include -#include -#include -#include -#include "audio_errors.h" -#include "media_info.h" -#include "format.h" -#include "codec_interface.h" -namespace OHOS { -namespace Audio { -constexpr int32_t AUDIO_ENC_PARAM_NUM = 8; -/* count of audio frame in Buffer */ -constexpr uint32_t AUDIO_FRAME_NUM_IN_BUF = 30; - -/* sample per frame for all encoder(aacplus:1024) */ -constexpr uint32_t AUDIO_POINT_NUM = 1024; - -struct AudioEncodeConfig { - AudioCodecFormat audioFormat; - uint32_t bitRate = 0; - uint32_t sampleRate = 0; - uint32_t channelCount = 0; - AudioBitWidth bitWidth = BIT_WIDTH_16; -}; - -struct AudioStream { - uint8_t *buffer = nullptr; /* the virtual address of stream */ - uint32_t bufferLen = 0; /* stream length, by bytes */ - int64_t timeStamp = 0; -}; - -class AudioEncoder { -public: - AudioEncoder(); - virtual ~AudioEncoder(); - - /** - * Init audio encoder with AudioEncodeConfig. - */ - int32_t Initialize(const AudioEncodeConfig &input); - - /** - * Binds the source deviceId. - */ - int32_t BindSource(uint32_t deviceId); - - /** - * Obtains whether the current encoding is muted. - */ - int32_t GetMute(bool &muted); - - /** - * Sets whether the current encoding is muted. - */ - int32_t SetMute(bool muted); - - /** - * Start the audio encoder. - */ - int32_t Start(); - - /** - * Reads the source data and returns the actual read size. - */ - int32_t ReadStream(AudioStream &stream, bool isBlockingRead); - - /** - * Stop the audio encoder. - */ - int32_t Stop(); - -private: - int32_t InitAudioEncoderAttr(const AudioEncodeConfig &input); - -private: - CODEC_HANDLETYPE encHandle_; - CodecType domainKind_ = AUDIO_ENCODER; - AvCodecMime codecMime_ = MEDIA_MIMETYPE_AUDIO_AAC; - Profile profile_ = INVALID_PROFILE; - AudioSampleRate sampleRate_ = AUD_SAMPLE_RATE_INVALID; - uint32_t bitRate_ = 0; - AudioSoundMode soundMode_ = AUD_SOUND_MODE_INVALID; - uint32_t ptNumPerFrm_ = AUDIO_POINT_NUM; - uint32_t bufSize_ = AUDIO_FRAME_NUM_IN_BUF; - Param encAttr_[AUDIO_ENC_PARAM_NUM]; - bool started_; -}; -} // namespace Audio -} // namespace OHOS -#endif // AUDIO_ENCODER_H diff --git a/frameworks/innerkitsimpl/audiocapturer/include/audio_source.h b/frameworks/innerkitsimpl/audiocapturer/include/audio_source.h deleted file mode 100755 index a540a0542b..0000000000 --- a/frameworks/innerkitsimpl/audiocapturer/include/audio_source.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_SOURCE_H -#define AUDIO_SOURCE_H - -#include -#include -#include -#include -#include - -#include "audio_errors.h" -#include "media_info.h" -#include "format.h" -#include "audio_manager.h" - -namespace OHOS { -namespace Audio { -struct AudioSourceConfig { - /** - * Select the device to be used for setting the current audio source based on the device enumerated by - * EnumDeviceBySourceType. - */ - uint32_t deviceId; - AudioCodecFormat audioFormat; - int32_t sampleRate = 0; - int32_t channelCount = 0; - bool interleaved; - AudioBitWidth bitWidth = BIT_WIDTH_16; - AudioStreamType streamUsage; -}; - -class AudioSource { -public: - AudioSource(); - virtual ~AudioSource(); - - /** - * Enumerates supported devices based on the input source type, including device names and device IDs. - */ - int32_t EnumDeviceBySourceType(AudioSourceType inputSource, std::vector &devices); - - /** - * Obtains the minimum frame count (in BytesPerSample) required in the specified conditions. - * - * @param sampleRate Indicates the sampling rate (Hz). - * @param channelCount Indicates the audio channel count. - * @param audioFormat Indicates the audio data format. - * @param frameCount the minimum frame count (in BytesPerSample). - * @return Returns {@code true} if success; returns {@code false} otherwise. - */ - static bool GetMinFrameCount(int32_t sampleRate, int32_t channelCount, - AudioCodecFormat audioFormat, size_t &frameCount); - - /** - * Obtains the frame count (in BytesPerSample) required in the current conditions. - * - * @return Returns the frame count (in BytesPerSample); returns {@code -1} if an exception occurs. - */ - uint64_t GetFrameCount(); - - /** - * Initializes the current source based on AudioSourceConfig. - */ - int32_t Initialize(const AudioSourceConfig &input); - - /** - * Set the input device ID, which is used when a device needs to be switched. - */ - int32_t SetInputDevice(uint32_t deviceId); - - /** - * Obtains the current device ID. - */ - int32_t GetCurrentDeviceId(uint32_t &deviceId); - - /** - * Start the source. - */ - int32_t Start(); - - /** - * Reads the source data and returns the actual read size. - */ - int32_t ReadFrame(uint8_t &buffer, size_t bufferBytes, bool isBlockingRead); - - /** - * Stop the source. - */ - int32_t Stop(); - -private: - int32_t InitCheck(); - -private: - bool initialized_; - bool started_; - AudioAdapter *audioAdapter_; - AudioCapture *audioCapture_; - AudioPort capturePort_ = {}; -}; -} // namespace Audio -} // namespace OHOS -#endif // AUDIO_SOURCE_H diff --git a/frameworks/innerkitsimpl/audiocapturer/src/audio_capturer.cpp b/frameworks/innerkitsimpl/audiocapturer/src/audio_capturer.cpp deleted file mode 100755 index fd34fad199..0000000000 --- a/frameworks/innerkitsimpl/audiocapturer/src/audio_capturer.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_capturer.h" -#include "audio_capturer_impl.h" - -namespace OHOS { -namespace Audio { -AudioCapturer::AudioCapturer() : impl_(new(std::nothrow) AudioCapturerImpl()) -{ -} - -AudioCapturer::~AudioCapturer() -{ -} - -bool AudioCapturer::GetMinFrameCount(int32_t sampleRate, int32_t channelCount, - AudioCodecFormat audioFormat, size_t &frameCount) -{ - return AudioCapturerImpl::GetMinFrameCount(sampleRate, channelCount, audioFormat, frameCount); -} - -uint64_t AudioCapturer::GetFrameCount() -{ - return impl_->GetFrameCount(); -} - -State AudioCapturer::GetStatus() -{ - return impl_->GetStatus(); -} - -bool AudioCapturer::GetAudioTime(Timestamp ×tamp, Timestamp::Timebase base) -{ - return impl_->GetTimestamp(timestamp, base); -} - -int32_t AudioCapturer::SetCapturerInfo(const AudioCapturerInfo info) -{ - return impl_->SetCapturerInfo(info); -} - -int32_t AudioCapturer::GetCapturerInfo(AudioCapturerInfo &info) -{ - return impl_->GetCapturerInfo(info); -} - -bool AudioCapturer::Start() -{ - return impl_->Record(); -} - -bool AudioCapturer::Stop() -{ - return impl_->Stop(); -} - -bool AudioCapturer::Release() -{ - return impl_->Release(); -} - -int32_t AudioCapturer::Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) -{ - return impl_->Read(buffer, userSize, isBlockingRead); -} -} // namespace Audio -} // namespace OHOS diff --git a/frameworks/innerkitsimpl/audiocapturer/src/audio_capturer_impl.cpp b/frameworks/innerkitsimpl/audiocapturer/src/audio_capturer_impl.cpp deleted file mode 100755 index 7035b166b9..0000000000 --- a/frameworks/innerkitsimpl/audiocapturer/src/audio_capturer_impl.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_capturer_impl.h" -#include "audio_encoder.h" -#include "audio_source.h" -#include "media_log.h" - -#include - -namespace OHOS { -namespace Audio { -using namespace OHOS::Media; -using namespace OHOS::AudioStandard; - -const unsigned long long TIME_CONVERSION_US_S = 1000000ULL; /* us to s */ -const unsigned long long TIME_CONVERSION_NS_US = 1000ULL; /* ns to us */ - - -AudioCapturer::AudioCapturerImpl::AudioCapturerImpl() : audioSource_(new(std::nothrow) AudioSource()), - audioEncoder_(new(std::nothrow) AudioEncoder()) -{ - MEDIA_DEBUG_LOG("ctor"); -} - -AudioCapturer::AudioCapturerImpl::~AudioCapturerImpl() -{ - Release(); -} - -bool AudioCapturer::AudioCapturerImpl::GetMinFrameCount(int32_t sampleRate, int32_t channelCount, - AudioCodecFormat audioFormat, size_t &frameCount) -{ - return AudioSource::GetMinFrameCount(sampleRate, channelCount, audioFormat, frameCount); -} - -uint64_t AudioCapturer::AudioCapturerImpl::GetFrameCount() -{ - return audioSource_->GetFrameCount(); -} - -State AudioCapturer::AudioCapturer::AudioCapturerImpl::GetStatus() -{ - return status; -} - -bool AudioCapturer::AudioCapturerImpl::GetTimestamp(Timestamp ×tamp, Timestamp::Timebase base) -{ - timestamp = timestamp_; - return true; -} - -int32_t AudioCapturer::AudioCapturerImpl::SetCapturerInfo(const AudioCapturerInfo info) -{ - int32_t ret = SUCCESS; - std::vector devices; - ret = audioSource_->EnumDeviceBySourceType(info.inputSource, devices); - if (ret != SUCCESS || devices.empty()) { - MEDIA_ERR_LOG("EnumDeviceBySourceType failed inputSource:%d", info.inputSource); - return ret; - } - MEDIA_INFO_LOG("info.sampleRate %d", info.sampleRate); - AudioSourceConfig sourceConfig; - sourceConfig.deviceId = devices[0].deviceId; // use the first device as default - sourceConfig.audioFormat = info.audioFormat; - sourceConfig.sampleRate = info.sampleRate; - sourceConfig.channelCount = info.channelCount; - sourceConfig.interleaved = false; - sourceConfig.bitWidth = info.bitWidth; - sourceConfig.streamUsage = TYPE_DEFAULT; - ret = audioSource_->Initialize(sourceConfig); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("Initialize failed inputSource:%d", info.inputSource); - return ret; - } - AudioEncodeConfig encodeConfig; - encodeConfig.audioFormat = info.audioFormat; - encodeConfig.bitRate = info.bitRate; - encodeConfig.sampleRate = info.sampleRate; - encodeConfig.channelCount = info.channelCount; - encodeConfig.bitWidth = info.bitWidth; - MEDIA_INFO_LOG("audioEncoder_ info.bitRate %d ", info.bitRate); - ret = audioEncoder_->Initialize(encodeConfig); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("Initialize failed inputSource:%d", info.inputSource); - return ret; - } - info_ = info; - status = PREPPARED; - MEDIA_INFO_LOG("Set Capturer Info SUCCESS"); - return SUCCESS; -} - - -int32_t AudioCapturer::AudioCapturerImpl::GetCapturerInfo(AudioCapturerInfo &info) -{ - info = info_; - return SUCCESS; -} - -bool AudioCapturer::AudioCapturerImpl::Record() -{ - if (status != PREPPARED && - status != STOPPED) { - MEDIA_ERR_LOG("Record ILLEGAL_STATE status:%u", status); - return ERR_ILLEGAL_STATE; - } - int32_t ret = audioSource_->Start(); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("audioSource_ Start failed:0x%x", ret); - return false; - } - uint32_t deviceId = 0; - ret = audioSource_->GetCurrentDeviceId(deviceId); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("audioSource_ GetCurrentDevice failed:0x%x", ret); - return false; - } - inputDeviceId_ = deviceId; - ret = audioEncoder_->BindSource(deviceId); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("audioEncoder_ BindSource failed:0x%x", ret); - return false; - } - ret = audioEncoder_->Start(); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("audioEncoder_ Start failed:0x%x", ret); - return false; - } - status = RECORDING; - MEDIA_INFO_LOG("Start Audio Capturer SUCCESS"); - return true; -} - -int32_t AudioCapturer::AudioCapturerImpl::Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) -{ - if (userSize == 0) { - MEDIA_ERR_LOG("Invalid userSize:%zu", userSize); - return ERR_INVALID_READ; - } - if (status != RECORDING) { - MEDIA_ERR_LOG("ILLEGAL_STATE status:%u", status); - return ERR_INVALID_READ; - } - AudioStream stream; - stream.buffer = &buffer; - stream.bufferLen = userSize; - int32_t readLen = audioEncoder_->ReadStream(stream, isBlockingRead); - if (readLen == ERR_INVALID_READ) { - MEDIA_ERR_LOG("audioEncoder_ ReadStream fail,ret:0x%x", readLen); - return ERR_INVALID_READ; - } - timestamp_.time.tv_sec = static_cast(stream.timeStamp / TIME_CONVERSION_US_S); // us - s - timestamp_.time.tv_nsec = static_cast((stream.timeStamp - timestamp_.time.tv_sec * TIME_CONVERSION_US_S) * - TIME_CONVERSION_NS_US); - return readLen; -} - -bool AudioCapturer::AudioCapturerImpl::Stop() -{ - if (status != RECORDING) { - MEDIA_ERR_LOG("ILLEGAL_STATE status:%u", status); - return ERR_ILLEGAL_STATE; - } - MEDIA_INFO_LOG("audioEncoder Stop"); - int32_t ret = audioEncoder_->Stop(); - if (ret != SUCCESS) { - MEDIA_DEBUG_LOG("audioEncoder_ stop fail,ret:0x%x", ret); - return false; - } - MEDIA_INFO_LOG("audioSource Stop"); - ret = audioSource_->Stop(); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("audioSource_ stop fail,ret:0x%x", ret); - return false; - } - MEDIA_INFO_LOG("Stop Audio Capturer SUCCESS"); - status = STOPPED; - return true; -} - -bool AudioCapturer::AudioCapturerImpl::Release() -{ - if (status == RELEASED) { - MEDIA_ERR_LOG("illegal state: status = %u", status); - return false; - } - if (status == RECORDING && Stop()) { - MEDIA_ERR_LOG("Stop failed: %u", status); - return false; - } - status = RELEASED; - MEDIA_INFO_LOG("Release Audio Capturer SUCCESS"); - return true; -} -} // namespace Audio -} // namespace OHOS diff --git a/frameworks/innerkitsimpl/audiocapturer/src/audio_encoder.cpp b/frameworks/innerkitsimpl/audiocapturer/src/audio_encoder.cpp deleted file mode 100755 index fa9fed58ed..0000000000 --- a/frameworks/innerkitsimpl/audiocapturer/src/audio_encoder.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_encoder.h" -#include "media_log.h" -#include "securec.h" - -namespace OHOS { -namespace Audio { -using namespace OHOS::Media; -using namespace OHOS::AudioStandard; - -constexpr uint32_t AUDIO_READ_STREAM_TIME_OUT_MS = 1000; /* 1S */ - -constexpr uint32_t AUDIO_CHANNEL_MONO = 1; -constexpr uint32_t AUDIO_CHANNEL_STEREO = 2; - -AudioEncoder::AudioEncoder() - : encHandle_(nullptr), - started_(false) -{ - for (int i = 0; i < AUDIO_ENC_PARAM_NUM; i++) { - encAttr_[i] = {}; - } - CodecInit(); - MEDIA_INFO_LOG("AudioEncoder ctor"); -} - -AudioEncoder::~AudioEncoder() -{ - if (encHandle_ != nullptr) { - CodecDestroy(encHandle_); - encHandle_ = nullptr; - } - CodecDeinit(); - MEDIA_INFO_LOG("AudioEncoder dtor"); -} - -static bool IsAudioCodecFormatSupported(AudioCodecFormat format) -{ - if ((format < AAC_LC) || (format > AAC_ELD)) { - MEDIA_ERR_LOG("Invalid format: 0x%x", format); - return false; - } - return true; -} - -static Profile GetProfileFromAudioCodecFormat(AudioCodecFormat format) -{ - switch (format) { - case AAC_LC: - return AAC_LC_PROFILE; - case AAC_HE_V1: - return AAC_HE_V1_PROFILE; - case AAC_HE_V2: - return AAC_HE_V2_PROFILE; - case AAC_LD: - return AAC_LD_PROFILE; - case AAC_ELD: - return AAC_ELD_PROFILE; - default: - MEDIA_ERR_LOG("Invalid format: 0x%x", format); - return AAC_LC_PROFILE; - } -} - -static AudioSampleRate ConvertSampleRate(uint32_t sampleRate) -{ - switch (sampleRate) { - case AUD_SAMPLE_RATE_8000: - return AUD_SAMPLE_RATE_8000; - case AUD_SAMPLE_RATE_11025: - return AUD_SAMPLE_RATE_11025; - case AUD_SAMPLE_RATE_12000: - return AUD_SAMPLE_RATE_12000; - case AUD_SAMPLE_RATE_16000: - return AUD_SAMPLE_RATE_16000; - case AUD_SAMPLE_RATE_22050: - return AUD_SAMPLE_RATE_22050; - case AUD_SAMPLE_RATE_24000: - return AUD_SAMPLE_RATE_24000; - case AUD_SAMPLE_RATE_32000: - return AUD_SAMPLE_RATE_24000; - case AUD_SAMPLE_RATE_44100: - return AUD_SAMPLE_RATE_44100; - case AUD_SAMPLE_RATE_48000: - return AUD_SAMPLE_RATE_48000; - case AUD_SAMPLE_RATE_64000: - return AUD_SAMPLE_RATE_64000; - case AUD_SAMPLE_RATE_96000: - return AUD_SAMPLE_RATE_96000; - default: - MEDIA_ERR_LOG("Invalid sample_rate: %u", sampleRate); - return AUD_SAMPLE_RATE_48000; - } -} - -static AudioSoundMode ConvertSoundMode(uint32_t channelCount) -{ - switch (channelCount) { - case AUDIO_CHANNEL_MONO: - return AUD_SOUND_MODE_MONO; - case AUDIO_CHANNEL_STEREO: - return AUD_SOUND_MODE_STEREO; - default: - MEDIA_ERR_LOG("Invalid soundMode: %u", channelCount); - return AUD_SOUND_MODE_MONO; - } -} - -int32_t AudioEncoder::InitAudioEncoderAttr(const AudioEncodeConfig &input) -{ - if (!IsAudioCodecFormatSupported(input.audioFormat)) { - MEDIA_ERR_LOG("input.audioFormat :0x%x is not supported", input.audioFormat); - return ERR_INVALID_PARAM; - } - - uint32_t paramIndex = 0; - domainKind_ = AUDIO_ENCODER; - encAttr_[paramIndex].key = KEY_CODEC_TYPE; - encAttr_[paramIndex].val = &domainKind_; - encAttr_[paramIndex].size = sizeof(CodecType); - paramIndex++; - codecMime_ = MEDIA_MIMETYPE_AUDIO_AAC; - encAttr_[paramIndex].key = KEY_MIMETYPE; - encAttr_[paramIndex].val = &codecMime_; - encAttr_[paramIndex].size = sizeof(AvCodecMime); - paramIndex++; - profile_ = GetProfileFromAudioCodecFormat(input.audioFormat); - encAttr_[paramIndex].key = KEY_AUDIO_PROFILE; - encAttr_[paramIndex].val = &profile_; - encAttr_[paramIndex].size = sizeof(Profile); - paramIndex++; - sampleRate_ = ConvertSampleRate(input.sampleRate); - encAttr_[paramIndex].key = KEY_SAMPLE_RATE; - encAttr_[paramIndex].val = &sampleRate_; - encAttr_[paramIndex].size = sizeof(AudioSampleRate); - paramIndex++; - bitRate_ = input.bitRate; - encAttr_[paramIndex].key = KEY_BITRATE; - encAttr_[paramIndex].val = &bitRate_; - encAttr_[paramIndex].size = sizeof(uint32_t); - paramIndex++; - soundMode_ = ConvertSoundMode(input.channelCount); - encAttr_[paramIndex].key = KEY_SOUND_MODE; - encAttr_[paramIndex].val = &soundMode_; - encAttr_[paramIndex].size = sizeof(AudioSoundMode); - paramIndex++; - ptNumPerFrm_ = AUDIO_POINT_NUM; - encAttr_[paramIndex].key = KEY_POINT_NUM_PER_FRAME; - encAttr_[paramIndex].val = &ptNumPerFrm_; - encAttr_[paramIndex].size = sizeof(uint32_t); - paramIndex++; - bufSize_ = AUDIO_FRAME_NUM_IN_BUF; - encAttr_[paramIndex].key = KEY_BUFFERSIZE; - encAttr_[paramIndex].val = &bufSize_; - encAttr_[paramIndex].size = sizeof(uint32_t); - return SUCCESS; -} - -int32_t AudioEncoder::Initialize(const AudioEncodeConfig &input) -{ - int32_t ret = InitAudioEncoderAttr(input); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("InitAudioEncoderAttr failed:%d", ret); - return ret; - } - const char *audioEncName = "codec.aac.hardware.encoder"; - ret = CodecCreate(audioEncName, encAttr_, AUDIO_ENC_PARAM_NUM, &encHandle_); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("CodecCreate failed :0x%x", ret); - return ret; - } - return SUCCESS; -} - -int32_t AudioEncoder::BindSource(uint32_t deviceId) -{ - int32_t ret = SUCCESS; - Param params[1]; // only deviceId needed. - (void) memset_s(params, sizeof(params), 0x00, sizeof(params)); - params[0].key = KEY_DEVICE_ID; - params[0].val = reinterpret_cast(&deviceId); - params[0].size = sizeof(uint32_t); - ret = CodecSetParameter(encHandle_, params, sizeof(params) / sizeof(params[0])); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("CodecSetParameter :0x%x", ret); - return ret; - } - return SUCCESS; -} - -int32_t AudioEncoder::GetMute(bool &muted) -{ - return ERR_UNKNOWN; -} - -int32_t AudioEncoder::SetMute(bool muted) -{ - return ERR_UNKNOWN; -} - -int32_t AudioEncoder::Start() -{ - int32_t ret = SUCCESS; - ret = CodecStart(encHandle_); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("CodecStart failed:0x%x", ret); - return ret; - } - started_ = true; - return ret; -} - -int32_t AudioEncoder::ReadStream(AudioStream &stream, bool isBlockingRead) -{ - if (!started_) { - MEDIA_ERR_LOG("Codec not Started"); - return ERR_INVALID_READ; - } - if (stream.buffer == nullptr || stream.bufferLen == 0) { - MEDIA_ERR_LOG("stream.buffer is nullptr"); - return ERR_INVALID_READ; - } - uint32_t timeoutMs; - if (isBlockingRead) { - timeoutMs = AUDIO_READ_STREAM_TIME_OUT_MS; - } else { - timeoutMs = 0; - } - OutputInfo outInfo; - CodecBufferInfo outBuf; - outInfo.bufferCnt = 1; // buffer count is 1. - outInfo.buffers = &outBuf; - int32_t ret = CodecDequeueOutput(encHandle_, timeoutMs, nullptr, &outInfo); - if ((ret != SUCCESS) && (outInfo.buffers[0].addr == nullptr)) { - MEDIA_ERR_LOG("CodecDequeueOutput failed:0x%x", ret); - return ERR_INVALID_READ; - } - int32_t readLen = 0; - errno_t retCopy = memcpy_s(stream.buffer, stream.bufferLen, outInfo.buffers[0].addr, - outInfo.buffers[0].length); - if (retCopy != EOK) { - MEDIA_ERR_LOG("memcpy_s timeStamp:%lld failed:0x%x", outInfo.timeStamp, retCopy); - return ERR_INVALID_OPERATION; - } else { - readLen = outInfo.buffers[0].length; - } - stream.timeStamp = outInfo.timeStamp; - (void)CodecQueueOutput(encHandle_, &outInfo, timeoutMs, -1); - return readLen; -} - -int32_t AudioEncoder::Stop() -{ - MEDIA_DEBUG_LOG("AudioEncoder::Stop"); - if (!started_) { - MEDIA_ERR_LOG("Codec not Started"); - } - return CodecStop(encHandle_); -} -} // namespace Audio -} // namespace OHOS diff --git a/frameworks/innerkitsimpl/audiocapturer/src/audio_source.cpp b/frameworks/innerkitsimpl/audiocapturer/src/audio_source.cpp deleted file mode 100755 index d17860fe8a..0000000000 --- a/frameworks/innerkitsimpl/audiocapturer/src/audio_source.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "audio_source.h" -#include "media_log.h" -#include "securec.h" - -namespace OHOS { -namespace Audio { -#define AUDIO_RETURN_VAL_IF_NULL(condition) \ - do { \ - if ((condition) == nullptr) { \ - return ERR_ILLEGAL_STATE; \ - } \ - } while (0) - -using namespace OHOS::Media; -using namespace OHOS::AudioStandard; -static AudioManager *g_audioManager = nullptr; -AudioSource::AudioSource() - : initialized_(false), - started_(false), - audioAdapter_(nullptr), - audioCapture_(nullptr) -{ - if (g_audioManager == nullptr) { - g_audioManager = GetAudioManagerFuncs(); - MEDIA_DEBUG_LOG("try to get g_audioManager."); - } - int size = 0; - struct AudioAdapterDescriptor *descs = nullptr; - g_audioManager->GetAllAdapters(g_audioManager, &descs, &size); - MEDIA_DEBUG_LOG("GetAllAdapters: %d ", size); - - for (int index = 0; index < size; index++) { - struct AudioAdapterDescriptor *desc = &descs[index]; - for (int port = 0; (desc != nullptr && port < static_cast(desc->portNum)); port++) { - if (desc->ports[port].dir == PORT_IN && - (g_audioManager->LoadAdapter(g_audioManager, desc, &audioAdapter_)) == 0) { - (void)audioAdapter_->InitAllPorts(audioAdapter_); - if (memcpy_s(&capturePort_, sizeof(struct AudioPort), - &desc->ports[port], sizeof(struct AudioPort)) != 0) { - MEDIA_WARNING_LOG("memcpy_s capturePort_ failed"); - } - break; - } - } - } - MEDIA_DEBUG_LOG("LoadAdapter audioAdapter_."); -} - -AudioSource::~AudioSource() -{ - MEDIA_DEBUG_LOG("Destroys the AudioSource"); - if (audioAdapter_ == nullptr) { - return; - } - if (g_audioManager != nullptr) { - g_audioManager->UnloadAdapter(g_audioManager, audioAdapter_); - } - audioAdapter_ = nullptr; -} - -int32_t AudioSource::InitCheck() -{ - if (!initialized_) { - MEDIA_ERR_LOG("not initialized"); - return ERR_ILLEGAL_STATE; - } - return SUCCESS; -} - -bool AudioSource::GetMinFrameCount(int32_t sampleRate, int32_t channelCount, - AudioCodecFormat audioFormat, size_t &frameCount) -{ - (void) sampleRate; - (void) channelCount; - (void) audioFormat; - frameCount = 0; - return true; -} - -uint64_t AudioSource::GetFrameCount() -{ - int32_t ret; - if ((ret = InitCheck()) != SUCCESS) { - return ret; - } - AUDIO_RETURN_VAL_IF_NULL(audioCapture_); - uint64_t frameCount = 0; - ret = audioCapture_->attr.GetFrameCount(reinterpret_cast(audioCapture_), &frameCount); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("attr GetFrameCount failed 0x%x ", ret); - return ret; - } - return frameCount; -} - -int32_t AudioSource::EnumDeviceBySourceType(AudioSourceType inputSource, std::vector &devices) -{ - if (inputSource != AUDIO_MIC) { - MEDIA_ERR_LOG("AudioSource only support AUDIO_MIC, actual inputSource(%d)", inputSource); - return ERR_INVALID_PARAM; - } - AUDIO_RETURN_VAL_IF_NULL(audioAdapter_); - - struct AudioPortCapability capability; - audioAdapter_->GetPortCapability(audioAdapter_, &capturePort_, &capability); - AudioDeviceDesc deviceDesc; - deviceDesc.deviceId = capability.deviceId; - deviceDesc.inputSourceType = AUDIO_MIC; - devices.push_back(deviceDesc); - return SUCCESS; -} - -int32_t AudioSource::Initialize(const AudioSourceConfig &input) -{ - AUDIO_RETURN_VAL_IF_NULL(audioAdapter_); - - MEDIA_INFO_LOG("input.sampleRate:%d", input.sampleRate); - int32_t ret = SUCCESS; - struct AudioDeviceDescriptor desc; - struct AudioSampleAttributes attrs; - attrs.type = AUDIO_IN_MEDIA; - attrs.sampleRate = input.sampleRate; - attrs.format = AUDIO_FORMAT_PCM_16_BIT; - attrs.channelCount = input.channelCount; - attrs.interleaved = input.interleaved; - ret = audioAdapter_->CreateCapture(audioAdapter_, &desc, &attrs, &audioCapture_); - if ((ret != SUCCESS) || (audioCapture_ == nullptr)) { - MEDIA_ERR_LOG("CreateCapture failed 0x%x", ret); - return ret; - } - initialized_ = true; - return SUCCESS; -} - -int32_t AudioSource::SetInputDevice(uint32_t deviceId) -{ - return SUCCESS; -} - -int32_t AudioSource::GetCurrentDeviceId(uint32_t &deviceId) -{ - AUDIO_RETURN_VAL_IF_NULL(audioCapture_); - int32_t ret = audioCapture_->attr.GetCurrentChannelId(reinterpret_cast(audioCapture_), &deviceId); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("GetCurrentChannelId failed 0x%x", ret); - return ret; - } - return SUCCESS; -} - -int32_t AudioSource::Start() -{ - int32_t ret; - if ((ret = InitCheck()) != SUCCESS) { - return ret; - } - - AUDIO_RETURN_VAL_IF_NULL(audioCapture_); - ret = audioCapture_->control.Start(reinterpret_cast(audioCapture_)); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("audioCapture_ Start failed 0x%x", ret); - return ret; - } - started_ = true; - return SUCCESS; -} - -int32_t AudioSource::ReadFrame(uint8_t &buffer, size_t bufferBytes, bool isBlockingRead) -{ - if (!started_) { - MEDIA_ERR_LOG("AudioSource not Started"); - return ERR_ILLEGAL_STATE; - } - return SUCCESS; -} - -int32_t AudioSource::Stop() -{ - MEDIA_INFO_LOG("AudioSource::Stop"); - int32_t ret; - if ((ret = InitCheck()) != SUCCESS) { - return ret; - } - - AUDIO_RETURN_VAL_IF_NULL(audioCapture_); - ret = audioCapture_->control.Stop(reinterpret_cast(audioCapture_)); - if (ret != SUCCESS) { - MEDIA_ERR_LOG("Stop failed 0x%x", ret); - return ret; - } - ret = audioAdapter_->DestroyCapture(audioAdapter_, audioCapture_); - audioCapture_ = nullptr; - started_ = false; - if (ret != SUCCESS) { - MEDIA_ERR_LOG("Close failed 0x%x", ret); - return ret; - } - return SUCCESS; -} -} // namespace Audio -} // namespace OHOS diff --git a/ohos.build b/ohos.build index 92ca3e932e..ef7592df6f 100644 --- a/ohos.build +++ b/ohos.build @@ -40,16 +40,6 @@ ] } }, - { - "type": "none", - "name": "//foundation/multimedia/audio_standard/interfaces/innerkits/native/audiocapturer:audio_capturer", - "header": { - "header_files": [ - "audio_capturer.h" - ], - "header_base": "//foundation/multimedia/audio_standard/interfaces/innerkits/native/audiocapturer/include" - } - }, { "type": "none", "name": "//foundation/multimedia/audio_standard/interfaces/innerkits/native/audiorecorder:audio_recorder", -- Gitee