Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "CameraStreamImpl.h" |
michael@0 | 6 | #include "nsCRTGlue.h" |
michael@0 | 7 | #include "nsThreadUtils.h" |
michael@0 | 8 | #include "nsXULAppAPI.h" |
michael@0 | 9 | #include "mozilla/Monitor.h" |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * JNI part & helper runnable |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | extern "C" { |
michael@0 | 16 | NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_cameraCallbackBridge(JNIEnv *, jclass, jbyteArray data); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | NS_EXPORT void JNICALL |
michael@0 | 20 | Java_org_mozilla_gecko_GeckoAppShell_cameraCallbackBridge(JNIEnv *env, jclass, jbyteArray data) { |
michael@0 | 21 | mozilla::net::CameraStreamImpl* impl = mozilla::net::CameraStreamImpl::GetInstance(0); |
michael@0 | 22 | |
michael@0 | 23 | impl->transmitFrame(env, &data); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | using namespace mozilla; |
michael@0 | 27 | |
michael@0 | 28 | namespace mozilla { |
michael@0 | 29 | namespace net { |
michael@0 | 30 | |
michael@0 | 31 | static CameraStreamImpl* mCamera0 = nullptr; |
michael@0 | 32 | static CameraStreamImpl* mCamera1 = nullptr; |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * CameraStreamImpl |
michael@0 | 36 | */ |
michael@0 | 37 | |
michael@0 | 38 | void CameraStreamImpl::transmitFrame(JNIEnv *env, jbyteArray *data) { |
michael@0 | 39 | if (!mCallback) |
michael@0 | 40 | return; |
michael@0 | 41 | jboolean isCopy; |
michael@0 | 42 | jbyte* jFrame = env->GetByteArrayElements(*data, &isCopy); |
michael@0 | 43 | uint32_t length = env->GetArrayLength(*data); |
michael@0 | 44 | if (length > 0) { |
michael@0 | 45 | mCallback->ReceiveFrame((char*)jFrame, length); |
michael@0 | 46 | } |
michael@0 | 47 | env->ReleaseByteArrayElements(*data, jFrame, 0); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | CameraStreamImpl* CameraStreamImpl::GetInstance(uint32_t aCamera) { |
michael@0 | 51 | CameraStreamImpl* res = nullptr; |
michael@0 | 52 | switch(aCamera) { |
michael@0 | 53 | case 0: |
michael@0 | 54 | if (mCamera0) |
michael@0 | 55 | res = mCamera0; |
michael@0 | 56 | else |
michael@0 | 57 | res = mCamera0 = new CameraStreamImpl(aCamera); |
michael@0 | 58 | break; |
michael@0 | 59 | case 1: |
michael@0 | 60 | if (mCamera1) |
michael@0 | 61 | res = mCamera1; |
michael@0 | 62 | else |
michael@0 | 63 | res = mCamera1 = new CameraStreamImpl(aCamera); |
michael@0 | 64 | break; |
michael@0 | 65 | } |
michael@0 | 66 | return res; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | CameraStreamImpl::CameraStreamImpl(uint32_t aCamera) : |
michael@0 | 71 | mInit(false), mCamera(aCamera) |
michael@0 | 72 | { |
michael@0 | 73 | NS_WARNING("CameraStreamImpl::CameraStreamImpl()"); |
michael@0 | 74 | mWidth = 0; |
michael@0 | 75 | mHeight = 0; |
michael@0 | 76 | mFps = 0; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | CameraStreamImpl::~CameraStreamImpl() |
michael@0 | 80 | { |
michael@0 | 81 | NS_WARNING("CameraStreamImpl::~CameraStreamImpl()"); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | bool CameraStreamImpl::Init(const nsCString& contentType, const uint32_t& camera, const uint32_t& width, const uint32_t& height, FrameCallback* aCallback) |
michael@0 | 85 | { |
michael@0 | 86 | mCallback = aCallback; |
michael@0 | 87 | mWidth = width; |
michael@0 | 88 | mHeight = height; |
michael@0 | 89 | return AndroidBridge::Bridge()->InitCamera(contentType, camera, &mWidth, &mHeight, &mFps); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | void CameraStreamImpl::Close() { |
michael@0 | 93 | mozilla::widget::android::GeckoAppShell::CloseCamera(); |
michael@0 | 94 | mCallback = nullptr; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | } // namespace net |
michael@0 | 98 | } // namespace mozilla |