Search in sources :

Example 1 with Player

use of net.pms.encoders.Player in project UniversalMediaServer by UniversalMediaServer.

the class TranscodingTab method addEngines.

public void addEngines() {
    ArrayList<Player> disPlayers = new ArrayList<>();
    ArrayList<Player> ordPlayers = new ArrayList<>();
    PMS r = PMS.get();
    for (String id : configuration.getEnginesAsList(r.getRegistry())) {
        // boolean matched = false;
        for (Player p : PlayerFactory.getAllPlayers()) {
            if (p.id().equals(id)) {
                ordPlayers.add(p);
                if (p.isGPUAccelerationReady()) {
                    videoHWacceleration.setEnabled(true);
                    videoHWacceleration.setSelected(configuration.isGPUAcceleration());
                }
            // matched = true;
            }
        }
    }
    for (Player p : PlayerFactory.getAllPlayers()) {
        if (!ordPlayers.contains(p)) {
            ordPlayers.add(p);
            disPlayers.add(p);
        }
    }
    for (Player p : ordPlayers) {
        TreeNodeSettings engine = new TreeNodeSettings(p.name(), p, null);
        if (disPlayers.contains(p)) {
            engine.setEnable(false);
        }
        JComponent jc = engine.getConfigPanel();
        if (jc == null) {
            jc = buildEmpty();
        }
        jc.addComponentListener(new ComponentAdapter() {

            @Override
            public void componentShown(ComponentEvent e) {
                handleCardComponentChange(e.getComponent());
            }
        });
        tabbedPanel.add(engine.id(), jc);
        parent[p.purpose()].add(engine);
    }
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }
    tree.setSelectionRow(0);
}
Also used : Player(net.pms.encoders.Player) PMS(net.pms.PMS) ArrayList(java.util.ArrayList)

Example 2 with Player

use of net.pms.encoders.Player in project UniversalMediaServer by UniversalMediaServer.

the class FileTranscodeVirtualFolder method resolveOnce.

/**
 * This populates the file-specific transcode folder with all combinations of players,
 * audio tracks and subtitles.
 */
@Override
protected void resolveOnce() {
    if (getChildren().size() == 1) {
        // OK
        DLNAResource child = getChildren().get(0);
        child.syncResolve();
        RendererConfiguration renderer = null;
        if (this.getParent() != null) {
            renderer = this.getParent().getDefaultRenderer();
        }
        // create copies of the audio/subtitle track lists as we're making (local)
        // modifications to them
        List<DLNAMediaAudio> audioTracks = new ArrayList<>(child.getMedia().getAudioTracksList());
        List<DLNAMediaSubtitle> subtitleTracks = new ArrayList<>(child.getMedia().getSubtitleTracksList());
        // assemble copies for each combination of audio, subtitle and player
        ArrayList<DLNAResource> entries = new ArrayList<>();
        // First, add the option to simply stream the resource.
        if (renderer != null) {
            LOGGER.trace("Duplicating {} for direct streaming to renderer: {}", child.getName(), renderer.getRendererName());
        }
        DLNAResource noTranscode = createResourceWithAudioSubtitlePlayer(child, null, null, null);
        addChildInternal(noTranscode);
        addChapterFolder(noTranscode);
        // add options for renderer capable to handle streamed subtitles
        if (!configuration.isDisableSubtitles() && renderer != null && renderer.isSubtitlesStreamingSupported()) {
            for (DLNAMediaSubtitle subtitle : subtitleTracks) {
                // only add the option if the renderer supports the given format
                if (subtitle.isExternal()) {
                    // do not check for embedded subs
                    if (renderer.isExternalSubtitlesFormatSupported(subtitle, child.getMedia())) {
                        DLNAResource copy = createResourceWithAudioSubtitlePlayer(child, null, subtitle, null);
                        copy.getMediaSubtitle().setSubsStreamable(true);
                        entries.add(copy);
                        LOGGER.trace("Duplicating {} for direct streaming subtitles {}", child.getName(), subtitle.toString());
                    }
                }
            }
        }
        if (audioTracks.isEmpty()) {
            audioTracks.add(null);
        }
        if (subtitleTracks.isEmpty()) {
            subtitleTracks.add(null);
        } else {
            // if there are subtitles, make sure a no-subtitle option is added
            // for each player
            DLNAMediaSubtitle noSubtitle = new DLNAMediaSubtitle();
            noSubtitle.setId(-1);
            subtitleTracks.add(noSubtitle);
        }
        for (DLNAMediaAudio audio : audioTracks) {
            // Create combinations of all audio tracks, subtitles and players.
            for (DLNAMediaSubtitle subtitle : subtitleTracks) {
                // Create a temporary copy of the child with the audio and
                // subtitle modified in order to be able to match players to it.
                DLNAResource temp = createResourceWithAudioSubtitlePlayer(child, audio, subtitle, null);
                // Determine which players match this audio track and subtitle
                ArrayList<Player> players = PlayerFactory.getPlayers(temp);
                // create a copy for each compatible player
                for (Player player : players) {
                    DLNAResource copy = createResourceWithAudioSubtitlePlayer(child, audio, subtitle, player);
                    entries.add(copy);
                }
            }
        }
        // Sort the list of combinations
        Collections.sort(entries, new ResourceSort(PlayerFactory.getPlayers()));
        // Now add the sorted list of combinations to the folder
        for (DLNAResource dlna : entries) {
            LOGGER.trace("Adding {}: audio: {}, subtitle: {}, player: {}", new Object[] { dlna.getName(), dlna.getMediaAudio(), dlna.getMediaSubtitle(), (dlna.getPlayer() != null ? dlna.getPlayer().name() : null) });
            addChildInternal(dlna);
            addChapterFolder(dlna);
        }
    }
}
Also used : Player(net.pms.encoders.Player) RendererConfiguration(net.pms.configuration.RendererConfiguration) ArrayList(java.util.ArrayList)

Example 3 with Player

use of net.pms.encoders.Player in project UniversalMediaServer by UniversalMediaServer.

the class CueFolder method resolveOnce.

@Override
protected void resolveOnce() {
    if (playlistfile.length() < 10000000) {
        CueSheet sheet;
        try {
            sheet = CueParser.parse(playlistfile);
        } catch (IOException e) {
            LOGGER.info("Error in parsing cue: " + e.getMessage());
            return;
        }
        if (sheet != null) {
            List<FileData> files = sheet.getFileData();
            // only the first one
            if (files.size() > 0) {
                FileData f = files.get(0);
                List<TrackData> tracks = f.getTrackData();
                Player defaultPlayer = null;
                DLNAMediaInfo originalMedia = null;
                ArrayList<DLNAResource> addedResources = new ArrayList<>();
                for (int i = 0; i < tracks.size(); i++) {
                    TrackData track = tracks.get(i);
                    if (i > 0) {
                        double end = getTime(track.getIndices().get(0).getPosition());
                        if (addedResources.isEmpty()) {
                            // seems the first file was invalid or non existent
                            return;
                        }
                        DLNAResource prec = addedResources.get(i - 1);
                        int count = 0;
                        while (prec.isFolder() && i + count < addedResources.size()) {
                            // not used anymore
                            prec = addedResources.get(i + count);
                            count++;
                        }
                        prec.getSplitRange().setEnd(end);
                        prec.getMedia().setDuration(prec.getSplitRange().getDuration());
                        LOGGER.debug("Track #" + i + " split range: " + prec.getSplitRange().getStartOrZero() + " - " + prec.getSplitRange().getDuration());
                    }
                    Position start = track.getIndices().get(0).getPosition();
                    RealFile realFile = new RealFile(new File(playlistfile.getParentFile(), f.getFile()));
                    addChild(realFile);
                    addedResources.add(realFile);
                    if (i > 0 && realFile.getMedia() == null) {
                        realFile.setMedia(new DLNAMediaInfo());
                        realFile.getMedia().setMediaparsed(true);
                    }
                    realFile.resolve();
                    if (i == 0) {
                        originalMedia = realFile.getMedia();
                        if (originalMedia == null) {
                            LOGGER.trace("Couldn't resolve media \"{}\" for cue file \"{}\" - aborting", realFile.getName(), playlistfile.getAbsolutePath());
                            return;
                        }
                    }
                    realFile.getSplitRange().setStart(getTime(start));
                    realFile.setSplitTrack(i + 1);
                    // Assign a splitter engine if file is natively supported by renderer
                    if (realFile.getPlayer() == null) {
                        if (defaultPlayer == null) {
                            /*
									XXX why are we creating new player instances? aren't they
									supposed to be singletons?

									TODO don't hardwire the player here; leave it to the
									player factory to select the right player for the
									resource's format e.g:

										defaultPlayer = PlayerFactory.getPlayer(realFile);
								*/
                            if (realFile.getFormat() == null) {
                                LOGGER.error("No file format known for file \"{}\", assuming it is a video for now.", realFile.getName());
                                /*
										TODO (see above):

											r.resolveFormat(); // sets the format based on the filename
											defaultPlayer = PlayerFactory.getPlayer(realFile);
									*/
                                defaultPlayer = new MEncoderVideo();
                            } else {
                                if (realFile.getFormat().isAudio()) {
                                    defaultPlayer = new FFmpegAudio();
                                } else {
                                    defaultPlayer = new MEncoderVideo();
                                }
                            }
                        }
                        realFile.setPlayer(defaultPlayer);
                    }
                    if (realFile.getMedia() != null) {
                        try {
                            realFile.setMedia((DLNAMediaInfo) originalMedia.clone());
                        } catch (CloneNotSupportedException e) {
                            LOGGER.info("Error in cloning media info: " + e.getMessage());
                        }
                        if (realFile.getMedia() != null && realFile.getMedia().getFirstAudioTrack() != null) {
                            if (realFile.getFormat().isAudio()) {
                                realFile.getMedia().getFirstAudioTrack().setSongname(track.getTitle());
                            } else {
                                realFile.getMedia().getFirstAudioTrack().setSongname("Chapter #" + (i + 1));
                            }
                            realFile.getMedia().getFirstAudioTrack().setTrack(i + 1);
                            realFile.getMedia().setSize(-1);
                            if (StringUtils.isNotBlank(sheet.getTitle())) {
                                realFile.getMedia().getFirstAudioTrack().setAlbum(sheet.getTitle());
                            }
                            if (StringUtils.isNotBlank(sheet.getPerformer())) {
                                realFile.getMedia().getFirstAudioTrack().setArtist(sheet.getPerformer());
                            }
                            if (StringUtils.isNotBlank(track.getPerformer())) {
                                realFile.getMedia().getFirstAudioTrack().setArtist(track.getPerformer());
                            }
                        }
                    }
                }
                if (tracks.size() > 0 && addedResources.size() > 0) {
                    DLNAResource lastTrack = addedResources.get(addedResources.size() - 1);
                    Time lastTrackSplitRange = lastTrack.getSplitRange();
                    DLNAMediaInfo lastTrackMedia = lastTrack.getMedia();
                    if (lastTrackSplitRange != null && lastTrackMedia != null) {
                        lastTrackSplitRange.setEnd(lastTrackMedia.getDurationInSeconds());
                        lastTrackMedia.setDuration(lastTrackSplitRange.getDuration());
                        LOGGER.debug("Track #" + childrenNumber() + " split range: " + lastTrackSplitRange.getStartOrZero() + " - " + lastTrackSplitRange.getDuration());
                    }
                }
                PMS.get().storeFileInCache(playlistfile, Format.PLAYLIST);
            }
        }
    }
}
Also used : Player(net.pms.encoders.Player) ArrayList(java.util.ArrayList) Time(net.pms.dlna.Range.Time) IOException(java.io.IOException) MEncoderVideo(net.pms.encoders.MEncoderVideo) FFmpegAudio(net.pms.encoders.FFmpegAudio) File(java.io.File)

