IMSDroid視頻橫屏顯示

集成了IMSdroid 視頻通話後,發現雙人視頻顯示爲橫屏,很納悶,仔細查看代碼,發現做了橫豎屏切換的重力感應監聽,就是可以發送任意的角度視頻。如下:

if (mIsVideoCall) {
			mListener = new OrientationEventListener(this,
					SensorManager.SENSOR_DELAY_NORMAL) {
				@Override
				public void onOrientationChanged(int orient) {
					try {
						if ((orient > 345 || orient < 15)
								|| (orient > 75 && orient < 105)
								|| (orient > 165 && orient < 195)
								|| (orient > 255 && orient < 285)) {
							int rotation = mAVSession.compensCamRotation(true);
							if (rotation != mLastRotation) {
								Log.d(ScreenAV.TAG,
										"Received Screen Orientation Change setRotation["
												+ String.valueOf(rotation)
												+ "]");
								applyCamRotation(rotation);
								if (mSendDeviceInfo && mAVSession != null) {
									final android.content.res.Configuration conf = getResources()
											.getConfiguration();
									if (conf.orientation != mLastOrientation) {
										mLastOrientation = conf.orientation;
										switch (mLastOrientation) {
										case android.content.res.Configuration.ORIENTATION_LANDSCAPE:
											mAVSession
													.sendInfo(
															"orientation:landscape\r\nlang:fr-FR\r\n",
															NgnContentType.DOUBANGO_DEVICE_INFO);
											break;
										case android.content.res.Configuration.ORIENTATION_PORTRAIT:
											mAVSession
													.sendInfo(
															"orientation:portrait\r\nlang:fr-FR\r\n",
															NgnContentType.DOUBANGO_DEVICE_INFO);
											break;
										}
									}
								}
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			};
			if (!mListener.canDetectOrientation()) {
				Log.w(TAG, "canDetectOrientation() is equal to false");
			}
		}

通過分析,雙方接收到的視頻顯示爲橫屏,應該是對方發送過來的就爲橫屏,但是我手機設置成豎屏顯示了,不可能會進入到橫豎屏切換的監聽器內部,通過查看視頻預覽產生類org.doubango.ngn.media.NgnProxyVideoProducer,觀察到裏面有個方法:

public int compensCamRotation(boolean preview){
		if(mVideoProducer != null){
			return mVideoProducer.compensCamRotation(preview);
		}
		return 0;
	}
	
	public int camRotation(boolean preview){
		if(mVideoProducer != null){
			return mVideoProducer.getNativeCameraHardRotation(preview);
		}
		return 0;
	}
顯而易見,應該就是這裏處理沒錯!再深入代碼查看:

public int compensCamRotation(boolean preview){

		final int cameraHardRotation = getNativeCameraHardRotation(preview);
		final android.content.res.Configuration conf = NgnApplication.getContext().getResources().getConfiguration();
		if(conf.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE){
			return 0;
		}

		if (NgnApplication.getSDKVersion() >= 9) {
			if (preview) {
				return cameraHardRotation;
			}
			else{
				switch (cameraHardRotation) {
					case 0:
					case 180:
					default:
						return 0;
					case 90:
					case 270:
						return 90;
				}
			}			
		}
		else {
			int     terminalRotation   = getTerminalRotation();
			int rotation = 0;
			rotation = (terminalRotation-cameraHardRotation) % 360;
			return rotation;
		}
	}

所以,我這邊在進入Incall狀態後,通過調用:

applyCamRotation(mAVSession.compensCamRotation(true));// 保持視頻豎屏(其實用平板的話是會自動橫屏顯示的)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章