mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 00:38:52 -05:00
Refactor media info cache synchronization
This commit is contained in:
parent
8f12961fe8
commit
53226d0809
@ -1013,7 +1013,7 @@ public class MediaBindingBean {
|
||||
return getMediaFile();
|
||||
}
|
||||
|
||||
private static final Map<File, MediaInfo> sharedMediaInfoObjects = new WeakValueHashMap<File, MediaInfo>(64);
|
||||
private static final Map<File, MediaInfo> sharedMediaInfoObjects = synchronizedMap(new WeakValueHashMap<File, MediaInfo>(64));
|
||||
|
||||
private synchronized MediaInfo getMediaInfo() {
|
||||
// lazy initialize
|
||||
@ -1021,7 +1021,6 @@ public class MediaBindingBean {
|
||||
// use inferred media file (e.g. actual movie file instead of subtitle file)
|
||||
File inferredMediaFile = getInferredMediaFile();
|
||||
|
||||
synchronized (sharedMediaInfoObjects) {
|
||||
mediaInfo = sharedMediaInfoObjects.computeIfAbsent(inferredMediaFile, f -> {
|
||||
try {
|
||||
return new MediaInfo().open(f);
|
||||
@ -1030,7 +1029,6 @@ public class MediaBindingBean {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return mediaInfo;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||
|
||||
private Map<String, Object> getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) {
|
||||
try {
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
Map<String, Object> props = new HashMap<String, Object>(2);
|
||||
float fps = Math.round(subtitle.getMovieFPS()); // round because most FPS values in the database are bad anyway
|
||||
if (fps > 0) {
|
||||
props.put(FPS, fps);
|
||||
@ -179,15 +179,12 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||
return emptyMap();
|
||||
}
|
||||
|
||||
private final Map<File, Map<String, Object>> mediaInfoCache = new WeakHashMap<File, Map<String, Object>>(64);
|
||||
private final Map<File, Map<String, Object>> mediaInfoCache = synchronizedMap(new WeakHashMap<File, Map<String, Object>>(64));
|
||||
|
||||
private Map<String, Object> getVideoProperties(File file) {
|
||||
synchronized (mediaInfoCache) {
|
||||
return mediaInfoCache.computeIfAbsent(file, (f) -> {
|
||||
try {
|
||||
Map<String, Object> props = new HashMap<String, Object>();
|
||||
MediaInfo mediaInfo = new MediaInfo().open(file);
|
||||
|
||||
return mediaInfoCache.computeIfAbsent(file, key -> {
|
||||
try (MediaInfo mediaInfo = new MediaInfo().open(file)) {
|
||||
Map<String, Object> props = new HashMap<String, Object>(2);
|
||||
float fps = Math.round(Float.parseFloat(mediaInfo.get(StreamKind.Video, 0, "FrameRate")));
|
||||
if (fps > 0) {
|
||||
props.put(FPS, fps);
|
||||
@ -203,7 +200,6 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||
return emptyMap();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// inner metric
|
||||
|
Loading…
Reference in New Issue
Block a user