mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
04083ef9b4
- Bug 1235261 - Part 1: Rename nsAutoTArray to AutoTArray. r=froydnj (0662c2ac56)
- Bug 1235261 - Part 2: Switch some uses of AutoFallibleTArray to AutoTArray. r=froydnj (ab52085f2a)
- Bug 1235261 - Part 3: Switch remaining uses of AutoFallibleTArray to AutoTArray. r=froydnj (3763b16ddd)
- Bug 1235261 - Part 4: Remove AutoFallibleTArray. r=froydnj (5480b0d786)
- Bug 1235261 - Part 5: Merge nsAutoArrayBase into AutoTArray. r=froydnj (6c64e73e3b)
- Bug 1235261 - Part 7: Remove AutoInfallibleTArray. r=froydnj (acf266464e)
- Bug 1222624: Make xpath document() function use nsIPrincipals and nsIURIs rather than strings. r=peterv (5ee694d132)
- Bug 1235261 - Part 6: Rename AutoInfallibleTArray to AutoTArray. r=froydnj (d282f7df6c)
- Bug 1241394 - Hit testing with 3d transforms should use fuzzy when comparing depths. r=thinker (6c3f50670f)
- Bug 1241394 - Follow up to fix windows build bustage. (02ab2600af)
- Bug 1241394 - Check clip for the children of the establisher. r=mattwoodrow (46f151ea55)
- bug 1241453 - allow caching proxies in xpcAccessibleDocuments r=davidb (f5d41ad2ee)
- Bug 1247364 - use AllChildrenIterator::Seek by a11y tree walker, r=davidb (0ec230908e)
- Bug 1248840 - rename TreeWalker::NextChild, r=yzen (c89ecc5a29)
- Bug 1249927 - devirtualize CanHavaAnonymousChildren, r=davdib (89e8088e63)
- Bug 1206598 - Use universal reference to reduce the redundant copy. r=nfroyd (bae4ad6dd1)
- Bug 1247364 - add AllChildrenIterator::Seek, r=bz (215abebf12)
- bug 1241453 - allow storing proxies in xpcAccessibleGeneric::mIntl r=davidb (dd5e6c896b)
- bug 1241453 - allow constructing xpcAccessibles with proxies r=davidb (d0258122be)
- bug 1241453 - fixup xpcAccessible Intl() methods to not assume mIntl is always an Accessible r=davidb (168f71fdf5)
- bug 1241453 - allow xpcAccessibleDocument::mCache to use proxies as keys r=davidb (85b7eec81c)
- bug 1241453 - assert accessibles are only added to non remote xpcAccessibleDocuments r=davidb (7731b21d17)
- bug 1243077 - add ToXPC{,Document} overloads for proxied accessibles r=davidb (7bc085f1b5)
- bug 1243077 - add AccessibleOrProxy xpcAccessible::IntlGeneric() r=davidb (006a635992)
- Bug 1245464 - initialize with 0 mSupportedIfaces in xpcAccessibleGeneric in order to avoid corrupted result after bit-wise operation. r=surkov (ae41bafcef)
- bug 1241453 - allow caching xpc documents for remote documents r=davidb (a357630690)
- bug 1241453 - factor dispatching nsIAccessibleEvents out of HandleAccEvent() r=davidb (091073d981)
- Bug 1249183 - Suppress GC harder, r=terrence (2185ccb4dd)
- Bug 1248420 - Handle JSObject::getGroup OOM in js::ArraySetLength. r=jandem (04b67c8d31)
- Bug 1242270 - Add SPS pseudo frames for the Array.prototype methods; r=shu (f5e5871439)
- Bug 1247701 - Bail from ArrayShiftDenseKernel if the array is used by for-in iteration. r=jandem (41eff38954)
- Bug 1247701 followup - Change ArrayShiftDenseKernel to receive handle. r=bz (b29ce0c555)
285 lines
11 KiB
C++
285 lines
11 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "MediaStreamGraphImpl.h"
|
|
#include "mozilla/MathAlgorithms.h"
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "AudioSegment.h"
|
|
#include "VideoSegment.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsIAppShell.h"
|
|
#include "nsIObserver.h"
|
|
#include "nsPrintfCString.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "nsWidgetsCID.h"
|
|
#include "prerror.h"
|
|
#include "mozilla/Logging.h"
|
|
#include "mozilla/Attributes.h"
|
|
#include "TrackUnionStream.h"
|
|
#include "ImageContainer.h"
|
|
#include "AudioChannelService.h"
|
|
#include "AudioNodeEngine.h"
|
|
#include "AudioNodeStream.h"
|
|
#include "AudioNodeExternalInputStream.h"
|
|
#include "webaudio/MediaStreamAudioDestinationNode.h"
|
|
#include <algorithm>
|
|
#include "DOMMediaStream.h"
|
|
#include "GeckoProfiler.h"
|
|
#ifdef MOZ_WEBRTC
|
|
#include "AudioOutputObserver.h"
|
|
#endif
|
|
|
|
using namespace mozilla::layers;
|
|
using namespace mozilla::dom;
|
|
using namespace mozilla::gfx;
|
|
|
|
namespace mozilla {
|
|
|
|
#ifdef STREAM_LOG
|
|
#undef STREAM_LOG
|
|
#endif
|
|
|
|
LazyLogModule gTrackUnionStreamLog("TrackUnionStream");
|
|
#define STREAM_LOG(type, msg) MOZ_LOG(gTrackUnionStreamLog, type, msg)
|
|
|
|
TrackUnionStream::TrackUnionStream(DOMMediaStream* aWrapper) :
|
|
ProcessedMediaStream(aWrapper), mNextAvailableTrackID(1)
|
|
{
|
|
}
|
|
|
|
void TrackUnionStream::RemoveInput(MediaInputPort* aPort)
|
|
{
|
|
STREAM_LOG(LogLevel::Debug, ("TrackUnionStream %p removing input %p", this, aPort));
|
|
for (int32_t i = mTrackMap.Length() - 1; i >= 0; --i) {
|
|
if (mTrackMap[i].mInputPort == aPort) {
|
|
STREAM_LOG(LogLevel::Debug, ("TrackUnionStream %p removing trackmap entry %d", this, i));
|
|
EndTrack(i);
|
|
mTrackMap.RemoveElementAt(i);
|
|
}
|
|
}
|
|
ProcessedMediaStream::RemoveInput(aPort);
|
|
}
|
|
void TrackUnionStream::ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags)
|
|
{
|
|
if (IsFinishedOnGraphThread()) {
|
|
return;
|
|
}
|
|
AutoTArray<bool,8> mappedTracksFinished;
|
|
AutoTArray<bool,8> mappedTracksWithMatchingInputTracks;
|
|
for (uint32_t i = 0; i < mTrackMap.Length(); ++i) {
|
|
mappedTracksFinished.AppendElement(true);
|
|
mappedTracksWithMatchingInputTracks.AppendElement(false);
|
|
}
|
|
bool allFinished = !mInputs.IsEmpty();
|
|
bool allHaveCurrentData = !mInputs.IsEmpty();
|
|
for (uint32_t i = 0; i < mInputs.Length(); ++i) {
|
|
MediaStream* stream = mInputs[i]->GetSource();
|
|
if (!stream->IsFinishedOnGraphThread()) {
|
|
// XXX we really should check whether 'stream' has finished within time aTo,
|
|
// not just that it's finishing when all its queued data eventually runs
|
|
// out.
|
|
allFinished = false;
|
|
}
|
|
if (!stream->HasCurrentData()) {
|
|
allHaveCurrentData = false;
|
|
}
|
|
bool trackAdded = false;
|
|
for (StreamBuffer::TrackIter tracks(stream->GetStreamBuffer());
|
|
!tracks.IsEnded(); tracks.Next()) {
|
|
bool found = false;
|
|
for (uint32_t j = 0; j < mTrackMap.Length(); ++j) {
|
|
TrackMapEntry* map = &mTrackMap[j];
|
|
if (map->mInputPort == mInputs[i] && map->mInputTrackID == tracks->GetID()) {
|
|
bool trackFinished;
|
|
StreamBuffer::Track* outputTrack = mBuffer.FindTrack(map->mOutputTrackID);
|
|
found = true;
|
|
if (!outputTrack || outputTrack->IsEnded() ||
|
|
!mInputs[i]->PassTrackThrough(tracks->GetID())) {
|
|
trackFinished = true;
|
|
} else {
|
|
CopyTrackData(tracks.get(), j, aFrom, aTo, &trackFinished);
|
|
}
|
|
mappedTracksFinished[j] = trackFinished;
|
|
mappedTracksWithMatchingInputTracks[j] = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!found && mInputs[i]->PassTrackThrough(tracks->GetID())) {
|
|
bool trackFinished = false;
|
|
trackAdded = true;
|
|
uint32_t mapIndex = AddTrack(mInputs[i], tracks.get(), aFrom);
|
|
CopyTrackData(tracks.get(), mapIndex, aFrom, aTo, &trackFinished);
|
|
mappedTracksFinished.AppendElement(trackFinished);
|
|
mappedTracksWithMatchingInputTracks.AppendElement(true);
|
|
}
|
|
}
|
|
if (trackAdded) {
|
|
for (MediaStreamListener* l : mListeners) {
|
|
l->NotifyFinishedTrackCreation(Graph());
|
|
}
|
|
}
|
|
}
|
|
for (int32_t i = mTrackMap.Length() - 1; i >= 0; --i) {
|
|
if (mappedTracksFinished[i]) {
|
|
EndTrack(i);
|
|
} else {
|
|
allFinished = false;
|
|
}
|
|
if (!mappedTracksWithMatchingInputTracks[i]) {
|
|
mTrackMap.RemoveElementAt(i);
|
|
}
|
|
}
|
|
if (allFinished && mAutofinish && (aFlags & ALLOW_FINISH)) {
|
|
// All streams have finished and won't add any more tracks, and
|
|
// all our tracks have actually finished and been removed from our map,
|
|
// so we're finished now.
|
|
FinishOnGraphThread();
|
|
} else {
|
|
mBuffer.AdvanceKnownTracksTime(GraphTimeToStreamTimeWithBlocking(aTo));
|
|
}
|
|
if (allHaveCurrentData) {
|
|
// We can make progress if we're not blocked
|
|
mHasCurrentData = true;
|
|
}
|
|
}
|
|
|
|
uint32_t TrackUnionStream::AddTrack(MediaInputPort* aPort, StreamBuffer::Track* aTrack,
|
|
GraphTime aFrom)
|
|
{
|
|
TrackID id = aTrack->GetID();
|
|
if (id > mNextAvailableTrackID &&
|
|
mUsedTracks.BinaryIndexOf(id) == mUsedTracks.NoIndex) {
|
|
// Input id available. Mark it used in mUsedTracks.
|
|
mUsedTracks.InsertElementSorted(id);
|
|
} else {
|
|
// Input id taken, allocate a new one.
|
|
id = mNextAvailableTrackID;
|
|
|
|
// Update mNextAvailableTrackID and prune any mUsedTracks members it now
|
|
// covers.
|
|
while (1) {
|
|
if (!mUsedTracks.RemoveElementSorted(++mNextAvailableTrackID)) {
|
|
// Not in use. We're done.
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Round up the track start time so the track, if anything, starts a
|
|
// little later than the true time. This means we'll have enough
|
|
// samples in our input stream to go just beyond the destination time.
|
|
StreamTime outputStart = GraphTimeToStreamTimeWithBlocking(aFrom);
|
|
|
|
nsAutoPtr<MediaSegment> segment;
|
|
segment = aTrack->GetSegment()->CreateEmptyClone();
|
|
for (uint32_t j = 0; j < mListeners.Length(); ++j) {
|
|
MediaStreamListener* l = mListeners[j];
|
|
l->NotifyQueuedTrackChanges(Graph(), id, outputStart,
|
|
MediaStreamListener::TRACK_EVENT_CREATED,
|
|
*segment,
|
|
aPort->GetSource(), aTrack->GetID());
|
|
}
|
|
segment->AppendNullData(outputStart);
|
|
StreamBuffer::Track* track =
|
|
&mBuffer.AddTrack(id, outputStart, segment.forget());
|
|
STREAM_LOG(LogLevel::Debug, ("TrackUnionStream %p adding track %d for input stream %p track %d, start ticks %lld",
|
|
this, id, aPort->GetSource(), aTrack->GetID(),
|
|
(long long)outputStart));
|
|
|
|
TrackMapEntry* map = mTrackMap.AppendElement();
|
|
map->mEndOfConsumedInputTicks = 0;
|
|
map->mEndOfLastInputIntervalInInputStream = -1;
|
|
map->mEndOfLastInputIntervalInOutputStream = -1;
|
|
map->mInputPort = aPort;
|
|
map->mInputTrackID = aTrack->GetID();
|
|
map->mOutputTrackID = track->GetID();
|
|
map->mSegment = aTrack->GetSegment()->CreateEmptyClone();
|
|
return mTrackMap.Length() - 1;
|
|
}
|
|
|
|
void TrackUnionStream::EndTrack(uint32_t aIndex)
|
|
{
|
|
StreamBuffer::Track* outputTrack = mBuffer.FindTrack(mTrackMap[aIndex].mOutputTrackID);
|
|
if (!outputTrack || outputTrack->IsEnded())
|
|
return;
|
|
STREAM_LOG(LogLevel::Debug, ("TrackUnionStream %p ending track %d", this, outputTrack->GetID()));
|
|
for (uint32_t j = 0; j < mListeners.Length(); ++j) {
|
|
MediaStreamListener* l = mListeners[j];
|
|
StreamTime offset = outputTrack->GetSegment()->GetDuration();
|
|
nsAutoPtr<MediaSegment> segment;
|
|
segment = outputTrack->GetSegment()->CreateEmptyClone();
|
|
l->NotifyQueuedTrackChanges(Graph(), outputTrack->GetID(), offset,
|
|
MediaStreamListener::TRACK_EVENT_ENDED,
|
|
*segment,
|
|
mTrackMap[aIndex].mInputPort->GetSource(),
|
|
mTrackMap[aIndex].mInputTrackID);
|
|
}
|
|
outputTrack->SetEnded();
|
|
}
|
|
|
|
void TrackUnionStream::CopyTrackData(StreamBuffer::Track* aInputTrack,
|
|
uint32_t aMapIndex, GraphTime aFrom, GraphTime aTo,
|
|
bool* aOutputTrackFinished)
|
|
{
|
|
TrackMapEntry* map = &mTrackMap[aMapIndex];
|
|
StreamBuffer::Track* outputTrack = mBuffer.FindTrack(map->mOutputTrackID);
|
|
MOZ_ASSERT(outputTrack && !outputTrack->IsEnded(), "Can't copy to ended track");
|
|
|
|
MediaSegment* segment = map->mSegment;
|
|
MediaStream* source = map->mInputPort->GetSource();
|
|
|
|
GraphTime next;
|
|
*aOutputTrackFinished = false;
|
|
for (GraphTime t = aFrom; t < aTo; t = next) {
|
|
MediaInputPort::InputInterval interval = map->mInputPort->GetNextInputInterval(t);
|
|
interval.mEnd = std::min(interval.mEnd, aTo);
|
|
StreamTime inputEnd = source->GraphTimeToStreamTimeWithBlocking(interval.mEnd);
|
|
StreamTime inputTrackEndPoint = STREAM_TIME_MAX;
|
|
|
|
if (aInputTrack->IsEnded() &&
|
|
aInputTrack->GetEnd() <= inputEnd) {
|
|
inputTrackEndPoint = aInputTrack->GetEnd();
|
|
*aOutputTrackFinished = true;
|
|
}
|
|
|
|
if (interval.mStart >= interval.mEnd) {
|
|
break;
|
|
}
|
|
StreamTime ticks = interval.mEnd - interval.mStart;
|
|
next = interval.mEnd;
|
|
|
|
StreamTime outputStart = outputTrack->GetEnd();
|
|
|
|
if (interval.mInputIsBlocked) {
|
|
// Maybe the input track ended?
|
|
segment->AppendNullData(ticks);
|
|
STREAM_LOG(LogLevel::Verbose, ("TrackUnionStream %p appending %lld ticks of null data to track %d",
|
|
this, (long long)ticks, outputTrack->GetID()));
|
|
} else if (InMutedCycle()) {
|
|
segment->AppendNullData(ticks);
|
|
} else {
|
|
if (source->IsSuspended()) {
|
|
segment->AppendNullData(aTo - aFrom);
|
|
} else {
|
|
MOZ_ASSERT(outputTrack->GetEnd() == GraphTimeToStreamTimeWithBlocking(interval.mStart),
|
|
"Samples missing");
|
|
StreamTime inputStart = source->GraphTimeToStreamTimeWithBlocking(interval.mStart);
|
|
segment->AppendSlice(*aInputTrack->GetSegment(),
|
|
std::min(inputTrackEndPoint, inputStart),
|
|
std::min(inputTrackEndPoint, inputEnd));
|
|
}
|
|
}
|
|
ApplyTrackDisabling(outputTrack->GetID(), segment);
|
|
for (uint32_t j = 0; j < mListeners.Length(); ++j) {
|
|
MediaStreamListener* l = mListeners[j];
|
|
l->NotifyQueuedTrackChanges(Graph(), outputTrack->GetID(),
|
|
outputStart, 0, *segment);
|
|
}
|
|
outputTrack->GetSegment()->AppendFrom(segment);
|
|
}
|
|
}
|
|
} // namespace mozilla
|