summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEino-Ville Talvala <etalvala@google.com>2011-11-15 11:08:38 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-11-15 11:08:38 -0800
commitf30e0fcdd498713b82f8ad0922baa4a8f030dcd9 (patch)
treeda9f1e44aa72f5d0343f34039fa220072d8dc3ce /src
parentf3a22b8ec6f172831606598663dead220f76957b (diff)
parentd628e27f561c4bedf0d457f64270fc12740b5280 (diff)
downloadLegacyCamera-f30e0fcdd498713b82f8ad0922baa4a8f030dcd9.zip
LegacyCamera-f30e0fcdd498713b82f8ad0922baa4a8f030dcd9.tar.gz
LegacyCamera-f30e0fcdd498713b82f8ad0922baa4a8f030dcd9.tar.bz2
Merge "Switch sound playing to use Camera.playSound()" into ics-mr1
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Camera.java9
-rw-r--r--src/com/android/camera/EffectsRecorder.java32
-rw-r--r--src/com/android/camera/FocusManager.java21
-rw-r--r--src/com/android/camera/SoundPlayer.java122
-rwxr-xr-xsrc/com/android/camera/panorama/PanoramaActivity.java42
5 files changed, 15 insertions, 211 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 0da0095..f0c1f30 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -380,7 +380,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
mFocusManager.initialize(mFocusAreaIndicator, mPreviewFrame, mFaceView, this,
mirror, mDisplayOrientation);
- mFocusManager.initializeSoundPlayer(getResources().openRawResourceFd(R.raw.camera_focus));
mImageSaver = new ImageSaver();
Util.initializeScreenBrightness(getWindow(), getContentResolver());
installIntentFilter();
@@ -440,7 +439,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
mLocationManager.recordLocation(recordLocation);
installIntentFilter();
- mFocusManager.initializeSoundPlayer(getResources().openRawResourceFd(R.raw.camera_focus));
mImageSaver = new ImageSaver();
initializeZoom();
keepMediaProviderInstance();
@@ -1058,6 +1056,11 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
setCameraParameters(UPDATE_PARAM_PREFERENCE);
}
+ @Override
+ public void playSound(int soundId) {
+ mCameraDevice.playSound(soundId);
+ }
+
private boolean saveDataToFile(String filePath, byte[] data) {
FileOutputStream f = null;
try {
@@ -1588,8 +1591,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
if (mLocationManager != null) mLocationManager.recordLocation(false);
updateExposureOnScreenIndicator(0);
- mFocusManager.releaseSoundPlayer();
-
if (mStorageHint != null) {
mStorageHint.cancel();
mStorageHint = null;
diff --git a/src/com/android/camera/EffectsRecorder.java b/src/com/android/camera/EffectsRecorder.java
index 737e828..ea7ce39 100644
--- a/src/com/android/camera/EffectsRecorder.java
+++ b/src/com/android/camera/EffectsRecorder.java
@@ -34,11 +34,9 @@ import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.media.MediaRecorder;
import android.media.CamcorderProfile;
-import android.os.ConditionVariable;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
-import android.os.SystemProperties;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
@@ -108,9 +106,6 @@ public class EffectsRecorder {
private SurfaceTexture mTextureSource;
- private static final String mVideoRecordSound = "/system/media/audio/ui/VideoRecord.ogg";
- private SoundPlayer mRecordSound;
-
private static final int STATE_CONFIGURE = 0;
private static final int STATE_WAITING_FOR_SURFACE = 1;
private static final int STATE_STARTING_PREVIEW = 2;
@@ -140,28 +135,6 @@ public class EffectsRecorder {
if (mLogVerbose) Log.v(TAG, "EffectsRecorder created (" + this + ")");
mContext = context;
mHandler = new Handler(Looper.getMainLooper());
-
- // Construct sound player; use enforced sound output if necessary
- File recordSoundFile = new File(mVideoRecordSound);
- try {
- ParcelFileDescriptor recordSoundParcel =
- ParcelFileDescriptor.open(recordSoundFile,
- ParcelFileDescriptor.MODE_READ_ONLY);
- AssetFileDescriptor recordSoundAsset =
- new AssetFileDescriptor(recordSoundParcel, 0,
- AssetFileDescriptor.UNKNOWN_LENGTH);
- if (SystemProperties.get("ro.camera.sound.forced", "0").equals("0")) {
- if (mLogVerbose) Log.v(TAG, "Standard recording sound");
- mRecordSound = new SoundPlayer(recordSoundAsset, false);
- } else {
- if (mLogVerbose) Log.v(TAG, "Forced recording sound");
- mRecordSound = new SoundPlayer(recordSoundAsset, true);
- }
- } catch (java.io.FileNotFoundException e) {
- Log.e(TAG, "System video record sound not found");
- mRecordSound = null;
- }
-
}
public void setCamera(Camera cameraDevice) {
@@ -713,7 +686,7 @@ public class EffectsRecorder {
recorder.setInputValue("maxFileSize", mMaxFileSize);
recorder.setInputValue("maxDurationMs", mMaxDurationMs);
recorder.setInputValue("recording", true);
- if (mRecordSound != null) mRecordSound.play();
+ mCameraDevice.playSound(Camera.Sound.START_VIDEO_RECORDING);
mState = STATE_RECORD;
}
@@ -733,7 +706,7 @@ public class EffectsRecorder {
}
Filter recorder = mRunner.getGraph().getFilter("recorder");
recorder.setInputValue("recording", false);
- if (mRecordSound != null) mRecordSound.play();
+ mCameraDevice.playSound(Camera.Sound.STOP_VIDEO_RECORDING);
mState = STATE_PREVIEW;
}
@@ -865,7 +838,6 @@ public class EffectsRecorder {
stopPreview();
// Fall-through
default:
- mRecordSound.release();
mState = STATE_RELEASED;
break;
}
diff --git a/src/com/android/camera/FocusManager.java b/src/com/android/camera/FocusManager.java
index 76a8737..8c3f14d 100644
--- a/src/com/android/camera/FocusManager.java
+++ b/src/com/android/camera/FocusManager.java
@@ -26,6 +26,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.hardware.Camera.Area;
import android.hardware.Camera.Parameters;
+import android.hardware.Camera.Sound;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
@@ -59,7 +60,6 @@ public class FocusManager {
private boolean mLockAeAwbNeeded;
private boolean mAeAwbLock;
private Matrix mMatrix;
- private SoundPlayer mSoundPlayer;
private View mFocusIndicatorRotateLayout;
private FocusIndicatorView mFocusIndicator;
private View mPreviewFrame;
@@ -81,6 +81,7 @@ public class FocusManager {
public void startFaceDetection();
public void stopFaceDetection();
public void setFocusParameters();
+ public void playSound(int soundId);
}
private class MainHandler extends Handler {
@@ -221,9 +222,9 @@ public class FocusManager {
// Do not play the sound in continuous autofocus mode. It does
// not do a full scan. The focus callback arrives before doSnap
// so the state is always STATE_FOCUSING.
- if (!Parameters.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mFocusMode)
- && mSoundPlayer != null) {
- mSoundPlayer.play();
+ if (!Parameters.FOCUS_MODE_CONTINUOUS_PICTURE.
+ equals(mFocusMode)) {
+ mListener.playSound(Sound.FOCUS_COMPLETE);
}
} else {
mState = STATE_FAIL;
@@ -346,18 +347,6 @@ public class FocusManager {
}
}
- public void initializeSoundPlayer(AssetFileDescriptor fd) {
- mSoundPlayer = new SoundPlayer(fd);
- }
-
- public void releaseSoundPlayer() {
- if (mSoundPlayer != null) {
- mSoundPlayer.release();
- mSoundPlayer = null;
- }
- }
-
-
// This can only be called after mParameters is initialized.
public String getFocusMode() {
if (mOverrideFocusMode != null) return mOverrideFocusMode;
diff --git a/src/com/android/camera/SoundPlayer.java b/src/com/android/camera/SoundPlayer.java
deleted file mode 100644
index a3acb44..0000000
--- a/src/com/android/camera/SoundPlayer.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.camera;
-
-import android.content.res.AssetFileDescriptor;
-import android.media.AudioManager;
-import android.media.MediaPlayer;
-import android.util.Log;
-
-import java.io.IOException;
-
-/**
- * Plays an AssetFileDescriptor, but does all the hard work on another thread so
- * that any slowness with preparing or loading doesn't block the calling thread.
- */
-public class SoundPlayer implements Runnable {
- private static final String TAG = "SoundPlayer";
- private Thread mThread;
- private MediaPlayer mPlayer;
- private int mPlayCount = 0;
- private boolean mExit;
- private AssetFileDescriptor mAfd;
- private int mAudioStreamType;
-
- @Override
- public void run() {
- while(true) {
- try {
- if (mPlayer == null) {
- MediaPlayer player = new MediaPlayer();
- player.setAudioStreamType(mAudioStreamType);
- player.setDataSource(mAfd.getFileDescriptor(), mAfd.getStartOffset(),
- mAfd.getLength());
- player.setLooping(false);
- player.prepare();
- mPlayer = player;
- mAfd.close();
- mAfd = null;
- }
- synchronized (this) {
- while(true) {
- if (mExit) {
- return;
- } else if (mPlayCount <= 0) {
- wait();
- } else {
- mPlayCount--;
- break;
- }
- }
- }
- mPlayer.start();
- } catch (Exception e) {
- Log.e(TAG, "Error playing sound", e);
- }
- }
- }
-
- public SoundPlayer(AssetFileDescriptor afd) {
- mAfd = afd;
- mAudioStreamType = AudioManager.STREAM_MUSIC;
- }
-
- public SoundPlayer(AssetFileDescriptor afd, boolean enforceAudible) {
- mAfd = afd;
- if (enforceAudible) {
- mAudioStreamType = 7; // AudioManager.STREAM_SYSTEM_ENFORCED; currently hidden API.
- } else {
- mAudioStreamType = AudioManager.STREAM_MUSIC;
- }
- }
-
- public void play() {
- if (mThread == null) {
- mThread = new Thread(this);
- mThread.start();
- }
- synchronized (this) {
- mPlayCount++;
- notifyAll();
- }
- }
-
- public void release() {
- if (mThread != null) {
- synchronized (this) {
- mExit = true;
- notifyAll();
- }
- try {
- mThread.join();
- } catch (InterruptedException e) {
- }
- mThread = null;
- }
- if (mAfd != null) {
- try {
- mAfd.close();
- } catch(IOException e) {
- }
- mAfd = null;
- }
- if (mPlayer != null) {
- mPlayer.release();
- mPlayer = null;
- }
- }
-}
diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java
index fe70827..e4c8d98 100755
--- a/src/com/android/camera/panorama/PanoramaActivity.java
+++ b/src/com/android/camera/panorama/PanoramaActivity.java
@@ -27,7 +27,6 @@ import com.android.camera.OnClickAttr;
import com.android.camera.R;
import com.android.camera.RotateDialogController;
import com.android.camera.ShutterButton;
-import com.android.camera.SoundPlayer;
import com.android.camera.Storage;
import com.android.camera.Thumbnail;
import com.android.camera.Util;
@@ -50,6 +49,7 @@ import android.graphics.SurfaceTexture;
import android.graphics.YuvImage;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
+import android.hardware.Camera.Sound;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.Uri;
@@ -57,7 +57,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelFileDescriptor;
-import android.os.SystemProperties;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
@@ -104,8 +103,6 @@ public class PanoramaActivity extends ActivityBase implements
// Ratio of nanosecond to second
private static final float NS2S = 1.0f / 1000000000.0f;
- private static final String VIDEO_RECORD_SOUND = "/system/media/audio/ui/VideoRecord.ogg";
-
private boolean mPausing;
private View mPanoLayout;
@@ -167,8 +164,6 @@ public class PanoramaActivity extends ActivityBase implements
private float[] mTransformMatrix;
private float mHorizontalViewAngle;
- private SoundPlayer mRecordSound;
-
// Prefer FOCUS_MODE_INFINITY to FOCUS_MODE_CONTINUOUS_VIDEO because of
// getting a better image quality by the former.
private String mTargetFocusMode = Parameters.FOCUS_MODE_INFINITY;
@@ -730,11 +725,11 @@ public class PanoramaActivity extends ActivityBase implements
// right now.
switch (mCaptureState) {
case CAPTURE_STATE_VIEWFINDER:
- if (mRecordSound != null) mRecordSound.play();
+ mCameraDevice.playSound(Sound.START_VIDEO_RECORDING);
startCapture();
break;
case CAPTURE_STATE_MOSAIC:
- if (mRecordSound != null) mRecordSound.play();
+ mCameraDevice.playSound(Sound.STOP_VIDEO_RECORDING);
stopCapture(false);
}
}
@@ -917,34 +912,6 @@ public class PanoramaActivity extends ActivityBase implements
mMosaicFrameProcessor.initialize();
}
- private void initSoundRecorder() {
- // Construct sound player; use enforced sound output if necessary
- File recordSoundFile = new File(VIDEO_RECORD_SOUND);
- try {
- ParcelFileDescriptor recordSoundParcel =
- ParcelFileDescriptor.open(recordSoundFile,
- ParcelFileDescriptor.MODE_READ_ONLY);
- AssetFileDescriptor recordSoundAsset =
- new AssetFileDescriptor(recordSoundParcel, 0,
- AssetFileDescriptor.UNKNOWN_LENGTH);
- if (SystemProperties.get("ro.camera.sound.forced", "0").equals("0")) {
- mRecordSound = new SoundPlayer(recordSoundAsset, false);
- } else {
- mRecordSound = new SoundPlayer(recordSoundAsset, true);
- }
- } catch (java.io.FileNotFoundException e) {
- Log.e(TAG, "System video record sound not found");
- mRecordSound = null;
- }
- }
-
- private void releaseSoundRecorder() {
- if (mRecordSound != null) {
- mRecordSound.release();
- mRecordSound = null;
- }
- }
-
@Override
protected void onPause() {
super.onPause();
@@ -963,7 +930,6 @@ public class PanoramaActivity extends ActivityBase implements
}
releaseCamera();
- releaseSoundRecorder();
mMosaicView.onPause();
clearMosaicFrameProcessorIfNeeded();
mOrientationEventListener.disable();
@@ -979,8 +945,6 @@ public class PanoramaActivity extends ActivityBase implements
mCaptureState = CAPTURE_STATE_VIEWFINDER;
setupCamera();
- initSoundRecorder();
-
// Camera must be initialized before MosaicFrameProcessor is initialized. The preview size
// has to be decided by camera device.
initMosaicFrameProcessorIfNeeded();