41
41
bool supports_decoder(const std::string& format)
43
static std::set<std::string> formats;
43
typedef std::unique_ptr<GstCaps, decltype(&gst_caps_unref)> CapsPtr;
44
static std::vector<CapsPtr> formats;
45
46
if (formats.empty())
63
std::unique_ptr<GstCaps, decltype(&gst_caps_unref)> caps(gst_static_caps_get(&t->static_caps),
65
for (unsigned int i = 0; i < gst_caps_get_size(caps.get()); i++)
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),
65
if (gst_caps_is_any(caps.get())) {
68
formats.emplace_back(std::move(caps));
74
return formats.find(format) != formats.end();
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);
80
for (const auto &other : formats) {
81
if (gst_caps_is_always_compatible(caps.get(), other.get())) {
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");
163
174
EXPECT_EQ(st.st_mtime, file.getModificationTime());
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");
184
string testfile = SOURCE_DIR "/media/testfile.m4a";
185
MediaFile file = e.extract(e.detect(testfile));
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());
199
ASSERT_EQ(0, stat(testfile.c_str(), &st));
200
EXPECT_EQ(st.st_mtime, file.getModificationTime());
166
203
TEST_F(MetadataExtractorTest, extract_video) {
167
204
MetadataExtractor e;
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");