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