From 7ca421a2d4274d0fba8d6e34e68f46e5a09caa8c Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 4 Jun 2015 15:35:34 +0900 Subject: [PATCH 01/16] Initialize package. Change-Id: I43c4bd62fcdb33616e4ccd2b7c04fc8ee81af992 Signed-off-by: Minje Ahn --- AUTHORS | 1 + CMakeLists.txt | 97 + LICENSE.APLv2.0 | 201 +++ NOTICE | 3 + capi-media-metadata-editor.manifest | 5 + capi-media-metadata-editor.pc.in | 13 + doc/metadata_editor_doc.h | 45 + include/metadata_editor.h | 231 +++ include/metadata_editor_private.h | 88 + include/metadata_editor_type.h | 88 + packaging/capi-media-metadata-editor.spec | 52 + src/metadata_editor.cpp | 2772 +++++++++++++++++++++++++++++ test/CMakeLists.txt | 18 + test/metadata_editor_test.c | 467 +++++ 14 files changed, 4081 insertions(+) create mode 100755 AUTHORS create mode 100755 CMakeLists.txt create mode 100755 LICENSE.APLv2.0 create mode 100755 NOTICE create mode 100755 capi-media-metadata-editor.manifest create mode 100755 capi-media-metadata-editor.pc.in create mode 100755 doc/metadata_editor_doc.h create mode 100755 include/metadata_editor.h create mode 100755 include/metadata_editor_private.h create mode 100755 include/metadata_editor_type.h create mode 100755 packaging/capi-media-metadata-editor.spec create mode 100755 src/metadata_editor.cpp create mode 100755 test/CMakeLists.txt create mode 100755 test/metadata_editor_test.c diff --git a/AUTHORS b/AUTHORS new file mode 100755 index 0000000..4fe6589 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Haejeong Kim diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..89c2122 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,97 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-media-metadata-editor") + +# project +SET(prefix "/usr") +SET(version "0.0.1") +SET(maintainer "Haejeong Kim ") +SET(description "A Metadata Editor library in Tizen Native API") +SET(service "metadata-editor") + +# for package file +SET(dependents "dlog capi-base-common taglib aul") + +PROJECT(${fw_name} C CXX) + +SET(CMAKE_INSTALL_PREFIX ${prefix}) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(VERSION ${version}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC -Wall") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" MATCHES "^arm.*") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/${service} + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${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 100755 index 0000000..ccdad52 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE file for Apache License terms and conditions. diff --git a/capi-media-metadata-editor.manifest b/capi-media-metadata-editor.manifest new file mode 100755 index 0000000..a76fdba --- /dev/null +++ b/capi-media-metadata-editor.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/capi-media-metadata-editor.pc.in b/capi-media-metadata-editor.pc.in new file mode 100755 index 0000000..b8a69f8 --- /dev/null +++ b/capi-media-metadata-editor.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/metadata-editor + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} @PC_CFLAGS@ diff --git a/doc/metadata_editor_doc.h b/doc/metadata_editor_doc.h new file mode 100755 index 0000000..30b2c93 --- /dev/null +++ b/doc/metadata_editor_doc.h @@ -0,0 +1,45 @@ +/* + * 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_METADATA_EDITOR_DOC_H__ +#define __TIZEN_METADATA_EDITOR_DOC_H__ + +/** + * @file metadata_editor_doc.h + * @brief File contains the high level documentation for the Metadata Editor API. + * + */ + +/** + * @defgroup CAPI_MEDIA_METADATA_EDITOR_MODULE Metadata Editor + * @ingroup CAPI_MEDIA_FRAMEWORK + */ + +/** + * @addtogroup CAPI_MEDIA_METADATA_EDITOR_MODULE + * @brief The @ref CAPI_MEDIA_METADATA_EDITOR_MODULE API provides functions for editing the metadata of several popular audio format. + * @ingroup CAPI_MEDIA_FRAMEWORK + * @section CAPI_MEDIA_METADATA_EDITOR_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_MEDIA_METADATA_EDITOR_OVERVIEW Overview + * The @ref CAPI_MEDIA_METADATA_EDITOR_MODULE API allows you to read the metadata from a media file(#metadata_editor_get_metadata()). To edit a metadata(#metadata_editor_set_metadata()), create/destory the handle(#metadata_editor_create()/#metadata_editor_destroy), and append/ remove a picture in the metadata(#metadata_editor_append_picture()/ #metadata_editor_remove_picture()). + */ + +#endif /* __TIZEN_METADATA_EDITOR_DOC_H__ */ + + diff --git a/include/metadata_editor.h b/include/metadata_editor.h new file mode 100755 index 0000000..1a038f6 --- /dev/null +++ b/include/metadata_editor.h @@ -0,0 +1,231 @@ +/* +* Copyright (c) 2013 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_METADATA_EDITOR_H__ +#define __TIZEN_METADATA_EDITOR_H__ + + +#include + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @addtogroup CAPI_MEDIA_METADATA_EDITOR_MODULE + * @{ + * + * @file metadata_editor.h + * @brief This file contains the API for metadata of several popular audio formats and related structure and enumeration. \n + * Description of metadata: title, album, artist, author, genre and description etc. \n + */ + + +/** + * @brief Create metadata + * @since_tizen 2.4 + * + * @remarks You must release @a metadata using metadata_editor_destroy(). + * + * @param [in] metadata The handle to metadata + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OUT_OF_MEMORY Not enough memory is available + * @see metadata_editor_destroy() + */ +int metadata_editor_create(metadata_editor_h *metadata); + + +/** + * @brief Set file path to read or write metadata + * @since_tizen 2.4 + * + * @remarks In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n + * For example, if you get the specific path by using storage_get_directory(). you should add previlege http://tizen.org/privilege/mediastorage or http://tizen.org/privilege/externalstorage. + * + * @param [in] metadata The handle to metadata + * @param [in] path path to read or write metadata + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_FILE_EXISTS File not exist + * @retval #METADATA_EDITOR_ERROR_NOT_SUPPORTED unsupported file type + * @retval #METADATA_EDITOR_ERROR_PERMISSION_DENIED Permission denied + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @pre Create metadata handle by calling metadata_editor_create() + * @see metadata_editor_create(), metadata_editor_destroy() + */ +int metadata_editor_set_path(metadata_editor_h metadata, const char *path); + + +/** + * @brief Get the metadata corresponding to the attribute. + * @since_tizen 2.4 + * + * @remarks You must release @a value using @c free(). \n + * If the attribute value of the metadata is empty, return value is NULL. \n + * In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n + * For example, if you get the specific path by using storage_get_directory(). you should add previlege http://tizen.org/privilege/mediastorage or http://tizen.org/privilege/externalstorage. + * + * @param [in] metadata The handle to metadata + * @param [in] attribute key attribute name to get + * @param [out] value The value of the attribute + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OUT_OF_MEMORY Not enough memory is available + * @retval #METADATA_EDITOR_ERROR_PERMISSION_DENIED Permission denied + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @pre Set path to read or write metadata by calling metadata_editor_set_path() + * @see metadata_editor_create(), metadata_editor_destroy() + */ +int metadata_editor_get_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, char **value); + + +/** + * @brief Set the attribute of the metadata. + * @since_tizen 2.4 + * @details This function set the attribute of the metadata for updating the metadata. \n + * + * @remarks You must release @a value using @c free(). \n + * You must call metadata_editor_update_metadata() for applying to the metadata of the media file. if not, you will see the existing metadata when you call metadata_editor_get_metadata(). + * + * @param [in] metadata The handle to metadata + * @param [in] attribute key attribute name to get + * @param [int] value The value of the attribute + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OUT_OF_MEMORY Not enough memory is available + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @pre Set path to read or write metadata by calling metadata_editor_set_path() + * @see metadata_editor_create(), metadata_editor_update_metadata(), metadata_editor_destroy() + */ +int metadata_editor_set_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, const char *value); + + +/** + * @brief Update the modified metadata + * @since_tizen 2.4 + * @details This function update the metadata in the media file that is modified by metadata_editor_set_metadata(). + * + * @remarks In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n + * For example, if you get the specific path by using storage_get_directory(). you should add previlege http://tizen.org/privilege/mediastorage or http://tizen.org/privilege/externalstorage. + * + * @param [in] metadata The handle to metadata + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OUT_OF_MEMORY Not enough memory is available + * @retval #METADATA_EDITOR_ERROR_PERMISSION_DENIED Permission denied + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @pre Set path to read or write metadata by calling metadata_editor_set_path() + * @see metadata_editor_create(), metadata_editor_destroy() + */ +int metadata_editor_update_metadata(metadata_editor_h metadata); + +/** + * @brief Get the picture in the media file + * @since_tizen 2.4 + * + * @remarks You must release @a picture using @c free(). \n + * In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n + * For example, if you get the specific path by using storage_get_directory(). you should add previlege http://tizen.org/privilege/mediastorage or http://tizen.org/privilege/externalstorage. + * + * @param [in] metadata The handle to metadata + * @param [in] index picture order + * @param [out] picture encoded picture + * @param [out] size encoded picture size + * @param [out] mime_type the mime type of picture + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OUT_OF_MEMORY Not enough memory is available + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @retval #METADATA_EDITOR_ERROR_PERMISSION_DENIED Permission denied + * @pre Set path to read or write metadata by calling metadata_editor_set_path() + * @see metadata_editor_create(), metadata_editor_destroy() + */ +int metadata_editor_get_picture(metadata_editor_h metadata, int index, void **picture, int *size, char **mime_type); + +/** + * @brief Append the picture to the media file + * @since_tizen 2.4 + * + * @remarks You must call metadata_editor_update_metadata() for applying to the metadata of the media file. if not, you will see the existing metadata when you call metadata_editor_get_metadata(). \n + * Image type of the metadata supports jpeg and png. \n + * In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n + * For example, if you get the specific path by using storage_get_directory(). you should add previlege http://tizen.org/privilege/mediastorage or http://tizen.org/privilege/externalstorage. + * + * @param [in] metadata The handle to metadata + * @param [in] picture_path The path of picture for adding to the metadata + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OUT_OF_MEMORY Not enough memory is available + * @retval #METADATA_EDITOR_ERROR_NOT_SUPPORTED unsupported file type + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @retval #METADATA_EDITOR_ERROR_PERMISSION_DENIED Permission denied + * @pre Set path to read or write metadata by calling metadata_editor_set_path() + * @see metadata_editor_create(), metadata_editor_destroy() + */ +int metadata_editor_append_picture(metadata_editor_h metadata, const char *picture_path); + +/** + * @brief Remove artwork image from media file + * @since_tizen 2.4 + * + * @remarks You must call metadata_editor_update_metadata() for applying to the metadata of the media file. if not, you will see the existing metadata when you call metadata_editor_get_metadata(). \n + * + * @param [in] metadata The handle to metadata + * @param [in] index artwork image order + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OUT_OF_MEMORY Not enough memory is available + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @retval #METADATA_EDITOR_ERROR_PERMISSION_DENIED Permission denied + * @pre Set path to read or write metadata by calling metadata_editor_set_path() + * @see metadata_editor_create(), metadata_editor_destroy() + */ +int metadata_editor_remove_picture(metadata_editor_h metadata, int index); + +/** + * @brief Destroy metadata + * @since_tizen 2.4 + * + * @param [in] metadata The handle to metadata + * @return 0 on success, otherwise a negative error value + * @retval #METADATA_EDITOR_ERROR_NONE Successful + * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #METADATA_EDITOR_ERROR_OPERATION_FAILED Internal Operation Fail + * @pre Create metadata handle by calling metadata_editor_create() + * @see metadata_editor_create() + */ +int metadata_editor_destroy(metadata_editor_h metadata); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __TIZEN_METADATA_EDITOR_H__ */ diff --git a/include/metadata_editor_private.h b/include/metadata_editor_private.h new file mode 100755 index 0000000..2471416 --- /dev/null +++ b/include/metadata_editor_private.h @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2013 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_METADATA_EDITOR_PRIVATE_H__ +#define __TIZEN_METADATA_EDITOR_PRIVATE_H__ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_MEDIA_METADATA_EDITOR" + +#define metadata_editor_debug(fmt, arg...) do { \ + LOGD(""fmt"", ##arg); \ + } while (0) + +#define metadata_editor_info(fmt, arg...) do { \ + LOGI(""fmt"", ##arg); \ + } while (0) + +#define metadata_editor_error(fmt, arg...) do { \ + LOGE(""fmt"", ##arg); \ + } while (0) + +#define metadata_editor_debug_fenter() do { \ + LOGD(""); \ + } while (0) + +#define metadata_editor_debug_fleave() do { \ + LOGD(""); \ + } while (0) + +typedef struct +{ + void* file; + int filetype; + bool isOpen; + bool isReadOnly; +} metadata_editor_s; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*__TIZEN_METADATA_EDITOR_PRIVATE_H__*/ diff --git a/include/metadata_editor_type.h b/include/metadata_editor_type.h new file mode 100755 index 0000000..7755ce9 --- /dev/null +++ b/include/metadata_editor_type.h @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2013 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_METADATA_EDITOR_TYPE_H__ +#define __TIZEN_METADATA_EDITOR_TYPE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/** +* @addtogroup CAPI_MEDIA_METADATA_EDITOR_MODULE +* @{ +*/ + +/** + * @ingroup CAPI_MEDIA_METADATA_EDITOR_MODULE + * @brief The enumerations of media metadata error + * @since_tizen 2.4 + */ +typedef enum +{ + METADATA_EDITOR_ERROR_NONE = TIZEN_ERROR_METADATA_EDITOR, /**< Successful */ + METADATA_EDITOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + METADATA_EDITOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + METADATA_EDITOR_ERROR_FILE_EXISTS = TIZEN_ERROR_FILE_EXISTS, /**< File not exist */ + METADATA_EDITOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + METADATA_EDITOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /* Unsupported type */ + METADATA_EDITOR_ERROR_OPERATION_FAILED = TIZEN_ERROR_METADATA_EDITOR |0x01, /**< Invalid internal operation */ +} metadata_editor_error_e; + + +/** + * @ingroup CAPI_MEDIA_METADATA_EDITOR_MODULE + * @brief The enumerations of attribute + * @since_tizen 2.4 + */ +typedef enum +{ + METADATA_EDITOR_ATTR_ARTIST, /**< Artist*/ + METADATA_EDITOR_ATTR_TITLE, /**< Title*/ + METADATA_EDITOR_ATTR_ALBUM, /**< Album*/ + METADATA_EDITOR_ATTR_GENRE, /**< Genre*/ + METADATA_EDITOR_ATTR_AUTHOR, /**< Author*/ + METADATA_EDITOR_ATTR_COPYRIGHT, /**< Copyright*/ + METADATA_EDITOR_ATTR_DATE, /**< Date*/ + METADATA_EDITOR_ATTR_DESCRIPTION, /**< Description*/ + METADATA_EDITOR_ATTR_COMMENT, /**< Comment*/ + METADATA_EDITOR_ATTR_TRACK_NUM, /**< Track number info*/ + METADATA_EDITOR_ATTR_PICTURE_NUM, /**< Picture number*/ + METADATA_EDITOR_ATTR_CONDUCTOR, /**< Conductor*/ + METADATA_EDITOR_ATTR_UNSYNCLYRICS, /**< Unsynchronized lyric*/ +} metadata_editor_attr_e; + +/** + * @ingroup CAPI_MEDIA_METADATA_EDITOR_MODULE + * @brief The handle of media metadata + * @since_tizen 2.4 + */ +typedef void * metadata_editor_h; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /*__TIZEN_METADATA_EDITOR_TYPE_H__*/ diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec new file mode 100755 index 0000000..919b74e --- /dev/null +++ b/packaging/capi-media-metadata-editor.spec @@ -0,0 +1,52 @@ +Name: capi-media-metadata-editor +Summary: A metadata editor library in SLP C API +Version: 0.1.0 +Release: 0 +Group: System/Libraries +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(taglib) +BuildRequires: pkgconfig(aul) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description +A metadata editor library in SLP C API + +%package devel +Summary: A metadata editor library in SLP C API (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel +A metadata editor library in SLP C API + +%prep +%setup -q + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install +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-media-metadata-editor.manifest +%{_libdir}/libcapi-media-metadata-editor.so +%{_datadir}/license/%{name} + +%files devel +%{_includedir}/metadata-editor/*.h +%{_libdir}/pkgconfig/capi-media-metadata-editor.pc diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp new file mode 100755 index 0000000..132aeb0 --- /dev/null +++ b/src/metadata_editor.cpp @@ -0,0 +1,2772 @@ +/* +* Copyright (c) 2013 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 + +static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value); +static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value); +static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value); +static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value); +static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value); +static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value); +static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* value); +static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* value); +static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemname, char** value); +static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemname, char** value); +static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value); +static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* itemname, const char* value); +static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value); +static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, char** value); +static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value); +static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value); + +typedef enum +{ + METADATA_EDITOR_FORMAT_MP3 = 0, /**< MP3 File */ + METADATA_EDITOR_FORMAT_MP4 = 1, /**< MP4 File */ + METADATA_EDITOR_FORMAT_FLAC, /**< FLAC File */ + METADATA_EDITOR_FORMAT_OGG_VORBIS, /**< Vorbis Audio in Ogg container */ + METADATA_EDITOR_FORMAT_OGG_FLAC, /**< FLAC Audio in Ogg container */ + METADATA_EDITOR_FORMAT_WAV, /**< WAV file */ + METADATA_EDITOR_FORMAT_NOTYPE = 0xFF /**< Error type. File type is not correct or not specified */ +} metadata_editor_format_e; + + +// *** This is an auxiliary function that is used to get the frame value *** // +// *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // +static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) +{ + // Check if we have valid arguments to work with + if((_metadata == NULL) || (frameID == NULL)) + { + metadata_editor_error("INVALID PARAMETER\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(value == NULL) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + // Check if the frame is empty (nothing to read) or ID3v2 tag does not exist + if(!tag2 || tag2->frameListMap()[frameID].isEmpty()) + { + metadata_editor_info("The frame %s in ID3v2 tag is empty\n", frameID); + // Check if the tag ID3v1 is also empty or does not exist + if(!tag1 || tag1->isEmpty()) + { + *value = NULL; + metadata_editor_info("The frame %s in ID3v1 tag is empty as well\n", frameID); + return METADATA_EDITOR_ERROR_NONE; + } + else // if not - read the frame you need there + { + metadata_editor_info("Reading data from ID3v1 tag\n"); + + TagLib::String str; + uint length; + bool found = false; + + if(!strcmp(frameID, "TPE1")) // artist + { + str = tag1->artist(); found = true; + } + else if(!strcmp(frameID, "TALB")) // album + { + str = tag1->album(); found = true; + } + else if(!strcmp(frameID, "COMM")) // comment + { + str = tag1->comment(); found = true; + } + else if(!strcmp(frameID, "TCON")) // genre + { + str = tag1->genre(); found = true; + } + else if(!strcmp(frameID, "TIT2")) // title + { + str = tag1->title(); found = true; + } + // Check if we have already found the frame + if(found) + { + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + length = strlen(str.toCString(isUTF)); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, str.toCString(isUTF)); + return METADATA_EDITOR_ERROR_NONE; + } + + uint size = 20; + char buf[size]; + + if(!strcmp(frameID, "TRCK")) // track + { + // Convert int into char[] + snprintf(buf, size, "%u", tag1->track()); found = true; + } + else if(!strcmp(frameID, "TDRC")) // data (year) + { + // Convert int into char[] + snprintf(buf, size, "%u", tag1->year()); found = true; + } + if(found) + { + length = strlen(buf); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, buf); + return METADATA_EDITOR_ERROR_NONE; + } + // The desired frame was not found + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + } + else // or frame has data to read + { + metadata_editor_info("The frame %s exists in ID3v2 tag\n", frameID); + // This string is used to copy the value in the frame + TagLib::String str = tag2->frameListMap()[frameID][0]->toString(); + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + uint length = strlen(str.toCString(isUTF)); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + // Allocate the memory and copy the value to this memory + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, str.toCString(isUTF)); + + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This is an auxiliary function that is used to write the new value to the frame *** // +// *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // +static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) +{ + // Check if we have valid arguments to work with + if((_metadata == NULL) || (frameID == NULL)) + { + metadata_editor_error("INVALID PARAMETER\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Check if the valid tag pointer exists + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + // If the pointer is NULL or c-string is empty - handle as request for deletion + if(!value || (*value == '\0')) + { + metadata_editor_info("Request for frame %s deletion\n", frameID); + tag2->removeFrames(frameID); + if(tag1 && !tag1->isEmpty()) + { + if(!strcmp(frameID, "TPE1")) { tag1->setArtist(""); } + else if(!strcmp(frameID, "TALB")) { tag1->setAlbum(""); } + else if(!strcmp(frameID, "TCON")) { tag1->setGenre(""); } + else if(!strcmp(frameID, "TIT2")) { tag1->setTitle(""); } + else if(!strcmp(frameID, "TRCK")) { tag1->setTrack(0); } + else if(!strcmp(frameID, "TDRC")) { tag1->setYear(0); } + } + return METADATA_EDITOR_ERROR_NONE; + } + // Check if the frame is empty (must create the frame before writing the data) + if(tag2->frameListMap()[frameID].isEmpty()) + { + metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); + // This is a common frame type for textural frames except comment frame + TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); + if(fr == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + fr->setTextEncoding(TagLib::String::UTF8); + fr->setText(TagLib::String(value,TagLib::String::UTF8)); + tag2->addFrame(fr); + } + else // if not - just modify the data in the existing frame + { + metadata_editor_info("The frame %s exists. Changing.\n", frameID); + tag2->frameListMap()[frameID][0]->setText(TagLib::String(value,TagLib::String::UTF8)); + } + if(tag1 && !tag1->isEmpty()) // Check if ID3v1 tag exists. Must copy data if yes. + { + metadata_editor_info("ID3v1 tag also exists. Copying frame\n"); + if(!strcmp(frameID, "TPE1")) + tag1->setArtist(value); + else if(!strcmp(frameID, "TALB")) + tag1->setAlbum(value); + else if(!strcmp(frameID, "TCON")) // Genre in ID3v1 is enumeration, so can not write it with "value" + tag1->setGenre(""); + else if(!strcmp(frameID, "TIT2")) + tag1->setTitle(value); + else if(!strcmp(frameID, "TRCK")) + tag1->setTrack(atoi(value)); + else if(!strcmp(frameID, "TDRC")) + tag1->setYear(atoi(value)); + } + return METADATA_EDITOR_ERROR_NONE; +} + +// *** This function reads frames that exist only in ID3v2 tag *** // +static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) +{ + // Check if we have valid arguments to work with + if((_metadata == NULL) || (frameID == NULL)) + { + metadata_editor_error("INVALID PARAMETER\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(value == NULL) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + // Check if the frame is empty (nothing to read) or ID3v2 tag does not exist + if (!tag2 || tag2->frameListMap()[frameID].isEmpty()) + { + metadata_editor_info("The frame %s does not exist\n", frameID); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } + else // frame exists - read it + { + metadata_editor_info("The frame %s exists\n", frameID); + // This string is used to copy the value in the frame + TagLib::String str = tag2->frameListMap()[frameID][0]->toString(); + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + uint length = strlen(str.toCString(isUTF)); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + // Allocate the memory and copy the value to this memory + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, str.toCString(isUTF)); + + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This function writes frames that exist only in ID3v2 tag *** // +static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) +{ + // Check if we have valid arguments to work with + if((_metadata == NULL) || (frameID == NULL)) + { + metadata_editor_error("INVALID PARAMETER\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Check if the valid tag pointer exist + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + // If the pointer is NULL or c-string is empty - handle as request for deletion + if(!value || (*value == '\0')) + { + metadata_editor_info("Request for frame %s deletion\n", frameID); + tag2->removeFrames(frameID); + return METADATA_EDITOR_ERROR_NONE; + } + + // Check if the ID3v2 tag exists + if (tag2->frameListMap()[frameID].isEmpty()) + { + metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); + // This is a common frame type for textural frames except comment frame + TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); + if(fr == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + fr->setTextEncoding(TagLib::String::UTF8); + fr->setText(TagLib::String(value,TagLib::String::UTF8)); + tag2->addFrame(fr); + } + else // if not - just modify the data in the existing frame + { + metadata_editor_info("The frame %s exists. Changing.\n", frameID); + tag2->frameListMap()[frameID][0]->setText(TagLib::String(value,TagLib::String::UTF8)); + } + return METADATA_EDITOR_ERROR_NONE; +} + +// *** This function is used to receive the number of pictures stored in ID3v2 tag of file *** // +static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) +{ + // Check if parameters are valid + if(_metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if((value == NULL)) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + // Check if the valid tag pointer exist + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag does not exist. Can not process further\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // link to picture frames in tag + // Check if the frames exist + if(lst.isEmpty()) + { + metadata_editor_info("No pictures in file\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } + else // picture frames exist + { + metadata_editor_info("APIC frames exist in file\n"); + int size = 20; + char buf[size]; + // Convert the number of frames (lst.size()) to c-string + snprintf(buf, size, "%u", lst.size()); + uint length = strlen(buf); + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + // Copy c-string to value for returning + strcpy(*value, buf); + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This function is used to receive unsynchronized lyrics from ID3v2 tag in file *** // +// *** This frame differs from other string-type frames and uses UnsynchronizedLyricsFrame instead of TextIdentificationFrame *** // +static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) +{ + // Check if parameters are valid + if(_metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if((value == NULL)) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + // Check if the valid tag pointer exist + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag does not exist. Can not process further\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag + // Check if frames exist in file + if(lst.isEmpty()) + { + metadata_editor_info("The frame USLT does not exist\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } + else + { + metadata_editor_info("The frame USLT exists\n"); + TagLib::ID3v2::FrameList::Iterator it = lst.begin(); + TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = static_cast(*it); + TagLib::String str = frame->text(); + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + uint length = strlen(str.toCString(isUTF)); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, str.toCString(isUTF)); + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This function is used to set text in comment frame. It processes both ID3v1 and ID3v2 tags *** // +// *** Comment frame is different from other string-type frames. It uses CommentsFrame instead of TextIdentificationFrame *** // +static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* value) +{ + // Check if we have a valid argument to work with + if(_metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Check if the valid tag pointer exist + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // If the pointer is NULL or c-string is empty - handle as request for deletion + if(!value || (*value == '\0')) + { + metadata_editor_info("Request for frame COMM deletion\n"); + tag2->removeFrames("COMM"); + if(tag1 && !tag1->isEmpty()) + tag1->setComment(""); + return METADATA_EDITOR_ERROR_NONE; + } + // If the comment frame is empty - create the frame and add it to the list + if (tag2->frameListMap()["COMM"].isEmpty()) + { + metadata_editor_info("The frame COMM does not exist. Creating.\n"); + TagLib::ID3v2::CommentsFrame* fr = new TagLib::ID3v2::CommentsFrame; + if(fr == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + fr->setText(TagLib::String(value, TagLib::String::UTF8)); + fr->setTextEncoding(TagLib::String::UTF8); + tag2->addFrame(fr); + } + else // If the frame already exists - just modify its value + { + metadata_editor_info("The frame COMM exists. Changing.\n"); + tag2->frameListMap()["COMM"][0]->setText(TagLib::String(value,TagLib::String::UTF8)); + } + if(tag1 && !tag1->isEmpty()) // Copy the value to ID3v1 tag comment + { + metadata_editor_info("ID3v1 tag also exists. Copying frame\n"); + tag1->setComment(value); + } + return METADATA_EDITOR_ERROR_NONE; +} + +// *** This function is used to set text in Lyrics frame *** // +// *** Lyrics frame is different from other string-type frames and uses UnsynchronizedLyricsFrame instead of TextIdentificationFrame *** // +static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* value) +{ + // Check if we have a valid argument to work with + if(_metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Check if the valid tag pointer exist + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag + // If the pointer is NULL or c-string is empty - handle as request for deletion + if(!value || (*value == '\0')) + { + metadata_editor_info("Request for frame USLT deletion\n"); + tag2->removeFrames("USLT"); + return METADATA_EDITOR_ERROR_NONE; + } + // Check if lyrics frames exist + if(lst.isEmpty()) + { + // No lyrics - create the frame and add it to the ID3v2 tag + metadata_editor_info("The frame USLT does not exist. Creating.\n"); + TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = new TagLib::ID3v2::UnsynchronizedLyricsFrame; + if(frame == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + frame->setTextEncoding(TagLib::String::UTF8); + frame->setText(TagLib::String(value,TagLib::String::UTF8)); + tag2->addFrame(frame); + } + else // the lyrics frames exist - change the existing one + { + metadata_editor_info("USLT frames exist in file. Changing.\n"); + TagLib::ID3v2::FrameList::Iterator it = lst.begin(); + TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = static_cast(*it); + frame->setTextEncoding(TagLib::String::UTF8); + frame->setText(TagLib::String(value,TagLib::String::UTF8)); + } + return METADATA_EDITOR_ERROR_NONE; +} + +// *** This function extracts string values from tag in MP4 file *** // +static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemname, char** value) +{ + // Check if parameters are valid + if((_metadata == NULL)|| (itemname == NULL)) + { + metadata_editor_error("INVALID Parameter\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(value == NULL) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); + if(it != itemMap.end()) // Item was found + { + TagLib::String str = it->second.toStringList()[0]; // Get the first string in item + // Check the encoding of the string (1252 or not) + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + // Get the length of the string and check if it is empty or not + uint length = strlen(str.toCString(isUTF)); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + // Allocate the memory and copy string to output variable + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, str.toCString(isUTF)); + return METADATA_EDITOR_ERROR_NONE; + } + else // Item was not found + { + metadata_editor_info("No item <%s> in file\n", itemname); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This function extracts integer value from item in MP4 tag *** // +static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemname, char** value) +{ + // Check if parameters are valid + if((_metadata == NULL)|| (itemname == NULL)) + { + metadata_editor_error("INVALID Parameter\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(value == NULL) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist.\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); + if(it != itemMap.end()) // Item was found + { + uint size = 20; + char buf[size]; + int num = it->second.toInt(); // Get integer value in item + snprintf(buf, size, "%u", num); // Convert int into char[] + // Determine the length of created c-string and copy it into the output variable + int length = strlen(buf); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, buf); + return METADATA_EDITOR_ERROR_NONE; + } + else // Item was not found + { + metadata_editor_info("No item <%s> in file\n", itemname); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This function adds (or changes) string item of itemname type *** // +static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value) +{ + // Check if parameters are valid + if((_metadata == NULL)|| (itemname == NULL)) + { + metadata_editor_error("INVALID Parameter\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag was not created.\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + // Check if it is a request for deletion + if((value == NULL) || value[0] == '\0') + { + metadata_editor_info("Request for deleting of item <%s>\n", itemname); + TagLib::MP4::ItemListMap::Iterator it = itemMap.find(itemname); + if(it != itemMap.end()) + itemMap.erase(it); + return METADATA_EDITOR_ERROR_NONE; + } + metadata_editor_info("The item <%s> will be added\n", itemname); + itemMap[itemname] = TagLib::MP4::Item(TagLib::String(value, TagLib::String::UTF8)); + return METADATA_EDITOR_ERROR_NONE; +} + +// *** This function adds (or changes) integer item of itemname type *** // +static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* itemname, const char* value) +{ + // Check if parameters are valid + if((_metadata == NULL) || (itemname == NULL)) + { + metadata_editor_error("INVALID Parameter\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag was not created.\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + // Check if it is a request for deletion + if((value == NULL) || value[0] == '\0') + { + metadata_editor_info("Request for deleting of item <%s>\n", itemname); + TagLib::MP4::ItemListMap::Iterator it = itemMap.find(itemname); + if(it != itemMap.end()) + itemMap.erase(it); + return METADATA_EDITOR_ERROR_NONE; + } + // Check if the value is integer string then it can be successfully converted into integer + if(isdigit(value[0])) + { + metadata_editor_info("The item <%s> will be added\n", itemname); + int number = atoi(value); + itemMap[itemname] = TagLib::MP4::Item(number); + return METADATA_EDITOR_ERROR_NONE; + } + else // Notify that string is not a number to process + { + metadata_editor_error("Error. String does not contain a number\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } +} + +// *** This function is used to find the number of pictures stored in MP4 file *** // +static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) +{ + // Check if parameters are valid + if(_metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if((value == NULL)) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); + if(it != itemMap.end()) // Item was found + { + uint number = it->second.toCoverArtList().size(); // Get the size of CoverList (i.e. number of pictures in file) + metadata_editor_info("There are %u picture(s) in file\n", number); + int size = 20; + char buf[size]; + snprintf(buf,size, "%u", number); // Convert integer value of size to its c-string representation + int length = strlen(buf); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, buf); + return METADATA_EDITOR_ERROR_NONE; + } + else // Item was not found + { + metadata_editor_info("No item in file\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This function is used to extract string from Xiph Comment field *** // +static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, char** value) +{ + // Check if we have a valid argument to work with + if((_metadata == NULL) || (fieldname == NULL)) + { + metadata_editor_error("INVALID Parameter\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(value == NULL) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + const TagLib::Ogg::FieldListMap& fieldMap = xtag->fieldListMap(); + TagLib::Ogg::FieldListMap::ConstIterator it = fieldMap.find(fieldname); + + if((xtag->contains(fieldname)) && (it != fieldMap.end())) // Field was found + { + metadata_editor_info("Field %s was found. Extracting\n", fieldname); + TagLib::String str = it->second[0]; // Get the first string in xiph field + // Check the encoding of the string (1252 or not) + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + // Get the length of the string and check if it is empty or not + uint length = strlen(str.toCString(isUTF)); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + // Allocate the memory and copy string to output variable + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, str.toCString(isUTF)); + return METADATA_EDITOR_ERROR_NONE; + } + else // Field was not found + { + metadata_editor_info("No field %s in Xiph Comment\n", fieldname); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } +} + +// *** This function is used to write string into Xiph Comment fields *** // +static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value) +{ + // Check if we have a valid argument to work with + if((_metadata == NULL) || (fieldname == NULL)) + { + metadata_editor_error("INVALID Parameter\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + // Check if it is a request for deletion + if((value == NULL) || value[0] == '\0') + { + metadata_editor_info("Request for deleting of field %s\n", fieldname); + xtag->removeField(fieldname); + return METADATA_EDITOR_ERROR_NONE; + } + metadata_editor_info("The field %s will be added\n", fieldname); + // "true" is used to remove other strings of the same "fieldname" first + xtag->addField(fieldname, TagLib::String(value,TagLib::String::UTF8), true); + return METADATA_EDITOR_ERROR_NONE; +} + +// *** This function is used to receive the number of pictures in FLAC file *** // +static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value) +{ + // Check if parameters are valid + if(_metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(value == NULL) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; + if(_file->pictureList().isEmpty()) + { + metadata_editor_info("No pictures in FLAC file\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_NONE; + } + uint number = _file->pictureList().size(); + metadata_editor_info("There are %u picture(s) in file\n", number); + int size = 20; + char buf[size]; + snprintf(buf,size, "%u", number); // Convert integer value of size to its c-string representation + int length = strlen(buf); + if(length == 0) + { + *value = NULL; + metadata_editor_info("Empty string...\n"); + return METADATA_EDITOR_ERROR_NONE; + } + *value = new char[length + 1]; + if(*value == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + strcpy(*value, buf); + return METADATA_EDITOR_ERROR_NONE; +} + +int __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int max_len) +{ + int i = 0; + + for (i = strlen(file_path); i >= 0; i--) + { + if ((file_path[i] == '.') && (i < strlen(file_path))) + { + strncpy(file_ext, &file_path[i + 1], max_len); + return 0; + } + + /* meet the dir. no ext */ + if (file_path[i] == '/') + { + return -1; + } + } + + return -1; +} + +int __metadata_editor_get_file_type(const char *path) +{ + int ret = 0; + char mimetype[255] = {0,}; + + /* get content type and mime type from file. */ + ret = aul_get_mime_from_file(path, mimetype, sizeof(mimetype)); + if (ret < 0) + { + metadata_editor_debug("aul_get_mime_from_file fail.. Now trying to get type by extension"); + + char ext[255] = { 0 }; + int ret = __metadata_editor_get_file_ext(path, ext, sizeof(ext)); + if (ret < 0) + { + metadata_editor_error("__metadata_editor_get_file_type failed"); + return METADATA_EDITOR_FORMAT_NOTYPE; + } + + if (strcasecmp(ext, "MP3") == 0) + { + return METADATA_EDITOR_FORMAT_MP3; + } + else if (strcasecmp(ext, "MP4") == 0) + { + return METADATA_EDITOR_FORMAT_MP4; + } + else + { + return METADATA_EDITOR_FORMAT_NOTYPE; + } + } + + metadata_editor_debug("mime type : %s", mimetype); + + /* categorize from mimetype */ + if (strstr(mimetype, "mpeg") != NULL) + { + return METADATA_EDITOR_FORMAT_MP3; + } + else if (strstr(mimetype, "mp4") != NULL) + { + return METADATA_EDITOR_FORMAT_MP4; + } + + return METADATA_EDITOR_FORMAT_NOTYPE; +} + +int __metadata_editor_get_picture_type(const char *path, char **type) +{ + int ret = 0; + char mimetype[255] = {0,}; + const char *type_jpeg = "image/jpeg"; + const char *type_png = "image/png"; + + /* get content type and mime type from file. */ + ret = aul_get_mime_from_file(path, mimetype, sizeof(mimetype)); + if (ret < 0) + { + metadata_editor_debug("aul_get_mime_from_file fail.. Now trying to get type by extension"); + + char ext[255] = { 0 }; + int ret = __metadata_editor_get_file_ext(path, ext, sizeof(ext)); + if (ret < 0) + { + metadata_editor_error("__metadata_editor_get_file_type failed"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + if (strcasecmp(ext, "JPG") == 0 || strcasecmp(ext, "JPEG") == 0) + { + *type = strndup(type_jpeg, strlen(type_jpeg)); + return METADATA_EDITOR_ERROR_NONE; + } + else if (strcasecmp(ext, "PNG") == 0) + { + *type = strndup(type_png, strlen(type_png)); + return METADATA_EDITOR_ERROR_NONE; + } + else + { + return METADATA_EDITOR_ERROR_NOT_SUPPORTED; + } + } + + metadata_editor_debug("mime type : %s", mimetype); + + /* categorize from mimetype */ + if (strstr(mimetype, "jpeg") != NULL) + { + *type = strndup(mimetype, strlen(mimetype)); + return METADATA_EDITOR_ERROR_NONE; + } + else if (strstr(mimetype, "png") != NULL) + { + *type = strndup(mimetype, strlen(mimetype)); + return METADATA_EDITOR_ERROR_NONE; + } + + return METADATA_EDITOR_ERROR_NOT_SUPPORTED; +} + +int __metadata_editor_get_picture_info(const char *path, void **picture, int *size, char **type) +{ + int ret; + + ret = __metadata_editor_get_picture_type(path, type); + if(ret != METADATA_EDITOR_ERROR_NONE) + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + + //IF ok.. read file + FILE* fin = fopen(path, "rb"); + int file_size = 0; + + if(fin) + { + while(fgetc(fin) != EOF) + { + file_size++; + } + fclose(fin); + char picture_buffer[file_size]; + fin = fopen(path, "rb"); + ret = fread(picture_buffer, file_size, 1, fin); + fclose(fin); + + *picture = malloc(file_size * sizeof(char)); + memset(*picture, 0, file_size * sizeof(char)); + memcpy(*picture, picture_buffer, file_size); + *size = file_size; + } + + return METADATA_EDITOR_ERROR_NONE; +} + +bool __metadata_editor_file_exist(const std::string& name) { + struct stat buffer; + return (stat (name.c_str(), &buffer) == 0); +} + + +// *** This function is used to allocate the metadata_editor_s in memory *** // +// *** The structure metadata_editor_s contains all information about the file *** // +extern "C" int metadata_editor_create(metadata_editor_h *metadata) +{ + // Check if we have a valid argument to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID PARAMETER\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_s *_metadata = new metadata_editor_s; // Allocate a structure for handler + if(_metadata == NULL) // Check if the structure was allocated successfully + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + + _metadata->file = NULL; + _metadata->filetype = METADATA_EDITOR_FORMAT_NOTYPE; // Specify file type out of range + _metadata->isOpen = false; // File is not opened yet + _metadata->isReadOnly = true; // Handle unexisting file as readonly + + // Save the structure in the metadata + *metadata = (metadata_editor_h)_metadata; + + return METADATA_EDITOR_ERROR_NONE; +} + +// *** This function is used to open the file. It creates the instance that is responsible for connection with file *** // +extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char *path) +{ + // Check if we have valid arguments to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(path == NULL) + { + metadata_editor_error("INVALID Path\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + if(!__metadata_editor_file_exist(path)) + { + metadata_editor_error("Not exist file\n"); + return METADATA_EDITOR_ERROR_FILE_EXISTS; + } + + metadata_editor_s *_metadata = (metadata_editor_s*)metadata; + int media_type; + + media_type = __metadata_editor_get_file_type(path); + + + + switch(media_type) // Parse file according the specified type + { + case METADATA_EDITOR_FORMAT_MP3: + { + // Allocate the file object in memory to work with it later on + TagLib::MPEG::File* _file = new TagLib::MPEG::File(path); + + if(_file == NULL) // Check if the file was allocated successfully + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + _metadata->file = _file; // Copy file pointer to the structure + + _metadata->filetype = METADATA_EDITOR_FORMAT_MP3; + + if (_file->isOpen()) // Check if the file was opened successfully + { + metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); + _metadata->isOpen = true; + } + else // The file does not exist or you have no permission to process it + { + metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); + _metadata->isOpen = false; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_file->readOnly()) // Check if the file is readonly + { + metadata_editor_info("File is readonly\n"); + _metadata->isReadOnly = true; + } + else // or not + { + metadata_editor_info("The file is writable\n"); + _metadata->isReadOnly = false; + } + return METADATA_EDITOR_ERROR_NONE; + } + case METADATA_EDITOR_FORMAT_MP4: + { + // Allocate the file object in memory to work with it later on + TagLib::MP4::File* _file = new TagLib::MP4::File(path); + + if(_file == NULL) // Check if the file was allocated successfully + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + _metadata->file = _file; // Copy file pointer to the structure + + _metadata->filetype = METADATA_EDITOR_FORMAT_MP4; + + if (_file->isOpen()) // Check if the file was opened successfully + { + metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); + _metadata->isOpen = true; + } + else // The file does not exist or you have no permission to process it + { + metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); + _metadata->isOpen = false; + return METADATA_EDITOR_ERROR_FILE_EXISTS; + } + if(_file->readOnly()) // Check if the file is readonly + { + metadata_editor_info("File is readonly\n"); + _metadata->isReadOnly = true; + } + else // or not + { + metadata_editor_info("The file is writable\n"); + _metadata->isReadOnly = false; + } + return METADATA_EDITOR_ERROR_NONE; + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + // Allocate the file object in memory to work with it later on + TagLib::FLAC::File* _file = new TagLib::FLAC::File(path); + + if(_file == NULL) // Check if the file was allocated successfully + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + _metadata->file = _file; // Copy file pointer to the structure + + _metadata->filetype = METADATA_EDITOR_FORMAT_FLAC; + + if (_file->isOpen()) // Check if the file was opened successfully + { + metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); + _metadata->isOpen = true; + } + else // The file does not exist or you have no permission to process it + { + metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); + _metadata->isOpen = false; + return METADATA_EDITOR_ERROR_FILE_EXISTS; + } + if(_file->readOnly()) // Check if the file is readonly + { + metadata_editor_info("File is readonly\n"); + _metadata->isReadOnly = true; + } + else // or not + { + metadata_editor_info("The file is writable\n"); + _metadata->isReadOnly = false; + } + return METADATA_EDITOR_ERROR_NONE; + } + case METADATA_EDITOR_FORMAT_OGG_VORBIS: + { + // Allocate the file object in memory to work with it later on + TagLib::Ogg::Vorbis::File* _file = new TagLib::Ogg::Vorbis::File(path); + + if(_file == NULL) // Check if the file was allocated successfully + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + _metadata->file = _file; // Copy file pointer to the structure + + _metadata->filetype = METADATA_EDITOR_FORMAT_OGG_VORBIS; + + if (_file->isOpen()) // Check if the file was opened successfully + { + metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); + _metadata->isOpen = true; + } + else // The file does not exist or you have no permission to process it + { + metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); + _metadata->isOpen = false; + return METADATA_EDITOR_ERROR_FILE_EXISTS; + } + if(_file->readOnly()) // Check if the file is readonly + { + metadata_editor_info("File is readonly\n"); + _metadata->isReadOnly = true; + } + else // or not + { + metadata_editor_info("The file is writable\n"); + _metadata->isReadOnly = false; + } + return METADATA_EDITOR_ERROR_NONE; + } + case METADATA_EDITOR_FORMAT_OGG_FLAC: + { + // Allocate the file object in memory to work with it later on + TagLib::Ogg::FLAC::File* _file = new TagLib::Ogg::FLAC::File(path); + + if(_file == NULL) // Check if the file was allocated successfully + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + _metadata->file = _file; // Copy file pointer to the structure + + _metadata->filetype = METADATA_EDITOR_FORMAT_OGG_FLAC; + + if (_file->isOpen()) // Check if the file was opened successfully + { + metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); + _metadata->isOpen = true; + } + else // The file does not exist or you have no permission to process it + { + metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); + _metadata->isOpen = false; + return METADATA_EDITOR_ERROR_FILE_EXISTS; + } + if(_file->readOnly()) // Check if the file is readonly + { + metadata_editor_info("File is readonly\n"); + _metadata->isReadOnly = true; + } + else // or not + { + metadata_editor_info("The file is writable\n"); + _metadata->isReadOnly = false; + } + return METADATA_EDITOR_ERROR_NONE; + } + case METADATA_EDITOR_FORMAT_WAV: + { + // Allocate the file object in memory to work with it later on + TagLib::RIFF::WAV::File* _file = new TagLib::RIFF::WAV::File(path); + + if(_file == NULL) // Check if the file was allocated successfully + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + _metadata->file = _file; // Copy file pointer to the structure + + _metadata->filetype = METADATA_EDITOR_FORMAT_WAV; + + if (_file->isOpen()) // Check if the file was opened successfully + { + metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); + _metadata->isOpen = true; + } + else // The file does not exist or you have no permission to process it + { + metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); + _metadata->isOpen = false; + return METADATA_EDITOR_ERROR_FILE_EXISTS; + } + if(_file->readOnly()) // Check if the file is readonly + { + metadata_editor_info("File is readonly\n"); + _metadata->isReadOnly = true; + } + else // or not + { + metadata_editor_info("The file is writable\n"); + _metadata->isReadOnly = false; + } + return METADATA_EDITOR_ERROR_NONE; + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + return METADATA_EDITOR_ERROR_NOT_SUPPORTED; + } +} + +// *** This function is used to get the tag frame (field, item - each tag has its own name for data unit) from file *** // +extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, char **value) +{ + // Check if we have valid arguments to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if(value == NULL) + { + metadata_editor_error("INVALID Value Pointer\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_s *_metadata = (metadata_editor_s*)metadata; + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + switch(_metadata->filetype) // Process the file according to the specified file type + { + case METADATA_EDITOR_FORMAT_MP3: + { + // Bring the pointer to actual file type and make tag pointers + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; + TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); + TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(); + + switch (attribute) // Check which one of frame types was given to the function for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(_metadata, tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(_metadata, tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(_metadata, tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "COMM", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(_metadata, tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(_metadata, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); + default: + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_MP4: + { + switch(attribute) // Check which one of frame types was given to the function for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __MP4_getStringItem(_metadata, "\xA9""ART", value); + case METADATA_EDITOR_ATTR_TITLE: return __MP4_getStringItem(_metadata, "\xA9""nam", value); + case METADATA_EDITOR_ATTR_ALBUM: return __MP4_getStringItem(_metadata, "\xA9""alb", value); + case METADATA_EDITOR_ATTR_GENRE: return __MP4_getStringItem(_metadata, "\xA9""gen", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __MP4_getStringItem(_metadata, "\xA9""wrt", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __MP4_getStringItem(_metadata, "cprt", value); + case METADATA_EDITOR_ATTR_DATE: return __MP4_getStringItem(_metadata, "\xA9""day", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __MP4_getStringItem(_metadata, "desc", value); + case METADATA_EDITOR_ATTR_COMMENT: return __MP4_getStringItem(_metadata, "\xA9""cmt", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __MP4_getIntegerItem(_metadata, "trkn", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __MP4_getStringItem(_metadata, "cond", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_getStringItem(_metadata, "\xA9""lyr", value); + case METADATA_EDITOR_ATTR_PICTURE_NUM: return __MP4_getNumberOfPictures(_metadata, value); + default: + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; + TagLib::Ogg::XiphComment* xtag = _file->xiphComment(false); + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + switch(attribute) // Check which one of frame types was given to the function for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(_metadata, xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(_metadata, xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(_metadata, xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(_metadata, xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(_metadata, xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(_metadata, xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(_metadata, xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(_metadata, xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(_metadata, xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(_metadata, xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(_metadata, xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(_metadata, xtag, "LYRICS", value); + case METADATA_EDITOR_ATTR_PICTURE_NUM: return __FLAC_getNumberOfPictures(_metadata, value); + default: + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_OGG_VORBIS: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; + TagLib::Ogg::XiphComment* xtag = _file->tag(); + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + switch(attribute) // Check which one of frame types was given to the function for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(_metadata, xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(_metadata, xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(_metadata, xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(_metadata, xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(_metadata, xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(_metadata, xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(_metadata, xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(_metadata, xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(_metadata, xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(_metadata, xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(_metadata, xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(_metadata, xtag, "LYRICS", value); + default: + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_OGG_FLAC: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; + TagLib::Ogg::XiphComment* xtag = _file->tag(); + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + switch(attribute) // Check which one of frame types was given to the function for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(_metadata, xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(_metadata, xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(_metadata, xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_getFieldValue(_metadata, xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_getFieldValue(_metadata, xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_getFieldValue(_metadata, xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_getFieldValue(_metadata, xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_getFieldValue(_metadata, xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_getFieldValue(_metadata, xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_getFieldValue(_metadata, xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(_metadata, xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(_metadata, xtag, "LYRICS", value); + default: + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_WAV: + { + // Bring the pointer to actual file type and make tag pointers + TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; + TagLib::ID3v2::Tag* tag2 = _file->tag(); + + if(tag2 == NULL) // Check if we have a valid tag for processing + { + metadata_editor_error("Error. ID3v2 tag does not exist. Can not proceed metadata extraction\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + switch (attribute) // Check which one of frame types was given to the function for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getFrameByName(_metadata, tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_getFrameByName(_metadata, tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getFrameByName(_metadata, tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_getFrameByName(_metadata, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_getFrameByName(_metadata, tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_getFrameByName(_metadata, tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_getFrameByName(_metadata, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_getFrameByName(_metadata, tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_getFrameByName(_metadata, tag2, "COMM", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getFrameByName(_metadata, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(_metadata, tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(_metadata, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); + default: + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + *value = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } +} + +// *** This function is used to modify the metadata (frame in tag). But it does not apply changes to file *** // +extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, const char* value) +{ + // Check if we have valid arguments to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + switch(_metadata->filetype) // Process the file according to the specified file type + { + case METADATA_EDITOR_FORMAT_MP3: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; + TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); + TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); + + if(tag2 == NULL) // Check if the valid tag pointer exist + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + switch (attribute) // Check which one of frame type was given for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(_metadata, tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(_metadata, tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(_metadata, tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(_metadata, tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(_metadata, tag1, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(_metadata, tag2, value); + default: + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_MP4: + { + switch(attribute) // Check which one of frame type was given for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __MP4_updateStringItem(_metadata, "\xA9""ART", value); + case METADATA_EDITOR_ATTR_TITLE: return __MP4_updateStringItem(_metadata, "\xA9""nam", value); + case METADATA_EDITOR_ATTR_ALBUM: return __MP4_updateStringItem(_metadata, "\xA9""alb", value); + case METADATA_EDITOR_ATTR_GENRE: return __MP4_updateStringItem(_metadata, "\xA9""gen", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __MP4_updateStringItem(_metadata, "\xA9""wrt", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __MP4_updateStringItem(_metadata, "cprt", value); + case METADATA_EDITOR_ATTR_DATE: return __MP4_updateStringItem(_metadata, "\xA9""day", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __MP4_updateStringItem(_metadata, "desc", value); + case METADATA_EDITOR_ATTR_COMMENT: return __MP4_updateStringItem(_metadata, "\xA9""cmt", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __MP4_updateIntegerItem(_metadata, "trkn", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __MP4_updateStringItem(_metadata, "cond", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_updateStringItem(_metadata, "\xA9""lyr", value); + default: + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; + TagLib::Ogg::XiphComment* xtag = _file->xiphComment(true); + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + switch(attribute) // Check which one of frame type was given for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(_metadata, xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(_metadata, xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(_metadata, xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(_metadata, xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(_metadata, xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(_metadata, xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(_metadata, xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(_metadata, xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(_metadata, xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(_metadata, xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(_metadata, xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(_metadata, xtag, "LYRICS", value); + default: + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_OGG_VORBIS: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; + TagLib::Ogg::XiphComment* xtag = _file->tag(); + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + switch(attribute) // Check which one of frame type was given for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(_metadata, xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(_metadata, xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(_metadata, xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(_metadata, xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(_metadata, xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(_metadata, xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(_metadata, xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(_metadata, xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(_metadata, xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(_metadata, xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(_metadata, xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(_metadata, xtag, "LYRICS", value); + default: + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_OGG_FLAC: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; + TagLib::Ogg::XiphComment* xtag = _file->tag(); + if(!xtag) // Check if we have a valid tag for processing + { + metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + switch(attribute) // Check which one of frame type was given for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(_metadata, xtag, "ARTIST", value); + case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(_metadata, xtag, "TITLE", value); + case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(_metadata, xtag, "ALBUM", value); + case METADATA_EDITOR_ATTR_GENRE: return __xiph_updateFieldValue(_metadata, xtag, "GENRE", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __xiph_updateFieldValue(_metadata, xtag, "COMPOSER", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __xiph_updateFieldValue(_metadata, xtag, "COPYRIGHT", value); + case METADATA_EDITOR_ATTR_DATE: return __xiph_updateFieldValue(_metadata, xtag, "DATE", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __xiph_updateFieldValue(_metadata, xtag, "DESCRIPTION", value); + case METADATA_EDITOR_ATTR_COMMENT: return __xiph_updateFieldValue(_metadata, xtag, "COMMENT", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __xiph_updateFieldValue(_metadata, xtag, "TRACKNUMBER", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_updateFieldValue(_metadata, xtag, "CONDUCTOR", value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_updateFieldValue(_metadata, xtag, "LYRICS", value); + default: + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } + case METADATA_EDITOR_FORMAT_WAV: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; + TagLib::ID3v2::Tag* tag2 = _file->tag(); + // Check if the valid tag pointer exist + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + switch (attribute) // Check which one of frame type was given for processing + { + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setFrameByName(_metadata, tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_setFrameByName(_metadata, tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setFrameByName(_metadata, tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_setFrameByName(_metadata, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(_metadata, tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(_metadata, tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_setFrameByName(_metadata, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(_metadata, tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setFrameByName(_metadata, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(_metadata, tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(_metadata, NULL, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(_metadata, tag2, value); + default: + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } +} + +// *** This function apply all changes done in the tag(s) and update them to file *** // +extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) +{ + // Check if we have a valid argument to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_s *_metadata = (metadata_editor_s*)metadata; + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + switch(_metadata->filetype) // Process the file according to the specified file type + { + case METADATA_EDITOR_FORMAT_MP3: + { + // Bring the pointer to actual file type + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; + + TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); + + if(!tag1 || tag1->isEmpty()) // If no ID3v1 tag - prevent its creation + { + if(_file->save(TagLib::MPEG::File::ID3v2 | TagLib::MPEG::File::APE)) + return METADATA_EDITOR_ERROR_NONE; + else + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + else // otherwise - save all tags in file + { + if(_file->save(TagLib::MPEG::File::AllTags)) + return METADATA_EDITOR_ERROR_NONE; + else + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + } + case METADATA_EDITOR_FORMAT_MP4: + { + TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; + if(_file->save()) + return METADATA_EDITOR_ERROR_NONE; + else + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; + if(_file->save()) + return METADATA_EDITOR_ERROR_NONE; + else + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + case METADATA_EDITOR_FORMAT_OGG_VORBIS: + { + TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; + if(_file->save()) + return METADATA_EDITOR_ERROR_NONE; + else + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + case METADATA_EDITOR_FORMAT_OGG_FLAC: + { + TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; + if(_file->save()) + return METADATA_EDITOR_ERROR_NONE; + else + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + case METADATA_EDITOR_FORMAT_WAV: + { + TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; + if(_file->save()) + return METADATA_EDITOR_ERROR_NONE; + else + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } +} + +// *** This function returns buffer with picture under the specified index and buffer's (picture's) size *** // +extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index, void **picture, int *size, char **mime_type) +{ + const char *TYPE_JPEG = "image/jpeg"; + const char *TYPE_PNG = "image/png"; + // Check if we have valid arguments to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + if((picture == NULL) || (size == NULL)) + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + + metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + switch(_metadata->filetype) // Process the file according to the specified file type + { + case METADATA_EDITOR_FORMAT_MP3: + { + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; // Bring the pointer to actual file type + TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(); + if(!tag2) + { + metadata_editor_error("No ID3v2 tag in file\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; + // Check if there are pictures in the tag + if(lst.isEmpty()) + { + metadata_editor_error("No pictures in file\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + else // pictures exist in file + { + // Check if index is correct or not + if( (index < 0) || (lst.size() <= (uint)index) ) + { + metadata_editor_error("Index of picture is out of range\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // everything is correct - begin extraction + { + metadata_editor_info("There are %u pictures in file. Start of picture number %d extraction", lst.size(), index); + int i = 0; + // Among all frames we must choose that one with specified index. "i" will be counter + for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) + { + if(i != index) continue; + TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); + uint pictureSize = pictureFrame->picture().size(); + if(pictureSize == 0) + { + *picture = NULL; *size = 0; *mime_type = NULL; + metadata_editor_error("Size of picture is 0\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + *picture = new char[pictureSize]; + if(*picture == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + memcpy(*picture, pictureFrame->picture().data(), pictureSize); + *size = pictureSize; + TagLib::String mime = pictureFrame->mimeType(); + if(!strcmp(mime.toCString(),"image/jpeg")) + *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); + else if(!strcmp(mime.toCString(),"image/png")) + *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); + else + *mime_type = NULL; + break; + } + return METADATA_EDITOR_ERROR_NONE; + } + } + } + case METADATA_EDITOR_FORMAT_MP4: + { + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); + if(it != itemMap.end()) // Item was found + { + TagLib::MP4::CoverArtList lst = it->second.toCoverArtList(); + // Check if the index is in range of CoverArtList Item + if((index < 0) || ((uint)index >= lst.size())) // it is not + { + metadata_editor_error("Index of picture is out of range\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // index is in range + { + int i = 0; + for(TagLib::MP4::CoverArtList::ConstIterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) + { + if(i != index) continue; + int pictureSize = picIt->data().size(); + if(pictureSize == 0) + { + *picture = NULL; *size = 0; *mime_type = NULL; + metadata_editor_error("Size of picture is 0\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + *picture = new char[pictureSize]; + if(*picture == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + memcpy(*picture, picIt->data().data(), pictureSize); + *size = pictureSize; + if(picIt->format() == TagLib::MP4::CoverArt::JPEG) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); + else if(picIt->format() == TagLib::MP4::CoverArt::PNG) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); + else *mime_type = NULL; + break; + } + return METADATA_EDITOR_ERROR_NONE; + } + } + else // Item was not found - no pictures in file + { + metadata_editor_error("No item in file. No pictures in file\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; + TagLib::List lst = _file->pictureList(); + if(lst.isEmpty()) + { + metadata_editor_error("No pictures in FLAC file\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + else + { + // Check if the index is in range of CoverArtList Item + if((index < 0) || ((uint)index >= lst.size())) // it is not + { + metadata_editor_error("Index of picture is out of range\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // index is in range + { + // Consecutive check of all pictures until the desired one is found + int i = 0; + for(TagLib::List::ConstIterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) + { + if(i != index) continue; + // picture can be received as ByteVector (picIt->data()). + // ByteVector has data() - picture itself and size() - the size of picture in data() method + int pictureSize = (*picIt)->data().size(); + if(pictureSize == 0) + { + *picture = NULL; *size = 0; *mime_type = NULL; + metadata_editor_error("Size of picture is 0\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + *picture = new char[pictureSize]; + if(*picture == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + memcpy(*picture, (*picIt)->data().data(), pictureSize); + *size = pictureSize; + TagLib::String mime = (*picIt)->mimeType(); + if(!strcmp(mime.toCString(),"image/jpeg")) + *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); + else if(!strcmp(mime.toCString(),"image/png")) + *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); + else + *mime_type = NULL; + break; + } + return METADATA_EDITOR_ERROR_NONE; + } + } + } + case METADATA_EDITOR_FORMAT_WAV: + { + TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; // Bring the pointer to actual file type + TagLib::ID3v2::Tag* tag2 = _file->tag(); + if(!tag2) + { + metadata_editor_error("No ID3v2 tag in file\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; + // Check if there are pictures in the tag + if(lst.isEmpty()) + { + metadata_editor_error("No pictures in file\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + else // pictures exist in file + { + // Check if index is correct or not + if( (index < 0) || (lst.size() <= (uint)index) ) + { + metadata_editor_error("Index of picture is out of range\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // everything is correct - begin extraction + { + metadata_editor_info("There are %u pictures in file. Start of picture number %d extraction", lst.size(), index); + int i = 0; + // Among all frames we must choose that one with specified index. "i" will be counter + for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) + { + if(i != index) continue; + TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); + uint pictureSize = pictureFrame->picture().size(); + if(pictureSize == 0) + { + *picture = NULL; *size = 0; *mime_type = NULL; + metadata_editor_error("Size of picture is 0\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + *picture = new char[pictureSize]; + if(*picture == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + memcpy(*picture, pictureFrame->picture().data(), pictureSize); + *size = pictureSize; + TagLib::String mime = pictureFrame->mimeType(); + if(!strcmp(mime.toCString(),"image/jpeg")) + *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); + else if(!strcmp(mime.toCString(),"image/png")) + *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); + else + *mime_type = NULL; + break; + } + return METADATA_EDITOR_ERROR_NONE; + } + } + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + *picture = NULL; *size = 0; *mime_type = NULL; + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } +} + +// *** This function appends a cover art picture to the file *** // +extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const char *path) +{ + // Check if we have valid arguments to work with + if((metadata == NULL) || (path == NULL)) + { + metadata_editor_error("INVALID Parameter\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + int ret; + void *picture; + int size; + char *type; + + ret = __metadata_editor_get_picture_info(path, &picture, &size, &type); + if(ret != METADATA_EDITOR_ERROR_NONE) { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + + switch(_metadata->filetype) // Process the file according to the specified file type + { + case METADATA_EDITOR_FORMAT_MP3: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; + TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); + // Check if the valid tag pointer exists + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + TagLib::ID3v2::AttachedPictureFrame* pictureFrame = new TagLib::ID3v2::AttachedPictureFrame(); + if(pictureFrame == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + metadata_editor_info("New APIC frame will be added to the ID3v2 tag\n"); + pictureFrame->setPicture(TagLib::ByteVector((char*)picture, size)); + pictureFrame->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover); + pictureFrame->setMimeType(type); + + tag2->addFrame(pictureFrame); + return METADATA_EDITOR_ERROR_NONE; + } + case METADATA_EDITOR_FORMAT_MP4: + { + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag was not created\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); + if(it != itemMap.end()) // Item was found + { + metadata_editor_info("The item exists. Adding picture\n"); + TagLib::MP4::CoverArtList lst = it->second.toCoverArtList(); + TagLib::MP4::CoverArt::Format format; + if(strncmp(type, "image/jpeg", strlen("image/jpeg")) == 0) + format = TagLib::MP4::CoverArt::JPEG; + else if(strncmp(type, "image/png", strlen("image/jpeg")) == 0) + format = TagLib::MP4::CoverArt::PNG; + else + format = (TagLib::MP4::CoverArt::Format)0xFFFF; + TagLib::MP4::CoverArt cover(format, TagLib::ByteVector((char*)picture, size)); + lst.append(cover); + itemMap.insert("covr", TagLib::MP4::Item(lst)); + return METADATA_EDITOR_ERROR_NONE; + } + else // Item was not found + { + metadata_editor_info("The item does not exist. Adding picture\n"); + TagLib::MP4::CoverArt::Format format; + if(strncmp(type, "image/jpeg", strlen("image/jpeg")) == 0) + format = TagLib::MP4::CoverArt::JPEG; + else if(strncmp(type, "image/png", strlen("image/jpeg")) == 0) + format = TagLib::MP4::CoverArt::PNG; + else + format = (TagLib::MP4::CoverArt::Format)0xFFFF; + TagLib::MP4::CoverArt cover(format, TagLib::ByteVector((char*)picture, size)); + TagLib::MP4::CoverArtList lst; + lst.append(cover); + itemMap.insert("covr", TagLib::MP4::Item(lst)); + return METADATA_EDITOR_ERROR_NONE; + } + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; + TagLib::FLAC::Picture* frontCover = new TagLib::FLAC::Picture; + if(frontCover == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + frontCover->setData(TagLib::ByteVector((char*)picture, size)); + frontCover->setType(TagLib::FLAC::Picture::FrontCover); + frontCover->setMimeType(type); + + metadata_editor_info("Picture will be added to FLAC file\n"); + _file->addPicture(frontCover); + return METADATA_EDITOR_ERROR_NONE; + } + case METADATA_EDITOR_FORMAT_WAV: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; + TagLib::ID3v2::Tag* tag2 = _file->tag(); + // Check if the valid tag pointer exists + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + TagLib::ID3v2::AttachedPictureFrame* pictureFrame = new TagLib::ID3v2::AttachedPictureFrame(); + if(pictureFrame == NULL) + { + metadata_editor_error("OUT_OF_MEMORY\n"); + return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + } + metadata_editor_info("New APIC frame will be added to the ID3v2 tag\n"); + pictureFrame->setPicture(TagLib::ByteVector((char*)picture, size)); + pictureFrame->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover); + pictureFrame->setMimeType(type); + tag2->addFrame(pictureFrame); + return METADATA_EDITOR_ERROR_NONE; + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + return METADATA_EDITOR_ERROR_NOT_SUPPORTED; + } +} + +// *** This function is used to delete picture with specified index *** // +extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int index) +{ + // Check if we have a valid argument to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID Parameter\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + + // Check if the file, given through metadata, exists and is opened correctly + if(_metadata->file && _metadata->isOpen == false) + { + metadata_editor_error("File does not exist or you have no rights to open it\n"); + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } + if(_metadata->isReadOnly) // Check if the file is writable or it is readonly + { + metadata_editor_error("File is readonly. Unable to modify\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + switch(_metadata->filetype) // Process the file according to the specified file type + { + case METADATA_EDITOR_FORMAT_MP3: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; + TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); + // Check if the valid tag pointer exists + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag does not exist. Can not remove picture\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; + // Check if there are pictures in the tag + if(lst.isEmpty()) + { + metadata_editor_error("No pictures in file\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + else // pictures exist in file + { + // Check if index is correct or not + if( (index < 0) || (lst.size() <= (uint)index) ) + { + metadata_editor_error("Index of picture is out of range\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // everything is correct - begin extraction + { + metadata_editor_info("Removing of picture number %d\n", index); + int i = 0; + // Among all frames we must choose that one with specified index. "i" will be counter + for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) + { + if(i != index) continue; + tag2->removeFrame(*it); + break; + } + return METADATA_EDITOR_ERROR_NONE; + } + } + } + case METADATA_EDITOR_FORMAT_MP4: + { + TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; + TagLib::MP4::Tag* tag = _file->tag(); + if(!tag) // Check if we have a valid tag for processing + { + metadata_editor_error("Tag does not exist\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + + // Get map of items directly from tag and launch a search of specific item + TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); + TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); + if(it != itemMap.end()) // Item was found + { + TagLib::MP4::CoverArtList lst = it->second.toCoverArtList(); + // Check if the index is in range of CoverArtList Item + if((index < 0) || ((uint)index >= lst.size())) // it is not + { + metadata_editor_error("Index of picture is out of range\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // index is in range + { + metadata_editor_info("The picture number %d will be deleted\n", index); + int i = 0; + for(TagLib::MP4::CoverArtList::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) + { + if(i != index) continue; + lst.erase(picIt); + break; + } + itemMap.insert("covr", TagLib::MP4::Item(lst)); + return METADATA_EDITOR_ERROR_NONE; + } + } + else // Item was not found + { + metadata_editor_error("The item does not exist. Nothing to delete\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; + TagLib::List lst = _file->pictureList(); + if(lst.isEmpty()) + { + metadata_editor_error("No pictures in file. Nothing to delete\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + // Check if the index is in range of CoverArtList Item + if((index < 0) || ((uint)index >= lst.size())) // it is not + { + metadata_editor_error("Index of picture is out of range\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // index is in range + { + metadata_editor_info("The picture number %d will be deleted\n", index); + int i = 0; + for(TagLib::List::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) + { + if(i != index) continue; + _file->removePicture(*picIt,true); + break; + } + return METADATA_EDITOR_ERROR_NONE; + } + } + case METADATA_EDITOR_FORMAT_WAV: + { + // Bring the pointer to actual file type and make tags pointers + TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; + TagLib::ID3v2::Tag* tag2 = _file->tag(); + // Check if the valid tag pointer exists + if(tag2 == NULL) + { + metadata_editor_error("Error. ID3v2 tag does not exist. Can not remove picture\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; + // Check if there are pictures in the tag + if(lst.isEmpty()) + { + metadata_editor_error("No pictures in file\n"); + return METADATA_EDITOR_ERROR_OPERATION_FAILED; + } + else // pictures exist in file + { + // Check if index is correct or not + if( (index < 0) || (lst.size() <= (uint)index) ) + { + metadata_editor_error("Index of picture is out of range\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + else // everything is correct - begin extraction + { + metadata_editor_info("Removing of picture number %d\n", index); + int i = 0; + // Among all frames we must choose that one with specified index. "i" will be counter + for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) + { + if(i != index) continue; + tag2->removeFrame(*it); + break; + } + return METADATA_EDITOR_ERROR_NONE; + } + } + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } +} + +// *** This function is used to free memory that was allocated with metadata_editor_create(...) and metadata_editor_set_path(...) functions *** // +extern "C" int metadata_editor_destroy(metadata_editor_h metadata) +{ + // Check if we have a valid argument to work with + if(metadata == NULL) + { + metadata_editor_error("INVALID Handle\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_s *_metadata = (metadata_editor_s*)metadata; + + switch(_metadata->filetype) + { + case METADATA_EDITOR_FORMAT_MP3: + { + // Bring the pointer to actual file type + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; + metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + delete _file; + break; + } + case METADATA_EDITOR_FORMAT_MP4: + { + TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; + metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + delete _file; + break; + } +#if 0 + case METADATA_EDITOR_FORMAT_FLAC: + { + TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; + metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + delete _file; + break; + } + case METADATA_EDITOR_FORMAT_OGG_VORBIS: + { + TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; + metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + delete _file; + break; + } + case METADATA_EDITOR_FORMAT_OGG_FLAC: + { + TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; + metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + delete _file; + break; + } + case METADATA_EDITOR_FORMAT_WAV: + { + TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; + metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + delete _file; + break; + } +#endif + default: + metadata_editor_error("Wrong file type\n"); + return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + } + + metadata_editor_info(" with address %lX will be freed\n", metadata); + delete _metadata; + + return METADATA_EDITOR_ERROR_NONE; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 0000000..a2e3764 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,18 @@ +SET(fw_test "${fw_name}-test") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_test} REQUIRED dlog) + +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -pie") + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + ADD_EXECUTABLE(${src_name} ${src}) + TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) +ENDFOREACH() diff --git a/test/metadata_editor_test.c b/test/metadata_editor_test.c new file mode 100755 index 0000000..0816bcf --- /dev/null +++ b/test/metadata_editor_test.c @@ -0,0 +1,467 @@ +/* +* Copyright (c) 2013 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 + +#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}} + +int dummy; + +void __flush(); +void __printRetValue(const char* func_name, int result); +static bool __get_tag_info(metadata_editor_h metadata); +static bool __write_tag_info(metadata_editor_h metadata); +static bool __add_picture(metadata_editor_h metadata); +static bool __delete_pictures(metadata_editor_h metadata); + +void __flush() +{ + char c; + while((c = getc(stdin)) != '\n'); +} + +void __printRetValue(const char* func_name, int result) +{ + printf("In function %s result is ", func_name); + if(result == METADATA_EDITOR_ERROR_NONE) printf("METADATA_EDITOR_ERROR_NONE\n"); + else if(result == METADATA_EDITOR_ERROR_INVALID_PARAMETER) printf("METADATA_EDITOR_ERROR_INVALID_PARAMETER\n"); + else if(result == METADATA_EDITOR_ERROR_OUT_OF_MEMORY) printf("METADATA_EDITOR_ERROR_OUT_OF_MEMORY\n"); + else if(result == METADATA_EDITOR_ERROR_FILE_EXISTS) printf("METADATA_EDITOR_ERROR_FILE_EXISTS\n"); + else if(result == METADATA_EDITOR_ERROR_OPERATION_FAILED) printf("METADATA_EDITOR_ERROR_OPERATION_FAILED\n"); + else printf("Unallowed value. Error!\n"); +} + +static bool __get_tag_info(metadata_editor_h metadata) +{ + int ret = METADATA_EDITOR_ERROR_NONE; + + char *artist = NULL; + char *title = NULL; + char *album = NULL; + char *genre = NULL; + char *composer = NULL; + char *copyright = NULL; + char *date = NULL; + char *description = NULL; + char *comment = NULL; + char *track_num = NULL; + char* picture_index = NULL; + int picture_size = 0; + char *picture_type = NULL; + void *picture = NULL; + char *conductor = NULL; + char *lyric = NULL; + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_ARTIST, &artist); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("1. - artist = [%s]\n", artist); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_TITLE, &title); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("2. - title = [%s]\n", title); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_ALBUM, &album); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("3. - album = [%s]\n", album); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_GENRE, &genre); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("4. - genre = [%s]\n", genre); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_AUTHOR, &composer); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("5. - composer = [%s]\n", composer); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_COPYRIGHT, ©right); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("6. - copyright = [%s]\n", copyright); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_DATE, &date); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("7. - date = [%s]\n", date); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_DESCRIPTION, &description); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("8. - description = [%s]\n", description); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_COMMENT, &comment); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("9. - comment = [%s]\n", comment); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_TRACK_NUM, &track_num); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("10. - track_num = [%s]\n", track_num); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_PICTURE_NUM, &picture_index); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + printf("Picture index is [%s]\n", picture_index); +#if 0 + if((filetype == METADATA_EDITOR_TYPE_OGG_VORBIS) || (filetype == METADATA_EDITOR_TYPE_OGG_FLAC)) + { + if(ret != METADATA_EDITOR_ERROR_INVALID_PARAMETER) + printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + } + else + { +#endif + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + else if((ret == METADATA_EDITOR_ERROR_NONE) && picture_index) + { + uint num, i; + num = atoi(picture_index); + printf("Number of pictures: %u\n", num); + for(i = 0; i < num; ++i) + { + ret = metadata_editor_get_picture(metadata, i, &picture, &picture_size, &picture_type); + //__printRetValue("metadata_editor_get_picture(...)", ret); + if(ret == METADATA_EDITOR_ERROR_NONE && picture) + { + printf("Saving picture number %u\n", i); + int size = 30; + char picture_file_name[size]; + snprintf(picture_file_name, size, "outputFile_%u" ,i+1); + if(strncmp(picture_type, "image/jpeg", strlen("image/jpeg")) == 0) strcat(picture_file_name,".jpg"); + else if(strncmp(picture_type, "image/png", strlen("image/jpeg")) == 0) strcat(picture_file_name,".png"); + FILE * fout = fopen(picture_file_name, "wb"); + fwrite(picture, picture_size, 1, fout); + fclose(fout); + } + else + printf("Error occured while picture extraction\n"); + } + free(picture_index); + } +#if 0 + } +#endif + printf("11. - picture size = [%u]\n", picture_size); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_CONDUCTOR, &conductor); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("12. - conductor = [%s]\n", conductor); + + ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_UNSYNCLYRICS, &lyric); + //__printRetValue("metadata_editor_get_metadata(...)",ret); + if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + printf("13. - lyric = [%s]\n", lyric); + + SAFE_FREE(artist); + SAFE_FREE(title); + SAFE_FREE(album); + SAFE_FREE(genre); + SAFE_FREE(composer); + SAFE_FREE(copyright); + SAFE_FREE(date); + SAFE_FREE(description); + SAFE_FREE(comment); + SAFE_FREE(track_num); + SAFE_FREE(picture); + SAFE_FREE(conductor); + SAFE_FREE(lyric); + + return true; +} + +static bool __write_tag_info(metadata_editor_h metadata) +{ + + char input_data[400]; + + printf("\n==========================================="); + printf("\nPlease, type in the following tag data: "); + printf("\n===========================================\n"); + + printf("\n 1. - Writing artist: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_ARTIST, input_data); + *input_data = '\0'; + printf("2. - Writing title: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_TITLE, input_data); + *input_data = '\0'; + printf("3. - Writing album: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_ALBUM, input_data); + *input_data = '\0'; + printf("4. - Writing genre: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_GENRE, input_data); + *input_data = '\0'; + printf("5. - Writing composer: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_AUTHOR, input_data); + *input_data = '\0'; + printf("6. - Writing copyright: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_COPYRIGHT, input_data); + *input_data = '\0'; + printf("7. - Writing year: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_DATE, input_data); + *input_data = '\0'; + printf("8. - Writing description: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_DESCRIPTION, input_data); + *input_data = '\0'; + printf("9. - Writing track: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_TRACK_NUM, input_data); + *input_data = '\0'; + printf("10. - Writing comment: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_COMMENT, input_data); + *input_data = '\0'; + printf("11. - Writing conductor: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_CONDUCTOR, input_data); + *input_data = '\0'; + printf("12. - Writing lyrics: "); + dummy = scanf("%[^\n]",input_data); + __flush(); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_UNSYNCLYRICS,input_data); + *input_data = '\0'; + + metadata_editor_update_metadata(metadata); + + return true; +} + +static bool __delete_tag_info(metadata_editor_h metadata) +{ + printf("\n 1. - Deleting artist: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_ARTIST, ""); + printf("\n 2. - Deleting title: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_TITLE, 0); + printf("\n 3. - Deleting album: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_ALBUM, ""); + printf("\n 4. - Deleting genre: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_GENRE, 0); + printf("\n 5. - Deleting composer: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_AUTHOR, ""); + printf("\n 6. - Deleting copyright: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_COPYRIGHT, 0); + printf("\n 7. - Deleting year: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_DATE, ""); + printf("\n 8. - Deleting description: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_DESCRIPTION, 0); + printf("\n 9. - Deleting track: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_TRACK_NUM, ""); + printf("\n 10. - Deleting comment: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_COMMENT, 0); + printf("\n 11. - Deleting conductor: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_CONDUCTOR, ""); + printf("\n 12. - Deleting lyrics: "); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_UNSYNCLYRICS, 0); + + metadata_editor_update_metadata(metadata); + return true; +} + +static bool __add_picture(metadata_editor_h metadata) +{ + uint c2 = 0; + char *picture_filename = NULL; + + printf("\n============================="); + printf("\n Choose picture: PNG or JPG "); + printf("\n============================="); + printf("\n | TestImage.png -> 1 | "); + printf("\n | TestImage.jpg -> 2 | "); + printf("\n Your choice : "); + + dummy = scanf("%u", &c2); + __flush(); + + switch (c2) + { + case 1: + printf("\n==========================="); + printf("\n Your choice is TestImage.png\n"); + picture_filename = "TestImage.png"; + break; + + case 2: + printf("\n==========================="); + printf("\n Your choice is TestImage.jpg\n"); + picture_filename = "TestImage.jpg"; + break; + } + + metadata_editor_append_picture(metadata, picture_filename); + + return true; +} + +static bool __delete_pictures(metadata_editor_h metadata) +{ + uint num, i; + char *picture_index = NULL; + + metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_PICTURE_NUM, &picture_index); + printf("The number of pictures is [%s]\n", picture_index); + + if(picture_index) + { + num = atoi(picture_index); + printf("Number of pictures: %u\n", num); + + for(i = 0; i < num; ++i) + { + metadata_editor_remove_picture(metadata, 0); + //__printRetValue("metadata_editor_remove_picture(...)", ret); + } + } + else + printf("There are no pictures to delete\n"); + return true; +} + +static bool __save_tags(metadata_editor_h metadata) +{ + + metadata_editor_update_metadata(metadata); + + return true; +} + + +int main(int argc, char *argv[]) +{ + int ret = METADATA_EDITOR_ERROR_NONE; + metadata_editor_h metadata = NULL; + int cnt = argc -1; + uint c2 = 0; + + if(cnt < 1) + { + printf("\n===================================================================================================="); + printf("\n Please type file path and media type as media-metadata-test /opt/usr/media/Sounds/ "); + printf("\n===================================================================================================="); + return 0; + } + printf("\n\n --- media metadata test start ---\n\n"); + + ret = metadata_editor_create(&metadata); + //__printRetValue("metadata_editor_create(...)",ret); + + if(ret != METADATA_EDITOR_ERROR_NONE) + { + printf("Fail metadata_editor_create() at line [%d]\n", __LINE__); + return 0; + } + + ret = metadata_editor_set_path(metadata, argv[1]); + //__printRetValue("metadata_editor_set_path(...)",ret); + + if(ret != METADATA_EDITOR_ERROR_NONE) + { + printf("Fail metadata_editor_set_path() at line [%d]\n", __LINE__); + goto exception; + } + + while (c2 != 9) + { + c2 = 0; + printf("\n========================================================================"); + printf("\n The file you are working with is %s", argv[1]); + printf("\n======================================================================== "); + printf("\n Choose desired operation for testing:\n"); + printf("1 - Read tags. Press 1 \n"); + printf("2 - Write tags. Press 2 \n"); + printf("3 - Delete tags. Press 3 \n"); + printf("4 - Add picture. Press 4 \n"); + printf("5 - Delete picture. Press 5 \n"); + printf("6 - Save tags. Press 6 \n"); + printf("9 - Quit. Press 9 "); + printf("\n=========================\n"); + printf("\n Your choice : "); + dummy = scanf("%u", &c2); + __flush(); + + switch (c2) + { + case 1: + printf("\n=============="); + printf("\n Reading tags \n"); + __get_tag_info(metadata); + break; + case 2: + printf("\n=============="); + printf("\n Writing tags "); + __write_tag_info(metadata); + break; + case 3: + printf("\n=============="); + printf("\n Deleting tags "); + __delete_tag_info(metadata); + break; + case 4: + printf("\n=============="); + printf("\n Adding picture "); + __add_picture(metadata); + break; + case 5: + printf("\n=============="); + printf("\n Deleting pictures \n"); + __delete_pictures(metadata); + break; + case 6: + printf("\n=============="); + printf("\n Saving updated tags \n"); + __save_tags(metadata); + break; + } + } + +exception: + ret = metadata_editor_destroy(metadata); + if(ret != METADATA_EDITOR_ERROR_NONE) + { + printf("Fail metadata_editor_destroy [%d]\n", ret); + return 0; + } + + printf("\n\n--- metadata writer test end ---\n\n"); + + return ret; +} -- 2.7.4 From 57ee86a4d4ddf32d1a6df8645b77788f23da09ee Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 5 Jun 2015 18:54:56 +0900 Subject: [PATCH 02/16] Modify build error. Change-Id: I0f3704d014e5f583574292b03eeadbf6fb9b6758 Signed-off-by: Minje Ahn --- CMakeLists.txt | 6 +++--- packaging/capi-media-metadata-editor.spec | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89c2122..9393b6d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,14 +37,14 @@ ENDIF("${ARCH}" MATCHES "^arm.*") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DTIZEN_DEBUG") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") aux_source_directory(src SOURCES) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) -INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) INSTALL( DIRECTORY ${INC_DIR}/ DESTINATION include/${service} FILES_MATCHING @@ -61,7 +61,7 @@ CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc @ONLY ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) ADD_SUBDIRECTORY(test) diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec index 919b74e..6899516 100755 --- a/packaging/capi-media-metadata-editor.spec +++ b/packaging/capi-media-metadata-editor.spec @@ -29,12 +29,11 @@ A metadata editor library in SLP C API %build MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} make %{?jobs:-j%jobs} %install -rm -rf %{buildroot} %make_install mkdir -p %{buildroot}/%{_datadir}/license cp -rf %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 %{buildroot}/%{_datadir}/license/%{name} -- 2.7.4 From 994624c6684e280d248b24b54bec116ba7594b67 Mon Sep 17 00:00:00 2001 From: "ji.yong.seo" Date: Thu, 11 Jun 2015 10:46:15 +0900 Subject: [PATCH 03/16] update code by Tizen coding convention Change-Id: I2387a7611ea4eea9aba7b8cdcc9cbfccea899410 --- include/metadata_editor_private.h | 23 ++-- include/metadata_editor_type.h | 3 +- packaging/capi-media-metadata-editor.spec | 2 +- test/metadata_editor_test.c | 183 ++++++++++++++---------------- 4 files changed, 96 insertions(+), 115 deletions(-) diff --git a/include/metadata_editor_private.h b/include/metadata_editor_private.h index 2471416..c8f1612 100755 --- a/include/metadata_editor_private.h +++ b/include/metadata_editor_private.h @@ -55,27 +55,26 @@ extern "C" { #define LOG_TAG "CAPI_MEDIA_METADATA_EDITOR" #define metadata_editor_debug(fmt, arg...) do { \ - LOGD(""fmt"", ##arg); \ - } while (0) + LOGD(""fmt"", ##arg); \ + } while (0) #define metadata_editor_info(fmt, arg...) do { \ - LOGI(""fmt"", ##arg); \ - } while (0) + LOGI(""fmt"", ##arg); \ + } while (0) #define metadata_editor_error(fmt, arg...) do { \ - LOGE(""fmt"", ##arg); \ - } while (0) + LOGE(""fmt"", ##arg); \ + } while (0) #define metadata_editor_debug_fenter() do { \ - LOGD(""); \ - } while (0) + LOGD(""); \ + } while (0) #define metadata_editor_debug_fleave() do { \ - LOGD(""); \ - } while (0) + LOGD(""); \ + } while (0) -typedef struct -{ +typedef struct { void* file; int filetype; bool isOpen; diff --git a/include/metadata_editor_type.h b/include/metadata_editor_type.h index 7755ce9..5b5d222 100755 --- a/include/metadata_editor_type.h +++ b/include/metadata_editor_type.h @@ -53,8 +53,7 @@ typedef enum * @brief The enumerations of attribute * @since_tizen 2.4 */ -typedef enum -{ +typedef enum { METADATA_EDITOR_ATTR_ARTIST, /**< Artist*/ METADATA_EDITOR_ATTR_TITLE, /**< Title*/ METADATA_EDITOR_ATTR_ALBUM, /**< Album*/ diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec index 6899516..025f9aa 100755 --- a/packaging/capi-media-metadata-editor.spec +++ b/packaging/capi-media-metadata-editor.spec @@ -1,6 +1,6 @@ Name: capi-media-metadata-editor Summary: A metadata editor library in SLP C API -Version: 0.1.0 +Version: 0.1.1 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/test/metadata_editor_test.c b/test/metadata_editor_test.c index 0816bcf..fe26dc4 100755 --- a/test/metadata_editor_test.c +++ b/test/metadata_editor_test.c @@ -26,7 +26,7 @@ int dummy; void __flush(); -void __printRetValue(const char* func_name, int result); +void __printRetValue(const char *func_name, int result); static bool __get_tag_info(metadata_editor_h metadata); static bool __write_tag_info(metadata_editor_h metadata); static bool __add_picture(metadata_editor_h metadata); @@ -35,17 +35,17 @@ static bool __delete_pictures(metadata_editor_h metadata); void __flush() { char c; - while((c = getc(stdin)) != '\n'); + while ((c = getc(stdin)) != '\n'); } -void __printRetValue(const char* func_name, int result) +void __printRetValue(const char *func_name, int result) { printf("In function %s result is ", func_name); - if(result == METADATA_EDITOR_ERROR_NONE) printf("METADATA_EDITOR_ERROR_NONE\n"); - else if(result == METADATA_EDITOR_ERROR_INVALID_PARAMETER) printf("METADATA_EDITOR_ERROR_INVALID_PARAMETER\n"); - else if(result == METADATA_EDITOR_ERROR_OUT_OF_MEMORY) printf("METADATA_EDITOR_ERROR_OUT_OF_MEMORY\n"); - else if(result == METADATA_EDITOR_ERROR_FILE_EXISTS) printf("METADATA_EDITOR_ERROR_FILE_EXISTS\n"); - else if(result == METADATA_EDITOR_ERROR_OPERATION_FAILED) printf("METADATA_EDITOR_ERROR_OPERATION_FAILED\n"); + if (result == METADATA_EDITOR_ERROR_NONE) printf("METADATA_EDITOR_ERROR_NONE\n"); + else if (result == METADATA_EDITOR_ERROR_INVALID_PARAMETER) printf("METADATA_EDITOR_ERROR_INVALID_PARAMETER\n"); + else if (result == METADATA_EDITOR_ERROR_OUT_OF_MEMORY) printf("METADATA_EDITOR_ERROR_OUT_OF_MEMORY\n"); + else if (result == METADATA_EDITOR_ERROR_FILE_EXISTS) printf("METADATA_EDITOR_ERROR_FILE_EXISTS\n"); + else if (result == METADATA_EDITOR_ERROR_OPERATION_FAILED) printf("METADATA_EDITOR_ERROR_OPERATION_FAILED\n"); else printf("Unallowed value. Error!\n"); } @@ -63,7 +63,7 @@ static bool __get_tag_info(metadata_editor_h metadata) char *description = NULL; char *comment = NULL; char *track_num = NULL; - char* picture_index = NULL; + char *picture_index = NULL; int picture_size = 0; char *picture_type = NULL; void *picture = NULL; @@ -71,90 +71,83 @@ static bool __get_tag_info(metadata_editor_h metadata) char *lyric = NULL; ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_ARTIST, &artist); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("1. - artist = [%s]\n", artist); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_TITLE, &title); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("2. - title = [%s]\n", title); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_ALBUM, &album); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("3. - album = [%s]\n", album); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_GENRE, &genre); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("4. - genre = [%s]\n", genre); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_AUTHOR, &composer); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("5. - composer = [%s]\n", composer); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_COPYRIGHT, ©right); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("6. - copyright = [%s]\n", copyright); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_DATE, &date); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("7. - date = [%s]\n", date); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_DESCRIPTION, &description); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("8. - description = [%s]\n", description); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_COMMENT, &comment); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("9. - comment = [%s]\n", comment); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_TRACK_NUM, &track_num); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("10. - track_num = [%s]\n", track_num); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_PICTURE_NUM, &picture_index); - //__printRetValue("metadata_editor_get_metadata(...)",ret); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ printf("Picture index is [%s]\n", picture_index); #if 0 - if((filetype == METADATA_EDITOR_TYPE_OGG_VORBIS) || (filetype == METADATA_EDITOR_TYPE_OGG_FLAC)) - { - if(ret != METADATA_EDITOR_ERROR_INVALID_PARAMETER) - printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); - } - else - { + if ((filetype == METADATA_EDITOR_TYPE_OGG_VORBIS) || (filetype == METADATA_EDITOR_TYPE_OGG_FLAC)) { + if (ret != METADATA_EDITOR_ERROR_INVALID_PARAMETER) + printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + } else { #endif - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); - else if((ret == METADATA_EDITOR_ERROR_NONE) && picture_index) - { + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + else if ((ret == METADATA_EDITOR_ERROR_NONE) && picture_index) { uint num, i; num = atoi(picture_index); printf("Number of pictures: %u\n", num); - for(i = 0; i < num; ++i) - { + for (i = 0; i < num; ++i) { ret = metadata_editor_get_picture(metadata, i, &picture, &picture_size, &picture_type); - //__printRetValue("metadata_editor_get_picture(...)", ret); - if(ret == METADATA_EDITOR_ERROR_NONE && picture) - { + /*__printRetValue("metadata_editor_get_picture(...)", ret); */ + if (ret == METADATA_EDITOR_ERROR_NONE && picture) { printf("Saving picture number %u\n", i); int size = 30; char picture_file_name[size]; - snprintf(picture_file_name, size, "outputFile_%u" ,i+1); - if(strncmp(picture_type, "image/jpeg", strlen("image/jpeg")) == 0) strcat(picture_file_name,".jpg"); - else if(strncmp(picture_type, "image/png", strlen("image/jpeg")) == 0) strcat(picture_file_name,".png"); - FILE * fout = fopen(picture_file_name, "wb"); + snprintf(picture_file_name, size, "outputFile_%u" , i + 1); + if (strncmp(picture_type, "image/jpeg", strlen("image/jpeg")) == 0) strcat(picture_file_name, ".jpg"); + else if (strncmp(picture_type, "image/png", strlen("image/jpeg")) == 0) strcat(picture_file_name, ".png"); + FILE *fout = fopen(picture_file_name, "wb"); fwrite(picture, picture_size, 1, fout); fclose(fout); - } - else + } else printf("Error occured while picture extraction\n"); } free(picture_index); @@ -165,13 +158,13 @@ static bool __get_tag_info(metadata_editor_h metadata) printf("11. - picture size = [%u]\n", picture_size); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_CONDUCTOR, &conductor); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("12. - conductor = [%s]\n", conductor); ret = metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_UNSYNCLYRICS, &lyric); - //__printRetValue("metadata_editor_get_metadata(...)",ret); - if(ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); + /*__printRetValue("metadata_editor_get_metadata(...)",ret); */ + if (ret != METADATA_EDITOR_ERROR_NONE) printf("Fail metadata_editor_get_metadata() at line [%d]\n", __LINE__); printf("13. - lyric = [%s]\n", lyric); SAFE_FREE(artist); @@ -201,64 +194,64 @@ static bool __write_tag_info(metadata_editor_h metadata) printf("\n===========================================\n"); printf("\n 1. - Writing artist: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_ARTIST, input_data); *input_data = '\0'; printf("2. - Writing title: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_TITLE, input_data); *input_data = '\0'; printf("3. - Writing album: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_ALBUM, input_data); *input_data = '\0'; printf("4. - Writing genre: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_GENRE, input_data); *input_data = '\0'; printf("5. - Writing composer: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_AUTHOR, input_data); *input_data = '\0'; printf("6. - Writing copyright: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_COPYRIGHT, input_data); *input_data = '\0'; printf("7. - Writing year: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_DATE, input_data); *input_data = '\0'; printf("8. - Writing description: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_DESCRIPTION, input_data); *input_data = '\0'; printf("9. - Writing track: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_TRACK_NUM, input_data); *input_data = '\0'; printf("10. - Writing comment: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_COMMENT, input_data); *input_data = '\0'; printf("11. - Writing conductor: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_CONDUCTOR, input_data); *input_data = '\0'; printf("12. - Writing lyrics: "); - dummy = scanf("%[^\n]",input_data); + dummy = scanf("%[^\n]", input_data); __flush(); - metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_UNSYNCLYRICS,input_data); + metadata_editor_set_metadata(metadata, METADATA_EDITOR_ATTR_UNSYNCLYRICS, input_data); *input_data = '\0'; metadata_editor_update_metadata(metadata); @@ -312,19 +305,18 @@ static bool __add_picture(metadata_editor_h metadata) dummy = scanf("%u", &c2); __flush(); - switch (c2) - { + switch (c2) { case 1: - printf("\n==========================="); - printf("\n Your choice is TestImage.png\n"); - picture_filename = "TestImage.png"; - break; + printf("\n==========================="); + printf("\n Your choice is TestImage.png\n"); + picture_filename = "TestImage.png"; + break; case 2: - printf("\n==========================="); - printf("\n Your choice is TestImage.jpg\n"); - picture_filename = "TestImage.jpg"; - break; + printf("\n==========================="); + printf("\n Your choice is TestImage.jpg\n"); + picture_filename = "TestImage.jpg"; + break; } metadata_editor_append_picture(metadata, picture_filename); @@ -340,18 +332,15 @@ static bool __delete_pictures(metadata_editor_h metadata) metadata_editor_get_metadata(metadata, METADATA_EDITOR_ATTR_PICTURE_NUM, &picture_index); printf("The number of pictures is [%s]\n", picture_index); - if(picture_index) - { + if (picture_index) { num = atoi(picture_index); printf("Number of pictures: %u\n", num); - for(i = 0; i < num; ++i) - { + for (i = 0; i < num; ++i) { metadata_editor_remove_picture(metadata, 0); - //__printRetValue("metadata_editor_remove_picture(...)", ret); + /*__printRetValue("metadata_editor_remove_picture(...)", ret); */ } - } - else + } else printf("There are no pictures to delete\n"); return true; } @@ -369,11 +358,10 @@ int main(int argc, char *argv[]) { int ret = METADATA_EDITOR_ERROR_NONE; metadata_editor_h metadata = NULL; - int cnt = argc -1; + int cnt = argc - 1; uint c2 = 0; - if(cnt < 1) - { + if (cnt < 1) { printf("\n===================================================================================================="); printf("\n Please type file path and media type as media-metadata-test /opt/usr/media/Sounds/ "); printf("\n===================================================================================================="); @@ -382,25 +370,22 @@ int main(int argc, char *argv[]) printf("\n\n --- media metadata test start ---\n\n"); ret = metadata_editor_create(&metadata); - //__printRetValue("metadata_editor_create(...)",ret); + /*__printRetValue("metadata_editor_create(...)",ret); */ - if(ret != METADATA_EDITOR_ERROR_NONE) - { + if (ret != METADATA_EDITOR_ERROR_NONE) { printf("Fail metadata_editor_create() at line [%d]\n", __LINE__); return 0; } ret = metadata_editor_set_path(metadata, argv[1]); - //__printRetValue("metadata_editor_set_path(...)",ret); + /*__printRetValue("metadata_editor_set_path(...)",ret); */ - if(ret != METADATA_EDITOR_ERROR_NONE) - { + if (ret != METADATA_EDITOR_ERROR_NONE) { printf("Fail metadata_editor_set_path() at line [%d]\n", __LINE__); goto exception; } - while (c2 != 9) - { + while (c2 != 9) { c2 = 0; printf("\n========================================================================"); printf("\n The file you are working with is %s", argv[1]); @@ -418,8 +403,7 @@ int main(int argc, char *argv[]) dummy = scanf("%u", &c2); __flush(); - switch (c2) - { + switch (c2) { case 1: printf("\n=============="); printf("\n Reading tags \n"); @@ -455,8 +439,7 @@ int main(int argc, char *argv[]) exception: ret = metadata_editor_destroy(metadata); - if(ret != METADATA_EDITOR_ERROR_NONE) - { + if (ret != METADATA_EDITOR_ERROR_NONE) { printf("Fail metadata_editor_destroy [%d]\n", ret); return 0; } -- 2.7.4 From b6464a81c8cd8d4def95aa98c81832250fa0bf0f Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 4 Sep 2015 16:15:08 +0900 Subject: [PATCH 04/16] Fix prevent issue Change-Id: I010da7f6b0149ed1e0155dda741d128294505edf Signed-off-by: Minje Ahn --- CMakeLists.txt | 4 +- include/metadata_editor_private.h | 13 + include/metadata_editor_type.h | 2 +- packaging/capi-media-metadata-editor.spec | 6 +- src/metadata_editor.cpp | 1141 ++++++++--------------------- test/metadata_editor_test.c | 26 +- 6 files changed, 330 insertions(+), 862 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9393b6d..8280500 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,8 +26,8 @@ FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC -Wall") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC -Wall -Werror") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") IF("${ARCH}" MATCHES "^arm.*") diff --git a/include/metadata_editor_private.h b/include/metadata_editor_private.h index c8f1612..a71df10 100755 --- a/include/metadata_editor_private.h +++ b/include/metadata_editor_private.h @@ -53,6 +53,12 @@ extern "C" { #undef LOG_TAG #endif #define LOG_TAG "CAPI_MEDIA_METADATA_EDITOR" +#define META_SAFE_FREE(src) { if(src) {free(src); src = NULL;} } +#define META_MALLOC(src, size) { if (size <= 0) {src = NULL;} \ + else { src = (char *)malloc(size); if(src) memset(src, 0x0, size);} } + +#define META_MAX_BUF_LEN 20 + #define metadata_editor_debug(fmt, arg...) do { \ LOGD(""fmt"", ##arg); \ @@ -74,6 +80,13 @@ extern "C" { LOGD(""); \ } while (0) +#define metadata_editor_retvm_if(expr, val, fmt, arg...) do { \ + if(expr) { \ + LOGE(""fmt"", ##arg); \ + return (val); \ + } \ + } while (0) + typedef struct { void* file; int filetype; diff --git a/include/metadata_editor_type.h b/include/metadata_editor_type.h index 5b5d222..37345a0 100755 --- a/include/metadata_editor_type.h +++ b/include/metadata_editor_type.h @@ -43,7 +43,7 @@ typedef enum METADATA_EDITOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ METADATA_EDITOR_ERROR_FILE_EXISTS = TIZEN_ERROR_FILE_EXISTS, /**< File not exist */ METADATA_EDITOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ - METADATA_EDITOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /* Unsupported type */ + METADATA_EDITOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Unsupported type */ METADATA_EDITOR_ERROR_OPERATION_FAILED = TIZEN_ERROR_METADATA_EDITOR |0x01, /**< Invalid internal operation */ } metadata_editor_error_e; diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec index 025f9aa..20095aa 100755 --- a/packaging/capi-media-metadata-editor.spec +++ b/packaging/capi-media-metadata-editor.spec @@ -1,6 +1,6 @@ Name: capi-media-metadata-editor Summary: A metadata editor library in SLP C API -Version: 0.1.1 +Version: 0.1.3 Release: 0 Group: System/Libraries License: Apache-2.0 @@ -28,12 +28,16 @@ A metadata editor library in SLP C API %setup -q %build +export CFLAGS+=" -Wextra -Wno-array-bounds" +export CFLAGS+=" -Wno-ignored-qualifiers -Wno-unused-parameter -Wshadow" +export CFLAGS+=" -Wwrite-strings -Wswitch-default" MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} make %{?jobs:-j%jobs} %install +rm -rf %{buildroot} %make_install mkdir -p %{buildroot}/%{_datadir}/license cp -rf %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 %{buildroot}/%{_datadir}/license/%{name} diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 132aeb0..65c9ba6 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -31,10 +31,11 @@ static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemna static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value); static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* itemname, const char* value); static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value); +#if 0 static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, char** value); static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value); static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value); - +#endif typedef enum { METADATA_EDITOR_FORMAT_MP3 = 0, /**< MP3 File */ @@ -52,25 +53,13 @@ typedef enum static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) { // Check if we have valid arguments to work with - if((_metadata == NULL) || (frameID == NULL)) - { - metadata_editor_error("INVALID PARAMETER\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(value == NULL) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); // Check if the frame is empty (nothing to read) or ID3v2 tag does not exist if(!tag2 || tag2->frameListMap()[frameID].isEmpty()) @@ -79,7 +68,6 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: // Check if the tag ID3v1 is also empty or does not exist if(!tag1 || tag1->isEmpty()) { - *value = NULL; metadata_editor_info("The frame %s in ID3v1 tag is empty as well\n", frameID); return METADATA_EDITOR_ERROR_NONE; } @@ -118,51 +106,28 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: if(!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); length = strlen(str.toCString(isUTF)); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, str.toCString(isUTF)); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; } - uint size = 20; - char buf[size]; + char buf[META_MAX_BUF_LEN] = {0, }; if(!strcmp(frameID, "TRCK")) // track { // Convert int into char[] - snprintf(buf, size, "%u", tag1->track()); found = true; + snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->track()); found = true; } else if(!strcmp(frameID, "TDRC")) // data (year) { // Convert int into char[] - snprintf(buf, size, "%u", tag1->year()); found = true; + snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->year()); found = true; } if(found) { length = strlen(buf); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, buf); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } // The desired frame was not found @@ -178,20 +143,8 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: if(!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); uint length = strlen(str.toCString(isUTF)); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - // Allocate the memory and copy the value to this memory - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, str.toCString(isUTF)); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; } @@ -202,30 +155,16 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) { // Check if we have valid arguments to work with - if((_metadata == NULL) || (frameID == NULL)) - { - metadata_editor_error("INVALID PARAMETER\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exists - if(tag2 == NULL) - { - metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); + // If the pointer is NULL or c-string is empty - handle as request for deletion if(!value || (*value == '\0')) { @@ -248,11 +187,8 @@ static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); // This is a common frame type for textural frames except comment frame TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); - if(fr == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(fr == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); + fr->setTextEncoding(TagLib::String::UTF8); fr->setText(TagLib::String(value,TagLib::String::UTF8)); tag2->addFrame(fr); @@ -285,89 +221,45 @@ static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) { // Check if we have valid arguments to work with - if((_metadata == NULL) || (frameID == NULL)) - { - metadata_editor_error("INVALID PARAMETER\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(value == NULL) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); // Check if the frame is empty (nothing to read) or ID3v2 tag does not exist - if (!tag2 || tag2->frameListMap()[frameID].isEmpty()) - { - metadata_editor_info("The frame %s does not exist\n", frameID); - *value = NULL; - return METADATA_EDITOR_ERROR_NONE; - } - else // frame exists - read it - { - metadata_editor_info("The frame %s exists\n", frameID); - // This string is used to copy the value in the frame - TagLib::String str = tag2->frameListMap()[frameID][0]->toString(); - bool isUTF = false; - if(!str.isLatin1()) isUTF = true; - metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); - uint length = strlen(str.toCString(isUTF)); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - // Allocate the memory and copy the value to this memory - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, str.toCString(isUTF)); + metadata_editor_retvm_if(!tag2 || tag2->frameListMap()[frameID].isEmpty(),METADATA_EDITOR_ERROR_NONE,"The frame %s does not exist\n", frameID); + + metadata_editor_info("The frame %s exists\n", frameID); + // This string is used to copy the value in the frame + TagLib::String str = tag2->frameListMap()[frameID][0]->toString(); + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + uint length = strlen(str.toCString(isUTF)); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); - return METADATA_EDITOR_ERROR_NONE; - } + return METADATA_EDITOR_ERROR_NONE; } // *** This function writes frames that exist only in ID3v2 tag *** // static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) { // Check if we have valid arguments to work with - if((_metadata == NULL) || (frameID == NULL)) - { - metadata_editor_error("INVALID PARAMETER\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exist - if(tag2 == NULL) - { - metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); + // If the pointer is NULL or c-string is empty - handle as request for deletion if(!value || (*value == '\0')) { @@ -382,11 +274,8 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); // This is a common frame type for textural frames except comment frame TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); - if(fr == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(fr == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); + fr->setTextEncoding(TagLib::String::UTF8); fr->setText(TagLib::String(value,TagLib::String::UTF8)); tag2->addFrame(fr); @@ -403,60 +292,27 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) { // Check if parameters are valid - if(_metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if((value == NULL)) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); // Check if the valid tag pointer exist - if(tag2 == NULL) - { - metadata_editor_error("Error. ID3v2 tag does not exist. Can not process further\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // link to picture frames in tag // Check if the frames exist - if(lst.isEmpty()) - { - metadata_editor_info("No pictures in file\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_NONE; - } - else // picture frames exist - { - metadata_editor_info("APIC frames exist in file\n"); - int size = 20; - char buf[size]; - // Convert the number of frames (lst.size()) to c-string - snprintf(buf, size, "%u", lst.size()); - uint length = strlen(buf); - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - // Copy c-string to value for returning - strcpy(*value, buf); - return METADATA_EDITOR_ERROR_NONE; - } + metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_NONE, "No pictures in file\n"); + + metadata_editor_info("APIC frames exist in file\n"); + char buf[META_MAX_BUF_LEN] = {0, }; + // Convert the number of frames (lst.size()) to c-string + snprintf(buf, META_MAX_BUF_LEN, "%u", lst.size()); + *value = strndup(buf, strlen(buf)); + return METADATA_EDITOR_ERROR_NONE; + } // *** This function is used to receive unsynchronized lyrics from ID3v2 tag in file *** // @@ -464,67 +320,31 @@ static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2 static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) { // Check if parameters are valid - if(_metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if((value == NULL)) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); // Check if the valid tag pointer exist - if(tag2 == NULL) - { - metadata_editor_error("Error. ID3v2 tag does not exist. Can not process further\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag does not exist. Can not process further"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag // Check if frames exist in file - if(lst.isEmpty()) - { - metadata_editor_info("The frame USLT does not exist\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_NONE; - } - else - { - metadata_editor_info("The frame USLT exists\n"); - TagLib::ID3v2::FrameList::Iterator it = lst.begin(); - TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = static_cast(*it); - TagLib::String str = frame->text(); - bool isUTF = false; - if(!str.isLatin1()) isUTF = true; - metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); - uint length = strlen(str.toCString(isUTF)); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, str.toCString(isUTF)); - return METADATA_EDITOR_ERROR_NONE; - } + metadata_editor_retvm_if(lst.isEmpty(),METADATA_EDITOR_ERROR_NONE,"The frame USLT does not exist\n"); + + metadata_editor_info("The frame USLT exists\n"); + TagLib::ID3v2::FrameList::Iterator it = lst.begin(); + TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = static_cast(*it); + TagLib::String str = frame->text(); + bool isUTF = false; + if(!str.isLatin1()) isUTF = true; + metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + uint length = strlen(str.toCString(isUTF)); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); + return METADATA_EDITOR_ERROR_NONE; } // *** This function is used to set text in comment frame. It processes both ID3v1 and ID3v2 tags *** // @@ -532,30 +352,14 @@ static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* value) { // Check if we have a valid argument to work with - if(_metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exist - if(tag2 == NULL) - { - metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); // If the pointer is NULL or c-string is empty - handle as request for deletion if(!value || (*value == '\0')) @@ -571,11 +375,7 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1 { metadata_editor_info("The frame COMM does not exist. Creating.\n"); TagLib::ID3v2::CommentsFrame* fr = new TagLib::ID3v2::CommentsFrame; - if(fr == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(fr == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY\n"); fr->setText(TagLib::String(value, TagLib::String::UTF8)); fr->setTextEncoding(TagLib::String::UTF8); tag2->addFrame(fr); @@ -598,30 +398,14 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1 static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* value) { // Check if we have a valid argument to work with - if(_metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exist - if(tag2 == NULL) - { - metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag // If the pointer is NULL or c-string is empty - handle as request for deletion @@ -637,11 +421,8 @@ static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag // No lyrics - create the frame and add it to the ID3v2 tag metadata_editor_info("The frame USLT does not exist. Creating.\n"); TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = new TagLib::ID3v2::UnsynchronizedLyricsFrame; - if(frame == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(frame == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); + frame->setTextEncoding(TagLib::String::UTF8); frame->setText(TagLib::String(value,TagLib::String::UTF8)); tag2->addFrame(frame); @@ -661,34 +442,18 @@ static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemname, char** value) { // Check if parameters are valid - if((_metadata == NULL)|| (itemname == NULL)) - { - metadata_editor_error("INVALID Parameter\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(value == NULL) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail."); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag does not exist\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -702,26 +467,13 @@ static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemnam metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); // Get the length of the string and check if it is empty or not uint length = strlen(str.toCString(isUTF)); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - // Allocate the memory and copy string to output variable - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, str.toCString(isUTF)); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; } else // Item was not found { metadata_editor_info("No item <%s> in file\n", itemname); - *value = NULL; return METADATA_EDITOR_ERROR_NONE; } } @@ -730,65 +482,36 @@ static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemnam static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemname, char** value) { // Check if parameters are valid - if((_metadata == NULL)|| (itemname == NULL)) - { - metadata_editor_error("INVALID Parameter\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(value == NULL) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail."); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag does not exist.\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); if(it != itemMap.end()) // Item was found { - uint size = 20; - char buf[size]; + char buf[META_MAX_BUF_LEN] = {0, }; int num = it->second.toInt(); // Get integer value in item - snprintf(buf, size, "%u", num); // Convert int into char[] + snprintf(buf, META_MAX_BUF_LEN, "%u", num); // Convert int into char[] // Determine the length of created c-string and copy it into the output variable int length = strlen(buf); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, buf); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } else // Item was not found { metadata_editor_info("No item <%s> in file\n", itemname); - *value = NULL; return METADATA_EDITOR_ERROR_NONE; } } @@ -797,31 +520,17 @@ static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemna static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value) { // Check if parameters are valid - if((_metadata == NULL)|| (itemname == NULL)) - { - metadata_editor_error("INVALID Parameter\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail."); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag was not created.\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag was not created"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -843,31 +552,17 @@ static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* item static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* itemname, const char* value) { // Check if parameters are valid - if((_metadata == NULL) || (itemname == NULL)) - { - metadata_editor_error("INVALID Parameter\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail."); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag was not created.\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag was not created"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -899,34 +594,17 @@ static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* ite static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) { // Check if parameters are valid - if(_metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if((value == NULL)) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail."); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag does not exist\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -935,62 +613,33 @@ static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) { uint number = it->second.toCoverArtList().size(); // Get the size of CoverList (i.e. number of pictures in file) metadata_editor_info("There are %u picture(s) in file\n", number); - int size = 20; - char buf[size]; - snprintf(buf,size, "%u", number); // Convert integer value of size to its c-string representation + char buf[META_MAX_BUF_LEN] = {0, }; + snprintf(buf,META_MAX_BUF_LEN, "%u", number); // Convert integer value of size to its c-string representation int length = strlen(buf); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, buf); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } else // Item was not found { metadata_editor_info("No item in file\n"); - *value = NULL; return METADATA_EDITOR_ERROR_NONE; } } - +#if 0 // *** This function is used to extract string from Xiph Comment field *** // static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, char** value) { // Check if we have a valid argument to work with - if((_metadata == NULL) || (fieldname == NULL)) - { - metadata_editor_error("INVALID Parameter\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(value == NULL) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(fieldname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Value Pointer"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(!xtag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag does not exist\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(!xtag,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); + const TagLib::Ogg::FieldListMap& fieldMap = xtag->fieldListMap(); TagLib::Ogg::FieldListMap::ConstIterator it = fieldMap.find(fieldname); @@ -1004,26 +653,13 @@ static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphC metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); // Get the length of the string and check if it is empty or not uint length = strlen(str.toCString(isUTF)); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - // Allocate the memory and copy string to output variable - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, str.toCString(isUTF)); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; } else // Field was not found { metadata_editor_info("No field %s in Xiph Comment\n", fieldname); - *value = NULL; return METADATA_EDITOR_ERROR_NONE; } } @@ -1032,29 +668,15 @@ static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphC static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value) { // Check if we have a valid argument to work with - if((_metadata == NULL) || (fieldname == NULL)) - { - metadata_editor_error("INVALID Parameter\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(fieldname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); + metadata_editor_retvm_if(!xtag,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); - if(!xtag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag does not exist\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } // Check if it is a request for deletion if((value == NULL) || value[0] == '\0') { @@ -1072,62 +694,38 @@ static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::Xi static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value) { // Check if parameters are valid - if(_metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(value == NULL) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Value Pointer"); + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; if(_file->pictureList().isEmpty()) { metadata_editor_info("No pictures in FLAC file\n"); - *value = NULL; return METADATA_EDITOR_ERROR_NONE; } uint number = _file->pictureList().size(); metadata_editor_info("There are %u picture(s) in file\n", number); - int size = 20; - char buf[size]; - snprintf(buf,size, "%u", number); // Convert integer value of size to its c-string representation - int length = strlen(buf); - if(length == 0) - { - *value = NULL; - metadata_editor_info("Empty string...\n"); - return METADATA_EDITOR_ERROR_NONE; - } - *value = new char[length + 1]; - if(*value == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } - strcpy(*value, buf); + char buf[META_MAX_BUF_LEN] = {0, }; + snprintf(buf,META_MAX_BUF_LEN, "%u", number); // Convert integer value of size to its c-string representation + uint length = strlen(buf); + metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } - +#endif int __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int max_len) { int i = 0; + unsigned int path_len = strlen(file_path); - for (i = strlen(file_path); i >= 0; i--) + for (i = (int)path_len; i >= 0; i--) { - if ((file_path[i] == '.') && (i < strlen(file_path))) + if ((file_path[i] == '.') && (i < (int)path_len)) { strncpy(file_ext, &file_path[i + 1], max_len); return 0; @@ -1156,11 +754,7 @@ int __metadata_editor_get_file_type(const char *path) char ext[255] = { 0 }; int ret = __metadata_editor_get_file_ext(path, ext, sizeof(ext)); - if (ret < 0) - { - metadata_editor_error("__metadata_editor_get_file_type failed"); - return METADATA_EDITOR_FORMAT_NOTYPE; - } + metadata_editor_retvm_if(ret < 0,METADATA_EDITOR_FORMAT_NOTYPE,"__metadata_editor_get_file_type failed"); if (strcasecmp(ext, "MP3") == 0) { @@ -1206,11 +800,7 @@ int __metadata_editor_get_picture_type(const char *path, char **type) char ext[255] = { 0 }; int ret = __metadata_editor_get_file_ext(path, ext, sizeof(ext)); - if (ret < 0) - { - metadata_editor_error("__metadata_editor_get_file_type failed"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(ret < 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"__metadata_editor_get_file_type failed"); if (strcasecmp(ext, "JPG") == 0 || strcasecmp(ext, "JPEG") == 0) { @@ -1264,15 +854,19 @@ int __metadata_editor_get_picture_info(const char *path, void **picture, int *si file_size++; } fclose(fin); - char picture_buffer[file_size]; + char picture_buffer[file_size] = {0,}; + memset(picture_buffer, 0, file_size * sizeof(char)); fin = fopen(path, "rb"); - ret = fread(picture_buffer, file_size, 1, fin); - fclose(fin); - - *picture = malloc(file_size * sizeof(char)); - memset(*picture, 0, file_size * sizeof(char)); - memcpy(*picture, picture_buffer, file_size); - *size = file_size; + if(fin) { + ret = fread(picture_buffer, file_size, 1, fin); + fclose(fin); + } + if(*picture == NULL) { + *picture = malloc(file_size * sizeof(char)); + memset(*picture, 0, file_size * sizeof(char)); + memcpy(*picture, picture_buffer, file_size); + *size = file_size; + } } return METADATA_EDITOR_ERROR_NONE; @@ -1289,18 +883,10 @@ bool __metadata_editor_file_exist(const std::string& name) { extern "C" int metadata_editor_create(metadata_editor_h *metadata) { // Check if we have a valid argument to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID PARAMETER\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_s *_metadata = new metadata_editor_s; // Allocate a structure for handler - if(_metadata == NULL) // Check if the structure was allocated successfully - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(_metadata == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); _metadata->file = NULL; _metadata->filetype = METADATA_EDITOR_FORMAT_NOTYPE; // Specify file type out of range @@ -1317,16 +903,8 @@ extern "C" int metadata_editor_create(metadata_editor_h *metadata) extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char *path) { // Check if we have valid arguments to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(path == NULL) - { - metadata_editor_error("INVALID Path\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); + metadata_editor_retvm_if(path == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); if(!__metadata_editor_file_exist(path)) { @@ -1335,12 +913,10 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * } metadata_editor_s *_metadata = (metadata_editor_s*)metadata; - int media_type; + int media_type = METADATA_EDITOR_FORMAT_NOTYPE; media_type = __metadata_editor_get_file_type(path); - - switch(media_type) // Parse file according the specified type { case METADATA_EDITOR_FORMAT_MP3: @@ -1348,11 +924,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * // Allocate the file object in memory to work with it later on TagLib::MPEG::File* _file = new TagLib::MPEG::File(path); - if(_file == NULL) // Check if the file was allocated successfully - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(_file == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _metadata->file = _file; // Copy file pointer to the structure _metadata->filetype = METADATA_EDITOR_FORMAT_MP3; @@ -1385,11 +958,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * // Allocate the file object in memory to work with it later on TagLib::MP4::File* _file = new TagLib::MP4::File(path); - if(_file == NULL) // Check if the file was allocated successfully - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(_file == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _metadata->file = _file; // Copy file pointer to the structure _metadata->filetype = METADATA_EDITOR_FORMAT_MP4; @@ -1423,11 +993,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * // Allocate the file object in memory to work with it later on TagLib::FLAC::File* _file = new TagLib::FLAC::File(path); - if(_file == NULL) // Check if the file was allocated successfully - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(_file == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _metadata->file = _file; // Copy file pointer to the structure _metadata->filetype = METADATA_EDITOR_FORMAT_FLAC; @@ -1460,11 +1027,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * // Allocate the file object in memory to work with it later on TagLib::Ogg::Vorbis::File* _file = new TagLib::Ogg::Vorbis::File(path); - if(_file == NULL) // Check if the file was allocated successfully - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(_file == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _metadata->file = _file; // Copy file pointer to the structure _metadata->filetype = METADATA_EDITOR_FORMAT_OGG_VORBIS; @@ -1497,11 +1061,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * // Allocate the file object in memory to work with it later on TagLib::Ogg::FLAC::File* _file = new TagLib::Ogg::FLAC::File(path); - if(_file == NULL) // Check if the file was allocated successfully - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(_file == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _metadata->file = _file; // Copy file pointer to the structure _metadata->filetype = METADATA_EDITOR_FORMAT_OGG_FLAC; @@ -1534,11 +1095,8 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * // Allocate the file object in memory to work with it later on TagLib::RIFF::WAV::File* _file = new TagLib::RIFF::WAV::File(path); - if(_file == NULL) // Check if the file was allocated successfully - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(_file == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _metadata->file = _file; // Copy file pointer to the structure _metadata->filetype = METADATA_EDITOR_FORMAT_WAV; @@ -1577,27 +1135,15 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, char **value) { // Check if we have valid arguments to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if(value == NULL) - { - metadata_editor_error("INVALID Value Pointer\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); + metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Value Pointer"); metadata_editor_s *_metadata = (metadata_editor_s*)metadata; + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *value = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *value = NULL; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); switch(_metadata->filetype) // Process the file according to the specified file type { @@ -1624,7 +1170,6 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(_metadata, tag2, value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); default: - *value = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1646,7 +1191,6 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __MP4_getStringItem(_metadata, "\xA9""lyr", value); case METADATA_EDITOR_ATTR_PICTURE_NUM: return __MP4_getNumberOfPictures(_metadata, value); default: - *value = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1678,7 +1222,6 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(_metadata, xtag, "LYRICS", value); case METADATA_EDITOR_ATTR_PICTURE_NUM: return __FLAC_getNumberOfPictures(_metadata, value); default: - *value = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1708,7 +1251,6 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(_metadata, xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(_metadata, xtag, "LYRICS", value); default: - *value = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1738,7 +1280,6 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_CONDUCTOR: return __xiph_getFieldValue(_metadata, xtag, "CONDUCTOR", value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __xiph_getFieldValue(_metadata, xtag, "LYRICS", value); default: - *value = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1771,14 +1312,12 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(_metadata, tag2, value); case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); default: - *value = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } #endif default: metadata_editor_error("Wrong file type\n"); - *value = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -1787,25 +1326,15 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, const char* value) { // Check if we have valid arguments to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); + // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch(_metadata->filetype) // Process the file according to the specified file type { @@ -1816,11 +1345,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); - if(tag2 == NULL) // Check if the valid tag pointer exist - { - metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); switch (attribute) // Check which one of frame type was given for processing { @@ -1986,25 +1511,14 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) { // Check if we have a valid argument to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle\n"); metadata_editor_s *_metadata = (metadata_editor_s*)metadata; + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch(_metadata->filetype) // Process the file according to the specified file type { @@ -2084,24 +1598,19 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index const char *TYPE_JPEG = "image/jpeg"; const char *TYPE_PNG = "image/png"; // Check if we have valid arguments to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - *picture = NULL; *size = 0; *mime_type = NULL; - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - if((picture == NULL) || (size == NULL)) - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle\n"); + metadata_editor_retvm_if(picture == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(size == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - *picture = NULL; *size = 0; *mime_type = NULL; - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + *picture = NULL; + *size = 0; + *mime_type = NULL; + + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); switch(_metadata->filetype) // Process the file according to the specified file type { @@ -2109,18 +1618,13 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index { TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; // Bring the pointer to actual file type TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(); - if(!tag2) - { - metadata_editor_error("No ID3v2 tag in file\n"); - *picture = NULL; *size = 0; *mime_type = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. No ID3v2 tag in file."); + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag if(lst.isEmpty()) { metadata_editor_error("No pictures in file\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } else // pictures exist in file @@ -2129,7 +1633,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if( (index < 0) || (lst.size() <= (uint)index) ) { metadata_editor_error("Index of picture is out of range\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } else // everything is correct - begin extraction @@ -2142,18 +1645,10 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if(i != index) continue; TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); uint pictureSize = pictureFrame->picture().size(); - if(pictureSize == 0) - { - *picture = NULL; *size = 0; *mime_type = NULL; - metadata_editor_error("Size of picture is 0\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - *picture = new char[pictureSize]; - if(*picture == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + META_MALLOC(*picture, pictureSize); + metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + memcpy(*picture, pictureFrame->picture().data(), pictureSize); *size = pictureSize; TagLib::String mime = pictureFrame->mimeType(); @@ -2173,12 +1668,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag does not exist\n"); - *picture = NULL; *size = 0; *mime_type = NULL; - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -2190,7 +1680,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if((index < 0) || ((uint)index >= lst.size())) // it is not { metadata_editor_error("Index of picture is out of range\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } else // index is in range @@ -2200,18 +1689,10 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index { if(i != index) continue; int pictureSize = picIt->data().size(); - if(pictureSize == 0) - { - *picture = NULL; *size = 0; *mime_type = NULL; - metadata_editor_error("Size of picture is 0\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - *picture = new char[pictureSize]; - if(*picture == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + META_MALLOC(*picture, pictureSize); + metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + memcpy(*picture, picIt->data().data(), pictureSize); *size = pictureSize; if(picIt->format() == TagLib::MP4::CoverArt::JPEG) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); @@ -2225,7 +1706,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index else // Item was not found - no pictures in file { metadata_editor_error("No item in file. No pictures in file\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } } @@ -2237,7 +1717,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if(lst.isEmpty()) { metadata_editor_error("No pictures in FLAC file\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } else @@ -2246,7 +1725,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if((index < 0) || ((uint)index >= lst.size())) // it is not { metadata_editor_error("Index of picture is out of range\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } else // index is in range @@ -2259,18 +1737,10 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index // picture can be received as ByteVector (picIt->data()). // ByteVector has data() - picture itself and size() - the size of picture in data() method int pictureSize = (*picIt)->data().size(); - if(pictureSize == 0) - { - *picture = NULL; *size = 0; *mime_type = NULL; - metadata_editor_error("Size of picture is 0\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - *picture = new char[pictureSize]; - if(*picture == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + META_MALLOC(*picture, pictureSize); + metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + memcpy(*picture, (*picIt)->data().data(), pictureSize); *size = pictureSize; TagLib::String mime = (*picIt)->mimeType(); @@ -2293,7 +1763,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if(!tag2) { metadata_editor_error("No ID3v2 tag in file\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; @@ -2301,7 +1770,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if(lst.isEmpty()) { metadata_editor_error("No pictures in file\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } else // pictures exist in file @@ -2310,7 +1778,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if( (index < 0) || (lst.size() <= (uint)index) ) { metadata_editor_error("Index of picture is out of range\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } else // everything is correct - begin extraction @@ -2323,18 +1790,11 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if(i != index) continue; TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); uint pictureSize = pictureFrame->picture().size(); - if(pictureSize == 0) - { - *picture = NULL; *size = 0; *mime_type = NULL; - metadata_editor_error("Size of picture is 0\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - *picture = new char[pictureSize]; - if(*picture == NULL) - { - metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; - } + metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + + META_MALLOC(*picture, pictureSize); + metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + memcpy(*picture, pictureFrame->picture().data(), pictureSize); *size = pictureSize; TagLib::String mime = pictureFrame->mimeType(); @@ -2353,7 +1813,6 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index #endif default: metadata_editor_error("Wrong file type\n"); - *picture = NULL; *size = 0; *mime_type = NULL; return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } @@ -2361,37 +1820,24 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index // *** This function appends a cover art picture to the file *** // extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const char *path) { + int ret = METADATA_EDITOR_ERROR_NONE; + void *picture = NULL; + int size = 0; + char *type = NULL; + // Check if we have valid arguments to work with - if((metadata == NULL) || (path == NULL)) - { - metadata_editor_error("INVALID Parameter\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); + metadata_editor_retvm_if(path == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - - int ret; - void *picture; - int size; - char *type; + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); ret = __metadata_editor_get_picture_info(path, &picture, &size, &type); - if(ret != METADATA_EDITOR_ERROR_NONE) { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } + metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); switch(_metadata->filetype) // Process the file according to the specified file type { @@ -2404,13 +1850,15 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const if(tag2 == NULL) { metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; + break; } TagLib::ID3v2::AttachedPictureFrame* pictureFrame = new TagLib::ID3v2::AttachedPictureFrame(); if(pictureFrame == NULL) { metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + break; } metadata_editor_info("New APIC frame will be added to the ID3v2 tag\n"); pictureFrame->setPicture(TagLib::ByteVector((char*)picture, size)); @@ -2418,16 +1866,19 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const pictureFrame->setMimeType(type); tag2->addFrame(pictureFrame); - return METADATA_EDITOR_ERROR_NONE; + + ret = METADATA_EDITOR_ERROR_NONE; + break; } case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing + if(!tag) { metadata_editor_error("Tag was not created\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; + break; } // Get map of items directly from tag and launch a search of specific item @@ -2447,7 +1898,9 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const TagLib::MP4::CoverArt cover(format, TagLib::ByteVector((char*)picture, size)); lst.append(cover); itemMap.insert("covr", TagLib::MP4::Item(lst)); - return METADATA_EDITOR_ERROR_NONE; + + ret = METADATA_EDITOR_ERROR_NONE; + break; } else // Item was not found { @@ -2463,7 +1916,9 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const TagLib::MP4::CoverArtList lst; lst.append(cover); itemMap.insert("covr", TagLib::MP4::Item(lst)); - return METADATA_EDITOR_ERROR_NONE; + + ret = METADATA_EDITOR_ERROR_NONE; + break; } } #if 0 @@ -2474,7 +1929,8 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const if(frontCover == NULL) { metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + break; } frontCover->setData(TagLib::ByteVector((char*)picture, size)); frontCover->setType(TagLib::FLAC::Picture::FrontCover); @@ -2482,7 +1938,8 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const metadata_editor_info("Picture will be added to FLAC file\n"); _file->addPicture(frontCover); - return METADATA_EDITOR_ERROR_NONE; + ret = METADATA_EDITOR_ERROR_NONE; + break; } case METADATA_EDITOR_FORMAT_WAV: { @@ -2493,51 +1950,51 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const if(tag2 == NULL) { metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; + ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; + break; } TagLib::ID3v2::AttachedPictureFrame* pictureFrame = new TagLib::ID3v2::AttachedPictureFrame(); if(pictureFrame == NULL) { metadata_editor_error("OUT_OF_MEMORY\n"); - return METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + break; } metadata_editor_info("New APIC frame will be added to the ID3v2 tag\n"); pictureFrame->setPicture(TagLib::ByteVector((char*)picture, size)); pictureFrame->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover); pictureFrame->setMimeType(type); tag2->addFrame(pictureFrame); - return METADATA_EDITOR_ERROR_NONE; + ret = METADATA_EDITOR_ERROR_NONE; + break; } #endif default: + { metadata_editor_error("Wrong file type\n"); - return METADATA_EDITOR_ERROR_NOT_SUPPORTED; + ret = METADATA_EDITOR_ERROR_NOT_SUPPORTED; + break; + } } + + META_SAFE_FREE(picture); + META_SAFE_FREE(type); + + return ret; } // *** This function is used to delete picture with specified index *** // extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int index) { // Check if we have a valid argument to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID Parameter\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID handler."); metadata_editor_s* _metadata = (metadata_editor_s*) metadata; + metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - if(_metadata->file && _metadata->isOpen == false) - { - metadata_editor_error("File does not exist or you have no rights to open it\n"); - return METADATA_EDITOR_ERROR_PERMISSION_DENIED; - } - if(_metadata->isReadOnly) // Check if the file is writable or it is readonly - { - metadata_editor_error("File is readonly. Unable to modify\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch(_metadata->filetype) // Process the file according to the specified file type { @@ -2547,11 +2004,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); // Check if the valid tag pointer exists - if(tag2 == NULL) - { - metadata_editor_error("Error. ID3v2 tag does not exist. Can not remove picture\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag if(lst.isEmpty()) @@ -2586,11 +2039,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) // Check if we have a valid tag for processing - { - metadata_editor_error("Tag does not exist\n"); - return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } + metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. tag not exist."); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -2705,11 +2154,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in extern "C" int metadata_editor_destroy(metadata_editor_h metadata) { // Check if we have a valid argument to work with - if(metadata == NULL) - { - metadata_editor_error("INVALID Handle\n"); - return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } + metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_s *_metadata = (metadata_editor_s*)metadata; diff --git a/test/metadata_editor_test.c b/test/metadata_editor_test.c index fe26dc4..132ab89 100755 --- a/test/metadata_editor_test.c +++ b/test/metadata_editor_test.c @@ -21,7 +21,7 @@ #include -#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}} +#define SAFE_FREE(src) { if (src) {free(src); src = NULL; } } int dummy; @@ -34,8 +34,8 @@ static bool __delete_pictures(metadata_editor_h metadata); void __flush() { - char c; - while ((c = getc(stdin)) != '\n'); + int c; + while ((c = getc(stdin)) != 10); } void __printRetValue(const char *func_name, int result) @@ -142,11 +142,13 @@ static bool __get_tag_info(metadata_editor_h metadata) int size = 30; char picture_file_name[size]; snprintf(picture_file_name, size, "outputFile_%u" , i + 1); - if (strncmp(picture_type, "image/jpeg", strlen("image/jpeg")) == 0) strcat(picture_file_name, ".jpg"); - else if (strncmp(picture_type, "image/png", strlen("image/jpeg")) == 0) strcat(picture_file_name, ".png"); + if (strncmp(picture_type, "image/jpeg", strlen("image/jpeg")) == 0) strncat(picture_file_name, ".jpg", strlen(".jpg")); + else if (strncmp(picture_type, "image/png", strlen("image/jpeg")) == 0) strncat(picture_file_name, ".png", strlen(".png")); FILE *fout = fopen(picture_file_name, "wb"); - fwrite(picture, picture_size, 1, fout); - fclose(fout); + if (fout) { + fwrite(picture, picture_size, 1, fout); + fclose(fout); + } } else printf("Error occured while picture extraction\n"); } @@ -309,18 +311,20 @@ static bool __add_picture(metadata_editor_h metadata) case 1: printf("\n==========================="); printf("\n Your choice is TestImage.png\n"); - picture_filename = "TestImage.png"; + picture_filename = strdup("TestImage.png"); break; case 2: printf("\n==========================="); printf("\n Your choice is TestImage.jpg\n"); - picture_filename = "TestImage.jpg"; + picture_filename = strdup("TestImage.jpg"); + break; + default: break; } metadata_editor_append_picture(metadata, picture_filename); - + SAFE_FREE(picture_filename); return true; } @@ -434,6 +438,8 @@ int main(int argc, char *argv[]) printf("\n Saving updated tags \n"); __save_tags(metadata); break; + default: + break; } } -- 2.7.4 From c070be64b6440e270cdce1f55830c9ebc4380418 Mon Sep 17 00:00:00 2001 From: "Haejeong, Kim" Date: Thu, 29 Oct 2015 14:35:50 +0900 Subject: [PATCH 05/16] Apply tizen coding rule Change-Id: I1f0c16794c0f8874a81d60d48b7641de64abbeef --- doc/metadata_editor_doc.h | 2 +- packaging/capi-media-metadata-editor.spec | 2 +- src/metadata_editor.cpp | 794 ++++++++++++------------------ 3 files changed, 305 insertions(+), 493 deletions(-) diff --git a/doc/metadata_editor_doc.h b/doc/metadata_editor_doc.h index 30b2c93..9821d03 100755 --- a/doc/metadata_editor_doc.h +++ b/doc/metadata_editor_doc.h @@ -33,7 +33,7 @@ * @addtogroup CAPI_MEDIA_METADATA_EDITOR_MODULE * @brief The @ref CAPI_MEDIA_METADATA_EDITOR_MODULE API provides functions for editing the metadata of several popular audio format. * @ingroup CAPI_MEDIA_FRAMEWORK - * @section CAPI_MEDIA_METADATA_EDITOR_MODULE_HEADER Required Header + * @section CAPI_MEDIA_METADATA_EDITOR_MODULE_HEADER Required Header * \#include * * @section CAPI_MEDIA_METADATA_EDITOR_OVERVIEW Overview diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec index 20095aa..fc9a75a 100755 --- a/packaging/capi-media-metadata-editor.spec +++ b/packaging/capi-media-metadata-editor.spec @@ -1,6 +1,6 @@ Name: capi-media-metadata-editor Summary: A metadata editor library in SLP C API -Version: 0.1.3 +Version: 0.1.4 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 65c9ba6..8994a54 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -36,20 +36,19 @@ static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphC static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value); static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value); #endif -typedef enum -{ - METADATA_EDITOR_FORMAT_MP3 = 0, /**< MP3 File */ - METADATA_EDITOR_FORMAT_MP4 = 1, /**< MP4 File */ - METADATA_EDITOR_FORMAT_FLAC, /**< FLAC File */ - METADATA_EDITOR_FORMAT_OGG_VORBIS, /**< Vorbis Audio in Ogg container */ - METADATA_EDITOR_FORMAT_OGG_FLAC, /**< FLAC Audio in Ogg container */ - METADATA_EDITOR_FORMAT_WAV, /**< WAV file */ - METADATA_EDITOR_FORMAT_NOTYPE = 0xFF /**< Error type. File type is not correct or not specified */ +typedef enum { + METADATA_EDITOR_FORMAT_MP3 = 0, /**< MP3 File */ + METADATA_EDITOR_FORMAT_MP4, /**< MP4 File */ + METADATA_EDITOR_FORMAT_FLAC, /**< FLAC File */ + METADATA_EDITOR_FORMAT_OGG_VORBIS, /**< Vorbis Audio in Ogg container */ + METADATA_EDITOR_FORMAT_OGG_FLAC, /**< FLAC Audio in Ogg container */ + METADATA_EDITOR_FORMAT_WAV, /**< WAV file */ + METADATA_EDITOR_FORMAT_NOTYPE = 0xFF /**< Error type. File type is not correct or not specified */ } metadata_editor_format_e; // *** This is an auxiliary function that is used to get the frame value *** // -// *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // +// *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) { // Check if we have valid arguments to work with @@ -62,48 +61,40 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); // Check if the frame is empty (nothing to read) or ID3v2 tag does not exist - if(!tag2 || tag2->frameListMap()[frameID].isEmpty()) - { + if (!tag2 || tag2->frameListMap()[frameID].isEmpty()) { metadata_editor_info("The frame %s in ID3v2 tag is empty\n", frameID); // Check if the tag ID3v1 is also empty or does not exist - if(!tag1 || tag1->isEmpty()) - { + if (!tag1 || tag1->isEmpty()) { metadata_editor_info("The frame %s in ID3v1 tag is empty as well\n", frameID); return METADATA_EDITOR_ERROR_NONE; - } - else // if not - read the frame you need there - { + } else { // if not - read the frame you need there metadata_editor_info("Reading data from ID3v1 tag\n"); TagLib::String str; uint length; bool found = false; - if(!strcmp(frameID, "TPE1")) // artist - { - str = tag1->artist(); found = true; - } - else if(!strcmp(frameID, "TALB")) // album - { - str = tag1->album(); found = true; - } - else if(!strcmp(frameID, "COMM")) // comment - { - str = tag1->comment(); found = true; - } - else if(!strcmp(frameID, "TCON")) // genre - { - str = tag1->genre(); found = true; - } - else if(!strcmp(frameID, "TIT2")) // title - { - str = tag1->title(); found = true; - } - // Check if we have already found the frame - if(found) - { + if (!strcmp(frameID, "TPE1")) { /* artist */ + str = tag1->artist(); + found = true; + } else if (!strcmp(frameID, "TALB")) { /* album */ + str = tag1->album(); + found = true; + } else if (!strcmp(frameID, "COMM")) { /* comment */ + str = tag1->comment(); + found = true; + } else if (!strcmp(frameID, "TCON")) { /* genre */ + str = tag1->genre(); + found = true; + } else if (!strcmp(frameID, "TIT2")) { /* title */ + str = tag1->title(); + found = true; + } + + /* Check if we have already found the frame */ + if (found) { bool isUTF = false; - if(!str.isLatin1()) isUTF = true; + if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); length = strlen(str.toCString(isUTF)); metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); @@ -113,37 +104,36 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: char buf[META_MAX_BUF_LEN] = {0, }; - if(!strcmp(frameID, "TRCK")) // track - { - // Convert int into char[] - snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->track()); found = true; + if (!strcmp(frameID, "TRCK")) { /* track */ + snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->track()); + found = true; + } else if (!strcmp(frameID, "TDRC")) { /* data (year) */ + snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->year()); + found = true; } - else if(!strcmp(frameID, "TDRC")) // data (year) - { - // Convert int into char[] - snprintf(buf, META_MAX_BUF_LEN, "%u", tag1->year()); found = true; - } - if(found) - { + + if (found) { length = strlen(buf); metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } - // The desired frame was not found + + /* The desired frame was not found */ return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - } - else // or frame has data to read - { + } else { // or frame has data to read metadata_editor_info("The frame %s exists in ID3v2 tag\n", frameID); + // This string is used to copy the value in the frame TagLib::String str = tag2->frameListMap()[frameID][0]->toString(); bool isUTF = false; - if(!str.isLatin1()) isUTF = true; + + if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); uint length = strlen(str.toCString(isUTF)); metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; @@ -151,7 +141,7 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: } // *** This is an auxiliary function that is used to write the new value to the frame *** // -// *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // +// *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) { // Check if we have valid arguments to work with @@ -166,24 +156,29 @@ static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); // If the pointer is NULL or c-string is empty - handle as request for deletion - if(!value || (*value == '\0')) - { + if (!value || (*value == '\0')) { metadata_editor_info("Request for frame %s deletion\n", frameID); tag2->removeFrames(frameID); - if(tag1 && !tag1->isEmpty()) - { - if(!strcmp(frameID, "TPE1")) { tag1->setArtist(""); } - else if(!strcmp(frameID, "TALB")) { tag1->setAlbum(""); } - else if(!strcmp(frameID, "TCON")) { tag1->setGenre(""); } - else if(!strcmp(frameID, "TIT2")) { tag1->setTitle(""); } - else if(!strcmp(frameID, "TRCK")) { tag1->setTrack(0); } - else if(!strcmp(frameID, "TDRC")) { tag1->setYear(0); } + if (tag1 && !tag1->isEmpty()) { + if (!strcmp(frameID, "TPE1")) + tag1->setArtist(""); + else if (!strcmp(frameID, "TALB")) + tag1->setAlbum(""); + else if (!strcmp(frameID, "TCON")) + tag1->setGenre(""); + else if (!strcmp(frameID, "TIT2")) + tag1->setTitle(""); + else if (!strcmp(frameID, "TRCK")) + tag1->setTrack(0); + else if (!strcmp(frameID, "TDRC")) + tag1->setYear(0); } + return METADATA_EDITOR_ERROR_NONE; } + // Check if the frame is empty (must create the frame before writing the data) - if(tag2->frameListMap()[frameID].isEmpty()) - { + if (tag2->frameListMap()[frameID].isEmpty()) { metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); // This is a common frame type for textural frames except comment frame TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); @@ -192,28 +187,27 @@ static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: fr->setTextEncoding(TagLib::String::UTF8); fr->setText(TagLib::String(value,TagLib::String::UTF8)); tag2->addFrame(fr); - } - else // if not - just modify the data in the existing frame - { + } else { // if not - just modify the data in the existing frame metadata_editor_info("The frame %s exists. Changing.\n", frameID); tag2->frameListMap()[frameID][0]->setText(TagLib::String(value,TagLib::String::UTF8)); } - if(tag1 && !tag1->isEmpty()) // Check if ID3v1 tag exists. Must copy data if yes. - { + + if (tag1 && !tag1->isEmpty()) { // Check if ID3v1 tag exists. Must copy data if yes. metadata_editor_info("ID3v1 tag also exists. Copying frame\n"); - if(!strcmp(frameID, "TPE1")) + if (!strcmp(frameID, "TPE1")) tag1->setArtist(value); - else if(!strcmp(frameID, "TALB")) + else if (!strcmp(frameID, "TALB")) tag1->setAlbum(value); - else if(!strcmp(frameID, "TCON")) // Genre in ID3v1 is enumeration, so can not write it with "value" + else if (!strcmp(frameID, "TCON")) // Genre in ID3v1 is enumeration, so can not write it with "value" tag1->setGenre(""); - else if(!strcmp(frameID, "TIT2")) + else if (!strcmp(frameID, "TIT2")) tag1->setTitle(value); - else if(!strcmp(frameID, "TRCK")) + else if (!strcmp(frameID, "TRCK")) tag1->setTrack(atoi(value)); - else if(!strcmp(frameID, "TDRC")) + else if (!strcmp(frameID, "TDRC")) tag1->setYear(atoi(value)); } + return METADATA_EDITOR_ERROR_NONE; } @@ -225,7 +219,6 @@ static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); - // Check if the file, given through metadata, exists and is opened correctly *value = NULL; metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); @@ -237,10 +230,12 @@ static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag // This string is used to copy the value in the frame TagLib::String str = tag2->frameListMap()[frameID][0]->toString(); bool isUTF = false; - if(!str.isLatin1()) isUTF = true; + if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); + uint length = strlen(str.toCString(isUTF)); metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; @@ -261,16 +256,14 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); // If the pointer is NULL or c-string is empty - handle as request for deletion - if(!value || (*value == '\0')) - { + if (!value || (*value == '\0')) { metadata_editor_info("Request for frame %s deletion\n", frameID); tag2->removeFrames(frameID); return METADATA_EDITOR_ERROR_NONE; } // Check if the ID3v2 tag exists - if (tag2->frameListMap()[frameID].isEmpty()) - { + if (tag2->frameListMap()[frameID].isEmpty()) { metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); // This is a common frame type for textural frames except comment frame TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); @@ -279,12 +272,11 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag fr->setTextEncoding(TagLib::String::UTF8); fr->setText(TagLib::String(value,TagLib::String::UTF8)); tag2->addFrame(fr); - } - else // if not - just modify the data in the existing frame - { + } else { // if not - just modify the data in the existing frame metadata_editor_info("The frame %s exists. Changing.\n", frameID); tag2->frameListMap()[frameID][0]->setText(TagLib::String(value,TagLib::String::UTF8)); } + return METADATA_EDITOR_ERROR_NONE; } @@ -302,7 +294,7 @@ static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2 // Check if the valid tag pointer exist metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); - TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // link to picture frames in tag + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // link to picture frames in tag // Check if the frames exist metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_NONE, "No pictures in file\n"); @@ -330,7 +322,7 @@ static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag // Check if the valid tag pointer exist metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag does not exist. Can not process further"); - TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag + TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag // Check if frames exist in file metadata_editor_retvm_if(lst.isEmpty(),METADATA_EDITOR_ERROR_NONE,"The frame USLT does not exist\n"); @@ -339,7 +331,7 @@ static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = static_cast(*it); TagLib::String str = frame->text(); bool isUTF = false; - if(!str.isLatin1()) isUTF = true; + if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); uint length = strlen(str.toCString(isUTF)); metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); @@ -362,34 +354,31 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1 metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); // If the pointer is NULL or c-string is empty - handle as request for deletion - if(!value || (*value == '\0')) - { + if (!value || (*value == '\0')) { metadata_editor_info("Request for frame COMM deletion\n"); tag2->removeFrames("COMM"); - if(tag1 && !tag1->isEmpty()) + if (tag1 && !tag1->isEmpty()) tag1->setComment(""); return METADATA_EDITOR_ERROR_NONE; } // If the comment frame is empty - create the frame and add it to the list - if (tag2->frameListMap()["COMM"].isEmpty()) - { + if (tag2->frameListMap()["COMM"].isEmpty()) { metadata_editor_info("The frame COMM does not exist. Creating.\n"); TagLib::ID3v2::CommentsFrame* fr = new TagLib::ID3v2::CommentsFrame; metadata_editor_retvm_if(fr == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY\n"); fr->setText(TagLib::String(value, TagLib::String::UTF8)); fr->setTextEncoding(TagLib::String::UTF8); tag2->addFrame(fr); - } - else // If the frame already exists - just modify its value - { + } else { // If the frame already exists - just modify its value metadata_editor_info("The frame COMM exists. Changing.\n"); tag2->frameListMap()["COMM"][0]->setText(TagLib::String(value,TagLib::String::UTF8)); } - if(tag1 && !tag1->isEmpty()) // Copy the value to ID3v1 tag comment - { + + if (tag1 && !tag1->isEmpty()) { // Copy the value to ID3v1 tag comment metadata_editor_info("ID3v1 tag also exists. Copying frame\n"); tag1->setComment(value); } + return METADATA_EDITOR_ERROR_NONE; } @@ -409,15 +398,13 @@ static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag // If the pointer is NULL or c-string is empty - handle as request for deletion - if(!value || (*value == '\0')) - { + if (!value || (*value == '\0')) { metadata_editor_info("Request for frame USLT deletion\n"); tag2->removeFrames("USLT"); return METADATA_EDITOR_ERROR_NONE; } // Check if lyrics frames exist - if(lst.isEmpty()) - { + if (lst.isEmpty()) { // No lyrics - create the frame and add it to the ID3v2 tag metadata_editor_info("The frame USLT does not exist. Creating.\n"); TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = new TagLib::ID3v2::UnsynchronizedLyricsFrame; @@ -426,15 +413,14 @@ static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag frame->setTextEncoding(TagLib::String::UTF8); frame->setText(TagLib::String(value,TagLib::String::UTF8)); tag2->addFrame(frame); - } - else // the lyrics frames exist - change the existing one - { + } else { // the lyrics frames exist - change the existing one metadata_editor_info("USLT frames exist in file. Changing.\n"); TagLib::ID3v2::FrameList::Iterator it = lst.begin(); TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = static_cast(*it); frame->setTextEncoding(TagLib::String::UTF8); frame->setText(TagLib::String(value,TagLib::String::UTF8)); } + return METADATA_EDITOR_ERROR_NONE; } @@ -458,21 +444,18 @@ static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemnam // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); - if(it != itemMap.end()) // Item was found - { + if (it != itemMap.end()) { // Item was found TagLib::String str = it->second.toStringList()[0]; // Get the first string in item // Check the encoding of the string (1252 or not) bool isUTF = false; - if(!str.isLatin1()) isUTF = true; + if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); // Get the length of the string and check if it is empty or not uint length = strlen(str.toCString(isUTF)); metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; - } - else // Item was not found - { + } else { // Item was not found metadata_editor_info("No item <%s> in file\n", itemname); return METADATA_EDITOR_ERROR_NONE; } @@ -498,8 +481,7 @@ static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemna // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find(itemname); - if(it != itemMap.end()) // Item was found - { + if (it != itemMap.end()) { // Item was found char buf[META_MAX_BUF_LEN] = {0, }; int num = it->second.toInt(); // Get integer value in item snprintf(buf, META_MAX_BUF_LEN, "%u", num); // Convert int into char[] @@ -508,9 +490,7 @@ static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemna metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; - } - else // Item was not found - { + } else { // Item was not found metadata_editor_info("No item <%s> in file\n", itemname); return METADATA_EDITOR_ERROR_NONE; } @@ -535,16 +515,16 @@ static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* item // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); // Check if it is a request for deletion - if((value == NULL) || value[0] == '\0') - { + if ((value == NULL) || value[0] == '\0') { metadata_editor_info("Request for deleting of item <%s>\n", itemname); TagLib::MP4::ItemListMap::Iterator it = itemMap.find(itemname); - if(it != itemMap.end()) + if (it != itemMap.end()) itemMap.erase(it); return METADATA_EDITOR_ERROR_NONE; } metadata_editor_info("The item <%s> will be added\n", itemname); itemMap[itemname] = TagLib::MP4::Item(TagLib::String(value, TagLib::String::UTF8)); + return METADATA_EDITOR_ERROR_NONE; } @@ -567,24 +547,20 @@ static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* ite // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); // Check if it is a request for deletion - if((value == NULL) || value[0] == '\0') - { + if ((value == NULL) || value[0] == '\0') { metadata_editor_info("Request for deleting of item <%s>\n", itemname); TagLib::MP4::ItemListMap::Iterator it = itemMap.find(itemname); - if(it != itemMap.end()) + if (it != itemMap.end()) itemMap.erase(it); return METADATA_EDITOR_ERROR_NONE; } // Check if the value is integer string then it can be successfully converted into integer - if(isdigit(value[0])) - { + if (isdigit(value[0])) { metadata_editor_info("The item <%s> will be added\n", itemname); int number = atoi(value); itemMap[itemname] = TagLib::MP4::Item(number); return METADATA_EDITOR_ERROR_NONE; - } - else // Notify that string is not a number to process - { + } else { // Notify that string is not a number to process metadata_editor_error("Error. String does not contain a number\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } @@ -609,8 +585,7 @@ static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); - if(it != itemMap.end()) // Item was found - { + if (it != itemMap.end()) { // Item was found uint number = it->second.toCoverArtList().size(); // Get the size of CoverList (i.e. number of pictures in file) metadata_editor_info("There are %u picture(s) in file\n", number); char buf[META_MAX_BUF_LEN] = {0, }; @@ -619,9 +594,7 @@ static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; - } - else // Item was not found - { + } else { // Item was not found metadata_editor_info("No item in file\n"); return METADATA_EDITOR_ERROR_NONE; } @@ -643,22 +616,19 @@ static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphC const TagLib::Ogg::FieldListMap& fieldMap = xtag->fieldListMap(); TagLib::Ogg::FieldListMap::ConstIterator it = fieldMap.find(fieldname); - if((xtag->contains(fieldname)) && (it != fieldMap.end())) // Field was found - { + if ((xtag->contains(fieldname)) && (it != fieldMap.end())) { // Field was found metadata_editor_info("Field %s was found. Extracting\n", fieldname); TagLib::String str = it->second[0]; // Get the first string in xiph field // Check the encoding of the string (1252 or not) bool isUTF = false; - if(!str.isLatin1()) isUTF = true; + if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); // Get the length of the string and check if it is empty or not uint length = strlen(str.toCString(isUTF)); metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; - } - else // Field was not found - { + } else { // Field was not found metadata_editor_info("No field %s in Xiph Comment\n", fieldname); return METADATA_EDITOR_ERROR_NONE; } @@ -678,8 +648,7 @@ static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::Xi metadata_editor_retvm_if(!xtag,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); // Check if it is a request for deletion - if((value == NULL) || value[0] == '\0') - { + if ((value == NULL) || value[0] == '\0') { metadata_editor_info("Request for deleting of field %s\n", fieldname); xtag->removeField(fieldname); return METADATA_EDITOR_ERROR_NONE; @@ -703,8 +672,7 @@ static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; - if(_file->pictureList().isEmpty()) - { + if (_file->pictureList().isEmpty()) { metadata_editor_info("No pictures in FLAC file\n"); return METADATA_EDITOR_ERROR_NONE; } @@ -723,19 +691,15 @@ int __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int ma int i = 0; unsigned int path_len = strlen(file_path); - for (i = (int)path_len; i >= 0; i--) - { - if ((file_path[i] == '.') && (i < (int)path_len)) - { + for (i = (int)path_len; i >= 0; i--) { + if ((file_path[i] == '.') && (i < (int)path_len)) { strncpy(file_ext, &file_path[i + 1], max_len); return 0; } /* meet the dir. no ext */ if (file_path[i] == '/') - { return -1; - } } return -1; @@ -748,8 +712,7 @@ int __metadata_editor_get_file_type(const char *path) /* get content type and mime type from file. */ ret = aul_get_mime_from_file(path, mimetype, sizeof(mimetype)); - if (ret < 0) - { + if (ret < 0) { metadata_editor_debug("aul_get_mime_from_file fail.. Now trying to get type by extension"); char ext[255] = { 0 }; @@ -757,30 +720,20 @@ int __metadata_editor_get_file_type(const char *path) metadata_editor_retvm_if(ret < 0,METADATA_EDITOR_FORMAT_NOTYPE,"__metadata_editor_get_file_type failed"); if (strcasecmp(ext, "MP3") == 0) - { return METADATA_EDITOR_FORMAT_MP3; - } else if (strcasecmp(ext, "MP4") == 0) - { return METADATA_EDITOR_FORMAT_MP4; - } else - { return METADATA_EDITOR_FORMAT_NOTYPE; - } } metadata_editor_debug("mime type : %s", mimetype); /* categorize from mimetype */ if (strstr(mimetype, "mpeg") != NULL) - { return METADATA_EDITOR_FORMAT_MP3; - } else if (strstr(mimetype, "mp4") != NULL) - { return METADATA_EDITOR_FORMAT_MP4; - } return METADATA_EDITOR_FORMAT_NOTYPE; } @@ -794,26 +747,20 @@ int __metadata_editor_get_picture_type(const char *path, char **type) /* get content type and mime type from file. */ ret = aul_get_mime_from_file(path, mimetype, sizeof(mimetype)); - if (ret < 0) - { + if (ret < 0) { metadata_editor_debug("aul_get_mime_from_file fail.. Now trying to get type by extension"); char ext[255] = { 0 }; int ret = __metadata_editor_get_file_ext(path, ext, sizeof(ext)); metadata_editor_retvm_if(ret < 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"__metadata_editor_get_file_type failed"); - if (strcasecmp(ext, "JPG") == 0 || strcasecmp(ext, "JPEG") == 0) - { + if (strcasecmp(ext, "JPG") == 0 || strcasecmp(ext, "JPEG") == 0) { *type = strndup(type_jpeg, strlen(type_jpeg)); return METADATA_EDITOR_ERROR_NONE; - } - else if (strcasecmp(ext, "PNG") == 0) - { + } else if (strcasecmp(ext, "PNG") == 0) { *type = strndup(type_png, strlen(type_png)); return METADATA_EDITOR_ERROR_NONE; - } - else - { + } else { return METADATA_EDITOR_ERROR_NOT_SUPPORTED; } } @@ -821,13 +768,10 @@ int __metadata_editor_get_picture_type(const char *path, char **type) metadata_editor_debug("mime type : %s", mimetype); /* categorize from mimetype */ - if (strstr(mimetype, "jpeg") != NULL) - { + if (strstr(mimetype, "jpeg") != NULL) { *type = strndup(mimetype, strlen(mimetype)); return METADATA_EDITOR_ERROR_NONE; - } - else if (strstr(mimetype, "png") != NULL) - { + } else if (strstr(mimetype, "png") != NULL) { *type = strndup(mimetype, strlen(mimetype)); return METADATA_EDITOR_ERROR_NONE; } @@ -840,28 +784,26 @@ int __metadata_editor_get_picture_info(const char *path, void **picture, int *si int ret; ret = __metadata_editor_get_picture_type(path, type); - if(ret != METADATA_EDITOR_ERROR_NONE) + if (ret != METADATA_EDITOR_ERROR_NONE) return METADATA_EDITOR_ERROR_OPERATION_FAILED; //IF ok.. read file FILE* fin = fopen(path, "rb"); int file_size = 0; - if(fin) - { - while(fgetc(fin) != EOF) - { + if (fin) { + while (fgetc(fin) != EOF) file_size++; - } + fclose(fin); char picture_buffer[file_size] = {0,}; memset(picture_buffer, 0, file_size * sizeof(char)); fin = fopen(path, "rb"); - if(fin) { + if (fin) { ret = fread(picture_buffer, file_size, 1, fin); fclose(fin); } - if(*picture == NULL) { + if (*picture == NULL) { *picture = malloc(file_size * sizeof(char)); memset(*picture, 0, file_size * sizeof(char)); memcpy(*picture, picture_buffer, file_size); @@ -872,9 +814,10 @@ int __metadata_editor_get_picture_info(const char *path, void **picture, int *si return METADATA_EDITOR_ERROR_NONE; } -bool __metadata_editor_file_exist(const std::string& name) { +bool __metadata_editor_file_exist(const std::string& name) +{ struct stat buffer; - return (stat (name.c_str(), &buffer) == 0); + return (stat(name.c_str(), &buffer) == 0); } @@ -906,8 +849,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); metadata_editor_retvm_if(path == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); - if(!__metadata_editor_file_exist(path)) - { + if (!__metadata_editor_file_exist(path)) { metadata_editor_error("Not exist file\n"); return METADATA_EDITOR_ERROR_FILE_EXISTS; } @@ -917,8 +859,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * media_type = __metadata_editor_get_file_type(path); - switch(media_type) // Parse file according the specified type - { + switch (media_type) { // Parse file according the specified type case METADATA_EDITOR_FORMAT_MP3: { // Allocate the file object in memory to work with it later on @@ -930,27 +871,23 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_MP3; - if (_file->isOpen()) // Check if the file was opened successfully - { + if (_file->isOpen()) { // Check if the file was opened successfully metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); _metadata->isOpen = true; - } - else // The file does not exist or you have no permission to process it - { + } else { // The file does not exist or you have no permission to process it metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); _metadata->isOpen = false; return METADATA_EDITOR_ERROR_PERMISSION_DENIED; } - if(_file->readOnly()) // Check if the file is readonly - { + + if (_file->readOnly()) { // Check if the file is readonly metadata_editor_info("File is readonly\n"); _metadata->isReadOnly = true; - } - else // or not - { + } else { // or not metadata_editor_info("The file is writable\n"); _metadata->isReadOnly = false; } + return METADATA_EDITOR_ERROR_NONE; } case METADATA_EDITOR_FORMAT_MP4: @@ -964,24 +901,18 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_MP4; - if (_file->isOpen()) // Check if the file was opened successfully - { + if (_file->isOpen()) { // Check if the file was opened successfully metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); _metadata->isOpen = true; - } - else // The file does not exist or you have no permission to process it - { + } else { // The file does not exist or you have no permission to process it metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); _metadata->isOpen = false; return METADATA_EDITOR_ERROR_FILE_EXISTS; } - if(_file->readOnly()) // Check if the file is readonly - { + if (_file->readOnly()) { // Check if the file is readonly metadata_editor_info("File is readonly\n"); _metadata->isReadOnly = true; - } - else // or not - { + } else { // or not metadata_editor_info("The file is writable\n"); _metadata->isReadOnly = false; } @@ -999,24 +930,18 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_FLAC; - if (_file->isOpen()) // Check if the file was opened successfully - { + if (_file->isOpen()) { // Check if the file was opened successfully metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); _metadata->isOpen = true; - } - else // The file does not exist or you have no permission to process it - { + } else { // The file does not exist or you have no permission to process it metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); _metadata->isOpen = false; return METADATA_EDITOR_ERROR_FILE_EXISTS; } - if(_file->readOnly()) // Check if the file is readonly - { + if (_file->readOnly()) { // Check if the file is readonly metadata_editor_info("File is readonly\n"); _metadata->isReadOnly = true; - } - else // or not - { + } else { // or not metadata_editor_info("The file is writable\n"); _metadata->isReadOnly = false; } @@ -1033,24 +958,18 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_OGG_VORBIS; - if (_file->isOpen()) // Check if the file was opened successfully - { + if (_file->isOpen()) { // Check if the file was opened successfully metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); _metadata->isOpen = true; - } - else // The file does not exist or you have no permission to process it - { + } else { // The file does not exist or you have no permission to process it metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); _metadata->isOpen = false; return METADATA_EDITOR_ERROR_FILE_EXISTS; } - if(_file->readOnly()) // Check if the file is readonly - { + if (_file->readOnly()) { // Check if the file is readonly metadata_editor_info("File is readonly\n"); _metadata->isReadOnly = true; - } - else // or not - { + } else { // or not metadata_editor_info("The file is writable\n"); _metadata->isReadOnly = false; } @@ -1067,24 +986,18 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_OGG_FLAC; - if (_file->isOpen()) // Check if the file was opened successfully - { + if (_file->isOpen()) { // Check if the file was opened successfully metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); _metadata->isOpen = true; - } - else // The file does not exist or you have no permission to process it - { + } else { // The file does not exist or you have no permission to process it metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); _metadata->isOpen = false; return METADATA_EDITOR_ERROR_FILE_EXISTS; } - if(_file->readOnly()) // Check if the file is readonly - { + if (_file->readOnly()) { // Check if the file is readonly metadata_editor_info("File is readonly\n"); _metadata->isReadOnly = true; - } - else // or not - { + } else { // or not metadata_editor_info("The file is writable\n"); _metadata->isReadOnly = false; } @@ -1101,24 +1014,18 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_WAV; - if (_file->isOpen()) // Check if the file was opened successfully - { + if (_file->isOpen()) { // Check if the file was opened successfully metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); _metadata->isOpen = true; - } - else // The file does not exist or you have no permission to process it - { + } else { // The file does not exist or you have no permission to process it metadata_editor_error("The file was not found. Pointer address is %lX\n", _metadata->file); _metadata->isOpen = false; return METADATA_EDITOR_ERROR_FILE_EXISTS; } - if(_file->readOnly()) // Check if the file is readonly - { + if (_file->readOnly()) { // Check if the file is readonly metadata_editor_info("File is readonly\n"); _metadata->isReadOnly = true; - } - else // or not - { + } else { // or not metadata_editor_info("The file is writable\n"); _metadata->isReadOnly = false; } @@ -1145,8 +1052,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata *value = NULL; metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); - switch(_metadata->filetype) // Process the file according to the specified file type - { + switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tag pointers @@ -1154,8 +1060,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(); - switch (attribute) // Check which one of frame types was given to the function for processing - { + switch (attribute) { // Check which one of frame types was given to the function for processing case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TPE1", value); case METADATA_EDITOR_ATTR_TITLE: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TIT2", value); case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TALB", value); @@ -1168,15 +1073,14 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getTwixFrameByName(_metadata, tag1, tag2, "TRCK", value); case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(_metadata, tag2, "TPE3", value); case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(_metadata, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); default: return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } case METADATA_EDITOR_FORMAT_MP4: { - switch(attribute) // Check which one of frame types was given to the function for processing - { + switch (attribute) { // Check which one of frame types was given to the function for processing case METADATA_EDITOR_ATTR_ARTIST: return __MP4_getStringItem(_metadata, "\xA9""ART", value); case METADATA_EDITOR_ATTR_TITLE: return __MP4_getStringItem(_metadata, "\xA9""nam", value); case METADATA_EDITOR_ATTR_ALBUM: return __MP4_getStringItem(_metadata, "\xA9""alb", value); @@ -1200,14 +1104,12 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata // Bring the pointer to actual file type and make tags pointers TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->xiphComment(false); - if(!xtag) // Check if we have a valid tag for processing - { + if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist\n"); *value = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch(attribute) // Check which one of frame types was given to the function for processing - { + switch (attribute) { // Check which one of frame types was given to the function for processing case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(_metadata, xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(_metadata, xtag, "TITLE", value); case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(_metadata, xtag, "ALBUM", value); @@ -1230,14 +1132,12 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); - if(!xtag) // Check if we have a valid tag for processing - { + if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist\n"); *value = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch(attribute) // Check which one of frame types was given to the function for processing - { + switch (attribute) { // Check which one of frame types was given to the function for processing case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(_metadata, xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(_metadata, xtag, "TITLE", value); case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(_metadata, xtag, "ALBUM", value); @@ -1259,14 +1159,12 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); - if(!xtag) // Check if we have a valid tag for processing - { + if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Tag does not exist\n"); *value = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch(attribute) // Check which one of frame types was given to the function for processing - { + switch (attribute) { // Check which one of frame types was given to the function for processing case METADATA_EDITOR_ATTR_ARTIST: return __xiph_getFieldValue(_metadata, xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_getFieldValue(_metadata, xtag, "TITLE", value); case METADATA_EDITOR_ATTR_ALBUM: return __xiph_getFieldValue(_metadata, xtag, "ALBUM", value); @@ -1289,15 +1187,13 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); - if(tag2 == NULL) // Check if we have a valid tag for processing - { + if (tag2 == NULL) { // Check if we have a valid tag for processing metadata_editor_error("Error. ID3v2 tag does not exist. Can not proceed metadata extraction\n"); *value = NULL; return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch (attribute) // Check which one of frame types was given to the function for processing - { + switch (attribute) { // Check which one of frame types was given to the function for processing case METADATA_EDITOR_ATTR_ARTIST: return __ID3_getFrameByName(_metadata, tag2, "TPE1", value); case METADATA_EDITOR_ATTR_TITLE: return __ID3_getFrameByName(_metadata, tag2, "TIT2", value); case METADATA_EDITOR_ATTR_ALBUM: return __ID3_getFrameByName(_metadata, tag2, "TALB", value); @@ -1310,7 +1206,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_getFrameByName(_metadata, tag2, "TRCK", value); case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_getFrameByName(_metadata, tag2, "TPE3", value); case METADATA_EDITOR_ATTR_PICTURE_NUM: return __ID3_getNumberOfPictures(_metadata, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_getLyricsFrame(_metadata, tag2, value); default: return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } @@ -1336,8 +1232,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); - switch(_metadata->filetype) // Process the file according to the specified file type - { + switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tags pointers @@ -1347,28 +1242,26 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); - switch (attribute) // Check which one of frame type was given for processing - { - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(_metadata, tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(_metadata, tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(_metadata, tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(_metadata, tag2, "TPE3", value); - case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(_metadata, tag1, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(_metadata, tag2, value); + switch (attribute) { // Check which one of frame type was given for processing + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(_metadata, tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(_metadata, tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(_metadata, tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(_metadata, tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(_metadata, tag1, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(_metadata, tag2, value); default: return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } case METADATA_EDITOR_FORMAT_MP4: { - switch(attribute) // Check which one of frame type was given for processing - { + switch (attribute) { // Check which one of frame type was given for processing case METADATA_EDITOR_ATTR_ARTIST: return __MP4_updateStringItem(_metadata, "\xA9""ART", value); case METADATA_EDITOR_ATTR_TITLE: return __MP4_updateStringItem(_metadata, "\xA9""nam", value); case METADATA_EDITOR_ATTR_ALBUM: return __MP4_updateStringItem(_metadata, "\xA9""alb", value); @@ -1391,13 +1284,11 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata // Bring the pointer to actual file type and make tags pointers TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->xiphComment(true); - if(!xtag) // Check if we have a valid tag for processing - { + if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch(attribute) // Check which one of frame type was given for processing - { + switch (attribute) { // Check which one of frame type was given for processing case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(_metadata, xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(_metadata, xtag, "TITLE", value); case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(_metadata, xtag, "ALBUM", value); @@ -1419,13 +1310,11 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); - if(!xtag) // Check if we have a valid tag for processing - { + if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch(attribute) // Check which one of frame type was given for processing - { + switch (attribute) { // Check which one of frame type was given for processing case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(_metadata, xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(_metadata, xtag, "TITLE", value); case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(_metadata, xtag, "ALBUM", value); @@ -1447,13 +1336,11 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); - if(!xtag) // Check if we have a valid tag for processing - { + if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch(attribute) // Check which one of frame type was given for processing - { + switch (attribute) { // Check which one of frame type was given for processing case METADATA_EDITOR_ATTR_ARTIST: return __xiph_updateFieldValue(_metadata, xtag, "ARTIST", value); case METADATA_EDITOR_ATTR_TITLE: return __xiph_updateFieldValue(_metadata, xtag, "TITLE", value); case METADATA_EDITOR_ATTR_ALBUM: return __xiph_updateFieldValue(_metadata, xtag, "ALBUM", value); @@ -1476,26 +1363,24 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); // Check if the valid tag pointer exist - if(tag2 == NULL) - { + if (tag2 == NULL) { metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - switch (attribute) // Check which one of frame type was given for processing - { - case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setFrameByName(_metadata, tag2, "TPE1", value); - case METADATA_EDITOR_ATTR_TITLE: return __ID3_setFrameByName(_metadata, tag2, "TIT2", value); - case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setFrameByName(_metadata, tag2, "TALB", value); - case METADATA_EDITOR_ATTR_GENRE: return __ID3_setFrameByName(_metadata, tag2, "TCON", value); - case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(_metadata, tag2, "TCOM", value); - case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(_metadata, tag2, "TCOP", value); - case METADATA_EDITOR_ATTR_DATE: return __ID3_setFrameByName(_metadata, tag2, "TDRC", value); - case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(_metadata, tag2, "TIT3", value); - case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setFrameByName(_metadata, tag2, "TRCK", value); - case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(_metadata, tag2, "TPE3", value); - case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(_metadata, NULL, tag2, value); - case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(_metadata, tag2, value); + switch (attribute) { // Check which one of frame type was given for processing + case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setFrameByName(_metadata, tag2, "TPE1", value); + case METADATA_EDITOR_ATTR_TITLE: return __ID3_setFrameByName(_metadata, tag2, "TIT2", value); + case METADATA_EDITOR_ATTR_ALBUM: return __ID3_setFrameByName(_metadata, tag2, "TALB", value); + case METADATA_EDITOR_ATTR_GENRE: return __ID3_setFrameByName(_metadata, tag2, "TCON", value); + case METADATA_EDITOR_ATTR_AUTHOR: return __ID3_setFrameByName(_metadata, tag2, "TCOM", value); + case METADATA_EDITOR_ATTR_COPYRIGHT: return __ID3_setFrameByName(_metadata, tag2, "TCOP", value); + case METADATA_EDITOR_ATTR_DATE: return __ID3_setFrameByName(_metadata, tag2, "TDRC", value); + case METADATA_EDITOR_ATTR_DESCRIPTION: return __ID3_setFrameByName(_metadata, tag2, "TIT3", value); + case METADATA_EDITOR_ATTR_TRACK_NUM: return __ID3_setFrameByName(_metadata, tag2, "TRCK", value); + case METADATA_EDITOR_ATTR_CONDUCTOR: return __ID3_setFrameByName(_metadata, tag2, "TPE3", value); + case METADATA_EDITOR_ATTR_COMMENT: return __ID3_setTwixCommentFrame(_metadata, NULL, tag2, value); + case METADATA_EDITOR_ATTR_UNSYNCLYRICS: return __ID3_setLyricsFrame(_metadata, tag2, value); default: return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } @@ -1520,8 +1405,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); - switch(_metadata->filetype) // Process the file according to the specified file type - { + switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type @@ -1529,16 +1413,13 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); - if(!tag1 || tag1->isEmpty()) // If no ID3v1 tag - prevent its creation - { - if(_file->save(TagLib::MPEG::File::ID3v2 | TagLib::MPEG::File::APE)) + if (!tag1 || tag1->isEmpty()) { // If no ID3v1 tag - prevent its creation + if (_file->save(TagLib::MPEG::File::ID3v2 | TagLib::MPEG::File::APE)) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - else // otherwise - save all tags in file - { - if(_file->save(TagLib::MPEG::File::AllTags)) + } else { // otherwise - save all tags in file + if (_file->save(TagLib::MPEG::File::AllTags)) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1547,7 +1428,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; - if(_file->save()) + if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1556,7 +1437,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) case METADATA_EDITOR_FORMAT_FLAC: { TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; - if(_file->save()) + if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1564,7 +1445,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) case METADATA_EDITOR_FORMAT_OGG_VORBIS: { TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; - if(_file->save()) + if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1572,7 +1453,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) case METADATA_EDITOR_FORMAT_OGG_FLAC: { TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; - if(_file->save()) + if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1580,7 +1461,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) case METADATA_EDITOR_FORMAT_WAV: { TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; - if(_file->save()) + if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; @@ -1612,8 +1493,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); - switch(_metadata->filetype) // Process the file according to the specified file type - { + switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: { TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; // Bring the pointer to actual file type @@ -1622,27 +1502,20 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag - if(lst.isEmpty()) - { + if (lst.isEmpty()) { metadata_editor_error("No pictures in file\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - else // pictures exist in file - { + } else { // pictures exist in file // Check if index is correct or not - if( (index < 0) || (lst.size() <= (uint)index) ) - { + if ((index < 0) || (lst.size() <= (uint)index)) { metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // everything is correct - begin extraction - { + } else { // everything is correct - begin extraction metadata_editor_info("There are %u pictures in file. Start of picture number %d extraction", lst.size(), index); int i = 0; // Among all frames we must choose that one with specified index. "i" will be counter - for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) - { - if(i != index) continue; + for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) { + if (i != index) continue; TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); uint pictureSize = pictureFrame->picture().size(); metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); @@ -1652,9 +1525,9 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index memcpy(*picture, pictureFrame->picture().data(), pictureSize); *size = pictureSize; TagLib::String mime = pictureFrame->mimeType(); - if(!strcmp(mime.toCString(),"image/jpeg")) + if (!strcmp(mime.toCString(),"image/jpeg")) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); - else if(!strcmp(mime.toCString(),"image/png")) + else if (!strcmp(mime.toCString(),"image/png")) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); else *mime_type = NULL; @@ -1673,21 +1546,16 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); - if(it != itemMap.end()) // Item was found - { + if (it != itemMap.end()) { // Item was found TagLib::MP4::CoverArtList lst = it->second.toCoverArtList(); // Check if the index is in range of CoverArtList Item - if((index < 0) || ((uint)index >= lst.size())) // it is not - { + if ((index < 0) || ((uint)index >= lst.size())) { // it is not metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // index is in range - { + } else { // index is in range int i = 0; - for(TagLib::MP4::CoverArtList::ConstIterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) - { - if(i != index) continue; + for (TagLib::MP4::CoverArtList::ConstIterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { + if (i != index) continue; int pictureSize = picIt->data().size(); metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); META_MALLOC(*picture, pictureSize); @@ -1695,16 +1563,14 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index memcpy(*picture, picIt->data().data(), pictureSize); *size = pictureSize; - if(picIt->format() == TagLib::MP4::CoverArt::JPEG) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); - else if(picIt->format() == TagLib::MP4::CoverArt::PNG) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); + if (picIt->format() == TagLib::MP4::CoverArt::JPEG) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); + else if (picIt->format() == TagLib::MP4::CoverArt::PNG) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); else *mime_type = NULL; break; } return METADATA_EDITOR_ERROR_NONE; } - } - else // Item was not found - no pictures in file - { + } else { // Item was not found - no pictures in file metadata_editor_error("No item in file. No pictures in file\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } @@ -1714,26 +1580,19 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index { TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; TagLib::List lst = _file->pictureList(); - if(lst.isEmpty()) - { + if (lst.isEmpty()) { metadata_editor_error("No pictures in FLAC file\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - else - { + } else { // Check if the index is in range of CoverArtList Item - if((index < 0) || ((uint)index >= lst.size())) // it is not - { + if ((index < 0) || ((uint)index >= lst.size())) { // it is not metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // index is in range - { + } else { // index is in range // Consecutive check of all pictures until the desired one is found int i = 0; - for(TagLib::List::ConstIterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) - { - if(i != index) continue; + for (TagLib::List::ConstIterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { + if (i != index) continue; // picture can be received as ByteVector (picIt->data()). // ByteVector has data() - picture itself and size() - the size of picture in data() method int pictureSize = (*picIt)->data().size(); @@ -1744,9 +1603,9 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index memcpy(*picture, (*picIt)->data().data(), pictureSize); *size = pictureSize; TagLib::String mime = (*picIt)->mimeType(); - if(!strcmp(mime.toCString(),"image/jpeg")) + if (!strcmp(mime.toCString(),"image/jpeg")) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); - else if(!strcmp(mime.toCString(),"image/png")) + else if (!strcmp(mime.toCString(),"image/png")) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); else *mime_type = NULL; @@ -1760,34 +1619,26 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index { TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; // Bring the pointer to actual file type TagLib::ID3v2::Tag* tag2 = _file->tag(); - if(!tag2) - { + if (!tag2) { metadata_editor_error("No ID3v2 tag in file\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag - if(lst.isEmpty()) - { + if (lst.isEmpty()) { metadata_editor_error("No pictures in file\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - else // pictures exist in file - { + } else { // pictures exist in file // Check if index is correct or not - if( (index < 0) || (lst.size() <= (uint)index) ) - { + if ((index < 0) || (lst.size() <= (uint)index)) { metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // everything is correct - begin extraction - { + } else { // everything is correct - begin extraction metadata_editor_info("There are %u pictures in file. Start of picture number %d extraction", lst.size(), index); int i = 0; // Among all frames we must choose that one with specified index. "i" will be counter - for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) - { - if(i != index) continue; + for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) { + if (i != index) continue; TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); uint pictureSize = pictureFrame->picture().size(); metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); @@ -1798,9 +1649,9 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index memcpy(*picture, pictureFrame->picture().data(), pictureSize); *size = pictureSize; TagLib::String mime = pictureFrame->mimeType(); - if(!strcmp(mime.toCString(),"image/jpeg")) + if (!strcmp(mime.toCString(),"image/jpeg")) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); - else if(!strcmp(mime.toCString(),"image/png")) + else if (!strcmp(mime.toCString(),"image/png")) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); else *mime_type = NULL; @@ -1839,25 +1690,22 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const ret = __metadata_editor_get_picture_info(path, &picture, &size, &type); metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); - switch(_metadata->filetype) // Process the file according to the specified file type - { + switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tags pointers TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); // Check if the valid tag pointer exists - if(tag2 == NULL) - { + if (tag2 == NULL) { metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; + ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; break; } TagLib::ID3v2::AttachedPictureFrame* pictureFrame = new TagLib::ID3v2::AttachedPictureFrame(); - if(pictureFrame == NULL) - { + if (pictureFrame == NULL) { metadata_editor_error("OUT_OF_MEMORY\n"); - ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; break; } metadata_editor_info("New APIC frame will be added to the ID3v2 tag\n"); @@ -1867,31 +1715,29 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const tag2->addFrame(pictureFrame); - ret = METADATA_EDITOR_ERROR_NONE; + ret = METADATA_EDITOR_ERROR_NONE; break; } case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - if(!tag) - { + if (!tag) { metadata_editor_error("Tag was not created\n"); - ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; + ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; break; } // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); - if(it != itemMap.end()) // Item was found - { + if (it != itemMap.end()) { // Item was found metadata_editor_info("The item exists. Adding picture\n"); TagLib::MP4::CoverArtList lst = it->second.toCoverArtList(); TagLib::MP4::CoverArt::Format format; - if(strncmp(type, "image/jpeg", strlen("image/jpeg")) == 0) + if (strncmp(type, "image/jpeg", strlen("image/jpeg")) == 0) format = TagLib::MP4::CoverArt::JPEG; - else if(strncmp(type, "image/png", strlen("image/jpeg")) == 0) + else if (strncmp(type, "image/png", strlen("image/jpeg")) == 0) format = TagLib::MP4::CoverArt::PNG; else format = (TagLib::MP4::CoverArt::Format)0xFFFF; @@ -1899,16 +1745,14 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const lst.append(cover); itemMap.insert("covr", TagLib::MP4::Item(lst)); - ret = METADATA_EDITOR_ERROR_NONE; + ret = METADATA_EDITOR_ERROR_NONE; break; - } - else // Item was not found - { + } else { // Item was not found metadata_editor_info("The item does not exist. Adding picture\n"); TagLib::MP4::CoverArt::Format format; - if(strncmp(type, "image/jpeg", strlen("image/jpeg")) == 0) + if (strncmp(type, "image/jpeg", strlen("image/jpeg")) == 0) format = TagLib::MP4::CoverArt::JPEG; - else if(strncmp(type, "image/png", strlen("image/jpeg")) == 0) + else if (strncmp(type, "image/png", strlen("image/jpeg")) == 0) format = TagLib::MP4::CoverArt::PNG; else format = (TagLib::MP4::CoverArt::Format)0xFFFF; @@ -1917,7 +1761,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const lst.append(cover); itemMap.insert("covr", TagLib::MP4::Item(lst)); - ret = METADATA_EDITOR_ERROR_NONE; + ret = METADATA_EDITOR_ERROR_NONE; break; } } @@ -1926,10 +1770,9 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const { TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; TagLib::FLAC::Picture* frontCover = new TagLib::FLAC::Picture; - if(frontCover == NULL) - { + if (frontCover == NULL) { metadata_editor_error("OUT_OF_MEMORY\n"); - ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; + ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; break; } frontCover->setData(TagLib::ByteVector((char*)picture, size)); @@ -1938,7 +1781,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const metadata_editor_info("Picture will be added to FLAC file\n"); _file->addPicture(frontCover); - ret = METADATA_EDITOR_ERROR_NONE; + ret = METADATA_EDITOR_ERROR_NONE; break; } case METADATA_EDITOR_FORMAT_WAV: @@ -1947,15 +1790,13 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); // Check if the valid tag pointer exists - if(tag2 == NULL) - { + if (tag2 == NULL) { metadata_editor_error("Error. ID3v2 tag was not created. Can not proceed metadata updating\n"); - ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; + ret = METADATA_EDITOR_ERROR_OPERATION_FAILED; break; } TagLib::ID3v2::AttachedPictureFrame* pictureFrame = new TagLib::ID3v2::AttachedPictureFrame(); - if(pictureFrame == NULL) - { + if (pictureFrame == NULL) { metadata_editor_error("OUT_OF_MEMORY\n"); ret = METADATA_EDITOR_ERROR_OUT_OF_MEMORY; break; @@ -1965,14 +1806,14 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const pictureFrame->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover); pictureFrame->setMimeType(type); tag2->addFrame(pictureFrame); - ret = METADATA_EDITOR_ERROR_NONE; + ret = METADATA_EDITOR_ERROR_NONE; break; } #endif default: { metadata_editor_error("Wrong file type\n"); - ret = METADATA_EDITOR_ERROR_NOT_SUPPORTED; + ret = METADATA_EDITOR_ERROR_NOT_SUPPORTED; break; } } @@ -1996,8 +1837,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); - switch(_metadata->filetype) // Process the file according to the specified file type - { + switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tags pointers @@ -2007,27 +1847,20 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag - if(lst.isEmpty()) - { + if (lst.isEmpty()) { metadata_editor_error("No pictures in file\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - else // pictures exist in file - { + } else { // pictures exist in file // Check if index is correct or not - if( (index < 0) || (lst.size() <= (uint)index) ) - { + if ((index < 0) || (lst.size() <= (uint)index)) { metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // everything is correct - begin extraction - { + } else { // everything is correct - begin extraction metadata_editor_info("Removing of picture number %d\n", index); int i = 0; // Among all frames we must choose that one with specified index. "i" will be counter - for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) - { - if(i != index) continue; + for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) { + if (i != index) continue; tag2->removeFrame(*it); break; } @@ -2044,31 +1877,24 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); TagLib::MP4::ItemListMap::ConstIterator it = itemMap.find("covr"); - if(it != itemMap.end()) // Item was found - { + if (it != itemMap.end()) { // Item was found TagLib::MP4::CoverArtList lst = it->second.toCoverArtList(); // Check if the index is in range of CoverArtList Item - if((index < 0) || ((uint)index >= lst.size())) // it is not - { + if ((index < 0) || ((uint)index >= lst.size())) { // it is not metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // index is in range - { + } else { // index is in range metadata_editor_info("The picture number %d will be deleted\n", index); int i = 0; - for(TagLib::MP4::CoverArtList::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) - { - if(i != index) continue; + for (TagLib::MP4::CoverArtList::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { + if (i != index) continue; lst.erase(picIt); break; } itemMap.insert("covr", TagLib::MP4::Item(lst)); return METADATA_EDITOR_ERROR_NONE; } - } - else // Item was not found - { + } else { // Item was not found metadata_editor_error("The item does not exist. Nothing to delete\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } @@ -2078,24 +1904,19 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in { TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; TagLib::List lst = _file->pictureList(); - if(lst.isEmpty()) - { + if (lst.isEmpty()) { metadata_editor_error("No pictures in file. Nothing to delete\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } // Check if the index is in range of CoverArtList Item - if((index < 0) || ((uint)index >= lst.size())) // it is not - { + if ((index < 0) || ((uint)index >= lst.size())) { // it is not metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // index is in range - { + } else { // index is in range metadata_editor_info("The picture number %d will be deleted\n", index); int i = 0; - for(TagLib::List::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) - { - if(i != index) continue; + for (TagLib::List::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { + if (i != index) continue; _file->removePicture(*picIt,true); break; } @@ -2108,34 +1929,26 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); // Check if the valid tag pointer exists - if(tag2 == NULL) - { + if (tag2 == NULL) { metadata_editor_error("Error. ID3v2 tag does not exist. Can not remove picture\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag - if(lst.isEmpty()) - { + if (lst.isEmpty()) { metadata_editor_error("No pictures in file\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; - } - else // pictures exist in file - { + } else { // pictures exist in file // Check if index is correct or not - if( (index < 0) || (lst.size() <= (uint)index) ) - { + if ((index < 0) || (lst.size() <= (uint)index)) { metadata_editor_error("Index of picture is out of range\n"); return METADATA_EDITOR_ERROR_INVALID_PARAMETER; - } - else // everything is correct - begin extraction - { + } else { // everything is correct - begin extraction metadata_editor_info("Removing of picture number %d\n", index); int i = 0; // Among all frames we must choose that one with specified index. "i" will be counter - for(TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) - { - if(i != index) continue; + for (TagLib::ID3v2::FrameList::Iterator it = lst.begin(); it != lst.end(); ++it, ++i) { + if (i != index) continue; tag2->removeFrame(*it); break; } @@ -2158,8 +1971,7 @@ extern "C" int metadata_editor_destroy(metadata_editor_h metadata) metadata_editor_s *_metadata = (metadata_editor_s*)metadata; - switch(_metadata->filetype) - { + switch (_metadata->filetype) { case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type -- 2.7.4 From 65b69ee8193c6f06b5de444bf29c9876a209a1c7 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 6 Nov 2015 15:35:34 +0900 Subject: [PATCH 06/16] Change file checker stat to open Change-Id: I66b87e6c0d46e1a282c4b2cca0653c9f13c7f2ac Signed-off-by: Minje Ahn --- packaging/capi-media-metadata-editor.spec | 2 +- src/metadata_editor.cpp | 57 +++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec index fc9a75a..6a3dd83 100755 --- a/packaging/capi-media-metadata-editor.spec +++ b/packaging/capi-media-metadata-editor.spec @@ -1,6 +1,6 @@ Name: capi-media-metadata-editor Summary: A metadata editor library in SLP C API -Version: 0.1.4 +Version: 0.1.5 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 8994a54..6b72724 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -17,6 +17,10 @@ #include #include #include +#include +#include +#include +#include static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value); static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value); @@ -814,13 +818,6 @@ int __metadata_editor_get_picture_info(const char *path, void **picture, int *si return METADATA_EDITOR_ERROR_NONE; } -bool __metadata_editor_file_exist(const std::string& name) -{ - struct stat buffer; - return (stat(name.c_str(), &buffer) == 0); -} - - // *** This function is used to allocate the metadata_editor_s in memory *** // // *** The structure metadata_editor_s contains all information about the file *** // extern "C" int metadata_editor_create(metadata_editor_h *metadata) @@ -849,11 +846,21 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); metadata_editor_retvm_if(path == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); - if (!__metadata_editor_file_exist(path)) { + int exist; + + /* check the file exits actually */ + exist = open(path, O_RDONLY); + if(exist < 0) { metadata_editor_error("Not exist file\n"); - return METADATA_EDITOR_ERROR_FILE_EXISTS; + if (errno == EACCES || errno == EPERM) { + return METADATA_EDITOR_ERROR_PERMISSION_DENIED; + } else { + return METADATA_EDITOR_ERROR_FILE_EXISTS; + } } + close(exist); + metadata_editor_s *_metadata = (metadata_editor_s*)metadata; int media_type = METADATA_EDITOR_FORMAT_NOTYPE; @@ -862,6 +869,16 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * switch (media_type) { // Parse file according the specified type case METADATA_EDITOR_FORMAT_MP3: { + if (_metadata->file) { + TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; + metadata_editor_info("file free [%lX]", _metadata->file); + delete _file; + _metadata->file = NULL; + _metadata->filetype = METADATA_EDITOR_FORMAT_NOTYPE; + _metadata->isOpen = false; + _metadata->isReadOnly = true; + } + // Allocate the file object in memory to work with it later on TagLib::MPEG::File* _file = new TagLib::MPEG::File(path); @@ -892,6 +909,16 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * } case METADATA_EDITOR_FORMAT_MP4: { + if (_metadata->file) { + TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; + metadata_editor_info("file free [%lX]", _metadata->file); + delete _file; + _metadata->file = NULL; + _metadata->filetype = METADATA_EDITOR_FORMAT_NOTYPE; + _metadata->isOpen = false; + _metadata->isReadOnly = true; + } + // Allocate the file object in memory to work with it later on TagLib::MP4::File* _file = new TagLib::MP4::File(path); @@ -1976,14 +2003,14 @@ extern "C" int metadata_editor_destroy(metadata_editor_h metadata) { // Bring the pointer to actual file type TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; - metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; - metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } @@ -1991,28 +2018,28 @@ extern "C" int metadata_editor_destroy(metadata_editor_h metadata) case METADATA_EDITOR_FORMAT_FLAC: { TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; - metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } case METADATA_EDITOR_FORMAT_OGG_VORBIS: { TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; - metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } case METADATA_EDITOR_FORMAT_OGG_FLAC: { TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; - metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } case METADATA_EDITOR_FORMAT_WAV: { TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; - metadata_editor_info("The file with address %lX will now be freed\n", _metadata->file); + metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } -- 2.7.4 From 5b9545e06c34ff42c0953a84323728e58509927e Mon Sep 17 00:00:00 2001 From: "Haejeong, Kim" Date: Fri, 6 Nov 2015 16:12:48 +0900 Subject: [PATCH 07/16] Just apply tizen coding rule Change-Id: I469ef23ec07d003f65c96a98a285037084778e97 --- src/metadata_editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index 6b72724..b152df9 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -957,7 +957,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * _metadata->filetype = METADATA_EDITOR_FORMAT_FLAC; - if (_file->isOpen()) { // Check if the file was opened successfully + if (_file->isOpen()) { // Check if the file was opened successfully metadata_editor_info("The file is successfully opened. Address is %lX\n", _metadata->file); _metadata->isOpen = true; } else { // The file does not exist or you have no permission to process it @@ -1363,7 +1363,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); - if (!xtag) { // Check if we have a valid tag for processing + if (!xtag) { // Check if we have a valid tag for processing metadata_editor_error("Error. Xiph Comment was not created. Can not proceed metadata updating\n"); return METADATA_EDITOR_ERROR_OPERATION_FAILED; } -- 2.7.4 From 91e9374aa46a45c4e0cb699d7c1fb7fb5d6eb64f Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Tue, 29 Dec 2015 10:35:55 +0900 Subject: [PATCH 08/16] Update package group Change-Id: I4469ea7dcf5d14109547581b2783d3da1acf4b5f Signed-off-by: Minje Ahn --- packaging/capi-media-metadata-editor.spec | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/capi-media-metadata-editor.spec b/packaging/capi-media-metadata-editor.spec index 6a3dd83..5dc6d23 100755 --- a/packaging/capi-media-metadata-editor.spec +++ b/packaging/capi-media-metadata-editor.spec @@ -1,8 +1,8 @@ Name: capi-media-metadata-editor -Summary: A metadata editor library in SLP C API +Summary: A metadata editor library in Tizen Native API Version: 0.1.5 Release: 0 -Group: System/Libraries +Group: Multimedia/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz BuildRequires: cmake @@ -14,15 +14,15 @@ Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig %description -A metadata editor library in SLP C API +A media metadata editor library in Tizen Native API. %package devel -Summary: A metadata editor library in SLP C API (Development) -Group: TO_BE/FILLED_IN +Summary: A metadata editor library in Tizen Native API (Development) +Group: Multimedia/Development Requires: %{name} = %{version}-%{release} %description devel -A metadata editor library in SLP C API +A media metadata editor library in Tizen Native API. (Development files included) %prep %setup -q -- 2.7.4 From d6b91b8bd212979b4996cb2d8747b96dedcc4aec Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 15 Jan 2016 15:12:48 +0900 Subject: [PATCH 09/16] Update document Change-Id: I9c5f3aa395a554c9199eaadbb688c69dff1336b7 Signed-off-by: Minje Ahn --- doc/metadata_editor_doc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/metadata_editor_doc.h b/doc/metadata_editor_doc.h index 9821d03..56f1310 100755 --- a/doc/metadata_editor_doc.h +++ b/doc/metadata_editor_doc.h @@ -31,7 +31,7 @@ /** * @addtogroup CAPI_MEDIA_METADATA_EDITOR_MODULE - * @brief The @ref CAPI_MEDIA_METADATA_EDITOR_MODULE API provides functions for editing the metadata of several popular audio format. + * @brief The @ref CAPI_MEDIA_METADATA_EDITOR_MODULE API provides functions for editing the metadata of mp3, mp4 contents. * @ingroup CAPI_MEDIA_FRAMEWORK * @section CAPI_MEDIA_METADATA_EDITOR_MODULE_HEADER Required Header * \#include -- 2.7.4 From 8e891f25aca30bae1460ea724cf0f95ec0424ca0 Mon Sep 17 00:00:00 2001 From: Haejeong Kim Date: Tue, 26 Jan 2016 15:24:31 +0900 Subject: [PATCH 10/16] Apply tizen coding rule Change-Id: Ib0db311b7d228881df5b6ba684df155065c33b64 --- test/metadata_editor_test.c | 98 ++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/test/metadata_editor_test.c b/test/metadata_editor_test.c index 132ab89..76ad7e6 100755 --- a/test/metadata_editor_test.c +++ b/test/metadata_editor_test.c @@ -308,19 +308,19 @@ static bool __add_picture(metadata_editor_h metadata) __flush(); switch (c2) { - case 1: - printf("\n==========================="); - printf("\n Your choice is TestImage.png\n"); - picture_filename = strdup("TestImage.png"); - break; - - case 2: - printf("\n==========================="); - printf("\n Your choice is TestImage.jpg\n"); - picture_filename = strdup("TestImage.jpg"); - break; - default: - break; + case 1: + printf("\n==========================="); + printf("\n Your choice is TestImage.png\n"); + picture_filename = strdup("TestImage.png"); + break; + + case 2: + printf("\n==========================="); + printf("\n Your choice is TestImage.jpg\n"); + picture_filename = strdup("TestImage.jpg"); + break; + default: + break; } metadata_editor_append_picture(metadata, picture_filename); @@ -367,7 +367,7 @@ int main(int argc, char *argv[]) if (cnt < 1) { printf("\n===================================================================================================="); - printf("\n Please type file path and media type as media-metadata-test /opt/usr/media/Sounds/ "); + printf("\n Please type file path and media type as media-metadata-test /opt/usr/media/Sounds/"); printf("\n===================================================================================================="); return 0; } @@ -377,7 +377,7 @@ int main(int argc, char *argv[]) /*__printRetValue("metadata_editor_create(...)",ret); */ if (ret != METADATA_EDITOR_ERROR_NONE) { - printf("Fail metadata_editor_create() at line [%d]\n", __LINE__); + printf("Fail metadata_editor_create() at line [%d]\n", __LINE__); return 0; } @@ -385,7 +385,7 @@ int main(int argc, char *argv[]) /*__printRetValue("metadata_editor_set_path(...)",ret); */ if (ret != METADATA_EDITOR_ERROR_NONE) { - printf("Fail metadata_editor_set_path() at line [%d]\n", __LINE__); + printf("Fail metadata_editor_set_path() at line [%d]\n", __LINE__); goto exception; } @@ -404,42 +404,42 @@ int main(int argc, char *argv[]) printf("9 - Quit. Press 9 "); printf("\n=========================\n"); printf("\n Your choice : "); - dummy = scanf("%u", &c2); + dummy = scanf("%u", &c2); __flush(); switch (c2) { - case 1: - printf("\n=============="); - printf("\n Reading tags \n"); - __get_tag_info(metadata); - break; - case 2: - printf("\n=============="); - printf("\n Writing tags "); - __write_tag_info(metadata); - break; - case 3: - printf("\n=============="); - printf("\n Deleting tags "); - __delete_tag_info(metadata); - break; - case 4: - printf("\n=============="); - printf("\n Adding picture "); - __add_picture(metadata); - break; - case 5: - printf("\n=============="); - printf("\n Deleting pictures \n"); - __delete_pictures(metadata); - break; - case 6: - printf("\n=============="); - printf("\n Saving updated tags \n"); - __save_tags(metadata); - break; - default: - break; + case 1: + printf("\n=============="); + printf("\n Reading tags \n"); + __get_tag_info(metadata); + break; + case 2: + printf("\n=============="); + printf("\n Writing tags "); + __write_tag_info(metadata); + break; + case 3: + printf("\n=============="); + printf("\n Deleting tags "); + __delete_tag_info(metadata); + break; + case 4: + printf("\n=============="); + printf("\n Adding picture "); + __add_picture(metadata); + break; + case 5: + printf("\n=============="); + printf("\n Deleting pictures \n"); + __delete_pictures(metadata); + break; + case 6: + printf("\n=============="); + printf("\n Saving updated tags \n"); + __save_tags(metadata); + break; + default: + break; } } -- 2.7.4 From 564eb422f457852a780f0276f98834c02f47b421 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Wed, 2 Mar 2016 17:43:12 +0900 Subject: [PATCH 11/16] Fix error type Change-Id: Ifd294812f6143d9b27d82f8ca2f29148c16f164b Signed-off-by: Minje Ahn --- include/metadata_editor_type.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/metadata_editor_type.h b/include/metadata_editor_type.h index 37345a0..2e738af 100755 --- a/include/metadata_editor_type.h +++ b/include/metadata_editor_type.h @@ -31,6 +31,9 @@ extern "C" { * @{ */ +/** @brief Definition for Metadata editor Error Class */ +#define METADATA_EDITOR_ERROR_CLASS TIZEN_ERROR_METADATA_EDITOR + /** * @ingroup CAPI_MEDIA_METADATA_EDITOR_MODULE * @brief The enumerations of media metadata error @@ -38,13 +41,13 @@ extern "C" { */ typedef enum { - METADATA_EDITOR_ERROR_NONE = TIZEN_ERROR_METADATA_EDITOR, /**< Successful */ + METADATA_EDITOR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ METADATA_EDITOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ METADATA_EDITOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ METADATA_EDITOR_ERROR_FILE_EXISTS = TIZEN_ERROR_FILE_EXISTS, /**< File not exist */ METADATA_EDITOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ METADATA_EDITOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Unsupported type */ - METADATA_EDITOR_ERROR_OPERATION_FAILED = TIZEN_ERROR_METADATA_EDITOR |0x01, /**< Invalid internal operation */ + METADATA_EDITOR_ERROR_OPERATION_FAILED = METADATA_EDITOR_ERROR_CLASS |0x01, /**< Invalid internal operation */ } metadata_editor_error_e; -- 2.7.4 From 09c03e69defe45bc39ab890f5cff0d08babf98d1 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Tue, 22 Mar 2016 14:14:51 +0900 Subject: [PATCH 12/16] Update API version description Change-Id: I867b863095d44467ed5f0412d33d4a49a299c11a Signed-off-by: Minje Ahn --- include/metadata_editor.h | 18 +++++++++--------- include/metadata_editor_type.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/metadata_editor.h b/include/metadata_editor.h index 1a038f6..1502e52 100755 --- a/include/metadata_editor.h +++ b/include/metadata_editor.h @@ -37,7 +37,7 @@ extern "C" { /** * @brief Create metadata - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * * @remarks You must release @a metadata using metadata_editor_destroy(). * @@ -53,7 +53,7 @@ int metadata_editor_create(metadata_editor_h *metadata); /** * @brief Set file path to read or write metadata - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * * @remarks In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n * For example, if you get the specific path by using storage_get_directory(). you should add previlege http://tizen.org/privilege/mediastorage or http://tizen.org/privilege/externalstorage. @@ -75,7 +75,7 @@ int metadata_editor_set_path(metadata_editor_h metadata, const char *path); /** * @brief Get the metadata corresponding to the attribute. - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * * @remarks You must release @a value using @c free(). \n * If the attribute value of the metadata is empty, return value is NULL. \n @@ -99,7 +99,7 @@ int metadata_editor_get_metadata(metadata_editor_h metadata, metadata_editor_att /** * @brief Set the attribute of the metadata. - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @details This function set the attribute of the metadata for updating the metadata. \n * * @remarks You must release @a value using @c free(). \n @@ -121,7 +121,7 @@ int metadata_editor_set_metadata(metadata_editor_h metadata, metadata_editor_att /** * @brief Update the modified metadata - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @details This function update the metadata in the media file that is modified by metadata_editor_set_metadata(). * * @remarks In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n @@ -141,7 +141,7 @@ int metadata_editor_update_metadata(metadata_editor_h metadata); /** * @brief Get the picture in the media file - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * * @remarks You must release @a picture using @c free(). \n * In case of accessing specific path in internal storage or external storage, you may add the privilege for accessing the path. \n @@ -165,7 +165,7 @@ int metadata_editor_get_picture(metadata_editor_h metadata, int index, void **pi /** * @brief Append the picture to the media file - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * * @remarks You must call metadata_editor_update_metadata() for applying to the metadata of the media file. if not, you will see the existing metadata when you call metadata_editor_get_metadata(). \n * Image type of the metadata supports jpeg and png. \n @@ -188,7 +188,7 @@ int metadata_editor_append_picture(metadata_editor_h metadata, const char *pictu /** * @brief Remove artwork image from media file - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * * @remarks You must call metadata_editor_update_metadata() for applying to the metadata of the media file. if not, you will see the existing metadata when you call metadata_editor_get_metadata(). \n * @@ -207,7 +207,7 @@ int metadata_editor_remove_picture(metadata_editor_h metadata, int index); /** * @brief Destroy metadata - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * * @param [in] metadata The handle to metadata * @return 0 on success, otherwise a negative error value diff --git a/include/metadata_editor_type.h b/include/metadata_editor_type.h index 2e738af..0c0354f 100755 --- a/include/metadata_editor_type.h +++ b/include/metadata_editor_type.h @@ -37,7 +37,7 @@ extern "C" { /** * @ingroup CAPI_MEDIA_METADATA_EDITOR_MODULE * @brief The enumerations of media metadata error - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif */ typedef enum { @@ -54,7 +54,7 @@ typedef enum /** * @ingroup CAPI_MEDIA_METADATA_EDITOR_MODULE * @brief The enumerations of attribute - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif */ typedef enum { METADATA_EDITOR_ATTR_ARTIST, /**< Artist*/ @@ -75,7 +75,7 @@ typedef enum { /** * @ingroup CAPI_MEDIA_METADATA_EDITOR_MODULE * @brief The handle of media metadata - * @since_tizen 2.4 + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif */ typedef void * metadata_editor_h; -- 2.7.4 From 4392787a14aec29c34c7ba619b1e8b0818143f19 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 1 Apr 2016 09:59:50 +0900 Subject: [PATCH 13/16] Apply coding rule Change-Id: I9235d4dcff529f0f0deacdcb399cf45b4edb9f24 Signed-off-by: Minje Ahn --- include/metadata_editor_private.h | 10 +++++----- include/metadata_editor_type.h | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/metadata_editor_private.h b/include/metadata_editor_private.h index a71df10..f60994f 100755 --- a/include/metadata_editor_private.h +++ b/include/metadata_editor_private.h @@ -53,9 +53,9 @@ extern "C" { #undef LOG_TAG #endif #define LOG_TAG "CAPI_MEDIA_METADATA_EDITOR" -#define META_SAFE_FREE(src) { if(src) {free(src); src = NULL;} } -#define META_MALLOC(src, size) { if (size <= 0) {src = NULL;} \ - else { src = (char *)malloc(size); if(src) memset(src, 0x0, size);} } +#define META_SAFE_FREE(src) { if (src) {free(src); src = NULL; } } +#define META_MALLOC(src, size) { if (size <= 0) src = NULL; \ + else { src = (char *)malloc(size); if (src) memset(src, 0x0, size); } } #define META_MAX_BUF_LEN 20 @@ -81,8 +81,8 @@ extern "C" { } while (0) #define metadata_editor_retvm_if(expr, val, fmt, arg...) do { \ - if(expr) { \ - LOGE(""fmt"", ##arg); \ + if (expr) { \ + LOGE(""fmt"", ##arg); \ return (val); \ } \ } while (0) diff --git a/include/metadata_editor_type.h b/include/metadata_editor_type.h index 0c0354f..d7ab918 100755 --- a/include/metadata_editor_type.h +++ b/include/metadata_editor_type.h @@ -39,11 +39,10 @@ extern "C" { * @brief The enumerations of media metadata error * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif */ -typedef enum -{ - METADATA_EDITOR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ +typedef enum { + METADATA_EDITOR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ METADATA_EDITOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - METADATA_EDITOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + METADATA_EDITOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ METADATA_EDITOR_ERROR_FILE_EXISTS = TIZEN_ERROR_FILE_EXISTS, /**< File not exist */ METADATA_EDITOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ METADATA_EDITOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Unsupported type */ -- 2.7.4 From bd3d6f71199bca30fd24ba81b2e3b3d7bfe9f9ff Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 14 Apr 2016 08:38:29 +0900 Subject: [PATCH 14/16] Apply tizen coding rule Change-Id: Ia165a1d0fb745012cce961c712077af831a2d9bc Signed-off-by: Minje Ahn --- src/metadata_editor.cpp | 157 ++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index b152df9..f7fa133 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -101,7 +101,7 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); length = strlen(str.toCString(isUTF)); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; } @@ -118,7 +118,7 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: if (found) { length = strlen(buf); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } @@ -136,7 +136,7 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: if (!str.isLatin1()) isUTF = true; metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); uint length = strlen(str.toCString(isUTF)); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(str.toCString(isUTF), length); @@ -153,7 +153,7 @@ static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exists @@ -186,14 +186,14 @@ static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); // This is a common frame type for textural frames except comment frame TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); - metadata_editor_retvm_if(fr == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); + metadata_editor_retvm_if(fr == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); fr->setTextEncoding(TagLib::String::UTF8); - fr->setText(TagLib::String(value,TagLib::String::UTF8)); + fr->setText(TagLib::String(value, TagLib::String::UTF8)); tag2->addFrame(fr); } else { // if not - just modify the data in the existing frame metadata_editor_info("The frame %s exists. Changing.\n", frameID); - tag2->frameListMap()[frameID][0]->setText(TagLib::String(value,TagLib::String::UTF8)); + tag2->frameListMap()[frameID][0]->setText(TagLib::String(value, TagLib::String::UTF8)); } if (tag1 && !tag1->isEmpty()) { // Check if ID3v1 tag exists. Must copy data if yes. @@ -225,10 +225,10 @@ static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); // Check if the frame is empty (nothing to read) or ID3v2 tag does not exist - metadata_editor_retvm_if(!tag2 || tag2->frameListMap()[frameID].isEmpty(),METADATA_EDITOR_ERROR_NONE,"The frame %s does not exist\n", frameID); + metadata_editor_retvm_if(!tag2 || tag2->frameListMap()[frameID].isEmpty(), METADATA_EDITOR_ERROR_NONE, "The frame %s does not exist\n", frameID); metadata_editor_info("The frame %s exists\n", frameID); // This string is used to copy the value in the frame @@ -238,7 +238,7 @@ static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); uint length = strlen(str.toCString(isUTF)); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(str.toCString(isUTF), length); @@ -253,7 +253,7 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exist @@ -271,14 +271,14 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag metadata_editor_info("The frame %s does not exist. Creating.\n", frameID); // This is a common frame type for textural frames except comment frame TagLib::ID3v2::TextIdentificationFrame* fr = new TagLib::ID3v2::TextIdentificationFrame(frameID); - metadata_editor_retvm_if(fr == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); + metadata_editor_retvm_if(fr == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); fr->setTextEncoding(TagLib::String::UTF8); - fr->setText(TagLib::String(value,TagLib::String::UTF8)); + fr->setText(TagLib::String(value, TagLib::String::UTF8)); tag2->addFrame(fr); } else { // if not - just modify the data in the existing frame metadata_editor_info("The frame %s exists. Changing.\n", frameID); - tag2->frameListMap()[frameID][0]->setText(TagLib::String(value,TagLib::String::UTF8)); + tag2->frameListMap()[frameID][0]->setText(TagLib::String(value, TagLib::String::UTF8)); } return METADATA_EDITOR_ERROR_NONE; @@ -293,7 +293,7 @@ static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2 // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); // Check if the valid tag pointer exist metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); @@ -308,7 +308,6 @@ static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2 snprintf(buf, META_MAX_BUF_LEN, "%u", lst.size()); *value = strndup(buf, strlen(buf)); return METADATA_EDITOR_ERROR_NONE; - } // *** This function is used to receive unsynchronized lyrics from ID3v2 tag in file *** // @@ -321,14 +320,14 @@ static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); // Check if the valid tag pointer exist - metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag does not exist. Can not process further"); + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag does not exist. Can not process further"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag // Check if frames exist in file - metadata_editor_retvm_if(lst.isEmpty(),METADATA_EDITOR_ERROR_NONE,"The frame USLT does not exist\n"); + metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_NONE, "The frame USLT does not exist\n"); metadata_editor_info("The frame USLT exists\n"); TagLib::ID3v2::FrameList::Iterator it = lst.begin(); @@ -351,11 +350,11 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1 metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exist - metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); // If the pointer is NULL or c-string is empty - handle as request for deletion if (!value || (*value == '\0')) { @@ -375,7 +374,7 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1 tag2->addFrame(fr); } else { // If the frame already exists - just modify its value metadata_editor_info("The frame COMM exists. Changing.\n"); - tag2->frameListMap()["COMM"][0]->setText(TagLib::String(value,TagLib::String::UTF8)); + tag2->frameListMap()["COMM"][0]->setText(TagLib::String(value, TagLib::String::UTF8)); } if (tag1 && !tag1->isEmpty()) { // Copy the value to ID3v1 tag comment @@ -394,11 +393,11 @@ static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); // Check if the valid tag pointer exist - metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["USLT"]; // link to unsynchronized lyric frames in tag // If the pointer is NULL or c-string is empty - handle as request for deletion @@ -412,17 +411,17 @@ static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag // No lyrics - create the frame and add it to the ID3v2 tag metadata_editor_info("The frame USLT does not exist. Creating.\n"); TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = new TagLib::ID3v2::UnsynchronizedLyricsFrame; - metadata_editor_retvm_if(frame == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); + metadata_editor_retvm_if(frame == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); frame->setTextEncoding(TagLib::String::UTF8); - frame->setText(TagLib::String(value,TagLib::String::UTF8)); + frame->setText(TagLib::String(value, TagLib::String::UTF8)); tag2->addFrame(frame); } else { // the lyrics frames exist - change the existing one metadata_editor_info("USLT frames exist in file. Changing.\n"); TagLib::ID3v2::FrameList::Iterator it = lst.begin(); TagLib::ID3v2::UnsynchronizedLyricsFrame* frame = static_cast(*it); frame->setTextEncoding(TagLib::String::UTF8); - frame->setText(TagLib::String(value,TagLib::String::UTF8)); + frame->setText(TagLib::String(value, TagLib::String::UTF8)); } return METADATA_EDITOR_ERROR_NONE; @@ -439,11 +438,11 @@ static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemnam // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist"); + metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -456,7 +455,7 @@ static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemnam metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); // Get the length of the string and check if it is empty or not uint length = strlen(str.toCString(isUTF)); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; } else { // Item was not found @@ -476,11 +475,11 @@ static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemna // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist"); + metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -491,7 +490,7 @@ static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemna snprintf(buf, META_MAX_BUF_LEN, "%u", num); // Convert int into char[] // Determine the length of created c-string and copy it into the output variable int length = strlen(buf); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } else { // Item was not found @@ -509,12 +508,12 @@ static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* item metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail."); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag was not created"); + metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag was not created"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -541,12 +540,12 @@ static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* ite metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail."); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag was not created"); + metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag was not created"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -580,11 +579,11 @@ static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); + metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist\n"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -593,9 +592,9 @@ static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) uint number = it->second.toCoverArtList().size(); // Get the size of CoverList (i.e. number of pictures in file) metadata_editor_info("There are %u picture(s) in file\n", number); char buf[META_MAX_BUF_LEN] = {0, }; - snprintf(buf,META_MAX_BUF_LEN, "%u", number); // Convert integer value of size to its c-string representation + snprintf(buf, META_MAX_BUF_LEN, "%u", number); // Convert integer value of size to its c-string representation int length = strlen(buf); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } else { // Item was not found @@ -614,8 +613,8 @@ static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphC // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); - metadata_editor_retvm_if(!xtag,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(!xtag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist\n"); const TagLib::Ogg::FieldListMap& fieldMap = xtag->fieldListMap(); TagLib::Ogg::FieldListMap::ConstIterator it = fieldMap.find(fieldname); @@ -629,7 +628,7 @@ static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphC metadata_editor_info("String is %sUTF\n", (isUTF ? "" : "not ")); // Get the length of the string and check if it is empty or not uint length = strlen(str.toCString(isUTF)); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(str.toCString(isUTF), length); return METADATA_EDITOR_ERROR_NONE; } else { // Field was not found @@ -647,9 +646,9 @@ static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::Xi // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); - metadata_editor_retvm_if(!xtag,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); + metadata_editor_retvm_if(!xtag, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist\n"); // Check if it is a request for deletion if ((value == NULL) || value[0] == '\0') { @@ -659,7 +658,7 @@ static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::Xi } metadata_editor_info("The field %s will be added\n", fieldname); // "true" is used to remove other strings of the same "fieldname" first - xtag->addField(fieldname, TagLib::String(value,TagLib::String::UTF8), true); + xtag->addField(fieldname, TagLib::String(value, TagLib::String::UTF8), true); return METADATA_EDITOR_ERROR_NONE; } @@ -673,7 +672,7 @@ static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; if (_file->pictureList().isEmpty()) { @@ -683,9 +682,9 @@ static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value uint number = _file->pictureList().size(); metadata_editor_info("There are %u picture(s) in file\n", number); char buf[META_MAX_BUF_LEN] = {0, }; - snprintf(buf,META_MAX_BUF_LEN, "%u", number); // Convert integer value of size to its c-string representation + snprintf(buf, META_MAX_BUF_LEN, "%u", number); // Convert integer value of size to its c-string representation uint length = strlen(buf); - metadata_editor_retvm_if(length == 0,METADATA_EDITOR_ERROR_NONE,"Empty string...\n"); + metadata_editor_retvm_if(length == 0, METADATA_EDITOR_ERROR_NONE, "Empty string...\n"); *value = strndup(buf, length); return METADATA_EDITOR_ERROR_NONE; } @@ -712,7 +711,7 @@ int __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int ma int __metadata_editor_get_file_type(const char *path) { int ret = 0; - char mimetype[255] = {0,}; + char mimetype[255] = {0, }; /* get content type and mime type from file. */ ret = aul_get_mime_from_file(path, mimetype, sizeof(mimetype)); @@ -721,7 +720,7 @@ int __metadata_editor_get_file_type(const char *path) char ext[255] = { 0 }; int ret = __metadata_editor_get_file_ext(path, ext, sizeof(ext)); - metadata_editor_retvm_if(ret < 0,METADATA_EDITOR_FORMAT_NOTYPE,"__metadata_editor_get_file_type failed"); + metadata_editor_retvm_if(ret < 0, METADATA_EDITOR_FORMAT_NOTYPE, "__metadata_editor_get_file_type failed"); if (strcasecmp(ext, "MP3") == 0) return METADATA_EDITOR_FORMAT_MP3; @@ -745,7 +744,7 @@ int __metadata_editor_get_file_type(const char *path) int __metadata_editor_get_picture_type(const char *path, char **type) { int ret = 0; - char mimetype[255] = {0,}; + char mimetype[255] = {0, }; const char *type_jpeg = "image/jpeg"; const char *type_png = "image/png"; @@ -756,7 +755,7 @@ int __metadata_editor_get_picture_type(const char *path, char **type) char ext[255] = { 0 }; int ret = __metadata_editor_get_file_ext(path, ext, sizeof(ext)); - metadata_editor_retvm_if(ret < 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"__metadata_editor_get_file_type failed"); + metadata_editor_retvm_if(ret < 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "__metadata_editor_get_file_type failed"); if (strcasecmp(ext, "JPG") == 0 || strcasecmp(ext, "JPEG") == 0) { *type = strndup(type_jpeg, strlen(type_jpeg)); @@ -800,7 +799,7 @@ int __metadata_editor_get_picture_info(const char *path, void **picture, int *si file_size++; fclose(fin); - char picture_buffer[file_size] = {0,}; + char picture_buffer[file_size] = {0, }; memset(picture_buffer, 0, file_size * sizeof(char)); fin = fopen(path, "rb"); if (fin) { @@ -826,7 +825,7 @@ extern "C" int metadata_editor_create(metadata_editor_h *metadata) metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_s *_metadata = new metadata_editor_s; // Allocate a structure for handler - metadata_editor_retvm_if(_metadata == NULL,METADATA_EDITOR_ERROR_OUT_OF_MEMORY,"OUT_OF_MEMORY"); + metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); _metadata->file = NULL; _metadata->filetype = METADATA_EDITOR_FORMAT_NOTYPE; // Specify file type out of range @@ -1077,7 +1076,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata // Check if the file, given through metadata, exists and is opened correctly *value = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: @@ -1256,7 +1255,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch (_metadata->filetype) { // Process the file according to the specified file type @@ -1267,7 +1266,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); - metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); switch (attribute) { // Check which one of frame type was given for processing case METADATA_EDITOR_ATTR_ARTIST: return __ID3_setTwixFrameByName(_metadata, tag1, tag2, "TPE1", value); @@ -1429,7 +1428,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch (_metadata->filetype) { // Process the file according to the specified file type @@ -1518,14 +1517,14 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index *size = 0; *mime_type = NULL; - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: { TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; // Bring the pointer to actual file type TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(); - metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. No ID3v2 tag in file."); + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. No ID3v2 tag in file."); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag @@ -1545,16 +1544,16 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if (i != index) continue; TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); uint pictureSize = pictureFrame->picture().size(); - metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + metadata_editor_retvm_if(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0"); META_MALLOC(*picture, pictureSize); metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); memcpy(*picture, pictureFrame->picture().data(), pictureSize); *size = pictureSize; TagLib::String mime = pictureFrame->mimeType(); - if (!strcmp(mime.toCString(),"image/jpeg")) + if (!strcmp(mime.toCString(), "image/jpeg")) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); - else if (!strcmp(mime.toCString(),"image/png")) + else if (!strcmp(mime.toCString(), "image/png")) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); else *mime_type = NULL; @@ -1568,7 +1567,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Tag does not exist\n"); + metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist\n"); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -1584,7 +1583,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index for (TagLib::MP4::CoverArtList::ConstIterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { if (i != index) continue; int pictureSize = picIt->data().size(); - metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + metadata_editor_retvm_if(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0"); META_MALLOC(*picture, pictureSize); metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); @@ -1623,16 +1622,16 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index // picture can be received as ByteVector (picIt->data()). // ByteVector has data() - picture itself and size() - the size of picture in data() method int pictureSize = (*picIt)->data().size(); - metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + metadata_editor_retvm_if(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0"); META_MALLOC(*picture, pictureSize); metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); memcpy(*picture, (*picIt)->data().data(), pictureSize); *size = pictureSize; TagLib::String mime = (*picIt)->mimeType(); - if (!strcmp(mime.toCString(),"image/jpeg")) + if (!strcmp(mime.toCString(), "image/jpeg")) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); - else if (!strcmp(mime.toCString(),"image/png")) + else if (!strcmp(mime.toCString(), "image/png")) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); else *mime_type = NULL; @@ -1668,7 +1667,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index if (i != index) continue; TagLib::ID3v2::AttachedPictureFrame* pictureFrame = static_cast(*it); uint pictureSize = pictureFrame->picture().size(); - metadata_editor_retvm_if(pictureSize == 0,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Size of picture is 0"); + metadata_editor_retvm_if(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0"); META_MALLOC(*picture, pictureSize); metadata_editor_retvm_if(*picture == NULL, METADATA_EDITOR_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); @@ -1676,9 +1675,9 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index memcpy(*picture, pictureFrame->picture().data(), pictureSize); *size = pictureSize; TagLib::String mime = pictureFrame->mimeType(); - if (!strcmp(mime.toCString(),"image/jpeg")) + if (!strcmp(mime.toCString(), "image/jpeg")) *mime_type = strndup(TYPE_JPEG, strlen(TYPE_JPEG)); - else if (!strcmp(mime.toCString(),"image/png")) + else if (!strcmp(mime.toCString(), "image/png")) *mime_type = strndup(TYPE_PNG, strlen(TYPE_PNG)); else *mime_type = NULL; @@ -1711,11 +1710,11 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); ret = __metadata_editor_get_picture_info(path, &picture, &size, &type); - metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); switch (_metadata->filetype) { // Process the file according to the specified file type case METADATA_EDITOR_FORMAT_MP3: @@ -1861,7 +1860,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in metadata_editor_retvm_if(_metadata->file == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "File loading fail.\n"); // Check if the file, given through metadata, exists and is opened correctly - metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false,METADATA_EDITOR_ERROR_PERMISSION_DENIED,"File does not exist or you have no rights to open it\n"); + metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch (_metadata->filetype) { // Process the file according to the specified file type @@ -1871,7 +1870,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); // Check if the valid tag pointer exists - metadata_editor_retvm_if(tag2 == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. ID3v2 tag was not created. Can not proceed metadata updating"); + metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating"); TagLib::ID3v2::FrameList lst = tag2->frameListMap()["APIC"]; // Check if there are pictures in the tag if (lst.isEmpty()) { @@ -1899,7 +1898,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); - metadata_editor_retvm_if(tag == NULL,METADATA_EDITOR_ERROR_OPERATION_FAILED,"Error. tag not exist."); + metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. tag not exist."); // Get map of items directly from tag and launch a search of specific item TagLib::MP4::ItemListMap& itemMap = tag->itemListMap(); @@ -1944,7 +1943,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in int i = 0; for (TagLib::List::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) { if (i != index) continue; - _file->removePicture(*picIt,true); + _file->removePicture(*picIt, true); break; } return METADATA_EDITOR_ERROR_NONE; -- 2.7.4 From 965fbc8cd0ff955983eba95f50fcc3b20f36c750 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Mon, 18 Apr 2016 15:37:57 +0900 Subject: [PATCH 15/16] Apply tizen coding rule Change-Id: Ibdea7c535d077fe248c24505621f10ea88be2d70 Signed-off-by: Minje Ahn --- src/metadata_editor.cpp | 216 ++++++++++++++++-------------------------------- 1 file changed, 72 insertions(+), 144 deletions(-) diff --git a/src/metadata_editor.cpp b/src/metadata_editor.cpp index f7fa133..d24c549 100755 --- a/src/metadata_editor.cpp +++ b/src/metadata_editor.cpp @@ -53,8 +53,7 @@ typedef enum { // *** This is an auxiliary function that is used to get the frame value *** // // *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // -static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) -{ +static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) { // Check if we have valid arguments to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -146,8 +145,7 @@ static int __ID3_getTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: // *** This is an auxiliary function that is used to write the new value to the frame *** // // *** It operates with frames that exists both in ID3v1 and ID3v2 tags *** // -static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) -{ +static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) { // Check if we have valid arguments to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -216,8 +214,7 @@ static int __ID3_setTwixFrameByName(metadata_editor_s* _metadata, TagLib::ID3v1: } // *** This function reads frames that exist only in ID3v2 tag *** // -static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) -{ +static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, char** value) { // Check if we have valid arguments to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -246,8 +243,7 @@ static int __ID3_getFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag } // *** This function writes frames that exist only in ID3v2 tag *** // -static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) -{ +static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* frameID, const char* value) { // Check if we have valid arguments to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(frameID == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -285,8 +281,7 @@ static int __ID3_setFrameByName(metadata_editor_s* _metadata, TagLib::ID3v2::Tag } // *** This function is used to receive the number of pictures stored in ID3v2 tag of file *** // -static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) -{ +static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -312,8 +307,7 @@ static int __ID3_getNumberOfPictures(metadata_editor_s* _metadata, TagLib::ID3v2 // *** This function is used to receive unsynchronized lyrics from ID3v2 tag in file *** // // *** This frame differs from other string-type frames and uses UnsynchronizedLyricsFrame instead of TextIdentificationFrame *** // -static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) -{ +static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, char** value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -344,8 +338,7 @@ static int __ID3_getLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag // *** This function is used to set text in comment frame. It processes both ID3v1 and ID3v2 tags *** // // *** Comment frame is different from other string-type frames. It uses CommentsFrame instead of TextIdentificationFrame *** // -static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* value) -{ +static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1::Tag* tag1, TagLib::ID3v2::Tag* tag2, const char* value) { // Check if we have a valid argument to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -387,8 +380,7 @@ static int __ID3_setTwixCommentFrame(metadata_editor_s* _metadata, TagLib::ID3v1 // *** This function is used to set text in Lyrics frame *** // // *** Lyrics frame is different from other string-type frames and uses UnsynchronizedLyricsFrame instead of TextIdentificationFrame *** // -static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* value) -{ +static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag* tag2, const char* value) { // Check if we have a valid argument to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -428,8 +420,7 @@ static int __ID3_setLyricsFrame(metadata_editor_s* _metadata, TagLib::ID3v2::Tag } // *** This function extracts string values from tag in MP4 file *** // -static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemname, char** value) -{ +static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemname, char** value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -465,8 +456,7 @@ static int __MP4_getStringItem(metadata_editor_s* _metadata, const char* itemnam } // *** This function extracts integer value from item in MP4 tag *** // -static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemname, char** value) -{ +static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemname, char** value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -500,8 +490,7 @@ static int __MP4_getIntegerItem(metadata_editor_s* _metadata, const char* itemna } // *** This function adds (or changes) string item of itemname type *** // -static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value) -{ +static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* itemname, const char* value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -532,8 +521,7 @@ static int __MP4_updateStringItem(metadata_editor_s* _metadata, const char* item } // *** This function adds (or changes) integer item of itemname type *** // -static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* itemname, const char* value) -{ +static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* itemname, const char* value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(itemname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -570,8 +558,7 @@ static int __MP4_updateIntegerItem(metadata_editor_s* _metadata, const char* ite } // *** This function is used to find the number of pictures stored in MP4 file *** // -static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) -{ +static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -604,8 +591,7 @@ static int __MP4_getNumberOfPictures(metadata_editor_s* _metadata, char** value) } #if 0 // *** This function is used to extract string from Xiph Comment field *** // -static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, char** value) -{ +static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, char** value) { // Check if we have a valid argument to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(fieldname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -638,8 +624,7 @@ static int __xiph_getFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphC } // *** This function is used to write string into Xiph Comment fields *** // -static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value) -{ +static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::XiphComment* xtag, const char* fieldname, const char* value) { // Check if we have a valid argument to work with metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_retvm_if(fieldname == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -663,8 +648,7 @@ static int __xiph_updateFieldValue(metadata_editor_s* _metadata, TagLib::Ogg::Xi } // *** This function is used to receive the number of pictures in FLAC file *** // -static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value) -{ +static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value) { // Check if parameters are valid metadata_editor_retvm_if(_metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Value Pointer"); @@ -689,8 +673,7 @@ static int __FLAC_getNumberOfPictures(metadata_editor_s* _metadata, char** value return METADATA_EDITOR_ERROR_NONE; } #endif -int __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int max_len) -{ +int __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int max_len) { int i = 0; unsigned int path_len = strlen(file_path); @@ -708,8 +691,7 @@ int __metadata_editor_get_file_ext(const char *file_path, char *file_ext, int ma return -1; } -int __metadata_editor_get_file_type(const char *path) -{ +int __metadata_editor_get_file_type(const char *path) { int ret = 0; char mimetype[255] = {0, }; @@ -741,8 +723,7 @@ int __metadata_editor_get_file_type(const char *path) return METADATA_EDITOR_FORMAT_NOTYPE; } -int __metadata_editor_get_picture_type(const char *path, char **type) -{ +int __metadata_editor_get_picture_type(const char *path, char **type) { int ret = 0; char mimetype[255] = {0, }; const char *type_jpeg = "image/jpeg"; @@ -782,8 +763,7 @@ int __metadata_editor_get_picture_type(const char *path, char **type) return METADATA_EDITOR_ERROR_NOT_SUPPORTED; } -int __metadata_editor_get_picture_info(const char *path, void **picture, int *size, char **type) -{ +int __metadata_editor_get_picture_info(const char *path, void **picture, int *size, char **type) { int ret; ret = __metadata_editor_get_picture_type(path, type); @@ -819,8 +799,7 @@ int __metadata_editor_get_picture_info(const char *path, void **picture, int *si // *** This function is used to allocate the metadata_editor_s in memory *** // // *** The structure metadata_editor_s contains all information about the file *** // -extern "C" int metadata_editor_create(metadata_editor_h *metadata) -{ +extern "C" int metadata_editor_create(metadata_editor_h *metadata) { // Check if we have a valid argument to work with metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); @@ -839,8 +818,7 @@ extern "C" int metadata_editor_create(metadata_editor_h *metadata) } // *** This function is used to open the file. It creates the instance that is responsible for connection with file *** // -extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char *path) -{ +extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char *path) { // Check if we have valid arguments to work with metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); metadata_editor_retvm_if(path == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); @@ -866,8 +844,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * media_type = __metadata_editor_get_file_type(path); switch (media_type) { // Parse file according the specified type - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { if (_metadata->file) { TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); @@ -906,8 +883,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * return METADATA_EDITOR_ERROR_NONE; } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { if (_metadata->file) { TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); @@ -945,8 +921,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * return METADATA_EDITOR_ERROR_NONE; } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { // Allocate the file object in memory to work with it later on TagLib::FLAC::File* _file = new TagLib::FLAC::File(path); @@ -973,8 +948,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * } return METADATA_EDITOR_ERROR_NONE; } - case METADATA_EDITOR_FORMAT_OGG_VORBIS: - { + case METADATA_EDITOR_FORMAT_OGG_VORBIS: { // Allocate the file object in memory to work with it later on TagLib::Ogg::Vorbis::File* _file = new TagLib::Ogg::Vorbis::File(path); @@ -1001,8 +975,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * } return METADATA_EDITOR_ERROR_NONE; } - case METADATA_EDITOR_FORMAT_OGG_FLAC: - { + case METADATA_EDITOR_FORMAT_OGG_FLAC: { // Allocate the file object in memory to work with it later on TagLib::Ogg::FLAC::File* _file = new TagLib::Ogg::FLAC::File(path); @@ -1029,8 +1002,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * } return METADATA_EDITOR_ERROR_NONE; } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { // Allocate the file object in memory to work with it later on TagLib::RIFF::WAV::File* _file = new TagLib::RIFF::WAV::File(path); @@ -1065,8 +1037,7 @@ extern "C" int metadata_editor_set_path(metadata_editor_h metadata, const char * } // *** This function is used to get the tag frame (field, item - each tag has its own name for data unit) from file *** // -extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, char **value) -{ +extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, char **value) { // Check if we have valid arguments to work with metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); metadata_editor_retvm_if(value == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Value Pointer"); @@ -1079,8 +1050,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); switch (_metadata->filetype) { // Process the file according to the specified file type - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tag pointers TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); @@ -1104,8 +1074,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { switch (attribute) { // Check which one of frame types was given to the function for processing case METADATA_EDITOR_ATTR_ARTIST: return __MP4_getStringItem(_metadata, "\xA9""ART", value); case METADATA_EDITOR_ATTR_TITLE: return __MP4_getStringItem(_metadata, "\xA9""nam", value); @@ -1125,8 +1094,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata } } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { // Bring the pointer to actual file type and make tags pointers TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->xiphComment(false); @@ -1153,8 +1121,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_OGG_VORBIS: - { + case METADATA_EDITOR_FORMAT_OGG_VORBIS: { // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); @@ -1180,8 +1147,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_OGG_FLAC: - { + case METADATA_EDITOR_FORMAT_OGG_FLAC: { // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); @@ -1207,8 +1173,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { // Bring the pointer to actual file type and make tag pointers TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); @@ -1245,8 +1210,7 @@ extern "C" int metadata_editor_get_metadata(metadata_editor_h metadata, metadata } // *** This function is used to modify the metadata (frame in tag). But it does not apply changes to file *** // -extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, const char* value) -{ +extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata_editor_attr_e attribute, const char* value) { // Check if we have valid arguments to work with metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle"); @@ -1259,8 +1223,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch (_metadata->filetype) { // Process the file according to the specified file type - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tags pointers TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; TagLib::ID3v1::Tag* tag1 = _file->ID3v1Tag(); @@ -1285,8 +1248,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { switch (attribute) { // Check which one of frame type was given for processing case METADATA_EDITOR_ATTR_ARTIST: return __MP4_updateStringItem(_metadata, "\xA9""ART", value); case METADATA_EDITOR_ATTR_TITLE: return __MP4_updateStringItem(_metadata, "\xA9""nam", value); @@ -1305,8 +1267,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata } } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { // Bring the pointer to actual file type and make tags pointers TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->xiphComment(true); @@ -1331,8 +1292,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_OGG_VORBIS: - { + case METADATA_EDITOR_FORMAT_OGG_VORBIS: { // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); @@ -1357,8 +1317,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_OGG_FLAC: - { + case METADATA_EDITOR_FORMAT_OGG_FLAC: { // Bring the pointer to actual file type and make tags pointers TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; TagLib::Ogg::XiphComment* xtag = _file->tag(); @@ -1383,8 +1342,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata return METADATA_EDITOR_ERROR_INVALID_PARAMETER; } } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { // Bring the pointer to actual file type and make tags pointers TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); @@ -1419,8 +1377,7 @@ extern "C" int metadata_editor_set_metadata(metadata_editor_h metadata, metadata } // *** This function apply all changes done in the tag(s) and update them to file *** // -extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) -{ +extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) { // Check if we have a valid argument to work with metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID Handle\n"); @@ -1432,8 +1389,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch (_metadata->filetype) { // Process the file according to the specified file type - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; @@ -1451,8 +1407,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) return METADATA_EDITOR_ERROR_OPERATION_FAILED; } } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; if (_file->save()) return METADATA_EDITOR_ERROR_NONE; @@ -1460,32 +1415,28 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) return METADATA_EDITOR_ERROR_OPERATION_FAILED; } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - case METADATA_EDITOR_FORMAT_OGG_VORBIS: - { + case METADATA_EDITOR_FORMAT_OGG_VORBIS: { TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - case METADATA_EDITOR_FORMAT_OGG_FLAC: - { + case METADATA_EDITOR_FORMAT_OGG_FLAC: { TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; if (_file->save()) return METADATA_EDITOR_ERROR_NONE; else return METADATA_EDITOR_ERROR_OPERATION_FAILED; } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; if (_file->save()) return METADATA_EDITOR_ERROR_NONE; @@ -1500,8 +1451,7 @@ extern "C" int metadata_editor_update_metadata(metadata_editor_h metadata) } // *** This function returns buffer with picture under the specified index and buffer's (picture's) size *** // -extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index, void **picture, int *size, char **mime_type) -{ +extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index, void **picture, int *size, char **mime_type) { const char *TYPE_JPEG = "image/jpeg"; const char *TYPE_PNG = "image/png"; // Check if we have valid arguments to work with @@ -1520,8 +1470,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index metadata_editor_retvm_if(_metadata->file && _metadata->isOpen == false, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); switch (_metadata->filetype) { // Process the file according to the specified file type - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; // Bring the pointer to actual file type TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(); metadata_editor_retvm_if(tag2 == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. No ID3v2 tag in file."); @@ -1563,8 +1512,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index } } } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Tag does not exist\n"); @@ -1602,8 +1550,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index } } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; TagLib::List lst = _file->pictureList(); if (lst.isEmpty()) { @@ -1641,8 +1588,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index } } } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; // Bring the pointer to actual file type TagLib::ID3v2::Tag* tag2 = _file->tag(); if (!tag2) { @@ -1695,8 +1641,7 @@ extern "C" int metadata_editor_get_picture(metadata_editor_h metadata, int index } // *** This function appends a cover art picture to the file *** // -extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const char *path) -{ +extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const char *path) { int ret = METADATA_EDITOR_ERROR_NONE; void *picture = NULL; int size = 0; @@ -1717,8 +1662,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const metadata_editor_retvm_if(ret != METADATA_EDITOR_ERROR_NONE, METADATA_EDITOR_ERROR_PERMISSION_DENIED, "File does not exist or you have no rights to open it\n"); switch (_metadata->filetype) { // Process the file according to the specified file type - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tags pointers TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); @@ -1744,8 +1688,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const ret = METADATA_EDITOR_ERROR_NONE; break; } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); if (!tag) { @@ -1792,8 +1735,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const } } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; TagLib::FLAC::Picture* frontCover = new TagLib::FLAC::Picture; if (frontCover == NULL) { @@ -1810,8 +1752,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const ret = METADATA_EDITOR_ERROR_NONE; break; } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { // Bring the pointer to actual file type and make tags pointers TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); @@ -1836,8 +1777,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const break; } #endif - default: - { + default: { metadata_editor_error("Wrong file type\n"); ret = METADATA_EDITOR_ERROR_NOT_SUPPORTED; break; @@ -1851,8 +1791,7 @@ extern "C" int metadata_editor_append_picture(metadata_editor_h metadata, const } // *** This function is used to delete picture with specified index *** // -extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int index) -{ +extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int index) { // Check if we have a valid argument to work with metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID handler."); @@ -1864,8 +1803,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in metadata_editor_retvm_if(_metadata->isReadOnly, METADATA_EDITOR_ERROR_OPERATION_FAILED, "File is readonly. Unable to modify\n"); switch (_metadata->filetype) { // Process the file according to the specified file type - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type and make tags pointers TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->ID3v2Tag(true); @@ -1894,8 +1832,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in } } } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*) _metadata->file; TagLib::MP4::Tag* tag = _file->tag(); metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. tag not exist."); @@ -1926,8 +1863,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in } } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { TagLib::FLAC::File* _file = (TagLib::FLAC::File*) _metadata->file; TagLib::List lst = _file->pictureList(); if (lst.isEmpty()) { @@ -1949,8 +1885,7 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in return METADATA_EDITOR_ERROR_NONE; } } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { // Bring the pointer to actual file type and make tags pointers TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; TagLib::ID3v2::Tag* tag2 = _file->tag(); @@ -1990,53 +1925,46 @@ extern "C" int metadata_editor_remove_picture(metadata_editor_h metadata, int in } // *** This function is used to free memory that was allocated with metadata_editor_create(...) and metadata_editor_set_path(...) functions *** // -extern "C" int metadata_editor_destroy(metadata_editor_h metadata) -{ +extern "C" int metadata_editor_destroy(metadata_editor_h metadata) { // Check if we have a valid argument to work with metadata_editor_retvm_if(metadata == NULL, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "INVALID PARAMETER"); metadata_editor_s *_metadata = (metadata_editor_s*)metadata; switch (_metadata->filetype) { - case METADATA_EDITOR_FORMAT_MP3: - { + case METADATA_EDITOR_FORMAT_MP3: { // Bring the pointer to actual file type TagLib::MPEG::File* _file = (TagLib::MPEG::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } - case METADATA_EDITOR_FORMAT_MP4: - { + case METADATA_EDITOR_FORMAT_MP4: { TagLib::MP4::File* _file = (TagLib::MP4::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } #if 0 - case METADATA_EDITOR_FORMAT_FLAC: - { + case METADATA_EDITOR_FORMAT_FLAC: { TagLib::FLAC::File* _file = (TagLib::FLAC::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } - case METADATA_EDITOR_FORMAT_OGG_VORBIS: - { + case METADATA_EDITOR_FORMAT_OGG_VORBIS: { TagLib::Ogg::Vorbis::File* _file = (TagLib::Ogg::Vorbis::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } - case METADATA_EDITOR_FORMAT_OGG_FLAC: - { + case METADATA_EDITOR_FORMAT_OGG_FLAC: { TagLib::Ogg::FLAC::File* _file = (TagLib::Ogg::FLAC::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); delete _file; break; } - case METADATA_EDITOR_FORMAT_WAV: - { + case METADATA_EDITOR_FORMAT_WAV: { TagLib::RIFF::WAV::File* _file = (TagLib::RIFF::WAV::File*)_metadata->file; metadata_editor_info("file free [%lX]", _metadata->file); delete _file; -- 2.7.4 From 6955f6010fc3d35e66643e7aa1e64a8eb670294c Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Fri, 23 Sep 2016 10:28:17 +0900 Subject: [PATCH 16/16] Fix native api reference warning Change-Id: I712c7e25e48cb0142b15f15df79c7d45e8dcf79d Signed-off-by: Minje Ahn --- include/metadata_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/metadata_editor.h b/include/metadata_editor.h index 1502e52..07d6a50 100755 --- a/include/metadata_editor.h +++ b/include/metadata_editor.h @@ -107,7 +107,7 @@ int metadata_editor_get_metadata(metadata_editor_h metadata, metadata_editor_att * * @param [in] metadata The handle to metadata * @param [in] attribute key attribute name to get - * @param [int] value The value of the attribute + * @param [in] value The value of the attribute * @return 0 on success, otherwise a negative error value * @retval #METADATA_EDITOR_ERROR_NONE Successful * @retval #METADATA_EDITOR_ERROR_INVALID_PARAMETER Invalid parameter -- 2.7.4