~ubuntu-branches/ubuntu/wily/thumbnailer/wily

« back to all changes in this revision

Viewing changes to src/vs-thumb/test-seq.cpp

  • Committer: Package Import Robot
  • Author(s): Michi Henning, Michi Henning, James Henstridge, Xavi Garcia, Albert Astals Cid, CI Train Bot
  • Date: 2015-09-15 11:04:14 UTC
  • mfrom: (1.1.31)
  • Revision ID: package-import@ubuntu.com-20150915110414-h5bpkfo7cj3vm54v
Tags: 2.3+15.10.20150915.1-0ubuntu1
[ Michi Henning ]
* Added man pages for thumbnailer-admin, thumbnailer-service,
  thumbnailer-settings, and vs-thumb.
* Removed a bunch of lintian warnings and errors.
* Removed source for persistent cache.
* Added inactivity timeout to admin interface, so the service
  exits after 30 seconds if it is started only to, for example,
  retrieve the stats. Activity on the admin interface now keeps
  the service alive the same way activity on the thumbnailer interface does.
* Added average hit and miss run length to stats returned by
  thumbnailer-admin.
* Changed semantics for requests with (0,0) size. All requests are now
  clamped to a 1920x1920 bounding box.
* Fixed incorrect timeout semantics for unexpected network errors.

[ James Henstridge ]
* Renamed QML package to qml-module-XXX format and add transitional
  package. (LP: #1342031)
* Port QML module to use libthumbnailer-qt.

[ Xavi Garcia ]
* Add new libthumbnailer-qt1.0 library, providing a C++ client API.

[ Albert Astals Cid ]
* In QML image provider, only create QQuickTextureFactory when
  needed, fixing a memory leak when requests are cancelled. (LP:
  #1484914)

[ CI Train Bot ]
* debian/libthumbnailer-qt1.0.symbols: update to released version.
* New rebuild forced.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: James Henstridge <james.henstridge@canonical.com>
 
17
 */
 
18
 
 
19
#include <cstdio>
 
20
#include <string>
 
21
#include <memory>
 
22
#include <stdexcept>
 
23
#pragma GCC diagnostic push
 
24
#pragma GCC diagnostic ignored "-Wold-style-cast"
 
25
#pragma GCC diagnostic ignored "-Wcast-qual"
 
26
#pragma GCC diagnostic ignored "-Wcast-align"
 
27
#include <gst/gst.h>
 
28
#include <gio/gio.h>
 
29
#include <glib.h>
 
30
#pragma GCC diagnostic pop
 
31
 
 
32
#include "thumbnailextractor.h"
 
33
 
 
34
using namespace std;
 
35
using namespace unity::thumbnailer::internal;
 
36
 
 
37
namespace
 
38
{
 
39
 
 
40
string command_line_arg_to_uri(string const& arg)
 
41
{
 
42
    unique_ptr<GFile, decltype(&g_object_unref)> file(g_file_new_for_commandline_arg(arg.c_str()), g_object_unref);
 
43
    if (!file)
 
44
    {
 
45
        throw runtime_error("Could not create parse argument as file");
 
46
    }
 
47
    char* c_uri = g_file_get_uri(file.get());
 
48
    if (!c_uri)
 
49
    {
 
50
        throw runtime_error("Could not convert to uri");
 
51
    }
 
52
    string uri(c_uri);
 
53
    g_free(c_uri);
 
54
    return uri;
 
55
}
 
56
 
 
57
}
 
58
 
 
59
int main(int argc, char** argv)
 
60
{
 
61
    gst_init(&argc, &argv);
 
62
 
 
63
    std::unique_ptr<GMainLoop, decltype(&g_main_loop_unref)> main_loop(
 
64
        g_main_loop_new(nullptr, false), g_main_loop_unref);
 
65
    bool success = true;
 
66
    ThumbnailExtractor extractor;
 
67
    for (int i = 1; i < argc; i++)
 
68
    {
 
69
        string uri;
 
70
        try
 
71
        {
 
72
            uri = command_line_arg_to_uri(argv[i]);
 
73
        }
 
74
        catch (exception const& e)
 
75
        {
 
76
            fprintf(stderr, "Error parsing \"%s\": %s\n", argv[i], e.what());
 
77
            return 1;
 
78
        }
 
79
        printf("Extracting from %s\n", uri.c_str());
 
80
        try
 
81
        {
 
82
            extractor.set_uri(uri);
 
83
            if (extractor.has_video())
 
84
            {
 
85
                success = extractor.extract_video_frame();
 
86
            }
 
87
            else
 
88
            {
 
89
                success = extractor.extract_audio_cover_art();
 
90
            }
 
91
        }
 
92
        catch (exception const& e)
 
93
        {
 
94
            fprintf(stderr, "Error extracting content \"%s\": %s\n", argv[1], e.what());
 
95
            return 1;
 
96
        }
 
97
        if (!success) break;
 
98
    }
 
99
 
 
100
    return success ? 0 : 1;
 
101
}