Commit f9bc2f17 by Kim Jinsung

THETA SC2端末で、ライブカメラ映像が正常に表示されない問題対応。

再現率は100%ではないが、初回ライブ映像表示時に発生率が高い
parent d0820eb3
...@@ -357,6 +357,7 @@ public class HttpConnector { ...@@ -357,6 +357,7 @@ public class HttpConnector {
try { try {
//API2.0 //API2.0
if (mIsOldApi) { if (mIsOldApi) {
//画像ファイルの場合、「recordTime」がないのでJSONException発生
entry.getInt("recordTime"); entry.getInt("recordTime");
//動画ファイルは保存しない。 //動画ファイルは保存しない。
continue; continue;
......
...@@ -12,16 +12,28 @@ import android.view.SurfaceView; ...@@ -12,16 +12,28 @@ import android.view.SurfaceView;
import java.io.IOException; import java.io.IOException;
import jp.agentec.abook.abv.bl.common.log.Logger;
/** /**
* Motion JPEG view * Motion JPEG view
*/ */
public class MJpegView extends SurfaceView implements SurfaceHolder.Callback { public class MJpegView extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = "MJpegView";
private MJpegViewThread mMJpegViewThread = null; private MJpegViewThread mMJpegViewThread = null;
private MJpegInputStream mMJpegInputStream = null; private MJpegInputStream mMJpegInputStream = null;
private boolean existSurface = false; private boolean existSurface = false;
private int mDisplayWidth; private int mDisplayWidth;
private int mDisplayHeight; private int mDisplayHeight;
private MJpegView.LiveCameraListener mListener;
public interface LiveCameraListener {
void liveCameraPlayFail();
}
public void setLiveCameraListenerListener(MJpegView.LiveCameraListener listener) {
this.mListener = listener;
}
/** /**
* Constructor * Constructor
* @param context * @param context
...@@ -185,7 +197,6 @@ public class MJpegView extends SurfaceView implements SurfaceHolder.Callback { ...@@ -185,7 +197,6 @@ public class MJpegView extends SurfaceView implements SurfaceHolder.Callback {
Bitmap bitmap; Bitmap bitmap;
Rect bitmapRect; Rect bitmapRect;
Canvas bitmapCanvas = null; Canvas bitmapCanvas = null;
while (keepRunning) { while (keepRunning) {
if (existSurface) { if (existSurface) {
try { try {
...@@ -201,7 +212,9 @@ public class MJpegView extends SurfaceView implements SurfaceHolder.Callback { ...@@ -201,7 +212,9 @@ public class MJpegView extends SurfaceView implements SurfaceHolder.Callback {
} }
} catch (IOException e) { } catch (IOException e) {
e.getStackTrace(); e.getStackTrace();
Logger.e(TAG, "MJpegView IOException = " + e.toString());
keepRunning = false; keepRunning = false;
mListener.liveCameraPlayFail();
} }
} }
} finally { } finally {
...@@ -228,6 +241,7 @@ public class MJpegView extends SurfaceView implements SurfaceHolder.Callback { ...@@ -228,6 +241,7 @@ public class MJpegView extends SurfaceView implements SurfaceHolder.Callback {
mMJpegInputStream.close(); mMJpegInputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Logger.e(TAG, "mMJpegInputStream IOException = " + e.toString());
} }
} }
} }
......
...@@ -38,7 +38,9 @@ public class ThetaCameraActivity extends ThetaActivity { ...@@ -38,7 +38,9 @@ public class ThetaCameraActivity extends ThetaActivity {
private static final String TAG = "ThetaCameraActivity"; private static final String TAG = "ThetaCameraActivity";
//画面表示後、ライブビューア取得を0.5秒後に取得 //画面表示後、ライブビューア取得を0.5秒後に取得
private static final int LIVE_VIEW_START_DELAY = 500; private static final int LIVE_VIEW_START_DELAY = 500;
private static final int LIVE_VIEW_FAIL_START_DELAY = 1000;
private static final int EV_TEXT_VIEW_TEXT_SIZE_PHONE = 16; private static final int EV_TEXT_VIEW_TEXT_SIZE_PHONE = 16;
private static final int LIVE_VIDEO_FAIL_MAX_COUNT = 3;
private MJpegView mLiveView; private MJpegView mLiveView;
private ShowLiveViewTask mLivePreviewTask; private ShowLiveViewTask mLivePreviewTask;
private Button mShootBtn; private Button mShootBtn;
...@@ -46,6 +48,8 @@ public class ThetaCameraActivity extends ThetaActivity { ...@@ -46,6 +48,8 @@ public class ThetaCameraActivity extends ThetaActivity {
private TextView mExposureTextView; private TextView mExposureTextView;
private SeekBar mExposureSeekBar; private SeekBar mExposureSeekBar;
private int mCurrentSeekBarProgress; private int mCurrentSeekBarProgress;
private int mLiveViewFailCount;
private boolean mInitOnResumeFlg = false;
private static final List<String> mExposureValues = new ArrayList<>(Arrays.asList("-2.0", "-1.7", "-1.3", "-1.0", "-0.7", "-0.3", "0.0", "0.3", "0.7", "1.0", "1.3", "1.7", "2.0")); private static final List<String> mExposureValues = new ArrayList<>(Arrays.asList("-2.0", "-1.7", "-1.3", "-1.0", "-0.7", "-0.3", "0.0", "0.3", "0.7", "1.0", "1.3", "1.7", "2.0"));
@Override @Override
...@@ -78,6 +82,7 @@ public class ThetaCameraActivity extends ThetaActivity { ...@@ -78,6 +82,7 @@ public class ThetaCameraActivity extends ThetaActivity {
showProgressPopup(); showProgressPopup();
new ShootTask(ThetaCameraActivity.this).execute(); new ShootTask(ThetaCameraActivity.this).execute();
mLiveView.setSource(null); mLiveView.setSource(null);
mLiveViewFailCount = 0;
} }
}); });
...@@ -90,22 +95,54 @@ public class ThetaCameraActivity extends ThetaActivity { ...@@ -90,22 +95,54 @@ public class ThetaCameraActivity extends ThetaActivity {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClassName(getPackageName(), ThetaImageListActivity.class.getName()); intent.setClassName(getPackageName(), ThetaImageListActivity.class.getName());
startActivity(intent); startActivity(intent);
mLiveViewFailCount = 0;
} }
}); });
//露出シークバー //露出シークバー
settingSeekbar(); settingSeekbar();
showProgressPopup(); showProgressPopup();
startLiveCameraTask(false);
mLiveViewFailCount = 0;
mLiveView.setLiveCameraListenerListener(new MJpegView.LiveCameraListener() {
@Override
public void liveCameraPlayFail() {
mLiveViewFailCount++;
Logger.e(TAG,"mLiveViewFailCount = " + mLiveViewFailCount);
if (mLiveViewFailCount == LIVE_VIDEO_FAIL_MAX_COUNT) {
handler.post(new Runnable() {
@Override
public void run() {
mLiveView.setSource(null);
thetaConnectError(R.string.msg_theta_live_image_fail);
}
});
return;
}
startLiveCameraTask(true);
}
});
}
private void startLiveCameraTask(final boolean isFailRetry) {
int delayTime = LIVE_VIEW_START_DELAY;
if (isFailRetry) { //失敗時にはリトライを1秒後に行うように設定
delayTime = LIVE_VIEW_FAIL_START_DELAY;
}
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (isFailRetry) {
showProgressPopup();
}
if (mLivePreviewTask != null) {
mLivePreviewTask.cancel(true);
}
mLivePreviewTask = new ShowLiveViewTask(ThetaCameraActivity.this); mLivePreviewTask = new ShowLiveViewTask(ThetaCameraActivity.this);
mLivePreviewTask.execute(); mLivePreviewTask.execute();
} }
}, LIVE_VIEW_START_DELAY); }, delayTime);
} }
//端末の戻るボタン禁止 //端末の戻るボタン禁止
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) { public boolean dispatchKeyEvent(KeyEvent event) {
...@@ -121,19 +158,18 @@ public class ThetaCameraActivity extends ThetaActivity { ...@@ -121,19 +158,18 @@ public class ThetaCameraActivity extends ThetaActivity {
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
mLiveView.stopPlay(); mLiveView.setSource(null);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
mLiveView.play(); Logger.d(TAG, "super.onResume()");
if (mInitOnResumeFlg) { //初回呼ばれた時は実行しない。(初期表示時)
if (mLivePreviewTask != null) { showProgressPopup();
mLivePreviewTask.cancel(true); startLiveCameraTask(false);
mLivePreviewTask = new ShowLiveViewTask(this);
mLivePreviewTask.execute();
} }
mInitOnResumeFlg = true;
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
...@@ -189,8 +225,6 @@ public class ThetaCameraActivity extends ThetaActivity { ...@@ -189,8 +225,6 @@ public class ThetaCameraActivity extends ThetaActivity {
public void onStartTrackingTouch(SeekBar seekBar) {} public void onStartTrackingTouch(SeekBar seekBar) {}
}); });
} }
/** /**
...@@ -225,7 +259,7 @@ public class ThetaCameraActivity extends ThetaActivity { ...@@ -225,7 +259,7 @@ public class ThetaCameraActivity extends ThetaActivity {
mLiveView.setSource(mJpegInputStream); mLiveView.setSource(mJpegInputStream);
new GetOptionExposureTask(ThetaCameraActivity.this).execute(); new GetOptionExposureTask(ThetaCameraActivity.this).execute();
} else { } else {
Logger.e("failed to start live view"); Logger.e(TAG, "failed to start live view");
thetaConnectError(R.string.msg_theta_live_image_fail); thetaConnectError(R.string.msg_theta_live_image_fail);
} }
} }
......
...@@ -25,7 +25,7 @@ import jp.agentec.abook.abv.ui.viewer.activity.theta.ThetaCameraActivity; ...@@ -25,7 +25,7 @@ import jp.agentec.abook.abv.ui.viewer.activity.theta.ThetaCameraActivity;
*/ */
public class ShowLiveViewTask extends AsyncTask<Void, String, MJpegInputStream> { public class ShowLiveViewTask extends AsyncTask<Void, String, MJpegInputStream> {
private static final String TAG = "ShowLiveViewTask"; private static final String TAG = "ShowLiveViewTask";
private static final int FAIL_RETRAY_DELAY_MILLIS = 500; private static final int FAIL_RETRAY_DELAY_MILLIS = 1000;
private final WeakReference<ThetaCameraActivity> refActivity; private final WeakReference<ThetaCameraActivity> refActivity;
public ShowLiveViewTask(ThetaCameraActivity refActivity) { public ShowLiveViewTask(ThetaCameraActivity refActivity) {
...@@ -43,8 +43,20 @@ public class ShowLiveViewTask extends AsyncTask<Void, String, MJpegInputStream> ...@@ -43,8 +43,20 @@ public class ShowLiveViewTask extends AsyncTask<Void, String, MJpegInputStream>
HttpConnector camera = new HttpConnector(ABookValues.THETA_IP_ADDRESS, isOldApi); HttpConnector camera = new HttpConnector(ABookValues.THETA_IP_ADDRESS, isOldApi);
InputStream is = camera.getLivePreview(); InputStream is = camera.getLivePreview();
mjis = new MJpegInputStream(is); mjis = new MJpegInputStream(is);
//正常にライブ再生されるか確認
mjis.readMJpegFrame();
retryCount = MAX_RETRY_COUNT; retryCount = MAX_RETRY_COUNT;
} catch (IOException e) { } catch (IOException e) {
Logger.e(TAG,"doInBackground fail e = " + e.toString());
if (mjis != null) {
try {
mjis.close();
} catch (IOException ex) {
Logger.e(TAG, "doInBackground fail ex = " + ex.toString());
}
}
try { try {
Thread.sleep(FAIL_RETRAY_DELAY_MILLIS); Thread.sleep(FAIL_RETRAY_DELAY_MILLIS);
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment