Skip to content
This repository
Browse code

cleanup

  • Loading branch information...
commit 848042937b0f81107441c6bd9ad8477b5c8c4038 1 parent e27c759
authored September 24, 2012
145  src/main/java/net/pms/dlna/DLNAResource.java
@@ -231,10 +231,10 @@
231 231
 	/**
232 232
 	 * @deprecated Use standard getter and setter to access this field.
233 233
 	 *
234  
-	 * the id which the last child got, so the next child can get unique id with incrementing this value.
  234
+	 * The numerical ID (1-based index) assigned to the last child of this folder. The next child is assigned this ID + 1.
235 235
 	 */
236 236
 	@Deprecated
237  
-	protected int lastChildrenId;
  237
+	protected int lastChildrenId = 0; // XXX make private and rename lastChildrenId -> lastChildId
238 238
 
239 239
 	/**
240 240
 	 * @deprecated Use standard getter and setter to access this field.
@@ -278,7 +278,7 @@ protected String getId() {
278 278
 	}
279 279
 
280 280
 	/**
281  
-	 * Set the id of this resource based on the index in its parent container.
  281
+	 * Set the ID of this resource based on the index in its parent container.
282 282
 	 * Its main purpose is to be unique in the parent container. The method is
283 283
 	 * automatically called by addChildInternal, so most of the time it is not
284 284
 	 * necessary to call it explicitly.
@@ -457,11 +457,11 @@ public void addChild(DLNAResource child) {
457 457
 		try {
458 458
 			if (child.isValid()) {
459 459
 				LOGGER.trace("Adding " + child.getName() + " / class: " + child.getClass().getName());
460  
-				VirtualFolder vf = null;
461 460
 
462 461
 				if (allChildrenAreFolders && !child.isFolder()) {
463 462
 					allChildrenAreFolders = false;
464 463
 				}
  464
+
465 465
 				addChildInternal(child);
466 466
 
467 467
 				boolean forceTranscodeV2 = false;
@@ -543,11 +543,11 @@ public void addChild(DLNAResource child) {
543 543
 							isIncompatible = true;
544 544
 						}
545 545
 
546  
-						// Force transcoding if
547  
-						// 1- MediaInfo support detected the file was not matched with supported codec configs and no SkipTranscode extension forced by user
548  
-						// or 2- ForceTranscode extension forced by user
549  
-						// or 3- FFmpeg support and the file is not ps3 compatible (need to remove this ?) and no SkipTranscode extension forced by user
550  
-						// or 4- There's some sub files or embedded subs to deal with and no SkipTranscode extension forced by user
  546
+						// Force transcoding if any of the following are true:
  547
+						// 1) The file is not supported by the renderer and SkipTranscode is not enabled for this extension
  548
+						// 2) ForceTranscode enabled for this extension
  549
+						// 3) FFmpeg support and the file is not PS3 compatible (XXX need to remove this?) and SkipTranscode is not enabled for this extension
  550
+						// 4) The file has embedded or external subs and SkipTranscode is not enabled for this extension
551 551
 						if (forceTranscode || !isSkipTranscode() && (forceTranscodeV2 || isIncompatible || hasSubsToTranscode)) {
552 552
 							child.setPlayer(player);
553 553
 							LOGGER.trace("Switching " + child.getName() + " to player " + player.toString() + " for transcoding");
@@ -555,19 +555,19 @@ public void addChild(DLNAResource child) {
555 555
 
556 556
 						// Should the child be added to the transcode folder?
557 557
 						if (child.getFormat().isVideo() && child.isTranscodeFolderAvailable()) {
558  
-							vf = getTranscodeFolder(true);
  558
+							// true: create (and append) the #--TRANSCODE--# folder to this folder if it doesn't already exist
  559
+							VirtualFolder transcodeFolder = getTranscodeFolder(true);
559 560
 
560  
-							if (vf != null) {
561  
-								VirtualFolder fileFolder = new FileTranscodeVirtualFolder(child.getName(), null);
  561
+							if (transcodeFolder != null) {
  562
+								VirtualFolder fileTranscodeFolder = new FileTranscodeVirtualFolder(child.getName(), null);
562 563
 
563 564
 								DLNAResource newChild = child.clone();
564 565
 								newChild.setPlayer(player);
565 566
 								newChild.setMedia(child.getMedia());
566  
-								// newChild.original = child;
567  
-								fileFolder.addChildInternal(newChild);
  567
+								fileTranscodeFolder.addChildInternal(newChild);
568 568
 								LOGGER.trace("Duplicate " + child.getName() + " with player: " + player.toString());
569 569
 
570  
-								vf.addChild(fileFolder);
  570
+								transcodeFolder.addChild(fileTranscodeFolder);
571 571
 							}
572 572
 						}
573 573
 
@@ -595,12 +595,13 @@ public void addChild(DLNAResource child) {
595 595
 						Player player = PlayerFactory.getPlayer(newChild);
596 596
 						newChild.setPlayer(player);
597 597
 					}
  598
+
598 599
 					if (child.getMedia() != null && child.getMedia().isSecondaryFormatValid()) {
599 600
 						addChild(newChild);
600 601
 					}
601 602
 				}
602 603
 			}
603  
-		}catch (Throwable t) {
  604
+		} catch (Throwable t) {
604 605
 			LOGGER.error(String.format("Failed to add child '%s'", child.getName()), t);
605 606
 
606 607
 			child.setParent(null);
@@ -609,46 +610,64 @@ public void addChild(DLNAResource child) {
609 610
 	}
610 611
 
611 612
 	/**
612  
-	 * Return the transcode virtual folder if it's supported and allowed. If create set to true, it tries to create if not yet created.
  613
+	 * Return the transcode folder for this resource.
  614
+	 * If PMS is configured to hide transcode folders, null is returned.
  615
+	 * If no folder exists and the create argument is false, null is returned.
  616
+	 * If no folder exists and the create argument is true, a new transcode folder is created.
  617
+	 * This method is called on the parent frolder each time a child is added to that parent
  618
+	 * (via {@link addChild(DLNAResource)}.
613 619
 	 * @param create
614  
-	 * @return
  620
+	 * @return the transcode virtual folder
615 621
 	 */
