提交 0acad031 编写于 作者: W wenjun

add OpenHarmony 1.0 baseline

上级 a60d348d
### 该问题是怎么引起的?
### 重现步骤
### 报错信息
### 相关的Issue
### 原因(目的、解决的问题等)
### 描述(做了什么,变更了什么)
### 测试用例(新增、改动、可能影响的功能)
# Copyright (c) 2020 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.
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
shared_library("media_common") {
sources = [
"src/format.cpp",
"src/source.cpp",
]
cflags = ["-fPIC"]
cflags += ["-Wall"]
cflags_cc = cflags
include_dirs = [
"include",
"//third_party/bounds_checking_function/include",
]
public_deps = [
"//third_party/bounds_checking_function:libsec_shared",
"$ohos_vendor_adapter_dir/../../hardware:hardware_media_sdk",
"$ohos_vendor_adapter_dir/../../middleware:middleware_source_sdk",
]
}
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
\ No newline at end of file
/*
* Copyright (c) 2020 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.
*/
/**
* @addtogroup MultiMedia_MediaCommon
* @{
*
* @brief Provides data types and media formats required for recording and playing audio and videos.
*
*
* @since 1.0
* @version 1.0
*/
/**
* @file format.h
*
* @brief Declares the media formats provided in the </b>Format</b> class.
*
*
* @since 1.0
* @version 1.0
*/
#ifndef FORMAT_H
#define FORMAT_H
#include <map>
#include <string>
#include <functional>
namespace OHOS {
namespace Media {
/** Indicates the key representing the codec type. */
extern const char *CODEC_MIME;
/** Indicates the codec for Advanced Audio Coding (AAC) streams, which is a value of the codec type key. */
extern const char *MIME_AUDIO_AAC;
/** Indicates the codec for RAW audios (not supported yet), which is a value of the codec type key. */
extern const char *MIME_AUDIO_RAW;
/**
* @brief Enumerates formats.
*
* @since 1.0
* @version 1.0
*/
enum FormatDataType : uint32_t {
/** None */
FORMAT_TYPE_NONE,
/** Int32 */
FORMAT_TYPE_INT32,
/** Int64 */
FORMAT_TYPE_INT64,
/** Float */
FORMAT_TYPE_FLOAT,
/** Double */
FORMAT_TYPE_DOUBLE,
/** String */
FORMAT_TYPE_STRING
};
/**
* @brief Represents the data format.
*
* @since 1.0
* @version 1.0
*/
class FormatData {
public:
explicit FormatData(FormatDataType type);
FormatData();
~FormatData();
/**
* @brief Obtains the format type.
*
* @return Returns the format type. For details, see {@link OHOS::Media::FormatDataType}.
* @since 1.0
* @version 1.0
*/
FormatDataType GetType() const
{
return type_;
}
/**
* @brief Sets a 32-bit integer.
*
* @param val Indicates the 32-bit integer to set.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool SetValue(int32_t val);
/**
* @brief Sets a 64-bit long integer.
*
* @param val Indicates the 64-bit long integer to set.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool SetValue(int64_t val);
/**
* @brief Sets a single-precision floating-point number.
*
* @param val Indicates the single-precision floating-point number to set.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool SetValue(float val);
/**
* @brief Sets a double-precision floating-point number.
*
* @param val Indicates the double-precision floating-point number to set.
* @return Returns <b>true</b> if the double-precision floating-point number is successfully set; returns
* <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool SetValue(double val);
/**
* @brief Sets a string.
*
* @param val Indicates the string to set.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool SetValue(const std::string &val);
/**
* @brief Obtains a 32-bit integer.
*
* @param val Indicates the 32-bit integer to obtain.
* @return Returns <b>true</b> if the integer is successfully obtained; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetInt32Value(int32_t &val) const;
/**
* @brief Obtains a long integer.
*
* @param val Indicates the long integer to obtain.
* @return Returns <b>true</b> if the integer is successfully obtained; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetInt64Value(int64_t &val) const;
/**
* @brief Obtains a single-precision floating-point number.
*
* @param val Indicates the single-precision floating-point number to obtain.
* @return Returns <b>true</b> if the single-precision number is successfully obtained; returns
* <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetFloatValue(float &val) const;
/**
* @brief Obtains a double-precision floating-point number.
*
* @param val Indicates the double-precision floating-point number to obtain.
* @return Returns <b>true</b> if the double-precision number is successfully obtained; returns
* <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetDoubleValue(double &val) const;
/**
* @brief Obtains a string.
*
* @param val Indicates the string to obtain.
* @return Returns <b>true</b> if the string is successfully obtained; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetStringValue(std::string &val) const;
private:
FormatDataType type_;
union {
int32_t int32Val;
int64_t int64Val;
float floatVal;
double doubleVal;
std::string *stringVal;
} val_;
};
/**
* @brief Saves and sets media metadata, such as the media playback duration.
*
* @since 1.0
* @version 1.0
*/
class Format {
public:
/**
* @brief Default constructor of the {@link Format} instance.
*
*/
Format();
~Format();
/**
* @brief Sets metadata of the integer type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value, which is a 32-bit integer.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool PutIntValue(const std::string &key, int32_t value);
/**
* @brief Sets metadata of the long integer type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value, which is a 64-bit integer.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool PutLongValue(const std::string &key, int64_t value);
/**
* @brief Sets metadata of the single-precision floating-point type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value, which is a single-precision floating-point number.
* @return Returns <b>true</b> if the metadata is successfully set; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool PutFloatValue(const std::string &key, float value);
/**
* @brief Sets metadata of the double-precision floating-point type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value, which is a double-precision floating-point number.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool PutDoubleValue(const std::string &key, double value);
/**
* @brief Sets metadata of the string type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value, which is a string.
* @return Returns <b>true</b> if the metadata is successfully set; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool PutStringValue(const std::string &key, const std::string &value);
/**
* @brief Obtains the metadata value of the integer type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value to obtain, which is a 32-bit integer.
* @return Returns <b>true</b> if the integer is successfully obtained; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetIntValue(const std::string &key, int32_t &value) const;
/**
* @brief Obtains the metadata value of the long integer type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value to obtain, which is a 64-bit long integer.
* @return Returns <b>true</b> if the integer is successfully obtained; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetLongValue(const std::string &key, int64_t &value) const;
/**
* @brief Obtains the metadata value of the single-precision floating-point type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value to obtain, which is a single-precision floating-point number.
* @return Returns <b>true</b> if the single-precision number is successfully obtained; returns
* <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetFloatValue(const std::string &key, float &value) const;
/**
* @brief Obtains the metadata value of the double-precision floating-point type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value to obtain, which is a double-precision floating-point number.
* @return Returns <b>true</b> if the double-precision number is successfully obtained; returns
* <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetDoubleValue(const std::string &key, double &value) const;
/**
* @brief Obtains the metadata value of the string type.
*
* @param key Indicates the metadata key.
* @param value Indicates the metadata value to obtain, which is a string.
* @return Returns <b>true</b> if the string is successfully obtained; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool GetStringValue(const std::string &key, std::string &value) const;
/**
* @brief Obtains the metadata map.
*
* @return Returns the map object.
* @since 1.0
* @version 1.0
*/
const std::map<std::string, FormatData *> &GetFormatMap() const;
/**
* @brief Sets all metadata to a specified format.
*
* @param format Indicates the format. For details, see {@link Format}.
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
bool CopyFrom(const Format &format);
private:
template<typename T>
bool SetFormatCommon(const std::string &key, const T &value, FormatDataType type);
std::map<std::string, FormatData *> formatMap_;
};
} // namespace Media
} // namespace OHOS
#endif // FORMAT_H
/*
* Copyright (c) 2020 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.
*/
/**
* @addtogroup MultiMedia_MediaCommon
* @{
*
* @brief Provides data types and media formats required for recording and playing audio and videos.
*
*
* @since 1.0
* @version 1.0
*/
/**
* @file media_errors.h
*
* @brief Declares the <b>media_errors</b> class to define errors that may occur during media operations.
*
*
* @since 1.0
* @version 1.0
*/
#ifndef MEDIA_ERRORS_H
#define MEDIA_ERRORS_H
#include <cstdint>
namespace OHOS {
namespace Media {
constexpr int MODULE_MEDIA = 1;
constexpr int SUBSYS_MEDIA = 30;
using ErrCode = int32_t;
constexpr int SUBSYSTEM_BIT_NUM = 21;
constexpr int MODULE_BIT_NUM = 16;
/**
* @brief Generates a start error code with a unique identifier based on specified subsystem and module bit numbers.
*
* @param subsystem Indicates the subsystem bit number.
* @param module Indicates the module bit number.
* @return
* @since 1.0
* @version 1.0
*/
constexpr ErrCode ErrCodeOffset(unsigned int subsystem, unsigned int module = 0)
{
return (subsystem << SUBSYSTEM_BIT_NUM) | (module << MODULE_BIT_NUM);
}
constexpr int32_t BASE_MEDIA_ERR_OFFSET = ErrCodeOffset(SUBSYS_MEDIA, MODULE_MEDIA);
/** Invalid data size that has been read */
const int32_t ERR_INVALID_READ = -1;
/** Success */
const int32_t SUCCESS = 0;
/** Fail */
const int32_t ERROR = BASE_MEDIA_ERR_OFFSET;
/** Status error */
const int32_t ERR_ILLEGAL_STATE = BASE_MEDIA_ERR_OFFSET + 1;
/** Invalid parameter */
const int32_t ERR_INVALID_PARAM = BASE_MEDIA_ERR_OFFSET + 2;
/** Early media preparation */
const int32_t ERR_EARLY_PREPARE = BASE_MEDIA_ERR_OFFSET + 3;
/** No media source */
const int32_t ERR_SOURCE_NOT_SET = BASE_MEDIA_ERR_OFFSET + 4;
/** Invalid operation */
const int32_t ERR_INVALID_OPERATION = BASE_MEDIA_ERR_OFFSET + 5;
/** No idle channel */
const int32_t ERR_NOFREE_CHANNEL = BASE_MEDIA_ERR_OFFSET + 6;
/** Buffer reading failed */
const int32_t ERR_READ_BUFFER = BASE_MEDIA_ERR_OFFSET + 7;
/** Device not started */
const int32_t ERR_NOT_STARTED = BASE_MEDIA_ERR_OFFSET + 8;
/** Unknown error */
const int32_t ERR_UNKNOWN = BASE_MEDIA_ERR_OFFSET + 200;
} // namespace Media
} // namespace OHOS
#endif // MEDIA_ERRORS_H
/*
* Copyright (c) 2020 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.
*/
/**
* @addtogroup MultiMedia_MediaCommon
* @{
*
* @brief Provides data types and media formats required for recording and playing audio and videos.
*
*
* @since 1.0
* @version 1.0
*/
/**
* @file media_info.h
*
* @brief Declares the <b>media_info</b> class and provides various audio, video, and codec types.
*
*
* @since 1.0
* @version 1.0
*/
#ifndef MEDIA_INFO_H
#define MEDIA_INFO_H
#include <string>
/**
* Indicates the constant quality mode. In this mode, the bit rate is not limited to guarantee the image quality to
* the largest extent.
*/
const int BITRATE_MODE_CQ = 0;
/**
* Indicates the variable bit rate mode. In this mode, the codec dynamically adjusts the output bit rate based on
* the image complexity. The codec increases the bit rate if the image is complex and decreases the bit rate if the
* image is simple.
*/
const int BITRATE_MODE_VBR = 1;
/** Indicates the constant bit rate mode. In this mode, the codec keeps the output bit rate as constant as possible. */
const int BITRATE_MODE_CBR = 2;
/** Indicates the ARGB8888 color format. */
const int32_t COLOR_FORMAT_ARGB8888_32BIT = 16;
/** Indicates the YUV420SP color format. */
const int32_t COLOR_FORMAT_YUV420SP = 21;
/** Indicates that the current frame is an Instantaneous Decoder Refresh (IDR) frame. */
const std::string KEY_IS_SYNC_FRAME = "is-sync-frame";
/** Indicates the frame timestamp. */
const std::string KEY_TIME_US = "timeUs";
/**
* @brief Enumerates audio source types.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Invalid audio source */
AUDIO_SOURCE_INVALID = -1,
/** Default audio source */
AUDIO_SOURCE_DEFAULT = 0,
/** Microphone */
AUDIO_MIC = 1,
/** Uplink voice */
AUDIO_VOICE_UPLINK = 2,
/** Downlink voice */
AUDIO_VOICE_DOWNLINK = 3,
/** Voice call */
AUDIO_VOICE_CALL = 4,
/** Camcorder */
AUDIO_CAMCORDER = 5,
/** Voice recognition */
AUDIO_VOICE_RECOGNITION = 6,
/** Voice communication */
AUDIO_VOICE_COMMUNICATION = 7,
/** Remote submix */
AUDIO_REMOTE_SUBMIX = 8,
/** Unprocessed audio */
AUDIO_UNPROCESSED = 9,
/** Voice performance */
AUDIO_VOICE_PERFORMANCE = 10,
/** Echo reference */
AUDIO_ECHO_REFERENCE = 1997,
/** Radio tuner */
AUDIO_RADIO_TUNER = 1998,
/** Hotword */
AUDIO_HOTWORD = 1999,
/** Extended remote submix */
AUDIO_REMOTE_SUBMIX_EXTEND = 10007,
} AudioSourceType;
/**
* @brief Defines the audio Device Descriptor.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
/** Device name */
std::string deviceName;
/** Type of the audio input source */
AudioSourceType inputSourceType;
/** Bits 31-24: reserved bits; bits 23-16: mode ID; bits 15-8: device ID; bits 7-0: channel ID */
uint32_t deviceId;
} AudioDeviceDesc;
/**
* @brief Enumerates audio stream types.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Default audio stream type */
TYPE_DEFAULT = -1,
/** Media */
TYPE_MEDIA = 0,
/** Voice call */
TYPE_VOICE_COMMUNICATION = 1,
/** System sound */
TYPE_SYSTEM = 2,
/** Ringtone */
TYPE_RING = 3,
/** Music */
TYPE_MUSIC = 4,
/** Alarm */
TYPE_ALARM = 5,
/** Notification */
TYPE_NOTIFICATION = 6,
/** Bluetooth Synchronous Connection-Oriented (SCO) */
TYPE_BLUETOOTH_SCO = 7,
/** Enforced audible */
TYPE_ENFORCED_AUDIBLE = 8,
/** Dual-tone multi-frequency (DTMF) */
TYPE_DTMF = 9,
/** Text-To-Speech (TTS) */
TYPE_TTS = 10,
/** Accessibility */
TYPE_ACCESSIBILITY = 11,
} AudioStreamType;
/**
* @brief Enumerates video codec formats.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Default format */
VIDEO_DEFAULT = 0,
/** H.264 */
H264 = 2,
/** High Efficiency Video Coding (HEVC) */
HEVC = 5,
} VideoCodecFormat;
/**
* @brief Enumerates audio codec formats.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** Default format */
AUDIO_DEFAULT = 0,
/** Advanced Audio Coding Low Complexity (AAC-LC) */
AAC_LC = 1,
/** High-Efficiency Advanced Audio Coding (AAC-HE), previously known as AAC+ or aacPlus v1 */
AAC_HE_V1 = 2,
/** AAC++ or aacPlus v2 */
AAC_HE_V2 = 3,
/** Advanced Audio Coding Low Delay (AAC-LD) */
AAC_LD = 4,
/** Advanced Audio Coding Enhanced Low Delay (AAC-ELD) */
AAC_ELD = 5,
/** Invalid value */
FORMAT_BUTT,
} AudioCodecFormat;
/**
* @brief Enumerates audio bit widths.
*
* @since 1.0
* @version 1.0
*/
typedef enum {
/** 8-bit width */
BIT_WIDTH_8 = 8,
/** 16-bit width */
BIT_WIDTH_16 = 16,
/** 24-bit width */
BIT_WIDTH_24 = 24,
/** Invalid value */
BIT_WIDTH_BUTT,
} AudioBitWidth;
#endif // MEDIA_INFO_H
/*
* Copyright (c) 2020 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 OHOS_MEDIA_LOG_H
#define OHOS_MEDIA_LOG_H
#include <stdio.h>
#include "log.h"
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD002B00
#define LOG_TAG "MultiMedia"
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#ifndef OHOS_DEBUG
#define DECORATOR_HILOG(op, fmt, args...) \
do { \
op(LOG_CORE, fmt, ##args); \
} while (0)
#else
#define DECORATOR_HILOG(op, fmt, args...) \
do { \
op(LOG_CORE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \
} while (0)
#endif
#define MEDIA_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
#define MEDIA_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
#define MEDIA_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
#define MEDIA_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
#define MEDIA_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
#define MEDIA_OK 0
#define MEDIA_INVALID_PARAM (-1)
#define MEDIA_INIT_FAIL (-2)
#define MEDIA_ERR (-3)
#define MEDIA_PERMISSION_DENIED (-4)
#endif // OHOS_MEDIA_LOG_H
\ No newline at end of file
/*
* Copyright (c) 2020 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.
*/
/**
* @addtogroup MultiMedia_MediaCommon
* @{
*
* @brief Provides data types and media formats required for recording and playing audio and videos.
*
*
* @since 1.0
* @version 1.0
*/
/**
* @file source.h
*
* @brief Declares the <b>Source</b> class, which is used to implement source-related operations.
*
*
* @since 1.0
* @version 1.0
*/
#ifndef SOURCE_H
#define SOURCE_H
#include <memory>
#include <map>
#include <string>
#include "format.h"
using std::shared_ptr;
namespace OHOS {
namespace Media {
/**
* @brief Enumerates media source types.
*
* @since 1.0
* @version 1.0
*/
enum class SourceType : int32_t {
/** Local file path or network address */
SOURCE_TYPE_URI = 0,
/** Local file descriptor */
SOURCE_TYPE_FD,
/** Stream data, such as Advanced Audio Coding (AAC) stream data */
SOURCE_TYPE_STREAM,
};
/**
* @brief Provides functions to obtain the address of a buffer memory and write the filled buffers into the playback
* queue. You need to implement the <b>StreamCallback</b> functions in a player object.
*
* @since 1.0
* @version 1.0
*/
struct StreamCallback {
/**
* @brief Enumerates buffer types of stream sources.
*
* @since 1.0
* @version 1.0
*/
enum BufferFlags : uint32_t {
/** Synchronous frame */
STREAM_FLAG_SYNCFRAME = 1,
/** Codec configuration information */
STREAM_FLAG_CODECCONFIG = 2,
/** End of Stream (EOS) */
STREAM_FLAG_EOS = 4,
/** Part of a frame */
STREAM_FLAG_PARTIAL_FRAME = 8,
/** End of a frame. It is used in pair with <b>STREAM_FLAG_PARTIAL_FRAME</b>. */
STREAM_FLAG_ENDOFFRAME = 16,
/** Container file data, such as MP4 file data (not supported yet) */
STREAM_FLAG_MUXER_DATA = 32,
};
/**
* @brief Obtains the virtual address of a buffer memory block based on its index.
*
* @param index Indicates the index of the buffer memory block.
* @return Returns the pointer to the virtual address of the buffer memory block.
* @since 1.0
* @version 1.0
*/
virtual uint8_t *GetBuffer(size_t index) = 0;
/**
* @brief Writes the filled buffer memory block into the player memory.
*
* @param index Indicates the index of the buffer memory block.
* @param offset Indicates the start offset into which the buffer memory block will be written.
* @param size Indicates the size of the data filled in the buffer memory block.
* @param timestampUs Indicates the timestamp of the frame filled in the buffer memory block. As data in AAC
* streams can be filled not on a frame basis, set this parameter to <b>0</b> for AAC streams.
* @param flags Indicates the type of the current buffer memory block. For details, see {@link BufferFlags}.
* @since 1.0
* @version 1.0
*/
virtual void QueueBuffer(size_t index, size_t offset, size_t size, int64_t timestampUs, uint32_t flags) = 0;
/**
* @brief Sets additional information about a stream.
*
* @param params Indicates the parameters for additional stream information. For details, see {@link Format}.
* @since 1.0
* @version 1.0
*/
virtual void SetParameters(const Format &params) = 0;
};
/**
* @brief Provides functions related to the stream source for upper-layer applications.
*
* After the {@link SetSource} function is called, the player invokes {@link OnBufferAvailable} to notify your
* application of the buffer memory block that can be filled with data.\n
* The player can invoke {@link SetStreamCallback} to register a callback for your application. For example,
* the {@link GetBuffer} callback obtains the address of the buffer block and sends the filled buffer memory block to
* the player. The buffer memory block is allocated and processed on the player.\n
* <b>StreamSource</b>is available only for the media source of the <b>SOURCE_TYPE_STREAM</b> type.
* For details, see {@link SourceType}.\n
*
* @since 1.0
* @version 1.0
*/
struct StreamSource {
/**
* @brief Notifies your application of the information about the buffer memory block that can be filled with data.
*
* @param index Indicates the index of the buffer memory block.
* @param offset Indicates the start offset into which the data will be written.
* @param size Indicates the size of data that the buffer memory block can store.
* @since 1.0
* @version 1.0
*/
virtual void OnBufferAvailable(size_t index, size_t offset, size_t size) = 0;
/**
* @brief Sets a callback function for your application.
*
* @param callback Indicates the {@link StreamCallback} function to set.
* @since 1.0
* @version 1.0
*/
virtual void SetStreamCallback(const std::shared_ptr<StreamCallback> &callback) = 0;
};
/**
* @brief Provides functions to implement source-related operations.
*
* @since 1.0
* @version 1.0
*/
class Source {
public:
/**
* @brief A constructor used to create a {@link Source} instance based on a specified URI.
*
* @param uri Indicates the media source URI, which can be a network URI or local file path.
* @since 1.0
* @version 1.0
*/
explicit Source(const std::string& uri);
/**
* @brief A constructor used to create a {@link Source} instance based on a specified URI and header.
*
* If the HTTP URL header does not carry valid information for network playback, this function is equivalent to
* {@link Source(const std::string& uri)}.
*
* @param uri Indicates the media source URI.
* @param header Indicates the header.
* @since 1.0
* @version 1.0
*/
Source(const std::string &uri, const std::map<std::string, std::string> &header);
/**
* @brief A constructor used to create a {@link Source} instance based on the stream source and format information.
*
*
*
* @param stream Indicates the media source stream. For details, see {@link StreamSource}.
* @param formats Indicates stream data information, which is subject to the stream type. For example, the key
* is {@link CODEC_MIME}, and the value is {@link MIME_AUDIO_AAC}. For details, see {@link Format}. This parameter
* can be null if no information needs to be passed.
* @since 1.0
* @version 1.0
*/
Source(const std::shared_ptr<StreamSource> &stream, const Format &formats);
~Source() = default;
/**
* @brief Obtains the source type.
*
* @return Returns the source type. For details, see {@link SourceType}.
* @since 1.0
* @version 1.0
*/
SourceType GetSourceType() const;
/**
* @brief Obtains the media source URI.
*
* This function is called only when the {@link SourceType} is {@link SOURCE_TYPE_URI}.
*
* @return Returns the media source URI.
* @since 1.0
* @version 1.0
*/
const std::string &GetSourceUri() const;
/**
* @brief Obtains the HTTP header for the media source.
*
* This function is called only when the {@link SourceType} is {@link SOURCE_TYPE_URI}.
*
* @return Returns the media source header.
* @since 1.0
* @version 1.0
*/
const std::map<std::string, std::string> &GetSourceHeader() const;
/**
* @brief Obtains information about the media source stream.
*
* This function is called only when the {@link SourceType} is {@link SOURCE_TYPE_STREAM}.
*
* @return Returns information about the media source stream. For details, see {@link StreamSource}.
* @since 1.0
* @version 1.0
*/
const std::shared_ptr<StreamSource> &GetSourceStream() const;
/**
* @brief Obtains the media source stream format.
*
* @return Returns the media source stream format. For details, see {@link Format}.
* @since 1.0
* @version 1.0
*/
const Format &GetSourceStreamFormat() const;
private:
std::string uri_;
SourceType sourceType_;
std::map<std::string, std::string> header_;
std::shared_ptr<StreamSource> stream_;
Format format_;
};
} // namespace Media
} // namespace OHOS
#endif // SOURCE_H
详见:https://gitee.com/openharmony/docs/blob/master/readme/媒体子系统README.md
/*
* Copyright (c) 2020 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 "format.h"
#include <cstdio>
namespace OHOS {
namespace Media {
const char *CODEC_MIME = "mime";
const char *MIME_AUDIO_AAC = "audio/mp4a-latm";
const char *MIME_AUDIO_RAW = "audio/raw";
#define SET_INT32_FORMAT(type, func) \
do { \
type val; \
if (formatData->func(val)) { \
PutIntValue(key, val); \
} \
} while (0)
#define SET_INT64_FORMAT(type, func) \
do { \
type val; \
if (formatData->func(val)) { \
PutLongValue(key, val); \
} \
} while (0)
#define SET_FLOAT_FORMAT(type, func) \
do { \
type val; \
if (formatData->func(val)) { \
PutFloatValue(key, val); \
} \
} while (0)
#define SET_DOUBLE_FORMAT(type, func) \
do { \
type val; \
if (formatData->func(val)) { \
PutDoubleValue(key, val); \
} \
} while (0)
#define SET_STRING_FORMAT(type, func) \
do { \
type val; \
if (formatData->func(val)) { \
PutStringValue(key, val); \
} \
} while (0)
// For Class FormatData
FormatData::FormatData() : type_(FORMAT_TYPE_NONE), val_({ 0 })
{}
FormatData::FormatData(FormatDataType type) : type_(type), val_({ 0 })
{}
FormatData::~FormatData()
{
if (type_ == FORMAT_TYPE_STRING) {
if (val_.stringVal != nullptr) {
delete val_.stringVal;
}
}
}
bool FormatData::SetValue(int32_t val)
{
if (type_ != FORMAT_TYPE_INT32) {
printf("FormatData set int32 value error, current type is %u", type_);
return false;
}
val_.int32Val = val;
return true;
}
bool FormatData::SetValue(int64_t val)
{
if (type_ != FORMAT_TYPE_INT64) {
printf("FormatData set int64 value error, current type is %u", type_);
return false;
}
val_.int64Val = val;
return true;
}
bool FormatData::SetValue(float val)
{
if (type_ != FORMAT_TYPE_FLOAT) {
printf("FormatData set float value error, current type is %u", type_);
return false;
}
val_.floatVal = val;
return true;
}
bool FormatData::SetValue(double val)
{
if (type_ != FORMAT_TYPE_DOUBLE) {
printf("FormatData set double value error, current type is %u", type_);
return false;
}
val_.doubleVal = val;
return true;
}
bool FormatData::SetValue(const std::string &val)
{
if (type_ != FORMAT_TYPE_STRING) {
printf("FormatData set string value error, current type is %u", type_);
return false;
}
val_.stringVal = new (std::nothrow) std::string();
if (val_.stringVal == nullptr) {
type_ = FORMAT_TYPE_NONE;
printf("FormatData set string value error, new string failed");
return false;
}
*(val_.stringVal) = val;
return true;
}
bool FormatData::GetInt32Value(int32_t &val) const
{
if (type_ != FORMAT_TYPE_INT32) {
printf("FormatData get int32 value error, current type is %u", type_);
return false;
}
val = val_.int32Val;
return true;
}
bool FormatData::GetInt64Value(int64_t &val) const
{
if (type_ != FORMAT_TYPE_INT64) {
printf("FormatData get int64 value error, current type is %u", type_);
return false;
}
val = val_.int64Val;
return true;
}
bool FormatData::GetFloatValue(float &val) const
{
if (type_ != FORMAT_TYPE_FLOAT) {
printf("FormatData get float value error, current type is %u", type_);
return false;
}
val = val_.floatVal;
return true;
}
bool FormatData::GetDoubleValue(double &val) const
{
if (type_ != FORMAT_TYPE_DOUBLE) {
printf("FormatData get double value error, current type is %u", type_);
return false;
}
val = val_.doubleVal;
return true;
}
bool FormatData::GetStringValue(std::string &val) const
{
if (type_ != FORMAT_TYPE_STRING) {
printf("FormatData get string value error, current type is %u", type_);
return false;
}
if (val_.stringVal == nullptr) {
printf("FormatData get string value error, stringVal is null");
return false;
}
val = *(val_.stringVal);
return true;
}
// For Class Format
Format::Format()
{}
Format::~Format()
{
for (auto &iter : formatMap_) {
if (iter.second != nullptr) {
delete iter.second;
}
}
formatMap_.clear();
}
bool Format::PutIntValue(const std::string &key, int32_t value)
{
return SetFormatCommon(key, value, FORMAT_TYPE_INT32);
}
bool Format::PutLongValue(const std::string &key, int64_t value)
{
return SetFormatCommon(key, value, FORMAT_TYPE_INT64);
}
bool Format::PutFloatValue(const std::string &key, float value)
{
return SetFormatCommon(key, value, FORMAT_TYPE_FLOAT);
}
bool Format::PutDoubleValue(const std::string &key, double value)
{
return SetFormatCommon(key, value, FORMAT_TYPE_DOUBLE);
}
bool Format::PutStringValue(const std::string &key, const std::string &value)
{
return SetFormatCommon(key, value, FORMAT_TYPE_STRING);
}
template<typename T>
bool Format::SetFormatCommon(const std::string &key, const T &value, FormatDataType type)
{
auto iter = formatMap_.find(key);
if (iter != formatMap_.end()) {
delete iter->second;
iter->second = nullptr;
formatMap_.erase(iter);
}
FormatData *data = new (std::nothrow) FormatData(type);
if (data == nullptr) {
printf("Format::SetFormatCommon new FormatData failed");
return false;
}
if (!data->SetValue(value)) {
printf("Format::SetFormatCommon failed. Key: %s", key.c_str());
delete data;
return false;
}
formatMap_[key] = data;
return true;
}
bool Format::GetStringValue(const std::string &key, std::string &value) const
{
auto iter = formatMap_.find(key);
if (iter == formatMap_.end() || iter->second == nullptr) {
printf("Format::GetFormat failed. Key: %s", key.c_str());
return false;
}
return (*iter->second).GetStringValue(value);
}
bool Format::GetIntValue(const std::string &key, int32_t &value) const
{
auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str());
return false;
}
return (*iter->second).GetInt32Value(value);
}
bool Format::GetLongValue(const std::string &key, int64_t &value) const
{
auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str());
return false;
}
return (*iter->second).GetInt64Value(value);
}
bool Format::GetFloatValue(const std::string &key, float &value) const
{
auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str());
return false;
}
return (*iter->second).GetFloatValue(value);
}
bool Format::GetDoubleValue(const std::string &key, double &value) const
{
auto iter = formatMap_.find(key);
if ((iter == formatMap_.end()) || (iter->second == nullptr)) {
printf("Format::GetFormat failed. Key: %s", key.c_str());
return false;
}
return (*iter->second).GetDoubleValue(value);
}
const std::map<std::string, FormatData *> &Format::GetFormatMap() const
{
return formatMap_;
}
bool Format::CopyFrom(const Format &format)
{
printf("CopyFrom begin");
std::map<std::string, FormatData *> formatMap = format.GetFormatMap();
for (auto &iter : formatMap) {
std::string key = iter.first;
FormatData *formatData = iter.second;
if (formatData == nullptr) {
printf("CopyFrom FormatData is null, key is %s", key.c_str());
continue;
}
FormatDataType type = formatData->GetType();
switch (type) {
case FORMAT_TYPE_INT32: {
SET_INT32_FORMAT(int32_t, GetInt32Value);
break;
}
case FORMAT_TYPE_INT64: {
SET_INT64_FORMAT(int64_t, GetInt64Value);
break;
}
case FORMAT_TYPE_FLOAT: {
SET_FLOAT_FORMAT(float, GetFloatValue);
break;
}
case FORMAT_TYPE_DOUBLE: {
SET_DOUBLE_FORMAT(double, GetDoubleValue);
break;
}
case FORMAT_TYPE_STRING: {
SET_STRING_FORMAT(std::string, GetStringValue);
break;
}
default: {
printf("CopyFrom unknown type, type is %d", type);
break;
}
}
}
return true;
}
} // namespace Media
} // namespace OHOS
/*
* Copyright (c) 2020 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 "source.h"
namespace OHOS {
namespace Media {
Source::Source(const std::string &uri)
: uri_(uri),
sourceType_(SourceType::SOURCE_TYPE_URI)
{}
Source::Source(const std::string &uri, const std::map<std::string, std::string> &header)
: uri_(uri),
sourceType_(SourceType::SOURCE_TYPE_URI),
header_(header)
{}
Source::Source(const std::shared_ptr<StreamSource> &stream, const Format &formats)
: sourceType_(SourceType::SOURCE_TYPE_STREAM),
stream_(stream)
{
format_.CopyFrom(formats);
}
SourceType Source::GetSourceType() const
{
return sourceType_;
}
const std::string &Source::GetSourceUri() const
{
return uri_;
}
const std::map<std::string, std::string> &Source::GetSourceHeader() const
{
return header_;
}
const std::shared_ptr<StreamSource> &Source::GetSourceStream() const
{
return stream_;
}
const Format &Source::GetSourceStreamFormat() const
{
return format_;
}
} // namespace Media
} // namespace OHOS
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册