Esempio n. 1
0
        /// <summary>
        /// Create an <see cref="FFMSSharp.AudioSource">AudioSource object</see>
        /// </summary>
        /// <remarks>
        /// <para>In FFMS2, the equivalent is <c>FFMS_CreateAudioSource</c>.</para>
        /// <para>Note that the index object is copied into the <see cref="FFMSSharp.AudioSource">AudioSource object</see> upon its creation, so once you've created the video source you can generally destroy the index object immediately, since all info you can retrieve from it is also retrievable from the <see cref="FFMSSharp.AudioSource">AudioSource object</see>.</para>
        /// </remarks>
        /// <param name="sourceFile">The media file. Can be an absolute or relative path</param>
        /// <param name="track">Track number of the specific audio track</param>
        /// <param name="delayMode">Controls how audio with a non-zero first PTS is handled; in other words what FFMS does about audio delay.</param>
        /// <returns>The generated <see cref="FFMSSharp.AudioSource">AudioSource object</see></returns>
        /// <seealso cref="VideoSource"/>
        /// <seealso cref="GetFirstTrackOfType"/>
        /// <seealso cref="GetFirstIndexedTrackOfType"/>
        /// <exception cref="System.IO.FileLoadException">Failure to open the <paramref name="sourceFile"/></exception>
        /// <exception cref="System.IO.FileNotFoundException">Trying to read a file that does not exist.</exception>
        /// <exception cref="ArgumentException">Trying to make a AudioSource out of an invalid track</exception>
        /// <exception cref="InvalidOperationException">Supplying the wrong <paramref name="sourceFile"/></exception>
        public AudioSource AudioSource(string sourceFile, int track, AudioDelayMode delayMode = AudioDelayMode.FirstVideoTrack)
        {
            if (sourceFile == null)
            {
                throw new ArgumentNullException(@"sourceFile");
            }

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

            var sourceFileBytes = Encoding.UTF8.GetBytes(sourceFile);
            var audioSource     = NativeMethods.FFMS_CreateAudioSource(sourceFileBytes, track, _handle, (int)delayMode, ref err);

            if (audioSource != IntPtr.Zero)
            {
                return(new AudioSource(audioSource));
            }

            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_PARSER && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_READ)
            {
                throw new System.IO.FileLoadException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_NO_FILE)
            {
                throw new System.IO.FileNotFoundException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_INVALID_ARGUMENT)
            {
                throw new ArgumentException(err.Buffer);
            }
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_MISMATCH)
            {
                throw new InvalidOperationException(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));
        }
Esempio n. 2
0
        /// <summary>
        /// Create an <see cref="FFMSSharp.AudioSource">AudioSource object</see>
        /// </summary>
        /// <remarks>
        /// <para>In FFMS2, the equivalent is <c>FFMS_CreateAudioSource</c>.</para>
        /// <para>Note that the index object is copied into the <see cref="FFMSSharp.AudioSource">AudioSource object</see> upon its creation, so once you've created the video source you can generally destroy the index object immediately, since all info you can retrieve from it is also retrievable from the <see cref="FFMSSharp.AudioSource">AudioSource object</see>.</para>
        /// </remarks>
        /// <param name="sourceFile">The media file. Can be an absolute or relative path</param>
        /// <param name="track">Track number of the specific audio track</param>
        /// <param name="delayMode">Controls how audio with a non-zero first PTS is handled; in other words what FFMS does about audio delay.</param>
        /// <returns>The generated <see cref="FFMSSharp.AudioSource">AudioSource object</see></returns>
        /// <seealso cref="VideoSource"/>
        /// <seealso cref="GetFirstTrackOfType"/>
        /// <seealso cref="GetFirstIndexedTrackOfType"/>
        /// <exception cref="System.IO.FileLoadException">Failure to open the <paramref name="sourceFile"/></exception>
        /// <exception cref="System.IO.FileNotFoundException">Trying to read a file that does not exist.</exception>
        /// <exception cref="ArgumentException">Trying to make a AudioSource out of an invalid track</exception>
        /// <exception cref="InvalidOperationException">Supplying the wrong <paramref name="sourceFile"/></exception>
        public AudioSource AudioSource(string sourceFile, int track, AudioDelayMode delayMode = AudioDelayMode.FirstVideoTrack)
        {
            if (sourceFile == null) throw new ArgumentNullException(@"sourceFile");

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

            var sourceFileBytes = Encoding.UTF8.GetBytes(sourceFile);
            var audioSource = NativeMethods.FFMS_CreateAudioSource(sourceFileBytes, track, _handle, (int)delayMode, ref err);

            if (audioSource != IntPtr.Zero) return new AudioSource(audioSource);

            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_PARSER && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_READ)
                throw new System.IO.FileLoadException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_NO_FILE)
                throw new System.IO.FileNotFoundException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_INVALID_ARGUMENT)
                throw new ArgumentException(err.Buffer);
            if (err.ErrorType == FFMS_Errors.FFMS_ERROR_INDEX && err.SubType == FFMS_Errors.FFMS_ERROR_FILE_MISMATCH)
                throw new InvalidOperationException(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));
        }