Merge lp:~jpakkane/thumbnailer/fix-1319698 into lp:thumbnailer

Proposed by Jussi Pakkanen
Status: Superseded
Proposed branch: lp:~jpakkane/thumbnailer/fix-1319698
Merge into: lp:thumbnailer
Diff against target: 4371 lines (+4019/-0) (has conflicts)
65 files modified
CMakeLists.txt (+53/-0)
COPYING (+165/-0)
cmake/coverage.cmake (+34/-0)
debian/changelog (+128/-0)
debian/compat (+1/-0)
debian/control (+74/-0)
debian/copyright (+19/-0)
debian/libthumbnailer-dev.install (+3/-0)
debian/libthumbnailer0.install (+2/-0)
debian/libthumbnailer0.symbols (+6/-0)
debian/qtdeclarative5-ubuntu-thumbnailer0.1.install (+1/-0)
debian/rules (+13/-0)
debian/source/format (+1/-0)
debian/thumbnailer-service.install (+2/-0)
include/CMakeLists.txt (+12/-0)
include/internal/CMakeLists.txt (+1/-0)
include/internal/audioimageextractor.h (+41/-0)
include/internal/config.h.in (+24/-0)
include/internal/gobj_memory.h (+112/-0)
include/internal/httpdownloader.h (+31/-0)
include/internal/imagescaler.h (+43/-0)
include/internal/lastfmdownloader.h (+41/-0)
include/internal/mediaartcache.h (+54/-0)
include/internal/soupdownloader.h (+40/-0)
include/internal/thumbnailcache.h (+45/-0)
include/internal/videoscreenshotter.h (+39/-0)
include/thumbnailer.h (+82/-0)
include/thumbnailer.pc.in (+10/-0)
plugins/Ubuntu/Thumbnailer/CMakeLists.txt (+22/-0)
plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp (+90/-0)
plugins/Ubuntu/Thumbnailer/albumartgenerator.h (+36/-0)
plugins/Ubuntu/Thumbnailer/plugin.cpp (+47/-0)
plugins/Ubuntu/Thumbnailer/plugin.h (+34/-0)
plugins/Ubuntu/Thumbnailer/qmldir (+2/-0)
plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp (+87/-0)
plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h (+36/-0)
src/CMakeLists.txt (+41/-0)
src/audioimageextractor.cpp (+100/-0)
src/imagescaler.cpp (+162/-0)
src/lastfmdownloader.cpp (+87/-0)
src/libthumbnailer.map (+14/-0)
src/mediaartcache.cpp (+201/-0)
src/service/CMakeLists.txt (+34/-0)
src/service/com.canonical.Thumbnailer.service.in (+4/-0)
src/service/dbus-interface.xml (+17/-0)
src/service/dbusinterface.cpp (+168/-0)
src/service/dbusinterface.h (+40/-0)
src/service/main.cpp (+44/-0)
src/soupdownloader.cpp (+46/-0)
src/thumbnailcache.cpp (+300/-0)
src/thumbnailer.cpp (+226/-0)
src/videoscreenshotter.cpp (+105/-0)
src/vs-thumb.cpp (+127/-0)
tests/CMakeLists.txt (+41/-0)
tests/basic.cpp (+183/-0)
tests/download.cpp (+110/-0)
tests/mediaartcachetest.cpp (+150/-0)
tests/qml/tst_image_provider.qml (+62/-0)
tests/testsetup.h.in (+6/-0)
tests/unique_gobj.cpp (+172/-0)
tools/CMakeLists.txt (+11/-0)
tools/cachetool.cpp (+37/-0)
tools/imdump.cpp (+34/-0)
tools/lastfmtest.cpp (+31/-0)
tools/scaler.cpp (+35/-0)
Conflict adding file CMakeLists.txt.  Moved existing file to CMakeLists.txt.moved.
Conflict adding file COPYING.  Moved existing file to COPYING.moved.
Conflict adding file cmake.  Moved existing file to cmake.moved.
Conflict adding file debian.  Moved existing file to debian.moved.
Conflict adding file include.  Moved existing file to include.moved.
Conflict adding file plugins.  Moved existing file to plugins.moved.
Conflict adding file src.  Moved existing file to src.moved.
Conflict adding file tests.  Moved existing file to tests.moved.
Conflict adding file tools.  Moved existing file to tools.moved.
To merge this branch: bzr merge lp:~jpakkane/thumbnailer/fix-1319698
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+248512@code.launchpad.net

Commit message

SRU backport of patch to make file names with chinese characters work.

Description of the change

SRU backport of patch to make file names with chinese characters work.

To post a comment you must log in.
lp:~jpakkane/thumbnailer/fix-1319698 updated
15. By Jussi Pakkanen

Added bzr-builddeb conf file to make this branch citrain ready.

Unmerged revisions

15. By Jussi Pakkanen

Added bzr-builddeb conf file to make this branch citrain ready.

14. By Jussi Pakkanen

Backport patch for filenames with chinese characters.

13. By PS Jenkins bot

[ Michal Hruby ]
Provide virtual thumbnailer package.

12. By PS Jenkins bot

[ Jussi Pakkanen ]
New minor release.

11. By PS Jenkins bot

[ Jussi Pakkanen ]
Obey the TMPDIR. (LP: #1296987)

10. By PS Jenkins bot

[ Jussi Pakkanen ]
Prevent crash if exif entry is null. (LP: #1294274)

9. By PS Jenkins bot

[ Jussi Pakkanen ]
* Added visibility info to prevent accidental ABI breakages.
* Reorient images manually to work around a bug in GdkPixbuf.

8. By PS Jenkins bot

[ CI bot ]
* Resync trunk

[ Ugo Riboni ]
* Add a new nonstandard thumbnail size (360) needed by gallery-app To
  test from QML you will need this MR as well:
  https://code.launchpad.net/~amanzi-team/ubuntu-ui-toolkit/ubuntu-ui-
  toolkit-xlarge-thumbnails/+merge/207500 (LP: #1221968)

[ Jussi Pakkanen ]
* Error condition checking and error messages.
* Fix image orientation.

7. By PS Jenkins bot

[ Ricardo Salveti de Araujo ]
* vs-thumb: give pipeline at least 3 seconds to preroll

[ Jussi Pakkanen ]
* Created a unique_gobj class for managing gobject based resources.
* Fix use of #includes. (LP: #1237045)
* A bunch of fixes to make the project compile on precise.
* Removed accidentally added file.
* Invalidate cached images when source has changed.

6. By PS Jenkins bot

[ Jussi Pakkanen ]
* Fix install directory of vs-thumb. (LP: #1235325)
* Wait for child process to die when killing it with SIGKILL.

[ Ubuntu daily release ]
* Automatic snapshot from revision 58

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'CMakeLists.txt'
2--- CMakeLists.txt 1970-01-01 00:00:00 +0000
3+++ CMakeLists.txt 2015-02-04 08:57:20 +0000
4@@ -0,0 +1,53 @@
5+project(thumbnailer C CXX)
6+cmake_minimum_required(VERSION 2.8.7)
7+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
8+
9+include(CheckCXXCompilerFlag)
10+check_cxx_compiler_flag(-std=c++11 HAS_C11)
11+# Precise's GCC is too old to have -std=c++11
12+if(HAS_C11)
13+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
14+else()
15+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Dfinal=")
16+endif()
17+
18+set(SO_VERSION_MAJOR "1")
19+set(SO_VERSION_MINOR "1")
20+set(SO_VERSION_PATCH "0")
21+
22+set(SO_VERSION "${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_PATCH}")
23+
24+# Increment this manually whenever breaking ABI.
25+# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN135
26+set(ABI_VERSION 0)
27+
28+include(cmake/coverage.cmake)
29+
30+include(GNUInstallDirs)
31+set(LIBDIR ${CMAKE_INSTALL_LIBDIR})
32+set(SHARE_PRIV_DIR ${CMAKE_INSTALL_LIBDIR}/thumbnailer)
33+set(SHARE_PRIV_ABS ${CMAKE_INSTALL_PREFIX}/${SHARE_PRIV_DIR})
34+
35+find_package(Threads REQUIRED)
36+find_package(Qt5Core REQUIRED)
37+include(FindPkgConfig)
38+pkg_check_modules(GST_DEPS REQUIRED gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-pbutils-1.0 gstreamer-app-1.0)
39+pkg_check_modules(GIO_DEPS REQUIRED gio-2.0 gio-unix-2.0)
40+pkg_check_modules(IMG_DEPS REQUIRED gdk-pixbuf-2.0 libexif)
41+pkg_check_modules(SOUP_DEPS REQUIRED libsoup-2.4)
42+pkg_check_modules(XML_DEPS REQUIRED libxml-2.0)
43+
44+include_directories(${GST_DEPS_INCLUDE_DIRS})
45+include_directories(${GIO_DEPS_INCLUDE_DIRS})
46+include_directories(${IMG_DEPS_INCLUDE_DIRS})
47+include_directories(${SOUP_DEPS_INCLUDE_DIRS})
48+include_directories(${XML_DEPS_INCLUDE_DIRS})
49+include_directories(include)
50+include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
51+
52+enable_testing()
53+add_subdirectory(src)
54+add_subdirectory(plugins/Ubuntu/Thumbnailer)
55+add_subdirectory(tests)
56+add_subdirectory(tools)
57+add_subdirectory(include)
58
59=== renamed file 'CMakeLists.txt' => 'CMakeLists.txt.moved'
60=== added file 'COPYING'
61--- COPYING 1970-01-01 00:00:00 +0000
62+++ COPYING 2015-02-04 08:57:20 +0000
63@@ -0,0 +1,165 @@
64+ GNU LESSER GENERAL PUBLIC LICENSE
65+ Version 3, 29 June 2007
66+
67+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
68+ Everyone is permitted to copy and distribute verbatim copies
69+ of this license document, but changing it is not allowed.
70+
71+
72+ This version of the GNU Lesser General Public License incorporates
73+the terms and conditions of version 3 of the GNU General Public
74+License, supplemented by the additional permissions listed below.
75+
76+ 0. Additional Definitions.
77+
78+ As used herein, "this License" refers to version 3 of the GNU Lesser
79+General Public License, and the "GNU GPL" refers to version 3 of the GNU
80+General Public License.
81+
82+ "The Library" refers to a covered work governed by this License,
83+other than an Application or a Combined Work as defined below.
84+
85+ An "Application" is any work that makes use of an interface provided
86+by the Library, but which is not otherwise based on the Library.
87+Defining a subclass of a class defined by the Library is deemed a mode
88+of using an interface provided by the Library.
89+
90+ A "Combined Work" is a work produced by combining or linking an
91+Application with the Library. The particular version of the Library
92+with which the Combined Work was made is also called the "Linked
93+Version".
94+
95+ The "Minimal Corresponding Source" for a Combined Work means the
96+Corresponding Source for the Combined Work, excluding any source code
97+for portions of the Combined Work that, considered in isolation, are
98+based on the Application, and not on the Linked Version.
99+
100+ The "Corresponding Application Code" for a Combined Work means the
101+object code and/or source code for the Application, including any data
102+and utility programs needed for reproducing the Combined Work from the
103+Application, but excluding the System Libraries of the Combined Work.
104+
105+ 1. Exception to Section 3 of the GNU GPL.
106+
107+ You may convey a covered work under sections 3 and 4 of this License
108+without being bound by section 3 of the GNU GPL.
109+
110+ 2. Conveying Modified Versions.
111+
112+ If you modify a copy of the Library, and, in your modifications, a
113+facility refers to a function or data to be supplied by an Application
114+that uses the facility (other than as an argument passed when the
115+facility is invoked), then you may convey a copy of the modified
116+version:
117+
118+ a) under this License, provided that you make a good faith effort to
119+ ensure that, in the event an Application does not supply the
120+ function or data, the facility still operates, and performs
121+ whatever part of its purpose remains meaningful, or
122+
123+ b) under the GNU GPL, with none of the additional permissions of
124+ this License applicable to that copy.
125+
126+ 3. Object Code Incorporating Material from Library Header Files.
127+
128+ The object code form of an Application may incorporate material from
129+a header file that is part of the Library. You may convey such object
130+code under terms of your choice, provided that, if the incorporated
131+material is not limited to numerical parameters, data structure
132+layouts and accessors, or small macros, inline functions and templates
133+(ten or fewer lines in length), you do both of the following:
134+
135+ a) Give prominent notice with each copy of the object code that the
136+ Library is used in it and that the Library and its use are
137+ covered by this License.
138+
139+ b) Accompany the object code with a copy of the GNU GPL and this license
140+ document.
141+
142+ 4. Combined Works.
143+
144+ You may convey a Combined Work under terms of your choice that,
145+taken together, effectively do not restrict modification of the
146+portions of the Library contained in the Combined Work and reverse
147+engineering for debugging such modifications, if you also do each of
148+the following:
149+
150+ a) Give prominent notice with each copy of the Combined Work that
151+ the Library is used in it and that the Library and its use are
152+ covered by this License.
153+
154+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
155+ document.
156+
157+ c) For a Combined Work that displays copyright notices during
158+ execution, include the copyright notice for the Library among
159+ these notices, as well as a reference directing the user to the
160+ copies of the GNU GPL and this license document.
161+
162+ d) Do one of the following:
163+
164+ 0) Convey the Minimal Corresponding Source under the terms of this
165+ License, and the Corresponding Application Code in a form
166+ suitable for, and under terms that permit, the user to
167+ recombine or relink the Application with a modified version of
168+ the Linked Version to produce a modified Combined Work, in the
169+ manner specified by section 6 of the GNU GPL for conveying
170+ Corresponding Source.
171+
172+ 1) Use a suitable shared library mechanism for linking with the
173+ Library. A suitable mechanism is one that (a) uses at run time
174+ a copy of the Library already present on the user's computer
175+ system, and (b) will operate properly with a modified version
176+ of the Library that is interface-compatible with the Linked
177+ Version.
178+
179+ e) Provide Installation Information, but only if you would otherwise
180+ be required to provide such information under section 6 of the
181+ GNU GPL, and only to the extent that such information is
182+ necessary to install and execute a modified version of the
183+ Combined Work produced by recombining or relinking the
184+ Application with a modified version of the Linked Version. (If
185+ you use option 4d0, the Installation Information must accompany
186+ the Minimal Corresponding Source and Corresponding Application
187+ Code. If you use option 4d1, you must provide the Installation
188+ Information in the manner specified by section 6 of the GNU GPL
189+ for conveying Corresponding Source.)
190+
191+ 5. Combined Libraries.
192+
193+ You may place library facilities that are a work based on the
194+Library side by side in a single library together with other library
195+facilities that are not Applications and are not covered by this
196+License, and convey such a combined library under terms of your
197+choice, if you do both of the following:
198+
199+ a) Accompany the combined library with a copy of the same work based
200+ on the Library, uncombined with any other library facilities,
201+ conveyed under the terms of this License.
202+
203+ b) Give prominent notice with the combined library that part of it
204+ is a work based on the Library, and explaining where to find the
205+ accompanying uncombined form of the same work.
206+
207+ 6. Revised Versions of the GNU Lesser General Public License.
208+
209+ The Free Software Foundation may publish revised and/or new versions
210+of the GNU Lesser General Public License from time to time. Such new
211+versions will be similar in spirit to the present version, but may
212+differ in detail to address new problems or concerns.
213+
214+ Each version is given a distinguishing version number. If the
215+Library as you received it specifies that a certain numbered version
216+of the GNU Lesser General Public License "or any later version"
217+applies to it, you have the option of following the terms and
218+conditions either of that published version or of any later version
219+published by the Free Software Foundation. If the Library as you
220+received it does not specify a version number of the GNU Lesser
221+General Public License, you may choose any version of the GNU Lesser
222+General Public License ever published by the Free Software Foundation.
223+
224+ If the Library as you received it specifies that a proxy can decide
225+whether future versions of the GNU Lesser General Public License shall
226+apply, that proxy's public statement of acceptance of any version is
227+permanent authorization for you to choose that version for the
228+Library.
229
230=== renamed file 'COPYING' => 'COPYING.moved'
231=== added directory 'cmake'
232=== renamed directory 'cmake' => 'cmake.moved'
233=== added file 'cmake/coverage.cmake'
234--- cmake/coverage.cmake 1970-01-01 00:00:00 +0000
235+++ cmake/coverage.cmake 2015-02-04 08:57:20 +0000
236@@ -0,0 +1,34 @@
237+if (CMAKE_BUILD_TYPE MATCHES coverage)
238+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
239+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
240+ set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage")
241+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
242+
243+ find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
244+ if (NOT GCOVR_EXECUTABLE)
245+ message(STATUS "Gcovr binary was not found, can not generate XML coverage info.")
246+ else ()
247+ message(STATUS "Gcovr found, can generate XML coverage info.")
248+ add_custom_target (coverage-xml
249+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
250+ COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" -x -r "${CMAKE_SOURCE_DIR}"
251+ --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml)
252+ endif()
253+
254+ find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin")
255+ find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT})
256+ if (NOT LCOV_EXECUTABLE)
257+ message(STATUS "Lcov binary was not found, can not generate HTML coverage info.")
258+ else ()
259+ if(NOT GENHTML_EXECUTABLE)
260+ message(STATUS "Genthml binary not found, can not generate HTML coverage info.")
261+ else()
262+ message(STATUS "Lcov and genhtml found, can generate HTML coverage info.")
263+ add_custom_target (coverage-html
264+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
265+ COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum
266+ COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
267+ )
268+ endif()
269+ endif()
270+endif()
271
272=== added directory 'debian'
273=== renamed directory 'debian' => 'debian.moved'
274=== added file 'debian/changelog'
275--- debian/changelog 1970-01-01 00:00:00 +0000
276+++ debian/changelog 2015-02-04 08:57:20 +0000
277@@ -0,0 +1,128 @@
278+thumbnailer (1.1+14.04.20140401.1-0ubuntu1) trusty; urgency=low
279+
280+ [ Michal Hruby ]
281+ * Provide virtual thumbnailer package.
282+
283+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 01 Apr 2014 22:45:34 +0000
284+
285+thumbnailer (1.1+14.04.20140331-0ubuntu1) trusty; urgency=medium
286+
287+ [ Jussi Pakkanen ]
288+ * New minor release.
289+
290+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Mon, 31 Mar 2014 09:08:36 +0000
291+
292+thumbnailer (1.0+14.04.20140327-0ubuntu1) trusty; urgency=low
293+
294+ [ Jussi Pakkanen ]
295+ * Obey the TMPDIR. (LP: #1296987)
296+
297+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 27 Mar 2014 08:36:59 +0000
298+
299+thumbnailer (1.0+14.04.20140319-0ubuntu1) trusty; urgency=low
300+
301+ [ Jussi Pakkanen ]
302+ * Prevent crash if exif entry is null. (LP: #1294274)
303+
304+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 19 Mar 2014 20:16:40 +0000
305+
306+thumbnailer (1.0+14.04.20140307-0ubuntu1) trusty; urgency=low
307+
308+ [ Jussi Pakkanen ]
309+ * Added visibility info to prevent accidental ABI breakages.
310+ * Reorient images manually to work around a bug in GdkPixbuf.
311+
312+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 07 Mar 2014 15:41:18 +0000
313+
314+thumbnailer (1.0+14.04.20140304-0ubuntu1) trusty; urgency=low
315+
316+ [ CI bot ]
317+ * Resync trunk
318+
319+ [ Ugo Riboni ]
320+ * Add a new nonstandard thumbnail size (360) needed by gallery-app To
321+ test from QML you will need this MR as well:
322+ https://code.launchpad.net/~amanzi-team/ubuntu-ui-toolkit/ubuntu-ui-
323+ toolkit-xlarge-thumbnails/+merge/207500 (LP: #1221968)
324+
325+ [ Jussi Pakkanen ]
326+ * Error condition checking and error messages.
327+ * Fix image orientation.
328+
329+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 04 Mar 2014 10:09:12 +0000
330+
331+thumbnailer (1.0+14.04.20140218-0ubuntu1) trusty; urgency=low
332+
333+ [ Ricardo Salveti de Araujo ]
334+ * vs-thumb: give pipeline at least 3 seconds to preroll
335+
336+ [ Jussi Pakkanen ]
337+ * Created a unique_gobj class for managing gobject based resources.
338+ * Fix use of #includes. (LP: #1237045)
339+ * A bunch of fixes to make the project compile on precise.
340+ * Removed accidentally added file.
341+ * Invalidate cached images when source has changed.
342+
343+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 18 Feb 2014 23:01:31 +0000
344+
345+thumbnailer (1.0+13.10.20131011-0ubuntu1) saucy; urgency=low
346+
347+ [ Jussi Pakkanen ]
348+ * Fix install directory of vs-thumb. (LP: #1235325)
349+ * Wait for child process to die when killing it with SIGKILL.
350+
351+ [ Ubuntu daily release ]
352+ * Automatic snapshot from revision 58
353+
354+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 11 Oct 2013 05:41:32 +0000
355+
356+thumbnailer (1.0+13.10.20131008-0ubuntu1) saucy; urgency=low
357+
358+ [ Jussi Pakkanen ]
359+ * Fix off by one error. (LP: #1235444)
360+ * Disable use of in-process GStreamer because we use 1.0, which
361+ clashes with 0.10. (LP: #1235484)
362+
363+ [ Ubuntu daily release ]
364+ * Automatic snapshot from revision 55
365+
366+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 08 Oct 2013 12:49:51 +0000
367+
368+thumbnailer (1.0+13.10.20131007-0ubuntu1) saucy; urgency=low
369+
370+ [ Jussi Pakkanen ]
371+ * Write files into cache atomically.
372+ * Guard against a frozen worker process.
373+ * Document the public interface.
374+
375+ [ Ubuntu daily release ]
376+ * Automatic snapshot from revision 52
377+
378+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Mon, 07 Oct 2013 10:52:14 +0000
379+
380+thumbnailer (1.0+13.10.20131003-0ubuntu1) saucy; urgency=low
381+
382+ [ Jussi Pakkanen ]
383+ * Run gstreamer video pipelines in an external process.
384+ * Get helper path from config.h.
385+ * Use helper binary from build dir when running tests.
386+ * Adds support for full resolution thumbnails.
387+
388+ [ Ubuntu daily release ]
389+ * Automatic snapshot from revision 48
390+
391+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 03 Oct 2013 03:26:49 +0000
392+
393+thumbnailer (1.0+13.10.20131002-0ubuntu1) saucy; urgency=low
394+
395+ [ Jussi Pakkanen ]
396+ * Initial release.
397+ * Typo fix.
398+
399+ [ Łukasz 'sil2100' Zemczak ]
400+ * Automatic snapshot from revision 41 (bootstrap)
401+
402+ [ Ubuntu daily release ]
403+ * Automatic snapshot from revision 43
404+
405+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 02 Oct 2013 02:34:38 +0000
406
407=== added file 'debian/compat'
408--- debian/compat 1970-01-01 00:00:00 +0000
409+++ debian/compat 2015-02-04 08:57:20 +0000
410@@ -0,0 +1,1 @@
411+9
412
413=== added file 'debian/control'
414--- debian/control 1970-01-01 00:00:00 +0000
415+++ debian/control 2015-02-04 08:57:20 +0000
416@@ -0,0 +1,74 @@
417+Source: thumbnailer
418+Section: libdevel
419+Priority: optional
420+Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
421+Standards-Version: 3.9.4
422+Build-Depends: cmake,
423+ debhelper (>= 9),
424+ gstreamer1.0-plugins-good,
425+ libexif-dev,
426+ libgdk-pixbuf2.0-dev,
427+ libgstreamer1.0-dev,
428+ libgstreamer-plugins-base1.0-dev,
429+ libgtest-dev,
430+ libsoup2.4-dev,
431+ libxml2-dev,
432+ qt5-default,
433+ qtbase5-dev,
434+ qtbase5-dev-tools,
435+ qtdeclarative5-dev,
436+ shared-mime-info,
437+Homepage: https://launchpad.net/thumbnailer
438+# if you don't have have commit access to this branch but would like to upload
439+# directly to Ubuntu, don't worry: your changes will be merged back into the
440+# upstream branch
441+Vcs-Bzr: lp:thumbnailer
442+
443+Package: libthumbnailer0
444+Architecture: any
445+Multi-Arch: same
446+Pre-Depends: ${misc:Pre-Depends},
447+Depends: ${misc:Depends},
448+ ${shlibs:Depends},
449+Description: generate thumbnails from files
450+ Thumbnailer is a shared library that generates
451+ thumbnail images for multiple file types such
452+ as video and audio files.
453+
454+Package: libthumbnailer-dev
455+Architecture: any
456+Multi-Arch: same
457+Pre-Depends: ${misc:Pre-Depends},
458+Depends: ${misc:Depends},
459+ ${shlibs:Depends},
460+ gstreamer1.0-plugins-base,
461+ gstreamer1.0-plugins-good,
462+ libthumbnailer0 (= ${binary:Version}),
463+Description: development files for thumbnailer
464+ This package contains development files
465+ for the thumbnailer package.
466+
467+Package: thumbnailer-service
468+Architecture: any
469+Multi-Arch: foreign
470+Pre-Depends: ${misc:Pre-Depends},
471+Depends: ${misc:Depends},
472+ ${shlibs:Depends},
473+ libthumbnailer0 (= ${binary:Version}),
474+Description: D-Bus service for out of process thumbnailing
475+ This package provides a D-Bus service that can provide thumbnails on
476+ behalf of another process.
477+
478+Package: qtdeclarative5-ubuntu-thumbnailer0.1
479+Architecture: any
480+Multi-Arch: same
481+Pre-Depends: ${misc:Pre-Depends},
482+Depends: ${misc:Depends},
483+ ${shlibs:Depends},
484+ libthumbnailer0 (= ${binary:Version}),
485+Provides: ubuntu-thumbnailer-impl,
486+ ubuntu-thumbnailer-impl-0,
487+Recommends: thumbnailer-service (= ${binary:Version}),
488+Description: QML interface for the thumbnailer.
489+ This package provides image providers that allow access to the
490+ thumbnailer from Qt Quick 2 / QML applications.
491
492=== added file 'debian/copyright'
493--- debian/copyright 1970-01-01 00:00:00 +0000
494+++ debian/copyright 2015-02-04 08:57:20 +0000
495@@ -0,0 +1,19 @@
496+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
497+Upstream-Name: thumbnailer
498+Source: https://launchpad.net/thumbnailer
499+
500+Files: *
501+Copyright: 2013 Canonical ltd
502+License: LGPL-3
503+ This program is free software: you can redistribute it and/or modify
504+ it under the terms of version 3 of the GNU Lesser General Public
505+ License as published by the Free Software Foundation.
506+ .
507+ This program is distributed in the hope that it will be useful,
508+ but WITHOUT ANY WARRANTY; without even the implied warranty of
509+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
510+ GNU General Public License for more details.
511+ .
512+ On Debian systems, the full text of the GNU Lesser General Public
513+ License version 3 can be found in the file
514+ `/usr/share/common-licenses/LGPL-3'
515
516=== added file 'debian/libthumbnailer-dev.install'
517--- debian/libthumbnailer-dev.install 1970-01-01 00:00:00 +0000
518+++ debian/libthumbnailer-dev.install 2015-02-04 08:57:20 +0000
519@@ -0,0 +1,3 @@
520+usr/include/*
521+usr/lib/*/lib*.so
522+usr/lib/*/pkgconfig/*
523
524=== added file 'debian/libthumbnailer0.install'
525--- debian/libthumbnailer0.install 1970-01-01 00:00:00 +0000
526+++ debian/libthumbnailer0.install 2015-02-04 08:57:20 +0000
527@@ -0,0 +1,2 @@
528+usr/lib/*/libthumb*.so.*
529+usr/lib/*/thumbnailer/vs-thumb
530
531=== added file 'debian/libthumbnailer0.symbols'
532--- debian/libthumbnailer0.symbols 1970-01-01 00:00:00 +0000
533+++ debian/libthumbnailer0.symbols 2015-02-04 08:57:20 +0000
534@@ -0,0 +1,6 @@
535+libthumbnailer.so.0 libthumbnailer0 #MINVER#
536+ (c++)"Thumbnailer::get_thumbnail(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize)@Base" 1.0
537+ (c++)"Thumbnailer::get_thumbnail(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize, ThumbnailPolicy)@Base" 1.0
538+ (c++)"Thumbnailer::get_album_art(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize, ThumbnailPolicy)@Base" 1.0
539+ (c++)"Thumbnailer::Thumbnailer()@Base" 1.0
540+ (c++)"Thumbnailer::~Thumbnailer()@Base" 1.0
541
542=== added file 'debian/qtdeclarative5-ubuntu-thumbnailer0.1.install'
543--- debian/qtdeclarative5-ubuntu-thumbnailer0.1.install 1970-01-01 00:00:00 +0000
544+++ debian/qtdeclarative5-ubuntu-thumbnailer0.1.install 2015-02-04 08:57:20 +0000
545@@ -0,0 +1,1 @@
546+usr/lib/*/qt5/qml/Ubuntu/Thumbnailer.0.1/*
547
548=== added file 'debian/rules'
549--- debian/rules 1970-01-01 00:00:00 +0000
550+++ debian/rules 2015-02-04 08:57:20 +0000
551@@ -0,0 +1,13 @@
552+#!/usr/bin/make -f
553+# -*- makefile -*-
554+
555+# Uncomment this to turn on verbose mode.
556+#export DH_VERBOSE=1
557+
558+export DPKG_GENSYMBOLS_CHECK_LEVEL=4
559+
560+# http://ccache.samba.org/manual.html#_precompiled_headers
561+export CCACHE_SLOPPINESS=time_macros
562+
563+%:
564+ dh $@ --parallel --fail-missing
565
566=== added directory 'debian/source'
567=== added file 'debian/source/format'
568--- debian/source/format 1970-01-01 00:00:00 +0000
569+++ debian/source/format 2015-02-04 08:57:20 +0000
570@@ -0,0 +1,1 @@
571+1.0
572
573=== added file 'debian/thumbnailer-service.install'
574--- debian/thumbnailer-service.install 1970-01-01 00:00:00 +0000
575+++ debian/thumbnailer-service.install 2015-02-04 08:57:20 +0000
576@@ -0,0 +1,2 @@
577+usr/lib/*/thumbnailer/thumbnailer-service
578+usr/share/dbus-1/services/com.canonical.Thumbnailer.service
579
580=== added directory 'include'
581=== renamed directory 'include' => 'include.moved'
582=== added file 'include/CMakeLists.txt'
583--- include/CMakeLists.txt 1970-01-01 00:00:00 +0000
584+++ include/CMakeLists.txt 2015-02-04 08:57:20 +0000
585@@ -0,0 +1,12 @@
586+add_subdirectory(internal)
587+
588+install(FILES thumbnailer.h DESTINATION include)
589+
590+# Build and install a pkg-config file
591+set(prefix ${CMAKE_INSTALL_PREFIX})
592+set(exec_prefix ${prefix}/bin)
593+set(libdir ${prefix}/${LIBDIR})
594+set(includedir ${prefix}/include)
595+set(pkg-name "lib${COL_LIB_BASENAME}")
596+configure_file(thumbnailer.pc.in thumbnailer.pc @ONLY)
597+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/thumbnailer.pc DESTINATION ${LIBDIR}/pkgconfig)
598
599=== added directory 'include/internal'
600=== added file 'include/internal/CMakeLists.txt'
601--- include/internal/CMakeLists.txt 1970-01-01 00:00:00 +0000
602+++ include/internal/CMakeLists.txt 2015-02-04 08:57:20 +0000
603@@ -0,0 +1,1 @@
604+configure_file(config.h.in config.h @ONLY)
605
606=== added file 'include/internal/audioimageextractor.h'
607--- include/internal/audioimageextractor.h 1970-01-01 00:00:00 +0000
608+++ include/internal/audioimageextractor.h 2015-02-04 08:57:20 +0000
609@@ -0,0 +1,41 @@
610+/*
611+ * Copyright (C) 2013 Canonical Ltd.
612+ *
613+ * This program is free software: you can redistribute it and/or modify
614+ * it under the terms of the GNU Lesser General Public License version 3 as
615+ * published by the Free Software Foundation.
616+ *
617+ * This program is distributed in the hope that it will be useful,
618+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
619+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
620+ * GNU Lesser General Public License for more details.
621+ *
622+ * You should have received a copy of the GNU Lesser General Public License
623+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
624+ *
625+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
626+ */
627+
628+#ifndef AUDIOIMAGEEXTRACTOR_H_
629+#define AUDIOIMAGEEXTRACTOR_H_
630+
631+#include<string>
632+
633+class AudioImageExtractorPrivate;
634+
635+class AudioImageExtractor final {
636+public:
637+ AudioImageExtractor();
638+ ~AudioImageExtractor();
639+
640+ AudioImageExtractor(const AudioImageExtractor &t) = delete;
641+ AudioImageExtractor & operator=(const AudioImageExtractor &t) = delete;
642+
643+ bool extract(const std::string &ifname, const std::string &ofname);
644+
645+private:
646+ AudioImageExtractorPrivate *p;
647+};
648+
649+
650+#endif
651
652=== added file 'include/internal/config.h.in'
653--- include/internal/config.h.in 1970-01-01 00:00:00 +0000
654+++ include/internal/config.h.in 2015-02-04 08:57:20 +0000
655@@ -0,0 +1,24 @@
656+/*
657+ * Copyright (C) 2013 Canonical Ltd.
658+ *
659+ * This program is free software: you can redistribute it and/or modify
660+ * it under the terms of the GNU Lesser General Public License version 3 as
661+ * published by the Free Software Foundation.
662+ *
663+ * This program is distributed in the hope that it will be useful,
664+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
665+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
666+ * GNU Lesser General Public License for more details.
667+ *
668+ * You should have received a copy of the GNU Lesser General Public License
669+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
670+ *
671+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
672+ */
673+
674+#ifndef THUMBNAILER_CONFIG_H
675+#define THUMBNAILER_CONFIG_H
676+
677+#cmakedefine SHARE_PRIV_ABS "@SHARE_PRIV_ABS@"
678+
679+#endif
680
681=== added file 'include/internal/gobj_memory.h'
682--- include/internal/gobj_memory.h 1970-01-01 00:00:00 +0000
683+++ include/internal/gobj_memory.h 2015-02-04 08:57:20 +0000
684@@ -0,0 +1,112 @@
685+/*
686+ * Copyright (C) 2013 Canonical Ltd.
687+ *
688+ * This program is free software: you can redistribute it and/or modify
689+ * it under the terms of the GNU Lesser General Public License version 3 as
690+ * published by the Free Software Foundation.
691+ *
692+ * This program is distributed in the hope that it will be useful,
693+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
694+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
695+ * GNU Lesser General Public License for more details.
696+ *
697+ * You should have received a copy of the GNU Lesser General Public License
698+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
699+ *
700+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
701+ */
702+
703+#ifndef GOBJ_MEMORY_H_
704+#define GOBJ_MEMORY_H_
705+
706+#include<glib-object.h>
707+#include<stdexcept>
708+
709+/**
710+ * This class is meant for automatically managing the lifetime of C objects derived
711+ * from gobject. Its API perfectly mirrors the API of unique_ptr except that you
712+ * can't define your own deleter function as it is always g_object_unref.
713+ *
714+ * API/ABI stability is not guaranteed. If you need to pass the object across an ABI
715+ * boundary, pass the plain gobject.
716+ *
717+ * This is how you would use unique_gobj 99% of the time:
718+ *
719+ * unique_gobj<GSomeType> o(g_some_type_new(...));
720+ *
721+ * More specifically, the object will decrement the gobject reference count
722+ * of the object it points to when it goes out of scope. It will never increment it.
723+ * Thus you should only assign to it when already holding a reference. unique_gobj
724+ * will then take ownership of that particular reference.
725+ *
726+ * Floating gobjects can not be put in this container as they are meant to be put
727+ * into native gobject aware containers immediately upon construction. Trying to insert
728+ * a floating gobject into a unique_gobj will throw an invalid_argument exception. To
729+ * prevent accidental memory leaks, the floating gobject is unreffed in this case.
730+ */
731+template<typename T>
732+class unique_gobj final {
733+private:
734+ T* u;
735+
736+ void validate_float(T *t) {
737+ if(t != nullptr && g_object_is_floating(G_OBJECT(t))) {
738+ throw std::invalid_argument("Tried to add a floating gobject into a unique_gobj.");
739+ }
740+ }
741+
742+public:
743+ typedef T element_type;
744+ typedef T* pointer;
745+ typedef decltype(g_object_unref) deleter_type;
746+
747+ constexpr unique_gobj() noexcept : u(nullptr) {}
748+ explicit unique_gobj(T *t) : u(t) {
749+ // What should we do if validate throws? Unreffing unknown objs
750+ // is dodgy but not unreffing runs the risk of
751+ // memory leaks. Currently unrefs as u is destroyed
752+ // when this exception is thrown.
753+ validate_float(t);
754+ }
755+ constexpr unique_gobj(std::nullptr_t) noexcept : u(nullptr) {};
756+ unique_gobj(unique_gobj &&o) noexcept { u = o.u; o.u = nullptr; }
757+ unique_gobj(const unique_gobj &o) = delete;
758+ unique_gobj& operator=(unique_gobj &o) = delete;
759+ ~unique_gobj() { reset(); }
760+
761+ deleter_type& get_deleter() noexcept { return g_object_unref; }
762+ const deleter_type& get_deleter() const noexcept { return g_object_unref; }
763+
764+ void swap(unique_gobj<T> &o) noexcept { T*tmp = u; u = o.u; o.u = tmp; }
765+ void reset(pointer p = pointer()) {
766+ if(u!=nullptr) {
767+ g_object_unref(G_OBJECT(u));
768+ u = nullptr;
769+ }
770+ // Same throw dilemma as in pointer constructor.
771+ u = p;
772+ validate_float(p);
773+ }
774+
775+ T* release() noexcept { T* r = u; u=nullptr; return r; }
776+ T* get() const noexcept { return u; }
777+
778+ T& operator*() const { return *u; }
779+ T* operator->() const noexcept { return u; }
780+ explicit operator bool() const noexcept { return u != nullptr; }
781+
782+ unique_gobj& operator=(unique_gobj &&o) noexcept { reset(); u = o.u; o.u = nullptr; return *this; }
783+ unique_gobj& operator=(std::nullptr_t) noexcept { reset(); return *this; }
784+ bool operator==(const unique_gobj<T> &o) const noexcept { return u == o.u; }
785+ bool operator!=(const unique_gobj<T> &o) const noexcept { return u != o.u; }
786+ bool operator<(const unique_gobj<T> &o) const noexcept { return u < o.u; }
787+ bool operator<=(const unique_gobj<T> &o) const noexcept { return u <= o.u; }
788+ bool operator>(const unique_gobj<T> &o) const noexcept { return u > o.u; }
789+ bool operator>=(const unique_gobj<T> &o) const noexcept { return u >= o.u; }
790+};
791+
792+template<typename T>
793+void ::std::swap(unique_gobj<T> &f, unique_gobj<T> &s) noexcept { f.swap(s); }
794+
795+
796+#endif
797
798=== added file 'include/internal/httpdownloader.h'
799--- include/internal/httpdownloader.h 1970-01-01 00:00:00 +0000
800+++ include/internal/httpdownloader.h 2015-02-04 08:57:20 +0000
801@@ -0,0 +1,31 @@
802+/*
803+ * Copyright (C) 2014 Canonical Ltd.
804+ *
805+ * This program is free software: you can redistribute it and/or modify
806+ * it under the terms of the GNU Lesser General Public License version 3 as
807+ * published by the Free Software Foundation.
808+ *
809+ * This program is distributed in the hope that it will be useful,
810+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
811+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
812+ * GNU Lesser General Public License for more details.
813+ *
814+ * You should have received a copy of the GNU Lesser General Public License
815+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
816+ *
817+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
818+ */
819+
820+#ifndef HTTPDOWNLOADER_H
821+#define HTTPDOWNLOADER_H
822+
823+#include<string>
824+
825+class HttpDownloader {
826+public:
827+ virtual std::string download(const std::string &url) = 0;
828+ virtual ~HttpDownloader() {};
829+};
830+
831+
832+#endif
833
834=== added file 'include/internal/imagescaler.h'
835--- include/internal/imagescaler.h 1970-01-01 00:00:00 +0000
836+++ include/internal/imagescaler.h 2015-02-04 08:57:20 +0000
837@@ -0,0 +1,43 @@
838+/*
839+ * Copyright (C) 2013 Canonical Ltd.
840+ *
841+ * This program is free software: you can redistribute it and/or modify
842+ * it under the terms of the GNU Lesser General Public License version 3 as
843+ * published by the Free Software Foundation.
844+ *
845+ * This program is distributed in the hope that it will be useful,
846+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
847+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
848+ * GNU Lesser General Public License for more details.
849+ *
850+ * You should have received a copy of the GNU Lesser General Public License
851+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
852+ *
853+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
854+ */
855+
856+#ifndef IMAGESCALER_H_
857+#define IMAGESCALER_H_
858+
859+#include<thumbnailer.h>
860+#include<string>
861+
862+class ImageScalerPrivate;
863+
864+class ImageScaler final {
865+public:
866+ ImageScaler();
867+ ~ImageScaler();
868+
869+ ImageScaler(const ImageScaler &t) = delete;
870+ ImageScaler & operator=(const ImageScaler &t) = delete;
871+
872+ bool scale(const std::string &ifilename, const std::string &ofilename,
873+ ThumbnailSize wanted, const std::string &original_location) const;
874+
875+private:
876+ ImageScalerPrivate *p;
877+};
878+
879+
880+#endif
881
882=== added file 'include/internal/lastfmdownloader.h'
883--- include/internal/lastfmdownloader.h 1970-01-01 00:00:00 +0000
884+++ include/internal/lastfmdownloader.h 2015-02-04 08:57:20 +0000
885@@ -0,0 +1,41 @@
886+/*
887+ * Copyright (C) 2014 Canonical Ltd.
888+ *
889+ * This program is free software: you can redistribute it and/or modify
890+ * it under the terms of the GNU Lesser General Public License version 3 as
891+ * published by the Free Software Foundation.
892+ *
893+ * This program is distributed in the hope that it will be useful,
894+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
895+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
896+ * GNU Lesser General Public License for more details.
897+ *
898+ * You should have received a copy of the GNU Lesser General Public License
899+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
900+ *
901+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
902+ */
903+
904+#ifndef LASTFM_DOWNLOADER_H
905+#define LASTFM_DOWNLOADER_H
906+
907+#include<string>
908+#include<memory>
909+#include<internal/httpdownloader.h>
910+
911+class LastFMDownloader final {
912+public:
913+ LastFMDownloader();
914+ LastFMDownloader(HttpDownloader *o); // Takes ownership.
915+ ~LastFMDownloader();
916+ LastFMDownloader(const LastFMDownloader &o) = delete;
917+ LastFMDownloader& operator=(const LastFMDownloader &o) = delete;
918+
919+ bool download(const std::string &artist, const std::string &album,
920+ const std::string &fname);
921+private:
922+ std::string parseXML(const std::string &xml);
923+ std::unique_ptr<HttpDownloader> dl;
924+};
925+
926+#endif
927
928=== added file 'include/internal/mediaartcache.h'
929--- include/internal/mediaartcache.h 1970-01-01 00:00:00 +0000
930+++ include/internal/mediaartcache.h 2015-02-04 08:57:20 +0000
931@@ -0,0 +1,54 @@
932+/*
933+ * Copyright (C) 2013-2014 Canonical Ltd.
934+ *
935+ * This program is free software: you can redistribute it and/or modify
936+ * it under the terms of the GNU Lesser General Public License version 3 as
937+ * published by the Free Software Foundation.
938+ *
939+ * This program is distributed in the hope that it will be useful,
940+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
941+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
942+ * GNU Lesser General Public License for more details.
943+ *
944+ * You should have received a copy of the GNU Lesser General Public License
945+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
946+ *
947+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
948+ */
949+
950+#ifndef MEDIAARTCACHE_H
951+#define MEDIAARTCACHE_H
952+
953+#include<string>
954+
955+/*
956+ * A class to store thumbnails for files according to
957+ * https://wiki.gnome.org/MediaArtStorageSpec
958+ *
959+ * As this class deals mostly with the filesystem, all
960+ * errors are reported with runtime_error exceptions.
961+ */
962+
963+
964+class MediaArtCache {
965+private:
966+ std::string root_dir;
967+
968+ std::string compute_base_name(const std::string &artist, const std::string &album) const;
969+ std::string get_full_filename(const std::string &artist, const std::string & album) const;
970+
971+public:
972+ static const unsigned int MAX_SIZE = 200;
973+
974+ MediaArtCache();
975+ bool has_art(const std::string &artist, const std::string &album) const;
976+ void add_art(const std::string &artist, const std::string &album,
977+ const char *data, unsigned int datalen);
978+ std::string get_art_file(const std::string &artist, const std::string &album) const;
979+ std::string get_art_uri(const std::string &artist, const std::string &album) const;
980+ void clear() const;
981+ void prune();
982+ std::string get_cache_dir() const { return root_dir; }
983+};
984+
985+#endif
986
987=== added file 'include/internal/soupdownloader.h'
988--- include/internal/soupdownloader.h 1970-01-01 00:00:00 +0000
989+++ include/internal/soupdownloader.h 2015-02-04 08:57:20 +0000
990@@ -0,0 +1,40 @@
991+/*
992+ * Copyright (C) 2014 Canonical Ltd.
993+ *
994+ * This program is free software: you can redistribute it and/or modify
995+ * it under the terms of the GNU Lesser General Public License version 3 as
996+ * published by the Free Software Foundation.
997+ *
998+ * This program is distributed in the hope that it will be useful,
999+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1000+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1001+ * GNU Lesser General Public License for more details.
1002+ *
1003+ * You should have received a copy of the GNU Lesser General Public License
1004+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1005+ *
1006+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1007+ */
1008+
1009+#ifndef SOUPDOWNLOADER_H
1010+#define SOUPDOWNLOADER_H
1011+
1012+#include<internal/httpdownloader.h>
1013+
1014+typedef struct _SoupSession SoupSession;
1015+
1016+class SoupDownloader final : public HttpDownloader {
1017+
1018+private:
1019+ SoupSession *session;
1020+
1021+public:
1022+ SoupDownloader();
1023+ virtual ~SoupDownloader();
1024+ SoupDownloader(const SoupDownloader &o) = delete;
1025+ SoupDownloader& operator=(const SoupDownloader &o) = delete;
1026+
1027+ std::string download(const std::string &url) override;
1028+};
1029+
1030+#endif
1031
1032=== added file 'include/internal/thumbnailcache.h'
1033--- include/internal/thumbnailcache.h 1970-01-01 00:00:00 +0000
1034+++ include/internal/thumbnailcache.h 2015-02-04 08:57:20 +0000
1035@@ -0,0 +1,45 @@
1036+/*
1037+ * Copyright (C) 2013 Canonical Ltd.
1038+ *
1039+ * This program is free software: you can redistribute it and/or modify
1040+ * it under the terms of the GNU Lesser General Public License version 3 as
1041+ * published by the Free Software Foundation.
1042+ *
1043+ * This program is distributed in the hope that it will be useful,
1044+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1045+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1046+ * GNU Lesser General Public License for more details.
1047+ *
1048+ * You should have received a copy of the GNU Lesser General Public License
1049+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1050+ *
1051+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1052+ */
1053+
1054+#ifndef THUMBNAILCACHE_H_
1055+#define THUMBNAILCACHE_H_
1056+
1057+#include<thumbnailer.h>
1058+#include<string>
1059+
1060+class ThumbnailCachePrivate;
1061+
1062+class ThumbnailCache final {
1063+public:
1064+ ThumbnailCache();
1065+ ~ThumbnailCache();
1066+
1067+ ThumbnailCache(const ThumbnailCache &t) = delete;
1068+ ThumbnailCache & operator=(const ThumbnailCache &t) = delete;
1069+
1070+ std::string get_if_exists(const std::string &abs_path, ThumbnailSize desired_size) const;
1071+ std::string get_cache_file_name(const std::string &as_path, ThumbnailSize desired_size) const;
1072+ void clear();
1073+ void prune();
1074+
1075+private:
1076+ ThumbnailCachePrivate *p;
1077+};
1078+
1079+
1080+#endif
1081
1082=== added file 'include/internal/videoscreenshotter.h'
1083--- include/internal/videoscreenshotter.h 1970-01-01 00:00:00 +0000
1084+++ include/internal/videoscreenshotter.h 2015-02-04 08:57:20 +0000
1085@@ -0,0 +1,39 @@
1086+/*
1087+ * Copyright (C) 2013 Canonical Ltd.
1088+ *
1089+ * This program is free software: you can redistribute it and/or modify
1090+ * it under the terms of the GNU Lesser General Public License version 3 as
1091+ * published by the Free Software Foundation.
1092+ *
1093+ * This program is distributed in the hope that it will be useful,
1094+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1095+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1096+ * GNU Lesser General Public License for more details.
1097+ *
1098+ * You should have received a copy of the GNU Lesser General Public License
1099+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1100+ *
1101+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1102+ */
1103+
1104+#ifndef VIDEOSCREENSHOTTER_H_
1105+#define VIDEOSCREENSHOTTER_H_
1106+
1107+#include<string>
1108+
1109+class VideoScreenshotterPrivate;
1110+
1111+class VideoScreenshotter final {
1112+public:
1113+ VideoScreenshotter();
1114+ ~VideoScreenshotter();
1115+
1116+ VideoScreenshotter(const VideoScreenshotter &t) = delete;
1117+ VideoScreenshotter & operator=(const VideoScreenshotter &t) = delete;
1118+
1119+ bool extract(const std::string &ifname, const std::string &ofname);
1120+
1121+};
1122+
1123+
1124+#endif
1125
1126=== added file 'include/thumbnailer.h'
1127--- include/thumbnailer.h 1970-01-01 00:00:00 +0000
1128+++ include/thumbnailer.h 2015-02-04 08:57:20 +0000
1129@@ -0,0 +1,82 @@
1130+/*
1131+ * Copyright (C) 2013 Canonical Ltd.
1132+ *
1133+ * This program is free software: you can redistribute it and/or modify
1134+ * it under the terms of the GNU Lesser General Public License version 3 as
1135+ * published by the Free Software Foundation.
1136+ *
1137+ * This program is distributed in the hope that it will be useful,
1138+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1139+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1140+ * GNU Lesser General Public License for more details.
1141+ *
1142+ * You should have received a copy of the GNU Lesser General Public License
1143+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1144+ *
1145+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1146+ */
1147+
1148+#ifndef THUMBNAILER_H_
1149+#define THUMBNAILER_H_
1150+
1151+#include<string>
1152+
1153+class ThumbnailerPrivate;
1154+
1155+enum ThumbnailSize {
1156+ TN_SIZE_SMALL, // maximum dimension 128 pixels
1157+ TN_SIZE_LARGE, // maximum dimension 256 pixels
1158+ TN_SIZE_XLARGE, // maximum dimension 512 pixels
1159+ TN_SIZE_ORIGINAL // Whatever the original size was, e.g. 1920x1080 for FullHD video
1160+};
1161+
1162+enum ThumbnailPolicy {
1163+ TN_LOCAL, // Use only local information
1164+ TN_REMOTE, // Use remote services (e.g. album art downloading)
1165+};
1166+
1167+/**
1168+ * This class provides a way to generate and access
1169+ * thumbnails of video, audio and image files.
1170+ *
1171+ * All methods are blocking.
1172+ *
1173+ * All methods are thread safe.
1174+ *
1175+ * Errors are reported as exceptions.
1176+ */
1177+
1178+class Thumbnailer {
1179+public:
1180+ Thumbnailer();
1181+ ~Thumbnailer();
1182+
1183+ /**
1184+ * Gets a thumbnail of the given input file in the requested size.
1185+ *
1186+ * Return value is a string pointing to the thumbnail file. If
1187+ * the thumbnail could not be generated and empty string is returned.
1188+ *
1189+ * Applications should treat the returned file as read only. They should _not_
1190+ * delete it.
1191+ *
1192+ * In case of unexpected problems, the function throws a
1193+ * std::runtime_error.
1194+ */
1195+ std::string get_thumbnail(const std::string &filename, ThumbnailSize desired_size,
1196+ ThumbnailPolicy policy);
1197+ /**
1198+ * Deprecated. Do not use!
1199+ */
1200+ std::string get_thumbnail(const std::string &filename, ThumbnailSize desired_size);
1201+
1202+ std::string get_album_art(const std::string &artist, const std::string &album,
1203+ ThumbnailSize desiredSize, ThumbnailPolicy policy);
1204+private:
1205+ Thumbnailer(const Thumbnailer &t);
1206+ Thumbnailer & operator=(const Thumbnailer &t);
1207+
1208+ ThumbnailerPrivate *p;
1209+};
1210+
1211+#endif
1212
1213=== added file 'include/thumbnailer.pc.in'
1214--- include/thumbnailer.pc.in 1970-01-01 00:00:00 +0000
1215+++ include/thumbnailer.pc.in 2015-02-04 08:57:20 +0000
1216@@ -0,0 +1,10 @@
1217+prefix=@prefix@
1218+exec_prefix=@exec_prefix@
1219+libdir=@libdir@
1220+includedir=@includedir@
1221+
1222+Name: thumbnailer
1223+Description: Thumbnail generator for multiple file types.
1224+Version: @SO_VERSION@
1225+Libs: -L${libdir} -lthumbnailer
1226+Cflags: -I${includedir}
1227
1228=== added directory 'plugins'
1229=== renamed directory 'plugins' => 'plugins.moved'
1230=== added directory 'plugins/Ubuntu'
1231=== added directory 'plugins/Ubuntu/Thumbnailer'
1232=== added file 'plugins/Ubuntu/Thumbnailer/CMakeLists.txt'
1233--- plugins/Ubuntu/Thumbnailer/CMakeLists.txt 1970-01-01 00:00:00 +0000
1234+++ plugins/Ubuntu/Thumbnailer/CMakeLists.txt 2015-02-04 08:57:20 +0000
1235@@ -0,0 +1,22 @@
1236+
1237+set(QML_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/qt5/qml/Ubuntu/Thumbnailer.0.1")
1238+
1239+add_library(thumbnailer-qml MODULE
1240+ plugin.cpp
1241+ albumartgenerator.cpp
1242+ thumbnailgenerator.cpp
1243+)
1244+
1245+set_target_properties(thumbnailer-qml PROPERTIES AUTOMOC TRUE)
1246+qt5_use_modules(thumbnailer-qml Qml Quick DBus)
1247+target_link_libraries(thumbnailer-qml thumbnailer)
1248+
1249+install(
1250+ TARGETS thumbnailer-qml
1251+ LIBRARY DESTINATION ${QML_PLUGIN_DIR}
1252+)
1253+
1254+install(
1255+ FILES qmldir
1256+ DESTINATION ${QML_PLUGIN_DIR}
1257+)
1258
1259=== added file 'plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp'
1260--- plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp 1970-01-01 00:00:00 +0000
1261+++ plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp 2015-02-04 08:57:20 +0000
1262@@ -0,0 +1,90 @@
1263+/*
1264+ * Copyright 2014 Canonical Ltd.
1265+ *
1266+ * This program is free software; you can redistribute it and/or modify
1267+ * it under the terms of the GNU Lesser General Public License as published by
1268+ * the Free Software Foundation; version 3.
1269+ *
1270+ * This program is distributed in the hope that it will be useful,
1271+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1272+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1273+ * GNU Lesser General Public License for more details.
1274+ *
1275+ * You should have received a copy of the GNU Lesser General Public License
1276+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1277+ *
1278+ * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1279+ * James Henstridge <james.henstridge@canonical.com>
1280+*/
1281+
1282+#include "albumartgenerator.h"
1283+#include <stdexcept>
1284+#include <QDebug>
1285+#include <QFile>
1286+#include <QUrlQuery>
1287+#include <QDBusUnixFileDescriptor>
1288+#include <QDBusReply>
1289+
1290+static const char DEFAULT_ALBUM_ART[] = "/usr/share/unity/icons/album_missing.png";
1291+
1292+static const char BUS_NAME[] = "com.canonical.Thumbnailer";
1293+static const char BUS_PATH[] = "/com/canonical/Thumbnailer";
1294+static const char THUMBNAILER_IFACE[] = "com.canonical.Thumbnailer";
1295+static const char GET_ALBUM_ART[] = "GetAlbumArt";
1296+
1297+AlbumArtGenerator::AlbumArtGenerator()
1298+ : QQuickImageProvider(QQuickImageProvider::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading),
1299+ iface(BUS_NAME, BUS_PATH, THUMBNAILER_IFACE) {
1300+}
1301+
1302+static QImage fallbackImage(QSize *realSize) {
1303+ QImage fallback;
1304+ fallback.load(DEFAULT_ALBUM_ART);
1305+ *realSize = fallback.size();
1306+ return fallback;
1307+}
1308+
1309+QImage AlbumArtGenerator::requestImage(const QString &id, QSize *realSize,
1310+ const QSize &requestedSize) {
1311+ QUrlQuery query(id);
1312+ if (!query.hasQueryItem("artist") || !query.hasQueryItem("album")) {
1313+ qWarning() << "Invalid albumart uri:" << id;
1314+ return fallbackImage(realSize);
1315+ }
1316+
1317+ const QString artist = query.queryItemValue("artist", QUrl::FullyDecoded);
1318+ const QString album = query.queryItemValue("album", QUrl::FullyDecoded);
1319+
1320+ QString desiredSize = "original";
1321+ int size = requestedSize.width() > requestedSize.height() ? requestedSize.width() : requestedSize.height();
1322+ if (size < 128) {
1323+ desiredSize = "small";
1324+ } else if (size < 256) {
1325+ desiredSize = "large";
1326+ } else if (size < 512) {
1327+ desiredSize = "xlarge";
1328+ }
1329+
1330+ // perform dbus call
1331+ QDBusReply<QDBusUnixFileDescriptor> reply = iface.call(
1332+ GET_ALBUM_ART, artist, album, desiredSize);
1333+ if (!reply.isValid()) {
1334+ qWarning() << "D-Bus error: " << reply.error().message();
1335+ return fallbackImage(realSize);
1336+ }
1337+
1338+ try {
1339+ QFile file;
1340+ file.open(reply.value().fileDescriptor(), QIODevice::ReadOnly);
1341+ QImage image;
1342+ image.load(&file, NULL);
1343+ *realSize = image.size();
1344+ return image;
1345+ } catch (const std::exception &e) {
1346+ qDebug() << "Album art loader failed: " << e.what();
1347+ } catch (...) {
1348+ qDebug() << "Unknown error when generating image.";
1349+ }
1350+
1351+ return fallbackImage(realSize);
1352+}
1353
1354=== added file 'plugins/Ubuntu/Thumbnailer/albumartgenerator.h'
1355--- plugins/Ubuntu/Thumbnailer/albumartgenerator.h 1970-01-01 00:00:00 +0000
1356+++ plugins/Ubuntu/Thumbnailer/albumartgenerator.h 2015-02-04 08:57:20 +0000
1357@@ -0,0 +1,36 @@
1358+/*
1359+ * Copyright 2014 Canonical Ltd.
1360+ *
1361+ * This program is free software; you can redistribute it and/or modify
1362+ * it under the terms of the GNU Lesser General Public License as published by
1363+ * the Free Software Foundation; version 3.
1364+ *
1365+ * This program is distributed in the hope that it will be useful,
1366+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1367+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1368+ * GNU Lesser General Public License for more details.
1369+ *
1370+ * You should have received a copy of the GNU Lesser General Public License
1371+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1372+ *
1373+ * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1374+ * James Henstridge <james.henstridge@canonical.com>
1375+*/
1376+
1377+#ifndef ALBUMART_GENERATOR_H
1378+#define ALBUMART_GENERATOR_H
1379+
1380+#include <QDBusInterface>
1381+#include <QQuickImageProvider>
1382+
1383+class AlbumArtGenerator: public QQuickImageProvider
1384+{
1385+private:
1386+ QDBusInterface iface;
1387+
1388+public:
1389+ AlbumArtGenerator();
1390+ QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
1391+};
1392+
1393+#endif
1394
1395=== added file 'plugins/Ubuntu/Thumbnailer/plugin.cpp'
1396--- plugins/Ubuntu/Thumbnailer/plugin.cpp 1970-01-01 00:00:00 +0000
1397+++ plugins/Ubuntu/Thumbnailer/plugin.cpp 2015-02-04 08:57:20 +0000
1398@@ -0,0 +1,47 @@
1399+/*
1400+ * Copyright 2014 Canonical Ltd.
1401+ *
1402+ * This program is free software; you can redistribute it and/or modify
1403+ * it under the terms of the GNU Lesser General Public License as published by
1404+ * the Free Software Foundation; version 3.
1405+ *
1406+ * This program is distributed in the hope that it will be useful,
1407+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1408+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1409+ * GNU Lesser General Public License for more details.
1410+ *
1411+ * You should have received a copy of the GNU Lesser General Public License
1412+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1413+ *
1414+ * Authors: James Henstridge <james.henstridge@canonical.com>
1415+*/
1416+
1417+#include "plugin.h"
1418+#include "albumartgenerator.h"
1419+#include "thumbnailgenerator.h"
1420+
1421+void ThumbnailerPlugin::registerTypes(const char *uri) {
1422+ qmlRegisterTypeNotAvailable(
1423+ uri, 0, 1, "__ThumbnailerIgnoreMe",
1424+ "Ignore this: QML plugins must contain at least one type");
1425+}
1426+
1427+void ThumbnailerPlugin::initializeEngine(QQmlEngine *engine, const char *uri) {
1428+ QQmlExtensionPlugin::initializeEngine(engine, uri);
1429+
1430+ try {
1431+ engine->addImageProvider("albumart", new AlbumArtGenerator());
1432+ } catch (const std::exception &e) {
1433+ qWarning() << "Failed to register albumart image provider:" << e.what();
1434+ } catch (...) {
1435+ qWarning() << "Failed to register albumart image provider.";
1436+ }
1437+
1438+ try {
1439+ engine->addImageProvider("thumbnailer", new ThumbnailGenerator());
1440+ } catch (const std::exception &e) {
1441+ qWarning() << "Failed to register thumbnailer image provider:" << e.what();
1442+ } catch (...) {
1443+ qWarning() << "Failed to register thumbnailer image provider.";
1444+ }
1445+}
1446
1447=== added file 'plugins/Ubuntu/Thumbnailer/plugin.h'
1448--- plugins/Ubuntu/Thumbnailer/plugin.h 1970-01-01 00:00:00 +0000
1449+++ plugins/Ubuntu/Thumbnailer/plugin.h 2015-02-04 08:57:20 +0000
1450@@ -0,0 +1,34 @@
1451+/*
1452+ * Copyright 2014 Canonical Ltd.
1453+ *
1454+ * This program is free software; you can redistribute it and/or modify
1455+ * it under the terms of the GNU Lesser General Public License as published by
1456+ * the Free Software Foundation; version 3.
1457+ *
1458+ * This program is distributed in the hope that it will be useful,
1459+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1460+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1461+ * GNU Lesser General Public License for more details.
1462+ *
1463+ * You should have received a copy of the GNU Lesser General Public License
1464+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1465+ *
1466+ * Authors: James Henstridge <james.henstridge@canonical.com>
1467+*/
1468+
1469+#ifndef THUMBNAILER_PLUGIN_H
1470+#define THUMBNAILER_PLUGIN_H
1471+
1472+#include <QtQml>
1473+
1474+class ThumbnailerPlugin : public QQmlExtensionPlugin
1475+{
1476+ Q_OBJECT
1477+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
1478+
1479+public:
1480+ virtual void registerTypes(const char *uri) override;
1481+ virtual void initializeEngine(QQmlEngine *engine, const char *uri) override;
1482+};
1483+
1484+#endif
1485
1486=== added file 'plugins/Ubuntu/Thumbnailer/qmldir'
1487--- plugins/Ubuntu/Thumbnailer/qmldir 1970-01-01 00:00:00 +0000
1488+++ plugins/Ubuntu/Thumbnailer/qmldir 2015-02-04 08:57:20 +0000
1489@@ -0,0 +1,2 @@
1490+module Ubuntu.Thumbnailer
1491+plugin thumbnailer-qml
1492
1493=== added file 'plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp'
1494--- plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp 1970-01-01 00:00:00 +0000
1495+++ plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp 2015-02-04 08:57:20 +0000
1496@@ -0,0 +1,87 @@
1497+/*
1498+ * Copyright 2013 Canonical Ltd.
1499+ *
1500+ * This program is free software; you can redistribute it and/or modify
1501+ * it under the terms of the GNU Lesser General Public License as published by
1502+ * the Free Software Foundation; version 3.
1503+ *
1504+ * This program is distributed in the hope that it will be useful,
1505+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1506+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1507+ * GNU Lesser General Public License for more details.
1508+ *
1509+ * You should have received a copy of the GNU Lesser General Public License
1510+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1511+ *
1512+ * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1513+*/
1514+
1515+#include "thumbnailgenerator.h"
1516+#include <stdexcept>
1517+#include <QDebug>
1518+#include <QMimeDatabase>
1519+#include <QUrl>
1520+
1521+static const char *DEFAULT_VIDEO_ART = "/usr/share/unity/icons/video_missing.png";
1522+static const char *DEFAULT_ALBUM_ART = "/usr/share/unity/icons/album_missing.png";
1523+
1524+ThumbnailGenerator::ThumbnailGenerator() : QQuickImageProvider(QQuickImageProvider::Image,
1525+ QQmlImageProviderBase::ForceAsynchronousImageLoading) {
1526+
1527+}
1528+
1529+QImage ThumbnailGenerator::requestImage(const QString &id, QSize *realSize,
1530+ const QSize &requestedSize) {
1531+ /* Allow appending a query string (e.g. ?something=timestamp)
1532+ * to the id and then ignore it.
1533+ * This is workaround to force reloading a thumbnail when it has
1534+ * the same file name on disk but we know the content has changed.
1535+ * It is necessary because in such a situation the QML image cache
1536+ * will kick in and this ImageProvider will never get called.
1537+ * The only "solution" is setting Image.cache = false, but in some
1538+ * cases we don't want to do that for performance reasons, so this
1539+ * is the only way around the issue for now. */
1540+ std::string src_path(QUrl(id).path().toUtf8().data());
1541+ std::string tgt_path;
1542+ try {
1543+ ThumbnailSize desiredSize;
1544+ const int xlarge_cutoff = 512;
1545+ const int large_cutoff = 256;
1546+ const int small_cutoff = 128;
1547+ if(requestedSize.width() > xlarge_cutoff || requestedSize.height() > xlarge_cutoff) {
1548+ desiredSize = TN_SIZE_ORIGINAL;
1549+ } if(requestedSize.width() > large_cutoff || requestedSize.height() > large_cutoff) {
1550+ desiredSize = TN_SIZE_XLARGE;
1551+ } else if(requestedSize.width() > small_cutoff || requestedSize.height() > small_cutoff) {
1552+ desiredSize = TN_SIZE_LARGE;
1553+ } else {
1554+ desiredSize = TN_SIZE_SMALL;
1555+ }
1556+ tgt_path = tn.get_thumbnail(src_path, desiredSize);
1557+ if(!tgt_path.empty()) {
1558+ QString tgt(tgt_path.c_str());
1559+ QImage image;
1560+ image.load(tgt);
1561+ *realSize = image.size();
1562+ return image;
1563+ }
1564+ } catch(std::runtime_error &e) {
1565+ qDebug() << "Thumbnail generator failed: " << e.what();
1566+ }
1567+ return getFallbackImage(id, realSize, requestedSize);
1568+}
1569+
1570+QImage ThumbnailGenerator::getFallbackImage(const QString &id, QSize *size,
1571+ const QSize &requestedSize) {
1572+ Q_UNUSED(requestedSize);
1573+ QMimeDatabase db;
1574+ QMimeType mime = db.mimeTypeForFile(id);
1575+ QImage result;
1576+ if(mime.name().contains("audio")) {
1577+ result.load(DEFAULT_ALBUM_ART);
1578+ } else if(mime.name().contains("video")) {
1579+ result.load(DEFAULT_VIDEO_ART);
1580+ }
1581+ *size = result.size();
1582+ return result;
1583+}
1584
1585=== added file 'plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h'
1586--- plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h 1970-01-01 00:00:00 +0000
1587+++ plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h 2015-02-04 08:57:20 +0000
1588@@ -0,0 +1,36 @@
1589+/*
1590+ * Copyright 2013 Canonical Ltd.
1591+ *
1592+ * This program is free software; you can redistribute it and/or modify
1593+ * it under the terms of the GNU Lesser General Public License as published by
1594+ * the Free Software Foundation; version 3.
1595+ *
1596+ * This program is distributed in the hope that it will be useful,
1597+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1598+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1599+ * GNU Lesser General Public License for more details.
1600+ *
1601+ * You should have received a copy of the GNU Lesser General Public License
1602+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1603+ *
1604+ * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1605+*/
1606+
1607+#ifndef THUMBNAIL_GENERATOR_H
1608+#define THUMBNAIL_GENERATOR_H
1609+
1610+#include <QQuickImageProvider>
1611+#include <thumbnailer.h>
1612+
1613+class ThumbnailGenerator: public QQuickImageProvider
1614+{
1615+private:
1616+ Thumbnailer tn;
1617+
1618+public:
1619+ ThumbnailGenerator();
1620+ QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
1621+ QImage getFallbackImage(const QString &id, QSize *size, const QSize &requestedSize);
1622+};
1623+
1624+#endif
1625
1626=== added directory 'src'
1627=== renamed directory 'src' => 'src.moved'
1628=== added file 'src/CMakeLists.txt'
1629--- src/CMakeLists.txt 1970-01-01 00:00:00 +0000
1630+++ src/CMakeLists.txt 2015-02-04 08:57:20 +0000
1631@@ -0,0 +1,41 @@
1632+add_library(thumbnailer SHARED
1633+#audioimageextractor.cpp
1634+imagescaler.cpp
1635+lastfmdownloader.cpp
1636+mediaartcache.cpp
1637+soupdownloader.cpp
1638+thumbnailcache.cpp
1639+thumbnailer.cpp
1640+videoscreenshotter.cpp
1641+)
1642+
1643+set(symbol_map "${CMAKE_CURRENT_SOURCE_DIR}/libthumbnailer.map")
1644+
1645+target_link_libraries(thumbnailer #${GST_DEPS_LDFLAGS}
1646+ ${GLIB_DEPS_LDFLAGS}
1647+ ${GIO_DEPS_LDFLAGS}
1648+ ${IMG_DEPS_LDFLAGS}
1649+ ${XML_DEPS_LDFLAGS}
1650+ ${SOUP_DEPS_LDFLAGS})
1651+set_target_properties(thumbnailer PROPERTIES VERSION ${SO_VERSION} SOVERSION ${ABI_VERSION})
1652+set_target_properties(thumbnailer PROPERTIES
1653+ LINK_FLAGS "${ldflags} -Wl,--version-script,${symbol_map}")
1654+set_target_properties(thumbnailer PROPERTIES LINK_DEPENDS ${symbol_map})
1655+
1656+install(
1657+ TARGETS thumbnailer
1658+ ARCHIVE DESTINATION ${LIBDIR}
1659+ RUNTIME DESTINATION bin
1660+ LIBRARY DESTINATION ${LIBDIR}
1661+)
1662+
1663+add_executable(vs-thumb vs-thumb.cpp)
1664+target_link_libraries(vs-thumb ${GST_DEPS_LDFLAGS} ${IMG_DEPS_LDFLAGS})
1665+install(
1666+ TARGETS vs-thumb
1667+ ARCHIVE DESTINATION ${SHARE_PRIV_DIR}
1668+ RUNTIME DESTINATION ${SHARE_PRIV_DIR}
1669+ LIBRARY DESTINATION ${SHARE_PRIV_DIR}
1670+)
1671+
1672+add_subdirectory(service)
1673
1674=== added file 'src/audioimageextractor.cpp'
1675--- src/audioimageextractor.cpp 1970-01-01 00:00:00 +0000
1676+++ src/audioimageextractor.cpp 2015-02-04 08:57:20 +0000
1677@@ -0,0 +1,100 @@
1678+/*
1679+ * Copyright (C) 2013 Canonical Ltd.
1680+ *
1681+ * This program is free software: you can redistribute it and/or modify
1682+ * it under the terms of the GNU Lesser General Public License version 3 as
1683+ * published by the Free Software Foundation.
1684+ *
1685+ * This program is distributed in the hope that it will be useful,
1686+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1687+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1688+ * GNU Lesser General Public License for more details.
1689+ *
1690+ * You should have received a copy of the GNU Lesser General Public License
1691+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1692+ *
1693+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1694+ */
1695+
1696+#include<cstdio>
1697+#include<internal/audioimageextractor.h>
1698+#include<unistd.h>
1699+#include<stdexcept>
1700+#include<memory>
1701+#include <gst/pbutils/pbutils.h>
1702+
1703+using namespace std;
1704+
1705+class GstInitializer {
1706+public:
1707+ GstInitializer() { gst_init(nullptr, nullptr); };
1708+};
1709+
1710+class AudioImageExtractorPrivate {
1711+};
1712+
1713+static bool has_tag(const GstTagList *tlist, const gchar *tagname) {
1714+ const GValue *val = gst_tag_list_get_value_index(tlist, tagname, 0);
1715+ return val;
1716+}
1717+
1718+static void extract_image(const GstTagList *tlist, FILE *outf) {
1719+ const GValue *val = gst_tag_list_get_value_index(tlist, GST_TAG_IMAGE, 0);
1720+ GstSample *sample = (GstSample*)g_value_get_boxed(val);
1721+ GstBuffer *buf = gst_sample_get_buffer(sample);
1722+
1723+ for(guint i=0; i<gst_buffer_n_memory(buf); i++) {
1724+ GstMemory *mem = gst_buffer_peek_memory(buf, i);
1725+ GstMapInfo mi;
1726+ gst_memory_map(mem, &mi, GST_MAP_READ);
1727+ fwrite(mi.data, 1, mi.size, outf);
1728+ gst_memory_unmap(mem, &mi);
1729+ }
1730+}
1731+
1732+AudioImageExtractor::AudioImageExtractor() {
1733+ static GstInitializer i; // C++ standard guarantees this to be lazy and thread safe.
1734+ p = new AudioImageExtractorPrivate();
1735+}
1736+
1737+AudioImageExtractor::~AudioImageExtractor() {
1738+ delete p;
1739+}
1740+
1741+
1742+bool AudioImageExtractor::extract(const string &ifname, const string &ofname) {
1743+ string uri("file://");
1744+ if(ifname[0] != '/') {
1745+ uri += getcwd(nullptr, 0);
1746+ uri += '/';
1747+ }
1748+ uri += ifname;
1749+ GError *err = nullptr;
1750+ unique_ptr<GstDiscoverer, void(*)(GstDiscoverer*)> dsc(
1751+ gst_discoverer_new(GST_SECOND, &err),
1752+ [](GstDiscoverer *t) {g_object_unref(G_OBJECT(t));});
1753+ if(err) {
1754+ string msg(err->message);
1755+ g_error_free(err);
1756+ throw runtime_error(msg);
1757+ }
1758+ unique_ptr<GstDiscovererInfo, void(*)(GstDiscovererInfo*)> info(
1759+ gst_discoverer_discover_uri(dsc.get(), uri.c_str(), &err),
1760+ [](GstDiscovererInfo *t) {g_object_unref(G_OBJECT(t));});
1761+ if(err) {
1762+ string msg(err->message);
1763+ g_error_free(err);
1764+ throw runtime_error(msg);
1765+ }
1766+ const GstTagList *tlist = gst_discoverer_info_get_tags(info.get());
1767+ if(!tlist) {
1768+ return false;
1769+ }
1770+ if(!has_tag(tlist, GST_TAG_IMAGE)) {
1771+ return false;
1772+ }
1773+ FILE *outfile = fopen(ofname.c_str(), "wb");
1774+ extract_image(tlist, outfile);
1775+ fclose(outfile);
1776+ return true;
1777+}
1778
1779=== added file 'src/imagescaler.cpp'
1780--- src/imagescaler.cpp 1970-01-01 00:00:00 +0000
1781+++ src/imagescaler.cpp 2015-02-04 08:57:20 +0000
1782@@ -0,0 +1,162 @@
1783+/*
1784+ * Copyright (C) 2013 Canonical Ltd.
1785+ *
1786+ * This program is free software: you can redistribute it and/or modify
1787+ * it under the terms of the GNU Lesser General Public License version 3 as
1788+ * published by the Free Software Foundation.
1789+ *
1790+ * This program is distributed in the hope that it will be useful,
1791+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1792+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1793+ * GNU Lesser General Public License for more details.
1794+ *
1795+ * You should have received a copy of the GNU Lesser General Public License
1796+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1797+ *
1798+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1799+ */
1800+
1801+#include<internal/imagescaler.h>
1802+#include<internal/gobj_memory.h>
1803+#include<gdk-pixbuf/gdk-pixbuf.h>
1804+#include<libexif/exif-loader.h>
1805+#include<memory>
1806+#include<stdexcept>
1807+#include<sys/stat.h>
1808+#include<cassert>
1809+#include<random>
1810+#include<cstring>
1811+
1812+using namespace std;
1813+
1814+static void determine_new_size(const int w, const int h, int &neww, int &newh,
1815+ const ThumbnailSize wanted) {
1816+ if(wanted == TN_SIZE_ORIGINAL) {
1817+ neww = w;
1818+ newh = h;
1819+ } else {
1820+ int max_dim = ((wanted == TN_SIZE_SMALL) ? 128 : ((wanted == TN_SIZE_LARGE) ? 256 : 512));
1821+ if(w > h) {
1822+ neww = max_dim;
1823+ newh = ((double)(max_dim))*h/w;
1824+ if (newh == 0)
1825+ newh = 1;
1826+ } else {
1827+ newh = max_dim;
1828+ neww = ((double)(max_dim))*w/h;
1829+ if(neww == 0)
1830+ neww = 1;
1831+ }
1832+ }
1833+}
1834+
1835+static GdkPixbuf* fix_orientation(const char *infile, GdkPixbuf *src) {
1836+ ExifLoader *l;
1837+ l = exif_loader_new();
1838+ ExifData *ed;
1839+ exif_loader_write_file(l, infile);
1840+ ed = exif_loader_get_data(l);
1841+ exif_loader_unref(l);
1842+ GdkPixbuf *rot = nullptr;
1843+ // Have to do this manually because of
1844+ // https://bugzilla.gnome.org/show_bug.cgi?id=725582
1845+ if(ed) {
1846+ ExifEntry *e = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION);
1847+ if(e) {
1848+ int orientation = exif_get_short(e->data, exif_data_get_byte_order(ed));
1849+ if(orientation == 6) {
1850+ rot = gdk_pixbuf_rotate_simple(src, GDK_PIXBUF_ROTATE_CLOCKWISE);
1851+ } else if (orientation == 8) {
1852+ rot = gdk_pixbuf_rotate_simple(src, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
1853+ } else if (orientation == 3) {
1854+ rot = gdk_pixbuf_rotate_simple(src, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
1855+ } else {
1856+ // We don't do mirrored images, at least not yet.
1857+ }
1858+ }
1859+ }
1860+ if(!rot) {
1861+ // This entire function should only contain this call, really.
1862+ rot = gdk_pixbuf_apply_embedded_orientation(src);
1863+ }
1864+ exif_data_unref(ed);
1865+ return rot;
1866+}
1867+
1868+class ImageScalerPrivate {
1869+};
1870+
1871+ImageScaler::ImageScaler() {
1872+ p = new ImageScalerPrivate();
1873+}
1874+
1875+ImageScaler::~ImageScaler() {
1876+ delete p;
1877+}
1878+
1879+bool ImageScaler::scale(const std::string &ifilename, const std::string &ofilename, ThumbnailSize wanted,
1880+ const std::string &original_location) const {
1881+ random_device rnd;
1882+ assert(ifilename[0] == '/');
1883+ assert(ofilename[0] == '/');
1884+ GError *err = nullptr;
1885+ string ofilename_tmp = ofilename;
1886+ ofilename_tmp += ".tmp." + to_string(rnd());
1887+ unique_gobj<GdkPixbuf> orig(gdk_pixbuf_new_from_file(ifilename.c_str(), &err));
1888+ if(err) {
1889+ string msg = err->message;
1890+ g_error_free(err);
1891+ throw runtime_error(msg);
1892+ }
1893+ unique_gobj<GdkPixbuf> src(fix_orientation(ifilename.c_str(), orig.get()));
1894+ if(!src) {
1895+ throw runtime_error("Unknown error reorienting image.");
1896+ }
1897+ const int w = gdk_pixbuf_get_width(src.get());
1898+ const int h = gdk_pixbuf_get_height(src.get());
1899+ if(w == 0 || h == 0) {
1900+ throw runtime_error("Invalid image resolution.");
1901+ }
1902+
1903+ int neww, newh;
1904+ determine_new_size(w, h, neww, newh, wanted);
1905+ unique_gobj<GdkPixbuf> dst(gdk_pixbuf_scale_simple(src.get(), neww, newh, GDK_INTERP_BILINEAR));
1906+ gboolean save_ok;
1907+ if(original_location.empty()) {
1908+ save_ok = gdk_pixbuf_save(dst.get(), ofilename_tmp.c_str(), "png", &err, NULL);
1909+ } else {
1910+ assert(original_location[0] == '/');
1911+ time_t mtime;
1912+ string uri = "file://" + original_location;
1913+ struct stat sbuf;
1914+ if(stat(original_location.c_str(), &sbuf) != 0) {
1915+ mtime = 0;
1916+ } else {
1917+ mtime = sbuf.st_mtim.tv_sec;
1918+ }
1919+ string mtime_str = to_string(mtime);
1920+ save_ok = gdk_pixbuf_save(dst.get(), ofilename_tmp.c_str(), "png", &err,
1921+ "tEXt::Thumb::URI", uri.c_str(), "tEXt::Thumb::MTime", mtime_str.c_str(), NULL);
1922+ if(!save_ok) {
1923+ // Sigh. PNG text chunks are encoded in ISO-8859-1 but this is impossible if
1924+ // the file name contains e.g. Chinese characters. Fall back to writing the
1925+ // thumbnail without metadata. This does not conform to the thumbnailing standard
1926+ // but at least it will give us a working thumbnail.
1927+ g_error_free(err);
1928+ err = nullptr;
1929+ save_ok = gdk_pixbuf_save(dst.get(), ofilename_tmp.c_str(), "png", &err, NULL);
1930+ }
1931+ }
1932+ if(!save_ok) {
1933+ string msg = err->message;
1934+ g_error_free(err);
1935+ throw runtime_error(msg);
1936+ }
1937+ if(rename(ofilename_tmp.c_str(), ofilename.c_str()) <0) {
1938+ string msg("Could not rename temp file to actual file: ");
1939+ msg += strerror(errno);
1940+ unlink(ofilename_tmp.c_str()); // Nothing we can do if it fails.
1941+ throw runtime_error(msg);
1942+ }
1943+ return true;
1944+}
1945
1946=== added file 'src/lastfmdownloader.cpp'
1947--- src/lastfmdownloader.cpp 1970-01-01 00:00:00 +0000
1948+++ src/lastfmdownloader.cpp 2015-02-04 08:57:20 +0000
1949@@ -0,0 +1,87 @@
1950+/*
1951+ * Copyright (C) 2014 Canonical Ltd.
1952+ *
1953+ * This program is free software: you can redistribute it and/or modify
1954+ * it under the terms of the GNU Lesser General Public License version 3 as
1955+ * published by the Free Software Foundation.
1956+ *
1957+ * This program is distributed in the hope that it will be useful,
1958+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1959+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1960+ * GNU Lesser General Public License for more details.
1961+ *
1962+ * You should have received a copy of the GNU Lesser General Public License
1963+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1964+ *
1965+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
1966+ */
1967+
1968+#include<internal/lastfmdownloader.h>
1969+#include<internal/soupdownloader.h>
1970+#include<internal/gobj_memory.h>
1971+#include<memory>
1972+#include <libxml/parser.h>
1973+#include <libxml/xmlmemory.h>
1974+#include <libxml/xpath.h>
1975+
1976+const char *NOTFOUND_IMAGE = "http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png";
1977+
1978+using namespace std;
1979+
1980+LastFMDownloader::LastFMDownloader() : dl(new SoupDownloader()){
1981+}
1982+
1983+LastFMDownloader::LastFMDownloader(HttpDownloader *o) : dl(o) {
1984+}
1985+
1986+LastFMDownloader::~LastFMDownloader() {
1987+}
1988+
1989+string LastFMDownloader::parseXML(const string &xml) {
1990+ string node = "/album/coverart/large";
1991+ unique_ptr<xmlDoc, void(*)(xmlDoc*)> doc(
1992+ xmlReadMemory(xml.c_str(), xmlStrlen ((xmlChar*) xml.c_str()), NULL, NULL,
1993+ XML_PARSE_RECOVER | XML_PARSE_NOBLANKS), xmlFreeDoc);
1994+ if (!doc) {
1995+ return "";
1996+ }
1997+ unique_ptr<xmlXPathContext, void(*)(xmlXPathContext*)> cntx(
1998+ xmlXPathNewContext(doc.get()), xmlXPathFreeContext);
1999+
2000+ unique_ptr<xmlXPathObject, void(*)(xmlXPathObject *)> path(
2001+ xmlXPathEvalExpression((xmlChar *) node.c_str(), cntx.get()),
2002+ xmlXPathFreeObject);
2003+ if (!path) {
2004+ return "";
2005+ }
2006+
2007+ char *imageurl;
2008+ if (path->nodesetval->nodeTab) {
2009+ imageurl = (char *) xmlNodeListGetString(doc.get(),
2010+ path->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
2011+ }
2012+ string url(imageurl);
2013+ xmlFree(imageurl);
2014+ return url;
2015+}
2016+
2017+bool LastFMDownloader::download(const std::string &artist,
2018+ const std::string &album, const std::string &fname) {
2019+ const char *lastfmTemplate = "http://ws.audioscrobbler.com/1.0/album/%s/%s/info.xml";
2020+ const int bufsize = 1024;
2021+ char buf[bufsize];
2022+ snprintf(buf, bufsize, lastfmTemplate, artist.c_str(), album.c_str());
2023+ string xml(dl->download(buf));
2024+ string parsed = parseXML(xml);
2025+ if(parsed.empty() ||
2026+ parsed == NOTFOUND_IMAGE) {
2027+ fprintf(stderr, "Could not find album art.\n");
2028+ return false;
2029+ }
2030+
2031+ string image(dl->download(parsed));
2032+ FILE *f = fopen(fname.c_str(), "w");
2033+ fwrite(image.c_str(), 1, image.length(), f);
2034+ fclose(f);
2035+ return true;
2036+}
2037
2038=== added file 'src/libthumbnailer.map'
2039--- src/libthumbnailer.map 1970-01-01 00:00:00 +0000
2040+++ src/libthumbnailer.map 2015-02-04 08:57:20 +0000
2041@@ -0,0 +1,14 @@
2042+{
2043+global:
2044+ extern "C++" {
2045+ "Thumbnailer::Thumbnailer()";
2046+ "Thumbnailer::~Thumbnailer()";
2047+ "Thumbnailer::get_thumbnail(std::string const&, ThumbnailSize)";
2048+ "Thumbnailer::get_thumbnail(std::string const&, ThumbnailSize, ThumbnailPolicy)";
2049+ "Thumbnailer::get_album_art(std::string const&, std::string const&, ThumbnailSize, ThumbnailPolicy)";
2050+ };
2051+local:
2052+ extern "C++" {
2053+ *;
2054+ };
2055+};
2056
2057=== added file 'src/mediaartcache.cpp'
2058--- src/mediaartcache.cpp 1970-01-01 00:00:00 +0000
2059+++ src/mediaartcache.cpp 2015-02-04 08:57:20 +0000
2060@@ -0,0 +1,201 @@
2061+/*
2062+ * Copyright (C) 2012-2014 Canonical Ltd.
2063+ *
2064+ * This program is free software: you can redistribute it and/or modify
2065+ * it under the terms of the GNU Lesser General Public License version 3 as
2066+ * published by the Free Software Foundation.
2067+ *
2068+ * This program is distributed in the hope that it will be useful,
2069+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2070+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2071+ * GNU Lesser General Public License for more details.
2072+ *
2073+ * You should have received a copy of the GNU Lesser General Public License
2074+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2075+ *
2076+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
2077+ */
2078+
2079+#include<internal/mediaartcache.h>
2080+
2081+#include<dirent.h>
2082+#include<sys/stat.h>
2083+#include<fcntl.h>
2084+#include<unistd.h>
2085+#include<errno.h>
2086+#include<stdio.h>
2087+#include<string.h>
2088+#include<stdlib.h>
2089+#include<assert.h>
2090+#include<utime.h>
2091+
2092+#include<glib.h>
2093+
2094+#include<vector>
2095+#include<algorithm>
2096+#include<stdexcept>
2097+
2098+using namespace std;
2099+
2100+static string md5(const string &str) {
2101+ const unsigned char *buf = (const unsigned char *)str.c_str();
2102+ char *normalized = g_utf8_normalize((const gchar*)buf, str.size(), G_NORMALIZE_ALL);
2103+ string final;
2104+ gchar *result;
2105+
2106+ if(normalized) {
2107+ buf = (const unsigned char*)normalized;
2108+ }
2109+
2110+ result = g_compute_checksum_for_data(G_CHECKSUM_MD5, buf, strlen((const char*)buf));
2111+ final = result;
2112+ g_free((gpointer)normalized);
2113+ g_free(result);
2114+ return final;
2115+}
2116+
2117+MediaArtCache::MediaArtCache() {
2118+ string xdg_base = g_get_user_cache_dir();
2119+
2120+ if (xdg_base == "") {
2121+ string s("Could not determine cache dir.");
2122+ throw runtime_error(s);
2123+ }
2124+ int ec = mkdir(xdg_base.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
2125+ if (ec < 0 && errno != EEXIST) {
2126+ string s("Could not create base dir.");
2127+ throw runtime_error(s);
2128+ }
2129+ root_dir = xdg_base + "/media-art";
2130+ ec = mkdir(root_dir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
2131+ if (ec < 0 && errno != EEXIST) {
2132+ string s("Could not create cache dir.");
2133+ throw runtime_error(s);
2134+ }
2135+}
2136+
2137+bool MediaArtCache::has_art(const std::string &artist, const std::string &album) const {
2138+ string fname = get_art_file(artist, album);
2139+ return access(fname.c_str(), R_OK) == 0;
2140+}
2141+
2142+void MediaArtCache::add_art(const std::string &artist, const std::string &album,
2143+ const char *data, unsigned int datalen) {
2144+ string abs_fname = get_full_filename(artist, album);
2145+ GError *err = nullptr;
2146+ if(!g_file_set_contents(abs_fname.c_str(), data, datalen, &err)) {
2147+ string e("Could not write file ");
2148+ e += abs_fname;
2149+ e += ": ";
2150+ e += err->message;
2151+ g_error_free(err);
2152+ throw runtime_error(e);
2153+ }
2154+}
2155+
2156+string MediaArtCache::get_art_file(const std::string &artist, const std::string &album) const {
2157+ string abs_fname = get_full_filename(artist, album);
2158+
2159+ if (access(abs_fname.c_str(), R_OK) == 0) {
2160+ utime(abs_fname.c_str(), nullptr); // update access times to current time
2161+ return abs_fname;
2162+ }
2163+ return "";
2164+}
2165+
2166+string MediaArtCache::get_art_uri(const string &artist, const string &album) const
2167+{
2168+ std::string filename = get_art_file(artist, album);
2169+
2170+ if (filename == "") {
2171+ return "";
2172+ }
2173+
2174+ GError *err = nullptr;
2175+ char *c_uri = g_filename_to_uri(filename.c_str(), "", &err);
2176+ if (!c_uri) {
2177+ string e("Could not convert file name ");
2178+ e += filename;
2179+ e += " to URI: ";
2180+ e += err->message;
2181+ g_error_free(err);
2182+ throw runtime_error(e);
2183+ }
2184+
2185+ std::string uri = c_uri;
2186+ g_free(c_uri);
2187+ return uri;
2188+}
2189+
2190+std::string MediaArtCache::get_full_filename(const std::string &artist, const std::string & album) const {
2191+ return root_dir + "/" + compute_base_name(artist, album);
2192+}
2193+
2194+
2195+std::string MediaArtCache::compute_base_name(const std::string &artist, const std::string &album) const {
2196+ string type = "album";
2197+ string h1 = md5(artist);
2198+ string h2 = md5(album);
2199+ return type + "-" + h1 + "-" + h2 + ".jpg";
2200+}
2201+
2202+
2203+void MediaArtCache::clear() const {
2204+ DIR *d = opendir(root_dir.c_str());
2205+ if(!d) {
2206+ string s = "Something went wrong.";
2207+ throw runtime_error(s);
2208+ }
2209+ struct dirent *entry, *de;
2210+ entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX + 1);
2211+ while(readdir_r(d, entry, &de) == 0 && de) {
2212+ string basename = entry->d_name;
2213+ if (basename == "." || basename == "..")
2214+ continue;
2215+ string fname = root_dir + "/" + basename;
2216+ if(remove(fname.c_str()) < 0) {
2217+ // This is not really an error worth
2218+ // halting everything for.
2219+ fprintf(stderr, "Could not delete file %s: %s.\n", fname.c_str(),
2220+ strerror(errno));
2221+ }
2222+ }
2223+ free(entry);
2224+ closedir(d);
2225+}
2226+
2227+void MediaArtCache::prune() {
2228+ vector<pair<double, string>> mtimes;
2229+ DIR *d = opendir(root_dir.c_str());
2230+ if(!d) {
2231+ string s = "Something went wrong.";
2232+ throw runtime_error(s);
2233+ }
2234+ struct dirent *entry, *de;
2235+ entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX + 1);
2236+ while(readdir_r(d, entry, &de) == 0 && de) {
2237+ string basename = entry->d_name;
2238+ if (basename == "." || basename == "..")
2239+ continue;
2240+ string fname = root_dir + "/" + basename;
2241+ struct stat sbuf;
2242+ if(stat(fname.c_str(), &sbuf) != 0) {
2243+ continue;
2244+ }
2245+ // Use mtime because atime is not guaranteed to work if, for example
2246+ // the filesystem is mounted with noatime or relatime.
2247+ mtimes.push_back(make_pair(sbuf.st_mtim.tv_sec + sbuf.st_mtim.tv_nsec/1000000000.0, fname));
2248+ }
2249+ free(entry);
2250+ closedir(d);
2251+ if (mtimes.size() <= MAX_SIZE)
2252+ return;
2253+ sort(mtimes.begin(), mtimes.end());
2254+ for(size_t i=0; i < mtimes.size()-MAX_SIZE; i++) {
2255+ if(remove(mtimes[i].second.c_str()) < 0) {
2256+ fprintf(stderr, "Could not remove file %s: %s.\n",
2257+ mtimes[i].second.c_str(), strerror(errno));
2258+ }
2259+ }
2260+}
2261+
2262
2263=== added directory 'src/service'
2264=== added file 'src/service/CMakeLists.txt'
2265--- src/service/CMakeLists.txt 1970-01-01 00:00:00 +0000
2266+++ src/service/CMakeLists.txt 2015-02-04 08:57:20 +0000
2267@@ -0,0 +1,34 @@
2268+add_definitions(${THUMBNAILER_CFLAGS})
2269+include_directories(${CMAKE_CURRENT_BINARY_DIR})
2270+
2271+add_executable(thumbnailer-service
2272+ main.cpp
2273+ dbusinterface.cpp
2274+ dbus-generated.c
2275+)
2276+
2277+target_link_libraries(thumbnailer-service thumbnailer)
2278+
2279+install(
2280+ TARGETS thumbnailer-service
2281+ RUNTIME DESTINATION ${SHARE_PRIV_DIR}
2282+)
2283+
2284+find_program(gdbus_codegen gdbus-codegen)
2285+if(NOT gdbus_codegen)
2286+ msg(FATAL_ERROR "Could not locate gdbus-codegen")
2287+endif()
2288+
2289+add_custom_command(
2290+ OUTPUT dbus-generated.c dbus-generated.h
2291+ COMMAND ${gdbus_codegen} --interface-prefix=com.canonical. --generate-c-code dbus-generated --c-namespace TN ${CMAKE_CURRENT_SOURCE_DIR}/dbus-interface.xml
2292+ MAIN_DEPENDENCY dbus-interface.xml
2293+)
2294+
2295+# Install the service file.
2296+configure_file(com.canonical.Thumbnailer.service.in com.canonical.Thumbnailer.service)
2297+
2298+install(
2299+ FILES ${CMAKE_CURRENT_BINARY_DIR}/com.canonical.Thumbnailer.service
2300+ DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services
2301+)
2302
2303=== added file 'src/service/com.canonical.Thumbnailer.service.in'
2304--- src/service/com.canonical.Thumbnailer.service.in 1970-01-01 00:00:00 +0000
2305+++ src/service/com.canonical.Thumbnailer.service.in 2015-02-04 08:57:20 +0000
2306@@ -0,0 +1,4 @@
2307+[D-BUS Service]
2308+Name=com.canonical.Thumbnailer
2309+Exec=@SHARE_PRIV_ABS@/thumbnailer-service
2310+
2311
2312=== added file 'src/service/dbus-interface.xml'
2313--- src/service/dbus-interface.xml 1970-01-01 00:00:00 +0000
2314+++ src/service/dbus-interface.xml 2015-02-04 08:57:20 +0000
2315@@ -0,0 +1,17 @@
2316+<node>
2317+ <interface name="com.canonical.Thumbnailer">
2318+ <method name="GetAlbumArt">
2319+ <arg direction="in" type="s" name="artist" />
2320+ <arg direction="in" type="s" name="album" />
2321+ <!-- possible values are "small", "large", "xlarge" and "original" -->
2322+ <arg direction="in" type="s" name="desiredSize" />
2323+ <arg direction="out" type="h" name="fd" />
2324+ <annotation name="org.gtk.GDBus.C.UnixFD" value="true" />
2325+ </method>
2326+
2327+ <!-- Note: if adding additional thumbnailing methods that take a
2328+ file name as input, ensure that the calling process has
2329+ permission to read said file. Otherwise we will leak
2330+ information to confined applications. -->
2331+ </interface>
2332+</node>
2333
2334=== added file 'src/service/dbusinterface.cpp'
2335--- src/service/dbusinterface.cpp 1970-01-01 00:00:00 +0000
2336+++ src/service/dbusinterface.cpp 2015-02-04 08:57:20 +0000
2337@@ -0,0 +1,168 @@
2338+/*
2339+ * Copyright (C) 2014 Canonical, Ltd.
2340+ *
2341+ * Authors:
2342+ * James Henstridge <james.henstridge@canonical.com>
2343+ *
2344+ * This library is free software; you can redistribute it and/or modify it under
2345+ * the terms of version 3 of the GNU General Public License as published
2346+ * by the Free Software Foundation.
2347+ *
2348+ * This library is distributed in the hope that it will be useful, but WITHOUT
2349+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2350+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
2351+ * details.
2352+ *
2353+ * You should have received a copy of the GNU General Public License
2354+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2355+ */
2356+
2357+#include "dbusinterface.h"
2358+
2359+#include <cstdio>
2360+#include <cstring>
2361+#include <memory>
2362+#include <stdexcept>
2363+#include <string>
2364+#include <thread>
2365+#include <fcntl.h>
2366+#include <unistd.h>
2367+
2368+#include <glib.h>
2369+#include <glib-object.h>
2370+#include <gio/gio.h>
2371+#include <gio/gunixfdlist.h>
2372+#include <thumbnailer.h>
2373+
2374+#include <internal/gobj_memory.h>
2375+#include "dbus-generated.h"
2376+
2377+using namespace std;
2378+
2379+static const char BUS_NAME[] = "com.canonical.MediaScanner2";
2380+static const char ART_ERROR[] = "com.canonical.MediaScanner2.Error.Failed";
2381+
2382+static const char MISSING_ALBUM_ART[] = "/usr/share/unity/icons/album_missing.png";
2383+
2384+struct DBusInterfacePrivate {
2385+ const std::string bus_path;
2386+ unique_gobj<GDBusConnection> bus;
2387+ unique_gobj<TNThumbnailer> iface;
2388+ unsigned int handler_id;
2389+ std::shared_ptr<Thumbnailer> thumbnailer;
2390+
2391+ DBusInterfacePrivate(GDBusConnection *g_bus, const std::string& bus_path)
2392+ : bus_path(bus_path),
2393+ bus(static_cast<GDBusConnection*>(g_object_ref(g_bus))),
2394+ iface(tn_thumbnailer_skeleton_new()),
2395+ handler_id(0),
2396+ thumbnailer(std::make_shared<Thumbnailer>()) {
2397+ handler_id = g_signal_connect(
2398+ iface.get(), "handle-get-album-art",
2399+ G_CALLBACK(&DBusInterfacePrivate::handleGetAlbumArt), this);
2400+
2401+ GError *error = nullptr;
2402+ if (!g_dbus_interface_skeleton_export(
2403+ G_DBUS_INTERFACE_SKELETON(iface.get()), bus.get(),
2404+ bus_path.c_str(), &error)) {
2405+ string errortxt(error->message);
2406+ g_error_free(error);
2407+
2408+ string msg = "Failed to export interface: ";
2409+ msg += errortxt;
2410+ throw runtime_error(msg);
2411+ }
2412+ }
2413+
2414+ ~DBusInterfacePrivate() {
2415+ g_dbus_interface_skeleton_unexport(
2416+ G_DBUS_INTERFACE_SKELETON(iface.get()));
2417+ g_signal_handler_disconnect(iface.get(), handler_id);
2418+ }
2419+
2420+ static gboolean handleGetAlbumArt(TNThumbnailer *iface, GDBusMethodInvocation *invocation, GUnixFDList *, const char *artist, const char *album, const char *size, void *user_data) {
2421+ auto p = static_cast<DBusInterfacePrivate*>(user_data);
2422+ fprintf(stderr, "Look up cover art for %s/%s at size %s\n", artist, album, size);
2423+
2424+ ThumbnailSize desiredSize;
2425+ if (!strcmp(size, "small")) {
2426+ desiredSize = TN_SIZE_SMALL;
2427+ } else if (!strcmp(size, "large")) {
2428+ desiredSize = TN_SIZE_LARGE;
2429+ } else if (!strcmp(size, "xlarge")) {
2430+ desiredSize = TN_SIZE_XLARGE;
2431+ } else if (!strcmp(size, "original")) {
2432+ desiredSize = TN_SIZE_ORIGINAL;
2433+ } else {
2434+ std::string error("Unknown size: ");
2435+ error += size;
2436+ g_dbus_method_invocation_return_dbus_error(
2437+ invocation, ART_ERROR, error.c_str());
2438+ return TRUE;
2439+ }
2440+
2441+ try {
2442+ std::thread t(&getAlbumArt,
2443+ unique_gobj<TNThumbnailer>(static_cast<TNThumbnailer*>(g_object_ref(iface))),
2444+ unique_gobj<GDBusMethodInvocation>(static_cast<GDBusMethodInvocation*>(g_object_ref(invocation))),
2445+ p->thumbnailer,
2446+ std::string(artist), std::string(album), desiredSize);
2447+ t.detach();
2448+ } catch (const std::exception &e) {
2449+ g_dbus_method_invocation_return_dbus_error(
2450+ invocation, ART_ERROR, e.what());
2451+ }
2452+ return TRUE;
2453+ }
2454+
2455+ static void getAlbumArt(unique_gobj<TNThumbnailer> iface,
2456+ unique_gobj<GDBusMethodInvocation> invocation,
2457+ std::shared_ptr<Thumbnailer> thumbnailer,
2458+ const std::string artist, const std::string album,
2459+ ThumbnailSize desiredSize) {
2460+ std::string art;
2461+ try {
2462+ art = thumbnailer->get_album_art(
2463+ artist, album, desiredSize, TN_REMOTE);
2464+ } catch (const std::exception &e) {
2465+ g_dbus_method_invocation_return_dbus_error(
2466+ invocation.get(), ART_ERROR, e.what());
2467+ return;
2468+ }
2469+
2470+ if (art.empty()) {
2471+ g_dbus_method_invocation_return_dbus_error(
2472+ invocation.get(), ART_ERROR, "Could not get thumbnail");
2473+ return;
2474+ }
2475+ int fd = open(art.c_str(), O_RDONLY);
2476+ if (fd < 0) {
2477+ g_dbus_method_invocation_return_dbus_error(
2478+ invocation.get(), ART_ERROR, strerror(errno));
2479+ return;
2480+ }
2481+
2482+ unique_gobj<GUnixFDList> fd_list(g_unix_fd_list_new());
2483+ GError *error = nullptr;
2484+ g_unix_fd_list_append(fd_list.get(), fd, &error);
2485+ close(fd);
2486+ if (error != nullptr) {
2487+ g_dbus_method_invocation_return_dbus_error(
2488+ invocation.get(), ART_ERROR, error->message);
2489+ g_error_free(error);
2490+ return;
2491+ }
2492+
2493+ tn_thumbnailer_complete_get_album_art(
2494+ iface.get(), invocation.get(), fd_list.get(), g_variant_new_handle(0));
2495+ }
2496+
2497+};
2498+
2499+DBusInterface::DBusInterface(GDBusConnection *bus, const std::string& bus_path)
2500+ : p(new DBusInterfacePrivate(bus, bus_path)) {
2501+}
2502+
2503+DBusInterface::~DBusInterface() {
2504+ delete p;
2505+}
2506
2507=== added file 'src/service/dbusinterface.h'
2508--- src/service/dbusinterface.h 1970-01-01 00:00:00 +0000
2509+++ src/service/dbusinterface.h 2015-02-04 08:57:20 +0000
2510@@ -0,0 +1,40 @@
2511+/*
2512+ * Copyright (C) 2014 Canonical, Ltd.
2513+ *
2514+ * Authors:
2515+ * James Henstridge <james.henstridge@canonical.com>
2516+ *
2517+ * This library is free software; you can redistribute it and/or modify it under
2518+ * the terms of version 3 of the GNU General Public License as published
2519+ * by the Free Software Foundation.
2520+ *
2521+ * This library is distributed in the hope that it will be useful, but WITHOUT
2522+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2523+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
2524+ * details.
2525+ *
2526+ * You should have received a copy of the GNU General Public License
2527+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2528+ */
2529+
2530+#ifndef DBUSINTERFACE_H
2531+#define DBUSINTERFACE_H
2532+
2533+#include <string>
2534+
2535+struct DBusInterfacePrivate;
2536+typedef struct _GDBusConnection GDBusConnection;
2537+
2538+class DBusInterface final {
2539+public:
2540+ DBusInterface(GDBusConnection *bus, const std::string& bus_path);
2541+ ~DBusInterface();
2542+
2543+ DBusInterface(const DBusInterface&) = delete;
2544+ DBusInterface& operator=(DBusInterface&) = delete;
2545+
2546+private:
2547+ DBusInterfacePrivate *p;
2548+};
2549+
2550+#endif
2551
2552=== added file 'src/service/main.cpp'
2553--- src/service/main.cpp 1970-01-01 00:00:00 +0000
2554+++ src/service/main.cpp 2015-02-04 08:57:20 +0000
2555@@ -0,0 +1,44 @@
2556+#include <cstdio>
2557+#include <memory>
2558+#include <stdexcept>
2559+#include <glib.h>
2560+#include <gio/gio.h>
2561+
2562+#include "dbusinterface.h"
2563+
2564+static const char BUS_NAME[] = "com.canonical.Thumbnailer";
2565+static const char BUS_PATH[] = "/com/canonical/Thumbnailer";
2566+
2567+static std::unique_ptr<GMainLoop,void(*)(GMainLoop*)> main_loop(
2568+ g_main_loop_new(nullptr, FALSE), g_main_loop_unref);
2569+
2570+static void nameLost(GDBusConnection *, const char *, void *) {
2571+ fprintf(stderr, "Could no acquire D-Bus name %s. Quitting.\n", BUS_NAME);
2572+ g_main_loop_quit(main_loop.get());
2573+}
2574+
2575+int main(int argc, char **argv) {
2576+ GError *error = nullptr;
2577+ std::unique_ptr<GDBusConnection, void(*)(void*)> bus(
2578+ g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error),
2579+ g_object_unref);
2580+ if (error != nullptr) {
2581+ fprintf(stderr, "Failed to connect to session bus: %s\n", error->message);
2582+ g_error_free(error);
2583+ return 1;
2584+ }
2585+
2586+ DBusInterface dbus(bus.get(), BUS_PATH);
2587+
2588+ unsigned int name_id = g_bus_own_name_on_connection(
2589+ bus.get(), BUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE,
2590+ nullptr, &nameLost, nullptr, nullptr);
2591+
2592+ g_main_loop_run(main_loop.get());
2593+
2594+ if (name_id != 0) {
2595+ g_bus_unown_name(name_id);
2596+ }
2597+
2598+ return 0;
2599+}
2600
2601=== added file 'src/soupdownloader.cpp'
2602--- src/soupdownloader.cpp 1970-01-01 00:00:00 +0000
2603+++ src/soupdownloader.cpp 2015-02-04 08:57:20 +0000
2604@@ -0,0 +1,46 @@
2605+/*
2606+ * Copyright (C) 2014 Canonical Ltd.
2607+ *
2608+ * This program is free software: you can redistribute it and/or modify
2609+ * it under the terms of the GNU Lesser General Public License version 3 as
2610+ * published by the Free Software Foundation.
2611+ *
2612+ * This program is distributed in the hope that it will be useful,
2613+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2614+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2615+ * GNU Lesser General Public License for more details.
2616+ *
2617+ * You should have received a copy of the GNU Lesser General Public License
2618+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2619+ *
2620+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
2621+ */
2622+
2623+#include<internal/soupdownloader.h>
2624+#include<libsoup/soup.h>
2625+#include<internal/gobj_memory.h>
2626+#include<stdexcept>
2627+
2628+SoupDownloader::SoupDownloader() {
2629+ session = soup_session_sync_new();
2630+ if(!session) {
2631+ throw std::runtime_error("Could not create Soup session.");
2632+ }
2633+}
2634+
2635+SoupDownloader::~SoupDownloader() {
2636+ g_object_unref(G_OBJECT(session));
2637+}
2638+
2639+std::string SoupDownloader::download(const std::string &url) {
2640+ unique_gobj<SoupMessage> msg(soup_message_new("GET", url.c_str()));
2641+ guint status;
2642+ status = soup_session_send_message(session, msg.get());
2643+ if(!SOUP_STATUS_IS_SUCCESSFUL(status)) {
2644+ fprintf(stderr, "Determination failed.\n");
2645+ return "";
2646+ }
2647+ std::string result(msg->response_body->data, msg->response_body->length);
2648+ return result;
2649+}
2650+
2651
2652=== added file 'src/thumbnailcache.cpp'
2653--- src/thumbnailcache.cpp 1970-01-01 00:00:00 +0000
2654+++ src/thumbnailcache.cpp 2015-02-04 08:57:20 +0000
2655@@ -0,0 +1,300 @@
2656+/*
2657+ * Copyright (C) 2013 Canonical Ltd.
2658+ *
2659+ * This program is free software: you can redistribute it and/or modify
2660+ * it under the terms of the GNU Lesser General Public License version 3 as
2661+ * published by the Free Software Foundation.
2662+ *
2663+ * This program is distributed in the hope that it will be useful,
2664+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2665+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2666+ * GNU Lesser General Public License for more details.
2667+ *
2668+ * You should have received a copy of the GNU Lesser General Public License
2669+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2670+ *
2671+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
2672+ */
2673+
2674+#ifndef _POSIX_SOURCE
2675+#define _POSIX_SOURCE
2676+#endif
2677+
2678+#include<thumbnailer.h>
2679+#include<internal/thumbnailcache.h>
2680+#include<stdexcept>
2681+#include<glib.h>
2682+#include<sys/stat.h>
2683+#include<sys/types.h>
2684+#include<cassert>
2685+#include<cstdio>
2686+#include<cstring>
2687+#include<errno.h>
2688+#include<fcntl.h>
2689+#include<unistd.h>
2690+#include<vector>
2691+#include<algorithm>
2692+#include<dirent.h>
2693+
2694+using namespace std;
2695+
2696+static void cleardir(const string &root_dir) {
2697+ DIR *d = opendir(root_dir.c_str());
2698+ if(!d) {
2699+ string s = "Something went wrong.";
2700+ throw runtime_error(s);
2701+ }
2702+ struct dirent *entry, *de;
2703+ entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX);
2704+ while(readdir_r(d, entry, &de) == 0 && de) {
2705+ string basename = entry->d_name;
2706+ if (basename == "." || basename == "..")
2707+ continue;
2708+ string fname = root_dir + "/" + basename;
2709+ remove(fname.c_str());
2710+ }
2711+ free(entry);
2712+ closedir(d);
2713+}
2714+
2715+/*
2716+ * This code is copied from mediaartcache. All tests etc
2717+ * are there. When we merge the two, remove this and
2718+ * make both use the same code.
2719+ */
2720+static void prune_dir(const string &root_dir, const size_t max_files) {
2721+ vector<pair<double, string>> mtimes;
2722+ DIR *d = opendir(root_dir.c_str());
2723+ if(!d) {
2724+ string s = "Something went wrong.";
2725+ throw runtime_error(s);
2726+ }
2727+ struct dirent *entry, *de;
2728+ entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX);
2729+ while(readdir_r(d, entry, &de) == 0 && de) {
2730+ string basename = entry->d_name;
2731+ if (basename == "." || basename == "..")
2732+ continue;
2733+ string fname = root_dir + "/" + basename;
2734+ struct stat sbuf;
2735+ if(stat(fname.c_str(), &sbuf) != 0) {
2736+ continue;
2737+ }
2738+ // Use mtime because atime is not guaranteed to work if, for example
2739+ // the filesystem is mounted with noatime or relatime.
2740+ mtimes.push_back(make_pair(sbuf.st_mtim.tv_sec + sbuf.st_mtim.tv_nsec/1000000000.0, fname));
2741+ }
2742+ free(entry);
2743+ closedir(d);
2744+ if (mtimes.size() <= max_files)
2745+ return;
2746+ sort(mtimes.begin(), mtimes.end());
2747+ for(size_t i=0; i < mtimes.size()-max_files; i++) {
2748+ remove(mtimes[i].second.c_str());
2749+ }
2750+}
2751+
2752+static string get_app_pkg_name() {
2753+ const int bufsize = 1024;
2754+ char data[bufsize+1];
2755+ FILE *f = fopen("/proc/self/attr/current", "r");
2756+ if(!f) {
2757+ throw runtime_error("Could not open /proc/self/attr/current.");
2758+ }
2759+ size_t numread = fread(data, 1, bufsize, f);
2760+ fclose(f);
2761+ if(numread == 0) {
2762+ throw runtime_error("Could not read from /proc/self/attr/current.");
2763+ }
2764+ data[numread] = '\0';
2765+ string core(data);
2766+ string::size_type ind = core.find('_');
2767+ if(ind == string::npos) {
2768+ throw runtime_error("/proc/self/attr/current malformed, does not have _ in it.");
2769+ }
2770+ if(ind == 0) {
2771+ throw runtime_error("/proc/self/attr/current malformed, starts with '_'.");
2772+ }
2773+ return core.substr(0, ind);
2774+}
2775+
2776+class ThumbnailCachePrivate {
2777+public:
2778+
2779+ ThumbnailCachePrivate();
2780+ string md5(const string &str) const;
2781+ string get_cache_file_name(const std::string &original, ThumbnailSize desired) const;
2782+ void clear();
2783+ void delete_from_cache(const std::string &abs_path);
2784+ void prune();
2785+
2786+private:
2787+ string tndir;
2788+ string smalldir;
2789+ string largedir;
2790+ string xlargedir;
2791+ string originaldir;
2792+ static const size_t MAX_FILES = 200;
2793+
2794+};
2795+
2796+void ThumbnailCachePrivate::clear() {
2797+ cleardir(smalldir);
2798+ cleardir(largedir);
2799+ cleardir(xlargedir);
2800+ cleardir(originaldir);
2801+}
2802+
2803+
2804+void ThumbnailCachePrivate::prune() {
2805+ prune_dir(smalldir, MAX_FILES);
2806+ prune_dir(largedir, MAX_FILES);
2807+ prune_dir(xlargedir, MAX_FILES);
2808+ prune_dir(originaldir, MAX_FILES);
2809+}
2810+
2811+void ThumbnailCachePrivate::delete_from_cache(const std::string &abs_path) {
2812+ unlink(get_cache_file_name(abs_path, TN_SIZE_SMALL).c_str());
2813+ unlink(get_cache_file_name(abs_path, TN_SIZE_LARGE).c_str());
2814+ unlink(get_cache_file_name(abs_path, TN_SIZE_XLARGE).c_str());
2815+ unlink(get_cache_file_name(abs_path, TN_SIZE_ORIGINAL).c_str());
2816+}
2817+
2818+static string makedir(const string &base, const string &subdir) {
2819+ string dirname = base;
2820+ dirname += "/";
2821+ dirname += subdir;
2822+ int ec;
2823+ errno = 0;
2824+ ec = mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
2825+ if (ec < 0 && errno != EEXIST) {
2826+ string s("Could not create ");
2827+ s += subdir;
2828+ s += " - ";
2829+ s += strerror(errno);
2830+ throw runtime_error(s);
2831+ }
2832+ return dirname;
2833+}
2834+
2835+ThumbnailCachePrivate::ThumbnailCachePrivate() {
2836+ string xdg_base = g_get_user_cache_dir();
2837+ if (xdg_base == "") {
2838+ string s("Could not determine cache dir.");
2839+ throw runtime_error(s);
2840+ }
2841+ int ec = mkdir(xdg_base.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
2842+ if (ec < 0 && errno != EEXIST) {
2843+ string s("Could not create base dir - ");
2844+ s += strerror(errno);
2845+ throw runtime_error(s);
2846+ }
2847+ // This is where it gets tricky. Desktop apps can write to
2848+ // cache dir but confined apps only to cache/appname/
2849+ // First try global cache and fall back to app-specific one.
2850+ string testfile = xdg_base + "/tncache-write-text.null";
2851+ int fd = open(testfile.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
2852+ bool use_global = true;
2853+ if(fd<0) {
2854+ if(errno == EACCES) {
2855+ use_global = false;
2856+ } else {
2857+ string s("Unknown error when checking cache access: ");
2858+ s += strerror(errno);
2859+ throw runtime_error(s);
2860+ }
2861+ } else {
2862+ use_global = true;
2863+ close(fd);
2864+ unlink(testfile.c_str());
2865+ }
2866+ if(!use_global) {
2867+ string app_pkgname = get_app_pkg_name();
2868+ xdg_base = makedir(xdg_base, app_pkgname);
2869+ }
2870+ tndir = xdg_base + "/thumbnails";
2871+ tndir = makedir(xdg_base, "thumbnails");
2872+ smalldir = makedir(tndir,"normal");
2873+ largedir = makedir(tndir, "large");
2874+ xlargedir = makedir(tndir, "xlarge");
2875+ originaldir = makedir(tndir, "original");
2876+}
2877+
2878+string ThumbnailCachePrivate::md5(const string &str) const {
2879+ const unsigned char *buf = (const unsigned char *)str.c_str();
2880+ char *normalized = g_utf8_normalize((const gchar*)buf, str.size(), G_NORMALIZE_ALL);
2881+ string final_result;
2882+ gchar *result;
2883+
2884+ if(normalized) {
2885+ buf = (const unsigned char*)normalized;
2886+ }
2887+ gssize bytes = str.length();
2888+
2889+ result = g_compute_checksum_for_data(G_CHECKSUM_MD5, buf, bytes);
2890+ final_result = result;
2891+ g_free((gpointer)normalized);
2892+ g_free(result);
2893+ return final_result;
2894+}
2895+
2896+string ThumbnailCachePrivate::get_cache_file_name(const std::string & abs_original, ThumbnailSize desired) const {
2897+ assert(abs_original[0] == '/');
2898+ string path;
2899+ switch(desired) {
2900+ case TN_SIZE_SMALL : path = smalldir; break;
2901+ case TN_SIZE_LARGE : path = largedir; break;
2902+ case TN_SIZE_XLARGE : path = xlargedir; break;
2903+ case TN_SIZE_ORIGINAL : path = originaldir; break;
2904+ default : throw runtime_error("Unreachable code");
2905+ }
2906+ path += "/" + md5("file://" + abs_original) + ".png";
2907+ return path;
2908+}
2909+
2910+ThumbnailCache::ThumbnailCache() : p(new ThumbnailCachePrivate()) {
2911+}
2912+
2913+ThumbnailCache::~ThumbnailCache() {
2914+ delete p;
2915+}
2916+
2917+std::string ThumbnailCache::get_if_exists(const std::string &abs_path, ThumbnailSize desired_size) const {
2918+ assert(abs_path[0] == '/');
2919+ string fname = p->get_cache_file_name(abs_path, desired_size);
2920+ FILE *f = fopen(abs_path.c_str(), "r");
2921+ if(!f) {
2922+ p->delete_from_cache(abs_path);
2923+ return "";
2924+ }
2925+ fclose(f);
2926+ f = fopen(fname.c_str(), "r");
2927+ bool existed = false;
2928+ if(f) {
2929+ existed = true;
2930+ fclose(f);
2931+ }
2932+ // Has it been changed since the thumbnail was taken?
2933+ if(existed) {
2934+ struct stat original, thumbnail;
2935+ stat(abs_path.c_str(), &original);
2936+ stat(fname.c_str(), &thumbnail);
2937+ if(original.st_mtime > thumbnail.st_mtime) {
2938+ p->delete_from_cache(abs_path);
2939+ return "";
2940+ }
2941+ }
2942+ return existed ? fname : string("");
2943+}
2944+
2945+std::string ThumbnailCache::get_cache_file_name(const std::string &abs_path, ThumbnailSize desired) const {
2946+ return p->get_cache_file_name(abs_path, desired);
2947+}
2948+
2949+void ThumbnailCache::clear() {
2950+ p->clear();
2951+}
2952+
2953+void ThumbnailCache::prune() {
2954+ p->prune();
2955+}
2956
2957=== added file 'src/thumbnailer.cpp'
2958--- src/thumbnailer.cpp 1970-01-01 00:00:00 +0000
2959+++ src/thumbnailer.cpp 2015-02-04 08:57:20 +0000
2960@@ -0,0 +1,226 @@
2961+/*
2962+ * Copyright (C) 2013 Canonical Ltd.
2963+ *
2964+ * This program is free software: you can redistribute it and/or modify
2965+ * it under the terms of the GNU Lesser General Public License version 3 as
2966+ * published by the Free Software Foundation.
2967+ *
2968+ * This program is distributed in the hope that it will be useful,
2969+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2970+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2971+ * GNU Lesser General Public License for more details.
2972+ *
2973+ * You should have received a copy of the GNU Lesser General Public License
2974+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2975+ *
2976+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
2977+ */
2978+
2979+#include<thumbnailer.h>
2980+#include<internal/thumbnailcache.h>
2981+#include<internal/audioimageextractor.h>
2982+#include<internal/videoscreenshotter.h>
2983+#include<internal/imagescaler.h>
2984+#include<internal/mediaartcache.h>
2985+#include<internal/lastfmdownloader.h>
2986+#include<gdk-pixbuf/gdk-pixbuf.h>
2987+#include<unistd.h>
2988+#include<gst/gst.h>
2989+#include<stdexcept>
2990+#include<random>
2991+#include<gio/gio.h>
2992+#include<glib.h>
2993+#include<memory>
2994+
2995+using namespace std;
2996+
2997+class ThumbnailerPrivate {
2998+private:
2999+ random_device rnd;
3000+
3001+ string create_audio_thumbnail(const string &abspath, ThumbnailSize desired_size,
3002+ ThumbnailPolicy policy);
3003+ string create_video_thumbnail(const string &abspath, ThumbnailSize desired_size);
3004+ string create_generic_thumbnail(const string &abspath, ThumbnailSize desired_size);
3005+
3006+public:
3007+ ThumbnailCache cache;
3008+// AudioImageExtractor audio;
3009+ VideoScreenshotter video;
3010+ ImageScaler scaler;
3011+ MediaArtCache macache;
3012+ LastFMDownloader lfm;
3013+
3014+ ThumbnailerPrivate() {};
3015+
3016+ string create_thumbnail(const string &abspath, ThumbnailSize desired_size,
3017+ ThumbnailPolicy policy);
3018+ string create_random_filename();
3019+};
3020+
3021+
3022+string ThumbnailerPrivate::create_random_filename() {
3023+ string fname;
3024+ char *dirbase = getenv("TMPDIR"); // Set when in a confined application.
3025+ if(dirbase) {
3026+ fname = dirbase;
3027+ } else {
3028+ fname = "/tmp";
3029+ }
3030+ fname += "/thumbnailer.";
3031+ fname += to_string(rnd());
3032+ fname += ".tmp";
3033+ return fname;
3034+}
3035+
3036+string ThumbnailerPrivate::create_audio_thumbnail(const string &/*abspath*/,
3037+ ThumbnailSize /*desired_size*/, ThumbnailPolicy /*policy*/) {
3038+ // There was a symbol clash between 1.0 and 0.10 versions of
3039+ // GStreamer on the desktop so we need to disable in-process
3040+ // usage of gstreamer. Re-enable this once desktop moves to
3041+ // newer Qt multimedia that has GStreamer 1.0.
3042+/*
3043+ try {
3044+ if(audio.extract(abspath, tmpname)) {
3045+ extracted = true;
3046+ }
3047+ } catch(runtime_error &e) {
3048+ }
3049+ if(extracted) {
3050+ scaler.scale(tmpname, tnfile, desired_size, abspath); // If this throws, let it propagate.
3051+ unlink(tmpname.c_str());
3052+ return tnfile;
3053+ }
3054+ */
3055+ return "";
3056+}
3057+string ThumbnailerPrivate::create_generic_thumbnail(const string &abspath, ThumbnailSize desired_size) {
3058+ int tmpw, tmph;
3059+ string tnfile = cache.get_cache_file_name(abspath, desired_size);
3060+ // Special case: full size image files are their own preview.
3061+ if(desired_size == TN_SIZE_ORIGINAL &&
3062+ gdk_pixbuf_get_file_info(abspath.c_str(), &tmpw, &tmph)) {
3063+ return abspath;
3064+ }
3065+ try {
3066+ if(scaler.scale(abspath, tnfile, desired_size, abspath))
3067+ return tnfile;
3068+ } catch(runtime_error &e) {
3069+ }
3070+ return "";
3071+}
3072+
3073+string ThumbnailerPrivate::create_video_thumbnail(const string &abspath, ThumbnailSize desired_size) {
3074+ string tnfile = cache.get_cache_file_name(abspath, desired_size);
3075+ string tmpname = create_random_filename();
3076+ if(video.extract(abspath, tmpname)) {
3077+ scaler.scale(tmpname, tnfile, desired_size, abspath);
3078+ unlink(tmpname.c_str());
3079+ return tnfile;
3080+ }
3081+ throw runtime_error("Video extraction failed.");
3082+}
3083+
3084+string ThumbnailerPrivate::create_thumbnail(const string &abspath, ThumbnailSize desired_size,
3085+ ThumbnailPolicy policy) {
3086+ // Every now and then see if we have too much stuff and delete them if so.
3087+ if((rnd() % 100) == 0) { // No, this is not perfectly random. It does not need to be.
3088+ cache.prune();
3089+ }
3090+ std::unique_ptr<GFile, void(*)(void *)> file(
3091+ g_file_new_for_path(abspath.c_str()), g_object_unref);
3092+ if(!file) {
3093+ return "";
3094+ }
3095+
3096+ std::unique_ptr<GFileInfo, void(*)(void *)> info(
3097+ g_file_query_info(file.get(), G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
3098+ G_FILE_QUERY_INFO_NONE, /* cancellable */ NULL, /* error */NULL),
3099+ g_object_unref);
3100+ if(!info) {
3101+ return "";
3102+ }
3103+
3104+ std::string content_type(g_file_info_get_content_type(info.get()));
3105+ if (content_type.empty()) {
3106+ return "";
3107+ }
3108+
3109+ if (content_type.find("audio/") == 0) {
3110+ return create_audio_thumbnail(abspath, desired_size, policy);
3111+ }
3112+
3113+ if (content_type.find("video/") == 0) {
3114+ return create_video_thumbnail(abspath, desired_size);
3115+ }
3116+
3117+ return create_generic_thumbnail(abspath, desired_size);
3118+}
3119+
3120+Thumbnailer::Thumbnailer() {
3121+ g_type_init(); // Unfortunately still needed in precise.
3122+ p = new ThumbnailerPrivate();
3123+}
3124+
3125+Thumbnailer::~Thumbnailer() {
3126+ delete p;
3127+}
3128+std::string Thumbnailer::get_thumbnail(const std::string &filename, ThumbnailSize desired_size,
3129+ ThumbnailPolicy policy) {
3130+ string abspath;
3131+ if(filename[0] != '/') {
3132+ abspath += getcwd(nullptr, 0);
3133+ abspath += "/" + filename;
3134+ } else {
3135+ abspath = filename;
3136+ }
3137+ std::string estimate = p->cache.get_if_exists(abspath, desired_size);
3138+ if(!estimate.empty())
3139+ return estimate;
3140+ string generated = p->create_thumbnail(abspath, desired_size, policy);
3141+ if(generated == abspath) {
3142+ return abspath;
3143+ }
3144+ return p->cache.get_if_exists(abspath, desired_size);
3145+}
3146+
3147+string Thumbnailer::get_thumbnail(const string &filename, ThumbnailSize desired_size) {
3148+ return get_thumbnail(filename, desired_size, TN_LOCAL);
3149+}
3150+
3151+std::string Thumbnailer::get_album_art(const std::string &artist, const std::string &album,
3152+ ThumbnailSize desired_size, ThumbnailPolicy policy) {
3153+ if(!p->macache.has_art(artist, album)) {
3154+ if(policy == TN_LOCAL) {
3155+ // We don't have it cached and can't access the net
3156+ // -> nothing to be done.
3157+ return "";
3158+ }
3159+ char filebuf[] = "/tmp/some/long/text/here/so/path/will/fit";
3160+ std::string tmpname = tmpnam(filebuf);
3161+ if(!p->lfm.download(artist, album, tmpname)) {
3162+ return "";
3163+ }
3164+ gchar *contents;
3165+ gsize content_size;
3166+ GError *err = nullptr;
3167+ if(!g_file_get_contents(tmpname.c_str(), &contents, &content_size, &err)) {
3168+ unlink(tmpname.c_str());
3169+ std::string msg("Error reading file: ");
3170+ msg += err->message;
3171+ g_error_free(err);
3172+ throw std::runtime_error(msg);
3173+ }
3174+ unlink(tmpname.c_str());
3175+ unique_ptr<gchar, void(*)(gpointer)> deleter(contents, g_free);
3176+ p->macache.add_art(artist, album, contents, content_size);
3177+ }
3178+ // At this point we know we have the image in our art cache (unless
3179+ // someone just deleted it concurrently, in which case we can't
3180+ // really do anything.
3181+ std::string original = p->macache.get_art_file(artist, album);
3182+ if(desired_size == TN_SIZE_ORIGINAL) {
3183+ return original;
3184+ }
3185+ return get_thumbnail(original, desired_size, policy);
3186+}
3187
3188=== added file 'src/videoscreenshotter.cpp'
3189--- src/videoscreenshotter.cpp 1970-01-01 00:00:00 +0000
3190+++ src/videoscreenshotter.cpp 2015-02-04 08:57:20 +0000
3191@@ -0,0 +1,105 @@
3192+/*
3193+ * Copyright (C) 2013 Canonical Ltd.
3194+ *
3195+ * This program is free software: you can redistribute it and/or modify
3196+ * it under the terms of the GNU Lesser General Public License version 3 as
3197+ * published by the Free Software Foundation.
3198+ *
3199+ * This program is distributed in the hope that it will be useful,
3200+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3201+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3202+ * GNU Lesser General Public License for more details.
3203+ *
3204+ * You should have received a copy of the GNU Lesser General Public License
3205+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
3206+ *
3207+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
3208+ */
3209+
3210+#include<internal/config.h>
3211+#include<internal/videoscreenshotter.h>
3212+
3213+#include<unistd.h>
3214+#include<sys/wait.h>
3215+#include<stdexcept>
3216+#include<cstring>
3217+#include<sys/time.h>
3218+#include<signal.h>
3219+#include<time.h>
3220+
3221+using namespace std;
3222+static double timestamp() {
3223+ struct timeval now;
3224+ gettimeofday(&now, NULL);
3225+ return now.tv_sec + now.tv_usec/1000000.0;
3226+
3227+}
3228+
3229+static bool wait_for_helper(pid_t child) {
3230+ const double max_wait_time = 10;
3231+ struct timespec sleep_time;
3232+ double start = timestamp();
3233+ sleep_time.tv_sec = 0;
3234+ sleep_time.tv_nsec = 100000000;
3235+ int status;
3236+ while(waitpid(child, &status, WNOHANG) == 0) {
3237+ struct timespec dummy;
3238+ double now = timestamp();
3239+ if(now - start >= max_wait_time) {
3240+ if(kill(child, SIGKILL) < 0) {
3241+ string msg("Could not kill child process: ");
3242+ msg += strerror(errno);
3243+ throw runtime_error(msg);
3244+ }
3245+ waitpid(child, &status, 0);
3246+ throw runtime_error("Helper process took too long.");
3247+ }
3248+ nanosleep(&sleep_time, &dummy);
3249+ }
3250+ if(status < 0) {
3251+ throw runtime_error("Waiting for child process failed.");
3252+ }
3253+ if(status == 0) {
3254+ return true;
3255+ }
3256+ if(status == 1) {
3257+ return false;
3258+ }
3259+ if(status == 2) {
3260+ throw runtime_error("Video extractor pipeline failed");
3261+ }
3262+ throw runtime_error("Unknown error when trying to extract video screenshot.");
3263+}
3264+
3265+VideoScreenshotter::VideoScreenshotter() {
3266+}
3267+
3268+VideoScreenshotter::~VideoScreenshotter() {
3269+}
3270+
3271+bool VideoScreenshotter::extract(const std::string &ifname, const std::string &ofname) {
3272+ // Gstreamer video pipelines are unstable so we need to run an
3273+ // external helper library.
3274+ string exe_path;
3275+ char *utildir = getenv("TN_UTILDIR");
3276+ exe_path = utildir ? utildir : SHARE_PRIV_ABS;
3277+ string cmd(exe_path + "/vs-thumb");
3278+ pid_t child = fork();
3279+ if(child == -1) {
3280+ throw runtime_error("Could not spawn worker process.");
3281+ }
3282+ if(child == 0) {
3283+ execl(cmd.c_str(), cmd.c_str(), ifname.c_str(), ofname.c_str(), (char*) NULL);
3284+ fprintf(stderr, "Could not execute worker process: %s", strerror(errno));
3285+ _exit(100);
3286+ } else {
3287+ try {
3288+ return wait_for_helper(child);
3289+ } catch(...) {
3290+ unlink(ofname.c_str());
3291+ throw;
3292+ }
3293+ }
3294+ throw runtime_error("Code that should not have been reached was reached.");
3295+}
3296+
3297
3298=== added file 'src/vs-thumb.cpp'
3299--- src/vs-thumb.cpp 1970-01-01 00:00:00 +0000
3300+++ src/vs-thumb.cpp 2015-02-04 08:57:20 +0000
3301@@ -0,0 +1,127 @@
3302+/*
3303+ * Copyright (C) 2013 Canonical Ltd.
3304+ *
3305+ * This program is free software: you can redistribute it and/or modify
3306+ * it under the terms of the GNU Lesser General Public License version 3 as
3307+ * published by the Free Software Foundation.
3308+ *
3309+ * This program is distributed in the hope that it will be useful,
3310+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3311+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3312+ * GNU Lesser General Public License for more details.
3313+ *
3314+ * You should have received a copy of the GNU Lesser General Public License
3315+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
3316+ *
3317+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
3318+ */
3319+
3320+#include<internal/gobj_memory.h>
3321+#include<cstdio>
3322+#include<memory>
3323+#include<stdexcept>
3324+#include<gst/gst.h>
3325+#include<gst/app/gstappsink.h>
3326+#include<gdk-pixbuf/gdk-pixbuf.h>
3327+
3328+using namespace std;
3329+
3330+bool extract(const std::string &ifname, const std::string &ofname) {
3331+ string caps_string = "video/x-raw,format=RGB,pixel-aspect-ratio=1/1";
3332+ GstElement *sink;
3333+ gint64 duration, seek_point;
3334+ string pipe_cmd = "filesrc location=\"";
3335+ pipe_cmd += ifname;
3336+ pipe_cmd += "\" ! decodebin ! videoconvert ! videoscale !";
3337+ pipe_cmd += "appsink name=sink caps=\"";
3338+ pipe_cmd += caps_string;
3339+ pipe_cmd += "\"";
3340+
3341+ unique_ptr<GstElement, void(*)(GstElement *t)> pipeline(
3342+ gst_parse_launch(pipe_cmd.c_str(), nullptr),
3343+ [](GstElement *t){ gst_object_unref(t);});
3344+ sink = gst_bin_get_by_name(GST_BIN(pipeline.get()), "sink");
3345+
3346+ GstStateChangeReturn ret = gst_element_set_state(pipeline.get(), GST_STATE_PAUSED);
3347+ switch (ret) {
3348+ case GST_STATE_CHANGE_FAILURE:
3349+ throw runtime_error("Fail to start thumbnail pipeline.");
3350+ case GST_STATE_CHANGE_NO_PREROLL:
3351+ throw runtime_error("Thumbnail not supported for live sources.");
3352+ default:
3353+ break;
3354+ }
3355+ // Need to preroll in order to get duration.
3356+ ret = gst_element_get_state(pipeline.get(), nullptr, nullptr, 3*GST_SECOND);
3357+ if(ret == GST_STATE_CHANGE_FAILURE) {
3358+ throw runtime_error("Failed to preroll.");
3359+ } else if(ret == GST_STATE_CHANGE_ASYNC) {
3360+ fprintf(stderr, "Problem prerolling, trying to continue anyway.\n");
3361+ }
3362+ if(!gst_element_query_duration(pipeline.get(), GST_FORMAT_TIME, &duration)) {
3363+ fprintf(stderr, "Media backend does not implement query_duration, using fallback time.\n");
3364+ seek_point = 10*GST_SECOND;
3365+ } else {
3366+ seek_point = 2*duration/7;
3367+ }
3368+ gst_element_seek_simple(pipeline.get(),
3369+ GST_FORMAT_TIME,
3370+ static_cast<GstSeekFlags>(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT),
3371+ seek_point);
3372+ GstSample *sample = nullptr;
3373+ sample = gst_app_sink_pull_preroll(GST_APP_SINK(sink));
3374+ if(sample == nullptr || !GST_IS_SAMPLE(sample)) {
3375+ throw runtime_error("Could not create sample. Unsupported or invalid file type?");
3376+ }
3377+ GstCaps *caps = gst_sample_get_caps(sample);
3378+
3379+ GstBuffer *buf = gst_sample_get_buffer(sample);
3380+ if (sample) {
3381+ gint width, height;
3382+ GstStructure *s = gst_caps_get_structure(caps, 0);
3383+ gboolean res = gst_structure_get_int(s, "width", &width);
3384+ res |= gst_structure_get_int (s, "height", &height);
3385+ if (!res) {
3386+ throw runtime_error("could not determine snapshot dimension.");
3387+ }
3388+ GstMapInfo mi;
3389+ gst_buffer_map(buf, &mi, GST_MAP_READ);
3390+ unique_gobj<GdkPixbuf> img(
3391+ gdk_pixbuf_new_from_data(mi.data, GDK_COLORSPACE_RGB,
3392+ false, 8, width, height,
3393+ (((width * 3)+3)&~3),
3394+ nullptr, nullptr));
3395+ gst_buffer_unmap(buf, &mi);
3396+ GError *err = nullptr;
3397+ if(!gdk_pixbuf_save(img.get(), ofname.c_str(), "jpeg", &err, NULL)) {
3398+ string msg = err->message;
3399+ g_error_free(err);
3400+ throw runtime_error(msg);
3401+ }
3402+ } else {
3403+ throw runtime_error("Pipeline failed.");
3404+ }
3405+
3406+ gst_element_set_state(pipeline.get(), GST_STATE_NULL);
3407+ return true;
3408+}
3409+
3410+int main(int argc, char **argv) {
3411+ gst_init(&argc, &argv);
3412+ if(argc != 3) {
3413+ printf("%s <source file> <output file>\n", argv[0]);
3414+ return 1;
3415+ }
3416+ string infile(argv[1]);
3417+ string outfile(argv[2]);
3418+ bool success;
3419+ try {
3420+ success = extract(infile, outfile);
3421+ } catch(runtime_error &e) {
3422+ return 2;
3423+ }
3424+ if(success) {
3425+ return 0;
3426+ }
3427+ return 1;
3428+}
3429
3430=== added directory 'tests'
3431=== renamed directory 'tests' => 'tests.moved'
3432=== added file 'tests/CMakeLists.txt'
3433--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
3434+++ tests/CMakeLists.txt 2015-02-04 08:57:20 +0000
3435@@ -0,0 +1,41 @@
3436+if (NOT DEFINED GTEST_ROOT)
3437+ set(GTEST_ROOT /usr/src/gtest)
3438+endif()
3439+
3440+set(GTEST_SRC_DIR "${GTEST_ROOT}/src")
3441+set(GTEST_INCLUDE_DIR ${GTEST_ROOT})
3442+
3443+add_library(gtest STATIC
3444+${GTEST_SRC_DIR}/gtest-all.cc
3445+)
3446+set_target_properties(gtest PROPERTIES INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR})
3447+target_link_libraries(gtest ${CMAKE_THREAD_LIBS_INIT})
3448+
3449+set(TESTDATADIR ${CMAKE_CURRENT_SOURCE_DIR})
3450+
3451+configure_file(testsetup.h.in testsetup.h @ONLY)
3452+include_directories(${CMAKE_CURRENT_BINARY_DIR})
3453+
3454+add_executable(basic basic.cpp)
3455+target_link_libraries(basic thumbnailer gtest)
3456+add_test(basic basic)
3457+set_property(TEST basic PROPERTY ENVIRONMENT "XDG_CACHE_HOME=${CMAKE_CURRENT_BINARY_DIR}")
3458+set_property(TEST basic APPEND PROPERTY ENVIRONMENT "TN_UTILDIR=${CMAKE_BINARY_DIR}/src")
3459+
3460+add_executable(mediaartcachetest mediaartcachetest.cpp ../src/mediaartcache.cpp)
3461+target_link_libraries(mediaartcachetest ${GIO_DEPS_LDFLAGS} gtest)
3462+add_test(mediaartcache mediaartcachetest)
3463+set_property(TEST mediaartcache PROPERTY ENVIRONMENT "XDG_CACHE_HOME=${CMAKE_CURRENT_BINARY_DIR}")
3464+
3465+add_executable(downloadtest download.cpp ../src/lastfmdownloader.cpp ../src/soupdownloader.cpp)
3466+target_link_libraries(downloadtest ${XML_DEPS_LDFLAGS} ${SOUP_DEPS_LDFLAGS} gtest)
3467+add_test(downloadtest downloadtest)
3468+
3469+# This is only needed here because GStreamer brings in gobject.
3470+pkg_check_modules(GOBJ_DEPS REQUIRED gobject-2.0)
3471+
3472+include_directories(${GOBJ_DEPS_INCLUDE_DIRS})
3473+
3474+add_executable(unique_gobj unique_gobj.cpp)
3475+target_link_libraries(unique_gobj ${GOBJ_DEPS_LDFLAGS} ${IMG_DEPS_LDFLAGS} gtest)
3476+add_test(unique_gobj unique_gobj)
3477
3478=== added file 'tests/basic.cpp'
3479--- tests/basic.cpp 1970-01-01 00:00:00 +0000
3480+++ tests/basic.cpp 2015-02-04 08:57:20 +0000
3481@@ -0,0 +1,183 @@
3482+/*
3483+ * Copyright (C) 2013 Canonical Ltd.
3484+ *
3485+ * This program is free software: you can redistribute it and/or modify
3486+ * it under the terms of the GNU Lesser General Public License version 3 as
3487+ * published by the Free Software Foundation.
3488+ *
3489+ * This program is distributed in the hope that it will be useful,
3490+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3491+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3492+ * GNU Lesser General Public License for more details.
3493+ *
3494+ * You should have received a copy of the GNU Lesser General Public License
3495+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
3496+ *
3497+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
3498+ */
3499+
3500+#include<thumbnailer.h>
3501+#include<testsetup.h>
3502+#include<gtest/gtest.h>
3503+#include<unistd.h>
3504+#include<gdk-pixbuf/gdk-pixbuf.h>
3505+
3506+#define TESTIMAGE TESTDATADIR "/testimage.jpg"
3507+#define ROTTESTIMAGE TESTDATADIR "/testrotate.jpg"
3508+#define TESTVIDEO TESTDATADIR "/testvideo.ogg"
3509+
3510+using namespace std;
3511+
3512+bool file_exists(const string &s) {
3513+ FILE *f = fopen(s.c_str(), "r");
3514+ if(f) {
3515+ fclose(f);
3516+ return true;
3517+ }
3518+ return false;
3519+}
3520+
3521+void copy_file(const string &src, const string &dst) {
3522+ FILE* f = fopen(src.c_str(), "r");
3523+ ASSERT_TRUE(f);
3524+ fseek(f, 0, SEEK_END);
3525+ size_t size = ftell(f);
3526+
3527+ char* buf = new char[size];
3528+
3529+ fseek(f, 0, SEEK_SET);
3530+ ASSERT_EQ(fread(buf, 1, size, f), size);
3531+ fclose(f);
3532+
3533+ f = fopen(dst.c_str(), "w");
3534+ ASSERT_TRUE(f);
3535+ ASSERT_EQ(fwrite(buf, 1, size, f), size);
3536+ fclose(f);
3537+ delete[] buf;
3538+}
3539+
3540+TEST(Thumbnailer, trivial) {
3541+ Thumbnailer tn;
3542+}
3543+
3544+static void file_test(Thumbnailer &tn, string &ifile) {
3545+ int w, h;
3546+ ASSERT_TRUE(file_exists(ifile));
3547+ string thumbfile = tn.get_thumbnail(ifile, TN_SIZE_SMALL, TN_LOCAL);
3548+ unlink(thumbfile.c_str());
3549+ ASSERT_FALSE(file_exists(thumbfile));
3550+ string thumbfile2 = tn.get_thumbnail(ifile, TN_SIZE_SMALL, TN_LOCAL);
3551+ ASSERT_EQ(thumbfile, thumbfile2);
3552+ ASSERT_TRUE(file_exists(thumbfile));
3553+ ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile.c_str(), &w, &h));
3554+ ASSERT_LE(w, 128);
3555+ ASSERT_LE(h, 128);
3556+}
3557+
3558+TEST(Thumbnailer, image) {
3559+ Thumbnailer tn;
3560+ string imfile(TESTIMAGE);
3561+ file_test(tn, imfile);
3562+}
3563+
3564+TEST(Thumbnailer, video) {
3565+ Thumbnailer tn;
3566+ string videofile(TESTVIDEO);
3567+ file_test(tn, videofile);
3568+}
3569+
3570+TEST(Thumbnailer, rotate) {
3571+ Thumbnailer tn;
3572+ string imfile(ROTTESTIMAGE);
3573+ int w, h;
3574+ ASSERT_TRUE(file_exists(imfile));
3575+ string thumbfile = tn.get_thumbnail(imfile, TN_SIZE_LARGE);
3576+ unlink(thumbfile.c_str());
3577+ ASSERT_FALSE(file_exists(thumbfile));
3578+ string thumbfile2 = tn.get_thumbnail(imfile, TN_SIZE_LARGE);
3579+ ASSERT_EQ(thumbfile, thumbfile2);
3580+ ASSERT_TRUE(file_exists(thumbfile));
3581+ ASSERT_TRUE(gdk_pixbuf_get_file_info(imfile.c_str(), &w, &h));
3582+ ASSERT_GT(w, h); // gdk_pixbuf does not reorient images automatically.
3583+ ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile.c_str(), &w, &h));
3584+ ASSERT_GT(h, w); // Has the orientation been straightened during scaling?
3585+}
3586+
3587+
3588+TEST(Thumbnailer, video_original) {
3589+ Thumbnailer tn;
3590+ int w, h;
3591+ string videofile(TESTVIDEO);
3592+ string origsize = tn.get_thumbnail(videofile, TN_SIZE_ORIGINAL);
3593+ ASSERT_TRUE(file_exists(origsize));
3594+ ASSERT_TRUE(gdk_pixbuf_get_file_info(origsize.c_str(), &w, &h));
3595+ ASSERT_EQ(w, 1920);
3596+ ASSERT_EQ(h, 1080);
3597+}
3598+
3599+
3600+TEST(Thumbnailer, size) {
3601+ Thumbnailer tn;
3602+ int w, h;
3603+ string imfile(TESTIMAGE);
3604+ string thumbfile = tn.get_thumbnail(imfile, TN_SIZE_SMALL);
3605+ string thumbfile2 = tn.get_thumbnail(imfile, TN_SIZE_LARGE);
3606+ string thumbfile3 = tn.get_thumbnail(imfile, TN_SIZE_XLARGE);
3607+ ASSERT_FALSE(thumbfile.empty());
3608+ ASSERT_FALSE(thumbfile2.empty());
3609+ ASSERT_FALSE(thumbfile3.empty());
3610+ ASSERT_NE(thumbfile, thumbfile2);
3611+ ASSERT_NE(thumbfile, thumbfile3);
3612+ ASSERT_NE(thumbfile2, thumbfile3);
3613+ ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile.c_str(), &w, &h));
3614+ ASSERT_EQ(w, 128);
3615+ ASSERT_LE(h, 128);
3616+ ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile2.c_str(), &w, &h));
3617+ ASSERT_EQ(w, 256);
3618+ ASSERT_LE(h, 256);
3619+ ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile3.c_str(), &w, &h));
3620+ ASSERT_EQ(w, 512);
3621+ ASSERT_LE(h, 512);
3622+}
3623+
3624+TEST(Thumbnailer, deletetest) {
3625+ Thumbnailer tn;
3626+ string srcimg(TESTIMAGE);
3627+ string workimage("working_image.jpg");
3628+ copy_file(srcimg, workimage);
3629+ ASSERT_TRUE(file_exists(workimage));
3630+ string thumbfile = tn.get_thumbnail(workimage, TN_SIZE_SMALL);
3631+ string thumbfile2 = tn.get_thumbnail(workimage, TN_SIZE_LARGE);
3632+ string thumbfile3 = tn.get_thumbnail(workimage, TN_SIZE_XLARGE);
3633+ ASSERT_TRUE(file_exists(thumbfile));
3634+ ASSERT_TRUE(file_exists(thumbfile2));
3635+ ASSERT_TRUE(file_exists(thumbfile3));
3636+ unlink(workimage.c_str());
3637+ string tmp = tn.get_thumbnail(workimage, TN_SIZE_SMALL);
3638+ ASSERT_TRUE(tmp.empty());
3639+ ASSERT_FALSE(file_exists(thumbfile));
3640+ ASSERT_FALSE(file_exists(thumbfile2));
3641+ ASSERT_FALSE(file_exists(thumbfile3));
3642+}
3643+
3644+TEST(Thumbnailer, no_image_cache) {
3645+ Thumbnailer tn;
3646+ string srcimg(TESTIMAGE);
3647+ string dstimg = tn.get_thumbnail(srcimg, TN_SIZE_ORIGINAL);
3648+ ASSERT_EQ(srcimg, dstimg);
3649+}
3650+
3651+TEST(Thumbnailer, album_art) {
3652+ // During test suite run we may not have access to the net.
3653+ // So just test calling to ensure symbol visibility etc work.
3654+ Thumbnailer tn;
3655+ string artist("The Prodigy");
3656+ string album("Music for the Jilted Generation");
3657+ tn.get_album_art(artist, album, TN_SIZE_ORIGINAL, TN_LOCAL);
3658+}
3659+
3660+int main(int argc, char **argv) {
3661+ g_type_init(); // Still needed in precise.
3662+ ::testing::InitGoogleTest(&argc, argv);
3663+ return RUN_ALL_TESTS();
3664+}
3665
3666=== added file 'tests/download.cpp'
3667--- tests/download.cpp 1970-01-01 00:00:00 +0000
3668+++ tests/download.cpp 2015-02-04 08:57:20 +0000
3669@@ -0,0 +1,110 @@
3670+/*
3671+ * Copyright (C) 2014 Canonical Ltd.
3672+ *
3673+ * This program is free software: you can redistribute it and/or modify
3674+ * it under the terms of the GNU Lesser General Public License version 3 as
3675+ * published by the Free Software Foundation.
3676+ *
3677+ * This program is distributed in the hope that it will be useful,
3678+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3679+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3680+ * GNU Lesser General Public License for more details.
3681+ *
3682+ * You should have received a copy of the GNU Lesser General Public License
3683+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
3684+ *
3685+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
3686+ */
3687+
3688+#include<gtest/gtest.h>
3689+#include<internal/lastfmdownloader.h>
3690+#include<cstdio>
3691+#include<unistd.h>
3692+#include<mutex>
3693+#include<condition_variable>
3694+#include<thread>
3695+
3696+using namespace std;
3697+
3698+const char *testimage = "abc";
3699+
3700+class FakeDownloader : public HttpDownloader {
3701+private:
3702+ constexpr static const char *imloc = "http://dummy";
3703+ constexpr static const char *xml = "<album><coverart><large>http://dummy</large></coverart></album>";
3704+
3705+public:
3706+ std::string download(const std::string &url) override {
3707+ if(url.find("audioscrobbler") != std::string::npos) {
3708+ return xml;
3709+ }
3710+ if(url == imloc) {
3711+ return testimage;
3712+ }
3713+ throw std::runtime_error("Tried to get unknown data from FakeDownloader.");
3714+ }
3715+};
3716+
3717+TEST(Downloader, canned) {
3718+ LastFMDownloader lfdl(new FakeDownloader());
3719+ string artist("Some guy");
3720+ string album("Some album");
3721+ string outfile("/tmp/temptestfile");
3722+ unlink(outfile.c_str());
3723+ ASSERT_TRUE(lfdl.download(artist, album, outfile));
3724+ char output[4];
3725+ FILE *f = fopen(outfile.c_str(), "r");
3726+ ASSERT_TRUE(f);
3727+ ASSERT_EQ(fread(output, 1, 3, f), 3);
3728+ output[3] = '\0';
3729+ fclose(f);
3730+ unlink(outfile.c_str());
3731+ string s1(testimage);
3732+ string s2(output);
3733+ ASSERT_EQ(s1, s2);
3734+}
3735+
3736+static std::mutex m;
3737+static std::condition_variable cv;
3738+static bool go = false;
3739+
3740+static void query_thread(LastFMDownloader *lfdl, int num) {
3741+ string fname("/tmp/tmpfile");
3742+ string artist("Some guy");
3743+ string album("Some album");
3744+ artist += num;
3745+ album += num;
3746+ fname += num;
3747+ {
3748+ std::unique_lock<std::mutex> lk(m);
3749+ cv.wait(lk, []{return go;});
3750+ }
3751+ for(int i=0; i<10; i++) {
3752+ unlink(fname.c_str());
3753+ ASSERT_TRUE(lfdl->download(artist, album, fname));
3754+ }
3755+ unlink(fname.c_str());
3756+}
3757+
3758+TEST(Downloader, threads) {
3759+ LastFMDownloader lfdl(new FakeDownloader());
3760+ vector<std::thread> workers;
3761+ for(int i=0; i<10; i++) {
3762+ workers.emplace_back(query_thread, &lfdl, i);
3763+ }
3764+ std::this_thread::sleep_for(std::chrono::seconds(1));
3765+ {
3766+ std::lock_guard<std::mutex> g(m);
3767+ go = true;
3768+ }
3769+ cv.notify_all();
3770+ for(auto &i : workers) {
3771+ i.join();
3772+ }
3773+}
3774+
3775+
3776+int main(int argc, char **argv) {
3777+ ::testing::InitGoogleTest(&argc, argv);
3778+ return RUN_ALL_TESTS();
3779+}
3780
3781=== added file 'tests/mediaartcachetest.cpp'
3782--- tests/mediaartcachetest.cpp 1970-01-01 00:00:00 +0000
3783+++ tests/mediaartcachetest.cpp 2015-02-04 08:57:20 +0000
3784@@ -0,0 +1,150 @@
3785+/*
3786+ * Copyright (C) 2013-2014 Canonical Ltd.
3787+ *
3788+ * This program is free software: you can redistribute it and/or modify
3789+ * it under the terms of the GNU General Public License version 3 as
3790+ * published by the Free Software Foundation.
3791+ *
3792+ * This program is distributed in the hope that it will be useful,
3793+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3794+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3795+ * GNU General Public License for more details.
3796+ *
3797+ * You should have received a copy of the GNU General Public License
3798+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
3799+ *
3800+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
3801+ */
3802+
3803+#include<sys/types.h>
3804+#include<string.h>
3805+#include<stdio.h>
3806+#include<dirent.h>
3807+
3808+#include<string>
3809+#include <gtest/gtest.h>
3810+
3811+#include "../include/internal/mediaartcache.h"
3812+
3813+using namespace std;
3814+
3815+namespace mediascanner {
3816+
3817+TEST(MediaArtCacheTest, BasicFunctionality) {
3818+ MediaArtCache mac;
3819+ mac.clear();
3820+ string artist = "Some Guy";
3821+ string album = "Muzak";
3822+ const int datasize = 3;
3823+ char data[datasize] = {'a', 'b', 'c'};
3824+ char indata[datasize];
3825+ FILE *f;
3826+
3827+ ASSERT_FALSE(mac.has_art(artist, album));
3828+ mac.add_art(artist, album, data, datasize);
3829+ ASSERT_TRUE(mac.has_art(artist, album));
3830+ f = fopen(mac.get_art_file(artist, album).c_str(), "r");
3831+ ASSERT_TRUE(f);
3832+ ASSERT_EQ(fread(indata, 1, datasize, f), datasize);
3833+ fclose(f);
3834+ ASSERT_EQ(memcmp(indata, data, datasize), 0);
3835+
3836+ mac.clear();
3837+ assert(!mac.has_art(artist, album));
3838+}
3839+
3840+TEST(MediaArtCacheTest, Swapped) {
3841+ string artist1("foo");
3842+ string album1("bar");
3843+ string artist2(album1);
3844+ string album2(artist1);
3845+ const int datasize = 4;
3846+ char data1[datasize] = {'a', 'b', 'c', 'd'};
3847+ char data2[datasize] = {'d', 'c', 'b', 'e'};
3848+ char indata[datasize];
3849+ MediaArtCache mac;
3850+ FILE *f;
3851+ mac.clear();
3852+
3853+ ASSERT_FALSE(mac.has_art(artist1, album1));
3854+ ASSERT_FALSE(mac.has_art(artist2, album2));
3855+
3856+ mac.add_art(artist1, album1, data1, datasize);
3857+ ASSERT_TRUE(mac.has_art(artist1, album1));
3858+ ASSERT_FALSE(mac.has_art(artist2, album2));
3859+
3860+ mac.clear();
3861+
3862+ mac.add_art(artist2, album2, data2, datasize);
3863+ ASSERT_FALSE(mac.has_art(artist1, album1));
3864+ ASSERT_TRUE(mac.has_art(artist2, album2));
3865+
3866+ mac.add_art(artist1, album1, data1, datasize);
3867+
3868+ f = fopen(mac.get_art_file(artist1, album1).c_str(), "r");
3869+ ASSERT_TRUE(f);
3870+ ASSERT_EQ(fread(indata, 1, datasize, f), datasize);
3871+ fclose(f);
3872+ ASSERT_EQ(memcmp(indata, data1, datasize), 0);
3873+
3874+ f = fopen(mac.get_art_file(artist2, album2).c_str(), "r");
3875+ ASSERT_TRUE(f);
3876+ ASSERT_EQ(fread(indata, 1, datasize, f), datasize);
3877+ fclose(f);
3878+ ASSERT_EQ(memcmp(indata, data2, datasize), 0);
3879+}
3880+
3881+static int count_files(const string &dir) {
3882+ DIR *d = opendir(dir.c_str());
3883+ int count = 0;
3884+ if(!d) {
3885+ string s = "Something went wrong.";
3886+ throw s;
3887+ }
3888+ struct dirent *entry, *de;
3889+ entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX);
3890+ while(readdir_r(d, entry, &de) == 0 && de) {
3891+ string basename = entry->d_name;
3892+ if (basename == "." || basename == "..")
3893+ continue;
3894+ count++;
3895+ }
3896+ closedir(d);
3897+ free(entry);
3898+ return count;
3899+}
3900+
3901+TEST(MediaArtCacheTest, Prune) {
3902+ MediaArtCache mac;
3903+ mac.clear();
3904+ const int max_files = MediaArtCache::MAX_SIZE;
3905+ string cache_dir = mac.get_cache_dir();
3906+ char arr[] = {'a', 'b', 'c'};
3907+ ASSERT_EQ(count_files(cache_dir), 0);
3908+ for(int i=0; i<max_files+5; i++) {
3909+ string tmpname = cache_dir + "/" + to_string(i) + ".jpg";
3910+ FILE *f = fopen(tmpname.c_str(), "w");
3911+ if (!f) {
3912+ string error("Could not create file ");
3913+ error += tmpname;
3914+ throw error;
3915+ }
3916+ fwrite(arr, 1, 3, f);
3917+ fflush(f);
3918+ fclose(f);
3919+ }
3920+ ASSERT_GT(count_files(cache_dir), max_files);
3921+ mac.prune();
3922+ int numfiles = count_files(cache_dir);
3923+ ASSERT_GT(numfiles, 0);
3924+ ASSERT_LE(numfiles, max_files);
3925+ mac.prune();
3926+ ASSERT_EQ(numfiles, count_files(cache_dir));
3927+}
3928+
3929+}
3930+
3931+int main(int argc, char *argv[]) {
3932+ ::testing::InitGoogleTest(&argc, argv);
3933+ return RUN_ALL_TESTS();
3934+}
3935
3936=== added directory 'tests/qml'
3937=== added file 'tests/qml/tst_image_provider.qml'
3938--- tests/qml/tst_image_provider.qml 1970-01-01 00:00:00 +0000
3939+++ tests/qml/tst_image_provider.qml 2015-02-04 08:57:20 +0000
3940@@ -0,0 +1,62 @@
3941+import QtQuick 2.0
3942+import QtTest 1.0
3943+import Ubuntu.Thumbnailer 0.1
3944+
3945+Item {
3946+ Image {
3947+ id: image
3948+ width: 200
3949+ height: 200
3950+
3951+ SignalSpy {
3952+ id: spy
3953+ target: image
3954+ signalName: "statusChanged"
3955+ }
3956+ }
3957+
3958+ Canvas {
3959+ id: canvas
3960+ width: 200
3961+ height: 200
3962+ renderStrategy: Canvas.Immediate
3963+ renderTarget: Canvas.Image
3964+ }
3965+
3966+ TestCase {
3967+ name: "ThumbnailerProviderTests"
3968+ when: windowShown
3969+
3970+ function test_albumart() {
3971+ var ctx = loadImage(
3972+ "image://albumart/artist=Gotye&album=Making%20Mirrors");
3973+ comparePixel(ctx, 0, 0, 242, 228, 209, 255);
3974+ }
3975+
3976+ function loadImage(uri) {
3977+ image.source = uri
3978+ while (image.status == Image.Loading) {
3979+ spy.wait();
3980+ }
3981+ compare(image.status, Image.Ready);
3982+
3983+ var ctx = canvas.getContext("2d");
3984+ ctx.drawImage(image, 0, 0);
3985+ return ctx;
3986+ }
3987+
3988+ function comparePixel(ctx,x,y,r,g,b,a, d) {
3989+ var c = ctx.getImageData(x,y,1,1).data;
3990+ if (d === undefined)
3991+ d = 0;
3992+ r = Math.round(r);
3993+ g = Math.round(g);
3994+ b = Math.round(b);
3995+ a = Math.round(a);
3996+ var notSame = Math.abs(c[0]-r)>d || Math.abs(c[1]-g)>d || Math.abs(c[2]-b)>d || Math.abs(c[3]-a)>d;
3997+ if (notSame)
3998+ qtest_fail('Pixel compare fail:\nactual :[' + c[0]+','+c[1]+','+c[2]+','+c[3] + ']\nexpected:['+r+','+g+','+b+','+a+'] +/- '+d, 1);
3999+
4000+ }
4001+ }
4002+}
4003
4004=== added file 'tests/testimage.jpg'
4005Binary files tests/testimage.jpg 1970-01-01 00:00:00 +0000 and tests/testimage.jpg 2015-02-04 08:57:20 +0000 differ
4006=== added file 'tests/testrotate.jpg'
4007Binary files tests/testrotate.jpg 1970-01-01 00:00:00 +0000 and tests/testrotate.jpg 2015-02-04 08:57:20 +0000 differ
4008=== added file 'tests/testsetup.h.in'
4009--- tests/testsetup.h.in 1970-01-01 00:00:00 +0000
4010+++ tests/testsetup.h.in 2015-02-04 08:57:20 +0000
4011@@ -0,0 +1,6 @@
4012+#ifndef TESTSETUP_H
4013+#define TESTSETUP_H
4014+
4015+#define TESTDATADIR "@TESTDATADIR@"
4016+
4017+#endif
4018
4019=== added file 'tests/testvideo.ogg'
4020Binary files tests/testvideo.ogg 1970-01-01 00:00:00 +0000 and tests/testvideo.ogg 2015-02-04 08:57:20 +0000 differ
4021=== added file 'tests/unique_gobj.cpp'
4022--- tests/unique_gobj.cpp 1970-01-01 00:00:00 +0000
4023+++ tests/unique_gobj.cpp 2015-02-04 08:57:20 +0000
4024@@ -0,0 +1,172 @@
4025+/*
4026+ * Copyright (C) 2013 Canonical Ltd.
4027+ *
4028+ * This program is free software: you can redistribute it and/or modify
4029+ * it under the terms of the GNU Lesser General Public License version 3 as
4030+ * published by the Free Software Foundation.
4031+ *
4032+ * This program is distributed in the hope that it will be useful,
4033+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4034+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4035+ * GNU Lesser General Public License for more details.
4036+ *
4037+ * You should have received a copy of the GNU Lesser General Public License
4038+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
4039+ *
4040+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
4041+ */
4042+
4043+#include<internal/gobj_memory.h>
4044+#include<gdk-pixbuf/gdk-pixbuf.h>
4045+#include<gtest/gtest.h>
4046+
4047+using namespace std;
4048+
4049+TEST(Unique_gobj, trivial) {
4050+ unique_gobj<GdkPixbuf> basic(gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480));
4051+ ASSERT_TRUE(bool(basic));
4052+ ASSERT_TRUE(gdk_pixbuf_get_width(basic.get()) == 640);
4053+ ASSERT_TRUE(gdk_pixbuf_get_height(basic.get()) == 480);
4054+}
4055+
4056+TEST(Unique_gobj, compare) {
4057+ GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4058+ GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4059+ if(pb1 > pb2) {
4060+ std::swap(pb1, pb2);
4061+ }
4062+ ASSERT_TRUE(pb1 < pb2);
4063+ unique_gobj<GdkPixbuf> u1(pb1);
4064+ unique_gobj<GdkPixbuf> u2(pb2);
4065+
4066+ ASSERT_TRUE(!(u1 == nullptr));
4067+ ASSERT_TRUE(u1 != nullptr);
4068+ ASSERT_TRUE(u1 != u2);
4069+ ASSERT_TRUE(!(u1 == u2));
4070+ ASSERT_TRUE(u1 < u2);
4071+ ASSERT_TRUE(!(u2 < u1));
4072+ ASSERT_TRUE(!(u1 == u2));
4073+ ASSERT_TRUE(!(u2 == u1));
4074+ ASSERT_TRUE(u1 <= u2);
4075+ ASSERT_TRUE(!(u2 <= u1));
4076+}
4077+
4078+// This is its own thing due to need to avoid double release.
4079+
4080+TEST(Unique_gobj, equality) {
4081+ GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4082+ unique_gobj<GdkPixbuf> u1(pb);
4083+ g_object_ref(G_OBJECT(pb));
4084+ unique_gobj<GdkPixbuf> u2(pb);
4085+ ASSERT_TRUE(u1 == u2);
4086+ ASSERT_TRUE(u2 == u1);
4087+ ASSERT_TRUE(!(u1 != u2));
4088+ ASSERT_TRUE(!(u2 != u1));
4089+}
4090+
4091+TEST(Unique_gobj, release) {
4092+ GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4093+ unique_gobj<GdkPixbuf> u(pb);
4094+ ASSERT_TRUE(u != nullptr);
4095+ ASSERT_TRUE(u.get() != nullptr);
4096+ ASSERT_TRUE(pb == u.release());
4097+ ASSERT_TRUE(!u);
4098+ ASSERT_TRUE(u.get() == nullptr);
4099+ g_object_unref(pb);
4100+}
4101+
4102+void sub_func(GdkPixbuf *pb) {
4103+ ASSERT_TRUE(G_OBJECT(pb)->ref_count == 2);
4104+ unique_gobj<GdkPixbuf> u(pb);
4105+ ASSERT_TRUE(G_OBJECT(pb)->ref_count == 2);
4106+ // Now it dies and refcount is reduced.
4107+}
4108+
4109+TEST(Unique_gobj, refcount) {
4110+ GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4111+ ASSERT_TRUE(G_OBJECT(pb)->ref_count == 1);
4112+ g_object_ref(G_OBJECT(pb));
4113+ sub_func(pb);
4114+ ASSERT_TRUE(G_OBJECT(pb)->ref_count == 1);
4115+ g_object_unref(G_OBJECT(pb));
4116+}
4117+
4118+TEST(Unique_gobj, swap) {
4119+ GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4120+ GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4121+ unique_gobj<GdkPixbuf> u1(pb1);
4122+ unique_gobj<GdkPixbuf> u2(pb2);
4123+
4124+ u1.swap(u2);
4125+ ASSERT_TRUE(u1.get() == pb2);
4126+ ASSERT_TRUE(u2.get() == pb1);
4127+
4128+ std::swap(u1, u2);
4129+ ASSERT_TRUE(u1.get() == pb1);
4130+ ASSERT_TRUE(u2.get() == pb2);
4131+}
4132+
4133+TEST(Unique_gobj, floating) {
4134+ GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4135+ bool got_exception = false;
4136+ g_object_force_floating(G_OBJECT(pb));
4137+ try {
4138+ unique_gobj<GdkPixbuf> u(pb);
4139+ } catch(const invalid_argument &c) {
4140+ got_exception = true;
4141+ }
4142+ g_object_unref(G_OBJECT(pb));
4143+ ASSERT_TRUE(got_exception);
4144+}
4145+
4146+TEST(Unique_gobj, move) {
4147+ GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4148+ GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4149+ g_object_ref(G_OBJECT(pb1));
4150+ unique_gobj<GdkPixbuf> u1(pb1);
4151+ unique_gobj<GdkPixbuf> u2(pb2);
4152+ u1 = std::move(u2);
4153+ ASSERT_TRUE(u1.get() == pb2);
4154+ ASSERT_TRUE(!u2);
4155+ ASSERT_TRUE(G_OBJECT(pb1)->ref_count == 1);
4156+ g_object_unref(G_OBJECT(pb1));
4157+}
4158+
4159+TEST(Unique_gobj, null) {
4160+ GdkPixbuf *pb1 = NULL;
4161+ GdkPixbuf *pb3 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4162+ unique_gobj<GdkPixbuf> u1(pb1);
4163+ unique_gobj<GdkPixbuf> u2(nullptr);
4164+ unique_gobj<GdkPixbuf> u3(pb3);
4165+
4166+ ASSERT_TRUE(!u1);
4167+ ASSERT_TRUE(!u2);
4168+ u3 = nullptr;
4169+ ASSERT_TRUE(!u3);
4170+}
4171+
4172+TEST(Unique_gobj, reset) {
4173+ GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4174+ GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
4175+ unique_gobj<GdkPixbuf> u(pb1);
4176+
4177+ u.reset(pb2);
4178+ ASSERT_TRUE(u.get() == pb2);
4179+ u.reset(nullptr);
4180+ ASSERT_TRUE(!u);
4181+}
4182+
4183+TEST(Unique_gobj, sizeoftest) {
4184+ ASSERT_TRUE(sizeof(GdkPixbuf*) == sizeof(unique_gobj<GdkPixbuf>));
4185+}
4186+
4187+TEST(Unique_gobj, deleter) {
4188+ unique_gobj<GdkPixbuf> u1;
4189+ ASSERT_TRUE(u1.get_deleter() == g_object_unref);
4190+}
4191+
4192+int main(int argc, char **argv) {
4193+ g_type_init(); // Still needed in precise.
4194+ ::testing::InitGoogleTest(&argc, argv);
4195+ return RUN_ALL_TESTS();
4196+}
4197
4198=== added directory 'tools'
4199=== renamed directory 'tools' => 'tools.moved'
4200=== added file 'tools/CMakeLists.txt'
4201--- tools/CMakeLists.txt 1970-01-01 00:00:00 +0000
4202+++ tools/CMakeLists.txt 2015-02-04 08:57:20 +0000
4203@@ -0,0 +1,11 @@
4204+#add_executable(imdump imdump.cpp)
4205+#target_link_libraries(imdump thumbnailer ${GST_DEPS_LDFLAGS})
4206+
4207+add_executable(scaler scaler.cpp ../src/imagescaler.cpp)
4208+target_link_libraries(scaler ${IMG_DEPS_LDFLAGS})
4209+
4210+add_executable(cachetool cachetool.cpp)
4211+target_link_libraries(cachetool thumbnailer)
4212+
4213+add_executable(lastfmtest lastfmtest.cpp ../src/lastfmdownloader.cpp ../src/soupdownloader.cpp)
4214+target_link_libraries(lastfmtest ${SOUP_DEPS_LDFLAGS} ${XML_DEPS_LDFLAGS})
4215
4216=== added file 'tools/cachetool.cpp'
4217--- tools/cachetool.cpp 1970-01-01 00:00:00 +0000
4218+++ tools/cachetool.cpp 2015-02-04 08:57:20 +0000
4219@@ -0,0 +1,37 @@
4220+/*
4221+ * Copyright (C) 2013 Canonical Ltd.
4222+ *
4223+ * This program is free software: you can redistribute it and/or modify
4224+ * it under the terms of the GNU Lesser General Public License version 3 as
4225+ * published by the Free Software Foundation.
4226+ *
4227+ * This program is distributed in the hope that it will be useful,
4228+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4229+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4230+ * GNU Lesser General Public License for more details.
4231+ *
4232+ * You should have received a copy of the GNU Lesser General Public License
4233+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
4234+ *
4235+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
4236+ */
4237+
4238+#include<thumbnailer.h>
4239+#include<cstdio>
4240+#include<gst/gst.h>
4241+#include<stdexcept>
4242+
4243+int main(int argc, char **argv) {
4244+ Thumbnailer t;
4245+ if(argc != 2) {
4246+ printf("%s <file name>\n", argv[0]);
4247+ return 1;
4248+ }
4249+ std::string ifilename(argv[1]);
4250+ std::string ofilename = t.get_thumbnail(ifilename, TN_SIZE_LARGE);
4251+ if(ofilename.empty())
4252+ printf("Thumbnail could not be generated.\n");
4253+ else
4254+ printf("Thumbnail file is %s.\n", ofilename.c_str());
4255+ return 0;
4256+}
4257
4258=== added file 'tools/imdump.cpp'
4259--- tools/imdump.cpp 1970-01-01 00:00:00 +0000
4260+++ tools/imdump.cpp 2015-02-04 08:57:20 +0000
4261@@ -0,0 +1,34 @@
4262+/*
4263+ * Copyright (C) 2013 Canonical Ltd.
4264+ *
4265+ * This program is free software: you can redistribute it and/or modify
4266+ * it under the terms of the GNU Lesser General Public License version 3 as
4267+ * published by the Free Software Foundation.
4268+ *
4269+ * This program is distributed in the hope that it will be useful,
4270+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4271+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4272+ * GNU Lesser General Public License for more details.
4273+ *
4274+ * You should have received a copy of the GNU Lesser General Public License
4275+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
4276+ *
4277+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
4278+ */
4279+
4280+#include<internal/audioimageextractor.h>
4281+#include<cstdio>
4282+#include<gst/gst.h>
4283+#include<stdexcept>
4284+
4285+int main(int argc, char **argv) {
4286+ gst_init(&argc, &argv);
4287+ AudioImageExtractor ae;
4288+ try {
4289+ ae.extract(argv[1], argv[2]);
4290+ } catch(std::runtime_error &e) {
4291+ printf("Failed: %s\n", e.what());
4292+ return 1;
4293+ }
4294+ return 0;
4295+}
4296
4297=== added file 'tools/lastfmtest.cpp'
4298--- tools/lastfmtest.cpp 1970-01-01 00:00:00 +0000
4299+++ tools/lastfmtest.cpp 2015-02-04 08:57:20 +0000
4300@@ -0,0 +1,31 @@
4301+/*
4302+ * Copyright (C) 2013 Canonical Ltd.
4303+ *
4304+ * This program is free software: you can redistribute it and/or modify
4305+ * it under the terms of the GNU Lesser General Public License version 3 as
4306+ * published by the Free Software Foundation.
4307+ *
4308+ * This program is distributed in the hope that it will be useful,
4309+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4310+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4311+ * GNU Lesser General Public License for more details.
4312+ *
4313+ * You should have received a copy of the GNU Lesser General Public License
4314+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
4315+ *
4316+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
4317+ */
4318+
4319+#include<string>
4320+#include<cstdio>
4321+
4322+#include<internal/lastfmdownloader.h>
4323+#include<memory>
4324+
4325+using namespace std;
4326+
4327+int main(int /*argc*/, char **/*argv*/) {
4328+ LastFMDownloader dl;
4329+ dl.download("The Prodigy", "Music for the Jilted Generation", "image.jpg");
4330+ return 0;
4331+}
4332
4333=== added file 'tools/scaler.cpp'
4334--- tools/scaler.cpp 1970-01-01 00:00:00 +0000
4335+++ tools/scaler.cpp 2015-02-04 08:57:20 +0000
4336@@ -0,0 +1,35 @@
4337+/*
4338+ * Copyright (C) 2013 Canonical Ltd.
4339+ *
4340+ * This program is free software: you can redistribute it and/or modify
4341+ * it under the terms of the GNU Lesser General Public License version 3 as
4342+ * published by the Free Software Foundation.
4343+ *
4344+ * This program is distributed in the hope that it will be useful,
4345+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4346+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4347+ * GNU Lesser General Public License for more details.
4348+ *
4349+ * You should have received a copy of the GNU Lesser General Public License
4350+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
4351+ *
4352+ * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
4353+ */
4354+
4355+#include<internal/imagescaler.h>
4356+#include<cstdio>
4357+#include<gst/gst.h>
4358+#include<stdexcept>
4359+
4360+int main(int argc, char **argv) {
4361+ ImageScaler sc;
4362+ try {
4363+ std::string ifilename(argv[1]);
4364+ std::string ofilename(argv[2]);
4365+ sc.scale(ifilename, ofilename, TN_SIZE_LARGE, ifilename);
4366+ } catch(std::runtime_error &e) {
4367+ printf("Failed: %s\n", e.what());
4368+ return 1;
4369+ }
4370+ return 0;
4371+}

Subscribers

People subscribed via source and target branches

to all changes: