~jamesh/mediascanner2/folder-coverart

« back to all changes in this revision

Viewing changes to test/test_metadataextractor.cc

  • Committer: CI Train Bot
  • Author(s): James Henstridge
  • Date: 2015-11-02 02:52:41 UTC
  • mfrom: (308.3.3 m4a-thumbnail)
  • Revision ID: ci-train-bot@canonical.com-20151102025241-66kyt26kvnx1nwry
Fix the metadata extractor so that it correctly extracts the date and presence of cover art from MPEG 4 audio files. Fixes: #1492407
Approved by: PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
bool supports_decoder(const std::string& format)
42
42
{
43
 
    static std::set<std::string> formats;
 
43
    typedef std::unique_ptr<GstCaps, decltype(&gst_caps_unref)> CapsPtr;
 
44
    static std::vector<CapsPtr> formats;
44
45
 
45
46
    if (formats.empty())
46
47
    {
59
60
                {
60
61
                    continue;
61
62
                }
62
 
 
63
 
                std::unique_ptr<GstCaps, decltype(&gst_caps_unref)> caps(gst_static_caps_get(&t->static_caps),
64
 
                                                                         gst_caps_unref);
65
 
                for (unsigned int i = 0; i < gst_caps_get_size(caps.get()); i++)
66
 
                {
67
 
                    const auto structure = gst_caps_get_structure(caps.get(), i);
68
 
                    formats.emplace(gst_structure_get_name(structure));
 
63
                CapsPtr caps(gst_static_caps_get(&t->static_caps),
 
64
                             gst_caps_unref);
 
65
                if (gst_caps_is_any(caps.get())) {
 
66
                    continue;
69
67
                }
 
68
                formats.emplace_back(std::move(caps));
70
69
            }
71
70
        }
72
71
    }
73
72
 
74
 
    return formats.find(format) != formats.end();
 
73
    char *end = nullptr;
 
74
    GstStructure *structure = gst_structure_from_string(format.c_str(), &end);
 
75
    assert(structure != nullptr);
 
76
    assert(end == format.c_str() + format.size());
 
77
    // GstCaps adopts the GstStructure
 
78
    CapsPtr caps(gst_caps_new_full(structure, nullptr), gst_caps_unref);
 
79
 
 
80
    for (const auto &other : formats) {
 
81
        if (gst_caps_is_always_compatible(caps.get(), other.get())) {
 
82
            return true;
 
83
        }
 
84
    }
 
85
    return false;
75
86
}
76
87
 
77
88
}
142
153
}
143
154
 
144
155
TEST_F(MetadataExtractorTest, extract_mp3) {
145
 
    if (!supports_decoder("audio/mpeg")) {
 
156
    if (!supports_decoder("audio/mpeg, mpegversion=(int)1, layer=(int)3")) {
146
157
        printf("MP3 codec not supported\n");
147
158
        return;
148
159
    }
163
174
    EXPECT_EQ(st.st_mtime, file.getModificationTime());
164
175
}
165
176
 
 
177
TEST_F(MetadataExtractorTest, extract_m4a) {
 
178
    if (!supports_decoder("audio/mpeg, mpegversion=(int)4, stream-format=(string)raw")) {
 
179
        printf("M4A codec not supported\n");
 
180
        return;
 
181
    }
 
182
 
 
183
    MetadataExtractor e;
 
184
    string testfile = SOURCE_DIR "/media/testfile.m4a";
 
185
    MediaFile file = e.extract(e.detect(testfile));
 
186
 
 
187
    EXPECT_EQ(AudioMedia, file.getType());
 
188
    EXPECT_EQ("Title", file.getTitle());
 
189
    EXPECT_EQ("Artist", file.getAuthor());
 
190
    EXPECT_EQ("Album", file.getAlbum());
 
191
    EXPECT_EQ("Album Artist", file.getAlbumArtist());
 
192
    EXPECT_EQ("2015-10-07", file.getDate());
 
193
    EXPECT_EQ(4, file.getTrackNumber());
 
194
    EXPECT_EQ(1, file.getDiscNumber());
 
195
    EXPECT_EQ(1, file.getDuration());
 
196
    EXPECT_EQ("Rock", file.getGenre());
 
197
    EXPECT_EQ(true, file.getHasThumbnail());
 
198
    struct stat st;
 
199
    ASSERT_EQ(0, stat(testfile.c_str(), &st));
 
200
    EXPECT_EQ(st.st_mtime, file.getModificationTime());
 
201
}
 
202
 
166
203
TEST_F(MetadataExtractorTest, extract_video) {
167
204
    MetadataExtractor e;
168
205
 
220
257
}
221
258
 
222
259
TEST_F(MetadataExtractorTest, extract_mp3_bad_date) {
223
 
    if (!supports_decoder("audio/mpeg")) {
 
260
    if (!supports_decoder("audio/mpeg, mpegversion=(int)1, layer=(int)3")) {
224
261
        printf("MP3 codec not supported\n");
225
262
        return;
226
263
    }