示例#1
0
        public override bool ValueEquals(WithPresentation other)
        {
            if (!base.ValueEquals(other))
            {
                return(false);
            }

            ExternalVideoMedia otherz = other as ExternalVideoMedia;

            if (otherz == null)
            {
                return(false);
            }

            if (Src != otherz.Src)
            {
                return(false);
            }

            if (!ClipBegin.IsEqualTo(otherz.ClipBegin))
            {
                return(false);
            }
            if (!ClipEnd.IsEqualTo(otherz.ClipEnd))
            {
                return(false);
            }

            return(true);
        }
示例#2
0
 /// <summary>
 /// Determines of <c>this</c> has the same value as a given other instance
 /// </summary>
 /// <param name="other">The other instance</param>
 /// <returns>A <see cref="bool"/> indicating the result</returns>
 public bool ValueEquals(WavClip other)
 {
     if (other == null)
     {
         //System.Diagnostics.Debug.Fail("! ValueEquals !");
         return(false);
     }
     if (other.GetType() != GetType())
     {
         //System.Diagnostics.Debug.Fail("! ValueEquals !");
         return(false);
     }
     if (!ClipBegin.IsEqualTo(other.ClipBegin))
     {
         //System.Diagnostics.Debug.Fail("! ValueEquals !");
         return(false);
     }
     if (IsClipEndTiedToEOM != other.IsClipEndTiedToEOM)
     {
         //System.Diagnostics.Debug.Fail("! ValueEquals !");
         return(false);
     }
     if (!ClipEnd.IsEqualTo(other.ClipEnd))
     {
         //System.Diagnostics.Debug.Fail("! ValueEquals !");
         return(false);
     }
     if (!DataProvider.ValueEquals(other.DataProvider))
     {
         //System.Diagnostics.Debug.Fail("! ValueEquals !");
         return(false);
     }
     return(true);
 }
示例#3
0
        /// <summary>
        /// Exports the external audio media to a destination <see cref="Presentation"/>
        /// - part of technical construct to have <see cref="Export"/> return <see cref="ExternalAudioMedia"/>
        /// </summary>
        /// <param name="destPres">The destination presentation</param>
        /// <returns>The exported external audio media</returns>
        protected override Media ExportProtected(Presentation destPres)
        {
            ExternalAudioMedia exported = (ExternalAudioMedia)base.ExportProtected(destPres);

            exported.Src       = Src;
            exported.ClipBegin = ClipBegin.Copy();
            exported.ClipEnd   = ClipEnd.Copy();
            return(exported);
        }
示例#4
0
        ///<summary>
        ///
        ///</summary>
        ///<returns></returns>
        protected override Media CopyProtected()
        {
            ExternalAudioMedia copy = (ExternalAudioMedia)base.CopyProtected();

            copy.Src       = Src;
            copy.ClipBegin = ClipBegin.Copy();
            copy.ClipEnd   = ClipEnd.Copy();
            return(copy);
        }
示例#5
0
        /// <summary>
        /// Exports the external video media to a destination <see cref="Presentation"/>
        /// </summary>
        /// <param name="destPres">The destination presentation</param>
        /// <returns>The exported external video media</returns>
        protected override Media ExportProtected(Presentation destPres)
        {
            ExternalVideoMedia exported = (ExternalVideoMedia)base.ExportProtected(destPres);

            exported.Src = Src;
            if (ClipBegin.IsNegative)
            {
                exported.ClipBegin = ClipBegin.Copy();
                exported.ClipEnd   = ClipEnd.Copy();
            }
            else
            {
                exported.ClipEnd   = ClipEnd.Copy();
                exported.ClipBegin = ClipBegin.Copy();
            }
            exported.Width  = Width;
            exported.Height = Height;
            return(exported);
        }
示例#6
0
        ///<summary>
        ///
        ///</summary>
        ///<returns></returns>
        protected override Media CopyProtected()
        {
            ExternalVideoMedia copy = (ExternalVideoMedia)base.CopyProtected();

            copy.Src = Src;
            if (ClipBegin.IsNegative)
            {
                copy.ClipBegin = ClipBegin.Copy();
                copy.ClipEnd   = ClipEnd.Copy();
            }
            else
            {
                copy.ClipEnd   = ClipEnd.Copy();
                copy.ClipBegin = ClipBegin.Copy();
            }
            copy.Width  = Width;
            copy.Height = Height;
            return(copy);
        }
