summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/device
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-02-22 20:10:23 -0500
committerMatt A. Tobin <email@mattatobin.com>2020-02-22 20:10:23 -0500
commitbdad2357a1f0d2aca7f1106f3195d1fd929dc1d1 (patch)
tree2166aa86e8378b6973e9ebc95b748ad9c632abb1 /netwerk/protocol/device
parent881c1e5f180c537b003b891dce7d7f114800ff3e (diff)
downloadUXP-bdad2357a1f0d2aca7f1106f3195d1fd929dc1d1.tar
UXP-bdad2357a1f0d2aca7f1106f3195d1fd929dc1d1.tar.gz
UXP-bdad2357a1f0d2aca7f1106f3195d1fd929dc1d1.tar.lz
UXP-bdad2357a1f0d2aca7f1106f3195d1fd929dc1d1.tar.xz
UXP-bdad2357a1f0d2aca7f1106f3195d1fd929dc1d1.zip
Issue #1053 - Remove android support from netwerk
Diffstat (limited to 'netwerk/protocol/device')
-rw-r--r--netwerk/protocol/device/AndroidCaptureProvider.cpp301
-rw-r--r--netwerk/protocol/device/AndroidCaptureProvider.h68
-rw-r--r--netwerk/protocol/device/CameraStreamImpl.cpp114
-rw-r--r--netwerk/protocol/device/CameraStreamImpl.h71
-rw-r--r--netwerk/protocol/device/moz.build9
-rw-r--r--netwerk/protocol/device/nsDeviceChannel.cpp13
6 files changed, 0 insertions, 576 deletions
diff --git a/netwerk/protocol/device/AndroidCaptureProvider.cpp b/netwerk/protocol/device/AndroidCaptureProvider.cpp
deleted file mode 100644
index e69766085..000000000
--- a/netwerk/protocol/device/AndroidCaptureProvider.cpp
+++ /dev/null
@@ -1,301 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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 "base/basictypes.h"
-#include "AndroidCaptureProvider.h"
-#include "nsXULAppAPI.h"
-#include "nsStreamUtils.h"
-#include "nsThreadUtils.h"
-#include "nsMemory.h"
-#include "RawStructs.h"
-
-// The maximum number of frames we keep in our queue. Don't live in the past.
-#define MAX_FRAMES_QUEUED 10
-
-using namespace mozilla::net;
-
-NS_IMPL_ISUPPORTS(AndroidCameraInputStream, nsIInputStream, nsIAsyncInputStream)
-
-AndroidCameraInputStream::AndroidCameraInputStream() :
- mWidth(0), mHeight(0), mCamera(0), mHeaderSent(false), mClosed(true), mFrameSize(0),
- mMonitor("AndroidCamera.Monitor")
-{
- mAvailable = sizeof(RawVideoHeader);
- mFrameQueue = new nsDeque();
-}
-
-AndroidCameraInputStream::~AndroidCameraInputStream() {
- // clear the frame queue
- while (mFrameQueue->GetSize() > 0) {
- free(mFrameQueue->PopFront());
- }
- delete mFrameQueue;
-}
-
-NS_IMETHODIMP
-AndroidCameraInputStream::Init(nsACString& aContentType, nsCaptureParams* aParams)
-{
- if (!XRE_IsParentProcess())
- return NS_ERROR_NOT_IMPLEMENTED;
-
- mContentType = aContentType;
- mWidth = aParams->width;
- mHeight = aParams->height;
- mCamera = aParams->camera;
-
- CameraStreamImpl *impl = CameraStreamImpl::GetInstance(0);
- if (!impl)
- return NS_ERROR_OUT_OF_MEMORY;
- if (impl->Init(mContentType, mCamera, mWidth, mHeight, this)) {
- mWidth = impl->GetWidth();
- mHeight = impl->GetHeight();
- mClosed = false;
- }
- return NS_OK;
-}
-
-void AndroidCameraInputStream::ReceiveFrame(char* frame, uint32_t length) {
- {
- mozilla::ReentrantMonitorAutoEnter autoMonitor(mMonitor);
- if (mFrameQueue->GetSize() > MAX_FRAMES_QUEUED) {
- free(mFrameQueue->PopFront());
- mAvailable -= mFrameSize;
- }
- }
-
- mFrameSize = sizeof(RawPacketHeader) + length;
-
- char* fullFrame = (char*)moz_xmalloc(mFrameSize);
-
- if (!fullFrame)
- return;
-
- RawPacketHeader* header = (RawPacketHeader*) fullFrame;
- header->packetID = 0xFF;
- header->codecID = 0x595556; // "YUV"
-
- // we copy the Y plane, and de-interlace the CrCb
-
- uint32_t yFrameSize = mWidth * mHeight;
- uint32_t uvFrameSize = yFrameSize / 4;
-
- memcpy(fullFrame + sizeof(RawPacketHeader), frame, yFrameSize);
-
- char* uFrame = fullFrame + yFrameSize;
- char* vFrame = fullFrame + yFrameSize + uvFrameSize;
- char* yFrame = frame + yFrameSize;
- for (uint32_t i = 0; i < uvFrameSize; i++) {
- uFrame[i] = yFrame[2 * i + 1];
- vFrame[i] = yFrame[2 * i];
- }
-
- {
- mozilla::ReentrantMonitorAutoEnter autoMonitor(mMonitor);
- mAvailable += mFrameSize;
- mFrameQueue->Push((void*)fullFrame);
- }
-
- NotifyListeners();
-}
-
-NS_IMETHODIMP
-AndroidCameraInputStream::Available(uint64_t *aAvailable)
-{
- mozilla::ReentrantMonitorAutoEnter autoMonitor(mMonitor);
-
- *aAvailable = mAvailable;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP AndroidCameraInputStream::IsNonBlocking(bool *aNonBlock) {
- *aNonBlock = true;
- return NS_OK;
-}
-
-NS_IMETHODIMP AndroidCameraInputStream::Read(char *aBuffer, uint32_t aCount, uint32_t *aRead) {
- return ReadSegments(NS_CopySegmentToBuffer, aBuffer, aCount, aRead);
-}
-
-NS_IMETHODIMP AndroidCameraInputStream::ReadSegments(nsWriteSegmentFun aWriter, void *aClosure, uint32_t aCount, uint32_t *aRead) {
- *aRead = 0;
-
- nsresult rv;
-
- if (mAvailable == 0)
- return NS_BASE_STREAM_WOULD_BLOCK;
-
- if (aCount > mAvailable)
- aCount = mAvailable;
-
- if (!mHeaderSent) {
- CameraStreamImpl *impl = CameraStreamImpl::GetInstance(0);
- RawVideoHeader header;
- header.headerPacketID = 0;
- header.codecID = 0x595556; // "YUV"
- header.majorVersion = 0;
- header.minorVersion = 1;
- header.options = 1 | 1 << 1; // color, 4:2:2
-
- header.alphaChannelBpp = 0;
- header.lumaChannelBpp = 8;
- header.chromaChannelBpp = 4;
- header.colorspace = 1;
-
- header.frameWidth = mWidth;
- header.frameHeight = mHeight;
- header.aspectNumerator = 1;
- header.aspectDenominator = 1;
-
- header.framerateNumerator = impl->GetFps();
- header.framerateDenominator = 1;
-
- rv = aWriter(this, aClosure, (const char*)&header, 0, sizeof(RawVideoHeader), aRead);
-
- if (NS_FAILED(rv))
- return NS_OK;
-
- mHeaderSent = true;
- aCount -= sizeof(RawVideoHeader);
- mAvailable -= sizeof(RawVideoHeader);
- }
-
- {
- mozilla::ReentrantMonitorAutoEnter autoMonitor(mMonitor);
- while ((mAvailable > 0) && (aCount >= mFrameSize)) {
- uint32_t readThisTime = 0;
-
- char* frame = (char*)mFrameQueue->PopFront();
- rv = aWriter(this, aClosure, (const char*)frame, *aRead, mFrameSize, &readThisTime);
-
- if (readThisTime != mFrameSize) {
- mFrameQueue->PushFront((void*)frame);
- return NS_OK;
- }
-
- // RawReader does a copy when calling VideoData::Create()
- free(frame);
-
- if (NS_FAILED(rv))
- return NS_OK;
-
- aCount -= readThisTime;
- mAvailable -= readThisTime;
- *aRead += readThisTime;
- }
- }
- return NS_OK;
-}
-
-NS_IMETHODIMP AndroidCameraInputStream::Close() {
- return CloseWithStatus(NS_OK);
-}
-
-
-/**
- * must be called on the main (java) thread
- */
-void AndroidCameraInputStream::doClose() {
- NS_ASSERTION(!mClosed, "Camera is already closed");
-
- CameraStreamImpl *impl = CameraStreamImpl::GetInstance(0);
- impl->Close();
- mClosed = true;
-}
-
-
-void AndroidCameraInputStream::NotifyListeners() {
- mozilla::ReentrantMonitorAutoEnter autoMonitor(mMonitor);
-
- if (mCallback && (mAvailable > sizeof(RawVideoHeader))) {
- nsCOMPtr<nsIInputStreamCallback> callback;
- if (mCallbackTarget) {
- callback = NS_NewInputStreamReadyEvent(mCallback, mCallbackTarget);
- } else {
- callback = mCallback;
- }
-
- NS_ASSERTION(callback, "Shouldn't fail to make the callback!");
-
- // Null the callback first because OnInputStreamReady may reenter AsyncWait
- mCallback = nullptr;
- mCallbackTarget = nullptr;
-
- callback->OnInputStreamReady(this);
- }
-}
-
-NS_IMETHODIMP AndroidCameraInputStream::AsyncWait(nsIInputStreamCallback *aCallback, uint32_t aFlags, uint32_t aRequestedCount, nsIEventTarget *aTarget)
-{
- if (aFlags != 0)
- return NS_ERROR_NOT_IMPLEMENTED;
-
- if (mCallback || mCallbackTarget)
- return NS_ERROR_UNEXPECTED;
-
- mCallbackTarget = aTarget;
- mCallback = aCallback;
-
- // What we are being asked for may be present already
- NotifyListeners();
- return NS_OK;
-}
-
-
-NS_IMETHODIMP AndroidCameraInputStream::CloseWithStatus(nsresult status)
-{
- AndroidCameraInputStream::doClose();
- return NS_OK;
-}
-
-/**
- * AndroidCaptureProvider implementation
- */
-
-NS_IMPL_ISUPPORTS0(AndroidCaptureProvider)
-
-AndroidCaptureProvider* AndroidCaptureProvider::sInstance = nullptr;
-
-AndroidCaptureProvider::AndroidCaptureProvider() {
-}
-
-AndroidCaptureProvider::~AndroidCaptureProvider() {
- AndroidCaptureProvider::sInstance = nullptr;
-}
-
-nsresult AndroidCaptureProvider::Init(nsACString& aContentType,
- nsCaptureParams* aParams,
- nsIInputStream** aStream) {
-
- NS_ENSURE_ARG_POINTER(aParams);
-
- NS_ASSERTION(aParams->frameLimit == 0 || aParams->timeLimit == 0,
- "Cannot set both a frame limit and a time limit!");
-
- RefPtr<AndroidCameraInputStream> stream;
-
- if (aContentType.EqualsLiteral("video/x-raw-yuv")) {
- stream = new AndroidCameraInputStream();
- if (stream) {
- nsresult rv = stream->Init(aContentType, aParams);
- if (NS_FAILED(rv))
- return rv;
- }
- else
- return NS_ERROR_OUT_OF_MEMORY;
- } else {
- NS_NOTREACHED("Should not have asked Android for this type!");
- }
- stream.forget(aStream);
- return NS_OK;
-}
-
-already_AddRefed<AndroidCaptureProvider> GetAndroidCaptureProvider() {
- if (!AndroidCaptureProvider::sInstance) {
- AndroidCaptureProvider::sInstance = new AndroidCaptureProvider();
- }
- RefPtr<AndroidCaptureProvider> ret = AndroidCaptureProvider::sInstance;
- return ret.forget();
-}
diff --git a/netwerk/protocol/device/AndroidCaptureProvider.h b/netwerk/protocol/device/AndroidCaptureProvider.h
deleted file mode 100644
index dd99ea541..000000000
--- a/netwerk/protocol/device/AndroidCaptureProvider.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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 AndroidDeviceCaptureProvide_h_
-#define AndroidDeviceCaptureProvide_h_
-
-#include "nsDeviceCaptureProvider.h"
-#include "nsIAsyncInputStream.h"
-#include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
-#include "nsString.h"
-#include "mozilla/net/CameraStreamImpl.h"
-#include "nsIEventTarget.h"
-#include "nsDeque.h"
-#include "mozilla/ReentrantMonitor.h"
-
-class AndroidCaptureProvider final : public nsDeviceCaptureProvider {
- private:
- ~AndroidCaptureProvider();
-
- public:
- AndroidCaptureProvider();
-
- NS_DECL_THREADSAFE_ISUPPORTS
-
- MOZ_MUST_USE nsresult Init(nsACString& aContentType, nsCaptureParams* aParams, nsIInputStream** aStream) override;
- static AndroidCaptureProvider* sInstance;
-};
-
-class AndroidCameraInputStream final : public nsIAsyncInputStream, mozilla::net::CameraStreamImpl::FrameCallback {
- private:
- ~AndroidCameraInputStream();
-
- public:
- AndroidCameraInputStream();
-
- NS_IMETHODIMP Init(nsACString& aContentType, nsCaptureParams* aParams);
-
- NS_DECL_THREADSAFE_ISUPPORTS
- NS_DECL_NSIINPUTSTREAM
- NS_DECL_NSIASYNCINPUTSTREAM
-
- void ReceiveFrame(char* frame, uint32_t length) override;
-
- protected:
- void NotifyListeners();
- void doClose();
-
- uint32_t mAvailable;
- nsCString mContentType;
- uint32_t mWidth;
- uint32_t mHeight;
- uint32_t mCamera;
- bool mHeaderSent;
- bool mClosed;
- nsDeque *mFrameQueue;
- uint32_t mFrameSize;
- mozilla::ReentrantMonitor mMonitor;
-
- nsCOMPtr<nsIInputStreamCallback> mCallback;
- nsCOMPtr<nsIEventTarget> mCallbackTarget;
-};
-
-already_AddRefed<AndroidCaptureProvider> GetAndroidCaptureProvider();
-
-#endif
diff --git a/netwerk/protocol/device/CameraStreamImpl.cpp b/netwerk/protocol/device/CameraStreamImpl.cpp
deleted file mode 100644
index f4a2cf4a4..000000000
--- a/netwerk/protocol/device/CameraStreamImpl.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/* 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 "CameraStreamImpl.h"
-#include "GeneratedJNINatives.h"
-#include "nsCRTGlue.h"
-#include "nsThreadUtils.h"
-#include "nsXULAppAPI.h"
-#include "mozilla/Monitor.h"
-
-using namespace mozilla;
-
-namespace mozilla {
-namespace net {
-
-static CameraStreamImpl* mCamera0 = nullptr;
-static CameraStreamImpl* mCamera1 = nullptr;
-
-class CameraStreamImpl::Callback
- : public java::GeckoAppShell::CameraCallback::Natives<Callback>
-{
-public:
- static void OnFrameData(int32_t aCamera, jni::ByteArray::Param aData)
- {
- MOZ_ASSERT(NS_IsMainThread());
-
- CameraStreamImpl* impl = GetInstance(uint32_t(aCamera));
- if (impl) {
- impl->TransmitFrame(aData);
- }
- }
-};
-
-/**
- * CameraStreamImpl
- */
-
-void CameraStreamImpl::TransmitFrame(jni::ByteArray::Param aData) {
- if (!mCallback) {
- return;
- }
-
- JNIEnv* const env = jni::GetGeckoThreadEnv();
- const size_t length = size_t(env->GetArrayLength(aData.Get()));
-
- if (!length) {
- return;
- }
-
- jbyte* const data = env->GetByteArrayElements(aData.Get(), nullptr);
- mCallback->ReceiveFrame(reinterpret_cast<char*>(data), length);
- env->ReleaseByteArrayElements(aData.Get(), data, JNI_ABORT);
-}
-
-CameraStreamImpl* CameraStreamImpl::GetInstance(uint32_t aCamera) {
- CameraStreamImpl* res = nullptr;
- switch(aCamera) {
- case 0:
- if (mCamera0)
- res = mCamera0;
- else
- res = mCamera0 = new CameraStreamImpl(aCamera);
- break;
- case 1:
- if (mCamera1)
- res = mCamera1;
- else
- res = mCamera1 = new CameraStreamImpl(aCamera);
- break;
- }
- return res;
-}
-
-
-CameraStreamImpl::CameraStreamImpl(uint32_t aCamera) :
- mInit(false), mCamera(aCamera)
-{
- NS_WARNING("CameraStreamImpl::CameraStreamImpl()");
- mWidth = 0;
- mHeight = 0;
- mFps = 0;
-}
-
-CameraStreamImpl::~CameraStreamImpl()
-{
- NS_WARNING("CameraStreamImpl::~CameraStreamImpl()");
-}
-
-bool CameraStreamImpl::Init(const nsCString& contentType, const uint32_t& camera, const uint32_t& width, const uint32_t& height, FrameCallback* aCallback)
-{
- mCallback = aCallback;
- mWidth = width;
- mHeight = height;
-
- Callback::Init();
- jni::IntArray::LocalRef retArray = java::GeckoAppShell::InitCamera(
- contentType, int32_t(camera), int32_t(width), int32_t(height));
- nsTArray<int32_t> ret = retArray->GetElements();
-
- mWidth = uint32_t(ret[1]);
- mHeight = uint32_t(ret[2]);
- mFps = uint32_t(ret[3]);
-
- return !!ret[0];
-}
-
-void CameraStreamImpl::Close() {
- java::GeckoAppShell::CloseCamera();
- mCallback = nullptr;
-}
-
-} // namespace net
-} // namespace mozilla
diff --git a/netwerk/protocol/device/CameraStreamImpl.h b/netwerk/protocol/device/CameraStreamImpl.h
deleted file mode 100644
index 93037caf6..000000000
--- a/netwerk/protocol/device/CameraStreamImpl.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* 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 __CAMERASTREAMIMPL_H__
-#define __CAMERASTREAMIMPL_H__
-
-#include "mozilla/jni/Refs.h"
-
-#include "nsString.h"
-
-/**
- * This singleton class handles communication with the Android camera
- * through JNI. It is used by the IPDL parent or directly from the chrome process
- */
-
-namespace mozilla {
-namespace net {
-
-class CameraStreamImpl {
-public:
- class FrameCallback {
- public:
- virtual void ReceiveFrame(char* frame, uint32_t length) = 0;
- };
-
- /**
- * instance bound to a given camera
- */
- static CameraStreamImpl* GetInstance(uint32_t aCamera);
-
- bool initNeeded() {
- return !mInit;
- }
-
- FrameCallback* GetFrameCallback() {
- return mCallback;
- }
-
- MOZ_MUST_USE bool Init(const nsCString& contentType, const uint32_t& camera, const uint32_t& width, const uint32_t& height, FrameCallback* callback);
- void Close();
-
- uint32_t GetWidth() { return mWidth; }
- uint32_t GetHeight() { return mHeight; }
- uint32_t GetFps() { return mFps; }
-
- void takePicture(const nsAString& aFileName);
-
-private:
- class Callback;
-
- CameraStreamImpl(uint32_t aCamera);
- CameraStreamImpl(const CameraStreamImpl&);
- CameraStreamImpl& operator=(const CameraStreamImpl&);
-
- ~CameraStreamImpl();
-
- void TransmitFrame(jni::ByteArray::Param aData);
-
- bool mInit;
- uint32_t mCamera;
- uint32_t mWidth;
- uint32_t mHeight;
- uint32_t mFps;
- FrameCallback* mCallback;
-};
-
-} // namespace net
-} // namespace mozilla
-
-#endif
diff --git a/netwerk/protocol/device/moz.build b/netwerk/protocol/device/moz.build
index a18672220..3bb95930e 100644
--- a/netwerk/protocol/device/moz.build
+++ b/netwerk/protocol/device/moz.build
@@ -4,15 +4,6 @@
# 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['MOZ_WIDGET_TOOLKIT'] == 'android':
- EXPORTS.mozilla.net += [
- 'CameraStreamImpl.h',
- ]
- UNIFIED_SOURCES += [
- 'AndroidCaptureProvider.cpp',
- 'CameraStreamImpl.cpp',
- ]
-
UNIFIED_SOURCES += [
'nsDeviceChannel.cpp',
'nsDeviceProtocolHandler.cpp',
diff --git a/netwerk/protocol/device/nsDeviceChannel.cpp b/netwerk/protocol/device/nsDeviceChannel.cpp
index 6c5788a56..d8b6900e8 100644
--- a/netwerk/protocol/device/nsDeviceChannel.cpp
+++ b/netwerk/protocol/device/nsDeviceChannel.cpp
@@ -7,11 +7,6 @@
#include "nsDeviceChannel.h"
#include "nsDeviceCaptureProvider.h"
-#ifdef MOZ_WIDGET_ANDROID
-#include "mozilla/Preferences.h"
-#include "AndroidCaptureProvider.h"
-#endif
-
using namespace mozilla;
// Copied from image/decoders/icon/nsIconURI.cpp
@@ -112,9 +107,6 @@ nsDeviceChannel::OpenContentStream(bool aAsync,
extractAttributeValue(spec.get(), "camera=", buffer);
captureParams.camera = buffer.ToInteger(&err);
captureParams.bpp = 32;
-#ifdef MOZ_WIDGET_ANDROID
- capture = GetAndroidCaptureProvider();
-#endif
} else if (kNotFound != spec.Find(NS_LITERAL_CSTRING("type=video/x-raw-yuv"),
true,
0,
@@ -138,11 +130,6 @@ nsDeviceChannel::OpenContentStream(bool aAsync,
captureParams.bpp = 32;
captureParams.timeLimit = 0;
captureParams.frameLimit = 60000;
-#ifdef MOZ_WIDGET_ANDROID
- // only enable if "device.camera.enabled" is true.
- if (Preferences::GetBool("device.camera.enabled", false) == true)
- capture = GetAndroidCaptureProvider();
-#endif
} else {
return NS_ERROR_NOT_IMPLEMENTED;
}