1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-02 17:51:06 +01:00
libtgvoip/os/android/VideoRendererAndroid.cpp
Grishka b1a0b3d94a 2.3
- Nonblocking sockets
- Better ShittyInternetMode
- Fixed a bunch of bugs
- Probably added some new bugs too
2018-11-09 18:44:01 +03:00

45 lines
1.2 KiB
C++

//
// Created by Grishka on 12.08.2018.
//
#include "VideoRendererAndroid.h"
#include "JNIUtilities.h"
using namespace tgvoip;
using namespace tgvoip::video;
jmethodID VideoRendererAndroid::resetMethod=NULL;
jmethodID VideoRendererAndroid::decodeAndDisplayMethod=NULL;
VideoRendererAndroid::VideoRendererAndroid(jobject jobj){
this->jobj=jobj;
}
VideoRendererAndroid::~VideoRendererAndroid(){
jni::DoWithJNI([this](JNIEnv* env){
env->DeleteGlobalRef(jobj);
});
}
void VideoRendererAndroid::Reset(uint32_t codec, unsigned int width, unsigned int height, std::vector<Buffer> &csd){
jni::DoWithJNI([&](JNIEnv* env){
jobjectArray jcsd=NULL;
if(!csd.empty()){
jcsd=env->NewObjectArray((jsize)csd.size(), env->FindClass("[B"), NULL);
jsize i=0;
for(Buffer& b:csd){
env->SetObjectArrayElement(jcsd, i, jni::BufferToByteArray(env, b));
i++;
}
}
env->CallVoidMethod(jobj, resetMethod, (jint)codec, (jint)width, (jint)height, jcsd);
});
}
void VideoRendererAndroid::DecodeAndDisplay(Buffer &frame, uint32_t pts){
jni::DoWithJNI([&](JNIEnv* env){
jobject jbuf=env->NewDirectByteBuffer(*frame, frame.Length());
env->CallVoidMethod(jobj, decodeAndDisplayMethod, jbuf, (jint)frame.Length(), (jlong)pts);
});
}