1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/device/CameraStreamImpl.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "CameraStreamImpl.h" 1.9 +#include "nsCRTGlue.h" 1.10 +#include "nsThreadUtils.h" 1.11 +#include "nsXULAppAPI.h" 1.12 +#include "mozilla/Monitor.h" 1.13 + 1.14 +/** 1.15 + * JNI part & helper runnable 1.16 + */ 1.17 + 1.18 +extern "C" { 1.19 + NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_cameraCallbackBridge(JNIEnv *, jclass, jbyteArray data); 1.20 +} 1.21 + 1.22 +NS_EXPORT void JNICALL 1.23 +Java_org_mozilla_gecko_GeckoAppShell_cameraCallbackBridge(JNIEnv *env, jclass, jbyteArray data) { 1.24 + mozilla::net::CameraStreamImpl* impl = mozilla::net::CameraStreamImpl::GetInstance(0); 1.25 + 1.26 + impl->transmitFrame(env, &data); 1.27 +} 1.28 + 1.29 +using namespace mozilla; 1.30 + 1.31 +namespace mozilla { 1.32 +namespace net { 1.33 + 1.34 +static CameraStreamImpl* mCamera0 = nullptr; 1.35 +static CameraStreamImpl* mCamera1 = nullptr; 1.36 + 1.37 +/** 1.38 + * CameraStreamImpl 1.39 + */ 1.40 + 1.41 +void CameraStreamImpl::transmitFrame(JNIEnv *env, jbyteArray *data) { 1.42 + if (!mCallback) 1.43 + return; 1.44 + jboolean isCopy; 1.45 + jbyte* jFrame = env->GetByteArrayElements(*data, &isCopy); 1.46 + uint32_t length = env->GetArrayLength(*data); 1.47 + if (length > 0) { 1.48 + mCallback->ReceiveFrame((char*)jFrame, length); 1.49 + } 1.50 + env->ReleaseByteArrayElements(*data, jFrame, 0); 1.51 +} 1.52 + 1.53 +CameraStreamImpl* CameraStreamImpl::GetInstance(uint32_t aCamera) { 1.54 + CameraStreamImpl* res = nullptr; 1.55 + switch(aCamera) { 1.56 + case 0: 1.57 + if (mCamera0) 1.58 + res = mCamera0; 1.59 + else 1.60 + res = mCamera0 = new CameraStreamImpl(aCamera); 1.61 + break; 1.62 + case 1: 1.63 + if (mCamera1) 1.64 + res = mCamera1; 1.65 + else 1.66 + res = mCamera1 = new CameraStreamImpl(aCamera); 1.67 + break; 1.68 + } 1.69 + return res; 1.70 +} 1.71 + 1.72 + 1.73 +CameraStreamImpl::CameraStreamImpl(uint32_t aCamera) : 1.74 + mInit(false), mCamera(aCamera) 1.75 +{ 1.76 + NS_WARNING("CameraStreamImpl::CameraStreamImpl()"); 1.77 + mWidth = 0; 1.78 + mHeight = 0; 1.79 + mFps = 0; 1.80 +} 1.81 + 1.82 +CameraStreamImpl::~CameraStreamImpl() 1.83 +{ 1.84 + NS_WARNING("CameraStreamImpl::~CameraStreamImpl()"); 1.85 +} 1.86 + 1.87 +bool CameraStreamImpl::Init(const nsCString& contentType, const uint32_t& camera, const uint32_t& width, const uint32_t& height, FrameCallback* aCallback) 1.88 +{ 1.89 + mCallback = aCallback; 1.90 + mWidth = width; 1.91 + mHeight = height; 1.92 + return AndroidBridge::Bridge()->InitCamera(contentType, camera, &mWidth, &mHeight, &mFps); 1.93 +} 1.94 + 1.95 +void CameraStreamImpl::Close() { 1.96 + mozilla::widget::android::GeckoAppShell::CloseCamera(); 1.97 + mCallback = nullptr; 1.98 +} 1.99 + 1.100 +} // namespace net 1.101 +} // namespace mozilla