Permalink
Browse files

cleanup

  • Loading branch information...
1 parent e27c759 commit 848042937b0f81107441c6bd9ad8477b5c8c4038 @chocolateboy chocolateboy committed Sep 24, 2012
@@ -231,10 +231,10 @@
/**
* @deprecated Use standard getter and setter to access this field.
*
- * the id which the last child got, so the next child can get unique id with incrementing this value.
+ * The numerical ID (1-based index) assigned to the last child of this folder. The next child is assigned this ID + 1.
*/
@Deprecated
- protected int lastChildrenId;
+ protected int lastChildrenId = 0; // XXX make private and rename lastChildrenId -> lastChildId
/**
* @deprecated Use standard getter and setter to access this field.
@@ -278,7 +278,7 @@ protected String getId() {
}
/**
- * Set the id of this resource based on the index in its parent container.
+ * Set the ID of this resource based on the index in its parent container.
* Its main purpose is to be unique in the parent container. The method is
* automatically called by addChildInternal, so most of the time it is not
* necessary to call it explicitly.
@@ -457,11 +457,11 @@ public void addChild(DLNAResource child) {
try {
if (child.isValid()) {
LOGGER.trace("Adding " + child.getName() + " / class: " + child.getClass().getName());
- VirtualFolder vf = null;
if (allChildrenAreFolders && !child.isFolder()) {
allChildrenAreFolders = false;
}
+
addChildInternal(child);
boolean forceTranscodeV2 = false;
@@ -543,31 +543,31 @@ public void addChild(DLNAResource child) {
isIncompatible = true;
}
- // Force transcoding if
- // 1- MediaInfo support detected the file was not matched with supported codec configs and no SkipTranscode extension forced by user
- // or 2- ForceTranscode extension forced by user
- // or 3- FFmpeg support and the file is not ps3 compatible (need to remove this ?) and no SkipTranscode extension forced by user
- // or 4- There's some sub files or embedded subs to deal with and no SkipTranscode extension forced by user
+ // Force transcoding if any of the following are true:
+ // 1) The file is not supported by the renderer and SkipTranscode is not enabled for this extension
+ // 2) ForceTranscode enabled for this extension
+ // 3) FFmpeg support and the file is not PS3 compatible (XXX need to remove this?) and SkipTranscode is not enabled for this extension
+ // 4) The file has embedded or external subs and SkipTranscode is not enabled for this extension
if (forceTranscode || !isSkipTranscode() && (forceTranscodeV2 || isIncompatible || hasSubsToTranscode)) {
child.setPlayer(player);
LOGGER.trace("Switching " + child.getName() + " to player " + player.toString() + " for transcoding");
}
// Should the child be added to the transcode folder?
if (child.getFormat().isVideo() && child.isTranscodeFolderAvailable()) {
- vf = getTranscodeFolder(true);
+ // true: create (and append) the #--TRANSCODE--# folder to this folder if it doesn't already exist
+ VirtualFolder transcodeFolder = getTranscodeFolder(true);
- if (vf != null) {
- VirtualFolder fileFolder = new FileTranscodeVirtualFolder(child.getName(), null);
+ if (transcodeFolder != null) {
+ VirtualFolder fileTranscodeFolder = new FileTranscodeVirtualFolder(child.getName(), null);
DLNAResource newChild = child.clone();
newChild.setPlayer(player);
newChild.setMedia(child.getMedia());
- // newChild.original = child;
- fileFolder.addChildInternal(newChild);
+ fileTranscodeFolder.addChildInternal(newChild);
LOGGER.trace("Duplicate " + child.getName() + " with player: " + player.toString());
- vf.addChild(fileFolder);
+ transcodeFolder.addChild(fileTranscodeFolder);
}
}
@@ -595,12 +595,13 @@ public void addChild(DLNAResource child) {
Player player = PlayerFactory.getPlayer(newChild);
newChild.setPlayer(player);
}
+
if (child.getMedia() != null && child.getMedia().isSecondaryFormatValid()) {
addChild(newChild);
}
}
}
- }catch (Throwable t) {
+ } catch (Throwable t) {
LOGGER.error(String.format("Failed to add child '%s'", child.getName()), t);
child.setParent(null);
@@ -609,46 +610,64 @@ public void addChild(DLNAResource child) {
}
/**
- * Return the transcode virtual folder if it's supported and allowed. If create set to true, it tries to create if not yet created.
+ * Return the transcode folder for this resource.
+ * If PMS is configured to hide transcode folders, null is returned.
+ * If no folder exists and the create argument is false, null is returned.
+ * If no folder exists and the create argument is true, a new transcode folder is created.
+ * This method is called on the parent frolder each time a child is added to that parent
+ * (via {@link addChild(DLNAResource)}.
* @param create
- * @return
+ * @return the transcode virtual folder
*/
TranscodeVirtualFolder getTranscodeFolder(boolean create) {
if (!isTranscodeFolderAvailable()) {
return null;
}
+
if (PMS.getConfiguration().getHideTranscodeEnabled()) {
return null;
}
+
// search for transcode folder
- for (DLNAResource r : getChildren()) {
- if (r instanceof TranscodeVirtualFolder) {
- return (TranscodeVirtualFolder) r;
+ for (DLNAResource child : getChildren()) {
+ if (child instanceof TranscodeVirtualFolder) {
+ return (TranscodeVirtualFolder) child;
}
}
+
if (create) {
- TranscodeVirtualFolder vf = new TranscodeVirtualFolder(null);
- addChildInternal(vf);
- return vf;
+ TranscodeVirtualFolder transcodeFolder = new TranscodeVirtualFolder(null);
+ addChildInternal(transcodeFolder);
+ return transcodeFolder;
}
+
return null;
}
/**
- * Add to the internal list of child nodes, and sets the parent to the
- * current node.
+ * Adds the supplied DNLA resource to the internal list of child nodes,
+ * and sets the parent to the current node. Avoids the side-effects
+ * associated with the {@link addChild(DLNAResource)} method.
*
- * @param res
- */
- protected synchronized void addChildInternal(DLNAResource res) {
- if (res.getInternalId() != null) {
- LOGGER.info("Node({}) already has an ID={}, which is overriden now. The previous parent node was:{}", new Object[] { res.getClass().getName(), res.getResourceId(), res.getParent()});
+ * @param child
+ */
+ protected synchronized void addChildInternal(DLNAResource child) {
+ if (child.getInternalId() != null) {
+ LOGGER.info(
+ "Node ({}) already has an ID ({}), which is overriden now. The previous parent node was: {}",
+ new Object[] {
+ child.getClass().getName(),
+ child.getResourceId(),
+ child.getParent()
+ }
+ );
}
- getChildren().add(res);
- res.setParent(this);
- setLastChildrenId(getLastChildrenId() + 1);
- res.setIndexId(getLastChildrenId());
+ getChildren().add(child);
+ child.setParent(this);
+
+ setLastChildId(getLastChildId() + 1);
+ child.setIndexId(getLastChildId());
}
/**
@@ -687,26 +706,30 @@ protected synchronized void addChildInternal(DLNAResource res) {
if (resource instanceof DVDISOFile) {
parallel_thread_number = 1; // my dvd drive is dying wih 3 parallel threads
}
+
ThreadPoolExecutor tpe = new ThreadPoolExecutor(Math.min(count, parallel_thread_number), count, 20, TimeUnit.SECONDS, queue);
for (int i = start; i < start + count; i++) {
if (i < resource.getChildren().size()) {
final DLNAResource child = resource.getChildren().get(i);
+
if (child != null) {
tpe.execute(child);
resources.add(child);
}
}
}
+
try {
tpe.shutdown();
tpe.awaitTermination(20, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- }
+ } catch (InterruptedException e) { }
+
LOGGER.trace("End of analysis");
}
}
}
+
return resources;
}
@@ -761,6 +784,7 @@ final protected void discoverWithRenderer(RendererConfiguration renderer, int co
public void run() {
if (first == null) {
resolve();
+
if (second != null) {
second.resolve();
}
@@ -778,11 +802,13 @@ public void run() {
public DLNAResource search(String searchId, int count, RendererConfiguration renderer) {
if (getId() != null && searchId != null) {
String[] indexPath = searchId.split("\\$", 2);
+
if (getId().equals(indexPath[0])) {
if (indexPath.length == 1 || indexPath[1].length() == 0) {
return this;
} else {
discoverWithRenderer(renderer, count, false);
+
for (DLNAResource file : getChildren()) {
DLNAResource found = file.search(indexPath[1], count, renderer);
if (found != null) {
@@ -794,6 +820,7 @@ public DLNAResource search(String searchId, int count, RendererConfiguration ren
return null;
}
}
+
return null;
}
@@ -862,7 +889,7 @@ public void resolve() {
// Ditlew
/**
* Returns the DisplayName for the default renderer.
- *
+ *
* @return The display name.
* @see #getDisplayName(RendererConfiguration)
*/
@@ -1015,7 +1042,7 @@ public String getDisplayName(RendererConfiguration mediaRenderer) {
format = smartRemove(format, "%A", true);
format = smartRemove(format, "%a", true);
}
-
+
// Handle subtitle
if (getMediaSubtitle() != null && getMediaSubtitle().getId() != -1) {
subType = getMediaSubtitle().getType().getDescription();
@@ -1058,14 +1085,14 @@ public String getDisplayName(RendererConfiguration mediaRenderer) {
return result;
}
-
+
/**
* Removes the given token from the format string while trying to be smart
* about it. This means that optional surrounding braces, curly braces,
* brackets are removed as well, as are superfluous whitespace and
* separators. For example, removing "%E" from "%F - %d [%E] {%x}" results
* in "%F - %d {%x}". Removing "%d" from that will return "%F {%x}".
- *
+ *
* @param format
* The format string to remove the token from.
* @param token
@@ -1174,12 +1201,13 @@ public int childrenNumber() {
if (getChildren() == null) {
return 0;
}
+
return getChildren().size();
}
+
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
-
@Override
protected DLNAResource clone() {
DLNAResource o = null;
@@ -2287,23 +2315,38 @@ protected void setChildren(List<DLNAResource> children) {
}
/**
- * Returns the id of the last child added.
- *
- * @return The id.
- * @since 1.50.0
+ * @deprecated use {@link #getLastChildId()} instead.
*/
+ @Deprecated
protected int getLastChildrenId() {
+ return getLastChildId();
+ }
+
+ /**
+ * Returns the numerical ID of the last child added.
+ *
+ * @return The ID.
+ * @since 1.80.0
+ */
+ protected int getLastChildId() {
return lastChildrenId;
}
/**
- * Sets the id of the last child added.
+ * @deprecated use {@link #setLastChildId(int)} instead.
+ */
+ protected void setLastChildrenId(int lastChildId) {
+ setLastChildId(lastChildId);
+ }
+
+ /**
+ * Sets the numerical ID of the last child added.
*
- * @param lastChildrenId The id to set.
- * @since 1.50.0
+ * @param lastChildId The ID to set.
+ * @since 1.80.0
*/
- protected void setLastChildrenId(int lastChildrenId) {
- this.lastChildrenId = lastChildrenId;
+ protected void setLastChildId(int lastChildId) {
+ this.lastChildrenId = lastChildId;
}
/**
Oops, something went wrong. Retry.

0 comments on commit 8480429

Please sign in to comment.