mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1180589 part 2 - Add code to create a simulated mediastream; r=seanlin
This commit is contained in:
parent
8478bd2e88
commit
9965826ab8
@ -24,7 +24,7 @@ function TVSimulatorService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TVSimulatorService.prototype = {
|
TVSimulatorService.prototype = {
|
||||||
classID: Components.ID("{f0ab9850-24b4-4f5d-83dd-0fea0c249ca1}"),
|
classID: Components.ID("{94b065ad-d45a-436a-b394-6dabc3cf110f}"),
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsITVSimulatorService,
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsITVSimulatorService,
|
||||||
Ci.nsITVService,
|
Ci.nsITVService,
|
||||||
Ci.nsITimerCallback]),
|
Ci.nsITimerCallback]),
|
||||||
@ -36,14 +36,10 @@ TVSimulatorService.prototype = {
|
|||||||
|
|
||||||
// Load the setting file from local JSON file.
|
// Load the setting file from local JSON file.
|
||||||
// Synchrhronous File Reading.
|
// Synchrhronous File Reading.
|
||||||
let dsFile = Cc["@mozilla.org/file/directory_service;1"]
|
|
||||||
.getService(Ci.nsIProperties)
|
|
||||||
.get("ProfD", Ci.nsIFile);
|
|
||||||
dsFile.append(TV_SIMULATOR_DUMMY_DIRECTORY);
|
|
||||||
dsFile.append(TV_SIMULATOR_DUMMY_FILE);
|
|
||||||
let file = Cc["@mozilla.org/file/local;1"]
|
let file = Cc["@mozilla.org/file/local;1"]
|
||||||
.createInstance(Ci.nsILocalFile);
|
.createInstance(Ci.nsILocalFile);
|
||||||
file.initWithPath(dsFile.path);
|
|
||||||
|
file.initWithPath(this._getFilePath(TV_SIMULATOR_DUMMY_FILE));
|
||||||
|
|
||||||
let fstream = Cc["@mozilla.org/network/file-input-stream;1"]
|
let fstream = Cc["@mozilla.org/network/file-input-stream;1"]
|
||||||
.createInstance(Ci.nsIFileInputStream);
|
.createInstance(Ci.nsIFileInputStream);
|
||||||
@ -97,7 +93,7 @@ TVSimulatorService.prototype = {
|
|||||||
* "number" : The LCN (Logical Channel Number) of the channel,
|
* "number" : The LCN (Logical Channel Number) of the channel,
|
||||||
* "isEmergency" : Whether this channel is emergency status,
|
* "isEmergency" : Whether this channel is emergency status,
|
||||||
* "isFree": Whether this channel is free or not,
|
* "isFree": Whether this channel is free or not,
|
||||||
* "videoFilePath": "The path of the fake movie file",
|
* "videoFilePath": "The path of the fake video file",
|
||||||
* "programs":[{
|
* "programs":[{
|
||||||
* "eventId": "The ID of this program event",
|
* "eventId": "The ID of this program event",
|
||||||
* "title" : "This program's title",
|
* "title" : "This program's title",
|
||||||
@ -222,8 +218,6 @@ TVSimulatorService.prototype = {
|
|||||||
if (!wrapTunerData) {
|
if (!wrapTunerData) {
|
||||||
return aCallback.notifyError(Ci.nsITVServiceCallback.TV_ERROR_FAILURE);
|
return aCallback.notifyError(Ci.nsITVServiceCallback.TV_ERROR_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bug 1180589 : We should change video source.
|
|
||||||
return aCallback.notifySuccess(null);
|
return aCallback.notifySuccess(null);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -399,13 +393,24 @@ TVSimulatorService.prototype = {
|
|||||||
return this._sourceListener;
|
return this._sourceListener;
|
||||||
},
|
},
|
||||||
|
|
||||||
getSimulatorVideoFilePath: function TVSimGetSimulatorVideoFilePath(aTunerId, aSourceType, aChannelNumber) {
|
getSimulatorVideoBlobURL: function TVSimGetSimulatorVideoBlob(aTunerId,
|
||||||
|
aSourceType,
|
||||||
|
aChannelNumber,
|
||||||
|
aWin) {
|
||||||
let wrapTunerData = this._getWrapTunerData(aTunerId, aSourceType);
|
let wrapTunerData = this._getWrapTunerData(aTunerId, aSourceType);
|
||||||
if (!wrapTunerData || !wrapTunerData.channels || wrapTunerData.channels.size <= 0) {
|
if (!wrapTunerData || !wrapTunerData.channels) {
|
||||||
return null;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrapTunerData.channels.get(aChannelNumber).videoFilePath;
|
let wrapChannelData = wrapTunerData.channels.get(aChannelNumber);
|
||||||
|
if (!wrapChannelData) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
let videoFile = new File(this._getFilePath(wrapChannelData.videoFilePath));
|
||||||
|
let videoBlobURL = aWin.URL.createObjectURL(videoFile);
|
||||||
|
|
||||||
|
return videoBlobURL;
|
||||||
},
|
},
|
||||||
|
|
||||||
_getTunerMapKey: function TVSimGetTunerMapKey(aTunerId, aSourceType) {
|
_getTunerMapKey: function TVSimGetTunerMapKey(aTunerId, aSourceType) {
|
||||||
@ -417,7 +422,17 @@ TVSimulatorService.prototype = {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this._internalTuners.get(this._getTunerMapKey(aTunerId, aSourceType));
|
return this._internalTuners.get(this._getTunerMapKey(aTunerId, aSourceType));
|
||||||
}
|
},
|
||||||
|
|
||||||
|
_getFilePath: function TVSimGetFilePathFromDummyDirectory(fileName) {
|
||||||
|
let dsFile = Cc["@mozilla.org/file/directory_service;1"]
|
||||||
|
.getService(Ci.nsIProperties)
|
||||||
|
.get("ProfD", Ci.nsIFile);
|
||||||
|
dsFile.append(TV_SIMULATOR_DUMMY_DIRECTORY);
|
||||||
|
dsFile.append(fileName);
|
||||||
|
|
||||||
|
return dsFile.path;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TVSimulatorService]);
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TVSimulatorService]);
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
component {f0ab9850-24b4-4f5d-83dd-0fea0c249ca1} TVSimulatorService.js
|
component {94b065ad-d45a-436a-b394-6dabc3cf110f} TVSimulatorService.js
|
||||||
contract @mozilla.org/tv/simulatorservice;1 {f0ab9850-24b4-4f5d-83dd-0fea0c249ca1}
|
contract @mozilla.org/tv/simulatorservice;1 {94b065ad-d45a-436a-b394-6dabc3cf110f}
|
||||||
TVSimulatorService @mozilla.org/tv/simulatorservice;1
|
TVSimulatorService @mozilla.org/tv/simulatorservice;1
|
||||||
|
@ -133,6 +133,14 @@ TVSource::SetCurrentChannel(nsITVChannelData* aChannelData)
|
|||||||
mCurrentChannel = TVChannel::Create(GetOwner(), this, aChannelData);
|
mCurrentChannel = TVChannel::Create(GetOwner(), this, aChannelData);
|
||||||
NS_ENSURE_TRUE(mCurrentChannel, NS_ERROR_DOM_ABORT_ERR);
|
NS_ENSURE_TRUE(mCurrentChannel, NS_ERROR_DOM_ABORT_ERR);
|
||||||
|
|
||||||
|
nsRefPtr<TVSource> currentSource = mTuner->GetCurrentSource();
|
||||||
|
if (currentSource && mType == currentSource->Type()) {
|
||||||
|
rv = mTuner->ReloadMediaStream();
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return DispatchCurrentChannelChangedEvent(mCurrentChannel);
|
return DispatchCurrentChannelChangedEvent(mCurrentChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,10 @@
|
|||||||
#include "mozilla/dom/TVUtils.h"
|
#include "mozilla/dom/TVUtils.h"
|
||||||
#include "nsISupportsPrimitives.h"
|
#include "nsISupportsPrimitives.h"
|
||||||
#include "nsITVService.h"
|
#include "nsITVService.h"
|
||||||
|
#include "nsITVSimulatorService.h"
|
||||||
#include "nsServiceManagerUtils.h"
|
#include "nsServiceManagerUtils.h"
|
||||||
#include "TVTuner.h"
|
#include "TVTuner.h"
|
||||||
|
#include "mozilla/dom/HTMLVideoElement.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@ -197,6 +199,12 @@ TVTuner::GetStream() const
|
|||||||
return stream.forget();
|
return stream.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
TVTuner::ReloadMediaStream()
|
||||||
|
{
|
||||||
|
return InitMediaStream();
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
TVTuner::InitMediaStream()
|
TVTuner::InitMediaStream()
|
||||||
{
|
{
|
||||||
@ -205,11 +213,7 @@ TVTuner::InitMediaStream()
|
|||||||
if (mStreamType == nsITVTunerData::TV_STREAM_TYPE_HW) {
|
if (mStreamType == nsITVTunerData::TV_STREAM_TYPE_HW) {
|
||||||
stream = DOMHwMediaStream::CreateHwStream(window);
|
stream = DOMHwMediaStream::CreateHwStream(window);
|
||||||
} else if (mStreamType == nsITVTunerData::TV_STREAM_TYPE_SIMULATOR) {
|
} else if (mStreamType == nsITVTunerData::TV_STREAM_TYPE_SIMULATOR) {
|
||||||
// Bug 1180589 : We should MediaStream from local file.
|
stream = CreateSimulatedMediaStream();
|
||||||
// We should create the PART.2 patch.
|
|
||||||
//stream = CreateSimulatedMediaStream();
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mStream = stream.forget();
|
mStream = stream.forget();
|
||||||
@ -219,7 +223,85 @@ TVTuner::InitMediaStream()
|
|||||||
already_AddRefed<DOMMediaStream>
|
already_AddRefed<DOMMediaStream>
|
||||||
TVTuner::CreateSimulatedMediaStream()
|
TVTuner::CreateSimulatedMediaStream()
|
||||||
{
|
{
|
||||||
return nullptr;
|
ErrorResult error;
|
||||||
|
|
||||||
|
nsIDocument* doc = GetOwner()->GetExtantDoc();
|
||||||
|
if (NS_WARN_IF(!doc)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
nsRefPtr<Element> element = doc->CreateElement(VIDEO_TAG, error);
|
||||||
|
if (NS_WARN_IF(error.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContent> content(do_QueryInterface(element));
|
||||||
|
if (NS_WARN_IF(!content)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(content.get());
|
||||||
|
if (NS_WARN_IF(!mediaElement)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaElement->SetAutoplay(true, error);
|
||||||
|
if (NS_WARN_IF(error.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaElement->SetLoop(true, error);
|
||||||
|
if (NS_WARN_IF(error.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(GetOwner()));
|
||||||
|
if (NS_WARN_IF(!domWin)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsITVSimulatorService> simService(do_QueryInterface(mTVService));
|
||||||
|
if (NS_WARN_IF(!simService)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_WARN_IF(!mCurrentSource)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsRefPtr<TVChannel> currentChannel = mCurrentSource->GetCurrentChannel();
|
||||||
|
if (NS_WARN_IF(!currentChannel)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsString currentChannelNumber;
|
||||||
|
currentChannel->GetNumber(currentChannelNumber);
|
||||||
|
if (currentChannelNumber.IsEmpty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsString currentVideoBlobUrl;
|
||||||
|
nsresult rv = simService->GetSimulatorVideoBlobURL(mId,
|
||||||
|
ToTVSourceTypeStr(mCurrentSource->Type()),
|
||||||
|
currentChannelNumber,
|
||||||
|
domWin,
|
||||||
|
currentVideoBlobUrl);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaElement->SetSrc(currentVideoBlobUrl, error);
|
||||||
|
if (NS_WARN_IF(error.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See Media Capture from DOM Elements spec.
|
||||||
|
// http://www.w3.org/TR/mediacapture-fromelement/
|
||||||
|
nsRefPtr<DOMMediaStream> stream = mediaElement->MozCaptureStream(error);
|
||||||
|
if (NS_WARN_IF(error.Failed())) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
// Include TVTunerBinding.h since enum TVSourceType can't be forward declared.
|
// Include TVTunerBinding.h since enum TVSourceType can't be forward declared.
|
||||||
#include "mozilla/dom/TVTunerBinding.h"
|
#include "mozilla/dom/TVTunerBinding.h"
|
||||||
|
|
||||||
|
#define VIDEO_TAG NS_LITERAL_STRING("video")
|
||||||
|
|
||||||
class nsITVService;
|
class nsITVService;
|
||||||
class nsITVTunerData;
|
class nsITVTunerData;
|
||||||
|
|
||||||
@ -59,6 +61,8 @@ public:
|
|||||||
|
|
||||||
IMPL_EVENT_HANDLER(currentsourcechanged);
|
IMPL_EVENT_HANDLER(currentsourcechanged);
|
||||||
|
|
||||||
|
nsresult ReloadMediaStream();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit TVTuner(nsPIDOMWindow* aWindow);
|
explicit TVTuner(nsPIDOMWindow* aWindow);
|
||||||
|
|
||||||
|
@ -4,25 +4,28 @@
|
|||||||
|
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
#include "nsITVService.idl"
|
#include "nsITVService.idl"
|
||||||
|
#include "nsIDOMWindow.idl"
|
||||||
|
|
||||||
%{C++
|
%{C++
|
||||||
#define TV_SIMULATOR_SERVICE_CONTRACTID\
|
#define TV_SIMULATOR_SERVICE_CONTRACTID\
|
||||||
"@mozilla.org/tv/simulatorservice;1"
|
"@mozilla.org/tv/simulatorservice;1"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
[scriptable, uuid(f0ab9850-24b4-4f5d-83dd-0fea0c249ca1)]
|
[scriptable, uuid(8ecae67d-a959-4f8a-a786-14dc12bd8d3c)]
|
||||||
interface nsITVSimulatorService : nsITVService
|
interface nsITVSimulatorService : nsITVService
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Get the simulate movie file.The path is full location path.
|
* Get the URL of simulated video blob.
|
||||||
* e.g. /home/user/simulator/gaia/profile/dummy/tv-movie1.ogv
|
|
||||||
*
|
*
|
||||||
* @param tunerId The ID of the tuner.
|
* @param tunerId The ID of the tuner.
|
||||||
* @param sourceType The source type to be used.
|
* @param sourceType The source type to be used.
|
||||||
* @param channelNumber The LCN (Logical Channel Number) of the channel.
|
* @param channelNumber The LCN (Logical Channel Number) of the channel.
|
||||||
|
* @param window The window object of content.
|
||||||
|
* @return blobUrl The URL of created blob from local video file.
|
||||||
*/
|
*/
|
||||||
void getSimulatorVideoFilePath(in DOMString tunerId,
|
void getSimulatorVideoBlobURL(in DOMString tunerId,
|
||||||
in DOMString sourceType,
|
in DOMString sourceType,
|
||||||
in DOMString channelNumber,
|
in DOMString channelNumber,
|
||||||
[retval] out string filePath);
|
in nsIDOMWindow window,
|
||||||
|
[retval] out DOMString blobUrl);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user