public void OnHeader([In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pHeader) { byte[] buffer; uint Length; if (pHeader is ManBuffer) { buffer = ((ManBuffer)pHeader).Buffer; Length = ((ManBuffer)pHeader).UsedLength; } else { NSSBuffer b = new NSSBuffer(pHeader); Length = b.Length; buffer = new byte[Length]; b.Read(buffer, 0, (int)Length); } if (!m_HeaderWrote) { if (BaseStream.CanSeek) { m_HeaderPosition = BaseStream.Position; m_HeaderLength = Length; } m_HeaderWrote = true; base.Write(buffer, 0, (int)Length); } else if (BaseStream.CanSeek && (Length == m_HeaderLength)) { long pos = BaseStream.Position; BaseStream.Position = m_HeaderPosition; BaseStream.Write(buffer, 0, (int)Length); BaseStream.Position = pos; } }
/// <summary> /// Write a buffer of uncompressed PCM data to the buffer. /// </summary> /// <param name="buffer">Byte array defining the buffer to write.</param> /// <param name="index">Index of first value to write</param> /// <param name="count">NUmber of byte to write. Must be multiple of PCM sample size <see cref="Yeti.WMFSdk.WmaWriterConfig.Format.nBlockAlign"/></param> public override void Write(byte[] buffer, int index, int count) { if ((count % m_InputDataFormat.nBlockAlign) == 0) { INSSBuffer IBuff; NSSBuffer NssBuff; m_Writer.AllocateSample((uint)count, out IBuff); NssBuff = new NSSBuffer(IBuff); NssBuff.Write(buffer, index, count); NssBuff.Length = (uint)count; m_Writer.WriteSample(0, m_MsAudioTime * 10000, 0, IBuff); m_MsAudioTime += ((ulong)count * 1000) / (ulong)m_InputDataFormat.nAvgBytesPerSec; } else { throw new ArgumentException( string.Format("Invalid buffer size. Buffer size must be aligned to {0} bytes.", m_InputDataFormat.nBlockAlign), "count"); } }
public void OnDataUnit([In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pDataUnit) { byte[] buffer; int Length; if (pDataUnit is ManBuffer) { buffer = ((ManBuffer)pDataUnit).Buffer; Length = (int)((ManBuffer)pDataUnit).UsedLength; } else { NSSBuffer b = new NSSBuffer(pDataUnit); Length = (int)b.Length; buffer = new byte[Length]; b.Read(buffer, 0, Length); } base.Write(buffer, 0, Length); }
public override long Seek(long offset, SeekOrigin origin) { if (CanSeek) { switch (origin) { case SeekOrigin.Current: offset += m_Position; break; case SeekOrigin.End: offset += m_Length; break; } if (offset == m_Position) { return(m_Position); // :-) } if ((offset < 0) || (offset > m_Length)) { throw new ArgumentException("Offset out of range", "offset"); } if ((offset % SeekAlign) > 0) { throw new ArgumentException(string.Format("Offset must be aligned by a value of SeekAlign ({0})", SeekAlign), "offset"); } ulong SampleTime = BytePosition2SampleTime(offset); m_Reader.SetRange(SampleTime, 0); m_Position = offset; m_BufferReader = null; return(offset); } else { throw new NotSupportedException(); } }
/// <summary> /// Write a buffer of uncompressed PCM data to the buffer. /// </summary> /// <param name="buffer">Byte array defining the buffer to write.</param> /// <param name="index">Index of first value to write</param> /// <param name="count">NUmber of byte to write. Must be multiple of PCM sample size <see cref="Yeti.WMFSdk.WmaWriterConfig.Format.nBlockAlign"/></param> public override void Write(byte[] buffer, int index, int count) { if ( (count % m_InputDataFormat.nBlockAlign) == 0 ) { INSSBuffer IBuff; NSSBuffer NssBuff; m_Writer.AllocateSample((uint)count, out IBuff); NssBuff = new NSSBuffer(IBuff); NssBuff.Write(buffer, index, count); NssBuff.Length = (uint)count; m_Writer.WriteSample(0, m_MsAudioTime*10000, 0, IBuff); m_MsAudioTime += ((ulong)count*1000)/(ulong)m_InputDataFormat.nAvgBytesPerSec; } else { throw new ArgumentException(string.Format("Invalid buffer size. Buffer size must be aligned to {0} bytes.", m_InputDataFormat.nBlockAlign), "count"); } }
public void OnDataUnit( [In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pDataUnit ) { byte[] buffer; int Length; if (pDataUnit is ManBuffer) { buffer = ((ManBuffer)pDataUnit).Buffer; Length = (int)((ManBuffer)pDataUnit).UsedLength; } else { NSSBuffer b = new NSSBuffer(pDataUnit); Length = (int)b.Length; buffer = new byte[Length]; b.Read(buffer, 0, Length); } base.Write(buffer, 0, Length); }
public void OnHeader( [In, MarshalAs(UnmanagedType.Interface)] INSSBuffer pHeader ) { byte[] buffer; uint Length; if ( pHeader is ManBuffer) { buffer = ((ManBuffer)pHeader).Buffer; Length = ((ManBuffer)pHeader).UsedLength; } else { NSSBuffer b = new NSSBuffer(pHeader); Length = b.Length; buffer = new byte[Length]; b.Read(buffer, 0, (int)Length); } if ( !m_HeaderWrote ) { if (BaseStream.CanSeek) { m_HeaderPosition = BaseStream.Position; m_HeaderLength = Length; } m_HeaderWrote = true; base.Write(buffer, 0, (int)Length); } else if (BaseStream.CanSeek && (Length == m_HeaderLength) ) { long pos = BaseStream.Position; BaseStream.Position = m_HeaderPosition; BaseStream.Write(buffer, 0, (int)Length); BaseStream.Position = pos; } }
public override int Read(byte[] buffer, int offset, int count) { if (m_Reader != null) { int read = 0; if ((m_Length > 0) && ((m_Length - m_Position) < count)) { count = (int)(m_Length - m_Position); } if (m_BufferReader != null) { while ((m_BufferReader.Position < m_BufferReader.Length) && (read < count)) { read += m_BufferReader.Read(buffer, offset, count); } } while (read < count) { INSSBuffer sample = null; ulong SampleTime = 0; ulong Duration = 0; uint Flags = 0; try { m_Reader.GetNextSample(m_OuputStream, out sample, out SampleTime, out Duration, out Flags, out m_OutputNumber, out m_OuputStream); } catch (COMException e) { if (e.ErrorCode == WM.NS_E_NO_MORE_SAMPLES) { //No more samples if (m_OutputFormat.wBitsPerSample == 8) { while (read < count) { buffer[offset + read] = 0x80; read++; } } else { Array.Clear(buffer, offset + read, count - read); read = count; } break; } else { throw(e); } } m_BufferReader = new NSSBuffer(sample); read += m_BufferReader.Read(buffer, offset + read, count - read); } if ((m_BufferReader != null) && (m_BufferReader.Position >= m_BufferReader.Length)) { m_BufferReader = null; } m_Position += read; return(read); } else { throw new ObjectDisposedException(this.ToString()); } }
public override long Seek(long offset, SeekOrigin origin) { if ( CanSeek ) { switch (origin) { case SeekOrigin.Current: offset += m_Position; break; case SeekOrigin.End: offset += m_Length; break; } if (offset == m_Position) { return m_Position; // :-) } if ( (offset < 0) || ( offset > m_Length) ) { throw new ArgumentException("Offset out of range", "offset"); } if ( (offset % SeekAlign) > 0 ) { throw new ArgumentException(string.Format("Offset must be aligned by a value of SeekAlign ({0})", SeekAlign), "offset"); } ulong SampleTime = BytePosition2SampleTime(offset); m_Reader.SetRange(SampleTime, 0); m_Position = offset; m_BufferReader = null; return offset; } else { throw new NotSupportedException(); } }
public override int Read(byte[] buffer, int offset, int count) { if (m_Reader != null) { int read = 0; if ( (m_Length > 0) && ( (m_Length-m_Position) < count) ) { count = (int)(m_Length-m_Position); } if (m_BufferReader != null) { while ( (m_BufferReader.Position < m_BufferReader.Length) && (read < count) ) { read += m_BufferReader.Read(buffer, offset, count); } } while (read < count) { INSSBuffer sample = null; ulong SampleTime = 0; ulong Duration = 0; uint Flags = 0; try { m_Reader.GetNextSample(m_OuputStream, out sample, out SampleTime, out Duration, out Flags, out m_OutputNumber, out m_OuputStream); } catch (COMException e) { if (e.ErrorCode == WM.NS_E_NO_MORE_SAMPLES) { //No more samples if (m_OutputFormat.wBitsPerSample == 8) { while ( read < count ) { buffer[offset+read] = 0x80; read++; } } else { Array.Clear(buffer, offset+read, count-read); read = count; } break; } else { throw (e); } } m_BufferReader = new NSSBuffer(sample); read += m_BufferReader.Read(buffer, offset+read, count-read); } if ( (m_BufferReader != null) && (m_BufferReader.Position >= m_BufferReader.Length) ) { m_BufferReader = null; } m_Position += read; return read; } else { throw new ObjectDisposedException(this.ToString()); } }