Skip to content
Snippets Groups Projects
Commit eb571498 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

videomanager: catch exceptions

Change-Id: Ic4a90183ae7589d4ddf7dd196e54cd6e8cba02f3
parent d10e7a1e
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,8 @@ std::vector<uint8_t> workspace;
int rotAngle = 0;
AVBufferRef* rotMatrix = nullptr;
constexpr const char TAG[] = "videomanager.i";
extern JavaVM *gJavaVM;
void setRotation(int angle)
......@@ -88,7 +90,7 @@ void rotateNV21(uint8_t* yinput, uint8_t* uvinput, unsigned ystride, unsigned uv
return;
}
if (rotation % 90 != 0 || rotation < 0 || rotation > 270) {
__android_log_print(ANDROID_LOG_ERROR, "videomanager.i", "%u %u %d", width, height, rotation);
__android_log_print(ANDROID_LOG_ERROR, TAG, "%u %u %d", width, height, rotation);
return;
}
bool swap = rotation % 180 != 0;
......@@ -149,6 +151,7 @@ int AndroidFormatToAVFormat(int androidformat) {
JNIEXPORT void JNICALL Java_cx_ring_daemon_RingserviceJNI_captureVideoPacket(JNIEnv *jenv, jclass jcls, jobject buffer, jint size, jint offset, jboolean keyframe, jlong timestamp, jint rotation)
{
try {
auto frame = DRing::getNewFrame();
if (not frame)
return;
......@@ -172,6 +175,9 @@ JNIEXPORT void JNICALL Java_cx_ring_daemon_RingserviceJNI_captureVideoPacket(JNI
packet->pts = timestamp;
frame->setPacket(std::move(packet));
DRing::publishFrame();
} catch (const std::exception& e) {
__android_log_print(ANDROID_LOG_ERROR, TAG, "Exception capturing video packet: %s", e.what());
}
}
JNIEXPORT void JNICALL Java_cx_ring_daemon_RingserviceJNI_captureVideoFrame(JNIEnv *jenv, jclass jcls, jobject image, jint rotation)
......@@ -184,6 +190,7 @@ JNIEXPORT void JNICALL Java_cx_ring_daemon_RingserviceJNI_captureVideoFrame(JNIE
static jmethodID imageGetPlanes = jenv->GetMethodID(imageClass, "getPlanes", "()[Landroid/media/Image$Plane;");
static jmethodID imageClose = jenv->GetMethodID(imageClass, "close", "()V");
try {
auto frame = DRing::getNewFrame();
if (not frame) {
jenv->CallVoidMethod(image, imageClose);
......@@ -271,6 +278,9 @@ JNIEXPORT void JNICALL Java_cx_ring_daemon_RingserviceJNI_captureVideoFrame(JNIE
gJavaVM->DetachCurrentThread();
});
DRing::publishFrame();
} catch (const std::exception& e) {
__android_log_print(ANDROID_LOG_ERROR, TAG, "Exception capturing video frame: %s", e.what());
}
}
JNIEXPORT jlong JNICALL Java_cx_ring_daemon_RingserviceJNI_acquireNativeWindow(JNIEnv *jenv, jclass jcls, jobject javaSurface)
......@@ -309,14 +319,14 @@ void AndroidDisplayCb(ANativeWindow *window, std::unique_ptr<DRing::FrameBuffer>
}
}
else
__android_log_print(ANDROID_LOG_WARN, "videomanager.i", "Can't copy surface");
__android_log_print(ANDROID_LOG_WARN, TAG, "Can't copy surface");
ANativeWindow_unlockAndPost(window);
} else {
__android_log_print(ANDROID_LOG_WARN, "videomanager.i", "Can't lock surface");
__android_log_print(ANDROID_LOG_WARN, TAG, "Can't lock surface");
}
i = std::move(frame);
} catch (...) {
__android_log_print(ANDROID_LOG_WARN, "videomanager.i", "Can't copy frame: no window");
__android_log_print(ANDROID_LOG_WARN, TAG, "Can't copy frame: no window");
}
}
......@@ -329,7 +339,7 @@ std::unique_ptr<DRing::FrameBuffer> sinkTargetPullCallback(ANativeWindow *window
ret = std::move(windows.at(window));
}
if (not ret) {
__android_log_print(ANDROID_LOG_WARN, "videomanager.i", "Creating new video buffer of %zu kib", bytes/1024);
__android_log_print(ANDROID_LOG_WARN, TAG, "Creating new video buffer of %zu kib", bytes/1024);
ret.reset(new DRing::FrameBuffer());
}
ret->storage.resize(bytes);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment