Search in sources :

Example 6 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class StatusTab method updateCurrentBitrate.

public void updateCurrentBitrate() {
    long total = 0;
    List<RendererConfiguration> foundRenderers = PMS.get().getFoundRenderers();
    synchronized (foundRenderers) {
        for (RendererConfiguration r : foundRenderers) {
            total += r.getBuffer();
        }
    }
    if (total == 0) {
        currentBitrate.setText("0");
    }
}
Also used : RendererConfiguration(net.pms.configuration.RendererConfiguration)

Example 7 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class StatusTab method updateMemoryUsage.

public void updateMemoryUsage() {
    final long max = Runtime.getRuntime().maxMemory() / 1048576;
    final long used = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576;
    long buf = 0;
    List<RendererConfiguration> foundRenderers = PMS.get().getFoundRenderers();
    synchronized (foundRenderers) {
        for (RendererConfiguration r : PMS.get().getFoundRenderers()) {
            buf += (r.getBuffer());
        }
    }
    final long buffer = buf;
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            memBarUI.setValues(0, (int) max, (int) (used - buffer), (int) buffer);
        }
    });
}
Also used : RendererConfiguration(net.pms.configuration.RendererConfiguration)

Example 8 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class RemoteMediaHandler method handle.

@Override
public void handle(HttpExchange httpExchange) throws IOException {
    if (RemoteUtil.deny(httpExchange)) {
        throw new IOException("Access denied");
    }
    RootFolder root = parent.getRoot(RemoteUtil.userName(httpExchange), httpExchange);
    if (root == null) {
        throw new IOException("Unknown root");
    }
    Headers h = httpExchange.getRequestHeaders();
    for (String h1 : h.keySet()) {
        LOGGER.debug("key " + h1 + "=" + h.get(h1));
    }
    String id = RemoteUtil.getId(path, httpExchange);
    id = RemoteUtil.strip(id);
    RendererConfiguration defaultRenderer = renderer;
    if (renderer == null) {
        defaultRenderer = root.getDefaultRenderer();
    }
    DLNAResource resource = root.getDLNAResource(id, defaultRenderer);
    if (resource == null) {
        // another error
        LOGGER.debug("media unkonwn");
        throw new IOException("Bad id");
    }
    if (!resource.isCodeValid(resource)) {
        LOGGER.debug("coded object with invalid code");
        throw new IOException("Bad code");
    }
    DLNAMediaSubtitle sid = null;
    String mimeType = root.getDefaultRenderer().getMimeType(resource.mimeType(), resource.getMedia());
    // DLNAResource dlna = res.get(0);
    WebRender renderer = (WebRender) defaultRenderer;
    DLNAMediaInfo media = resource.getMedia();
    if (media == null) {
        media = new DLNAMediaInfo();
        resource.setMedia(media);
    }
    if (mimeType.equals(FormatConfiguration.MIMETYPE_AUTO) && media.getMimeType() != null) {
        mimeType = media.getMimeType();
    }
    int code = 200;
    resource.setDefaultRenderer(defaultRenderer);
    if (resource.getFormat().isVideo()) {
        if (flash) {
            mimeType = "video/flash";
        } else if (!RemoteUtil.directmime(mimeType) || RemoteUtil.transMp4(mimeType, media)) {
            mimeType = renderer != null ? renderer.getVideoMimeType() : RemoteUtil.transMime();
            if (FileUtil.isUrl(resource.getSystemName())) {
                resource.setPlayer(new FFmpegWebVideo());
            } else if (!(resource instanceof DVDISOTitle)) {
                resource.setPlayer(new FFMpegVideo());
            }
        // code = 206;
        }
        if (PMS.getConfiguration().getWebSubs() && resource.getMediaSubtitle() != null && resource.getMediaSubtitle().isExternal()) {
            // fetched on the side
            sid = resource.getMediaSubtitle();
            resource.setMediaSubtitle(null);
        }
    }
    if (!RemoteUtil.directmime(mimeType) && resource.getFormat().isAudio()) {
        resource.setPlayer(new FFmpegAudio());
        code = 206;
    }
    media.setMimeType(mimeType);
    Range.Byte range = RemoteUtil.parseRange(httpExchange.getRequestHeaders(), resource.length());
    LOGGER.debug("Sending {} with mime type {} to {}", resource, mimeType, renderer);
    InputStream in = resource.getInputStream(range, root.getDefaultRenderer());
    if (range.getEnd() == 0) {
        // For web resources actual length may be unknown until we open the stream
        range.setEnd(resource.length());
    }
    Headers headers = httpExchange.getResponseHeaders();
    headers.add("Content-Type", mimeType);
    headers.add("Accept-Ranges", "bytes");
    long end = range.getEnd();
    long start = range.getStart();
    String rStr = start + "-" + end + "/*";
    headers.add("Content-Range", "bytes " + rStr);
    if (start != 0) {
        code = 206;
    }
    headers.add("Server", PMS.get().getServerName());
    headers.add("Connection", "keep-alive");
    httpExchange.sendResponseHeaders(code, 0);
    OutputStream os = httpExchange.getResponseBody();
    if (renderer != null) {
        renderer.start(resource);
    }
    if (sid != null) {
        resource.setMediaSubtitle(sid);
    }
    RemoteUtil.dump(in, os, renderer);
}
Also used : WebRender(net.pms.configuration.WebRender) Headers(com.sun.net.httpserver.Headers) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FFMpegVideo(net.pms.encoders.FFMpegVideo) IOException(java.io.IOException) FFmpegAudio(net.pms.encoders.FFmpegAudio) RendererConfiguration(net.pms.configuration.RendererConfiguration) FFmpegWebVideo(net.pms.encoders.FFmpegWebVideo)

