public SourceDetector(string avsScript, string d2vFile, bool bIsAnime, int iFrameCount, ThreadPriority priority, SourceDetectorSettings oSettings, UpdateSourceDetectionStatus updateMethod, FinishedAnalysis finishedMethod) { script = avsScript; d2vFileName = d2vFile; settings = oSettings; isAnime = bIsAnime; frameCount = iFrameCount; trimmedFilteredLine = ""; type = SourceType.UNKNOWN; majorityFilm = false; error = false; continueWorking = true; isStopped = false; oSourceInfo = new SourceDetectorInfo(); this.priority = priority; analyseUpdate += updateMethod; finishedAnalysis += finishedMethod; }
private bool GetSectionCounts(string logFileName) { #region variable declaration bool[,] data = new bool[5, 2]; int count = 0; // Decimation data int totalCombed = 0; int[] portionLength = new int[2]; int[] nextPortionIndex = new int[2]; bool[] inPortion = new bool[2]; int[] portionStatus = new int[2]; #endregion StreamReader instream; try { instream = new StreamReader(logFileName); } catch (Exception ex) { error = true; errorMessage = "Cannot open analysis log file \"" + logFileName + "\". error: " + ex.Message; FinishProcessing(); return(false); } oSourceInfo = new SourceDetectorInfo(); #region loop string line = instream.ReadLine(); while (line != null) { if (line.Length > 11) { error = true; errorMessage = "Unexpected value in file " + logFileName + ": " + line; break; } string[] contents = line.Split(new char[] { '-' }); data[count, 0] = (contents[0].Equals("true")); data[count, 1] = (contents[1].Equals("true")); count++; #region 5-ly analysis if (count == 5) { oSourceInfo.sectionCount++; int numComb = 0; int numMoving = 0; int combA = -1, combB = -1; for (int i = 0; i < 5; i++) { if (data[i, 0]) { numComb++; if (combA == -1) { combA = i; } else { combB = i; } } if (data[i, 1]) { numMoving++; } } totalCombed += numComb; oSourceInfo.sectionsWithMovingFrames[numMoving]++; if (numMoving < 5) { oSourceInfo.numUseless++; portionStatus[0] = 1; portionStatus[1] = 1; } else if (numComb == 2 && ((combB - combA == 1) || (combB - combA == 4))) { oSourceInfo.numTC++; portionStatus[0] = 0; portionStatus[1] = 2; } else if (numComb > 0) { oSourceInfo.numInt++; portionStatus[0] = 2; portionStatus[1] = 0; } else { oSourceInfo.numProg++; portionStatus[0] = 0; portionStatus[1] = 0; } #region portions // Manage film and interlaced portions for (int i = 0; i < 2; i++) { if (portionStatus[i] == 0) // Stop any portions we are in. { if (inPortion[i]) { ((int[])oSourceInfo.portions[i][nextPortionIndex[i]])[1] = oSourceInfo.sectionCount; #region useless comments /* if (portionLength[i] == 1) // This should help reduce random fluctuations, by removing length 1 portions * I've now changed my mind about random fluctuations. I believe they are good, because they occur when TIVTC is on the verge of making * a wrong decision. Instead of continuing with this decision, which would then regard this section of the film as progressive, leaving combing * this now has the effect of dramatically increasing the number of portions, forcing the whole thing to be deinterlaced, which is better, * as it leaves no residual combing. * * Edit again: i've left this section commented out, but the other section which removes length 1 progressive sections, I've left in, as it is * safer to deinterlace progressive stuff than vice versa. * { * portions[i].RemoveAt(nextPortionIndex[i]); * nextPortionIndex[i]--; * numPortions[i]--; * } */ #endregion nextPortionIndex[i]++; inPortion[i] = false; } portionLength[i] = 0; } else if (portionStatus[i] == 1) // Continue all portions, but don't start a new one. { portionLength[i]++; } else if (portionStatus[i] == 2) // Start a new portion, or continue an old one. { if (inPortion[i]) { portionLength[i]++; } else { int startIndex = oSourceInfo.sectionCount - portionLength[i]; int lastEndIndex = -2; if (nextPortionIndex[i] > 0) { lastEndIndex = ((int[])oSourceInfo.portions[i][nextPortionIndex[i] - 1])[1]; } if (startIndex - lastEndIndex > 1) // If the last portion ended more than 1 section ago. This culls trivial portions { oSourceInfo.portions[i].Add(new int[2]); ((int[])oSourceInfo.portions[i][nextPortionIndex[i]])[0] = startIndex; portionLength[i]++; oSourceInfo.numPortions[i]++; } else { nextPortionIndex[i]--; } inPortion[i] = true; } } } #endregion count = 0; } #endregion line = instream.ReadLine(); } #endregion instream.Close(); return(true); }