Esempio n. 1
0
uint32_t ResourceQueue::EvictBefore(uint64_t aOffset, ErrorResult& aRv)
{
  SBR_DEBUG("EvictBefore(%llu)", aOffset);
  uint32_t evicted = 0;
  while (ResourceItem* item = ResourceAt(0)) {
    SBR_DEBUG("item=%p length=%d offset=%llu",
              item, item->mData->Length(), mOffset);
    if (item->mData->Length() + mOffset >= aOffset) {
      if (aOffset <= mOffset) {
        break;
      }
      uint32_t offset = aOffset - mOffset;
      mOffset += offset;
      evicted += offset;
      RefPtr<MediaByteBuffer> data = new MediaByteBuffer;
      if (!data->AppendElements(item->mData->Elements() + offset,
                                item->mData->Length() - offset,
                                fallible)) {
        aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
        return 0;
      }

      item->mData = data;
      break;
    }
    mOffset += item->mData->Length();
    evicted += item->mData->Length();
    delete PopFront();
  }
  return evicted;
}
Esempio n. 2
0
uint32_t
ResourceQueue::EvictAll()
{
  SBR_DEBUG("EvictAll()");
  uint32_t evicted = 0;
  while (ResourceItem* item = ResourceAt(0)) {
    SBR_DEBUG("item=%p length=%d offset=%llu",
              item, item->mData->Length(), mOffset);
    mOffset += item->mData->Length();
    evicted += item->mData->Length();
    delete PopFront();
  }
  return evicted;
}
uint32_t
SourceBufferResource::EvictAll()
{
  SBR_DEBUG("EvictAll()");
  ReentrantMonitorAutoEnter mon(mMonitor);
  return mInputBuffer.EvictAll();
}
Esempio n. 4
0
nsresult
SourceBufferResource::Seek(int32_t aWhence, int64_t aOffset)
{
  SBR_DEBUG("Seek(aWhence=%d, aOffset=%lld)",
            aWhence, aOffset);
  ReentrantMonitorAutoEnter mon(mMonitor);

  int64_t newOffset = mOffset;
  switch (aWhence) {
  case nsISeekableStream::NS_SEEK_END:
    newOffset = GetLength() - aOffset;
    break;
  case nsISeekableStream::NS_SEEK_CUR:
    newOffset += aOffset;
    break;
  case nsISeekableStream::NS_SEEK_SET:
    newOffset = aOffset;
    break;
  }

  SBR_DEBUGV("newOffset=%lld GetOffset()=%llu GetLength()=%llu)",
             newOffset, mInputBuffer.GetOffset(), GetLength());
  nsresult rv = SeekInternal(newOffset);
  mon.NotifyAll();
  return rv;
}
nsresult
SourceBufferResource::ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes)
{
  SBR_DEBUG("ReadAt(aOffset=%lld, aBuffer=%p, aCount=%u, aBytes=%p)",
            aOffset, aBytes, aCount, aBytes);
  ReentrantMonitorAutoEnter mon(mMonitor);
  return ReadAtInternal(aOffset, aBuffer, aCount, aBytes, /* aMayBlock = */ true);
}
void
SourceBufferResource::Ended()
{
  SBR_DEBUG("");
  ReentrantMonitorAutoEnter mon(mMonitor);
  mEnded = true;
  mon.NotifyAll();
}
Esempio n. 7
0
uint32_t
ResourceQueue::Evict(uint64_t aOffset, uint32_t aSizeToEvict,
                     ErrorResult& aRv)
{
  SBR_DEBUG("Evict(aOffset=%llu, aSizeToEvict=%u)",
            aOffset, aSizeToEvict);
  return EvictBefore(std::min(aOffset, mOffset + (uint64_t)aSizeToEvict), aRv);
}
nsresult
SourceBufferResource::Close()
{
  ReentrantMonitorAutoEnter mon(mMonitor);
  SBR_DEBUG("Close");
  //MOZ_ASSERT(!mClosed);
  mClosed = true;
  mon.NotifyAll();
  return NS_OK;
}
SourceBufferResource::SourceBufferResource(const nsACString& aType)
  : mType(aType)
  , mMonitor("mozilla::SourceBufferResource::mMonitor")
  , mOffset(0)
  , mClosed(false)
  , mEnded(false)
{
  SBR_DEBUG("");
  MOZ_COUNT_CTOR(SourceBufferResource);
}
Esempio n. 10
0
void
SourceBufferResource::AppendData(MediaByteBuffer* aData)
{
  SBR_DEBUG("AppendData(aData=%p, aLength=%u)",
            aData->Elements(), aData->Length());
  ReentrantMonitorAutoEnter mon(mMonitor);
  mInputBuffer.AppendItem(aData);
  mEnded = false;
  mon.NotifyAll();
}
Esempio n. 11
0
void
SourceBufferResource::EvictBefore(uint64_t aOffset, ErrorResult& aRv)
{
  SBR_DEBUG("EvictBefore(aOffset=%llu)", aOffset);
  ReentrantMonitorAutoEnter mon(mMonitor);
  // If aOffset is past the current playback offset we don't evict.
  if (aOffset < mOffset) {
    mInputBuffer.EvictBefore(aOffset, aRv);
  }
  // Wake up any waiting threads in case a ReadInternal call
  // is now invalid.
  mon.NotifyAll();
}
uint32_t
SourceBufferResource::EvictData(uint64_t aPlaybackOffset, uint32_t aThreshold)
{
  SBR_DEBUG("EvictData(aPlaybackOffset=%llu,"
            "aThreshold=%u)", aPlaybackOffset, aThreshold);
  ReentrantMonitorAutoEnter mon(mMonitor);
  uint32_t result = mInputBuffer.Evict(aPlaybackOffset, aThreshold);
  if (result > 0) {
    // Wake up any waiting threads in case a ReadInternal call
    // is now invalid.
    mon.NotifyAll();
  }
  return result;
}
Esempio n. 13
0
nsresult
SourceBufferResource::ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount)
{
  SBR_DEBUG("ReadFromCache(aBuffer=%p, aOffset=%lld, aCount=%u)",
            aBuffer, aOffset, aCount);
  ReentrantMonitorAutoEnter mon(mMonitor);
  uint32_t bytesRead;
  int64_t oldOffset = mOffset;
  nsresult rv = ReadAtInternal(aOffset, aBuffer, aCount, &bytesRead, /* aMayBlock = */ false);
  mOffset = oldOffset; // ReadFromCache isn't supposed to affect the seek position.
  NS_ENSURE_SUCCESS(rv, rv);

  // ReadFromCache return failure if not all the data is cached.
  return bytesRead == aCount ? NS_OK : NS_ERROR_FAILURE;
}
Esempio n. 14
0
SourceBufferResource::~SourceBufferResource()
{
  SBR_DEBUG("");
  MOZ_COUNT_DTOR(SourceBufferResource);
}