2012-06-03 00:34:40 -07:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "MediaEngineDefault.h"
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMFile.h"
|
|
|
|
#include "nsILocalFile.h"
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "Layers.h"
|
2012-08-20 21:06:46 -07:00
|
|
|
#include "ImageContainer.h"
|
|
|
|
#include "ImageTypes.h"
|
2012-12-04 23:55:37 -08:00
|
|
|
#include "prmem.h"
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2013-02-20 07:18:54 -08:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
|
|
|
#endif
|
|
|
|
|
2012-10-25 17:14:47 -07:00
|
|
|
#define VIDEO_RATE USECS_PER_S
|
|
|
|
#define AUDIO_RATE 16000
|
2013-09-05 05:34:49 -07:00
|
|
|
#define AUDIO_FRAME_LENGTH ((AUDIO_RATE * MediaEngine::DEFAULT_AUDIO_TIMER_MS) / 1000)
|
2012-06-03 00:34:40 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-07-18 19:21:19 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(MediaEngineDefaultVideoSource, nsITimerCallback)
|
2012-06-03 00:34:40 -07:00
|
|
|
/**
|
|
|
|
* Default video source.
|
|
|
|
*/
|
2012-07-30 17:42:26 -07:00
|
|
|
|
2013-03-04 13:02:17 -08:00
|
|
|
MediaEngineDefaultVideoSource::MediaEngineDefaultVideoSource()
|
2013-08-14 14:01:16 -07:00
|
|
|
: mTimer(nullptr), mMonitor("Fake video")
|
2012-10-16 17:53:55 -07:00
|
|
|
{
|
2013-08-14 14:01:16 -07:00
|
|
|
mImageContainer = layers::LayerManager::CreateImageContainer();
|
2012-10-16 17:53:55 -07:00
|
|
|
mState = kReleased;
|
|
|
|
}
|
2012-07-30 17:42:26 -07:00
|
|
|
|
|
|
|
MediaEngineDefaultVideoSource::~MediaEngineDefaultVideoSource()
|
|
|
|
{}
|
|
|
|
|
2012-06-03 00:34:40 -07:00
|
|
|
void
|
|
|
|
MediaEngineDefaultVideoSource::GetName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Assign(NS_LITERAL_STRING("Default Video Device"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaEngineDefaultVideoSource::GetUUID(nsAString& aUUID)
|
|
|
|
{
|
|
|
|
aUUID.Assign(NS_LITERAL_STRING("1041FCBD-3F12-4F7B-9E9B-1EC556DD5676"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-19 17:29:43 -07:00
|
|
|
nsresult
|
2013-03-04 13:02:17 -08:00
|
|
|
MediaEngineDefaultVideoSource::Allocate(const MediaEnginePrefs &aPrefs)
|
2012-06-03 00:34:40 -07:00
|
|
|
{
|
|
|
|
if (mState != kReleased) {
|
2012-06-19 17:29:43 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-06-03 00:34:40 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 13:02:17 -08:00
|
|
|
mOpts = aPrefs;
|
2012-06-03 00:34:40 -07:00
|
|
|
mState = kAllocated;
|
2012-06-19 17:29:43 -07:00
|
|
|
return NS_OK;
|
2012-06-03 00:34:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
MediaEngineDefaultVideoSource::Deallocate()
|
|
|
|
{
|
|
|
|
if (mState != kStopped && mState != kAllocated) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mState = kReleased;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-01 17:57:50 -07:00
|
|
|
static void AllocateSolidColorFrame(layers::PlanarYCbCrData& aData,
|
2012-11-27 16:15:55 -08:00
|
|
|
int aWidth, int aHeight,
|
|
|
|
int aY, int aCb, int aCr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!(aWidth&1));
|
|
|
|
MOZ_ASSERT(!(aHeight&1));
|
|
|
|
// Allocate a single frame with a solid color
|
|
|
|
int yLen = aWidth*aHeight;
|
|
|
|
int cbLen = yLen>>2;
|
|
|
|
int crLen = cbLen;
|
|
|
|
uint8_t* frame = (uint8_t*) PR_Malloc(yLen+cbLen+crLen);
|
|
|
|
memset(frame, aY, yLen);
|
|
|
|
memset(frame+yLen, aCb, cbLen);
|
|
|
|
memset(frame+yLen+cbLen, aCr, crLen);
|
|
|
|
|
|
|
|
aData.mYChannel = frame;
|
|
|
|
aData.mYSize = gfxIntSize(aWidth, aHeight);
|
|
|
|
aData.mYStride = aWidth;
|
|
|
|
aData.mCbCrStride = aWidth>>1;
|
|
|
|
aData.mCbChannel = frame + yLen;
|
|
|
|
aData.mCrChannel = aData.mCbChannel + cbLen;
|
|
|
|
aData.mCbCrSize = gfxIntSize(aWidth>>1, aHeight>>1);
|
|
|
|
aData.mPicX = 0;
|
|
|
|
aData.mPicY = 0;
|
|
|
|
aData.mPicSize = gfxIntSize(aWidth, aHeight);
|
|
|
|
aData.mStereoMode = STEREO_MODE_MONO;
|
|
|
|
}
|
|
|
|
|
2013-10-01 17:57:50 -07:00
|
|
|
static void ReleaseFrame(layers::PlanarYCbCrData& aData)
|
2012-11-27 16:15:55 -08:00
|
|
|
{
|
|
|
|
PR_Free(aData.mYChannel);
|
|
|
|
}
|
|
|
|
|
2012-06-03 00:34:40 -07:00
|
|
|
nsresult
|
|
|
|
MediaEngineDefaultVideoSource::Start(SourceMediaStream* aStream, TrackID aID)
|
|
|
|
{
|
|
|
|
if (mState != kAllocated) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
|
|
if (!mTimer) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:01:16 -07:00
|
|
|
aStream->AddTrack(aID, VIDEO_RATE, 0, new VideoSegment());
|
|
|
|
aStream->AdvanceKnownTracksTime(STREAM_TIME_MAX);
|
2012-06-03 00:34:40 -07:00
|
|
|
|
|
|
|
// Remember TrackID so we can end it later
|
|
|
|
mTrackID = aID;
|
|
|
|
|
|
|
|
// Start timer for subsequent frames
|
2013-03-04 13:02:17 -08:00
|
|
|
mTimer->InitWithCallback(this, 1000 / mOpts.mFPS, nsITimer::TYPE_REPEATING_SLACK);
|
2012-06-03 00:34:40 -07:00
|
|
|
mState = kStarted;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-31 15:12:12 -08:00
|
|
|
MediaEngineDefaultVideoSource::Stop(SourceMediaStream *aSource, TrackID aID)
|
2012-06-03 00:34:40 -07:00
|
|
|
{
|
|
|
|
if (mState != kStarted) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (!mTimer) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimer->Cancel();
|
2013-10-23 13:34:10 -07:00
|
|
|
mTimer = nullptr;
|
2012-06-03 00:34:40 -07:00
|
|
|
|
2012-12-31 15:12:12 -08:00
|
|
|
aSource->EndTrack(aID);
|
|
|
|
aSource->Finish();
|
2012-06-03 00:34:40 -07:00
|
|
|
|
|
|
|
mState = kStopped;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
MediaEngineDefaultVideoSource::Snapshot(uint32_t aDuration, nsIDOMFile** aFile)
|
2012-06-03 00:34:40 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aFile = nullptr;
|
2012-06-10 16:44:50 -07:00
|
|
|
|
|
|
|
#ifndef MOZ_WIDGET_ANDROID
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#else
|
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString filePath;
|
|
|
|
AndroidBridge::Bridge()->ShowFilePickerForMimeType(filePath, NS_LITERAL_STRING("image/*"));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv = NS_NewLocalFile(filePath, false, getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*aFile = new nsDOMFileFile(file));
|
|
|
|
return NS_OK;
|
|
|
|
#endif
|
2012-06-03 00:34:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MediaEngineDefaultVideoSource::Notify(nsITimer* aTimer)
|
|
|
|
{
|
2012-11-27 16:15:55 -08:00
|
|
|
// Update the target color
|
|
|
|
if (mCr <= 16) {
|
|
|
|
if (mCb < 240) {
|
|
|
|
mCb++;
|
|
|
|
} else {
|
|
|
|
mCr++;
|
|
|
|
}
|
|
|
|
} else if (mCb >= 240) {
|
|
|
|
if (mCr < 240) {
|
|
|
|
mCr++;
|
|
|
|
} else {
|
|
|
|
mCb--;
|
|
|
|
}
|
|
|
|
} else if (mCr >= 240) {
|
|
|
|
if (mCb > 16) {
|
|
|
|
mCb--;
|
|
|
|
} else {
|
|
|
|
mCr--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCr--;
|
|
|
|
}
|
2012-06-03 00:34:40 -07:00
|
|
|
|
2012-11-27 16:15:55 -08:00
|
|
|
// Allocate a single solid color image
|
|
|
|
ImageFormat format = PLANAR_YCBCR;
|
|
|
|
nsRefPtr<layers::Image> image = mImageContainer->CreateImage(&format, 1);
|
|
|
|
nsRefPtr<layers::PlanarYCbCrImage> ycbcr_image =
|
|
|
|
static_cast<layers::PlanarYCbCrImage*>(image.get());
|
2013-10-01 17:57:50 -07:00
|
|
|
layers::PlanarYCbCrData data;
|
2013-02-20 07:18:54 -08:00
|
|
|
AllocateSolidColorFrame(data, mOpts.mWidth, mOpts.mHeight, 0x80, mCb, mCr);
|
2012-11-27 16:15:55 -08:00
|
|
|
ycbcr_image->SetData(data);
|
|
|
|
// SetData copies data, so we can free the frame
|
|
|
|
ReleaseFrame(data);
|
|
|
|
|
2013-08-14 14:01:16 -07:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
// implicitly releases last image
|
|
|
|
mImage = ycbcr_image.forget();
|
2012-06-03 00:34:40 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-17 02:46:40 -07:00
|
|
|
void
|
|
|
|
MediaEngineDefaultVideoSource::NotifyPull(MediaStreamGraph* aGraph,
|
2013-08-14 14:01:16 -07:00
|
|
|
SourceMediaStream *aSource,
|
|
|
|
TrackID aID,
|
|
|
|
StreamTime aDesiredTime,
|
|
|
|
TrackTicks &aLastEndTime)
|
2012-10-17 02:46:40 -07:00
|
|
|
{
|
2013-08-14 14:01:16 -07:00
|
|
|
// AddTrack takes ownership of segment
|
|
|
|
VideoSegment segment;
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
if (mState != kStarted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: we're not giving up mImage here
|
|
|
|
nsRefPtr<layers::Image> image = mImage;
|
|
|
|
TrackTicks target = TimeToTicksRoundUp(USECS_PER_S, aDesiredTime);
|
|
|
|
TrackTicks delta = target - aLastEndTime;
|
|
|
|
|
|
|
|
if (delta > 0) {
|
2013-10-23 13:34:10 -07:00
|
|
|
// nullptr images are allowed
|
2013-08-14 14:01:16 -07:00
|
|
|
if (image) {
|
|
|
|
segment.AppendFrame(image.forget(), delta,
|
|
|
|
gfxIntSize(mOpts.mWidth, mOpts.mHeight));
|
|
|
|
} else {
|
|
|
|
segment.AppendFrame(nullptr, delta, gfxIntSize(0,0));
|
|
|
|
}
|
|
|
|
// This can fail if either a) we haven't added the track yet, or b)
|
|
|
|
// we've removed or finished the track.
|
|
|
|
if (aSource->AppendToTrack(aID, &segment)) {
|
|
|
|
aLastEndTime = target;
|
|
|
|
}
|
|
|
|
}
|
2012-10-17 02:46:40 -07:00
|
|
|
}
|
|
|
|
|
2013-09-05 05:34:49 -07:00
|
|
|
// generate 1k sine wave per second
|
|
|
|
class SineWaveGenerator : public RefCounted<SineWaveGenerator>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const int bytesPerSample = 2;
|
|
|
|
static const int millisecondsPerSecond = 1000;
|
|
|
|
static const int frequency = 1000;
|
|
|
|
|
|
|
|
SineWaveGenerator(int aSampleRate) :
|
|
|
|
mTotalLength(aSampleRate / frequency),
|
|
|
|
mReadLength(0) {
|
|
|
|
MOZ_ASSERT(mTotalLength * frequency == aSampleRate);
|
|
|
|
mAudioBuffer = new int16_t[mTotalLength];
|
|
|
|
for(int i = 0; i < mTotalLength; i++) {
|
|
|
|
// Set volume to -20db. It's from 32768.0 * 10^(-20/20) = 3276.8
|
|
|
|
mAudioBuffer[i] = (3276.8f * sin(2 * M_PI * i / mTotalLength));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void generate(int16_t* aBuffer, int16_t aLengthInSamples) {
|
|
|
|
int16_t remaining = aLengthInSamples;
|
|
|
|
|
|
|
|
while (remaining) {
|
|
|
|
int16_t processSamples = 0;
|
|
|
|
|
|
|
|
if (mTotalLength - mReadLength >= remaining) {
|
|
|
|
processSamples = remaining;
|
|
|
|
} else {
|
|
|
|
processSamples = mTotalLength - mReadLength;
|
|
|
|
}
|
|
|
|
memcpy(aBuffer, mAudioBuffer + mReadLength, processSamples * bytesPerSample);
|
|
|
|
aBuffer += processSamples;
|
|
|
|
mReadLength += processSamples;
|
|
|
|
remaining -= processSamples;
|
|
|
|
if (mReadLength == mTotalLength) {
|
|
|
|
mReadLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsAutoArrayPtr<int16_t> mAudioBuffer;
|
|
|
|
int16_t mTotalLength;
|
|
|
|
int16_t mReadLength;
|
|
|
|
};
|
2012-10-17 02:46:40 -07:00
|
|
|
|
2012-06-03 00:34:40 -07:00
|
|
|
/**
|
|
|
|
* Default audio source.
|
|
|
|
*/
|
2013-07-18 19:21:19 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(MediaEngineDefaultAudioSource, nsITimerCallback)
|
2012-10-17 02:46:40 -07:00
|
|
|
|
2012-10-16 17:53:55 -07:00
|
|
|
MediaEngineDefaultAudioSource::MediaEngineDefaultAudioSource()
|
|
|
|
: mTimer(nullptr)
|
|
|
|
{
|
|
|
|
mState = kReleased;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaEngineDefaultAudioSource::~MediaEngineDefaultAudioSource()
|
|
|
|
{}
|
|
|
|
|
2012-06-03 00:34:40 -07:00
|
|
|
void
|
|
|
|
MediaEngineDefaultAudioSource::GetName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Assign(NS_LITERAL_STRING("Default Audio Device"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaEngineDefaultAudioSource::GetUUID(nsAString& aUUID)
|
|
|
|
{
|
|
|
|
aUUID.Assign(NS_LITERAL_STRING("B7CBD7C1-53EF-42F9-8353-73F61C70C092"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-19 17:29:43 -07:00
|
|
|
nsresult
|
2013-03-04 13:02:17 -08:00
|
|
|
MediaEngineDefaultAudioSource::Allocate(const MediaEnginePrefs &aPrefs)
|
2012-06-03 00:34:40 -07:00
|
|
|
{
|
|
|
|
if (mState != kReleased) {
|
2012-06-19 17:29:43 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-06-03 00:34:40 -07:00
|
|
|
}
|
2012-06-19 17:29:43 -07:00
|
|
|
|
2012-06-03 00:34:40 -07:00
|
|
|
mState = kAllocated;
|
2013-09-05 05:34:49 -07:00
|
|
|
// generate 1Khz sine wave
|
|
|
|
mSineGenerator = new SineWaveGenerator(AUDIO_RATE);
|
2012-06-19 17:29:43 -07:00
|
|
|
return NS_OK;
|
2012-06-03 00:34:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
MediaEngineDefaultAudioSource::Deallocate()
|
|
|
|
{
|
|
|
|
if (mState != kStopped && mState != kAllocated) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mState = kReleased;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
MediaEngineDefaultAudioSource::Start(SourceMediaStream* aStream, TrackID aID)
|
|
|
|
{
|
|
|
|
if (mState != kAllocated) {
|
2012-06-19 17:29:43 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-06-03 00:34:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
|
|
if (!mTimer) {
|
2012-06-19 17:29:43 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-06-03 00:34:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mSource = aStream;
|
|
|
|
|
|
|
|
// AddTrack will take ownership of segment
|
|
|
|
AudioSegment* segment = new AudioSegment();
|
2012-10-25 17:14:47 -07:00
|
|
|
mSource->AddTrack(aID, AUDIO_RATE, 0, segment);
|
2012-06-03 00:34:40 -07:00
|
|
|
|
|
|
|
// We aren't going to add any more tracks
|
|
|
|
mSource->AdvanceKnownTracksTime(STREAM_TIME_MAX);
|
|
|
|
|
|
|
|
// Remember TrackID so we can finish later
|
|
|
|
mTrackID = aID;
|
|
|
|
|
2013-08-14 14:01:16 -07:00
|
|
|
// 1 Audio frame per 10ms
|
2013-06-20 10:14:04 -07:00
|
|
|
mTimer->InitWithCallback(this, MediaEngine::DEFAULT_AUDIO_TIMER_MS,
|
2013-09-05 05:34:49 -07:00
|
|
|
nsITimer::TYPE_REPEATING_PRECISE);
|
2012-06-03 00:34:40 -07:00
|
|
|
mState = kStarted;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-31 15:12:12 -08:00
|
|
|
MediaEngineDefaultAudioSource::Stop(SourceMediaStream *aSource, TrackID aID)
|
2012-06-03 00:34:40 -07:00
|
|
|
{
|
|
|
|
if (mState != kStarted) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (!mTimer) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimer->Cancel();
|
2013-10-23 13:34:10 -07:00
|
|
|
mTimer = nullptr;
|
2012-06-03 00:34:40 -07:00
|
|
|
|
2012-12-31 15:12:12 -08:00
|
|
|
aSource->EndTrack(aID);
|
|
|
|
aSource->Finish();
|
2012-06-03 00:34:40 -07:00
|
|
|
|
|
|
|
mState = kStopped;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
MediaEngineDefaultAudioSource::Snapshot(uint32_t aDuration, nsIDOMFile** aFile)
|
2012-06-03 00:34:40 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MediaEngineDefaultAudioSource::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
AudioSegment segment;
|
2013-09-05 05:34:49 -07:00
|
|
|
nsRefPtr<SharedBuffer> buffer = SharedBuffer::Create(AUDIO_FRAME_LENGTH * sizeof(int16_t));
|
|
|
|
int16_t* dest = static_cast<int16_t*>(buffer->Data());
|
2013-06-20 10:14:04 -07:00
|
|
|
|
2013-09-05 05:34:49 -07:00
|
|
|
mSineGenerator->generate(dest, AUDIO_FRAME_LENGTH);
|
|
|
|
nsAutoTArray<const int16_t*,1> channels;
|
|
|
|
channels.AppendElement(dest);
|
|
|
|
segment.AppendFrames(buffer.forget(), channels, AUDIO_FRAME_LENGTH);
|
2012-06-03 00:34:40 -07:00
|
|
|
mSource->AppendToTrack(mTrackID, &segment);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaEngineDefault::EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >* aVSources) {
|
2012-10-19 15:06:18 -07:00
|
|
|
MutexAutoLock lock(mMutex);
|
2013-02-20 07:18:54 -08:00
|
|
|
|
2013-03-04 13:02:17 -08:00
|
|
|
// We once had code here to find a VideoSource with the same settings and re-use that.
|
|
|
|
// This no longer is possible since the resolution is being set in Allocate().
|
|
|
|
|
|
|
|
nsRefPtr<MediaEngineVideoSource> newSource = new MediaEngineDefaultVideoSource();
|
|
|
|
mVSources.AppendElement(newSource);
|
|
|
|
aVSources->AppendElement(newSource);
|
2012-10-16 17:53:55 -07:00
|
|
|
|
2012-06-03 00:34:40 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaEngineDefault::EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >* aASources) {
|
2012-10-19 15:06:18 -07:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
int32_t len = mASources.Length();
|
|
|
|
|
2012-10-16 17:53:55 -07:00
|
|
|
for (int32_t i = 0; i < len; i++) {
|
|
|
|
nsRefPtr<MediaEngineAudioSource> source = mASources.ElementAt(i);
|
|
|
|
if (source->IsAvailable()) {
|
|
|
|
aASources->AppendElement(source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// All streams are currently busy, just make a new one.
|
|
|
|
if (aASources->Length() == 0) {
|
|
|
|
nsRefPtr<MediaEngineAudioSource> newSource =
|
|
|
|
new MediaEngineDefaultAudioSource();
|
|
|
|
mASources.AppendElement(newSource);
|
|
|
|
aASources->AppendElement(newSource);
|
|
|
|
}
|
2012-06-03 00:34:40 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-03 00:35:15 -07:00
|
|
|
} // namespace mozilla
|