зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1399751. P1 - pass a block index to AllocateAndWriteBlock() so it doesn't depend on mChannelOffset. r=gerald
MozReview-Commit-ID: EJmxrE5X6nA --HG-- extra : rebase_source : 0d89f6e1de8082ebe0fa3a20c1c8d2e34d4e1982
This commit is contained in:
Родитель
3a3834f7a8
Коммит
a00d1e2c0a
|
@ -173,8 +173,11 @@ public:
|
||||||
// Free all blocks belonging to aStream.
|
// Free all blocks belonging to aStream.
|
||||||
void ReleaseStreamBlocks(MediaCacheStream* aStream);
|
void ReleaseStreamBlocks(MediaCacheStream* aStream);
|
||||||
// Find a cache entry for this data, and write the data into it
|
// Find a cache entry for this data, and write the data into it
|
||||||
void AllocateAndWriteBlock(MediaCacheStream* aStream,
|
void AllocateAndWriteBlock(
|
||||||
MediaCacheStream::ReadMode aMode, Span<const uint8_t> aData1,
|
MediaCacheStream* aStream,
|
||||||
|
int32_t aStreamBlockIndex,
|
||||||
|
MediaCacheStream::ReadMode aMode,
|
||||||
|
Span<const uint8_t> aData1,
|
||||||
Span<const uint8_t> aData2 = Span<const uint8_t>());
|
Span<const uint8_t> aData2 = Span<const uint8_t>());
|
||||||
|
|
||||||
// mReentrantMonitor must be held; can be called on any thread
|
// mReentrantMonitor must be held; can be called on any thread
|
||||||
|
@ -1576,27 +1579,28 @@ MediaCache::InsertReadaheadBlock(BlockOwner* aBlockOwner,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaCache::AllocateAndWriteBlock(
|
MediaCache::AllocateAndWriteBlock(MediaCacheStream* aStream,
|
||||||
MediaCacheStream* aStream, MediaCacheStream::ReadMode aMode,
|
int32_t aStreamBlockIndex,
|
||||||
Span<const uint8_t> aData1, Span<const uint8_t> aData2)
|
MediaCacheStream::ReadMode aMode,
|
||||||
|
Span<const uint8_t> aData1,
|
||||||
|
Span<const uint8_t> aData2)
|
||||||
{
|
{
|
||||||
mReentrantMonitor.AssertCurrentThreadIn();
|
mReentrantMonitor.AssertCurrentThreadIn();
|
||||||
|
|
||||||
int32_t streamBlockIndex =
|
|
||||||
OffsetToBlockIndexUnchecked(aStream->mChannelOffset);
|
|
||||||
|
|
||||||
// Remove all cached copies of this block
|
// Remove all cached copies of this block
|
||||||
ResourceStreamIterator iter(this, aStream->mResourceID);
|
ResourceStreamIterator iter(this, aStream->mResourceID);
|
||||||
while (MediaCacheStream* stream = iter.Next()) {
|
while (MediaCacheStream* stream = iter.Next()) {
|
||||||
while (streamBlockIndex >= int32_t(stream->mBlocks.Length())) {
|
while (aStreamBlockIndex >= int32_t(stream->mBlocks.Length())) {
|
||||||
stream->mBlocks.AppendElement(-1);
|
stream->mBlocks.AppendElement(-1);
|
||||||
}
|
}
|
||||||
if (stream->mBlocks[streamBlockIndex] >= 0) {
|
if (stream->mBlocks[aStreamBlockIndex] >= 0) {
|
||||||
// We no longer want to own this block
|
// We no longer want to own this block
|
||||||
int32_t globalBlockIndex = stream->mBlocks[streamBlockIndex];
|
int32_t globalBlockIndex = stream->mBlocks[aStreamBlockIndex];
|
||||||
LOG("Released block %d from stream %p block %d(%" PRId64 ")",
|
LOG("Released block %d from stream %p block %d(%" PRId64 ")",
|
||||||
globalBlockIndex, stream, streamBlockIndex,
|
globalBlockIndex,
|
||||||
streamBlockIndex*BLOCK_SIZE);
|
stream,
|
||||||
|
aStreamBlockIndex,
|
||||||
|
aStreamBlockIndex * BLOCK_SIZE);
|
||||||
RemoveBlockOwner(globalBlockIndex, stream);
|
RemoveBlockOwner(globalBlockIndex, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1610,7 +1614,10 @@ MediaCache::AllocateAndWriteBlock(
|
||||||
|
|
||||||
Block* block = &mIndex[blockIndex];
|
Block* block = &mIndex[blockIndex];
|
||||||
LOG("Allocated block %d to stream %p block %d(%" PRId64 ")",
|
LOG("Allocated block %d to stream %p block %d(%" PRId64 ")",
|
||||||
blockIndex, aStream, streamBlockIndex, streamBlockIndex*BLOCK_SIZE);
|
blockIndex,
|
||||||
|
aStream,
|
||||||
|
aStreamBlockIndex,
|
||||||
|
aStreamBlockIndex * BLOCK_SIZE);
|
||||||
|
|
||||||
ResourceStreamIterator iter(this, aStream->mResourceID);
|
ResourceStreamIterator iter(this, aStream->mResourceID);
|
||||||
while (MediaCacheStream* stream = iter.Next()) {
|
while (MediaCacheStream* stream = iter.Next()) {
|
||||||
|
@ -1633,10 +1640,10 @@ MediaCache::AllocateAndWriteBlock(
|
||||||
|
|
||||||
// Tell each stream using this resource about the new block.
|
// Tell each stream using this resource about the new block.
|
||||||
for (auto& bo : block->mOwners) {
|
for (auto& bo : block->mOwners) {
|
||||||
bo.mStreamBlock = streamBlockIndex;
|
bo.mStreamBlock = aStreamBlockIndex;
|
||||||
bo.mLastUseTime = now;
|
bo.mLastUseTime = now;
|
||||||
bo.mStream->mBlocks[streamBlockIndex] = blockIndex;
|
bo.mStream->mBlocks[aStreamBlockIndex] = blockIndex;
|
||||||
if (streamBlockIndex*BLOCK_SIZE < bo.mStream->mStreamOffset) {
|
if (aStreamBlockIndex * BLOCK_SIZE < bo.mStream->mStreamOffset) {
|
||||||
bo.mClass = aMode == MediaCacheStream::MODE_PLAYBACK ? PLAYED_BLOCK
|
bo.mClass = aMode == MediaCacheStream::MODE_PLAYBACK ? PLAYED_BLOCK
|
||||||
: METADATA_BLOCK;
|
: METADATA_BLOCK;
|
||||||
// This must be the most-recently-used block, since we
|
// This must be the most-recently-used block, since we
|
||||||
|
@ -1661,7 +1668,10 @@ MediaCache::AllocateAndWriteBlock(
|
||||||
nsresult rv = mBlockCache->WriteBlock(blockIndex, aData1, aData2);
|
nsresult rv = mBlockCache->WriteBlock(blockIndex, aData1, aData2);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
LOG("Released block %d from stream %p block %d(%" PRId64 ")",
|
LOG("Released block %d from stream %p block %d(%" PRId64 ")",
|
||||||
blockIndex, aStream, streamBlockIndex, streamBlockIndex*BLOCK_SIZE);
|
blockIndex,
|
||||||
|
aStream,
|
||||||
|
aStreamBlockIndex,
|
||||||
|
aStreamBlockIndex * BLOCK_SIZE);
|
||||||
FreeBlock(blockIndex);
|
FreeBlock(blockIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1916,7 +1926,7 @@ MediaCacheStream::NotifyDataReceived(int64_t aSize, const char* aData)
|
||||||
mPartialBlockBuffer.get(), blockOffset);
|
mPartialBlockBuffer.get(), blockOffset);
|
||||||
auto data2 = MakeSpan<const uint8_t>(
|
auto data2 = MakeSpan<const uint8_t>(
|
||||||
reinterpret_cast<const uint8_t*>(data), chunkSize);
|
reinterpret_cast<const uint8_t*>(data), chunkSize);
|
||||||
mMediaCache->AllocateAndWriteBlock(this, mode, data1, data2);
|
mMediaCache->AllocateAndWriteBlock(this, blockIndex, mode, data1, data2);
|
||||||
} else {
|
} else {
|
||||||
memcpy(mPartialBlockBuffer.get() + blockOffset, data, chunkSize);
|
memcpy(mPartialBlockBuffer.get() + blockOffset, data, chunkSize);
|
||||||
}
|
}
|
||||||
|
@ -1947,6 +1957,7 @@ MediaCacheStream::FlushPartialBlockInternal(bool aNotifyAll,
|
||||||
{
|
{
|
||||||
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
|
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
|
||||||
|
|
||||||
|
int32_t blockIndex = OffsetToBlockIndexUnchecked(mChannelOffset);
|
||||||
int32_t blockOffset = OffsetInBlock(mChannelOffset);
|
int32_t blockOffset = OffsetInBlock(mChannelOffset);
|
||||||
if (blockOffset > 0) {
|
if (blockOffset > 0) {
|
||||||
LOG("Stream %p writing partial block: [%d] bytes; "
|
LOG("Stream %p writing partial block: [%d] bytes; "
|
||||||
|
@ -1960,6 +1971,7 @@ MediaCacheStream::FlushPartialBlockInternal(bool aNotifyAll,
|
||||||
auto data = MakeSpan<const uint8_t>(mPartialBlockBuffer.get(), BLOCK_SIZE);
|
auto data = MakeSpan<const uint8_t>(mPartialBlockBuffer.get(), BLOCK_SIZE);
|
||||||
mMediaCache->AllocateAndWriteBlock(
|
mMediaCache->AllocateAndWriteBlock(
|
||||||
this,
|
this,
|
||||||
|
blockIndex,
|
||||||
mMetadataInPartialBlockBuffer ? MODE_METADATA : MODE_PLAYBACK,
|
mMetadataInPartialBlockBuffer ? MODE_METADATA : MODE_PLAYBACK,
|
||||||
data);
|
data);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче