summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2021-09-02 08:59:16 +0900
committerMinje Ahn <minje.ahn@samsung.com>2021-09-03 08:37:25 +0900
commitd3537f962eef5d8ff436dcf355f4007405746123 (patch)
tree8da1c718e0d4c3fa77aa624b6708403521a75981
parenta2a2b5f484caa3174c87413f41dcde5e46493f8d (diff)
downloadlibmedia-service-tizen_6.5.tar.gz
libmedia-service-tizen_6.5.tar.bz2
libmedia-service-tizen_6.5.zip
It took a lot of time to read podofo, so split it with dlopen. Change-Id: I57b49f062019311ba8aa3b26094c9a0c0fcd4ae4 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
-rw-r--r--CMakeLists.txt12
-rw-r--r--packaging/libmedia-service.spec5
-rw-r--r--plugin/media-ebook-plugin.cpp (renamed from src/common/media-svc-util-ebook.cpp)57
-rw-r--r--src/common/media-svc-util.c26
-rw-r--r--src/include/common/media-svc-util-ebook.h36
5 files changed, 72 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 39191b2..738a8d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,13 +6,13 @@ SET(VERSION "${VERSION_MAJOR}.0.0")
SET(MEDIASERVICE-LIB "media-service")
SET(MEDIASERVICE-HASH-LIB "media-svc-hash")
SET(MEDIACONTENT-PLUGIN-LIB "media-content-plugin")
-SET(SRCS
+SET(MEDIAEBOOK-PLUGIN-LIB "media-ebook-plugin")
+SET(SRCS
src/common/media-svc.c
src/common/media-svc-media.c
src/common/media-svc-album.c
src/common/media-svc-media-folder.c
src/common/media-svc-db-utils.c
- src/common/media-svc-util-ebook.cpp
src/common/media-svc-util.c
src/common/media-svc-noti.c
src/common/media-svc-storage.c
@@ -24,8 +24,8 @@ SET(HASH_SRCS
md5/media-svc-hash.c
)
-SET(PLUGIN_SRCS
- plugin/media-svc-plugin.c
+SET(EBOOKPLUGIN_SRCS
+ plugin/media-ebook-plugin.cpp
)
SET(CONTENTPLUGIN_SRCS
plugin/media-content-plugin.c
@@ -97,10 +97,12 @@ ADD_LIBRARY(${MEDIACONTENT-PLUGIN-LIB} SHARED ${CONTENTPLUGIN_SRCS})
TARGET_LINK_LIBRARIES(${MEDIACONTENT-PLUGIN-LIB} ${MEDIASERVICE-LIB})
SET_TARGET_PROPERTIES(${MEDIACONTENT-PLUGIN-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${MEDIACONTENT-PLUGIN-LIB} PROPERTIES VERSION ${VERSION})
+ADD_LIBRARY(${MEDIAEBOOK-PLUGIN-LIB} SHARED ${EBOOKPLUGIN_SRCS})
+TARGET_LINK_LIBRARIES(${MEDIAEBOOK-PLUGIN-LIB} ${pkgs_LDFLAGS})
INSTALL(TARGETS ${MEDIASERVICE-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
INSTALL(TARGETS ${MEDIASERVICE-HASH-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
INSTALL(TARGETS ${MEDIACONTENT-PLUGIN-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-#INSTALL(TARGETS ${MEDIACONTENT-PLUGIN-LIB} LIBRARY DESTINATION /usr/lib)
+INSTALL(TARGETS ${MEDIAEBOOK-PLUGIN-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-svc.h DESTINATION include/media-service/)
diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec
index d29d25d..523e17e 100644
--- a/packaging/libmedia-service.spec
+++ b/packaging/libmedia-service.spec
@@ -1,6 +1,6 @@
Name: libmedia-service
Summary: Media information service library for multimedia applications
-Version: 0.4.20
+Version: 0.4.21
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0 and PD
@@ -48,7 +48,7 @@ This package is a library that provides the media information service for the mu
cp %{SOURCE1001} .
%build
-export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE -DSYSCONFDIR=\\\"%{_sysconfdir}\\\""
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE -DSYSCONFDIR=\\\"%{_sysconfdir}\\\" -DPATH_LIBDIR=\\\"%{_libdir}\\\""
%cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0}
make %{?jobs:-j%jobs}
@@ -66,6 +66,7 @@ rm -rf %{buildroot}
%{_libdir}/libmedia-svc-hash.so.*
%{_libdir}/libmedia-content-plugin.so
%{_libdir}/libmedia-content-plugin.so.*
+%{_libdir}/libmedia-ebook-plugin.so
%if 0%{?gtests:1}
%{_bindir}/gtest*
%endif
diff --git a/src/common/media-svc-util-ebook.cpp b/plugin/media-ebook-plugin.cpp
index 9007265..49ea76b 100644
--- a/src/common/media-svc-util-ebook.cpp
+++ b/plugin/media-ebook-plugin.cpp
@@ -18,9 +18,10 @@
*/
#include <podofo/podofo.h>
#include <stack>
-#include <media-svc-util-ebook.h>
-#include <media-svc-debug.h>
+#include <memory>
+#include <dlog.h>
#include <glib.h>
+#include <stdbool.h>
#include <zip.h>
#include <libxml/xmlmemory.h>
@@ -29,6 +30,12 @@
#include <regex>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "MEDIA_SERVICE"
+
class TextFinderInterface
{
public:
@@ -55,17 +62,17 @@ private:
PdfTextFinder::PdfTextFinder(const char *path)
{
if (!path) {
- media_svc_error("invalid path");
+ LOGE("invalid path");
return;
}
- media_svc_debug("%s", path);
+ LOGD("%s", path);
try {
pdf.Load(path);
loaded = true;
} catch (const PoDoFo::PdfError& e) {
- media_svc_error("Initialization failed : %s", e.what());
+ LOGE("Initialization failed : %s", e.what());
}
}
@@ -74,7 +81,10 @@ bool PdfTextFinder::find(const char *keyword)
if (!loaded)
return false;
- media_svc_retvm_if(!keyword, false, "Invalid keyword");
+ if (!keyword) {
+ LOGE("Invalid keyword");
+ return false;
+ }
for (int n = 0; n < pdf.GetPageCount(); ++n) {
auto text = parseTextFromPage(n);
@@ -99,7 +109,8 @@ std::string PdfTextFinder::parseTextFromPage(unsigned int index)
PoDoFo::PdfArray array;
PoDoFo::PdfPage* page = pdf.GetPage(index);
- media_svc_retv_if(!page, fullText);
+ if (!page)
+ return fullText;
PoDoFo::PdfContentsTokenizer tokenizer(page);
@@ -165,7 +176,8 @@ std::string PdfTextFinder::parseTextFromPage(unsigned int index)
/* ToDo : match can be passed to EbookText */
bool PdfTextFinder::match(std::string& text, const char *keyword)
{
- media_svc_retv_if(!keyword, false);
+ if (!keyword)
+ return false;
if (text.empty())
return false;
@@ -173,7 +185,7 @@ bool PdfTextFinder::match(std::string& text, const char *keyword)
std::regex re(keyword, std::regex::icase);
if (std::regex_search(text, re)) {
- media_svc_debug("Found [%s]", keyword);
+ LOGD("Found [%s]", keyword);
return true;
}
@@ -201,16 +213,16 @@ private:
EpubTextFinder::EpubTextFinder(const char *path)
{
if (!path) {
- media_svc_error("invalid path");
+ LOGE("invalid path");
return;
}
- media_svc_debug("%s", path);
+ LOGD("%s", path);
int err = 0;
z = zip_open(path, ZIP_RDONLY, &err);
if (err != 0)
- media_svc_error("zip_open failed");
+ LOGE("zip_open failed");
}
EpubTextFinder::~EpubTextFinder()
@@ -226,7 +238,10 @@ bool EpubTextFinder::find(const char *keyword)
{
zip_stat_t sb = {0, };
- media_svc_retvm_if(!keyword, false, "Invalid keyword");
+ if (!keyword) {
+ LOGE("Invalid keyword");
+ return false;
+ }
int entry_len = zip_get_num_entries(z, ZIP_FL_UNCHANGED);
for (int i = 0; i < entry_len; i++) {
@@ -256,14 +271,16 @@ bool EpubTextFinder::find(const char *keyword)
bool EpubTextFinder::match(const char *text, const char *keyword)
{
- media_svc_retv_if(!keyword, false);
+ if (!keyword)
+ return false;
+
if (!text)
return false;
std::regex re(keyword, std::regex::icase);
if (std::regex_search(text, re)) {
- media_svc_debug("Found [%s]", keyword);
+ LOGD("Found [%s]", keyword);
return true;
}
@@ -287,7 +304,11 @@ bool EpubTextFinder::htmlFind(const char *html_buf, int buf_size, const char *ke
{
htmlDocPtr doc = htmlReadMemory(html_buf, buf_size, "/", NULL,
HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET);
- media_svc_retvm_if(!doc, false, "htmlReadMemory failed");
+
+ if (!doc) {
+ LOGE("htmlReadMemory failed");
+ return false;
+ }
bool result = htmlNodeFindRecursive(xmlDocGetRootElement(doc), keyword);
@@ -296,7 +317,7 @@ bool EpubTextFinder::htmlFind(const char *html_buf, int buf_size, const char *ke
return result;
}
-bool _media_svc_pdf_is_keyword_included(const char *path, const char *keyword)
+extern "C" bool media_svc_pdf_is_keyword_included(const char *path, const char *keyword)
{
/* ToDo: factory pattern */
std::unique_ptr<TextFinderInterface> ebookText = std::make_unique<PdfTextFinder>(path);
@@ -304,7 +325,7 @@ bool _media_svc_pdf_is_keyword_included(const char *path, const char *keyword)
return ebookText->find(keyword);
}
-bool _media_svc_epub_is_keyword_included(const char *path, const char *keyword)
+extern "C" bool media_svc_epub_is_keyword_included(const char *path, const char *keyword)
{
/* ToDo: factory pattern */
std::unique_ptr<TextFinderInterface> ebookText = std::make_unique<EpubTextFinder>(path);
diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c
index 46746c6..829d892 100644
--- a/src/common/media-svc-util.c
+++ b/src/common/media-svc-util.c
@@ -51,12 +51,12 @@
#include "media-svc-hash.h"
#include "media-svc-album.h"
#include "media-svc-localize_ch.h"
-#include "media-svc-util-ebook.h"
/*For ebook metadata */
#include <zip.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/HTMLparser.h>
+#include <dlfcn.h>
#define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
@@ -79,6 +79,8 @@
#define MEDIA_SVC_PDF_TAG_TAIL_LEN 12
#define MEDIA_SVC_PDF_BUF_SIZE 256
+#define PATH_PLUGIN_LIB PATH_LIBDIR"/libmedia-ebook-plugin.so"
+
enum Exif_Orientation {
NOT_AVAILABLE = 0,
NORMAL = 1,
@@ -1578,11 +1580,29 @@ bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
bool _media_svc_is_keyword_included(const char *path, const char *keyword)
{
+ bool ret = false;
+ void *handle = NULL;
+ bool (*svc_search) (const char *, const char *);
+
media_svc_retvm_if(!path, false, "Invalid path");
media_svc_retvm_if(!keyword, false, "Invalid keyword");
+ handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
+ media_svc_retvm_if(!handle, false, "dlopen failed");
+
if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
- return _media_svc_epub_is_keyword_included(path, keyword);
+ svc_search = dlsym(handle, "media_svc_epub_is_keyword_included");
else
- return _media_svc_pdf_is_keyword_included(path, keyword);
+ svc_search = dlsym(handle, "media_svc_pdf_is_keyword_included");
+
+ if (!svc_search) {
+ media_svc_error("dlsym failed - %s", dlerror());
+ dlclose(handle);
+ return false;
+ }
+
+ ret = svc_search(path, keyword);
+ dlclose(handle);
+
+ return ret;
}
diff --git a/src/include/common/media-svc-util-ebook.h b/src/include/common/media-svc-util-ebook.h
deleted file mode 100644
index 23b6748..0000000
--- a/src/include/common/media-svc-util-ebook.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * libmedia-service
- *
- * Copyright (c) 2021 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 _MEDIA_SVC_UTIL_EBOOK_H_
-#define _MEDIA_SVC_UTIL_EBOOK_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bool _media_svc_pdf_is_keyword_included(const char *path, const char *keyword);
-bool _media_svc_epub_is_keyword_included(const char *path, const char *keyword);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_MEDIA_SVC_UTIL_EBOOK_H_*/