1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-11 16:49:52 +01:00
libtgvoip/os/android/VideoSourceAndroid.cpp

93 lines
2.4 KiB
C++
Raw Normal View History

//
// Created by Grishka on 12.08.2018.
//
#include "VideoSourceAndroid.h"
#include "JNIUtilities.h"
#include "../../logging.h"
2019-02-05 12:41:00 +01:00
#include "../../PrivateDefines.h"
using namespace tgvoip;
using namespace tgvoip::video;
extern JavaVM* sharedJVM;
2019-02-05 12:41:00 +01:00
std::vector<uint32_t> VideoSourceAndroid::availableEncoders;
2019-02-05 12:41:00 +01:00
VideoSourceAndroid::VideoSourceAndroid(jobject jobj) : javaObject(jobj){
jni::DoWithJNI([&](JNIEnv* env){
jclass cls=env->GetObjectClass(javaObject);
startMethod=env->GetMethodID(cls, "start", "()V");
stopMethod=env->GetMethodID(cls, "stop", "()V");
prepareEncoderMethod=env->GetMethodID(cls, "prepareEncoder", "(Ljava/lang/String;I)V");
requestKeyFrameMethod=env->GetMethodID(cls, "requestKeyFrame", "()V");
setBitrateMethod=env->GetMethodID(cls, "setBitrate", "(I)V");
2019-02-05 12:41:00 +01:00
});
}
VideoSourceAndroid::~VideoSourceAndroid(){
jni::DoWithJNI([this](JNIEnv* env){
env->DeleteGlobalRef(javaObject);
});
}
void VideoSourceAndroid::Start(){
2019-02-05 12:41:00 +01:00
jni::DoWithJNI([this](JNIEnv* env){
env->CallVoidMethod(javaObject, startMethod);
});
}
void VideoSourceAndroid::Stop(){
2019-02-05 12:41:00 +01:00
jni::DoWithJNI([this](JNIEnv* env){
env->CallVoidMethod(javaObject, stopMethod);
});
}
void VideoSourceAndroid::SendFrame(Buffer frame, uint32_t flags){
callback(frame, flags, rotation);
}
void VideoSourceAndroid::SetStreamParameters(std::vector<Buffer> csd, unsigned int width, unsigned int height){
LOGD("Video stream parameters: %d x %d", width, height);
this->width=width;
this->height=height;
this->csd=std::move(csd);
}
2019-02-05 12:41:00 +01:00
void VideoSourceAndroid::Reset(uint32_t codec, int maxResolution){
jni::DoWithJNI([&](JNIEnv* env){
std::string codecStr="";
switch(codec){
case CODEC_AVC:
codecStr="video/avc";
break;
case CODEC_HEVC:
codecStr="video/hevc";
break;
case CODEC_VP8:
codecStr="video/x-vnd.on2.vp8";
break;
case CODEC_VP9:
codecStr="video/x-vnd.on2.vp9";
break;
}
env->CallVoidMethod(javaObject, prepareEncoderMethod, env->NewStringUTF(codecStr.c_str()), maxResolution);
});
}
void VideoSourceAndroid::RequestKeyFrame(){
jni::DoWithJNI([this](JNIEnv* env){
env->CallVoidMethod(javaObject, requestKeyFrameMethod);
});
}
void VideoSourceAndroid::SetBitrate(uint32_t bitrate){
jni::DoWithJNI([&](JNIEnv* env){
env->CallVoidMethod(javaObject, setBitrateMethod, (jint)bitrate);
});
}
2019-04-24 18:36:32 +02:00
void VideoSourceAndroid::SetStreamPaused(bool paused){
streamStateCallback(paused);
}