示例#7
0
        /// <summary>
        /// Gets an input <see cref="Stream"/> providing read access to the raw PCM audio data
        /// between given sub-clip begin and end times
        /// </summary>
        /// <param name="subClipBegin">The beginning of the sub-clip</param>
        /// <param name="subClipEnd">The end of the sub-clip</param>
        /// <returns>The raw PCM audio data <see cref="Stream"/></returns>
        /// <remarks>
        /// <para>Sub-clip times must be in the interval <c>[0;this.getAudioDuration()]</c>.</para>
        /// <para>
        /// The sub-clip is
        /// relative to clip begin of the WavClip, that if <c>this.getClipBegin()</c>
        /// returns <c>00:00:10</c>, <c>this.getClipEnd()</c> returns <c>00:00:50</c>,
        /// <c>x</c> and <c>y</c> is <c>00:00:05</c> and <c>00:00:30</c> respectively,
        /// then <c>this.GetAudioData(x, y)</c> will get the audio in the underlying wave audio between
        /// <c>00:00:15</c> and <c>00:00:40</c>
        /// </para>
        /// </remarks>
        public Stream OpenPcmInputStream(Time subClipBegin, Time subClipEnd)
        {
            if (subClipBegin == null)
            {
                throw new exception.MethodParameterIsNullException("subClipBegin must not be null");
            }
            if (subClipEnd == null)
            {
                throw new exception.MethodParameterIsNullException("subClipEnd must not be null");
            }
            if (
                subClipBegin.IsLessThan(Time.Zero) ||
                subClipEnd.IsLessThan(subClipBegin) ||
                subClipEnd.IsGreaterThan(Duration)
                )
            {
                string msg = String.Format(
                    "subClipBegin/subClipEnd [{0};{1}] not within ([0;{2}])",
                    subClipBegin, subClipEnd, Duration);
                throw new exception.MethodParameterIsOutOfBoundsException(msg);
            }

            Stream            raw = DataProvider.OpenInputStream();
            uint              dataLength;
            AudioLibPCMFormat format     = AudioLibPCMFormat.RiffHeaderParse(raw, out dataLength);
            Time              rawEndTime = new Time(format.ConvertBytesToTime(dataLength));

#if DEBUG
            DebugFix.Assert(rawEndTime.IsEqualTo(MediaDuration));
#endif

            //Time rawEndTime = Time.Zero.Add(MediaDuration); // We don't call this to avoid unnecessary I/O (Strem.Open() twice)

            if (
                ClipBegin.IsLessThan(Time.Zero) ||
                ClipBegin.IsGreaterThan(ClipEnd) ||
                ClipEnd.IsGreaterThan(rawEndTime)
                )
            {
                string msg = String.Format(
                    "WavClip [{0};{1}] is empty or not within the underlying wave data stream ([0;{2}])",
                    ClipBegin, ClipEnd, rawEndTime);
                throw new exception.InvalidDataFormatException(msg);
            }

            /*
             * Time clipDuration = Duration;
             * if (subClipBegin.IsEqualTo(Time.Zero) && subClipEnd.IsEqualTo(Time.Zero.Add(clipDuration)))
             * {
             *  // Stream.Position is at the end of the RIFF header, we need to bring it back to the begining
             *  return new SubStream(
             *  raw,
             *  raw.Position, raw.Length - raw.Position);
             * }
             */

            //Time rawClipBegin = new Time(ClipBegin.AsTimeSpan + subClipBegin.AsTimeSpan);
            //Time rawClipEnd = new Time(ClipBegin.AsTimeSpan + subClipEnd.AsTimeSpan);

            long ClipBegin_AsLocalUnits = ClipBegin.AsLocalUnits;

            long posRiffHeader = raw.Position; //44

            long beginPos = posRiffHeader + format.ConvertTimeToBytes(ClipBegin_AsLocalUnits + subClipBegin.AsLocalUnits);
            long endPos   = posRiffHeader + format.ConvertTimeToBytes(ClipBegin_AsLocalUnits + subClipEnd.AsLocalUnits);

            long rawLen = raw.Length;
#if DEBUG
            long rawLenCheck = posRiffHeader + dataLength;
            DebugFix.Assert(rawLen == rawLenCheck);
#endif
            if (endPos > rawLen)
            {
//#if DEBUG
//                Debugger.Break();
//#endif
                endPos = rawLen;
            }

            long len = endPos - beginPos;

            return(new SubStream(
                       raw,
                       beginPos,
                       len,
                       DataProvider is FileDataProvider ? ((FileDataProvider)DataProvider).DataFileFullPath : null));
        }