This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
/
FFmpegProtocols.java
83 lines (70 loc) · 2.37 KB
/
FFmpegProtocols.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* PS3 Media Server, for streaming any media to your PS3.
* Copyright (C) 2008-2013 A.Brochard
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.pms.encoders;
import java.util.ArrayList;
import java.util.List;
import net.pms.PMS;
import net.pms.configuration.PmsConfiguration;
import net.pms.util.ProcessUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A helper class that provides access to the list of protocols supported by FFmpeg.
*/
public final class FFmpegProtocols {
private final Logger logger = LoggerFactory.getLogger(FFmpegProtocols.class);
private final List<String> protocols = new ArrayList<String>();
private final PmsConfiguration configuration;
private boolean convertMmsToMmsh = false;
// package-private constructor
FFmpegProtocols(PmsConfiguration configuration) {
this.configuration = configuration;
queryProtocols();
if (!protocols.contains("mms") && protocols.contains("mmsh")) {
protocols.add("mms");
convertMmsToMmsh = true;
}
logger.debug("FFmpeg supported protocols: {}", protocols);
}
public boolean isSupportedProtocol(String protocol) {
return protocols.contains(protocol);
}
public String getFilename(String filename) {
// XXX work around an ffmpeg bug: http://ffmpeg.org/trac/ffmpeg/ticket/998
if (convertMmsToMmsh) {
if (filename.startsWith("mms:")) {
filename = "mmsh:" + filename.substring(4);
}
}
return filename;
}
private void queryProtocols() {
String output = ProcessUtil.run(configuration.getFfmpegPath(), "-protocols");
boolean add = false;
for (String line : output.split("\n")) {
if (line.equals("Input:")) {
add = true;
} else if (line.equals("Output:")) {
break;
} else if (add) {
protocols.add(line);
}
}
}
}