Beispiel #1
0
        private void CopyOrEncodeAudioFile(AudioFileEncoding encoding)
        {
            if (!encoding.TryToCopyAlreadyEncodedFile)
            {
                encoding.EncodeAudioFile_Async();  //We need to encode it

                return;
            }

            AlreadyEncodedFile file = _History.GetAlreadyEncodedFileAndReCheckValidation(encoding);

            if (file != null)  //Already Encoded File found (copy it)
            {
                encoding.CopyOrEncodeAudioFile_Async(file);

                return;
            }

            AudioFileEncoding activeEncoding = GetActiveEncodingForPendingCopy(encoding);

            if (activeEncoding != null)  //Pending active encoding should be creating the Already Encoded file we seek (copy it)
            {
                encoding.CopyOrEncodeAudioFile_Async(activeEncoding);

                return;
            }

            encoding.EncodeAudioFile_Async();  //If all else fails, just encode it
        }
Beispiel #2
0
 private void AddToActiveOrWaitingList(AudioFileEncoding encoding)
 {
     if (encoding.IsWaiting == false)
     {
         _ActiveEncodings.Add(encoding);
     }
     else
     {
         _WaitingEncodings.Add(encoding);
     }
 }
Beispiel #3
0
        public AlreadyEncodedFile(AudioFileEncoding encoding)
        {
            _LoadSheetRowNumber = encoding.LSR.LoadSheetRowNumber;

            _EncodedFilePath = encoding.LSR.DestinationPath;
            _SourceFilePath  = encoding.LSR.SuggestedAudioFile.FullPath;
            _EncodedStatus   = encoding.LSR.EncodingResult;

            _EncodedFileExtension = Path.GetExtension(_EncodedFilePath).ToLower();

            CheckIfValid();
        }
Beispiel #4
0
        public AudioFileEncoding GetActiveEncodingForPendingCopy(AudioFileEncoding encoding)
        {
            foreach (AudioFileEncoding activeEncoding in _ActiveEncodings)
            {
                if (encoding.LSR.IsLSREncodingEligibleForCopying(activeEncoding.LSR.PotentialFile))
                {
                    return(activeEncoding);
                }
            }

            return(null);  //Not Found
        }
Beispiel #5
0
        public void CopyOrEncodeAudioFile_Async(AudioFileEncoding activeEncoding)
        {
            _CopyOrEncodeActionTaken = "Copy From Active Encoding (ID: " + activeEncoding.EncodingID.ToString() + ")";

            _FileToCopy = activeEncoding.LSR.PotentialFile;  //Not Finished Encoding Yet (not yet valid)

            if (activeEncoding.HasFinished == false)
            {
                _IsWaiting = true;
            }

            Task.Run(() => CopyOrEncodeAudioFile(activeEncoding));
        }
        public AlreadyEncodedFile GetAlreadyEncodedFileAndReCheckValidation(AudioFileEncoding encoding)
        {
            foreach (AlreadyEncodedFile file in _AlreadyEncodedFiles)
            {
                if (encoding.LSR.IsLSREncodingEligibleForCopying(file))
                {
                    if (file.ReCheckIfValid())  //re-checked because AudioFileEncoding.CopyAudioFile() does a re-check. Let's verify it passes upfront.
                    {
                        return(file);
                    }
                }
            }

            return(null);  //Not Found
        }
Beispiel #7
0
        private void CopyOrEncodeAudioFile(AudioFileEncoding activeEncoding)
        {
            while (activeEncoding.HasFinished == false)
            {
                Thread.Sleep(1000);
            }

            _IsWaiting = false;

            _FileToCopy = new AlreadyEncodedFile(activeEncoding);  //Now Finished (Need to get updated 'Encoding Result' to verify if valid)

            if (_FileToCopy.IsValid)
            {
                CopyorEncodeAudioFile();
            }
            else
            {
                EncodeAudioFile();
            }
        }
