提交 009ad00d 编写于 作者: H hangliebe

add interfaces/kits

上级 187a6d9c
/*
* 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_ERROR, fmt, ##__VA_ARGS__)
#define MEDIA_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
#define MEDIA_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, 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);
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;
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册