//------------------------------------------------------------------------------
    ByteBufferUPtr BinaryInputStream::Read(u64 length) noexcept
    {
        CS_ASSERT(IsValid(), "Trying to use an invalid FileStream.");
        
        if(m_fileStream.eof())
        {
            return nullptr;
        }
        
        //Ensure that we never overrun the file stream
        const auto currentPosition = GetReadPosition();
        const auto maxValidLength = std::min(m_length - currentPosition, length);
        
        if(maxValidLength == 0)
        {
            return nullptr;
        }
        
        s8* data = new s8[maxValidLength];
        m_fileStream.read(data, maxValidLength);
        
        CS_ASSERT(!m_fileStream.fail(), "Unexpected error occured in filestream");

        std::unique_ptr<const u8[]> uniqueData(reinterpret_cast<const u8*>(data));
        return ByteBufferUPtr(new ByteBuffer(std::move(uniqueData), u32(maxValidLength)));
    }
Beispiel #2
0
uint64_t BDRingBuffer::Seek(uint64_t pos)
{
    VERBOSE(VB_PLAYBACK|VB_EXTRA, LOC + QString("Seeking to %1.")
                .arg(pos));

    bd_seek_time(bdnav, pos);

    return GetReadPosition();
}
 //------------------------------------------------------------------------------
 bool BinaryInputStream::Read(u8* buffer, u64 length) noexcept
 {
     CS_ASSERT(IsValid(), "Trying to use an invalid FileStream.");
     
     if(m_fileStream.eof())
     {
         return false;
     }
     
     //Ensure that we never overrun the file stream
     const auto currentPosition = GetReadPosition();
     const auto maxValidLength = std::min(m_length - currentPosition, length);
     
     if(maxValidLength == 0)
     {
         return true;
     }
     
     m_fileStream.read(reinterpret_cast<s8*>(buffer), maxValidLength);
     
     CS_ASSERT(!m_fileStream.fail(), "Unexpected error occured in filestream");
     
     return true;
 }