LibMedia: Add a method to get the available bytes from a MediaStream
This will be used to determine the buffered time ranges.
This commit is contained in:
parent
c7eee655c2
commit
c4514c27ab
3 changed files with 18 additions and 0 deletions
|
|
@ -101,6 +101,15 @@ void IncrementallyPopulatedStream::add_chunk_at(u64 offset, ReadonlyBytes data)
|
|||
m_state_changed.broadcast();
|
||||
}
|
||||
|
||||
Vector<MediaStream::ByteRange> IncrementallyPopulatedStream::available_byte_ranges() const
|
||||
{
|
||||
Sync::MutexLocker locker { m_mutex };
|
||||
Vector<ByteRange> ranges;
|
||||
for (auto it = m_chunks.begin(); it != m_chunks.end(); ++it)
|
||||
ranges.empend(it->offset(), it->end());
|
||||
return ranges;
|
||||
}
|
||||
|
||||
void IncrementallyPopulatedStream::close()
|
||||
{
|
||||
Sync::MutexLocker locker { m_mutex };
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ public:
|
|||
|
||||
void close();
|
||||
|
||||
virtual Vector<ByteRange> available_byte_ranges() const override;
|
||||
|
||||
u64 size();
|
||||
void set_expected_size(u64);
|
||||
Optional<u64> expected_size() const;
|
||||
|
|
|
|||
|
|
@ -32,9 +32,16 @@ public:
|
|||
|
||||
class MediaStream : public AtomicRefCounted<MediaStream> {
|
||||
public:
|
||||
struct ByteRange {
|
||||
size_t start { 0 };
|
||||
size_t end { 0 };
|
||||
};
|
||||
|
||||
virtual ~MediaStream() = default;
|
||||
|
||||
virtual NonnullRefPtr<MediaStreamCursor> create_cursor() = 0;
|
||||
|
||||
virtual Vector<ByteRange> available_byte_ranges() const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue