Bug 987498 - Part 3 - Implement DOMHwMediaStream. r=roc

This commit is contained in:
Daosheng Mu 2015-06-18 00:21:00 +02:00
parent 72e5400a5f
commit 317b5386b4
3 changed files with 122 additions and 1 deletions

View File

@ -18,9 +18,13 @@
#include "MediaStreamGraph.h"
#include "AudioStreamTrack.h"
#include "VideoStreamTrack.h"
#include "Layers.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::layers;
const TrackID TRACK_VIDEO_PRIMARY = 1;
class DOMMediaStream::StreamListener : public MediaStreamListener {
public:
@ -668,3 +672,76 @@ DOMAudioNodeMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow,
return stream.forget();
}
DOMHwMediaStream::DOMHwMediaStream()
{
#ifdef MOZ_WIDGET_GONK
mImageContainer = LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS_OVERLAY);
nsRefPtr<Image> img = mImageContainer->CreateImage(ImageFormat::OVERLAY_IMAGE);
mOverlayImage = static_cast<layers::OverlayImage*>(img.get());
mImageContainer->SetCurrentImage(mOverlayImage);
#endif
}
DOMHwMediaStream::~DOMHwMediaStream()
{
}
already_AddRefed<DOMHwMediaStream>
DOMHwMediaStream::CreateHwStream(nsIDOMWindow* aWindow)
{
nsRefPtr<DOMHwMediaStream> stream = new DOMHwMediaStream();
stream->InitSourceStream(aWindow);
stream->Init(stream->GetStream());
return stream.forget();
}
void
DOMHwMediaStream::Init(MediaStream* stream)
{
SourceMediaStream* srcStream = stream->AsSourceStream();
if (srcStream) {
VideoSegment segment;
#ifdef MOZ_WIDGET_GONK
const StreamTime delta = STREAM_TIME_MAX; // Because MediaStreamGraph will run out frames in non-autoplay mode,
// we must give it bigger frame length to cover this situation.
mImageData.mOverlayId = DEFAULT_IMAGE_ID;
mImageData.mSize.width = DEFAULT_IMAGE_WIDTH;
mImageData.mSize.height = DEFAULT_IMAGE_HEIGHT;
mOverlayImage->SetData(mImageData);
nsRefPtr<Image> image = static_cast<Image*>(mOverlayImage.get());
mozilla::gfx::IntSize size = image->GetSize();
segment.AppendFrame(image.forget(), delta, size);
#endif
srcStream->AddTrack(TRACK_VIDEO_PRIMARY, 0, new VideoSegment());
srcStream->AppendToTrack(TRACK_VIDEO_PRIMARY, &segment);
srcStream->FinishAddTracks();
srcStream->AdvanceKnownTracksTime(STREAM_TIME_MAX);
}
}
int32_t
DOMHwMediaStream::RequestOverlayId()
{
#ifdef MOZ_WIDGET_GONK
return mOverlayImage->GetOverlayId();
#else
return -1;
#endif
}
void
DOMHwMediaStream::SetOverlayId(int32_t aOverlayId)
{
#ifdef MOZ_WIDGET_GONK
OverlayImage::Data imgData;
imgData.mOverlayId = aOverlayId;
imgData.mSize = mOverlayImage->GetSize();
mOverlayImage->SetData(imgData);
#endif
}

View File

@ -6,6 +6,8 @@
#ifndef NSDOMMEDIASTREAM_H_
#define NSDOMMEDIASTREAM_H_
#include "ImageContainer.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "StreamBuffer.h"
@ -29,6 +31,7 @@
namespace mozilla {
class DOMHwMediaStream;
class DOMLocalMediaStream;
class MediaStream;
class MediaEngineSource;
@ -47,6 +50,11 @@ class VideoTrackList;
class MediaTrackListListener;
}
namespace layers {
class ImageContainer;
class OverlayImage;
}
class MediaStreamDirectListener;
#define NS_DOMMEDIASTREAM_IID \
@ -114,6 +122,7 @@ public:
virtual void StopTrack(TrackID aTrackID);
virtual DOMLocalMediaStream* AsDOMLocalMediaStream() { return nullptr; }
virtual DOMHwMediaStream* AsDOMHwMediaStream() { return nullptr; }
bool IsFinished();
/**
@ -375,6 +384,39 @@ private:
nsRefPtr<AudioNode> mStreamNode;
};
class DOMHwMediaStream : public DOMLocalMediaStream
{
typedef mozilla::gfx::IntSize IntSize;
typedef layers::ImageContainer ImageContainer;
#ifdef MOZ_WIDGET_GONK
typedef layers::OverlayImage OverlayImage;
typedef layers::OverlayImage::Data Data;
#endif
public:
DOMHwMediaStream();
static already_AddRefed<DOMHwMediaStream> CreateHwStream(nsIDOMWindow* aWindow);
virtual DOMHwMediaStream* AsDOMHwMediaStream() override { return this; }
int32_t RequestOverlayId();
void SetOverlayId(int32_t aOverlayId);
protected:
~DOMHwMediaStream();
private:
void Init(MediaStream* aStream);
#ifdef MOZ_WIDGET_GONK
nsRefPtr<ImageContainer> mImageContainer;
const int DEFAULT_IMAGE_ID = 0x01;
const int DEFAULT_IMAGE_WIDTH = 400;
const int DEFAULT_IMAGE_HEIGHT = 300;
nsRefPtr<OverlayImage> mOverlayImage;
Data mImageData;
#endif
};
}
#endif /* NSDOMMEDIASTREAM_H_ */

View File

@ -197,8 +197,10 @@ TVTuner::GetStream() const
nsresult
TVTuner::InitMediaStream()
{
// TODO Instantiate |mStream| when bug 987498 is done.
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetOwner());
nsRefPtr<DOMHwMediaStream> stream = DOMHwMediaStream::CreateHwStream(window);
mStream = stream.forget();
return NS_OK;
}