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 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()); } }