netwerk/protocol/device/CameraStreamImpl.cpp

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial