Example #1
0
        private void ScanWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            Logger.Info("ScanWorker[" + Id + "]: called");

            ScanStart = DateTime.Now;

            if (MainModel.IsAuthorized() == false)
            {
                Logger.Error("Engine not authorized!");
                ScanWorkerResult = ScanWorkerResults.NotAuthorized;
                e.Result = 0;
                ScanStop = DateTime.Now;
                return;
            }

            // don't check for engine cancel here because we want status to say "cancelling..."

            #region Raise status update event

            ReportProgress(0);
            //MainModel.OnStatusUpdateEvent();

            #endregion Raise status update event

            int returnCode;

            #region Get total frames

            if (SetTotalFrames() == false)
            {
                Logger.Error("ScanWorker[" + Id + "]: Total frames = 0 in " + InputFileObject.SourceFileInfo.FullName);
                // keep going. it just means we can't calculate progress.
            }

            #endregion Get total frames

            if (CheckForCancelledWorker()) return;

            #region Get FramesPerSecond

            if (SetFramesPerSecond() == false || Math.Abs(InputFileObject.FramesPerSecond - 0) < Double.Epsilon)
            {
                Logger.Error("ScanWorker[" + Id + "]: Frames per second = 0 in " + InputFileObject.SourceFileInfo.FullName);
                ScanWorkerResult = ScanWorkerResults.UnableToDetermineFramesPerSecond;
                e.Result = 0; // number of highlights found
                ScanStop = DateTime.Now;
                return;
            }

            #endregion Get FramesPerSecond

            if (CheckForCancelledWorker()) return;

            #region Get video duration

            if (SetVideoDuration() == false || Math.Abs(InputFileObject.VideoDurationInSeconds - 0) < Double.Epsilon)
            {
                Logger.Error("ScanWorker[" + Id + "]: Unable to get video duration of " + InputFileObject.SourceFileInfo.FullName);
                ScanWorkerResult = ScanWorkerResults.UnableToDetermineVideoDuration;
                e.Result = 0; // number of highlights found
                ScanStop = DateTime.Now;
                return;
            }

            #endregion Get video duration

            if (CheckForCancelledWorker()) return;

            #region Get bitrate

            if (SetBitrate() == false || InputFileObject.Bitrate == 0)
            {
                Logger.Error("ScanWorker[" + Id + "]: Unable to determine bitrate of " + InputFileObject.SourceFileInfo.FullName);
                ScanWorkerResult = ScanWorkerResults.UnableToDetermineBitrate;
                e.Result = 0;
                ScanStop = DateTime.Now;
                return;
            }

            #endregion Get bitrate

            if (CheckForCancelledWorker()) return;

            #region Get video dimensions

            if (SetVideoDimensions() == false || InputFileObject.VideoWidth == 0 || InputFileObject.VideoHeight == 0)
            {
                Logger.Error("ScanWorker[" + Id + "]: Unable to determine dimensions of " + InputFileObject.SourceFileInfo.FullName);
                ScanWorkerResult = ScanWorkerResults.UnableToDetermineDimensions;
                e.Result = 0;
                ScanStop = DateTime.Now;
                return;
            }

            #endregion Get video dimensions

            if (CheckForCancelledWorker()) return;

            #region Scan for bookmarks

            Logger.Info("ScanWorker[" + Id + "]: Scanning for bookmarks");

            var updateScanProgress = new Timer(200);
            updateScanProgress.Elapsed += UpdateScanProgressElapsed;
            updateScanProgress.Enabled = true;

            var darkFrameNumbers = new List<long>();
            try
            {
                returnCode = FindDarkFrames(ref darkFrameNumbers);
                OdessaReturnCode = (NativeOdessaMethods.OdessaReturnCodes)returnCode;
                UpdateScanProgressElapsed(sender, null); // call this so progress is updated before we disable it
                updateScanProgress.Enabled = false;
            }
            catch (Exception ex)
            {
                Logger.Info("ScanWorker[" + Id + "]: Exception while scanning for bookmarks in " + InputFileObject.SourceFileInfo.FullName +
                            ": " + ex);
                ScanWorkerResult = ScanWorkerResults.UnableToScan;
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToScan - " + ex);
                var extension = Path.GetExtension(InputFileObject.SourceFileInfo.Name);
                if (extension != null)
                    AnalyticsHelper.FireEvent("Each video - scan result - UnableToScan - " + extension.ToLowerInvariant());
                ScanStop = DateTime.Now;
                return;
            }
            if (returnCode != (int)NativeOdessaMethods.OdessaReturnCodes.Success)
            {
                Logger.Info("ScanWorker[" + Id + "]: Unable to scan for bookmarks: returnCode=" + returnCode);
                ScanWorkerResult = ScanWorkerResults.UnableToScan;
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToScan - " + returnCode);
                ScanStop = DateTime.Now;
                return;
            }

            #endregion Scan for bookmarks

            if (CheckForCancelledWorker()) return;

            // Find the video chunks among the black frames
            TotalHighlightsFound = CreateHighlightObjects(darkFrameNumbers,
                                                    MainModel.CaptureDurationInSeconds,
                                                    MainModel.IgnoreEarlyHighlights, UseCaptureOffset);

            Logger.Info("ScanWorker[" + Id + "]: Total highlights: " + TotalHighlightsFound);

            ScanStop = DateTime.Now; // this is where we mark the end of the scan. we don't include splicing.

            ScanWorkerResult = ScanWorkerResults.Success;
        }
 internal UploadMediaInfoWorker(FileInfo inputFile, NativeOdessaMethods.OdessaReturnCodes odessaReturnCode)
     : this(inputFile)
 {
     this.odessaReturnCode = odessaReturnCode;
 }
