Exemple #1
0
        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 (m_outputStream.CanSeek)
                {
                    m_HeaderPosition = m_outputStream.Position;
                    m_HeaderLength   = Length;
                }
                m_HeaderWrote = true;
                m_outputStream.Write(buffer, 0, (int)Length);
            }
            else if (m_outputStream.CanSeek && (Length == m_HeaderLength))
            {
                long pos = m_outputStream.Position;
                m_outputStream.Position = m_HeaderPosition;
                m_outputStream.Write(buffer, 0, (int)Length);
                m_outputStream.Position = pos;
            }
        }
Exemple #2
0
 /// <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 void Write(byte[] buffer, int index, int count)
 {
     if ((count % m_inputFormat.BlockAlign) == 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_inputFormat.AverageBytesPerSecond;
     }
     else
     {
         throw new ArgumentException(string.Format("Invalid buffer size. Buffer size must be aligned to {0} bytes.", m_inputFormat.BlockAlign), "count");
     }
 }
Exemple #3
0
        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);
            }
            m_outputStream.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();
            }
        }
Exemple #5
0
 /// <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 void Write(byte[] buffer, int index, int count)
 {
     if ((count % m_inputFormat.BlockAlign) == 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_inputFormat.AverageBytesPerSecond;
     }
     else
     {
         throw new ArgumentException(string.Format("Invalid buffer size. Buffer size must be aligned to {0} bytes.", m_inputFormat.BlockAlign), "count");
     }
 }
Exemple #6
0
 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 (m_outputStream.CanSeek)
         {
             m_HeaderPosition = m_outputStream.Position;
             m_HeaderLength = Length;
         }
         m_HeaderWrote = true;
         m_outputStream.Write(buffer, 0, (int)Length);
     }
     else if (m_outputStream.CanSeek && (Length == m_HeaderLength))
     {
         long pos = m_outputStream.Position;
         m_outputStream.Position = m_HeaderPosition;
         m_outputStream.Write(buffer, 0, (int)Length);
         m_outputStream.Position = pos;
     }
 }
Exemple #7
0
 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);
     }
     m_outputStream.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();
     }
 }
 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_outputStream, out sample, out SampleTime, out Duration, out Flags, out m_outputNumber, out m_outputStream);
             }
             catch (COMException e)
             {
                 if (e.ErrorCode == WM.NS_E_NO_MORE_SAMPLES)
                 { //No more samples
                     if (m_outputFormat.BitsPerSample == 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 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_outputStream, out sample, out SampleTime, out Duration, out Flags, out m_outputNumber, out m_outputStream);
             }
             catch (COMException e)
             {
                 if (e.ErrorCode == WM.NS_E_NO_MORE_SAMPLES)
                 { //No more samples
                     if (m_outputFormat.BitsPerSample == 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());
     }
 }