- int media_format_set_codec_data(media_format_h fmt, void *codec_data, unsigned int size);
- int media_format_get_codec_data(media_format_h fmt, void **codec_data, unsigned int *size);
[Version] 0.1.56
[Issue Type] New feature
Change-Id: I43d8ac2b6f47a9723fa2e4150432ca2f44bd9384
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
* @internal
* @brief Get reference count of #media_format_h object.
* @since_tizen 7.0
- * @param[in] fmt The #media_format_h to get
+ * @param[in] fmt The media format handle
* @param[out] ref_count Reference count of #media_format_h
*
* @return @c 0 on success,
*/
int media_format_get_refcount(media_format_h fmt, int *ref_count);
+/**
+ * @internal
+ * @brief Sets codec data and the codec data size.
+ * @since_tizen 7.5
+ * @param[in] fmt The media format handle
+ * @param[in] codec_data The codec data to set
+ * @param[in] size The size of codec data
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int media_format_set_codec_data(media_format_h fmt, void *codec_data, unsigned int size);
+
+/**
+ * @internal
+ * @brief Gets codec data and the size.
+ * @since_tizen 7.5
+ * @remarks The @a codec_data should be released using free().
+ * @param[in] fmt The media format handle
+ * @param[out] codec_data The codec data to get
+ * @param[out] size The size of codec data
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_format_get_codec_data(media_format_h fmt, void **codec_data, unsigned int *size);
+
/**
* @}
*/
media_format_text_type_e type; /**< media format text (or subtile) codec type */
} media_format_text_spec_s;
+/**
+ * @brief Media format for codec data.
+ * @since_tizen 7.5
+ */
+typedef struct _media_fomat_codec_data_s {
+ void *data; /**< codec data */
+ unsigned int size; /**< codec data size */
+} media_format_codec_data_s;
+
/**
* @brief Structure of media format.
* @since_tizen 2.3
media_format_text_spec_s text; /**< media format struct video of media_format_text_spec_s (Since 3.0) */
} detail;
+ media_format_codec_data_s codec_data; /**< media format codec data */
} media_format_s;
#ifdef __cplusplus
bool is_allocated;
bool using_pool;
void *extradata;
- void *codec_data;
- unsigned int codec_data_size;
media_format_s *format;
media_buffer_type_e type;
Name: capi-media-tool
Summary: A Core API media tool library in Tizen Native API
-Version: 0.1.55
+Version: 0.1.56
Release: 0
Group: Multimedia/API
License: Apache-2.0
{
MEDIA_FORMAT_INSTANCE_CHEC_VOID(fmt);
+ if (fmt->codec_data.data)
+ free(fmt->codec_data.data);
+
free(fmt);
- fmt = NULL;
}
int media_format_get_type(media_format_h fmt, media_format_type_e *formattype)
return MEDIA_FORMAT_ERROR_NONE;
}
+
+
+int media_format_set_codec_data(media_format_h fmt, void *codec_data, unsigned int size)
+{
+ media_format_s *fmt_handle = (media_format_s *)fmt;
+ void *tmp_data = NULL;
+
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt_handle);
+ MEDIA_FORMAT_NULL_ARG_CHECK(codec_data);
+ MEDIA_FORMAT_NULL_ARG_CHECK(size > 0);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt)) {
+ LOGE("The format can not be changed");
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ tmp_data = malloc(size);
+ if (!tmp_data) {
+ LOGE("alloc[%u] failed", size);
+ return MEDIA_FORMAT_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (fmt_handle->codec_data.data) {
+ LOGW("release current codec data[%p], size[%u]",
+ fmt_handle->codec_data.data, fmt_handle->codec_data.size);
+ free(fmt_handle->codec_data.data);
+ }
+
+ memcpy(tmp_data, codec_data, size);
+
+ fmt_handle->codec_data.data = tmp_data;
+ fmt_handle->codec_data.size = size;
+
+ LOGI("set new codec data[%p], size[%u]",
+ fmt_handle->codec_data.data, fmt_handle->codec_data.size);
+
+ return MEDIA_FORMAT_ERROR_NONE;
+}
+
+
+int media_format_get_codec_data(media_format_h fmt, void **codec_data, unsigned int *size)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ media_format_s *fmt_handle = (media_format_s *)fmt;
+ void *new_data = NULL;
+
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt_handle);
+ MEDIA_FORMAT_NULL_ARG_CHECK(codec_data);
+ MEDIA_FORMAT_NULL_ARG_CHECK(size);
+
+ if (fmt_handle->codec_data.data && fmt_handle->codec_data.size > 0) {
+ new_data = malloc(fmt_handle->codec_data.size);
+ if (!new_data) {
+ LOGE("alloc[%u] failed", fmt_handle->codec_data.size);
+ return MEDIA_FORMAT_ERROR_OUT_OF_MEMORY;
+ }
+
+ memcpy(new_data, fmt_handle->codec_data.data, fmt_handle->codec_data.size);
+ }
+
+ *codec_data = new_data;
+ *size = fmt_handle->codec_data.size;
+
+ LOGI("get codec data[%p], size[%u]", *codec_data, *size);
+
+ return MEDIA_FORMAT_ERROR_NONE;
+}
return MEDIA_PACKET_ERROR_INVALID_OPERATION;
}
- /* free codec_data if it is allocated */
- if (handle->codec_data) {
- free(handle->codec_data);
- handle->codec_data = NULL;
- handle->codec_data_size = 0;
- }
-
handle->is_allocated = false;
return MEDIA_PACKET_ERROR_NONE;
int media_packet_get_codec_data(media_packet_h packet, void **codec_data, unsigned int *codec_data_size)
{
- media_packet_s *handle;
- int ret = MEDIA_PACKET_ERROR_NONE;
-
- MEDIA_PACKET_INSTANCE_CHECK(packet);
- MEDIA_PACKET_NULL_ARG_CHECK(codec_data);
- MEDIA_PACKET_NULL_ARG_CHECK(codec_data_size);
-
- handle = (media_packet_s *)packet;
-
- LOGI("Get: codec data = %p, codec_data_size = %u", handle->codec_data, handle->codec_data_size); //LCOV_EXCL_LINE
+ media_packet_s *handle = (media_packet_s *)packet;
- if (handle->codec_data) {
- *codec_data_size = handle->codec_data_size;
- *codec_data = handle->codec_data;
- } else {
- *codec_data = NULL;
- *codec_data_size = 0;
+ MEDIA_PACKET_INSTANCE_CHECK(handle);
- LOGE("There is no codec data");
- ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ switch (media_format_get_codec_data(handle->format, codec_data, codec_data_size)) {
+ case MEDIA_FORMAT_ERROR_NONE:
+ return MEDIA_PACKET_ERROR_NONE;
+ case MEDIA_FORMAT_ERROR_INVALID_PARAMETER:
+ return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+ case MEDIA_FORMAT_ERROR_INVALID_OPERATION: /* fall through */
+ default:
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
}
-
- return ret;
}
int media_packet_destroy(media_packet_h packet)
LOGI("Set: codec data = %p, codec_data_size = %u\n", codec_data, codec_data_size);
- handle->codec_data = (void *)malloc(codec_data_size);
- if (handle->codec_data == NULL) {
- LOGE("MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)", MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
- return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+ switch (media_format_set_codec_data(handle->format, codec_data, codec_data_size)) {
+ case MEDIA_FORMAT_ERROR_NONE:
+ return MEDIA_PACKET_ERROR_NONE;
+ case MEDIA_FORMAT_ERROR_INVALID_PARAMETER:
+ return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+ case MEDIA_FORMAT_ERROR_INVALID_OPERATION: /* fall through */
+ default:
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
}
-
- memcpy(handle->codec_data, codec_data, codec_data_size);
- handle->codec_data_size = codec_data_size;
-
- return MEDIA_PACKET_ERROR_NONE;
}
int media_packet_reset_flags(media_packet_h packet)
g_print("media_packet_get_codec_data is sucess ... !\n");
g_print("codec_data_size = %u\n", get_codec_data_size);
- if (get_codec_data_size == 0)
+ if (!get_codec_data || get_codec_data_size == 0)
return;
int i;
g_print("codec_data[%d] ", i);
g_print(" = 0x%x\n", get_codec_data[i]);
}
+
+ free(get_codec_data);
} else {
g_print("media_packet_get_codec_data is failed...\n");
}