1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/update.patch Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,2296 @@ 1.4 +diff --git a/GonkCameraListener.h b/GonkCameraListener.h 1.5 +index 67eeef3..243264c 100644 1.6 +--- a/GonkCameraListener.h 1.7 ++++ b/GonkCameraListener.h 1.8 +@@ -14,49 +14,16 @@ 1.9 + * limitations under the License. 1.10 + */ 1.11 + 1.12 +-#ifndef ANDROID_HARDWARE_CAMERA_H 1.13 +-#define ANDROID_HARDWARE_CAMERA_H 1.14 ++#ifndef GONK_CAMERA_LISTENER_H 1.15 ++#define GONK_CAMERA_LISTENER_H 1.16 + 1.17 + #include <utils/Timers.h> 1.18 +-#include <gui/ISurfaceTexture.h> 1.19 +-#include <system/camera.h> 1.20 +-#include <camera/ICameraClient.h> 1.21 +-#include <camera/ICameraRecordingProxy.h> 1.22 +-#include <camera/ICameraRecordingProxyListener.h> 1.23 ++#include "libcameraservice/CameraHardwareInterface.h" 1.24 + 1.25 + namespace android { 1.26 + 1.27 +-struct CameraInfo { 1.28 +- /** 1.29 +- * The direction that the camera faces to. It should be CAMERA_FACING_BACK 1.30 +- * or CAMERA_FACING_FRONT. 1.31 +- */ 1.32 +- int facing; 1.33 +- 1.34 +- /** 1.35 +- * The orientation of the camera image. The value is the angle that the 1.36 +- * camera image needs to be rotated clockwise so it shows correctly on the 1.37 +- * display in its natural orientation. It should be 0, 90, 180, or 270. 1.38 +- * 1.39 +- * For example, suppose a device has a naturally tall screen. The 1.40 +- * back-facing camera sensor is mounted in landscape. You are looking at 1.41 +- * the screen. If the top side of the camera sensor is aligned with the 1.42 +- * right edge of the screen in natural orientation, the value should be 1.43 +- * 90. If the top side of a front-facing camera sensor is aligned with the 1.44 +- * right of the screen, the value should be 270. 1.45 +- */ 1.46 +- int orientation; 1.47 +- int mode; 1.48 +-}; 1.49 +- 1.50 +-class ICameraService; 1.51 +-class ICamera; 1.52 +-class Surface; 1.53 +-class Mutex; 1.54 +-class String8; 1.55 +- 1.56 + // ref-counted object for callbacks 1.57 +-class CameraListener: virtual public RefBase 1.58 ++class GonkCameraListener: virtual public RefBase 1.59 + { 1.60 + public: 1.61 + virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0; 1.62 +@@ -65,133 +32,6 @@ public: 1.63 + virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0; 1.64 + }; 1.65 + 1.66 +-class Camera : public BnCameraClient, public IBinder::DeathRecipient 1.67 +-{ 1.68 +-public: 1.69 +- // construct a camera client from an existing remote 1.70 +- static sp<Camera> create(const sp<ICamera>& camera); 1.71 +- static int32_t getNumberOfCameras(); 1.72 +- static status_t getCameraInfo(int cameraId, 1.73 +- struct CameraInfo* cameraInfo); 1.74 +- static sp<Camera> connect(int cameraId); 1.75 +- virtual ~Camera(); 1.76 +- void init(); 1.77 +- 1.78 +- status_t reconnect(); 1.79 +- void disconnect(); 1.80 +- status_t lock(); 1.81 +- status_t unlock(); 1.82 +- 1.83 +- status_t getStatus() { return mStatus; } 1.84 +- 1.85 +- // pass the buffered Surface to the camera service 1.86 +- status_t setPreviewDisplay(const sp<Surface>& surface); 1.87 +- 1.88 +- // pass the buffered ISurfaceTexture to the camera service 1.89 +- status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture); 1.90 +- 1.91 +- // start preview mode, must call setPreviewDisplay first 1.92 +- status_t startPreview(); 1.93 +- 1.94 +- // stop preview mode 1.95 +- void stopPreview(); 1.96 +- 1.97 +- // get preview state 1.98 +- bool previewEnabled(); 1.99 +- 1.100 +- // start recording mode, must call setPreviewDisplay first 1.101 +- status_t startRecording(); 1.102 +- 1.103 +- // stop recording mode 1.104 +- void stopRecording(); 1.105 +- 1.106 +- // get recording state 1.107 +- bool recordingEnabled(); 1.108 +- 1.109 +- // release a recording frame 1.110 +- void releaseRecordingFrame(const sp<IMemory>& mem); 1.111 +- 1.112 +- // autoFocus - status returned from callback 1.113 +- status_t autoFocus(); 1.114 +- 1.115 +- // cancel auto focus 1.116 +- status_t cancelAutoFocus(); 1.117 +- 1.118 +- // take a picture - picture returned from callback 1.119 +- status_t takePicture(int msgType); 1.120 +- 1.121 +- // set preview/capture parameters - key/value pairs 1.122 +- status_t setParameters(const String8& params); 1.123 +- 1.124 +- // get preview/capture parameters - key/value pairs 1.125 +- String8 getParameters() const; 1.126 +- 1.127 +- // send command to camera driver 1.128 +- status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); 1.129 +- 1.130 +- // tell camera hal to store meta data or real YUV in video buffers. 1.131 +- status_t storeMetaDataInBuffers(bool enabled); 1.132 +- 1.133 +- void setListener(const sp<CameraListener>& listener); 1.134 +- void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); 1.135 +- void setPreviewCallbackFlags(int preview_callback_flag); 1.136 +- 1.137 +- sp<ICameraRecordingProxy> getRecordingProxy(); 1.138 +- 1.139 +- // ICameraClient interface 1.140 +- virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); 1.141 +- virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, 1.142 +- camera_frame_metadata_t *metadata); 1.143 +- virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); 1.144 +- 1.145 +- sp<ICamera> remote(); 1.146 +- 1.147 +- class RecordingProxy : public BnCameraRecordingProxy 1.148 +- { 1.149 +- public: 1.150 +- RecordingProxy(const sp<Camera>& camera); 1.151 +- 1.152 +- // ICameraRecordingProxy interface 1.153 +- virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener); 1.154 +- virtual void stopRecording(); 1.155 +- virtual void releaseRecordingFrame(const sp<IMemory>& mem); 1.156 +- 1.157 +- private: 1.158 +- sp<Camera> mCamera; 1.159 +- }; 1.160 +- 1.161 +-private: 1.162 +- Camera(); 1.163 +- Camera(const Camera&); 1.164 +- Camera& operator=(const Camera); 1.165 +- virtual void binderDied(const wp<IBinder>& who); 1.166 +- 1.167 +- class DeathNotifier: public IBinder::DeathRecipient 1.168 +- { 1.169 +- public: 1.170 +- DeathNotifier() { 1.171 +- } 1.172 +- 1.173 +- virtual void binderDied(const wp<IBinder>& who); 1.174 +- }; 1.175 +- 1.176 +- static sp<DeathNotifier> mDeathNotifier; 1.177 +- 1.178 +- // helper function to obtain camera service handle 1.179 +- static const sp<ICameraService>& getCameraService(); 1.180 +- 1.181 +- sp<ICamera> mCamera; 1.182 +- status_t mStatus; 1.183 +- 1.184 +- sp<CameraListener> mListener; 1.185 +- sp<ICameraRecordingProxyListener> mRecordingProxyListener; 1.186 +- 1.187 +- friend class DeathNotifier; 1.188 +- 1.189 +- static Mutex mLock; 1.190 +- static sp<ICameraService> mCameraService; 1.191 +-}; 1.192 +- 1.193 + }; // namespace android 1.194 + 1.195 + #endif 1.196 +diff --git a/GonkCameraSource.cpp b/GonkCameraSource.cpp 1.197 +index af6b340..9dba596 100644 1.198 +--- a/GonkCameraSource.cpp 1.199 ++++ b/GonkCameraSource.cpp 1.200 +@@ -14,29 +14,34 @@ 1.201 + * limitations under the License. 1.202 + */ 1.203 + 1.204 +-//#define LOG_NDEBUG 0 1.205 +-#define LOG_TAG "CameraSource" 1.206 +-#include <utils/Log.h> 1.207 ++#include <base/basictypes.h> 1.208 ++#include "nsDebug.h" 1.209 ++#define DOM_CAMERA_LOG_LEVEL 3 1.210 ++#include "CameraCommon.h" 1.211 ++#define LOGD DOM_CAMERA_LOGA 1.212 ++#define LOGV DOM_CAMERA_LOGI 1.213 ++#define LOGI DOM_CAMERA_LOGI 1.214 ++#define LOGW DOM_CAMERA_LOGW 1.215 ++#define LOGE DOM_CAMERA_LOGE 1.216 + 1.217 + #include <OMX_Component.h> 1.218 +-#include <binder/IPCThreadState.h> 1.219 +-#include <media/stagefright/CameraSource.h> 1.220 ++#include "GonkCameraSource.h" 1.221 ++#include "GonkCameraListener.h" 1.222 ++#include "GonkCameraHwMgr.h" 1.223 + #include <media/stagefright/MediaDebug.h> 1.224 + #include <media/stagefright/MediaDefs.h> 1.225 + #include <media/stagefright/MediaErrors.h> 1.226 + #include <media/stagefright/MetaData.h> 1.227 +-#include <camera/Camera.h> 1.228 +-#include <camera/CameraParameters.h> 1.229 +-#include <surfaceflinger/Surface.h> 1.230 + #include <utils/String8.h> 1.231 + #include <cutils/properties.h> 1.232 + 1.233 ++using namespace mozilla; 1.234 + namespace android { 1.235 + 1.236 + static const int64_t CAMERA_SOURCE_TIMEOUT_NS = 3000000000LL; 1.237 + 1.238 +-struct CameraSourceListener : public CameraListener { 1.239 +- CameraSourceListener(const sp<CameraSource> &source); 1.240 ++struct GonkCameraSourceListener : public GonkCameraListener { 1.241 ++ GonkCameraSourceListener(const sp<GonkCameraSource> &source); 1.242 + 1.243 + virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2); 1.244 + virtual void postData(int32_t msgType, const sp<IMemory> &dataPtr, 1.245 +@@ -46,41 +51,41 @@ struct CameraSourceListener : public CameraListener { 1.246 + nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); 1.247 + 1.248 + protected: 1.249 +- virtual ~CameraSourceListener(); 1.250 ++ virtual ~GonkCameraSourceListener(); 1.251 + 1.252 + private: 1.253 +- wp<CameraSource> mSource; 1.254 ++ wp<GonkCameraSource> mSource; 1.255 + 1.256 +- CameraSourceListener(const CameraSourceListener &); 1.257 +- CameraSourceListener &operator=(const CameraSourceListener &); 1.258 ++ GonkCameraSourceListener(const GonkCameraSourceListener &); 1.259 ++ GonkCameraSourceListener &operator=(const GonkCameraSourceListener &); 1.260 + }; 1.261 + 1.262 +-CameraSourceListener::CameraSourceListener(const sp<CameraSource> &source) 1.263 ++GonkCameraSourceListener::GonkCameraSourceListener(const sp<GonkCameraSource> &source) 1.264 + : mSource(source) { 1.265 + } 1.266 + 1.267 +-CameraSourceListener::~CameraSourceListener() { 1.268 ++GonkCameraSourceListener::~GonkCameraSourceListener() { 1.269 + } 1.270 + 1.271 +-void CameraSourceListener::notify(int32_t msgType, int32_t ext1, int32_t ext2) { 1.272 ++void GonkCameraSourceListener::notify(int32_t msgType, int32_t ext1, int32_t ext2) { 1.273 + LOGV("notify(%d, %d, %d)", msgType, ext1, ext2); 1.274 + } 1.275 + 1.276 +-void CameraSourceListener::postData(int32_t msgType, const sp<IMemory> &dataPtr, 1.277 ++void GonkCameraSourceListener::postData(int32_t msgType, const sp<IMemory> &dataPtr, 1.278 + camera_frame_metadata_t *metadata) { 1.279 + LOGV("postData(%d, ptr:%p, size:%d)", 1.280 + msgType, dataPtr->pointer(), dataPtr->size()); 1.281 + 1.282 +- sp<CameraSource> source = mSource.promote(); 1.283 ++ sp<GonkCameraSource> source = mSource.promote(); 1.284 + if (source.get() != NULL) { 1.285 + source->dataCallback(msgType, dataPtr); 1.286 + } 1.287 + } 1.288 + 1.289 +-void CameraSourceListener::postDataTimestamp( 1.290 ++void GonkCameraSourceListener::postDataTimestamp( 1.291 + nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) { 1.292 + 1.293 +- sp<CameraSource> source = mSource.promote(); 1.294 ++ sp<GonkCameraSource> source = mSource.promote(); 1.295 + if (source.get() != NULL) { 1.296 + source->dataCallbackTimestamp(timestamp/1000, msgType, dataPtr); 1.297 + } 1.298 +@@ -114,48 +119,30 @@ static int32_t getColorFormat(const char* colorFormat) { 1.299 + } 1.300 + 1.301 + LOGE("Uknown color format (%s), please add it to " 1.302 +- "CameraSource::getColorFormat", colorFormat); 1.303 ++ "GonkCameraSource::getColorFormat", colorFormat); 1.304 + 1.305 + CHECK_EQ(0, "Unknown color format"); 1.306 + } 1.307 + 1.308 +-CameraSource *CameraSource::Create() { 1.309 +- Size size; 1.310 +- size.width = -1; 1.311 +- size.height = -1; 1.312 +- 1.313 +- sp<ICamera> camera; 1.314 +- return new CameraSource(camera, NULL, 0, size, -1, NULL, false); 1.315 +-} 1.316 +- 1.317 +-// static 1.318 +-CameraSource *CameraSource::CreateFromCamera( 1.319 +- const sp<ICamera>& camera, 1.320 +- const sp<ICameraRecordingProxy>& proxy, 1.321 +- int32_t cameraId, 1.322 ++GonkCameraSource *GonkCameraSource::Create( 1.323 ++ int32_t cameraHandle, 1.324 + Size videoSize, 1.325 + int32_t frameRate, 1.326 +- const sp<Surface>& surface, 1.327 + bool storeMetaDataInVideoBuffers) { 1.328 + 1.329 +- CameraSource *source = new CameraSource(camera, proxy, cameraId, 1.330 +- videoSize, frameRate, surface, 1.331 ++ GonkCameraSource *source = new GonkCameraSource(cameraHandle, 1.332 ++ videoSize, frameRate, 1.333 + storeMetaDataInVideoBuffers); 1.334 + return source; 1.335 + } 1.336 + 1.337 +-CameraSource::CameraSource( 1.338 +- const sp<ICamera>& camera, 1.339 +- const sp<ICameraRecordingProxy>& proxy, 1.340 +- int32_t cameraId, 1.341 ++GonkCameraSource::GonkCameraSource( 1.342 ++ int32_t cameraHandle, 1.343 + Size videoSize, 1.344 + int32_t frameRate, 1.345 +- const sp<Surface>& surface, 1.346 + bool storeMetaDataInVideoBuffers) 1.347 + : mCameraFlags(0), 1.348 + mVideoFrameRate(-1), 1.349 +- mCamera(0), 1.350 +- mSurface(surface), 1.351 + mNumFramesReceived(0), 1.352 + mLastFrameTimestampUs(0), 1.353 + mStarted(false), 1.354 +@@ -169,43 +156,19 @@ CameraSource::CameraSource( 1.355 + mVideoSize.width = -1; 1.356 + mVideoSize.height = -1; 1.357 + 1.358 +- mInitCheck = init(camera, proxy, cameraId, 1.359 ++ mCameraHandle = cameraHandle; 1.360 ++ 1.361 ++ mInitCheck = init( 1.362 + videoSize, frameRate, 1.363 + storeMetaDataInVideoBuffers); 1.364 + if (mInitCheck != OK) releaseCamera(); 1.365 + } 1.366 + 1.367 +-status_t CameraSource::initCheck() const { 1.368 ++status_t GonkCameraSource::initCheck() const { 1.369 + return mInitCheck; 1.370 + } 1.371 + 1.372 +-status_t CameraSource::isCameraAvailable( 1.373 +- const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, 1.374 +- int32_t cameraId) { 1.375 +- 1.376 +- if (camera == 0) { 1.377 +- mCamera = Camera::connect(cameraId); 1.378 +- if (mCamera == 0) return -EBUSY; 1.379 +- mCameraFlags &= ~FLAGS_HOT_CAMERA; 1.380 +- } else { 1.381 +- // We get the proxy from Camera, not ICamera. We need to get the proxy 1.382 +- // to the remote Camera owned by the application. Here mCamera is a 1.383 +- // local Camera object created by us. We cannot use the proxy from 1.384 +- // mCamera here. 1.385 +- mCamera = Camera::create(camera); 1.386 +- if (mCamera == 0) return -EBUSY; 1.387 +- mCameraRecordingProxy = proxy; 1.388 +- mCameraFlags |= FLAGS_HOT_CAMERA; 1.389 +- mDeathNotifier = new DeathNotifier(); 1.390 +- // isBinderAlive needs linkToDeath to work. 1.391 +- mCameraRecordingProxy->asBinder()->linkToDeath(mDeathNotifier); 1.392 +- } 1.393 +- 1.394 +- mCamera->lock(); 1.395 +- 1.396 +- return OK; 1.397 +-} 1.398 +- 1.399 ++//TODO: Do we need to reimplement isCameraAvailable? 1.400 + 1.401 + /* 1.402 + * Check to see whether the requested video width and height is one 1.403 +@@ -267,7 +230,7 @@ static void getSupportedVideoSizes( 1.404 + * @param params CameraParameters to retrieve the information 1.405 + * @return OK if no error. 1.406 + */ 1.407 +-status_t CameraSource::isCameraColorFormatSupported( 1.408 ++status_t GonkCameraSource::isCameraColorFormatSupported( 1.409 + const CameraParameters& params) { 1.410 + mColorFormat = getColorFormat(params.get( 1.411 + CameraParameters::KEY_VIDEO_FRAME_FORMAT)); 1.412 +@@ -292,7 +255,7 @@ status_t CameraSource::isCameraColorFormatSupported( 1.413 + * @param frameRate the target frame rate in frames per second. 1.414 + * @return OK if no error. 1.415 + */ 1.416 +-status_t CameraSource::configureCamera( 1.417 ++status_t GonkCameraSource::configureCamera( 1.418 + CameraParameters* params, 1.419 + int32_t width, int32_t height, 1.420 + int32_t frameRate) { 1.421 +@@ -347,10 +310,9 @@ status_t CameraSource::configureCamera( 1.422 + 1.423 + if (isCameraParamChanged) { 1.424 + // Either frame rate or frame size needs to be changed. 1.425 +- String8 s = params->flatten(); 1.426 +- if (OK != mCamera->setParameters(s)) { 1.427 ++ if (OK != GonkCameraHardware::PushParameters(mCameraHandle,*params)) { 1.428 + LOGE("Could not change settings." 1.429 +- " Someone else is using camera %p?", mCamera.get()); 1.430 ++ " Someone else is using camera ?"); 1.431 + return -EBUSY; 1.432 + } 1.433 + } 1.434 +@@ -368,7 +330,7 @@ status_t CameraSource::configureCamera( 1.435 + * @param the target video frame height in pixels to check against 1.436 + * @return OK if no error 1.437 + */ 1.438 +-status_t CameraSource::checkVideoSize( 1.439 ++status_t GonkCameraSource::checkVideoSize( 1.440 + const CameraParameters& params, 1.441 + int32_t width, int32_t height) { 1.442 + 1.443 +@@ -420,7 +382,7 @@ status_t CameraSource::checkVideoSize( 1.444 + * @param the target video frame rate to check against 1.445 + * @return OK if no error. 1.446 + */ 1.447 +-status_t CameraSource::checkFrameRate( 1.448 ++status_t GonkCameraSource::checkFrameRate( 1.449 + const CameraParameters& params, 1.450 + int32_t frameRate) { 1.451 + 1.452 +@@ -462,39 +424,17 @@ status_t CameraSource::checkFrameRate( 1.453 + * 1.454 + * @return OK if no error. 1.455 + */ 1.456 +-status_t CameraSource::init( 1.457 +- const sp<ICamera>& camera, 1.458 +- const sp<ICameraRecordingProxy>& proxy, 1.459 +- int32_t cameraId, 1.460 ++status_t GonkCameraSource::init( 1.461 + Size videoSize, 1.462 + int32_t frameRate, 1.463 + bool storeMetaDataInVideoBuffers) { 1.464 + 1.465 + LOGV("init"); 1.466 + status_t err = OK; 1.467 +- int64_t token = IPCThreadState::self()->clearCallingIdentity(); 1.468 +- err = initWithCameraAccess(camera, proxy, cameraId, 1.469 +- videoSize, frameRate, 1.470 +- storeMetaDataInVideoBuffers); 1.471 +- IPCThreadState::self()->restoreCallingIdentity(token); 1.472 +- return err; 1.473 +-} 1.474 +- 1.475 +-status_t CameraSource::initWithCameraAccess( 1.476 +- const sp<ICamera>& camera, 1.477 +- const sp<ICameraRecordingProxy>& proxy, 1.478 +- int32_t cameraId, 1.479 +- Size videoSize, 1.480 +- int32_t frameRate, 1.481 +- bool storeMetaDataInVideoBuffers) { 1.482 +- LOGV("initWithCameraAccess"); 1.483 +- status_t err = OK; 1.484 ++ //TODO: need to do something here to check the sanity of camera 1.485 + 1.486 +- if ((err = isCameraAvailable(camera, proxy, cameraId)) != OK) { 1.487 +- LOGE("Camera connection could not be established."); 1.488 +- return err; 1.489 +- } 1.490 +- CameraParameters params(mCamera->getParameters()); 1.491 ++ CameraParameters params; 1.492 ++ GonkCameraHardware::PullParameters(mCameraHandle, params); 1.493 + if ((err = isCameraColorFormatSupported(params)) != OK) { 1.494 + return err; 1.495 + } 1.496 +@@ -508,7 +448,8 @@ status_t CameraSource::initWithCameraAccess( 1.497 + } 1.498 + 1.499 + // Check on video frame size and frame rate. 1.500 +- CameraParameters newCameraParams(mCamera->getParameters()); 1.501 ++ CameraParameters newCameraParams; 1.502 ++ GonkCameraHardware::PullParameters(mCameraHandle, newCameraParams); 1.503 + if ((err = checkVideoSize(newCameraParams, 1.504 + videoSize.width, videoSize.height)) != OK) { 1.505 + return err; 1.506 +@@ -517,15 +458,11 @@ status_t CameraSource::initWithCameraAccess( 1.507 + return err; 1.508 + } 1.509 + 1.510 +- // This CHECK is good, since we just passed the lock/unlock 1.511 +- // check earlier by calling mCamera->setParameters(). 1.512 +- CHECK_EQ(OK, mCamera->setPreviewDisplay(mSurface)); 1.513 +- 1.514 + // By default, do not store metadata in video buffers 1.515 + mIsMetaDataStoredInVideoBuffers = false; 1.516 +- mCamera->storeMetaDataInBuffers(false); 1.517 ++ GonkCameraHardware::StoreMetaDataInBuffers(mCameraHandle, false); 1.518 + if (storeMetaDataInVideoBuffers) { 1.519 +- if (OK == mCamera->storeMetaDataInBuffers(true)) { 1.520 ++ if (OK == GonkCameraHardware::StoreMetaDataInBuffers(mCameraHandle, true)) { 1.521 + mIsMetaDataStoredInVideoBuffers = true; 1.522 + } 1.523 + } 1.524 +@@ -568,40 +505,28 @@ status_t CameraSource::initWithCameraAccess( 1.525 + return OK; 1.526 + } 1.527 + 1.528 +-CameraSource::~CameraSource() { 1.529 ++GonkCameraSource::~GonkCameraSource() { 1.530 + if (mStarted) { 1.531 + stop(); 1.532 + } else if (mInitCheck == OK) { 1.533 + // Camera is initialized but because start() is never called, 1.534 + // the lock on Camera is never released(). This makes sure 1.535 + // Camera's lock is released in this case. 1.536 ++ // TODO: Don't think I need to do this 1.537 + releaseCamera(); 1.538 + } 1.539 + } 1.540 + 1.541 +-void CameraSource::startCameraRecording() { 1.542 ++void GonkCameraSource::startCameraRecording() { 1.543 + LOGV("startCameraRecording"); 1.544 +- // Reset the identity to the current thread because media server owns the 1.545 +- // camera and recording is started by the applications. The applications 1.546 +- // will connect to the camera in ICameraRecordingProxy::startRecording. 1.547 +- int64_t token = IPCThreadState::self()->clearCallingIdentity(); 1.548 +- if (mCameraFlags & FLAGS_HOT_CAMERA) { 1.549 +- mCamera->unlock(); 1.550 +- mCamera.clear(); 1.551 +- CHECK_EQ(OK, mCameraRecordingProxy->startRecording(new ProxyListener(this))); 1.552 +- } else { 1.553 +- mCamera->setListener(new CameraSourceListener(this)); 1.554 +- mCamera->startRecording(); 1.555 +- CHECK(mCamera->recordingEnabled()); 1.556 +- } 1.557 +- IPCThreadState::self()->restoreCallingIdentity(token); 1.558 ++ CHECK_EQ(OK, GonkCameraHardware::StartRecording(mCameraHandle)); 1.559 + } 1.560 + 1.561 +-status_t CameraSource::start(MetaData *meta) { 1.562 ++status_t GonkCameraSource::start(MetaData *meta) { 1.563 + LOGV("start"); 1.564 + CHECK(!mStarted); 1.565 + if (mInitCheck != OK) { 1.566 +- LOGE("CameraSource is not initialized yet"); 1.567 ++ LOGE("GonkCameraSource is not initialized yet"); 1.568 + return mInitCheck; 1.569 + } 1.570 + 1.571 +@@ -614,58 +539,34 @@ status_t CameraSource::start(MetaData *meta) { 1.572 + mStartTimeUs = 0; 1.573 + int64_t startTimeUs; 1.574 + if (meta && meta->findInt64(kKeyTime, &startTimeUs)) { 1.575 ++ LOGV("Metadata enabled, startime: %lld us", startTimeUs); 1.576 + mStartTimeUs = startTimeUs; 1.577 + } 1.578 + 1.579 ++ // Register a listener with GonkCameraHardware so that we can get callbacks 1.580 ++ GonkCameraHardware::SetListener(mCameraHandle, new GonkCameraSourceListener(this)); 1.581 ++ 1.582 + startCameraRecording(); 1.583 + 1.584 + mStarted = true; 1.585 + return OK; 1.586 + } 1.587 + 1.588 +-void CameraSource::stopCameraRecording() { 1.589 ++void GonkCameraSource::stopCameraRecording() { 1.590 + LOGV("stopCameraRecording"); 1.591 +- if (mCameraFlags & FLAGS_HOT_CAMERA) { 1.592 +- mCameraRecordingProxy->stopRecording(); 1.593 +- } else { 1.594 +- mCamera->setListener(NULL); 1.595 +- mCamera->stopRecording(); 1.596 +- } 1.597 ++ GonkCameraHardware::StopRecording(mCameraHandle); 1.598 + } 1.599 + 1.600 +-void CameraSource::releaseCamera() { 1.601 ++void GonkCameraSource::releaseCamera() { 1.602 + LOGV("releaseCamera"); 1.603 +- if (mCamera != 0) { 1.604 +- int64_t token = IPCThreadState::self()->clearCallingIdentity(); 1.605 +- if ((mCameraFlags & FLAGS_HOT_CAMERA) == 0) { 1.606 +- LOGV("Camera was cold when we started, stopping preview"); 1.607 +- mCamera->stopPreview(); 1.608 +- mCamera->disconnect(); 1.609 +- } 1.610 +- mCamera->unlock(); 1.611 +- mCamera.clear(); 1.612 +- mCamera = 0; 1.613 +- IPCThreadState::self()->restoreCallingIdentity(token); 1.614 +- } 1.615 +- if (mCameraRecordingProxy != 0) { 1.616 +- mCameraRecordingProxy->asBinder()->unlinkToDeath(mDeathNotifier); 1.617 +- mCameraRecordingProxy.clear(); 1.618 +- } 1.619 +- mCameraFlags = 0; 1.620 + } 1.621 + 1.622 +-status_t CameraSource::stop() { 1.623 +- LOGD("stop: E"); 1.624 ++status_t GonkCameraSource::stop() { 1.625 ++ LOGV("stop: E"); 1.626 + Mutex::Autolock autoLock(mLock); 1.627 + mStarted = false; 1.628 + mFrameAvailableCondition.signal(); 1.629 + 1.630 +- int64_t token; 1.631 +- bool isTokenValid = false; 1.632 +- if (mCamera != 0) { 1.633 +- token = IPCThreadState::self()->clearCallingIdentity(); 1.634 +- isTokenValid = true; 1.635 +- } 1.636 + releaseQueuedFrames(); 1.637 + while (!mFramesBeingEncoded.empty()) { 1.638 + if (NO_ERROR != 1.639 +@@ -675,11 +576,9 @@ status_t CameraSource::stop() { 1.640 + mFramesBeingEncoded.size()); 1.641 + } 1.642 + } 1.643 ++ LOGV("Calling stopCameraRecording"); 1.644 + stopCameraRecording(); 1.645 + releaseCamera(); 1.646 +- if (isTokenValid) { 1.647 +- IPCThreadState::self()->restoreCallingIdentity(token); 1.648 +- } 1.649 + 1.650 + if (mCollectStats) { 1.651 + LOGI("Frames received/encoded/dropped: %d/%d/%d in %lld us", 1.652 +@@ -692,22 +591,16 @@ status_t CameraSource::stop() { 1.653 + } 1.654 + 1.655 + CHECK_EQ(mNumFramesReceived, mNumFramesEncoded + mNumFramesDropped); 1.656 +- LOGD("stop: X"); 1.657 ++ LOGV("stop: X"); 1.658 + return OK; 1.659 + } 1.660 + 1.661 +-void CameraSource::releaseRecordingFrame(const sp<IMemory>& frame) { 1.662 ++void GonkCameraSource::releaseRecordingFrame(const sp<IMemory>& frame) { 1.663 + LOGV("releaseRecordingFrame"); 1.664 +- if (mCameraRecordingProxy != NULL) { 1.665 +- mCameraRecordingProxy->releaseRecordingFrame(frame); 1.666 +- } else if (mCamera != NULL) { 1.667 +- int64_t token = IPCThreadState::self()->clearCallingIdentity(); 1.668 +- mCamera->releaseRecordingFrame(frame); 1.669 +- IPCThreadState::self()->restoreCallingIdentity(token); 1.670 +- } 1.671 ++ GonkCameraHardware::ReleaseRecordingFrame(mCameraHandle, frame); 1.672 + } 1.673 + 1.674 +-void CameraSource::releaseQueuedFrames() { 1.675 ++void GonkCameraSource::releaseQueuedFrames() { 1.676 + List<sp<IMemory> >::iterator it; 1.677 + while (!mFramesReceived.empty()) { 1.678 + it = mFramesReceived.begin(); 1.679 +@@ -717,15 +610,15 @@ void CameraSource::releaseQueuedFrames() { 1.680 + } 1.681 + } 1.682 + 1.683 +-sp<MetaData> CameraSource::getFormat() { 1.684 ++sp<MetaData> GonkCameraSource::getFormat() { 1.685 + return mMeta; 1.686 + } 1.687 + 1.688 +-void CameraSource::releaseOneRecordingFrame(const sp<IMemory>& frame) { 1.689 ++void GonkCameraSource::releaseOneRecordingFrame(const sp<IMemory>& frame) { 1.690 + releaseRecordingFrame(frame); 1.691 + } 1.692 + 1.693 +-void CameraSource::signalBufferReturned(MediaBuffer *buffer) { 1.694 ++void GonkCameraSource::signalBufferReturned(MediaBuffer *buffer) { 1.695 + LOGV("signalBufferReturned: %p", buffer->data()); 1.696 + Mutex::Autolock autoLock(mLock); 1.697 + for (List<sp<IMemory> >::iterator it = mFramesBeingEncoded.begin(); 1.698 +@@ -743,7 +636,7 @@ void CameraSource::signalBufferReturned(MediaBuffer *buffer) { 1.699 + CHECK_EQ(0, "signalBufferReturned: bogus buffer"); 1.700 + } 1.701 + 1.702 +-status_t CameraSource::read( 1.703 ++status_t GonkCameraSource::read( 1.704 + MediaBuffer **buffer, const ReadOptions *options) { 1.705 + LOGV("read"); 1.706 + 1.707 +@@ -764,11 +657,7 @@ status_t CameraSource::read( 1.708 + if (NO_ERROR != 1.709 + mFrameAvailableCondition.waitRelative(mLock, 1.710 + mTimeBetweenFrameCaptureUs * 1000LL + CAMERA_SOURCE_TIMEOUT_NS)) { 1.711 +- if (mCameraRecordingProxy != 0 && 1.712 +- !mCameraRecordingProxy->asBinder()->isBinderAlive()) { 1.713 +- LOGW("camera recording proxy is gone"); 1.714 +- return ERROR_END_OF_STREAM; 1.715 +- } 1.716 ++ //TODO: check sanity of camera? 1.717 + LOGW("Timed out waiting for incoming camera video frames: %lld us", 1.718 + mLastFrameTimestampUs); 1.719 + } 1.720 +@@ -790,9 +679,10 @@ status_t CameraSource::read( 1.721 + return OK; 1.722 + } 1.723 + 1.724 +-void CameraSource::dataCallbackTimestamp(int64_t timestampUs, 1.725 ++void GonkCameraSource::dataCallbackTimestamp(int64_t timestampUs, 1.726 + int32_t msgType, const sp<IMemory> &data) { 1.727 + LOGV("dataCallbackTimestamp: timestamp %lld us", timestampUs); 1.728 ++ //LOGV("dataCallbackTimestamp: data %x size %d", data->pointer(), data->size()); 1.729 + Mutex::Autolock autoLock(mLock); 1.730 + if (!mStarted || (mNumFramesReceived == 0 && timestampUs < mStartTimeUs)) { 1.731 + LOGV("Drop frame at %lld/%lld us", timestampUs, mStartTimeUs); 1.732 +@@ -808,7 +698,7 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs, 1.733 + } 1.734 + 1.735 + // May need to skip frame or modify timestamp. Currently implemented 1.736 +- // by the subclass CameraSourceTimeLapse. 1.737 ++ // by the subclass GonkCameraSourceTimeLapse. 1.738 + if (skipCurrentFrame(timestampUs)) { 1.739 + releaseOneRecordingFrame(data); 1.740 + return; 1.741 +@@ -839,22 +729,9 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs, 1.742 + mFrameAvailableCondition.signal(); 1.743 + } 1.744 + 1.745 +-bool CameraSource::isMetaDataStoredInVideoBuffers() const { 1.746 ++bool GonkCameraSource::isMetaDataStoredInVideoBuffers() const { 1.747 + LOGV("isMetaDataStoredInVideoBuffers"); 1.748 + return mIsMetaDataStoredInVideoBuffers; 1.749 + } 1.750 + 1.751 +-CameraSource::ProxyListener::ProxyListener(const sp<CameraSource>& source) { 1.752 +- mSource = source; 1.753 +-} 1.754 +- 1.755 +-void CameraSource::ProxyListener::dataCallbackTimestamp( 1.756 +- nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) { 1.757 +- mSource->dataCallbackTimestamp(timestamp / 1000, msgType, dataPtr); 1.758 +-} 1.759 +- 1.760 +-void CameraSource::DeathNotifier::binderDied(const wp<IBinder>& who) { 1.761 +- LOGI("Camera recording proxy died"); 1.762 +-} 1.763 +- 1.764 +-} // namespace android 1.765 ++} // namespace android 1.766 +diff --git a/GonkCameraSource.h b/GonkCameraSource.h 1.767 +index 446720b..fe58f96 100644 1.768 +--- a/GonkCameraSource.h 1.769 ++++ b/GonkCameraSource.h 1.770 +@@ -14,69 +14,31 @@ 1.771 + * limitations under the License. 1.772 + */ 1.773 + 1.774 +-#ifndef CAMERA_SOURCE_H_ 1.775 ++#ifndef GONK_CAMERA_SOURCE_H_ 1.776 + 1.777 +-#define CAMERA_SOURCE_H_ 1.778 ++#define GONK_CAMERA_SOURCE_H_ 1.779 + 1.780 + #include <media/stagefright/MediaBuffer.h> 1.781 + #include <media/stagefright/MediaSource.h> 1.782 +-#include <camera/ICamera.h> 1.783 +-#include <camera/ICameraRecordingProxyListener.h> 1.784 + #include <camera/CameraParameters.h> 1.785 + #include <utils/List.h> 1.786 + #include <utils/RefBase.h> 1.787 ++#include <utils/threads.h> 1.788 + 1.789 + namespace android { 1.790 + 1.791 + class IMemory; 1.792 +-class Camera; 1.793 +-class Surface; 1.794 ++class GonkCameraSourceListener; 1.795 + 1.796 +-class CameraSource : public MediaSource, public MediaBufferObserver { 1.797 ++class GonkCameraSource : public MediaSource, public MediaBufferObserver { 1.798 + public: 1.799 +- /** 1.800 +- * Factory method to create a new CameraSource using the current 1.801 +- * settings (such as video size, frame rate, color format, etc) 1.802 +- * from the default camera. 1.803 +- * 1.804 +- * @return NULL on error. 1.805 +- */ 1.806 +- static CameraSource *Create(); 1.807 + 1.808 +- /** 1.809 +- * Factory method to create a new CameraSource. 1.810 +- * 1.811 +- * @param camera the video input frame data source. If it is NULL, 1.812 +- * we will try to connect to the camera with the given 1.813 +- * cameraId. 1.814 +- * 1.815 +- * @param cameraId the id of the camera that the source will connect 1.816 +- * to if camera is NULL; otherwise ignored. 1.817 +- * 1.818 +- * @param videoSize the dimension (in pixels) of the video frame 1.819 +- * @param frameRate the target frames per second 1.820 +- * @param surface the preview surface for display where preview 1.821 +- * frames are sent to 1.822 +- * @param storeMetaDataInVideoBuffers true to request the camera 1.823 +- * source to store meta data in video buffers; false to 1.824 +- * request the camera source to store real YUV frame data 1.825 +- * in the video buffers. The camera source may not support 1.826 +- * storing meta data in video buffers, if so, a request 1.827 +- * to do that will NOT be honored. To find out whether 1.828 +- * meta data is actually being stored in video buffers 1.829 +- * during recording, call isMetaDataStoredInVideoBuffers(). 1.830 +- * 1.831 +- * @return NULL on error. 1.832 +- */ 1.833 +- static CameraSource *CreateFromCamera(const sp<ICamera> &camera, 1.834 +- const sp<ICameraRecordingProxy> &proxy, 1.835 +- int32_t cameraId, 1.836 +- Size videoSize, 1.837 +- int32_t frameRate, 1.838 +- const sp<Surface>& surface, 1.839 +- bool storeMetaDataInVideoBuffers = false); 1.840 ++ static GonkCameraSource *Create(int32_t cameraHandle, 1.841 ++ Size videoSize, 1.842 ++ int32_t frameRate, 1.843 ++ bool storeMetaDataInVideoBuffers = false); 1.844 + 1.845 +- virtual ~CameraSource(); 1.846 ++ virtual ~GonkCameraSource(); 1.847 + 1.848 + virtual status_t start(MetaData *params = NULL); 1.849 + virtual status_t stop(); 1.850 +@@ -84,14 +46,14 @@ public: 1.851 + MediaBuffer **buffer, const ReadOptions *options = NULL); 1.852 + 1.853 + /** 1.854 +- * Check whether a CameraSource object is properly initialized. 1.855 ++ * Check whether a GonkCameraSource object is properly initialized. 1.856 + * Must call this method before stop(). 1.857 + * @return OK if initialization has successfully completed. 1.858 + */ 1.859 + virtual status_t initCheck() const; 1.860 + 1.861 + /** 1.862 +- * Returns the MetaData associated with the CameraSource, 1.863 ++ * Returns the MetaData associated with the GonkCameraSource, 1.864 + * including: 1.865 + * kKeyColorFormat: YUV color format of the video frames 1.866 + * kKeyWidth, kKeyHeight: dimension (in pixels) of the video frames 1.867 +@@ -113,22 +75,6 @@ public: 1.868 + virtual void signalBufferReturned(MediaBuffer* buffer); 1.869 + 1.870 + protected: 1.871 +- class ProxyListener: public BnCameraRecordingProxyListener { 1.872 +- public: 1.873 +- ProxyListener(const sp<CameraSource>& source); 1.874 +- virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType, 1.875 +- const sp<IMemory> &data); 1.876 +- 1.877 +- private: 1.878 +- sp<CameraSource> mSource; 1.879 +- }; 1.880 +- 1.881 +- // isBinderAlive needs linkToDeath to work. 1.882 +- class DeathNotifier: public IBinder::DeathRecipient { 1.883 +- public: 1.884 +- DeathNotifier() {} 1.885 +- virtual void binderDied(const wp<IBinder>& who); 1.886 +- }; 1.887 + 1.888 + enum CameraFlags { 1.889 + FLAGS_SET_CAMERA = 1L << 0, 1.890 +@@ -141,10 +87,6 @@ protected: 1.891 + int32_t mColorFormat; 1.892 + status_t mInitCheck; 1.893 + 1.894 +- sp<Camera> mCamera; 1.895 +- sp<ICameraRecordingProxy> mCameraRecordingProxy; 1.896 +- sp<DeathNotifier> mDeathNotifier; 1.897 +- sp<Surface> mSurface; 1.898 + sp<MetaData> mMeta; 1.899 + 1.900 + int64_t mStartTimeUs; 1.901 +@@ -156,11 +98,9 @@ protected: 1.902 + // Time between capture of two frames. 1.903 + int64_t mTimeBetweenFrameCaptureUs; 1.904 + 1.905 +- CameraSource(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, 1.906 +- int32_t cameraId, 1.907 ++ GonkCameraSource(int32_t cameraHandle, 1.908 + Size videoSize, int32_t frameRate, 1.909 +- const sp<Surface>& surface, 1.910 +- bool storeMetaDataInVideoBuffers); 1.911 ++ bool storeMetaDataInVideoBuffers = false); 1.912 + 1.913 + virtual void startCameraRecording(); 1.914 + virtual void stopCameraRecording(); 1.915 +@@ -170,6 +110,7 @@ protected: 1.916 + // Called from dataCallbackTimestamp. 1.917 + virtual bool skipCurrentFrame(int64_t timestampUs) {return false;} 1.918 + 1.919 ++ friend class GonkCameraSourceListener; 1.920 + // Callback called when still camera raw data is available. 1.921 + virtual void dataCallback(int32_t msgType, const sp<IMemory> &data) {} 1.922 + 1.923 +@@ -177,7 +118,6 @@ protected: 1.924 + const sp<IMemory> &data); 1.925 + 1.926 + private: 1.927 +- friend class CameraSourceListener; 1.928 + 1.929 + Mutex mLock; 1.930 + Condition mFrameAvailableCondition; 1.931 +@@ -192,23 +132,13 @@ private: 1.932 + int64_t mGlitchDurationThresholdUs; 1.933 + bool mCollectStats; 1.934 + bool mIsMetaDataStoredInVideoBuffers; 1.935 ++ int32_t mCameraHandle; 1.936 + 1.937 + void releaseQueuedFrames(); 1.938 + void releaseOneRecordingFrame(const sp<IMemory>& frame); 1.939 + 1.940 +- 1.941 +- status_t init(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, 1.942 +- int32_t cameraId, Size videoSize, int32_t frameRate, 1.943 +- bool storeMetaDataInVideoBuffers); 1.944 +- 1.945 +- status_t initWithCameraAccess( 1.946 +- const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, 1.947 +- int32_t cameraId, Size videoSize, int32_t frameRate, 1.948 ++ status_t init(Size videoSize, int32_t frameRate, 1.949 + bool storeMetaDataInVideoBuffers); 1.950 +- 1.951 +- status_t isCameraAvailable(const sp<ICamera>& camera, 1.952 +- const sp<ICameraRecordingProxy>& proxy, 1.953 +- int32_t cameraId); 1.954 + status_t isCameraColorFormatSupported(const CameraParameters& params); 1.955 + status_t configureCamera(CameraParameters* params, 1.956 + int32_t width, int32_t height, 1.957 +@@ -222,10 +152,10 @@ private: 1.958 + 1.959 + void releaseCamera(); 1.960 + 1.961 +- CameraSource(const CameraSource &); 1.962 +- CameraSource &operator=(const CameraSource &); 1.963 ++ GonkCameraSource(const GonkCameraSource &); 1.964 ++ GonkCameraSource &operator=(const GonkCameraSource &); 1.965 + }; 1.966 + 1.967 + } // namespace android 1.968 + 1.969 +-#endif // CAMERA_SOURCE_H_ 1.970 ++#endif // GONK_CAMERA_SOURCE_H_ 1.971 +diff --git a/GonkRecorder.cpp b/GonkRecorder.cpp 1.972 +index b20ca9d..2dc625c 100644 1.973 +--- a/GonkRecorder.cpp 1.974 ++++ b/GonkRecorder.cpp 1.975 +@@ -16,35 +16,23 @@ 1.976 + */ 1.977 + 1.978 + //#define LOG_NDEBUG 0 1.979 +-#define LOG_TAG "StagefrightRecorder" 1.980 ++#define LOG_TAG "GonkRecorder" 1.981 ++ 1.982 + #include <utils/Log.h> 1.983 + #include <media/AudioParameter.h> 1.984 +-#include "StagefrightRecorder.h" 1.985 +- 1.986 +-#include <binder/IPCThreadState.h> 1.987 +-#include <binder/IServiceManager.h> 1.988 ++#include "GonkRecorder.h" 1.989 + 1.990 +-#include <media/IMediaPlayerService.h> 1.991 + #include <media/stagefright/AudioSource.h> 1.992 + #include <media/stagefright/AMRWriter.h> 1.993 +-#include <media/stagefright/AACWriter.h> 1.994 +-#include <media/stagefright/ExtendedWriter.h> 1.995 +-#include <media/stagefright/FMA2DPWriter.h> 1.996 +-#include <media/stagefright/CameraSource.h> 1.997 +-#include <media/stagefright/CameraSourceTimeLapse.h> 1.998 + #include <media/stagefright/ExtendedWriter.h> 1.999 + #include <media/stagefright/MPEG2TSWriter.h> 1.1000 + #include <media/stagefright/MPEG4Writer.h> 1.1001 + #include <media/stagefright/MediaDebug.h> 1.1002 + #include <media/stagefright/MediaDefs.h> 1.1003 + #include <media/stagefright/MetaData.h> 1.1004 +-#include <media/stagefright/OMXClient.h> 1.1005 ++#include <OMX.h> 1.1006 + #include <media/stagefright/OMXCodec.h> 1.1007 +-#include <media/stagefright/SurfaceMediaSource.h> 1.1008 + #include <media/MediaProfiles.h> 1.1009 +-#include <camera/ICamera.h> 1.1010 +-#include <camera/CameraParameters.h> 1.1011 +-#include <surfaceflinger/Surface.h> 1.1012 + #include <utils/String8.h> 1.1013 + 1.1014 + #include <utils/Errors.h> 1.1015 +@@ -57,51 +45,41 @@ 1.1016 + #include "ARTPWriter.h" 1.1017 + 1.1018 + #include <cutils/properties.h> 1.1019 ++#include "GonkCameraSource.h" 1.1020 + 1.1021 + namespace android { 1.1022 + 1.1023 +-// To collect the encoder usage for the battery app 1.1024 +-static void addBatteryData(uint32_t params) { 1.1025 +- sp<IBinder> binder = 1.1026 +- defaultServiceManager()->getService(String16("media.player")); 1.1027 +- sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); 1.1028 +- CHECK(service.get() != NULL); 1.1029 +- 1.1030 +- service->addBatteryData(params); 1.1031 ++static sp<IOMX> sOMX = NULL; 1.1032 ++static sp<IOMX> GetOMX() { 1.1033 ++ if(sOMX.get() == NULL) { 1.1034 ++ sOMX = new OMX; 1.1035 ++ } 1.1036 ++ return sOMX; 1.1037 + } 1.1038 + 1.1039 +- 1.1040 +-StagefrightRecorder::StagefrightRecorder() 1.1041 ++GonkRecorder::GonkRecorder() 1.1042 + : mWriter(NULL), 1.1043 + mOutputFd(-1), 1.1044 + mAudioSource(AUDIO_SOURCE_CNT), 1.1045 + mVideoSource(VIDEO_SOURCE_LIST_END), 1.1046 +- mStarted(false), mSurfaceMediaSource(NULL), 1.1047 ++ mStarted(false), 1.1048 + mDisableAudio(false) { 1.1049 + 1.1050 + LOGV("Constructor"); 1.1051 + reset(); 1.1052 + } 1.1053 + 1.1054 +-StagefrightRecorder::~StagefrightRecorder() { 1.1055 ++GonkRecorder::~GonkRecorder() { 1.1056 + LOGV("Destructor"); 1.1057 + stop(); 1.1058 + } 1.1059 + 1.1060 +-status_t StagefrightRecorder::init() { 1.1061 ++status_t GonkRecorder::init() { 1.1062 + LOGV("init"); 1.1063 + return OK; 1.1064 + } 1.1065 + 1.1066 +-// The client side of mediaserver asks it to creat a SurfaceMediaSource 1.1067 +-// and return a interface reference. The client side will use that 1.1068 +-// while encoding GL Frames 1.1069 +-sp<ISurfaceTexture> StagefrightRecorder::querySurfaceMediaSource() const { 1.1070 +- LOGV("Get SurfaceMediaSource"); 1.1071 +- return mSurfaceMediaSource; 1.1072 +-} 1.1073 +- 1.1074 +-status_t StagefrightRecorder::setAudioSource(audio_source_t as) { 1.1075 ++status_t GonkRecorder::setAudioSource(audio_source_t as) { 1.1076 + LOGV("setAudioSource: %d", as); 1.1077 + if (as < AUDIO_SOURCE_DEFAULT || 1.1078 + as >= AUDIO_SOURCE_CNT) { 1.1079 +@@ -122,7 +100,7 @@ 1.1080 + return OK; 1.1081 + } 1.1082 + 1.1083 +-status_t StagefrightRecorder::setVideoSource(video_source vs) { 1.1084 ++status_t GonkRecorder::setVideoSource(video_source vs) { 1.1085 + LOGV("setVideoSource: %d", vs); 1.1086 + if (vs < VIDEO_SOURCE_DEFAULT || 1.1087 + vs >= VIDEO_SOURCE_LIST_END) { 1.1088 +@@ -139,7 +117,7 @@ 1.1089 + return OK; 1.1090 + } 1.1091 + 1.1092 +-status_t StagefrightRecorder::setOutputFormat(output_format of) { 1.1093 ++status_t GonkRecorder::setOutputFormat(output_format of) { 1.1094 + LOGV("setOutputFormat: %d", of); 1.1095 + if (of < OUTPUT_FORMAT_DEFAULT || 1.1096 + of >= OUTPUT_FORMAT_LIST_END) { 1.1097 +@@ -156,7 +134,7 @@ 1.1098 + return OK; 1.1099 + } 1.1100 + 1.1101 +-status_t StagefrightRecorder::setAudioEncoder(audio_encoder ae) { 1.1102 ++status_t GonkRecorder::setAudioEncoder(audio_encoder ae) { 1.1103 + LOGV("setAudioEncoder: %d", ae); 1.1104 + if (ae < AUDIO_ENCODER_DEFAULT || 1.1105 + ae >= AUDIO_ENCODER_LIST_END) { 1.1106 +@@ -174,21 +152,10 @@ 1.1107 + mAudioEncoder = ae; 1.1108 + } 1.1109 + 1.1110 +- // Use default values if appropriate setparam's weren't called. 1.1111 +- if(mAudioEncoder == AUDIO_ENCODER_AAC) { 1.1112 +- mSampleRate = mSampleRate ? mSampleRate : 48000; 1.1113 +- mAudioChannels = mAudioChannels ? mAudioChannels : 2; 1.1114 +- mAudioBitRate = mAudioBitRate ? mAudioBitRate : 156000; 1.1115 +- } 1.1116 +- else{ 1.1117 +- mSampleRate = mSampleRate ? mSampleRate : 8000; 1.1118 +- mAudioChannels = mAudioChannels ? mAudioChannels : 1; 1.1119 +- mAudioBitRate = mAudioBitRate ? mAudioBitRate : 12200; 1.1120 +- } 1.1121 + return OK; 1.1122 + } 1.1123 + 1.1124 +-status_t StagefrightRecorder::setVideoEncoder(video_encoder ve) { 1.1125 ++status_t GonkRecorder::setVideoEncoder(video_encoder ve) { 1.1126 + LOGV("setVideoEncoder: %d", ve); 1.1127 + if (ve < VIDEO_ENCODER_DEFAULT || 1.1128 + ve >= VIDEO_ENCODER_LIST_END) { 1.1129 +@@ -205,7 +172,7 @@ 1.1130 + return OK; 1.1131 + } 1.1132 + 1.1133 +-status_t StagefrightRecorder::setVideoSize(int width, int height) { 1.1134 ++status_t GonkRecorder::setVideoSize(int width, int height) { 1.1135 + LOGV("setVideoSize: %dx%d", width, height); 1.1136 + if (width <= 0 || height <= 0) { 1.1137 + LOGE("Invalid video size: %dx%d", width, height); 1.1138 +@@ -219,7 +186,7 @@ 1.1139 + return OK; 1.1140 + } 1.1141 + 1.1142 +-status_t StagefrightRecorder::setVideoFrameRate(int frames_per_second) { 1.1143 ++status_t GonkRecorder::setVideoFrameRate(int frames_per_second) { 1.1144 + LOGV("setVideoFrameRate: %d", frames_per_second); 1.1145 + if ((frames_per_second <= 0 && frames_per_second != -1) || 1.1146 + frames_per_second > 120) { 1.1147 +@@ -233,31 +200,7 @@ 1.1148 + return OK; 1.1149 + } 1.1150 + 1.1151 +-status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera, 1.1152 +- const sp<ICameraRecordingProxy> &proxy) { 1.1153 +- LOGV("setCamera"); 1.1154 +- if (camera == 0) { 1.1155 +- LOGE("camera is NULL"); 1.1156 +- return BAD_VALUE; 1.1157 +- } 1.1158 +- if (proxy == 0) { 1.1159 +- LOGE("camera proxy is NULL"); 1.1160 +- return BAD_VALUE; 1.1161 +- } 1.1162 +- 1.1163 +- mCamera = camera; 1.1164 +- mCameraProxy = proxy; 1.1165 +- return OK; 1.1166 +-} 1.1167 +- 1.1168 +-status_t StagefrightRecorder::setPreviewSurface(const sp<Surface> &surface) { 1.1169 +- LOGV("setPreviewSurface: %p", surface.get()); 1.1170 +- mPreviewSurface = surface; 1.1171 +- 1.1172 +- return OK; 1.1173 +-} 1.1174 +- 1.1175 +-status_t StagefrightRecorder::setOutputFile(const char *path) { 1.1176 ++status_t GonkRecorder::setOutputFile(const char *path) { 1.1177 + LOGE("setOutputFile(const char*) must not be called"); 1.1178 + // We don't actually support this at all, as the media_server process 1.1179 + // no longer has permissions to create files. 1.1180 +@@ -265,7 +208,7 @@ 1.1181 + return -EPERM; 1.1182 + } 1.1183 + 1.1184 +-status_t StagefrightRecorder::setOutputFile(int fd, int64_t offset, int64_t length) { 1.1185 ++status_t GonkRecorder::setOutputFile(int fd, int64_t offset, int64_t length) { 1.1186 + LOGV("setOutputFile: %d, %lld, %lld", fd, offset, length); 1.1187 + // These don't make any sense, do they? 1.1188 + CHECK_EQ(offset, 0); 1.1189 +@@ -339,7 +282,7 @@ 1.1190 + s->setTo(String8(&data[leading_space], i - leading_space)); 1.1191 + } 1.1192 + 1.1193 +-status_t StagefrightRecorder::setParamAudioSamplingRate(int32_t sampleRate) { 1.1194 ++status_t GonkRecorder::setParamAudioSamplingRate(int32_t sampleRate) { 1.1195 + LOGV("setParamAudioSamplingRate: %d", sampleRate); 1.1196 + if (sampleRate <= 0) { 1.1197 + LOGE("Invalid audio sampling rate: %d", sampleRate); 1.1198 +@@ -351,7 +294,7 @@ 1.1199 + return OK; 1.1200 + } 1.1201 + 1.1202 +-status_t StagefrightRecorder::setParamAudioNumberOfChannels(int32_t channels) { 1.1203 ++status_t GonkRecorder::setParamAudioNumberOfChannels(int32_t channels) { 1.1204 + LOGV("setParamAudioNumberOfChannels: %d", channels); 1.1205 + if (channels <= 0 || channels >= 3) { 1.1206 + LOGE("Invalid number of audio channels: %d", channels); 1.1207 +@@ -363,7 +306,7 @@ 1.1208 + return OK; 1.1209 + } 1.1210 + 1.1211 +-status_t StagefrightRecorder::setParamAudioEncodingBitRate(int32_t bitRate) { 1.1212 ++status_t GonkRecorder::setParamAudioEncodingBitRate(int32_t bitRate) { 1.1213 + LOGV("setParamAudioEncodingBitRate: %d", bitRate); 1.1214 + if (bitRate <= 0) { 1.1215 + LOGE("Invalid audio encoding bit rate: %d", bitRate); 1.1216 +@@ -378,7 +321,7 @@ 1.1217 + return OK; 1.1218 + } 1.1219 + 1.1220 +-status_t StagefrightRecorder::setParamVideoEncodingBitRate(int32_t bitRate) { 1.1221 ++status_t GonkRecorder::setParamVideoEncodingBitRate(int32_t bitRate) { 1.1222 + LOGV("setParamVideoEncodingBitRate: %d", bitRate); 1.1223 + if (bitRate <= 0) { 1.1224 + LOGE("Invalid video encoding bit rate: %d", bitRate); 1.1225 +@@ -394,7 +337,7 @@ 1.1226 + } 1.1227 + 1.1228 + // Always rotate clockwise, and only support 0, 90, 180 and 270 for now. 1.1229 +-status_t StagefrightRecorder::setParamVideoRotation(int32_t degrees) { 1.1230 ++status_t GonkRecorder::setParamVideoRotation(int32_t degrees) { 1.1231 + LOGV("setParamVideoRotation: %d", degrees); 1.1232 + if (degrees < 0 || degrees % 90 != 0) { 1.1233 + LOGE("Unsupported video rotation angle: %d", degrees); 1.1234 +@@ -404,7 +347,7 @@ 1.1235 + return OK; 1.1236 + } 1.1237 + 1.1238 +-status_t StagefrightRecorder::setParamMaxFileDurationUs(int64_t timeUs) { 1.1239 ++status_t GonkRecorder::setParamMaxFileDurationUs(int64_t timeUs) { 1.1240 + LOGV("setParamMaxFileDurationUs: %lld us", timeUs); 1.1241 + 1.1242 + // This is meant for backward compatibility for MediaRecorder.java 1.1243 +@@ -423,7 +366,7 @@ 1.1244 + return OK; 1.1245 + } 1.1246 + 1.1247 +-status_t StagefrightRecorder::setParamMaxFileSizeBytes(int64_t bytes) { 1.1248 ++status_t GonkRecorder::setParamMaxFileSizeBytes(int64_t bytes) { 1.1249 + LOGV("setParamMaxFileSizeBytes: %lld bytes", bytes); 1.1250 + 1.1251 + // This is meant for backward compatibility for MediaRecorder.java 1.1252 +@@ -449,7 +392,7 @@ 1.1253 + return OK; 1.1254 + } 1.1255 + 1.1256 +-status_t StagefrightRecorder::setParamInterleaveDuration(int32_t durationUs) { 1.1257 ++status_t GonkRecorder::setParamInterleaveDuration(int32_t durationUs) { 1.1258 + LOGV("setParamInterleaveDuration: %d", durationUs); 1.1259 + if (durationUs <= 500000) { // 500 ms 1.1260 + // If interleave duration is too small, it is very inefficient to do 1.1261 +@@ -471,20 +414,20 @@ 1.1262 + // If seconds < 0, only the first frame is I frame, and rest are all P frames 1.1263 + // If seconds == 0, all frames are encoded as I frames. No P frames 1.1264 + // If seconds > 0, it is the time spacing (seconds) between 2 neighboring I frames 1.1265 +-status_t StagefrightRecorder::setParamVideoIFramesInterval(int32_t seconds) { 1.1266 ++status_t GonkRecorder::setParamVideoIFramesInterval(int32_t seconds) { 1.1267 + LOGV("setParamVideoIFramesInterval: %d seconds", seconds); 1.1268 + mIFramesIntervalSec = seconds; 1.1269 + return OK; 1.1270 + } 1.1271 + 1.1272 +-status_t StagefrightRecorder::setParam64BitFileOffset(bool use64Bit) { 1.1273 ++status_t GonkRecorder::setParam64BitFileOffset(bool use64Bit) { 1.1274 + LOGV("setParam64BitFileOffset: %s", 1.1275 + use64Bit? "use 64 bit file offset": "use 32 bit file offset"); 1.1276 + mUse64BitFileOffset = use64Bit; 1.1277 + return OK; 1.1278 + } 1.1279 + 1.1280 +-status_t StagefrightRecorder::setParamVideoCameraId(int32_t cameraId) { 1.1281 ++status_t GonkRecorder::setParamVideoCameraId(int32_t cameraId) { 1.1282 + LOGV("setParamVideoCameraId: %d", cameraId); 1.1283 + if (cameraId < 0) { 1.1284 + return BAD_VALUE; 1.1285 +@@ -493,7 +436,7 @@ 1.1286 + return OK; 1.1287 + } 1.1288 + 1.1289 +-status_t StagefrightRecorder::setParamTrackTimeStatus(int64_t timeDurationUs) { 1.1290 ++status_t GonkRecorder::setParamTrackTimeStatus(int64_t timeDurationUs) { 1.1291 + LOGV("setParamTrackTimeStatus: %lld", timeDurationUs); 1.1292 + if (timeDurationUs < 20000) { // Infeasible if shorter than 20 ms? 1.1293 + LOGE("Tracking time duration too short: %lld us", timeDurationUs); 1.1294 +@@ -503,7 +446,7 @@ 1.1295 + return OK; 1.1296 + } 1.1297 + 1.1298 +-status_t StagefrightRecorder::setParamVideoEncoderProfile(int32_t profile) { 1.1299 ++status_t GonkRecorder::setParamVideoEncoderProfile(int32_t profile) { 1.1300 + LOGV("setParamVideoEncoderProfile: %d", profile); 1.1301 + 1.1302 + // Additional check will be done later when we load the encoder. 1.1303 +@@ -512,7 +455,7 @@ 1.1304 + return OK; 1.1305 + } 1.1306 + 1.1307 +-status_t StagefrightRecorder::setParamVideoEncoderLevel(int32_t level) { 1.1308 ++status_t GonkRecorder::setParamVideoEncoderLevel(int32_t level) { 1.1309 + LOGV("setParamVideoEncoderLevel: %d", level); 1.1310 + 1.1311 + // Additional check will be done later when we load the encoder. 1.1312 +@@ -521,7 +464,7 @@ 1.1313 + return OK; 1.1314 + } 1.1315 + 1.1316 +-status_t StagefrightRecorder::setParamMovieTimeScale(int32_t timeScale) { 1.1317 ++status_t GonkRecorder::setParamMovieTimeScale(int32_t timeScale) { 1.1318 + LOGV("setParamMovieTimeScale: %d", timeScale); 1.1319 + 1.1320 + // The range is set to be the same as the audio's time scale range 1.1321 +@@ -534,7 +477,7 @@ 1.1322 + return OK; 1.1323 + } 1.1324 + 1.1325 +-status_t StagefrightRecorder::setParamVideoTimeScale(int32_t timeScale) { 1.1326 ++status_t GonkRecorder::setParamVideoTimeScale(int32_t timeScale) { 1.1327 + LOGV("setParamVideoTimeScale: %d", timeScale); 1.1328 + 1.1329 + // 60000 is chosen to make sure that each video frame from a 60-fps 1.1330 +@@ -547,7 +490,7 @@ 1.1331 + return OK; 1.1332 + } 1.1333 + 1.1334 +-status_t StagefrightRecorder::setParamAudioTimeScale(int32_t timeScale) { 1.1335 ++status_t GonkRecorder::setParamAudioTimeScale(int32_t timeScale) { 1.1336 + LOGV("setParamAudioTimeScale: %d", timeScale); 1.1337 + 1.1338 + // 96000 Hz is the highest sampling rate support in AAC. 1.1339 +@@ -559,33 +502,7 @@ 1.1340 + return OK; 1.1341 + } 1.1342 + 1.1343 +-status_t StagefrightRecorder::setParamTimeLapseEnable(int32_t timeLapseEnable) { 1.1344 +- LOGV("setParamTimeLapseEnable: %d", timeLapseEnable); 1.1345 +- 1.1346 +- if(timeLapseEnable == 0) { 1.1347 +- mCaptureTimeLapse = false; 1.1348 +- } else if (timeLapseEnable == 1) { 1.1349 +- mCaptureTimeLapse = true; 1.1350 +- } else { 1.1351 +- return BAD_VALUE; 1.1352 +- } 1.1353 +- return OK; 1.1354 +-} 1.1355 +- 1.1356 +-status_t StagefrightRecorder::setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs) { 1.1357 +- LOGV("setParamTimeBetweenTimeLapseFrameCapture: %lld us", timeUs); 1.1358 +- 1.1359 +- // Not allowing time more than a day 1.1360 +- if (timeUs <= 0 || timeUs > 86400*1E6) { 1.1361 +- LOGE("Time between time lapse frame capture (%lld) is out of range [0, 1 Day]", timeUs); 1.1362 +- return BAD_VALUE; 1.1363 +- } 1.1364 +- 1.1365 +- mTimeBetweenTimeLapseFrameCaptureUs = timeUs; 1.1366 +- return OK; 1.1367 +-} 1.1368 +- 1.1369 +-status_t StagefrightRecorder::setParamGeoDataLongitude( 1.1370 ++status_t GonkRecorder::setParamGeoDataLongitude( 1.1371 + int64_t longitudex10000) { 1.1372 + 1.1373 + if (longitudex10000 > 1800000 || longitudex10000 < -1800000) { 1.1374 +@@ -595,7 +512,7 @@ 1.1375 + return OK; 1.1376 + } 1.1377 + 1.1378 +-status_t StagefrightRecorder::setParamGeoDataLatitude( 1.1379 ++status_t GonkRecorder::setParamGeoDataLatitude( 1.1380 + int64_t latitudex10000) { 1.1381 + 1.1382 + if (latitudex10000 > 900000 || latitudex10000 < -900000) { 1.1383 +@@ -605,7 +522,7 @@ 1.1384 + return OK; 1.1385 + } 1.1386 + 1.1387 +-status_t StagefrightRecorder::setParameter( 1.1388 ++status_t GonkRecorder::setParameter( 1.1389 + const String8 &key, const String8 &value) { 1.1390 + LOGV("setParameter: key (%s) => value (%s)", key.string(), value.string()); 1.1391 + if (key == "max-duration") { 1.1392 +@@ -703,24 +620,13 @@ 1.1393 + if (safe_strtoi32(value.string(), &timeScale)) { 1.1394 + return setParamVideoTimeScale(timeScale); 1.1395 + } 1.1396 +- } else if (key == "time-lapse-enable") { 1.1397 +- int32_t timeLapseEnable; 1.1398 +- if (safe_strtoi32(value.string(), &timeLapseEnable)) { 1.1399 +- return setParamTimeLapseEnable(timeLapseEnable); 1.1400 +- } 1.1401 +- } else if (key == "time-between-time-lapse-frame-capture") { 1.1402 +- int64_t timeBetweenTimeLapseFrameCaptureMs; 1.1403 +- if (safe_strtoi64(value.string(), &timeBetweenTimeLapseFrameCaptureMs)) { 1.1404 +- return setParamTimeBetweenTimeLapseFrameCapture( 1.1405 +- 1000LL * timeBetweenTimeLapseFrameCaptureMs); 1.1406 +- } 1.1407 + } else { 1.1408 + LOGE("setParameter: failed to find key %s", key.string()); 1.1409 + } 1.1410 + return BAD_VALUE; 1.1411 + } 1.1412 + 1.1413 +-status_t StagefrightRecorder::setParameters(const String8 ¶ms) { 1.1414 ++status_t GonkRecorder::setParameters(const String8 ¶ms) { 1.1415 + LOGV("setParameters: %s", params.string()); 1.1416 + const char *cparams = params.string(); 1.1417 + const char *key_start = cparams; 1.1418 +@@ -755,13 +661,13 @@ 1.1419 + return OK; 1.1420 + } 1.1421 + 1.1422 +-status_t StagefrightRecorder::setListener(const sp<IMediaRecorderClient> &listener) { 1.1423 ++status_t GonkRecorder::setListener(const sp<IMediaRecorderClient> &listener) { 1.1424 + mListener = listener; 1.1425 + 1.1426 + return OK; 1.1427 + } 1.1428 + 1.1429 +-status_t StagefrightRecorder::prepare() { 1.1430 ++status_t GonkRecorder::prepare() { 1.1431 + LOGV(" %s E", __func__ ); 1.1432 + 1.1433 + if(mVideoSource != VIDEO_SOURCE_LIST_END && mVideoEncoder != VIDEO_ENCODER_LIST_END && mVideoHeight && mVideoWidth && /*Video recording*/ 1.1434 +@@ -776,17 +682,15 @@ 1.1435 + return OK; 1.1436 + } 1.1437 + 1.1438 +-status_t StagefrightRecorder::start() { 1.1439 ++status_t GonkRecorder::start() { 1.1440 + CHECK(mOutputFd >= 0); 1.1441 + 1.1442 + if (mWriter != NULL) { 1.1443 +- LOGE("File writer is not avaialble"); 1.1444 ++ LOGE("File writer is not available"); 1.1445 + return UNKNOWN_ERROR; 1.1446 + } 1.1447 + 1.1448 + status_t status = OK; 1.1449 +- if(AUDIO_SOURCE_FM_RX_A2DP == mAudioSource) 1.1450 +- return startFMA2DPWriter(); 1.1451 + 1.1452 + switch (mOutputFormat) { 1.1453 + case OUTPUT_FORMAT_DEFAULT: 1.1454 +@@ -800,22 +704,9 @@ 1.1455 + status = startAMRRecording(); 1.1456 + break; 1.1457 + 1.1458 +- case OUTPUT_FORMAT_AAC_ADIF: 1.1459 +- case OUTPUT_FORMAT_AAC_ADTS: 1.1460 +- status = startAACRecording(); 1.1461 +- break; 1.1462 +- 1.1463 +- case OUTPUT_FORMAT_RTP_AVP: 1.1464 +- status = startRTPRecording(); 1.1465 +- break; 1.1466 +- 1.1467 + case OUTPUT_FORMAT_MPEG2TS: 1.1468 + status = startMPEG2TSRecording(); 1.1469 + break; 1.1470 +- 1.1471 +- case OUTPUT_FORMAT_QCP: 1.1472 +- status = startExtendedRecording( ); 1.1473 +- break; 1.1474 + default: 1.1475 + LOGE("Unsupported output file format: %d", mOutputFormat); 1.1476 + status = UNKNOWN_ERROR; 1.1477 +@@ -824,22 +715,12 @@ 1.1478 + 1.1479 + if ((status == OK) && (!mStarted)) { 1.1480 + mStarted = true; 1.1481 +- 1.1482 +- uint32_t params = IMediaPlayerService::kBatteryDataCodecStarted; 1.1483 +- if (mAudioSource != AUDIO_SOURCE_CNT) { 1.1484 +- params |= IMediaPlayerService::kBatteryDataTrackAudio; 1.1485 +- } 1.1486 +- if (mVideoSource != VIDEO_SOURCE_LIST_END) { 1.1487 +- params |= IMediaPlayerService::kBatteryDataTrackVideo; 1.1488 +- } 1.1489 +- 1.1490 +- addBatteryData(params); 1.1491 + } 1.1492 + 1.1493 + return status; 1.1494 + } 1.1495 + 1.1496 +-sp<MediaSource> StagefrightRecorder::createAudioSource() { 1.1497 ++sp<MediaSource> GonkRecorder::createAudioSource() { 1.1498 + 1.1499 + bool tunneledSource = false; 1.1500 + const char *tunnelMime; 1.1501 +@@ -907,12 +788,6 @@ 1.1502 + case AUDIO_ENCODER_AAC: 1.1503 + mime = MEDIA_MIMETYPE_AUDIO_AAC; 1.1504 + break; 1.1505 +- case AUDIO_ENCODER_EVRC: 1.1506 +- mime = MEDIA_MIMETYPE_AUDIO_EVRC; 1.1507 +- break; 1.1508 +- case AUDIO_ENCODER_QCELP: 1.1509 +- mime = MEDIA_MIMETYPE_AUDIO_QCELP; 1.1510 +- break; 1.1511 + default: 1.1512 + LOGE("Unknown audio encoder: %d", mAudioEncoder); 1.1513 + return NULL; 1.1514 +@@ -931,36 +806,17 @@ 1.1515 + encMeta->setInt32(kKeyTimeScale, mAudioTimeScale); 1.1516 + } 1.1517 + 1.1518 +- OMXClient client; 1.1519 +- CHECK_EQ(client.connect(), OK); 1.1520 +- 1.1521 ++ // use direct OMX interface instead of connecting to 1.1522 ++ // mediaserver over binder calls 1.1523 + sp<MediaSource> audioEncoder = 1.1524 +- OMXCodec::Create(client.interface(), encMeta, 1.1525 ++ OMXCodec::Create(GetOMX(), encMeta, 1.1526 + true /* createEncoder */, audioSource); 1.1527 + mAudioSourceNode = audioSource; 1.1528 + 1.1529 + return audioEncoder; 1.1530 + } 1.1531 + 1.1532 +-status_t StagefrightRecorder::startAACRecording() { 1.1533 +- // FIXME: 1.1534 +- // Add support for OUTPUT_FORMAT_AAC_ADIF 1.1535 +- CHECK(mOutputFormat == OUTPUT_FORMAT_AAC_ADTS); 1.1536 +- 1.1537 +- CHECK(mAudioEncoder == AUDIO_ENCODER_AAC); 1.1538 +- CHECK(mAudioSource != AUDIO_SOURCE_CNT); 1.1539 +- 1.1540 +- mWriter = new AACWriter(mOutputFd); 1.1541 +- status_t status = startRawAudioRecording(); 1.1542 +- if (status != OK) { 1.1543 +- mWriter.clear(); 1.1544 +- mWriter = NULL; 1.1545 +- } 1.1546 +- 1.1547 +- return status; 1.1548 +-} 1.1549 +- 1.1550 +-status_t StagefrightRecorder::startAMRRecording() { 1.1551 ++status_t GonkRecorder::startAMRRecording() { 1.1552 + CHECK(mOutputFormat == OUTPUT_FORMAT_AMR_NB || 1.1553 + mOutputFormat == OUTPUT_FORMAT_AMR_WB); 1.1554 + 1.1555 +@@ -971,28 +827,12 @@ 1.1556 + mAudioEncoder); 1.1557 + return BAD_VALUE; 1.1558 + } 1.1559 +- if (mSampleRate != 8000) { 1.1560 +- LOGE("Invalid sampling rate %d used for AMRNB recording", 1.1561 +- mSampleRate); 1.1562 +- return BAD_VALUE; 1.1563 +- } 1.1564 + } else { // mOutputFormat must be OUTPUT_FORMAT_AMR_WB 1.1565 + if (mAudioEncoder != AUDIO_ENCODER_AMR_WB) { 1.1566 + LOGE("Invlaid encoder %d used for AMRWB recording", 1.1567 + mAudioEncoder); 1.1568 + return BAD_VALUE; 1.1569 + } 1.1570 +- if (mSampleRate != 16000) { 1.1571 +- LOGE("Invalid sample rate %d used for AMRWB recording", 1.1572 +- mSampleRate); 1.1573 +- return BAD_VALUE; 1.1574 +- } 1.1575 +- } 1.1576 +- 1.1577 +- if (mAudioChannels != 1) { 1.1578 +- LOGE("Invalid number of audio channels %d used for amr recording", 1.1579 +- mAudioChannels); 1.1580 +- return BAD_VALUE; 1.1581 + } 1.1582 + 1.1583 + mWriter = new AMRWriter(mOutputFd); 1.1584 +@@ -1004,7 +844,7 @@ 1.1585 + return status; 1.1586 + } 1.1587 + 1.1588 +-status_t StagefrightRecorder::startRawAudioRecording() { 1.1589 ++status_t GonkRecorder::startRawAudioRecording() { 1.1590 + if (mAudioSource >= AUDIO_SOURCE_CNT) { 1.1591 + LOGE("Invalid audio source: %d", mAudioSource); 1.1592 + return BAD_VALUE; 1.1593 +@@ -1035,62 +875,7 @@ 1.1594 + return OK; 1.1595 + } 1.1596 + 1.1597 +-status_t StagefrightRecorder::startFMA2DPWriter() { 1.1598 +- /* FM soc outputs at 48k */ 1.1599 +- mSampleRate = 48000; 1.1600 +- mAudioChannels = 2; 1.1601 +- 1.1602 +- sp<MetaData> meta = new MetaData; 1.1603 +- meta->setInt32(kKeyChannelCount, mAudioChannels); 1.1604 +- meta->setInt32(kKeySampleRate, mSampleRate); 1.1605 +- 1.1606 +- mWriter = new FMA2DPWriter(); 1.1607 +- mWriter->setListener(mListener); 1.1608 +- mWriter->start(meta.get()); 1.1609 +- return OK; 1.1610 +-} 1.1611 +- 1.1612 +-status_t StagefrightRecorder::startRTPRecording() { 1.1613 +- CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_RTP_AVP); 1.1614 +- 1.1615 +- if ((mAudioSource != AUDIO_SOURCE_CNT 1.1616 +- && mVideoSource != VIDEO_SOURCE_LIST_END) 1.1617 +- || (mAudioSource == AUDIO_SOURCE_CNT 1.1618 +- && mVideoSource == VIDEO_SOURCE_LIST_END)) { 1.1619 +- // Must have exactly one source. 1.1620 +- return BAD_VALUE; 1.1621 +- } 1.1622 +- 1.1623 +- if (mOutputFd < 0) { 1.1624 +- return BAD_VALUE; 1.1625 +- } 1.1626 +- 1.1627 +- sp<MediaSource> source; 1.1628 +- 1.1629 +- if (mAudioSource != AUDIO_SOURCE_CNT) { 1.1630 +- source = createAudioSource(); 1.1631 +- } else { 1.1632 +- 1.1633 +- sp<MediaSource> mediaSource; 1.1634 +- status_t err = setupMediaSource(&mediaSource); 1.1635 +- if (err != OK) { 1.1636 +- return err; 1.1637 +- } 1.1638 +- 1.1639 +- err = setupVideoEncoder(mediaSource, mVideoBitRate, &source); 1.1640 +- if (err != OK) { 1.1641 +- return err; 1.1642 +- } 1.1643 +- } 1.1644 +- 1.1645 +- mWriter = new ARTPWriter(mOutputFd); 1.1646 +- mWriter->addSource(source); 1.1647 +- mWriter->setListener(mListener); 1.1648 +- 1.1649 +- return mWriter->start(); 1.1650 +-} 1.1651 +- 1.1652 +-status_t StagefrightRecorder::startMPEG2TSRecording() { 1.1653 ++status_t GonkRecorder::startMPEG2TSRecording() { 1.1654 + CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_MPEG2TS); 1.1655 + 1.1656 + sp<MediaWriter> writer = new MPEG2TSWriter(mOutputFd); 1.1657 +@@ -1141,7 +926,7 @@ 1.1658 + return mWriter->start(); 1.1659 + } 1.1660 + 1.1661 +-void StagefrightRecorder::clipVideoFrameRate() { 1.1662 ++void GonkRecorder::clipVideoFrameRate() { 1.1663 + LOGV("clipVideoFrameRate: encoder %d", mVideoEncoder); 1.1664 + int minFrameRate = mEncoderProfiles->getVideoEncoderParamByName( 1.1665 + "enc.vid.fps.min", mVideoEncoder); 1.1666 +@@ -1158,7 +943,7 @@ 1.1667 + } 1.1668 + } 1.1669 + 1.1670 +-void StagefrightRecorder::clipVideoBitRate() { 1.1671 ++void GonkRecorder::clipVideoBitRate() { 1.1672 + LOGV("clipVideoBitRate: encoder %d", mVideoEncoder); 1.1673 + int minBitRate = mEncoderProfiles->getVideoEncoderParamByName( 1.1674 + "enc.vid.bps.min", mVideoEncoder); 1.1675 +@@ -1175,7 +960,7 @@ 1.1676 + } 1.1677 + } 1.1678 + 1.1679 +-void StagefrightRecorder::clipVideoFrameWidth() { 1.1680 ++void GonkRecorder::clipVideoFrameWidth() { 1.1681 + LOGV("clipVideoFrameWidth: encoder %d", mVideoEncoder); 1.1682 + int minFrameWidth = mEncoderProfiles->getVideoEncoderParamByName( 1.1683 + "enc.vid.width.min", mVideoEncoder); 1.1684 +@@ -1192,8 +977,7 @@ 1.1685 + } 1.1686 + } 1.1687 + 1.1688 +-status_t StagefrightRecorder::checkVideoEncoderCapabilities() { 1.1689 +- if (!mCaptureTimeLapse) { 1.1690 ++status_t GonkRecorder::checkVideoEncoderCapabilities() { 1.1691 + // Dont clip for time lapse capture as encoder will have enough 1.1692 + // time to encode because of slow capture rate of time lapse. 1.1693 + clipVideoBitRate(); 1.1694 +@@ -1201,13 +985,12 @@ 1.1695 + clipVideoFrameWidth(); 1.1696 + clipVideoFrameHeight(); 1.1697 + setDefaultProfileIfNecessary(); 1.1698 +- } 1.1699 + return OK; 1.1700 + } 1.1701 + 1.1702 + // Set to use AVC baseline profile if the encoding parameters matches 1.1703 + // CAMCORDER_QUALITY_LOW profile; this is for the sake of MMS service. 1.1704 +-void StagefrightRecorder::setDefaultProfileIfNecessary() { 1.1705 ++void GonkRecorder::setDefaultProfileIfNecessary() { 1.1706 + LOGV("setDefaultProfileIfNecessary"); 1.1707 + 1.1708 + camcorder_quality quality = CAMCORDER_QUALITY_LOW; 1.1709 +@@ -1263,14 +1046,14 @@ 1.1710 + } 1.1711 + } 1.1712 + 1.1713 +-status_t StagefrightRecorder::checkAudioEncoderCapabilities() { 1.1714 ++status_t GonkRecorder::checkAudioEncoderCapabilities() { 1.1715 + clipAudioBitRate(); 1.1716 + clipAudioSampleRate(); 1.1717 + clipNumberOfAudioChannels(); 1.1718 + return OK; 1.1719 + } 1.1720 + 1.1721 +-void StagefrightRecorder::clipAudioBitRate() { 1.1722 ++void GonkRecorder::clipAudioBitRate() { 1.1723 + LOGV("clipAudioBitRate: encoder %d", mAudioEncoder); 1.1724 + 1.1725 + int minAudioBitRate = 1.1726 +@@ -1292,7 +1075,7 @@ 1.1727 + } 1.1728 + } 1.1729 + 1.1730 +-void StagefrightRecorder::clipAudioSampleRate() { 1.1731 ++void GonkRecorder::clipAudioSampleRate() { 1.1732 + LOGV("clipAudioSampleRate: encoder %d", mAudioEncoder); 1.1733 + 1.1734 + int minSampleRate = 1.1735 +@@ -1314,7 +1097,7 @@ 1.1736 + } 1.1737 + } 1.1738 + 1.1739 +-void StagefrightRecorder::clipNumberOfAudioChannels() { 1.1740 ++void GonkRecorder::clipNumberOfAudioChannels() { 1.1741 + LOGV("clipNumberOfAudioChannels: encoder %d", mAudioEncoder); 1.1742 + 1.1743 + int minChannels = 1.1744 +@@ -1336,7 +1119,7 @@ 1.1745 + } 1.1746 + } 1.1747 + 1.1748 +-void StagefrightRecorder::clipVideoFrameHeight() { 1.1749 ++void GonkRecorder::clipVideoFrameHeight() { 1.1750 + LOGV("clipVideoFrameHeight: encoder %d", mVideoEncoder); 1.1751 + int minFrameHeight = mEncoderProfiles->getVideoEncoderParamByName( 1.1752 + "enc.vid.height.min", mVideoEncoder); 1.1753 +@@ -1354,61 +1137,26 @@ 1.1754 + } 1.1755 + 1.1756 + // Set up the appropriate MediaSource depending on the chosen option 1.1757 +-status_t StagefrightRecorder::setupMediaSource( 1.1758 ++status_t GonkRecorder::setupMediaSource( 1.1759 + sp<MediaSource> *mediaSource) { 1.1760 + if (mVideoSource == VIDEO_SOURCE_DEFAULT 1.1761 + || mVideoSource == VIDEO_SOURCE_CAMERA) { 1.1762 +- sp<CameraSource> cameraSource; 1.1763 ++ sp<GonkCameraSource> cameraSource; 1.1764 + status_t err = setupCameraSource(&cameraSource); 1.1765 + if (err != OK) { 1.1766 + return err; 1.1767 + } 1.1768 + *mediaSource = cameraSource; 1.1769 + } else if (mVideoSource == VIDEO_SOURCE_GRALLOC_BUFFER) { 1.1770 +- // If using GRAlloc buffers, setup surfacemediasource. 1.1771 +- // Later a handle to that will be passed 1.1772 +- // to the client side when queried 1.1773 +- status_t err = setupSurfaceMediaSource(); 1.1774 +- if (err != OK) { 1.1775 +- return err; 1.1776 +- } 1.1777 +- *mediaSource = mSurfaceMediaSource; 1.1778 ++ return BAD_VALUE; 1.1779 + } else { 1.1780 + return INVALID_OPERATION; 1.1781 + } 1.1782 + return OK; 1.1783 + } 1.1784 + 1.1785 +-// setupSurfaceMediaSource creates a source with the given 1.1786 +-// width and height and framerate. 1.1787 +-// TODO: This could go in a static function inside SurfaceMediaSource 1.1788 +-// similar to that in CameraSource 1.1789 +-status_t StagefrightRecorder::setupSurfaceMediaSource() { 1.1790 +- status_t err = OK; 1.1791 +- mSurfaceMediaSource = new SurfaceMediaSource(mVideoWidth, mVideoHeight); 1.1792 +- if (mSurfaceMediaSource == NULL) { 1.1793 +- return NO_INIT; 1.1794 +- } 1.1795 +- 1.1796 +- if (mFrameRate == -1) { 1.1797 +- int32_t frameRate = 0; 1.1798 +- CHECK (mSurfaceMediaSource->getFormat()->findInt32( 1.1799 +- kKeyFrameRate, &frameRate)); 1.1800 +- LOGI("Frame rate is not explicitly set. Use the current frame " 1.1801 +- "rate (%d fps)", frameRate); 1.1802 +- mFrameRate = frameRate; 1.1803 +- } else { 1.1804 +- err = mSurfaceMediaSource->setFrameRate(mFrameRate); 1.1805 +- } 1.1806 +- CHECK(mFrameRate != -1); 1.1807 +- 1.1808 +- mIsMetaDataStoredInVideoBuffers = 1.1809 +- mSurfaceMediaSource->isMetaDataStoredInVideoBuffers(); 1.1810 +- return err; 1.1811 +-} 1.1812 +- 1.1813 +-status_t StagefrightRecorder::setupCameraSource( 1.1814 +- sp<CameraSource> *cameraSource) { 1.1815 ++status_t GonkRecorder::setupCameraSource( 1.1816 ++ sp<GonkCameraSource> *cameraSource) { 1.1817 + status_t err = OK; 1.1818 + if ((err = checkVideoEncoderCapabilities()) != OK) { 1.1819 + return err; 1.1820 +@@ -1416,26 +1164,15 @@ 1.1821 + Size videoSize; 1.1822 + videoSize.width = mVideoWidth; 1.1823 + videoSize.height = mVideoHeight; 1.1824 +- if (mCaptureTimeLapse) { 1.1825 +- mCameraSourceTimeLapse = CameraSourceTimeLapse::CreateFromCamera( 1.1826 +- mCamera, mCameraProxy, mCameraId, 1.1827 +- videoSize, mFrameRate, mPreviewSurface, 1.1828 +- mTimeBetweenTimeLapseFrameCaptureUs); 1.1829 +- *cameraSource = mCameraSourceTimeLapse; 1.1830 +- } else { 1.1831 +- 1.1832 +- bool useMeta = true; 1.1833 +- char value[PROPERTY_VALUE_MAX]; 1.1834 +- if (property_get("debug.camcorder.disablemeta", value, NULL) && 1.1835 ++ bool useMeta = true; 1.1836 ++ char value[PROPERTY_VALUE_MAX]; 1.1837 ++ if (property_get("debug.camcorder.disablemeta", value, NULL) && 1.1838 + atoi(value)) { 1.1839 +- useMeta = false; 1.1840 +- } 1.1841 +- *cameraSource = CameraSource::CreateFromCamera( 1.1842 +- mCamera, mCameraProxy, mCameraId, videoSize, mFrameRate, 1.1843 +- mPreviewSurface, useMeta); 1.1844 ++ useMeta = false; 1.1845 + } 1.1846 +- mCamera.clear(); 1.1847 +- mCameraProxy.clear(); 1.1848 ++ 1.1849 ++ *cameraSource = GonkCameraSource::Create( 1.1850 ++ mCameraHandle, videoSize, mFrameRate, useMeta); 1.1851 + if (*cameraSource == NULL) { 1.1852 + return UNKNOWN_ERROR; 1.1853 + } 1.1854 +@@ -1465,7 +1202,7 @@ 1.1855 + return OK; 1.1856 + } 1.1857 + 1.1858 +-status_t StagefrightRecorder::setupVideoEncoder( 1.1859 ++status_t GonkRecorder::setupVideoEncoder( 1.1860 + sp<MediaSource> cameraSource, 1.1861 + int32_t videoBitRate, 1.1862 + sp<MediaSource> *source) { 1.1863 +@@ -1501,10 +1238,7 @@ 1.1864 + CHECK(meta->findInt32(kKeyStride, &stride)); 1.1865 + CHECK(meta->findInt32(kKeySliceHeight, &sliceHeight)); 1.1866 + CHECK(meta->findInt32(kKeyColorFormat, &colorFormat)); 1.1867 +- hfr = 0; 1.1868 +- if (!meta->findInt32(kKeyHFR, &hfr)) { 1.1869 +- LOGW("hfr not found, default to 0"); 1.1870 +- } 1.1871 ++ CHECK(meta->findInt32(kKeyHFR, &hfr)); 1.1872 + 1.1873 + if(hfr) { 1.1874 + mMaxFileDurationUs = mMaxFileDurationUs * (hfr/mFrameRate); 1.1875 +@@ -1598,30 +1332,17 @@ 1.1876 + enc_meta->setInt32(kKey3D, is3D); 1.1877 + } 1.1878 + 1.1879 +- OMXClient client; 1.1880 +- CHECK_EQ(client.connect(), OK); 1.1881 +- 1.1882 + uint32_t encoder_flags = 0; 1.1883 + if (mIsMetaDataStoredInVideoBuffers) { 1.1884 + LOGW("Camera source supports metadata mode, create OMXCodec for metadata"); 1.1885 + encoder_flags |= OMXCodec::kHardwareCodecsOnly; 1.1886 + encoder_flags |= OMXCodec::kStoreMetaDataInVideoBuffers; 1.1887 +- if (property_get("ro.board.platform", value, "0") 1.1888 +- && (!strncmp(value, "msm7627", sizeof("msm7627") - 1))) { 1.1889 +- LOGW("msm7627 family of chipsets supports, only one buffer at a time"); 1.1890 +- encoder_flags |= OMXCodec::kOnlySubmitOneInputBufferAtOneTime; 1.1891 +- } 1.1892 +- } 1.1893 +- 1.1894 +- // Do not wait for all the input buffers to become available. 1.1895 +- // This give timelapse video recording faster response in 1.1896 +- // receiving output from video encoder component. 1.1897 +- if (mCaptureTimeLapse) { 1.1898 + encoder_flags |= OMXCodec::kOnlySubmitOneInputBufferAtOneTime; 1.1899 + } 1.1900 + 1.1901 + sp<MediaSource> encoder = OMXCodec::Create( 1.1902 +- client.interface(), enc_meta, 1.1903 ++ GetOMX(), 1.1904 ++ enc_meta, 1.1905 + true /* createEncoder */, cameraSource, 1.1906 + NULL, encoder_flags); 1.1907 + if (encoder == NULL) { 1.1908 +@@ -1638,7 +1359,7 @@ 1.1909 + return OK; 1.1910 + } 1.1911 + 1.1912 +-status_t StagefrightRecorder::setupAudioEncoder(const sp<MediaWriter>& writer) { 1.1913 ++status_t GonkRecorder::setupAudioEncoder(const sp<MediaWriter>& writer) { 1.1914 + status_t status = BAD_VALUE; 1.1915 + if (OK != (status = checkAudioEncoderCapabilities())) { 1.1916 + return status; 1.1917 +@@ -1664,7 +1385,7 @@ 1.1918 + return OK; 1.1919 + } 1.1920 + 1.1921 +-status_t StagefrightRecorder::setupMPEG4Recording( 1.1922 ++status_t GonkRecorder::setupMPEG4Recording( 1.1923 + int outputFd, 1.1924 + int32_t videoWidth, int32_t videoHeight, 1.1925 + int32_t videoBitRate, 1.1926 +@@ -1696,7 +1417,7 @@ 1.1927 + // Audio source is added at the end if it exists. 1.1928 + // This help make sure that the "recoding" sound is suppressed for 1.1929 + // camcorder applications in the recorded files. 1.1930 +- if (!mCaptureTimeLapse && (mAudioSource != AUDIO_SOURCE_CNT)) { 1.1931 ++ if (mAudioSource != AUDIO_SOURCE_CNT) { 1.1932 + err = setupAudioEncoder(writer); 1.1933 + if (err != OK) return err; 1.1934 + *totalBitRate += mAudioBitRate; 1.1935 +@@ -1728,7 +1449,7 @@ 1.1936 + return OK; 1.1937 + } 1.1938 + 1.1939 +-void StagefrightRecorder::setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, 1.1940 ++void GonkRecorder::setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, 1.1941 + sp<MetaData> *meta) { 1.1942 + (*meta)->setInt64(kKeyTime, startTimeUs); 1.1943 + (*meta)->setInt32(kKeyFileType, mOutputFormat); 1.1944 +@@ -1752,7 +1473,7 @@ 1.1945 + } 1.1946 + } 1.1947 + 1.1948 +-status_t StagefrightRecorder::startMPEG4Recording() { 1.1949 ++status_t GonkRecorder::startMPEG4Recording() { 1.1950 + int32_t totalBitRate; 1.1951 + status_t err = setupMPEG4Recording( 1.1952 + mOutputFd, mVideoWidth, mVideoHeight, 1.1953 +@@ -1761,7 +1482,14 @@ 1.1954 + return err; 1.1955 + } 1.1956 + 1.1957 +- int64_t startTimeUs = systemTime() / 1000; 1.1958 ++ //systemTime() doesn't give correct time because 1.1959 ++ //HAVE_POSIX_CLOCKS is not defined for utils/Timers.cpp 1.1960 ++ //so, using clock_gettime directly 1.1961 ++#include <time.h> 1.1962 ++ struct timespec t; 1.1963 ++ clock_gettime(CLOCK_MONOTONIC, &t); 1.1964 ++ int64_t startTimeUs = int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; 1.1965 ++ startTimeUs = startTimeUs / 1000; 1.1966 + sp<MetaData> meta = new MetaData; 1.1967 + setupMPEG4MetaData(startTimeUs, totalBitRate, &meta); 1.1968 + 1.1969 +@@ -1773,7 +1501,7 @@ 1.1970 + return OK; 1.1971 + } 1.1972 + 1.1973 +-status_t StagefrightRecorder::pause() { 1.1974 ++status_t GonkRecorder::pause() { 1.1975 + LOGV("pause"); 1.1976 + if (mWriter == NULL) { 1.1977 + return UNKNOWN_ERROR; 1.1978 +@@ -1782,31 +1510,16 @@ 1.1979 + 1.1980 + if (mStarted) { 1.1981 + mStarted = false; 1.1982 +- 1.1983 +- uint32_t params = 0; 1.1984 +- if (mAudioSource != AUDIO_SOURCE_CNT) { 1.1985 +- params |= IMediaPlayerService::kBatteryDataTrackAudio; 1.1986 +- } 1.1987 +- if (mVideoSource != VIDEO_SOURCE_LIST_END) { 1.1988 +- params |= IMediaPlayerService::kBatteryDataTrackVideo; 1.1989 +- } 1.1990 +- 1.1991 +- addBatteryData(params); 1.1992 + } 1.1993 + 1.1994 + 1.1995 + return OK; 1.1996 + } 1.1997 + 1.1998 +-status_t StagefrightRecorder::stop() { 1.1999 ++status_t GonkRecorder::stop() { 1.2000 + LOGV("stop"); 1.2001 + status_t err = OK; 1.2002 + 1.2003 +- if (mCaptureTimeLapse && mCameraSourceTimeLapse != NULL) { 1.2004 +- mCameraSourceTimeLapse->startQuickReadReturns(); 1.2005 +- mCameraSourceTimeLapse = NULL; 1.2006 +- } 1.2007 +- 1.2008 + if (mWriter != NULL) { 1.2009 + err = mWriter->stop(); 1.2010 + mWriter.clear(); 1.2011 +@@ -1819,30 +1532,20 @@ 1.2012 + 1.2013 + if (mStarted) { 1.2014 + mStarted = false; 1.2015 +- 1.2016 +- uint32_t params = 0; 1.2017 +- if (mAudioSource != AUDIO_SOURCE_CNT) { 1.2018 +- params |= IMediaPlayerService::kBatteryDataTrackAudio; 1.2019 +- } 1.2020 +- if (mVideoSource != VIDEO_SOURCE_LIST_END) { 1.2021 +- params |= IMediaPlayerService::kBatteryDataTrackVideo; 1.2022 +- } 1.2023 +- 1.2024 +- addBatteryData(params); 1.2025 + } 1.2026 + 1.2027 + 1.2028 + return err; 1.2029 + } 1.2030 + 1.2031 +-status_t StagefrightRecorder::close() { 1.2032 ++status_t GonkRecorder::close() { 1.2033 + LOGV("close"); 1.2034 + stop(); 1.2035 + 1.2036 + return OK; 1.2037 + } 1.2038 + 1.2039 +-status_t StagefrightRecorder::reset() { 1.2040 ++status_t GonkRecorder::reset() { 1.2041 + LOGV("reset"); 1.2042 + stop(); 1.2043 + 1.2044 +@@ -1858,9 +1561,9 @@ 1.2045 + mVideoHeight = 144; 1.2046 + mFrameRate = -1; 1.2047 + mVideoBitRate = 192000; 1.2048 +- mSampleRate = 0; 1.2049 +- mAudioChannels = 0; 1.2050 +- mAudioBitRate = 0; 1.2051 ++ mSampleRate = 8000; 1.2052 ++ mAudioChannels = 1; 1.2053 ++ mAudioBitRate = 12200; 1.2054 + mInterleaveDurationUs = 0; 1.2055 + mIFramesIntervalSec = 2; 1.2056 + mAudioSourceNode = 0; 1.2057 +@@ -1875,9 +1578,6 @@ 1.2058 + mMaxFileDurationUs = 0; 1.2059 + mMaxFileSizeBytes = 0; 1.2060 + mTrackEveryTimeDurationUs = 0; 1.2061 +- mCaptureTimeLapse = false; 1.2062 +- mTimeBetweenTimeLapseFrameCaptureUs = -1; 1.2063 +- mCameraSourceTimeLapse = NULL; 1.2064 + mIsMetaDataStoredInVideoBuffers = false; 1.2065 + mEncoderProfiles = MediaProfiles::getInstance(); 1.2066 + mRotationDegrees = 0; 1.2067 +@@ -1885,6 +1585,11 @@ 1.2068 + mLongitudex10000 = -3600000; 1.2069 + 1.2070 + mOutputFd = -1; 1.2071 ++ mCameraHandle = -1; 1.2072 ++ //TODO: May need to register a listener eventually 1.2073 ++ //if someone is interested in recorder events for now 1.2074 ++ //default to no listener registered 1.2075 ++ mListener = NULL; 1.2076 + 1.2077 + // Disable Audio Encoding 1.2078 + char value[PROPERTY_VALUE_MAX]; 1.2079 +@@ -1894,7 +1599,7 @@ 1.2080 + return OK; 1.2081 + } 1.2082 + 1.2083 +-status_t StagefrightRecorder::getMaxAmplitude(int *max) { 1.2084 ++status_t GonkRecorder::getMaxAmplitude(int *max) { 1.2085 + LOGV("getMaxAmplitude"); 1.2086 + 1.2087 + if (max == NULL) { 1.2088 +@@ -1911,7 +1616,7 @@ 1.2089 + return OK; 1.2090 + } 1.2091 + 1.2092 +-status_t StagefrightRecorder::dump( 1.2093 ++status_t GonkRecorder::dump( 1.2094 + int fd, const Vector<String16>& args) const { 1.2095 + LOGV("dump"); 1.2096 + const size_t SIZE = 256; 1.2097 +@@ -1958,6 +1663,8 @@ 1.2098 + result.append(buffer); 1.2099 + snprintf(buffer, SIZE, " Camera Id: %d\n", mCameraId); 1.2100 + result.append(buffer); 1.2101 ++ snprintf(buffer, SIZE, " Camera Handle: %d\n", mCameraHandle); 1.2102 ++ result.append(buffer); 1.2103 + snprintf(buffer, SIZE, " Start time offset (ms): %d\n", mStartTimeOffsetMs); 1.2104 + result.append(buffer); 1.2105 + snprintf(buffer, SIZE, " Encoder: %d\n", mVideoEncoder); 1.2106 +@@ -1978,45 +1685,12 @@ 1.2107 + return OK; 1.2108 + } 1.2109 + 1.2110 +-status_t StagefrightRecorder::startExtendedRecording() { 1.2111 +- CHECK(mOutputFormat == OUTPUT_FORMAT_QCP); 1.2112 +- 1.2113 +- if (mSampleRate != 8000) { 1.2114 +- LOGE("Invalid sampling rate %d used for recording", 1.2115 +- mSampleRate); 1.2116 +- return BAD_VALUE; 1.2117 +- } 1.2118 +- if (mAudioChannels != 1) { 1.2119 +- LOGE("Invalid number of audio channels %d used for recording", 1.2120 +- mAudioChannels); 1.2121 +- return BAD_VALUE; 1.2122 +- } 1.2123 +- 1.2124 +- if (mAudioSource >= AUDIO_SOURCE_CNT) { 1.2125 +- LOGE("Invalid audio source: %d", mAudioSource); 1.2126 +- return BAD_VALUE; 1.2127 +- } 1.2128 +- 1.2129 +- sp<MediaSource> audioEncoder = createAudioSource(); 1.2130 +- 1.2131 +- if (audioEncoder == NULL) { 1.2132 +- LOGE("AudioEncoder NULL"); 1.2133 +- return UNKNOWN_ERROR; 1.2134 +- } 1.2135 +- 1.2136 +- mWriter = new ExtendedWriter(dup(mOutputFd)); 1.2137 +- mWriter->addSource(audioEncoder); 1.2138 +- 1.2139 +- if (mMaxFileDurationUs != 0) { 1.2140 +- mWriter->setMaxFileDuration(mMaxFileDurationUs); 1.2141 +- } 1.2142 +- if (mMaxFileSizeBytes != 0) { 1.2143 +- mWriter->setMaxFileSize(mMaxFileSizeBytes); 1.2144 +- } 1.2145 +- mWriter->setListener(mListener); 1.2146 +- mWriter->start(); 1.2147 +- 1.2148 +- return OK; 1.2149 ++status_t GonkRecorder::setCameraHandle(int32_t handle) { 1.2150 ++ if (handle < 0) { 1.2151 ++ return BAD_VALUE; 1.2152 ++ } 1.2153 ++ mCameraHandle = handle; 1.2154 ++ return OK; 1.2155 + } 1.2156 + 1.2157 + } // namespace android 1.2158 +diff --git a/GonkRecorder.h b/GonkRecorder.h 1.2159 +index dba6110..fa948af 100644 1.2160 +--- a/GonkRecorder.h 1.2161 ++++ b/GonkRecorder.h 1.2162 +@@ -14,11 +14,11 @@ 1.2163 + * limitations under the License. 1.2164 + */ 1.2165 + 1.2166 +-#ifndef STAGEFRIGHT_RECORDER_H_ 1.2167 ++#ifndef GONK_RECORDER_H_ 1.2168 + 1.2169 +-#define STAGEFRIGHT_RECORDER_H_ 1.2170 ++#define GONK_RECORDER_H_ 1.2171 + 1.2172 +-#include <media/MediaRecorderBase.h> 1.2173 ++#include <media/mediarecorder.h> 1.2174 + #include <camera/CameraParameters.h> 1.2175 + #include <utils/String8.h> 1.2176 + 1.2177 +@@ -26,21 +26,16 @@ 1.2178 + 1.2179 + namespace android { 1.2180 + 1.2181 +-class Camera; 1.2182 +-class ICameraRecordingProxy; 1.2183 +-class CameraSource; 1.2184 +-class CameraSourceTimeLapse; 1.2185 ++class GonkCameraSource; 1.2186 + struct MediaSource; 1.2187 + struct MediaWriter; 1.2188 + class MetaData; 1.2189 + struct AudioSource; 1.2190 + class MediaProfiles; 1.2191 +-class ISurfaceTexture; 1.2192 +-class SurfaceMediaSource; 1.2193 + 1.2194 +-struct StagefrightRecorder : public MediaRecorderBase { 1.2195 +- StagefrightRecorder(); 1.2196 +- virtual ~StagefrightRecorder(); 1.2197 ++struct GonkRecorder { 1.2198 ++ GonkRecorder(); 1.2199 ++ virtual ~GonkRecorder(); 1.2200 + 1.2201 + virtual status_t init(); 1.2202 + virtual status_t setAudioSource(audio_source_t as); 1.2203 +@@ -50,11 +45,10 @@ 1.2204 + virtual status_t setVideoEncoder(video_encoder ve); 1.2205 + virtual status_t setVideoSize(int width, int height); 1.2206 + virtual status_t setVideoFrameRate(int frames_per_second); 1.2207 +- virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy); 1.2208 +- virtual status_t setPreviewSurface(const sp<Surface>& surface); 1.2209 + virtual status_t setOutputFile(const char *path); 1.2210 + virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); 1.2211 + virtual status_t setParameters(const String8& params); 1.2212 ++ virtual status_t setCameraHandle(int32_t handle); 1.2213 + virtual status_t setListener(const sp<IMediaRecorderClient>& listener); 1.2214 + virtual status_t prepare(); 1.2215 + virtual status_t start(); 1.2216 +@@ -65,12 +59,8 @@ 1.2217 + virtual status_t getMaxAmplitude(int *max); 1.2218 + virtual status_t dump(int fd, const Vector<String16>& args) const; 1.2219 + // Querying a SurfaceMediaSourcer 1.2220 +- virtual sp<ISurfaceTexture> querySurfaceMediaSource() const; 1.2221 + 1.2222 + private: 1.2223 +- sp<ICamera> mCamera; 1.2224 +- sp<ICameraRecordingProxy> mCameraProxy; 1.2225 +- sp<Surface> mPreviewSurface; 1.2226 + sp<IMediaRecorderClient> mListener; 1.2227 + sp<MediaWriter> mWriter; 1.2228 + int mOutputFd; 1.2229 +@@ -104,11 +94,6 @@ 1.2230 + int32_t mLongitudex10000; 1.2231 + int32_t mStartTimeOffsetMs; 1.2232 + 1.2233 +- bool mCaptureTimeLapse; 1.2234 +- int64_t mTimeBetweenTimeLapseFrameCaptureUs; 1.2235 +- sp<CameraSourceTimeLapse> mCameraSourceTimeLapse; 1.2236 +- 1.2237 +- 1.2238 + String8 mParams; 1.2239 + 1.2240 + bool mIsMetaDataStoredInVideoBuffers; 1.2241 +@@ -119,8 +104,8 @@ 1.2242 + // An <ISurfaceTexture> pointer 1.2243 + // will be sent to the client side using which the 1.2244 + // frame buffers will be queued and dequeued 1.2245 +- sp<SurfaceMediaSource> mSurfaceMediaSource; 1.2246 + bool mDisableAudio; 1.2247 ++ int32_t mCameraHandle; 1.2248 + 1.2249 + status_t setupMPEG4Recording( 1.2250 + int outputFd, 1.2251 +@@ -132,10 +117,7 @@ 1.2252 + sp<MetaData> *meta); 1.2253 + status_t startMPEG4Recording(); 1.2254 + status_t startAMRRecording(); 1.2255 +- status_t startFMA2DPWriter(); 1.2256 +- status_t startAACRecording(); 1.2257 + status_t startRawAudioRecording(); 1.2258 +- status_t startRTPRecording(); 1.2259 + status_t startMPEG2TSRecording(); 1.2260 + sp<MediaSource> createAudioSource(); 1.2261 + status_t checkVideoEncoderCapabilities(); 1.2262 +@@ -144,9 +126,8 @@ 1.2263 + // source (CameraSource or SurfaceMediaSource) 1.2264 + // depending on the videosource type 1.2265 + status_t setupMediaSource(sp<MediaSource> *mediaSource); 1.2266 +- status_t setupCameraSource(sp<CameraSource> *cameraSource); 1.2267 ++ status_t setupCameraSource(sp<GonkCameraSource> *cameraSource); 1.2268 + // setup the surfacemediasource for the encoder 1.2269 +- status_t setupSurfaceMediaSource(); 1.2270 + 1.2271 + status_t setupAudioEncoder(const sp<MediaWriter>& writer); 1.2272 + status_t setupVideoEncoder( 1.2273 +@@ -160,8 +141,6 @@ 1.2274 + status_t setParamAudioNumberOfChannels(int32_t channles); 1.2275 + status_t setParamAudioSamplingRate(int32_t sampleRate); 1.2276 + status_t setParamAudioTimeScale(int32_t timeScale); 1.2277 +- status_t setParamTimeLapseEnable(int32_t timeLapseEnable); 1.2278 +- status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs); 1.2279 + status_t setParamVideoEncodingBitRate(int32_t bitRate); 1.2280 + status_t setParamVideoIFramesInterval(int32_t seconds); 1.2281 + status_t setParamVideoEncoderProfile(int32_t profile); 1.2282 +@@ -186,14 +165,10 @@ 1.2283 + void clipNumberOfAudioChannels(); 1.2284 + void setDefaultProfileIfNecessary(); 1.2285 + 1.2286 +- 1.2287 +- StagefrightRecorder(const StagefrightRecorder &); 1.2288 +- StagefrightRecorder &operator=(const StagefrightRecorder &); 1.2289 +- 1.2290 +- /* extension */ 1.2291 +- status_t startExtendedRecording(); 1.2292 ++ GonkRecorder(const GonkRecorder &); 1.2293 ++ GonkRecorder &operator=(const GonkRecorder &); 1.2294 + }; 1.2295 + 1.2296 + } // namespace android 1.2297 + 1.2298 +-#endif // STAGEFRIGHT_RECORDER_H_ 1.2299 ++#endif // GONK_RECORDER_H_