зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1257318: Move MediaRecorder to use DirectListeners wherever possible. r=roc
--HG-- extra : rebase_source : 5350255f08a3409568f6f4501f32111a7525df5b
This commit is contained in:
Родитель
b0aa7aad31
Коммит
2de5a1de8e
|
@ -326,7 +326,7 @@ class MediaRecorder::Session: public nsIObserver
|
|||
{
|
||||
LOG(LogLevel::Debug, ("Session.DestroyRunnable session refcnt = (%d) stopIssued %d s=(%p)",
|
||||
(int)mSession->mRefCnt, mSession->mStopIssued, mSession.get()));
|
||||
MOZ_ASSERT(NS_IsMainThread() && mSession.get());
|
||||
MOZ_ASSERT(NS_IsMainThread() && mSession);
|
||||
RefPtr<MediaRecorder> recorder = mSession->mRecorder;
|
||||
if (!recorder) {
|
||||
return NS_OK;
|
||||
|
@ -635,6 +635,16 @@ private:
|
|||
return;
|
||||
}
|
||||
mTrackUnionStream->AddListener(mEncoder);
|
||||
// Try to use direct listeners if possible
|
||||
DOMMediaStream* domStream = mRecorder->Stream();
|
||||
if (domStream) {
|
||||
mInputStream = domStream->GetInputStream()->AsSourceStream();
|
||||
if (mInputStream) {
|
||||
mInputStream->AddDirectListener(mEncoder);
|
||||
mEncoder->SetDirectConnect(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a thread to read encode media data from MediaEncoder.
|
||||
if (!mReadThread) {
|
||||
nsresult rv = NS_NewNamedThread("Media_Encoder", getter_AddRefs(mReadThread));
|
||||
|
@ -687,12 +697,21 @@ private:
|
|||
}
|
||||
void CleanupStreams()
|
||||
{
|
||||
if (mInputPort.get()) {
|
||||
if (mInputStream) {
|
||||
if (mEncoder) {
|
||||
mInputStream->RemoveDirectListener(mEncoder);
|
||||
}
|
||||
mInputStream = nullptr;
|
||||
}
|
||||
if (mInputPort) {
|
||||
mInputPort->Destroy();
|
||||
mInputPort = nullptr;
|
||||
}
|
||||
|
||||
if (mTrackUnionStream.get()) {
|
||||
if (mTrackUnionStream) {
|
||||
if (mEncoder) {
|
||||
mTrackUnionStream->RemoveListener(mEncoder);
|
||||
}
|
||||
mTrackUnionStream->Destroy();
|
||||
mTrackUnionStream = nullptr;
|
||||
}
|
||||
|
@ -734,6 +753,7 @@ private:
|
|||
// Receive track data from source and dispatch to Encoder.
|
||||
// Pause/ Resume controller.
|
||||
RefPtr<ProcessedMediaStream> mTrackUnionStream;
|
||||
RefPtr<SourceMediaStream> mInputStream;
|
||||
RefPtr<MediaInputPort> mInputPort;
|
||||
|
||||
// Runnable thread for read data from MediaEncode.
|
||||
|
|
|
@ -36,6 +36,34 @@ mozilla::LazyLogModule gMediaEncoderLog("MediaEncoder");
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
void
|
||||
MediaEncoder::SetDirectConnect(bool aConnected)
|
||||
{
|
||||
fprintf(stderr, "****** direct connect: %s\n", aConnected ? "true" : "false");
|
||||
mDirectConnected = aConnected;
|
||||
}
|
||||
|
||||
void
|
||||
MediaEncoder::NotifyRealtimeData(MediaStreamGraph* aGraph,
|
||||
TrackID aID,
|
||||
StreamTime aTrackOffset,
|
||||
uint32_t aTrackEvents,
|
||||
const MediaSegment& aRealtimeMedia)
|
||||
{
|
||||
// Process the incoming raw track data from MediaStreamGraph, called on the
|
||||
// thread of MediaStreamGraph.
|
||||
if (mAudioEncoder && aRealtimeMedia.GetType() == MediaSegment::AUDIO) {
|
||||
mAudioEncoder->NotifyQueuedTrackChanges(aGraph, aID,
|
||||
aTrackOffset, aTrackEvents,
|
||||
aRealtimeMedia);
|
||||
|
||||
} else if (mVideoEncoder && aRealtimeMedia.GetType() == MediaSegment::VIDEO) {
|
||||
mVideoEncoder->NotifyQueuedTrackChanges(aGraph, aID,
|
||||
aTrackOffset, aTrackEvents,
|
||||
aRealtimeMedia);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MediaEncoder::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph,
|
||||
TrackID aID,
|
||||
|
@ -45,17 +73,8 @@ MediaEncoder::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph,
|
|||
MediaStream* aInputStream,
|
||||
TrackID aInputTrackID)
|
||||
{
|
||||
// Process the incoming raw track data from MediaStreamGraph, called on the
|
||||
// thread of MediaStreamGraph.
|
||||
if (mAudioEncoder && aQueuedMedia.GetType() == MediaSegment::AUDIO) {
|
||||
mAudioEncoder->NotifyQueuedTrackChanges(aGraph, aID,
|
||||
aTrackOffset, aTrackEvents,
|
||||
aQueuedMedia);
|
||||
|
||||
} else if (mVideoEncoder && aQueuedMedia.GetType() == MediaSegment::VIDEO) {
|
||||
mVideoEncoder->NotifyQueuedTrackChanges(aGraph, aID,
|
||||
aTrackOffset, aTrackEvents,
|
||||
aQueuedMedia);
|
||||
if (!mDirectConnected) {
|
||||
NotifyRealtimeData(aGraph, aID, aTrackOffset, aTrackEvents, aQueuedMedia);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace mozilla {
|
|||
* 4) To stop encoding, remove this component from its source stream.
|
||||
* => sourceStream->RemoveListener(encoder);
|
||||
*/
|
||||
class MediaEncoder : public MediaStreamListener
|
||||
class MediaEncoder : public MediaStreamDirectListener
|
||||
{
|
||||
public :
|
||||
enum {
|
||||
|
@ -74,10 +74,25 @@ public :
|
|||
, mSizeOfBuffer(0)
|
||||
, mState(MediaEncoder::ENCODE_METADDATA)
|
||||
, mShutdown(false)
|
||||
, mDirectConnected(false)
|
||||
{}
|
||||
|
||||
~MediaEncoder() {};
|
||||
|
||||
/**
|
||||
* Tells us which Notify to pay attention to for media
|
||||
*/
|
||||
void SetDirectConnect(bool aConnected);
|
||||
|
||||
/**
|
||||
* Notified by the AppendToTrack in MediaStreamGraph; aRealtimeMedia is the raw
|
||||
* track data in form of MediaSegment.
|
||||
*/
|
||||
void NotifyRealtimeData(MediaStreamGraph* aGraph, TrackID aID,
|
||||
StreamTime aTrackOffset,
|
||||
uint32_t aTrackEvents,
|
||||
const MediaSegment& aRealtimeMedia) override;
|
||||
|
||||
/**
|
||||
* Notified by the control loop of MediaStreamGraph; aQueueMedia is the raw
|
||||
* track data in form of MediaSegment.
|
||||
|
@ -169,6 +184,7 @@ private:
|
|||
int64_t mSizeOfBuffer;
|
||||
int mState;
|
||||
bool mShutdown;
|
||||
bool mDirectConnected;
|
||||
// Get duration from create encoder, for logging purpose
|
||||
double GetEncodeTimeStamp()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче