public override bool ValueEquals(WithPresentation other) { if (!base.ValueEquals(other)) { return(false); } AudioMediaData otherz = other as AudioMediaData; if (otherz == null) { return(false); } if (OriginalRelativePath != null && DataProvider != null) { if (OriginalRelativePath != otherz.OriginalRelativePath) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } if (!DataProvider.ValueEquals(otherz.DataProvider)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } return(true); } if (!PCMFormat.ValueEquals(otherz.PCMFormat)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } if (PCMFormat.Data.ConvertTimeToBytes(AudioDuration.AsLocalUnits) != otherz.PCMFormat.Data.ConvertTimeToBytes(otherz.AudioDuration.AsLocalUnits)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } if (HasActualPcmData != otherz.HasActualPcmData) { return(false); } if (HasActualPcmData) { Stream thisData = OpenPcmInputStream(); try { Stream otherdata = otherz.OpenPcmInputStream(); try { if (!AudioLibPCMFormat.CompareStreamData(thisData, otherdata, (int)thisData.Length)) { //System.Diagnostics.Debug.Fail("! ValueEquals !"); return(false); } } finally { otherdata.Close(); } } finally { thisData.Close(); } } return(true); }
private static void CheckPublishedFiles(TreeNode node, Channel sourceCh, Channel destCh, Uri curWavUri_, MemoryStream curAudioData, PCMFormatInfo curPCMFormat) { Uri curWavUri = (curWavUri_ == null ? null : new Uri(curWavUri_.ToString())); if (node.HasProperties(typeof(ChannelsProperty))) { ChannelsProperty chProp = node.GetProperty <ChannelsProperty>(); ManagedAudioMedia mam = chProp.GetMedia(sourceCh) as ManagedAudioMedia; ExternalAudioMedia eam = chProp.GetMedia(destCh) as ExternalAudioMedia; //Assert.AreEqual(mam == null, eam == null, "There may be external audio media if and only if there is managed audio media"); if (mam != null && eam != null) { Assert.IsTrue(mam.Duration.IsEqualTo(eam.Duration), "Duration of managed and external audio media differs"); if (eam.Uri != null) { FileStream wavFS_ = new FileStream(eam.Uri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.None); Stream manAudioStream = mam.AudioMediaData.OpenPcmInputStream(); try { uint dataLength; AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavFS_, out dataLength); Assert.IsTrue(pcmInfo.IsCompatibleWith(mam.AudioMediaData.PCMFormat.Data), "External audio has incompatible pcm format"); wavFS_.Position += pcmInfo.ConvertTimeToBytes(eam.ClipBegin.TimeAsMillisecondFloat); Assert.IsTrue( AudioLibPCMFormat.CompareStreamData(manAudioStream, wavFS_, (int)manAudioStream.Length), "External audio contains wrong data"); } finally { wavFS_.Close(); manAudioStream.Close(); } } if (curWavUri != null) { FileStream wavFS = new FileStream(curWavUri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.None); try { uint dataLength; AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavFS, out dataLength); Assert.IsTrue(pcmInfo.IsCompatibleWith(curPCMFormat.Data), "External audio has incompatible pcm format"); curAudioData.Position = 0; Assert.AreEqual(curAudioData.Length, (long)dataLength, "External audio has unexpected length"); Assert.IsTrue( AudioLibPCMFormat.CompareStreamData(curAudioData, wavFS, (int)curAudioData.Length), "External audio contains wrong data"); } finally { wavFS.Close(); } } if (curWavUri == null) { curWavUri = new Uri(eam.Uri.ToString()); curAudioData = new MemoryStream(); curPCMFormat = mam.AudioMediaData.PCMFormat; } else if (curWavUri.ToString() != eam.Uri.ToString()) { curWavUri = new Uri(eam.Uri.ToString()); curAudioData = new MemoryStream(); curPCMFormat = mam.AudioMediaData.PCMFormat; } Assert.IsTrue(curPCMFormat.ValueEquals(mam.AudioMediaData.PCMFormat), "Managed audio has incompatible pcm format"); Stream manAudio = mam.AudioMediaData.OpenPcmInputStream(); try { media.data.StreamUtils.CopyData(manAudio, curAudioData); } finally { manAudio.Close(); } } } foreach (TreeNode child in node.Children.ContentsAs_YieldEnumerable) { CheckPublishedFiles(child, sourceCh, destCh, curWavUri, curAudioData, curPCMFormat); } }