Example #1
0
        /// <summary>
        /// Index the media file
        /// </summary>
        /// <remarks>
        /// <para>In FFMS2, the equivalent is <c>FFMS_DoIndexing</c>.</para>
        /// <para>By default, you will index all <see cref="TrackType.Audio">Audio</see> tracks.</para>
        /// </remarks>
        /// <param name="audioIndex">A list of specific <see cref="TrackType.Audio">Audio</see> tracks to index</param>
        /// <param name="audioDump">A list of <see cref="TrackType.Audio">Audio</see> tracks to dump while indexing</param>
        /// <param name="audioDumpFileName">The filename format for audio tracks getting dumped
        /// <para>The following variables can be used:</para>
        /// <para><c>%sourcefile%</c> - same as the source file name, i.e. the file the audio is decoded from</para>
        /// <para><c>%trackn%</c> - the track number</para>
        /// <para><c>%trackzn%</c> - the track number zero padded to 2 digits</para>
        /// <para><c>%samplerate%</c> - the audio sample rate</para>
        /// <para><c>%channels%</c> - number of audio channels</para>
        /// <para><c>%bps%</c> - bits per sample</para>
        /// <para><c>%delay%</c> - delay, or more exactly the first timestamp encountered in the audio stream</para>
        /// <para>Example string: <c>%sourcefile%_track%trackzn%.w64</c></para></param>
        /// <param name="indexErrorHandling">Control behavior when a decoding error is encountered</param>
        /// <returns>The generated <see cref="FFMSSharp.Index">Index</see> object</returns>
        /// <event cref="UpdateIndexProgress">Called to give you an update on indexing progress</event>
        /// <event cref="OnIndexingCompleted">Called when the indexing has finished</event>
        /// <exception cref="NotSupportedException">Attempting to index a codec not supported by the indexer</exception>
        /// <exception cref="System.IO.InvalidDataException">Failure to index a file that should be supported</exception>
        /// <exception cref="OperationCanceledException">Canceling the indexing process</exception>
        /// <exception cref="ObjectDisposedException">Calling this function after you have already called <see cref="Index"/>.</exception>
        public Index Index(IEnumerable <int> audioIndex = null, IEnumerable <int> audioDump = null, string audioDumpFileName = null, IndexErrorHandling indexErrorHandling = IndexErrorHandling.Abort)
        {
            if (_handle.IsInvalid)
            {
                throw new ObjectDisposedException(@"Indexer");
            }

            var indexMask = -1;

            if (audioIndex != null)
            {
                indexMask = audioIndex.Aggregate(0, (current, track) => current | (1 << track));
            }

            var dumpMask = 0;

            if (audioDump != null)
            {
                if (audioDumpFileName == null)
                {
                    throw new ArgumentNullException(@"audioDumpFileName", "You must specify a filename format if you want to dump audio files.");
                }

                dumpMask = audioDump.Aggregate(dumpMask, (current, track) => current | (1 << track));
            }

            var err = new FFMS_ErrorInfo
            {
                BufferSize = 1024,
                Buffer     = new String((char)0, 1024)
            };
            SafeIndexHandle index;

            IsIndexing     = true;
            CancelIndexing = false;

            lock (this)
            {
                index = NativeMethods.FFMS_DoIndexing(_handle, indexMask, dumpMask, AudioNameCallback, audioDumpFileName, (int)indexErrorHandling, IndexingCallback, IntPtr.Zero, ref err);
            }

            _handle.SetHandleAsInvalid(); // "Note that calling this function destroys the FFMS_Indexer object and frees the memory allocated by FFMS_CreateIndexer (even if indexing fails for any reason)."
            IsIndexing = false;

            if (!index.IsInvalid)
            {
                return(new Index(index));
            }

            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_CODEC && err.SubType == FFMS_Errors.FFMS_ERROR_UNSUPPORTED)
            {
                throw new NotSupportedException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_UNSUPPORTED && err.SubType == FFMS_Errors.FFMS_ERROR_DECODING)
            {
                throw new NotSupportedException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_CODEC && err.SubType == FFMS_Errors.FFMS_ERROR_DECODING)
            {
                throw new System.IO.InvalidDataException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_CANCELLED && err.SubType == FFMS_Errors.FFMS_ERROR_USER)
            {
                throw new OperationCanceledException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEXING && err.SubType == FFMS_Errors.FFMS_ERROR_PARSER)
            {
                throw new System.IO.InvalidDataException(err.Buffer);
            }

            throw new NotImplementedException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unknown FFMS2 error encountered: ({0}, {1}, '{2}'). Please report this issue on FFMSSharp's GitHub.", err.ErrorType, err.SubType, err.Buffer));
        }
