diff --git a/app/build.gradle b/app/build.gradle index a6f02996..7f708e72 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,7 +56,7 @@ dependencies { implementation project(path: ':preferences') implementation project(':VideoCore') - //implementation 'com.github.Consti10:LiveVideo10ms:v1.2' + //implementation 'com.github.Consti10:LiveVideo10ms:v1.3' implementation project(':TelemetryCore') implementation project(':RenderingXCore') diff --git a/app/src/main/cpp/GLRenderer/GLRMono360.cpp b/app/src/main/cpp/GLRenderer/GLRMono360.cpp index 8b14dfd9..bb308fb6 100644 --- a/app/src/main/cpp/GLRenderer/GLRMono360.cpp +++ b/app/src/main/cpp/GLRenderer/GLRMono360.cpp @@ -21,10 +21,12 @@ void GLRMono360::onSurfaceCreated360(JNIEnv* env,jobject androidContext,jint vid mVideoRenderer=std::make_unique(mBasicGLPrograms->vc, nullptr,mSettingsVR.DEV_3D_VIDEO,mGLProgramSpherical.get()); } -void GLRMono360::onSurfaceChanged360(int width, int height) { +void GLRMono360::onSurfaceChanged360(int width, int height,float video360FOV) { + screenW=width; + screenH=height; GLRMono::onSurfaceChanged(width,height); const float displayRatio=(float) width/(float)height; - mMatricesM.calculateProjectionAndDefaultView360(40.0f,displayRatio); + mMatricesM.calculateProjectionAndDefaultView360(video360FOV,displayRatio); cpuFrameTimeVidOSD.reset(); } @@ -46,6 +48,7 @@ void GLRMono360::setHomeOrientation() { mMatricesM.setHomeOrientation360(gvr_api_.get()); } + //----------------------------------------------------JAVA bindings--------------------------------------------------------------- #define JNI_METHOD(return_type, method_name) \ @@ -74,8 +77,8 @@ JNI_METHOD(void, nativeOnSurfaceCreated) native(glRendererMono)->onSurfaceCreated360(env,androidContext,videoTexture); } JNI_METHOD(void, nativeOnSurfaceChanged) -(JNIEnv *env, jobject obj, jlong glRendererMono,jint w,jint h) { - native(glRendererMono)->onSurfaceChanged360(w, h); +(JNIEnv *env, jobject obj, jlong glRendererMono,jint w,jint h,jfloat video360FOV) { + native(glRendererMono)->onSurfaceChanged360(w, h,video360FOV); } JNI_METHOD(void, nativeOnDrawFrame) (JNIEnv *env, jobject obj, jlong glRendererMono) { diff --git a/app/src/main/cpp/GLRenderer/GLRMono360.h b/app/src/main/cpp/GLRenderer/GLRMono360.h index efdd9d94..fc5c6642 100644 --- a/app/src/main/cpp/GLRenderer/GLRMono360.h +++ b/app/src/main/cpp/GLRenderer/GLRMono360.h @@ -15,12 +15,13 @@ class GLRMono360 : private GLRMono{ explicit GLRMono360(JNIEnv* env,jobject androidContext,TelemetryReceiver& telemetryReceiver,gvr_context* gvr_context,bool renderOSD); public: void onSurfaceCreated360(JNIEnv * env,jobject obj,jint videoTexture); - void onSurfaceChanged360(int width, int height); + void onSurfaceChanged360(int width, int height,float video360FOV); //Draw the 360° video, optionally also the OSD as overlay void onDrawFrame360(); void setHomeOrientation(); private: const int renderOSD; + int screenW,screenH; std::unique_ptr mGLProgramSpherical=nullptr; std::unique_ptr mVideoRenderer= nullptr; std::unique_ptr gvr_api_; diff --git a/app/src/main/cpp/Other/MatricesManager.cpp b/app/src/main/cpp/Other/MatricesManager.cpp index 49b3ca23..4277b6c6 100644 --- a/app/src/main/cpp/Other/MatricesManager.cpp +++ b/app/src/main/cpp/Other/MatricesManager.cpp @@ -2,12 +2,13 @@ // Created by Constantin on 12.12.2017. // +#include #include "MatricesManager.h" #include "MatrixHelper.h" #include "SettingsVR.h" -//#define TAG "HeadTrackerExtended" -//#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) +constexpr auto TAG="HeadTrackerExtended"; +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) constexpr auto NANO_TO_MS=1000*1000; MatricesManager::MatricesManager(const SettingsVR& settingsVR): @@ -63,15 +64,23 @@ void MatricesManager::calculateNewHeadPose360(gvr::GvrApi *gvr_api, const int pr target_time.monotonic_system_time_nanos+=predictMS*NANO_TO_MS; gvr::Mat4f tmpHeadPose = gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time); //we only want rotation, screw the mirage solo tmpHeadPose = MatrixMul(worldMatrices.monoForward360, tmpHeadPose); - gvr_api->ApplyNeckModel(tmpHeadPose,1); + //gvr_api->ApplyNeckModel(tmpHeadPose,1); worldMatrices.monoViewTracked360=toGLM(tmpHeadPose); } void MatricesManager::setHomeOrientation360(gvr::GvrApi *gvr_api) { // Get the current start->head transformation gvr::Mat4f tmpHeadPose=gvr_api->GetHeadSpaceFromStartSpaceRotation(gvr::GvrApi::GetTimePointNow()); - gvr_api->ApplyNeckModel(tmpHeadPose,1); + //gvr_api->ApplyNeckModel(tmpHeadPose,1); We do not want to apply the neck model here,else the world shifts glm::mat4 headView=toGLM(tmpHeadPose); - worldMatrices.monoForward360*=headView; + headView=glm::toMat4(glm::quat_cast(headView)); + worldMatrices.monoForward360=worldMatrices.monoForward360*headView; + gvr_api->RecenterTracking(); } +/*if(TEST()){ + LOGD("SUCCESS"); + }else{ + LOGD("FAIL"); + }*/ +//Reset tracking resets the rotation around the y axis, leaving everything else untouched \ No newline at end of file diff --git a/app/src/main/cpp/Other/MatrixHelper.h b/app/src/main/cpp/Other/MatrixHelper.h index d89719ec..54202b4a 100644 --- a/app/src/main/cpp/Other/MatrixHelper.h +++ b/app/src/main/cpp/Other/MatrixHelper.h @@ -40,6 +40,30 @@ static gvr::Mat4f MatrixMul(const glm::mat4x4 &m1, const gvr::Mat4f &m2){ return toGVR(m1*m2AsGLM); } + +static bool TEST(){ + float aaa[16]; + for(int i=0;i<4;i++){ + for(int j=0;j<4;j++){ + int idx=i*4+j; + aaa[idx]=idx; + } + } + { + glm::mat4 glmMat=glm::make_mat4x4(aaa); + gvr::Mat4f gvrMat=toGVR(glmMat); + glm::mat4 glmMat2=toGLM(gvrMat); + if(glmMat != glmMat2) { + return false; + } + } + glm::mat4 glmMat=glm::make_mat4x4(aaa); + glm::mat4 glmMat2=glm::make_mat4x4(aaa); + glm::mat4 multiplyGLM=glmMat*glmMat2; + glm::mat4 multiplyGVR=toGLM(MatrixMul(glmMat,toGVR(glmMat2))); + return multiplyGLM==multiplyGVR; +} + //remove rotation around specific axes, but leaves //all other axes & translations intact //We can lock head tracking on specific axises. Therefore, we first calculate the inverse quaternion from the headView (rotation) matrix. diff --git a/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java b/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java index 0b355d6c..cd65533b 100644 --- a/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java +++ b/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java @@ -108,7 +108,7 @@ protected void onPause() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle("Options"); - getMenuInflater().inflate(R.menu.video_context_menu, menu); + getMenuInflater().inflate(R.menu.video360_context_menu, menu); } @Override diff --git a/app/src/main/java/constantin/fpv_vr/APlay/AStereoNormal.java b/app/src/main/java/constantin/fpv_vr/APlay/AStereoNormal.java index 35719157..cab83130 100644 --- a/app/src/main/java/constantin/fpv_vr/APlay/AStereoNormal.java +++ b/app/src/main/java/constantin/fpv_vr/APlay/AStereoNormal.java @@ -9,6 +9,10 @@ import android.opengl.GLSurfaceView; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; + +import android.view.ContextMenu; +import android.view.MenuItem; +import android.view.View; import android.view.WindowManager; import com.google.vr.ndk.base.GvrLayout; @@ -16,6 +20,7 @@ import constantin.fpv_vr.AirHeadTrackingSender; import constantin.fpv_vr.GLRenderer.GLRStereoNormal; +import constantin.fpv_vr.R; import constantin.fpv_vr.Settings.SJ; import constantin.fpv_vr.Toaster; import constantin.renderingX.MyEGLConfigChooser; @@ -65,6 +70,8 @@ public void run() { mGvrLayout.setPresentationView(mGLViewStereo); setContentView(mGvrLayout); airHeadTrackingSender=new AirHeadTrackingSender(this,mGvrLayout.getGvrApi()); + + registerForContextMenu(mGvrLayout); } @@ -106,5 +113,23 @@ protected void onDestroy(){ telemetryReceiver.delete(); } + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + menu.setHeaderTitle("Options"); + getMenuInflater().inflate(R.menu.videovr_context_menu, menu); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.option_reset_tracking: + mGvrLayout.getGvrApi().recenterTracking(); + return true; + default: + return super.onContextItemSelected(item); + } + } + } \ No newline at end of file diff --git a/app/src/main/java/constantin/fpv_vr/GLRenderer/GLRMono360.java b/app/src/main/java/constantin/fpv_vr/GLRenderer/GLRMono360.java index 9fc35913..ed3da16a 100644 --- a/app/src/main/java/constantin/fpv_vr/GLRenderer/GLRMono360.java +++ b/app/src/main/java/constantin/fpv_vr/GLRenderer/GLRMono360.java @@ -12,6 +12,7 @@ import javax.microedition.khronos.opengles.GL10; import constantin.fpv_vr.MVideoPlayer; +import constantin.fpv_vr.R; import constantin.telemetry.core.TelemetryReceiver; import constantin.video.core.DecodingInfo; import constantin.video.core.IVideoParamsChanged; @@ -27,7 +28,7 @@ public class GLRMono360 implements GLSurfaceView.Renderer, IVideoParamsChanged { private native long nativeConstruct(Context context,long telemetryReceiver,long nativeGvrContext,boolean renderOSD); private native void nativeDelete(long glRendererMonoP); private native void nativeOnSurfaceCreated(long glRendererP,int videoTexture,Context androidContext); - private native void nativeOnSurfaceChanged(long glRendererMonoP,int width,int height); + private native void nativeOnSurfaceChanged(long glRendererMonoP,int width,int height,float video360FOV); private native void nativeOnDrawFrame(long glRendererMonoP); private native void nativeSetHomeOrientation(long glRendererMonoP); @@ -35,9 +36,11 @@ public class GLRMono360 implements GLSurfaceView.Renderer, IVideoParamsChanged { private final Context mContext; private SurfaceTexture mSurfaceTexture; private MVideoPlayer mVideoPlayer; + private final TelemetryReceiver telemetryReceiver; public GLRMono360(final Context context, final TelemetryReceiver telemetryReceiver, GvrApi gvrApi,final boolean renderOSD){ mContext=context; + this.telemetryReceiver=telemetryReceiver; nativeGLRendererMono=nativeConstruct(context,telemetryReceiver.getNativeInstance(),gvrApi.getNativeGvrContext(),renderOSD); } @@ -52,7 +55,8 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) { @Override public void onSurfaceChanged(GL10 gl, int width, int height) { - nativeOnSurfaceChanged(nativeGLRendererMono,width,height); + final float video360FOV=mContext.getSharedPreferences("pref_video",Context.MODE_PRIVATE).getFloat(mContext.getString(R.string.VS_360_VIDEO_FOV),50); + nativeOnSurfaceChanged(nativeGLRendererMono,width,height,video360FOV); //MyEGLConfigChooser.setEglSurfaceAttrib(EGL14.EGL_RENDER_BUFFER,EGL14.EGL_SINGLE_BUFFER); } @@ -97,7 +101,10 @@ public void onVideoRatioChanged(int videoW, int videoH) { @Override public void onDecodingInfoChanged(DecodingInfo decodingInfo) { - + if(telemetryReceiver!=null){ + telemetryReceiver.setDecodingInfo(decodingInfo.currentFPS,decodingInfo.currentKiloBitsPerSecond,decodingInfo.avgParsingTime_ms,decodingInfo.avgWaitForInputBTime_ms, + decodingInfo.avgHWDecodingTime_ms); + } } public void setHomeOrientation(){ diff --git a/app/src/main/res/menu/video_context_menu.xml b/app/src/main/res/menu/video360_context_menu.xml similarity index 100% rename from app/src/main/res/menu/video_context_menu.xml rename to app/src/main/res/menu/video360_context_menu.xml diff --git a/app/src/main/res/menu/videovr_context_menu.xml b/app/src/main/res/menu/videovr_context_menu.xml new file mode 100644 index 00000000..8ff0ab03 --- /dev/null +++ b/app/src/main/res/menu/videovr_context_menu.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file