From 1b40680a5f7fb8e4cfd31b1330301f97fbe21319 Mon Sep 17 00:00:00 2001 From: Sehong Na Date: Sat, 31 May 2014 12:33:37 +0900 Subject: [PATCH 1/1] Initialize Tizen 2.3 --- AUTHORS | 2 + CMakeLists.txt | 97 + LICENSE.APLv2.0 | 201 ++ NOTICE | 4 + capi-content-media-content.manifest | 6 + capi-content-media-content.pc.in | 15 + include/media_audio.h | 372 ++++ include/media_bookmark.h | 163 ++ include/media_content.h | 139 ++ include/media_content_type.h | 604 ++++++ include/media_filter.h | 172 ++ include/media_folder.h | 276 +++ include/media_group.h | 319 +++ include/media_image.h | 234 +++ include/media_info.h | 1020 ++++++++++ include/media_info_private.h | 759 +++++++ include/media_playlist.h | 366 ++++ include/media_tag.h | 306 +++ include/media_util_private.h | 38 + include/media_video.h | 379 ++++ packaging/capi-content-media-content.spec | 73 + src/media_audio.c | 761 +++++++ src/media_bookmark.c | 218 ++ src/media_content.c | 978 +++++++++ src/media_db.c | 1047 ++++++++++ src/media_filter.c | 1255 ++++++++++++ src/media_folder.c | 460 +++++ src/media_group.c | 395 ++++ src/media_image.c | 444 ++++ src/media_info.c | 2964 +++++++++++++++++++++++++++ src/media_playlist.c | 738 +++++++ src/media_tag.c | 547 +++++ src/media_util_private.c | 131 ++ src/media_video.c | 770 +++++++ test/CMakeLists.txt | 18 + test/media-content_test.c | 3119 +++++++++++++++++++++++++++++ 36 files changed, 19390 insertions(+) create mode 100755 AUTHORS create mode 100755 CMakeLists.txt create mode 100755 LICENSE.APLv2.0 create mode 100644 NOTICE create mode 100644 capi-content-media-content.manifest create mode 100644 capi-content-media-content.pc.in create mode 100755 include/media_audio.h create mode 100755 include/media_bookmark.h create mode 100755 include/media_content.h create mode 100755 include/media_content_type.h create mode 100755 include/media_filter.h create mode 100755 include/media_folder.h create mode 100755 include/media_group.h create mode 100755 include/media_image.h create mode 100755 include/media_info.h create mode 100755 include/media_info_private.h create mode 100755 include/media_playlist.h create mode 100755 include/media_tag.h create mode 100755 include/media_util_private.h create mode 100755 include/media_video.h create mode 100755 packaging/capi-content-media-content.spec create mode 100755 src/media_audio.c create mode 100755 src/media_bookmark.c create mode 100755 src/media_content.c create mode 100755 src/media_db.c create mode 100755 src/media_filter.c create mode 100755 src/media_folder.c create mode 100755 src/media_group.c create mode 100755 src/media_image.c create mode 100755 src/media_info.c create mode 100755 src/media_playlist.c create mode 100755 src/media_tag.c create mode 100755 src/media_util_private.c create mode 100755 src/media_video.c create mode 100755 test/CMakeLists.txt create mode 100755 test/media-content_test.c diff --git a/AUTHORS b/AUTHORS new file mode 100755 index 0000000..677fb81 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Haejeong Kim +Hyunjun Ko diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..ae15081 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,97 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-content-media-content") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(dependents "dlog libmedia-service media-thumbnail libmedia-utils capi-base-common icu-i18n vconf") +SET(pc_dependents "dlog capi-base-common") + +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 "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +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") +ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64") + +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-content + 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}) + +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.0 b/LICENSE.APLv2.0 new file mode 100755 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE.APLv2.0 @@ -0,0 +1,201 @@ + 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 100644 index 0000000..ffbca8e --- /dev/null +++ b/NOTICE @@ -0,0 +1,4 @@ +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-content-media-content.manifest b/capi-content-media-content.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/capi-content-media-content.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/capi-content-media-content.pc.in b/capi-content-media-content.pc.in new file mode 100644 index 0000000..69956a2 --- /dev/null +++ b/capi-content-media-content.pc.in @@ -0,0 +1,15 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/media-content + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} + diff --git a/include/media_audio.h b/include/media_audio.h new file mode 100755 index 0000000..f1f345e --- /dev/null +++ b/include/media_audio.h @@ -0,0 +1,372 @@ +/* +* 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_AUDIO_META_H__ +#define __TIZEN_AUDIO_META_H__ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_CONTENT_MEDIA_AUDIO_META_MODULE + * @{ + * + * @file audio_meta.h + * @brief This file contains the audio metadata API and related structure and enumeration. \n + * Description of the audio content involves: album, artist, album_artist, author, genre and description tags. \n + * Parameters of the recording are also supported, as: format, bitrate, duration, size etc. + */ + + +/** + * @brief Destroys audio metadata. + * + * @param [in] audio The handle to audio metadata. + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Get copy of audio metadata handle handle by calling audio_meta_clone() + * @see audio_meta_clone() + */ +int audio_meta_destroy(audio_meta_h audio); + +/** + * @brief Clones audio metadata. + * @details Function copies the audio metadata handle handle from source to destination. + * + * @remark The destination handle must be released with audio_meta_destroy() by you. + * + * @param [out] dst A destination handle to audio metadata + * @param [in] src The source handle to audio metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see audio_meta_destroy() + */ +int audio_meta_clone(audio_meta_h *dst, audio_meta_h src); + +/** + * @brief Gets id of audio of given audio metadata. + * + * @remarks @a audio id must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] media_id The id of the audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_media_id(audio_meta_h audio, char **media_id); + +/** + * @brief Gets title of audio of given audio metadata. + * + * @remarks @a audio title must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] title The title of the audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_title(audio_meta_h audio, char **title); + +/** + * @brief Gets name of album of given audio metadata.\n + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a album_name must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] album_name The name of the album + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_album(audio_meta_h audio, char **album_name); + +/** + * @brief Gets name of artist of given audio metadata.\n + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a artist_name must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] artist_name The name of the artist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_artist(audio_meta_h audio, char **artist_name); + +/** + * @brief Gets name of album_artist of given audio metadata.\n + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a album_artist_name must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] album_artist_name The name of the album_artist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_album_artist(audio_meta_h audio, char **album_artist_name); + +/** + + * @brief Gets name of genre of given audio metadata.\n + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a genre_name must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] genre_name The name of the genre + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_genre(audio_meta_h audio, char **genre_name); + +/** + * @brief Gets name of composer of given audio metadata.\n + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a author_name must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] author_name The name of the author of audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_composer(audio_meta_h audio, char **composer_name); + +/** + * @brief Gets year of given audio metadata.\n + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a year must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] year The year of the audio file + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_year(audio_meta_h audio, char **year); + +/** + * @brief Gets recorded date of given audio metadata. + * + * @remarks @a recorded date must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] recorded_date The recorded date of the audio file + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_recorded_date(audio_meta_h audio, char **recorded_date); + +/** + * @brief Gets copyright notice of given audio metadata. + * + * @remarks @a copyright must be released with free() by you. + * + * @param [in] audio The handle to audio metadata + * @param [out] copyright The audio copyright notice + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int audio_meta_get_copyright(audio_meta_h audio, char **copyright); + +/** + * @brief Gets track number of given audio metadata. \n + * If the value is an empty string, the method returns "Unknown". + * + * @param [in] audio The handle to audio metadata + * @param [out] track_num The audio track number + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_track_num(audio_meta_h audio, char **track_num); + +/** + * @brief Gets bitrate of given audio metadata in bitrate per second. + * + * @param [in] audio The handle to audio metadata + * @param [out] bit_rate The audio bitrate in bit per second [bps] + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate); + +/** + * @brief Gets sample rate of given audio metadata. + * + * @param [in] audio The handle to audio metadata + * @param [out] sample_rate The audio sample rate[hz] + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_sample_rate(audio_meta_h audio, int *sample_rate); + +/** + * @brief Gets channel of given audio metadata. + * + * @param [in] audio The handle to audio metadata + * @param [out] channel The channel of audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_channel(audio_meta_h audio, int *channel); + +/** + * @brief Gets track duration of given audio metadata. + * + * @param [in] audio The handle to audio metadata + * @param [out] duration The audio file duration + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_duration(audio_meta_h audio, int *duration); + +/** + * @brief Gets number which represents how many times given audio has been played. + * + * @param [in] audio The handle to audio metadata + * @param [out] count_played The counter of audio played + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_played_count(audio_meta_h audio, int *played_count); + +/** + * @brief Gets the audio's played time parameter. + * @details Function returns audio's elapsed playback time parameter as period + * starting from the beginning of the track. + * + * @param [in] audio The handle to audio metadata + * @param [out] played_time The elapsed time of the audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_played_time(audio_meta_h audio, time_t *played_time); + +/** + * @brief Gets the audio's played position parameter. + * @details Function returns audio's elapsed playback position parameter as period + * starting from the beginning of the track. + * + * @param [in] audio The handle to audio metadata + * @param [out] played_position The elapsed time of the audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int audio_meta_get_played_position(audio_meta_h audio, int *played_position); + +/** + * @brief Sets the played count to audio meta handle. + * + * @param [in] audio The handle to audio metadata + * @param [in] played_count The played count of audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post audio_meta_update_to_db() + */ +int audio_meta_set_played_count(audio_meta_h audio, int played_count); + +/** + * @brief Sets the played time to audio meta handle. + * + * @param [in] audio The handle to audio metadata + * @param [in] played_time The played time of audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post audio_meta_update_to_db() + */ +int audio_meta_set_played_time(audio_meta_h audio, time_t played_time); + +/** + * @brief Sets the played position to audio meta handle. + * + * @param [in] audio The handle to audio metadata + * @param [in] played_position The played position of audio + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post audio_meta_update_to_db() + */ +int audio_meta_set_played_position(audio_meta_h audio, int played_position); + +/** + * @brief Updates audio metadata which is modified attributes to the media database. + * + * @details The function updates the given audio meta in the media database.\n + * The function should be called after any change in the attributes, to be updated to the media database.\n + * For example, after using audio_meta_set_played_count() for changing the count of the played, + * audio_meta_update_to_db() function should be called so as to update the given the attibutes in the media database. + * + * @param [in] audio The handle to audio metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see audio_meta_set_played_count() + * @see audio_meta_set_played_time() + * @see audio_meta_set_played_position() + */ +int audio_meta_update_to_db(audio_meta_h audio); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + +#endif /*__TIZEN_AUDIO_META_H__*/ diff --git a/include/media_bookmark.h b/include/media_bookmark.h new file mode 100755 index 0000000..3f73766 --- /dev/null +++ b/include/media_bookmark.h @@ -0,0 +1,163 @@ +/* +* 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_BOOKMARK_H__ +#define __TIZEN_MEDIA_BOOKMARK_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/** + * @addtogroup CAPI_CONTENT_MEDIA_BOOKMARK_MODULE + * @{ + * + * @file media_bookmark.h + * @brief This file contains API on main functional operations with bookmarks that are related to media resources in the media database. \n + * Operations include: inserting a new bookmark in media to the media database, removing bookmark from database, \n + * getting number of bookmarks, cloning and destroying bookmark, getting bookmark`s id, time marked parameter and thumbnail. + */ + +/** + * @brief Inserts a new bookmark in media on specified time offset to the media database. + * + * @param [in] media_id The id of media + * @param [in] time The bookmark time offset(in seconds) + * @param [in] thumbnail_path The thumbnail path of video bookmark. If the media type is audio, then thumbnail is null. + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_bookmark_delete_from_db() + * + */ +int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path); + +/** + * @brief Removes media bookmark from the media database. + * + * @param [in] bookmark The handle to media bookmark + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_bookmark_insert_to_db() + * + */ +int media_bookmark_delete_from_db(int bookmark_id); + +/** + * @brief Gets number of bookmark with optional filter from media database. + * + * @param [in] filter The handle to media filter + * @param [out] bookmark_count The count of media bookmark + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count); + +/** + * @brief Clones media bookmark. + * @details This function copies the media bookmark handle from a source to destination. There is no media_bookmark_create() function. + * The media_bookmark_h is created internally and available through media bookmark foreach function such as media_info_foreach_bookmark_from_db(). + * To use this handle outside of these foreach functions, use this function. + * + * @remark The destination handle must be released with media_bookmark_destroy() by you. + * + * @param [out] dst A destination handle to media bookmark + * @param [in] src The source handle to media bookmark + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_bookmark_destroy() + * @see media_info_foreach_bookmark_from_db() + * + */ +int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src); + +/** + * @brief Destroys media bookmark. + * @details Function frees all resources related to bookmark handle. This handle + * no longer can be used to perform any operation. A new handle has to + * be created before the next use. + * + * @param [in] bookmark The handle to media bookmark + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Get copy of bookmark handle by calling media_bookmark_clone() + * @see media_bookmark_clone() + */ +int media_bookmark_destroy(media_bookmark_h bookmark); + +/** + * @brief Gets bookmark's id. + * + * @param [in] bookmark The handle to media bookmark + * @param [out] bookmark_id The id of media bookmark + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id); + +/** + * @brief Gets bookmark's time marked parameter. + * @details Function returns time offset in milliseconds from beginning of the movie on which bookmark + * was placed. + * + * @param [in] bookmark The handle to media bookmark + * @param [out] marked_time The bookmark time offset(in milliseconds) + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t *marked_time); + +/** + * @brief Gets the media bookmark's thumbnail. + * + * @remarks @a path must be released with free() by you. + * + * @param [in] bookmark The handle to media bookmark + * @param [out] path The thumbnail path of media bookmark + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*__TIZEN_MEDIA_BOOKMARK_H__*/ diff --git a/include/media_content.h b/include/media_content.h new file mode 100755 index 0000000..141e4fd --- /dev/null +++ b/include/media_content.h @@ -0,0 +1,139 @@ +/* +* 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_CONTENT_H__ +#define __TIZEN_MEDIA_CONTENT_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @addtogroup CAPI_MEDIA_CONTENT_MODULE + * @{ + * @file media-content.h + * @brief This file contains API on functions proceeding with media content in db. \n + * Operations include connect and disconnect the media content service,scanning media file and folder with subfolders, \n + * subscribing and unsubscribing notifications of media db change. + */ + +/** + * @brief Connects to the media content service. + * @details Any media content related function call should be invoked after this function call. + * + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @post media_content_disconnect() + * @see media_content_disconnect() + * + */ +int media_content_connect(void); + +/** + * @brief Disconnects from the media content service. + * @details This function closes connection to the media content service. Any further media content related operation + * cannot be performed after this function is called. + * + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre media_content_connect() + * @see media_content_connect() + * + */ +int media_content_disconnect(void); + +/** + * @brief Requests to scan a media file. + * @details This function requests to scan a media file to media server. + * if media file was not registered to db yet, that media file information will be added to media db. And if already registered to db, then try to refresh information. + * if requested file is not exist on file system, information of the media file will be removed from media db. + * @param[in] path The file path + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @pre This function requires opened connection to content service by media_content_connect(). + * + */ +int media_content_scan_file(const char *path); + + +/** + * @brief Requests to scan a media folder, asynchronously. + * @details This function requests to scan a media folder to media server with given completed callback fucntion. + * #media_scan_completed_cb() function will be called when the scanning is finished. + * The sub folders are also scanned, if there are sub folder in that folder. \n + * If you want that the any folders are not scanned, you have to create a blank file ".scan_ignore" in that folder. + * @param[in] path The folder path + * @param[in] is_recursive /@a true if scan recursively subdirectories, + * /@a false if scan only current directory, + * @param[in] callback The callback to invoke when the scanning is finished + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @see media_scan_completed_cb() + * + */ +int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data); + +/** + * @brief Subscribe notifications of media db change. + * @details This function subscribes notifications of media db change, which are published by media server or other apps. + * #media_content_db_update_cb() function will be called when notification of media db change is subscribed. + * @param[in] callback The callback to invoke when the scanning is finished + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @see media_content_db_update_cb() + * @see media_content_unset_db_updated_cb() + * + */ +int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data); + +/** + + * @brief Unsubscribe notifications of media db change. + * @details This function unsubscribes notifications of media db change, which are published by media server or other apps. + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @pre media_content_set_db_updated_cb() + * @see media_content_set_db_updated_cb() + * + */ +int media_content_unset_db_updated_cb(void); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIA_CONTENT_H__ */ diff --git a/include/media_content_type.h b/include/media_content_type.h new file mode 100755 index 0000000..5c613d6 --- /dev/null +++ b/include/media_content_type.h @@ -0,0 +1,604 @@ +/* +* 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_CONTENT_TYPE_H__ +#define __TIZEN_MEDIA_CONTENT_TYPE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +#ifndef DEPRECATED_API +#define DEPRECATED_API __attribute__ ((deprecated)) +#endif + +/** +* @addtogroup CAPI_MEDIA_CONTENT_MODULE + * @{ + * @file media-content.h + * @brief This file contains API related to media-content enumerations for media data types, groups, orientations, \n + * classes of errors and definitions of media-data. \n + * Listed APIs are called when iterating over lists of album, group, bookmark and other media, \n + * when media items and burst shot are inserted completely and when notification of media db change is subscribed. + */ + +/** + * @ingroup CAPI_MEDIA_CONTENT_MODULE + * @brief The enumerations of the media file format. + */ +typedef enum +{ + MEDIA_CONTENT_TYPE_IMAGE = 0, /** + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @addtogroup CAPI_CONTENT_MEDIA_FILTER_MODULE + * @{ + * + * @file media-filter.h + * @brief This file contains the media filter API and related operatioins with filters \n + * The following functions include: creating and destroying media filter handles that are used to get filtered information, \n + * making free all resources related to filter handle, limiting number of items returned, setting conditions for filter, \n + * setting and getting media filter's content order and ordering keyword either descending or ascending. + */ + +/** + * @brief Creates a media filter handle. + * @details This function creates a media filter handle. The handle can be + * used to get filtered information based on filter properties i.e. offset, count, condition for searching and order. + * @remarks The @a filter handle must be released with media_info_filter_destroy() by you. + * @param[out] filter A handle to media filter + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_filter_destroy() + * + */ +int media_filter_create(filter_h *filter); + +/** + * @brief Destroys a media filter handle. + * @details The function frees all resources related to the media filter handle. The filter + * handle no longer can be used to perform any operation. A new filter handle + * has to be created before the next usage. + * + * @param[in] filter The handle to media filter + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * + */ +int media_filter_destroy(filter_h filter); + +/** + * @brief Set the media filter's offset and count. + * @details This function set the @a offset and @a count for the given filter used to limit number of items returned. + * For example, if you set the @a offset as 10 and @a count as 5, then only searched data from 10 to 14 will be returned when the filter is used with foreach functions. + * + * @param[in] filter The handle to media filter + * @param[in] offset The start position of the given filter(Starting from zero). + * @param[in] count The number of items to be searched with respect to offset + * @return return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * @see media_filter_destroy() + */ +int media_filter_set_offset(filter_h filter, int offset, int count); + +/** + * @brief Set the @a condition for given @a filter. + * + * @param[in] filter The handle to media filter + * @param[in] condition The condition which is used WHERE clause on a query + * @param[in] collate_type The collate type for comparing two strings + * @return return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * @see media_filter_destroy() + */ +int media_filter_set_condition(filter_h filter, const char *condition, media_content_collation_e collate_type); + +/** + * @brief Set the media filter's content @a order and @a order @a keyword either descending or ascending. + * + * @param[in] filter The handle to media filter + * @param[in] order_type The search order type + * @param[in] order_keyword The search order keyword + * @param[in] collate_type The collate type for comparing two strings + * @return return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * @see media_filter_destroy() + */ +int media_filter_set_order(filter_h filter, media_content_order_e order_type, const char *order_keyword, media_content_collation_e collate_type); + +/** + * @brief Gets the @a offset and @a count for the given @a filter used to limit number of items returned. + * + * @param[in] filter The handle to Media filter + * @param[out] offset The start position of the given filter(Starting from zero) + * @param[out] count The number of items to be searched with respect to offset + * @return return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * @see media_filter_destroy() + */ +int media_filter_get_offset(filter_h filter, int *offset, int *count); + +/** + * @brief Get the @a condition for given @a filter. + * + * @remarks @a condition must be released with free() by you. + * @param[in] filter The handle to media info filter + * @param[out] condition The condition which is used WHERE clause on a query + * @param[out] collate_type The collate type for comparing two strings + * @return return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * @see media_filter_destroy() + */ +int media_filter_get_condition(filter_h filter, char **condition, media_content_collation_e *collate_type); + +/** + * @brief Get the media filter's content @a order and @a order @a keyword either descending or ascending. + * + * @remarks @a order_keyword must be released with free() by you. + * @param[in] filter The handle to media filter + * @param[out] order_type The search order type + * @param[out] order_keyword The search order keyword + * @param[out] collate_type The collate type for comparing two strings + * @return return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * @see media_filter_destroy() + */ +int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *collate_type); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIA_FILTER_H__ */ diff --git a/include/media_folder.h b/include/media_folder.h new file mode 100755 index 0000000..e926791 --- /dev/null +++ b/include/media_folder.h @@ -0,0 +1,276 @@ +/* +* 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_FOLDER_H__ +#define __TIZEN_MEDIA_FOLDER_H__ + + +#include + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @addtogroup CAPI_CONTENT_MEDIA_FOLDER_MODULE + * @{ + * + * @file media-folder.h + * @brief This file contains API realted to all operations with media folder in db. \n + * These functions include getting number of folder and media files filtered from db, \n + * iterating through media files and folders filtered in the given folder from db; \n + * clonning and destroying media folder, getting its name, ID, absolute path and date \n + * and updating the media folder to the media database. + */ + +/** + * @brief Gets the number of folder for the passed @a filter from the media database. + * + * @param[in] filter The handle to filter. \n To allow searching over different content types, you should use @a filter_h. + * @param[out] folder_count The count of media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_folder_get_folder_count_from_db(filter_h filter, int *folder_count); + +/** + * @brief Iterates through available media folders with optional @a filter from the media database. + * @details This function gets media folder handles meeting the given + * @a filter. The @a callback function will be invoked for every retrieved + * folder. If NULL is passed to the @a filter, no filtering is applied. + * + * @param[in] filter The handle to media folder filter + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @pre A filter handle has to be created by calling media_folder_filter_create() + * @post This function invokes media_folder_cb() + * @see media_content_connect() + * @see #media_folder_cb + * @see media_filter_create() + */ +int media_folder_foreach_folder_from_db(filter_h filter, media_folder_cb callback, void *user_data); + +/** + * @brief Gets the number of media files for the passed @a filter in the given @a folder from the media database. + * + * @param[in] folder_id The ID of media folder + * @param[in] filter The filter of media content + * @param[out] media_count The count of media folder items + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_folder_get_media_count_from_db(const char *folder_id, filter_h filter, int *media_count); + +/** + * @brief Iterates through the media files with optional @a filter in the given @a folder from the media database. + * @details This function gets all media files associated with the given folder and + * meeting desired filter option and calls registered callback function for + * every retrieved media item. If NULL is passed to the @a filter, no filtering is applied. + * + * @param[in] folder_id The ID of media folder + * @param[in] filter The handle to media info filter + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_info_cb() + * @see #media_info_cb + * @see media_content_connect() + * @see media_folder_filter_create() + */ +int media_folder_foreach_media_from_db(const char *folder_id, filter_h filter, media_info_cb callback, void *user_data); + +/** + * @brief Clones the media folder. + * @details This function copies the media folder handle from a source to + * destination. There is no media_folder_create() function. The media_folder_h is created internally and available through + * media folder foreach function such as media_folder_foreach_folder_from_db(). To use this handle outside of these foreach functions, + * use this function. + * @remark The destination handle must be released with media_folder_destroy() by you. + * @param[out] dst A destination handle to media folder + * @param[in] src The source handle to media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_folder_destroy() + * @see media_folder_foreach_folder_from_db() + */ +int media_folder_clone(media_folder_h *dst, media_folder_h src); + +/** + * @brief Destroys the media folder. + * @details The function frees all resources related to the folder handle. This handle + * no longer can be used to perform any operation. A new handle has to + * be created before the next use. + * + * @param[in] folder The handle to media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre A copy of the media folder handle created by calling media_folder_clone() + * @see media_folder_clone() + */ +int media_folder_destroy(media_folder_h folder); + +/** + * @brief Gets media folder's ID. + * + * @remarks @a folder_id must be released with free() by you. + * + * @param [in] folder The handle to media folder + * @param [out] folder_id The ID of media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int media_folder_get_folder_id(media_folder_h folder, char **folder_id); + +/** + * @brief Gets the absolute path to the folder. + * + * @remarks @a path must be released with free() by you. + * + * @param[in] folder The handle to media folder + * @param[out] path The path of the media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_folder_get_path(media_folder_h folder, char **path); + +/** + * @brief Gets the folder name. + * + * @remarks @a folder_name must be released with free() by you. + * + * @param[in] folder The handle to media folder + * @param[out] folder_name The name of the media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_folder_get_name(media_folder_h folder, char **folder_name); + +/** + * @brief Gets the modified date of the folder. + * + * @param[in] folder The handle to media folder + * @param[out] date The modified date of folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_folder_get_modified_time(media_folder_h folder, time_t *date); + +/** + * @brief Gets the folder storage type. + * + * @param[in] folder The handle to media folder + * @param[out] storage_type The storage type of the media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_folder_get_storage_type(media_folder_h folder, media_content_storage_e *storage_type); + +/** + * @brief Gets the media folder from the media database. + * + * @details This function creates a new media folder handle from the media database by the given folder_id. + * media folder will be created, which is filled with folder information. + * + * @remarks @a folder must be released with media_folder_destroy() by you. + * + * @param[in] folder_id The ID of media folder + * @param[out] folder The media folder handle associated with the folder ID + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_folder_destroy() + * + */ +int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folder); + +/** + * @brief Updates the media folder to the media database. + * + * @details The function updates the given media folder in the media database. The function should be called after any change in folder attributes, to be updated to the media + * database. For example, after using media_folder_set_name() for setting the name of the folder, media_folder_update_to_db() function should be called so as to update + * the given folder attibutes in the media database. + * + * @param[in] folder The handle to media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_folder_destroy() + * @see media_folder_set_name() + * + */ +int media_folder_update_to_db(media_folder_h folder); + +/** + * @brief Sets the folder name. + * + * @param[in] folder The handle to media folder + * @param[in] name The name of the media folder + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @post media_folder_update_to_db() + * + */ +int media_folder_set_name(media_folder_h folder, const char *name); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIA_FOLDER_H__ */ diff --git a/include/media_group.h b/include/media_group.h new file mode 100755 index 0000000..fe62070 --- /dev/null +++ b/include/media_group.h @@ -0,0 +1,319 @@ +/* +* 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_GROUP_H__ +#define __TIZEN_MEDIA_GROUP_H__ + + +#include + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @addtogroup CAPI_CONTENT_MEDIA_ALBUM_MODULE + * @{ + * + * @file media_group.h + * @brief This file contains API related to handling different operations with album and other media data groups in db. \n + * The following APIs are capable to get number of albums, media info in the given album from db, \n + * to clone, destroy and get all albums and media files associated with the given media album from db, \n + * to get name, ID, artist, album art path from album; to get number of groups and their names, \n + * to get the number of media files and their content associated with the given group from db. + */ + +/** + * @brief Gets the number of album for the passed @a filter from the media database. + * + * @param[in] filter The handle to media filter. + * @param[out] album_count The count of media album + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_album_get_album_count_from_db(filter_h filter, int *album_count); + +/** + * @brief Iterates through the media album with optional @a filter from the media database. + * @details This function gets all media album handles meeting the given filter. + * The callback function will be invoked for every retrieved media album. + * If NULL is passed to the filter, no filtering is applied. + * + * @param [in] filter The handle to media filter + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_album_cb(). + * @see #media_album_cb + * @see media_content_connect() + * @see media_filter_create() + * + */ +int media_album_foreach_album_from_db(filter_h filter, media_album_cb callback, void *user_data); + +/** + * @brief Gets number of media info for the given album present in the media database. + * + * @param [in] album_id The ID of media album + * @param [in] filter The handle to media filter + * @param [out] media_count A count of album + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_album_get_media_count_from_db (int album_id, filter_h filter, int *media_count); + +/** + * @brief Iterates through the media files with optional @a filter in the given @a media @a album from the media database. + * @details This function gets all media files associated with the given media album and + * meeting desired filter option and calls registered callback function for + * every retrieved media info. If NULL is passed to the @a filter, no filtering is applied. + * + * @param [in] album_id The ID of media album + * @param [in] filter The handle to media filter + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_info_cb(). + * @see #media_info_cb + * @see media_content_connect() + * @see media_filter_create() + */ +int media_album_foreach_media_from_db(int album_id, filter_h filter, media_info_cb callback, void *user_data); + +/** + * @brief Destroys album handle. + * @details Function frees all resources related to album handle. This handle + * no longer can be used to perform any operation. A new handle has to + * be created before the next use. + * + * @param [in] album The handle to media album + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Get copy of album handle by calling media_album_clone() + * @see media_album_clone() + */ +int media_album_destroy(media_album_h album); + +/** + * @brief Clones media album. + * @details This function copies the media album handle from a source to + * destination. There is no media_album_create() function. The media_album_h is created internally and available through + * media album foreach function such as media_album_foreach_album_from_db(). To use this handle outside of these foreach functions, + * use this function. + * + * @remark The destination handle must be released with media_album_destroy() by you. + * + * @param [in] src The source handle to media album + * @param [out] dst A destination handle to media album + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_album_destroy() + * @see media_album_foreach_album_from_db() + */ +int media_album_clone(media_album_h *dst, media_album_h src); + +/** + * @brief Gets a ID of the album. + * + * @param [in] album The handle to media album + * @param [out] album_id A ID of media album + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_album_foreach_album_from_db() + * + */ +int media_album_get_album_id(media_album_h album, int *album_id); + +/** + * @brief Gets a name of the album. + * + * @remarks @a album_name must be released with free() by you. + * + * @param [in] album The handle to media album + * @param [out] album_name A name of media album handle + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_album_get_name(media_album_h album, char **album_name); + +/** + * @brief Gets a name of the artist from album. + * + * @remarks @a artist must be released with free() by you. + * + * @param [in] album The handle to media album + * @param [out] artist A name of media artist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_album_get_artist(media_album_h album, char **artist); + +/** + * @brief Gets a album art path from album. + * + * @remarks @a album_art must be released with free() by you. + * + * @param [in] album The handle to media album + * @param [out] album_art A path of media album_art + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_album_get_album_art(media_album_h album, char **album_art); + +/** + * @brief Gets the media album from the media database. + * + * @details This function creates a new media album handle from the media database by the given album_id. + * media album will be created, which is filled with album information. + * + * @remarks @a folder must be released with media_album_destroy() by you. + * + * @param[in] album_id The ID of media album + * @param[out] album The album handle associated with the album ID + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_album_destroy() + * + */ +int media_album_get_album_from_db(int album_id, media_album_h *album); + + +/** + * @} + */ + + +/** +* @addtogroup CAPI_CONTENT_MEDIA_GROUP_MODULE +* @{ +*/ + + /** + * @brief Gets the number of group for the passed @a filter from the media database. + * + * @param[in] filter The handle to media filter + * @param [in] group The type of media group + * @param[out] group_count The count of media group + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_group_get_group_count_from_db(filter_h filter, media_group_e group, int *group_count); + + /** + * @brief Iterates through the media group with optional @a filter from the media database. + * @details This function gets the names of media group meeting the given filter. + * The callback function will be invoked for every retrieved media group. + * If NULL is passed to the filter, no filtering is applied. + * + * @param [in] filter The handle to media filter + * @param [in] group The type of media group + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_group_cb(). + * @see #media_group_cb + * @see media_content_connect() + * @see media_filter_create() + */ +int media_group_foreach_group_from_db(filter_h filter, media_group_e group, media_group_cb callback, void *user_data); + + /** + * @brief Gets number of media info for the given media group present in the media database. + * + * @param [in] group_name The name of media group + * @param [in] group The type of media group + * @param [in] filter The handle to media filter + * @param [out] media_count The count of media + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_group_get_media_count_from_db(const char *group_name, media_group_e group, filter_h filter, int *media_count); + + /** + * @brief Iterates through the media files with optional @a filter in the given @a group from the media database. + * @details This function gets all media files associated with the given group and + * meeting desired filter option and calls registered callback function for + * every retrieved media info. If NULL is passed to the @a filter, no filtering is applied. + * + * @param [in] group_name The name of media group + * @param [in] group The type of media group + * @param [in] filter The handle to media filter + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_info_cb(). + * @see #media_info_cb + * @see media_content_connect() + * @see media_filter_create() + */ +int media_group_foreach_media_from_db(const char *group_name, media_group_e group, filter_h filter, media_info_cb callback, void *user_data); + + /** + * @} + */ + +#ifdef __cplusplus + } +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIA_GROUP_H__ */ diff --git a/include/media_image.h b/include/media_image.h new file mode 100755 index 0000000..e005f1b --- /dev/null +++ b/include/media_image.h @@ -0,0 +1,234 @@ +/* +* 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_IMAGE_META_H__ +#define __TIZEN_IMAGE_META_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/** + * @addtogroup CAPI_CONTENT_MEDIA_IMAGE_MODULE + * @{ + * + * @file media_image.h + * @brief This file contains the image metadata API and related functions to proceed with them. \n + * Functions include clonning and destroying image metadata, getting image metadata as width, height, \n + * orientation, date taken, title, weather, burst shot id and updating image to db. + */ + +/** + * @brief Clones image metadata. + * @details Function copies the image metadata handle from source to destination. + * + * @remark The destination handle must be released with image_meta_destroy() by you. + * + * @param [out] dst A destination handle to image metadata + * @param [in] src The source handle to image metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see image_meta_destroy() + */ +int image_meta_clone(image_meta_h *dst, image_meta_h src); + +/** + * @brief Destroys image metadata. + * @details The function frees all resources related to the image metadata handle. This handle + * no longer can be used to perform any operation. A new handle has to + * be created before next usage. + * + * @param [in] image The handle to image metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @pre Get copy of image_meta handle by calling image_meta_clone() + * @see image_meta_clone() + */ +int image_meta_destroy(image_meta_h image); + +/** + * @brief Gets the ID of image. + * + * @param [in] image The handle to image metadata + * @param [out] media_id The ID of image + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int image_meta_get_media_id(image_meta_h image, char **media_id); + +/** + * @brief Gets image's width in pixels. + * + * @param [in] image The handle to image metadata + * @param [out] width The image width in pixels + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int image_meta_get_width(image_meta_h image, int *width); + +/** + * @brief Gets image's height in pixels. + * + * @param [in] image The handle to image metadata + * @param [out] height The image height in pixels + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int image_meta_get_height(image_meta_h image, int *height); + +/** + * @brief Gets the image orientation. + * + * @param [in] image The handle to image metadata + * @param [out] orientation The image orientation + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int image_meta_get_orientation(image_meta_h image, media_content_orientation_e *orientation); + +/** + * @brief Gets the date, when image was created as time_t structure. + * + * @param [in] image The handle to image metadata + * @param [out] date_taken The time, when image was taken (in seconds, since the Epoch) + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int image_meta_get_date_taken(image_meta_h image, char **date_taken); + +/** + * @brief Gets the title. + * + * @remarks @a title must be released with free() by you. + * + * @param[in] media The handle to image metadata + * @param[out] title title of image + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int image_meta_get_title(image_meta_h image, char **title); + +/** + * @brief Gets the weather in maker note in exif. + * Example) WeatherInfo: Weather Condition=Sunny, Low Temp=22, High Temp=31 + * + * @remarks @a weather must be released with free() by you. + * + * @param[in] image The handle to image metadata + * @param[out] weather weather of image + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int image_meta_get_weather(image_meta_h image, char **weather); + +/** + * @brief Gets the burst shot id. + * + * @remarks @a burst id must be released with free() by you. + * + * @param[in] media The handle toimage metadata + * @param[out] burst_id The id of burst shot. if burst_id is NULL, this is not burst shot. + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int image_meta_get_burst_id(image_meta_h image, char **burst_id); + +/** + * @brief Checks whether the media is burst shot image. + * + * @param[in] media The handle to image metadata + * @param[out] is_burst_shot /@a true if the burst shot image, + * /@a false if not burst shot image. + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot); + +/** + * @brief Sets the weather information. + * + * @param [in] image The handle to image metadata + * @param [in] weather The image weather information + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post image_meta_update_to_db() + */ +int image_meta_set_weather(image_meta_h image, const char *weather); + +/** + * @brief Sets the image orientation. + * + * @param [in] image The handle to image metadata + * @param [in] orientation The image orientation + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post image_meta_update_to_db() + */ +int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation); + +/** + * @brief Updates the image to the media database. + * + * @details The function updates the given image meta in the media database. The function should be called after any change in image attributes, to be updated to the media + * database. For example, after using image_meta_set_orientation() for setting the orientation of the image, image_meta_update_to_db() function should be called so as to update + * the given image attibutes in the media database. + * + * @param[in] image The handle to image + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see image_meta_set_orientation() + * + */ +int image_meta_update_to_db(image_meta_h image); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /*__TIZEN_IMAGE_META_H__*/ diff --git a/include/media_info.h b/include/media_info.h new file mode 100755 index 0000000..e61da76 --- /dev/null +++ b/include/media_info.h @@ -0,0 +1,1020 @@ +/* +* 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_INFORMATION_H__ +#define __TIZEN_MEDIA_INFORMATION_H__ + +#include + + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/** + * @addtogroup CAPI_CONTENT_MEDIA_INFO_MODULE + * @{ + * @file media_info.h + * @brief This file contains the media info API and related functions to proceed with it. \n + * Functions are capabale to insert, clone, delete, get number, content of files from db. \n + * Get and set properties and parameters such as storage type, provider, category etc. of media info, \n + * handling with thumbnail and updaing media info to db. + */ + +/** + * @brief Inserts media file into the media database. + * @details This function inserts an media item into the content storage. + * Normally, inserting a media file in database is done automatically by media server, without calling this function. + * This function is only called when media server is busy and user needs to get quick result of inserting + * e.g. Taking a photo while media server is busy and user want to see the quick snapshot of the photo taken. + * @remark The handle must be released with media_info_destroy() by you. + * + * @param[in] path The path to the media file + * @param[out] info The handle to the media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_info_insert_to_db (const char *path, media_info_h *info); + +/** + * @brief Insert media files into the media database, asynchronously. + * @details This function insert an media items into the content storage. + * Normally, inserting a media file in database is done automatically by media server, without calling this function. + * This function invokes media_insert_completed_cb callback function. + * #media_insert_completed_cb will be called when insertion to media database is finished. + * + * @param[in] path_array The path array to the media files + * @param[in] array_length The length of array + * @param[in] callback The callback to invoke when media items inserted completely + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_insert_completed_cb() + */ +int media_info_insert_batch_to_db(const char **path_array,unsigned int array_length, media_insert_completed_cb callback, void *user_data); + +/** + * @brief Insert the burst shot images into the media database, asynchronously. + * @details This function insert the busrt images into the content storage. + * #media_insert_burst_shot_completed_cb will be called when insertion to media database is finished. + * + * @param[in] path_array The path array to the burst shot images + * @param[in] array_length The length of array + * @param[in] callback The callback to invoke when the images inserted completely + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_insert_burst_shot_completed_cb() + */ +int media_info_insert_burst_shot_to_db(const char **path_array,unsigned int array_length, media_insert_burst_shot_completed_cb callback, void *user_data); + +/** + * @brief Deletes media file from the media database. + * @details This function deletes an media item from the content storage. + * Normally, deleting a media file in database is done automatically by media server, without calling this function. + * This function is only called when media server is busy and user needs to get quick result of deleting + * + * @param[in] media_id The ID to the media file + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_info_delete_from_db(const char *media_id); + +/** + * @brief Deletes media files from the media database. The media files to delete can be specified as a condition in a filter. + * @details This function deletes the media items from the content storage. + * Normally, deleting media files in database are done automatically by media server, without calling this function. + * This function is only called when media server is busy and user needs to get quick result of deleting + * + * @param[in] filter The handle to filter + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_info_delete_batch_from_db(filter_h filter); + + +/** + * @brief Destroys the media info. + * @details The function frees all resources related to the media info handle. This handle + * no longer can be used to perform any operation. New media info handle has to + * be created before next usage. + * + * @param[in] media The handle to media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Get copy of media_info handle by calling media_info_clone() + * @see media_info_clone() + */ +int media_info_destroy(media_info_h media); + +/** + * @brief Clones the media info handle. + * + * @details This function copies the media info handle from a source to destination. + * There is no media_info_create() function. The media_info_h is created internally and + * available through media info foreach function such as media_info_foreach_media_from_db(). + * To use this handle outside of these foreach functions, use this function. + * @remark The destination handle must be released with media_info_destroy() by you. + * + * @param[out] dst A destination handle to media info + * @param[in] src The source handle to media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_info_destroy() + * @see media_album_foreach_media_from_db() + * @see media_playlist_foreach_media_from_db() + * @see media_group_foreach_media_from_db + * @see media_tag_foreach_media_from_db() + * @see media_info_foreach_media_from_db() + * @see media_folder_foreach_media_from_db() + * + */ +int media_info_clone(media_info_h *dst, media_info_h src); + +/** + * @brief Gets the number of media info for the passed @a filter from the media database. + * + * @param[in] filter The handle to filter. + * @param[out] media_count The count of media + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_info_get_media_count_from_db(filter_h filter, int *media_count); + +/** + * @brief Iterates through media info from the media database. + * @details This function gets all media info handles meeting the given @a filter. The @a callback function will be invoked for every retrieved media info. + * If NULL is passed to the @a filter, no filtering is applied. + * @param[in] filter The handle to media info filter + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_info_cb(). + * @see media_content_connect() + * @see #media_info_cb + * @see media_info_filter_create() + * + */ +int media_info_foreach_media_from_db(filter_h filter, media_info_cb callback, void *user_data); + +/** + * @brief Gets the number of media tag for the passed @a filter in the given @a media ID from the media database. + * + * @param[in] media_id The ID of media info + * @param[in] filter The handle to media filter + * @param[out] tag_count The count of media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_info_get_tag_count_from_db(const char *media_id, filter_h filter, int *tag_count); + +/** + * @brief Iterates through the media tag in the given @a media @a info from the media database. + * @details This function gets all media tag associated with the given @a media and calls registered callback function for every retrieved media tag. + * @param[in] media_id The ID of media info + * @param[in] filter The handle to media filter + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_tag_cb(). + * @see media_content_connect() + * @see #media_tag_cb + */ +int media_info_foreach_tag_from_db(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data); + +/** + * @brief Gets the number of bookmark for the passed @a filter in the given @a media ID from the media database. + * + * @param[in] media_id The ID of media info + * @param[in] filter The handle to media filter + * @param[out] bookmark_count The count of media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_info_get_bookmark_count_from_db(const char *media_id, filter_h filter, int *bookmark_count); + +/** + * @brief Iterates through the media bookmark in the given @a media @a info from the media database. + * @details This function gets all media bookmark associated with the given @a media and calls registered callback function for every retrieved media bookmark. + * @param[in] media_id The ID of media info + * @param[in] filter The handle to media filter + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_bookmark_cb(). + * @see media_content_connect() + * @see #media_bookmark_cb + */ +int media_info_foreach_bookmark_from_db (const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data); + +/** + * @brief Gets image metadata for a given media info. + * @details This function returns an image metadata handle retrieved from the media info. + * + * @remark The @a image handle must be released with image_meta_destroy() by you. + * + * @param [in] media The handle to media info + * @param[out] image A handle to image meta + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see image_meta_destroy() + */ +int media_info_get_image(media_info_h media, image_meta_h *image); + +/** + * @brief Gets video metadata for a given media info. + * @details This function returns a video metadata handle retrieved from the media info handle. + * + * @remark The @a video handle must be released with video_meta_destroy() by you. + * + * @param [in] media The handle to media info + * @param[out] video A handle to the video meta + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see video_meta_destroy() + * + */ +int media_info_get_video(media_info_h media, video_meta_h *video); + +/** + * @brief Gets audio metadata for a given media info. + * @details This function returns an audio metadata handle retrieved from the media info handle. + * + * @remark The @a audio handle must be released with audio_meta_destroy() by you. + * + * @param [in] media The handle to media info + * @param[out] audio A handle to the audio meta + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see audio_meta_destroy() + */ +int media_info_get_audio(media_info_h media, audio_meta_h *audio); + +/** + * @brief Gets ID to media info. + * + * @param [in] media_id The ID if media info + * @param [out] media_id The ID of media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int media_info_get_media_id(media_info_h media, char **media_id); + +/** + * @brief Gets path to media info. + * + * @remarks @a path must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] path The path of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_info_get_file_path(media_info_h media, char **path); + +/** + * @brief Gets name to media info. + * + * @remarks @a name must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] name The name of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_display_name(media_info_h media, char **name); + +/** + * @brief Gets media info's content type. + * + * @param[in] media The handle to media info + * @param[out] type The type of media content(#media_content_type_e) + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_media_type(media_info_h media, media_content_type_e *type); + +/** + * @brief Gets name to media info. + * + * @remarks @a mime_type must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] mime_type The mime type of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_mime_type(media_info_h media, char **mime_type); + +/** + * @brief Gets media file's size. + * + * @param[in] media The handle to media info + * @param[out] size The type of media content + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_size(media_info_h media, unsigned long long *size); + +/** + * @brief Gets added time. + * + * @param[in] media The handle to media info + * @param[out] added_time The added time to DB + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_added_time(media_info_h media, time_t *added_time); + +/** + * @brief Gets media info's date of modification. + * + * @param[in] media The handle to media info + * @param[out] time The date of modification of File. Get from File + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_modified_time(media_info_h media, time_t *time); + +/** + * @brief Gets media info's timeline. + * + * @param[in] media The handle to media info + * @param[out] time The date of timeline. + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_timeline(media_info_h media, time_t* time); + +/** + * @brief Gets the thumbnail to media info. + * + * @remarks @a path must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] path The path to thumbnail of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_thumbnail_path(media_info_h media, char **path); + +/** + * @brief Gets the description to media info. + * + * @remarks @a description must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] description The description of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_description(media_info_h media, char **description); + +/** + * @brief Gets media info's longitude. + * + * @param[in] media The handle to media info + * @param[out] longitude The longitude of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_longitude(media_info_h media, double* longitude); + +/** + * @brief Gets media info's latitude. + * + * @param[in] media The handle to media info + * @param[out] latitude The latitude of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_latitude(media_info_h media, double* latitude); + +/** + * @brief Gets media info's altitude of modification. + * + * @param[in] media The handle to media info + * @param[out] altitude The altitude of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_altitude(media_info_h media, double* altitude); + +/** + * @brief Gets media info's weather. + * + * @param[in] media The handle to media info + * @param[out] weater The weather of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_weather(media_info_h media, char **weather); + +/** + * @brief Gets media info's rating. + * + * @param[in] media The handle to media info + * @param[out] rating The rating of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_rating(media_info_h media, int *rating); + +/** + * @brief Gets the given media info's favorite status. + * + * @param [in] media The handle to media info + * @param [out] favorite The media favorite status(non zero if favorite, 0 if not favorite) + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_favorite(media_info_h media, bool* favorite); + +/** + * @brief Gets the author to media info. + * + * @remarks @a author must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] author The author of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_author(media_info_h media, char **author); + +/** + * @brief Gets the provider to media info. + * + * @remarks @a provider must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] provider The provider of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_provider(media_info_h media, char **provider); + +/** + * @brief Gets the content name to media info. + * + * @remarks @a content_name must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] content_name The content name of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_content_name(media_info_h media, char **content_name); + +/** + * @brief Gets the title to media info. + * + * @remarks @a title must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] title The title of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_title(media_info_h media, char **title); + +/** + * @brief Gets the provider to media info. + * + * @remarks @a category must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] category The category of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_category(media_info_h media, char **category); + +/** + * @brief Gets the location_tag to media info. + * + * @remarks @a location_tag must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] location_tag The location of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_location_tag(media_info_h media, char **location_tag); + +/** + * @brief Gets the age_rating to media info. + * + * @remarks @a age_rating must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] age_rating The age rating of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_age_rating(media_info_h media, char **age_rating); + +/** + * @brief Gets the keyword to media info. + * + * @remarks @a keyword must be released with free() by you. + * + * @param[in] media The handle to media info + * @param[out] keyword The keyword of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_keyword(media_info_h media, char **keyword); + +/** + * @brief Checks whether the media is protected via drm. + * + * @param[in] media The handle to media info + * @param[out] is_drm /@a true if the drm media, + * /@a false if not drm. + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_is_drm(media_info_h media, bool *is_drm); + +/** + * @brief Gets media info's storage_type. + * + * @param[in] media The handle to media info + * @param[out] storage_type The storage type of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type); + +/** + * @brief Gets the media info from the media database. + * + * @details This function creates a new media handle from the media database by the given media_id. + * media info will be created, which is filled with info information. + * + * @remarks @a media must be released with media_tag_destroy() by you. + * + * @param[in] media_id The ID of media info + * @param[out] media The media handle associated with the media ID + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_info_destroy() + * + */ +int media_info_get_media_from_db(const char *media_id, media_info_h *media); + +/** + * @brief Sets display name to media info. + * + * @param[in] media The handle to media info + * @param[in] display_name The display name of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_display_name(media_info_h media, const char *display_name); + +/** + * @brief Sets description to media info. + * + * @param[in] media The handle to media info + * @param[in] description The description of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_description(media_info_h media, const char *description); + +/** + * @brief Sets longitude to media info. + * + * @param[in] media The handle to media info + * @param[in] longitude The longitude of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_longitude(media_info_h media, double longitude); + +/** + * @brief Sets latitude to media info. + * + * @param[in] media The handle to media info + * @param[in] latitude The latitude of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_latitude(media_info_h media, double latitude); + +/** + * @brief Sets altitude to media info. + * + * @param[in] media The handle to media info + * @param[in] altitude The altitude of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_altitude(media_info_h media, double altitude); + +/** + * @brief Sets weather to media info. + * + * @param[in] media The handle to media info + * @param[in] weather The weather of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_weather(media_info_h media, const char *weather); + +/** + * @brief Sets rating to media info. + * + * @param[in] media The handle to media info + * @param[in] rating The rating of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_rating(media_info_h media, int rating); + +/** + * @brief Sets favorite to media info. + * + * @param[in] media The handle to media info + * @param[in] favorite The favorite of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_set_favorite(media_info_h media, bool favorite); + +/** + * @brief Sets author to media info. + * + * @param[in] media The handle to media info + * @param[in] author The author of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_set_author(media_info_h media, const char *author); + +/** + * @brief Sets provider to media info. + * + * @param[in] media The handle to media info + * @param[in] provider The provider of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + */ +int media_info_set_provider(media_info_h media, const char *provider); + +/** + * @brief Sets content name to media info. + * + * @param[in] media The handle to media info + * @param[in] content_name The content name of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_content_name(media_info_h media, const char *content_name); + +/** + * @brief Sets category to media info. + * + * @param[in] media The handle to media info + * @param[in] category The category of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_category(media_info_h media, const char *category); + +/** + * @brief Sets location tag to media info. + * + * @param[in] media The handle to media info + * @param[in] location_tag The location of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_location_tag(media_info_h media, const char *location_tag); + +/** + * @brief Sets age rating to media info. + * + * @param[in] media The handle to media info + * @param[in] age_rating The age rating of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_age_rating(media_info_h media, const char *age_rating); + +/** + * @brief Sets keyword to media info. + * + * @param[in] media The handle to media info + * @param[in] keyword The keyword of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_keyword(media_info_h media, const char *keyword); + +/** + * @brief Updates the media info to the media database. + * + * @details The function updates the given media info in the media database. The function should be called after any change in media, to be updated to the media + * database. For example, after using media_info_set_display_name() for setting the name of the media, media_info_update_to_db() function should be called so as to update + * the given media info attibutes in the media database. + * + * @param[in] media The handle to media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_info_set_display_name() + * @see media_info_set_description() + * @see media_info_set_longitude() + * @see media_info_set_latitude() + * @see media_info_set_altitude() + * @see media_info_set_rating() + * @see media_info_set_favorite() + * @see media_info_set_author() + * @see media_info_set_provider() + * @see media_info_set_content_name() + * @see media_info_set_category() + * @see media_info_set_location_tag() + * @see media_info_set_age_rating() + * + */ +int media_info_update_to_db(media_info_h media); + +/** + * @brief Refresh the metadata of media to media database. + * + * @param[in] media_id The ID of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_info_refresh_metadata_to_db(const char *media_id); + +/** + * @brief Sets added_time to media info. + * + * @param[in] media The handle to media info + * @param[in] added_time The added time of media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post media_info_update_to_db() + * + */ +int media_info_set_added_time(media_info_h media, time_t added_time); + +/** + * @brief Moves the media info to the given destination path in the media database. + * + * @param[in] media The handle to media info + * @param[in] dst_path The path of destination + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_info_move_to_db(media_info_h media, const char* dst_path); + +/** + * @brief Creates a thumbnail image for given the media, asynchronously. + * @details This function creates an thumbnail image for given media item and and calls registered callback function for completion of creating the thumbnail. + * If there already exist a thumbnail for given media, then the path of thumbnail will be return in callback function. + * + * @param[in] media The handle to media info + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter ( Especially, if the request is duplicated, this error returns. ) + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data); + + +/** + * @brief Cancel to creates a thumbnail image for given the media. + * + * @param[in] media The handle to media info + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + */ +int media_info_cancel_thumbnail(media_info_h media); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIA_INFORMATION_H__ */ diff --git a/include/media_info_private.h b/include/media_info_private.h new file mode 100755 index 0000000..1b1109c --- /dev/null +++ b/include/media_info_private.h @@ -0,0 +1,759 @@ +/* +* 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_INFO_PRIVATE_H__ +#define __TIZEN_MEDIA_INFO_PRIVATE_H__ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +/** + * @addtogroup CAPI_CONTENT_MEDIA_INFO_MODULE +* @{ +* +* @file media_info_private.h +* @brief This file contains the media info API and related structure and enumeration. \n +* Description of the audio, video,image content involves: album, artist, album_artist, author, genre and description tags. \n +* Parameters of the recording are also supported, as: format, bitrate, duration, size etc. \n +* Defenitions of media DB fields and tables, operations with media data relating to DB and handling with media filter attributes. +*/ + +#define LOG_TAG "CAPI_CONTENT_MEDIA_CONTENT" + +#define SAFE_STRLCPY(dst, src, n) ((g_strlcpy(dst, src, n) < n) ? TRUE : FALSE) +#define SAFE_STRLCAT(dst, src, n) g_strlcat(dst, src, n); +#define SAFE_FREE(src) {if(src) {free(src); src = NULL;}} +#define STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE) +#define SQLITE3_FINALIZE(x) {if(x != NULL) {sqlite3_finalize(x);}} + +#define MEDIA_CONTENT_THUMB_DEFAULT_PATH MEDIA_DATA_PATH"/.thumb/thumb_default.png" +#define MEDIA_CONTENT_INSERT_FILES_PATH MEDIA_DATA_PATH"/" + +#define MAX_QUERY_SIZE 4096 +#define DEFAULT_QUERY_SIZE 1024 +#define COLLATE_STR_SIZE 32 +#define MEDIA_CONTENT_UUID_SIZE 36 +#define BATCH_REQUEST_MAX 300 + +typedef enum { + MEDIA_CONTENT_TYPE = 0, + MEDIA_THUMBNAIL_TYPE, + MEDIA_REGISTER_TYPE +} media_info_error_type_e; + +typedef enum { + MEDIA_TAG_ADD, + MEDIA_TAG_REMOVE, + MEDIA_TAG_UPDATE_TAG_NAME, +} tag_function_e; + +typedef enum { + MEDIA_PLAYLIST_ADD, + MEDIA_PLAYLIST_REMOVE, + MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME, + MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH, + MEDIA_PLAYLIST_UPDATE_PLAY_ORDER, +} playlist_function_e; + +typedef enum { + MEDIA_GROUP_NONE, + MEDIA_GROUP_ALBUM, + MEDIA_GROUP_FOLDER, + MEDIA_GROUP_PLAYLIST, + MEDIA_GROUP_TAG, + MEDIA_GROUP_BOOKMARK, + MEDIA_GROUP_TAG_BY_MEDIA_ID, + MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, +} group_list_e; + +typedef enum { + MEDIA_BATCH_INSERT_NORMAL, + MEDIA_BATCH_INSERT_BURSTSHOT, +} media_batch_insert_e; + +typedef struct _filter_s +{ + char *condition; + char *order_keyword; + media_content_order_e order_type; + media_content_collation_e condition_collate_type; + media_content_collation_e order_collate_type; + int offset; + int count; +}filter_s; + +typedef struct +{ + char *folder_id; //image id, audio id, video id + char *path; + char *name; + time_t modified_time; + media_content_storage_e storage_type; +}media_folder_s; + +typedef struct +{ + int tag_id; + char *name; +}media_tag_s; + +typedef struct +{ + int bookmark_id; + char *media_id; + time_t marked_time; + char *thumbnail_path; +}media_bookmark_s; + +typedef struct +{ + int album_id; + char *name; + char *artist; + char *album_art_path; +}media_album_s; + +typedef struct +{ + int playlist_id; //playlist id + char *name; // playlist name + char *thumbnail_path; //playlist thumbnail path +}media_playlist_s; + +typedef struct +{ + char *media_id; + int width; + int height; + char *date_taken; + char *title; + char *burst_id; + char *weather; + media_content_orientation_e orientation; +}image_meta_s; + +typedef struct +{ + char *media_id; + char *title; + char *album; + char *artist; + char *album_artist; + char *genre; + char *composer; + char *year; + char *recorded_date; + char *copyright; + char *track_num; + int bitrate; + int duration; + int width; + int height; + int played_count; + time_t played_time; + int played_position; +}video_meta_s; + +typedef struct +{ + char *media_id; + char *title; + char *album; + char *artist; + char *album_artist; + char *genre; + char *composer; + char *year; + char *recorded_date; + char *copyright; + char *track_num; + int bitrate; + int samplerate; + int channel; + int duration; + int played_count; + time_t played_time; + int played_position; +}audio_meta_s; + +typedef struct +{ + char *media_id; //image id, audio id, video id + char *file_path; + char *display_name; + media_content_type_e media_type; + char *mime_type; + unsigned long long size; + time_t added_time; + time_t modified_time; + time_t timeline; + char *thumbnail_path; + char *description; + double longitude; + double latitude; + double altitude; + char *weather; + int rating; + time_t favourite; + char *title; + char *author; + char *provider; + char *content_name; + char *category; + char *location_tag; + char *age_rating; + char *keyword; + int is_drm; + int storage_type; + int sync_status; + image_meta_s *image_meta; + video_meta_s *video_meta; + audio_meta_s *audio_meta; +}media_info_s; + +typedef struct +{ + char *media_id; // media_uuid + int function; // Add, remove, modify + char *tag_name; // tag_name +}media_tag_item_s; + +typedef struct +{ + char *media_id; // media_uuid + int function; // Add, remove, modify + char *playlist_name; // playlist_name + char *thumbnail_path; //playlist thumbnail path + int playlist_member_id; // playlist unique id of media. Same content which has same media_id can be added to Playlist + int play_order; //play_order +}media_playlist_item_s; + +typedef struct _attribute_map_s +{ + GHashTable *attr_map; +}attribute_s; + +typedef struct +{ + media_info_s *handle; + void *user_data; + media_thumbnail_completed_cb thumbnail_completed_cb; +}media_thumbnail_cb_s; + +typedef struct +{ + media_insert_completed_cb insert_completed_cb; + char *insert_list_path; + void *user_data; +} media_insert_cb_s; + +typedef struct +{ + media_content_db_update_cb update_noti_cb; + void *user_data; +} media_noti_cb_s; + +typedef struct attribute_s *attribute_h; + + +typedef struct _media_content_cb_data { + media_scan_completed_cb callback; + void *user_data; +} media_content_scan_cb_data; + + +/* DB Table */ +#define DB_TABLE_MEDIA "media" +#define DB_TABLE_FOLDER "folder" +#define DB_TABLE_ALBUM "album" +#define DB_TABLE_TAG "tag" +#define DB_TABLE_TAG_MAP "tag_map" +#define DB_TABLE_PLAYLIST "playlist" +#define DB_TABLE_PLAYLIST_MAP "playlist_map" +#define DB_TABLE_BOOKMARK "bookmark" + +/* DB View */ +#define DB_VIEW_PLAYLIST "playlist_view" +#define DB_VIEW_TAG "tag_view" + +/* DB Table Alias */ +#define DB_TABLE_ALIAS_MEDIA "m" +#define DB_TABLE_ALIAS_FOLDER "f" +#define DB_TABLE_ALIAS_PLAYLIST "p" +#define DB_TABLE_ALIAS_PLAYLIST_MAP "pm" +#define DB_TABLE_ALIAS_TAG "t" +#define DB_TABLE_ALIAS_BOOKMARK "b" +#define DB_TABLE_ALIAS_ALBUM "a" + +/* DB field for media */ +#define DB_FIELD_MEDIA_ID "media_uuid" +#define DB_FIELD_MEDIA_PATH "path" +#define DB_FIELD_MEDIA_DISPLAY_NAME "file_name" +#define DB_FIELD_MEDIA_TYPE "media_type" +#define DB_FIELD_MEDIA_MIME_TYPE "mime_type" +#define DB_FIELD_MEDIA_SIZE "size" +#define DB_FIELD_MEDIA_ADDED_TIME "added_time" +#define DB_FIELD_MEDIA_MODIFIED_TIME "modified_time" +#define DB_FIELD_MEDIA_TIMELINE "timeline" +#define DB_FIELD_MEDIA_THUMBNAIL_PATH "thumbnail_path" +#define DB_FIELD_MEDIA_TITLE "title" +#define DB_FIELD_MEDIA_ALBUM "album" +#define DB_FIELD_MEDIA_ARTIST "artist" +#define DB_FIELD_MEDIA_ALBUM_ARTIST "album_artist" +#define DB_FIELD_MEDIA_GENRE "genre" +#define DB_FIELD_MEDIA_COMPOSER "composer" +#define DB_FIELD_MEDIA_YEAR "year" +#define DB_FIELD_MEDIA_RECORDED_DATE "recorded_date" +#define DB_FIELD_MEDIA_COPYRIGHT "copyright" +#define DB_FIELD_MEDIA_TRACK_NUM "track_num" +#define DB_FIELD_MEDIA_DESCRIPTION "description" +#define DB_FIELD_MEDIA_BITRATE "bitrate" +#define DB_FIELD_MEDIA_SAMPLERATE "samplerate" +#define DB_FIELD_MEDIA_CHANNEL "channel" +#define DB_FIELD_MEDIA_DURATION "duration" +#define DB_FIELD_MEDIA_LONGITUDE "longitude" +#define DB_FIELD_MEDIA_LATITUDE "latitude" +#define DB_FIELD_MEDIA_ALTITUDE "altitude" +#define DB_FIELD_MEDIA_WIDTH "width" +#define DB_FIELD_MEDIA_HEIGHT "height" +#define DB_FIELD_MEDIA_DATETAKEN "datetaken" +#define DB_FIELD_MEDIA_ORIENTATION "orientation" +#define DB_FIELD_MEDIA_BURST_ID "burst_id" +#define DB_FIELD_MEDIA_PLAYED_COUNT "played_count" +#define DB_FIELD_MEDIA_LAST_PLAYED_TIME "last_played_time" +#define DB_FIELD_MEDIA_LAST_PLAYED_POSITION "last_played_position" +#define DB_FIELD_MEDIA_RATING "rating" +#define DB_FIELD_MEDIA_FAVOURITE "favourite" +#define DB_FIELD_MEDIA_AUTHOR "author" +#define DB_FIELD_MEDIA_PROVIDER "provider" +#define DB_FIELD_MEDIA_CONTENT_NAME "content_name" +#define DB_FIELD_MEDIA_CATEGORY "category" +#define DB_FIELD_MEDIA_LOCATION_TAG "location_tag" +#define DB_FIELD_MEDIA_AGE_RATING "age_rating" +#define DB_FIELD_MEDIA_KEYWORD "keyword" +#define DB_FIELD_MEDIA_WEATHER "weather" +#define DB_FIELD_MEDIA_IS_DRM "is_drm" +#define DB_FIELD_MEDIA_STORAGE_TYPE "storage_type" + +#define DB_FIELD_MEDIA_FILE_NAME_PINYIN "file_name_pinyin" +#define DB_FIELD_MEDIA_TITLE_PINYIN "title_pinyin" +#define DB_FIELD_MEDIA_ALBUM_PINYIN "album_pinyin" +#define DB_FIELD_MEDIA_ARTIST_PINYIN "artist_pinyin" +#define DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN "album_artist_pinyin" +#define DB_FIELD_MEDIA_GENRE_PINYIN "genre_pinyin" +#define DB_FIELD_MEDIA_COMPOSER_PINYIN "composer_pinyin" +#define DB_FIELD_MEDIA_COPYRIGHT_PINYIN "copyright_pinyin" +#define DB_FIELD_MEDIA_DESCRIPTION_PINYIN "description_pinyin" +#define DB_FIELD_MEDIA_AUTHOR_PINYIN "author_pinyin" +#define DB_FIELD_MEDIA_PROVIDER_PINYIN "provider_pinyin" +#define DB_FIELD_MEDIA_CONTENT_NAME_PINYIN "content_name_pinyin" +#define DB_FIELD_MEDIA_CATEGORY_PINYIN "category_pinyin" +#define DB_FIELD_MEDIA_LOCATION_TAG_PINYIN "location_tag_pinyin" +#define DB_FIELD_MEDIA_AGE_RATING_PINYIN "age_rating_pinyin" +#define DB_FIELD_MEDIA_KEYWORD_PINYIN "keyword_pinyin" + +/* DB field for folder */ +#define DB_FIELD_FOLDER_ID "folder_uuid" +#define DB_FIELD_FOLDER_PATH "path" +#define DB_FIELD_FOLDER_NAME "name" +#define DB_FIELD_FOLDER_MODIFIED_TIME "modified_time" +#define DB_FIELD_FOLDER_STORAGE_TYPE "storage_type" +#define DB_FIELD_FOLDER_NAME_PINYIN "name_pinyin" + +/* DB field for playlist */ +#define DB_FIELD_PLAYLIST_ID "playlist_id" +#define DB_FIELD_PLAYLIST_NAME "name" +#define DB_FIELD_PLAYLIST_MEMBER_ORDER "play_order" +#define DB_FIELD_PLAYLIST_MEDIA_COUNT "media_count" + +/* DB field for tag */ +#define DB_FIELD_TAG_ID "tag_id" +#define DB_FIELD_TAG_NAME "name" +#define DB_FIELD_TAG_MEDIA_COUNT "media_count" + +/* DB field for bookmark */ +#define DB_FIELD_BOOKMARK_ID "bookmark_id" +#define DB_FIELD_BOOKMARK_MARKED_TIME "marked_time" + +/* DB field for album*/ +#define DB_FIELD_ALBUM_ID "album_id" +#define DB_FIELD_ALBUM_NAME "name" +#define DB_FIELD_ALBUM_ARTIST "artist" + +/* DB Query Keyword */ +#define QUERY_KEYWORD_AND "AND" +#define QUERY_KEYWORD_OR "OR" +#define QUERY_KEYWORD_ORDER_BY "ORDER BY" +#define QUERY_KEYWORD_LIMIT "limit" +#define QUERY_KEYWORD_DESC "DESC" +#define QUERY_KEYWORD_SPACE " " +#define QUERY_KEYWORD_OPEN_BRACKET "(" +#define QUERY_KEYWORD_BRACKET ")" + +/* DB TABLE JOIN */ +#define FOLDER_MEDIA_JOIN "("DB_TABLE_FOLDER" AS f INNER JOIN "DB_TABLE_MEDIA" AS m ON f.folder_uuid=m.folder_uuid) WHERE m.validity=1" +#define BOOKMARK_MEDIA_JOIN "("DB_TABLE_BOOKMARK" AS b INNER JOIN "DB_TABLE_MEDIA" AS m \ + ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1" +#define ALBUM_MEDIA_JOIN "("DB_TABLE_ALBUM" AS a INNER JOIN "DB_TABLE_MEDIA" AS m \ + ON (a.album_id = m.album_id)) WHERE m.validity=1" + +/* Get Group List */ +#define SELECT_ALBUM_LIST "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN +#define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM "DB_TABLE_MEDIA" WHERE validity=1 " + +#define SELECT_FOLDER_LIST "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time FROM "FOLDER_MEDIA_JOIN +#define SELECT_TAG_LIST "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 " +#define SELECT_PLAYLIST_LIST "SELECT DISTINCT playlist_id, name, thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 " + +/* Get Group Count */ +#define SELECT_ALBUM_COUNT "SELECT COUNT(DISTINCT a.album_id) FROM "ALBUM_MEDIA_JOIN +#define SELECT_FOLDER_COUNT "SELECT COUNT(DISTINCT f.folder_uuid) FROM "FOLDER_MEDIA_JOIN +#define SELECT_TAG_COUNT "SELECT COUNT(DISTINCT tag_id) FROM "DB_VIEW_TAG" WHERE 1 " +#define SELECT_PLAYLIST_COUNT "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 " +#define SELECT_BOOKMARK_COUNT "SELECT COUNT(DISTINCT b.bookmark_id) FROM "BOOKMARK_MEDIA_JOIN +#define SELECT_MEDIA_GROUP_COUNT "SELECT COUNT(*) FROM ("SELECT_MEDIA_GROUP_LIST +/*count(distinct x) count only non-null values, but select distinct X returns include null. so sync the result of count and list, don't use count(distinct x)*/ + +/* Get Media Count of Group */ +#define SELECT_MEDIA_COUNT_FROM_MEDIA "SELECT COUNT(*) FROM ("SELECT_MEDIA_ITEM //to apply limit condition. "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1" +#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 " +#define SELECT_MEDIA_COUNT_FROM_ALBUM "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND album_id='%d'" +#define SELECT_MEDIA_COUNT_FROM_GROUP "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP //to apply limit condition. +#define SELECT_MEDIA_COUNT_FROM_GROUP_NULL "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL //to apply limit condition. +#define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND folder_uuid='%q'" +#define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) " +#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " + +/* Get Group Info by Group ID*/ +#define SELECT_ALBUM_FROM_ALBUM "SELECT * FROM "DB_TABLE_ALBUM" WHERE album_id=%d" +#define SELECT_FOLDER_FROM_FOLDER "SELECT * FROM "DB_TABLE_FOLDER" WHERE folder_uuid='%s'" +#define SELECT_FOLDER_BY_PATH "SELECT * FROM "DB_TABLE_FOLDER" WHERE path='%q'" +#define SELECT_PLAYLIST_FROM_PLAYLIST "SELECT * FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d" +#define SELECT_TAG_FROM_TAG "SELECT * FROM "DB_TABLE_TAG" WHERE tag_id=%d" +#define SELECT_TAG_BY_NAME "SELECT * FROM "DB_TABLE_TAG" WHERE name='%q'" + +/* Tag info*/ +#define INSERT_TAG_TO_TAG "INSERT INTO "DB_TABLE_TAG" (name) VALUES (%Q)" +#define REMOVE_TAG_ITEM_FROM_TAG_MAP "DELETE FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid='%q'" +#define UPDATE_TAG_NAME_FROM_TAG "UPDATE "DB_TABLE_TAG" SET name='%q' WHERE tag_id=%d" +#define SELECT_TAG_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'" +#define SELECT_TAG_LIST_BY_MEDIA_ID "SELECT tag_id, name FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'" + +/* Playlist Info */ +#define INSERT_PLAYLIST_TO_PLAYLIST "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)" +#define UPDATE_PLAYLIST_NAME_FROM_PLAYLIST "UPDATE "DB_TABLE_PLAYLIST" SET name='%q' WHERE playlist_id=%d" +#define UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST "UPDATE "DB_TABLE_PLAYLIST" SET thumbnail_path='%q' WHERE playlist_id=%d" +#define SELECT_PLAYLIST_ID_FROM_PLAYLIST "SELECT playlist_id FROM "DB_TABLE_PLAYLIST" WHERE name='%q'" +#define SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW "SELECT pm_id, media_uuid FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) " +#define SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW "SELECT play_order FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d and pm_id=%d" +#define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW "SELECT MAX(play_order) FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d" +#define REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP "DELETE FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND _id=%d" +#define UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP "UPDATE "DB_TABLE_PLAYLIST_MAP" SET play_order=%d WHERE playlist_id=%d AND _id=%d" + +/* Bookmark */ +#define INSERT_BOOKMARK_TO_BOOKMARK "INSERT INTO "DB_TABLE_BOOKMARK" (media_uuid, marked_time, thumbnail_path) VALUES ('%q', '%d', %Q)" +#define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'" +#define SELECT_BOOKMARK_LIST_BY_MEDIA_ID "SELECT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'" + +/* Update Meta*/ +#define UPDATE_AV_META_FROM_MEDIA "UPDATE "DB_TABLE_MEDIA" SET played_count=%d, last_played_time=%d, last_played_position=%d WHERE media_uuid='%q'" +#define UPDATE_IMAGE_META_FROM_MEDIA "UPDATE "DB_TABLE_MEDIA" SET orientation=%d, weather=%Q WHERE media_uuid='%q'" + +/* Get Media list of Group */ +#define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \ + rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, width, height, datetaken, orientation, title, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel, burst_id, timeline, weather, sync_status" + +#define SELECT_MEDIA_ITEM "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1" +#define SELECT_MEDIA_FROM_MEDIA "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND media_uuid='%s'" +#define SELECT_MEDIA_BY_PATH "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND path='%q'" +#define SELECT_MEDIA_FROM_ALBUM "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND album_id=%d" +#define SELECT_MEDIA_FROM_GROUP "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND %s='%q'" +#define SELECT_MEDIA_FROM_GROUP_NULL "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND %s IS NULL" +#define SELECT_MEDIA_FROM_FOLDER "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND folder_uuid='%s'" +#define SELECT_MEDIA_FROM_TAG "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d) AND validity=1" +#define SELECT_MEDIA_FROM_PLAYLIST "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d) AND validity=1" +#define SELECT_MEDIA_PATH_BY_ID "SELECT path FROM "DB_TABLE_MEDIA" WHERE media_uuid='%q'" + +/* Delete */ +#define DELETE_MEDIA_FROM_MEDIA_BATCH "DELETE FROM "DB_TABLE_MEDIA" WHERE %s" +#define DELETE_PLAYLIST_FROM_PLAYLIST "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d" +#define DELETE_TAG_FROM_TAG "DELETE FROM "DB_TABLE_TAG" WHERE tag_id=%d" +#define DELETE_BOOKMARK_FROM_BOOKMARK "DELETE FROM "DB_TABLE_BOOKMARK" WHERE bookmark_id=%d" + +/** + *@internal + */ +int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query); + +/** + *@internal + */ +int _content_error_capi(int type, int cotent_error); + +/** + *@internal + */ +int _content_query_sql(char *query_str); + +/** + *@internal + */ +MediaSvcHandle* _content_get_db_handle(void); + +/** + *@internal + */ +attribute_h _content_get_attirbute_handle(void); + +/** + *@internal + */ +attribute_h _content_get_alias_attirbute_handle(void); + +/** + *@internal + */ +int _media_info_get_media_info_from_db(const char *path, media_info_h media); + +/** + *@internal + */ +void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media); + +/** + *@internal + */ +int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count); + +/** + *@internal + */ +int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count); + +/** + *@internal + */ +int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data); + +/** + *@internal + */ +int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data); + +/** + *@internal + */ +int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data); + +/** + *@internal + */ +int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data); + +/** + *@internal + */ +int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data); + +/** + *@internal + */ +int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data); + +/** + *@internal + */ +int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data); + +/** + *@internal + */ +int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count); + +/** + *@internal + */ +int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count); + +/** + *@internal + */ +int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type); + +/** + *@internal + */ +int _media_db_get_group_item(const char *group_name, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type); + +/** + *@internal + */ +int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count); + +/** + *@internal + */ +int _media_db_get_media_group_item(const char *group_name, filter_h filter, media_group_e group, media_info_cb callback, void *user_data); + +/** + * @brief Creates a media filter attribute handle. + * @details This function creates a media filter attribute handle. The handle can be + * used to convert to attributes of database from attributes of user. + * @remarks The @a handle must be released with media_filter_attribute_destory() by you. + * @param[out] filter A handle to media filter attribute + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_filter_attribute_destory() + * + */ +int _media_filter_attribute_create(attribute_h *attr); + +/** + * @brief Add the attributes to the handle. + * @details This function add the attribute to handle. + * @param[in] filter The handle to media filter attribute + * @param[in] user_attr The user attribute + * @param[in] platform_attr The platform attribute + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_filter_attribute_remove() + * + */ +int _media_filter_attribute_add(attribute_h atrr, char *user_attr, char *platform_attr); + +/** + * @brief Destroys a media filter attribute handle. + * @details The function frees all resources related to the media filter attribute handle. The filter attribute + * handle no longer can be used to perform any operation. A new handle + * has to be created before the next usage. + * + * @param[in] filter The handle to media filter attribute + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_filter_create() + * + */ +int _media_filter_attribute_destory(attribute_h attr); + +/** + * @brief Replace to platform attributes from user attributes. + * @details This function replace to platform attributes from user attributes to generate the WHERE clause + * @param[in] filter The handle to media filter attribute + * @param[in] user_attr The user attribute + * @param[in] platform_attr The platform attribute + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_filter_attribute_create() + * @see media_filter_attribute_destory() + * + */ +int _media_filter_attribute_generate(attribute_h attr, char *condition, media_content_collation_e collate_type, char **generated_condition); + + +/** + * @brief Replace to platform attributes from user attributes. + * @details This function replace to platform attributes from user attributes to generate the WHERE clause + * @param[in] filter The handle to media filter attribute + * @param[in] attr The attribute + * @param[in] generated_option The handle to generated option + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED Filed DB + * @see media_filter_attribute_create() + * @see media_filter_attribute_destory() + * + */ + +int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option); + +#define FONT_COLOR_RESET "\033[0m" +#define FONT_COLOR_RED "\033[31m" +#define FONT_COLOR_GREEN "\033[32m" +#define FONT_COLOR_YELLOW "\033[33m" +#define FONT_COLOR_BLUE "\033[34m" +#define FONT_COLOR_PURPLE "\033[35m" +#define FONT_COLOR_CYAN "\033[36m" +#define FONT_COLOR_GRAY "\033[37m" + +#define media_content_gettid() syscall(__NR_gettid) + +#define media_content_retv_if(expr, val) do { \ + if(expr) { \ + LOGE(FONT_COLOR_RED"[%d]", media_content_gettid()); \ + return (val); \ + } \ + } while (0) + +#define media_content_debug(fmt, arg...) do { \ + LOGD(FONT_COLOR_RESET"[%d]"fmt"", media_content_gettid(), ##arg); \ + } while (0) + +#define media_content_info(fmt, arg...) do { \ + LOGI(FONT_COLOR_GREEN"[%d]"fmt"", media_content_gettid() ,##arg); \ + } while (0) + +#define media_content_error(fmt, arg...) do { \ + LOGE(FONT_COLOR_RED"[%d]"fmt"",media_content_gettid(), ##arg); \ + } while (0) + +#define media_content_debug_func() do { \ + LOGD(FONT_COLOR_RESET"[%d]", media_content_gettid()); \ + } while (0) + +#define media_content_sec_debug(fmt, arg...) do { \ + SECURE_LOGD(FONT_COLOR_RESET"[%d]"fmt"", media_content_gettid(), ##arg); \ + } while (0) + +#define media_content_sec_warn(fmt, arg...) do { \ + SECURE_LOGW(FONT_COLOR_GREEN"[%d]"fmt"",media_content_gettid(), ##arg); \ + } while (0) + +#define media_content_sec_error(fmt, arg...) do { \ + SECURE_LOGE(FONT_COLOR_RED"[%d]"fmt"",media_content_gettid(), ##arg); \ + } while (0) + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*__TIZEN_MEDIA_INFO_PRIVATE_H__*/ diff --git a/include/media_playlist.h b/include/media_playlist.h new file mode 100755 index 0000000..588b848 --- /dev/null +++ b/include/media_playlist.h @@ -0,0 +1,366 @@ +/* +* 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_PLAYLIST_H__ +#define __TIZEN_MEDIA_PLAYLIST_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + + +/** + * @addtogroup CAPI_CONTENT_MEDIA_PLAYLIST_MODULE + * @{ + * + * @file media_playlist.h + * @brief This file contains the playlist API and related functions handling with playlist. \n + * Functions include operations to get the number of playlist,the number of media-info for the playlist \n + * and all media files in the playlist, to clone,destroy, insert and delete playlist from db, \n + * to handle with name, ID, thumbnail, played order and media info of playlist. + */ + +/** + * @brief Gets the number of playlist for the passed @a filter from the media database. + * + * @param[in] filter The handle to filter. + * @param[out] playlist_count The count of media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_playlist_get_playlist_count_from_db(filter_h filter, int *playlist_count); + +/** + * @brief Iterates through the media playlist with optional @a filter from the media database. + * @details This function gets all media playlist handles meeting the given filter. + * The callback function will be invoked for every retrieved media playlist. + * If NULL is passed to the filter, no filtering is applied. + * + * @param [in] filter The handle to audio filter + * @param [in] callback The callback function to invoke + * @param [in] user_data User data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_playlist_cb(). + * @see #media_playlist_cb + * @see media_content_connect() + * @see media_filter_create() + * + */ +int media_playlist_foreach_playlist_from_db(filter_h filter, media_playlist_cb callback, void *user_data); + +/** + * @brief Gets number of media info for the given playlist present in the media database. + * + * @param [in] playlist_id The ID of media playlist + * @param [in] filter The handle to media filter + * @param [out] media_count The number of media items + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_playlist_get_media_count_from_db(int playlist_id, filter_h filter, int *media_count); + +/** + * @brief Iterates through the media files with optional @a filter in the given @a audio @a playlist from the media database. + * @details This function gets all media files associated with the given media playlist and + * meeting desired filter option and calls registered callback function for + * every retrieved media info. If NULL is passed to the @a filter, no filtering is applied. + * + * @param [in] playlist_id The ID of media playlist + * @param [in] filter The handle to audio filter + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_info_cb(). + * @see #media_info_cb + * @see media_content_connect() + * @see media_filter_create() + * + */ +int media_playlist_foreach_media_from_db(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data); + +/** + * @brief Inserts a new playlist with given name in the media database. + * + * @remark The created handle must be released with media_playlist_destroy() by you. + * @param [in] name The name of the inserted playlist + * @param [out] playlist A created handle to media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_OPERATION Invalid Operation + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB Operation failed + * @retval #MEDIA_CONTENT_ERROR_DB_BUSY DB Operation BUSY + * @retval #MEDIA_CONTENT_ERROR_NETWORK Network Fail + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_playlist_delete_from_db() + * + */ +int media_playlist_insert_to_db(const char *name, media_playlist_h *playlist); + +/** + * @brief Deletes the given playlist from the media database. + * + * @param [in] playlist The handle to media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_playlist_insert_to_db() + * + */ +int media_playlist_delete_from_db(int playlist_id); + +/** + * @brief Gets the media playlist from the media database. + * + * @details This function creates a new media playlist handle from the media database by the given playlist_id. + * media playlist will be created, which is filled with playlist information. + * + * @remarks @a playlist must be released with media_playlist_destroy() by you. + * + * @param[in] playlist_id The ID of media playlist + * @param[out] playlist The media playlist handle associated with the playlist ID + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_playlist_destroy() + * + */ +int media_playlist_get_playlist_from_db(int playlist_id, media_playlist_h *playlist); + +/** + * @brief Destroys a playlist handle. + * @details Function frees all resources related to playlist handle. This + * handle no longer can be used to perform any operation. New handle has to + * be created before next usage. + * + * @param [in] playlist The handle to media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_playlist_clone() + * @pre Get copy of playlist handle by calling media_playlist_clone() or media_playlist_insert_to_db() + * @see media_playlist_clone() + * + */ +int media_playlist_destroy(media_playlist_h playlist); + +/** + * @brief Clones playlist handle. + * @details This function copies the media playlist handle from a source to + * destination. There is no media_playlist_create() function. The media_playlist_h is created internally and available through + * media playlist foreach function such as media_playlist_foreach_playlist_from_db(). To use this handle outside of these foreach functions, + * use this function. + * + * @remark The destination handle must be released with media_playlist_destroy() by you. + * + * @param [in] src The source handle to media playlist + * @param [out] dst A destination handle to media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see media_playlist_destroy() + * @see media_playlist_foreach_playlist_from_db() + */ +int media_playlist_clone(media_playlist_h *dst, media_playlist_h src); + +/** + * @brief Gets media playlist's ID. + * + * @param [in] playlist The handle to media playlist + * @param [out] playlist_id The ID of media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int media_playlist_get_playlist_id(media_playlist_h playlist, int *playlist_id); + +/** + * @brief Gets a name of the playlist. + * + * @remarks @a playlist_name must be released with free() by you. + * + * @param [in] playlist The handle to media playlist + * @param [out] playlist_name The playlist name + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_playlist_get_name(media_playlist_h playlist, char **playlist_name); + +/** + * @brief Sets the playlist name. + * + * @param[in] playlist The handle to media playlist + * @param[in] playlist_name The name of the media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @post media_playlist_update_to_db() + * + */ +int media_playlist_set_name(media_playlist_h playlist, const char *playlist_name); + +/** + * @brief Gets a thumbnail path of the playlist. + * + * @remarks @a path must be released with free() by you. + * + * @param [in] playlist The handle to media playlist + * @param [out] path The path of thumbnail + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_playlist_get_thumbnail_path(media_playlist_h playlist, char **path); + +/** + * @brief Sets the thumbnail path of the playlist. + * + * @param[in] playlist The handle to media playlist + * @param[in] path The path of thumbnail + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @post media_playlist_update_to_db() + * + */ +int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *path); + + +/** + * @brief Sets the played order in the playlist. + * + * @param[in] playlist The handle to media playlist + * @param[in] playlist_member_id The ID to member of playlist + * @param[in] play_order The played order + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @post media_playlist_update_to_db() + * + */ +int media_playlist_set_play_order(media_playlist_h playlist, int playlist_member_id, int play_order); + +/** + * @brief Adds a new media info to the playlist. + * + * @param[in] playlist The handle to media playlist + * @param[in] media_id The ID to media info which is added + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post media_playlist_update_to_db() + * @see media_content_connect() + * @see media_playlist_remove_media() + * + */ +int media_playlist_add_media(media_playlist_h playlist, const char *media_id); + +/** + * @brief Removes the playlist member related with media from the given playlist. + * + * @param[in] playlist The handle to media playlist + * @param[in] playlist_member_id The ID to member of playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post media_playlist_update_to_db() + * @see media_content_connect() + * @see media_playlist_add_media() + * + */ +int media_playlist_remove_media(media_playlist_h playlist, int playlist_member_id); + +/** + * @brief Gets the played order in the playlist. + * + * @param[in] playlist The handle to media playlist + * @param[in] playlist_member_id The ID to member of playlist + * @param [out] play_order The played order + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int media_playlist_get_play_order(media_playlist_h playlist, int playlist_member_id, int *play_order); + +/** + * @brief Updates the media playlist to the media database. + * + * @details The function updates the given media playlist in the media database. The function should be called after any change in playlist, to be updated to the media + * database. For example, after using media_playlist_set_name() for setting the name of the playlist, media_playlist_update_to_db() function should be called so as to update + * the given playlist attibutes in the media database. + * + * @param[in] playlist The handle to media playlist + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_playlist_destroy() + * @see media_playlist_add_media() + * @see media_playlist_remove_media() + * @see media_playlist_set_name() + * @see media_playlist_set_play_order() + * + */ +int media_playlist_update_to_db(media_playlist_h playlist); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*__TIZEN_MEDIA_PLAYLIST_H__*/ diff --git a/include/media_tag.h b/include/media_tag.h new file mode 100755 index 0000000..9547c15 --- /dev/null +++ b/include/media_tag.h @@ -0,0 +1,306 @@ +/* +* 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_TAG_H__ +#define __TIZEN_MEDIA_TAG_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/** + * @addtogroup CAPI_CONTENT_MEDIA_TAG_MODULE + * @{ + * + * @file media-tag.h + * @brief This file contains the media tag API and related functions handling with tag. \n + * Functions include operations to get the number and content of tag, the number of media files \n + * and all media items in the tag, to clone, destroy, insert and delete tag from db, \n + * to handle with name, ID, and media info of the tag. + */ + +/** + * @brief Inserts a new tag in the media database. + * + * @remark The created tag handle must be released with media_tag_destroy() by you. + * + * @param[in] tag_name The tag name to be inserted + * @param[out] tag A created handle to media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_tag_delete_from_db() + * @see media_tag_destroy() + * + */ +int media_tag_insert_to_db(const char *tag_name, media_tag_h *tag); + +/** + * @brief Deletes a given tag from the media database. + * + * @param[in] tag The handle to media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_tag_insert_to_db() + * + */ +int media_tag_delete_from_db(int tag_id); + +/** + * @brief Gets the number of tag for the passed @a filter from the media database. + * + * @param[in] filter The handle to filter + * @param[out] tag_count The count of media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_tag_get_tag_count_from_db(filter_h filter, int *tag_count); + +/** + * @brief Iterates through tags from the media database. + * @details This function gets all tags meeting a desired @a filter + * and calls a registered callback function for every retrieved tag. If NULL is passed to the @a filter, no filtering is applied. + * + * @param[in] filter The handle to tag filter + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_tag_cb(). + * @see media_content_connect() + * @see #media_tag_cb + * @see media_filter_create() + * + */ +int media_tag_foreach_tag_from_db (filter_h filter, media_tag_cb callback, void *user_data); + +/** + * @brief Gets the number of media files for the passed @a filter in the given @a tag from the media database. + * + * @param[in] tag_id The ID of media tag + * @param[in] filter The handle to media filter + * @param[out] media_count The count of media items + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB operation failed + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * + */ +int media_tag_get_media_count_from_db (int tag_id, filter_h filter, int *media_count); + +/** + * @brief Iterates through media items for a given tag from the media database. + * @details This function gets all media items associated with a given tag and + * meeting a desired @a filter and calls a registered callback function for + * every retrieved media item. If NULL is passed to the @a filter, no filtering is applied. + * + * @param[in] tag_id The ID of media tag + * @param[in] filter The handle to media filter + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_info_cb(). + * @see media_content_connect() + * @see #media_info_cb + * @see media_filter_create() + */ +int media_tag_foreach_media_from_db(int tag_id, filter_h filter, media_info_cb callback, void *user_data); + +/** + * @brief Clones the media tag. + * @details This function copies the media tag handle from a source to destination. + * There is no media_tag_create() function. The media_tag_h is created internally and available through media tag foreach function + * such as media_tag_foreach_tag_from_db(). + * To use this handle outside of these foreach functions, use this function. + * @remark The destination handle must be released with media_tag_destroy() by you. + * + * @param[out] dst A destination handle to media tag + * @param[in] src The source handle to media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @see media_tag_destroy() + * + */ +int media_tag_clone(media_tag_h *dst, media_tag_h src); + +/** + * @brief Destroys the media tag. + * @details This function frees all resources related to the tag handle. The tag handle can no longer + * be used for any operation. A new tag handle has to be created before next usage. + * + * @param[in] tag The media tag handle + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre A copy of the media tag handle created by calling media_tag_clone() or media_tag_insert_to_db() + * @see media_tag_clone() + * @see media_tag_insert_to_db() + * + */ +int media_tag_destroy(media_tag_h tag); + +/** + * @brief Gets media tag's ID. + * + * + * @param [in] tag The handle to media tag + * @param [out] tag_id The ID of media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int media_tag_get_tag_id(media_tag_h tag, int *tag_id); + +/** + * @brief Gets the tag name. + * + * @remarks @a tag_name must be released with free() by you. + * + * @param[in] tag The handle to media tag + * @param[out] tag_name The name of the tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + */ +int media_tag_get_name(media_tag_h tag, char **tag_name); + +/** + * @brief Gets the media tag from the media database. + * + * @details This function creates a new media tag handle from the media database by the given tag_id. + * media tag will be created, which is filled with tag information. + * + * @remarks @a folder must be released with media_tag_destroy() by you. + * + * @param[in] tag_id The ID of media tag + * @param[out] tag The media tag handle associated with the tag ID + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_tag_destroy() + * + */ +int media_tag_get_tag_from_db(int tag_id, media_tag_h *tag); + +/** + * @brief Adds a new media info to the tag. + * + * @param[in] tag The handle to media tag + * @param[in] media_id The ID to media info which is added + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post media_tag_update_to_db() + * @see media_content_connect() + * @see media_tag_remove_media() + * + */ +int media_tag_add_media(media_tag_h tag, const char *media_id); + +/** + * @brief Removes the media info from the given tag. + * + * @param[in] tag The handle to media tag + * @param[in] media_id The ID to media info which is removed + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @pre This function requires opened connection to content service by media_content_connect(). + * @post media_tag_update_to_db() + * @see media_content_connect() + * @see media_tag_add_media() + * + */ +int media_tag_remove_media(media_tag_h tag, const char *media_id); + +/** + * @brief Sets the tag name. + * + * @param[in] tag The handle to media tag + * @param[in] tag_name The name of the media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @post media_tag_update_to_db() + * + */ +int media_tag_set_name(media_tag_h tag, char *tag_name); + +/** + * @brief Updates the media tag to the media database. + * + * @details The function updates the given media tag in the media database. The function should be called after any change in tag attributes, to be updated to the media + * database. For example, after using media_tag_set_name() for setting the name of the tag, media_tag_update_to_db() function should be called so as to update + * the given tag attibutes in the media database. + * + * @param[in] tag The handle to media tag + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see media_tag_destroy() + * @see media_tag_add_media() + * @see media_tag_remove_media() + * @see media_tag_set_name() + * + */ +int media_tag_update_to_db(media_tag_h tag); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_MEDIA_TAG_H__ */ diff --git a/include/media_util_private.h b/include/media_util_private.h new file mode 100755 index 0000000..d0452b7 --- /dev/null +++ b/include/media_util_private.h @@ -0,0 +1,38 @@ +/* +* 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_UTIL_PRIVATE_H__ +#define __TIZEN_MEDIA_UTIL_PRIVATE_H__ + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + + +/** + *@internal + */ +int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*__TIZEN_MEDIA_UTIL_PRIVATE_H__*/ diff --git a/include/media_video.h b/include/media_video.h new file mode 100755 index 0000000..c00fbc1 --- /dev/null +++ b/include/media_video.h @@ -0,0 +1,379 @@ +/* +* 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_VIDEO_META_H__ +#define __TIZEN_VIDEO_META_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/** + * @addtogroup CAPI_CONTENT_MEDIA_VIDEO_META_MODULE + * @{ + * + * @file media_video.h + * @brief This file contains the video metadata API and related functions to proceed with video metadata. \n + * Functions include clonning and destroying video metadata, getting video metadata as width, height, \n + * album, genre, played parameters etc. and updating video to db. + */ + +/** + * @brief Clones video metadata. + * @details This function copies the video metadata handle from a source to + * destination. + + * @remark The destination handle must be released with video_meta_destroy() by you. + * + * @param [out] dst A destination handle to video metadata + * @param [in] src The source handle to video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @see video_meta_destroy() + */ +int video_meta_clone(video_meta_h *dst, video_meta_h src); + +/** + * @brief Destroys video metadata. + * @details Function frees all resources related to video metadata handle. This handle + * no longer can be used to perform any operation. A new handle has to + * be created before the next use. + * + * @param [in] video The handle to video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Get copy of video metadata handle by calling video_meta_clone() + * @see video_meta_clone() + * + */ +int video_meta_destroy(video_meta_h video); + +/** + * @brief Gets id of media of given video metadata. + * + * @remarks @a media id must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] media_id The id of the video + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_media_id(video_meta_h video, char **media_id); + +/** + * @brief Gets the video's title. + * + * @remarks @a title must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] title The title of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_title(video_meta_h video, char **title); + +/** + * @brief Gets the video's album. + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a album must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] album The video album or NULL + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_album(video_meta_h video, char **album); + +/** + * @brief Gets the video's artist. + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a artist must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] artist The artist of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_artist(video_meta_h video, char **artist); + +/** + * @brief Gets the video's album_artist. + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a album_artist must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] album_artist The album_artist of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_album_artist(video_meta_h video, char **album_artist); + +/** + * @brief Gets the video's genre. + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a genre must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] genre The genre of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_genre(video_meta_h video, char **genre); + +/** + * @brief Gets the video's composer. + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a composer must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] composer The composer of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_composer(video_meta_h video, char **composer); + +/** + * @brief Gets the video's year. + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a year must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] year The year of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_year(video_meta_h video, char **year); + +/** + * @brief Gets the video's recorded_date. + * + * @remarks @a recorded_date must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] recorded_date The recorded_date of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_recorded_date(video_meta_h video, char **recorded_date); + +/** + * @brief Gets the video's copyright. + * + * @remarks @a copyright must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] copyright The copyright of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_copyright(video_meta_h video, char **copyright); + +/** + * @brief Gets the video's track number. + * If the value is an empty string, the method returns "Unknown". + * + * @remarks @a track_num must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] track_num The track number of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_track_num(video_meta_h video, char **track_num); + +/** + * @brief Gets the video's bit rate. + * + * @remarks @a bit_rate must be released with free() by you. + * + * @param [in] video The handle to video metadata + * @param [out] bit_rate The bit rate of video metadata + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + */ +int video_meta_get_bit_rate(video_meta_h video, int *bit_rate); + +/** + * @brief Gets duration of video metadata. + * + * @param [in] video The handle to video metadata + * @param [out] duration The video duration in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int video_meta_get_duration(video_meta_h video, int *duration); + +/** + * @brief Gets the video's width in pixels. + * + * @param [in] video The handle to video metadata + * @param [out] width The video width in pixels + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int video_meta_get_width(video_meta_h video, int *width); + +/** + * @brief Gets the video's height in pixels. + * + * @param [in] video The handle to video metadata + * @param [out] height The video height in pixels + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int video_meta_get_height(video_meta_h video, int *height); + +/** + * @brief Gets the video's played count. + * + * @param [in] video The handle to video metadata + * @param [out] played_count The number of played + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int video_meta_get_played_count(video_meta_h video, int *played_count); + +/** + * @brief Gets the video's time last played parameter. + * + * @param [in] video The handle to video metadata + * @param [out] played_time The time last played in the video + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int video_meta_get_played_time(video_meta_h video, time_t *played_time); + +/** + * @brief Gets the video's position played parameter. + * @details Function returns video's elapsed playback time parameter as period + * starting from the beginning of the movie. + * + * @param [in] video The handle to video metadata + * @param [out] played_position The position from the beginning of the video (in milliseconds) + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int video_meta_get_played_position(video_meta_h video, int *played_position); + +/** + * @brief Sets the video's played count. + * + * @param [in] video The handle to video metadata + * @param [in] played_count The number of played + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post video_meta_update_to_db() + */ +int video_meta_set_played_count(video_meta_h video, int played_count); + +/** + * @brief Sets the video's time last played parameter. + * + * @param [in] video The handle to video metadata + * @param [in] played_time The time last played in the video + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post video_meta_update_to_db() + */ +int video_meta_set_played_time(video_meta_h video, time_t played_time); + +/** + * @brief Sets the video's position played parameter. + * @details Function returns video's elapsed playback time parameter as period + * starting from the beginning of the movie. + * + * @param [in] video The handle to video metadata + * @param [in] played_position The position from the beginning of the video (in milliseconds) + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @post video_meta_update_to_db() + */ +int video_meta_set_played_position(video_meta_h video, int played_position); + +/** + * @brief Updates the video to the media database. + * + * @details The function updates the given video meta in the media database. The function should be called after any change in video attributes, to be updated to the media + * database. For example, after using video_meta_get_played_time() for setting the played time of the video, video_meta_update_to_db() function should be called so as to update + * the given video attibutes in the media database. + * + * @param[in] image The handle to image + * @return 0 on success, otherwise a negative error value. + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre This function requires opened connection to content service by media_content_connect(). + * @see media_content_connect() + * @see video_meta_set_played_time() + * @see video_meta_set_played_count() + * @see video_meta_set_played_position() + */ +int video_meta_update_to_db(video_meta_h video); + +/** + *@} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*__TIZEN_VIDEO_META_H__*/ diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec new file mode 100755 index 0000000..037205d --- /dev/null +++ b/packaging/capi-content-media-content.spec @@ -0,0 +1,73 @@ +Name: capi-content-media-content +Summary: A Media content library in SLP C API +Version: 0.2.109 +Release: 0 +Group: System/Libraries +License: Apache License, Version 2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(libmedia-service) +BuildRequires: pkgconfig(media-thumbnail) +BuildRequires: pkgconfig(libmedia-utils) +BuildRequires: pkgconfig(icu-i18n) +BuildRequires: pkgconfig(vconf) + + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description + + +%package devel +Summary: A Media content library in SLP C API (Development) +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel + +%prep +%setup -q + + +%build + +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` + +%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 +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +#License +mkdir -p %{buildroot}/%{_datadir}/license +cp -rf %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 %{buildroot}/%{_datadir}/license/%{name} + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%manifest capi-content-media-content.manifest +%{_libdir}/libcapi-content-media-content.so.* +#License +%{_datadir}/license/%{name} + +%files devel +%{_includedir}/media-content/*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/libcapi-content-media-content.so + + diff --git a/src/media_audio.c b/src/media_audio.c new file mode 100755 index 0000000..580cb53 --- /dev/null +++ b/src/media_audio.c @@ -0,0 +1,761 @@ +/* +* 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 + + +int audio_meta_destroy(audio_meta_h audio) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio) + { + SAFE_FREE(_audio->media_id); + SAFE_FREE(_audio->title); + SAFE_FREE(_audio->album); + SAFE_FREE(_audio->artist); + SAFE_FREE(_audio->album_artist); + SAFE_FREE(_audio->genre); + SAFE_FREE(_audio->composer); + SAFE_FREE(_audio->year); + SAFE_FREE(_audio->recorded_date); + SAFE_FREE(_audio->copyright); + SAFE_FREE(_audio->track_num); + SAFE_FREE(_audio); + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_clone(audio_meta_h *dst, audio_meta_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_src = (audio_meta_s*)src; + + if(_src != NULL) + { + audio_meta_s *_dst = (audio_meta_s*)calloc(1, sizeof(audio_meta_s)); + + if(_dst == NULL) + { + + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->media_id)) + { + _dst->media_id = strdup(_src->media_id); + if(_dst->media_id == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->title)) + { + _dst->title = strdup(_src->title); + if(_dst->title == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->album)) + { + _dst->album = strdup(_src->album); + if(_dst->album == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->artist)) + { + _dst->artist = strdup(_src->artist); + if(_dst->artist == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->album_artist)) + { + _dst->album_artist = strdup(_src->album_artist); + if(_dst->album_artist == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->genre)) + { + _dst->genre = strdup(_src->genre); + if(_dst->genre == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->composer)) + { + _dst->composer = strdup(_src->composer); + if(_dst->composer == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->year)) + { + _dst->year = strdup(_src->year); + if(_dst->year == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->recorded_date)) + { + _dst->recorded_date = strdup(_src->recorded_date); + if(_dst->recorded_date == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->copyright)) + { + _dst->copyright = strdup(_src->copyright); + if(_dst->copyright == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->track_num)) + { + _dst->track_num = strdup(_src->track_num); + if(_dst->track_num == NULL) + { + audio_meta_destroy((audio_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->bitrate = _src->bitrate; + _dst->samplerate = _src->samplerate; + _dst->channel = _src->channel; + _dst->duration = _src->duration; + _dst->played_count = _src->played_count; + _dst->played_time = _src->played_time; + _dst->played_position = _src->played_position; + + *dst = (audio_meta_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_media_id(audio_meta_h audio, char **media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->media_id)) + { + *media_id = strdup(_audio->media_id); + if(*media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *media_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_title(audio_meta_h audio, char **title) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->title)) + { + *title = strdup(_audio->title); + if(*title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *title = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_album(audio_meta_h audio, char **album_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->album)) + { + *album_name = strdup(_audio->album); + if(*album_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *album_name = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_artist(audio_meta_h audio, char **artist_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio) + { + if(STRING_VALID(_audio->artist)) + { + *artist_name = strdup(_audio->artist); + if(*artist_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *artist_name = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_album_artist(audio_meta_h audio, char **album_artist_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio) + { + if(STRING_VALID(_audio->album_artist)) + { + *album_artist_name = strdup(_audio->album_artist); + if(*album_artist_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *album_artist_name = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_genre(audio_meta_h audio, char **genre_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->genre)) + { + *genre_name = strdup(_audio->genre); + if(*genre_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *genre_name = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_composer(audio_meta_h audio, char **composer_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->composer)) + { + *composer_name = strdup(_audio->composer); + if(*composer_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *composer_name = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_year(audio_meta_h audio, char **year) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->year)) + { + *year = strdup(_audio->year); + if(*year == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *year = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_recorded_date(audio_meta_h audio, char **recorded_date) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->recorded_date)) + { + *recorded_date = strdup(_audio->recorded_date); + if(*recorded_date == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *recorded_date = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_copyright(audio_meta_h audio, char **copyright) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->copyright)) + { + *copyright = strdup(_audio->copyright); + if(*copyright == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *copyright = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_track_num(audio_meta_h audio, char **track_num) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + if(_audio) + { + if(STRING_VALID(_audio->track_num)) + { + *track_num = strdup(_audio->track_num); + if(*track_num == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *track_num = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio && bit_rate) + { + *bit_rate = _audio->bitrate; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_sample_rate(audio_meta_h audio, int *sample_rate) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio && sample_rate) + { + *sample_rate = _audio->samplerate; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_channel(audio_meta_h audio, int *channel) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio && channel) + { + *channel = _audio->channel; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_duration(audio_meta_h audio, int *duration) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio) + { + *duration = _audio->duration; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_played_count(audio_meta_h audio, int *played_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio) + { + *played_count = _audio->played_count; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_played_time(audio_meta_h audio, time_t* played_time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio) + { + *played_time = _audio->played_time; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_get_played_position(audio_meta_h audio, int *played_position) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if(_audio) + { + *played_position = _audio->played_position; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_set_played_count(audio_meta_h audio, int played_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + audio_meta_s *_audio = (audio_meta_s*)audio; + + if((_audio != NULL) && (played_count >= 0)) + { + _audio->played_count = played_count; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_set_played_time(audio_meta_h audio, time_t played_time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + audio_meta_s *_audio = (audio_meta_s*)audio; + + if((_audio != NULL) && (played_time >= 0)) + { + _audio->played_time = played_time; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_set_played_position(audio_meta_h audio, int played_position) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + + if((_audio != NULL) && (played_position >= 0)) + { + _audio->played_position = played_position; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int audio_meta_update_to_db(audio_meta_h audio) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + audio_meta_s *_audio = (audio_meta_s*)audio; + char *sql = NULL; + + if(_audio != NULL && STRING_VALID(_audio->media_id)) + { + sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id); + ret = _content_query_sql(sql); + sqlite3_free(sql); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_bookmark.c b/src/media_bookmark.c new file mode 100755 index 0000000..466e6e3 --- /dev/null +++ b/src/media_bookmark.c @@ -0,0 +1,218 @@ +/* +* 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 + + +int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *sql = NULL; + + if(STRING_VALID(media_id)) + { + sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path); + ret = _content_query_sql(sql); + sqlite3_free(sql); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_bookmark_delete_from_db(int bookmark_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + if(bookmark_id < 0) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + query_str = sqlite3_mprintf(DELETE_BOOKMARK_FROM_BOOKMARK, bookmark_id); + + ret = _content_query_sql(query_str); + + sqlite3_free(query_str); + + return ret; +} + +int media_bookmark_get_bookmark_count_from_db(filter_h filter, int *bookmark_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if (bookmark_count == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_group_count(filter, MEDIA_GROUP_BOOKMARK, bookmark_count); + + return ret; +} + +int media_bookmark_destroy(media_bookmark_h bookmark) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark; + + if(_bookmark) + { + SAFE_FREE(_bookmark->media_id); + SAFE_FREE(_bookmark->thumbnail_path); + free(_bookmark); + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} +int media_bookmark_clone(media_bookmark_h *dst, media_bookmark_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((src != NULL)) + { + media_bookmark_s *_src = (media_bookmark_s*)src; + media_bookmark_s *_dst = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s)); + + if(NULL == _dst) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _dst->bookmark_id = _src->bookmark_id; + + if(STRING_VALID(_src->media_id)) + { + _dst->media_id = (char*)strdup(_src->media_id); + if(_dst->media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_bookmark_destroy((media_bookmark_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->marked_time = _src->marked_time; + + if(STRING_VALID(_src->thumbnail_path)) + { + _dst->thumbnail_path = (char*)strdup(_src->thumbnail_path); + if(_dst->thumbnail_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_bookmark_destroy((media_bookmark_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + *dst = (media_bookmark_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_bookmark_get_bookmark_id(media_bookmark_h bookmark, int *bookmark_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark; + + if(_bookmark) + { + *bookmark_id = _bookmark->bookmark_id; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_bookmark_get_marked_time(media_bookmark_h bookmark, time_t* marked_time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark; + + if(_bookmark) + { + *marked_time = _bookmark->marked_time; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_bookmark_get_thumbnail_path(media_bookmark_h bookmark, char **path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_bookmark_s *_bookmark = (media_bookmark_s*)bookmark; + + if(_bookmark) + { + if(STRING_VALID(_bookmark->thumbnail_path)) + { + *path = strdup(_bookmark->thumbnail_path); + if(*path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *path = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_content.c b/src/media_content.c new file mode 100755 index 0000000..0509300 --- /dev/null +++ b/src/media_content.c @@ -0,0 +1,978 @@ +/* +* 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 +#include +#include + +#include +#include +#include +#include + +static attribute_h g_attr_handle = NULL; +static attribute_h g_alias_attr_handle = NULL; +static MediaSvcHandle *db_handle = NULL; +static int ref_count = 0; +static GMutex *db_mutex = NULL; + +static media_noti_cb_s *g_noti_info = NULL; + +static int __media_content_create_attr_handle(void); +static int __media_content_create_alias_attr_handle(void); +static int __media_content_create_attribute_handle(void); +static int __media_content_destroy_attribute_handle(void); + +static int __media_content_create_attr_handle(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = _media_filter_attribute_create(&g_attr_handle); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Media Info */ + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ID, DB_FIELD_MEDIA_ID); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PATH, DB_FIELD_MEDIA_PATH); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DISPLAY_NAME, DB_FIELD_MEDIA_DISPLAY_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TYPE, DB_FIELD_MEDIA_TYPE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_MIME_TYPE, DB_FIELD_MEDIA_MIME_TYPE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_SIZE, DB_FIELD_MEDIA_SIZE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ADDED_TIME, DB_FIELD_MEDIA_ADDED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_MODIFIED_TIME, DB_FIELD_MEDIA_MODIFIED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TIMELINE, DB_FIELD_MEDIA_TIMELINE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_THUMBNAIL_PATH, DB_FIELD_MEDIA_THUMBNAIL_PATH); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TITLE, DB_FIELD_MEDIA_TITLE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM, DB_FIELD_MEDIA_ALBUM); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ARTIST, DB_FIELD_MEDIA_ARTIST); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM_ARTIST, DB_FIELD_MEDIA_ALBUM_ARTIST); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_GENRE, DB_FIELD_MEDIA_GENRE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COMPOSER, DB_FIELD_MEDIA_COMPOSER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_YEAR, DB_FIELD_MEDIA_YEAR); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_RECORDED_DATE, DB_FIELD_MEDIA_RECORDED_DATE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COPYRIGHT, DB_FIELD_MEDIA_COPYRIGHT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TRACK_NUM, DB_FIELD_MEDIA_TRACK_NUM); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DESCRIPTION, DB_FIELD_MEDIA_DESCRIPTION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_BITRATE, DB_FIELD_MEDIA_BITRATE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_SAMPLERATE, DB_FIELD_MEDIA_SAMPLERATE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CHANNEL, DB_FIELD_MEDIA_CHANNEL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DURATION, DB_FIELD_MEDIA_DURATION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LONGITUDE, DB_FIELD_MEDIA_LONGITUDE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LATITUDE, DB_FIELD_MEDIA_LATITUDE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALTITUDE, DB_FIELD_MEDIA_ALTITUDE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_WIDTH, DB_FIELD_MEDIA_WIDTH); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_HEIGHT, DB_FIELD_MEDIA_HEIGHT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DATETAKEN, DB_FIELD_MEDIA_DATETAKEN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ORIENTATION, DB_FIELD_MEDIA_ORIENTATION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_BURST_ID, DB_FIELD_MEDIA_BURST_ID); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PLAYED_COUNT, DB_FIELD_MEDIA_PLAYED_COUNT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LAST_PLAYED_TIME, DB_FIELD_MEDIA_LAST_PLAYED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LAST_PLAYED_POSITION, DB_FIELD_MEDIA_LAST_PLAYED_POSITION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_RATING, DB_FIELD_MEDIA_RATING); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_FAVOURITE, DB_FIELD_MEDIA_FAVOURITE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AUTHOR, DB_FIELD_MEDIA_AUTHOR); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PROVIDER, DB_FIELD_MEDIA_PROVIDER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CONTENT_NAME, DB_FIELD_MEDIA_CONTENT_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CATEGORY, DB_FIELD_MEDIA_CATEGORY); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LOCATION_TAG, DB_FIELD_MEDIA_LOCATION_TAG); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AGE_RATING, DB_FIELD_MEDIA_AGE_RATING); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_KEYWORD, DB_FIELD_MEDIA_KEYWORD); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_WEATHER, DB_FIELD_MEDIA_WEATHER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_IS_DRM, DB_FIELD_MEDIA_IS_DRM); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_STORAGE_TYPE, DB_FIELD_MEDIA_STORAGE_TYPE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Pinyin*/ + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_FILE_NAME_PINYIN, DB_FIELD_MEDIA_FILE_NAME_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TITLE_PINYIN, DB_FIELD_MEDIA_TITLE_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM_PINYIN, DB_FIELD_MEDIA_ALBUM_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ARTIST_PINYIN, DB_FIELD_MEDIA_ARTIST_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM_ARTIST_PINYIN, DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_GENRE_PINYIN, DB_FIELD_MEDIA_GENRE_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COMPOSER_PINYIN, DB_FIELD_MEDIA_COMPOSER_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COPYRIGHT_PINYIN, DB_FIELD_MEDIA_COPYRIGHT_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DESCRIPTION_PINYIN, DB_FIELD_MEDIA_DESCRIPTION_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AUTHOR_PINYIN, DB_FIELD_MEDIA_AUTHOR_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PROVIDER_PINYIN, DB_FIELD_MEDIA_PROVIDER_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CONTENT_NAME_PINYIN, DB_FIELD_MEDIA_CONTENT_NAME_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CATEGORY_PINYIN, DB_FIELD_MEDIA_CATEGORY_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LOCATION_TAG_PINYIN, DB_FIELD_MEDIA_LOCATION_TAG_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AGE_RATING_PINYIN, DB_FIELD_MEDIA_AGE_RATING_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, MEDIA_KEYWORD_PINYIN, DB_FIELD_MEDIA_KEYWORD_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Playlist*/ + ret = _media_filter_attribute_add(g_attr_handle, PLAYLIST_NAME, DB_FIELD_PLAYLIST_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_attr_handle, PLAYLIST_MEMBER_ORDER, DB_FIELD_PLAYLIST_MEMBER_ORDER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Playlist View */ + ret = _media_filter_attribute_add(g_attr_handle, PLAYLIST_MEDIA_COUNT, DB_FIELD_PLAYLIST_MEDIA_COUNT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Tag*/ + ret = _media_filter_attribute_add(g_attr_handle, TAG_NAME, DB_FIELD_TAG_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Tag View */ + ret = _media_filter_attribute_add(g_attr_handle, TAG_MEDIA_COUNT, DB_FIELD_TAG_MEDIA_COUNT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Bookmark*/ + ret = _media_filter_attribute_add(g_attr_handle, BOOKMARK_MARKED_TIME, DB_FIELD_BOOKMARK_MARKED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + return ret; +} + +static int __media_content_create_alias_attr_handle(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = _media_filter_attribute_create(&g_alias_attr_handle); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Media Info */ + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ID, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ID); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PATH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PATH); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DISPLAY_NAME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DISPLAY_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TYPE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_MIME_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_MIME_TYPE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_SIZE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_SIZE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ADDED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ADDED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_MODIFIED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_MODIFIED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TIMELINE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TIMELINE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_THUMBNAIL_PATH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_THUMBNAIL_PATH); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TITLE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TITLE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ARTIST, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ARTIST); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM_ARTIST, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_ARTIST); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_GENRE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_GENRE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COMPOSER, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COMPOSER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_YEAR, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_YEAR); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_RECORDED_DATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_RECORDED_DATE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COPYRIGHT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COPYRIGHT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TRACK_NUM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TRACK_NUM); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DESCRIPTION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DESCRIPTION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_BITRATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_BITRATE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_SAMPLERATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_SAMPLERATE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CHANNEL, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CHANNEL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DURATION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DURATION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LONGITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LONGITUDE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LATITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LATITUDE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALTITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALTITUDE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_WIDTH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_WIDTH); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_HEIGHT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_HEIGHT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DATETAKEN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DATETAKEN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ORIENTATION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ORIENTATION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_BURST_ID, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_BURST_ID); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PLAYED_COUNT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PLAYED_COUNT); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LAST_PLAYED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LAST_PLAYED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LAST_PLAYED_POSITION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LAST_PLAYED_POSITION); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_RATING, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_RATING); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_FAVOURITE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_FAVOURITE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AUTHOR, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AUTHOR); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PROVIDER, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PROVIDER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CONTENT_NAME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CONTENT_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CATEGORY, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CATEGORY); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LOCATION_TAG, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LOCATION_TAG); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AGE_RATING, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AGE_RATING); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_KEYWORD, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_KEYWORD); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_WEATHER, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_WEATHER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_IS_DRM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_IS_DRM); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_STORAGE_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_STORAGE_TYPE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Pinyin*/ + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_FILE_NAME_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_FILE_NAME_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TITLE_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TITLE_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ARTIST_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ARTIST_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM_ARTIST_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_GENRE_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_GENRE_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COMPOSER_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COMPOSER_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COPYRIGHT_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COPYRIGHT_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DESCRIPTION_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DESCRIPTION_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AUTHOR_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AUTHOR_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PROVIDER_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PROVIDER_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CONTENT_NAME_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CONTENT_NAME_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CATEGORY_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CATEGORY_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LOCATION_TAG_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LOCATION_TAG_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AGE_RATING_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AGE_RATING_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_KEYWORD_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_KEYWORD_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Folder */ + ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_ID, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_ID); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_PATH, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_PATH); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_NAME, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_MODIFIED_TIME, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_MODIFIED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_STORAGE_TYPE, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_STORAGE_TYPE); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_NAME_PINYIN, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME_PINYIN); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Playlist*/ + ret = _media_filter_attribute_add(g_alias_attr_handle, PLAYLIST_NAME, DB_TABLE_ALIAS_PLAYLIST"."DB_FIELD_PLAYLIST_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _media_filter_attribute_add(g_alias_attr_handle, PLAYLIST_MEMBER_ORDER, DB_TABLE_ALIAS_PLAYLIST_MAP"."DB_FIELD_PLAYLIST_MEMBER_ORDER); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Tag*/ + ret = _media_filter_attribute_add(g_alias_attr_handle, TAG_NAME, DB_TABLE_ALIAS_TAG"."DB_FIELD_TAG_NAME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + /* Bookmark*/ + ret = _media_filter_attribute_add(g_alias_attr_handle, BOOKMARK_MARKED_TIME, DB_TABLE_ALIAS_BOOKMARK"."DB_FIELD_BOOKMARK_MARKED_TIME); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + return ret; +} + +static int __media_content_create_attribute_handle(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = __media_content_create_attr_handle(); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = __media_content_create_alias_attr_handle(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + _media_filter_attribute_destory(g_attr_handle); + + return ret; +} + +static int __media_content_destroy_attribute_handle(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = _media_filter_attribute_destory(g_attr_handle); + ret = _media_filter_attribute_destory(g_alias_attr_handle); + + g_attr_handle = NULL; + g_alias_attr_handle = NULL; + + return ret; +} + +attribute_h _content_get_attirbute_handle(void) +{ + return g_attr_handle; +} + +attribute_h _content_get_alias_attirbute_handle(void) +{ + return g_alias_attr_handle; +} + +MediaSvcHandle* _content_get_db_handle(void) +{ + return db_handle; +} + +int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query) +{ + int len = 0; + int err = MEDIA_CONTENT_ERROR_NONE; + char query[MAX_QUERY_SIZE]; + memset(query, '\0', sizeof(query)); + + if(db_handle == NULL) + { + media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED); + return MEDIA_CONTENT_ERROR_DB_FAILED; + } + + if(STRING_VALID(select_query)) + { + if(!STRING_VALID(condition_query)) + { + condition_query = " "; + } + + if(!STRING_VALID(option_query)) + { + option_query = " "; + } + + //query = sqlite3_mprintf("%s %s %s", select_query, condition_query, option_query); + len = snprintf(query, sizeof(query), "%s %s %s", select_query, condition_query, option_query); + if (len > 0 && len < MAX_QUERY_SIZE) { + query[len] = '\0'; + } else if (len >= MAX_QUERY_SIZE) { + query[MAX_QUERY_SIZE -1] = '\0'; + } else { + media_content_error("snprintf failed"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_content_sec_debug("Query : [%s]", query); + + err = sqlite3_prepare_v2((sqlite3*)db_handle, query, strlen(query), stmt, NULL); + if(err != SQLITE_OK) + { + media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg((sqlite3*)db_handle)); + + if (err == SQLITE_BUSY) + return MEDIA_CONTENT_ERROR_DB_BUSY; + else + return MEDIA_CONTENT_ERROR_DB_FAILED; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int _content_error_capi(int type, int content_error) +{ + if(content_error != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("[type : %d] content_error : %d ", type, content_error); + } + + if(type == MEDIA_CONTENT_TYPE) + { + if(content_error == MEDIA_INFO_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + else if(content_error == MEDIA_INFO_ERROR_INVALID_PARAMETER) + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + else if((content_error == MEDIA_INFO_ERROR_DATABASE_CONNECT) || (content_error == MEDIA_INFO_ERROR_DATABASE_DISCONNECT) || + (content_error == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) ||(content_error == MEDIA_INFO_ERROR_DATABASE_INTERNAL)) + return MEDIA_CONTENT_ERROR_DB_FAILED; + else if((content_error == MS_MEDIA_ERR_SOCKET_CONN) ||(content_error == MS_MEDIA_ERR_SOCKET_INTERNAL) || + (content_error == MS_MEDIA_ERR_SOCKET_SEND) ||(content_error == MS_MEDIA_ERR_SOCKET_RECEIVE) || (content_error == MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT)) + return MEDIA_CONTENT_ERROR_NETWORK; + } else if(type == MEDIA_THUMBNAIL_TYPE) { + if(content_error == MEDIA_THUMB_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + else if(content_error == MEDIA_THUMB_ERROR_INVALID_PARAMETER || content_error == MEDIA_THUMB_ERROR_DUPLICATED_REQUEST) + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + else if(content_error == MEDIA_THUMB_ERROR_DB) + return MEDIA_CONTENT_ERROR_DB_FAILED; + else if(content_error == MEDIA_THUMB_ERROR_NETWORK) + return MEDIA_CONTENT_ERROR_NETWORK; + else if(content_error == MEDIA_THUMB_ERROR_TIMEOUT) + return MEDIA_CONTENT_ERROR_NETWORK; + else if(content_error == MEDIA_THUMB_ERROR_MM_UTIL) /* Error in mm-util lib */ + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + else if(content_error == MEDIA_THUMB_ERROR_HASHCODE) /* Failed to generate hash code */ + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + else if(content_error == MEDIA_THUMB_ERROR_TOO_BIG) /* Original is too big to make thumb */ + return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT; + else if(content_error == MEDIA_THUMB_ERROR_UNSUPPORTED) /* Unsupported type */ + return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT; + + } else if(type == MEDIA_REGISTER_TYPE) { + if(content_error == MS_MEDIA_ERR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + else if(content_error == MS_MEDIA_ERR_INVALID_PARAMETER || content_error == MS_MEDIA_ERR_INVALID_PATH) + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + else if(content_error == MS_MEDIA_ERR_DB_INSERT_FAIL) + return MEDIA_CONTENT_ERROR_DB_FAILED; + else if(content_error == MS_MEDIA_ERR_DB_BUSY_FAIL) + return MEDIA_CONTENT_ERROR_DB_BUSY; + else if(content_error == MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL) + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + else if(content_error == MS_MEDIA_ERR_DBUS_GET || content_error == MS_MEDIA_ERR_DBUS_ADD_FILTER) + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + else if(content_error == MS_MEDIA_ERR_VCONF_GET_FAIL) + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; +} + +int _content_query_sql(char *query_str) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + //DB will be updated by Media Server. + ret = media_svc_request_update_db(query_str); + + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); +} + +int media_content_connect(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if (!db_mutex) + db_mutex = g_mutex_new(); + + if (db_mutex != NULL) { + g_mutex_lock(db_mutex); + + media_content_info("ref count : %d", ref_count); + + if(ref_count == 0) + { + if(db_handle == NULL) + { + ret = __media_content_create_attribute_handle(); + if(ret == MEDIA_CONTENT_ERROR_NONE) { + ret = media_svc_connect(&db_handle); + ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); + if(ret == MEDIA_CONTENT_ERROR_NONE) { + ref_count++; + } else { + __media_content_destroy_attribute_handle(); + } + } else { + media_content_error("Internal DB Connection Error"); + } + } else { + media_content_error("Wrong DB Connection status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } + } else { + if(db_handle != NULL) { + ref_count++; + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } + } + + media_content_info("ref count changed to: %d", ref_count); + g_mutex_unlock(db_mutex); + } else { + media_content_error("mutex is NULL"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } + + return ret; +} + +int media_content_disconnect(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if (db_mutex != NULL) { + g_mutex_lock(db_mutex); + + media_content_debug("ref count : %d", ref_count); + if(ref_count > 0) + { + if(db_handle != NULL) { + ref_count--; + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } + } + else + { + media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED); + g_mutex_unlock(db_mutex); + return MEDIA_CONTENT_ERROR_DB_FAILED; + } + + if(ref_count == 0) + { + if(db_handle != NULL) + { + ret = media_svc_disconnect(db_handle); + ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); + if(ret == MEDIA_CONTENT_ERROR_NONE) { + ret = __media_content_destroy_attribute_handle(); + db_handle = NULL; + } else { + media_content_error("database disconnect fail"); + ref_count++; + } + } else { + media_content_error("Wrong DB Handle status"); + ret = MEDIA_CONTENT_ERROR_DB_FAILED; + } + + g_mutex_unlock(db_mutex); + g_mutex_free(db_mutex); + db_mutex = NULL; + + media_content_info("ref count changed to: %d", ref_count); + + return ret; + } + + g_mutex_unlock(db_mutex); + } else { + media_content_error("mutex is NULL"); + ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + media_content_info("ref count changed to: %d", ref_count); + + return ret; +} + +int media_content_scan_file(const char *path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + bool ignore_dir = FALSE; + char *folder_path = NULL; + + if (!STRING_VALID(path)) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_content_sec_debug("Path : %s", path); + + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { + /* This means this path has to be inserted or refreshed */ + folder_path = g_path_get_dirname(path); + ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); + SAFE_FREE(folder_path); + + if(ignore_dir) { + media_content_error("Invalid folder path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_svc_storage_type_e storage_type; + + ret = media_svc_get_storage_type(path, &storage_type); + if(ret != MEDIA_INFO_ERROR_NONE) { + media_content_sec_error("media_svc_get_storage_type failed : %d (%s)", ret, path); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path); + if (ret == MEDIA_INFO_ERROR_NONE) { + /* Refresh */ + ret = media_svc_refresh_item(_content_get_db_handle(), storage_type, path); + if(ret != MEDIA_INFO_ERROR_NONE) { + media_content_error("media_svc_refresh_item failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + } else if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) { + /* Insert */ + ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_type, path); + if(ret != MEDIA_INFO_ERROR_NONE) { + if (ret == MEDIA_INFO_ERROR_DATABASE_CONSTRAINT) { + media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path); + ret = MEDIA_INFO_ERROR_NONE; + } else { + media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path); + } + + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + } else { + media_content_error("media_svc_check_item_exist_by_path failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + } else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { + /* Dierectory is not accpted in this function */ + media_content_error("This path is directory"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } else { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + } else { + /* This means this path has to be deleted */ + media_content_debug("This path doesn't exists in file system... So now start to delete it from DB"); + ret = media_svc_delete_item_by_path(_content_get_db_handle(), path); + if(ret != MEDIA_INFO_ERROR_NONE) { + media_content_error("media_svc_delete_item_by_path failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + } + + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); +} + +void _media_content_scan_cb(media_request_result_s* result, void *user_data) +{ + int err = -1; + media_content_scan_cb_data *cb_data = user_data; + + err = result->result; + + if (cb_data && cb_data->callback) { + media_content_debug("User callback is being called now"); + cb_data->callback(err, cb_data->user_data); + } + + SAFE_FREE(cb_data); + + return; +} + +int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + bool ignore_dir = FALSE; + + if (!STRING_VALID(path)) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_util_check_ignore_dir(path, &ignore_dir); + if(ignore_dir) { + media_content_error("Invalid folder path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_content_scan_cb_data *cb_data = NULL; + cb_data = (media_content_scan_cb_data *)malloc(sizeof(media_content_scan_cb_data)); + if (cb_data == NULL) { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + cb_data->callback = callback; + cb_data->user_data = user_data; + + ret = media_directory_scanning_async(path, is_recursive, _media_content_scan_cb, cb_data); + if(ret != MS_MEDIA_ERR_NONE) { + media_content_error("media_directory_scanning_async failed : %d", ret); + } + + return _content_error_capi(MEDIA_REGISTER_TYPE, ret); +} + +void _media_content_db_update_noti_cb( + int pid, + media_item_type_e item, + media_item_update_type_e update_type, + char* path, + char* uuid, + media_type_e content_type, + char *mime_type, + void *user_data) +{ + int error_value = MEDIA_CONTENT_ERROR_NONE; + + media_noti_cb_s *_noti_info = (media_noti_cb_s *)user_data; + + if(_noti_info != NULL) + { + if (_noti_info->update_noti_cb) + _noti_info->update_noti_cb(error_value, pid, item, update_type, content_type, uuid, path, mime_type, _noti_info->user_data); + } + + return; +} + +int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if (callback == NULL) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (g_noti_info != NULL) { + media_content_error("Noti callback is alreay set"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + g_noti_info = (media_noti_cb_s*)calloc(1, sizeof(media_noti_cb_s)); + if (g_noti_info == NULL) { + media_content_error("Failed to create noti info"); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + g_noti_info->update_noti_cb = callback; + g_noti_info->user_data = user_data; + + ret = media_db_update_subscribe(_media_content_db_update_noti_cb, (void *)g_noti_info); + + return _content_error_capi(MEDIA_REGISTER_TYPE, ret); +} + +int media_content_unset_db_updated_cb(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + SAFE_FREE(g_noti_info); + ret = media_db_update_unsubscribe(); + + return _content_error_capi(MEDIA_REGISTER_TYPE, ret); +} + diff --git a/src/media_db.c b/src/media_db.c new file mode 100755 index 0000000..9447043 --- /dev/null +++ b/src/media_db.c @@ -0,0 +1,1047 @@ +/* +* 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 +#include + +static char * __media_db_get_group_name(media_group_e group); +static int __media_db_make_query(filter_h filter, attribute_h attr, char *select_query, int select_query_size, char **condition_query, char **option_query); + +static char * __media_db_get_group_name(media_group_e group) +{ + switch(group) + { + case MEDIA_CONTENT_GROUP_DISPLAY_NAME: + return DB_FIELD_MEDIA_DISPLAY_NAME; + case MEDIA_CONTENT_GROUP_TYPE: + return DB_FIELD_MEDIA_TYPE; + case MEDIA_CONTENT_GROUP_MIME_TYPE: + return DB_FIELD_MEDIA_MIME_TYPE; + case MEDIA_CONTENT_GROUP_SIZE: + return DB_FIELD_MEDIA_SIZE; + case MEDIA_CONTENT_GROUP_ADDED_TIME: + return DB_FIELD_MEDIA_ADDED_TIME; + case MEDIA_CONTENT_GROUP_MODIFIED_TIME: + return DB_FIELD_MEDIA_MODIFIED_TIME; + case MEDIA_CONTENT_GROUP_TITLE: + return DB_FIELD_MEDIA_TITLE; + case MEDIA_CONTENT_GROUP_ARTIST: + return DB_FIELD_MEDIA_ARTIST; + case MEDIA_CONTENT_GROUP_ALBUM_ARTIST: + return DB_FIELD_MEDIA_ALBUM_ARTIST; + case MEDIA_CONTENT_GROUP_GENRE: + return DB_FIELD_MEDIA_GENRE; + case MEDIA_CONTENT_GROUP_COMPOSER: + return DB_FIELD_MEDIA_COMPOSER; + case MEDIA_CONTENT_GROUP_YEAR: + return DB_FIELD_MEDIA_YEAR; + case MEDIA_CONTENT_GROUP_RECORDED_DATE: + return DB_FIELD_MEDIA_RECORDED_DATE; + case MEDIA_CONTENT_GROUP_COPYRIGHT: + return DB_FIELD_MEDIA_COPYRIGHT; + case MEDIA_CONTENT_GROUP_TRACK_NUM: + return DB_FIELD_MEDIA_TRACK_NUM; + case MEDIA_CONTENT_GROUP_DESCRIPTION: + return DB_FIELD_MEDIA_DESCRIPTION; + case MEDIA_CONTENT_GROUP_LONGITUDE: + return DB_FIELD_MEDIA_LONGITUDE; + case MEDIA_CONTENT_GROUP_LATITUDE: + return DB_FIELD_MEDIA_LATITUDE; + case MEDIA_CONTENT_GROUP_ALTITUDE: + return DB_FIELD_MEDIA_ALTITUDE; + case MEDIA_CONTENT_GROUP_BURST_IMAGE: + return DB_FIELD_MEDIA_BURST_ID; + case MEDIA_CONTENT_GROUP_RATING: + return DB_FIELD_MEDIA_RATING; + case MEDIA_CONTENT_GROUP_AUTHOR: + return DB_FIELD_MEDIA_AUTHOR; + case MEDIA_CONTENT_GROUP_PROVIDER: + return DB_FIELD_MEDIA_PROVIDER; + case MEDIA_CONTENT_GROUP_CONTENT_NAME: + return DB_FIELD_MEDIA_CONTENT_NAME; + case MEDIA_CONTENT_GROUP_CATEGORY: + return DB_FIELD_MEDIA_CATEGORY; + case MEDIA_CONTENT_GROUP_LOCATION_TAG: + return DB_FIELD_MEDIA_LOCATION_TAG; + case MEDIA_CONTENT_GROUP_AGE_RATING: + return DB_FIELD_MEDIA_AGE_RATING; + case MEDIA_CONTENT_GROUP_KEYWORD: + return DB_FIELD_MEDIA_KEYWORD; + case MEDIA_CONTENT_GROUP_WEATHER: + return DB_FIELD_MEDIA_WEATHER; + default: + return NULL; + } + + return NULL; +} + +static int __media_db_make_query(filter_h filter, attribute_h attr, char *select_query, int select_query_size, char **condition_query, char **option_query) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = NULL; + + if(filter != NULL) + { + _filter = (filter_s*)filter; + + if(STRING_VALID(_filter->condition)) + { + /*bracket should be added to condition. If application use "OR" condition, F/W restriction condition like "validity=1" is disregared + ex) select path from media where validity=1 and media_type=3 or media_type=1;*/ + char bracket_added_condition[MAX_QUERY_SIZE] = {0, }; + memset(bracket_added_condition, 0x00, sizeof(bracket_added_condition)); + + SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_OPEN_BRACKET, MAX_QUERY_SIZE); + SAFE_STRLCAT(bracket_added_condition, _filter->condition, MAX_QUERY_SIZE); + SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_BRACKET, MAX_QUERY_SIZE); + { + ret = _media_filter_attribute_generate(attr, bracket_added_condition, _filter->condition_collate_type, condition_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + } + } + + ret = _media_filter_attribute_option_generate(attr, filter, option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(*condition_query); + return ret; + } + + if(STRING_VALID(*condition_query)) + { + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, select_query_size); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_AND, select_query_size); + } + } + + return ret; +} + +int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + switch(group_type) { + case MEDIA_GROUP_NONE: + case MEDIA_GROUP_TAG_BY_MEDIA_ID: + case MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID: + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_ALBUM: + attr = _content_get_alias_attirbute_handle(); + if(!SAFE_STRLCPY(select_query, SELECT_ALBUM_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + break; + case MEDIA_GROUP_FOLDER: + attr = _content_get_alias_attirbute_handle(); + if(!SAFE_STRLCPY(select_query, SELECT_FOLDER_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_PLAYLIST: + if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_TAG: + if(!SAFE_STRLCPY(select_query, SELECT_TAG_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + case MEDIA_GROUP_BOOKMARK: + attr = _content_get_alias_attirbute_handle(); + if(!SAFE_STRLCPY(select_query, SELECT_BOOKMARK_COUNT, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + break; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + *group_count = (int)sqlite3_column_int(stmt, 0); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_COUNT, __media_db_get_group_name(group)); + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); + if(STRING_VALID(condition_query)) + SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); + if(STRING_VALID(option_query)) + SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query)); + + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + *group_count = (int)sqlite3_column_int(stmt, 0); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + char *name = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_GROUP_LIST, __media_db_get_group_name(group)); + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) + { + name = strdup((const char *)sqlite3_column_text(stmt, 0)); + } + + if(callback(name, user_data) == false) + { + SAFE_FREE(name); + break; + } + + SAFE_FREE(name); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_alias_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(!SAFE_STRLCPY(select_query, SELECT_ALBUM_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_album_s *album = (media_album_s*)calloc(1, sizeof(media_album_s)); + + if(album == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + album->album_id = (int)sqlite3_column_int(stmt, 0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + album->name = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + album->artist = strdup((const char *)sqlite3_column_text(stmt, 2)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) + album->album_art_path = strdup((const char *)sqlite3_column_text(stmt, 3)); + + if(callback((media_album_h)album, user_data) == false) + { + media_album_destroy((media_album_h)album); + break; + } + + media_album_destroy((media_album_h)album); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_alias_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(!SAFE_STRLCPY(select_query, SELECT_FOLDER_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + + /*this is temporary log to fix bug*/ + if (condition_query != NULL) media_content_error("condition_query %s", condition_query); + if (option_query != NULL) media_content_error("condition_query %s", option_query); + + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + /*this is temporary log to fix bug*/ + media_content_error(""); + + media_folder_s *_folder = (media_folder_s*)calloc(1, sizeof(media_folder_s)); + + if(_folder == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + /*this is temporary log to fix bug*/ + media_content_error("folder handle %x", _folder); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) + _folder->folder_id = strdup((const char *)sqlite3_column_text(stmt, 0)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _folder->path = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + _folder->name = strdup((const char *)sqlite3_column_text(stmt, 2)); + + _folder->storage_type = (int)sqlite3_column_int(stmt,3); + + _folder->modified_time = (int)sqlite3_column_int(stmt,4); + + if(callback((media_folder_h)_folder, user_data) == false) + { + media_folder_destroy((media_folder_h) _folder); + break; + } + + media_folder_destroy((media_folder_h) _folder); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(!SAFE_STRLCPY(select_query, SELECT_PLAYLIST_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s)); + + if(_playlist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _playlist->name = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + _playlist->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 2)); + + if(callback((media_playlist_h)_playlist, user_data) == false) + { + media_playlist_destroy((media_playlist_h)_playlist); + break; + } + media_playlist_destroy((media_playlist_h)_playlist); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW, playlist_id); + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + int playlist_member_id = 0; + char media_uuid[MEDIA_CONTENT_UUID_SIZE+1]; + media_info_h media = NULL; + memset(media_uuid, 0x00, sizeof(media_uuid)); + + playlist_member_id = (int)sqlite3_column_int(stmt, 0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + strncpy(media_uuid, (const char *)sqlite3_column_text(stmt, 1), MEDIA_CONTENT_UUID_SIZE); + + ret = media_info_get_media_from_db(media_uuid, &media); + + if(callback(playlist_member_id, media, user_data) == false) + { + media_info_destroy(media); + break; + } + media_info_destroy(media); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(!STRING_VALID(media_id)) + { + if(!SAFE_STRLCPY(select_query, SELECT_TAG_LIST, sizeof(select_query))) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + } + else + { + snprintf(select_query, sizeof(select_query), SELECT_TAG_LIST_BY_MEDIA_ID, media_id); + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s)); + + if(_tag == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _tag->tag_id = (int)sqlite3_column_int(stmt, 0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _tag->name = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(callback((media_tag_h)_tag, user_data) == false) + { + media_tag_destroy((media_tag_h)_tag); + break; + } + media_tag_destroy((media_tag_h)_tag); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_LIST_BY_MEDIA_ID, media_id); + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_bookmark_s *bookmark = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s)); + + if(bookmark == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + bookmark->bookmark_id = (int)sqlite3_column_int(stmt, 0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + bookmark->media_id = strdup((const char *)sqlite3_column_text(stmt, 1)); + + bookmark->marked_time = (int)sqlite3_column_int(stmt, 2); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 3))) + bookmark->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 3)); + + if(callback((media_bookmark_h)bookmark, user_data) == false) + { + media_bookmark_destroy((media_bookmark_h)bookmark); + break; + } + + media_bookmark_destroy((media_bookmark_h)bookmark); + } + + SQLITE3_FINALIZE(stmt); + + return ret; + +} + +int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(group_type == MEDIA_GROUP_ALBUM) + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_ALBUM, group_id); + } + else if(group_type == MEDIA_GROUP_PLAYLIST) + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_PLAYLIST, group_id); + } + else if(group_type == MEDIA_GROUP_TAG) + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_TAG, group_id); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + *item_count = (int)sqlite3_column_int(stmt, 0); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + filter_s *_filter = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *tmp_query = NULL; + char *condition_query = NULL; + char *option_query = NULL; + bool is_simple = FALSE; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(group_type == MEDIA_GROUP_NONE) + { + /* There are 2 ways to get count for media table for performance + If user wants to set offset and count, use SQL SELECT_MEDIA_COUNT_FROM_MEDIA. + If user wants to get count without setting count, SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE */ + _filter = (filter_s*)filter; + if (_filter && ((_filter->offset < 0) && (_filter->count < 0))) { + + SAFE_STRLCAT(select_query, SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE, sizeof(select_query)); + is_simple = TRUE; + } else { + SAFE_STRLCAT(select_query, SELECT_MEDIA_COUNT_FROM_MEDIA, sizeof(select_query)); + } + } + else if(group_type == MEDIA_GROUP_FOLDER) + { + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_FOLDER, group_name); + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); + } + else if(group_type == MEDIA_GROUP_TAG_BY_MEDIA_ID) + { + snprintf(select_query, sizeof(select_query), SELECT_TAG_COUNT_BY_MEDIA_ID, group_name); + } + else if(group_type == MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID) + { + snprintf(select_query, sizeof(select_query), SELECT_BOOKMARK_COUNT_BY_MEDIA_ID, group_name); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + if(tmp_query != NULL) + sqlite3_free(tmp_query); + return ret; + } + + if(group_type == MEDIA_GROUP_NONE) + { + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); + if(STRING_VALID(condition_query)) + SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); + if(STRING_VALID(option_query)) + SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); + + if (!is_simple) + SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query)); + + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + } + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + if(tmp_query != NULL) + sqlite3_free(tmp_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + *item_count = (int)sqlite3_column_int(stmt, 0); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(group_type == MEDIA_GROUP_ALBUM) + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_ALBUM, group_id); + } + else if(group_type == MEDIA_GROUP_PLAYLIST) + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_PLAYLIST, group_id); + } + else if(group_type == MEDIA_GROUP_TAG) + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_TAG, group_id); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media_info_item_get_detail(stmt, (media_info_h)item); + + if(callback((media_info_h)item, user_data) == false) + { + media_info_destroy((media_info_h)item); + break; + } + + media_info_destroy((media_info_h)item); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_group_item(const char *group_name, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(group_type == MEDIA_GROUP_NONE) + { + SAFE_STRLCAT(select_query, SELECT_MEDIA_ITEM, sizeof(select_query)); + } + else if(group_type == MEDIA_GROUP_FOLDER) + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_FOLDER, group_name); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media_info_item_get_detail(stmt, (media_info_h)item); + + if(callback((media_info_h)item, user_data) == false) + { + media_info_destroy((media_info_h)item); + break; + } + + media_info_destroy((media_info_h)item); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *tmp_query = NULL; + char *condition_query = NULL; + char *option_query = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(group_name != NULL) + { + tmp_query = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_GROUP, __media_db_get_group_name(group), group_name); + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); + } + else + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_COUNT_FROM_GROUP_NULL, __media_db_get_group_name(group)); + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + if(tmp_query != NULL) + sqlite3_free(tmp_query); + return ret; + } + + SAFE_STRLCAT(select_query, QUERY_KEYWORD_SPACE, sizeof(select_query)); + if(STRING_VALID(condition_query)) + SAFE_STRLCAT(select_query, condition_query, sizeof(select_query)); + if(STRING_VALID(option_query)) + SAFE_STRLCAT(select_query, option_query, sizeof(select_query)); + SAFE_STRLCAT(select_query, QUERY_KEYWORD_BRACKET, sizeof(select_query)); + + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + if(tmp_query != NULL) + sqlite3_free(tmp_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + *item_count = (int)sqlite3_column_int(stmt, 0); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int _media_db_get_media_group_item(const char *group_name, filter_h filter, media_group_e group, media_info_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[MAX_QUERY_SIZE] = {0, }; + char *tmp_query = NULL; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + attribute_h attr = NULL; + + attr = _content_get_attirbute_handle(); + memset(select_query, 0x00, sizeof(select_query)); + + if(group_name != NULL) + { + tmp_query = sqlite3_mprintf(SELECT_MEDIA_FROM_GROUP, __media_db_get_group_name(group), group_name); + SAFE_STRLCAT(select_query, tmp_query, sizeof(select_query)); + } + else + { + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_GROUP_NULL, __media_db_get_group_name(group)); + } + + ret = __media_db_make_query(filter, attr, select_query, sizeof(select_query), &condition_query, &option_query); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + if(tmp_query != NULL) + sqlite3_free(tmp_query); + return ret; + } + + ret = _content_query_prepare(&stmt, select_query, condition_query, option_query); + if(tmp_query != NULL) + sqlite3_free(tmp_query); + SAFE_FREE(condition_query); + SAFE_FREE(option_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_info_s *item = (media_info_s*)calloc(1, sizeof(media_info_s)); + if(item == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media_info_item_get_detail(stmt, (media_info_h)item); + + if(callback((media_info_h)item, user_data) == false) + { + media_info_destroy((media_info_h)item); + break; + } + + media_info_destroy((media_info_h)item); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} diff --git a/src/media_filter.c b/src/media_filter.c new file mode 100755 index 0000000..9c2e311 --- /dev/null +++ b/src/media_filter.c @@ -0,0 +1,1255 @@ +/* +* 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 +#include + +static char *media_token[] = +{ + " ", + "\"", + "'", + "(", + ")", + "=", + "<=", + "<", + ">=", + ">", +}; + + +typedef struct _token_t +{ + int type; + char *str; +}token_t; + + +#define MAX_LEFT_VALUE 512 +#define SPACE_LEN 1 +#define SPACE " " +#define UNKNOWN_TYPE 1000 +#define STRING_TYPE 100 + +static char *__get_order_str(media_content_order_e order_enum); +static char *__get_collate_str(media_content_collation_e collate_type); +static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data); +static char *__media_filter_replace_attr(attribute_h attr, char *name); +static int __tokenize_operator(token_t *token, const char *str, int op_type); +static int __tokenize(GList **token_list, const char *str); + +static bool __is_pinyin_needed(void) +{ + char *lang = NULL; + char *china = "zh_CN"; + int ret = FALSE; + + /*Check CSC first*/ + bool pinyin_support = FALSE; + media_svc_check_pinyin_support(&pinyin_support); + if(pinyin_support) + { + /*Check Language Setting*/ + lang = vconf_get_str(VCONFKEY_LANGSET); + if(strncmp(china, lang, strlen(china)) == 0) + { + ret = TRUE; + } + + SAFE_FREE(lang); + } + + return ret; +} + +static char *__get_order_str(media_content_order_e order_enum) +{ + switch(order_enum) { + case MEDIA_CONTENT_ORDER_ASC: + return "ASC"; + case MEDIA_CONTENT_ORDER_DESC: + return "DESC"; + default: + return " "; + } +} + +static char *__get_collate_str(media_content_collation_e collate_type) +{ + switch(collate_type) { + case MEDIA_CONTENT_COLLATE_NOCASE: + return "NOCASE"; + case MEDIA_CONTENT_COLLATE_RTRIM: + return "RTRIM"; + case MEDIA_CONTENT_COLLATE_LOCALIZED: + if(__is_pinyin_needed()) + return "NOCASE"; + else + return "localized"; + default: return " "; + } +} + +static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data) +{ + SAFE_FREE(key); + SAFE_FREE(value); +} + +static char *__media_filter_replace_attr(attribute_h attr, char *name) +{ + char *key_temp = NULL; + char *generated_value = NULL; + attribute_s *_attr = (attribute_s *)attr; + + if(!g_hash_table_lookup_extended(_attr->attr_map, + name, + (gpointer)&key_temp, (gpointer)&generated_value)) + { + //can't find the value + //media_content_error("NOT_FOUND_VALUE(%s)", name); + return NULL; + } + + if(STRING_VALID(generated_value)) + { + return strdup(generated_value); + } + + media_content_error("__media_filter_replace_attr fail"); + + return NULL; +} + +static int __tokenize_operator(token_t *token, const char *str, int op_type) +{ + int ret = 0; + const char *tmp = str; + + if(token != NULL && STRING_VALID(tmp)) + { + token->type = op_type; + int token_size = strlen(media_token[op_type]); + if(token_size == 0) + { + media_content_error("Invalid token_size. op_type[%d]", op_type); + return -1; + } + + token->str = (char*)calloc(token_size+1, sizeof(char)); + if(token->str == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + strncpy(token->str, tmp, token_size); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); + ret = token_size; + } + else + { + ret = -1; + } + + return ret; +} + +static int __tokenize_string(token_t *token, const char *str, int size) +{ + int ret = size; + const char *tmp = str; + + if(token != NULL && STRING_VALID(tmp) && size > 0) + { + token->str = (char*)calloc(size+1, sizeof(char)); + if(token->str == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + token->type = UNKNOWN_TYPE; + strncpy(token->str, tmp, size); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); + } + else + { + ret = -1; + } + + return ret; +} + +static int __tokenize_attribute(GList **token_list, const char *str) +{ + int ret = 0; + int idx = 0; + + if(!STRING_VALID(str)) { + media_content_error("Parameter string in invalid"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + const char *tmp = str; + const char *dst_ptr = str + strlen(str); + + for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++) + { + //media_content_debug("[%d] '%c'", idx, tmp[idx]); + if(tmp[idx] == ' ') //" " + { + if(idx == 0) // ignore the space. + { + tmp++; + idx = -1; + continue; + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + token->type = UNKNOWN_TYPE; + token->str = (char*)calloc(idx+1, sizeof(char)); + strncpy(token->str, tmp, idx); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); + *token_list = g_list_append(*token_list, token); + tmp = tmp +idx + strlen(media_token[0]); + idx = -1; + } + else if(tmp[idx] == ',') // " , " + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,3); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + } + } + + if(*tmp) //remained string + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +static int __tokenize(GList **token_list, const char *str) +{ + int ret = 0; + int idx = 0; + + if(!STRING_VALID(str)) { + media_content_error("Parameter string in invalid"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + const char *tmp = str; + const char *dst_ptr = str + strlen(str); + + for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++) + { + //media_content_debug("[%d] '%c'", idx, tmp[idx]); + if(tmp[idx] == media_token[0][0]) //" " + { + if(idx == 0) // ignore the space. + { + tmp++; + idx = -1; + continue; + } + + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + token->type = UNKNOWN_TYPE; + token->str = (char*)calloc(idx+1, sizeof(char)); + strncpy(token->str, tmp, idx); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); + *token_list = g_list_append(*token_list, token); + tmp = tmp +idx + strlen(media_token[0]); + idx = -1; + } + else if(tmp[idx] == media_token[1][0]) // " \" " + { + int j; + bool flag = false; + for(j = idx+1; tmp[j]; j++) //find next quotation + { + if(tmp[j] == media_token[1][0] && tmp[j+1] == media_token[1][0]) + { + j += 1; + continue; + } + if(tmp[j] == media_token[1][0]) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + token->str = (char*) calloc(j+1+1, sizeof(char)); + token->type = STRING_TYPE; + strncpy(token->str, tmp, j+1); + //media_content_debug("type : [%d] str : [%s], j : %d", token->type, token->str, j); + *token_list = g_list_append(*token_list, token); + tmp = tmp + strlen(token->str); + idx = -1; + flag = true; + break; + } + } + + if(!flag && *tmp != '\0' && tmp[j]=='\0') + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + token->str = (char*) calloc(j+1,sizeof(char)); + token->type = UNKNOWN_TYPE; + strncpy(token->str, tmp,j); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); + *token_list = g_list_append(*token_list, token); + tmp = tmp +strlen(token->str); + idx = -1; + } + } + else if(tmp[idx] == media_token[2][0]) // " \' " + { + int j; + bool flag = false; + for(j = idx+1; tmp[j]; j++) + { + if(tmp[j] == media_token[2][0] && tmp[j+1] == media_token[2][0]) + { + j += 1; + continue; + } + if(tmp[j] == media_token[2][0]) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + token->str = (char*) calloc(j+1+1, sizeof(char)); + token->type = STRING_TYPE; + strncpy(token->str, tmp, j+1); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); + *token_list = g_list_append(*token_list, token); + tmp = tmp + strlen(token->str); + idx = -1; + flag = true; + break; + } + } + + if(!flag && *tmp != '\0' && tmp[j]=='\0') + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + token->str = (char*) calloc(j+1,sizeof(char)); + token->type = UNKNOWN_TYPE; + strncpy(token->str, tmp,j); + //media_content_debug("type : [%d] str : [%s]", token->type, token->str); + *token_list = g_list_append(*token_list, token); + tmp = tmp + strlen(token->str); + idx = -1; + } + } + else if(tmp[idx] == media_token[3][0]) //"(" + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,3); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + } + else if(tmp[idx] == media_token[4][0]) //")" + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,4); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + } + else if(tmp[idx] == media_token[5][0]) //"=" + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,5); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + } + else if(tmp[idx] == media_token[6][0] && tmp[idx+1] == media_token[6][1]) //"<=", + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,6); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + } + else if(tmp[idx] == media_token[7][0]) //"<", + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,7); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + } + else if(tmp[idx] == media_token[8][0] && tmp[idx+1] == media_token[8][1]) //">=", + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,8); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + } + else if(tmp[idx] == media_token[9][0]) //">", + { + if(idx != 0) + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + else + { + *token_list = g_list_append(*token_list, token); + tmp = tmp + idx; + } + } + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + int size = __tokenize_operator(token, tmp,9); + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + tmp += size; + idx = -1; + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + } + } + + if(*tmp) //remained string + { + token_t *token = (token_t*)calloc(1, sizeof(token_t)); + if(token == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return -1; + } + + ret = __tokenize_string(token, tmp, idx); + if (ret < 0) + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + + if(token != NULL && STRING_VALID(token->str)) + { + *token_list = g_list_append(*token_list, token); + } + else + { + SAFE_FREE(token); + media_content_error("tokenize error occued"); + return -1; + } + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int _media_filter_attribute_create(attribute_h *attr) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(attr == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + attribute_s *_attr = (attribute_s*)calloc(1, sizeof(attribute_s)); + + if(_attr == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + else + { + _attr->attr_map = g_hash_table_new (g_str_hash, g_str_equal); + *attr = (attribute_h)_attr; + } + + return ret; +} + +int _media_filter_attribute_add(attribute_h attr, char *user_attr, char *platform_attr) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *_user = NULL; + char *_platform = NULL; + attribute_s *_attr = (attribute_s*)attr; + + if(_attr != NULL) + { + if(STRING_VALID(user_attr) && STRING_VALID(platform_attr)) + { + _user = strdup(user_attr); + if(_user == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _platform = strdup(platform_attr); + if(_platform == NULL) + { + SAFE_FREE(_user); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + g_hash_table_insert (_attr->attr_map, _user, _platform); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int _media_filter_attribute_destory(attribute_h attr) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + attribute_s *_attr = (attribute_s*)attr; + + if(_attr != NULL) + { + if(_attr->attr_map != NULL) + { + g_hash_table_foreach(_attr->attr_map, __filter_attribute_free_value, NULL); + g_hash_table_destroy(_attr->attr_map); + } + + SAFE_FREE(_attr); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int _media_filter_attribute_generate(attribute_h attr, char *condition, media_content_collation_e collate_type, char **generated_condition) +{ + int idx = 0; + GList *token_list = NULL; + int size = 0; + int ret = MEDIA_CONTENT_ERROR_NONE; + int total_str_size = 0; + token_t *token; + + if((condition == NULL) || (generated_condition == NULL)) + { + media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(attr != NULL) + { + if(__tokenize(&token_list, condition) < 0) + { + media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + for(idx = 0; idx < g_list_length(token_list); idx++) + { + token = (token_t*)g_list_nth_data(token_list, idx); + + if(token->type == UNKNOWN_TYPE) + { + char *replace_str = __media_filter_replace_attr(attr, token->str); + if(STRING_VALID(replace_str)) + { + SAFE_FREE(token->str); + token->str = replace_str; + } + } + + total_str_size += strlen(token->str)+1; + //media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str); + } + + //make the statment + size = total_str_size + COLLATE_STR_SIZE + 1; + * generated_condition = (char*)calloc(size, sizeof(char)); + + for(idx = 0; idx < g_list_length(token_list); idx++) + { + token = (token_t*)g_list_nth_data(token_list, idx); + + if((token != NULL) && STRING_VALID(token->str)) + { + SAFE_STRLCAT(*generated_condition, token->str, size); + SAFE_STRLCAT(*generated_condition, SPACE, size); + + SAFE_FREE(token->str); + SAFE_FREE(token); + } + } + + if(collate_type == MEDIA_CONTENT_COLLATE_NOCASE || collate_type == MEDIA_CONTENT_COLLATE_RTRIM ||collate_type == MEDIA_CONTENT_COLLATE_LOCALIZED) { + SAFE_STRLCAT(*generated_condition, "COLLATE ", size); + SAFE_STRLCAT(*generated_condition, __get_collate_str(collate_type), size); + SAFE_STRLCAT(*generated_condition, SPACE, size); + } + + //media_content_debug("statement : %s(%d) (total:%d)", *generated_condition, strlen(*generated_condition), total_str_size); + media_content_sec_debug("Condition : %s", *generated_condition); + + //if(*generated_condition != NULL) + // res = 1; + + if(token_list != NULL) + g_list_free(token_list); + } + else + { + media_content_error("DB field mapping table doesn't exist. Check db connection", MEDIA_CONTENT_ERROR_DB_FAILED); + return MEDIA_CONTENT_ERROR_DB_FAILED; + } + + return ret; +} + +int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = NULL; + char option_query[DEFAULT_QUERY_SIZE] = {0, }; + char condition[DEFAULT_QUERY_SIZE] = {0, }; + int size = 0; + //bool order_by = true; + + if(filter == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(attr == NULL) + { + media_content_error("DB field mapping table doesn't exist. Check db connection", MEDIA_CONTENT_ERROR_DB_FAILED); + return MEDIA_CONTENT_ERROR_DB_FAILED; + } + + _filter = (filter_s*)filter; + + memset(option_query, 0x00, sizeof(option_query)); + + /* Order by*/ + if(STRING_VALID(_filter->order_keyword) && ((_filter->order_type == MEDIA_CONTENT_ORDER_ASC) ||(_filter->order_type == MEDIA_CONTENT_ORDER_DESC))) + { + int idx = 0; + int total_str_size = 0; + GList *token_list = NULL; + token_t *token; + char *attr_str; + + if(__tokenize_attribute(&token_list, _filter->order_keyword) < 0) + { + media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + for(idx = 0; idx < g_list_length(token_list); idx++) + { + token = (token_t*)g_list_nth_data(token_list, idx); + + if(token->type == UNKNOWN_TYPE) + { + char *replace_str = __media_filter_replace_attr(attr, token->str); + if(STRING_VALID(replace_str)) + { + attr_str = (char*)calloc(strlen(replace_str) + COLLATE_STR_SIZE + 1, sizeof(char)); + + if(_filter->order_collate_type == MEDIA_CONTENT_COLLATE_NOCASE || _filter->order_collate_type == MEDIA_CONTENT_COLLATE_RTRIM ||_filter->order_collate_type == MEDIA_CONTENT_COLLATE_LOCALIZED) { + snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s COLLATE %s %s", replace_str, __get_collate_str(_filter->order_collate_type), __get_order_str(_filter->order_type)); + } else { + snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s %s", replace_str, __get_order_str(_filter->order_type)); + } + + SAFE_FREE(token->str); + token->str = attr_str; + SAFE_FREE(replace_str); + } + else + { + media_content_error("There is no matched db field for %s", token->str); + } + } + + total_str_size += strlen(token->str) + 1; + //media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str); + } + + //make the statment + char *generated_condition = NULL; + size = total_str_size + COLLATE_STR_SIZE + 1; + generated_condition = (char*)calloc(size, sizeof(char)); + + for(idx = 0; idx < g_list_length(token_list); idx++) + { + token = (token_t*)g_list_nth_data(token_list, idx); + + if((token != NULL) && STRING_VALID(token->str)) + { + //media_content_debug("[%d] %s", idx, token->str); + SAFE_STRLCAT(generated_condition, token->str, size); + SAFE_STRLCAT(generated_condition, SPACE, size); + + SAFE_FREE(token->str); + SAFE_FREE(token); + } + } + + snprintf(condition, sizeof(condition), "ORDER BY %s", generated_condition); + SAFE_STRLCAT(option_query, condition, sizeof(option_query)); + + if(token_list != NULL) + g_list_free(token_list); + + SAFE_FREE(generated_condition); + } + + /* offset */ + SAFE_STRLCAT(option_query, SPACE, sizeof(option_query)); + snprintf(condition, sizeof(condition), "LIMIT %d, %d", _filter->offset, _filter->count); + SAFE_STRLCAT(option_query, condition, sizeof(option_query)); + + if(STRING_VALID(option_query)) + { + *generated_option = strdup(option_query); + } + else + { + *generated_option = NULL; + } + + return ret; +} + +int media_filter_create(filter_h *filter) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(filter == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + filter_s *_filter = (filter_s*)calloc(1, sizeof(filter_s)); + + if(_filter == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + else + { + _filter->condition = NULL; + _filter->order_keyword = NULL; + _filter->order_type = -1; + _filter->condition_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT; + _filter->order_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT; + _filter->offset = -1; + _filter->count = -1; + + *filter = (filter_h)_filter; + } + + return ret; +} + +int media_filter_destroy(filter_h filter) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if(_filter) + { + SAFE_FREE(_filter->condition); + SAFE_FREE(_filter->order_keyword); + SAFE_FREE(_filter); + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_filter_set_offset(filter_h filter, int offset, int count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if(_filter != NULL) + { + _filter->offset = offset; + _filter->count = count; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_filter_set_condition(filter_h filter, const char *condition, media_content_collation_e collate_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if((_filter != NULL) && STRING_VALID(condition) + && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) + { + if(STRING_VALID(_filter->condition)) + { + SAFE_FREE(_filter->condition); + } + + _filter->condition = strdup(condition); + if(_filter->condition == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + media_content_sec_debug("Condition string : %s", _filter->condition); + + _filter->condition_collate_type = collate_type; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_filter_set_order(filter_h filter, media_content_order_e order_type, const char *order_keyword, media_content_collation_e collate_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if((_filter != NULL) && STRING_VALID(order_keyword) + && ((order_type == MEDIA_CONTENT_ORDER_ASC) ||(order_type == MEDIA_CONTENT_ORDER_DESC)) + && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) + { + SAFE_FREE(_filter->order_keyword); + + if(STRING_VALID(order_keyword)) + { + _filter->order_keyword = strdup(order_keyword); + + if(_filter->order_keyword == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + _filter->order_type = order_type; + _filter->order_collate_type = collate_type; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_filter_get_offset(filter_h filter, int *offset, int *count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if(_filter) + { + *offset = _filter->offset; + *count = _filter->count; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_filter_get_condition(filter_h filter, char **condition, media_content_collation_e *collate_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if(_filter) + { + if(STRING_VALID(_filter->condition)) + { + *condition = strdup(_filter->condition); + if(*condition == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *condition = NULL; + } + + *collate_type = _filter->condition_collate_type; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *collate_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_s *_filter = (filter_s*)filter; + + if(_filter) + { + if(STRING_VALID(_filter->order_keyword)) + { + *order_keyword = strdup(_filter->order_keyword); + if(*order_keyword == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *order_keyword = NULL; + } + + *order_type = _filter->order_type; + *collate_type = _filter->order_collate_type; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_folder.c b/src/media_folder.c new file mode 100755 index 0000000..4e40618 --- /dev/null +++ b/src/media_folder.c @@ -0,0 +1,460 @@ + /* + * 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 +#include + +static char *g_src_path = NULL; + +static char *__media_folder_get_update_folder_sql(media_folder_h folder); + +static char *__media_folder_get_update_folder_sql(media_folder_h folder) +{ + media_folder_s *_folder = (media_folder_s*)folder; + char *return_sql = NULL; + char *name_pinyin = NULL; + bool pinyin_support = FALSE; + + /*Update Pinyin If Support Pinyin*/ + media_svc_check_pinyin_support(&pinyin_support); + if(pinyin_support) + media_svc_get_pinyin(_content_get_db_handle(), _folder->name, &name_pinyin); + + return_sql = sqlite3_mprintf("%q='%q', %q='%q', %q=%d, %q='%q'", + DB_FIELD_FOLDER_PATH, _folder->path, + DB_FIELD_FOLDER_NAME, _folder->name, + DB_FIELD_FOLDER_MODIFIED_TIME, _folder->modified_time, + DB_FIELD_FOLDER_NAME_PINYIN, name_pinyin); + + SAFE_FREE(name_pinyin); + return return_sql; +} + +int media_folder_get_folder_count_from_db(filter_h filter, int *folder_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(!folder_count) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_group_count(filter, MEDIA_GROUP_FOLDER, folder_count); + + return ret; +} + +int media_folder_foreach_folder_from_db(filter_h filter, media_folder_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(callback == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_folder(filter, callback, user_data); + + return ret; +} + +int media_folder_get_media_count_from_db(const char *folder_id, filter_h filter, int *media_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(STRING_VALID(folder_id) && media_count) + { + ret = _media_db_get_group_item_count(folder_id, filter, MEDIA_GROUP_FOLDER, media_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_foreach_media_from_db(const char *folder_id, filter_h filter, media_info_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((callback != NULL) && STRING_VALID(folder_id)) + { + ret = _media_db_get_group_item(folder_id, filter, callback, user_data, MEDIA_GROUP_FOLDER); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_destroy(media_folder_h folder) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + if(_folder) + { + SAFE_FREE(_folder->path); + SAFE_FREE(_folder->name); + SAFE_FREE(_folder->folder_id); + SAFE_FREE(_folder); + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} +int media_folder_clone(media_folder_h *dst, media_folder_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_src = (media_folder_s*)src; + + /*this is temporary log to fix bug*/ + media_content_error(""); + + if(_src != NULL) + { + media_folder_s *_dst = (media_folder_s*)calloc(1, sizeof(media_folder_s)); + if(_dst == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->folder_id)) + { + _dst->folder_id = strdup(_src->folder_id); + if(_dst->folder_id == NULL) + { + SAFE_FREE(_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->storage_type = _src->storage_type; + + if(STRING_VALID(_src->name)) + { + _dst->name = strdup(_src->name); + if(_dst->name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_folder_destroy((media_folder_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->path)) + { + _dst->path = strdup(_src->path); + if(_dst->path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_folder_destroy((media_folder_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + *dst = (media_folder_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_get_folder_id(media_folder_h folder, char **folder_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + + if(_folder) + { + if(STRING_VALID(_folder->folder_id)) + { + *folder_id = strdup(_folder->folder_id); + if(*folder_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *folder_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_get_path(media_folder_h folder, char **path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + if(_folder) + { + if(STRING_VALID(_folder->path)) + { + *path = strdup(_folder->path); + if(*path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *path = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; + +} + +int media_folder_get_name(media_folder_h folder, char **name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + if(_folder) + { + if(STRING_VALID(_folder->name)) + { + *name = strdup(_folder->name); + if(*name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *name = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_get_modified_time(media_folder_h folder, time_t* time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + if(_folder) + { + *time = _folder->modified_time; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_get_storage_type(media_folder_h folder, media_content_storage_e* storage_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + if(_folder) + { + *storage_type = _folder->storage_type; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folder) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[DEFAULT_QUERY_SIZE]; + + if(!STRING_VALID(folder_id)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_FOLDER_FROM_FOLDER, folder_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_folder_s *_folder = (media_folder_s*)calloc(1, sizeof(media_folder_s)); + + if(_folder == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + media_content_error("folder handle %x", _folder); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) + _folder->folder_id = strdup((const char *)sqlite3_column_text(stmt, 0)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _folder->path = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + _folder->name = strdup((const char *)sqlite3_column_text(stmt, 2)); + + *folder = (media_folder_h)_folder; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_folder_update_to_db(media_folder_h folder) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + char *set_sql = NULL; + char *sql = NULL; + + if((_folder != NULL) && STRING_VALID(_folder->folder_id) && g_src_path) + { + /* Set modified time */ + time_t date; + time(&date); + _folder->modified_time = date; + + set_sql = __media_folder_get_update_folder_sql((media_folder_h)_folder); + if(set_sql == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE folder_uuid=%Q", DB_TABLE_FOLDER, set_sql, _folder->folder_id); + + ret = _content_query_sql(sql); + + sqlite3_free(set_sql); + sqlite3_free(sql); + + /* Do folder rename operation using libmedia-service */ + ret = media_svc_rename_folder(_content_get_db_handle(), g_src_path, _folder->path); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_folder_set_name(media_folder_h folder, const char *name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_folder_s *_folder = (media_folder_s*)folder; + + if(_folder != NULL && STRING_VALID(name)) + { + if (STRING_VALID(_folder->path) && STRING_VALID(_folder->name)) { + char *folder_path = NULL; + char new_folder_path[MAX_QUERY_SIZE] = {0,}; + + folder_path = g_path_get_dirname(_folder->path); + media_content_sec_debug("Existed Folder Path : %s", _folder->path); + snprintf(new_folder_path, sizeof(new_folder_path), "%s/%s", folder_path, name); + media_content_sec_debug("New Path : %s", new_folder_path); + + SAFE_FREE(g_src_path); + g_src_path = strdup(_folder->path); + + SAFE_FREE(_folder->path); + SAFE_FREE(_folder->name); + _folder->path = strdup(new_folder_path); + + if(_folder->path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _folder->name = strdup(name); + if(_folder->name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_group.c b/src/media_group.c new file mode 100755 index 0000000..4b236b5 --- /dev/null +++ b/src/media_group.c @@ -0,0 +1,395 @@ +/* +* 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 +#include +#include +#include + + +int media_album_get_album_count_from_db(filter_h filter, int *album_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(album_count != NULL) + { + ret = _media_db_get_group_count(filter, MEDIA_GROUP_ALBUM, album_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_foreach_album_from_db(filter_h filter, media_album_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(callback == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_album(filter, callback, user_data); + + return ret; +} + +int media_album_get_media_count_from_db(int album_id, filter_h filter, int *media_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((album_id > 0) && (media_count != NULL)) + { + ret = _media_db_get_group_item_count_by_id(album_id, filter, MEDIA_GROUP_ALBUM, media_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_foreach_media_from_db(int album_id, filter_h filter, media_info_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((album_id > 0) && (callback != NULL)) + { + ret = _media_db_get_group_item_by_id(album_id, filter, callback, user_data, MEDIA_GROUP_ALBUM); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_get_album_from_db(int album_id, media_album_h *album) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[DEFAULT_QUERY_SIZE]; + + if(album_id < 0) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_ALBUM_FROM_ALBUM, album_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_album_s *_album = (media_album_s*)calloc(1, sizeof(media_album_s)); + + _album->album_id = (int)sqlite3_column_int(stmt, 0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _album->name = strdup((const char *)sqlite3_column_text(stmt, 1)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + _album->artist = strdup((const char *)sqlite3_column_text(stmt, 2)); + + *album = (media_album_h)_album; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_album_destroy(media_album_h album) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_album_s *_album = (media_album_s*)album; + + if(_album) + { + SAFE_FREE(_album->name); + SAFE_FREE(_album->artist); + SAFE_FREE(_album->album_art_path); + SAFE_FREE(_album); + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_clone(media_album_h *dst, media_album_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_album_s *_src = (media_album_s*)src; + + if(_src != NULL) + { + media_album_s *_dst = (media_album_s*)calloc(1, sizeof(media_album_s)); + + if(_dst == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _dst->album_id = _src->album_id; + + if(STRING_VALID(_src->name)) + { + _dst->name = strdup(_src->name); + if(_dst->name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_album_destroy((media_album_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->artist)) + { + _dst->artist = strdup(_src->artist); + if(_dst->artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_album_destroy((media_album_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->album_art_path)) + { + _dst->album_art_path = strdup(_src->album_art_path); + if(_dst->album_art_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_album_destroy((media_album_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + *dst = (media_album_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_get_album_id(media_album_h album, int *album_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_album_s *_album = (media_album_s*)album; + + if(_album && album_id) + { + *album_id = _album->album_id; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_get_name(media_album_h album, char **name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_album_s *_album = (media_album_s*)album; + + if(_album) + { + if(STRING_VALID(_album->name)) + { + *name = strdup(_album->name); + if(*name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *name = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_get_artist(media_album_h album, char **artist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_album_s *_album = (media_album_s*)album; + + if(_album) + { + if(STRING_VALID(_album->artist)) + { + *artist = strdup(_album->artist); + if(*artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *artist = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_album_get_album_art(media_album_h album, char **album_art) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_album_s *_album = (media_album_s*)album; + + if(_album) + { + if(STRING_VALID(_album->album_art_path)) + { + *album_art = strdup(_album->album_art_path); + if(*album_art == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *album_art = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_group_get_group_count_from_db(filter_h filter, media_group_e group, int *group_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX) || (group_count == NULL)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + else + { + ret = _media_db_get_media_group_count(group, filter, group_count); + } + + return ret; +} + +int media_group_foreach_group_from_db(filter_h filter, media_group_e group, media_group_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + else + { + ret = _media_db_get_media_group(group, filter, callback, user_data); + } + + return ret; +} + +int media_group_get_media_count_from_db(const char *group_name, media_group_e group, filter_h filter, int *media_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((media_count == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + else + { + ret = _media_db_get_media_group_item_count(group_name, filter, group, media_count); + } + + return ret; +} + +int media_group_foreach_media_from_db(const char *group_name, media_group_e group, filter_h filter, media_info_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((callback == NULL) || (group < MEDIA_CONTENT_GROUP_DISPLAY_NAME) || (group >= MEDIA_CONTENT_GROUP_MAX)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + else + { + ret = _media_db_get_media_group_item(group_name, filter, group, callback, user_data); + } + + return ret; +} diff --git a/src/media_image.c b/src/media_image.c new file mode 100755 index 0000000..c11d538 --- /dev/null +++ b/src/media_image.c @@ -0,0 +1,444 @@ +/* +* 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 + + +int image_meta_destroy(image_meta_h image) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image) + { + SAFE_FREE(_image->media_id); + SAFE_FREE(_image->date_taken); + SAFE_FREE(_image->title); + SAFE_FREE(_image->weather); + SAFE_FREE(_image->burst_id); + SAFE_FREE(_image); + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_clone(image_meta_h *dst, image_meta_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_src = (image_meta_s*)src; + + if(_src != NULL) + { + image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s)); + if(NULL == _dst) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->media_id)) + { + _dst->media_id = strdup(_src->media_id); + if(_dst->media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + image_meta_destroy((image_meta_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->date_taken)) + { + _dst->date_taken = strdup(_src->date_taken); + if(_dst->date_taken == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + image_meta_destroy((image_meta_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->title)) + { + _dst->title = strdup(_src->title); + if(_dst->title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + image_meta_destroy((image_meta_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->weather)) + { + _dst->weather = strdup(_src->weather); + if(_dst->weather == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + image_meta_destroy((image_meta_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->burst_id)) + { + _dst->burst_id = strdup(_src->burst_id); + if(_dst->burst_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + image_meta_destroy((image_meta_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->width = _src->width; + _dst->height = _src->height; + _dst->orientation = _src->orientation; + + *dst = (image_meta_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_get_media_id(image_meta_h image, char **media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image && media_id) + { + if(STRING_VALID(_image->media_id)) + { + char *new_string = strdup(_image->media_id); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *media_id = new_string; + } + else + { + *media_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; + +} + +int image_meta_get_width(image_meta_h image, int *width) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image && width) + { + *width = _image->width; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} +int image_meta_get_height(image_meta_h image, int *height) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image && height) + { + *height = _image->height; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image && orientation) + { + *orientation = _image->orientation; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_get_date_taken(image_meta_h image, char **date_taken) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image && date_taken) + { + if(STRING_VALID(_image->date_taken)) + { + char *new_string = strdup(_image->date_taken); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *date_taken = new_string; + } + else + { + *date_taken = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_get_title(image_meta_h image, char **title) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + if(_image) + { + if(STRING_VALID(_image->title)) + { + *title = strdup(_image->title); + if(*title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *title = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_get_weather(image_meta_h image, char **weather) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + if(_image) + { + if(STRING_VALID(_image->weather)) + { + *weather = strdup(_image->weather); + if(*weather == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *weather = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_get_burst_id(image_meta_h image, char **burst_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image && burst_id) + { + if(STRING_VALID(_image->burst_id)) + { + *burst_id = strdup(_image->burst_id); + if(*burst_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *burst_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image && is_burst_shot) + { + if(STRING_VALID(_image->burst_id)) + *is_burst_shot = true; + else + *is_burst_shot = false; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_set_weather(image_meta_h image, const char *weather) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image != NULL) + { + SAFE_FREE(_image->weather); + + if(STRING_VALID(weather)) + { + _image->weather = strdup(weather); + if(_image->weather == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _image->weather = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + + if(_image == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + _image->orientation = orientation; + + return ret; +} + +int image_meta_update_to_db(image_meta_h image) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + image_meta_s *_image = (image_meta_s*)image; + char *sql = NULL; + + if(_image != NULL && STRING_VALID(_image->media_id)) + { + sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->weather, _image->media_id); + ret = _content_query_sql(sql); + sqlite3_free(sql); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} \ No newline at end of file diff --git a/src/media_info.c b/src/media_info.c new file mode 100755 index 0000000..7b36de4 --- /dev/null +++ b/src/media_info.c @@ -0,0 +1,2964 @@ +/* +* 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 +#include +#include +#include + +static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data); +static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data); +static bool __media_info_delete_batch_cb(media_info_h media, void *user_data); +static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, unsigned int array_length, media_insert_completed_cb completed_cb, void *user_data); + +static int __media_info_get_media_path_by_id_from_db(const char *media_id, char **path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char *select_query = NULL; + + if(!STRING_VALID(media_id)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + select_query = sqlite3_mprintf(SELECT_MEDIA_PATH_BY_ID, media_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + sqlite3_free(select_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if(sqlite3_step(stmt) == SQLITE_ROW) + { + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0))) + *path = strdup((const char *)sqlite3_column_text(stmt, 0)); + } else { + media_content_error("There's no media with this ID : %s", media_id); + *path = NULL; + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_insert_cb_s *_cb_data = (media_insert_cb_s *)user_data; + + if (_cb_data) { + if (result) { + ret = _content_error_capi(MEDIA_CONTENT_TYPE, result->result); + } + + if (_cb_data->insert_completed_cb) + _cb_data->insert_completed_cb(ret, _cb_data->user_data); + + if (STRING_VALID(_cb_data->insert_list_path)) { + if (unlink(_cb_data->insert_list_path) < 0) { + media_content_error("failed to delete : %s", strerror(errno)); + } + SAFE_FREE(_cb_data->insert_list_path); + } + } + + SAFE_FREE(_cb_data); + + return; +} + +static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data) +{ + int error_value = MEDIA_CONTENT_ERROR_NONE; + + media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s *)user_data; + media_info_s *media = NULL; + + if(_thumb_cb != NULL) + { + media = _thumb_cb->handle; + if((media != NULL) && STRING_VALID(path)) + { + SAFE_FREE(media->thumbnail_path); + media->thumbnail_path = strdup(path); + } + + media_content_debug("error [%d], thumbnail_path [%s]", error, path); + error_value = _content_error_capi(MEDIA_THUMBNAIL_TYPE, error); + if (_thumb_cb->thumbnail_completed_cb) + _thumb_cb->thumbnail_completed_cb(error_value, path, _thumb_cb->user_data); + } + + SAFE_FREE(_thumb_cb); + + return; +} + +static bool __media_info_delete_batch_cb(media_info_h media, void *user_data) +{ + char *thumb_path = NULL; + media_content_type_e media_type = 0; + + if(media == NULL) + { + media_content_debug("NO Item"); + return true; + } + + media_info_get_media_type(media, &media_type); + media_content_debug("media_type : [%d]", media_type); + + media_info_get_thumbnail_path(media, &thumb_path); + if (STRING_VALID(thumb_path)) { + if (strncmp(MEDIA_CONTENT_THUMB_DEFAULT_PATH, thumb_path, strlen(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) != 0) { + media_content_debug("Deleting thumbnail : [%s]", thumb_path); + if (unlink(thumb_path) < 0) { + media_content_error("failed to delete : %s", strerror(errno)); + } + } + + SAFE_FREE(thumb_path); + } + + return true; +} + +static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, + unsigned int array_length, + media_insert_completed_cb completed_cb, + void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + FILE *fp = NULL; + char list_path[255] = {0,}; + int idx = 0; + int nwrites = 0; + + for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) { + snprintf(list_path, sizeof(list_path), "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx); + + if (g_file_test(list_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + memset(list_path, 0x00, sizeof(list_path)); + continue; + } else { + media_content_debug("The request file list path : %s", list_path); + break; + } + } + + if (idx == BATCH_REQUEST_MAX) { + media_content_error("Too many batch request for one thread"); + return MEDIA_CONTENT_ERROR_DB_BUSY; + } + + fp = fopen(list_path, "w"); + if (fp == NULL) { + media_content_error("failed to open file : %s [%s]", list_path, strerror(errno)); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + for (idx = 0; idx < array_length; idx++) { + if (STRING_VALID(path_array[idx])) { + int size = strlen(path_array[idx]); + + nwrites = fwrite(path_array[idx], 1, size, fp); + if (nwrites != size) { + media_content_error("failed to write : %s", strerror(errno)); + fclose(fp); + if (unlink(list_path) < 0) { + media_content_error("failed to delete : %s", strerror(errno)); + } + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + nwrites = fwrite("\n", 1, 1, fp); + if (nwrites != 1) { + media_content_error("failed to write : %s", strerror(errno)); + fclose(fp); + if (unlink(list_path) < 0) { + media_content_error("failed to delete : %s", strerror(errno)); + } + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + } else { + media_content_error("path[%d] is invalid string", idx); + } + } + + fclose(fp); + + media_insert_cb_s *_cb_data = (media_insert_cb_s *)calloc(1, sizeof(media_insert_cb_s)); + _cb_data->insert_completed_cb = completed_cb; + _cb_data->user_data = user_data; + _cb_data->insert_list_path = strdup(list_path); + + if(insert_type == MEDIA_BATCH_INSERT_NORMAL) + ret = media_files_register(list_path, __media_info_insert_completed_cb, _cb_data); + else if(insert_type == MEDIA_BATCH_INSERT_BURSTSHOT) + ret = media_burstshot_register(list_path, __media_info_insert_completed_cb, _cb_data); + else + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + + if (ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_files_register failed : %d", ret); + if (unlink(list_path) < 0) { + media_content_error("failed to delete : %s", strerror(errno)); + } + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + return ret; +} + +typedef enum { + MEDIA_INFO_UUID = 0, + MEDIA_INFO_PATH, + MEDIA_INFO_FILE_NAME, + MEDIA_INFO_TYPE, + MEDIA_INFO_MIME_TYPE, + MEDIA_INFO_SIZE, + MEDIA_INFO_ADDED_TIME, + MEDIA_INFO_MODIFIED_TIME, + MEDIA_INFO_THUMBNAIL_PATH, + MEDIA_INFO_DESCRIPTION, + MEDIA_INFO_RATING, //10 + MEDIA_INFO_FAVOURITE, + MEDIA_INFO_AUTHOR, + MEDIA_INFO_PROVIDER, + MEDIA_INFO_CONTENT_NAME, + MEDIA_INFO_CATEGORY, + MEDIA_INFO_LOCATION_TAG, + MEDIA_INFO_AGE_RATING, + MEDIA_INFO_KEYWORD, + MEDIA_INFO_IS_DRM, + MEDIA_INFO_STORAGE_TYPE, //20 + MEDIA_INFO_LONGITUDE, + MEDIA_INFO_LATITUDE, + MEDIA_INFO_ALTITUDE, + MEDIA_INFO_WIDTH, + MEDIA_INFO_HEIGHT, + MEDIA_INFO_DATETAKEN, + MEDIA_INFO_ORIENTATION, + MEDIA_INFO_TITLE, + MEDIA_INFO_ALBUM, + MEDIA_INFO_ARTIST, //30 + MEDIA_INFO_ALBUM_ARTIST, + MEDIA_INFO_GENRE, + MEDIA_INFO_COMPOSER, + MEDIA_INFO_YEAR, + MEDIA_INFO_RECORDED_DATE, + MEDIA_INFO_COPYRIGHT, + MEDIA_INFO_TRACK_NUM, + MEDIA_INFO_BITRATE, + MEDIA_INFO_DURATION, + MEDIA_INFO_PLAYED_COUNT, //40 + MEDIA_INFO_LAST_PLAYED_TIME, + MEDIA_INFO_LAST_PLAYED_POSITION, + MEDIA_INFO_SAMPLERATE, + MEDIA_INFO_CHANNEL, + MEDIA_INFO_BURST_ID, + MEDIA_INFO_TIMELINE, + MEDIA_INFO_WEATHER, + MEDIA_INFO_SYNC_STATUS, + MEDIA_INFO_ITEM_MAX, +} media_info_item_e; + +void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) +{ +//#define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, +// rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, width, height, datetaken, orientation, title, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel, burst_id, timeline, weather" + + media_info_s *_media = (media_info_s*)media; + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID))) + _media->media_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH))) + _media->file_path = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_FILE_NAME))) + _media->display_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_FILE_NAME)); + + _media->media_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_TYPE); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MIME_TYPE))) + _media->mime_type = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MIME_TYPE)); + + _media->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_INFO_SIZE); + + _media->added_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_ADDED_TIME); + + _media->modified_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_MODIFIED_TIME); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_THUMBNAIL_PATH))) + _media->thumbnail_path= strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_THUMBNAIL_PATH)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DESCRIPTION))) + _media->description = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DESCRIPTION)); + + _media->rating = (int)sqlite3_column_int(stmt, MEDIA_INFO_RATING); + + _media->favourite = (int)sqlite3_column_int(stmt, MEDIA_INFO_FAVOURITE); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AUTHOR))) + _media->author = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AUTHOR)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PROVIDER))) + _media->provider = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PROVIDER)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CONTENT_NAME))) + _media->content_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CONTENT_NAME)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CATEGORY))) + _media->category = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CATEGORY)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_LOCATION_TAG))) + _media->location_tag = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_LOCATION_TAG)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AGE_RATING))) + _media->age_rating = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AGE_RATING)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_KEYWORD))) + _media->keyword = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_KEYWORD)); + + _media->is_drm = (int)sqlite3_column_int(stmt, MEDIA_INFO_IS_DRM); + + _media->storage_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_STORAGE_TYPE); + + _media->longitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LONGITUDE); + _media->latitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LATITUDE); + _media->altitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_ALTITUDE); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE))) + _media->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)); + + _media->timeline = (double)sqlite3_column_double(stmt, MEDIA_INFO_TIMELINE); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER))) + _media->weather = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER)); + + _media->sync_status = (int)sqlite3_column_int(stmt, MEDIA_INFO_SYNC_STATUS); + + + if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) { + _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s)); + if(_media->image_meta) { + if(STRING_VALID(_media->media_id)) + _media->image_meta->media_id = strdup(_media->media_id); + + _media->image_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH); + _media->image_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DATETAKEN))) + _media->image_meta->date_taken = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DATETAKEN)); + + _media->image_meta->orientation = sqlite3_column_int(stmt, MEDIA_INFO_ORIENTATION); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE))) + _media->image_meta->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_BURST_ID))) + _media->image_meta->burst_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_BURST_ID)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER))) + _media->image_meta->weather = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER)); + } + + } else if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) { + _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s)); + if(_media->video_meta) { + if(STRING_VALID(_media->media_id)) + _media->video_meta->media_id = strdup(_media->media_id); + + _media->video_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH); + _media->video_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE))) + _media->video_meta->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM))) + _media->video_meta->album = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST))) + _media->video_meta->artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST))) + _media->video_meta->album_artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE))) + _media->video_meta->genre = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER))) + _media->video_meta->composer = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR))) + _media->video_meta->year = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE))) + _media->video_meta->recorded_date = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT))) + _media->video_meta->copyright = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM))) + _media->video_meta->track_num = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM)); + + _media->video_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE); + _media->video_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION); + _media->video_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT); + _media->video_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME); + _media->video_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION); + } + + } + else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) { + _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s)); + if(_media->audio_meta) { + if(STRING_VALID(_media->media_id)) + _media->audio_meta->media_id = strdup(_media->media_id); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE))) + _media->audio_meta->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM))) + _media->audio_meta->album = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST))) + _media->audio_meta->artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST))) + _media->audio_meta->album_artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE))) + _media->audio_meta->genre = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER))) + _media->audio_meta->composer = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR))) + _media->audio_meta->year = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE))) + _media->audio_meta->recorded_date = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT))) + _media->audio_meta->copyright = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT)); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM))) + _media->audio_meta->track_num = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM)); + + _media->audio_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE); + _media->audio_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION); + _media->audio_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT); + _media->audio_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME); + _media->audio_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION); + _media->audio_meta->samplerate = sqlite3_column_int(stmt, MEDIA_INFO_SAMPLERATE); + _media->audio_meta->channel = sqlite3_column_int(stmt, MEDIA_INFO_CHANNEL); + } + } +} + +int _media_info_get_media_info_from_db(const char *path, media_info_h media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char *select_query = NULL; + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + sqlite3_free(select_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if(sqlite3_step(stmt) == SQLITE_ROW) + { + _media_info_item_get_detail(stmt, (media_info_h)_media); + } else { + media_content_error("There's no media!!"); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_info_insert_to_db(const char *path, media_info_h *info) +{ + bool ignore_dir = FALSE; + char *folder_path = NULL; + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(!STRING_VALID(path)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(info == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + folder_path = g_path_get_dirname(path); + ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); + SAFE_FREE(folder_path); + + if(ignore_dir) { + media_content_error("Invalid folder path"); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path); + if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) { + media_content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path); + + media_svc_storage_type_e storage_type = 0; + + ret = media_svc_get_storage_type(path, &storage_type); + if(ret != MEDIA_INFO_ERROR_NONE) + { + media_content_sec_error("media_svc_get_storage_type failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_type, path); + + if(ret != MEDIA_INFO_ERROR_NONE) { + if (ret == MEDIA_INFO_ERROR_DATABASE_CONSTRAINT) { + media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path); + ret = MEDIA_INFO_ERROR_NONE; + } else { + media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path); + } + + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + } else if (ret != MEDIA_INFO_ERROR_NONE) { + media_content_sec_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, path); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s)); + if(_media == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + ret = _media_info_get_media_info_from_db(path, (media_info_h)_media); + + *info = (media_info_h)_media; + return ret; +} + +int media_info_insert_batch_to_db( + const char **path_array, + unsigned int array_length, + media_insert_completed_cb completed_cb, + void *user_data) +{ + if (path_array == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (array_length <= 0) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return __media_info_insert_batch(MEDIA_BATCH_INSERT_NORMAL, path_array, array_length, completed_cb, user_data); +} + +int media_info_insert_burst_shot_to_db(const char **path_array, unsigned int array_length, media_insert_burst_shot_completed_cb callback, void *user_data) +{ + if (path_array == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (array_length <= 0) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return __media_info_insert_batch(MEDIA_BATCH_INSERT_BURSTSHOT, path_array, array_length, callback, user_data); +} + +int media_info_delete_from_db(const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *path = NULL; + + if(!STRING_VALID(media_id)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = __media_info_get_media_path_by_id_from_db(media_id, &path); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("__media_info_get_media_path_by_id_from_db failed : %d", ret); + SAFE_FREE(path); + return ret; + } + + ret = media_svc_delete_item_by_path(_content_get_db_handle(), path); + SAFE_FREE(path); + + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); +} + +int media_info_delete_batch_from_db(filter_h filter) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + char *query_string = NULL; + filter_s *_filter = NULL; + attribute_h attr; + char *condition_query = NULL; + + if(filter == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + /* Delete thumbnail of each item */ + ret = _media_db_get_group_item(NULL, filter, __media_info_delete_batch_cb, NULL, MEDIA_GROUP_NONE); + + _filter = (filter_s*)filter; + attr = _content_get_attirbute_handle(); + + if(_filter->condition) + { + ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + } + + if(STRING_VALID(condition_query)) + { + query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, condition_query); + } + else + { + SAFE_FREE(condition_query); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _content_query_sql(query_string); + if (ret == MEDIA_CONTENT_ERROR_NONE) { + /* Send notification for this + In this case, send noti for internal storage and external storage + */ + media_content_debug("Batch deletion is successfull. Send notification for this"); + media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_INTERNAL, -1, NULL, NULL); + media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_SDCARD, -1, NULL, NULL); + } + + SAFE_FREE(condition_query); + sqlite3_free(query_string); + + return ret; +} + +int media_info_destroy(media_info_h media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media) + { + SAFE_FREE(_media->media_id); + SAFE_FREE(_media->file_path); + SAFE_FREE(_media->display_name); + SAFE_FREE(_media->mime_type); + SAFE_FREE(_media->thumbnail_path); + SAFE_FREE(_media->description); + SAFE_FREE(_media->author); + SAFE_FREE(_media->provider); + SAFE_FREE(_media->content_name); + SAFE_FREE(_media->category); + SAFE_FREE(_media->location_tag); + SAFE_FREE(_media->age_rating); + SAFE_FREE(_media->keyword); + SAFE_FREE(_media->title); + SAFE_FREE(_media->weather); + + if(_media->image_meta) { + SAFE_FREE(_media->image_meta->media_id); + SAFE_FREE(_media->image_meta->date_taken); + SAFE_FREE(_media->image_meta->burst_id); + SAFE_FREE(_media->image_meta->title); + SAFE_FREE(_media->image_meta->weather); + + SAFE_FREE(_media->image_meta); + } else if(_media->video_meta) { + SAFE_FREE(_media->video_meta->media_id); + SAFE_FREE(_media->video_meta->title); + SAFE_FREE(_media->video_meta->album); + SAFE_FREE(_media->video_meta->artist); + SAFE_FREE(_media->video_meta->album_artist); + SAFE_FREE(_media->video_meta->genre); + SAFE_FREE(_media->video_meta->composer); + SAFE_FREE(_media->video_meta->year); + SAFE_FREE(_media->video_meta->recorded_date); + SAFE_FREE(_media->video_meta->copyright); + SAFE_FREE(_media->video_meta->track_num); + + SAFE_FREE(_media->video_meta); + } else if(_media->audio_meta) { + SAFE_FREE(_media->audio_meta->media_id); + SAFE_FREE(_media->audio_meta->title); + SAFE_FREE(_media->audio_meta->album); + SAFE_FREE(_media->audio_meta->artist); + SAFE_FREE(_media->audio_meta->album_artist); + SAFE_FREE(_media->audio_meta->genre); + SAFE_FREE(_media->audio_meta->composer); + SAFE_FREE(_media->audio_meta->year); + SAFE_FREE(_media->audio_meta->recorded_date); + SAFE_FREE(_media->audio_meta->copyright); + SAFE_FREE(_media->audio_meta->track_num); + + SAFE_FREE(_media->audio_meta); + } + + SAFE_FREE(_media); + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_clone(media_info_h *dst, media_info_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_src = (media_info_s*)src; + + + if(_src != NULL) + { + media_info_s *_dst = (media_info_s*)calloc(1, sizeof(media_info_s)); + + if(_dst == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->media_id)) + { + _dst->media_id = strdup(_src->media_id); + if(_dst->media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->file_path)) + { + _dst->file_path = strdup(_src->file_path); + if(_dst->file_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->display_name)) + { + _dst->display_name = strdup(_src->display_name); + if(_dst->display_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->mime_type)) + { + _dst->mime_type = strdup(_src->mime_type); + if(_dst->mime_type == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->thumbnail_path)) + { + _dst->thumbnail_path = strdup(_src->thumbnail_path); + if(_dst->thumbnail_path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->description)) + { + _dst->description = strdup(_src->description); + if(_dst->description == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->weather)) + { + _dst->weather = strdup(_src->weather); + if(_dst->weather == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->title)) + { + _dst->title = strdup(_src->title); + if(_dst->title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->author)) + { + _dst->author = strdup(_src->author); + if(_dst->author == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->provider)) + { + _dst->provider = strdup(_src->provider); + if(_dst->provider == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->content_name)) + { + _dst->content_name = strdup(_src->content_name); + if(_dst->content_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->category)) + { + _dst->category = strdup(_src->category); + if(_dst->category == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->location_tag)) + { + _dst->location_tag = strdup(_src->location_tag); + if(_dst->location_tag == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->age_rating)) + { + _dst->age_rating = strdup(_src->age_rating); + if(_dst->age_rating == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->keyword)) + { + _dst->keyword = strdup(_src->keyword); + if(_dst->keyword == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->media_type = _src->media_type; + _dst->size = _src->size; + _dst->added_time = _src->added_time; + _dst->modified_time = _src->modified_time; + _dst->timeline = _src->timeline; + _dst->longitude = _src->longitude; + _dst->latitude = _src->latitude; + _dst->altitude = _src->altitude; + _dst->rating = _src->rating; + _dst->favourite = _src->favourite; + _dst->is_drm = _src->is_drm; + _dst->storage_type = _src->storage_type; + _dst->sync_status = _src->sync_status; + + if(_src->media_type == MEDIA_CONTENT_TYPE_IMAGE && _src->image_meta) { + _dst->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s)); + if(_dst->image_meta == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->image_meta->media_id)) + { + _dst->image_meta->media_id = strdup(_src->image_meta->media_id); + if(_dst->image_meta->media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->image_meta->date_taken)) + { + _dst->image_meta->date_taken = strdup(_src->image_meta->date_taken); + if(_dst->image_meta->date_taken == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->image_meta->burst_id)) + { + _dst->image_meta->burst_id = strdup(_src->image_meta->burst_id); + if(_dst->image_meta->burst_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->image_meta->weather)) + { + _dst->image_meta->weather = strdup(_src->image_meta->weather); + if(_dst->image_meta->weather == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->image_meta->width = _src->image_meta->width; + _dst->image_meta->height = _src->image_meta->height; + _dst->image_meta->orientation = _src->image_meta->orientation; + + } else if(_src->media_type == MEDIA_CONTENT_TYPE_VIDEO && _src->video_meta) { + _dst->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s)); + if(_dst->video_meta == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->video_meta->media_id)) + { + _dst->video_meta->media_id = strdup(_src->video_meta->media_id); + if(_dst->video_meta->media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->title)) + { + _dst->video_meta->title = strdup(_src->video_meta->title); + if(_dst->video_meta->title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->album)) + { + _dst->video_meta->album = strdup(_src->video_meta->album); + if(_dst->video_meta->album == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->artist)) + { + _dst->video_meta->artist = strdup(_src->video_meta->artist); + if(_dst->video_meta->artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->album_artist)) + { + _dst->video_meta->album_artist = strdup(_src->video_meta->album_artist); + if(_dst->video_meta->album_artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->genre)) + { + _dst->video_meta->genre = strdup(_src->video_meta->genre); + if(_dst->video_meta->genre == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->composer)) + { + _dst->video_meta->composer = strdup(_src->video_meta->composer); + if(_dst->video_meta->composer == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->year)) + { + _dst->video_meta->year = strdup(_src->video_meta->year); + if(_dst->video_meta->year == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->recorded_date)) + { + _dst->video_meta->recorded_date = strdup(_src->video_meta->recorded_date); + if(_dst->video_meta->recorded_date == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->copyright)) + { + _dst->video_meta->copyright = strdup(_src->video_meta->copyright); + if(_dst->video_meta->copyright == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->video_meta->track_num)) + { + _dst->video_meta->track_num = strdup(_src->video_meta->track_num); + if(_dst->video_meta->track_num == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->video_meta->width = _src->video_meta->width; + _dst->video_meta->height = _src->video_meta->height; + _dst->video_meta->duration = _src->video_meta->duration; + _dst->video_meta->bitrate = _src->video_meta->bitrate; + _dst->video_meta->played_count = _src->video_meta->played_count; + _dst->video_meta->played_time = _src->video_meta->played_time; + _dst->video_meta->played_position = _src->video_meta->played_position; + + } else if((_src->media_type == MEDIA_CONTENT_TYPE_MUSIC || _src->media_type == MEDIA_CONTENT_TYPE_SOUND) && _src->audio_meta) { + _dst->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s)); + if(_dst->audio_meta == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->audio_meta->media_id)) + { + _dst->audio_meta->media_id = strdup(_src->audio_meta->media_id); + if(_dst->audio_meta->media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->title)) + { + _dst->audio_meta->title = strdup(_src->audio_meta->title); + if(_dst->audio_meta->title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->album)) + { + _dst->audio_meta->album = strdup(_src->audio_meta->album); + if(_dst->audio_meta->album == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->artist)) + { + _dst->audio_meta->artist = strdup(_src->audio_meta->artist); + if(_dst->audio_meta->artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->album_artist)) + { + _dst->audio_meta->album_artist = strdup(_src->audio_meta->album_artist); + if(_dst->audio_meta->album_artist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->genre)) + { + _dst->audio_meta->genre = strdup(_src->audio_meta->genre); + if(_dst->audio_meta->genre == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->composer)) + { + _dst->audio_meta->composer = strdup(_src->audio_meta->composer); + if(_dst->audio_meta->composer == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->year)) + { + _dst->audio_meta->year = strdup(_src->audio_meta->year); + if(_dst->audio_meta->year == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->recorded_date)) + { + _dst->audio_meta->recorded_date = strdup(_src->audio_meta->recorded_date); + if(_dst->audio_meta->recorded_date == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->copyright)) + { + _dst->audio_meta->copyright = strdup(_src->audio_meta->copyright); + if(_dst->audio_meta->copyright == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + if(STRING_VALID(_src->audio_meta->track_num)) + { + _dst->audio_meta->track_num = strdup(_src->audio_meta->track_num); + if(_dst->audio_meta->track_num == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + media_info_destroy((media_info_h)_dst); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->audio_meta->channel = _src->audio_meta->channel; + _dst->audio_meta->samplerate = _src->audio_meta->samplerate; + _dst->audio_meta->duration = _src->audio_meta->duration; + _dst->audio_meta->bitrate = _src->audio_meta->bitrate; + _dst->audio_meta->played_count = _src->audio_meta->played_count; + _dst->audio_meta->played_time = _src->audio_meta->played_time; + _dst->audio_meta->played_position = _src->audio_meta->played_position; + + } + *dst = (media_info_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_media_count_from_db(filter_h filter, int *media_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(media_count == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + + return ret; + } + + ret = _media_db_get_group_item_count(NULL, filter, MEDIA_GROUP_NONE, media_count); + + return ret; +} + +int media_info_foreach_media_from_db(filter_h filter, media_info_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(callback == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_group_item(NULL, filter, callback, user_data, MEDIA_GROUP_NONE); + + return ret; +} + +int media_info_get_tag_count_from_db(const char *media_id, filter_h filter, int *tag_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(STRING_VALID(media_id) && tag_count) + { + ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_TAG_BY_MEDIA_ID, tag_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_foreach_tag_from_db(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((callback != NULL) && STRING_VALID(media_id)) + { + ret = _media_db_get_tag(media_id, filter, callback, user_data); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_bookmark_count_from_db(const char *media_id, filter_h filter, int *bookmark_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(STRING_VALID(media_id) && bookmark_count) + { + ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, bookmark_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_foreach_bookmark_from_db (const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((callback != NULL) && STRING_VALID(media_id)) + { + ret = _media_db_get_bookmark(media_id, filter, callback, user_data); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_image(media_info_h media, image_meta_h *image) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->media_type != MEDIA_CONTENT_TYPE_IMAGE) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->image_meta == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + image_meta_s *_image = (image_meta_s*)calloc(1, sizeof(image_meta_s)); + + if(_image == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_media->media_id)) { + _image->media_id = strdup(_media->media_id); + } + + _image->width = _media->image_meta->width; + _image->height = _media->image_meta->height; + _image->orientation = _media->image_meta->orientation; + + if(STRING_VALID(_media->image_meta->date_taken)) { + _image->date_taken = strdup(_media->image_meta->date_taken); + } + + if(STRING_VALID(_media->image_meta->title)) { + _image->title = strdup(_media->image_meta->title); + } + + if(STRING_VALID(_media->image_meta->burst_id)) { + _image->burst_id = strdup(_media->image_meta->burst_id); + } + + if(STRING_VALID(_media->image_meta->weather)) { + _image->weather = strdup(_media->image_meta->weather); + } + + *image = (image_meta_h)_image; + + return ret; +} + +int media_info_get_video(media_info_h media, video_meta_h *video) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->media_type != MEDIA_CONTENT_TYPE_VIDEO) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->video_meta == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + video_meta_s *_video = (video_meta_s*)calloc(1, sizeof(video_meta_s)); + + if(_video == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_media->media_id)) { + _video->media_id = strdup(_media->media_id); + } + + if(STRING_VALID(_media->video_meta->title)) { + _video->title = strdup(_media->video_meta->title); + } + if(STRING_VALID(_media->video_meta->album)) { + _video->album = strdup(_media->video_meta->album); + } + if(STRING_VALID(_media->video_meta->artist)) { + _video->artist = strdup(_media->video_meta->artist); + } + if(STRING_VALID(_media->video_meta->album_artist)) { + _video->album_artist = strdup(_media->video_meta->album_artist); + } + if(STRING_VALID(_media->video_meta->genre)) { + _video->genre = strdup(_media->video_meta->genre); + } + if(STRING_VALID(_media->video_meta->composer)) { + _video->composer = strdup(_media->video_meta->composer); + } + if(STRING_VALID(_media->video_meta->year)) { + _video->year = strdup(_media->video_meta->year); + } + if(STRING_VALID(_media->video_meta->recorded_date)) { + _video->recorded_date = strdup(_media->video_meta->recorded_date); + } + if(STRING_VALID(_media->video_meta->copyright)) { + _video->copyright = strdup(_media->video_meta->copyright); + } + if(STRING_VALID(_media->video_meta->track_num)) { + _video->track_num = strdup(_media->video_meta->track_num); + } + + _video->width = _media->video_meta->width; + _video->height = _media->video_meta->height; + _video->duration = _media->video_meta->duration; + _video->bitrate = _media->video_meta->bitrate; + _video->played_count = _media->video_meta->played_count; + _video->played_time = _media->video_meta->played_time; + _video->played_position = _media->video_meta->played_position; + + *video = (video_meta_h)_video; + + return ret; +} + +int media_info_get_audio(media_info_h media, audio_meta_h *audio) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_info_s *_media = (media_info_s*)media; + + if(_media == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->media_type != MEDIA_CONTENT_TYPE_MUSIC && _media->media_type != MEDIA_CONTENT_TYPE_SOUND) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if(_media->audio_meta == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + audio_meta_s *_audio = (audio_meta_s*)calloc(1, sizeof(audio_meta_s)); + + if(_audio == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_media->media_id)) { + _audio->media_id = strdup(_media->media_id); + } + + if(STRING_VALID(_media->audio_meta->title)) { + _audio->title = strdup(_media->audio_meta->title); + } + if(STRING_VALID(_media->audio_meta->album)) { + _audio->album = strdup(_media->audio_meta->album); + } + if(STRING_VALID(_media->audio_meta->artist)) { + _audio->artist = strdup(_media->audio_meta->artist); + } + if(STRING_VALID(_media->audio_meta->album_artist)) { + _audio->album_artist = strdup(_media->audio_meta->album_artist); + } + if(STRING_VALID(_media->audio_meta->genre)) { + _audio->genre = strdup(_media->audio_meta->genre); + } + if(STRING_VALID(_media->audio_meta->composer)) { + _audio->composer = strdup(_media->audio_meta->composer); + } + if(STRING_VALID(_media->audio_meta->year)) { + _audio->year = strdup(_media->audio_meta->year); + } + if(STRING_VALID(_media->audio_meta->recorded_date)) { + _audio->recorded_date = strdup(_media->audio_meta->recorded_date); + } + if(STRING_VALID(_media->audio_meta->copyright)) { + _audio->copyright = strdup(_media->audio_meta->copyright); + } + if(STRING_VALID(_media->audio_meta->track_num)) { + _audio->track_num = strdup(_media->audio_meta->track_num); + } + + _audio->duration = _media->audio_meta->duration; + _audio->bitrate = _media->audio_meta->bitrate; + _audio->samplerate = _media->audio_meta->samplerate; + _audio->channel = _media->audio_meta->channel; + _audio->played_time = _media->audio_meta->played_time; + _audio->played_count = _media->audio_meta->played_count; + _audio->played_position = _media->audio_meta->played_position; + + *audio = (audio_meta_h)_audio; + + return ret; +} + +int media_info_get_media_id(media_info_h media, char **media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && media_id) + { + if(STRING_VALID(_media->media_id)) + { + *media_id = strdup(_media->media_id); + if(*media_id == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *media_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_file_path(media_info_h media, char **path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && path) + { + if(STRING_VALID(_media->file_path)) + { + *path = strdup(_media->file_path); + if(*path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *path = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_display_name(media_info_h media, char **name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + if(_media && name) + { + if(STRING_VALID(_media->display_name)) + { + *name = strdup(_media->display_name); + if(*name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *name = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_media_type(media_info_h media, media_content_type_e *type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + if(_media && type) + { + *type = _media->media_type; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_mime_type(media_info_h media, char **mime_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && mime_type) + { + if(STRING_VALID(_media->mime_type)) + { + *mime_type = strdup(_media->mime_type); + if(*mime_type == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *mime_type = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_size(media_info_h media, unsigned long long *size) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && size) + { + *size = _media->size; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_added_time(media_info_h media, time_t *added_time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + if(_media && added_time) + { + *added_time = _media->added_time; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_modified_time(media_info_h media, time_t* time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + if(_media && time) + { + *time = _media->modified_time; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_timeline(media_info_h media, time_t* time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + if(_media && time) + { + *time = _media->timeline; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_thumbnail_path(media_info_h media, char **path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + if(_media && path) + { + if(STRING_VALID(_media->thumbnail_path)) + { + *path = strdup(_media->thumbnail_path); + if(*path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *path = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_title(media_info_h media, char **title) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && title) + { + if(STRING_VALID(_media->title)) + { + *title = strdup(_media->title); + if(*title == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *title = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_description(media_info_h media, char **description) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && description) + { + if(STRING_VALID(_media->description)) + { + *description = strdup(_media->description); + if(*description == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *description = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_longitude(media_info_h media, double* longitude) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && longitude) + { + *longitude = _media->longitude; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} +int media_info_get_latitude(media_info_h media, double* latitude) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && latitude) + { + *latitude = _media->latitude; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_altitude(media_info_h media, double *altitude) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && altitude) + { + *altitude = _media->altitude; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_weather(media_info_h media, char **weather) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && weather) + { + if(STRING_VALID(_media->weather)) + { + *weather = strdup(_media->weather); + if(*weather == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *weather = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_rating(media_info_h media, int *rating) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && rating) + { + *rating = _media->rating; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_favorite(media_info_h media, bool* favorite) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && favorite) + { + + *favorite = _media->favourite; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_author(media_info_h media, char **author) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && author) + { + if(STRING_VALID(_media->author)) + { + *author = strdup(_media->author); + if(*author == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *author = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_provider(media_info_h media, char **provider) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && provider) + { + if(STRING_VALID(_media->provider)) + { + *provider = strdup(_media->provider); + if(*provider == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *provider = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_content_name(media_info_h media, char **content_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && content_name) + { + if(STRING_VALID(_media->content_name)) + { + *content_name = strdup(_media->content_name); + if(*content_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *content_name = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_category(media_info_h media, char **category) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && category) + { + if(STRING_VALID(_media->category)) + { + *category = strdup(_media->category); + if(*category == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *category = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_location_tag(media_info_h media, char **location_tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && location_tag) + { + if(STRING_VALID(_media->location_tag)) + { + *location_tag = strdup(_media->location_tag); + if(*location_tag == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *location_tag = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_age_rating(media_info_h media, char **age_rating) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && age_rating) + { + if(STRING_VALID(_media->age_rating)) + { + *age_rating = strdup(_media->age_rating); + if(*age_rating == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *age_rating = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_keyword(media_info_h media, char **keyword) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && keyword) + { + if(STRING_VALID(_media->keyword)) + { + *keyword = strdup(_media->keyword); + if(*keyword == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *keyword = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_is_drm(media_info_h media, bool *is_drm) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media) + { + *is_drm = _media->is_drm; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media && storage_type) + { + *storage_type = _media->storage_type; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_get_media_from_db(const char *media_id, media_info_h *media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char select_query[DEFAULT_QUERY_SIZE]; + sqlite3_stmt *stmt = NULL; + + if(!STRING_VALID(media_id) || (media == NULL)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, media_id); + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s)); + + if(_media == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + SQLITE3_FINALIZE(stmt); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _media_info_item_get_detail(stmt, (media_info_h)_media); + + *media = (media_info_h)_media; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_info_set_display_name(media_info_h media, const char *display_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL && STRING_VALID(display_name)) + { + SAFE_FREE(_media->display_name); + + _media->display_name = strdup(display_name); + if(_media->display_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_description(media_info_h media, const char *description) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->description); + + if(STRING_VALID(description)) + { + _media->description = strdup(description); + + if(_media->description == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->description = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_longitude(media_info_h media, double longitude) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + _media->longitude = longitude; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_latitude(media_info_h media, double latitude) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + _media->latitude = latitude; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_altitude(media_info_h media, double altitude) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + _media->altitude = altitude; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_weather(media_info_h media, const char *weather) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->weather); + + if(STRING_VALID(weather)) + { + _media->weather = strdup(weather); + + if(_media->weather == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->weather = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_rating(media_info_h media, int rating) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + _media->rating = rating; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_added_time(media_info_h media, time_t added_time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_info_s *_media = (media_info_s*)media; + + if((_media != NULL) && (added_time >= 0)) + { + _media->added_time = added_time; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_favorite(media_info_h media, bool favorite) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + if(favorite == TRUE) + { + time(&_media->favourite); + } + else + { + _media->favourite = 0; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_author(media_info_h media, const char *author) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + if(STRING_VALID(author)) + { + _media->author = strdup(author); + if(_media->author == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->author = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_provider(media_info_h media, const char *provider) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->provider); + + if(STRING_VALID(provider)) + { + _media->provider = strdup(provider); + if(_media->provider == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->provider = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_content_name(media_info_h media, const char *content_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->content_name); + + if(STRING_VALID(content_name)) + { + _media->content_name = strdup(content_name); + if(_media->content_name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->content_name = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_category(media_info_h media, const char *category) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->category); + + if(STRING_VALID(category)) + { + _media->category = strdup(category); + if(_media->category == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->category = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_location_tag(media_info_h media, const char *location_tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->location_tag); + + if(STRING_VALID(location_tag)) + { + _media->location_tag = strdup(location_tag); + if(_media->location_tag == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->location_tag = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_age_rating(media_info_h media, const char *age_rating) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->age_rating); + + if(STRING_VALID(age_rating)) + { + _media->age_rating = strdup(age_rating); + if(_media->age_rating == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->age_rating = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_set_keyword(media_info_h media, const char *keyword) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL) + { + SAFE_FREE(_media->keyword); + + if(STRING_VALID(keyword)) + { + _media->keyword = strdup(keyword); + if(_media->keyword == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + _media->keyword = NULL; + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_update_to_db(media_info_h media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + char *set_sql = NULL; + char *sql = NULL; + + if(_media != NULL && STRING_VALID(_media->media_id)) + { + /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */ + /* This code will be removed when sqlite3_mprintf works clearly */ + char *test_sql = sqlite3_mprintf("%f, %f, %f", _media->longitude, _media->latitude, _media->altitude); + sqlite3_free(test_sql); + + /*Update Pinyin If Support Pinyin*/ + char *file_name_pinyin = NULL; + char *description_pinyin = NULL; + char *author_pinyin = NULL; + char *provider_pinyin = NULL; + char *content_name_pinyin = NULL; + char *category_pinyin = NULL; + char *location_tag_pinyin = NULL; + char *age_rating_pinyin = NULL; + char *keyword_pinyin = NULL; + bool pinyin_support = FALSE; + + /*Update Pinyin If Support Pinyin*/ + media_svc_check_pinyin_support(&pinyin_support); + if(pinyin_support) + { + if(STRING_VALID(_media->display_name)) + media_svc_get_pinyin(_content_get_db_handle(), _media->display_name, &file_name_pinyin); + if(STRING_VALID(_media->description)) + media_svc_get_pinyin(_content_get_db_handle(), _media->description, &description_pinyin); + if(STRING_VALID(_media->author)) + media_svc_get_pinyin(_content_get_db_handle(), _media->author, &author_pinyin); + if(STRING_VALID(_media->provider)) + media_svc_get_pinyin(_content_get_db_handle(), _media->provider, &provider_pinyin); + if(STRING_VALID(_media->content_name)) + media_svc_get_pinyin(_content_get_db_handle(), _media->content_name, &content_name_pinyin); + if(STRING_VALID(_media->category)) + media_svc_get_pinyin(_content_get_db_handle(), _media->category, &category_pinyin); + if(STRING_VALID(_media->location_tag)) + media_svc_get_pinyin(_content_get_db_handle(), _media->location_tag, &location_tag_pinyin); + if(STRING_VALID(_media->age_rating)) + media_svc_get_pinyin(_content_get_db_handle(), _media->age_rating, &age_rating_pinyin); + if(STRING_VALID(_media->keyword)) + media_svc_get_pinyin(_content_get_db_handle(), _media->keyword, &keyword_pinyin); + } + + set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \ + rating=%d, favourite=%d, author=%Q, provider=%Q, content_name=%Q, category=%Q, location_tag=%Q, age_rating=%Q, keyword=%Q, weather=%Q, sync_status=%d, \ + file_name_pinyin=%Q, description_pinyin=%Q, author_pinyin=%Q, provider_pinyin=%Q, content_name_pinyin=%Q, category_pinyin=%Q, location_tag_pinyin=%Q, age_rating_pinyin=%Q, keyword_pinyin=%Q", + _media->display_name, _media->added_time, _media->description, _media->longitude, _media->latitude, _media->altitude, _media->rating, _media->favourite, + _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status, + file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin); + + sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", DB_TABLE_MEDIA, set_sql, _media->media_id); + + ret = _content_query_sql(sql); + sqlite3_free(set_sql); + sqlite3_free(sql); + + SAFE_FREE(description_pinyin); + SAFE_FREE(author_pinyin); + SAFE_FREE(provider_pinyin); + SAFE_FREE(content_name_pinyin); + SAFE_FREE(category_pinyin); + SAFE_FREE(location_tag_pinyin); + SAFE_FREE(age_rating_pinyin); + SAFE_FREE(keyword_pinyin); + + if (ret == MEDIA_CONTENT_ERROR_NONE) { + /* Send notification for this update */ + media_content_debug("Update is successfull. Send notification for this"); + if (_media->file_path && _media->mime_type) { + media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_type, _media->media_id, _media->mime_type); + } else { + media_content_error("Can't Send Noti : path or mime type is NULL"); + } + } + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_refresh_metadata_to_db(const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_h media = NULL; + char *file_path = NULL; + media_content_storage_e storage_type = 0; + + if(!STRING_VALID(media_id)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = media_info_get_media_from_db(media_id, &media); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_info_destroy(media); + return ret; + } + + ret = media_info_get_storage_type(media, &storage_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_info_destroy(media); + return ret; + } + + ret = media_info_get_file_path(media, &file_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_info_destroy(media); + return ret; + } + + ret = media_svc_refresh_item(_content_get_db_handle(), storage_type, file_path); + + SAFE_FREE(file_path); + media_info_destroy(media); + + return ret; +} + +int media_info_move_to_db(media_info_h media, const char* dst_path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_svc_storage_type_e src_storage_type = 0; + media_svc_storage_type_e dst_storage_type = 0; + + if(media == NULL || !STRING_VALID(dst_path)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_info_s *_media = (media_info_s*)media; + + ret = media_svc_get_storage_type(_media->file_path, &src_storage_type); + if(ret != MEDIA_INFO_ERROR_NONE) + { + media_content_sec_error("media_svc_get_storage_type failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + ret = media_svc_get_storage_type(dst_path, &dst_storage_type); + if(ret != MEDIA_INFO_ERROR_NONE) + { + media_content_sec_error("media_svc_get_storage_type failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + ret = media_svc_move_item(_content_get_db_handle(), src_storage_type, _media->file_path, dst_storage_type, dst_path); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); +} + +int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) + { + media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s)); + _thumb_cb->handle = _media; + _thumb_cb->user_data = user_data; + _thumb_cb->thumbnail_completed_cb = callback; + + ret = thumbnail_request_from_db_async(_media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb); + ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_info_cancel_thumbnail(media_info_h media) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_s *_media = (media_info_s*)media; + + if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) + { + ret = thumbnail_request_cancel_media(_media->file_path); + ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/src/media_playlist.c b/src/media_playlist.c new file mode 100755 index 0000000..d839668 --- /dev/null +++ b/src/media_playlist.c @@ -0,0 +1,738 @@ +/* +* 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 +#include +#include +#include + + +static __thread GList *g_playlist_item_list = NULL; + +static void __media_playlist_item_add(media_playlist_item_s *item_s); +static void __media_playlist_item_release(void); +static int __media_playlist_insert_playlist_record(const char *playlist_name, int *playlist_id); +static int __media_playlist_insert_item_to_playlist(int playlist_id, const char *media_id); +static int __media_playlist_remove_item_from_playlist(int playlist_id, int playlist_member_id); +static int __media_playlist_update_playlist_name(int playlist_id, const char *playlist_name); +static int __media_playlist_update_thumbnail_path(int playlist_id, const char *path); +static int __media_playlist_update_play_order(int playlist_id, int playlist_member_id, int play_order); + +static void __media_playlist_item_add(media_playlist_item_s *item_s) +{ + g_playlist_item_list = g_list_append(g_playlist_item_list, item_s); +} + +static void __media_playlist_item_release(void) +{ + int idx = 0; + int list_cnt = 0; + media_playlist_item_s *item = NULL; + + list_cnt = g_list_length(g_playlist_item_list); + + media_content_debug("list_cnt : [%d]", list_cnt); + + for(idx = 0; idx < list_cnt; idx++) + { + item = (media_playlist_item_s*)g_list_nth_data(g_playlist_item_list, idx); + if(item != NULL) + { + SAFE_FREE(item->media_id); + SAFE_FREE(item->playlist_name); + SAFE_FREE(item->thumbnail_path); + SAFE_FREE(item); + } + } + + g_list_free(g_playlist_item_list); + g_playlist_item_list = NULL; + +} + +static int __media_playlist_insert_playlist_record(const char *playlist_name, int *playlist_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + char *select_query = NULL; + sqlite3_stmt *stmt = NULL; + + query_str = sqlite3_mprintf(INSERT_PLAYLIST_TO_PLAYLIST, playlist_name); + + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + select_query = sqlite3_mprintf(SELECT_PLAYLIST_ID_FROM_PLAYLIST, playlist_name); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + sqlite3_free(select_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + *playlist_id = (int)sqlite3_column_int(stmt,0); + } + + SQLITE3_FINALIZE(stmt); + + return MEDIA_CONTENT_ERROR_NONE; +} + +static int __media_playlist_insert_item_to_playlist(int playlist_id, const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[DEFAULT_QUERY_SIZE]; + char *query_str = NULL; + int play_order = 0; + + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id); + + /* get the max play_order */ + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + play_order = (int)sqlite3_column_int(stmt, 0); + } + + SQLITE3_FINALIZE(stmt); + + ++play_order; + + query_str = sqlite3_mprintf("INSERT INTO %q (playlist_id, media_uuid, play_order) values (%d, '%q', %d)", + DB_TABLE_PLAYLIST_MAP, playlist_id, media_id, play_order); + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +static int __media_playlist_remove_item_from_playlist(int playlist_id, int playlist_member_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + query_str = sqlite3_mprintf(REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP, playlist_id, playlist_member_id); + + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +static int __media_playlist_update_playlist_name(int playlist_id, const char *playlist_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + query_str = sqlite3_mprintf(UPDATE_PLAYLIST_NAME_FROM_PLAYLIST, playlist_name, playlist_id); + + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +static int __media_playlist_update_thumbnail_path(int playlist_id, const char *path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + query_str = sqlite3_mprintf(UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST, path, playlist_id); + + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +static int __media_playlist_update_play_order(int playlist_id, int playlist_member_id, int play_order) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + query_str = sqlite3_mprintf(UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP, play_order, playlist_id, playlist_member_id); + + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +int media_playlist_insert_to_db(const char *name, media_playlist_h *playlist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + int playlist_id = 0; + + if(!STRING_VALID(name)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s)); + + if(_playlist == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + ret = __media_playlist_insert_playlist_record(name, &playlist_id); + + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(_playlist); + return ret; + } + + _playlist->playlist_id = playlist_id; + _playlist->name = strdup(name); + + if(_playlist->name == NULL) + { + SAFE_FREE(_playlist); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + *playlist = (media_playlist_h)_playlist; + + return ret; +} + +int media_playlist_delete_from_db(int playlist_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + if(playlist_id < 0) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + query_str = sqlite3_mprintf(DELETE_PLAYLIST_FROM_PLAYLIST, playlist_id); + + ret = _content_query_sql(query_str); + + sqlite3_free(query_str); + + return ret; +} + +int media_playlist_get_playlist_count_from_db(filter_h filter, int *playlist_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(playlist_count != NULL) + { + ret = _media_db_get_group_count(filter, MEDIA_GROUP_PLAYLIST, playlist_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_foreach_playlist_from_db(filter_h filter, media_playlist_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(callback == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_playlist(filter, callback, user_data); + + return ret; +} + +int media_playlist_get_media_count_from_db(int playlist_id, filter_h filter, int *media_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((playlist_id > 0) && (media_count != NULL)) + { + ret = _media_db_get_group_item_count_by_id(playlist_id, filter, MEDIA_GROUP_PLAYLIST, media_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_foreach_media_from_db(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((playlist_id > 0) && (callback != NULL)) + { + ret = _media_db_get_playlist_item(playlist_id, filter, callback, user_data); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_destroy(media_playlist_h playlist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + if(_playlist) + { + SAFE_FREE(_playlist->name); + SAFE_FREE(_playlist->thumbnail_path); + SAFE_FREE(_playlist); + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_clone(media_playlist_h *dst, media_playlist_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_src = (media_playlist_s*)src; + + if(_src != NULL) + { + media_playlist_s *_dst = (media_playlist_s*)calloc(1, sizeof(media_playlist_s)); + if(_dst == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _dst->playlist_id = _src->playlist_id; + + if(STRING_VALID(_src->name)) + { + _dst->name = strdup(_src->name); + if(_dst->name == NULL) + { + media_playlist_destroy((media_playlist_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + *dst = (media_playlist_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_get_playlist_from_db(int playlist_id, media_playlist_h *playlist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[DEFAULT_QUERY_SIZE]; + + if(playlist_id > 0) + { + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_PLAYLIST_FROM_PLAYLIST, playlist_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s)); + + _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0); + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + _playlist->name = strdup((const char *)sqlite3_column_text(stmt, 1)); + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 2))) + _playlist->thumbnail_path = strdup((const char *)sqlite3_column_text(stmt, 2)); + + *playlist = (media_playlist_h)_playlist; + } + + SQLITE3_FINALIZE(stmt); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_get_playlist_id(media_playlist_h playlist, int *playlist_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + if((_playlist != NULL) && (playlist_id != NULL)) + { + *playlist_id = _playlist->playlist_id; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_get_name(media_playlist_h playlist, char **name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + if(_playlist) + { + if(STRING_VALID(_playlist->name)) + { + *name = strdup(_playlist->name); + if(*name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *name = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_get_thumbnail_path(media_playlist_h playlist, char **path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + if(_playlist) + { + if(STRING_VALID(_playlist->thumbnail_path)) + { + *path = strdup(_playlist->thumbnail_path); + if(*path == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *path = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_get_play_order(media_playlist_h playlist, int playlist_member_id, int *play_order) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + int playlist_id = 0; + sqlite3_stmt *stmt = NULL; + char select_query[DEFAULT_QUERY_SIZE]; + + if((_playlist == NULL) || (playlist_member_id < 0) || (play_order == NULL)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + playlist_id = _playlist->playlist_id; + + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id, playlist_member_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + *play_order = (int)sqlite3_column_int(stmt, 0); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_playlist_set_name(media_playlist_h playlist, const char *playlist_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + if(_playlist != NULL && STRING_VALID(playlist_name)) + { + SAFE_FREE(_playlist->name); + + media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + + item->playlist_name = strdup(playlist_name); + item->function = MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME; + if(item->playlist_name == NULL) + { + SAFE_FREE(item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _playlist->name = strdup(playlist_name); + if(_playlist->name == NULL) + { + SAFE_FREE(item->playlist_name); + SAFE_FREE(item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + __media_playlist_item_add(item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + if(_playlist != NULL && STRING_VALID(path)) + { + SAFE_FREE(_playlist->thumbnail_path); + + media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + + item->thumbnail_path = strdup(path); + item->function = MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH; + if(item->thumbnail_path == NULL) + { + SAFE_FREE(item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _playlist->thumbnail_path = strdup(path); + if(_playlist->thumbnail_path == NULL) + { + SAFE_FREE(item->thumbnail_path); + SAFE_FREE(item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + __media_playlist_item_add(item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_set_play_order(media_playlist_h playlist, int playlist_member_id, int play_order) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + if((_playlist != NULL) && (playlist_member_id > 0) && (play_order >= 0)) + { + media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + + item->playlist_member_id = playlist_member_id; + item->function = MEDIA_PLAYLIST_UPDATE_PLAY_ORDER; + item->play_order = play_order; + + __media_playlist_item_add(item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_add_media(media_playlist_h playlist, const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + if(_playlist != NULL && STRING_VALID(media_id)) + { + media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + + item->media_id = strdup(media_id); + item->function = MEDIA_PLAYLIST_ADD; + + if(item->media_id == NULL) + { + SAFE_FREE(item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + __media_playlist_item_add(item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + + +int media_playlist_remove_media(media_playlist_h playlist, int playlist_member_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + if((_playlist != NULL) && (playlist_member_id > 0)) + { + media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); + + item->playlist_member_id = playlist_member_id; + item->function = MEDIA_PLAYLIST_REMOVE; + + __media_playlist_item_add(item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_playlist_update_to_db(media_playlist_h playlist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_s *_playlist = (media_playlist_s*)playlist; + int idx = 0; + int length = 0; + media_playlist_item_s *_playlist_item = NULL; + + if(_playlist == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + length = g_list_length(g_playlist_item_list); + + for (idx = 0; idx < length; idx++) { + _playlist_item = (media_playlist_item_s*)g_list_nth_data(g_playlist_item_list, idx); + if(_playlist_item != NULL) { + switch(_playlist_item->function) { + case MEDIA_PLAYLIST_ADD: + { + ret = __media_playlist_insert_item_to_playlist(_playlist->playlist_id, _playlist_item->media_id); + } + break; + + case MEDIA_PLAYLIST_REMOVE: + { + ret = __media_playlist_remove_item_from_playlist(_playlist->playlist_id, _playlist_item->playlist_member_id); + } + break; + + case MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME: + { + ret = __media_playlist_update_playlist_name(_playlist->playlist_id, _playlist_item->playlist_name); + } + break; + + case MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH: + { + ret = __media_playlist_update_thumbnail_path(_playlist->playlist_id, _playlist_item->thumbnail_path); + } + break; + + case MEDIA_PLAYLIST_UPDATE_PLAY_ORDER: + { + ret = __media_playlist_update_play_order(_playlist->playlist_id, _playlist_item->playlist_member_id, _playlist_item->play_order); + } + break; + } + } + } + + __media_playlist_item_release(); + + return ret; +} diff --git a/src/media_tag.c b/src/media_tag.c new file mode 100755 index 0000000..00a2629 --- /dev/null +++ b/src/media_tag.c @@ -0,0 +1,547 @@ +/* +* 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 + + +static __thread GList *g_tag_item_list = NULL; + +static void __media_tag_item_add(media_tag_item_s *item_s); +static void __media_tag_item_release(void); +static int __media_tag_insert_item_to_tag(int tag_id, const char *media_id); +static int __media_tag_remove_item_from_tag(int tag_id, const char *media_id); +static int __media_tag_update_tag_name(int tag_id, const char *tag_name); +static int __media_tag_get_tag_info_from_db(const char *name, media_tag_h tag); + +static void __media_tag_item_add(media_tag_item_s *item_s) +{ + g_tag_item_list = g_list_append(g_tag_item_list, item_s); +} + +static void __media_tag_item_release(void) +{ + int idx = 0; + int list_cnt = 0; + media_tag_item_s *item = NULL; + + list_cnt = g_list_length(g_tag_item_list); + + media_content_debug("list_cnt : [%d]", list_cnt); + + for(idx = 0; idx < list_cnt; idx++) + { + item = (media_tag_item_s*)g_list_nth_data(g_tag_item_list, idx); + if(item != NULL) + { + SAFE_FREE(item->media_id); + SAFE_FREE(item->tag_name); + SAFE_FREE(item); + } + } + + g_list_free(g_tag_item_list); + g_tag_item_list = NULL; + +} + +static int __media_tag_insert_item_to_tag(int tag_id, const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + query_str = sqlite3_mprintf("INSERT INTO %q (tag_id, media_uuid) values (%d, '%q')", + DB_TABLE_TAG_MAP, tag_id, media_id); + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +static int __media_tag_remove_item_from_tag(int tag_id, const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + query_str = sqlite3_mprintf(REMOVE_TAG_ITEM_FROM_TAG_MAP, tag_id, media_id); + + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +static int __media_tag_update_tag_name(int tag_id, const char *tag_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + query_str = sqlite3_mprintf(UPDATE_TAG_NAME_FROM_TAG, tag_name, tag_id); + + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + return ret; +} + +static int __media_tag_get_tag_info_from_db(const char *name, media_tag_h tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char *select_query = NULL; + media_tag_s *_tag = (media_tag_s*)tag; + + if(_tag == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + select_query = sqlite3_mprintf(SELECT_TAG_BY_NAME, name); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + sqlite3_free(select_query); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + _tag->tag_id = (int)sqlite3_column_int(stmt,0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + { + _tag->name = strdup((const char *)sqlite3_column_text(stmt, 1)); + } + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_tag_insert_to_db(const char *tag_name, media_tag_h *tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + if(!STRING_VALID(tag_name)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + query_str = sqlite3_mprintf(INSERT_TAG_TO_TAG, tag_name); + ret = _content_query_sql(query_str); + sqlite3_free(query_str); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + { + media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s)); + if(_tag == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + ret = __media_tag_get_tag_info_from_db(tag_name, (media_tag_h)_tag); + *tag = (media_tag_h)_tag; + } + + return ret; +} + +int media_tag_delete_from_db(int tag_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + + if(tag_id < 0) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + query_str = sqlite3_mprintf(DELETE_TAG_FROM_TAG, tag_id); + + ret = _content_query_sql(query_str); + + sqlite3_free(query_str); + + return ret; +} + +int media_tag_get_tag_count_from_db(filter_h filter, int *tag_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(tag_count != NULL) + { + ret = _media_db_get_group_count(filter, MEDIA_GROUP_TAG, tag_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_foreach_tag_from_db (filter_h filter, media_tag_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(callback == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_tag(NULL, filter, callback, user_data); + + return ret; +} + +int media_tag_get_media_count_from_db(int tag_id, filter_h filter, int *media_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if((tag_id > 0) && (media_count != NULL)) + { + ret = _media_db_get_group_item_count_by_id(tag_id, filter, MEDIA_GROUP_TAG, media_count); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_foreach_media_from_db(int tag_id, filter_h filter, media_info_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(callback == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + ret = _media_db_get_group_item_by_id(tag_id, filter, callback, user_data, MEDIA_GROUP_TAG); + + return ret; +} + +int media_tag_destroy(media_tag_h tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + if(_tag) + { + SAFE_FREE(_tag->name); + SAFE_FREE(_tag); + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} +int media_tag_clone(media_tag_h *dst, media_tag_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_src = (media_tag_s*)src; + media_tag_s *_dst = NULL; + + if((_src != NULL)) + { + _dst = (media_tag_s*)calloc(1, sizeof(media_tag_s)); + + if(_dst == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _dst->tag_id = _src->tag_id; + + if(STRING_VALID(_src->name)) + { + _dst->name = strdup(_src->name); + if(_dst->name == NULL) + { + SAFE_FREE(_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + *dst = (media_tag_h)_dst; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_get_tag_id(media_tag_h tag, int *tag_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + + if((_tag != NULL) && (tag_id != NULL)) + { + *tag_id = _tag->tag_id; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_get_name(media_tag_h tag, char **name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + if(_tag) + { + if(STRING_VALID(_tag->name)) + { + *name = strdup(_tag->name); + if(*name == NULL) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + else + { + *name = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_get_tag_from_db(int tag_id, media_tag_h *tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[DEFAULT_QUERY_SIZE]; + + if(tag_id <= 0) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_TAG_FROM_TAG, tag_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while(sqlite3_step(stmt) == SQLITE_ROW) + { + media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s)); + + if(_tag == NULL) + { + SQLITE3_FINALIZE(stmt); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _tag->tag_id = (int)sqlite3_column_int(stmt, 0); + + if(STRING_VALID((const char *)sqlite3_column_text(stmt, 1))) + { + _tag->name = strdup((const char *)sqlite3_column_text(stmt, 1)); + } + + *tag = (media_tag_h)_tag; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_tag_add_media(media_tag_h tag, const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + + if((_tag != NULL) && STRING_VALID(media_id)) + { + media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s)); + + _item->media_id = strdup(media_id); + _item->function = MEDIA_TAG_ADD; + + if(_item->media_id == NULL) + { + SAFE_FREE(_item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + __media_tag_item_add(_item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_remove_media(media_tag_h tag, const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + + if(_tag != NULL && STRING_VALID(media_id)) + { + media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s)); + + _item->media_id = strdup(media_id); + _item->function = MEDIA_TAG_REMOVE; + + if(_item->media_id == NULL) + { + SAFE_FREE(_item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + __media_tag_item_add(_item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_set_name(media_tag_h tag, char *tag_name) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + + if(_tag != NULL && STRING_VALID(tag_name)) + { + SAFE_FREE(_tag->name); + + media_tag_item_s *_item = (media_tag_item_s*)calloc(1, sizeof(media_tag_item_s)); + + _item->tag_name = strdup(tag_name); + _item->function = MEDIA_TAG_UPDATE_TAG_NAME; + + if(_item->tag_name == NULL) + { + SAFE_FREE(_item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + _tag->name = strdup(tag_name); + if(_tag->name == NULL) + { + SAFE_FREE(_item->tag_name); + SAFE_FREE(_item); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + __media_tag_item_add(_item); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int media_tag_update_to_db(media_tag_h tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + int idx = 0; + int length = 0; + media_tag_item_s *_tag_item = NULL; + + if(_tag == NULL) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + length = g_list_length(g_tag_item_list); + + for (idx = 0; idx < length; idx++) { + _tag_item = (media_tag_item_s*)g_list_nth_data(g_tag_item_list, idx); + if(_tag_item != NULL) { + switch(_tag_item->function) { + case MEDIA_TAG_ADD: + { + ret = __media_tag_insert_item_to_tag(_tag->tag_id, _tag_item->media_id); + } + break; + + case MEDIA_TAG_REMOVE: + { + ret = __media_tag_remove_item_from_tag(_tag->tag_id, _tag_item->media_id); + } + break; + + case MEDIA_TAG_UPDATE_TAG_NAME: + { + ret = __media_tag_update_tag_name(_tag->tag_id, _tag_item->tag_name); + } + break; + } + } + } + + __media_tag_item_release(); + + return ret; +} diff --git a/src/media_util_private.c b/src/media_util_private.c new file mode 100755 index 0000000..3a22c60 --- /dev/null +++ b/src/media_util_private.c @@ -0,0 +1,131 @@ +/* +* 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 +#include +#include +#include +#include +#include + + +int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_svc_storage_type_e storage_type = 0; + char *scan_ignore = ".scan_ignore"; + bool find = false; + + media_content_sec_debug("dir_path : %s", dir_path); + + if(!STRING_VALID(dir_path)) + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + *ignore = FALSE; + /*1. Check Hidden Directory*/ + if(strstr(dir_path, "/.")) + { + *ignore = TRUE; + media_content_info("hidden path"); + return MEDIA_CONTENT_ERROR_NONE; + } + + /*2. Check Scan Ignore Directory*/ + ret = media_svc_get_storage_type(dir_path, &storage_type); + if(ret != MEDIA_INFO_ERROR_NONE) + { + media_content_error("media_svc_get_storage_type failed : %d", ret); + return _content_error_capi(MEDIA_CONTENT_TYPE, ret); + } + + DIR *dp = NULL; + struct dirent entry; + struct dirent *result = NULL; + + char *leaf_path = NULL; + char search_path[4096] = {0, }; + + strncpy(search_path, dir_path, strlen(dir_path)); + while(STRING_VALID(search_path)) + { + dp = opendir(search_path); + if(dp == NULL) + { + media_content_error("Fail Open Directory"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + while (!readdir_r(dp, &entry, &result)) + { + if (result == NULL) + break; + + if(STRING_VALID(entry.d_name) && (strcmp(entry.d_name, scan_ignore) == 0)) + { + media_content_info("Find Ignore path"); + media_content_sec_debug("Ignore path[%s]", search_path); + find = TRUE; + break; + } + else + { + //media_content_sec_debug("entry.d_name[%s]", entry.d_name); + continue; + } + } + + if (dp) closedir(dp); + dp = NULL; + + if(find) + { + *ignore = TRUE; + break; + } + else + { + /*If root path, Stop Scanning*/ + if((storage_type == MEDIA_SVC_STORAGE_INTERNAL) && (strcmp(search_path, MEDIA_ROOT_PATH_INTERNAL) == 0)) + { + //media_content_debug("Internal root path. Stop Scanning. Not found Ignore information"); + break; + } + else if((storage_type == MEDIA_SVC_STORAGE_EXTERNAL) && (strcmp(search_path, MEDIA_ROOT_PATH_SDCARD) == 0)) + { + //media_content_debug("Enternal root path. Stop Scanning. Not found Ignore information"); + break; + } + + leaf_path = strrchr(search_path, '/'); + if(leaf_path != NULL) + { + int seek_len = leaf_path -search_path; + search_path[seek_len] = '\0'; + //media_content_sec_debug("go to other dir [%s]", search_path); + } + else + { + media_content_debug("Fail to find leaf path"); + break; + } + } + } + + return MEDIA_CONTENT_ERROR_NONE; +} diff --git a/src/media_video.c b/src/media_video.c new file mode 100755 index 0000000..a1f0bda --- /dev/null +++ b/src/media_video.c @@ -0,0 +1,770 @@ +/* +* 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 + + +int video_meta_destroy(video_meta_h video) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video) + { + SAFE_FREE(_video->media_id); + SAFE_FREE(_video->title); + SAFE_FREE(_video->album); + SAFE_FREE(_video->artist); + SAFE_FREE(_video->album_artist); + SAFE_FREE(_video->genre); + SAFE_FREE(_video->composer); + SAFE_FREE(_video->year); + SAFE_FREE(_video->recorded_date); + SAFE_FREE(_video->copyright); + SAFE_FREE(_video->track_num); + SAFE_FREE(_video); + + SAFE_FREE(_video); + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_clone(video_meta_h *dst, video_meta_h src) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_src = (video_meta_s*)src; + + if(_src != NULL) + { + video_meta_s *_dst = (video_meta_s*)calloc(1, sizeof(video_meta_s)); + + if(_dst == NULL) + { + + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + if(STRING_VALID(_src->media_id)) + { + _dst->media_id = strdup(_src->media_id); + if(_dst->media_id == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->title)) + { + _dst->title = strdup(_src->title); + if(_dst->title == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->album)) + { + _dst->album = strdup(_src->album); + if(_dst->album == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->artist)) + { + _dst->artist = strdup(_src->artist); + if(_dst->artist == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->album_artist)) + { + _dst->album_artist = strdup(_src->album_artist); + if(_dst->album_artist == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->genre)) + { + _dst->genre = strdup(_src->genre); + if(_dst->genre == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->composer)) + { + _dst->composer = strdup(_src->composer); + if(_dst->composer == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->year)) + { + _dst->year = strdup(_src->year); + if(_dst->year == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->recorded_date)) + { + _dst->recorded_date = strdup(_src->recorded_date); + if(_dst->recorded_date == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->copyright)) + { + _dst->copyright = strdup(_src->copyright); + if(_dst->copyright == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + if(STRING_VALID(_src->track_num)) + { + _dst->track_num = strdup(_src->track_num); + if(_dst->track_num == NULL) + { + video_meta_destroy((video_meta_h)_dst); + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + } + + _dst->bitrate = _src->bitrate; + _dst->duration = _src->duration; + _dst->width = _src->width; + _dst->height = _src->height; + _dst->played_count = _src->played_count; + _dst->played_time = _src->played_time; + _dst->played_position = _src->played_position; + + *dst = (video_meta_h)_dst; + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_media_id(video_meta_h video, char **media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->media_id)) + { + char *new_string = strdup(_video->media_id); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *media_id = new_string; + } + else + { + *media_id = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_title(video_meta_h video, char **title) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->title)) + { + char *new_string = strdup(_video->title); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *title = new_string; + } + else + { + *title = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_album(video_meta_h video, char **album) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->album)) + { + char *new_string = strdup(_video->album); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *album = new_string; + } + else + { + *album = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; + +} +int video_meta_get_artist(video_meta_h video, char **artist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->artist)) + { + char *new_string = strdup(_video->artist); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *artist = new_string; + } + else + { + *artist = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; + +} + +int video_meta_get_album_artist(video_meta_h video, char **album_artist) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->album_artist)) + { + char *new_string = strdup(_video->album_artist); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *album_artist = new_string; + } + else + { + *album_artist = NULL; + } + ret = MEDIA_CONTENT_ERROR_NONE; + + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; + +} + +int video_meta_get_genre(video_meta_h video, char **genre) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->genre)) + { + char *new_string = strdup(_video->genre); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *genre = new_string; + } + else + { + *genre = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_composer(video_meta_h video, char **composer) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->composer)) + { + char *new_string = strdup(_video->composer); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *composer = new_string; + } + else + { + *composer = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_year(video_meta_h video, char **year) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->year)) + { + char *new_string = strdup(_video->year); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *year = new_string; + } + else + { + *year = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_recorded_date(video_meta_h video, char **recorded_date) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->recorded_date)) + { + char *new_string = strdup(_video->recorded_date); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *recorded_date = new_string; + } + else + { + *recorded_date = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_copyright(video_meta_h video, char **copyright) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->copyright)) + { + char *new_string = strdup(_video->copyright); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *copyright = new_string; + } + else + { + *copyright = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_track_num(video_meta_h video, char **track_num) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video) + { + if(STRING_VALID(_video->track_num)) + { + char *new_string = strdup(_video->track_num); + if(NULL == new_string) + { + media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + *track_num = new_string; + } + else + { + *track_num = NULL; + } + + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_bit_rate(video_meta_h video, int *bit_rate) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video && bit_rate) + { + *bit_rate = _video->bitrate; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_duration(video_meta_h video, int *duration) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video && duration) + { + *duration = _video->duration; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_width(video_meta_h video, int *width) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video && width) + { + *width = _video->width; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_height(video_meta_h video, int *height) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + if(_video && height) + { + *height = _video->height; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_played_count(video_meta_h video, int *played_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video && played_count) + { + *played_count = _video->played_count; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_played_time(video_meta_h video, time_t* played_time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video) + { + *played_time = _video->played_time; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_get_played_position(video_meta_h video, int *played_position) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video) + { + *played_position = _video->played_position; + ret = MEDIA_CONTENT_ERROR_NONE; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_set_played_count(video_meta_h video, int played_count) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video != NULL) + { + _video->played_count = played_count; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_set_played_time(video_meta_h video, time_t played_time) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video != NULL) + { + _video->played_time = played_time; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_set_played_position(video_meta_h video, int played_position) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + + if(_video != NULL) + { + _video->played_position = played_position; + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +int video_meta_update_to_db(video_meta_h video) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + video_meta_s *_video = (video_meta_s*)video; + char *sql = NULL; + + if(_video != NULL && STRING_VALID(_video->media_id)) + { + sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, _video->played_count, _video->played_time, _video->played_position, _video->media_id); + ret = _content_query_sql(sql); + sqlite3_free(sql); + } + else + { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + return ret; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 0000000..7097377 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,18 @@ +SET(fw_name "capi-content-media-content") +SET(fw_test "${fw_name}-test") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_test} REQUIRED glib-2.0 dlog libmedia-service capi-base-common libmedia-utils) +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") + +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} ${fw_name} ${${fw_test}_LDFLAGS}) +ENDFOREACH() diff --git a/test/media-content_test.c b/test/media-content_test.c new file mode 100755 index 0000000..a1345e0 --- /dev/null +++ b/test/media-content_test.c @@ -0,0 +1,3119 @@ +/* +* 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 +#include +#include +#include +#include +#include +#include +#include +#include + +filter_h g_filter = NULL; +filter_h g_filter_g = NULL; //filter for group like folder, tag, playlist, album, year ... + +GMainLoop *g_loop = NULL; +static int g_cnt = 0; +static int g_media_cnt = 0; + +#define test_audio_id "0f999626-6218-450c-a4ad-181a3bab6ebf" +#define test_video_id "c1a92494-cc5b-4d74-aa7d-253199234548" +#define test_image_id "db1c184c-6f31-43b4-b924-8c00ac5b6197" +media_folder_h g_folder = NULL; + +bool get_audio_meta(audio_meta_h audio) +{ + char *c_value = NULL; + int i_value = 0; + time_t t_value = 0; + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_content_debug("=== audio meta ==="); + + ret = audio_meta_get_media_id(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("audio_id : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_title(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("title : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_album(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("album : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_artist(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("artist : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_album_artist(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("album_artist : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_genre(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("genre : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_composer(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("composer : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_year(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("year : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_recorded_date(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("recorded_date : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_copyright(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("copyright : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_track_num(audio, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("track_num : [%s]", c_value); + SAFE_FREE(c_value); + + ret = audio_meta_get_bit_rate(audio, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("bitrate : [%d]", i_value); + + ret = audio_meta_get_sample_rate(audio, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("samplerate : [%d]", i_value); + + ret = audio_meta_get_channel(audio, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("channel : [%d]", i_value); + + ret = audio_meta_get_duration(audio, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("duration : [%d]", i_value); + + ret = audio_meta_get_played_count(audio, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("played_count : [%d]", i_value); + + ret = audio_meta_get_played_time(audio, &t_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("played_time : [%d]", t_value); + + ret = audio_meta_get_played_position(audio, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("played_position : [%d]", i_value); + + return true; +} + +bool get_video_meta(video_meta_h video) +{ + char *c_value = NULL; + int i_value = 0; + time_t t_value = 0; + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_content_debug("=== video meta ==="); + + ret = video_meta_get_media_id(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("video_id : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_title(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("title : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_album(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("album : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_artist(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("artist : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_album_artist(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("album_artist : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_genre(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("genre : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_composer(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("omposer : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_year(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("year : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_recorded_date(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("recorded_date : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_copyright(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("copyright : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_track_num(video, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("track_num : [%s]", c_value); + SAFE_FREE(c_value); + + ret = video_meta_get_bit_rate(video, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("bitrate : [%d]", i_value); + + ret = video_meta_get_duration(video, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("duration : [%d]", i_value); + + ret = video_meta_get_width(video, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("width : [%d]", i_value); + + ret = video_meta_get_height(video, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("height : [%d]", i_value); + + ret = video_meta_get_played_count(video, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("played_count : [%d]", i_value); + + ret = video_meta_get_played_time(video, &t_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("played_time : [%d]", t_value); + + ret = video_meta_get_played_position(video, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get meta : [%d]", ret); + media_content_debug("played_position : [%d]", i_value); + + return true; +} + +bool gallery_folder_list_cb(media_folder_h folder, void *user_data) +{ + media_folder_h new_folder = NULL; + media_folder_clone(&new_folder, folder); + + GList **list = (GList**)user_data; + *list = g_list_append(*list, new_folder); + + return true; +} + +bool gallery_media_item_cb(media_info_h media, void *user_data) +{ + media_info_h new_media = NULL; + media_info_clone(&new_media, media); + + GList **list = (GList**)user_data; + *list = g_list_append(*list, new_media); + + return true; +} + +bool gallery_tag_item_cb(media_tag_h tag, void *user_data) +{ + media_tag_h new_tag = NULL; + media_tag_clone(&new_tag, tag); + + GList **list = (GList**)user_data; + *list = g_list_append(*list, new_tag); + + return true; +} + +bool gallery_bookmarks_cb(media_bookmark_h bookmark, void *user_data) +{ + media_bookmark_h new_bm = NULL; + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = media_bookmark_clone(&new_bm, bookmark); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_clone : [%d]", ret); + + GList **list = (GList**)user_data; + *list = g_list_append(*list, new_bm); + + return true; +} + +bool media_item_cb(media_info_h media, void *user_data) +{ + char *c_value = NULL; + char *media_id = NULL; + media_content_type_e media_type = 0; + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(media == NULL) + { + media_content_debug("NO Item"); + return true; + } + + ret = media_info_get_media_type(media, &media_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("media_type : [%d]", media_type); + + ret = media_info_get_media_id(media, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("media_id : [%s]", media_id); + + ret = media_info_get_file_path(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("file_path : [%s]", c_value); + SAFE_FREE(c_value); + +#if 0 + int i_value = 0; + time_t t_value = 0; + bool b_value = false; + unsigned long long size = 0; + + if(media_type == MEDIA_CONTENT_TYPE_MUSIC) + { + audio_meta_h audio; + + if(media_info_get_audio(media, &audio) == MEDIA_CONTENT_ERROR_NONE) + { + get_audio_meta(audio); + ret = audio_meta_destroy(audio); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error audio_meta_destroy : [%d]", ret); + } + else + media_content_error("[audio_error]"); + + } + else if(media_type == MEDIA_CONTENT_TYPE_IMAGE) + { + image_meta_h image; + media_content_orientation_e orientation = 0; + bool is_burst_shot = false; + char *burst_id = NULL; + char *weather = NULL; + + if(media_info_get_image(media, &image) == MEDIA_CONTENT_ERROR_NONE) + { + ret = image_meta_get_orientation(image, &orientation); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_orientation : [%d]", ret); + else + media_content_debug("[image] orientation : %d", orientation); + + ret = image_meta_is_burst_shot(image, &is_burst_shot); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_is_burst_shot : [%d]", ret); + if(is_burst_shot) + { + ret = image_meta_get_burst_id(image, &burst_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_burst_id : [%d]", ret); + else + media_content_debug("[image] burst_id : [%s]", burst_id); + + SAFE_FREE(burst_id); + } + + ret = image_meta_get_weather(image, &weather); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_weather : [%d]", ret); + else + media_content_debug("[image] weather : %s", weather); + + ret = image_meta_destroy(image); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_destroy : [%d]", ret); + } + else + media_content_error("[image_error]"); + + } + else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + video_meta_h video; + + if(media_info_get_video(media, &video) == MEDIA_CONTENT_ERROR_NONE) + { + get_video_meta(video); + ret = video_meta_destroy(video); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_destroy : [%d]", ret); + } + else + media_content_error("[video_error]"); + + } + else + { + media_content_debug("Other Content"); + } + + media_content_debug("=== media_info ==="); + ret = media_info_get_file_path(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("file_path : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_display_name(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("display_name : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_mime_type(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("mime_type : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_thumbnail_path(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("thumbnail_path : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_description(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("description : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_author(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("author : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_provider(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("provider : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_content_name(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("content_name : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_category(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("category : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_location_tag(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("location_tag : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_age_rating(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("age_rating : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_keyword(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("keyword : [%s]", c_value); + SAFE_FREE(c_value); + + ret = media_info_get_size(media, &size); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("size : [%lld]", size); + + ret = media_info_get_added_time(media, &t_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("added_time : [%d]", t_value); + + ret = media_info_get_modified_time(media, &t_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("modified_time : [%d]", t_value); + + ret = media_info_get_timeline(media, &t_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("timeline : [%d]", t_value); + + ret = media_info_get_rating(media, &i_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("rating : [%d]", i_value); + + ret = media_info_get_favorite(media, &b_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("favorite : [%d]", b_value); + + ret = media_info_is_drm(media, &b_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("is_drm : [%d]", b_value); + + ret = media_info_set_weather(media, "Sunny"); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to set weather"); + return ret; + + ret = media_info_get_weather(media, &c_value); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error when get info : [%d]", ret); + media_content_debug("weather : [%s]", c_value); + SAFE_FREE(c_value); + + /* Media server can't update when another db handle holds DB connection by sqlite3_prepare */ + //ret = media_info_set_location_tag(media, "Test location tag"); + //media_info_update_to_db(media); + SAFE_FREE(media_id); +#endif + return true; +} + +bool folder_list_cb(media_folder_h folder, void *user_data) +{ + int item_count; + char *folder_id = NULL; + char *folder_path = NULL; + char *folder_name = NULL; + media_content_storage_e storage_type; + bool ret; + media_folder_h *_folder = (media_folder_h*)user_data; + + if(folder != NULL) + { + if(_folder != NULL) + media_folder_clone(_folder, folder); + + if(media_folder_get_folder_id(folder, &folder_id) != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("[ERROR] media_folder_get_folder_id is failed"); + return false; + } + media_content_debug("folder_id = [%s]", folder_id); + + if(media_folder_get_path(folder, &folder_path) != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(folder_id); + media_content_error("[ERROR] media_folder_get_path is failed"); + return false; + } + media_content_debug("folder_path = [%s]", folder_path); + SAFE_FREE(folder_path); + + if(media_folder_get_name(folder, &folder_name) != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(folder_id); + SAFE_FREE(folder_path); + media_content_error("[ERROR] media_folder_get_name is failed"); + return false; + } + media_content_debug("folder_name = [%s]", folder_name); + SAFE_FREE(folder_name); + + if(media_folder_get_storage_type(folder, &storage_type) != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(folder_id); + SAFE_FREE(folder_path); + SAFE_FREE(folder_name); + media_content_error("[ERROR] media_folder_get_storage_type is failed"); + return false; + } + media_content_debug("storage_type = [%d]", storage_type); + + if(media_folder_get_media_count_from_db(folder_id, g_filter, &item_count) != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(folder_id); + SAFE_FREE(folder_path); + SAFE_FREE(folder_name); + media_content_error("[ERROR] media_folder_get_media_count_from_db is failed"); + return false; + } + + if(media_folder_foreach_media_from_db(folder_id, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) + { + SAFE_FREE(folder_id); + SAFE_FREE(folder_path); + SAFE_FREE(folder_name); + media_content_error("[ERROR] media_folder_foreach_media_from_db is failed"); + return false; + } + + SAFE_FREE(folder_id); + SAFE_FREE(folder_path); + SAFE_FREE(folder_name); + + ret = true; + } + else + { + ret = false; + } + + return ret; +} + +bool test_album_from_db(int album_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_album_h album_h; + int test_album_id = 0; + char *album_name = NULL; + char *artist = NULL; + + ret = media_album_get_album_from_db(album_id, &album_h); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("error when get album"); + return false; + } + + if(media_album_get_album_id(album_h, &test_album_id) != MEDIA_CONTENT_ERROR_NONE) + { + media_album_destroy(album_h); + return false; + } + + media_content_debug("test_album_id : [%d]", test_album_id); + + if(media_album_get_name(album_h, &album_name) != MEDIA_CONTENT_ERROR_NONE) + { + media_album_destroy(album_h); + return false; + } + + media_content_debug("album_name : [%s]", album_name); + + if(media_album_get_artist(album_h, &artist) != MEDIA_CONTENT_ERROR_NONE) + { + media_album_destroy(album_h); + return false; + } + + media_content_debug("artist : [%s]", artist); + + SAFE_FREE(album_name); + SAFE_FREE(artist); + + media_album_destroy(album_h); + + return true; +} + +bool playlist_list_cb(media_playlist_h playlist, void *user_data) +{ + int playlist_id = 0; + char *playlist_name = NULL; + media_playlist_h playlist_h; + char *playlist_thumbnail_path = NULL; + + media_content_debug("playlist_list_cb ======"); + + GList **list = (GList**)user_data; + + if(playlist == NULL) + { + media_content_debug(" playlist handle is NULL"); + return false; + } + + media_playlist_get_playlist_id(playlist, &playlist_id); + media_content_debug("playlist_id : %d", playlist_id); + + if(user_data != NULL) + *list = g_list_append(*list, (gpointer)playlist_id); + + media_playlist_get_name(playlist, &playlist_name); + media_content_debug("playlist_name : %s", playlist_name); + SAFE_FREE(playlist_name); + + media_playlist_get_thumbnail_path(playlist, &playlist_thumbnail_path); + media_content_debug("playlist_thumbnail_path : %s", playlist_thumbnail_path); + SAFE_FREE(playlist_thumbnail_path); + + media_playlist_get_playlist_from_db(playlist_id, &playlist_h); + + media_playlist_destroy(playlist_h); + + return true; +} + +bool tag_list_cb(media_tag_h tag, void *user_data) +{ + int tag_id = 0; + char *tag_name = NULL; + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(tag == NULL) + { + media_content_debug(" tag handle is NULL"); + return false; + } + + ret = media_tag_get_tag_id(tag, &tag_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_tag_id : [%d]", ret); + else + media_content_debug("tag_id : %d", tag_id); + + ret = media_tag_get_name(tag, &tag_name); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_name : [%d]", ret); + else + media_content_debug("tag_name : %s", tag_name); + SAFE_FREE(tag_name); + + return true; +} + +bool bookmarks_cb(media_bookmark_h bookmark, void *user_data) +{ + media_bookmark_h *_bookmark = (media_bookmark_h*)bookmark; + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(_bookmark != NULL) + { + char *name = NULL; + time_t time = 0; + int bookmark_id = 0; + + ret = media_bookmark_get_bookmark_id(bookmark, &bookmark_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_get_bookmark_id : [%d]", ret); + else + media_content_debug("bookmark_id : %d", bookmark_id); + + ret = media_bookmark_get_thumbnail_path(bookmark, &name); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_get_thumbnail_path : [%d]", ret); + else + media_content_debug("bookmark thumbnail_path : %s", name); + SAFE_FREE(name); + + ret = media_bookmark_get_marked_time(bookmark, &time); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_get_marked_time : [%d]", ret); + else + media_content_debug("bookmark marked_time : %d", time); + } + + return true; +} + +bool album_list_cb(media_album_h album, void *user_data) +{ + int album_id = 0; + char *album_name = NULL; + char *artist = NULL; + char *album_art = NULL; + int media_count = 0; + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_h filter = NULL; + + /*Set Filter*/ + char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to create filter"); + return ret; + } + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set condition"); + return ret; + } + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_NOCASE); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set order"); + return ret; + } + + if(album != NULL) + { + if(media_album_get_album_id(album, &album_id) != MEDIA_CONTENT_ERROR_NONE) + { + media_filter_destroy(filter); + return false; + } + + media_content_debug("album_id : [%d]", album_id); + + if(media_album_get_name(album, &album_name) != MEDIA_CONTENT_ERROR_NONE) + { + media_filter_destroy(filter); + return false; + } + + media_content_debug("album_name : [%s]", album_name); + + if(media_album_get_artist(album, &artist) != MEDIA_CONTENT_ERROR_NONE) + { + media_filter_destroy(filter); + return false; + } + + media_content_debug("artist : [%s]", artist); + + if(media_album_get_album_art(album, &album_art) != MEDIA_CONTENT_ERROR_NONE) + { + media_filter_destroy(filter); + return false; + } + + media_content_debug("album_art : [%s]", album_art); + + SAFE_FREE(album_name); + SAFE_FREE(artist); + SAFE_FREE(album_art); + + if(media_album_get_media_count_from_db(album_id, filter, &media_count) != MEDIA_CONTENT_ERROR_NONE) + { + media_filter_destroy(filter); + return false; + } + + media_content_debug("media_count : [%d]", media_count); + + if(media_album_foreach_media_from_db(album_id, filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) + { + media_filter_destroy(filter); + return false; + } + + test_album_from_db(album_id); + } + else + { + media_content_error("album item not Found!!"); + } + + media_filter_destroy(filter); + + return true; +} + +bool group_list_cb(const char *group_name, void *user_data) +{ + int media_count = 0; + int *idx = user_data; + + media_content_debug("group item : [%s] [%d]", group_name, *idx); + + if(media_group_get_media_count_from_db(group_name, *idx, g_filter, &media_count) != MEDIA_CONTENT_ERROR_NONE) + return false; + + media_content_debug("media_count : [%d]", media_count); + + if(media_group_foreach_media_from_db(group_name, *idx, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE) + return false; + + return true; +} + +bool playlist_item_cb(int playlist_member_id, media_info_h media, void *user_data) +{ + media_content_debug("playlist_member_id : [%d]", playlist_member_id); + + GList **list = (GList**)user_data; + *list = g_list_append(*list, (gpointer)playlist_member_id); + + //media_item_cb(media, user_data); + + return true; +} + +int test_filter_create(void) +{ + media_content_debug("\n============Filter Create============\n\n"); + + int ret = MEDIA_CONTENT_ERROR_NONE; + + /* Filter for media */ + char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + //char *condition = "MEDIA_TYPE IS NOT 0 AND MEDIA_DESCRIPTION IS NOT NULL"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + + ret = media_filter_create(&g_filter); + + /* Set condition and collate + * Condition string : You can make where statement of sql. + * Colation : You can use collation when comparing. + * Ex) In case of FILE_NAME='Samsung' as condition string, + * if you want to compare with NOCASE collation, + * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_NOCASE); + * if you want to compare in case-sensitive, + * call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + */ + ret = media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + + /* Collation of ordering + * If you want to get list, which is sorted by NOCASE, + * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_NOCASE); + * Or, + * call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT); + */ + /* Able to set multi column to set order */ + //ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, "MEDIA_MODIFIED_TIME, MEDIA_DISPLAY_NAME", MEDIA_CONTENT_COLLATE_DEFAULT); + ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT); + //ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TRACK_NUM_INT, MEDIA_CONTENT_COLLATE_DEFAULT); + + /* Filter for group */ + char *g_condition = "TAG_NAME like \"\%my\%\""; + //char *g_condition = "BOOKMARK_MARKED_TIME > 300"; + + ret = media_filter_create(&g_filter_g); + + ret = media_filter_set_condition(g_filter_g, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT); + ret = media_filter_set_order(g_filter_g, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT); + + return ret; +} + +int test_filter_destroy(void) +{ + media_content_debug("\n============Filter Create============\n\n"); + + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = media_filter_destroy(g_filter); + + return ret; +} + +int test_connect_database(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_content_debug("\n============DB Connection Test============\n\n"); + + ret = media_content_connect(); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + { + media_content_debug("connection is success\n\n"); + } + else + media_content_error("connection is failed\n\n"); + + return ret; +} + +int test_gallery_scenario(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + int i; + filter_h filter = NULL; + + int count; + GList *folder_list = NULL; + media_folder_h folder_handle = NULL; + + /* First, Get folder list */ + ret = media_folder_foreach_folder_from_db(filter, gallery_folder_list_cb, &folder_list); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_folder_foreach_folder_from_db failed: %d", ret); + return -1; + } else { + media_content_debug("media_folder_foreach_folder_from_db success!!"); + char *folder_id = NULL; + char *folder_name = NULL; + char *folder_path = NULL; + + for(i = 0; i < g_list_length(folder_list); i++) { + folder_handle = (media_folder_h)g_list_nth_data(folder_list, i); + + ret = media_folder_get_folder_id(folder_handle, &folder_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_folder_get_folder_id failed: %d", ret); + ret = media_folder_get_name(folder_handle, &folder_name); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_folder_get_name failed: %d", ret); + ret = media_folder_get_path(folder_handle, &folder_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_folder_get_path failed: %d", ret); + + media_content_debug("folder_id [%d] : %s", i, folder_id); + media_content_debug("folder_name [%d] : %s", i, folder_name); + media_content_debug("folder_path [%d] : %s", i, folder_path); + + + ret = media_folder_get_media_count_from_db(folder_id, filter, &count); + /* User should free these string */ + SAFE_FREE(folder_id); + SAFE_FREE(folder_name); + SAFE_FREE(folder_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_folder_get_media_count_from_db failed: %d", ret); + return -1; + } else { + media_content_debug("media count [%d] : %d", i, count); + } + } + } + + /* To check performance */ + struct timeval start, end; + gettimeofday(&start, NULL); + + /* Second, Get all item list */ + media_info_h media_handle = NULL; + GList *all_item_list = NULL; + + media_content_collation_e collate_type = MEDIA_CONTENT_COLLATE_NOCASE; + media_content_order_e order_type = MEDIA_CONTENT_ORDER_DESC; + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to create filter"); + return ret; + } + ret = media_filter_set_condition(filter, "MEDIA_TYPE = 0", collate_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set condition"); + return ret; + } + ret = media_filter_set_order(filter, order_type, MEDIA_DISPLAY_NAME, collate_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set order"); + return ret; + } + + ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_foreach_media_from_db failed: %d", ret); + media_filter_destroy(filter); + return -1; + } else { + media_content_debug("media_info_foreach_media_from_db success"); + media_content_type_e media_type; + char *media_id = NULL; + char *media_name = NULL; + char *media_path = NULL; + + for(i = 0; i < g_list_length(all_item_list); i++) { + media_handle = (media_info_h)g_list_nth_data(all_item_list, i); + + ret = media_info_get_media_id(media_handle, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_id failed: %d", ret); + ret = media_info_get_media_type(media_handle, &media_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_type failed: %d", ret); + ret = media_info_get_display_name(media_handle, &media_name); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_display_name failed: %d", ret); + ret = media_info_get_file_path(media_handle, &media_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_file_path failed: %d", ret); + + if(media_type == MEDIA_CONTENT_TYPE_IMAGE) { + image_meta_h image_handle; + int width = 0, height = 0; + media_content_orientation_e orientation = 0; + char *datetaken = NULL; + char *burst_id = NULL; + + ret = media_info_get_image(media_handle, &image_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_get_image failed: %d", ret); + } else { + ret = image_meta_get_width(image_handle, &width); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_width : [%d]", ret); + ret = image_meta_get_height(image_handle, &height); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_height : [%d]", ret); + ret = image_meta_get_orientation(image_handle, &orientation); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_orientation : [%d]", ret); + ret = image_meta_get_date_taken(image_handle, &datetaken); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_date_taken : [%d]", ret); + ret = image_meta_get_burst_id(image_handle, &burst_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_burst_id : [%d]", ret); + + media_content_debug("This is Image"); + media_content_debug("Width : %d, Height : %d, Orientation : %d, Date taken : %s", width, height, orientation, datetaken); + } + + SAFE_FREE(datetaken); + SAFE_FREE(burst_id); + ret = image_meta_destroy(image_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_destroy : [%d]", ret); + + } else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) { + video_meta_h video_handle; + char *title = NULL, *artist = NULL, *album = NULL, *album_artist = NULL; + int duration = 0; + time_t time_played = 0; + + ret = media_info_get_video(media_handle, &video_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_get_video failed: %d", ret); + } else { + ret = video_meta_get_title(video_handle, &title); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_title : [%d]", ret); + ret = video_meta_get_artist(video_handle, &artist); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_artist : [%d]", ret); + ret = video_meta_get_album(video_handle, &album); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_album : [%d]", ret); + ret = video_meta_get_album_artist(video_handle, &album_artist); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_album_artist : [%d]", ret); + ret = video_meta_get_duration(video_handle, &duration); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_duration : [%d]", ret); + ret = video_meta_get_played_time(video_handle, &time_played); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_played_time : [%d]", ret); + + media_content_debug("This is Video"); + media_content_debug("Title: %s, Album: %s, Artist: %s, Album_artist: %s \n Duration: %d, Played time: %d", title, album, artist, album_artist, duration, time_played); + } + + SAFE_FREE(title); + SAFE_FREE(artist); + SAFE_FREE(album); + SAFE_FREE(album_artist); + + ret = video_meta_destroy(video_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_destroy : [%d]", ret); + } + //media_content_debug("media_id [%d] : %s", i, media_id); + //media_content_debug("media_name [%d] : %s", i, media_name); + //media_content_debug("media_path [%d] : %s", i, media_path); + + SAFE_FREE(media_id); + SAFE_FREE(media_name); + SAFE_FREE(media_path); + } + } + + media_filter_destroy(filter); + filter = NULL; + + /* To check performance */ + gettimeofday(&end, NULL); + long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec); + printf("Time : %ld\n", time); + + /* Third, Get item list of a folder */ + GList *item_list = NULL; + + for(i = 0; i < g_list_length(folder_list); i++) { + int j = 0; + char *folder_id = NULL; + char *folder_name = NULL; + folder_handle = (media_folder_h)g_list_nth_data(folder_list, i); + + media_folder_get_folder_id(folder_handle, &folder_id); + media_folder_get_name(folder_handle, &folder_name); + + ret = media_folder_foreach_media_from_db(folder_id, filter, gallery_media_item_cb, &item_list); + SAFE_FREE(folder_id); + SAFE_FREE(folder_name); + + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_folder_foreach_media_from_db failed: %d", ret); + return -1; + } else { + media_content_error("media_folder_foreach_media_from_db success!", ret); + char *media_id = NULL; + char *media_name = NULL; + char *media_path = NULL; + media_content_type_e media_type = 0; + + for(j = 0; j < g_list_length(item_list); j++) { + media_handle = (media_info_h)g_list_nth_data(item_list, j); + + ret = media_info_get_media_id(media_handle, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_id failed: %d", ret); + ret = media_info_get_display_name(media_handle, &media_name); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_display_name failed: %d", ret); + ret = media_info_get_file_path(media_handle, &media_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_file_path failed: %d", ret); + ret = media_info_get_media_type(media_handle, &media_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_type failed: %d", ret); + + media_content_debug("[%s] media_id [%d] : %s", folder_name, j, media_id); + media_content_debug("[%s] media_type [%d] : %d", folder_name, j, media_type); + media_content_debug("[%s] media_name [%d] : %s", folder_name, j, media_name); + media_content_debug("[%s] media_path [%d] : %s", folder_name, j, media_path); + + if(media_type == MEDIA_CONTENT_TYPE_IMAGE) { + image_meta_h image_handle; + int width = 0, height = 0; + media_content_orientation_e orientation = 0; + char *datetaken = NULL; + + ret = media_info_get_image(media_handle, &image_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_get_image failed: %d", ret); + } else { + ret = image_meta_get_width(image_handle, &width); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_width : [%d]", ret); + ret = image_meta_get_height(image_handle, &height); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_height : [%d]", ret); + ret = image_meta_get_orientation(image_handle, &orientation); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_orientation : [%d]", ret); + ret = image_meta_get_date_taken(image_handle, &datetaken); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_get_date_taken : [%d]", ret); + + media_content_debug("This is Image"); + media_content_debug("Width : %d, Height : %d, Orientation : %d, Date taken : %s", width, height, orientation, datetaken); + } + + SAFE_FREE(datetaken); + ret = image_meta_destroy(image_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error image_meta_destroy : [%d]", ret); + + } else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) { + video_meta_h video_handle; + char *title = NULL, *artist = NULL, *album = NULL, *album_artist = NULL;; + int duration = 0; + time_t time_played; + + ret = media_info_get_video(media_handle, &video_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_get_video failed: %d", ret); + } else { + ret = video_meta_get_title(video_handle, &title); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_title : [%d]", ret); + ret = video_meta_get_artist(video_handle, &artist); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_artist : [%d]", ret); + ret = video_meta_get_album(video_handle, &album); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_album : [%d]", ret); + ret = video_meta_get_album_artist(video_handle, &album_artist); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_album_artist : [%d]", ret); + ret = video_meta_get_duration(video_handle, &duration); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_duration : [%d]", ret); + ret = video_meta_get_played_time(video_handle, &time_played); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_get_played_time : [%d]", ret); + + media_content_debug("This is Video"); + media_content_debug("Title: %s, Album: %s, Artist: %s, Album_artist: %s \n Duration: %d, Played time: %d\n", title, album, artist, album_artist, duration, time_played); + } + + SAFE_FREE(title); + SAFE_FREE(artist); + SAFE_FREE(album); + SAFE_FREE(album_artist); + + ret = video_meta_destroy(video_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error video_meta_destroy : [%d]", ret); + + /* Get bookmar list in case of video */ + media_bookmark_h bm_handle; + GList *bm_list = NULL; + + ret = media_info_foreach_bookmark_from_db(media_id, filter, gallery_bookmarks_cb, &bm_list); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_foreach_bookmark_from_db failed: %d", ret); + } else { + media_content_debug("media_info_foreach_bookmark_from_db success"); + + int k = 0; + + for(k = 0; k < g_list_length(bm_list); k++) { + bm_handle = (media_bookmark_h)g_list_nth_data(bm_list, k); + time_t marked_time; + char *thumb_path = NULL; + + ret = media_bookmark_get_marked_time(bm_handle, &marked_time); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_get_marked_time : [%d]", ret); + ret = media_bookmark_get_thumbnail_path(bm_handle, &thumb_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_get_thumbnail_path : [%d]", ret); + + media_content_debug("Bookmark time : %d\nBookmar thumb: %s", marked_time, thumb_path); + SAFE_FREE(thumb_path); + } + + /* Remove bookmark list */ + int l = 0; + if(bm_list) { + for(l = 0; l < g_list_length(bm_list); l++) { + bm_handle = (media_bookmark_h)g_list_nth_data(bm_list, l); + ret = media_bookmark_destroy(bm_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_destroy : [%d]", ret); + } + + g_list_free(bm_list); + } + + } + } + + SAFE_FREE(media_id); + SAFE_FREE(media_name); + SAFE_FREE(media_path); + } + } + } + + /* Get tag list */ + media_tag_h tag_handle = NULL; + GList *tag_list = NULL; + GList *media_list_in_tag = NULL; + + ret = media_tag_foreach_tag_from_db (filter, gallery_tag_item_cb, &tag_list); + + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_tag_foreach_tag_from_db failed: %d", ret); + return -1; + } else { + media_content_error("media_tag_foreach_tag_from_db success"); + char *tag_name = NULL; + int tag_id; + + for(i = 0; i < g_list_length(tag_list); i++) { + tag_handle = (media_tag_h)g_list_nth_data(tag_list, i); + media_tag_get_tag_id(tag_handle, &tag_id); + media_tag_get_name(tag_handle, &tag_name); + + printf("[%d] %s", tag_id, tag_name); + + ret = media_tag_foreach_media_from_db(tag_id, filter, gallery_media_item_cb, &media_list_in_tag); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_tag_foreach_media_from_db failed: %d", ret); + return -1; + } else { + media_content_error("media_tag_foreach_media_from_db success"); + int j = 0; + media_info_h tag_media_handle; + char *media_id = NULL; + char *media_name = NULL; + char *media_path = NULL; + media_content_type_e media_type = 0; + + for(j = 0; j < g_list_length(media_list_in_tag); j++) { + tag_media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, j); + ret = media_info_get_media_id(tag_media_handle, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_id failed: %d", ret); + ret = media_info_get_display_name(tag_media_handle, &media_name); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_display_name failed: %d", ret); + ret = media_info_get_file_path(tag_media_handle, &media_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_file_path failed: %d", ret); + ret = media_info_get_media_type(tag_media_handle, &media_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_type failed: %d", ret); + + media_content_debug("[%s] media_id [%d] : %s", tag_name, j, media_id); + media_content_debug("[%s] media_type [%d] : %d", tag_name, j, media_type); + media_content_debug("[%s] media_name [%d] : %s", tag_name, j, media_name); + media_content_debug("[%s] media_path [%d] : %s", tag_name, j, media_path); + } + SAFE_FREE(media_id); + SAFE_FREE(media_name); + SAFE_FREE(media_path); + } + SAFE_FREE(tag_name); + } + } + + /* Remove folder list */ + if(folder_list) { + for(i = 0; i < g_list_length(folder_list); i++) { + folder_handle = (media_folder_h)g_list_nth_data(folder_list, i); + media_folder_destroy(folder_handle); + } + + g_list_free(folder_list); + } + + /* Remove all items list */ + if(all_item_list) { + for(i = 0; i < g_list_length(all_item_list); i++) { + media_handle = (media_info_h)g_list_nth_data(all_item_list, i); + ret = media_info_destroy(media_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_destroy failed: %d", ret); + } + + g_list_free(all_item_list); + } + + /* Remove items list */ + if(item_list) { + for(i = 0; i < g_list_length(item_list); i++) { + media_handle = (media_info_h)g_list_nth_data(item_list, i); + ret = media_info_destroy(media_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_destroy failed: %d", ret); + } + + g_list_free(item_list); + } + + /* Remove tag list */ + if(tag_list) { + for(i = 0; i < g_list_length(tag_list); i++) { + tag_handle = (media_tag_h)g_list_nth_data(tag_list, i); + ret = media_tag_destroy(tag_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_destroy : [%d]", ret); + } + + g_list_free(tag_list); + } + + /* Remove media list in a tag */ + if(media_list_in_tag) { + for(i = 0; i < g_list_length(media_list_in_tag); i++) { + media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, i); + ret = media_info_destroy(media_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_destroy failed: %d", ret); + } + + g_list_free(media_list_in_tag); + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +/*Get All Music file. sort by Title and not case sensitive*/ +int test_get_all_music_files(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + int media_count = 0; + filter_h filter; + + /*Set Filter*/ + char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/ + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to create filter"); + return ret; + } + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_LOCALIZED); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set condition"); + return ret; + } + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_LOCALIZED); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set order"); + return ret; + } + + /*Get Media Count*/ + ret = media_info_get_media_count_from_db(filter, &media_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to get media count"); + return ret; + } + + media_content_debug("media_count : [%d]", media_count); + + ret = media_info_foreach_media_from_db(filter, media_item_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to get media"); + return ret; + } + + ret = media_filter_destroy(filter); + + return ret; +} + +int test_media_info_operation(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + int media_count = 0; + + media_content_debug("\n============Media info Test============\n\n"); + + test_filter_create(); + + ret = media_info_get_media_count_from_db(g_filter, &media_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_count_from_db failed: %d", ret); + else + media_content_debug("media_count : [%d]", media_count); + + ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL); + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_info_foreach_media_from_db is success"); + else + media_content_error("media_info_foreach_media_from_db is failed"); + + test_filter_destroy(); + + return ret; +} + +int test_media_info_operation_2(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + int bookmark_count = 0; + + media_content_debug("\n============Media info Test 2============\n\n"); + + test_filter_create(); + +#if 0 + /* Bookmark */ + char *thumbnail_path1 = "/opt/media/Images and videos/My video clips/teat11.jpg"; + media_bookmark_insert_to_db(test_video_id, 100, thumbnail_path1); + media_bookmark_insert_to_db(test_video_id, 200, thumbnail_path1); + + media_info_get_bookmark_count_from_db(test_video_id, g_filter_g, &bookmark_count); + + media_content_debug("bookmark_count : [%d]", bookmark_count); + + ret = media_info_foreach_bookmark_from_db(test_video_id, g_filter_g, bookmarks_cb, NULL); +#endif + + /* Tag */ + ret = media_info_get_tag_count_from_db(test_audio_id, g_filter_g, &bookmark_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_tag_count_from_db failed: %d", ret); + else + media_content_debug("tag_count : [%d]", bookmark_count); + + ret = media_info_foreach_tag_from_db(test_audio_id, g_filter_g, tag_list_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_foreach_tag_from_db failed: %d", ret); + + test_filter_destroy(); + + return ret; +} + +int test_folder_operation(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_h filter; + media_folder_h folder = NULL; + char *folder_id = NULL; + int folder_count = 0; + + media_content_debug("\n============Folder Test============\n\n"); + + test_filter_create(); + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("[ERROR] media_folder_filter_create is failed"); + return ret; + } + + media_filter_set_condition(filter, "(MEDIA_TYPE = 0 or MEDIA_TYPE = 1) and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + media_filter_set_offset(filter, 0,5); + media_filter_set_order(filter,MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE); + + ret = media_folder_get_folder_count_from_db(filter, &folder_count); + media_content_debug("Folder count : %d", folder_count); + + ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder); + + //test.3 get the media list in first folder + filter_h m_filter = NULL; + ret = media_filter_create(&m_filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + test_filter_destroy(); + media_filter_destroy(filter); + media_content_error("[ERROR] media_info_filter_create is failed"); + return ret; + } + + media_filter_set_condition(m_filter, "MEDIA_TYPE=1 and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + media_filter_set_offset(m_filter, 0,5); + media_filter_set_order(m_filter,MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE); + + media_folder_get_folder_id(folder, &folder_id); + media_content_debug("folder_id : %s", folder_id); + + ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL); + + if(ret != MEDIA_CONTENT_ERROR_NONE) + { + media_content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d", ret); + } + + media_filter_destroy(filter); + media_filter_destroy(m_filter); + + test_filter_destroy(); + + return ret; +} + +bool folder_update_cb(media_folder_h folder, void *user_data) +{ + char *folder_id = NULL; + char *folder_path = NULL; + char *folder_name = NULL; + bool ret = true; + + if(folder != NULL) + { + ret = media_folder_get_folder_id(folder, &folder_id); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + media_content_debug("folder_id = [%s]", folder_id); + SAFE_FREE(folder_id); + + ret = media_folder_get_path(folder, &folder_path); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + media_content_debug("folder_path = [%s]", folder_path); + SAFE_FREE(folder_path); + + ret = media_folder_get_name(folder, &folder_name); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + media_content_debug("folder_name = [%s]", folder_name); + SAFE_FREE(folder_name); + + ret = media_folder_clone(&g_folder, folder); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = true; + } + else + { + ret = false; + } + + return ret; +} + + +int test_folder_update(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + filter_h filter; + int folder_count = 0; + + media_content_debug("\n============Folder Update Test============\n\n"); + + ret = media_filter_create(&filter); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + media_filter_set_condition(filter, "MEDIA_TYPE=0 and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + + ret = media_folder_get_folder_count_from_db(filter, &folder_count); + + media_content_debug("Folder count : %d", folder_count); + + ret = media_folder_foreach_folder_from_db(filter, folder_update_cb, NULL); + + media_filter_destroy(filter); + + ret = media_folder_set_name(g_folder, "test_folder"); + + ret = media_folder_update_to_db(g_folder); + + ret = media_folder_destroy(g_folder); + + return ret; +} + +int test_playlist_operation(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_playlist_h playlist_1 = NULL; + media_playlist_h playlist_2 = NULL; + media_playlist_h playlist_3 = NULL; + int playlist_id_1 = 0; + int playlist_id_2 = 0; + int playlist_id_3 = 0; + char *playlist_name_1 = "myPlaylist_1"; + char *playlist_name_2 = "myPlaylist_2"; + char *playlist_name_3 = "myPlaylist_3"; + int playlist_count = 0; + int media_count = 0; + int order_1 = 0; + int order_2 = 0; + int order_3 = 0; + int order_4 = 0; + int order_5 = 0; + filter_h filter = NULL; + filter_h m_filter = NULL; + + media_content_debug("\n============Playlist Test============\n\n"); + + /* Filter for playlist */ + + char *condition = "(MEDIA_TYPE=1 or MEDIA_TYPE=3)"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/ + + ret = media_filter_create(&filter); + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_NOCASE); + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_NAME, MEDIA_CONTENT_COLLATE_NOCASE); + + /* Create Playlist */ + media_playlist_insert_to_db(playlist_name_1, &playlist_1); + media_playlist_insert_to_db(playlist_name_2, &playlist_2); + media_playlist_insert_to_db(playlist_name_3, &playlist_3); + + if(playlist_1 != NULL) + { + /* Add media to Playlist */ + media_playlist_add_media(playlist_1, test_audio_id); + media_playlist_add_media(playlist_1, test_audio_id); + media_playlist_add_media(playlist_1, test_video_id); + + #if 0 + char *playlist_thumb_path = "/opt/usr/media/Images/Default.jpg"; + media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path); + #endif + + media_playlist_update_to_db(playlist_1); + } + + if(playlist_2 != NULL) + { + media_playlist_add_media(playlist_2, test_audio_id); + media_playlist_add_media(playlist_2, test_audio_id); + media_playlist_update_to_db(playlist_2); + } + + /* Get Playlist Count*/ + ret = media_playlist_get_playlist_count_from_db(filter, &playlist_count); + if (ret == 0) + media_content_debug("playlist_count [%d]", playlist_count); + + /* Get Playlist*/ + GList *playlist_id_list = NULL; + media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, &playlist_id_list); + + /* Get Playlist id*/ + playlist_id_1 = (int)g_list_nth_data(playlist_id_list, 0); + playlist_id_2 = (int)g_list_nth_data(playlist_id_list, 1); + playlist_id_3 = (int)g_list_nth_data(playlist_id_list, 2); + media_content_debug("playlist_id_1 [%d]", playlist_id_1); + media_content_debug("playlist_id_2 [%d]", playlist_id_2); + media_content_debug("playlist_id_3 [%d]", playlist_id_3); + + /* Filter for media*/ + ret = media_filter_create(&m_filter); + + ret = media_filter_set_condition(m_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + + ret = media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_MEMBER_ORDER, MEDIA_CONTENT_COLLATE_DEFAULT); + + /* Get media count */ + media_playlist_get_media_count_from_db(playlist_id_1, m_filter, &media_count); + media_content_debug("playlist_1_media_count [%d]", media_count); + + media_playlist_get_media_count_from_db(playlist_id_2, m_filter, &media_count); + media_content_debug("playlist_2_media_count [%d]", media_count); + + media_playlist_get_media_count_from_db(playlist_id_3, m_filter, &media_count); + media_content_debug("playlist_3_media_count [%d]", media_count); + + /* Get media of playlist */ + GList *playlist_member_id_list = NULL; + GList *playlist_member_id_list_1 = NULL; + + media_playlist_foreach_media_from_db(playlist_id_1, m_filter, playlist_item_cb, &playlist_member_id_list); + media_playlist_foreach_media_from_db(playlist_id_2, m_filter, playlist_item_cb, &playlist_member_id_list_1); + + int playlist_member_id_1_1 =0; + int playlist_member_id_1_2 =0; + int playlist_member_id_1_3 =0; + int playlist_member_id_2_1 =0; + int playlist_member_id_2_2 =0; + + playlist_member_id_1_1 = (int)g_list_nth_data(playlist_member_id_list, 0); + playlist_member_id_1_2 = (int)g_list_nth_data(playlist_member_id_list, 1); + playlist_member_id_1_3 = (int)g_list_nth_data(playlist_member_id_list, 2); + playlist_member_id_2_1 = (int)g_list_nth_data(playlist_member_id_list_1, 0); + playlist_member_id_2_2 = (int)g_list_nth_data(playlist_member_id_list_1, 1); + + media_content_debug("playlist_member_id_1_1 [%d]", playlist_member_id_1_1); + media_content_debug("playlist_member_id_1_2 [%d]", playlist_member_id_1_2); + media_content_debug("playlist_member_id_1_3 [%d]", playlist_member_id_1_3); + media_content_debug("playlist_member_id_2_1 [%d]", playlist_member_id_2_1); + media_content_debug("playlist_member_id_2_2 [%d]", playlist_member_id_2_2); + + media_playlist_get_play_order(playlist_1, playlist_member_id_1_1, &order_1); + media_playlist_get_play_order(playlist_1, playlist_member_id_1_2, &order_2); + media_playlist_get_play_order(playlist_1, playlist_member_id_1_3, &order_3); + media_playlist_get_play_order(playlist_2, playlist_member_id_2_1, &order_4); + media_playlist_get_play_order(playlist_2, playlist_member_id_2_2, &order_5); + media_content_debug("order_1 [%d] order_2 [%d] order_3 [%d] order_4 [%d] order_5 [%d]", order_1, order_2, order_3, order_4, order_5); + + /* Update Playlist */ + media_playlist_remove_media(playlist_2, playlist_member_id_2_1); + media_playlist_add_media(playlist_2, test_video_id); + media_playlist_set_name(playlist_2, "test_playlist"); + media_playlist_set_play_order(playlist_2, playlist_member_id_2_2, order_5+100); + media_playlist_update_to_db(playlist_2); + + /* Get Updated Playlist*/ + media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, NULL); + + /* deletes the playlist */ + //media_playlist_delete_from_db(playlist_id_1); + //media_playlist_delete_from_db(playlist_id_2); + + if(playlist_1 != NULL) + media_playlist_destroy(playlist_1); + if(playlist_2 != NULL) + media_playlist_destroy(playlist_2); + if(playlist_3 != NULL) + media_playlist_destroy(playlist_3); + + g_list_free(playlist_id_list); + g_list_free(playlist_member_id_list); + g_list_free(playlist_member_id_list_1); + + if(filter != NULL) + ret = media_filter_destroy(filter); + if(m_filter != NULL) + ret = media_filter_destroy(m_filter); + + return ret; +} + +int test_tag_operation(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_h tag_1; + media_tag_h tag_2; + media_tag_h tag_3; + int tag_id_1 = 0; + int tag_id_2 = 0; + int tag_id_3 = 0; + char *tag_name_1 = "myTag_1"; + char *tag_name_2 = "myTag_2"; + char *tag_name_3 = "myTag_3"; + int tag_count = 0; + int media_count = 0; + filter_h filter; + + media_content_debug("\n============Tag Test============\n\n"); + + char *g_condition = "TAG_NAME like \"%%my%%\""; + + ret = media_filter_create(&filter); + + ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT); + + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT); + + /* Create Tag */ + ret = media_tag_insert_to_db(tag_name_1, &tag_1); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_insert_to_db : [%d]", ret); + ret = media_tag_insert_to_db(tag_name_2, &tag_2); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_insert_to_db : [%d]", ret); + ret = media_tag_insert_to_db(tag_name_3, &tag_3); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_insert_to_db : [%d]", ret); + + /* Add media to Tag */ + ret = media_tag_add_media(tag_1, test_audio_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_add_media : [%d]", ret); + ret = media_tag_add_media(tag_1, test_video_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_add_media : [%d]", ret); + ret = media_tag_update_to_db(tag_1); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_update_to_db : [%d]", ret); + + ret = media_tag_add_media(tag_2, test_audio_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_add_media : [%d]", ret); + ret = media_tag_update_to_db(tag_2); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_update_to_db : [%d]", ret); + + /* Get Tag Count*/ + ret = media_tag_get_tag_count_from_db(filter, &tag_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_tag_count_from_db : [%d]", ret); + else + media_content_debug("tag_count [%d]", tag_count); + + /* Get Tag*/ + ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_foreach_tag_from_db : [%d]", ret); + + /* Get Tag id*/ + ret = media_tag_get_tag_id(tag_1, &tag_id_1); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_tag_id : [%d]", ret); + else + media_content_debug("tag_id_1 [%d]", tag_id_1); + + ret = media_tag_get_tag_id(tag_2, &tag_id_2); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_tag_id : [%d]", ret); + else + media_content_debug("tag_id_2 [%d]", tag_id_2); + + ret = media_tag_get_tag_id(tag_3, &tag_id_3); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_tag_id : [%d]", ret); + else + media_content_debug("tag_id_3 [%d]", tag_id_3); + + /* Get media count */ + ret = media_tag_get_media_count_from_db(tag_id_1, NULL, &media_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_media_count_from_db : [%d]", ret); + else + media_content_debug("tag_1_media_count [%d]", media_count); + + ret = media_tag_get_media_count_from_db(tag_id_2, NULL, &media_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_media_count_from_db : [%d]", ret); + else + media_content_debug("tag_2_media_count [%d]", media_count); + + /* Get media of Tag */ + ret = media_tag_foreach_media_from_db(tag_id_1, NULL, media_item_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_foreach_media_from_db : [%d]", ret); + + ret = media_tag_foreach_media_from_db(tag_id_2, NULL, media_item_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_foreach_media_from_db : [%d]", ret); + + /* Update Tag */ + ret = media_tag_add_media(tag_2, test_video_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_add_media : [%d]", ret); + ret = media_tag_set_name(tag_2, "test_tag"); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_set_name : [%d]", ret); + ret = media_tag_update_to_db(tag_2); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_update_to_db : [%d]", ret); + + /* Get Updated Tag*/ + ret = media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_foreach_tag_from_db : [%d]", ret); + + /* deletes the tag */ + ret = media_tag_delete_from_db(tag_id_1); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_delete_from_db : [%d]", ret); + ret = media_tag_delete_from_db(tag_id_2); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_delete_from_db : [%d]", ret); + + ret = media_tag_destroy(tag_1); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_destroy : [%d]", ret); + ret = media_tag_destroy(tag_2); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_destroy : [%d]", ret); + ret = media_filter_destroy(filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_filter_destroy : [%d]", ret); + + return ret; +} + + +int test_bookmark_operation(void) +{ + //bookmark is only supported for video information. + int ret = MEDIA_CONTENT_ERROR_NONE; + int bookmark_count = 0; + filter_h filter; + + media_content_debug("\n============Bookmark Test============\n\n"); + + char *g_condition = "BOOKMARK_MARKED_TIME > 300"; + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_filter_create : [%d]", ret); + + ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_filter_set_condition : [%d]", ret); + + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, BOOKMARK_MARKED_TIME, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_filter_set_order : [%d]", ret); + + //insert bookmark to video + char *thumbnail_path1 = "/opt/usr/media/Images and videos/My video clips/teat11.jpg"; + ret = media_bookmark_insert_to_db(test_video_id, 400, thumbnail_path1); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_insert_to_db : [%d]", ret); + + ret = media_bookmark_insert_to_db(test_video_id, 600, thumbnail_path1); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_insert_to_db : [%d]", ret); + + ret = media_bookmark_get_bookmark_count_from_db(filter, &bookmark_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_bookmark_get_bookmark_count_from_db : [%d]", ret); + else + media_content_debug("bookmark_count = [%d]", bookmark_count); + + ret = media_filter_destroy(filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_filter_destroy : [%d]", ret); + + return ret; +} + +int test_album_list(void) +{ + media_content_debug("\n============Album Test============\n\n"); + + int ret = MEDIA_CONTENT_ERROR_NONE; + int album_count = 0; + filter_h filter; + + /*Set Filter*/ + char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/ + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to create filter"); + return ret; + } + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set condition"); + return ret; + } + ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ALBUM, MEDIA_CONTENT_COLLATE_NOCASE); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set order"); + return ret; + } + + ret = media_album_get_album_count_from_db(filter, &album_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + return ret; + } else { + media_content_debug("album_count [%d]", album_count); + } + + ret = media_album_foreach_album_from_db(filter, album_list_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_album_foreach_album_from_db : [%d]", ret); + + ret = media_filter_destroy(filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_filter_destroy : [%d]", ret); + + return ret; +} + +int test_group_operation(void) +{ + media_content_debug("\n============Group Test============\n\n"); + + int ret = MEDIA_CONTENT_ERROR_NONE; + int group_count = 0; + int idx = 0; + + ret = test_filter_create(); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("[error(0x%08x)", ret); + return ret; + } + + for(idx = 0; idx < MEDIA_CONTENT_GROUP_MAX; idx++) + { + ret = media_group_get_group_count_from_db(g_filter, idx, &group_count); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + test_filter_destroy(); + media_content_error("media_group_get_group_count_from_db fail. idx=[%d]", ret, idx); + return ret; + } else { + media_content_debug("[%2d]group_count [%d]", idx, group_count); + } + + ret = media_group_foreach_group_from_db(g_filter, idx, group_list_cb, &idx); + } + ret = test_filter_destroy(); + + return ret; +} + +int test_update_operation() +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + int i; + media_info_h media_handle = NULL; + GList *all_item_list = NULL; + + /* Get all item list */ + ret = media_info_foreach_media_from_db(NULL, gallery_media_item_cb, &all_item_list); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_foreach_media_from_db failed: %d", ret); + return -1; + } else { + media_content_debug("media_info_foreach_media_from_db success"); + char *media_id = NULL; + char *media_path = NULL; + media_content_type_e media_type = 0; + + for(i = 0; i < g_list_length(all_item_list); i++) { + media_handle = (media_info_h)g_list_nth_data(all_item_list, i); + + ret = media_info_get_media_id(media_handle, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_id failed: %d", ret); + ret = media_info_get_file_path(media_handle, &media_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_file_path failed: %d", ret); + ret = media_info_get_media_type(media_handle, &media_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_type failed: %d", ret); + + media_content_debug("media_id [%d] : %s", i, media_id); + media_content_debug("media_type [%d] : %d", i, media_type); + media_content_debug("media_path [%d] : %s", i, media_path); +#if 0 + if(media_type == MEDIA_CONTENT_TYPE_IMAGE) { + image_meta_h image_handle; + media_content_orientation_e orientation; + + ret = media_info_get_image(media_handle, &image_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_get_image failed: %d", ret); + } else { + media_content_debug("media_info_get_image success"); + + //update image meta + orientation = MEDIA_CONTENT_ORIENTATION_ROT_180; + image_meta_set_orientation(image_handle, orientation); + + ret = image_meta_update_to_db(image_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("image_meta_update_to_db failed: %d", ret); + } else { + media_content_debug("image_meta_update_to_db success"); + } + } + + } else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) { + video_meta_h video_handle; + + ret = media_info_get_video(media_handle, &video_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_get_video failed: %d", ret); + } else { + media_content_debug("media_info_get_video success"); + + //update video meta + video_meta_set_played_count(video_handle,5); + video_meta_set_played_time(video_handle,5); + video_meta_set_played_position(video_handle,5); + video_meta_update_to_db(video_handle); + + ret = video_meta_update_to_db(video_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("video_meta_update_to_db failed: %d", ret); + } else { + media_content_debug("video_meta_update_to_db success"); + } + } + } else if(media_type == MEDIA_CONTENT_TYPE_MUSIC) {//update audio meta + audio_meta_h audio_handle = NULL; + ret = media_info_get_audio(media_handle, &audio_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_get_audio failed: %d", ret); + } else { + media_content_debug("media_info_get_audio success"); + + audio_meta_set_played_count(audio_handle,5); + audio_meta_set_played_time(audio_handle,1000); + audio_meta_set_played_position(audio_handle,180); + + ret = audio_meta_update_to_db(audio_handle); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("audio_meta_update_to_db failed: %d", ret); + } else { + media_content_debug("audio_meta_update_to_db success"); + } + } + + } +#endif + } + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int test_insert(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *path = "/opt/usr/media/Images/Default.jpg"; + //char *path = "/opt/usr/media/Others/other.txt"; + //char *path = NULL; + media_info_h media_item = NULL; + media_content_debug("\n============DB Insert Test============\n\n"); + + ret = media_info_insert_to_db(path, &media_item); + + if((ret == MEDIA_CONTENT_ERROR_NONE) && (media_item != NULL)) + { + media_content_debug("Insertion is success"); + } + else + { + media_content_error("Insertion is failed"); + ret = media_info_destroy(media_item); + return ret; + } + + char *media_id = NULL; + + ret = media_info_get_media_id(media_item, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_id failed: %d", ret); + else + media_content_debug("Media ID: %s", media_id); + + SAFE_FREE(media_id); + + ret = media_info_update_to_db(media_item); + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_info_update_to_db is success"); + else + media_content_error("media_info_update_to_db is failed"); + + ret = media_info_destroy(media_item); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_destroy failed: %d", ret); + + return ret; +} + +int test_move(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + const char *move_media_id = "60aea677-4742-408e-b5f7-f2628062d06d"; + char *dst_path = "/opt/usr/media/Images/XX/Default1.jpg"; + media_info_h move_media = NULL; + + ret = media_info_get_media_from_db(move_media_id, &move_media); + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_info_get_media_from_db success"); + else + media_content_error("media_info_get_media_from_db failed: %d", ret); + + media_content_debug("\n============DB Move Test============\n\n"); + + if(move_media) { + ret = media_info_move_to_db(move_media, dst_path); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("Move is success"); + else + media_content_error("Move is failed"); + + ret = media_info_destroy(move_media); + } else { + media_content_debug("There is no item : %s", move_media_id); + } + + return ret; +} + +void thumbnail_completed_cb(media_content_error_e error, const char *path, void *user_data) +{ + char *thumbnail_path = NULL; + int ret = MEDIA_CONTENT_ERROR_NONE; + g_cnt++; + + media_content_debug("=================[%d][%d]", g_media_cnt, g_cnt); + media_content_debug("error_code [%d]", error); + media_content_debug("thumbnail_path [%s]", path); + if(user_data != NULL) + { + media_info_h media = (media_info_h)user_data; + ret = media_info_get_thumbnail_path(media, &thumbnail_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_thumbnail_path failed: %d", ret); + else + media_content_debug("thumbnail_path get from media[%s]", thumbnail_path); + SAFE_FREE(thumbnail_path); + ret = media_info_destroy(media); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_destroy failed: %d", ret); + } + + if(g_cnt == g_media_cnt) + g_main_loop_quit(g_loop); + + return; +} + +bool thumbnail_create_cb(media_info_h media, void *user_data) +{ + char *media_id = NULL; + media_info_h dst = NULL; + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(media == NULL) + { + media_content_debug("NO Item"); + return true; + } + + ret = media_info_get_media_id(media, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_id failed: %d", ret); + else + media_content_debug("media_id : [%s]", media_id); + + ret = media_info_clone(&dst, media); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_clone failed: %d", ret); + else + { + ret = media_info_create_thumbnail(dst, thumbnail_completed_cb, dst); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_create_thumbnail failed: %d", ret); + } + + return true; +} + +bool thumbnail_cancel_cb(media_info_h media, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + char *media_id = NULL; + media_info_h dst = NULL; + + g_cnt++; + + if(media == NULL) + { + media_content_debug("NO Item"); + return true; + } + + ret = media_info_get_media_id(media, &media_id); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_id failed: %d", ret); + else + media_content_debug("media_id : [%s]", media_id); + + ret = media_info_clone(&dst, media); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_clone failed: %d", ret); + + ret = media_info_cancel_thumbnail(dst); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_cancel_thumbnail failed: %d", ret); + + ret = media_info_destroy(dst); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_destroy failed: %d", ret); + + if(g_cnt == g_media_cnt) + g_main_loop_quit(g_loop); + + return true; +} + +gboolean create_thumbnail_start(gpointer data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = media_info_foreach_media_from_db(g_filter, thumbnail_create_cb, NULL); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_info_foreach_media_from_db is success"); + else + media_content_error("media_info_foreach_media_from_db is failed"); + + return false; +} + +gboolean cancel_thumbnail_start(gpointer data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = media_info_foreach_media_from_db(g_filter, thumbnail_cancel_cb, NULL); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_info_foreach_media_from_db is success"); + else + media_content_error("media_info_foreach_media_from_db is failed"); + + return false; +} + +int test_create_thumbnail(int cancel) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + GSource *source = NULL; + GMainContext *context = NULL; + + test_filter_create(); + + ret = media_info_get_media_count_from_db(g_filter, &g_media_cnt); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_count_from_db failed: %d", ret); + else + media_content_debug("media_count : [%d]", g_media_cnt); + + g_loop = g_main_loop_new(NULL, FALSE); + context = g_main_loop_get_context(g_loop); + source = g_idle_source_new(); + g_source_set_callback (source, create_thumbnail_start, NULL, NULL); + g_source_attach (source, context); + + /* Logic to cancel */ + if (cancel) { + GSource *cancel_src = NULL; + cancel_src = g_idle_source_new(); + g_source_set_callback (cancel_src, cancel_thumbnail_start, NULL, NULL); + g_source_attach (cancel_src, context); + } + + g_main_loop_run(g_loop); + g_main_loop_unref(g_loop); + + test_filter_destroy(); + + return ret; +} + +int test_disconnect_database(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_content_debug("\n============DB Disconnection Test============\n\n"); + + ret = media_content_disconnect(); + + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("disconnection is success"); + else + media_content_error("disconnection is failed"); + + return ret; +} + +int test_request_update_db(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_info_h media = NULL; + + //get the content of Over the horizon + ret = media_info_get_media_from_db("0f999626-6218-450c-a4ad-181a3bab6ebf", &media); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_from_db failed: %d", ret); + + test_disconnect_database(); + + ret = media_info_set_content_name(media, "TEST_content_name"); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_set_content_name failed: %d", ret); + + ret = media_info_update_to_db(media); + if(ret == MEDIA_CONTENT_ERROR_NONE) + media_content_debug("media_info_update_to_db is success"); + else + media_content_error("media_info_update_to_db is failed"); + + if(media != NULL) + media_info_destroy(media); + + return ret; +} + +int g_total_photo_size = 0; +int g_total_video_size = 0; +int g_total_mp3_size = 0; +int g_total_voice_memo_size = 0; + +bool dft_cb(media_info_h media, void *user_data) +{ + unsigned long long file_size = 0; + media_content_type_e media_type = -1; + char *mime_type = NULL; + int ret = MEDIA_CONTENT_ERROR_NONE; + + if(media == NULL) + { + return true; + } + + ret = media_info_get_media_type(media, &media_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_media_type failed: %d", ret); + ret = media_info_get_size(media, &file_size); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_size failed: %d", ret); + ret = media_info_get_mime_type(media, &mime_type); + if(ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("media_info_get_mime_type failed: %d", ret); + + if(media_type == MEDIA_CONTENT_TYPE_IMAGE) + { + g_total_photo_size += file_size; + } + else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + g_total_video_size += file_size; + } + else if(media_type == MEDIA_CONTENT_TYPE_SOUND) + { + g_total_voice_memo_size += file_size; + } + else if(media_type == MEDIA_CONTENT_TYPE_MUSIC) + { + if((mime_type != NULL) && (!strcmp("audio/mpeg", mime_type))) + { + g_total_mp3_size += file_size; + } + else + { + g_total_voice_memo_size += file_size; + } + } + else + { + printf("invalid media_type"); + } + + if(mime_type != NULL) + free(mime_type); + + return true; + +} + +int DFT_test(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + printf("\n============DFT_test============\n\n"); + + filter_h filter = NULL; + int media_cnt = 0; + + /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/ + + ret = media_filter_create(&filter); + +/*Internal Memory*/ + printf("[Internal Memory]\n"); + /*1. Photo ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get Photo Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("Photo count = [%d]\n", media_cnt); + + /*Get Photo Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("Photo size = [%d]\n", g_total_photo_size); + + /*2. Video ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get Video Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("Video count = [%d]\n", media_cnt); + + /*Get Video Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("Video size = [%d]\n", g_total_video_size); + + /*3. MP3 ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get MP3 Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("MP3 count = [%d]\n", media_cnt); + + /*Get MP3 Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("MP3 size = [%d]\n", g_total_mp3_size); + + /*4. Voice Memo ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get Voice Memo Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("Voice Memo count = [%d]\n", media_cnt); + + /*Get Voice Memo Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("Voice Memo size = [%d]\n", g_total_voice_memo_size); + + g_total_photo_size = 0; + g_total_video_size = 0; + g_total_mp3_size = 0; + g_total_voice_memo_size = 0; + +/*External Memory*/ + printf("\n[External Memory]\n"); + /*1. Photo ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get Photo Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("Photo count = [%d]\n", media_cnt); + + /*Get Photo Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("Photo size = [%d]\n", g_total_photo_size); + + /*2. Video ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get Video Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("Video count = [%d]\n", media_cnt); + + /*Get Video Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("Video size = [%d]\n", g_total_video_size); + + /*3. MP3 ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get MP3 Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("MP3 count = [%d]\n", media_cnt); + + /*Get MP3 Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("MP3 size = [%d]\n", g_total_mp3_size); + + /*4. Voice Memo ============================================================*/ + ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT); + + /*Get Voice Memo Count*/ + ret = media_info_get_media_count_from_db(filter, &media_cnt); + printf("Voice Memo count = [%d]\n", media_cnt); + + /*Get Voice Memo Size*/ + ret = media_info_foreach_media_from_db(filter, dft_cb, NULL); + printf("Voice Memo size = [%d]\n", g_total_voice_memo_size); + ret = media_filter_destroy(filter); + + return ret; +} + +void insert_batch_cb(media_content_error_e error, void * user_data) +{ + printf("media_info_insert_batch_to_db completed!\n"); +} + +int test_batch_operations() +{ + int ret = -1; + int i; + char *file_list[10]; + + for (i = 0; i < 10; i++) { + char filepath[255] = {0,}; + snprintf(filepath, sizeof(filepath), "%s%d.jpg", "/opt/usr/media/test/image", i+1); + media_content_debug("File : %s\n", filepath); + file_list[i] = strdup(filepath); + } + + ret = media_info_insert_batch_to_db((const char **)file_list, 10, insert_batch_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_insert_batch_to_db failed : %d\n", ret); + } + + filter_h filter; + char *condition = "MEDIA_PATH LIKE \'/opt/usr/media/test/image%%jpg\'"; + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to create filter"); + return ret; + } + + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("Fail to set condition"); + return ret; + } + + ret = media_info_delete_batch_from_db(filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_content_error("media_info_delete_batch_from_db failed : %d\n", ret); + return ret; + } + + ret = media_filter_destroy(filter); + + return ret; +} + +void insert_burst_shot_cb(media_content_error_e error, void * user_data) +{ + printf("media_info_insert_burst_shot_to_db completed![%d]\n", error); + g_main_loop_quit(g_loop); +} + +gboolean test_insert_burst_shot_to_db_start(gpointer data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + int i = 0; + char *file_list[10]; + + for (i = 0; i < 10; i++) { + char filepath[255] = {0,}; + snprintf(filepath, sizeof(filepath), "%s%d.jpg", "/opt/usr/media/test/image", i+1); + media_content_debug("File : %s\n", filepath); + file_list[i] = strdup(filepath); + } + + ret = media_info_insert_burst_shot_to_db((const char **)file_list, 10, insert_burst_shot_cb, NULL); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_insert_burst_shot_to_db failed : %d\n", ret); + } + + return ret; +} + +int test_insert_burst_shot_to_db(void) +{ + GSource *source = NULL; + GMainContext *context = NULL; + + g_loop = g_main_loop_new(NULL, FALSE); + context = g_main_loop_get_context(g_loop); + source = g_idle_source_new(); + g_source_set_callback (source, test_insert_burst_shot_to_db_start, NULL, NULL); + g_source_attach (source, context); + + g_main_loop_run(g_loop); + g_main_loop_unref(g_loop); + + return 0; +} + +void _scan_cb(media_content_error_e err, void *user_data) +{ + printf("scan callback is called : %d\n", err); + g_main_loop_quit(g_loop); + + return; +} + +int test_scan_file() +{ + int ret = -1; + + const char *file_path = "/opt/usr/media/test/image1.jpg"; + + ret = media_content_scan_file(file_path); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to media_content_scan_file : %d", ret); + return ret; + } + + return 0; +} + +gboolean test_scan_dir_start(gpointer data) +{ + int ret = -1; + + const char *dir_path = "/opt/usr/media"; + + ret = media_content_scan_folder(dir_path, TRUE, _scan_cb, NULL); + + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to test_scan_dir_start : %d", ret); + return ret; + } + + return 0; +} + +int test_scan_dir() +{ + GSource *source = NULL; + GMainContext *context = NULL; + + g_loop = g_main_loop_new(NULL, FALSE); + context = g_main_loop_get_context(g_loop); + source = g_idle_source_new(); + g_source_set_callback (source, test_scan_dir_start, NULL, NULL); + g_source_attach (source, context); + + g_main_loop_run(g_loop); + g_main_loop_unref(g_loop); + + return 0; +} + +void _noti_cb(media_content_error_e error, + int pid, + media_content_db_update_item_type_e update_item, + media_content_db_update_type_e update_type, + media_content_type_e media_type, + char *uuid, + char *path, + char *mime_type, + void *user_data) +{ + if (error == 0) { + printf("noti success! : %d\n", error); + } else { + printf("error occured! : %d\n", error); + } + + printf("Noti from PID(%d)\n", pid); + + if (update_item == MEDIA_ITEM_FILE) { + printf("Noti item : MEDIA_ITEM_FILE\n"); + } else if (update_item == MEDIA_ITEM_DIRECTORY) { + printf("Noti item : MEDIA_ITEM_DIRECTORY\n"); + } + + if (update_type == MEDIA_CONTENT_INSERT) { + printf("Noti type : MEDIA_CONTENT_INSERT\n"); + } else if (update_type == MEDIA_CONTENT_DELETE) { + printf("Noti type : MEDIA_CONTENT_DELETE\n"); + } else if (update_type == MEDIA_CONTENT_UPDATE) { + printf("Noti type : MEDIA_CONTENT_UPDATE\n"); + } + + printf("content type : %d\n", media_type); + + if (path) + printf("path : %s\n", path); + else + printf("path not\n"); + + if (uuid) + printf("uuid : %s\n", uuid); + else + printf("uuid not\n"); + + if (mime_type) + printf("mime_type : %s\n", mime_type); + else + printf("mime not\n"); + + if (user_data) printf("String : %s\n", (char *)user_data); + + //g_main_loop_quit(g_loop); + return; +} + +gboolean _send_noti_operations(gpointer data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + /* First of all, noti subscription */ + char *user_str = strdup("hi"); + media_content_set_db_updated_cb(_noti_cb, (void*)user_str); + + /* media_info_insert_to_db */ + media_info_h media_item = NULL; + char *path = "/opt/usr/media/test/image1.jpg"; + + ret = media_info_insert_to_db(path, &media_item); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_insert_to_db failed : %d", ret); + media_info_destroy(media_item); + return FALSE; + } + + media_content_debug("media_info_insert_to_db success"); + + /* media_info_delete_batch_from_db */ + filter_h filter; + char *condition = "MEDIA_PATH LIKE \'/opt/usr/media/test/image%%jpg\'"; + + ret = media_filter_create(&filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("Fail to create filter"); + media_info_destroy(media_item); + return ret; + } + + ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_info_destroy(media_item); + media_content_error("Fail to set condition"); + return ret; + } + ret = media_info_delete_batch_from_db(filter); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_filter_destroy(filter); + media_info_destroy(media_item); + media_content_error("media_info_delete_batch_from_db failed : %d\n", ret); + return ret; + } + + media_filter_destroy(filter); + + /* media_info_update_to_db */ + ret = media_info_update_to_db(media_item); + if(ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("media_info_update_to_db failed : %d\n", ret); + media_info_destroy(media_item); + return ret; + } + + media_info_destroy(media_item); + + return FALSE; +} + +int test_noti() +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + GSource *source = NULL; + GMainContext *context = NULL; + + g_loop = g_main_loop_new(NULL, FALSE); + context = g_main_loop_get_context(g_loop); + source = g_idle_source_new(); + g_source_set_callback (source, _send_noti_operations, NULL, NULL); + g_source_attach (source, context); + + g_main_loop_run(g_loop); + g_main_loop_unref(g_loop); + + test_filter_destroy(); + media_content_unset_db_updated_cb(); + + return ret; +} + +int main(int argc, char *argv[]) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_content_debug("--- content manager test start ---\n\n"); + + ret = test_connect_database(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + +#if 0 + ret = test_move(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_gallery_scenario(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_get_all_music_files(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_media_info_operation(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_folder_operation(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_folder_update(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_playlist_operation(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_tag_operation(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_bookmark_operation(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_album_list(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_group_operation(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_update_operation(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_insert(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_move(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_create_thumbnail(TRUE); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_request_update_db(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = DFT_test(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + ret = test_batch_operations(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + + ret = test_insert_burst_shot_to_db(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + + ret = test_scan_file(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + + ret = test_scan_dir(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; + + ret = test_noti(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; +#endif + + ret = test_disconnect_database(); + if(ret != MEDIA_CONTENT_ERROR_NONE) + return ret; + + media_content_debug("--- content manager test end ---\n"); + + return ret; +} -- 2.7.4