/**
  * Releases the resources associated with the camera source, the associated detectors, and the
  * rest of the processing pipeline.
  */
 @Override
 protected void onDestroy() {
   super.onDestroy();
   if (mPreview != null) {
     mPreview.release();
   }
 }
 /** Stops the camera. */
 @Override
 protected void onPause() {
   super.onPause();
   if (mPreview != null) {
     mPreview.stop();
   }
 }
  /**
   * Starts or restarts the camera source, if it exists. If the camera source doesn't exist yet
   * (e.g., because onResume was called before the camera source was created), this will be called
   * again when the camera source is created.
   */
  private void startCameraSource() throws SecurityException {
    // check that the device has play services available.
    int code =
        GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext());
    if (code != ConnectionResult.SUCCESS) {
      Dialog dlg = GoogleApiAvailability.getInstance().getErrorDialog(this, code, RC_HANDLE_GMS);
      dlg.show();
    }

    if (mCameraSource != null) {
      try {
        mPreview.start(mCameraSource, mGraphicOverlay);
      } catch (IOException e) {
        Log.e(TAG, "Unable to start camera source.", e);
        mCameraSource.release();
        mCameraSource = null;
      }
    }
  }