Example #2
0
        /// <summary>
        /// Index the media file
        /// </summary>
        /// <remarks>
        /// <para>In FFMS2, the equivalent is <c>FFMS_DoIndexing</c>.</para>
        /// <para>By default, you will index all <see cref="TrackType.Audio">Audio</see> tracks.</para>
        /// </remarks>
        /// <param name="audioIndex">A list of specific <see cref="TrackType.Audio">Audio</see> tracks to index</param>
        /// <param name="audioDump">A list of <see cref="TrackType.Audio">Audio</see> tracks to dump while indexing</param>
        /// <param name="audioDumpFileName">The filename format for audio tracks getting dumped
        /// <para>The following variables can be used:</para>
        /// <para><c>%sourcefile%</c> - same as the source file name, i.e. the file the audio is decoded from</para>
        /// <para><c>%trackn%</c> - the track number</para>
        /// <para><c>%trackzn%</c> - the track number zero padded to 2 digits</para>
        /// <para><c>%samplerate%</c> - the audio sample rate</para>
        /// <para><c>%channels%</c> - number of audio channels</para>
        /// <para><c>%bps%</c> - bits per sample</para>
        /// <para><c>%delay%</c> - delay, or more exactly the first timestamp encountered in the audio stream</para>
        /// <para>Example string: <c>%sourcefile%_track%trackzn%.w64</c></para></param>
        /// <param name="indexErrorHandling">Control behavior when a decoding error is encountered</param>
        /// <returns>The generated <see cref="FFMSSharp.Index">Index</see> object</returns>
        /// <event cref="UpdateIndexProgress">Called to give you an update on indexing progress</event>
        /// <event cref="OnIndexingCompleted">Called when the indexing has finished</event>
        /// <exception cref="NotSupportedException">Attempting to index a codec not supported by the indexer</exception>
        /// <exception cref="System.IO.InvalidDataException">Failure to index a file that should be supported</exception>
        /// <exception cref="OperationCanceledException">Canceling the indexing process</exception>
        /// <exception cref="ObjectDisposedException">Calling this function after you have already called <see cref="Index"/>.</exception>
        public Index Index(IEnumerable<int> audioIndex = null, IEnumerable<int> audioDump = null, string audioDumpFileName = null, IndexErrorHandling indexErrorHandling = IndexErrorHandling.Abort)
        {
            if (_handle.IsInvalid) throw new ObjectDisposedException(@"Indexer");

            var indexMask = -1;
            if (audioIndex != null)
            {
                indexMask = audioIndex.Aggregate(0, (current, track) => current | (1 << track));
            }

            var dumpMask = 0;
            if (audioDump != null)
            {
                if (audioDumpFileName == null)
                    throw new ArgumentNullException(@"audioDumpFileName", "You must specify a filename format if you want to dump audio files.");

                dumpMask = audioDump.Aggregate(dumpMask, (current, track) => current | (1 << track));
            }

            var err = new FFMS_ErrorInfo
            {
                BufferSize = 1024,
                Buffer = new String((char)0, 1024)
            };
            SafeIndexHandle index;
            IsIndexing = true;
            CancelIndexing = false;

            lock (this)
            {
                index = NativeMethods.FFMS_DoIndexing(_handle, indexMask, dumpMask, AudioNameCallback, audioDumpFileName, (int)indexErrorHandling, IndexingCallback, IntPtr.Zero, ref err);
            }

            _handle.SetHandleAsInvalid(); // "Note that calling this function destroys the FFMS_Indexer object and frees the memory allocated by FFMS_CreateIndexer (even if indexing fails for any reason)."
            IsIndexing = false;

            if (!index.IsInvalid) return new Index(index);

            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_CODEC && err.SubType == FFMS_Errors.FFMS_ERROR_UNSUPPORTED)
                throw new NotSupportedException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_UNSUPPORTED && err.SubType == FFMS_Errors.FFMS_ERROR_DECODING)
                throw new NotSupportedException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_CODEC && err.SubType == FFMS_Errors.FFMS_ERROR_DECODING)
                throw new System.IO.InvalidDataException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_CANCELLED && err.SubType == FFMS_Errors.FFMS_ERROR_USER)
                throw new OperationCanceledException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEXING && err.SubType == FFMS_Errors.FFMS_ERROR_PARSER)
                throw new System.IO.InvalidDataException(err.Buffer);

            throw new NotImplementedException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unknown FFMS2 error encountered: ({0}, {1}, '{2}'). Please report this issue on FFMSSharp's GitHub.", err.ErrorType, err.SubType, err.Buffer));
        }