summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjk7744.park <jk7744.park@samsung.com>2015-09-08 22:08:42 +0900
committerjk7744.park <jk7744.park@samsung.com>2015-09-08 22:08:42 +0900
commitf412b83af8df235cee2d5dec9c34f96e0719e4bb (patch)
tree3c560a4f352a42258e03a0377bba5c840a2fa55a
parent3a201e3e04372e0b8d4d349d80c38a2d45f0e58e (diff)
downloadcapi-media-tool-tizen_2.3.1.tar.gz
capi-media-tool-tizen_2.3.1.tar.bz2
capi-media-tool-tizen_2.3.1.zip
-rwxr-xr-xAUTHORS2
-rwxr-xr-xCMakeLists.txt98
-rwxr-xr-xLICENSE.APLv2206
-rwxr-xr-xNOTICE3
-rwxr-xr-xcapi-media-tool.manifest8
-rwxr-xr-xcapi-media-tool.pc.in15
-rwxr-xr-xdoc/capi_media_tool_doc.h55
-rwxr-xr-xinclude/media_format.h407
-rwxr-xr-xinclude/media_format_private.h151
-rwxr-xr-xinclude/media_packet.h714
-rwxr-xr-xinclude/media_packet_private.h135
-rwxr-xr-xpackaging/capi-media-tool.spec74
-rwxr-xr-xsrc/media_format.c484
-rwxr-xr-xsrc/media_packet.c1312
-rwxr-xr-xsrc/media_packet_private.c20
-rwxr-xr-xtest/CMakeLists.txt22
-rwxr-xr-xtest/media_packet_test.c1357
17 files changed, 5063 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100755
index 0000000..b01c60f
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Kangho Hur <kanho.hur@samsung.com>
+Seungkeun Lee <sngn.lee@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..6e75836
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,98 @@
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-media-tool")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(dependents "dlog glib-2.0")
+SET(pc_dependents "dlog capi-base-common libtbm")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "-I./include -I./include/headers ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -w")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+aux_source_directory(src SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(
+ DIRECTORY ${INC_DIR}/ DESTINATION include/media
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "${INC_DIR}/*.h"
+ )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_dependents})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_CFLAGS -I\${includedir}/media)
+
+CONFIGURE_FILE(
+ ${fw_name}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+ADD_SUBDIRECTORY(test)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+ DEPENDS clean
+ COMMENT "distribution clean"
+ COMMAND find
+ ARGS .
+ -not -name config.cmake -and \(
+ -name tester.c -or
+ -name Testing -or
+ -name CMakeFiles -or
+ -name cmake.depends -or
+ -name cmake.check_depends -or
+ -name CMakeCache.txt -or
+ -name cmake.check_cache -or
+ -name *.cmake -or
+ -name Makefile -or
+ -name core -or
+ -name core.* -or
+ -name gmon.out -or
+ -name install_manifest.txt -or
+ -name *.pc -or
+ -name *~ \)
+ | grep -v TC | xargs rm -rf
+ TARGET distclean
+ VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100755
index 0000000..f94008a
--- /dev/null
+++ b/LICENSE.APLv2
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ 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
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
+
diff --git a/NOTICE b/NOTICE
new file mode 100755
index 0000000..ccdad52
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE file for Apache License terms and conditions.
diff --git a/capi-media-tool.manifest b/capi-media-tool.manifest
new file mode 100755
index 0000000..59167d9
--- /dev/null
+++ b/capi-media-tool.manifest
@@ -0,0 +1,8 @@
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+ <assign>
+ <filesystem path="/usr/bin/media_packet_test" label="_" exec_label="none" />
+ </assign>
+</manifest>
diff --git a/capi-media-tool.pc.in b/capi-media-tool.pc.in
new file mode 100755
index 0000000..afda32e
--- /dev/null
+++ b/capi-media-tool.pc.in
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/media
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
diff --git a/doc/capi_media_tool_doc.h b/doc/capi_media_tool_doc.h
new file mode 100755
index 0000000..e58ec44
--- /dev/null
+++ b/doc/capi_media_tool_doc.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 __TIZEN_MEDIA_TOOL_DOC_H__
+#define __TIZEN_MEDIA_TOOL_DOC_H__
+
+
+/**
+ * @file capi_media_tool_doc.h
+ * @brief This file contains high level documentation of the CAPI MEDIA TOOL API.
+ */
+
+/**
+ * @defgroup CAPI_MEDIA_TOOL_MODULE Media Tool
+ * @brief The @ref CAPI_MEDIA_TOOL_MODULE APIs provides functions for AV packet buffer for interworking between mutimedia framework module .
+ * @ingroup CAPI_MEDIA_FRAMEWORK
+ *
+ * @section CAPI_MEDIA_TOOL_MODULE_HEADER Required Header
+ * \#include <media_packet.h>
+ *
+ * @section CAPI_MEDIA_TOOL_MODULE_OVERVIEW Overview
+ *
+ * MEDIA TOOL API allows :
+ *- Create media_packet handle and Allocate buffer to heap or tbm_surface
+ *- Set and Get metadata of media packet
+ *
+ * The media packet handle is created by caller.
+ * After creating media_packet_h handle, the caller can set & get other meta datas.
+ *
+ */
+
+/**
+ * @defgroup CAPI_MEDIA_TOOL_MEDIA_FORMAT_MODULE Media Format
+ * @brief The @ref CAPI_MEDIA_TOOL_MEDIA_FORMAT_MODULE APIs provides functions for specify video or audio information.
+ * @ingroup CAPI_MEDIA_TOOL_MODULE
+ *
+ * @section CAPI_MEDIA_TOOL_MEDIA_FORMAT_MODULE_HEADER Required Header
+ * \#include <media_format.h>
+ */
+
+#endif // __TIZEN_MEDIA_TOOL_DOC_H__
diff --git a/include/media_format.h b/include/media_format.h
new file mode 100755
index 0000000..53d4d82
--- /dev/null
+++ b/include/media_format.h
@@ -0,0 +1,407 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 __TIZEN_MEDIA_FORMAT_H__
+#define __TIZEN_MEDIA_FORMAT_H__
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file media_format.h
+ * @brief This file contains the capi media tool API.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_TOOL_MEDIA_FORMAT_MODULE
+ * @{
+ */
+
+/**
+ * @brief Media Format handle type.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct media_format_s* media_format_h;
+
+
+/**
+ * @brief Enumerations of media format error
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum
+{
+ MEDIA_FORMAT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ MEDIA_FORMAT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ MEDIA_FORMAT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ MEDIA_FORMAT_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
+ MEDIA_FORMAT_ERROR_FILE_NO_SPACE_ON_DEVICE = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */
+} media_format_error_e;
+
+
+/**
+ * @brief Enumeration for media format type.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ MEDIA_FORMAT_NONE = 0x00000000, /**< media format type is NONE */
+ MEDIA_FORMAT_AUDIO = 0x01000000, /**< media format type is AUDIO */
+ MEDIA_FORMAT_VIDEO = 0x02000000, /**< media format type is VIDEO */
+ MEDIA_FORMAT_TEXT = 0x03000000, /**< media format type is TEXT */
+ MEDIA_FORMAT_UNKNOWN = 0x0a000000, /**< media format type is UNKNOWN */
+} media_format_type_e;
+
+/**
+ * @brief Enumeration for media format data type.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ MEDIA_FORMAT_ENCODED = 0x10000000, /**< media format data type is encoded type */
+ MEDIA_FORMAT_RAW = 0x20000000, /**< media format data type is raw type */
+} media_format_data_type_e;
+
+/**
+ * @brief Enumeration for media format MIME type.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+
+/* TODO : More an more audio/video types are needed !!!! */
+/* TODO : consider to make those enumerations into a combination of bitwised structure
+ * Then we can check just few bits rather than compare all items.
+*/
+typedef enum {
+ /* Audio */
+ MEDIA_FORMAT_L16 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1010), /**< media format mime type is L16, AUDIO*/
+ MEDIA_FORMAT_ALAW = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1020), /**< media format mime type is ALAW, AUDIO*/
+ MEDIA_FORMAT_ULAW = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1030), /**< media format mime type is ULAW, AUDIO */
+ MEDIA_FORMAT_AMR = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1040), /**< media format mime type is AMR, AUDIO */
+ MEDIA_FORMAT_G729 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1050), /**< media format mime type is G729, AUDIO*/
+ MEDIA_FORMAT_AAC = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1060), /**< media format mime type is AAC, AUDIO*/
+ MEDIA_FORMAT_MP3 = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_ENCODED | 0x1070), /**< media format mime type is MP3, AUDIO*/
+
+ MEDIA_FORMAT_PCM = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1510), /**< media format mime type is PCM, AUDIO*/
+ MEDIA_FORMAT_PCMA = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1520), /**< media format mime type is PCM A-law, AUDIO*/
+ MEDIA_FORMAT_PCMU = (MEDIA_FORMAT_AUDIO | MEDIA_FORMAT_RAW | 0x1530), /**< media format mime type is PCM U-law, AUDIO */
+
+ /* Video */
+ MEDIA_FORMAT_H261 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2010), /**< media format mime type is H261, VIDEO */
+ MEDIA_FORMAT_H263 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2020), /**< media format mime type is H263, VIDEO */
+ MEDIA_FORMAT_H263P = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2021), /**< media format mime type is H263P, VIDEO */
+ MEDIA_FORMAT_H264_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2030), /**< media format mime type is H264_SP, VIDEO */
+ MEDIA_FORMAT_H264_MP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2031), /**< media format mime type is H264_MP, VIDEO */
+ MEDIA_FORMAT_H264_HP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2032), /**< media format mime type is H264_HP, VIDEO */
+ MEDIA_FORMAT_MJPEG = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2040), /**< media format mime type is MJPEG, VIDEO */
+ MEDIA_FORMAT_MPEG1 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2050), /**< media format mime type is MPEG1, VIDEO */
+ MEDIA_FORMAT_MPEG2_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2060), /**< media format mime type is MPEG2_SP, VIDEO */
+ MEDIA_FORMAT_MPEG2_MP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2061), /**< media format mime type is MPEG2_MP, VIDEO */
+ MEDIA_FORMAT_MPEG2_HP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2062), /**< media format mime type is MPEG2_HP, VIDEO */
+ MEDIA_FORMAT_MPEG4_SP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2070), /**< media format mime type is MPEG4_SP, VIDEO */
+ MEDIA_FORMAT_MPEG4_ASP = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_ENCODED | 0x2071), /**< media format mime type is MPEG4_ASP, VIDEO */
+
+ MEDIA_FORMAT_I420 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2510), /**< media format mime type is I420, VIDEO */
+ MEDIA_FORMAT_NV12 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2520), /**< media format mime type is NV12, VIDEO */
+ MEDIA_FORMAT_NV12T = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2530), /**< media format mime type is NV12T, VIDEO */
+ MEDIA_FORMAT_YV12 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2540), /**< media format mime type is YV12, VIDEO */
+ MEDIA_FORMAT_NV21 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2550), /**< media format mime type is NV21, VIDEO */
+ MEDIA_FORMAT_NV16 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2560), /**< media format mime type is NV16, VIDEO */
+ MEDIA_FORMAT_YUYV = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2570), /**< media format mime type is YUYV, VIDEO */
+ MEDIA_FORMAT_UYVY = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2580), /**< media format mime type is UYVY, VIDEO */
+ MEDIA_FORMAT_422P = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x2590), /**< media format mime type is 422P, VIDEO */
+ MEDIA_FORMAT_RGB565 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25a0), /**< media format mime type is RGB565, VIDEO */
+ MEDIA_FORMAT_RGB888 = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25b0), /**< media format mime type is RGB888, VIDEO */
+ MEDIA_FORMAT_RGBA = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25c0), /**< media format mime type is RGBA, VIDEO */
+ MEDIA_FORMAT_ARGB = (MEDIA_FORMAT_VIDEO | MEDIA_FORMAT_RAW | 0x25d0), /**< media format mime type is ARGB, VIDEO */
+
+ MEDIA_FORMAT_MAX /**< media format mime type is MEDIA_FORMAT_MAX, Do not use */
+} media_format_mimetype_e;
+
+/**
+ * @brief Enumeration for media color model.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+ MEDIA_COLOR_MODEL_NONE, /**< media format color model is NONE */
+ MEDIA_COLOR_MODEL_RGB, /**< media format color model is RGB */
+ MEDIA_COLOR_MODEL_YUV /**< media format color model is YUV */
+} media_format_color_model_e;
+
+
+/**
+ * @brief Creates a media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details It creates media format. and reference count will be set to 1
+ For destroying media_format_h handle, use media_format_unref()
+ * @param[out] fmt allocated media_format_h
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_ref()
+ * @see media_format_unref()
+ */
+int media_format_create(media_format_h* fmt);
+
+/**
+ * @brief Gets video information of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details returns mimetype, width, height, average bps, max bps of this media format
+ * @param[in] fmt media_format_h to get video information
+ * @param[out] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_H264_HP
+ * @param[out] width width of the video
+ * @param[out] height height of the video
+ * @param[out] avg_bps average bps of the video
+ * @param[out] max_bps max bps of the video
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_set_video_mime()
+ * @see media_format_set_video_width()
+ * @see media_format_set_video_height()
+ * @see media_format_set_video_avg_bps()
+ * @see media_format_set_video_max_bps()
+ */
+int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e* mimetype, int* width, int* height, int* avg_bps, int* max_bps);
+
+/**
+ * @brief Gets audio information of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details returns mimetype, channels, height, samplerate bps, max bps of this media format
+ * @param[in] fmt media_format_h to get audio information
+ * @param[out] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_PCM
+ * @param[out] channel channel of the audio
+ * @param[out] samplerate sampling rate of the audio
+ * @param[out] bit bit resolution of the audio
+ * @param[out] avg_bps average bps of the audio
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_set_audio_mime()
+ * @see media_format_set_audio_channel()
+ * @see media_format_set_audio_samplerate()
+ * @see media_format_set_audio_bit()
+ * @see media_format_set_audio_avg_bps()
+ */
+int media_format_get_audio_info(media_format_h fmt, media_format_mimetype_e* mimetype, int* channel, int* samplerate, int* bit, int* avg_bps);
+
+/**
+ * @brief Sets video MIME type of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets MIME type
+ * @param[in] fmt media_format_h to set
+ * @param[in] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_H264_HP
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_video()
+ */
+int media_format_set_video_mime(media_format_h fmt, media_format_mimetype_e mimetype);
+
+/**
+ * @brief Sets video width of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets video width
+ * @param[in] fmt media_format_h to set
+ * @param[in] width width of the video
+ * @pre must set video MIME type by media_format_set_video_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_video()
+ */
+int media_format_set_video_width(media_format_h fmt, int width);
+
+
+/**
+ * @brief Sets video height of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets video height
+ * @param[in] fmt media_format_h to set
+ * @param[in] height height of the video
+ * @pre must set video MIME type by media_format_set_video_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_video()
+ */
+int media_format_set_video_height(media_format_h fmt, int height);
+
+/**
+ * @brief Sets video avg_bps of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets avg_bps
+ * @param[in] fmt media_format_h to set
+ * @param[in] avg_bps average bps of the video
+ * @pre must set video MIME type by media_format_set_video_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_video()
+ */
+int media_format_set_video_avg_bps(media_format_h fmt, int avg_bps);
+
+/**
+ * @brief Sets video max_bps of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets max_bps
+ * @param[in] fmt media_format_h to set
+ * @param[in] max_bps max bps of the video
+ * @pre must set video MIME type by media_format_set_video_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_video()
+ */
+int media_format_set_video_max_bps(media_format_h fmt, int max_bps);
+
+/**
+ * @brief Sets audio MIME type of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets MIME type
+ * @param[in] fmt media_format_h to set audio information
+ * @param[in] mimetype media_format_mimetype_e , ex) MEDIA_FORMAT_PCM
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_audio()
+ */
+int media_format_set_audio_mime(media_format_h fmt, media_format_mimetype_e mimetype);
+
+/**
+ * @brief Sets audio channel of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets audio channel
+ * @param[in] fmt media_format_h to set audio information
+ * @param[in] channel channel of the audio
+ * @pre must set audio MIME type by media_format_set_audio_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_audio()
+ */
+int media_format_set_audio_channel(media_format_h fmt, int channel);
+
+/**
+ * @brief Sets audio samplerate of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets audio samplerate of this media format
+ * @param[in] fmt media_format_h to set
+ * @param[in] samplerate sampling rate of the audio
+ * @pre must set audio MIME type by media_format_set_audio_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_audio()
+ */
+int media_format_set_audio_samplerate(media_format_h fmt, int samplerate);
+
+ /**
+ * @brief Sets audio bit of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets audio bit resolution of this media format
+ * @param[in] fmt media_format_h to set
+ * @param[in] bit bit of the audio
+ * @pre must set audio MIME type by media_format_set_audio_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_audio()
+ */
+int media_format_set_audio_bit(media_format_h fmt, int bit);
+
+ /**
+ * @brief Sets audio avg_bps of media format
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Sets audio avg_bps of this media format
+ * @param[in] fmt media_format_h to set
+ * @param[in] avg_bps avg_bps of the audio
+ * @pre must set audio MIME type by media_format_set_audio_mime()
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_get_audio()
+ */
+int media_format_set_audio_avg_bps(media_format_h fmt, int avg_bps);
+
+/**
+ * @brief Increase reference count of media_format_h object
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details increase ref_count of media_format_h
+ * @param[in] fmt exist media_format_h
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_unref()
+ */
+int media_format_ref(media_format_h fmt);
+
+/**
+ * @brief Decrease reference count of media_format_h object
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details decrease ref_count of media_format_h
+ * @param[in] fmt exist media_format_h
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_ref()
+ */
+int media_format_unref(media_format_h fmt);
+
+/**
+ * @brief Check whether the media_format_h is writable or not.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details Check the number of media_format's ref_count
+ * @param[in] fmt exist media_format_h
+ * @param[out] is_writable if ref_count is 1, return true. if not, return false
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_format_is_writable(media_format_h fmt, bool* is_writable);
+
+ /**
+ * @brief Returns a writable copy of media_format_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @details If there is only one reference count on fmt, the caller must be the owner,
+ * and so this function will return the object unchanged.
+ * while, if there is more than one reference count on the object, a new object will be returned.
+ * The caller will own a reference to the returned object.
+ * In a nutshell, this function unrefs the fmt and refs the out_fmt returned.
+ * Don't access fmt after calling this function.
+ * @param[in] fmt exist media_format_h , don't access it after calling this function.
+ * @param[out] out_fmt new copied media_format_h, the caller is owner of this object.
+ * @retval #MEDIA_FORMAT_ERROR_NONE Successful
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_FORMAT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_FORMAT_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_format_make_writable(media_format_h fmt, media_format_h* out_fmt);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_MEDIA_AV_PACKET_BUFFER_H__ */
diff --git a/include/media_format_private.h b/include/media_format_private.h
new file mode 100755
index 0000000..c44b1b7
--- /dev/null
+++ b/include/media_format_private.h
@@ -0,0 +1,151 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 __TIZEN_MEDIA_FORMAT_PRIVATE_H__
+#define __TIZEN_MEDIA_FORMAT_PRIVATE_H__
+
+#include <media_format.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "TIZEN_MEDIA_TOOL"
+
+#define MEDIA_FORMAT_CHECK_CONDITION(condition,error,msg) \
+ if(condition) {} else \
+ { LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg,error); return error;}; \
+
+#define MEDIA_FORMAT_INSTANCE_CHECK(media_format) \
+ MEDIA_FORMAT_CHECK_CONDITION(media_format != NULL, MEDIA_FORMAT_ERROR_INVALID_PARAMETER, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
+
+#define MEDIA_FORMAT_NULL_ARG_CHECK(arg) \
+ MEDIA_FORMAT_CHECK_CONDITION(arg != NULL, MEDIA_FORMAT_ERROR_INVALID_PARAMETER, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
+
+#if 0
+#define atomic_int_inc(atomic) \
+ (__extension__({ \
+ STATIC_ASSERT (sizeof *(atomic) == sizeof (int)); \
+ (void) (0 ? *(atomic) ^ *(atomic) : 0); \
+ (void) __sync_fetch_and_add ((atomic), 1); \
+ }))
+#endif
+
+
+#define MEDIA_FORMAT_CAST(obj) ((media_format_s*)(obj))
+
+/**
+ * @brief Check whether given media format is for audio or not
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_IS_AUDIO(x_fmt) (MEDIA_FORMAT_CAST(x_fmt)->mimetype & MEDIA_FORMAT_AUDIO)
+
+/**
+ * @brief Check whether given media format is for video or not
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_IS_VIDEO(x_fmt) (MEDIA_FORMAT_CAST(x_fmt)->mimetype & MEDIA_FORMAT_VIDEO)
+
+/**
+ * @brief Check whether given media format is for text or not
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_IS_TEXT(x_fmt) (false)
+
+/**
+ * @brief Check whether given media format is for raw type or not
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_IS_RAW(x_fmt) (MEDIA_FORMAT_CAST(x_fmt)->mimetype & MEDIA_FORMAT_RAW)
+
+/**
+ * @brief Check whether given media format is for encoded type or not
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_IS_ENCODED(x_fmt) (MEDIA_FORMAT_CAST(x_fmt)->mimetype & MEDIA_FORMAT_ENCODED)
+
+/**
+ * @brief Gets the number of media format ref_count
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_GET_REFCOUNT(x_fmt) (g_atomic_int_get(&(MEDIA_FORMAT_CAST(x_fmt))->ref_count))
+
+/**
+ * @brief Check whether given media format is writable or not
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_IS_WRITABLE(x_fmt) (MEDIA_FORMAT_GET_REFCOUNT(x_fmt) == 1)
+
+/**
+ * @brief increase the media format's ref_count
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_INC_REFCOUNT(x_fmt) (g_atomic_int_inc(&(MEDIA_FORMAT_CAST(x_fmt))->ref_count))
+
+/**
+ * @brief decrease the media format's ref_count and return true if ref_count become zero.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_FORMAT_DEC_REFCOUNT_TEST(x_fmt) (g_atomic_int_dec_and_test(&(MEDIA_FORMAT_CAST(x_fmt))->ref_count))
+
+/**
+ * @brief Media format for configuring video codec.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _media_format_video_spec_s {
+ int width; /**< media format video width */
+ int height; /**< media format video height */
+ int avg_bps; /**< media format video average bps */
+ int max_bps; /**< media format video max bps */
+} media_format_video_spec_s;
+
+/**
+ * @brief Media format for configuring audio codec.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _media_fomat_audio_spec_s {
+ int channel; /**< media format audio's the number of channels */
+ int samplerate; /**< media format audio sampling rate */
+ int bit; /**< media format audio's the bit resolution */
+ int avg_bps; /**< media format audio max bps */
+} media_format_audio_spec_s;
+
+/**
+ * @brief Structure of media format.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct _media_format_s
+{
+ int ref_count; /**< media format struct reference count */
+ media_format_mimetype_e mimetype; /**< media format struct mimetype of media_format_mimetype_e */
+
+ union {
+ media_format_audio_spec_s audio; /**< media format struct audio of media_format_audio_spec_s */
+ media_format_video_spec_s video; /**< media format struct video of media_format_video_spec_s */
+ }detail;
+
+} media_format_s;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_MEDIA_FORMAT_PRIVATE_H__ */
+
diff --git a/include/media_packet.h b/include/media_packet.h
new file mode 100755
index 0000000..8c60d20
--- /dev/null
+++ b/include/media_packet.h
@@ -0,0 +1,714 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 __TIZEN_MEDIA_PACKET_H__
+#define __TIZEN_MEDIA_PACKET_H__
+
+#include <tizen.h>
+#include <stdint.h>
+
+#include <media_format.h>
+
+#include <tbm_type.h>
+#include <tbm_surface.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file media_packet.h
+ * @brief This file contains the capi media tool API.
+ */
+
+/**
+ * @addtogroup CAPI_MEDIA_TOOL_MODULE
+ * @{
+ */
+
+/**
+ * @brief The Media Packet handle.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef struct media_packet_s *media_packet_h;
+
+/**
+ * @brief Enumeration for media packet error.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum
+{
+ MEDIA_PACKET_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ MEDIA_PACKET_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ MEDIA_PACKET_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ MEDIA_PACKET_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
+ MEDIA_PACKET_ERROR_FILE_NO_SPACE_ON_DEVICE = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */
+} media_packet_error_e;
+
+/**
+ * @brief Enumeration for media buffer flag.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum
+{
+ MEDIA_PACKET_CODEC_CONFIG = 0x1, /**< The buffer marked as such contains codec initialization/codec specific data instead of media data */
+ MEDIA_PACKET_END_OF_STREAM = 0x2, /**< The end of stream */
+ MEDIA_PACKET_SYNC_FRAME = 0x4, /**< The buffer marked as such contains the data for a sync frame */
+} media_buffer_flags_e;
+
+/**
+ * @brief Enumeration for the return values of media packet finalize call back functions.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @see media_packet_finalize_cb()
+ */
+typedef enum _finalize_cb_ret
+{
+ MEDIA_PACKET_REUSE = 0, /**< Packet handle is not destroyed */
+ MEDIA_PACKET_FINALIZE, /**< Destroy packet handle */
+} media_packet_finalize_cb_ret_t;
+
+/**
+ * @brief Called when the media packet is destroyed.
+ * @details It will be invoked when media_packet_destroy() is called.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] error_code The error code of #media_packet_error_e
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @pre It will be invoked when media packet is destroyed.
+ *
+ * @retval #MEDIA_PACKET_REUSE Packet handle is not destroyed, the handle will be reused.
+ * @retval #MEDIA_PACKET_FINALIZE Destroy media packet handle, the handle will not be reused.
+ *
+ * @see media_packet_destroy()
+ * @see media_packet_create_alloc()
+ * @see media_packet_create()
+ * @see media_packet_copy()
+ * @see media_packet_create_from_tbm_surface()
+ */
+typedef int (*media_packet_finalize_cb)(media_packet_h packet, int error_code, void *user_data);
+
+/**
+ * @brief Creates a media packet handle and allocates buffer.
+ * @details The buffer will be allocated to heap or tbm_surface.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @remarks The @c packet must be released by using media_packet_destroy().
+ * @param[in] fmt The allocated #media_format_h by caller
+ * @param[in] fcb The media_packet_finalize_cb() to register
+ * @param[in] fcb_data The user data to be passed to the media_packet_finalize_cb() function
+ * @param[out] packet A new handle for media packet
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Must have media_format_h instance by media_format_create()
+ * @post Must do media_format_unref()
+ *
+ * @see media_packet_destroy()
+ * @see media_packet_finalize_cb()
+ * @see media_format_unref()
+ * @par Example
+ @code
+ #include <media_packet.h>
+
+ {
+ media_format_h fmt;
+ media_packet_h packet;
+
+ media_format_create(&fmt);
+ media_format_set_video_mime(fmt, MEDIA_FORMAT_H264_HP);
+ media_format_set_video_width(fmt, 640);
+ media_format_set_video_height(fmt, 480);
+ media_format_set_video_avg_bps(fmt, 10000000);
+ media_format_set_video_max_bps(fmt, 15000000);
+
+ media_packet_create_alloc (fmt, _finalize_callback, fcb_data, &packet);
+ media_format_unref(fmt);
+
+ ...
+ media_packet_destroy(packet);
+ }
+
+ int _finalize_callback(media_packet_h packet, int err, void* userdata)
+ {
+ ...
+ return MEDIA_PACKET_FINALIZE;
+ }
+
+ @endcode
+ */
+int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet);
+
+/**
+ * @brief Creates a media packet handle.
+ * @details It creates only media packet handle without allocated buffer.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @remarks The @c packet must be released by using media_packet_destroy().
+ * @param[in] fmt The allocated #media_format_h by caller
+ * @param[in] fcb The media_packet_finalize_cb() to register
+ * @param[in] fcb_data The user data to be passed to the media_packet_finalize_cb() function
+ * @param[out] packet A new handle for media packet
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Must have media_format_h instance by media_format_create()
+ * @post Must do media_format_unref()
+ *
+ * @see media_packet_destroy()
+ * @see media_packet_finalize_cb()
+ * @see media_format_unref()
+ * @par Example
+ @code
+ #include <media_packet.h>
+
+ {
+ media_format_h fmt;
+ media_packet_h packet;
+
+ media_format_create(&fmt);
+ media_format_set_video_mime(fmt, MEDIA_FORMAT_H264_HP);
+ media_format_set_video_width(fmt, 640);
+ media_format_set_video_height(fmt, 480);
+ media_format_set_video_avg_bps(fmt, 10000000);
+ media_format_set_video_max_bps(fmt, 15000000);
+
+ media_packet_create (fmt, _finalize_callback, fcb_data, &packet);
+ media_format_unref(fmt);
+
+ ...
+ media_packet_destroy(packet);
+ }
+
+ int _finalize_callback(media_packet_h packet, int err, void* userdata)
+ {
+ ...
+ return MEDIA_PACKET_FINALIZE;
+ }
+
+ @endcode
+ */
+int media_packet_create(media_format_h fmt, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet);
+
+/**
+ * @brief Copies a media packet handle.
+ * @details It re-creates only media packet handle with exist media packet handle.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @remarks The @c new_packet must be released by using media_packet_destroy().
+ * @param[in] org_packet The existing media packet handle
+ * @param[in] fcb The media_packet_finalize_cb() to register
+ * @param[in] fcb_data The user data to be passed to the media_packet_finalize_cb() function
+ * @param[out] new_packet A new handle for media packet
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_packet_destroy()
+ * @see media_packet_finalize_cb()
+ */
+int media_packet_copy(media_packet_h org_packet, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h* new_packet);
+
+/**
+ * @brief Allocates buffer with media packet handle.
+ * @details Before using media_packet_alloc(), media packet handle must be exist.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The existing media packet handle
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_packet_create()
+ * @see media_packet_destroy()
+ */
+int media_packet_alloc(media_packet_h packet);
+
+/**
+ * @brief Creates media packet handle and allocates buffer with #tbm_surface_h.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @remarks The @c packet must be released by using media_packet_destroy().
+ * @param[in] fmt The allocated #media_format_h by caller
+ * @param[in] surface The #tbm_surface_h by caller
+ * @param[in] fcb The media_packet_finalize_cb() to register
+ * @param[in] fcb_data The user data to be passed to the media_packet_finalize_cb() function
+ * @param[out] packet A new handle for media packet
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Must have media_format_h instance by media_format_create()
+ * @post Must do media_format_unref()
+ *
+ * @see media_packet_destroy()
+ * @see media_packet_finalize_cb()
+ * @see media_format_unref()
+ * @par Example
+ @code
+ #include <media_packet.h>
+
+ {
+ media_format_h fmt;
+ media_packet_h packet;
+
+ media_format_create(&fmt);
+ media_format_set_video_mime(fmt, MEDIA_FORMAT_H264_HP);
+ media_format_set_video_width(fmt, 640);
+ media_format_set_video_height(fmt, 480);
+ media_format_set_video_avg_bps(fmt, 10000000);
+ media_format_set_video_max_bps(fmt, 15000000);
+
+ media_packet_create_from_tbm_surface (fmt, surface, _finalize_callback, fcb_data, &packet);
+ media_format_unref(fmt);
+
+ ...
+ media_pacekt_destory(packet);
+ }
+
+ int _finalize_callback(media_packet_h packet, int err, void* userdata)
+ {
+ ...
+ return MEDIA_PACKET_FINALIZE;
+ }
+
+ @endcode
+ */
+int media_packet_create_from_tbm_surface(media_format_h fmt, tbm_surface_h surface, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet);
+
+/**
+ * @brief Gets #media_format_h of media packet
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] fmt The media format of media packet
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see media_format_unref()
+ * @par Example
+ @code
+ #include <media_packet.h>
+
+ {
+ media_format_h* fmt;
+
+ media_packet_get_format (pakcet, &fmt);
+ ..
+
+ media_format_unref(fmt);
+ ...
+ }
+
+ @endcode
+ */
+int media_packet_get_format(media_packet_h packet, media_format_h *fmt);
+
+/**
+ * @brief Sets #media_format_h of media packet
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] fmt The #media_format_h to set
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see media_format_unref()
+ * @par Example
+ @code
+ #include <media_packet.h>
+
+ {
+ media_format_h fmt;
+
+ media_packet_set_format (pakcet, fmt);
+ ..
+
+ media_format_unref(fmt);
+ ...
+ }
+
+ @endcode
+ */
+int media_packet_set_format(media_packet_h packet, media_format_h fmt);
+
+/**
+ * @brief Sets PTS of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] pts The PTS value to set
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_set_pts(media_packet_h packet, uint64_t pts);
+
+/**
+ * @brief Sets DTS of media packet handle.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] dts The DTS value to set
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_set_dts(media_packet_h packet, uint64_t dts);
+
+/**
+ * @brief Sets PTS of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] duration The duration value to set
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_set_duration(media_packet_h packet, uint64_t duration);
+
+/**
+ * @brief Sets buffer size of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] size The buffer size value to set
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_set_buffer_size(media_packet_h packet, uint64_t size);
+
+/**
+ * @brief Gets PTS of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] pts The PTS value to get
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int media_packet_get_pts(media_packet_h packet, uint64_t *pts);
+
+/**
+ * @brief Gets DTS of media packet
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] dts The DTS value to get
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_dts(media_packet_h packet, uint64_t *dts);
+
+/**
+ * @brief Gets duration of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] duration The duration value to get
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_duration(media_packet_h packet, uint64_t *duration);
+
+/**
+ * @brief Gets buffer size of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] size The buffer size value to get
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_buffer_size(media_packet_h packet, uint64_t *size);
+
+/**
+ * @brief Gets buffer data pointer of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] data The allocated buffer data pointer
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_buffer_data_ptr(media_packet_h packet, void **data);
+
+/**
+ * @brief Gets TBM surface data of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] surface The tbm_surface data pointer
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_tbm_surface(media_packet_h packet, tbm_surface_h *surface);
+
+/**
+ * @brief Sets extra data of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] extra The extra data to set
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_set_extra(media_packet_h packet, void *extra);
+
+/**
+ * @brief Gets extra data of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] extra The extra data to get
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_get_extra(media_packet_h packet, void **extra);
+
+/**
+ * @brief Checks whether the given media packet is for video.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] is_video @c true if the given media packet is for video,
+ * otherwise @c false if the given media packet is not for video
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_format_mimetype_e
+ * @see media_format_type_e
+ */
+int media_packet_is_video(media_packet_h packet, bool *is_video);
+
+/**
+ * @brief Checks whether the given media packet is for audio.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] is_audio @c true if the given media packet is for audio,
+ * otherwise @c false if the given media packet is not for audio
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ * @see media_format_mimetype_e
+ * @see media_format_type_e
+ */
+int media_packet_is_audio(media_packet_h packet, bool *is_audio);
+
+/**
+ * @brief Checks whether the given media packet is encoded type.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] is_encoded @c true if the given media packet is encoded,
+ * otherwise @c false if the given media packet is not encoded
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_format_mimetype_e
+ * @see media_format_data_type_e
+ */
+int media_packet_is_encoded(media_packet_h packet, bool *is_encoded);
+
+/**
+ * @brief Checks whether the given media packet is raw type.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] is_raw @c true if the given media packet is for raw video,
+ * otherwise @c false if the given media packet is not for raw video
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_format_mimetype_e
+ * @see media_format_data_type_e
+ */
+int media_packet_is_raw(media_packet_h packet, bool *is_raw);
+
+/**
+ * @brief Sets #media_buffer_flags_e of media packet.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] flags The media_buffer_flags_e of media packet to set
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_buffer_flags_e
+ * @see media_packet_unset_flags()
+ */
+int media_packet_set_flags(media_packet_h packet, media_buffer_flags_e flags);
+
+/**
+ * @brief Unsets media_buffer_flags_e of media packet
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[in] flags The media_buffer_flags_e of media packet to unset
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_buffer_flags_e
+ * @see media_packet_set_flags()
+ * */
+int media_packet_unset_flags(media_packet_h packet, media_buffer_flags_e flags);
+
+/**
+ * @brief Checks whether the given media packet is codec data.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] is_codec_config @c true if the given media packet is for codec data,
+ * otherwise @c false if the given media packet is not for codec data
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_format_mimetype_e
+ * @see media_format_data_type_e
+ */
+int media_packet_is_codec_config(media_packet_h packet, bool *is_codec_config);
+
+/**
+ * @brief Checks whether the given media packet is eos.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] is_eos @c true if the given media packet is for eos,
+ * otherwise @c false if the given media packet is not for eos
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_format_mimetype_e
+ * @see media_format_data_type_e
+ */
+int media_packet_is_end_of_stream(media_packet_h packet, bool *is_eos);
+
+/**
+ * @brief Checks whether the given media packet is sync frame.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] is_sync @c true if the given media packet is for sync frame,
+ * otherwise @c false if the given media packet is not for sync frame
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_format_mimetype_e
+ * @see media_format_data_type_e
+ */
+int media_packet_is_sync_frame(media_packet_h packet, bool *is_sync);
+
+/**
+ * @brief Checks whether the allocated buffer is tbm surface or not.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The media packet handle
+ * @param[out] has_tbm_surface @c true if the given media packet's allocated buffer is tbm surface,
+ * otherwise @c false if the given media packet's allocated buffer is not tbm surface
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ */
+int media_packet_has_tbm_surface_buffer(media_packet_h packet, bool* has_tbm_surface);
+
+/**
+ * @brief Destroys the media packet handle.
+ * @details The registered finalize_callback() function will be invoked to destroy the media packet handle.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ *
+ * @param[in] packet The handle to media packet to be destroyed
+ *
+ * @retval #MEDIA_PACKET_ERROR_NONE Successful
+ * @retval #MEDIA_PACKET_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_PACKET_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @see media_packet_create_alloc()
+ * @see media_packet_create()
+ * @see media_packet_copy()
+ * @see media_packet_create_from_tbm_surface()
+ */
+int media_packet_destroy(media_packet_h packet);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_MEDIA_AV_PACKET_BUFFER_H__ */
diff --git a/include/media_packet_private.h b/include/media_packet_private.h
new file mode 100755
index 0000000..e9d9176
--- /dev/null
+++ b/include/media_packet_private.h
@@ -0,0 +1,135 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 __TIZEN_MEDIA_PACKET_PRIVATE_H__
+#define __TIZEN_MEDIA_PACKET_PRIVATE_H__
+
+#include <media_packet.h>
+#include <media_format_private.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "TIZEN_MEDIA_TOOL"
+
+#define MEDIA_PACKET_CHECK_CONDITION(condition,error,msg) \
+ if(condition) {} else \
+ { LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg,error); return error;}; \
+
+#define MEDIA_PACKET_INSTANCE_CHECK(media_packet) \
+ MEDIA_PACKET_CHECK_CONDITION(media_packet != NULL, MEDIA_PACKET_ERROR_INVALID_PARAMETER, "MEDIA_PACKET_ERROR_INVALID_PARAMETER")
+
+#define MEDIA_PACKET_NULL_ARG_CHECK(arg) \
+ MEDIA_PACKET_CHECK_CONDITION(arg != NULL, MEDIA_PACKET_ERROR_INVALID_PARAMETER, "MEDIA_PACKET_ERROR_INVALID_PARAMETER")
+
+/**
+ * @brief Gets pts of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_PTS(arg) (MEDIA_PACKET_CAST(arg)->pts)
+
+/**
+ * @brief Gets dts of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_DTS(arg) (MEDIA_PACKET_CAST(arg)->dts)
+
+/**
+ * @brief Gets duration of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_DURATION(arg) (MEDIA_PACKET_CAST(arg)->duration)
+
+/**
+ * @brief Gets size of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_SIZE(arg) (MEDIA_PACKET_CAST(arg)->size)
+
+/**
+ * @brief Gets data of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_DATA(arg) (MEDIA_PACKET_CAST(arg)->data)
+
+/**
+ * @brief Gets the buffer flags of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_FLAGS(arg) (MEDIA_PACKET_CAST(arg)->flags)
+
+/**
+ * @brief Gets the buffer config flag of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_CODEC_CONFIG_DATA(arg) (((MEDIA_PACKET_CAST(arg)->flags) >> 0) & 0x001)
+
+/**
+ * @brief Gets the buffer eos flag of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_CODEC_END_OF_STREAM(arg) (((MEDIA_PACKET_CAST(arg)->flags) >> 1) & 0x001)
+
+/**
+ * @brief Gets the buffer sync flag of media_packet_h
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_CODEC_SYNC_FRAME(arg) (((MEDIA_PACKET_CAST(arg)->flags) >> 2) & 0x001)
+
+/**
+ * @brief Casting to media_packet_s
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+#define MEDIA_PACKET_CAST(obj) ((media_packet_s*)(obj))
+
+
+typedef enum {
+ MEDIA_BUFFER_TYPE_TBM_SURFACE,
+ MEDIA_BUFFER_TYPE_EXTERNAL_TBM_SURFACE,
+ MEDIA_BUFFER_TYPE_NORMAL,
+ MEDIA_BUFFER_TYPE_AUTO,
+ MEDIA_BUFFER_TYPE_MAX
+} media_buffer_type_e;
+
+typedef struct _media_packet_s{
+
+ uint64_t pts;
+ uint64_t dts;
+ uint64_t duration;
+ uint64_t size;
+ void* data;
+ void* surface_data;
+ media_packet_finalize_cb finalizecb_func;
+ void* userdata;
+ bool is_allocated;
+ void *extradata;
+
+ media_format_s* format;
+ media_buffer_type_e type;
+ media_buffer_flags_e flags;
+
+} media_packet_s;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_MEDIA_PACKET_PRIVATE_H__ */
+
diff --git a/packaging/capi-media-tool.spec b/packaging/capi-media-tool.spec
new file mode 100755
index 0000000..c78819f
--- /dev/null
+++ b/packaging/capi-media-tool.spec
@@ -0,0 +1,74 @@
+Name: capi-media-tool
+Summary: A Core API media tool library in Tizen Native API
+Version: 0.1.1
+Release: 0
+Group: Multimedia/API
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(appcore-efl)
+BuildRequires: pkgconfig(libtbm)
+
+Requires(post): /sbin/ldconfig
+Requires(post): libprivilege-control
+Requires(postun): /sbin/ldconfig
+
+%description
+
+
+%package devel
+Summary: A Core API media tool library in Tizen Native API (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+Requires: pkgconfig(libtbm)
+
+%description devel
+
+%prep
+%setup -q
+
+
+%build
+%if 0%{?sec_build_binary_debug_enable}
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+%endif
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+mkdir -p %{buildroot}/usr/bin
+mkdir -p %{buildroot}/opt/usr/devel
+cp test/media_packet_test %{buildroot}/opt/usr/devel
+cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+
+%make_install
+
+%post
+/sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%manifest capi-media-tool.manifest
+%{_libdir}/libcapi-media-tool.so.*
+%{_datadir}/license/%{name}
+/opt/usr/devel/*
+#%{_bindir}/*
+
+%files devel
+%{_includedir}/media/*.h
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libcapi-media-tool.so
+
+
diff --git a/src/media_format.c b/src/media_format.c
new file mode 100755
index 0000000..e7a7fe8
--- /dev/null
+++ b/src/media_format.c
@@ -0,0 +1,484 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dlog.h>
+#include <media_format.h>
+#include <media_format_private.h>
+
+static void _media_format_destroy(media_format_s* fmt);
+
+int media_format_create(media_format_h* fmt)
+{
+ MEDIA_FORMAT_NULL_ARG_CHECK(fmt);
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)malloc(sizeof(media_format_s));
+ if (fmt_handle)
+ {
+ memset(fmt_handle, 0, sizeof(media_format_s));
+ }
+ else
+ {
+ return MEDIA_FORMAT_ERROR_OUT_OF_MEMORY;
+ }
+
+ fmt_handle->ref_count = 1;
+
+ *fmt = (media_format_h)fmt_handle;
+
+ LOGI("The new format handle: %p \n", *fmt);
+
+ return ret;
+}
+
+static void _media_format_destroy(media_format_s* fmt)
+{
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ free(fmt);
+ fmt = NULL;
+}
+
+int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e* mimetype, int* width, int* height, int* avg_bps, int* max_bps)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ if (mimetype)
+ *mimetype = fmt_handle->mimetype;
+ if (width)
+ *width = fmt_handle->detail.video.width;
+ if (height)
+ *height = fmt_handle->detail.video.height;
+ if (avg_bps)
+ *avg_bps = fmt_handle->detail.video.avg_bps;
+ if (max_bps)
+ *max_bps = fmt_handle->detail.video.max_bps;
+
+ return ret;
+}
+
+int media_format_get_audio_info(media_format_h fmt, media_format_mimetype_e* mimetype, int* channel, int* samplerate, int* bit, int* avg_bps)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+ if (mimetype)
+ *mimetype = fmt_handle->mimetype;
+ if (channel)
+ *channel = fmt_handle->detail.audio.channel;
+ if (samplerate)
+ *samplerate = fmt_handle->detail.audio.samplerate;
+ if (bit)
+ *bit = fmt_handle->detail.audio.bit;
+ if (avg_bps)
+ *avg_bps = fmt_handle->detail.audio.avg_bps;
+
+ return ret;
+}
+
+int media_format_set_video_mime(media_format_h fmt, media_format_mimetype_e mimetype)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("The format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(mimetype & MEDIA_FORMAT_VIDEO))
+ {
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->mimetype = mimetype;
+
+ return ret;
+}
+
+int media_format_set_video_width(media_format_h fmt, int width)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("the format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.video.width = width;
+
+ return ret;
+}
+
+int media_format_set_video_height(media_format_h fmt, int height)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("The format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.video.height = height;
+
+ return ret;
+}
+
+int media_format_set_video_avg_bps(media_format_h fmt, int avg_bps)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("The format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.video.avg_bps = avg_bps;
+
+ return ret;
+}
+
+int media_format_set_video_max_bps(media_format_h fmt, int max_bps)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("The format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_VIDEO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_VIDEO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.video.max_bps = max_bps;
+
+ return ret;
+}
+
+
+int media_format_set_audio_mime(media_format_h fmt, media_format_mimetype_e mimetype)
+{
+
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("the format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(mimetype & MEDIA_FORMAT_AUDIO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->mimetype = mimetype;
+
+ return ret;
+}
+
+int media_format_set_audio_channel(media_format_h fmt, int channel)
+{
+
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("the format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.audio.channel = channel;
+
+ return ret;
+}
+
+int media_format_set_audio_samplerate(media_format_h fmt, int samplerate)
+{
+
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("the format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.audio.samplerate = samplerate;
+
+ return ret;
+}
+
+int media_format_set_audio_bit(media_format_h fmt, int bit)
+{
+
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("the format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.audio.bit = bit;
+
+ return ret;
+}
+
+int media_format_set_audio_avg_bps(media_format_h fmt, int avg_bps)
+{
+
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ if (!MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ LOGE("the format can not be changed..\n", __FUNCTION__);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (!(fmt_handle->mimetype & MEDIA_FORMAT_AUDIO))
+ {
+ LOGE("The format handle is not for MEDIA_FORMAT_AUDIO..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
+ }
+
+ fmt_handle->detail.audio.avg_bps = avg_bps;
+
+ return ret;
+}
+
+int media_format_ref(media_format_h fmt)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (MEDIA_FORMAT_GET_REFCOUNT(fmt) <= 0)
+ {
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ g_atomic_int_inc(&fmt_handle->ref_count);
+
+ return ret;
+}
+
+int media_format_unref(media_format_h fmt)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+ bool is_zero;
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (MEDIA_FORMAT_GET_REFCOUNT(fmt) <= 0)
+ {
+ LOGE("The format ref_count is less than 0..\n");
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ is_zero = g_atomic_int_dec_and_test(&fmt_handle->ref_count);
+ if (is_zero)
+ {
+ LOGI("The format handle(%p) will be destroyed..\n", fmt);
+ /* if reference count become 0 , free fmt. */
+ _media_format_destroy(fmt_handle);
+ }
+
+ return ret;
+}
+
+int media_format_is_writable(media_format_h fmt, bool* is_writable)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+ if (MEDIA_FORMAT_GET_REFCOUNT(fmt) <= 0)
+ {
+ LOGE("The format ref_count is less than 0..\n.");
+ ret = MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (g_atomic_int_get(&fmt_handle->ref_count) == 1)
+ {
+ /* if reference count is 1, the caller must be owner. */
+ *is_writable = true;
+ }
+ else
+ {
+ *is_writable = false;
+ }
+
+ return ret;
+}
+
+int media_format_make_writable(media_format_h fmt, media_format_h* out_fmt)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+
+ media_format_s* fmt_handle;
+ fmt_handle = (media_format_s*)fmt;
+
+ if (MEDIA_FORMAT_IS_WRITABLE(fmt))
+ {
+ /* If there is only one reference count on @fmt, the caller must be the owner */
+ *out_fmt = fmt;
+ }
+ else
+ {
+ /* If there is more than one reference on the object, a new media_format_h object will be returned.
+ The caller's reference on @fmt will be removed, and instead the caller will own a reference to the returned object.*/
+ media_format_s* copy;
+ copy = (media_format_s*)malloc(sizeof(media_format_s));
+ if (copy)
+ {
+ memset(copy, 0, sizeof(media_format_s));
+ }
+ else
+ {
+ return MEDIA_FORMAT_ERROR_OUT_OF_MEMORY;
+ }
+
+ memcpy(copy, fmt_handle, sizeof(media_format_s));
+ copy->ref_count = 1;
+
+ if (media_format_unref(fmt) != MEDIA_FORMAT_ERROR_NONE)
+ {
+ free(copy);
+ return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ }
+
+ *out_fmt = (media_format_h)copy;
+ LOGI("the copied new format handle: %p\n", *out_fmt);
+
+ }
+
+ return ret;
+}
+
+
diff --git a/src/media_packet.c b/src/media_packet.c
new file mode 100755
index 0000000..9487a00
--- /dev/null
+++ b/src/media_packet.c
@@ -0,0 +1,1312 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dlog.h>
+#include <media_format.h>
+#include <media_packet.h>
+#include <media_packet_private.h>
+#include <media_format_private.h>
+
+/* NOTE : static internal functions does not check anything on incomming parameters
+ * Caller should takecare it
+ */
+static int _pkt_alloc_buffer(media_packet_s* pkt);
+static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt);
+static uint64_t _pkt_calculate_audio_buffer_size(media_packet_s* pkt);
+static uint32_t _convert_to_tbm_surface_format(media_format_mimetype_e format_type);
+static void* _aligned_malloc_normal_buffer_type (uint64_t size, int alignment);
+static void _aligned_free_normal_buffer_type (void* buffer_ptr);
+
+
+int media_packet_create_alloc(media_format_h fmt, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet)
+{
+ media_packet_s* handle = NULL;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(fmt);
+ MEDIA_PACKET_NULL_ARG_CHECK(packet);
+ if (MEDIA_FORMAT_GET_REFCOUNT(fmt) < 1)
+ {
+ LOGE("The media format handle is corrupted or Not set media info");
+ return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!MEDIA_FORMAT_IS_VIDEO(fmt) && !MEDIA_FORMAT_IS_AUDIO(fmt))
+ {
+ LOGE("The media format handle is not specified. set video info or audio info...");
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ }
+ /* TODO : need more validation on fmt */
+
+ handle = (media_packet_s*)malloc(sizeof(media_packet_s));
+ if (handle != NULL)
+ memset(handle, 0, sizeof(media_packet_s));
+ else
+ {
+ LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__, MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+ ret = MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+ goto fail;
+ }
+
+ /* TODO : need to consider to give application to select buffer type(tbm or heap) */
+
+ /* check if tbm surface is needed.
+ * This time, Only raw video format is considered to be allocated in TBM
+ */
+ if (MEDIA_FORMAT_IS_VIDEO(fmt) && MEDIA_FORMAT_IS_RAW(fmt))
+ {
+ handle->type = MEDIA_BUFFER_TYPE_TBM_SURFACE;
+ }
+ else
+ {
+ handle->type = MEDIA_BUFFER_TYPE_NORMAL;
+ }
+
+ /* take fmt */
+ handle->format = MEDIA_FORMAT_CAST(fmt);
+
+ /* alloc buffer */
+ int err = _pkt_alloc_buffer(handle);
+ if (err != MEDIA_PACKET_ERROR_NONE)
+ {
+ LOGE("[%s] failed _pkt_alloc_buffer(), err = (0x%08x)", __FUNCTION__, err);
+ ret = err;
+ goto fail;
+ }
+
+ /* allocated buffer */
+ handle->is_allocated = true;
+
+ /* set finalized callback and user data */
+ handle->finalizecb_func = fcb;
+ handle->userdata = fcb_data;
+
+ /* increase format reference count */
+ media_format_ref((media_format_h)handle->format);
+
+ /* take handle */
+ *packet = (media_packet_h)handle;
+ LOGI("[%s] new handle : %p", __FUNCTION__, *packet);
+ return ret;
+
+fail:
+
+ if (handle)
+ {
+ free(handle);
+ handle = NULL;
+ }
+
+ *packet = NULL;
+ return ret;
+}
+
+int media_packet_create(media_format_h fmt, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet)
+{
+ media_packet_s* handle = NULL;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(fmt);
+ MEDIA_PACKET_NULL_ARG_CHECK(packet);
+ if (MEDIA_FORMAT_GET_REFCOUNT(fmt) < 1)
+ {
+ LOGE("The media format handle is corrupted or Not set media info");
+ return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!MEDIA_FORMAT_IS_VIDEO(fmt) && !MEDIA_FORMAT_IS_AUDIO(fmt))
+ {
+ LOGE("The media format handle is not specified. set video info or audio info...");
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ }
+ /* TODO : need more validation on fmt */
+
+ handle = (media_packet_s*)malloc(sizeof(media_packet_s));
+ if (handle != NULL)
+ memset(handle, 0, sizeof(media_packet_s));
+ else
+ {
+ LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__, MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+ return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+ }
+
+ /* TODO : need to consider to give application to select buffer type(tbm or heap) */
+
+ /* check if tbm surface is needed.
+ * This time, Only raw video format is considered to be allocated in TBM
+ */
+ if (MEDIA_FORMAT_IS_VIDEO(fmt) && MEDIA_FORMAT_IS_RAW(fmt))
+ {
+ handle->type = MEDIA_BUFFER_TYPE_TBM_SURFACE;
+ }
+ else
+ {
+ handle->type = MEDIA_BUFFER_TYPE_NORMAL;
+ }
+
+ /* take fmt */
+ handle->format = MEDIA_FORMAT_CAST(fmt);
+
+ /* NOT allocated buffer */
+ handle->is_allocated = false;
+
+ /* set finalized callback and user data */
+ handle->finalizecb_func = fcb;
+ handle->userdata = fcb_data;
+
+ /* increase format reference count */
+ media_format_ref((media_format_h)handle->format);
+
+ /* take handle */
+ *packet = (media_packet_h)handle;
+ LOGI("[%s] new handle : %p", __FUNCTION__, *packet);
+ return ret;
+
+}
+
+int media_packet_copy(media_packet_h org_packet, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h* new_packet)
+{
+ media_packet_s* handle;
+ media_packet_s* org_handle;
+
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(org_packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(new_packet);
+
+ org_handle = (media_packet_s*)org_packet;
+
+ handle = (media_packet_s*)malloc(sizeof(media_packet_s));
+ if (handle != NULL)
+ memset(handle, 0, sizeof(media_packet_s));
+ else
+ {
+ LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__, MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+ return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+ }
+
+ /* copy handle*/
+ memcpy(handle, org_handle, sizeof(media_packet_s));
+
+ /* the caller can not get exist allocated buffer pointer */
+ handle->data = NULL;
+ handle->surface_data = NULL;
+ handle->is_allocated = false;
+ handle->size = 0;
+
+ /* set finalized callback and user data */
+ handle->finalizecb_func = fcb;
+ handle->userdata = fcb_data;
+
+ /* increase format reference count */
+ media_format_ref((media_format_h)handle->format);
+
+ /* take handle */
+ *new_packet = (media_packet_h)handle;
+ LOGI("[%s] new handle : %p", __FUNCTION__, *new_packet);
+ return ret;
+
+}
+
+int media_packet_alloc(media_packet_h packet)
+{
+ LOGI("[%s] start", __FUNCTION__);
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ /* alloc buffer */
+ int err = _pkt_alloc_buffer(handle);
+ if (err != MEDIA_PACKET_ERROR_NONE)
+ {
+ LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+ ret = err;
+ goto fail;
+ }
+
+ /* allocated buffer */
+ handle->is_allocated = true;
+
+ LOGI("[%s] end", __FUNCTION__);
+ return ret;
+
+fail:
+ if(handle)
+ {
+ free(handle);
+ handle = NULL;
+ }
+ return ret;
+
+}
+
+
+int _pkt_alloc_buffer(media_packet_s* pkt)
+{
+ /* skip validating pkt */
+ uint64_t buffersize = 0;
+
+ /* need to use format,width,height to get buffer size for raw video frame */
+ if (pkt->type == MEDIA_BUFFER_TYPE_TBM_SURFACE)
+ {
+ buffersize = _pkt_calculate_video_buffer_size(pkt);
+ pkt->size = buffersize;
+ /* NOTE : size of buffer may not equal to w*h*bpp. Not sure we need to
+ * do some verifying between given size and calculated size.
+ */
+ }
+ else
+ {
+ buffersize = pkt->size;
+ }
+
+ if (pkt->type == MEDIA_BUFFER_TYPE_NORMAL)
+ {
+ /* need to use format,width,height to get buffer size */
+ if (MEDIA_FORMAT_IS_VIDEO(pkt->format))
+ {
+ buffersize = _pkt_calculate_video_buffer_size(pkt);
+ // 16bytes aligned malloc
+ pkt->data = _aligned_malloc_normal_buffer_type(buffersize, 16);
+ if (!pkt->data)
+ {
+ return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+ }
+ }
+ else
+ {
+ buffersize = _pkt_calculate_audio_buffer_size(pkt);
+ pkt->data = (void*)malloc(buffersize);
+ if (!pkt->data)
+ {
+ return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+ }
+ }
+ pkt->size = buffersize;
+ }
+ else if (pkt->type == MEDIA_BUFFER_TYPE_TBM_SURFACE)
+ {
+
+ /* convert to tbm_format*/
+ uint32_t tbm_format;
+ tbm_format = _convert_to_tbm_surface_format(pkt->format->mimetype);
+
+#if 0
+ /*check whether given tbm_format is supported or not*/
+ uint32_t *supported_formats;
+ uint32_t supported_format_num;
+ bool is_supported_format;
+ int i;
+
+ if (tbm_surface_query_formats(&supported_formats, &supported_format_num))
+ {
+ is_supported_format = false;
+ for (i = 0 ; i < supported_format_num ; i++)
+ {
+ if (supported_formats[i] == tbm_format)
+ {
+ is_supported_format = true;
+ break;
+ }
+ }
+
+ free (supported_formats);
+ }
+ else
+ {
+ /* tbm_surface_query_format returns error */
+ LOGE("tbm_surface_query_format is failed..");
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ }
+
+ /* if not supported tbm_format by backend, don't need to do tbm_surface_create() */
+ if (!is_supported_format)
+ {
+ LOGE("the backend doesn't support 0x%x mimetype", pkt->format->mimetype);
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ }
+#endif
+ /*create tbm_surface*/
+ pkt->surface_data = (void*)tbm_surface_create(pkt->format->detail.video.width, pkt->format->detail.video.height, tbm_format);
+ if (pkt->surface_data != NULL)
+ {
+
+ /* get tbm_surface_info */
+ tbm_surface_info_s surface_info;
+ int err = tbm_surface_get_info((tbm_surface_h)pkt->surface_data, &surface_info);
+ if (err == TBM_SURFACE_ERROR_NONE)
+ {
+ pkt->data = surface_info.planes[0].ptr;
+ pkt->size = (uint64_t)surface_info.size;
+ LOGD("tbm_surface_created, pkt->size = %llu\n", pkt->size);
+ }
+ else
+ {
+ LOGE("tbm_surface_get_info() is failed.. err = 0x%08x \n", err);
+ tbm_surface_destroy((tbm_surface_h)pkt->surface_data);
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ }
+ }
+ else
+ {
+ LOGE("\n tbm_surface_create() is failed!! \n");
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ }
+
+ }
+ return MEDIA_PACKET_ERROR_NONE;
+}
+
+/* TODO : rename below macro or make it able to use original from mm_transform */
+#define _ROUND_UP_16(num) (((num)+15)&~15)
+#define _GEN_MASK(x) ((1<<(x))-1)
+#define _ROUND_UP_X(v,x) (((v) + _GEN_MASK(x)) & ~_GEN_MASK(x))
+#define _DIV_ROUND_UP_X(v,x) (((v) + _GEN_MASK(x)) >> (x))
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+static uint64_t _pkt_calculate_video_buffer_size(media_packet_s* pkt)
+{
+ unsigned char x_chroma_shift = 0;
+ unsigned char y_chroma_shift = 0;
+ int size, w2, h2, size2;
+ int stride, stride2;
+ int width = 0;
+ int height = 0;
+ uint64_t buffersize = 0;
+
+ if (MEDIA_FORMAT_IS_VIDEO(pkt->format)) {
+ width = pkt->format->detail.video.width;
+ height = pkt->format->detail.video.height;
+ }
+
+ /* TODO : need to check type mapping again with mm_transform */
+ switch (pkt->format->mimetype)
+ {
+
+ case MEDIA_FORMAT_I420:
+ x_chroma_shift = 1;
+ y_chroma_shift = 1;
+ stride = _ROUND_UP_16 (width);
+ h2 = _ROUND_UP_X (height, x_chroma_shift);
+ size = stride * h2;
+ w2 = _DIV_ROUND_UP_X (width, x_chroma_shift);
+ stride2 = _ROUND_UP_16 (w2);
+ h2 = _DIV_ROUND_UP_X (height, y_chroma_shift);
+ size2 = stride2 * h2;
+ buffersize = size + 2 * size2;
+ break;
+
+ case MEDIA_FORMAT_YUYV:
+ case MEDIA_FORMAT_UYVY:
+ case MEDIA_FORMAT_NV16:
+ stride = _ROUND_UP_16 (width * 2);
+ size = stride * height;
+ buffersize = size;
+ break;
+
+ case MEDIA_FORMAT_RGB565:
+ stride = _ROUND_UP_16 (width * 2);
+ size = stride * height;
+ buffersize = size;
+ break;
+
+ case MEDIA_FORMAT_RGB888:
+ stride = _ROUND_UP_16 (width * 3);
+ size = stride * height;
+ buffersize = size;
+ break;
+
+ case MEDIA_FORMAT_ARGB:
+ case MEDIA_FORMAT_RGBA:
+ stride = width * 4;
+ size = stride * height;
+ buffersize = size;
+ break;
+
+ case MEDIA_FORMAT_NV12:
+ case MEDIA_FORMAT_NV12T:
+ case MEDIA_FORMAT_H261:
+ case MEDIA_FORMAT_H263:
+ case MEDIA_FORMAT_H263P:
+ case MEDIA_FORMAT_H264_SP:
+ case MEDIA_FORMAT_H264_MP:
+ case MEDIA_FORMAT_H264_HP:
+ case MEDIA_FORMAT_MJPEG:
+ case MEDIA_FORMAT_MPEG1:
+ case MEDIA_FORMAT_MPEG2_SP:
+ case MEDIA_FORMAT_MPEG2_MP:
+ case MEDIA_FORMAT_MPEG2_HP:
+ case MEDIA_FORMAT_MPEG4_SP:
+ case MEDIA_FORMAT_MPEG4_ASP:
+ x_chroma_shift = 1;
+ y_chroma_shift = 1;
+ stride = _ROUND_UP_16 (width);
+ h2 = _ROUND_UP_X (height, y_chroma_shift);
+ size = stride * h2;
+ w2 = 2 * _DIV_ROUND_UP_X (width, x_chroma_shift);
+ stride2 = _ROUND_UP_16 (w2);
+ h2 = _DIV_ROUND_UP_X (height, y_chroma_shift);
+ size2 = stride2 * h2;
+ buffersize = size + size2;
+ break;
+ default:
+ LOGE("Not supported format\n");
+ return 0;
+ }
+
+ LOGD("format 0x%x, buffersize %llu\n", pkt->format->mimetype, buffersize);
+
+ return buffersize;
+}
+
+
+#define PCM_MAX_FRM_SIZE (2048)
+#define PCM_MIN_FRM_SIZE (1024)
+#define AAC_MAX_SAMPLE_SIZE (1024)
+#define MP3_MAX_SAMPLE_SIZE (1152)
+#define MPEG_MAX_FRM_SIZE (6144/4) /* 1536 */
+#define MPEG_MIN_NCH (2)
+
+static uint64_t _pkt_calculate_audio_buffer_size(media_packet_s* pkt)
+{
+ int channel = 0;
+ int bit = 0;
+ uint64_t buffersize = 0;
+
+ if (!MEDIA_FORMAT_IS_VIDEO(pkt->format)) {
+ channel = pkt->format->detail.audio.channel;
+ bit = pkt->format->detail.audio.bit;
+ }
+
+ switch (pkt->format->mimetype)
+ {
+ case MEDIA_FORMAT_PCM:
+ buffersize = (PCM_MAX_FRM_SIZE * channel) * (uint64_t)(bit /8);
+ break;
+ case MEDIA_FORMAT_AAC:
+ case MEDIA_FORMAT_MP3:
+ buffersize = (MPEG_MAX_FRM_SIZE * MPEG_MIN_NCH) * (uint64_t)(2); /* 2 = (16bit/8)*/
+ break;
+ /* TODO : extenstion format */
+ default:
+ LOGE("Not supported format\n");
+ return 0;
+ }
+
+ LOGD("format 0x%x, buffersize %llu\n", pkt->format->mimetype, buffersize);
+
+ return buffersize;
+}
+
+int media_packet_create_from_tbm_surface(media_format_h fmt, tbm_surface_h surface, media_packet_finalize_cb fcb, void *fcb_data, media_packet_h *packet)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ if (surface == NULL)
+ return MEDIA_PACKET_ERROR_INVALID_PARAMETER;
+
+ MEDIA_PACKET_INSTANCE_CHECK(fmt);
+ MEDIA_PACKET_INSTANCE_CHECK(surface);
+ MEDIA_PACKET_NULL_ARG_CHECK(packet);
+ /* TODO : need more validation on fmt */
+
+ handle = (media_packet_s*)malloc( sizeof(media_packet_s));
+ if (handle != NULL)
+ {
+ memset(handle, 0 , sizeof(media_packet_s));
+ }
+ else
+ {
+ LOGE("[%s] MEDIA_PACKET_ERROR_OUT_OF_MEMORY(0x%08x)" ,__FUNCTION__,MEDIA_PACKET_ERROR_OUT_OF_MEMORY);
+ return MEDIA_PACKET_ERROR_OUT_OF_MEMORY;
+ }
+
+ handle->type = MEDIA_BUFFER_TYPE_EXTERNAL_TBM_SURFACE;
+ handle->surface_data = (void*)surface;
+
+ /* alloc handle->format */
+ handle->format = MEDIA_FORMAT_CAST(fmt);
+
+ /* get tbm_surface_info */
+ tbm_surface_info_s surface_info;
+ int err = tbm_surface_get_info((tbm_surface_h)handle->surface_data, &surface_info);
+ if (err == TBM_SURFACE_ERROR_NONE)
+ {
+ handle->data = surface_info.planes[0].ptr;
+ handle->size = (uint64_t)surface_info.size;
+ }
+ else
+ {
+ LOGE("tbm_surface_get_info() is failed.. err =0x%08x", err);
+ ret = MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ goto fail;
+ }
+
+ /* allocated buffer */
+ handle->is_allocated = true;
+
+ /* set finalized callback and user data */
+ handle->finalizecb_func = fcb;
+ handle->userdata = fcb_data;
+
+ /* increase format reference count */
+ ret = media_format_ref((media_format_h)handle->format);
+
+ /* take handle */
+ *packet = (media_packet_h)handle;
+ LOGI("[%s] new handle : %p", __FUNCTION__, *packet);
+ return ret;
+
+fail:
+
+ if (handle)
+ {
+ free(handle);
+ handle = NULL;
+ }
+
+ *packet = NULL;
+ return ret;
+}
+
+int media_packet_get_buffer_data_ptr(media_packet_h packet, void **data)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(data);
+
+ handle = (media_packet_s*) packet;
+
+ *data = handle->data;
+
+ return ret;
+
+}
+
+int media_packet_get_tbm_surface(media_packet_h packet, tbm_surface_h *surface)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(surface);
+
+ handle = (media_packet_s*) packet;
+
+ *surface = (tbm_surface_h)handle->surface_data;
+
+ return ret;
+}
+
+int media_packet_get_format(media_packet_h packet, media_format_h *fmt)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(fmt);
+
+ handle = (media_packet_s*) packet;
+
+ /* ref exist format */
+ media_format_ref((media_format_h)handle->format);
+
+ *fmt = (media_format_h)handle->format;
+
+ return ret;
+}
+
+int media_packet_set_format(media_packet_h packet, media_format_h fmt)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(fmt);
+
+ handle = (media_packet_s*) packet;
+
+ /* if trying to set same format, return*/
+ if (handle->format == MEDIA_FORMAT_CAST(fmt))
+ {
+ LOGE("The packet handle already refers the format handle..\n");
+ return MEDIA_PACKET_ERROR_INVALID_OPERATION;
+ }
+
+ /* unref exist format */
+ media_format_unref((media_format_h)handle->format);
+
+ /* set as new format to packet */
+ handle->format = MEDIA_FORMAT_CAST(fmt);
+
+ /* ref new format */
+ media_format_ref(fmt);
+
+ return ret;
+}
+
+int media_packet_set_pts(media_packet_h packet, uint64_t pts)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ handle->pts = pts;
+
+ return ret;
+}
+
+int media_packet_set_dts(media_packet_h packet, uint64_t dts)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ handle->dts = dts;
+
+ return ret;
+}
+
+int media_packet_set_duration(media_packet_h packet, uint64_t duration)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ handle->duration = duration;
+
+ return ret;
+}
+
+int media_packet_set_buffer_size(media_packet_h packet, uint64_t size)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ handle->size = size;
+
+ return ret;
+}
+
+int media_packet_get_pts(media_packet_h packet, uint64_t *pts)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(pts);
+
+ handle = (media_packet_s*) packet;
+
+ *pts = handle->pts;
+
+ return ret;
+}
+
+int media_packet_get_dts(media_packet_h packet, uint64_t *dts)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(dts);
+
+ handle = (media_packet_s*) packet;
+
+ *dts = handle->dts;
+
+ return ret;
+}
+
+int media_packet_get_duration(media_packet_h packet, uint64_t *duration)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(duration);
+
+ handle = (media_packet_s*) packet;
+
+ *duration = handle->duration;
+
+ return ret;
+}
+
+int media_packet_get_buffer_size(media_packet_h packet, uint64_t *size)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(size);
+
+ handle = (media_packet_s*) packet;
+
+ *size = handle->size;
+
+ return ret;
+}
+
+int media_packet_set_extra(media_packet_h packet, void *extra)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(extra);
+
+ handle = (media_packet_s*) packet;
+
+ handle->extradata = extra;
+
+ return ret;
+}
+
+int media_packet_get_extra(media_packet_h packet, void **extra)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(extra);
+
+ handle = (media_packet_s*) packet;
+
+ *extra = handle->extradata;
+
+ return ret;
+}
+
+int media_packet_is_video(media_packet_h packet, bool *is_video)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(is_video);
+
+ handle = (media_packet_s*) packet;
+
+ if (MEDIA_FORMAT_IS_VIDEO(handle->format))
+ *is_video = true;
+ else
+ *is_video = false;
+
+ return ret;
+}
+
+int media_packet_is_audio(media_packet_h packet, bool *is_audio)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(is_audio);
+
+ handle = (media_packet_s*) packet;
+
+ if (MEDIA_FORMAT_IS_AUDIO(handle->format))
+ *is_audio = true;
+ else
+ *is_audio = false;
+
+ return ret;
+}
+
+int media_packet_is_encoded(media_packet_h packet, bool *is_encoded)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(is_encoded);
+
+ handle = (media_packet_s*) packet;
+
+ if (MEDIA_FORMAT_IS_ENCODED(handle->format))
+ *is_encoded = true;
+ else
+ *is_encoded = false;
+
+ return ret;
+}
+
+int media_packet_is_raw(media_packet_h packet, bool *is_raw)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(is_raw);
+
+ handle = (media_packet_s*) packet;
+
+ if (MEDIA_FORMAT_IS_RAW(handle->format))
+ *is_raw = true;
+ else
+ *is_raw = false;
+
+ return ret;
+}
+
+int media_packet_set_flags(media_packet_h packet, media_buffer_flags_e flags)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ handle->flags |= flags;
+
+ return ret;
+}
+
+int media_packet_unset_flags(media_packet_h packet, media_buffer_flags_e flags)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ handle->flags &= ~flags;
+
+ return ret;
+}
+
+int media_packet_is_codec_config(media_packet_h packet, bool *is_codec_config)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(is_codec_config);
+
+ handle = (media_packet_s*) packet;
+
+ if (MEDIA_PACKET_CODEC_CONFIG_DATA(packet))
+ *is_codec_config = true;
+ else
+ *is_codec_config = false;
+
+ return ret;
+}
+
+int media_packet_is_end_of_stream(media_packet_h packet, bool *is_eos)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(is_eos);
+
+ handle = (media_packet_s*) packet;
+
+ if (MEDIA_PACKET_CODEC_END_OF_STREAM(packet))
+ *is_eos = true;
+ else
+ *is_eos = false;
+
+ return ret;
+}
+
+int media_packet_is_sync_frame(media_packet_h packet, bool *is_sync)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(is_sync);
+
+ handle = (media_packet_s*) packet;
+
+ if (MEDIA_PACKET_CODEC_SYNC_FRAME(packet))
+ *is_sync = true;
+ else
+ *is_sync = false;
+
+ return ret;
+}
+
+int media_packet_has_tbm_surface_buffer(media_packet_h packet, bool* has_tbm_surface)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+ MEDIA_PACKET_NULL_ARG_CHECK(has_tbm_surface);
+
+ handle = (media_packet_s*) packet;
+
+ if ((handle->type == MEDIA_BUFFER_TYPE_TBM_SURFACE || handle->type == MEDIA_BUFFER_TYPE_EXTERNAL_TBM_SURFACE) && handle->surface_data)
+ {
+ *has_tbm_surface = true;
+ }
+ else
+ {
+ *has_tbm_surface = false;
+ }
+ return ret;
+}
+
+int media_packet_destroy(media_packet_h packet)
+{
+ media_packet_s* handle;
+ int ret = MEDIA_PACKET_ERROR_NONE;
+
+ MEDIA_PACKET_INSTANCE_CHECK(packet);
+
+ handle = (media_packet_s*) packet;
+
+ /* finailize callback */
+ if (handle->finalizecb_func)
+ {
+ int finalize_cb_ret;
+ finalize_cb_ret = handle->finalizecb_func((media_packet_h)handle, MEDIA_PACKET_ERROR_NONE, handle->userdata);
+
+ /* creator do not want to destroy media packet handle*/
+ if(finalize_cb_ret == MEDIA_PACKET_REUSE)
+ {
+ LOGI("the media packet handle will be reused.");
+ return MEDIA_PACKET_ERROR_NONE;
+ }
+ }
+
+ if(handle->type == MEDIA_BUFFER_TYPE_TBM_SURFACE)
+ {
+ if(handle->surface_data)
+ {
+ tbm_surface_destroy((tbm_surface_h)handle->surface_data);
+ }
+ }
+ else if (handle->type == MEDIA_BUFFER_TYPE_NORMAL)
+ {
+ if(handle->data)
+ {
+ _aligned_free_normal_buffer_type(handle->data);
+ handle->data = NULL;
+ }
+ }
+ else if (handle->type == MEDIA_BUFFER_TYPE_EXTERNAL_TBM_SURFACE)
+ {
+ // there is nothing to do
+ }
+
+ /* unreference media_format */
+ media_format_unref(handle->format);
+
+ LOGI("The packet handle(%p) is will be destroyed..\n", handle);
+
+ free(handle);
+ handle = NULL;
+
+ return ret;
+}
+
+static uint32_t _convert_to_tbm_surface_format(media_format_mimetype_e format_type)
+{
+ uint32_t tbm_format;
+
+ switch(format_type) {
+ case MEDIA_FORMAT_NV12:
+ case MEDIA_FORMAT_NV12T:
+ tbm_format = TBM_FORMAT_NV12;
+ break;
+ case MEDIA_FORMAT_NV16:
+ tbm_format = TBM_FORMAT_NV16;
+ break;
+ case MEDIA_FORMAT_NV21:
+ tbm_format = TBM_FORMAT_NV21;
+ break;
+ case MEDIA_FORMAT_YUYV:
+ tbm_format = TBM_FORMAT_YUYV;
+ break;
+ case MEDIA_FORMAT_UYVY:
+ tbm_format = TBM_FORMAT_UYVY;
+ break;
+ case MEDIA_FORMAT_422P:
+ tbm_format = TBM_FORMAT_YUV422;
+ break;
+ case MEDIA_FORMAT_I420:
+ tbm_format = TBM_FORMAT_YUV420;
+ break;
+ case MEDIA_FORMAT_YV12:
+ tbm_format = TBM_FORMAT_YVU420;
+ break;
+ case MEDIA_FORMAT_RGB565:
+ tbm_format = TBM_FORMAT_RGB565;
+ break;
+ case MEDIA_FORMAT_RGB888:
+ tbm_format = TBM_FORMAT_RGB888;
+ break;
+ case MEDIA_FORMAT_RGBA:
+ tbm_format = TBM_FORMAT_RGBA8888;
+ break;
+ case MEDIA_FORMAT_ARGB:
+ tbm_format = TBM_FORMAT_ARGB8888;
+ break;
+ default:
+ LOGE("Invalid format mime type!");
+ tbm_format = 0;
+ break;
+ }
+
+ return tbm_format;
+}
+
+
+static void* _aligned_malloc_normal_buffer_type (uint64_t size, int alignment)
+{
+ unsigned char* buffer_ptr;
+ unsigned char* temp_ptr;
+
+ if((temp_ptr = (void*)malloc(size + alignment)) != NULL)
+ {
+ buffer_ptr = (void*)((unsigned int)(temp_ptr + alignment - 1) & (~(unsigned int)(alignment -1)));
+
+ if(buffer_ptr == temp_ptr)
+ {
+ buffer_ptr += alignment;
+ }
+
+ *(buffer_ptr - 1) = (unsigned int)(buffer_ptr - temp_ptr);
+ return (void*)buffer_ptr;
+ }
+
+ return NULL;
+}
+
+static void _aligned_free_normal_buffer_type (void* buffer_ptr)
+{
+ unsigned char* ptr;
+ if (buffer_ptr == NULL)
+ return;
+
+ ptr = (unsigned char*)buffer_ptr;
+
+ // *(ptr - 1) holds the offset to the real allocated block
+ // we sub that offset os we free the real pointer
+ ptr -= *(ptr - 1);
+
+ // Free the memory
+ free(ptr);
+ ptr = NULL;
+}
+
+#if 0
+int media_tool_create(mediatool_h *mediatool)
+{
+ MediaTool_s *handle;
+ int ret;
+ handle = (MediaTool_s*)malloc(sizeof(MediaTool_s));
+
+ if (handle != NULL)
+ memset(handle, 0, sizeof(MediaTool_s));
+ else
+ return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
+
+ //TODO : make _media_tool_create function
+ //ret = _media_tool_create(&handle->mediatool_handle);
+ if(ret != MEDIA_TOOL_ERROR_NONE)
+ {
+ free(handle);
+ handle = NULL;
+ return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+ }
+ else
+ {
+ *mediatool = (mediatool_h*)handle;
+ handle->refcount = 1;
+ return MEDIA_TOOL_ERROR_NONE;
+ }
+}
+
+int media_tool_destroy(mediatool_h mediatool)
+{
+ MediaTool_s* handle = (MediaTool_s *) mediatool;
+ int ret;
+
+ if (handle == NULL)
+ return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
+
+ //TODO : make _media_tool_create function
+ ret = _media_tool_destroy(handle->mediatool_handle);
+ if (ret != MEDIA_TOOL_ERROR_NONE)
+ {
+ return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+ }
+ else
+ {
+ free(handle);
+ handle = NULL;
+ return MEDIA_TOOL_ERROR_NONE;
+ }
+}
+
+int media_tool_is_Iframe(mediatool_h mediatool, bool *isIFrame)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+ int ret;
+ if (handle == NULL)
+ return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
+
+ *isIFrame = handle->videocodecformat->isIFrame;
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_set_buffer(mediatool_h mediatool, MediaToolBufferPrivate_s* privBuffer)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+ int ret;
+ handle->bufferpriv = (MediaToolBufferPrivate_s *)malloc(sizeof(MediaToolBufferPrivate_s));
+
+ if (handle->bufferpriv != NULL)
+ memset(handle->bufferpriv, 0, sizeof(MediaToolBufferPrivate_s));
+ else
+ return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_get_buffer(mediatool_h mediatool, MediaToolBufferPrivate_s** privBuffer)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+ int ret;
+ if (handle->bufferpriv == NULL)
+ return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+
+ memcpy(*privBuffer, handle->bufferpriv, sizeof(handle->bufferpriv));
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_set_video_codec_format(mediatool_h mediatool, VideoCodecFormat_s* videoCodecFormat)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+ int ret;
+ handle->videocodecformat = (VideoCodecFormat_s *)malloc(sizeof(VideoCodecFormat_s));
+
+ if (handle->videocodecformat != NULL)
+ memset(handle->videocodecformat, 0, sizeof(VideoCodecFormat_s));
+ else
+ return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_get_video_codec_format(mediatool_h mediatool, VideoCodecFormat_s** videoCodecFormat)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+ int ret;
+ if (handle->videocodecformat == NULL)
+ return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+
+ memcpy(*videoCodecFormat, handle->videocodecformat, sizeof(handle->videocodecformat));
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_set_audio_codec_format(mediatool_h mediatool, AudioCodecFormat_s* audioCodecFormat)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+ int ret;
+ handle->audiocodecformat = (AudioCodecFormat_s *)malloc(sizeof(AudioCodecFormat_s));
+
+ if (handle->audiocodecformat != NULL)
+ memset(handle->audiocodecformat, 0, sizeof(AudioCodecFormat_s));
+ else
+ return MEDIA_TOOL_ERROR_OUT_OF_MEMORY;
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_get_audio_codec_format(mediatool_h mediatool, AudioCodecFormat_s** audioCodecFormat)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+ int ret;
+ if (handle->audiocodecformat == NULL)
+ return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+
+ memcpy(*audioCodecFormat, handle->audiocodecformat, sizeof(handle->audiocodecformat));
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_ref(mediatool_h mediatool)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+
+ if (handle == NULL)
+ return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
+
+ if (!(handle->refcount> 0))
+ return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+
+ g_atomic_int_inc (&handle->refcount);
+
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+int media_tool_unref(mediatool_h mediatool)
+{
+ MediaTool_s *handle = (MediaTool_s *) mediatool;
+
+ if (handle == NULL)
+ return MEDIA_TOOL_ERROR_INVALID_PARAMETER;
+
+ if (!(handle->refcount> 0))
+ return MEDIA_TOOL_ERROR_INVALID_OPERATION;
+
+ int zero;
+
+ zero = g_atomic_int_dec_and_test (&handle->refcount);
+ if (zero)
+ {
+ free(handle);
+ handle = NULL;
+ }
+ return MEDIA_TOOL_ERROR_NONE;
+}
+
+#endif
+
diff --git a/src/media_packet_private.c b/src/media_packet_private.c
new file mode 100755
index 0000000..5b20107
--- /dev/null
+++ b/src/media_packet_private.c
@@ -0,0 +1,20 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <glib.h>
+#include <media_packet_private.h>
+
+
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100755
index 0000000..aed006f
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,22 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_test "${fw_name}-test")
+
+INCLUDE_DIRECTORIES(../include)
+link_directories(${CMAKE_SOURCE_DIR}/../)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED libtbm appcore-efl)
+FOREACH(flag ${${fw_test}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -pie")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+ GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+ MESSAGE("${src_name}")
+ ADD_EXECUTABLE(${src_name} ${src})
+ TARGET_LINK_LIBRARIES(${src_name} capi-media-tool ${${fw_test}_LDFLAGS})
+ENDFOREACH()
+
diff --git a/test/media_packet_test.c b/test/media_packet_test.c
new file mode 100755
index 0000000..ade3cde
--- /dev/null
+++ b/test/media_packet_test.c
@@ -0,0 +1,1357 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+
+#include <media_packet_private.h>
+#include <media_format.h>
+#include <media_format_private.h>
+
+
+#include <appcore-efl.h>
+
+#define PACKAGE "media_tool_test"
+#define MAX_STRING_LEN 2048
+#define MAX_HANDLE 10
+#define MEDIA_FORMAT_MAX_HANDLE 3
+
+
+enum
+{
+ CURRENT_STATUS_MAINMENU,
+ CURRENT_STATUS_PACKET_SET_FORMAT,
+ CURRENT_STATUS_DURATION,
+ CURRENT_STATUS_FORMAT_SET_VIDEO_MIME,
+ CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH,
+ CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT,
+ CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS,
+ CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS,
+ CURRENT_STATUS_FORMAT_SET_AUDIO_MIME,
+ CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL,
+ CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE,
+ CURRENT_STATUS_FORMAT_SET_AUDIO_BIT,
+ CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS,
+};
+
+
+char g_uri[MAX_STRING_LEN];
+int g_menu_state = CURRENT_STATUS_MAINMENU;
+int g_handle_num = 1;
+static media_packet_h g_media_packet[MAX_HANDLE] = {0};
+ media_format_h g_media_format[MEDIA_FORMAT_MAX_HANDLE] = {0};
+int media_format_idx = -1;
+bool is_only_created_handle;
+bool is_excute_create;
+
+/***********************************************/
+/*** Test API part
+/***********************************************/
+static void _media_format_create(void)
+{
+ int ret;
+
+ if (g_media_format[0] == NULL)
+ {
+ int ret = media_format_create(&g_media_format[0]);
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ {
+ g_print("media_format_h[0] is created successfully! \n");
+ media_format_idx = 0;
+ g_print("ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ }
+ else
+ {
+ g_print("media_format_create failed...\n");
+ g_print("==> ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ }
+ }
+ else
+ {
+ ret = MEDIA_FORMAT_ERROR_INVALID_OPERATION;
+ g_print("\n can not create media_format_h handle anymore...already exist.\n");
+ }
+
+
+}
+
+static void _media_format_set_video_mime(int num)
+{
+ int ret;
+ if (num == 0)
+ {
+ ret = media_format_set_video_mime(g_media_format[media_format_idx], MEDIA_FORMAT_H264_HP);
+ }
+ else if (num == 1)
+ {
+ ret = media_format_set_video_mime(g_media_format[media_format_idx], MEDIA_FORMAT_RGB888);
+ }
+ else if (num == 2)
+ {
+ ret = media_format_set_video_mime(g_media_format[media_format_idx], MEDIA_FORMAT_I420);
+ }
+ else
+ {
+ g_print("Invalid number...\n");
+ }
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_video_mime is succeeded!!\n");
+ else
+ g_print("media_format_set_video_mime is failed...!!\n");
+
+}
+
+static void _media_format_set_video_width(int w)
+{
+ int ret;
+ ret = media_format_set_video_width(g_media_format[media_format_idx], w);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_video_width is succeeded!!\n");
+ else
+ g_print("media_format_set_video_width is failed...!!\n");
+}
+
+static void _media_format_set_video_height(int h)
+{
+ int ret;
+ ret = media_format_set_video_height(g_media_format[media_format_idx], h);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_video_height is succeeded!!\n");
+ else
+ g_print("media_format_set_video_height is failed...!!\n");
+
+
+}
+
+static void _media_format_set_video_avg_bps(int avg_bps)
+{
+ int ret;
+ ret = media_format_set_video_avg_bps(g_media_format[media_format_idx], avg_bps);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_video_avg_bps is succeeded!!\n");
+ else
+ g_print("media_format_set_video_avg_bps is failed...!!\n");
+}
+
+static void _media_format_set_video_max_bps(int max_bps)
+{
+ int ret;
+ ret = media_format_set_video_max_bps(g_media_format[media_format_idx], max_bps);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_video_max_bps is succeeded!!\n");
+ else
+ g_print("media_format_set_video_max_bps is failed...!!\n");
+}
+
+static void _media_format_set_audio_mime(int num)
+{
+ int ret;
+ if (num == 0)
+ {
+ ret = media_format_set_audio_mime(g_media_format[media_format_idx], MEDIA_FORMAT_AMR);
+ }
+ else if (num == 1)
+ {
+ ret = media_format_set_audio_mime(g_media_format[media_format_idx], MEDIA_FORMAT_PCM);
+ }
+ else if (num == 2)
+ {
+ ret = media_format_set_audio_mime(g_media_format[media_format_idx], MEDIA_FORMAT_AAC);
+ }
+ else
+ {
+ g_print("Invalid number...\n");
+ }
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_audio_mime is succeeded!!\n");
+ else
+ g_print("media_format_set_audio_mime is failed...!!\n");
+
+}
+
+static void _media_format_set_audio_channel(int channel)
+{
+ int ret;
+ ret = media_format_set_audio_channel(g_media_format[media_format_idx], channel);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_audio_channel is succeeded!!\n");
+ else
+ g_print("media_format_set_audio_channel is failed...!!\n");
+}
+
+static void _media_format_set_audio_samplerate(int samplerate)
+{
+ int ret;
+ ret = media_format_set_audio_samplerate(g_media_format[media_format_idx], samplerate);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_audio_samplerate is succeeded!!\n");
+ else
+ g_print("media_format_set_audio_samplerate is failed...!!\n");
+}
+
+static void _media_format_set_audio_bit(int bit)
+{
+ int ret;
+ ret = media_format_set_audio_bit(g_media_format[media_format_idx], bit);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_audio_bit is succeeded!!\n");
+ else
+ g_print("media_format_set_audio_bit is failed...!!\n");
+}
+
+static void _media_format_set_audio_avg_bps(int avg_bps)
+{
+ int ret;
+ ret = media_format_set_audio_avg_bps(g_media_format[media_format_idx], avg_bps);
+
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ g_print("media_format_set_audio_avg_bps is succeeded!!\n");
+ else
+ g_print("media_format_set_audio_avg_bps is failed...!!\n");
+}
+
+static void _create_format_320_240_es(void)
+{
+
+ if (media_format_create(&g_media_format[1]) == MEDIA_FORMAT_ERROR_NONE)
+ {
+ g_print("media_format_create is succeeded! \n");
+ g_print("the media_format_h[1] is created..\n");
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ media_format_idx = 1;
+
+ media_format_mimetype_e mime = MEDIA_FORMAT_H264_HP;
+ int w = 320;
+ int h = 240;
+ int avg_bps = 3000000;
+ int max_bps = 15000000;
+ ret = media_format_set_video_mime(g_media_format[1], MEDIA_FORMAT_H264_HP);
+ ret = media_format_set_video_width(g_media_format[1], 320);
+ ret = media_format_set_video_height(g_media_format[1], 240);
+ ret = media_format_set_video_avg_bps(g_media_format[1], 3000000);
+ ret = media_format_set_video_max_bps(g_media_format[1], 15000000);
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ {
+ g_print("media_format_set_video_xxx succeed! w:%d, h:%d, 0x%x, avg_bps: %d, max_bps: %d\n", w, h, mime, avg_bps, max_bps);
+ g_print("\t\t\t\t ====>> ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[1]));
+ }
+ else
+ g_print("media_format_set_video_xxx failed..\n");
+ }
+ else
+ {
+ g_print("media_format_create failed..\n");
+ }
+
+}
+
+
+static void _create_format_raw(void)
+{
+
+ if (media_format_create(&g_media_format[2]) == MEDIA_FORMAT_ERROR_NONE)
+ {
+ g_print("media_format_create is succeeded! \n");
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+
+ media_format_mimetype_e mime = MEDIA_FORMAT_I420;
+ int w = 128;
+ int h = 128;
+ int avg_bps = 2000000;
+ int max_bps = 15000000;
+ ret = media_format_set_video_mime(g_media_format[2], mime);
+ ret = media_format_set_video_width(g_media_format[2], w);
+ ret = media_format_set_video_height(g_media_format[2], h);
+ ret = media_format_set_video_avg_bps(g_media_format[2], avg_bps);
+ ret = media_format_set_video_max_bps(g_media_format[2], max_bps);
+ if (ret == MEDIA_FORMAT_ERROR_NONE)
+ {
+ g_print("media_format_set_video_xxx success! w:%d, h:%d, 0x%x, avg_bps: %d, max_bps: %d\n", w, h, mime, avg_bps, max_bps);
+ g_print("\t\t\t\t ====>> ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[2]));
+ }
+ else
+ g_print("media_format_set_video_xxx failed..\n");
+ }
+ else
+ {
+ g_print("media_format_create failed..\n");
+ }
+
+
+}
+
+static int _finalize_callback(media_packet_h packet, int err, void* userdata)
+{
+ g_print("==> finalize callback func is called\n");
+ return MEDIA_PACKET_FINALIZE;
+}
+
+static void _media_packet_create_alloc(void)
+{
+ g_print("=== create_and_alloc!!\n");
+ int i;
+
+ for(i = 0; i < g_handle_num; i++)
+ {
+ if(g_media_packet[i] != NULL)
+ {
+ int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
+ media_packet_destroy(g_media_packet[i]);
+ if (ref_count == 1)
+ {
+ g_media_format[media_format_idx] = NULL;
+ g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+ }
+ g_media_packet[i] = NULL;
+ }
+
+ if(g_media_format[0] == NULL)
+ {
+ g_print("media_format_h is NULL!! create media_format_h handle \n");
+ break;
+ }
+
+ if (media_packet_create_alloc(g_media_format[0], _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet create is failed\n");
+ }
+ else
+ {
+ media_format_idx = 0;
+ g_print("succeeded media_packet_create_alloc !!\n");
+ g_print(" ==> media_format_h[0] ref_count =%d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ media_format_unref(g_media_format[0]);
+ g_print(" ====> media_format_unref, media_format_h[0] ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ is_excute_create = true;
+ }
+
+ }
+}
+
+static void _media_packet_create(void)
+{
+ g_print("=== create!!\n");
+ is_only_created_handle = true;
+ int i;
+
+ for(i = 0; i < g_handle_num; i++)
+ {
+ if(g_media_packet[i] != NULL)
+ {
+ int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
+ media_packet_destroy(g_media_packet[i]);
+ if (ref_count == 1)
+ {
+ g_media_format[media_format_idx] = NULL;
+ g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+ }
+ g_media_packet[i] = NULL;
+ }
+
+ if(g_media_format[0] == NULL)
+ {
+ g_print("media_format_h is NULL!! create media_format_h handle \n");
+ break;
+ }
+
+ /* only ES format , if you want to another format, see _create_format_es() */
+ if (media_packet_create(g_media_format[0], _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet create is failed\n");
+ }
+ else
+ {
+ media_format_idx = 0;
+ g_print("media_packet_create is sucess!!\n");
+ g_print(" ==> media_format_h[0] ref_count =%d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ media_format_unref(g_media_format[0]);
+ g_print(" ====> media_format_unref, media_format_h[0] ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ is_excute_create = true;
+ }
+ }
+}
+
+static void _media_packet_alloc(void)
+{
+ g_print("=== alloc!!\n");
+ if (is_only_created_handle)
+ {
+ if (media_packet_alloc(g_media_packet[0]) == MEDIA_PACKET_ERROR_NONE)
+ g_print("media_packet_alloc is sucess\n");
+ else
+ g_print("media_packet_alloc is failed\n");
+ }
+ else
+ {
+ g_print("*** can not excute!! fisrt excute media_packet_create() before this alloc. \n");
+ }
+}
+
+static void _media_packet_create_from_tbm_surface(void)
+{
+ g_print("=== create_from_tbm_surface!!\n");
+
+ tbm_surface_h surface;
+ surface = tbm_surface_create(128, 128, TBM_FORMAT_YUV420);
+
+ if (surface)
+ {
+ int i;
+
+ for(i = 0; i < g_handle_num; i++)
+ {
+ if(g_media_packet[i] != NULL)
+ {
+ int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
+ media_packet_destroy(g_media_packet[i]);
+
+ if (ref_count == 1 )
+ {
+ g_media_format[media_format_idx] = NULL;
+ g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+ }
+
+ g_media_packet[i] = NULL;
+ }
+
+ if(g_media_format[2] == NULL)
+ {
+ g_print("create raw video type media_format_h[2]... \n");
+ _create_format_raw();
+ }
+
+ /* only RAW format , if you want to another format, see _create_format_raw() */
+ if (media_packet_create_from_tbm_surface(g_media_format[2], surface, _finalize_callback, NULL, &g_media_packet[i]) != MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_create_from_tbm_surface is failed\n");
+ }
+ else
+ {
+ g_print("media_packet_create_from_tbm_surface is sucess!!\n");
+ g_print(" ==> media_format_h[2] ref_count =%d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[2]));
+ media_format_unref(g_media_format[2]);
+ g_print(" ====> media_format_unref, media_format_h[2] ref_count = %d\n", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[2]));
+ media_format_idx = 2;
+ is_excute_create = true;
+ }
+ }
+
+ }
+ else
+ {
+ g_print("tbm_surface_create failed...\n");
+ }
+}
+
+static void _media_packet_copy(void)
+{
+ g_print("=== copy!!\n");
+
+ if (is_excute_create)
+ {
+ if (media_packet_copy(g_media_packet[0], _finalize_callback, NULL, &g_media_packet[1]) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_copy sucess !!");
+ is_only_created_handle = true;
+ memset (g_media_packet[0], 0, sizeof(media_packet_s));
+ memcpy (g_media_packet[0], g_media_packet[1], sizeof(media_packet_s));
+ if(g_media_packet[1])
+ {
+ free(g_media_packet[1]);
+ g_media_packet[1] = NULL;
+ }
+
+ }
+ else
+ {
+ g_print("media_packet_copy failed");
+ }
+ }
+ else
+ {
+ g_print("denied... excute create or create_alloc or create_from_surface");
+ }
+
+}
+
+static void _media_packet_destroy()
+{
+ g_print("=== destroy!!\n");
+ int i;
+ int ret;
+
+ int ref_count;
+
+ for (i = 0; i < g_handle_num ; i++)
+ {
+ if(g_media_packet[i]!=NULL)
+ {
+ ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
+ ret = media_packet_destroy(g_media_packet[i]);
+ g_media_packet[i] = NULL;
+
+ if (ref_count == 1)
+ {
+ g_media_format[media_format_idx] = NULL;
+ g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+ }
+
+ if (ret == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_destroy is succeeded!!\n");
+ if (g_media_format[media_format_idx] != NULL)
+ g_print(" ==> media_format_h[%d] ref_count = %d\n", media_format_idx, MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]));
+ }
+ else
+ g_print("media_packet_destroy is failed...\n");
+ }
+ else
+ g_print("There is nothing to destroy media_packet_h[%d] handle...\n", i);
+ }
+}
+
+static void _media_packet_get_buffer_size(void)
+{
+ uint64_t size;
+ if (media_packet_get_buffer_size(g_media_packet[0],&size) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_get_buffer_size is sucess!!");
+ g_print("\t\t[media_packet]===> size = %llu", size);
+ }
+ else
+ {
+ g_print("media_packet_get_buffer_size is failed...");
+ }
+}
+
+static void _media_packet_get_duration(void)
+{
+ uint64_t duration;
+
+ if (media_packet_get_duration(g_media_packet[0], &duration) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_get_duration is sucess!!");
+ g_print("\t\t[media_packet]===> duration = %llu", duration);
+ }
+ else
+ {
+ g_print("media_packet_get_duration is failed...");
+ }
+}
+
+static void _media_packet_get_buffer_data_ptr(void)
+{
+ void* ptr;
+ media_packet_s* packet = g_media_packet[0];
+ ptr = (void*)malloc(sizeof(packet->size));
+
+ if (ptr)
+ memset(packet, 0, sizeof(packet->size));
+ else
+ g_print("_get_buffer_ptr , malloc failed...");
+
+ if (media_packet_get_buffer_data_ptr(g_media_packet[0], &ptr) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_get_buffer_data_ptr is sucess!!");
+ g_print("\t\t[media_packet]===> buffer_data_ptr = %p", ptr);
+ }
+ else
+ {
+ g_print("media_packet_get_buffer_data_ptr is failed...");
+ }
+
+}
+
+static void _media_packet_get_tbm_surface()
+{
+ tbm_surface_h tbm_surface;
+
+ if (media_packet_get_tbm_surface(g_media_packet[0], &tbm_surface) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_get_tbm_surface is sucess!!");
+ g_print("\t\t[media_packet]===> tbm_surface = %p", (void*)tbm_surface);
+ }
+ else
+ {
+ g_print("media_packet_get_duration is failed...");
+ }
+}
+
+static void _media_packet_set_duration(uint64_t duration)
+{
+ if (media_packet_set_duration(g_media_packet[0], duration) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_set_duration is sucess!!\n");
+ }
+ else
+ {
+ g_print("media_packet_set_duration is failed..\n");
+ }
+}
+
+static void _media_packet_is_video(void)
+{
+ bool is_video;
+ if (media_packet_is_video(g_media_packet[0], &is_video) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_is_video is sucess!!\n");
+ g_print("\t\t[media_packet]===> is_video = %d", is_video);
+ }
+ else
+ {
+ g_print("media_packet_is_video is failed...");
+ }
+}
+
+static void _media_packet_is_audio(void)
+{
+ bool is_audio;
+ if (media_packet_is_audio(g_media_packet[0], &is_audio) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_is_audio is sucess!!\n");
+ g_print("\t\t[media_packet]===> is_audio = %d", is_audio);
+ }
+ else
+ {
+ g_print("media_packet_is_audio is failed...");
+ }
+}
+
+static void _media_packet_is_encoded(void)
+{
+ bool is_encoded;
+ if (media_packet_is_encoded(g_media_packet[0], &is_encoded) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_is_encoded is sucess!!\n");
+ g_print("\t\t[media_packet]===> is_encoded = %d", is_encoded);
+ }
+ else
+ {
+ g_print("media_packet_is_encoded is failed...");
+ }
+
+}
+static void _media_packet_is_raw(void)
+{
+ bool is_raw;
+ if (media_packet_is_raw(g_media_packet[0], &is_raw) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_is_raw is sucess!!\n");
+ g_print("\t\t[media_packet]===> is_raw = %d", is_raw);
+ }
+ else
+ {
+ g_print("media_packet_is_raw is failed...");
+ }
+
+}
+
+static void _media_packet_get_format(void)
+{
+ media_format_h fmt;
+ if (media_packet_get_format(g_media_packet[0], &fmt) == MEDIA_PACKET_ERROR_NONE)
+ {
+ int w;
+ int h;
+
+ int channel;
+ int samplerate;
+ int bit;
+ int audio_avg_bps;
+
+ g_print("media_packet_get_format is sucess! %p \n", fmt);
+
+ if (MEDIA_FORMAT_IS_VIDEO(fmt))
+ {
+ if (media_format_get_video_info(fmt, NULL, &w, &h, NULL, NULL) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("\t\t [media_format] width = %d, height =%d", w, h);
+ }
+ else
+ {
+ g_print("media_format_get_video is failed...");
+ }
+ }
+ else if (MEDIA_FORMAT_IS_AUDIO(fmt))
+ {
+ if (media_format_get_audio_info(fmt, NULL, &channel, &samplerate, &bit, &audio_avg_bps) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("\t\t [media_format] channel = %d, samplerate = %d, bit = %d, avg_bps = %d", channel, samplerate, bit, audio_avg_bps);
+ }
+ else
+ {
+ g_print("media_format_get_video is failed...");
+ }
+ }
+
+ }
+ else
+ {
+ g_print("media_packet_get_format is failed...");
+ }
+
+}
+
+
+static void _media_packet_set_format(media_format_h fmt)
+{
+ if (media_packet_set_format(g_media_packet[0], fmt) == MEDIA_PACKET_ERROR_NONE)
+ {
+ media_format_unref(fmt);
+ g_print("media_packet_set_format is sucess!\n");
+ }
+ else
+ {
+ g_print("media_packet_get_format is failed...");
+ }
+
+}
+
+static void _media_packet_set_extra(void)
+{
+ char* extra = "extra";
+
+ if (media_packet_set_extra(g_media_packet[0], (void*)extra) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_set_extra is sucess!\n");
+ }
+ else
+ {
+ g_print("media_packet_set_extra is failed...");
+ }
+
+}
+
+static void _media_packet_get_extra(void)
+{
+ void* extra;
+
+ if (media_packet_get_extra(g_media_packet[0], &extra) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_get_extra is sucess!\n");
+ g_print("\t\t extra = %s\n", (char*)extra);
+ }
+ else
+ {
+ g_print("media_packet_get_extra is failed...");
+ }
+
+}
+
+static void _media_packet_has_tbm_surface_buffer(void)
+{
+ bool has_tbm;
+
+ if (media_packet_has_tbm_surface_buffer(g_media_packet[0], &has_tbm) == MEDIA_PACKET_ERROR_NONE)
+ {
+ g_print("media_packet_has_tbm_surface_buffer is sucess! \n");
+ g_print("\t\t has_tbm_surface_buffer = %d \n", has_tbm);
+ }
+ else
+ {
+ g_print("media_packet_has_tbm_surface_buffer is failed! \n");
+ }
+}
+
+static void _media_format_get_video_info(void)
+{
+ media_format_mimetype_e mime;
+ int w = 0;
+ int h = 0;
+ int avg_bps = 0;
+ int max_bps = 0;
+
+ if (media_format_get_video_info(g_media_format[0], &mime, &w, &h, &avg_bps, &max_bps) == MEDIA_FORMAT_ERROR_NONE)
+ {
+ g_print("media_format_get_video is sucess!\n");
+ g_print("\t\t[media_format_get_video]mime:0x%x, width :%d, height :%d\n", mime, w, h);
+ g_print("packet format ref_count: %d", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ }
+ else
+ {
+ g_print("media_format_get_video is failed..");
+ }
+}
+
+static void _media_format_get_audio_info(void)
+{
+ media_format_mimetype_e mime;
+ int channel = 0;
+ int samplerate = 0;
+ int bit = 0;
+ int avg_bps = 0;
+
+ if (media_format_get_audio_info(g_media_format[0], &mime, &channel, &samplerate, &bit, &avg_bps)== MEDIA_FORMAT_ERROR_NONE)
+ {
+ g_print("media_format_get_audio_info is sucess!\n");
+ g_print("\t\t[media_format_get_audio_info]mime:0x%x, channel :%d, samplerate :%d, bit: %d, avg_bps:%d \n", mime, channel, samplerate, bit, avg_bps);
+ g_print("packet format ref_count: %d", MEDIA_FORMAT_GET_REFCOUNT(g_media_format[0]));
+ }
+ else
+ {
+ g_print("media_format_get_audio_info is failed..");
+ }
+}
+
+
+/***********************************************/
+/*** Test suit frame API part
+/***********************************************/
+static int _create_app(void *data)
+{
+ printf("media_packet_test is started!\n");
+ return 0;
+}
+
+static int _terminate_app(void *data)
+{
+ printf("media_packet_test is terminated!\n");
+ return 0;
+}
+
+
+struct appcore_ops ops = {
+ .create = _create_app,
+ .terminate = _terminate_app,
+};
+
+void reset_menu_state()
+{
+ g_menu_state = CURRENT_STATUS_MAINMENU;
+}
+
+void quit_program(void)
+{
+ int i = 0;
+ int ref_count;
+
+ for (i = 0; i < g_handle_num; i++)
+ {
+ if(g_media_packet[i] != NULL)
+ {
+ ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[media_format_idx]);
+ media_packet_destroy(g_media_packet[i]);
+ g_media_packet[i] = NULL;
+ if (ref_count == 1)
+ {
+ g_media_format[media_format_idx] = NULL;
+ g_print("media_format_h[%d] is destroyed...\n", media_format_idx);
+ }
+ }
+ }
+
+
+ for (i = 0; i < MEDIA_FORMAT_MAX_HANDLE; i++)
+ {
+ if (g_media_format[i] != NULL)
+ {
+ int ref_count = MEDIA_FORMAT_GET_REFCOUNT(g_media_format[i]);
+ g_print("media_format_h[%d] ref_count:%d. excute media_format_unref().\n", i, ref_count);
+
+ if (ref_count == 1)
+ {
+ media_format_unref(g_media_format[i]);
+ g_media_format[i] = NULL;
+ g_print("media_format_h[%d] is destroyed...\n", i);
+ }
+ else
+ {
+
+ int j = 1;
+ for (j = 1; j <= ref_count; j++)
+ {
+ g_print("(%d) media_format_unref\n", j);
+ media_format_unref(g_media_format[i]);
+
+ }
+ g_media_format[i] = NULL;
+ g_print("media_format_h[%d] is destroyed...\n", i);
+ }
+
+ }
+ }
+
+ elm_exit();
+}
+
+void _interpret_main_menu(char *cmd)
+{
+ int len = strlen(cmd);
+ if (len == 1)
+ {
+ if (strncmp(cmd, "a", 1) == 0)
+ {
+ _media_packet_create_alloc();
+ }
+ else if (strncmp(cmd, "d", 1) == 0)
+ {
+ _media_packet_destroy();
+ }
+ else if (strncmp(cmd, "b", 1) == 0)
+ {
+ _media_packet_create_from_tbm_surface();
+ }
+ else if (strncmp(cmd, "c", 1) == 0)
+ {
+ _media_packet_copy();
+ }
+ else if (strncmp(cmd, "q", 1) == 0)
+ {
+ quit_program();
+ }
+ }
+ else if (len == 2)
+ {
+ if (strncmp(cmd, "aa", 2) == 0)
+ {
+ _media_packet_create();
+ }
+ else if (strncmp(cmd, "ab", 2) == 0)
+ {
+ _media_packet_alloc();
+ }
+ else if (strncmp(cmd, "iv", 2) == 0)
+ {
+ _media_packet_is_video();
+ }
+ else if (strncmp(cmd, "ia", 2) == 0)
+ {
+ _media_packet_is_audio();
+ }
+ else if (strncmp(cmd, "ie", 2) == 0)
+ {
+ _media_packet_is_encoded();
+ }
+ else if (strncmp(cmd, "ir", 2) == 0)
+ {
+ _media_packet_is_raw();
+ }
+ else if (strncmp(cmd, "gd", 2) == 0)
+ {
+ _media_packet_get_duration();
+ }
+ else if (strncmp(cmd, "sd", 2) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_DURATION;
+ }
+ else if (strncmp(cmd, "gf", 2) == 0)
+ {
+ _media_packet_get_format();
+ }
+ else if (strncmp(cmd, "gs", 2) == 0)
+ {
+ _media_packet_get_buffer_size();
+ }
+ else if (strncmp(cmd, "sf", 2) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_PACKET_SET_FORMAT;
+ }
+ else if (strncmp(cmd, "se", 2) == 0)
+ {
+ _media_packet_set_extra();
+ }
+ else if (strncmp(cmd, "ge", 2) == 0)
+ {
+ _media_packet_get_extra();
+ }
+ else if (strncmp(cmd, "ht", 2) == 0)
+ {
+ _media_packet_has_tbm_surface_buffer();
+ }
+ else if (strncmp(cmd, "cf", 2) == 0)
+ {
+ _media_format_create();
+ }
+
+ }
+ else if (len == 3)
+ {
+ if (strncmp(cmd, "gbp", 3) == 0)
+ {
+ _media_packet_get_buffer_data_ptr();
+ }
+ else if (strncmp(cmd, "gts", 3) == 0)
+ {
+ _media_packet_get_tbm_surface();
+ }
+ else if (strncmp(cmd, "fgv", 3) == 0)
+ {
+ _media_format_get_video_info();
+ }
+ else if (strncmp(cmd, "fga", 3) == 0)
+ {
+ _media_format_get_audio_info();
+ }
+ else if (strncmp(cmd, "svm", 3) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_MIME;
+ }
+ else if (strncmp(cmd, "svw", 3) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH;
+ }
+ else if (strncmp(cmd, "svh", 3) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT;
+ }
+ else if (strncmp(cmd, "sam", 3) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_MIME;
+ }
+ else if (strncmp(cmd, "sac", 3) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL;
+ }
+ else if (strncmp(cmd, "sas", 3) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE;
+ }
+ else if (strncmp(cmd, "sab", 3) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_BIT;
+ }
+ }
+ else if (len == 4)
+ {
+ if (strncmp(cmd, "fraw", 4) == 0)
+ {
+ _create_format_raw();
+ }
+ else if (strncmp(cmd, "fes2", 4) == 0)
+ {
+ _create_format_320_240_es();
+ }
+ else if (strncmp(cmd, "svab", 4) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS;
+ }
+ else if (strncmp(cmd, "svmb", 4) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS;
+ }
+ else if (strncmp(cmd, "saab", 4) == 0)
+ {
+ g_menu_state = CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS;
+ }
+ }
+
+
+}
+
+static void displaymenu(void)
+{
+ if (g_menu_state == CURRENT_STATUS_MAINMENU)
+ {
+ display_sub_basic();
+ }
+ else if (g_menu_state == CURRENT_STATUS_PACKET_SET_FORMAT)
+ {
+ g_print("*** choose format.\n");
+ g_print("1. 320x240 , MEDIA_FORMAT_H264_HP\n");
+ g_print("2. 128x128 , MEDIA_FORMAT_I420\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_DURATION)
+ {
+ g_print("*** input duration: \n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_MIME)
+ {
+ g_print("choose video media format mime type\n");
+ g_print("0. MEDIA_FORMAT_H264_HP\n");
+ g_print("1. MEDIA_FORMAT_RGB888\n");
+ g_print("2. MEDIA_FORMAT_I420\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH)
+ {
+ g_print("input video width:\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT)
+ {
+ g_print("input video height:\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS)
+ {
+ g_print("input video avg_bps:\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS)
+ {
+ g_print("input video max_bps:\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_MIME)
+ {
+ g_print("choose audio media format mime type\n");
+ g_print("0. MEDIA_FORMAT_AMR\n");
+ g_print("1. MEDIA_FORMAT_PCM\n");
+ g_print("2. MEDIA_FORMAT_AAC\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL)
+ {
+ g_print("input audio channel:\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE)
+ {
+ g_print("input audio sample rate:\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_BIT)
+ {
+ g_print("input audio bit:\n");
+ }
+ else if (g_menu_state == CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS)
+ {
+ g_print("input audio average bps:\n");
+ }
+ else
+ {
+ g_print("*** unknown status.\n");
+ quit_program();
+ }
+ g_print(" >>> ");
+}
+
+
+gboolean timeout_menu_display(void* data)
+{
+ displaymenu();
+ return FALSE;
+}
+
+static void interpret (char *cmd)
+{
+ switch (g_menu_state)
+ {
+ case CURRENT_STATUS_MAINMENU:
+ {
+ _interpret_main_menu(cmd);
+ }
+ break;
+ case CURRENT_STATUS_PACKET_SET_FORMAT:
+ {
+ int num = atoi(cmd);
+ switch (num)
+ {
+ case 1:
+ if(g_media_format[1])
+ {
+ _media_packet_set_format(g_media_format[1]);
+ }
+ else
+ {
+ _create_format_320_240_es();
+ _media_packet_set_format(g_media_format[1]);
+ }
+ break;
+ case 2:
+ if(g_media_format[2])
+ {
+ _media_packet_set_format(g_media_format[2]);
+ }
+ else
+ {
+ _create_format_raw();
+ _media_packet_set_format(g_media_format[2]);
+ }
+ break;
+ default:
+ g_print("invalid number..");
+
+
+ }
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_VIDEO_MIME:
+ {
+ int video_mime_idx = atoi(cmd);
+ _media_format_set_video_mime(video_mime_idx);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_VIDEO_WIDTH:
+ {
+ int width = atoi(cmd);
+ _media_format_set_video_width(width);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_VIDEO_HEIGHT:
+ {
+ int height = atoi(cmd);
+ _media_format_set_video_height(height);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_VIDEO_AVG_BPS:
+ {
+ int video_avg_bps = atoi(cmd);
+ _media_format_set_video_avg_bps(video_avg_bps);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_VIDEO_MAX_BPS:
+ {
+ int max_bps = atoi(cmd);
+ _media_format_set_video_max_bps(max_bps);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_AUDIO_MIME:
+ {
+ int audio_mime_idx = atoi(cmd);
+ _media_format_set_audio_mime(audio_mime_idx);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_AUDIO_CHANNEL:
+ {
+ int channel = atoi(cmd);
+ _media_format_set_audio_channel(channel);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_AUDIO_SAMPLERATE:
+ {
+ int samplerate = atoi(cmd);
+ _media_format_set_audio_samplerate(samplerate);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_AUDIO_BIT:
+ {
+ int bit = atoi(cmd);
+ _media_format_set_audio_bit(bit);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_FORMAT_SET_AUDIO_AVG_BPS:
+ {
+ int audio_avg_bps = atoi(cmd);
+ _media_format_set_audio_avg_bps(audio_avg_bps);
+ reset_menu_state();
+ }
+ break;
+ case CURRENT_STATUS_DURATION:
+ {
+ uint64_t duration = atoi(cmd);
+ _media_packet_set_duration(duration);
+ reset_menu_state();
+ }
+ }
+
+ g_timeout_add(100, timeout_menu_display, 0);
+}
+
+void display_sub_basic()
+{
+ g_print("\n");
+ g_print("=========================================================================================\n");
+ g_print(" media tool test\n");
+ g_print("-----------------------------------------------------------------------------------------\n");
+ g_print(" *** How to use ***\n");
+ g_print(" : You can create 1 media_format_h handle by 'cf' and 1 media_packet_handle \n");
+ g_print(" : ex) cf > svm > svw > svh > svab > svmb >fgv > > a > iv > ir ...> d\n");
+ g_print(" : media_format_create is set to 'media_format_h[0]' \n");
+ g_print(" : media_packet_create_alloc & media_packet_create use 'media_format_h[0]' \n");
+ g_print(" : media_packet_create_from_tbm_surface use 'media_format_h[2]' \n");
+ g_print("\n");
+ g_print("cf. media_format_create\t\t");
+ g_print("\n");
+ g_print("svm. media_format_set_video_mime\t");
+ g_print("svw. media_format_set_video_width\t");
+ g_print("svh. media_format_set_video_height\t");
+ g_print("svab. media_format_set_video_avg_bps\t");
+ g_print("svmb. media_format_set_video_max_bps\t");
+ g_print("\n");
+ g_print("sam. media_format_set_audio_mime\t");
+ g_print("sac. media_format_set_audio_channel\t");
+ g_print("sas. media_format_set_audio_samplerate\t");
+ g_print("sab. media_format_set_audio_bit \t");
+ g_print("saab. media_format_set_audio_avg_bps\t");
+ g_print("\n");
+ g_print("fgv. media_format_get_video_info \t");
+ g_print("fga. media_format_get_audio_info \t\t");
+ g_print("\n");
+ g_print("\n");
+ g_print("a. media_packet_create_alloc(+media_format_unref) \t");
+ g_print("aa. media_packet_create(+media_format_unref) \t");
+ g_print("b. media_packet_create_from_tbm_surface(+media_format_unref) \n");
+ g_print("ab. media_packet_alloc \t\t");
+ g_print("c. media_packet_copy \t");
+ g_print("\n");
+ g_print("\n");
+ g_print("iv. media_packet_is_video \t");
+ g_print("ia. media_packet_is_audio \t");
+ g_print("ie. media_packet_is_encoded \t");
+ g_print("ir. media_packet_is_raw \t");
+ g_print("ht. media_packet_has_tbm_surface_buffer \t");
+ g_print("\n");
+ g_print("sd. media_packet_set_duration \t");
+ g_print("sf. media_packet_set_format(+media_format_unref) \t");
+ g_print("se. media_packet_set_extra \t");
+ g_print("\n");
+ g_print("gd. media_packet_get_duration \t");
+ g_print("gbp. media_packet_get_buffer_data_ptr \t");
+ g_print("gts. media_packet_get_tbm_surface \t");
+ g_print("gf. media_packet_get_format \t");
+ g_print("ge. media_packet_get_extra \t");
+ g_print("\n");
+ g_print("gs. media_packet_get_buffer_size\t");
+ g_print("\n");
+ g_print("\n");
+ g_print("d. media_packet_destroy \n");
+ g_print("q. quit test suite(if exist alive media_format, do media_format_unref)");
+ g_print("\n");
+ g_print("=========================================================================================\n");
+}
+
+
+gboolean input (GIOChannel *channel)
+{
+ gchar buf[MAX_STRING_LEN];
+ gsize read;
+ GError *error = NULL;
+
+ g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
+ buf[read] = '\0';
+ g_strstrip(buf);
+ interpret (buf);
+
+ return TRUE;
+}
+
+int main(int argc, char *argv[])
+{
+ GIOChannel *stdin_channel;
+ stdin_channel = g_io_channel_unix_new(0);
+ g_io_channel_set_flags (stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_add_watch (stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
+
+ displaymenu();
+
+ ops.data = NULL;
+
+ return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
+
+}
+