Commit f9bc2f17 by Kim Jinsung

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

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