616 622
 	TranscodeVirtualFolder getTranscodeFolder(boolean create) {
617 623
 		if (!isTranscodeFolderAvailable()) {
618 624
 			return null;
619 625
 		}
  626
+
620 627
 		if (PMS.getConfiguration().getHideTranscodeEnabled()) {
621 628
 			return null;
622 629
 		}
  630
+
623 631
 		// search for transcode folder
624  
-		for (DLNAResource r : getChildren()) {
625  
-			if (r instanceof TranscodeVirtualFolder) {
626  
-				return (TranscodeVirtualFolder) r;
  632
+		for (DLNAResource child : getChildren()) {
  633
+			if (child instanceof TranscodeVirtualFolder) {
  634
+				return (TranscodeVirtualFolder) child;
627 635
 			}
628 636
 		}
  637
+
629 638
 		if (create) {
630  
-			TranscodeVirtualFolder vf = new TranscodeVirtualFolder(null);
631  
-			addChildInternal(vf);
632  
-			return vf;
  639
+			TranscodeVirtualFolder transcodeFolder = new TranscodeVirtualFolder(null);
  640
+			addChildInternal(transcodeFolder);
  641
+			return transcodeFolder;
633 642
 		}
  643
+
634 644
 		return null;
635 645
 	}
636 646
 
637 647
 	/**
638  
-	 * Add to the internal list of child nodes, and sets the parent to the
639  
-	 * current node.
  648
+	 * Adds the supplied DNLA resource to the internal list of child nodes,
  649
+	 * and sets the parent to the current node. Avoids the side-effects
  650
+	 * associated with the {@link addChild(DLNAResource)} method.
640 651
 	 *
641  
-	 * @param res
642  
-	 */
643  
-	protected synchronized void addChildInternal(DLNAResource res) {
644  
-		if (res.getInternalId() != null) {
645  
-			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()});
  652
+	 * @param child
  653
+	 */
  654
+	protected synchronized void addChildInternal(DLNAResource child) {
  655
+		if (child.getInternalId() != null) {
  656
+			LOGGER.info(
  657
+				"Node ({}) already has an ID ({}), which is overriden now. The previous parent node was: {}",
  658
+				new Object[] {
  659
+					child.getClass().getName(),
  660
+					child.getResourceId(),
  661
+					child.getParent()
  662
+				}
  663
+			);
646 664
 		}
647  
-		getChildren().add(res);
648  
-		res.setParent(this);
649 665
 
650  
-		setLastChildrenId(getLastChildrenId() + 1);
651  
-		res.setIndexId(getLastChildrenId());
  666
+		getChildren().add(child);
  667
+		child.setParent(this);
  668
+
  669
+		setLastChildId(getLastChildId() + 1);
  670
+		child.setIndexId(getLastChildId());
652 671
 	}
653 672
 
654 673
 	/**
@@ -687,26 +706,30 @@ protected synchronized void addChildInternal(DLNAResource res) {
687 706
 					if (resource instanceof DVDISOFile) {
688 707
 						parallel_thread_number = 1; // my dvd drive is dying wih 3 parallel threads
689 708
 					}
  709
+
690 710
 					ThreadPoolExecutor tpe = new ThreadPoolExecutor(Math.min(count, parallel_thread_number), count, 20, TimeUnit.SECONDS, queue);
691 711
 
692 712
 					for (int i = start; i < start + count; i++) {
693 713
 						if (i < resource.getChildren().size()) {
694 714
 							final DLNAResource child = resource.getChildren().get(i);
  715
+
695 716
 							if (child != null) {
696 717
 								tpe.execute(child);
697 718
 								resources.add(child);
698 719
 							}
699 720
 						}
700 721
 					}
  722
+
701 723
 					try {
702 724
 						tpe.shutdown();
703 725
 						tpe.awaitTermination(20, TimeUnit.SECONDS);
704  
-					} catch (InterruptedException e) {
705  
-					}
  726
+					} catch (InterruptedException e) { }
  727
+
706 728
 					LOGGER.trace("End of analysis");
707 729
 				}
708 730
 			}
709 731
 		}
  732
+
710 733
 		return resources;
711 734
 	}
712 735
 
@@ -761,6 +784,7 @@ final protected void discoverWithRenderer(RendererConfiguration renderer, int co
761 784
 	public void run() {
762 785
 		if (first == null) {
763 786
 			resolve();
  787
+
764 788
 			if (second != null) {
765 789
 				second.resolve();
766 790
 			}
@@ -778,11 +802,13 @@ public void run() {
778 802
 	public DLNAResource search(String searchId, int count, RendererConfiguration renderer) {
779 803
 		if (getId() != null && searchId != null) {
780 804
 			String[] indexPath = searchId.split("\\$", 2);
  805
+
781 806
 			if (getId().equals(indexPath[0])) {
782 807
 				if (indexPath.length == 1 || indexPath[1].length() == 0) {
783 808
 					return this;
784 809
 				} else {
785 810
 					discoverWithRenderer(renderer, count, false);
  811
+
786 812
 					for (DLNAResource file : getChildren()) {
787 813
 						DLNAResource found = file.search(indexPath[1], count, renderer);
788 814
 						if (found != null) {
@@ -794,6 +820,7 @@ public DLNAResource search(String searchId, int count, RendererConfiguration ren
794 820
 				return null;
795 821
 			}
796 822
 		}
  823
+
797 824
 		return null;
798 825
 	}
799 826
 
@@ -862,7 +889,7 @@ public void resolve() {
862 889
 	// Ditlew
863 890
 	/**
864 891
 	 * Returns the DisplayName for the default renderer.
865  
-	 * 
  892
+	 *
866 893
 	 * @return The display name.
867 894
 	 * @see #getDisplayName(RendererConfiguration)
868 895
 	 */
@@ -1015,7 +1042,7 @@ public String getDisplayName(RendererConfiguration mediaRenderer) {
1015 1042
 			format = smartRemove(format, "%A", true);
1016 1043
 			format = smartRemove(format, "%a", true);
1017 1044
 		}
1018  
-		
  1045
+
1019 1046
 		// Handle subtitle
1020 1047
 		if (getMediaSubtitle() != null && getMediaSubtitle().getId() != -1) {
1021 1048
 			subType = getMediaSubtitle().getType().getDescription();
@@ -1058,14 +1085,14 @@ public String getDisplayName(RendererConfiguration mediaRenderer) {
1058 1085
 
1059 1086
 		return result;
1060 1087
 	}
1061  
-	
  1088
+
1062 1089
 	/**
1063 1090
 	 * Removes the given token from the format string while trying to be smart
1064 1091
 	 * about it. This means that optional surrounding braces, curly braces,
1065 1092
 	 * brackets are removed as well, as are superfluous whitespace and
1066 1093
 	 * separators. For example, removing "%E" from "%F - %d [%E] {%x}" results
1067 1094
 	 * in "%F - %d {%x}". Removing "%d" from that will return "%F {%x}".
1068  
-	 * 
  1095
+	 *
1069 1096
 	 * @param format
1070 1097
 	 *            The format string to remove the token from.
1071 1098
 	 * @param token
@@ -1174,12 +1201,13 @@ public int childrenNumber() {
1174 1201
 		if (getChildren() == null) {
1175 1202
 			return 0;
1176 1203
 		}
  1204
+
1177 1205
 		return getChildren().size();
1178 1206
 	}
  1207
+
1179 1208
 	/* (non-Javadoc)
1180 1209
 	 * @see java.lang.Object#clone()
1181 1210
 	 */
1182  
-
1183 1211
 	@Override
1184 1212
 	protected DLNAResource clone() {
1185 1213
 		DLNAResource o = null;
@@ -2287,23 +2315,38 @@ protected void setChildren(List<DLNAResource> children) {
2287 2315
 	}
2288 2316
 
2289 2317
 	/**
2290  
-	 * Returns the id of the last child added.
2291  
-	 *
2292  
-	 * @return The id.
2293  
-	 * @since 1.50.0
  2318
+	 * @deprecated use {@link #getLastChildId()} instead.
2294 2319
 	 */
  2320
+	@Deprecated
2295 2321
 	protected int getLastChildrenId() {
  2322
+		return getLastChildId();
  2323
+	}
  2324
+
  2325
+	/**
  2326
+	 * Returns the numerical ID of the last child added.
  2327
+	 *
  2328
+	 * @return The ID.
  2329
+	 * @since 1.80.0
  2330
+	 */
  2331
+	protected int getLastChildId() {
2296 2332
 		return lastChildrenId;
2297 2333
 	}
2298 2334
 
2299 2335
 	/**
2300  
-	 * Sets the id of the last child added.
  2336
+	 * @deprecated use {@link #setLastChildId(int)} instead.
  2337
+	 */
  2338
+	protected void setLastChildrenId(int lastChildId) {
  2339
+		setLastChildId(lastChildId);
  2340
+	}
  2341
+
  2342
+	/**
  2343
+	 * Sets the numerical ID of the last child added.
2301 2344
 	 *
2302  
-	 * @param lastChildrenId The id to set.
2303  
-	 * @since 1.50.0
  2345
+	 * @param lastChildId The ID to set.
  2346
+	 * @since 1.80.0
2304 2347
 	 */
2305  
-	protected void setLastChildrenId(int lastChildrenId) {
2306  
-		this.lastChildrenId = lastChildrenId;
  2348
+	protected void setLastChildId(int lastChildId) {
  2349
+		this.lastChildrenId = lastChildId;
2307 2350
 	}
2308 2351
 
2309 2352
 	/**
66  src/main/java/net/pms/dlna/FileTranscodeVirtualFolder.java
@@ -32,14 +32,14 @@
32 32
 import org.slf4j.LoggerFactory;
33 33
 
34 34
 /**
35  
- * This class populates the TRANSCODE folder with content. 
  35
+ * This class populates the file-specific transcode folder with content.
36 36
  */
37 37
 public class FileTranscodeVirtualFolder extends VirtualFolder {
38 38
 	private static final Logger LOGGER = LoggerFactory.getLogger(FileTranscodeVirtualFolder.class);
39 39
 	private boolean resolved;
40 40
 
41 41
 	/**
42  
-	 * Class to take care of sorting the resources properly. Resources
  42
+	 * Class to take care of sorting the resources correctly. Resources
43 43
 	 * are sorted by player, then by audio track, then by subtitle.
44 44
 	 */
45 45
 	private class ResourceSort implements Comparator<DLNAResource> {
@@ -53,7 +53,7 @@
53 53
 		public int compare(DLNAResource resource1, DLNAResource resource2) {
54 54
 			Integer playerIndex1 = players.indexOf(resource1.getPlayer());
55 55
 			Integer playerIndex2 = players.indexOf(resource2.getPlayer());
56  
-			
  56
+
57 57
 			if (playerIndex1.equals(playerIndex2)) {
58 58
 				String audioLang1 = resource1.getMediaAudio().getLang();
59 59
 				String audioLang2 = resource2.getMediaAudio().getLang();
@@ -82,20 +82,40 @@ public int compare(DLNAResource resource1, DLNAResource resource2) {
82 82
 				return playerIndex1.compareTo(playerIndex2);
83 83
 			}
84 84
 		}
85  
-		
86 85
 	}
87 86
 
  87
+	// FIXME unused
  88
+	@Deprecated
88 89
 	public FileTranscodeVirtualFolder(String name, String thumbnailIcon, boolean copy) {
89 90
 		super(name, thumbnailIcon);
90 91
 	}
91 92
 
  93
+	public FileTranscodeVirtualFolder(String name, String thumbnailIcon) { // XXX thumbnailIcon is always null
  94
+		super(name, thumbnailIcon);
  95
+	}
  96
+
  97
+	private void addChapterFile(DLNAResource source) {
  98
+		if (PMS.getConfiguration().isChapterSupport() && PMS.getConfiguration().getChapterInterval() > 0) {
  99
+			ChapterFileTranscodeVirtualFolder chapterFolder = new ChapterFileTranscodeVirtualFolder(
  100
+				"Chapters:" + source.getDisplayName(),
  101
+				null,
  102
+				PMS.getConfiguration().getChapterInterval()
  103
+			);
  104
+			DLNAResource newSeekChild = source.clone();
  105
+			newSeekChild.setNoName(true);
  106
+			chapterFolder.addChildInternal(newSeekChild);
  107
+			addChildInternal(chapterFolder);
  108
+		}
  109
+	}
  110
+
92 111
 	/**
93  
-	 * This populates the TRANSCODE folder with all combinations of players,
  112
+	 * This populates the file-specific transcode folder with all combinations of players,
94 113
 	 * audio tracks and subtitles.
95 114
 	 */
96 115
 	@Override
97 116
 	public void resolve() {
98 117
 		super.resolve();
  118
+
99 119
 		if (!resolved && getChildren().size() == 1) { // OK
100 120
 			DLNAResource child = getChildren().get(0);
101 121
 			child.resolve();
@@ -143,7 +163,7 @@ public void resolve() {
143 163
 					// Create a temporary copy of the child with the audio and
144 164
 					// subtitle modified in order to be able to match players to it.
145 165
 					DLNAResource tempModifiedCopy = createModifiedResource(child, audio, subtitle);
146  
-			
  166
+
147 167
 					// Determine which players match this audio track and subtitle
148 168
 					ArrayList<Player> players = PlayerFactory.getPlayers(tempModifiedCopy);
149 169
 
@@ -183,9 +203,12 @@ public void resolve() {
183 203
 	 * @param player The player to use.
184 204
 	 * @return The copy.
185 205
 	 */
186  
-	private DLNAResource createComboResource(DLNAResource original,
187  
-			DLNAMediaAudio audio, DLNAMediaSubtitle subtitle, Player player) {
188  
-
  206
+	private DLNAResource createComboResource(
  207
+		DLNAResource original,
  208
+		DLNAMediaAudio audio,
  209
+		DLNAMediaSubtitle subtitle,
  210
+		Player player
  211
+	) {
189 212
 		// FIXME: Use new DLNAResource() instead of clone(). Clone is bad, mmmkay?
190 213
 		DLNAResource copy = original.clone();
191 214
 
@@ -199,7 +222,7 @@ private DLNAResource createComboResource(DLNAResource original,
199 222
 	}
200 223
 
201 224
 	/**
202  
-	 * Create a copy of the provided original resource and modifies it with
  225
+	 * Create a copy of the provided original resource and modify it with
203 226
 	 * the given audio track and subtitles.
204 227
 	 *
205 228
 	 * @param original The original {@link DLNAResource} to create a copy of.
@@ -207,9 +230,11 @@ private DLNAResource createComboResource(DLNAResource original,
207 230
 	 * @param subtitle The subtitle track to use.
208 231
 	 * @return The copy.
209 232
 	 */
210  
-	private DLNAResource createModifiedResource(DLNAResource original,
211  
-			DLNAMediaAudio audio, DLNAMediaSubtitle subtitle) {
212  
-
  233
+	private DLNAResource createModifiedResource(
  234
+		DLNAResource original,
  235
+		DLNAMediaAudio audio,
  236
+		DLNAMediaSubtitle subtitle
  237
+	) {
213 238
 		// FIXME: Use new DLNAResource() instead of clone(). Clone is bad, mmmkay?
214 239
 		DLNAResource copy = original.clone();
215 240
 
@@ -219,19 +244,4 @@ private DLNAResource createModifiedResource(DLNAResource original,
219 244
 		copy.setMediaSubtitle(subtitle);
220 245
 		return copy;
221 246
 	}
222  
-
223  
-
224  
-	private void addChapterFile(DLNAResource source) {
225  
-		if (PMS.getConfiguration().getChapterInterval() > 0 && PMS.getConfiguration().isChapterSupport()) {
226  
-			ChapterFileTranscodeVirtualFolder chapterFolder = new ChapterFileTranscodeVirtualFolder("Chapters:" + source.getDisplayName(), null, PMS.getConfiguration().getChapterInterval());
227  
-			DLNAResource newSeekChild = source.clone();
228  
-			newSeekChild.setNoName(true);
229  
-			chapterFolder.addChildInternal(newSeekChild);
230  
-			addChildInternal(chapterFolder);
231  
-		}
232  
-	}
233  
-
234  
-	public FileTranscodeVirtualFolder(String name, String thumbnailIcon) {
235  
-		super(name, thumbnailIcon);
236  
-	}
237 247
 }
2  src/main/java/net/pms/dlna/MapFile.java
@@ -300,10 +300,12 @@ public void doRefreshChildren() {
300 300
 			LOGGER.debug("File automatically added: " + f.getName());
301 301
 		}
302 302
 
  303
+		// false: don't create the folder if it doesn't exist i.e. find the folder
303 304
 		TranscodeVirtualFolder vf = getTranscodeFolder(false);
304 305
 
305 306
 		for (DLNAResource f : removedFiles) {
306 307
 			getChildren().remove(f);
  308
+
307 309
 			if (vf != null) {
308 310
 				for (int j = vf.getChildren().size() - 1; j >= 0; j--) {
309 311
 					if (vf.getChildren().get(j).getName().equals(f.getName())) {
2  src/main/java/net/pms/dlna/virtual/TranscodeVirtualFolder.java
@@ -21,7 +21,7 @@
21 21
 import net.pms.PMS;
22 22
 
23 23
 public class TranscodeVirtualFolder extends VirtualFolder {
24  
-	public TranscodeVirtualFolder(String thumbnailIcon) {
  24
+	public TranscodeVirtualFolder(String thumbnailIcon) { // XXX thumbnailIcon is always null
25 25
 		super(PMS.getConfiguration().getTranscodeFolderName(), thumbnailIcon);
26 26
 	}
27 27
 }

0 notes on commit 8480429

Please sign in to comment.
Something went wrong with that request. Please try again.