How can I change state of the camera flash throgh JNI function? I am looking to be able to have ON/OFF state control, just like in Java CameraManager.setTorchMode(cameraId, state); method. I've tried to search for it in native camera API ,but no success. Here's what I have done so far:
#include <jni.h>
#include <assert.h>
#include <jni.h>
#include <pthread.h>
#include <android/native_window_jni.h>
#include <camera/NdkCameraDevice.h>
#include <camera/NdkCameraManager.h>
#include <android/asset_manager.h>
#include "messages-internal.h"
JNIEXPORT void JNICALL
Java_com_android_rxjava_flashlightflicker_MainActivity_flasher(JNIEnv *env, jobject instance) {
ACameraIdList *cameraIdList = NULL;
const char *selectedCameraId = NULL;
ACameraManager *cameraManager = ACameraManager_create();
camera_status_t camera_status = ACAMERA_OK;
camera_status = ACameraManager_getCameraIdList(cameraManager, &cameraIdList);
/// Camera status not ok
if (camera_status != ACAMERA_OK) {
LOGE("Camera is bad id: %d \n", camera_status);
return;
}
// There is no camera
if (cameraIdList->numCameras < 1 ) {
LOGE("Camera is not present on the device.");
return;
}
selectedCameraId = cameraIdList->cameraIds[0];
ACameraMetadata *cameraMetedata = NULL;
ACameraManager_getCameraCharacteristics(cameraManager, selectedCameraId, &cameraMetedata);
// ACaptureSessionOutput_create()
}
I also tried to look in asset manager but no success, can anybody experienced with NDK camera give me a hand with it?
Thanks in advance!
This method is only available in Java API. You could access it through JNI, but IMO it would be easier and safer to write a wrapper static method in Java and have this wrapper called from your C++ code.
Related
Im trying to create a program which will interrupt when I press the button. I have Atmega8 and I use Microchip studio for coding.
I checked the document about interrupts on atmega's website however I can't say I totally got it.
Here is my code:
#define F_CPU 1000000UL
#define IRQ1 INT0_vect
#define IRQ2 INT1_vect
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
void init()
{
DDRB=0b11111111;
PORTB=255;
_delay_ms(2000);
PORTB=0;
DDRD = 0b00000000;
GICR=0xc0;
MCUCR=0x08;
}
int main(void){
init();
volatile int mode = 0;
ISR(IRQ1){
_delay_ms(500);
if (mode<3)mode++; else mode = 0;
}
ISR(IRQ2){
_delay_ms(150);
}
}
Errors I get:
Imgur
I would be glad if any admin edits my question and add picture here, website doesn't let me add photo because I need at least 10 reputation to post image
Don't try to define functions inside of other functions unless you really know what you are doing. You should move the ISR definitions to the top level of the file, putting them outside of main.
I’m making a standalone ROOT application which should terminate upon closing a canvas. The following is my experimental code.
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
int main(){
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas *c1 =new TCanvas("c1","Canvas Test",800,800);
c1->Connect("TCanvas", "Closed()", "TApplication",gApplication, "Terminate()");
myapp->Run();
return 0;
}
The code compiles without any warnings. The canvas opens when I run it. But when I close the the canvas, application doesn’t terminate and the terminal doesn’t prompt. Any suggestions ?
_ROOT Version: 6.20
_Platform: Ubuntu 20.04
_Compiler: g++
Thanks to #bellenot from root-forum for providing the following solution. Apparently, for ROOT 6 & above, This should be done with a TRootCanvas object.
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
int main()
{
TApplication *myapp = new TApplication("myapp", 0, 0);
TCanvas *c1 = new TCanvas("c1","Canvas Test",800,800);
TRootCanvas *rc = (TRootCanvas *)c1->GetCanvasImp();
rc->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
myapp->Run();
return 0;
}
I have C++/CLI console application that uses direct sound. I am unsure if directsound is a problem or not, but after Windows 10 update application hangs before even launching. To reproduce this problem please create C++/CLI console application, link it against dsound.lib and copy paste this code into main file. You will notice that it unhangs as soon as DirectSoundEnumerate is commented.
#include "stdafx.h"
#include <vector>
#include <Windows.h>
#include <dsound.h>
using namespace System;
using namespace System::Collections::Generic;
static BOOL CALLBACK DSEnumOutputProc(LPGUID lpGUID,
LPCWSTR lpszDesc,
LPCWSTR lpszDrvName,
LPVOID lpContext)
{
return(TRUE);
}
void EnumerateDirectSoundDevices()
{
if (SUCCEEDED(DirectSoundEnumerate(&DSEnumOutputProc, LPVOID(NULL))))
{
printf("output devices enumerated.\n");
}
}
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
I am creating a QR code scanner program in C++ using the library called libdecodeqr.
I downloaded all the files from https://github.com/josephholsten/libdecodeqr and I modified one of the test programs. However, I keep getting the error "unresolved external symbol". It's because I have not linked the libraries.
But I can't find libdecodeqr.lib anywhere! It's not included in the GitHub package and it's nowhere online!
In the instructions on the GitHub page, it says to add decodeqr.h, qrtypes.h, qrerror.h and libdecodeqr.lib to my environment. Other than the .lib file, I have added all those files to my environment.
Where can I find libdecodeqr.lib?
Also, here is the sample program I modified and am testing:
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "C:/Users/Asish/Documents/libdecodeqr-master/libdecodeqr/decodeqr.h"
#include "C:/Users/Asish/Documents/libdecodeqr-master/libdecodeqr/qrerror.h"
#include "C:/Users/Asish/Documents/libdecodeqr-master/libdecodeqr/qrtypes.h"
#include "bitstream.h"
using namespace cv;
int main(int argc, char *argv[])
{
namedWindow("src", 1);
//
// load image
//
Mat src_old = imread("qrTest.png", 1);
IplImage* src = new IplImage(src_old);
imshow("src", src_old);
//
// show version info
//
printf("libdecodeqr version %s\n", qr_decoder_version());
//
// initialize
//
QrDecoderHandle decoder = qr_decoder_open();
//
// do decode using default parameter
//
short stat = qr_decoder_decode_image(decoder, src);
printf("STATUS=%04x\n", stat);
//
// get QR code header
//
QrCodeHeader header;
if (qr_decoder_get_header(decoder, &header)){
//
// get QR code text
// To null terminate, a buffer size is larger than body size.
//
char *buf = new char[header.byte_size + 1];
qr_decoder_get_body(decoder, (unsigned char *)buf, header.byte_size + 1);
printf("%s\n", buf);
}
//
// finalize
//
qr_decoder_close(decoder);
puts("");
puts("Hit any key to end.");
cvWaitKey(0);
destroyAllWindows();
cvReleaseImage(&src);
return(0);
}
You are downloading the source code from GitHub, which means that you also need to create a new VisualStudio C++ project to compile your own libdecodeqr.lib (or dll). This will require you also install OpenCV in your computer.
Good morning !
I have recently read articles quite interesting about hooking functions, I have followed one or two tutorials but it never seems to work, I am using Detoured and here is the full code which seems to me perfectly normal :(
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include "detours.h"
#pragma comment(lib, "detours.lib")
int(__stdcall* realFunc)(int) = (int(__stdcall*)(int))(0x004157B0);
void hookedFunc(int num)
{
printf("Test : %d\n", num + 100);
}
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DetourAttach((PVOID*)(&realFunc), (PVOID)hookedFunc);
break;
case DLL_THREAD_ATTACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)(&realFunc), (PVOID)hookedFunc);
DetourTransactionCommit();
hookedFunc(100);
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
DetourDetach((PVOID*)0x004157B0, hookedFunc);
break;
}
return TRUE;
}
When using RemoteDLL and a simple console application as dummy to hook the function, all steps are completed successfully (running as administrator), the memory address to the function I want to be hooked matches, however the code line "printf("Test : %d\n", num + 100);" is not executed, the result does not appears at screen...
If anyone would have an idea about what's going on I would be really happy to hear it !
Thanks in advance !
First, hookedFunc must have the same signature: int __stdcall hookedFunc(int x).
I suppose the following effect of your code: hookedFunc is called each time somebody calls the function at address 0x004157B0. Is it what you expect?
For testing, you call this address. Let me change the code a little to clarify:
extern int __stdcall FunctionIWantToHook(int);
int(__stdcall* realFunc)(int) = FunctionIWantToHook;
...
DetourAttach((PVOID*)(&realFunc), (PVOID)hookedFunc);
FunctionIWantToHook(100); // hookedFunc will be called here