Merge duplicate code 07/277707/2 accepted/tizen/unified/20220714.135249 submit/tizen/20220714.004316
authorminje.ahn <minje.ahn@samsung.com>
Tue, 12 Jul 2022 08:03:06 +0000 (17:03 +0900)
committerminje.ahn <minje.ahn@samsung.com>
Tue, 12 Jul 2022 08:16:07 +0000 (17:16 +0900)
Change-Id: I8d641d1f20ee5dc6997bb25edeeb10f28e0fa7b7
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
src/metadata_editor.cpp

index bcda6e48d8f01bf044fc18779d07194880beed7a..81f57e727f5dba61e22894561db7278e5e3d3573 100755 (executable)
@@ -64,10 +64,10 @@ class PictureFrame
 public:
        explicit PictureFrame(const char *path) : stream(path, true) {}
        ~PictureFrame() = default;
-       TagLib::ByteVector data() {
+       ByteVector data() {
                return stream.readBlock(stream.length());
        }
-       TagLib::String mime() const {
+       String mime() const {
                return __get_picture_type(stream.name());
        }
        bool opened() {
@@ -82,7 +82,7 @@ public:
                        return MP4::CoverArt::Unknown;
        }
 private:
-       TagLib::FileStream stream;
+       FileStream stream;
 };
 
 template <class T>
@@ -112,15 +112,11 @@ static int __get_APIC(ID3v2::Tag *tag, int index, void **picture, int *size, cha
        return METADATA_EDITOR_ERROR_NONE;
 }
 
-static int __get_ogg_picture(Ogg::XiphComment *xtag, int index, void **picture, int *size, char **mime_type)
+static int __get_flac_picture(List<FLAC::Picture *> lst, int index, void **picture, int *size, char **mime_type)
 {
-       ME_RETVM_IF(!xtag, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid XiphComment");
-
-       auto lst = xtag->pictureList();
        ME_RETV_IF(!__is_valid_index(lst, index), METADATA_EDITOR_ERROR_INVALID_PARAMETER);
 
        auto pictureFrame = static_cast<FLAC::Picture*>(lst[index]);
-
        int pictureSize = pictureFrame->data().size();
        ME_RETVM_IF(pictureSize == 0, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Size of picture is 0");
 
@@ -174,7 +170,7 @@ static int __remove_ogg_picture(Ogg::XiphComment *xtag, int index)
        auto lst = xtag->pictureList();
        ME_RETV_IF(!__is_valid_index(lst, index), METADATA_EDITOR_ERROR_INVALID_PARAMETER);
 
-       TagLib::List<TagLib::FLAC::Picture*>::Iterator it = lst.begin();
+       List<FLAC::Picture*>::Iterator it = lst.begin();
        std::advance(it, index);
        xtag->removePicture(*it, true);
 
@@ -294,18 +290,7 @@ public:
                return METADATA_EDITOR_ERROR_NONE;
        }
        int read(int index, void **picture, int *size, char **mime_type) override {
-               auto lst = file->pictureList();
-               ME_RETV_IF(!__is_valid_index(lst, index), METADATA_EDITOR_ERROR_INVALID_PARAMETER);
-
-               auto pictureFrame = static_cast<FLAC::Picture*>(lst[index]);
-               int pictureSize = pictureFrame->data().size();
-               ME_RETVM_IF(pictureSize == 0, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Size of picture is 0");
-
-               *picture = g_memdup2(pictureFrame->data().data(), pictureSize);
-               *size = pictureSize;
-               *mime_type = g_strdup(pictureFrame->mimeType().toCString());
-
-               return METADATA_EDITOR_ERROR_NONE;
+               return __get_flac_picture(file->pictureList(), index, picture, size, mime_type);
        }
        uint count() override {
                return file->pictureList().size();
@@ -328,7 +313,8 @@ public:
                return __remove_ogg_picture(file->tag(), index);
        }
        int read(int index, void **picture, int *size, char **mime_type) override {
-               return __get_ogg_picture(file->tag(), index, picture, size, mime_type);
+               ME_RETVM_IF(!file->tag(), METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid XiphComment");
+               return __get_flac_picture(file->tag()->pictureList(), index, picture, size, mime_type);
        }
        uint count() override {
                return file->tag() ? file->tag()->pictureList().size() : 0;
@@ -351,7 +337,8 @@ public:
                return __remove_ogg_picture(file->tag(), index);
        }
        int read(int index, void **picture, int *size, char **mime_type) override {
-               return __get_ogg_picture(file->tag(), index, picture, size, mime_type);
+               ME_RETVM_IF(!file->tag(), METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid XiphComment");
+               return __get_flac_picture(file->tag()->pictureList(), index, picture, size, mime_type);
        }
        uint count() override {
                return file->tag() ? file->tag()->pictureList().size() : 0;
@@ -437,8 +424,7 @@ static int __get_from_property_map(PropertyMap tags, String key, char **value)
        ME_RETVM_IF(key.isEmpty(), METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid field_name");
        ME_RETVM_IF(!value, METADATA_EDITOR_ERROR_INVALID_PARAMETER, "Invalid value");
 
-       if (tags.isEmpty())
-               return METADATA_EDITOR_ERROR_NONE;
+       ME_RETV_IF(tags.isEmpty(), METADATA_EDITOR_ERROR_NONE);
 
        PropertyMap::ConstIterator found = tags.find(key);
 
@@ -448,8 +434,8 @@ static int __get_from_property_map(PropertyMap tags, String key, char **value)
        return METADATA_EDITOR_ERROR_NONE;
 }
 
-class OggFileTypeResolver : public TagLib::FileRef::FileTypeResolver {
-       TagLib::File *createFile(TagLib::FileName fileName, bool, AudioProperties::ReadStyle) const {
+class OggFileTypeResolver : public FileRef::FileTypeResolver {
+       File *createFile(FileName fileName, bool, AudioProperties::ReadStyle) const {
                String ext = __get_file_ext(fileName);
                if (ext == "OGG") {
                        File *file = new Ogg::FLAC::File(fileName);