Example #3
0
        internal bool SetVideoDuration()
        {
            if (InputFileObject == null)
                return false;

            Logger.Info("ScanWorker[" + Id + "]: called");

            try
            {
                double duration;
                int returnCode = NativeOdessaMethods.GetDuration(InputFileObject.SourceFileInfo.FullName, out duration);
                if (returnCode == (int)NativeOdessaMethods.OdessaReturnCodes.Success)
                {
                    Logger.Info("ScanWorker[" + Id + "]: Video duration: " + duration);
                    InputFileObject.VideoDurationInSeconds = duration;
                    return true;
                }

                OdessaReturnCode = (NativeOdessaMethods.OdessaReturnCodes)returnCode;
                Logger.Error("ScanWorker[" + Id + "]: Error while getting video duration of " + InputFileObject.SourceFileInfo.FullName +
                             ". returnCode=" + returnCode);
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineVideoDuration - " + returnCode);
                var extension = Path.GetExtension(InputFileObject.SourceFileInfo.Name);
                if (extension != null)
                    AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineVideoDuration - " + returnCode + " - " + extension.ToLowerInvariant());
                return false;
            }
            catch (Exception ex)
            {
                Logger.Error("ScanWorker[" + Id + "]: Exception thrown while getting video duration of " +
                             InputFileObject.SourceFileInfo.FullName + ". " + ex);
                return false;
            }
        }
Example #4
0
        internal bool SetVideoDimensions()
        {
            if (InputFileObject == null)
                return false;

            Logger.Info("ScanWorker[" + Id + "]: called");

            try
            {
                int height;
                int width;
                int returnCode = NativeOdessaMethods.GetDimensions(InputFileObject.SourceFileInfo.FullName, out width, out height);
                if (returnCode == (int)NativeOdessaMethods.OdessaReturnCodes.Success)
                {
                    Logger.Info("ScanWorker[" + Id + "]: Dimensions: " + width + "x" + height);
                    InputFileObject.VideoWidth = width;
                    InputFileObject.VideoHeight = height;
                    return true;
                }

                OdessaReturnCode = (NativeOdessaMethods.OdessaReturnCodes)returnCode;
                Logger.Error("ScanWorker[" + Id + "]: Unable to determine dimensions: returnCode=" + returnCode);
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineDimensions - " + returnCode);
                var extension = Path.GetExtension(InputFileObject.SourceFileInfo.Name);
                if (extension != null)
                    AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineDimensions - " + returnCode + " - " + extension.ToLowerInvariant());
                return false;
            }
            catch (Exception ex)
            {
                Logger.Error("ScanWorker[" + Id + "]: Exception while determining dimensions: " + ex);
                return false;
            }
        }
