-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
376 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <stdio.h> | ||
#include <strings.h> | ||
#include <map> | ||
#include <string> | ||
#include <scx/Conv.h> | ||
#include <scx/FileHelper.h> | ||
using namespace scx; | ||
#include <plugin/FormatProbeProto.h> | ||
using namespace mous; | ||
#ifdef ENABLE_CAF | ||
#include "ProbeCaf.h" | ||
#endif | ||
#ifdef ENABLE_MP4 | ||
#include "ProbeMp4.h" | ||
#endif | ||
|
||
using ProbeFunc = const char* (*)(void* ptr, const char* path); | ||
|
||
namespace { | ||
struct Self { | ||
const std::map<std::string, ProbeFunc> probes { | ||
#ifdef ENABLE_CAF | ||
{ "caf", ProbeCaf }, | ||
#endif | ||
#ifdef ENABLE_MP4 | ||
{ "alac", ProbeMp4 }, | ||
{ "m4a", ProbeMp4 }, | ||
{ "mp4", ProbeMp4 }, | ||
#endif | ||
}; | ||
}; | ||
} | ||
|
||
static void* Create(void) { | ||
return new Self; | ||
} | ||
|
||
static void Destroy(void* ptr) { | ||
delete SELF; | ||
} | ||
|
||
static const char* Probe(void* ptr, const char* path) { | ||
const auto& suffix = ToLower(FileHelper::FileSuffix(path)); | ||
const auto iter = SELF->probes.find(suffix); | ||
return iter != SELF->probes.end() ? iter->second(ptr, path) : nullptr; | ||
} | ||
|
||
static const BaseOption** GetOptions(void* ptr) { | ||
(void) ptr; | ||
return nullptr; | ||
} | ||
|
||
const char** GetSuffixes(void* ptr) { | ||
(void) ptr; | ||
static const char* suffixes[] { | ||
"alac", | ||
#ifdef ENABLE_CAF | ||
"caf", | ||
#endif | ||
#ifdef ENABLE_MP4 | ||
"m4a", | ||
"mp4", | ||
#endif | ||
nullptr | ||
}; | ||
return suffixes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <util/PluginHelper.h> | ||
using namespace mous; | ||
|
||
MOUS_EXPORT_PLUGIN( | ||
PluginType::FormatProbe, | ||
"format-probe", | ||
"Format Probe", | ||
2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
static const char* ProbeCaf(void* ptr, const char* path) { | ||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <mp4v2/mp4v2.h> | ||
|
||
namespace { | ||
struct MP4File { | ||
explicit MP4File(const char* path) { | ||
handle = MP4Read(path); | ||
} | ||
~MP4File() { | ||
if (handle) { | ||
MP4Close(handle); | ||
handle = nullptr; | ||
} | ||
} | ||
operator bool() const { | ||
return handle; | ||
} | ||
MP4FileHandle handle = nullptr; | ||
}; | ||
} | ||
|
||
static const char* ProbeMp4(void* ptr, const char* path) { | ||
MP4File file(path); | ||
if (!file) { | ||
return nullptr; | ||
} | ||
MP4TrackId trackid = MP4_INVALID_TRACK_ID; | ||
auto ntrack = MP4GetNumberOfTracks(file.handle); | ||
for (decltype(ntrack) itrack = 0; itrack < ntrack; ++itrack) { | ||
trackid = MP4FindTrackId(file.handle, itrack); | ||
if (trackid != MP4_INVALID_TRACK_ID) { | ||
const auto type = MP4GetTrackType(file.handle, trackid); | ||
if (MP4_IS_AUDIO_TRACK_TYPE(type)) { | ||
break; | ||
}; | ||
} | ||
} | ||
if (trackid == MP4_INVALID_TRACK_ID) { | ||
return nullptr; | ||
} | ||
const char* media_data_name = MP4GetTrackMediaDataName(file.handle, trackid); | ||
if (strcasecmp(media_data_name, "mp4a") == 0) { | ||
const auto type = MP4GetTrackEsdsObjectTypeId(file.handle, trackid); | ||
if (type == MP4_MPEG4_AUDIO_TYPE) { | ||
return "aac"; | ||
} | ||
} | ||
if (strcasecmp(media_data_name, "alac") == 0) { | ||
return "alac"; | ||
} | ||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.