| 6 |
| #include "JNIUtilities.h" |
| 7 | #include "../../logging.h" |
| 8 | #include "../../PrivateDefines.h" |
| 9 |
| 10 | using namespace tgvoip; |
| 11 | using namespace tgvoip::video; |
| 12 |
| 13 | extern JavaVM* sharedJVM; |
| 14 |
| 15 | std::vector<uint32_t> VideoSourceAndroid::availableEncoders; |
| 16 |
| 17 | VideoSourceAndroid::VideoSourceAndroid(jobject jobj) : javaObject(jobj){ |
| 18 | jni::DoWithJNI([&](JNIEnv* env){ |
| 19 | jclass cls=env->GetObjectClass(javaObject); |
| 20 | startMethod=env->GetMethodID(cls, "start", "()V"); |
| 21 | stopMethod=env->GetMethodID(cls, "stop", "()V"); |
| 22 | prepareEncoderMethod=env->GetMethodID(cls, "prepareEncoder", "(Ljava/lang/String;I)V"); |
| 23 | requestKeyFrameMethod=env->GetMethodID(cls, "requestKeyFrame", "()V"); |
| 24 | setBitrateMethod=env->GetMethodID(cls, "setBitrate", "(I)V"); |
| 25 | }); |
| 26 | } |
| 27 |
| 28 | VideoSourceAndroid::~VideoSourceAndroid(){ |
| 29 | jni::DoWithJNI([this](JNIEnv* env){ |
| 30 | env->DeleteGlobalRef(javaObject); |
| 31 | }); |
| 32 | } |
| 33 |
| 34 | void VideoSourceAndroid::Start(){ |
| 35 | jni::DoWithJNI([this](JNIEnv* env){ |
| 36 | env->CallVoidMethod(javaObject, startMethod); |
| 37 | }); |
| 38 | } |
| 39 |
| 40 | void VideoSourceAndroid::Stop(){ |
| 41 | jni::DoWithJNI([this](JNIEnv* env){ |
| 42 | env->CallVoidMethod(javaObject, stopMethod); |
| 43 | }); |
| 44 | } |
| 45 |
| 46 | void VideoSourceAndroid::SendFrame(Buffer frame, uint32_t flags){ |
| 47 | callback(frame, flags, rotation); |
| 48 | } |
| 49 |
| 50 | void VideoSourceAndroid::SetStreamParameters(std::vector<Buffer> csd, unsigned int width, unsigned int height){ |
| 51 | LOGD("Video stream parameters: %d x %d", width, height); |
| 52 | this->width=width; |
| 53 | this->height=height; |
| 54 | this->csd=std::move(csd); |
| 55 | } |
| 56 |
| 57 | void VideoSourceAndroid::Reset(uint32_t codec, int maxResolution){ |
| 58 | jni::DoWithJNI([&](JNIEnv* env){ |
| 59 | std::string codecStr=""; |
| 60 | switch(codec){ |
| 61 | case CODEC_AVC: |
| 62 | codecStr="video/avc"; |
| 63 | break; |
| 64 | case CODEC_HEVC: |
| 65 | codecStr="video/hevc"; |
| 66 | break; |
| 67 | case CODEC_VP8: |
| 68 | codecStr="video/x-vnd.on2.vp8"; |
| 69 | break; |
| 70 | case CODEC_VP9: |
| 71 | codecStr="video/x-vnd.on2.vp9"; |
| 72 | break; |
| 73 | } |
| 74 | env->CallVoidMethod(javaObject, prepareEncoderMethod, env->NewStringUTF(codecStr.c_str()), maxResolution); |
| 75 | }); |
| 76 | } |
| 77 |
| 78 | void VideoSourceAndroid::RequestKeyFrame(){ |
| 79 | jni::DoWithJNI([this](JNIEnv* env){ |
| 80 | env->CallVoidMethod(javaObject, requestKeyFrameMethod); |
| 81 | }); |
| 82 | } |
| 83 |
| 84 | void VideoSourceAndroid::SetBitrate(uint32_t bitrate){ |
| 85 | jni::DoWithJNI([&](JNIEnv* env){ |
| 86 | env->CallVoidMethod(javaObject, setBitrateMethod, (jint)bitrate); |
| 87 | }); |
| 88 | } |
| 89 |