Example 9 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class RemoteUtil method matchRenderer.

public static WebRender matchRenderer(String user, HttpExchange t) {
    int browser = WebRender.getBrowser(t.getRequestHeaders().getFirst("User-agent"));
    String confName = WebRender.getBrowserName(browser);
    RendererConfiguration r = RendererConfiguration.find(confName, t.getRemoteAddress().getAddress());
    return ((r instanceof WebRender) && (StringUtils.isBlank(user) || user.equals(((WebRender) r).getUser()))) ? (WebRender) r : null;
}
Also used : WebRender(net.pms.configuration.WebRender) RendererConfiguration(net.pms.configuration.RendererConfiguration)

Example 10 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class FFMpegVideo method getVideoTranscodeOptions.

/**
 * Returns a list of <code>String</code>s representing ffmpeg output
 * options (i.e. options that define the output file's video codec,
 * audio codec and container) compatible with the renderer's
 * <code>TranscodeVideo</code> profile.
 *
 * @param dlna
 * @param media the media metadata for the video being streamed. May contain unset/null values (e.g. for web videos).
 * @param params output parameters
 *
 * @return a {@link List} of <code>String</code>s representing the FFmpeg output parameters for the renderer according
 * to its <code>TranscodeVideo</code> profile.
 */
public synchronized List<String> getVideoTranscodeOptions(DLNAResource dlna, DLNAMediaInfo media, OutputParams params) {
    List<String> transcodeOptions = new ArrayList<>();
    final String filename = dlna.getFileName();
    final RendererConfiguration renderer = params.mediaRenderer;
    String customFFmpegOptions = renderer.getCustomFFmpegOptions();
    if ((renderer.isTranscodeToWMV() && !renderer.isXbox360()) || (renderer.isXboxOne() && purpose() == VIDEO_WEBSTREAM_PLAYER)) {
        // WMV
        transcodeOptions.add("-c:v");
        transcodeOptions.add("wmv2");
        if (!customFFmpegOptions.contains("-c:a ")) {
            transcodeOptions.add("-c:a");
            transcodeOptions.add("wmav2");
        }
        transcodeOptions.add("-f");
        transcodeOptions.add("asf");
    } else {
        // MPEGPSMPEG2AC3, MPEGTSMPEG2AC3, MPEGTSH264AC3 or MPEGTSH264AAC
        final boolean isTsMuxeRVideoEngineEnabled = configuration.getEnginesAsList(PMS.get().getRegistry()).contains(TsMuxeRVideo.ID);
        // Output audio codec
        dtsRemux = isTsMuxeRVideoEngineEnabled && configuration.isAudioEmbedDtsInPcm() && params.aid != null && params.aid.isDTS() && !avisynth() && renderer.isDTSPlayable();
        boolean isSubtitlesAndTimeseek = !isDisableSubtitles(params) && params.timeseek > 0;
        if (configuration.isAudioRemuxAC3() && params.aid != null && params.aid.isAC3() && !avisynth() && renderer.isTranscodeToAC3() && !isSubtitlesAndTimeseek) {
            // AC-3 remux
            if (!customFFmpegOptions.contains("-c:a ")) {
                transcodeOptions.add("-c:a");
                transcodeOptions.add("copy");
            }
        } else {
            if (dtsRemux) {
                // Audio is added in a separate process later
                transcodeOptions.add("-an");
            } else if (type() == Format.AUDIO) {
            // Skip
            } else if (renderer.isTranscodeToAAC()) {
                transcodeOptions.add("-c:a");
                transcodeOptions.add("aac");
            } else {
                if (!customFFmpegOptions.contains("-c:a ")) {
                    transcodeOptions.add("-c:a");
                    transcodeOptions.add("ac3");
                }
            }
        }
        InputFile newInput = null;
        if (filename != null) {
            newInput = new InputFile();
            newInput.setFilename(filename);
            newInput.setPush(params.stdin);
        }
        // Output video codec
        if (renderer.isTranscodeToH264() || renderer.isTranscodeToH265()) {
            if (!customFFmpegOptions.contains("-c:v")) {
                transcodeOptions.add("-c:v");
                if (renderer.isTranscodeToH264()) {
                    transcodeOptions.add("libx264");
                } else {
                    transcodeOptions.add("libx265");
                }
                transcodeOptions.add("-tune");
                transcodeOptions.add("zerolatency");
            }
            if (!customFFmpegOptions.contains("-preset")) {
                transcodeOptions.add("-preset");
                transcodeOptions.add("ultrafast");
            }
            if (!customFFmpegOptions.contains("-level")) {
                transcodeOptions.add("-level");
                transcodeOptions.add("31");
            }
            transcodeOptions.add("-pix_fmt");
            transcodeOptions.add("yuv420p");
        } else if (!dtsRemux) {
            transcodeOptions.add("-c:v");
            transcodeOptions.add("mpeg2video");
        }
        if (!customFFmpegOptions.contains("-f")) {
            // Output file format
            transcodeOptions.add("-f");
            if (dtsRemux) {
                transcodeOptions.add("mpeg2video");
            } else if (renderer.isTranscodeToMPEGTS()) {
                transcodeOptions.add("mpegts");
            } else {
                transcodeOptions.add("vob");
            }
        }
    }
    return transcodeOptions;
}
Also used : ArrayList(java.util.ArrayList) RendererConfiguration(net.pms.configuration.RendererConfiguration) InputFile(net.pms.dlna.InputFile)

Aggregations

RendererConfiguration (net.pms.configuration.RendererConfiguration)24 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)5 Test (org.junit.Test)5 InetAddress (java.net.InetAddress)4 DLNAMediaInfo (net.pms.dlna.DLNAMediaInfo)4 Format (net.pms.formats.Format)4 UnknownHostException (java.net.UnknownHostException)3 PmsConfiguration (net.pms.configuration.PmsConfiguration)3 WebRender (net.pms.configuration.WebRender)3 DLNAMediaAudio (net.pms.dlna.DLNAMediaAudio)3 ExternalListener (net.pms.external.ExternalListener)3 MPG (net.pms.formats.MPG)3 InetSocketAddress (java.net.InetSocketAddress)2 StringTokenizer (java.util.StringTokenizer)2 DeviceConfiguration (net.pms.configuration.DeviceConfiguration)2 InputFile (net.pms.dlna.InputFile)2 StartStopListener (net.pms.external.StartStopListener)2 MP3 (net.pms.formats.audio.MP3)2 KeyedComboBoxModel (net.pms.util.KeyedComboBoxModel)2