本文整理汇总了C++中MediaByteRange类的典型用法代码示例。如果您正苦于以下问题:C++ MediaByteRange类的具体用法?C++ MediaByteRange怎么用?C++ MediaByteRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MediaByteRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MediaRawData
already_AddRefed<MediaRawData>
WAVTrackDemuxer::GetFileHeader(const MediaByteRange& aRange)
{
if (!aRange.Length()) {
return nullptr;
}
RefPtr<MediaRawData> fileHeader = new MediaRawData();
fileHeader->mOffset = aRange.mStart;
nsAutoPtr<MediaRawDataWriter> headerWriter(fileHeader->CreateWriter());
if (!headerWriter->SetSize(aRange.Length())) {
return nullptr;
}
const uint32_t read =
Read(headerWriter->Data(), fileHeader->mOffset, fileHeader->Size());
if (read != aRange.Length()) {
return nullptr;
}
UpdateState(aRange);
return fileHeader.forget();
}
示例2: CombineRanges
void CombineRanges(const MediaByteRange& pending, const MediaByteRange& preload,
MediaByteRange& request)
{
OP_ASSERT(request.IsEmpty());
// If pending and preload overlap, let request be their union,
// clamped to pending.start.
if (!pending.IsEmpty() && !preload.IsEmpty())
{
request = pending;
request.IntersectWith(preload);
if (!request.IsEmpty())
{
// non-empty intersection => overlap
request = pending;
request.UnionWith(preload);
request.IntersectWith(MediaByteRange(pending.start));
OP_ASSERT(!request.IsEmpty());
}
}
// Otherwise, pick the first non-empty of pending and preload.
if (request.IsEmpty())
{
if (!pending.IsEmpty())
request = pending;
else
request = preload;
}
}
示例3: stream
nsRefPtr<MP4Demuxer::InitPromise>
MP4Demuxer::Init()
{
AutoPinned<mp4_demuxer::ResourceStream> stream(mStream);
// Check that we have enough data to read the metadata.
MediaByteRange br = mp4_demuxer::MP4Metadata::MetadataRange(stream);
if (br.IsNull()) {
return InitPromise::CreateAndReject(DemuxerFailureReason::WAITING_FOR_DATA, __func__);
}
if (!mInitData->SetLength(br.Length(), fallible)) {
// OOM
return InitPromise::CreateAndReject(DemuxerFailureReason::DEMUXER_ERROR, __func__);
}
size_t size;
mStream->ReadAt(br.mStart, mInitData->Elements(), br.Length(), &size);
if (size != size_t(br.Length())) {
return InitPromise::CreateAndReject(DemuxerFailureReason::DEMUXER_ERROR, __func__);
}
nsRefPtr<mp4_demuxer::BufferStream> bufferstream =
new mp4_demuxer::BufferStream(mInitData);
mMetadata = MakeUnique<mp4_demuxer::MP4Metadata>(bufferstream);
if (!mMetadata->GetNumberTracks(mozilla::TrackInfo::kAudioTrack) &&
!mMetadata->GetNumberTracks(mozilla::TrackInfo::kVideoTrack)) {
return InitPromise::CreateAndReject(DemuxerFailureReason::DEMUXER_ERROR, __func__);
}
return InitPromise::CreateAndResolve(NS_OK, __func__);
}
示例4: IntersectWithUnavailable
void IntersectWithUnavailable(MediaByteRange& range, URL& url)
{
if (range.IsEmpty())
return;
// find the first unavailable range on or after range.start
MediaByteRange unavail;
BOOL available = FALSE;
OpFileLength length = 0;
url.GetPartialCoverage(range.start, available, length, TRUE);
if (available)
{
OP_ASSERT(length > 0);
unavail.start = range.start + length;
length = 0;
url.GetPartialCoverage(unavail.start, available, length, TRUE);
OP_ASSERT(!available);
}
else
unavail.start = range.start;
// length is now the number of unavailable bytes, or 0 if unknown
if (length > 0)
unavail.SetLength(length);
range.IntersectWith(unavail);
}
示例5: BlockingStream
bool
MoofParser::HasMetadata()
{
int64_t length = std::numeric_limits<int64_t>::max();
mSource->Length(&length);
nsTArray<MediaByteRange> byteRanges;
byteRanges.AppendElement(MediaByteRange(0, length));
nsRefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
MediaByteRange ftyp;
MediaByteRange moov;
BoxContext context(stream, byteRanges);
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
if (box.IsType("ftyp")) {
ftyp = box.Range();
continue;
}
if (box.IsType("moov")) {
moov = box.Range();
break;
}
}
if (!ftyp.Length() || !moov.Length()) {
return false;
}
mInitRange = ftyp.Extents(moov);
return true;
}
示例6: StartBuffering
MediaSourceImpl::State
MediaSourceImpl::EnsureBufferingInternal()
{
MediaByteRange request;
CalcRequest(request);
if (!request.IsEmpty())
{
m_clamp_request = FALSE;
if (NeedRestart(request))
{
StopBuffering();
return StartBuffering(request);
}
// The request wasn't restarted, so it may need to be clamped
// by aborting it once enough data has become available.
if (request.IsFinite() && !IsStreaming())
{
OpFileLength loading_end = FILE_LENGTH_NONE;
m_use_url->GetAttribute(URL::KHTTPRangeEnd, &loading_end);
if (loading_end == FILE_LENGTH_NONE || request.end < loading_end)
m_clamp_request = TRUE;
}
}
else
{
// We have all the data we wanted, so stop buffering if possible.
switch (m_state)
{
case NONE:
// Already loaded (data: URL or in cache).
return IDLE;
case IDLE:
case FAILED:
// not loading
break;
case STARTED:
case HEADERS:
case LOADING:
case PAUSED:
// Only stop a load if it's in fact already complete or if
// it's one that we can later resume. However, when using
// the streaming cache, continue loading until either the
// cache fills up and PauseBuffering() is called or (if
// the request fits in cache) IsLoadedURL() is true.
if (IsLoadedURL(m_use_url) || (IsResumableURL(m_use_url) && !IsStreaming()))
{
StopBuffering();
return IDLE;
}
break;
}
}
return NONE;
}
示例7:
void
MP3TrackDemuxer::UpdateState(const MediaByteRange& aRange) {
// Prevent overflow.
if (mTotalFrameLen + aRange.Length() < mTotalFrameLen) {
// These variables have a linear dependency and are only used to derive the
// average frame length.
mTotalFrameLen /= 2;
mNumParsedFrames /= 2;
}
// Full frame parsed, move offset to its end.
mOffset = aRange.mEnd;
mTotalFrameLen += aRange.Length();
if (!mSamplesPerFrame) {
mSamplesPerFrame = mParser.CurrentFrame().Header().SamplesPerFrame();
mSamplesPerSecond = mParser.CurrentFrame().Header().SampleRate();
mChannels = mParser.CurrentFrame().Header().Channels();
}
++mNumParsedFrames;
++mFrameIndex;
MOZ_ASSERT(mFrameIndex > 0);
// Prepare the parser for the next frame parsing session.
mParser.EndFrameSession();
}
示例8: ScanForMetadata
already_AddRefed<mozilla::MediaByteBuffer>
MoofParser::Metadata()
{
MediaByteRange moov;
ScanForMetadata(moov);
CheckedInt<MediaByteBuffer::size_type> moovLength = moov.Length();
if (!moovLength.isValid() || !moovLength.value()) {
// No moov, or cannot be used as array size.
return nullptr;
}
RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
if (!metadata->SetLength(moovLength.value(), fallible)) {
LOG(Moof, "OOM");
return nullptr;
}
RefPtr<BlockingStream> stream = new BlockingStream(mSource);
size_t read;
bool rv =
stream->ReadAt(moov.mStart, metadata->Elements(), moovLength.value(), &read);
if (!rv || read != moovLength.value()) {
return nullptr;
}
return metadata.forget();
}
示例9: ScanForMetadata
bool
MoofParser::HasMetadata()
{
MediaByteRange ftyp;
MediaByteRange moov;
ScanForMetadata(ftyp, moov);
return !!ftyp.Length() && !!moov.Length();
}
示例10: reader
already_AddRefed<MediaRawData>
MP3TrackDemuxer::GetNextFrame(const MediaByteRange& aRange) {
MP3LOG("GetNext() Begin({mStart=%" PRId64 " Length()=%" PRId64 "})",
aRange.mStart, aRange.Length());
if (!aRange.Length()) {
return nullptr;
}
RefPtr<MediaRawData> frame = new MediaRawData();
frame->mOffset = aRange.mStart;
nsAutoPtr<MediaRawDataWriter> frameWriter(frame->CreateWriter());
if (!frameWriter->SetSize(aRange.Length())) {
MP3LOG("GetNext() Exit failed to allocated media buffer");
return nullptr;
}
const uint32_t read = Read(frameWriter->Data(), frame->mOffset, frame->Size());
if (read != aRange.Length()) {
MP3LOG("GetNext() Exit read=%u frame->Size()=%u", read, frame->Size());
return nullptr;
}
UpdateState(aRange);
frame->mTime = Duration(mFrameIndex - 1).ToMicroseconds();
frame->mDuration = Duration(1).ToMicroseconds();
frame->mTimecode = frame->mTime;
frame->mKeyframe = true;
MOZ_ASSERT(frame->mTime >= 0);
MOZ_ASSERT(frame->mDuration > 0);
if (mNumParsedFrames == 1) {
// First frame parsed, let's read VBR info if available.
// TODO: read info that helps with seeking (bug 1163667).
ByteReader reader(frame->Data(), frame->Size());
mParser.ParseVBRHeader(&reader);
reader.DiscardRemaining();
mFirstFrameOffset = frame->mOffset;
}
MP3LOGV("GetNext() End mOffset=%" PRIu64 " mNumParsedFrames=%" PRIu64
" mFrameIndex=%" PRId64 " mTotalFrameLen=%" PRIu64
" mSamplesPerFrame=%d mSamplesPerSecond=%d mChannels=%d",
mOffset, mNumParsedFrames, mFrameIndex, mTotalFrameLen,
mSamplesPerFrame, mSamplesPerSecond, mChannels);
return frame.forget();
}
示例11:
void
WAVTrackDemuxer::UpdateState(const MediaByteRange& aRange)
{
// Full chunk parsed, move offset to its end.
mOffset = aRange.mEnd;
mTotalChunkLen += aRange.Length();
}
示例12: FindNextFrame
MediaByteRange
MP3TrackDemuxer::FindFirstFrame() {
static const int MIN_SUCCESSIVE_FRAMES = 4;
MediaByteRange candidateFrame = FindNextFrame();
int numSuccFrames = candidateFrame.Length() > 0;
MediaByteRange currentFrame = candidateFrame;
MP3LOGV("FindFirst() first candidate frame: mOffset=%" PRIu64 " Length()=%" PRIu64,
candidateFrame.mStart, candidateFrame.Length());
while (candidateFrame.Length() && numSuccFrames < MIN_SUCCESSIVE_FRAMES) {
mParser.EndFrameSession();
mOffset = currentFrame.mEnd;
const MediaByteRange prevFrame = currentFrame;
// FindNextFrame() here will only return frames consistent with our candidate frame.
currentFrame = FindNextFrame();
numSuccFrames += currentFrame.Length() > 0;
// Multiple successive false positives, which wouldn't be caught by the consistency
// checks alone, can be detected by wrong alignment (non-zero gap between frames).
const int64_t frameSeparation = currentFrame.mStart - prevFrame.mEnd;
if (!currentFrame.Length() || frameSeparation != 0) {
MP3LOGV("FindFirst() not enough successive frames detected, "
"rejecting candidate frame: successiveFrames=%d, last Length()=%" PRIu64
", last frameSeparation=%" PRId64, numSuccFrames, currentFrame.Length(),
frameSeparation);
mParser.ResetFrameData();
mOffset = candidateFrame.mStart + 1;
candidateFrame = FindNextFrame();
numSuccFrames = candidateFrame.Length() > 0;
currentFrame = candidateFrame;
MP3LOGV("FindFirst() new candidate frame: mOffset=%" PRIu64 " Length()=%" PRIu64,
candidateFrame.mStart, candidateFrame.Length());
}
}
if (numSuccFrames >= MIN_SUCCESSIVE_FRAMES) {
MP3LOG("FindFirst() accepting candidate frame: "
"successiveFrames=%d", numSuccFrames);
} else {
MP3LOG("FindFirst() no suitable first frame found");
}
return candidateFrame;
}
示例13: frame
bool
MP3TrackDemuxer::SkipNextFrame(const MediaByteRange& aRange) {
if (!mNumParsedFrames || !aRange.Length()) {
// We can't skip the first frame, since it could contain VBR headers.
nsRefPtr<MediaRawData> frame(GetNextFrame(aRange));
return frame;
}
UpdateState(aRange);
return true;
}
示例14: ReduceRanges
void ReduceRanges(const List<MediaSourceClient>& clients,
MediaByteRange& pending, MediaByteRange& preload)
{
OP_ASSERT(preload.IsEmpty());
MediaSourceClient* client = clients.First();
if (client)
{
for ( ; client; client = client->Suc())
{
// take the first non-empty pending
if (pending.IsEmpty())
pending = client->GetPending();
// preload the union of all ranges
preload.UnionWith(client->GetPreload());
}
}
else
{
// with no clients, preload the whole resource
preload.start = 0;
}
}
示例15: OP_ASSERT
BOOL
MediaSourceImpl::NeedRestart(const MediaByteRange& request)
{
OP_ASSERT(!request.IsEmpty());
// Note: this function assumes that request is not in cache
// If not loading we certainly need to start.
if (m_state == NONE || m_state == IDLE)
return TRUE;
// Only restart resumable resources.
if (!IsResumableURL(m_use_url))
return FALSE;
// Get the currently loading range.
MediaByteRange loading;
m_use_url->GetAttribute(URL::KHTTPRangeStart, &loading.start);
m_use_url->GetAttribute(URL::KHTTPRangeEnd, &loading.end);
OP_ASSERT(!loading.IsEmpty());
// When streaming, adjust the loading range to not include what
// has already been evicted from the cache. Note: This must not be
// done for a request that was just started, as the cache can then
// contain data from the previous request which is not relevant.
if (m_state >= LOADING && IsStreaming())
{
BOOL available = FALSE;
OpFileLength length = 0;
GetPartialCoverage(loading.start, available, length);
if (!available && (!loading.IsFinite() || length < loading.Length()))
loading.start += length;
}
// Restart if request is before currently loading range.
if (request.start < loading.start)
return TRUE;
// Restart if request is after currently loading range.
if (loading.IsFinite() && request.start > loading.end)
return TRUE;
// request is now a subset of loading, check how much we have left
// to load until request.start.
BOOL available = FALSE;
OpFileLength length = 0;
GetPartialCoverage(loading.start, available, length);
if (!available)
length = 0;
if (request.start > loading.start + length)
{
// FIXME: calculate download rate and time taken to reach offset (CORE-27952)
OpFileLength remaining = request.start - (loading.start + length);
if (remaining > MEDIA_SOURCE_MAX_WAIT)
return TRUE;
}
return FALSE;
}