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:
Zaggy1024 2026-03-29 01:45:55 -05:00 committed by Gregory Bertilson
parent c7eee655c2
commit c4514c27ab
3 changed files with 18 additions and 0 deletions

View file

@ -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 };

View file

@ -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;

View file

@ -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;
};
}