зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1130290 - Remove PeerConnectionImpl::CreateFakeMediaStream. r=jesup
--HG-- extra : rebase_source : c5fe9a894178e600c48ce22e45b9c124c76cf712
This commit is contained in:
Родитель
0aeec913e7
Коммит
a85bba5efb
|
@ -309,8 +309,6 @@ namespace mozilla {
|
|||
|
||||
class nsIDOMDataChannel;
|
||||
|
||||
static const int MEDIA_STREAM_MUTE = 0x80;
|
||||
|
||||
PRLogModuleInfo *signalingLogInfo() {
|
||||
static PRLogModuleInfo *logModuleInfo = nullptr;
|
||||
if (!logModuleInfo) {
|
||||
|
@ -1010,39 +1008,6 @@ PeerConnectionImpl::GetIdentity() const
|
|||
return mIdentity;
|
||||
}
|
||||
|
||||
nsresult
|
||||
PeerConnectionImpl::CreateFakeMediaStream(uint32_t aHint, DOMMediaStream** aRetval)
|
||||
{
|
||||
MOZ_ASSERT(aRetval);
|
||||
PC_AUTO_ENTER_API_CALL(false);
|
||||
|
||||
bool mute = false;
|
||||
|
||||
// Hack to allow you to mute the stream
|
||||
if (aHint & MEDIA_STREAM_MUTE) {
|
||||
mute = true;
|
||||
aHint &= ~MEDIA_STREAM_MUTE;
|
||||
}
|
||||
|
||||
nsRefPtr<DOMMediaStream> stream = MakeMediaStream(aHint);
|
||||
if (!stream) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (!mute) {
|
||||
if (aHint & DOMMediaStream::HINT_CONTENTS_AUDIO) {
|
||||
new Fake_AudioGenerator(stream);
|
||||
} else {
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
new Fake_VideoGenerator(stream);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
stream.forget(aRetval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Data channels won't work without a window, so in order for the C++ unit
|
||||
// tests to work (it doesn't have a window available) we ifdef the following
|
||||
// two implementations.
|
||||
|
|
|
@ -321,9 +321,6 @@ public:
|
|||
// Get the DTLS identity (local side)
|
||||
mozilla::RefPtr<DtlsIdentity> const GetIdentity() const;
|
||||
|
||||
// Create a fake media stream
|
||||
nsresult CreateFakeMediaStream(uint32_t hint, mozilla::DOMMediaStream** retval);
|
||||
|
||||
nsPIDOMWindow* GetWindow() const {
|
||||
PC_AUTO_ENTER_API_CALL_NO_CHECK();
|
||||
return mWindow;
|
||||
|
|
|
@ -57,123 +57,6 @@ class PeerConnectionImpl;
|
|||
class PeerConnectionMedia;
|
||||
class PCUuidGenerator;
|
||||
|
||||
/* Temporary for providing audio data */
|
||||
class Fake_AudioGenerator {
|
||||
public:
|
||||
explicit Fake_AudioGenerator(DOMMediaStream* aStream) : mStream(aStream), mCount(0) {
|
||||
mTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
MOZ_ASSERT(mTimer);
|
||||
|
||||
// Make a track
|
||||
mozilla::AudioSegment *segment = new mozilla::AudioSegment();
|
||||
mStream->GetStream()->AsSourceStream()->AddAudioTrack(1, 16000, 0, segment);
|
||||
|
||||
// Set the timer
|
||||
mTimer->InitWithFuncCallback(Callback, this, 100, nsITimer::TYPE_REPEATING_PRECISE);
|
||||
}
|
||||
|
||||
static void Callback(nsITimer* timer, void *arg) {
|
||||
Fake_AudioGenerator* gen = static_cast<Fake_AudioGenerator*>(arg);
|
||||
|
||||
nsRefPtr<mozilla::SharedBuffer> samples = mozilla::SharedBuffer::Create(1600 * sizeof(int16_t));
|
||||
int16_t* data = static_cast<int16_t*>(samples->Data());
|
||||
for (int i=0; i<1600; i++) {
|
||||
data[i] = ((gen->mCount % 8) * 4000) - (7*4000)/2;
|
||||
++gen->mCount;
|
||||
}
|
||||
|
||||
mozilla::AudioSegment segment;
|
||||
nsAutoTArray<const int16_t*,1> channelData;
|
||||
channelData.AppendElement(data);
|
||||
segment.AppendFrames(samples.forget(), channelData, 1600);
|
||||
gen->mStream->GetStream()->AsSourceStream()->AppendToTrack(1, &segment);
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsRefPtr<DOMMediaStream> mStream;
|
||||
int mCount;
|
||||
};
|
||||
|
||||
/* Temporary for providing video data */
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
class Fake_VideoGenerator {
|
||||
public:
|
||||
typedef mozilla::gfx::IntSize IntSize;
|
||||
|
||||
explicit Fake_VideoGenerator(DOMMediaStream* aStream) {
|
||||
mStream = aStream;
|
||||
mCount = 0;
|
||||
mTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
MOZ_ASSERT(mTimer);
|
||||
|
||||
// Make a track
|
||||
mozilla::VideoSegment *segment = new mozilla::VideoSegment();
|
||||
mStream->GetStream()->AsSourceStream()->AddTrack(1, 0, segment);
|
||||
mStream->GetStream()->AsSourceStream()->AdvanceKnownTracksTime(mozilla::STREAM_TIME_MAX);
|
||||
|
||||
// Set the timer. Set to 10 fps.
|
||||
mTimer->InitWithFuncCallback(Callback, this, 100, nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
static void Callback(nsITimer* timer, void *arg) {
|
||||
Fake_VideoGenerator* gen = static_cast<Fake_VideoGenerator*>(arg);
|
||||
|
||||
const uint32_t WIDTH = 640;
|
||||
const uint32_t HEIGHT = 480;
|
||||
|
||||
// Allocate a single blank Image
|
||||
nsRefPtr<mozilla::layers::ImageContainer> container =
|
||||
mozilla::layers::LayerManager::CreateImageContainer();
|
||||
|
||||
nsRefPtr<mozilla::layers::Image> image =
|
||||
container->CreateImage(mozilla::ImageFormat::PLANAR_YCBCR);
|
||||
|
||||
int len = ((WIDTH * HEIGHT) * 3 / 2);
|
||||
mozilla::layers::PlanarYCbCrImage* planar =
|
||||
static_cast<mozilla::layers::PlanarYCbCrImage*>(image.get());
|
||||
uint8_t* frame = (uint8_t*) PR_Malloc(len);
|
||||
++gen->mCount;
|
||||
memset(frame, (gen->mCount / 8) & 0xff, len); // Rotating colors
|
||||
|
||||
const uint8_t lumaBpp = 8;
|
||||
const uint8_t chromaBpp = 4;
|
||||
|
||||
mozilla::layers::PlanarYCbCrData data;
|
||||
data.mYChannel = frame;
|
||||
data.mYSize = IntSize(WIDTH, HEIGHT);
|
||||
data.mYStride = (int32_t) (WIDTH * lumaBpp / 8.0);
|
||||
data.mCbCrStride = (int32_t) (WIDTH * chromaBpp / 8.0);
|
||||
data.mCbChannel = frame + HEIGHT * data.mYStride;
|
||||
data.mCrChannel = data.mCbChannel + HEIGHT * data.mCbCrStride / 2;
|
||||
data.mCbCrSize = IntSize(WIDTH / 2, HEIGHT / 2);
|
||||
data.mPicX = 0;
|
||||
data.mPicY = 0;
|
||||
data.mPicSize = IntSize(WIDTH, HEIGHT);
|
||||
data.mStereoMode = mozilla::StereoMode::MONO;
|
||||
|
||||
// SetData copies data, so we can free the frame
|
||||
planar->SetData(data);
|
||||
PR_Free(frame);
|
||||
|
||||
// AddTrack takes ownership of segment
|
||||
mozilla::VideoSegment *segment = new mozilla::VideoSegment();
|
||||
// 10 fps.
|
||||
segment->AppendFrame(image.forget(),
|
||||
gen->mStream->GetStream()->GraphRate() / 10,
|
||||
IntSize(WIDTH, HEIGHT));
|
||||
|
||||
gen->mStream->GetStream()->AsSourceStream()->AppendToTrack(1, segment);
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsRefPtr<DOMMediaStream> mStream;
|
||||
int mCount;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
class SourceStreamInfo {
|
||||
public:
|
||||
SourceStreamInfo(DOMMediaStream* aMediaStream,
|
||||
|
|
Загрузка…
Ссылка в новой задаче