-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create aac_utils to hold encoder/decoder common utils
PiperOrigin-RevId: 635443367
- Loading branch information
1 parent
5686c76
commit b06b2d2
Showing
5 changed files
with
114 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "iamf/cli/codec/aac_utils.h" | ||
|
||
#include <string> | ||
|
||
#include "absl/log/log.h" | ||
|
||
// This symbol conflicts with `aacenc_lib.h` and `aacdecoder_lib.h`. | ||
#ifdef IS_LITTLE_ENDIAN | ||
#undef IS_LITTLE_ENDIAN | ||
#endif | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/strings/str_cat.h" | ||
#include "iamf/cli/proto/codec_config.pb.h" | ||
#include "libAACenc/include/aacenc_lib.h" | ||
|
||
namespace iamf_tools { | ||
|
||
absl::Status AacEncErrorToAbslStatus(AACENC_ERROR aac_error_code, | ||
const std::string& error_message) { | ||
absl::StatusCode status_code; | ||
switch (aac_error_code) { | ||
case AACENC_OK: | ||
return absl::OkStatus(); | ||
case AACENC_INVALID_HANDLE: | ||
status_code = absl::StatusCode::kInvalidArgument; | ||
break; | ||
case AACENC_MEMORY_ERROR: | ||
status_code = absl::StatusCode::kResourceExhausted; | ||
break; | ||
case AACENC_UNSUPPORTED_PARAMETER: | ||
status_code = absl::StatusCode::kInvalidArgument; | ||
break; | ||
case AACENC_INVALID_CONFIG: | ||
status_code = absl::StatusCode::kFailedPrecondition; | ||
break; | ||
case AACENC_INIT_ERROR: | ||
case AACENC_INIT_AAC_ERROR: | ||
case AACENC_INIT_SBR_ERROR: | ||
case AACENC_INIT_TP_ERROR: | ||
case AACENC_INIT_META_ERROR: | ||
case AACENC_INIT_MPS_ERROR: | ||
status_code = absl::StatusCode::kInternal; | ||
break; | ||
case AACENC_ENCODE_EOF: | ||
status_code = absl::StatusCode::kOutOfRange; | ||
break; | ||
case AACENC_ENCODE_ERROR: | ||
default: | ||
status_code = absl::StatusCode::kUnknown; | ||
break; | ||
} | ||
|
||
return absl::Status( | ||
status_code, | ||
absl::StrCat(error_message, " AACENC_ERROR= ", aac_error_code)); | ||
} | ||
|
||
} // namespace iamf_tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef CLI_CODEC_AAC_UTILS_H_ | ||
#define CLI_CODEC_AAC_UTILS_H_ | ||
|
||
#include <cstddef> | ||
#include <string> | ||
|
||
#include "absl/status/status.h" | ||
#include "iamf/cli/proto/codec_config.pb.h" | ||
#include "libAACenc/include/aacenc_lib.h" | ||
#include "libSYS/include/FDK_audio.h" | ||
#include "libSYS/include/machine_type.h" | ||
|
||
namespace iamf_tools { | ||
|
||
/*!\brief IAMF requires raw AAC frames with no ADTS header. */ | ||
constexpr TRANSPORT_TYPE GetAacTransportationType() { return TT_MP4_RAW; } | ||
|
||
/*!\brief The FDK AAC encoder uses 16-bit PCM. */ | ||
constexpr size_t GetFdkAacBytesPerSample() { return sizeof(INT_PCM); } | ||
|
||
/*!\brief Convenience method for getting bit depth. */ | ||
constexpr size_t GetFdkAacBitDepth() { return GetFdkAacBytesPerSample() * 8; } | ||
|
||
/*!\brief Converts an AACENC_ERROR to an absl::Status. */ | ||
absl::Status AacEncErrorToAbslStatus(AACENC_ERROR aac_error_code, | ||
const std::string& error_message); | ||
|
||
} // namespace iamf_tools | ||
|
||
#endif // CLI_CODEC_AAC_UTILS_H_ |