Backed out changeset 1c8af95cd440 (bug 1201363)

This commit is contained in:
Carsten "Tomcat" Book 2016-08-02 12:53:51 +02:00
parent 1d6d29d0c6
commit 2854eb5e13
3 changed files with 30 additions and 46 deletions

View File

@ -15,32 +15,6 @@
namespace mozilla {
class CaptureTask::MediaStreamEventListener : public MediaStreamTrackListener
{
public:
MediaStreamEventListener(CaptureTask* aCaptureTask)
: mCaptureTask(aCaptureTask) {};
// MediaStreamListener methods.
void NotifyEnded() override
{
if(!mCaptureTask->mImageGrabbedOrTrackEnd) {
mCaptureTask->PostTrackEndEvent();
}
}
private:
CaptureTask* mCaptureTask;
};
CaptureTask::CaptureTask(dom::ImageCapture* aImageCapture)
: mImageCapture(aImageCapture)
, mEventListener(new MediaStreamEventListener(this))
, mImageGrabbedOrTrackEnd(false)
, mPrincipalChanged(false)
{
}
nsresult
CaptureTask::TaskComplete(already_AddRefed<dom::Blob> aBlob, nsresult aRv)
{
@ -81,8 +55,7 @@ CaptureTask::AttachTrack()
dom::VideoStreamTrack* track = mImageCapture->GetVideoStreamTrack();
track->AddPrincipalChangeObserver(this);
track->AddListener(mEventListener.get());
track->AddDirectListener(this);
track->AddListener(this);
}
void
@ -92,8 +65,7 @@ CaptureTask::DetachTrack()
dom::VideoStreamTrack* track = mImageCapture->GetVideoStreamTrack();
track->RemovePrincipalChangeObserver(this);
track->RemoveListener(mEventListener.get());
track->RemoveDirectListener(this);
track->RemoveListener(this);
}
void
@ -104,12 +76,16 @@ CaptureTask::PrincipalChanged(dom::MediaStreamTrack* aMediaStreamTrack)
}
void
CaptureTask::SetCurrentFrames(const VideoSegment& aSegment)
CaptureTask::NotifyQueuedChanges(MediaStreamGraph* aGraph,
StreamTime aTrackOffset,
const MediaSegment& aQueuedMedia)
{
if (mImageGrabbedOrTrackEnd) {
return;
}
MOZ_ASSERT(aQueuedMedia.GetType() == MediaSegment::VIDEO);
// Callback for encoding complete, it calls on main thread.
class EncodeComplete : public dom::EncodeCompleteCallback
{
@ -128,13 +104,11 @@ CaptureTask::SetCurrentFrames(const VideoSegment& aSegment)
RefPtr<CaptureTask> mTask;
};
VideoSegment::ConstChunkIterator iter(aSegment);
VideoSegment* video =
const_cast<VideoSegment*> (static_cast<const VideoSegment*>(&aQueuedMedia));
VideoSegment::ChunkIterator iter(*video);
while (!iter.IsEnded()) {
VideoChunk chunk = *iter;
// Extract the first valid video frame.
VideoFrame frame;
if (!chunk.IsNull()) {
@ -167,6 +141,14 @@ CaptureTask::SetCurrentFrames(const VideoSegment& aSegment)
}
}
void
CaptureTask::NotifyEnded()
{
if(!mImageGrabbedOrTrackEnd) {
PostTrackEndEvent();
}
}
void
CaptureTask::PostTrackEndEvent()
{

View File

@ -10,7 +10,6 @@
#include "MediaStreamGraph.h"
#include "MediaStreamListener.h"
#include "PrincipalChangeObserver.h"
#include "MediaStreamVideoSink.h"
namespace mozilla {
@ -30,15 +29,16 @@ class MediaStreamTrack;
* CaptureTask holds a reference of ImageCapture to ensure ImageCapture won't be
* released during the period of the capturing process described above.
*/
class CaptureTask : public MediaStreamVideoSink,
class CaptureTask : public MediaStreamTrackListener,
public dom::PrincipalChangeObserver<dom::MediaStreamTrack>
{
public:
class MediaStreamEventListener;
// MediaStreamTrackListener methods.
void NotifyQueuedChanges(MediaStreamGraph* aGraph,
StreamTime aTrackOffset,
const MediaSegment& aQueuedMedia) override;
// MediaStreamVideoSink methods.
void SetCurrentFrames(const VideoSegment& aSegment) override;
void ClearFrames() override {}
void NotifyEnded() override;
// PrincipalChangeObserver<MediaStreamTrack> method.
void PrincipalChanged(dom::MediaStreamTrack* aMediaStreamTrack) override;
@ -61,7 +61,10 @@ public:
void DetachTrack();
// CaptureTask should be created on main thread.
CaptureTask(dom::ImageCapture* aImageCapture);
explicit CaptureTask(dom::ImageCapture* aImageCapture)
: mImageCapture(aImageCapture)
, mImageGrabbedOrTrackEnd(false)
, mPrincipalChanged(false) {}
protected:
virtual ~CaptureTask() {}
@ -75,8 +78,6 @@ protected:
// event to script.
RefPtr<dom::ImageCapture> mImageCapture;
RefPtr<MediaStreamEventListener> mEventListener;
// True when an image is retrieved from MediaStreamGraph or MediaStreamGraph
// sends a track finish, end, or removed event.
bool mImageGrabbedOrTrackEnd;

View File

@ -147,7 +147,8 @@ ImageCapture::TakePhoto(ErrorResult& aResult)
// support TakePhoto().
if (rv == NS_ERROR_NOT_IMPLEMENTED) {
IC_LOG("MediaEngine doesn't support TakePhoto(), it falls back to MediaStreamGraph.");
RefPtr<CaptureTask> task = new CaptureTask(this);
RefPtr<CaptureTask> task =
new CaptureTask(this);
// It adds itself into MediaStreamGraph, so ImageCapture doesn't need to hold
// the reference.