Bug 1101651 - Part 1, xpcomrt version of dom media library need for standalone webrtcs. r=jesup

Enable WebRTC unit tests to be built using standalone WebRTC library Includes VideoSegment and SimpleImageBuffer.
This commit is contained in:
Randall Barker 2015-04-02 12:14:15 -07:00
parent 65ae1a9380
commit 96ef4da6bd
8 changed files with 175 additions and 0 deletions

View File

@ -199,12 +199,14 @@ AudioSegment::WriteTo(uint64_t aID, AudioMixer& aMixer, uint32_t aOutputChannels
offset += frames * aOutputChannels;
#if !defined(MOZILLA_XPCOMRT_API)
if (!c.mTimeStamp.IsNull()) {
TimeStamp now = TimeStamp::Now();
// would be more efficient to c.mTimeStamp to ms on create time then pass here
LogTime(AsyncLatencyLogger::AudioMediaStreamTrack, aID,
(now - c.mTimeStamp).ToMilliseconds(), c.mTimeStamp);
}
#endif // !defined(MOZILLA_XPCOMRT_API)
}
if (offset) {

View File

@ -198,7 +198,10 @@ public:
MOZ_ASSERT(channels == segmentChannelCount);
output.SetLength(channels);
bufferPtrs.SetLength(channels);
#if !defined(MOZILLA_XPCOMRT_API)
// FIXME Bug 1126414 - XPCOMRT does not support dom::WebAudioUtils::SpeexResamplerProcess
uint32_t inFrames = c.mDuration;
#endif // !defined(MOZILLA_XPCOMRT_API)
// Round up to allocate; the last frame may not be used.
NS_ASSERTION((UINT32_MAX - aInRate + 1) / c.mDuration >= aOutRate,
"Dropping samples");
@ -208,10 +211,13 @@ public:
T* out = output[i].AppendElements(outSize);
uint32_t outFrames = outSize;
#if !defined(MOZILLA_XPCOMRT_API)
// FIXME Bug 1126414 - XPCOMRT does not support dom::WebAudioUtils::SpeexResamplerProcess
dom::WebAudioUtils::SpeexResamplerProcess(aResampler, i,
in, &inFrames,
out, &outFrames);
MOZ_ASSERT(inFrames == c.mDuration);
#endif // !defined(MOZILLA_XPCOMRT_API)
bufferPtrs[i] = out;
output[i].SetLength(outFrames);
}

View File

@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 sts=4 ci et: */
/* 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 "SimpleImageBuffer.h"
#include "mozilla/NullPtr.h"
namespace mozilla {
void
SimpleImageBuffer::SetImage(const unsigned char* frame, unsigned int size, int width, int height)
{
mWidth = width;
mHeight = height;
if (!mBuffer || (size > mBufferSize)) {
if (mBuffer) {
delete[] mBuffer;
mBuffer = nullptr;
}
mBufferSize = size;
if (size > 0) {
mBuffer = new unsigned char[size];
}
}
if (mBuffer) {
if (frame && (size > 0)) {
memcpy((void *)mBuffer, (const void*)frame, size);
}
mSize = size;
}
}
void
SimpleImageBuffer::Copy(const SimpleImageBuffer* aImage)
{
if (aImage) {
SetImage(aImage->mBuffer, aImage->mSize, aImage->mWidth, aImage->mHeight);
}
}
const unsigned char*
SimpleImageBuffer::GetImage(unsigned int* size) const
{
if (size) {
*size = mSize;
}
return mBuffer;
}
} // namespace mozilla

View File

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 sts=4 ci et: */
/* 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/. */
#ifndef simple_image_buffer_h
#define simple_image_buffer_h
#include "mozilla/NullPtr.h"
#include "nsISupportsImpl.h"
namespace mozilla {
class SimpleImageBuffer {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SimpleImageBuffer)
public:
SimpleImageBuffer() : mBuffer(nullptr), mBufferSize(0), mSize(0), mWidth(0), mHeight(0) {}
void SetImage(const unsigned char* frame, unsigned int size, int width, int height);
void Copy(const SimpleImageBuffer* aImage);
const unsigned char* GetImage(unsigned int* size) const;
void GetWidthAndHeight(int* width, int* height) const
{
if (width) {
*width = mWidth;
}
if (height) {
*height = mHeight;
}
}
protected:
~SimpleImageBuffer()
{
delete[] mBuffer;
}
const unsigned char* mBuffer;
unsigned int mBufferSize;
unsigned int mSize;
int mWidth;
int mHeight;
private:
SimpleImageBuffer(const SimpleImageBuffer& aImage);
SimpleImageBuffer& operator=(const SimpleImageBuffer& aImage);
};
} // namespace mozilla
#endif // simple_image_buffer_h

