提交 9a9d0935 编写于 作者: O openharmony_ci 提交者: Gitee

!15 支持PCM/G711/G726编解码格式音频采集

Merge pull request !15 from starfish/master
...@@ -175,17 +175,25 @@ typedef enum { ...@@ -175,17 +175,25 @@ typedef enum {
*/ */
typedef enum { typedef enum {
/** Default format */ /** Default format */
AUDIO_DEFAULT = 0, AUDIO_DEFAULT = 0,
/** PCM */
PCM = 1,
/** Advanced Audio Coding Low Complexity (AAC-LC) */ /** Advanced Audio Coding Low Complexity (AAC-LC) */
AAC_LC = 1, AAC_LC = 2,
/** High-Efficiency Advanced Audio Coding (AAC-HE), previously known as AAC+ or aacPlus v1 */ /** High-Efficiency Advanced Audio Coding (AAC-HE), previously known as AAC+ or aacPlus v1 */
AAC_HE_V1 = 2, AAC_HE_V1 = 3,
/** AAC++ or aacPlus v2 */ /** AAC++ or aacPlus v2 */
AAC_HE_V2 = 3, AAC_HE_V2 = 4,
/** Advanced Audio Coding Low Delay (AAC-LD) */ /** Advanced Audio Coding Low Delay (AAC-LD) */
AAC_LD = 4, AAC_LD = 5,
/** Advanced Audio Coding Enhanced Low Delay (AAC-ELD) */ /** Advanced Audio Coding Enhanced Low Delay (AAC-ELD) */
AAC_ELD = 5, AAC_ELD = 6,
/** G711 a-law*/
G711A = 7,
/** G711 u-law */
G711U = 8,
/** G726 */
G726 = 9,
/** Invalid value */ /** Invalid value */
FORMAT_BUTT, FORMAT_BUTT,
} AudioCodecFormat; } AudioCodecFormat;
...@@ -203,6 +211,8 @@ typedef enum { ...@@ -203,6 +211,8 @@ typedef enum {
BIT_WIDTH_16 = 16, BIT_WIDTH_16 = 16,
/** 24-bit width */ /** 24-bit width */
BIT_WIDTH_24 = 24, BIT_WIDTH_24 = 24,
/** 32-bit width */
BIT_WIDTH_32 = 32,
/** Invalid value */ /** Invalid value */
BIT_WIDTH_BUTT, BIT_WIDTH_BUTT,
} AudioBitWidth; } AudioBitWidth;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "format.h" #include "format.h"
#include <cstdio> #include <cstdio>
#include "media_log.h"
namespace OHOS { namespace OHOS {
namespace Media { namespace Media {
...@@ -81,7 +82,7 @@ FormatData::~FormatData() ...@@ -81,7 +82,7 @@ FormatData::~FormatData()
bool FormatData::SetValue(int32_t val) bool FormatData::SetValue(int32_t val)
{ {
if (type_ != FORMAT_TYPE_INT32) { if (type_ != FORMAT_TYPE_INT32) {
printf("FormatData set int32 value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData set int32 value error, current type is %u", type_);
return false; return false;
} }
val_.int32Val = val; val_.int32Val = val;
...@@ -91,7 +92,7 @@ bool FormatData::SetValue(int32_t val) ...@@ -91,7 +92,7 @@ bool FormatData::SetValue(int32_t val)
bool FormatData::SetValue(int64_t val) bool FormatData::SetValue(int64_t val)
{ {
if (type_ != FORMAT_TYPE_INT64) { if (type_ != FORMAT_TYPE_INT64) {
printf("FormatData set int64 value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData set int64 value error, current type is %u", type_);
return false; return false;
} }
val_.int64Val = val; val_.int64Val = val;
...@@ -101,7 +102,7 @@ bool FormatData::SetValue(int64_t val) ...@@ -101,7 +102,7 @@ bool FormatData::SetValue(int64_t val)
bool FormatData::SetValue(float val) bool FormatData::SetValue(float val)
{ {
if (type_ != FORMAT_TYPE_FLOAT) { if (type_ != FORMAT_TYPE_FLOAT) {
printf("FormatData set float value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData set float value error, current type is %u", type_);
return false; return false;
} }
val_.floatVal = val; val_.floatVal = val;
...@@ -111,7 +112,7 @@ bool FormatData::SetValue(float val) ...@@ -111,7 +112,7 @@ bool FormatData::SetValue(float val)
bool FormatData::SetValue(double val) bool FormatData::SetValue(double val)
{ {
if (type_ != FORMAT_TYPE_DOUBLE) { if (type_ != FORMAT_TYPE_DOUBLE) {
printf("FormatData set double value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData set double value error, current type is %u", type_);
return false; return false;
} }
val_.doubleVal = val; val_.doubleVal = val;
...@@ -121,13 +122,13 @@ bool FormatData::SetValue(double val) ...@@ -121,13 +122,13 @@ bool FormatData::SetValue(double val)
bool FormatData::SetValue(const std::string &val) bool FormatData::SetValue(const std::string &val)
{ {
if (type_ != FORMAT_TYPE_STRING) { if (type_ != FORMAT_TYPE_STRING) {
printf("FormatData set string value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData set string value error, current type is %u", type_);
return false; return false;
} }
val_.stringVal = new (std::nothrow) std::string(); val_.stringVal = new (std::nothrow) std::string();
if (val_.stringVal == nullptr) { if (val_.stringVal == nullptr) {
type_ = FORMAT_TYPE_NONE; type_ = FORMAT_TYPE_NONE;
printf("FormatData set string value error, new string failed"); MEDIA_ERR_LOG("FormatData set string value error, new string failed");
return false; return false;
} }
*(val_.stringVal) = val; *(val_.stringVal) = val;
...@@ -137,7 +138,7 @@ bool FormatData::SetValue(const std::string &val) ...@@ -137,7 +138,7 @@ bool FormatData::SetValue(const std::string &val)
bool FormatData::GetInt32Value(int32_t &val) const bool FormatData::GetInt32Value(int32_t &val) const
{ {
if (type_ != FORMAT_TYPE_INT32) { if (type_ != FORMAT_TYPE_INT32) {
printf("FormatData get int32 value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData get int32 value error, current type is %u", type_);
return false; return false;
} }
val = val_.int32Val; val = val_.int32Val;
...@@ -147,7 +148,7 @@ bool FormatData::GetInt32Value(int32_t &val) const ...@@ -147,7 +148,7 @@ bool FormatData::GetInt32Value(int32_t &val) const
bool FormatData::GetInt64Value(int64_t &val) const bool FormatData::GetInt64Value(int64_t &val) const
{ {
if (type_ != FORMAT_TYPE_INT64) { if (type_ != FORMAT_TYPE_INT64) {
printf("FormatData get int64 value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData get int64 value error, current type is %u", type_);
return false; return false;
} }
val = val_.int64Val; val = val_.int64Val;
...@@ -157,7 +158,7 @@ bool FormatData::GetInt64Value(int64_t &val) const ...@@ -157,7 +158,7 @@ bool FormatData::GetInt64Value(int64_t &val) const
bool FormatData::GetFloatValue(float &val) const bool FormatData::GetFloatValue(float &val) const
{ {
if (type_ != FORMAT_TYPE_FLOAT) { if (type_ != FORMAT_TYPE_FLOAT) {
printf("FormatData get float value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData get float value error, current type is %u", type_);
return false; return false;
} }
val = val_.floatVal; val = val_.floatVal;
...@@ -167,7 +168,7 @@ bool FormatData::GetFloatValue(float &val) const ...@@ -167,7 +168,7 @@ bool FormatData::GetFloatValue(float &val) const
bool FormatData::GetDoubleValue(double &val) const bool FormatData::GetDoubleValue(double &val) const
{ {
if (type_ != FORMAT_TYPE_DOUBLE) { if (type_ != FORMAT_TYPE_DOUBLE) {
printf("FormatData get double value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData get double value error, current type is %u", type_);
return false; return false;
} }
val = val_.doubleVal; val = val_.doubleVal;
...@@ -177,11 +178,11 @@ bool FormatData::GetDoubleValue(double &val) const ...@@ -177,11 +178,11 @@ bool FormatData::GetDoubleValue(double &val) const
bool FormatData::GetStringValue(std::string &val) const bool FormatData::GetStringValue(std::string &val) const
{ {
if (type_ != FORMAT_TYPE_STRING) { if (type_ != FORMAT_TYPE_STRING) {
printf("FormatData get string value error, current type is %u", type_); MEDIA_ERR_LOG("FormatData get string value error, current type is %u", type_);
return false; return false;
} }
if (val_.stringVal == nullptr) { if (val_.stringVal == nullptr) {
printf("FormatData get string value error, stringVal is null"); MEDIA_ERR_LOG("FormatData get string value error, stringVal is null");
return false; return false;
} }
val = *(val_.stringVal); val = *(val_.stringVal);
...@@ -238,11 +239,11 @@ bool Format::SetFormatCommon(const std::string &key, const T &value, FormatDataT ...@@ -238,11 +239,11 @@ bool Format::SetFormatCommon(const std::string &key, const T &value, FormatDataT
} }
FormatData *data = new (std::nothrow) FormatData(type); FormatData *data = new (std::nothrow) FormatData(type);
if (data == nullptr) { if (data == nullptr) {
printf("Format::SetFormatCommon new FormatData failed"); MEDIA_ERR_LOG("Format::SetFormatCommon new FormatData failed");
return false; return false;
} }
if (!data->SetValue(value)) { if (!data->SetValue(value)) {
printf("Format::SetFormatCommon failed. Key: %s", key.c_str()); MEDIA_ERR_LOG("Format::SetFormatCommon failed. Key: %s", key.c_str());
delete data; delete data;
return false; return false;
} }
...@@ -254,7 +255,7 @@ bool Format::GetStringValue(const std::string &key, std::string &value) const ...@@ -254,7 +255,7 @@ bool Format::GetStringValue(const std::string &key, std::string &value) const
{ {
auto iter = formatMap_.find(key); auto iter = formatMap_.find(key);
if (iter == formatMap_.end() || iter->second == nullptr) { if (iter == formatMap_.end() || iter->second == nullptr) {
printf("Format::GetFormat failed. Key: %s", key.c_str()); MEDIA_DEBUG_LOG("Format::GetFormat failed. Key: %s", key.c_str());
return false; return false;
} }
...@@ -265,7 +266,7 @@ bool Format::GetIntValue(const std::string &key, int32_t &value) const ...@@ -265,7 +266,7 @@ bool Format::GetIntValue(const std::string &key, int32_t &value) const
{ {
auto iter = formatMap_.find(key); auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) { if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str()); MEDIA_DEBUG_LOG("Format::GetFormat failed. Key: %s", key.c_str());
return false; return false;
} }
...@@ -276,7 +277,7 @@ bool Format::GetLongValue(const std::string &key, int64_t &value) const ...@@ -276,7 +277,7 @@ bool Format::GetLongValue(const std::string &key, int64_t &value) const
{ {
auto iter = formatMap_.find(key); auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) { if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str()); MEDIA_DEBUG_LOG("Format::GetFormat failed. Key: %s", key.c_str());
return false; return false;
} }
...@@ -287,7 +288,7 @@ bool Format::GetFloatValue(const std::string &key, float &value) const ...@@ -287,7 +288,7 @@ bool Format::GetFloatValue(const std::string &key, float &value) const
{ {
auto iter = formatMap_.find(key); auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) { if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str()); MEDIA_DEBUG_LOG("Format::GetFormat failed. Key: %s", key.c_str());
return false; return false;
} }
...@@ -298,7 +299,7 @@ bool Format::GetDoubleValue(const std::string &key, double &value) const ...@@ -298,7 +299,7 @@ bool Format::GetDoubleValue(const std::string &key, double &value) const
{ {
auto iter = formatMap_.find(key); auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) { if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str()); MEDIA_DEBUG_LOG("Format::GetFormat failed. Key: %s", key.c_str());
return false; return false;
} }
...@@ -312,13 +313,13 @@ const std::map<std::string, FormatData *> &Format::GetFormatMap() const ...@@ -312,13 +313,13 @@ const std::map<std::string, FormatData *> &Format::GetFormatMap() const
bool Format::CopyFrom(const Format &format) bool Format::CopyFrom(const Format &format)
{ {
printf("CopyFrom begin"); MEDIA_INFO_LOG("CopyFrom begin");
std::map<std::string, FormatData *> formatMap = format.GetFormatMap(); std::map<std::string, FormatData *> formatMap = format.GetFormatMap();
for (auto &iter : formatMap) { for (auto &iter : formatMap) {
std::string key = iter.first; std::string key = iter.first;
FormatData *formatData = iter.second; FormatData *formatData = iter.second;
if (formatData == nullptr) { if (formatData == nullptr) {
printf("CopyFrom FormatData is null, key is %s", key.c_str()); MEDIA_ERR_LOG("CopyFrom FormatData is null, key is %s", key.c_str());
continue; continue;
} }
FormatDataType type = formatData->GetType(); FormatDataType type = formatData->GetType();
...@@ -344,7 +345,7 @@ bool Format::CopyFrom(const Format &format) ...@@ -344,7 +345,7 @@ bool Format::CopyFrom(const Format &format)
break; break;
} }
default: { default: {
printf("CopyFrom unknown type, type is %d", type); MEDIA_ERR_LOG("CopyFrom unknown type, type is %d", type);
break; break;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册