2018-11-09 16:44:01 +01:00
|
|
|
//
|
|
|
|
// 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"
|
2018-11-09 16:44:01 +01:00
|
|
|
|
|
|
|
using namespace tgvoip;
|
|
|
|
using namespace tgvoip::video;
|
|
|
|
|
|
|
|
extern JavaVM* sharedJVM;
|
|
|
|
|
2019-02-05 12:41:00 +01:00
|
|
|
std::vector<uint32_t> VideoSourceAndroid::availableEncoders;
|
2018-11-09 16:44:01 +01:00
|
|
|
|
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");
|
2019-03-10 23:12:09 +01:00
|
|
|
setBitrateMethod=env->GetMethodID(cls, "setBitrate", "(I)V");
|
2019-02-05 12:41:00 +01:00
|
|
|
});
|
2018-11-09 16:44:01 +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);
|
|
|
|
});
|
2018-11-09 16:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoSourceAndroid::Stop(){
|
2019-02-05 12:41:00 +01:00
|
|
|
jni::DoWithJNI([this](JNIEnv* env){
|
|
|
|
env->CallVoidMethod(javaObject, stopMethod);
|
|
|
|
});
|
2018-11-09 16:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoSourceAndroid::SendFrame(Buffer frame, uint32_t flags){
|
2019-04-15 01:43:10 +02:00
|
|
|
callback(frame, flags, rotation);
|
2018-11-09 16:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2019-03-10 23:12:09 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|