View File

@ -39,6 +39,7 @@ VideoFrame::TakeFrom(VideoFrame* aFrame)
mForceBlack = aFrame->GetForceBlack();
}
#if !defined(MOZILLA_XPCOMRT_API)
/* static */ already_AddRefed<Image>
VideoFrame::CreateBlackImage(const gfxIntSize& aSize)
{
@ -83,6 +84,7 @@ VideoFrame::CreateBlackImage(const gfxIntSize& aSize)
return image.forget();
}
#endif // !defined(MOZILLA_XPCOMRT_API)
VideoChunk::VideoChunk()
{}

View File

@ -10,7 +10,11 @@
#include "nsCOMPtr.h"
#include "gfxPoint.h"
#include "nsAutoPtr.h"
#if defined(MOZILLA_XPCOMRT_API)
#include "SimpleImageBuffer.h"
#else
#include "ImageContainer.h"
#endif
namespace mozilla {
@ -20,7 +24,11 @@ class Image;
class VideoFrame {
public:
#if defined(MOZILLA_XPCOMRT_API)
typedef mozilla::SimpleImageBuffer Image;
#else
typedef mozilla::layers::Image Image;
#endif
VideoFrame(already_AddRefed<Image>& aImage, const gfxIntSize& aIntrinsicSize);
VideoFrame();
@ -44,8 +52,10 @@ public:
void SetNull();
void TakeFrom(VideoFrame* aFrame);
#if !defined(MOZILLA_XPCOMRT_API)
// Create a planar YCbCr black image.
static already_AddRefed<Image> CreateBlackImage(const gfxIntSize& aSize);
#endif // !defined(MOZILLA_XPCOMRT_API)
protected:
// mImage can be null to indicate "no video" (aka "empty frame"). It can
@ -93,7 +103,11 @@ struct VideoChunk {
class VideoSegment : public MediaSegmentBase<VideoSegment, VideoChunk> {
public:
#if defined(MOZILLA_XPCOMRT_API)
typedef mozilla::SimpleImageBuffer Image;
#else
typedef mozilla::layers::Image Image;
#endif
typedef mozilla::gfx::IntSize IntSize;
VideoSegment();

View File

@ -16,6 +16,7 @@ DIRS += [
'webrtc',
'webspeech',
'webvtt',
'standalone',
]
if CONFIG['MOZ_RAW']:

View File

@ -0,0 +1,47 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
if CONFIG['OS_TARGET'] != 'WINNT' and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
Library('media_standalone')
UNIFIED_SOURCES += [
'../AudioChannelFormat.cpp',
'../AudioSegment.cpp',
'../SimpleImageBuffer.cpp',
'../VideoSegment.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
UNIFIED_SOURCES += ['../systemservices/OSXRunLoopSingleton.cpp']
MSVC_ENABLE_PGO = True
LOCAL_INCLUDES += [
'/caps',
'/dom/base',
'/dom/camera',
'/layout/generic',
'/layout/xul',
'/netwerk/base',
]
if CONFIG['MOZ_WEBRTC']:
LOCAL_INCLUDES += [
'/media/webrtc/signaling/src/common',
'/media/webrtc/trunk',
]
DEFINES['MOZILLA_INTERNAL_API'] = True
DEFINES['MOZILLA_XPCOMRT_API'] = True
DEFINES['MOZILLA_EXTERNAL_LINKAGE'] = True
include('/ipc/chromium/chromium-config.mozbuild')
# Suppress some GCC warnings being treated as errors:
# - about attributes on forward declarations for types that are already
# defined, which complains about an important MOZ_EXPORT for android::AString
if CONFIG['GNU_CC']:
CXXFLAGS += ['-Wno-error=attributes']