Example #5
0
        internal bool SetTotalFrames()
        {
            if (InputFileObject == null)
                return false;

            Logger.Info("ScanWorker[" + Id + "]: called");

            try
            {
                long frames;
                int returnCode = NativeOdessaMethods.GetTotalFrames(InputFileObject.SourceFileInfo.FullName, out frames);
                if (returnCode == (int)NativeOdessaMethods.OdessaReturnCodes.Success)
                {
                    Logger.Info("ScanWorker[" + Id + "]: Total frames: " + frames);
                    InputFileObject.TotalFrames = frames;
                    return true;
                }

                OdessaReturnCode = (NativeOdessaMethods.OdessaReturnCodes)returnCode;
                Logger.Error("ScanWorker[" + Id + "]: Error while getting total frames in " + InputFileObject.SourceFileInfo.FullName +
                             ". returnCode = " + returnCode);
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineTotalFrames - " + returnCode);
                var extension = Path.GetExtension(InputFileObject.SourceFileInfo.Name);
                if (extension != null)
                    AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineTotalFrames - " + returnCode + " - " + extension.ToLowerInvariant());
                return false;
            }
            catch (Exception ex)
            {
                Logger.Error("ScanWorker[" + Id + "]: Exception thrown while getting total frames in " + InputFileObject.SourceFileInfo.FullName +
                             ". " + ex);
                return false;
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>True on success</returns>
        internal bool SetFramesPerSecond()
        {
            if (InputFileObject == null)
                return false;

            Logger.Info("ScanWorker[" + Id + "]: called");

            try
            {
                double fps;
                int returnCode = NativeOdessaMethods.GetFramesPerSecond(InputFileObject.SourceFileInfo.FullName, out fps);
                if (returnCode == (int)NativeOdessaMethods.OdessaReturnCodes.Success)
                {
                    Logger.Info("ScanWorker[" + Id + "]: FPS: " + fps);
                    InputFileObject.FramesPerSecond = fps;
                    return true;
                }

                OdessaReturnCode = (NativeOdessaMethods.OdessaReturnCodes)returnCode;
                Logger.Error("ScanWorker[" + Id + "]: Error while getting FPS in " + InputFileObject.SourceFileInfo.FullName +
                             ". returnCode = " + returnCode);
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineFramesPerSecond - " + returnCode);
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineFramesPerSecond - " + returnCode + " - " + Path.GetExtension(InputFileObject.SourceFileInfo.Name));
                return false;
            }
            catch (Exception ex)
            {
                Logger.Error("ScanWorker[" + Id + "]: Exception thrown while getting FPS in " + InputFileObject.SourceFileInfo.FullName +
                             ". " + ex);
                return false;
            }
        }
Example #7
0
        internal bool SetBitrate()
        {
            Logger.Info("ScanWorker[" + Id + "]: called");

            if (InputFileObject == null)
                return false;

            try
            {
                int bitrate;
                int returnCode = NativeOdessaMethods.GetBitrate(InputFileObject.SourceFileInfo.FullName, out bitrate);
                // MainModel.GetBitrate(inputFile);
                if (returnCode == (int)NativeOdessaMethods.OdessaReturnCodes.Success)
                {
                    Logger.Info("ScanWorker[" + Id + "]: Bitrate: " + bitrate);
                    InputFileObject.Bitrate = bitrate;
                    return true;
                }

                OdessaReturnCode = (NativeOdessaMethods.OdessaReturnCodes)returnCode;
                Logger.Error("ScanWorker[" + Id + "]: Unable to determine bitrate: returnCode=" + returnCode);
                AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineBitrate - " + returnCode);
                var extension = Path.GetExtension(InputFileObject.SourceFileInfo.Name);
                if (extension != null)
                    AnalyticsHelper.FireEvent("Each video - scan result - UnableToDetermineBitrate - " + returnCode + " - " + extension.ToLowerInvariant());
                return false;
            }
            catch (Exception ex)
            {
                Logger.Error("ScanWorker[" + Id + "]: Exception while determining bitrate: " + ex);
                return false;
            }
        }