Example 4 with Player

use of net.pms.encoders.Player in project UniversalMediaServer by UniversalMediaServer.

the class TreeRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (leaf && value instanceof TreeNodeSettings) {
        if (((TreeNodeSettings) value).getPlayer() == null) {
            setIcon(LooksFrame.readImageIcon("icon-treemenu-category.png"));
        } else {
            if (((TreeNodeSettings) value).isEnable()) {
                Player p = ((TreeNodeSettings) value).getPlayer();
                if (PlayerFactory.getPlayers().contains(p)) {
                    setIcon(LooksFrame.readImageIcon("icon-treemenu-engineenabled.png"));
                } else {
                    setIcon(LooksFrame.readImageIcon("icon-treemenu-enginewarning.png"));
                }
            } else {
                setIcon(LooksFrame.readImageIcon("icon-treemenu-enginedisabled.png"));
            }
        }
        if (((TreeNodeSettings) value).getPlayer() != null && ((TreeNodeSettings) value).getParent().getIndex((TreeNodeSettings) value) == 0) {
            setFont(getFont().deriveFont(Font.BOLD));
        } else {
            setFont(getFont().deriveFont(Font.PLAIN));
        }
    } else {
        setIcon(LooksFrame.readImageIcon("icon-treemenu-category.png"));
    }
    setBorder(border);
    return this;
}
Also used : Player(net.pms.encoders.Player)

Aggregations

Player (net.pms.encoders.Player)4 ArrayList (java.util.ArrayList)3 File (java.io.File)1 IOException (java.io.IOException)1 PMS (net.pms.PMS)1 RendererConfiguration (net.pms.configuration.RendererConfiguration)1 Time (net.pms.dlna.Range.Time)1 FFmpegAudio (net.pms.encoders.FFmpegAudio)1 MEncoderVideo (net.pms.encoders.MEncoderVideo)1