2012-07-31 16:17:21 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_TRACKUNIONSTREAM_H_
|
|
|
|
#define MOZILLA_TRACKUNIONSTREAM_H_
|
|
|
|
|
|
|
|
#include "MediaStreamGraph.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-07-31 16:17:21 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See MediaStreamGraph::CreateTrackUnionStream.
|
|
|
|
*/
|
|
|
|
class TrackUnionStream : public ProcessedMediaStream {
|
|
|
|
public:
|
2016-06-29 13:27:13 +03:00
|
|
|
explicit TrackUnionStream();
|
2012-07-31 16:17:21 +04:00
|
|
|
|
2016-05-27 09:33:50 +03:00
|
|
|
virtual TrackUnionStream* AsTrackUnionStream() override { return this; }
|
|
|
|
friend class DOMMediaStream;
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
void RemoveInput(MediaInputPort* aPort) override;
|
|
|
|
void ProcessInput(GraphTime aFrom, GraphTime aTo, uint32_t aFlags) override;
|
2012-07-31 16:17:21 +04:00
|
|
|
|
2016-08-15 15:19:42 +03:00
|
|
|
void SetTrackEnabledImpl(TrackID aTrackID, DisabledTrackMode aMode) override;
|
2016-03-18 16:21:51 +03:00
|
|
|
|
2016-05-24 14:23:50 +03:00
|
|
|
MediaStream* GetInputStreamFor(TrackID aTrackID) override;
|
|
|
|
TrackID GetInputTrackIDFor(TrackID aTrackID) override;
|
|
|
|
|
2016-07-25 05:01:26 +03:00
|
|
|
friend class MediaStreamGraphImpl;
|
|
|
|
|
2012-07-31 16:17:21 +04:00
|
|
|
protected:
|
|
|
|
// Only non-ended tracks are allowed to persist in this map.
|
|
|
|
struct TrackMapEntry {
|
2013-08-01 08:02:49 +04:00
|
|
|
// mEndOfConsumedInputTicks is the end of the input ticks that we've consumed.
|
|
|
|
// 0 if we haven't consumed any yet.
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime mEndOfConsumedInputTicks;
|
2013-08-01 08:02:49 +04:00
|
|
|
// mEndOfLastInputIntervalInInputStream is the timestamp for the end of the
|
|
|
|
// previous interval which was unblocked for both the input and output
|
|
|
|
// stream, in the input stream's timeline, or -1 if there wasn't one.
|
|
|
|
StreamTime mEndOfLastInputIntervalInInputStream;
|
|
|
|
// mEndOfLastInputIntervalInOutputStream is the timestamp for the end of the
|
|
|
|
// previous interval which was unblocked for both the input and output
|
|
|
|
// stream, in the output stream's timeline, or -1 if there wasn't one.
|
|
|
|
StreamTime mEndOfLastInputIntervalInOutputStream;
|
2012-07-31 16:17:21 +04:00
|
|
|
MediaInputPort* mInputPort;
|
2012-11-02 14:42:59 +04:00
|
|
|
// We keep track IDs instead of track pointers because
|
|
|
|
// tracks can be removed without us being notified (e.g.
|
|
|
|
// when a finished track is forgotten.) When we need a Track*,
|
2016-01-26 05:49:01 +03:00
|
|
|
// we call StreamTracks::FindTrack, which will return null if
|
2012-11-02 14:42:59 +04:00
|
|
|
// the track has been deleted.
|
|
|
|
TrackID mInputTrackID;
|
|
|
|
TrackID mOutputTrackID;
|
2012-07-31 16:17:21 +04:00
|
|
|
nsAutoPtr<MediaSegment> mSegment;
|
2016-03-18 16:21:51 +03:00
|
|
|
// These are direct track listeners that have been added to this
|
|
|
|
// TrackUnionStream-track and forwarded to the input track. We will update
|
|
|
|
// these when this track's disabled status changes.
|
2016-04-29 06:45:25 +03:00
|
|
|
nsTArray<RefPtr<DirectMediaStreamTrackListener>> mOwnedDirectListeners;
|
2012-07-31 16:17:21 +04:00
|
|
|
};
|
|
|
|
|
2015-06-12 13:56:27 +03:00
|
|
|
// Add the track to this stream, retaining its TrackID if it has never
|
|
|
|
// been previously used in this stream, allocating a new TrackID otherwise.
|
2016-01-26 05:49:01 +03:00
|
|
|
uint32_t AddTrack(MediaInputPort* aPort, StreamTracks::Track* aTrack,
|
2014-10-11 17:02:59 +04:00
|
|
|
GraphTime aFrom);
|
|
|
|
void EndTrack(uint32_t aIndex);
|
2016-01-26 05:49:01 +03:00
|
|
|
void CopyTrackData(StreamTracks::Track* aInputTrack,
|
2012-11-02 14:42:59 +04:00
|
|
|
uint32_t aMapIndex, GraphTime aFrom, GraphTime aTo,
|
2014-10-11 17:02:59 +04:00
|
|
|
bool* aOutputTrackFinished);
|
2012-07-31 16:17:21 +04:00
|
|
|
|
2016-04-29 06:45:25 +03:00
|
|
|
void AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStreamTrackListener> aListener,
|
2016-03-03 19:28:37 +03:00
|
|
|
TrackID aTrackID) override;
|
2016-04-29 06:45:25 +03:00
|
|
|
void RemoveDirectTrackListenerImpl(DirectMediaStreamTrackListener* aListener,
|
2016-03-03 19:28:37 +03:00
|
|
|
TrackID aTrackID) override;
|
|
|
|
|
2012-07-31 16:17:21 +04:00
|
|
|
nsTArray<TrackMapEntry> mTrackMap;
|
2015-06-12 13:56:27 +03:00
|
|
|
|
|
|
|
// The next available TrackID, starting at 1 and progressing upwards.
|
|
|
|
// All TrackIDs in [1, mNextAvailableTrackID) have implicitly been used.
|
|
|
|
TrackID mNextAvailableTrackID;
|
|
|
|
|
|
|
|
// Sorted array of used TrackIDs that require manual tracking.
|
|
|
|
nsTArray<TrackID> mUsedTracks;
|
2016-03-03 19:28:37 +03:00
|
|
|
|
|
|
|
// Direct track listeners that have not been forwarded to their input stream
|
|
|
|
// yet. We'll forward these as their inputs become available.
|
2016-04-29 06:45:25 +03:00
|
|
|
nsTArray<TrackBound<DirectMediaStreamTrackListener>> mPendingDirectTrackListeners;
|
2012-07-31 16:17:21 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2012-07-31 16:17:21 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_MEDIASTREAMGRAPH_H_ */
|