michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "CameraStreamImpl.h" michael@0: #include "nsCRTGlue.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "nsXULAppAPI.h" michael@0: #include "mozilla/Monitor.h" michael@0: michael@0: /** michael@0: * JNI part & helper runnable michael@0: */ michael@0: michael@0: extern "C" { michael@0: NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_cameraCallbackBridge(JNIEnv *, jclass, jbyteArray data); michael@0: } michael@0: michael@0: NS_EXPORT void JNICALL michael@0: Java_org_mozilla_gecko_GeckoAppShell_cameraCallbackBridge(JNIEnv *env, jclass, jbyteArray data) { michael@0: mozilla::net::CameraStreamImpl* impl = mozilla::net::CameraStreamImpl::GetInstance(0); michael@0: michael@0: impl->transmitFrame(env, &data); michael@0: } michael@0: michael@0: using namespace mozilla; michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: static CameraStreamImpl* mCamera0 = nullptr; michael@0: static CameraStreamImpl* mCamera1 = nullptr; michael@0: michael@0: /** michael@0: * CameraStreamImpl michael@0: */ michael@0: michael@0: void CameraStreamImpl::transmitFrame(JNIEnv *env, jbyteArray *data) { michael@0: if (!mCallback) michael@0: return; michael@0: jboolean isCopy; michael@0: jbyte* jFrame = env->GetByteArrayElements(*data, &isCopy); michael@0: uint32_t length = env->GetArrayLength(*data); michael@0: if (length > 0) { michael@0: mCallback->ReceiveFrame((char*)jFrame, length); michael@0: } michael@0: env->ReleaseByteArrayElements(*data, jFrame, 0); michael@0: } michael@0: michael@0: CameraStreamImpl* CameraStreamImpl::GetInstance(uint32_t aCamera) { michael@0: CameraStreamImpl* res = nullptr; michael@0: switch(aCamera) { michael@0: case 0: michael@0: if (mCamera0) michael@0: res = mCamera0; michael@0: else michael@0: res = mCamera0 = new CameraStreamImpl(aCamera); michael@0: break; michael@0: case 1: michael@0: if (mCamera1) michael@0: res = mCamera1; michael@0: else michael@0: res = mCamera1 = new CameraStreamImpl(aCamera); michael@0: break; michael@0: } michael@0: return res; michael@0: } michael@0: michael@0: michael@0: CameraStreamImpl::CameraStreamImpl(uint32_t aCamera) : michael@0: mInit(false), mCamera(aCamera) michael@0: { michael@0: NS_WARNING("CameraStreamImpl::CameraStreamImpl()"); michael@0: mWidth = 0; michael@0: mHeight = 0; michael@0: mFps = 0; michael@0: } michael@0: michael@0: CameraStreamImpl::~CameraStreamImpl() michael@0: { michael@0: NS_WARNING("CameraStreamImpl::~CameraStreamImpl()"); michael@0: } michael@0: michael@0: bool CameraStreamImpl::Init(const nsCString& contentType, const uint32_t& camera, const uint32_t& width, const uint32_t& height, FrameCallback* aCallback) michael@0: { michael@0: mCallback = aCallback; michael@0: mWidth = width; michael@0: mHeight = height; michael@0: return AndroidBridge::Bridge()->InitCamera(contentType, camera, &mWidth, &mHeight, &mFps); michael@0: } michael@0: michael@0: void CameraStreamImpl::Close() { michael@0: mozilla::widget::android::GeckoAppShell::CloseCamera(); michael@0: mCallback = nullptr; michael@0: } michael@0: michael@0: } // namespace net michael@0: } // namespace mozilla