Beispiel #8
0
        public void PrintEncodingQueue_DEBUG(AudioEncoderController controller)
        {
            ConsolePrintHelpers.PrintHeader();

            ConsolePrintHelpers.PrintWhiteText("  Printing Encoding Queue...");

            PrintPendingCopyOrEncodeStats();

            ConsolePrintHelpers.Wait();

            Console.WriteLine("\n");

            foreach (AudioFileEncoding encoding in _EncodingQueue)
            {
                ConsolePrintHelpers.PrintFullWidthLine();

                ConsolePrintHelpers.PrintWhiteText("  Encoding ID           :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.EncodingID.ToString());
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Load Sheet Row #      :  ");
                ConsolePrintHelpers.PrintCyanText((encoding.LSR.LoadSheetRowNumber + 1).ToString());
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Source File Size      :  ");
                ConsolePrintHelpers.PrintCyanText((encoding.LSR.SuggestedAudioFile.FileSize / 1024 / 1024).ToString() + " MB");
                Console.WriteLine("\n");

                ConsolePrintHelpers.PrintWhiteText("  Source File           :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.LSR.SuggestedAudioFile.FullPath);
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Destination File      :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.LSR.DestinationPath);
                Console.WriteLine();

                ConsolePrintHelpers.PrintWhiteText("  Destination File Ext  :  ");
                ConsolePrintHelpers.PrintCyanText(encoding.LSR.OutputFilenameExtension);
                Console.WriteLine("\n");

                ConsolePrintHelpers.PrintWhiteText("  Copy Or Encode        :  ");

                if (encoding.TryToCopyAlreadyEncodedFile)
                {
                    AlreadyEncodedFile file = controller.History.GetAlreadyEncodedFileAndReCheckValidation(encoding);

                    if (file != null)  //Already Encoded File found
                    {
                        ConsolePrintHelpers.PrintYellowText("Copy Already Encoded File");
                    }
                    else
                    {
                        AudioFileEncoding activeEncoding = controller.GetActiveEncodingForPendingCopy(encoding);

                        if (activeEncoding != null)  //Pending active encoding should be creating the Already Encoded file we seek
                        {
                            file = activeEncoding.LSR.PotentialFile;

                            ConsolePrintHelpers.PrintYellowText("Copy from Active Encoding (ID: " + activeEncoding.EncodingID.ToString() + ")");
                        }
                        else
                        {
                            ConsolePrintHelpers.PrintRedText("Encode (No Eligible File To Copy Found)");
                        }
                    }

                    if (file != null)
                    {
                        Console.WriteLine("\n");
                        ConsolePrintHelpers.PrintWhiteText("  Load Sheet Row #      :  ");
                        ConsolePrintHelpers.PrintGreenText((file.LoadSheetRowNumber + 1).ToString());
                        Console.WriteLine();
                        ConsolePrintHelpers.PrintWhiteText("  Source File           :  ");

                        if (encoding.LSR.SuggestedAudioFile.FullPath == file.SourceFilePath)
                        {
                            ConsolePrintHelpers.PrintGreenText(file.SourceFilePath);
                        }
                        else
                        {
                            ConsolePrintHelpers.PrintRedText(file.SourceFilePath);
                        }

                        Console.WriteLine();
                        ConsolePrintHelpers.PrintWhiteText("  Encoded File          :  ");

                        if (encoding.LSR.OutputFilenameExtension == file.EncodedFileExtension)
                        {
                            ConsolePrintHelpers.PrintGreenText(file.EncodedFilePath);
                            Console.WriteLine();
                            ConsolePrintHelpers.PrintWhiteText("  Encoded File Ext      :  ");
                            ConsolePrintHelpers.PrintGreenText(file.EncodedFileExtension);
                        }
                        else
                        {
                            ConsolePrintHelpers.PrintRedText(file.EncodedFilePath);
                            Console.WriteLine();
                            ConsolePrintHelpers.PrintWhiteText("  Encoded File Ext      :  ");
                            ConsolePrintHelpers.PrintRedText(file.EncodedFileExtension);
                        }
                    }
                }
                else
                {
                    ConsolePrintHelpers.PrintCyanText("Encode");
                }

                Console.WriteLine("\n");
            }

            ConsolePrintHelpers.PressAnyKeyToContinue();
        }
Beispiel #9
0
        public void EncodeAudioFiles()
        {
            if (!_IsQueueBuilt)
            {
                BuildEncodingQueue();
            }

            Stopwatch stopwatch = ConsolePrintHelpers.PrintHeaderAndStartStopWatch();

            ConsolePrintHelpers.PrintWhiteText("  Encoding Audio Files...");

            PrintEncodingQueueAndHistoryStats();

            _History.WriteApprovalHistoryToFile(true);

            ConsolePrintHelpers.Wait();

            CleanTranscodeTempDirectory();

            _LoadSheetUpdateInterval = Globals.InitialLoadSheetUpdateInterval;

            _ActiveEncodings.Clear();

            _FinishedEncodings.Clear();

            _WaitingEncodings.Clear();

            _EncodedFilesCount = 0;

            _CopiedFilesCount = 0;

            int encodingQueueCount = _EncodingQueues.EncodingQueue.Count;

            for (int i = 0; i < encodingQueueCount; i++)
            {
                AudioFileEncoding encoding = _EncodingQueues.EncodingQueue.Dequeue();

                CopyOrEncodeAudioFile(encoding);

                AddToActiveOrWaitingList(encoding);

                IncrementalUpdateLoadSheet();

                encoding.PrintAudioFileEncoding();

                PrintEncodingStatsHeaders();

                CheckForFinishedEncodings(Globals.MaxDegreeOfParallelism);
            }

            foreach (AudioFileEncoding waitingEncoding in _WaitingEncodings)
            {
                _ActiveEncodings.Add(waitingEncoding);
            }

            foreach (AODLoadSheetRow skippedLSR in _EncodingQueues.SkippedQueue)
            {
                _FinishedEncodings.Add(new AudioFileEncoding(skippedLSR, 0, false));  //Add skipped rows for updating back to loadsheet
            }

            if (encodingQueueCount > 0)
            {
                CheckForFinishedEncodings(1);
            }

            _History.WriteEncodingHistoryToFile(true);

            UpdateLoadSheet();   //final update to AOD Loadsheet with remaining rows not saved yet (including skipped rows)

            ConsolePrintHelpers.PrintDuration(stopwatch, "Encoding");
            ConsolePrintHelpers.PrintYellowText("\n\n\n  Encoding Run Completed");

            if (_EncodingQueues.SkippedQueue.Count == 0)
            {
                ConsolePrintHelpers.PressAnyKeyToExit();
            }
            else
            {
                _EncodingQueues.PrintAndEmptySkippedQueue();
            }
        }