Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | diff --git a/GonkCameraListener.h b/GonkCameraListener.h |
michael@0 | 2 | index 67eeef3..243264c 100644 |
michael@0 | 3 | --- a/GonkCameraListener.h |
michael@0 | 4 | +++ b/GonkCameraListener.h |
michael@0 | 5 | @@ -14,49 +14,16 @@ |
michael@0 | 6 | * limitations under the License. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | -#ifndef ANDROID_HARDWARE_CAMERA_H |
michael@0 | 10 | -#define ANDROID_HARDWARE_CAMERA_H |
michael@0 | 11 | +#ifndef GONK_CAMERA_LISTENER_H |
michael@0 | 12 | +#define GONK_CAMERA_LISTENER_H |
michael@0 | 13 | |
michael@0 | 14 | #include <utils/Timers.h> |
michael@0 | 15 | -#include <gui/ISurfaceTexture.h> |
michael@0 | 16 | -#include <system/camera.h> |
michael@0 | 17 | -#include <camera/ICameraClient.h> |
michael@0 | 18 | -#include <camera/ICameraRecordingProxy.h> |
michael@0 | 19 | -#include <camera/ICameraRecordingProxyListener.h> |
michael@0 | 20 | +#include "libcameraservice/CameraHardwareInterface.h" |
michael@0 | 21 | |
michael@0 | 22 | namespace android { |
michael@0 | 23 | |
michael@0 | 24 | -struct CameraInfo { |
michael@0 | 25 | - /** |
michael@0 | 26 | - * The direction that the camera faces to. It should be CAMERA_FACING_BACK |
michael@0 | 27 | - * or CAMERA_FACING_FRONT. |
michael@0 | 28 | - */ |
michael@0 | 29 | - int facing; |
michael@0 | 30 | - |
michael@0 | 31 | - /** |
michael@0 | 32 | - * The orientation of the camera image. The value is the angle that the |
michael@0 | 33 | - * camera image needs to be rotated clockwise so it shows correctly on the |
michael@0 | 34 | - * display in its natural orientation. It should be 0, 90, 180, or 270. |
michael@0 | 35 | - * |
michael@0 | 36 | - * For example, suppose a device has a naturally tall screen. The |
michael@0 | 37 | - * back-facing camera sensor is mounted in landscape. You are looking at |
michael@0 | 38 | - * the screen. If the top side of the camera sensor is aligned with the |
michael@0 | 39 | - * right edge of the screen in natural orientation, the value should be |
michael@0 | 40 | - * 90. If the top side of a front-facing camera sensor is aligned with the |
michael@0 | 41 | - * right of the screen, the value should be 270. |
michael@0 | 42 | - */ |
michael@0 | 43 | - int orientation; |
michael@0 | 44 | - int mode; |
michael@0 | 45 | -}; |
michael@0 | 46 | - |
michael@0 | 47 | -class ICameraService; |
michael@0 | 48 | -class ICamera; |
michael@0 | 49 | -class Surface; |
michael@0 | 50 | -class Mutex; |
michael@0 | 51 | -class String8; |
michael@0 | 52 | - |
michael@0 | 53 | // ref-counted object for callbacks |
michael@0 | 54 | -class CameraListener: virtual public RefBase |
michael@0 | 55 | +class GonkCameraListener: virtual public RefBase |
michael@0 | 56 | { |
michael@0 | 57 | public: |
michael@0 | 58 | virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0; |
michael@0 | 59 | @@ -65,133 +32,6 @@ public: |
michael@0 | 60 | virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0; |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | -class Camera : public BnCameraClient, public IBinder::DeathRecipient |
michael@0 | 64 | -{ |
michael@0 | 65 | -public: |
michael@0 | 66 | - // construct a camera client from an existing remote |
michael@0 | 67 | - static sp<Camera> create(const sp<ICamera>& camera); |
michael@0 | 68 | - static int32_t getNumberOfCameras(); |
michael@0 | 69 | - static status_t getCameraInfo(int cameraId, |
michael@0 | 70 | - struct CameraInfo* cameraInfo); |
michael@0 | 71 | - static sp<Camera> connect(int cameraId); |
michael@0 | 72 | - virtual ~Camera(); |
michael@0 | 73 | - void init(); |
michael@0 | 74 | - |
michael@0 | 75 | - status_t reconnect(); |
michael@0 | 76 | - void disconnect(); |
michael@0 | 77 | - status_t lock(); |
michael@0 | 78 | - status_t unlock(); |
michael@0 | 79 | - |
michael@0 | 80 | - status_t getStatus() { return mStatus; } |
michael@0 | 81 | - |
michael@0 | 82 | - // pass the buffered Surface to the camera service |
michael@0 | 83 | - status_t setPreviewDisplay(const sp<Surface>& surface); |
michael@0 | 84 | - |
michael@0 | 85 | - // pass the buffered ISurfaceTexture to the camera service |
michael@0 | 86 | - status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture); |
michael@0 | 87 | - |
michael@0 | 88 | - // start preview mode, must call setPreviewDisplay first |
michael@0 | 89 | - status_t startPreview(); |
michael@0 | 90 | - |
michael@0 | 91 | - // stop preview mode |
michael@0 | 92 | - void stopPreview(); |
michael@0 | 93 | - |
michael@0 | 94 | - // get preview state |
michael@0 | 95 | - bool previewEnabled(); |
michael@0 | 96 | - |
michael@0 | 97 | - // start recording mode, must call setPreviewDisplay first |
michael@0 | 98 | - status_t startRecording(); |
michael@0 | 99 | - |
michael@0 | 100 | - // stop recording mode |
michael@0 | 101 | - void stopRecording(); |
michael@0 | 102 | - |
michael@0 | 103 | - // get recording state |
michael@0 | 104 | - bool recordingEnabled(); |
michael@0 | 105 | - |
michael@0 | 106 | - // release a recording frame |
michael@0 | 107 | - void releaseRecordingFrame(const sp<IMemory>& mem); |
michael@0 | 108 | - |
michael@0 | 109 | - // autoFocus - status returned from callback |
michael@0 | 110 | - status_t autoFocus(); |
michael@0 | 111 | - |
michael@0 | 112 | - // cancel auto focus |
michael@0 | 113 | - status_t cancelAutoFocus(); |
michael@0 | 114 | - |
michael@0 | 115 | - // take a picture - picture returned from callback |
michael@0 | 116 | - status_t takePicture(int msgType); |
michael@0 | 117 | - |
michael@0 | 118 | - // set preview/capture parameters - key/value pairs |
michael@0 | 119 | - status_t setParameters(const String8& params); |
michael@0 | 120 | - |
michael@0 | 121 | - // get preview/capture parameters - key/value pairs |
michael@0 | 122 | - String8 getParameters() const; |
michael@0 | 123 | - |
michael@0 | 124 | - // send command to camera driver |
michael@0 | 125 | - status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); |
michael@0 | 126 | - |
michael@0 | 127 | - // tell camera hal to store meta data or real YUV in video buffers. |
michael@0 | 128 | - status_t storeMetaDataInBuffers(bool enabled); |
michael@0 | 129 | - |
michael@0 | 130 | - void setListener(const sp<CameraListener>& listener); |
michael@0 | 131 | - void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); |
michael@0 | 132 | - void setPreviewCallbackFlags(int preview_callback_flag); |
michael@0 | 133 | - |
michael@0 | 134 | - sp<ICameraRecordingProxy> getRecordingProxy(); |
michael@0 | 135 | - |
michael@0 | 136 | - // ICameraClient interface |
michael@0 | 137 | - virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); |
michael@0 | 138 | - virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, |
michael@0 | 139 | - camera_frame_metadata_t *metadata); |
michael@0 | 140 | - virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); |
michael@0 | 141 | - |
michael@0 | 142 | - sp<ICamera> remote(); |
michael@0 | 143 | - |
michael@0 | 144 | - class RecordingProxy : public BnCameraRecordingProxy |
michael@0 | 145 | - { |
michael@0 | 146 | - public: |
michael@0 | 147 | - RecordingProxy(const sp<Camera>& camera); |
michael@0 | 148 | - |
michael@0 | 149 | - // ICameraRecordingProxy interface |
michael@0 | 150 | - virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener); |
michael@0 | 151 | - virtual void stopRecording(); |
michael@0 | 152 | - virtual void releaseRecordingFrame(const sp<IMemory>& mem); |
michael@0 | 153 | - |
michael@0 | 154 | - private: |
michael@0 | 155 | - sp<Camera> mCamera; |
michael@0 | 156 | - }; |
michael@0 | 157 | - |
michael@0 | 158 | -private: |
michael@0 | 159 | - Camera(); |
michael@0 | 160 | - Camera(const Camera&); |
michael@0 | 161 | - Camera& operator=(const Camera); |
michael@0 | 162 | - virtual void binderDied(const wp<IBinder>& who); |
michael@0 | 163 | - |
michael@0 | 164 | - class DeathNotifier: public IBinder::DeathRecipient |
michael@0 | 165 | - { |
michael@0 | 166 | - public: |
michael@0 | 167 | - DeathNotifier() { |
michael@0 | 168 | - } |
michael@0 | 169 | - |
michael@0 | 170 | - virtual void binderDied(const wp<IBinder>& who); |
michael@0 | 171 | - }; |
michael@0 | 172 | - |
michael@0 | 173 | - static sp<DeathNotifier> mDeathNotifier; |
michael@0 | 174 | - |
michael@0 | 175 | - // helper function to obtain camera service handle |
michael@0 | 176 | - static const sp<ICameraService>& getCameraService(); |
michael@0 | 177 | - |
michael@0 | 178 | - sp<ICamera> mCamera; |
michael@0 | 179 | - status_t mStatus; |
michael@0 | 180 | - |
michael@0 | 181 | - sp<CameraListener> mListener; |
michael@0 | 182 | - sp<ICameraRecordingProxyListener> mRecordingProxyListener; |
michael@0 | 183 | - |
michael@0 | 184 | - friend class DeathNotifier; |
michael@0 | 185 | - |
michael@0 | 186 | - static Mutex mLock; |
michael@0 | 187 | - static sp<ICameraService> mCameraService; |
michael@0 | 188 | -}; |
michael@0 | 189 | - |
michael@0 | 190 | }; // namespace android |
michael@0 | 191 | |
michael@0 | 192 | #endif |
michael@0 | 193 | diff --git a/GonkCameraSource.cpp b/GonkCameraSource.cpp |
michael@0 | 194 | index af6b340..9dba596 100644 |
michael@0 | 195 | --- a/GonkCameraSource.cpp |
michael@0 | 196 | +++ b/GonkCameraSource.cpp |
michael@0 | 197 | @@ -14,29 +14,34 @@ |
michael@0 | 198 | * limitations under the License. |
michael@0 | 199 | */ |
michael@0 | 200 | |
michael@0 | 201 | -//#define LOG_NDEBUG 0 |
michael@0 | 202 | -#define LOG_TAG "CameraSource" |
michael@0 | 203 | -#include <utils/Log.h> |
michael@0 | 204 | +#include <base/basictypes.h> |
michael@0 | 205 | +#include "nsDebug.h" |
michael@0 | 206 | +#define DOM_CAMERA_LOG_LEVEL 3 |
michael@0 | 207 | +#include "CameraCommon.h" |
michael@0 | 208 | +#define LOGD DOM_CAMERA_LOGA |
michael@0 | 209 | +#define LOGV DOM_CAMERA_LOGI |
michael@0 | 210 | +#define LOGI DOM_CAMERA_LOGI |
michael@0 | 211 | +#define LOGW DOM_CAMERA_LOGW |
michael@0 | 212 | +#define LOGE DOM_CAMERA_LOGE |
michael@0 | 213 | |
michael@0 | 214 | #include <OMX_Component.h> |
michael@0 | 215 | -#include <binder/IPCThreadState.h> |
michael@0 | 216 | -#include <media/stagefright/CameraSource.h> |
michael@0 | 217 | +#include "GonkCameraSource.h" |
michael@0 | 218 | +#include "GonkCameraListener.h" |
michael@0 | 219 | +#include "GonkCameraHwMgr.h" |
michael@0 | 220 | #include <media/stagefright/MediaDebug.h> |
michael@0 | 221 | #include <media/stagefright/MediaDefs.h> |
michael@0 | 222 | #include <media/stagefright/MediaErrors.h> |
michael@0 | 223 | #include <media/stagefright/MetaData.h> |
michael@0 | 224 | -#include <camera/Camera.h> |
michael@0 | 225 | -#include <camera/CameraParameters.h> |
michael@0 | 226 | -#include <surfaceflinger/Surface.h> |
michael@0 | 227 | #include <utils/String8.h> |
michael@0 | 228 | #include <cutils/properties.h> |
michael@0 | 229 | |
michael@0 | 230 | +using namespace mozilla; |
michael@0 | 231 | namespace android { |
michael@0 | 232 | |
michael@0 | 233 | static const int64_t CAMERA_SOURCE_TIMEOUT_NS = 3000000000LL; |
michael@0 | 234 | |
michael@0 | 235 | -struct CameraSourceListener : public CameraListener { |
michael@0 | 236 | - CameraSourceListener(const sp<CameraSource> &source); |
michael@0 | 237 | +struct GonkCameraSourceListener : public GonkCameraListener { |
michael@0 | 238 | + GonkCameraSourceListener(const sp<GonkCameraSource> &source); |
michael@0 | 239 | |
michael@0 | 240 | virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2); |
michael@0 | 241 | virtual void postData(int32_t msgType, const sp<IMemory> &dataPtr, |
michael@0 | 242 | @@ -46,41 +51,41 @@ struct CameraSourceListener : public CameraListener { |
michael@0 | 243 | nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); |
michael@0 | 244 | |
michael@0 | 245 | protected: |
michael@0 | 246 | - virtual ~CameraSourceListener(); |
michael@0 | 247 | + virtual ~GonkCameraSourceListener(); |
michael@0 | 248 | |
michael@0 | 249 | private: |
michael@0 | 250 | - wp<CameraSource> mSource; |
michael@0 | 251 | + wp<GonkCameraSource> mSource; |
michael@0 | 252 | |
michael@0 | 253 | - CameraSourceListener(const CameraSourceListener &); |
michael@0 | 254 | - CameraSourceListener &operator=(const CameraSourceListener &); |
michael@0 | 255 | + GonkCameraSourceListener(const GonkCameraSourceListener &); |
michael@0 | 256 | + GonkCameraSourceListener &operator=(const GonkCameraSourceListener &); |
michael@0 | 257 | }; |
michael@0 | 258 | |
michael@0 | 259 | -CameraSourceListener::CameraSourceListener(const sp<CameraSource> &source) |
michael@0 | 260 | +GonkCameraSourceListener::GonkCameraSourceListener(const sp<GonkCameraSource> &source) |
michael@0 | 261 | : mSource(source) { |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | -CameraSourceListener::~CameraSourceListener() { |
michael@0 | 265 | +GonkCameraSourceListener::~GonkCameraSourceListener() { |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | -void CameraSourceListener::notify(int32_t msgType, int32_t ext1, int32_t ext2) { |
michael@0 | 269 | +void GonkCameraSourceListener::notify(int32_t msgType, int32_t ext1, int32_t ext2) { |
michael@0 | 270 | LOGV("notify(%d, %d, %d)", msgType, ext1, ext2); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | -void CameraSourceListener::postData(int32_t msgType, const sp<IMemory> &dataPtr, |
michael@0 | 274 | +void GonkCameraSourceListener::postData(int32_t msgType, const sp<IMemory> &dataPtr, |
michael@0 | 275 | camera_frame_metadata_t *metadata) { |
michael@0 | 276 | LOGV("postData(%d, ptr:%p, size:%d)", |
michael@0 | 277 | msgType, dataPtr->pointer(), dataPtr->size()); |
michael@0 | 278 | |
michael@0 | 279 | - sp<CameraSource> source = mSource.promote(); |
michael@0 | 280 | + sp<GonkCameraSource> source = mSource.promote(); |
michael@0 | 281 | if (source.get() != NULL) { |
michael@0 | 282 | source->dataCallback(msgType, dataPtr); |
michael@0 | 283 | } |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | -void CameraSourceListener::postDataTimestamp( |
michael@0 | 287 | +void GonkCameraSourceListener::postDataTimestamp( |
michael@0 | 288 | nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) { |
michael@0 | 289 | |
michael@0 | 290 | - sp<CameraSource> source = mSource.promote(); |
michael@0 | 291 | + sp<GonkCameraSource> source = mSource.promote(); |
michael@0 | 292 | if (source.get() != NULL) { |
michael@0 | 293 | source->dataCallbackTimestamp(timestamp/1000, msgType, dataPtr); |
michael@0 | 294 | } |
michael@0 | 295 | @@ -114,48 +119,30 @@ static int32_t getColorFormat(const char* colorFormat) { |
michael@0 | 296 | } |
michael@0 | 297 | |
michael@0 | 298 | LOGE("Uknown color format (%s), please add it to " |
michael@0 | 299 | - "CameraSource::getColorFormat", colorFormat); |
michael@0 | 300 | + "GonkCameraSource::getColorFormat", colorFormat); |
michael@0 | 301 | |
michael@0 | 302 | CHECK_EQ(0, "Unknown color format"); |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | -CameraSource *CameraSource::Create() { |
michael@0 | 306 | - Size size; |
michael@0 | 307 | - size.width = -1; |
michael@0 | 308 | - size.height = -1; |
michael@0 | 309 | - |
michael@0 | 310 | - sp<ICamera> camera; |
michael@0 | 311 | - return new CameraSource(camera, NULL, 0, size, -1, NULL, false); |
michael@0 | 312 | -} |
michael@0 | 313 | - |
michael@0 | 314 | -// static |
michael@0 | 315 | -CameraSource *CameraSource::CreateFromCamera( |
michael@0 | 316 | - const sp<ICamera>& camera, |
michael@0 | 317 | - const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 318 | - int32_t cameraId, |
michael@0 | 319 | +GonkCameraSource *GonkCameraSource::Create( |
michael@0 | 320 | + int32_t cameraHandle, |
michael@0 | 321 | Size videoSize, |
michael@0 | 322 | int32_t frameRate, |
michael@0 | 323 | - const sp<Surface>& surface, |
michael@0 | 324 | bool storeMetaDataInVideoBuffers) { |
michael@0 | 325 | |
michael@0 | 326 | - CameraSource *source = new CameraSource(camera, proxy, cameraId, |
michael@0 | 327 | - videoSize, frameRate, surface, |
michael@0 | 328 | + GonkCameraSource *source = new GonkCameraSource(cameraHandle, |
michael@0 | 329 | + videoSize, frameRate, |
michael@0 | 330 | storeMetaDataInVideoBuffers); |
michael@0 | 331 | return source; |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | -CameraSource::CameraSource( |
michael@0 | 335 | - const sp<ICamera>& camera, |
michael@0 | 336 | - const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 337 | - int32_t cameraId, |
michael@0 | 338 | +GonkCameraSource::GonkCameraSource( |
michael@0 | 339 | + int32_t cameraHandle, |
michael@0 | 340 | Size videoSize, |
michael@0 | 341 | int32_t frameRate, |
michael@0 | 342 | - const sp<Surface>& surface, |
michael@0 | 343 | bool storeMetaDataInVideoBuffers) |
michael@0 | 344 | : mCameraFlags(0), |
michael@0 | 345 | mVideoFrameRate(-1), |
michael@0 | 346 | - mCamera(0), |
michael@0 | 347 | - mSurface(surface), |
michael@0 | 348 | mNumFramesReceived(0), |
michael@0 | 349 | mLastFrameTimestampUs(0), |
michael@0 | 350 | mStarted(false), |
michael@0 | 351 | @@ -169,43 +156,19 @@ CameraSource::CameraSource( |
michael@0 | 352 | mVideoSize.width = -1; |
michael@0 | 353 | mVideoSize.height = -1; |
michael@0 | 354 | |
michael@0 | 355 | - mInitCheck = init(camera, proxy, cameraId, |
michael@0 | 356 | + mCameraHandle = cameraHandle; |
michael@0 | 357 | + |
michael@0 | 358 | + mInitCheck = init( |
michael@0 | 359 | videoSize, frameRate, |
michael@0 | 360 | storeMetaDataInVideoBuffers); |
michael@0 | 361 | if (mInitCheck != OK) releaseCamera(); |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | -status_t CameraSource::initCheck() const { |
michael@0 | 365 | +status_t GonkCameraSource::initCheck() const { |
michael@0 | 366 | return mInitCheck; |
michael@0 | 367 | } |
michael@0 | 368 | |
michael@0 | 369 | -status_t CameraSource::isCameraAvailable( |
michael@0 | 370 | - const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 371 | - int32_t cameraId) { |
michael@0 | 372 | - |
michael@0 | 373 | - if (camera == 0) { |
michael@0 | 374 | - mCamera = Camera::connect(cameraId); |
michael@0 | 375 | - if (mCamera == 0) return -EBUSY; |
michael@0 | 376 | - mCameraFlags &= ~FLAGS_HOT_CAMERA; |
michael@0 | 377 | - } else { |
michael@0 | 378 | - // We get the proxy from Camera, not ICamera. We need to get the proxy |
michael@0 | 379 | - // to the remote Camera owned by the application. Here mCamera is a |
michael@0 | 380 | - // local Camera object created by us. We cannot use the proxy from |
michael@0 | 381 | - // mCamera here. |
michael@0 | 382 | - mCamera = Camera::create(camera); |
michael@0 | 383 | - if (mCamera == 0) return -EBUSY; |
michael@0 | 384 | - mCameraRecordingProxy = proxy; |
michael@0 | 385 | - mCameraFlags |= FLAGS_HOT_CAMERA; |
michael@0 | 386 | - mDeathNotifier = new DeathNotifier(); |
michael@0 | 387 | - // isBinderAlive needs linkToDeath to work. |
michael@0 | 388 | - mCameraRecordingProxy->asBinder()->linkToDeath(mDeathNotifier); |
michael@0 | 389 | - } |
michael@0 | 390 | - |
michael@0 | 391 | - mCamera->lock(); |
michael@0 | 392 | - |
michael@0 | 393 | - return OK; |
michael@0 | 394 | -} |
michael@0 | 395 | - |
michael@0 | 396 | +//TODO: Do we need to reimplement isCameraAvailable? |
michael@0 | 397 | |
michael@0 | 398 | /* |
michael@0 | 399 | * Check to see whether the requested video width and height is one |
michael@0 | 400 | @@ -267,7 +230,7 @@ static void getSupportedVideoSizes( |
michael@0 | 401 | * @param params CameraParameters to retrieve the information |
michael@0 | 402 | * @return OK if no error. |
michael@0 | 403 | */ |
michael@0 | 404 | -status_t CameraSource::isCameraColorFormatSupported( |
michael@0 | 405 | +status_t GonkCameraSource::isCameraColorFormatSupported( |
michael@0 | 406 | const CameraParameters& params) { |
michael@0 | 407 | mColorFormat = getColorFormat(params.get( |
michael@0 | 408 | CameraParameters::KEY_VIDEO_FRAME_FORMAT)); |
michael@0 | 409 | @@ -292,7 +255,7 @@ status_t CameraSource::isCameraColorFormatSupported( |
michael@0 | 410 | * @param frameRate the target frame rate in frames per second. |
michael@0 | 411 | * @return OK if no error. |
michael@0 | 412 | */ |
michael@0 | 413 | -status_t CameraSource::configureCamera( |
michael@0 | 414 | +status_t GonkCameraSource::configureCamera( |
michael@0 | 415 | CameraParameters* params, |
michael@0 | 416 | int32_t width, int32_t height, |
michael@0 | 417 | int32_t frameRate) { |
michael@0 | 418 | @@ -347,10 +310,9 @@ status_t CameraSource::configureCamera( |
michael@0 | 419 | |
michael@0 | 420 | if (isCameraParamChanged) { |
michael@0 | 421 | // Either frame rate or frame size needs to be changed. |
michael@0 | 422 | - String8 s = params->flatten(); |
michael@0 | 423 | - if (OK != mCamera->setParameters(s)) { |
michael@0 | 424 | + if (OK != GonkCameraHardware::PushParameters(mCameraHandle,*params)) { |
michael@0 | 425 | LOGE("Could not change settings." |
michael@0 | 426 | - " Someone else is using camera %p?", mCamera.get()); |
michael@0 | 427 | + " Someone else is using camera ?"); |
michael@0 | 428 | return -EBUSY; |
michael@0 | 429 | } |
michael@0 | 430 | } |
michael@0 | 431 | @@ -368,7 +330,7 @@ status_t CameraSource::configureCamera( |
michael@0 | 432 | * @param the target video frame height in pixels to check against |
michael@0 | 433 | * @return OK if no error |
michael@0 | 434 | */ |
michael@0 | 435 | -status_t CameraSource::checkVideoSize( |
michael@0 | 436 | +status_t GonkCameraSource::checkVideoSize( |
michael@0 | 437 | const CameraParameters& params, |
michael@0 | 438 | int32_t width, int32_t height) { |
michael@0 | 439 | |
michael@0 | 440 | @@ -420,7 +382,7 @@ status_t CameraSource::checkVideoSize( |
michael@0 | 441 | * @param the target video frame rate to check against |
michael@0 | 442 | * @return OK if no error. |
michael@0 | 443 | */ |
michael@0 | 444 | -status_t CameraSource::checkFrameRate( |
michael@0 | 445 | +status_t GonkCameraSource::checkFrameRate( |
michael@0 | 446 | const CameraParameters& params, |
michael@0 | 447 | int32_t frameRate) { |
michael@0 | 448 | |
michael@0 | 449 | @@ -462,39 +424,17 @@ status_t CameraSource::checkFrameRate( |
michael@0 | 450 | * |
michael@0 | 451 | * @return OK if no error. |
michael@0 | 452 | */ |
michael@0 | 453 | -status_t CameraSource::init( |
michael@0 | 454 | - const sp<ICamera>& camera, |
michael@0 | 455 | - const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 456 | - int32_t cameraId, |
michael@0 | 457 | +status_t GonkCameraSource::init( |
michael@0 | 458 | Size videoSize, |
michael@0 | 459 | int32_t frameRate, |
michael@0 | 460 | bool storeMetaDataInVideoBuffers) { |
michael@0 | 461 | |
michael@0 | 462 | LOGV("init"); |
michael@0 | 463 | status_t err = OK; |
michael@0 | 464 | - int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
michael@0 | 465 | - err = initWithCameraAccess(camera, proxy, cameraId, |
michael@0 | 466 | - videoSize, frameRate, |
michael@0 | 467 | - storeMetaDataInVideoBuffers); |
michael@0 | 468 | - IPCThreadState::self()->restoreCallingIdentity(token); |
michael@0 | 469 | - return err; |
michael@0 | 470 | -} |
michael@0 | 471 | - |
michael@0 | 472 | -status_t CameraSource::initWithCameraAccess( |
michael@0 | 473 | - const sp<ICamera>& camera, |
michael@0 | 474 | - const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 475 | - int32_t cameraId, |
michael@0 | 476 | - Size videoSize, |
michael@0 | 477 | - int32_t frameRate, |
michael@0 | 478 | - bool storeMetaDataInVideoBuffers) { |
michael@0 | 479 | - LOGV("initWithCameraAccess"); |
michael@0 | 480 | - status_t err = OK; |
michael@0 | 481 | + //TODO: need to do something here to check the sanity of camera |
michael@0 | 482 | |
michael@0 | 483 | - if ((err = isCameraAvailable(camera, proxy, cameraId)) != OK) { |
michael@0 | 484 | - LOGE("Camera connection could not be established."); |
michael@0 | 485 | - return err; |
michael@0 | 486 | - } |
michael@0 | 487 | - CameraParameters params(mCamera->getParameters()); |
michael@0 | 488 | + CameraParameters params; |
michael@0 | 489 | + GonkCameraHardware::PullParameters(mCameraHandle, params); |
michael@0 | 490 | if ((err = isCameraColorFormatSupported(params)) != OK) { |
michael@0 | 491 | return err; |
michael@0 | 492 | } |
michael@0 | 493 | @@ -508,7 +448,8 @@ status_t CameraSource::initWithCameraAccess( |
michael@0 | 494 | } |
michael@0 | 495 | |
michael@0 | 496 | // Check on video frame size and frame rate. |
michael@0 | 497 | - CameraParameters newCameraParams(mCamera->getParameters()); |
michael@0 | 498 | + CameraParameters newCameraParams; |
michael@0 | 499 | + GonkCameraHardware::PullParameters(mCameraHandle, newCameraParams); |
michael@0 | 500 | if ((err = checkVideoSize(newCameraParams, |
michael@0 | 501 | videoSize.width, videoSize.height)) != OK) { |
michael@0 | 502 | return err; |
michael@0 | 503 | @@ -517,15 +458,11 @@ status_t CameraSource::initWithCameraAccess( |
michael@0 | 504 | return err; |
michael@0 | 505 | } |
michael@0 | 506 | |
michael@0 | 507 | - // This CHECK is good, since we just passed the lock/unlock |
michael@0 | 508 | - // check earlier by calling mCamera->setParameters(). |
michael@0 | 509 | - CHECK_EQ(OK, mCamera->setPreviewDisplay(mSurface)); |
michael@0 | 510 | - |
michael@0 | 511 | // By default, do not store metadata in video buffers |
michael@0 | 512 | mIsMetaDataStoredInVideoBuffers = false; |
michael@0 | 513 | - mCamera->storeMetaDataInBuffers(false); |
michael@0 | 514 | + GonkCameraHardware::StoreMetaDataInBuffers(mCameraHandle, false); |
michael@0 | 515 | if (storeMetaDataInVideoBuffers) { |
michael@0 | 516 | - if (OK == mCamera->storeMetaDataInBuffers(true)) { |
michael@0 | 517 | + if (OK == GonkCameraHardware::StoreMetaDataInBuffers(mCameraHandle, true)) { |
michael@0 | 518 | mIsMetaDataStoredInVideoBuffers = true; |
michael@0 | 519 | } |
michael@0 | 520 | } |
michael@0 | 521 | @@ -568,40 +505,28 @@ status_t CameraSource::initWithCameraAccess( |
michael@0 | 522 | return OK; |
michael@0 | 523 | } |
michael@0 | 524 | |
michael@0 | 525 | -CameraSource::~CameraSource() { |
michael@0 | 526 | +GonkCameraSource::~GonkCameraSource() { |
michael@0 | 527 | if (mStarted) { |
michael@0 | 528 | stop(); |
michael@0 | 529 | } else if (mInitCheck == OK) { |
michael@0 | 530 | // Camera is initialized but because start() is never called, |
michael@0 | 531 | // the lock on Camera is never released(). This makes sure |
michael@0 | 532 | // Camera's lock is released in this case. |
michael@0 | 533 | + // TODO: Don't think I need to do this |
michael@0 | 534 | releaseCamera(); |
michael@0 | 535 | } |
michael@0 | 536 | } |
michael@0 | 537 | |
michael@0 | 538 | -void CameraSource::startCameraRecording() { |
michael@0 | 539 | +void GonkCameraSource::startCameraRecording() { |
michael@0 | 540 | LOGV("startCameraRecording"); |
michael@0 | 541 | - // Reset the identity to the current thread because media server owns the |
michael@0 | 542 | - // camera and recording is started by the applications. The applications |
michael@0 | 543 | - // will connect to the camera in ICameraRecordingProxy::startRecording. |
michael@0 | 544 | - int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
michael@0 | 545 | - if (mCameraFlags & FLAGS_HOT_CAMERA) { |
michael@0 | 546 | - mCamera->unlock(); |
michael@0 | 547 | - mCamera.clear(); |
michael@0 | 548 | - CHECK_EQ(OK, mCameraRecordingProxy->startRecording(new ProxyListener(this))); |
michael@0 | 549 | - } else { |
michael@0 | 550 | - mCamera->setListener(new CameraSourceListener(this)); |
michael@0 | 551 | - mCamera->startRecording(); |
michael@0 | 552 | - CHECK(mCamera->recordingEnabled()); |
michael@0 | 553 | - } |
michael@0 | 554 | - IPCThreadState::self()->restoreCallingIdentity(token); |
michael@0 | 555 | + CHECK_EQ(OK, GonkCameraHardware::StartRecording(mCameraHandle)); |
michael@0 | 556 | } |
michael@0 | 557 | |
michael@0 | 558 | -status_t CameraSource::start(MetaData *meta) { |
michael@0 | 559 | +status_t GonkCameraSource::start(MetaData *meta) { |
michael@0 | 560 | LOGV("start"); |
michael@0 | 561 | CHECK(!mStarted); |
michael@0 | 562 | if (mInitCheck != OK) { |
michael@0 | 563 | - LOGE("CameraSource is not initialized yet"); |
michael@0 | 564 | + LOGE("GonkCameraSource is not initialized yet"); |
michael@0 | 565 | return mInitCheck; |
michael@0 | 566 | } |
michael@0 | 567 | |
michael@0 | 568 | @@ -614,58 +539,34 @@ status_t CameraSource::start(MetaData *meta) { |
michael@0 | 569 | mStartTimeUs = 0; |
michael@0 | 570 | int64_t startTimeUs; |
michael@0 | 571 | if (meta && meta->findInt64(kKeyTime, &startTimeUs)) { |
michael@0 | 572 | + LOGV("Metadata enabled, startime: %lld us", startTimeUs); |
michael@0 | 573 | mStartTimeUs = startTimeUs; |
michael@0 | 574 | } |
michael@0 | 575 | |
michael@0 | 576 | + // Register a listener with GonkCameraHardware so that we can get callbacks |
michael@0 | 577 | + GonkCameraHardware::SetListener(mCameraHandle, new GonkCameraSourceListener(this)); |
michael@0 | 578 | + |
michael@0 | 579 | startCameraRecording(); |
michael@0 | 580 | |
michael@0 | 581 | mStarted = true; |
michael@0 | 582 | return OK; |
michael@0 | 583 | } |
michael@0 | 584 | |
michael@0 | 585 | -void CameraSource::stopCameraRecording() { |
michael@0 | 586 | +void GonkCameraSource::stopCameraRecording() { |
michael@0 | 587 | LOGV("stopCameraRecording"); |
michael@0 | 588 | - if (mCameraFlags & FLAGS_HOT_CAMERA) { |
michael@0 | 589 | - mCameraRecordingProxy->stopRecording(); |
michael@0 | 590 | - } else { |
michael@0 | 591 | - mCamera->setListener(NULL); |
michael@0 | 592 | - mCamera->stopRecording(); |
michael@0 | 593 | - } |
michael@0 | 594 | + GonkCameraHardware::StopRecording(mCameraHandle); |
michael@0 | 595 | } |
michael@0 | 596 | |
michael@0 | 597 | -void CameraSource::releaseCamera() { |
michael@0 | 598 | +void GonkCameraSource::releaseCamera() { |
michael@0 | 599 | LOGV("releaseCamera"); |
michael@0 | 600 | - if (mCamera != 0) { |
michael@0 | 601 | - int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
michael@0 | 602 | - if ((mCameraFlags & FLAGS_HOT_CAMERA) == 0) { |
michael@0 | 603 | - LOGV("Camera was cold when we started, stopping preview"); |
michael@0 | 604 | - mCamera->stopPreview(); |
michael@0 | 605 | - mCamera->disconnect(); |
michael@0 | 606 | - } |
michael@0 | 607 | - mCamera->unlock(); |
michael@0 | 608 | - mCamera.clear(); |
michael@0 | 609 | - mCamera = 0; |
michael@0 | 610 | - IPCThreadState::self()->restoreCallingIdentity(token); |
michael@0 | 611 | - } |
michael@0 | 612 | - if (mCameraRecordingProxy != 0) { |
michael@0 | 613 | - mCameraRecordingProxy->asBinder()->unlinkToDeath(mDeathNotifier); |
michael@0 | 614 | - mCameraRecordingProxy.clear(); |
michael@0 | 615 | - } |
michael@0 | 616 | - mCameraFlags = 0; |
michael@0 | 617 | } |
michael@0 | 618 | |
michael@0 | 619 | -status_t CameraSource::stop() { |
michael@0 | 620 | - LOGD("stop: E"); |
michael@0 | 621 | +status_t GonkCameraSource::stop() { |
michael@0 | 622 | + LOGV("stop: E"); |
michael@0 | 623 | Mutex::Autolock autoLock(mLock); |
michael@0 | 624 | mStarted = false; |
michael@0 | 625 | mFrameAvailableCondition.signal(); |
michael@0 | 626 | |
michael@0 | 627 | - int64_t token; |
michael@0 | 628 | - bool isTokenValid = false; |
michael@0 | 629 | - if (mCamera != 0) { |
michael@0 | 630 | - token = IPCThreadState::self()->clearCallingIdentity(); |
michael@0 | 631 | - isTokenValid = true; |
michael@0 | 632 | - } |
michael@0 | 633 | releaseQueuedFrames(); |
michael@0 | 634 | while (!mFramesBeingEncoded.empty()) { |
michael@0 | 635 | if (NO_ERROR != |
michael@0 | 636 | @@ -675,11 +576,9 @@ status_t CameraSource::stop() { |
michael@0 | 637 | mFramesBeingEncoded.size()); |
michael@0 | 638 | } |
michael@0 | 639 | } |
michael@0 | 640 | + LOGV("Calling stopCameraRecording"); |
michael@0 | 641 | stopCameraRecording(); |
michael@0 | 642 | releaseCamera(); |
michael@0 | 643 | - if (isTokenValid) { |
michael@0 | 644 | - IPCThreadState::self()->restoreCallingIdentity(token); |
michael@0 | 645 | - } |
michael@0 | 646 | |
michael@0 | 647 | if (mCollectStats) { |
michael@0 | 648 | LOGI("Frames received/encoded/dropped: %d/%d/%d in %lld us", |
michael@0 | 649 | @@ -692,22 +591,16 @@ status_t CameraSource::stop() { |
michael@0 | 650 | } |
michael@0 | 651 | |
michael@0 | 652 | CHECK_EQ(mNumFramesReceived, mNumFramesEncoded + mNumFramesDropped); |
michael@0 | 653 | - LOGD("stop: X"); |
michael@0 | 654 | + LOGV("stop: X"); |
michael@0 | 655 | return OK; |
michael@0 | 656 | } |
michael@0 | 657 | |
michael@0 | 658 | -void CameraSource::releaseRecordingFrame(const sp<IMemory>& frame) { |
michael@0 | 659 | +void GonkCameraSource::releaseRecordingFrame(const sp<IMemory>& frame) { |
michael@0 | 660 | LOGV("releaseRecordingFrame"); |
michael@0 | 661 | - if (mCameraRecordingProxy != NULL) { |
michael@0 | 662 | - mCameraRecordingProxy->releaseRecordingFrame(frame); |
michael@0 | 663 | - } else if (mCamera != NULL) { |
michael@0 | 664 | - int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
michael@0 | 665 | - mCamera->releaseRecordingFrame(frame); |
michael@0 | 666 | - IPCThreadState::self()->restoreCallingIdentity(token); |
michael@0 | 667 | - } |
michael@0 | 668 | + GonkCameraHardware::ReleaseRecordingFrame(mCameraHandle, frame); |
michael@0 | 669 | } |
michael@0 | 670 | |
michael@0 | 671 | -void CameraSource::releaseQueuedFrames() { |
michael@0 | 672 | +void GonkCameraSource::releaseQueuedFrames() { |
michael@0 | 673 | List<sp<IMemory> >::iterator it; |
michael@0 | 674 | while (!mFramesReceived.empty()) { |
michael@0 | 675 | it = mFramesReceived.begin(); |
michael@0 | 676 | @@ -717,15 +610,15 @@ void CameraSource::releaseQueuedFrames() { |
michael@0 | 677 | } |
michael@0 | 678 | } |
michael@0 | 679 | |
michael@0 | 680 | -sp<MetaData> CameraSource::getFormat() { |
michael@0 | 681 | +sp<MetaData> GonkCameraSource::getFormat() { |
michael@0 | 682 | return mMeta; |
michael@0 | 683 | } |
michael@0 | 684 | |
michael@0 | 685 | -void CameraSource::releaseOneRecordingFrame(const sp<IMemory>& frame) { |
michael@0 | 686 | +void GonkCameraSource::releaseOneRecordingFrame(const sp<IMemory>& frame) { |
michael@0 | 687 | releaseRecordingFrame(frame); |
michael@0 | 688 | } |
michael@0 | 689 | |
michael@0 | 690 | -void CameraSource::signalBufferReturned(MediaBuffer *buffer) { |
michael@0 | 691 | +void GonkCameraSource::signalBufferReturned(MediaBuffer *buffer) { |
michael@0 | 692 | LOGV("signalBufferReturned: %p", buffer->data()); |
michael@0 | 693 | Mutex::Autolock autoLock(mLock); |
michael@0 | 694 | for (List<sp<IMemory> >::iterator it = mFramesBeingEncoded.begin(); |
michael@0 | 695 | @@ -743,7 +636,7 @@ void CameraSource::signalBufferReturned(MediaBuffer *buffer) { |
michael@0 | 696 | CHECK_EQ(0, "signalBufferReturned: bogus buffer"); |
michael@0 | 697 | } |
michael@0 | 698 | |
michael@0 | 699 | -status_t CameraSource::read( |
michael@0 | 700 | +status_t GonkCameraSource::read( |
michael@0 | 701 | MediaBuffer **buffer, const ReadOptions *options) { |
michael@0 | 702 | LOGV("read"); |
michael@0 | 703 | |
michael@0 | 704 | @@ -764,11 +657,7 @@ status_t CameraSource::read( |
michael@0 | 705 | if (NO_ERROR != |
michael@0 | 706 | mFrameAvailableCondition.waitRelative(mLock, |
michael@0 | 707 | mTimeBetweenFrameCaptureUs * 1000LL + CAMERA_SOURCE_TIMEOUT_NS)) { |
michael@0 | 708 | - if (mCameraRecordingProxy != 0 && |
michael@0 | 709 | - !mCameraRecordingProxy->asBinder()->isBinderAlive()) { |
michael@0 | 710 | - LOGW("camera recording proxy is gone"); |
michael@0 | 711 | - return ERROR_END_OF_STREAM; |
michael@0 | 712 | - } |
michael@0 | 713 | + //TODO: check sanity of camera? |
michael@0 | 714 | LOGW("Timed out waiting for incoming camera video frames: %lld us", |
michael@0 | 715 | mLastFrameTimestampUs); |
michael@0 | 716 | } |
michael@0 | 717 | @@ -790,9 +679,10 @@ status_t CameraSource::read( |
michael@0 | 718 | return OK; |
michael@0 | 719 | } |
michael@0 | 720 | |
michael@0 | 721 | -void CameraSource::dataCallbackTimestamp(int64_t timestampUs, |
michael@0 | 722 | +void GonkCameraSource::dataCallbackTimestamp(int64_t timestampUs, |
michael@0 | 723 | int32_t msgType, const sp<IMemory> &data) { |
michael@0 | 724 | LOGV("dataCallbackTimestamp: timestamp %lld us", timestampUs); |
michael@0 | 725 | + //LOGV("dataCallbackTimestamp: data %x size %d", data->pointer(), data->size()); |
michael@0 | 726 | Mutex::Autolock autoLock(mLock); |
michael@0 | 727 | if (!mStarted || (mNumFramesReceived == 0 && timestampUs < mStartTimeUs)) { |
michael@0 | 728 | LOGV("Drop frame at %lld/%lld us", timestampUs, mStartTimeUs); |
michael@0 | 729 | @@ -808,7 +698,7 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs, |
michael@0 | 730 | } |
michael@0 | 731 | |
michael@0 | 732 | // May need to skip frame or modify timestamp. Currently implemented |
michael@0 | 733 | - // by the subclass CameraSourceTimeLapse. |
michael@0 | 734 | + // by the subclass GonkCameraSourceTimeLapse. |
michael@0 | 735 | if (skipCurrentFrame(timestampUs)) { |
michael@0 | 736 | releaseOneRecordingFrame(data); |
michael@0 | 737 | return; |
michael@0 | 738 | @@ -839,22 +729,9 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs, |
michael@0 | 739 | mFrameAvailableCondition.signal(); |
michael@0 | 740 | } |
michael@0 | 741 | |
michael@0 | 742 | -bool CameraSource::isMetaDataStoredInVideoBuffers() const { |
michael@0 | 743 | +bool GonkCameraSource::isMetaDataStoredInVideoBuffers() const { |
michael@0 | 744 | LOGV("isMetaDataStoredInVideoBuffers"); |
michael@0 | 745 | return mIsMetaDataStoredInVideoBuffers; |
michael@0 | 746 | } |
michael@0 | 747 | |
michael@0 | 748 | -CameraSource::ProxyListener::ProxyListener(const sp<CameraSource>& source) { |
michael@0 | 749 | - mSource = source; |
michael@0 | 750 | -} |
michael@0 | 751 | - |
michael@0 | 752 | -void CameraSource::ProxyListener::dataCallbackTimestamp( |
michael@0 | 753 | - nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) { |
michael@0 | 754 | - mSource->dataCallbackTimestamp(timestamp / 1000, msgType, dataPtr); |
michael@0 | 755 | -} |
michael@0 | 756 | - |
michael@0 | 757 | -void CameraSource::DeathNotifier::binderDied(const wp<IBinder>& who) { |
michael@0 | 758 | - LOGI("Camera recording proxy died"); |
michael@0 | 759 | -} |
michael@0 | 760 | - |
michael@0 | 761 | -} // namespace android |
michael@0 | 762 | +} // namespace android |
michael@0 | 763 | diff --git a/GonkCameraSource.h b/GonkCameraSource.h |
michael@0 | 764 | index 446720b..fe58f96 100644 |
michael@0 | 765 | --- a/GonkCameraSource.h |
michael@0 | 766 | +++ b/GonkCameraSource.h |
michael@0 | 767 | @@ -14,69 +14,31 @@ |
michael@0 | 768 | * limitations under the License. |
michael@0 | 769 | */ |
michael@0 | 770 | |
michael@0 | 771 | -#ifndef CAMERA_SOURCE_H_ |
michael@0 | 772 | +#ifndef GONK_CAMERA_SOURCE_H_ |
michael@0 | 773 | |
michael@0 | 774 | -#define CAMERA_SOURCE_H_ |
michael@0 | 775 | +#define GONK_CAMERA_SOURCE_H_ |
michael@0 | 776 | |
michael@0 | 777 | #include <media/stagefright/MediaBuffer.h> |
michael@0 | 778 | #include <media/stagefright/MediaSource.h> |
michael@0 | 779 | -#include <camera/ICamera.h> |
michael@0 | 780 | -#include <camera/ICameraRecordingProxyListener.h> |
michael@0 | 781 | #include <camera/CameraParameters.h> |
michael@0 | 782 | #include <utils/List.h> |
michael@0 | 783 | #include <utils/RefBase.h> |
michael@0 | 784 | +#include <utils/threads.h> |
michael@0 | 785 | |
michael@0 | 786 | namespace android { |
michael@0 | 787 | |
michael@0 | 788 | class IMemory; |
michael@0 | 789 | -class Camera; |
michael@0 | 790 | -class Surface; |
michael@0 | 791 | +class GonkCameraSourceListener; |
michael@0 | 792 | |
michael@0 | 793 | -class CameraSource : public MediaSource, public MediaBufferObserver { |
michael@0 | 794 | +class GonkCameraSource : public MediaSource, public MediaBufferObserver { |
michael@0 | 795 | public: |
michael@0 | 796 | - /** |
michael@0 | 797 | - * Factory method to create a new CameraSource using the current |
michael@0 | 798 | - * settings (such as video size, frame rate, color format, etc) |
michael@0 | 799 | - * from the default camera. |
michael@0 | 800 | - * |
michael@0 | 801 | - * @return NULL on error. |
michael@0 | 802 | - */ |
michael@0 | 803 | - static CameraSource *Create(); |
michael@0 | 804 | |
michael@0 | 805 | - /** |
michael@0 | 806 | - * Factory method to create a new CameraSource. |
michael@0 | 807 | - * |
michael@0 | 808 | - * @param camera the video input frame data source. If it is NULL, |
michael@0 | 809 | - * we will try to connect to the camera with the given |
michael@0 | 810 | - * cameraId. |
michael@0 | 811 | - * |
michael@0 | 812 | - * @param cameraId the id of the camera that the source will connect |
michael@0 | 813 | - * to if camera is NULL; otherwise ignored. |
michael@0 | 814 | - * |
michael@0 | 815 | - * @param videoSize the dimension (in pixels) of the video frame |
michael@0 | 816 | - * @param frameRate the target frames per second |
michael@0 | 817 | - * @param surface the preview surface for display where preview |
michael@0 | 818 | - * frames are sent to |
michael@0 | 819 | - * @param storeMetaDataInVideoBuffers true to request the camera |
michael@0 | 820 | - * source to store meta data in video buffers; false to |
michael@0 | 821 | - * request the camera source to store real YUV frame data |
michael@0 | 822 | - * in the video buffers. The camera source may not support |
michael@0 | 823 | - * storing meta data in video buffers, if so, a request |
michael@0 | 824 | - * to do that will NOT be honored. To find out whether |
michael@0 | 825 | - * meta data is actually being stored in video buffers |
michael@0 | 826 | - * during recording, call isMetaDataStoredInVideoBuffers(). |
michael@0 | 827 | - * |
michael@0 | 828 | - * @return NULL on error. |
michael@0 | 829 | - */ |
michael@0 | 830 | - static CameraSource *CreateFromCamera(const sp<ICamera> &camera, |
michael@0 | 831 | - const sp<ICameraRecordingProxy> &proxy, |
michael@0 | 832 | - int32_t cameraId, |
michael@0 | 833 | - Size videoSize, |
michael@0 | 834 | - int32_t frameRate, |
michael@0 | 835 | - const sp<Surface>& surface, |
michael@0 | 836 | - bool storeMetaDataInVideoBuffers = false); |
michael@0 | 837 | + static GonkCameraSource *Create(int32_t cameraHandle, |
michael@0 | 838 | + Size videoSize, |
michael@0 | 839 | + int32_t frameRate, |
michael@0 | 840 | + bool storeMetaDataInVideoBuffers = false); |
michael@0 | 841 | |
michael@0 | 842 | - virtual ~CameraSource(); |
michael@0 | 843 | + virtual ~GonkCameraSource(); |
michael@0 | 844 | |
michael@0 | 845 | virtual status_t start(MetaData *params = NULL); |
michael@0 | 846 | virtual status_t stop(); |
michael@0 | 847 | @@ -84,14 +46,14 @@ public: |
michael@0 | 848 | MediaBuffer **buffer, const ReadOptions *options = NULL); |
michael@0 | 849 | |
michael@0 | 850 | /** |
michael@0 | 851 | - * Check whether a CameraSource object is properly initialized. |
michael@0 | 852 | + * Check whether a GonkCameraSource object is properly initialized. |
michael@0 | 853 | * Must call this method before stop(). |
michael@0 | 854 | * @return OK if initialization has successfully completed. |
michael@0 | 855 | */ |
michael@0 | 856 | virtual status_t initCheck() const; |
michael@0 | 857 | |
michael@0 | 858 | /** |
michael@0 | 859 | - * Returns the MetaData associated with the CameraSource, |
michael@0 | 860 | + * Returns the MetaData associated with the GonkCameraSource, |
michael@0 | 861 | * including: |
michael@0 | 862 | * kKeyColorFormat: YUV color format of the video frames |
michael@0 | 863 | * kKeyWidth, kKeyHeight: dimension (in pixels) of the video frames |
michael@0 | 864 | @@ -113,22 +75,6 @@ public: |
michael@0 | 865 | virtual void signalBufferReturned(MediaBuffer* buffer); |
michael@0 | 866 | |
michael@0 | 867 | protected: |
michael@0 | 868 | - class ProxyListener: public BnCameraRecordingProxyListener { |
michael@0 | 869 | - public: |
michael@0 | 870 | - ProxyListener(const sp<CameraSource>& source); |
michael@0 | 871 | - virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType, |
michael@0 | 872 | - const sp<IMemory> &data); |
michael@0 | 873 | - |
michael@0 | 874 | - private: |
michael@0 | 875 | - sp<CameraSource> mSource; |
michael@0 | 876 | - }; |
michael@0 | 877 | - |
michael@0 | 878 | - // isBinderAlive needs linkToDeath to work. |
michael@0 | 879 | - class DeathNotifier: public IBinder::DeathRecipient { |
michael@0 | 880 | - public: |
michael@0 | 881 | - DeathNotifier() {} |
michael@0 | 882 | - virtual void binderDied(const wp<IBinder>& who); |
michael@0 | 883 | - }; |
michael@0 | 884 | |
michael@0 | 885 | enum CameraFlags { |
michael@0 | 886 | FLAGS_SET_CAMERA = 1L << 0, |
michael@0 | 887 | @@ -141,10 +87,6 @@ protected: |
michael@0 | 888 | int32_t mColorFormat; |
michael@0 | 889 | status_t mInitCheck; |
michael@0 | 890 | |
michael@0 | 891 | - sp<Camera> mCamera; |
michael@0 | 892 | - sp<ICameraRecordingProxy> mCameraRecordingProxy; |
michael@0 | 893 | - sp<DeathNotifier> mDeathNotifier; |
michael@0 | 894 | - sp<Surface> mSurface; |
michael@0 | 895 | sp<MetaData> mMeta; |
michael@0 | 896 | |
michael@0 | 897 | int64_t mStartTimeUs; |
michael@0 | 898 | @@ -156,11 +98,9 @@ protected: |
michael@0 | 899 | // Time between capture of two frames. |
michael@0 | 900 | int64_t mTimeBetweenFrameCaptureUs; |
michael@0 | 901 | |
michael@0 | 902 | - CameraSource(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 903 | - int32_t cameraId, |
michael@0 | 904 | + GonkCameraSource(int32_t cameraHandle, |
michael@0 | 905 | Size videoSize, int32_t frameRate, |
michael@0 | 906 | - const sp<Surface>& surface, |
michael@0 | 907 | - bool storeMetaDataInVideoBuffers); |
michael@0 | 908 | + bool storeMetaDataInVideoBuffers = false); |
michael@0 | 909 | |
michael@0 | 910 | virtual void startCameraRecording(); |
michael@0 | 911 | virtual void stopCameraRecording(); |
michael@0 | 912 | @@ -170,6 +110,7 @@ protected: |
michael@0 | 913 | // Called from dataCallbackTimestamp. |
michael@0 | 914 | virtual bool skipCurrentFrame(int64_t timestampUs) {return false;} |
michael@0 | 915 | |
michael@0 | 916 | + friend class GonkCameraSourceListener; |
michael@0 | 917 | // Callback called when still camera raw data is available. |
michael@0 | 918 | virtual void dataCallback(int32_t msgType, const sp<IMemory> &data) {} |
michael@0 | 919 | |
michael@0 | 920 | @@ -177,7 +118,6 @@ protected: |
michael@0 | 921 | const sp<IMemory> &data); |
michael@0 | 922 | |
michael@0 | 923 | private: |
michael@0 | 924 | - friend class CameraSourceListener; |
michael@0 | 925 | |
michael@0 | 926 | Mutex mLock; |
michael@0 | 927 | Condition mFrameAvailableCondition; |
michael@0 | 928 | @@ -192,23 +132,13 @@ private: |
michael@0 | 929 | int64_t mGlitchDurationThresholdUs; |
michael@0 | 930 | bool mCollectStats; |
michael@0 | 931 | bool mIsMetaDataStoredInVideoBuffers; |
michael@0 | 932 | + int32_t mCameraHandle; |
michael@0 | 933 | |
michael@0 | 934 | void releaseQueuedFrames(); |
michael@0 | 935 | void releaseOneRecordingFrame(const sp<IMemory>& frame); |
michael@0 | 936 | |
michael@0 | 937 | - |
michael@0 | 938 | - status_t init(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 939 | - int32_t cameraId, Size videoSize, int32_t frameRate, |
michael@0 | 940 | - bool storeMetaDataInVideoBuffers); |
michael@0 | 941 | - |
michael@0 | 942 | - status_t initWithCameraAccess( |
michael@0 | 943 | - const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 944 | - int32_t cameraId, Size videoSize, int32_t frameRate, |
michael@0 | 945 | + status_t init(Size videoSize, int32_t frameRate, |
michael@0 | 946 | bool storeMetaDataInVideoBuffers); |
michael@0 | 947 | - |
michael@0 | 948 | - status_t isCameraAvailable(const sp<ICamera>& camera, |
michael@0 | 949 | - const sp<ICameraRecordingProxy>& proxy, |
michael@0 | 950 | - int32_t cameraId); |
michael@0 | 951 | status_t isCameraColorFormatSupported(const CameraParameters& params); |
michael@0 | 952 | status_t configureCamera(CameraParameters* params, |
michael@0 | 953 | int32_t width, int32_t height, |
michael@0 | 954 | @@ -222,10 +152,10 @@ private: |
michael@0 | 955 | |
michael@0 | 956 | void releaseCamera(); |
michael@0 | 957 | |
michael@0 | 958 | - CameraSource(const CameraSource &); |
michael@0 | 959 | - CameraSource &operator=(const CameraSource &); |
michael@0 | 960 | + GonkCameraSource(const GonkCameraSource &); |
michael@0 | 961 | + GonkCameraSource &operator=(const GonkCameraSource &); |
michael@0 | 962 | }; |
michael@0 | 963 | |
michael@0 | 964 | } // namespace android |
michael@0 | 965 | |
michael@0 | 966 | -#endif // CAMERA_SOURCE_H_ |
michael@0 | 967 | +#endif // GONK_CAMERA_SOURCE_H_ |
michael@0 | 968 | diff --git a/GonkRecorder.cpp b/GonkRecorder.cpp |
michael@0 | 969 | index b20ca9d..2dc625c 100644 |
michael@0 | 970 | --- a/GonkRecorder.cpp |
michael@0 | 971 | +++ b/GonkRecorder.cpp |
michael@0 | 972 | @@ -16,35 +16,23 @@ |
michael@0 | 973 | */ |
michael@0 | 974 | |
michael@0 | 975 | //#define LOG_NDEBUG 0 |
michael@0 | 976 | -#define LOG_TAG "StagefrightRecorder" |
michael@0 | 977 | +#define LOG_TAG "GonkRecorder" |
michael@0 | 978 | + |
michael@0 | 979 | #include <utils/Log.h> |
michael@0 | 980 | #include <media/AudioParameter.h> |
michael@0 | 981 | -#include "StagefrightRecorder.h" |
michael@0 | 982 | - |
michael@0 | 983 | -#include <binder/IPCThreadState.h> |
michael@0 | 984 | -#include <binder/IServiceManager.h> |
michael@0 | 985 | +#include "GonkRecorder.h" |
michael@0 | 986 | |
michael@0 | 987 | -#include <media/IMediaPlayerService.h> |
michael@0 | 988 | #include <media/stagefright/AudioSource.h> |
michael@0 | 989 | #include <media/stagefright/AMRWriter.h> |
michael@0 | 990 | -#include <media/stagefright/AACWriter.h> |
michael@0 | 991 | -#include <media/stagefright/ExtendedWriter.h> |
michael@0 | 992 | -#include <media/stagefright/FMA2DPWriter.h> |
michael@0 | 993 | -#include <media/stagefright/CameraSource.h> |
michael@0 | 994 | -#include <media/stagefright/CameraSourceTimeLapse.h> |
michael@0 | 995 | #include <media/stagefright/ExtendedWriter.h> |
michael@0 | 996 | #include <media/stagefright/MPEG2TSWriter.h> |
michael@0 | 997 | #include <media/stagefright/MPEG4Writer.h> |
michael@0 | 998 | #include <media/stagefright/MediaDebug.h> |
michael@0 | 999 | #include <media/stagefright/MediaDefs.h> |
michael@0 | 1000 | #include <media/stagefright/MetaData.h> |
michael@0 | 1001 | -#include <media/stagefright/OMXClient.h> |
michael@0 | 1002 | +#include <OMX.h> |
michael@0 | 1003 | #include <media/stagefright/OMXCodec.h> |
michael@0 | 1004 | -#include <media/stagefright/SurfaceMediaSource.h> |
michael@0 | 1005 | #include <media/MediaProfiles.h> |
michael@0 | 1006 | -#include <camera/ICamera.h> |
michael@0 | 1007 | -#include <camera/CameraParameters.h> |
michael@0 | 1008 | -#include <surfaceflinger/Surface.h> |
michael@0 | 1009 | #include <utils/String8.h> |
michael@0 | 1010 | |
michael@0 | 1011 | #include <utils/Errors.h> |
michael@0 | 1012 | @@ -57,51 +45,41 @@ |
michael@0 | 1013 | #include "ARTPWriter.h" |
michael@0 | 1014 | |
michael@0 | 1015 | #include <cutils/properties.h> |
michael@0 | 1016 | +#include "GonkCameraSource.h" |
michael@0 | 1017 | |
michael@0 | 1018 | namespace android { |
michael@0 | 1019 | |
michael@0 | 1020 | -// To collect the encoder usage for the battery app |
michael@0 | 1021 | -static void addBatteryData(uint32_t params) { |
michael@0 | 1022 | - sp<IBinder> binder = |
michael@0 | 1023 | - defaultServiceManager()->getService(String16("media.player")); |
michael@0 | 1024 | - sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); |
michael@0 | 1025 | - CHECK(service.get() != NULL); |
michael@0 | 1026 | - |
michael@0 | 1027 | - service->addBatteryData(params); |
michael@0 | 1028 | +static sp<IOMX> sOMX = NULL; |
michael@0 | 1029 | +static sp<IOMX> GetOMX() { |
michael@0 | 1030 | + if(sOMX.get() == NULL) { |
michael@0 | 1031 | + sOMX = new OMX; |
michael@0 | 1032 | + } |
michael@0 | 1033 | + return sOMX; |
michael@0 | 1034 | } |
michael@0 | 1035 | |
michael@0 | 1036 | - |
michael@0 | 1037 | -StagefrightRecorder::StagefrightRecorder() |
michael@0 | 1038 | +GonkRecorder::GonkRecorder() |
michael@0 | 1039 | : mWriter(NULL), |
michael@0 | 1040 | mOutputFd(-1), |
michael@0 | 1041 | mAudioSource(AUDIO_SOURCE_CNT), |
michael@0 | 1042 | mVideoSource(VIDEO_SOURCE_LIST_END), |
michael@0 | 1043 | - mStarted(false), mSurfaceMediaSource(NULL), |
michael@0 | 1044 | + mStarted(false), |
michael@0 | 1045 | mDisableAudio(false) { |
michael@0 | 1046 | |
michael@0 | 1047 | LOGV("Constructor"); |
michael@0 | 1048 | reset(); |
michael@0 | 1049 | } |
michael@0 | 1050 | |
michael@0 | 1051 | -StagefrightRecorder::~StagefrightRecorder() { |
michael@0 | 1052 | +GonkRecorder::~GonkRecorder() { |
michael@0 | 1053 | LOGV("Destructor"); |
michael@0 | 1054 | stop(); |
michael@0 | 1055 | } |
michael@0 | 1056 | |
michael@0 | 1057 | -status_t StagefrightRecorder::init() { |
michael@0 | 1058 | +status_t GonkRecorder::init() { |
michael@0 | 1059 | LOGV("init"); |
michael@0 | 1060 | return OK; |
michael@0 | 1061 | } |
michael@0 | 1062 | |
michael@0 | 1063 | -// The client side of mediaserver asks it to creat a SurfaceMediaSource |
michael@0 | 1064 | -// and return a interface reference. The client side will use that |
michael@0 | 1065 | -// while encoding GL Frames |
michael@0 | 1066 | -sp<ISurfaceTexture> StagefrightRecorder::querySurfaceMediaSource() const { |
michael@0 | 1067 | - LOGV("Get SurfaceMediaSource"); |
michael@0 | 1068 | - return mSurfaceMediaSource; |
michael@0 | 1069 | -} |
michael@0 | 1070 | - |
michael@0 | 1071 | -status_t StagefrightRecorder::setAudioSource(audio_source_t as) { |
michael@0 | 1072 | +status_t GonkRecorder::setAudioSource(audio_source_t as) { |
michael@0 | 1073 | LOGV("setAudioSource: %d", as); |
michael@0 | 1074 | if (as < AUDIO_SOURCE_DEFAULT || |
michael@0 | 1075 | as >= AUDIO_SOURCE_CNT) { |
michael@0 | 1076 | @@ -122,7 +100,7 @@ |
michael@0 | 1077 | return OK; |
michael@0 | 1078 | } |
michael@0 | 1079 | |
michael@0 | 1080 | -status_t StagefrightRecorder::setVideoSource(video_source vs) { |
michael@0 | 1081 | +status_t GonkRecorder::setVideoSource(video_source vs) { |
michael@0 | 1082 | LOGV("setVideoSource: %d", vs); |
michael@0 | 1083 | if (vs < VIDEO_SOURCE_DEFAULT || |
michael@0 | 1084 | vs >= VIDEO_SOURCE_LIST_END) { |
michael@0 | 1085 | @@ -139,7 +117,7 @@ |
michael@0 | 1086 | return OK; |
michael@0 | 1087 | } |
michael@0 | 1088 | |
michael@0 | 1089 | -status_t StagefrightRecorder::setOutputFormat(output_format of) { |
michael@0 | 1090 | +status_t GonkRecorder::setOutputFormat(output_format of) { |
michael@0 | 1091 | LOGV("setOutputFormat: %d", of); |
michael@0 | 1092 | if (of < OUTPUT_FORMAT_DEFAULT || |
michael@0 | 1093 | of >= OUTPUT_FORMAT_LIST_END) { |
michael@0 | 1094 | @@ -156,7 +134,7 @@ |
michael@0 | 1095 | return OK; |
michael@0 | 1096 | } |
michael@0 | 1097 | |
michael@0 | 1098 | -status_t StagefrightRecorder::setAudioEncoder(audio_encoder ae) { |
michael@0 | 1099 | +status_t GonkRecorder::setAudioEncoder(audio_encoder ae) { |
michael@0 | 1100 | LOGV("setAudioEncoder: %d", ae); |
michael@0 | 1101 | if (ae < AUDIO_ENCODER_DEFAULT || |
michael@0 | 1102 | ae >= AUDIO_ENCODER_LIST_END) { |
michael@0 | 1103 | @@ -174,21 +152,10 @@ |
michael@0 | 1104 | mAudioEncoder = ae; |
michael@0 | 1105 | } |
michael@0 | 1106 | |
michael@0 | 1107 | - // Use default values if appropriate setparam's weren't called. |
michael@0 | 1108 | - if(mAudioEncoder == AUDIO_ENCODER_AAC) { |
michael@0 | 1109 | - mSampleRate = mSampleRate ? mSampleRate : 48000; |
michael@0 | 1110 | - mAudioChannels = mAudioChannels ? mAudioChannels : 2; |
michael@0 | 1111 | - mAudioBitRate = mAudioBitRate ? mAudioBitRate : 156000; |
michael@0 | 1112 | - } |
michael@0 | 1113 | - else{ |
michael@0 | 1114 | - mSampleRate = mSampleRate ? mSampleRate : 8000; |
michael@0 | 1115 | - mAudioChannels = mAudioChannels ? mAudioChannels : 1; |
michael@0 | 1116 | - mAudioBitRate = mAudioBitRate ? mAudioBitRate : 12200; |
michael@0 | 1117 | - } |
michael@0 | 1118 | return OK; |
michael@0 | 1119 | } |
michael@0 | 1120 | |
michael@0 | 1121 | -status_t StagefrightRecorder::setVideoEncoder(video_encoder ve) { |
michael@0 | 1122 | +status_t GonkRecorder::setVideoEncoder(video_encoder ve) { |
michael@0 | 1123 | LOGV("setVideoEncoder: %d", ve); |
michael@0 | 1124 | if (ve < VIDEO_ENCODER_DEFAULT || |
michael@0 | 1125 | ve >= VIDEO_ENCODER_LIST_END) { |
michael@0 | 1126 | @@ -205,7 +172,7 @@ |
michael@0 | 1127 | return OK; |
michael@0 | 1128 | } |
michael@0 | 1129 | |
michael@0 | 1130 | -status_t StagefrightRecorder::setVideoSize(int width, int height) { |
michael@0 | 1131 | +status_t GonkRecorder::setVideoSize(int width, int height) { |
michael@0 | 1132 | LOGV("setVideoSize: %dx%d", width, height); |
michael@0 | 1133 | if (width <= 0 || height <= 0) { |
michael@0 | 1134 | LOGE("Invalid video size: %dx%d", width, height); |
michael@0 | 1135 | @@ -219,7 +186,7 @@ |
michael@0 | 1136 | return OK; |
michael@0 | 1137 | } |
michael@0 | 1138 | |
michael@0 | 1139 | -status_t StagefrightRecorder::setVideoFrameRate(int frames_per_second) { |
michael@0 | 1140 | +status_t GonkRecorder::setVideoFrameRate(int frames_per_second) { |
michael@0 | 1141 | LOGV("setVideoFrameRate: %d", frames_per_second); |
michael@0 | 1142 | if ((frames_per_second <= 0 && frames_per_second != -1) || |
michael@0 | 1143 | frames_per_second > 120) { |
michael@0 | 1144 | @@ -233,31 +200,7 @@ |
michael@0 | 1145 | return OK; |
michael@0 | 1146 | } |
michael@0 | 1147 | |
michael@0 | 1148 | -status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera, |
michael@0 | 1149 | - const sp<ICameraRecordingProxy> &proxy) { |
michael@0 | 1150 | - LOGV("setCamera"); |
michael@0 | 1151 | - if (camera == 0) { |
michael@0 | 1152 | - LOGE("camera is NULL"); |
michael@0 | 1153 | - return BAD_VALUE; |
michael@0 | 1154 | - } |
michael@0 | 1155 | - if (proxy == 0) { |
michael@0 | 1156 | - LOGE("camera proxy is NULL"); |
michael@0 | 1157 | - return BAD_VALUE; |
michael@0 | 1158 | - } |
michael@0 | 1159 | - |
michael@0 | 1160 | - mCamera = camera; |
michael@0 | 1161 | - mCameraProxy = proxy; |
michael@0 | 1162 | - return OK; |
michael@0 | 1163 | -} |
michael@0 | 1164 | - |
michael@0 | 1165 | -status_t StagefrightRecorder::setPreviewSurface(const sp<Surface> &surface) { |
michael@0 | 1166 | - LOGV("setPreviewSurface: %p", surface.get()); |
michael@0 | 1167 | - mPreviewSurface = surface; |
michael@0 | 1168 | - |
michael@0 | 1169 | - return OK; |
michael@0 | 1170 | -} |
michael@0 | 1171 | - |
michael@0 | 1172 | -status_t StagefrightRecorder::setOutputFile(const char *path) { |
michael@0 | 1173 | +status_t GonkRecorder::setOutputFile(const char *path) { |
michael@0 | 1174 | LOGE("setOutputFile(const char*) must not be called"); |
michael@0 | 1175 | // We don't actually support this at all, as the media_server process |
michael@0 | 1176 | // no longer has permissions to create files. |
michael@0 | 1177 | @@ -265,7 +208,7 @@ |
michael@0 | 1178 | return -EPERM; |
michael@0 | 1179 | } |
michael@0 | 1180 | |
michael@0 | 1181 | -status_t StagefrightRecorder::setOutputFile(int fd, int64_t offset, int64_t length) { |
michael@0 | 1182 | +status_t GonkRecorder::setOutputFile(int fd, int64_t offset, int64_t length) { |
michael@0 | 1183 | LOGV("setOutputFile: %d, %lld, %lld", fd, offset, length); |
michael@0 | 1184 | // These don't make any sense, do they? |
michael@0 | 1185 | CHECK_EQ(offset, 0); |
michael@0 | 1186 | @@ -339,7 +282,7 @@ |
michael@0 | 1187 | s->setTo(String8(&data[leading_space], i - leading_space)); |
michael@0 | 1188 | } |
michael@0 | 1189 | |
michael@0 | 1190 | -status_t StagefrightRecorder::setParamAudioSamplingRate(int32_t sampleRate) { |
michael@0 | 1191 | +status_t GonkRecorder::setParamAudioSamplingRate(int32_t sampleRate) { |
michael@0 | 1192 | LOGV("setParamAudioSamplingRate: %d", sampleRate); |
michael@0 | 1193 | if (sampleRate <= 0) { |
michael@0 | 1194 | LOGE("Invalid audio sampling rate: %d", sampleRate); |
michael@0 | 1195 | @@ -351,7 +294,7 @@ |
michael@0 | 1196 | return OK; |
michael@0 | 1197 | } |
michael@0 | 1198 | |
michael@0 | 1199 | -status_t StagefrightRecorder::setParamAudioNumberOfChannels(int32_t channels) { |
michael@0 | 1200 | +status_t GonkRecorder::setParamAudioNumberOfChannels(int32_t channels) { |
michael@0 | 1201 | LOGV("setParamAudioNumberOfChannels: %d", channels); |
michael@0 | 1202 | if (channels <= 0 || channels >= 3) { |
michael@0 | 1203 | LOGE("Invalid number of audio channels: %d", channels); |
michael@0 | 1204 | @@ -363,7 +306,7 @@ |
michael@0 | 1205 | return OK; |
michael@0 | 1206 | } |
michael@0 | 1207 | |
michael@0 | 1208 | -status_t StagefrightRecorder::setParamAudioEncodingBitRate(int32_t bitRate) { |
michael@0 | 1209 | +status_t GonkRecorder::setParamAudioEncodingBitRate(int32_t bitRate) { |
michael@0 | 1210 | LOGV("setParamAudioEncodingBitRate: %d", bitRate); |
michael@0 | 1211 | if (bitRate <= 0) { |
michael@0 | 1212 | LOGE("Invalid audio encoding bit rate: %d", bitRate); |
michael@0 | 1213 | @@ -378,7 +321,7 @@ |
michael@0 | 1214 | return OK; |
michael@0 | 1215 | } |
michael@0 | 1216 | |
michael@0 | 1217 | -status_t StagefrightRecorder::setParamVideoEncodingBitRate(int32_t bitRate) { |
michael@0 | 1218 | +status_t GonkRecorder::setParamVideoEncodingBitRate(int32_t bitRate) { |
michael@0 | 1219 | LOGV("setParamVideoEncodingBitRate: %d", bitRate); |
michael@0 | 1220 | if (bitRate <= 0) { |
michael@0 | 1221 | LOGE("Invalid video encoding bit rate: %d", bitRate); |
michael@0 | 1222 | @@ -394,7 +337,7 @@ |
michael@0 | 1223 | } |
michael@0 | 1224 | |
michael@0 | 1225 | // Always rotate clockwise, and only support 0, 90, 180 and 270 for now. |
michael@0 | 1226 | -status_t StagefrightRecorder::setParamVideoRotation(int32_t degrees) { |
michael@0 | 1227 | +status_t GonkRecorder::setParamVideoRotation(int32_t degrees) { |
michael@0 | 1228 | LOGV("setParamVideoRotation: %d", degrees); |
michael@0 | 1229 | if (degrees < 0 || degrees % 90 != 0) { |
michael@0 | 1230 | LOGE("Unsupported video rotation angle: %d", degrees); |
michael@0 | 1231 | @@ -404,7 +347,7 @@ |
michael@0 | 1232 | return OK; |
michael@0 | 1233 | } |
michael@0 | 1234 | |
michael@0 | 1235 | -status_t StagefrightRecorder::setParamMaxFileDurationUs(int64_t timeUs) { |
michael@0 | 1236 | +status_t GonkRecorder::setParamMaxFileDurationUs(int64_t timeUs) { |
michael@0 | 1237 | LOGV("setParamMaxFileDurationUs: %lld us", timeUs); |
michael@0 | 1238 | |
michael@0 | 1239 | // This is meant for backward compatibility for MediaRecorder.java |
michael@0 | 1240 | @@ -423,7 +366,7 @@ |
michael@0 | 1241 | return OK; |
michael@0 | 1242 | } |
michael@0 | 1243 | |
michael@0 | 1244 | -status_t StagefrightRecorder::setParamMaxFileSizeBytes(int64_t bytes) { |
michael@0 | 1245 | +status_t GonkRecorder::setParamMaxFileSizeBytes(int64_t bytes) { |
michael@0 | 1246 | LOGV("setParamMaxFileSizeBytes: %lld bytes", bytes); |
michael@0 | 1247 | |
michael@0 | 1248 | // This is meant for backward compatibility for MediaRecorder.java |
michael@0 | 1249 | @@ -449,7 +392,7 @@ |
michael@0 | 1250 | return OK; |
michael@0 | 1251 | } |
michael@0 | 1252 | |
michael@0 | 1253 | -status_t StagefrightRecorder::setParamInterleaveDuration(int32_t durationUs) { |
michael@0 | 1254 | +status_t GonkRecorder::setParamInterleaveDuration(int32_t durationUs) { |
michael@0 | 1255 | LOGV("setParamInterleaveDuration: %d", durationUs); |
michael@0 | 1256 | if (durationUs <= 500000) { // 500 ms |
michael@0 | 1257 | // If interleave duration is too small, it is very inefficient to do |
michael@0 | 1258 | @@ -471,20 +414,20 @@ |
michael@0 | 1259 | // If seconds < 0, only the first frame is I frame, and rest are all P frames |
michael@0 | 1260 | // If seconds == 0, all frames are encoded as I frames. No P frames |
michael@0 | 1261 | // If seconds > 0, it is the time spacing (seconds) between 2 neighboring I frames |
michael@0 | 1262 | -status_t StagefrightRecorder::setParamVideoIFramesInterval(int32_t seconds) { |
michael@0 | 1263 | +status_t GonkRecorder::setParamVideoIFramesInterval(int32_t seconds) { |
michael@0 | 1264 | LOGV("setParamVideoIFramesInterval: %d seconds", seconds); |
michael@0 | 1265 | mIFramesIntervalSec = seconds; |
michael@0 | 1266 | return OK; |
michael@0 | 1267 | } |
michael@0 | 1268 | |
michael@0 | 1269 | -status_t StagefrightRecorder::setParam64BitFileOffset(bool use64Bit) { |
michael@0 | 1270 | +status_t GonkRecorder::setParam64BitFileOffset(bool use64Bit) { |
michael@0 | 1271 | LOGV("setParam64BitFileOffset: %s", |
michael@0 | 1272 | use64Bit? "use 64 bit file offset": "use 32 bit file offset"); |
michael@0 | 1273 | mUse64BitFileOffset = use64Bit; |
michael@0 | 1274 | return OK; |
michael@0 | 1275 | } |
michael@0 | 1276 | |
michael@0 | 1277 | -status_t StagefrightRecorder::setParamVideoCameraId(int32_t cameraId) { |
michael@0 | 1278 | +status_t GonkRecorder::setParamVideoCameraId(int32_t cameraId) { |
michael@0 | 1279 | LOGV("setParamVideoCameraId: %d", cameraId); |
michael@0 | 1280 | if (cameraId < 0) { |
michael@0 | 1281 | return BAD_VALUE; |
michael@0 | 1282 | @@ -493,7 +436,7 @@ |
michael@0 | 1283 | return OK; |
michael@0 | 1284 | } |
michael@0 | 1285 | |
michael@0 | 1286 | -status_t StagefrightRecorder::setParamTrackTimeStatus(int64_t timeDurationUs) { |
michael@0 | 1287 | +status_t GonkRecorder::setParamTrackTimeStatus(int64_t timeDurationUs) { |
michael@0 | 1288 | LOGV("setParamTrackTimeStatus: %lld", timeDurationUs); |
michael@0 | 1289 | if (timeDurationUs < 20000) { // Infeasible if shorter than 20 ms? |
michael@0 | 1290 | LOGE("Tracking time duration too short: %lld us", timeDurationUs); |
michael@0 | 1291 | @@ -503,7 +446,7 @@ |
michael@0 | 1292 | return OK; |
michael@0 | 1293 | } |
michael@0 | 1294 | |
michael@0 | 1295 | -status_t StagefrightRecorder::setParamVideoEncoderProfile(int32_t profile) { |
michael@0 | 1296 | +status_t GonkRecorder::setParamVideoEncoderProfile(int32_t profile) { |
michael@0 | 1297 | LOGV("setParamVideoEncoderProfile: %d", profile); |
michael@0 | 1298 | |
michael@0 | 1299 | // Additional check will be done later when we load the encoder. |
michael@0 | 1300 | @@ -512,7 +455,7 @@ |
michael@0 | 1301 | return OK; |
michael@0 | 1302 | } |
michael@0 | 1303 | |
michael@0 | 1304 | -status_t StagefrightRecorder::setParamVideoEncoderLevel(int32_t level) { |
michael@0 | 1305 | +status_t GonkRecorder::setParamVideoEncoderLevel(int32_t level) { |
michael@0 | 1306 | LOGV("setParamVideoEncoderLevel: %d", level); |
michael@0 | 1307 | |
michael@0 | 1308 | // Additional check will be done later when we load the encoder. |
michael@0 | 1309 | @@ -521,7 +464,7 @@ |
michael@0 | 1310 | return OK; |
michael@0 | 1311 | } |
michael@0 | 1312 | |
michael@0 | 1313 | -status_t StagefrightRecorder::setParamMovieTimeScale(int32_t timeScale) { |
michael@0 | 1314 | +status_t GonkRecorder::setParamMovieTimeScale(int32_t timeScale) { |
michael@0 | 1315 | LOGV("setParamMovieTimeScale: %d", timeScale); |
michael@0 | 1316 | |
michael@0 | 1317 | // The range is set to be the same as the audio's time scale range |
michael@0 | 1318 | @@ -534,7 +477,7 @@ |
michael@0 | 1319 | return OK; |
michael@0 | 1320 | } |
michael@0 | 1321 | |
michael@0 | 1322 | -status_t StagefrightRecorder::setParamVideoTimeScale(int32_t timeScale) { |
michael@0 | 1323 | +status_t GonkRecorder::setParamVideoTimeScale(int32_t timeScale) { |
michael@0 | 1324 | LOGV("setParamVideoTimeScale: %d", timeScale); |
michael@0 | 1325 | |
michael@0 | 1326 | // 60000 is chosen to make sure that each video frame from a 60-fps |
michael@0 | 1327 | @@ -547,7 +490,7 @@ |
michael@0 | 1328 | return OK; |
michael@0 | 1329 | } |
michael@0 | 1330 | |
michael@0 | 1331 | -status_t StagefrightRecorder::setParamAudioTimeScale(int32_t timeScale) { |
michael@0 | 1332 | +status_t GonkRecorder::setParamAudioTimeScale(int32_t timeScale) { |
michael@0 | 1333 | LOGV("setParamAudioTimeScale: %d", timeScale); |
michael@0 | 1334 | |
michael@0 | 1335 | // 96000 Hz is the highest sampling rate support in AAC. |
michael@0 | 1336 | @@ -559,33 +502,7 @@ |
michael@0 | 1337 | return OK; |
michael@0 | 1338 | } |
michael@0 | 1339 | |
michael@0 | 1340 | -status_t StagefrightRecorder::setParamTimeLapseEnable(int32_t timeLapseEnable) { |
michael@0 | 1341 | - LOGV("setParamTimeLapseEnable: %d", timeLapseEnable); |
michael@0 | 1342 | - |
michael@0 | 1343 | - if(timeLapseEnable == 0) { |
michael@0 | 1344 | - mCaptureTimeLapse = false; |
michael@0 | 1345 | - } else if (timeLapseEnable == 1) { |
michael@0 | 1346 | - mCaptureTimeLapse = true; |
michael@0 | 1347 | - } else { |
michael@0 | 1348 | - return BAD_VALUE; |
michael@0 | 1349 | - } |
michael@0 | 1350 | - return OK; |
michael@0 | 1351 | -} |
michael@0 | 1352 | - |
michael@0 | 1353 | -status_t StagefrightRecorder::setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs) { |
michael@0 | 1354 | - LOGV("setParamTimeBetweenTimeLapseFrameCapture: %lld us", timeUs); |
michael@0 | 1355 | - |
michael@0 | 1356 | - // Not allowing time more than a day |
michael@0 | 1357 | - if (timeUs <= 0 || timeUs > 86400*1E6) { |
michael@0 | 1358 | - LOGE("Time between time lapse frame capture (%lld) is out of range [0, 1 Day]", timeUs); |
michael@0 | 1359 | - return BAD_VALUE; |
michael@0 | 1360 | - } |
michael@0 | 1361 | - |
michael@0 | 1362 | - mTimeBetweenTimeLapseFrameCaptureUs = timeUs; |
michael@0 | 1363 | - return OK; |
michael@0 | 1364 | -} |
michael@0 | 1365 | - |
michael@0 | 1366 | -status_t StagefrightRecorder::setParamGeoDataLongitude( |
michael@0 | 1367 | +status_t GonkRecorder::setParamGeoDataLongitude( |
michael@0 | 1368 | int64_t longitudex10000) { |
michael@0 | 1369 | |
michael@0 | 1370 | if (longitudex10000 > 1800000 || longitudex10000 < -1800000) { |
michael@0 | 1371 | @@ -595,7 +512,7 @@ |
michael@0 | 1372 | return OK; |
michael@0 | 1373 | } |
michael@0 | 1374 | |
michael@0 | 1375 | -status_t StagefrightRecorder::setParamGeoDataLatitude( |
michael@0 | 1376 | +status_t GonkRecorder::setParamGeoDataLatitude( |
michael@0 | 1377 | int64_t latitudex10000) { |
michael@0 | 1378 | |
michael@0 | 1379 | if (latitudex10000 > 900000 || latitudex10000 < -900000) { |
michael@0 | 1380 | @@ -605,7 +522,7 @@ |
michael@0 | 1381 | return OK; |
michael@0 | 1382 | } |
michael@0 | 1383 | |
michael@0 | 1384 | -status_t StagefrightRecorder::setParameter( |
michael@0 | 1385 | +status_t GonkRecorder::setParameter( |
michael@0 | 1386 | const String8 &key, const String8 &value) { |
michael@0 | 1387 | LOGV("setParameter: key (%s) => value (%s)", key.string(), value.string()); |
michael@0 | 1388 | if (key == "max-duration") { |
michael@0 | 1389 | @@ -703,24 +620,13 @@ |
michael@0 | 1390 | if (safe_strtoi32(value.string(), &timeScale)) { |
michael@0 | 1391 | return setParamVideoTimeScale(timeScale); |
michael@0 | 1392 | } |
michael@0 | 1393 | - } else if (key == "time-lapse-enable") { |
michael@0 | 1394 | - int32_t timeLapseEnable; |
michael@0 | 1395 | - if (safe_strtoi32(value.string(), &timeLapseEnable)) { |
michael@0 | 1396 | - return setParamTimeLapseEnable(timeLapseEnable); |
michael@0 | 1397 | - } |
michael@0 | 1398 | - } else if (key == "time-between-time-lapse-frame-capture") { |
michael@0 | 1399 | - int64_t timeBetweenTimeLapseFrameCaptureMs; |
michael@0 | 1400 | - if (safe_strtoi64(value.string(), &timeBetweenTimeLapseFrameCaptureMs)) { |
michael@0 | 1401 | - return setParamTimeBetweenTimeLapseFrameCapture( |
michael@0 | 1402 | - 1000LL * timeBetweenTimeLapseFrameCaptureMs); |
michael@0 | 1403 | - } |
michael@0 | 1404 | } else { |
michael@0 | 1405 | LOGE("setParameter: failed to find key %s", key.string()); |
michael@0 | 1406 | } |
michael@0 | 1407 | return BAD_VALUE; |
michael@0 | 1408 | } |
michael@0 | 1409 | |
michael@0 | 1410 | -status_t StagefrightRecorder::setParameters(const String8 ¶ms) { |
michael@0 | 1411 | +status_t GonkRecorder::setParameters(const String8 ¶ms) { |
michael@0 | 1412 | LOGV("setParameters: %s", params.string()); |
michael@0 | 1413 | const char *cparams = params.string(); |
michael@0 | 1414 | const char *key_start = cparams; |
michael@0 | 1415 | @@ -755,13 +661,13 @@ |
michael@0 | 1416 | return OK; |
michael@0 | 1417 | } |
michael@0 | 1418 | |
michael@0 | 1419 | -status_t StagefrightRecorder::setListener(const sp<IMediaRecorderClient> &listener) { |
michael@0 | 1420 | +status_t GonkRecorder::setListener(const sp<IMediaRecorderClient> &listener) { |
michael@0 | 1421 | mListener = listener; |
michael@0 | 1422 | |
michael@0 | 1423 | return OK; |
michael@0 | 1424 | } |
michael@0 | 1425 | |
michael@0 | 1426 | -status_t StagefrightRecorder::prepare() { |
michael@0 | 1427 | +status_t GonkRecorder::prepare() { |
michael@0 | 1428 | LOGV(" %s E", __func__ ); |
michael@0 | 1429 | |
michael@0 | 1430 | if(mVideoSource != VIDEO_SOURCE_LIST_END && mVideoEncoder != VIDEO_ENCODER_LIST_END && mVideoHeight && mVideoWidth && /*Video recording*/ |
michael@0 | 1431 | @@ -776,17 +682,15 @@ |
michael@0 | 1432 | return OK; |
michael@0 | 1433 | } |
michael@0 | 1434 | |
michael@0 | 1435 | -status_t StagefrightRecorder::start() { |
michael@0 | 1436 | +status_t GonkRecorder::start() { |
michael@0 | 1437 | CHECK(mOutputFd >= 0); |
michael@0 | 1438 | |
michael@0 | 1439 | if (mWriter != NULL) { |
michael@0 | 1440 | - LOGE("File writer is not avaialble"); |
michael@0 | 1441 | + LOGE("File writer is not available"); |
michael@0 | 1442 | return UNKNOWN_ERROR; |
michael@0 | 1443 | } |
michael@0 | 1444 | |
michael@0 | 1445 | status_t status = OK; |
michael@0 | 1446 | - if(AUDIO_SOURCE_FM_RX_A2DP == mAudioSource) |
michael@0 | 1447 | - return startFMA2DPWriter(); |
michael@0 | 1448 | |
michael@0 | 1449 | switch (mOutputFormat) { |
michael@0 | 1450 | case OUTPUT_FORMAT_DEFAULT: |
michael@0 | 1451 | @@ -800,22 +704,9 @@ |
michael@0 | 1452 | status = startAMRRecording(); |
michael@0 | 1453 | break; |
michael@0 | 1454 | |
michael@0 | 1455 | - case OUTPUT_FORMAT_AAC_ADIF: |
michael@0 | 1456 | - case OUTPUT_FORMAT_AAC_ADTS: |
michael@0 | 1457 | - status = startAACRecording(); |
michael@0 | 1458 | - break; |
michael@0 | 1459 | - |
michael@0 | 1460 | - case OUTPUT_FORMAT_RTP_AVP: |
michael@0 | 1461 | - status = startRTPRecording(); |
michael@0 | 1462 | - break; |
michael@0 | 1463 | - |
michael@0 | 1464 | case OUTPUT_FORMAT_MPEG2TS: |
michael@0 | 1465 | status = startMPEG2TSRecording(); |
michael@0 | 1466 | break; |
michael@0 | 1467 | - |
michael@0 | 1468 | - case OUTPUT_FORMAT_QCP: |
michael@0 | 1469 | - status = startExtendedRecording( ); |
michael@0 | 1470 | - break; |
michael@0 | 1471 | default: |
michael@0 | 1472 | LOGE("Unsupported output file format: %d", mOutputFormat); |
michael@0 | 1473 | status = UNKNOWN_ERROR; |
michael@0 | 1474 | @@ -824,22 +715,12 @@ |
michael@0 | 1475 | |
michael@0 | 1476 | if ((status == OK) && (!mStarted)) { |
michael@0 | 1477 | mStarted = true; |
michael@0 | 1478 | - |
michael@0 | 1479 | - uint32_t params = IMediaPlayerService::kBatteryDataCodecStarted; |
michael@0 | 1480 | - if (mAudioSource != AUDIO_SOURCE_CNT) { |
michael@0 | 1481 | - params |= IMediaPlayerService::kBatteryDataTrackAudio; |
michael@0 | 1482 | - } |
michael@0 | 1483 | - if (mVideoSource != VIDEO_SOURCE_LIST_END) { |
michael@0 | 1484 | - params |= IMediaPlayerService::kBatteryDataTrackVideo; |
michael@0 | 1485 | - } |
michael@0 | 1486 | - |
michael@0 | 1487 | - addBatteryData(params); |
michael@0 | 1488 | } |
michael@0 | 1489 | |
michael@0 | 1490 | return status; |
michael@0 | 1491 | } |
michael@0 | 1492 | |
michael@0 | 1493 | -sp<MediaSource> StagefrightRecorder::createAudioSource() { |
michael@0 | 1494 | +sp<MediaSource> GonkRecorder::createAudioSource() { |
michael@0 | 1495 | |
michael@0 | 1496 | bool tunneledSource = false; |
michael@0 | 1497 | const char *tunnelMime; |
michael@0 | 1498 | @@ -907,12 +788,6 @@ |
michael@0 | 1499 | case AUDIO_ENCODER_AAC: |
michael@0 | 1500 | mime = MEDIA_MIMETYPE_AUDIO_AAC; |
michael@0 | 1501 | break; |
michael@0 | 1502 | - case AUDIO_ENCODER_EVRC: |
michael@0 | 1503 | - mime = MEDIA_MIMETYPE_AUDIO_EVRC; |
michael@0 | 1504 | - break; |
michael@0 | 1505 | - case AUDIO_ENCODER_QCELP: |
michael@0 | 1506 | - mime = MEDIA_MIMETYPE_AUDIO_QCELP; |
michael@0 | 1507 | - break; |
michael@0 | 1508 | default: |
michael@0 | 1509 | LOGE("Unknown audio encoder: %d", mAudioEncoder); |
michael@0 | 1510 | return NULL; |
michael@0 | 1511 | @@ -931,36 +806,17 @@ |
michael@0 | 1512 | encMeta->setInt32(kKeyTimeScale, mAudioTimeScale); |
michael@0 | 1513 | } |
michael@0 | 1514 | |
michael@0 | 1515 | - OMXClient client; |
michael@0 | 1516 | - CHECK_EQ(client.connect(), OK); |
michael@0 | 1517 | - |
michael@0 | 1518 | + // use direct OMX interface instead of connecting to |
michael@0 | 1519 | + // mediaserver over binder calls |
michael@0 | 1520 | sp<MediaSource> audioEncoder = |
michael@0 | 1521 | - OMXCodec::Create(client.interface(), encMeta, |
michael@0 | 1522 | + OMXCodec::Create(GetOMX(), encMeta, |
michael@0 | 1523 | true /* createEncoder */, audioSource); |
michael@0 | 1524 | mAudioSourceNode = audioSource; |
michael@0 | 1525 | |
michael@0 | 1526 | return audioEncoder; |
michael@0 | 1527 | } |
michael@0 | 1528 | |
michael@0 | 1529 | -status_t StagefrightRecorder::startAACRecording() { |
michael@0 | 1530 | - // FIXME: |
michael@0 | 1531 | - // Add support for OUTPUT_FORMAT_AAC_ADIF |
michael@0 | 1532 | - CHECK(mOutputFormat == OUTPUT_FORMAT_AAC_ADTS); |
michael@0 | 1533 | - |
michael@0 | 1534 | - CHECK(mAudioEncoder == AUDIO_ENCODER_AAC); |
michael@0 | 1535 | - CHECK(mAudioSource != AUDIO_SOURCE_CNT); |
michael@0 | 1536 | - |
michael@0 | 1537 | - mWriter = new AACWriter(mOutputFd); |
michael@0 | 1538 | - status_t status = startRawAudioRecording(); |
michael@0 | 1539 | - if (status != OK) { |
michael@0 | 1540 | - mWriter.clear(); |
michael@0 | 1541 | - mWriter = NULL; |
michael@0 | 1542 | - } |
michael@0 | 1543 | - |
michael@0 | 1544 | - return status; |
michael@0 | 1545 | -} |
michael@0 | 1546 | - |
michael@0 | 1547 | -status_t StagefrightRecorder::startAMRRecording() { |
michael@0 | 1548 | +status_t GonkRecorder::startAMRRecording() { |
michael@0 | 1549 | CHECK(mOutputFormat == OUTPUT_FORMAT_AMR_NB || |
michael@0 | 1550 | mOutputFormat == OUTPUT_FORMAT_AMR_WB); |
michael@0 | 1551 | |
michael@0 | 1552 | @@ -971,28 +827,12 @@ |
michael@0 | 1553 | mAudioEncoder); |
michael@0 | 1554 | return BAD_VALUE; |
michael@0 | 1555 | } |
michael@0 | 1556 | - if (mSampleRate != 8000) { |
michael@0 | 1557 | - LOGE("Invalid sampling rate %d used for AMRNB recording", |
michael@0 | 1558 | - mSampleRate); |
michael@0 | 1559 | - return BAD_VALUE; |
michael@0 | 1560 | - } |
michael@0 | 1561 | } else { // mOutputFormat must be OUTPUT_FORMAT_AMR_WB |
michael@0 | 1562 | if (mAudioEncoder != AUDIO_ENCODER_AMR_WB) { |
michael@0 | 1563 | LOGE("Invlaid encoder %d used for AMRWB recording", |
michael@0 | 1564 | mAudioEncoder); |
michael@0 | 1565 | return BAD_VALUE; |
michael@0 | 1566 | } |
michael@0 | 1567 | - if (mSampleRate != 16000) { |
michael@0 | 1568 | - LOGE("Invalid sample rate %d used for AMRWB recording", |
michael@0 | 1569 | - mSampleRate); |
michael@0 | 1570 | - return BAD_VALUE; |
michael@0 | 1571 | - } |
michael@0 | 1572 | - } |
michael@0 | 1573 | - |
michael@0 | 1574 | - if (mAudioChannels != 1) { |
michael@0 | 1575 | - LOGE("Invalid number of audio channels %d used for amr recording", |
michael@0 | 1576 | - mAudioChannels); |
michael@0 | 1577 | - return BAD_VALUE; |
michael@0 | 1578 | } |
michael@0 | 1579 | |
michael@0 | 1580 | mWriter = new AMRWriter(mOutputFd); |
michael@0 | 1581 | @@ -1004,7 +844,7 @@ |
michael@0 | 1582 | return status; |
michael@0 | 1583 | } |
michael@0 | 1584 | |
michael@0 | 1585 | -status_t StagefrightRecorder::startRawAudioRecording() { |
michael@0 | 1586 | +status_t GonkRecorder::startRawAudioRecording() { |
michael@0 | 1587 | if (mAudioSource >= AUDIO_SOURCE_CNT) { |
michael@0 | 1588 | LOGE("Invalid audio source: %d", mAudioSource); |
michael@0 | 1589 | return BAD_VALUE; |
michael@0 | 1590 | @@ -1035,62 +875,7 @@ |
michael@0 | 1591 | return OK; |
michael@0 | 1592 | } |
michael@0 | 1593 | |
michael@0 | 1594 | -status_t StagefrightRecorder::startFMA2DPWriter() { |
michael@0 | 1595 | - /* FM soc outputs at 48k */ |
michael@0 | 1596 | - mSampleRate = 48000; |
michael@0 | 1597 | - mAudioChannels = 2; |
michael@0 | 1598 | - |
michael@0 | 1599 | - sp<MetaData> meta = new MetaData; |
michael@0 | 1600 | - meta->setInt32(kKeyChannelCount, mAudioChannels); |
michael@0 | 1601 | - meta->setInt32(kKeySampleRate, mSampleRate); |
michael@0 | 1602 | - |
michael@0 | 1603 | - mWriter = new FMA2DPWriter(); |
michael@0 | 1604 | - mWriter->setListener(mListener); |
michael@0 | 1605 | - mWriter->start(meta.get()); |
michael@0 | 1606 | - return OK; |
michael@0 | 1607 | -} |
michael@0 | 1608 | - |
michael@0 | 1609 | -status_t StagefrightRecorder::startRTPRecording() { |
michael@0 | 1610 | - CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_RTP_AVP); |
michael@0 | 1611 | - |
michael@0 | 1612 | - if ((mAudioSource != AUDIO_SOURCE_CNT |
michael@0 | 1613 | - && mVideoSource != VIDEO_SOURCE_LIST_END) |
michael@0 | 1614 | - || (mAudioSource == AUDIO_SOURCE_CNT |
michael@0 | 1615 | - && mVideoSource == VIDEO_SOURCE_LIST_END)) { |
michael@0 | 1616 | - // Must have exactly one source. |
michael@0 | 1617 | - return BAD_VALUE; |
michael@0 | 1618 | - } |
michael@0 | 1619 | - |
michael@0 | 1620 | - if (mOutputFd < 0) { |
michael@0 | 1621 | - return BAD_VALUE; |
michael@0 | 1622 | - } |
michael@0 | 1623 | - |
michael@0 | 1624 | - sp<MediaSource> source; |
michael@0 | 1625 | - |
michael@0 | 1626 | - if (mAudioSource != AUDIO_SOURCE_CNT) { |
michael@0 | 1627 | - source = createAudioSource(); |
michael@0 | 1628 | - } else { |
michael@0 | 1629 | - |
michael@0 | 1630 | - sp<MediaSource> mediaSource; |
michael@0 | 1631 | - status_t err = setupMediaSource(&mediaSource); |
michael@0 | 1632 | - if (err != OK) { |
michael@0 | 1633 | - return err; |
michael@0 | 1634 | - } |
michael@0 | 1635 | - |
michael@0 | 1636 | - err = setupVideoEncoder(mediaSource, mVideoBitRate, &source); |
michael@0 | 1637 | - if (err != OK) { |
michael@0 | 1638 | - return err; |
michael@0 | 1639 | - } |
michael@0 | 1640 | - } |
michael@0 | 1641 | - |
michael@0 | 1642 | - mWriter = new ARTPWriter(mOutputFd); |
michael@0 | 1643 | - mWriter->addSource(source); |
michael@0 | 1644 | - mWriter->setListener(mListener); |
michael@0 | 1645 | - |
michael@0 | 1646 | - return mWriter->start(); |
michael@0 | 1647 | -} |
michael@0 | 1648 | - |
michael@0 | 1649 | -status_t StagefrightRecorder::startMPEG2TSRecording() { |
michael@0 | 1650 | +status_t GonkRecorder::startMPEG2TSRecording() { |
michael@0 | 1651 | CHECK_EQ(mOutputFormat, OUTPUT_FORMAT_MPEG2TS); |
michael@0 | 1652 | |
michael@0 | 1653 | sp<MediaWriter> writer = new MPEG2TSWriter(mOutputFd); |
michael@0 | 1654 | @@ -1141,7 +926,7 @@ |
michael@0 | 1655 | return mWriter->start(); |
michael@0 | 1656 | } |
michael@0 | 1657 | |
michael@0 | 1658 | -void StagefrightRecorder::clipVideoFrameRate() { |
michael@0 | 1659 | +void GonkRecorder::clipVideoFrameRate() { |
michael@0 | 1660 | LOGV("clipVideoFrameRate: encoder %d", mVideoEncoder); |
michael@0 | 1661 | int minFrameRate = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 1662 | "enc.vid.fps.min", mVideoEncoder); |
michael@0 | 1663 | @@ -1158,7 +943,7 @@ |
michael@0 | 1664 | } |
michael@0 | 1665 | } |
michael@0 | 1666 | |
michael@0 | 1667 | -void StagefrightRecorder::clipVideoBitRate() { |
michael@0 | 1668 | +void GonkRecorder::clipVideoBitRate() { |
michael@0 | 1669 | LOGV("clipVideoBitRate: encoder %d", mVideoEncoder); |
michael@0 | 1670 | int minBitRate = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 1671 | "enc.vid.bps.min", mVideoEncoder); |
michael@0 | 1672 | @@ -1175,7 +960,7 @@ |
michael@0 | 1673 | } |
michael@0 | 1674 | } |
michael@0 | 1675 | |
michael@0 | 1676 | -void StagefrightRecorder::clipVideoFrameWidth() { |
michael@0 | 1677 | +void GonkRecorder::clipVideoFrameWidth() { |
michael@0 | 1678 | LOGV("clipVideoFrameWidth: encoder %d", mVideoEncoder); |
michael@0 | 1679 | int minFrameWidth = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 1680 | "enc.vid.width.min", mVideoEncoder); |
michael@0 | 1681 | @@ -1192,8 +977,7 @@ |
michael@0 | 1682 | } |
michael@0 | 1683 | } |
michael@0 | 1684 | |
michael@0 | 1685 | -status_t StagefrightRecorder::checkVideoEncoderCapabilities() { |
michael@0 | 1686 | - if (!mCaptureTimeLapse) { |
michael@0 | 1687 | +status_t GonkRecorder::checkVideoEncoderCapabilities() { |
michael@0 | 1688 | // Dont clip for time lapse capture as encoder will have enough |
michael@0 | 1689 | // time to encode because of slow capture rate of time lapse. |
michael@0 | 1690 | clipVideoBitRate(); |
michael@0 | 1691 | @@ -1201,13 +985,12 @@ |
michael@0 | 1692 | clipVideoFrameWidth(); |
michael@0 | 1693 | clipVideoFrameHeight(); |
michael@0 | 1694 | setDefaultProfileIfNecessary(); |
michael@0 | 1695 | - } |
michael@0 | 1696 | return OK; |
michael@0 | 1697 | } |
michael@0 | 1698 | |
michael@0 | 1699 | // Set to use AVC baseline profile if the encoding parameters matches |
michael@0 | 1700 | // CAMCORDER_QUALITY_LOW profile; this is for the sake of MMS service. |
michael@0 | 1701 | -void StagefrightRecorder::setDefaultProfileIfNecessary() { |
michael@0 | 1702 | +void GonkRecorder::setDefaultProfileIfNecessary() { |
michael@0 | 1703 | LOGV("setDefaultProfileIfNecessary"); |
michael@0 | 1704 | |
michael@0 | 1705 | camcorder_quality quality = CAMCORDER_QUALITY_LOW; |
michael@0 | 1706 | @@ -1263,14 +1046,14 @@ |
michael@0 | 1707 | } |
michael@0 | 1708 | } |
michael@0 | 1709 | |
michael@0 | 1710 | -status_t StagefrightRecorder::checkAudioEncoderCapabilities() { |
michael@0 | 1711 | +status_t GonkRecorder::checkAudioEncoderCapabilities() { |
michael@0 | 1712 | clipAudioBitRate(); |
michael@0 | 1713 | clipAudioSampleRate(); |
michael@0 | 1714 | clipNumberOfAudioChannels(); |
michael@0 | 1715 | return OK; |
michael@0 | 1716 | } |
michael@0 | 1717 | |
michael@0 | 1718 | -void StagefrightRecorder::clipAudioBitRate() { |
michael@0 | 1719 | +void GonkRecorder::clipAudioBitRate() { |
michael@0 | 1720 | LOGV("clipAudioBitRate: encoder %d", mAudioEncoder); |
michael@0 | 1721 | |
michael@0 | 1722 | int minAudioBitRate = |
michael@0 | 1723 | @@ -1292,7 +1075,7 @@ |
michael@0 | 1724 | } |
michael@0 | 1725 | } |
michael@0 | 1726 | |
michael@0 | 1727 | -void StagefrightRecorder::clipAudioSampleRate() { |
michael@0 | 1728 | +void GonkRecorder::clipAudioSampleRate() { |
michael@0 | 1729 | LOGV("clipAudioSampleRate: encoder %d", mAudioEncoder); |
michael@0 | 1730 | |
michael@0 | 1731 | int minSampleRate = |
michael@0 | 1732 | @@ -1314,7 +1097,7 @@ |
michael@0 | 1733 | } |
michael@0 | 1734 | } |
michael@0 | 1735 | |
michael@0 | 1736 | -void StagefrightRecorder::clipNumberOfAudioChannels() { |
michael@0 | 1737 | +void GonkRecorder::clipNumberOfAudioChannels() { |
michael@0 | 1738 | LOGV("clipNumberOfAudioChannels: encoder %d", mAudioEncoder); |
michael@0 | 1739 | |
michael@0 | 1740 | int minChannels = |
michael@0 | 1741 | @@ -1336,7 +1119,7 @@ |
michael@0 | 1742 | } |
michael@0 | 1743 | } |
michael@0 | 1744 | |
michael@0 | 1745 | -void StagefrightRecorder::clipVideoFrameHeight() { |
michael@0 | 1746 | +void GonkRecorder::clipVideoFrameHeight() { |
michael@0 | 1747 | LOGV("clipVideoFrameHeight: encoder %d", mVideoEncoder); |
michael@0 | 1748 | int minFrameHeight = mEncoderProfiles->getVideoEncoderParamByName( |
michael@0 | 1749 | "enc.vid.height.min", mVideoEncoder); |
michael@0 | 1750 | @@ -1354,61 +1137,26 @@ |
michael@0 | 1751 | } |
michael@0 | 1752 | |
michael@0 | 1753 | // Set up the appropriate MediaSource depending on the chosen option |
michael@0 | 1754 | -status_t StagefrightRecorder::setupMediaSource( |
michael@0 | 1755 | +status_t GonkRecorder::setupMediaSource( |
michael@0 | 1756 | sp<MediaSource> *mediaSource) { |
michael@0 | 1757 | if (mVideoSource == VIDEO_SOURCE_DEFAULT |
michael@0 | 1758 | || mVideoSource == VIDEO_SOURCE_CAMERA) { |
michael@0 | 1759 | - sp<CameraSource> cameraSource; |
michael@0 | 1760 | + sp<GonkCameraSource> cameraSource; |
michael@0 | 1761 | status_t err = setupCameraSource(&cameraSource); |
michael@0 | 1762 | if (err != OK) { |
michael@0 | 1763 | return err; |
michael@0 | 1764 | } |
michael@0 | 1765 | *mediaSource = cameraSource; |
michael@0 | 1766 | } else if (mVideoSource == VIDEO_SOURCE_GRALLOC_BUFFER) { |
michael@0 | 1767 | - // If using GRAlloc buffers, setup surfacemediasource. |
michael@0 | 1768 | - // Later a handle to that will be passed |
michael@0 | 1769 | - // to the client side when queried |
michael@0 | 1770 | - status_t err = setupSurfaceMediaSource(); |
michael@0 | 1771 | - if (err != OK) { |
michael@0 | 1772 | - return err; |
michael@0 | 1773 | - } |
michael@0 | 1774 | - *mediaSource = mSurfaceMediaSource; |
michael@0 | 1775 | + return BAD_VALUE; |
michael@0 | 1776 | } else { |
michael@0 | 1777 | return INVALID_OPERATION; |
michael@0 | 1778 | } |
michael@0 | 1779 | return OK; |
michael@0 | 1780 | } |
michael@0 | 1781 | |
michael@0 | 1782 | -// setupSurfaceMediaSource creates a source with the given |
michael@0 | 1783 | -// width and height and framerate. |
michael@0 | 1784 | -// TODO: This could go in a static function inside SurfaceMediaSource |
michael@0 | 1785 | -// similar to that in CameraSource |
michael@0 | 1786 | -status_t StagefrightRecorder::setupSurfaceMediaSource() { |
michael@0 | 1787 | - status_t err = OK; |
michael@0 | 1788 | - mSurfaceMediaSource = new SurfaceMediaSource(mVideoWidth, mVideoHeight); |
michael@0 | 1789 | - if (mSurfaceMediaSource == NULL) { |
michael@0 | 1790 | - return NO_INIT; |
michael@0 | 1791 | - } |
michael@0 | 1792 | - |
michael@0 | 1793 | - if (mFrameRate == -1) { |
michael@0 | 1794 | - int32_t frameRate = 0; |
michael@0 | 1795 | - CHECK (mSurfaceMediaSource->getFormat()->findInt32( |
michael@0 | 1796 | - kKeyFrameRate, &frameRate)); |
michael@0 | 1797 | - LOGI("Frame rate is not explicitly set. Use the current frame " |
michael@0 | 1798 | - "rate (%d fps)", frameRate); |
michael@0 | 1799 | - mFrameRate = frameRate; |
michael@0 | 1800 | - } else { |
michael@0 | 1801 | - err = mSurfaceMediaSource->setFrameRate(mFrameRate); |
michael@0 | 1802 | - } |
michael@0 | 1803 | - CHECK(mFrameRate != -1); |
michael@0 | 1804 | - |
michael@0 | 1805 | - mIsMetaDataStoredInVideoBuffers = |
michael@0 | 1806 | - mSurfaceMediaSource->isMetaDataStoredInVideoBuffers(); |
michael@0 | 1807 | - return err; |
michael@0 | 1808 | -} |
michael@0 | 1809 | - |
michael@0 | 1810 | -status_t StagefrightRecorder::setupCameraSource( |
michael@0 | 1811 | - sp<CameraSource> *cameraSource) { |
michael@0 | 1812 | +status_t GonkRecorder::setupCameraSource( |
michael@0 | 1813 | + sp<GonkCameraSource> *cameraSource) { |
michael@0 | 1814 | status_t err = OK; |
michael@0 | 1815 | if ((err = checkVideoEncoderCapabilities()) != OK) { |
michael@0 | 1816 | return err; |
michael@0 | 1817 | @@ -1416,26 +1164,15 @@ |
michael@0 | 1818 | Size videoSize; |
michael@0 | 1819 | videoSize.width = mVideoWidth; |
michael@0 | 1820 | videoSize.height = mVideoHeight; |
michael@0 | 1821 | - if (mCaptureTimeLapse) { |
michael@0 | 1822 | - mCameraSourceTimeLapse = CameraSourceTimeLapse::CreateFromCamera( |
michael@0 | 1823 | - mCamera, mCameraProxy, mCameraId, |
michael@0 | 1824 | - videoSize, mFrameRate, mPreviewSurface, |
michael@0 | 1825 | - mTimeBetweenTimeLapseFrameCaptureUs); |
michael@0 | 1826 | - *cameraSource = mCameraSourceTimeLapse; |
michael@0 | 1827 | - } else { |
michael@0 | 1828 | - |
michael@0 | 1829 | - bool useMeta = true; |
michael@0 | 1830 | - char value[PROPERTY_VALUE_MAX]; |
michael@0 | 1831 | - if (property_get("debug.camcorder.disablemeta", value, NULL) && |
michael@0 | 1832 | + bool useMeta = true; |
michael@0 | 1833 | + char value[PROPERTY_VALUE_MAX]; |
michael@0 | 1834 | + if (property_get("debug.camcorder.disablemeta", value, NULL) && |
michael@0 | 1835 | atoi(value)) { |
michael@0 | 1836 | - useMeta = false; |
michael@0 | 1837 | - } |
michael@0 | 1838 | - *cameraSource = CameraSource::CreateFromCamera( |
michael@0 | 1839 | - mCamera, mCameraProxy, mCameraId, videoSize, mFrameRate, |
michael@0 | 1840 | - mPreviewSurface, useMeta); |
michael@0 | 1841 | + useMeta = false; |
michael@0 | 1842 | } |
michael@0 | 1843 | - mCamera.clear(); |
michael@0 | 1844 | - mCameraProxy.clear(); |
michael@0 | 1845 | + |
michael@0 | 1846 | + *cameraSource = GonkCameraSource::Create( |
michael@0 | 1847 | + mCameraHandle, videoSize, mFrameRate, useMeta); |
michael@0 | 1848 | if (*cameraSource == NULL) { |
michael@0 | 1849 | return UNKNOWN_ERROR; |
michael@0 | 1850 | } |
michael@0 | 1851 | @@ -1465,7 +1202,7 @@ |
michael@0 | 1852 | return OK; |
michael@0 | 1853 | } |
michael@0 | 1854 | |
michael@0 | 1855 | -status_t StagefrightRecorder::setupVideoEncoder( |
michael@0 | 1856 | +status_t GonkRecorder::setupVideoEncoder( |
michael@0 | 1857 | sp<MediaSource> cameraSource, |
michael@0 | 1858 | int32_t videoBitRate, |
michael@0 | 1859 | sp<MediaSource> *source) { |
michael@0 | 1860 | @@ -1501,10 +1238,7 @@ |
michael@0 | 1861 | CHECK(meta->findInt32(kKeyStride, &stride)); |
michael@0 | 1862 | CHECK(meta->findInt32(kKeySliceHeight, &sliceHeight)); |
michael@0 | 1863 | CHECK(meta->findInt32(kKeyColorFormat, &colorFormat)); |
michael@0 | 1864 | - hfr = 0; |
michael@0 | 1865 | - if (!meta->findInt32(kKeyHFR, &hfr)) { |
michael@0 | 1866 | - LOGW("hfr not found, default to 0"); |
michael@0 | 1867 | - } |
michael@0 | 1868 | + CHECK(meta->findInt32(kKeyHFR, &hfr)); |
michael@0 | 1869 | |
michael@0 | 1870 | if(hfr) { |
michael@0 | 1871 | mMaxFileDurationUs = mMaxFileDurationUs * (hfr/mFrameRate); |
michael@0 | 1872 | @@ -1598,30 +1332,17 @@ |
michael@0 | 1873 | enc_meta->setInt32(kKey3D, is3D); |
michael@0 | 1874 | } |
michael@0 | 1875 | |
michael@0 | 1876 | - OMXClient client; |
michael@0 | 1877 | - CHECK_EQ(client.connect(), OK); |
michael@0 | 1878 | - |
michael@0 | 1879 | uint32_t encoder_flags = 0; |
michael@0 | 1880 | if (mIsMetaDataStoredInVideoBuffers) { |
michael@0 | 1881 | LOGW("Camera source supports metadata mode, create OMXCodec for metadata"); |
michael@0 | 1882 | encoder_flags |= OMXCodec::kHardwareCodecsOnly; |
michael@0 | 1883 | encoder_flags |= OMXCodec::kStoreMetaDataInVideoBuffers; |
michael@0 | 1884 | - if (property_get("ro.board.platform", value, "0") |
michael@0 | 1885 | - && (!strncmp(value, "msm7627", sizeof("msm7627") - 1))) { |
michael@0 | 1886 | - LOGW("msm7627 family of chipsets supports, only one buffer at a time"); |
michael@0 | 1887 | - encoder_flags |= OMXCodec::kOnlySubmitOneInputBufferAtOneTime; |
michael@0 | 1888 | - } |
michael@0 | 1889 | - } |
michael@0 | 1890 | - |
michael@0 | 1891 | - // Do not wait for all the input buffers to become available. |
michael@0 | 1892 | - // This give timelapse video recording faster response in |
michael@0 | 1893 | - // receiving output from video encoder component. |
michael@0 | 1894 | - if (mCaptureTimeLapse) { |
michael@0 | 1895 | encoder_flags |= OMXCodec::kOnlySubmitOneInputBufferAtOneTime; |
michael@0 | 1896 | } |
michael@0 | 1897 | |
michael@0 | 1898 | sp<MediaSource> encoder = OMXCodec::Create( |
michael@0 | 1899 | - client.interface(), enc_meta, |
michael@0 | 1900 | + GetOMX(), |
michael@0 | 1901 | + enc_meta, |
michael@0 | 1902 | true /* createEncoder */, cameraSource, |
michael@0 | 1903 | NULL, encoder_flags); |
michael@0 | 1904 | if (encoder == NULL) { |
michael@0 | 1905 | @@ -1638,7 +1359,7 @@ |
michael@0 | 1906 | return OK; |
michael@0 | 1907 | } |
michael@0 | 1908 | |
michael@0 | 1909 | -status_t StagefrightRecorder::setupAudioEncoder(const sp<MediaWriter>& writer) { |
michael@0 | 1910 | +status_t GonkRecorder::setupAudioEncoder(const sp<MediaWriter>& writer) { |
michael@0 | 1911 | status_t status = BAD_VALUE; |
michael@0 | 1912 | if (OK != (status = checkAudioEncoderCapabilities())) { |
michael@0 | 1913 | return status; |
michael@0 | 1914 | @@ -1664,7 +1385,7 @@ |
michael@0 | 1915 | return OK; |
michael@0 | 1916 | } |
michael@0 | 1917 | |
michael@0 | 1918 | -status_t StagefrightRecorder::setupMPEG4Recording( |
michael@0 | 1919 | +status_t GonkRecorder::setupMPEG4Recording( |
michael@0 | 1920 | int outputFd, |
michael@0 | 1921 | int32_t videoWidth, int32_t videoHeight, |
michael@0 | 1922 | int32_t videoBitRate, |
michael@0 | 1923 | @@ -1696,7 +1417,7 @@ |
michael@0 | 1924 | // Audio source is added at the end if it exists. |
michael@0 | 1925 | // This help make sure that the "recoding" sound is suppressed for |
michael@0 | 1926 | // camcorder applications in the recorded files. |
michael@0 | 1927 | - if (!mCaptureTimeLapse && (mAudioSource != AUDIO_SOURCE_CNT)) { |
michael@0 | 1928 | + if (mAudioSource != AUDIO_SOURCE_CNT) { |
michael@0 | 1929 | err = setupAudioEncoder(writer); |
michael@0 | 1930 | if (err != OK) return err; |
michael@0 | 1931 | *totalBitRate += mAudioBitRate; |
michael@0 | 1932 | @@ -1728,7 +1449,7 @@ |
michael@0 | 1933 | return OK; |
michael@0 | 1934 | } |
michael@0 | 1935 | |
michael@0 | 1936 | -void StagefrightRecorder::setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, |
michael@0 | 1937 | +void GonkRecorder::setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, |
michael@0 | 1938 | sp<MetaData> *meta) { |
michael@0 | 1939 | (*meta)->setInt64(kKeyTime, startTimeUs); |
michael@0 | 1940 | (*meta)->setInt32(kKeyFileType, mOutputFormat); |
michael@0 | 1941 | @@ -1752,7 +1473,7 @@ |
michael@0 | 1942 | } |
michael@0 | 1943 | } |
michael@0 | 1944 | |
michael@0 | 1945 | -status_t StagefrightRecorder::startMPEG4Recording() { |
michael@0 | 1946 | +status_t GonkRecorder::startMPEG4Recording() { |
michael@0 | 1947 | int32_t totalBitRate; |
michael@0 | 1948 | status_t err = setupMPEG4Recording( |
michael@0 | 1949 | mOutputFd, mVideoWidth, mVideoHeight, |
michael@0 | 1950 | @@ -1761,7 +1482,14 @@ |
michael@0 | 1951 | return err; |
michael@0 | 1952 | } |
michael@0 | 1953 | |
michael@0 | 1954 | - int64_t startTimeUs = systemTime() / 1000; |
michael@0 | 1955 | + //systemTime() doesn't give correct time because |
michael@0 | 1956 | + //HAVE_POSIX_CLOCKS is not defined for utils/Timers.cpp |
michael@0 | 1957 | + //so, using clock_gettime directly |
michael@0 | 1958 | +#include <time.h> |
michael@0 | 1959 | + struct timespec t; |
michael@0 | 1960 | + clock_gettime(CLOCK_MONOTONIC, &t); |
michael@0 | 1961 | + int64_t startTimeUs = int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; |
michael@0 | 1962 | + startTimeUs = startTimeUs / 1000; |
michael@0 | 1963 | sp<MetaData> meta = new MetaData; |
michael@0 | 1964 | setupMPEG4MetaData(startTimeUs, totalBitRate, &meta); |
michael@0 | 1965 | |
michael@0 | 1966 | @@ -1773,7 +1501,7 @@ |
michael@0 | 1967 | return OK; |
michael@0 | 1968 | } |
michael@0 | 1969 | |
michael@0 | 1970 | -status_t StagefrightRecorder::pause() { |
michael@0 | 1971 | +status_t GonkRecorder::pause() { |
michael@0 | 1972 | LOGV("pause"); |
michael@0 | 1973 | if (mWriter == NULL) { |
michael@0 | 1974 | return UNKNOWN_ERROR; |
michael@0 | 1975 | @@ -1782,31 +1510,16 @@ |
michael@0 | 1976 | |
michael@0 | 1977 | if (mStarted) { |
michael@0 | 1978 | mStarted = false; |
michael@0 | 1979 | - |
michael@0 | 1980 | - uint32_t params = 0; |
michael@0 | 1981 | - if (mAudioSource != AUDIO_SOURCE_CNT) { |
michael@0 | 1982 | - params |= IMediaPlayerService::kBatteryDataTrackAudio; |
michael@0 | 1983 | - } |
michael@0 | 1984 | - if (mVideoSource != VIDEO_SOURCE_LIST_END) { |
michael@0 | 1985 | - params |= IMediaPlayerService::kBatteryDataTrackVideo; |
michael@0 | 1986 | - } |
michael@0 | 1987 | - |
michael@0 | 1988 | - addBatteryData(params); |
michael@0 | 1989 | } |
michael@0 | 1990 | |
michael@0 | 1991 | |
michael@0 | 1992 | return OK; |
michael@0 | 1993 | } |
michael@0 | 1994 | |
michael@0 | 1995 | -status_t StagefrightRecorder::stop() { |
michael@0 | 1996 | +status_t GonkRecorder::stop() { |
michael@0 | 1997 | LOGV("stop"); |
michael@0 | 1998 | status_t err = OK; |
michael@0 | 1999 | |
michael@0 | 2000 | - if (mCaptureTimeLapse && mCameraSourceTimeLapse != NULL) { |
michael@0 | 2001 | - mCameraSourceTimeLapse->startQuickReadReturns(); |
michael@0 | 2002 | - mCameraSourceTimeLapse = NULL; |
michael@0 | 2003 | - } |
michael@0 | 2004 | - |
michael@0 | 2005 | if (mWriter != NULL) { |
michael@0 | 2006 | err = mWriter->stop(); |
michael@0 | 2007 | mWriter.clear(); |
michael@0 | 2008 | @@ -1819,30 +1532,20 @@ |
michael@0 | 2009 | |
michael@0 | 2010 | if (mStarted) { |
michael@0 | 2011 | mStarted = false; |
michael@0 | 2012 | - |
michael@0 | 2013 | - uint32_t params = 0; |
michael@0 | 2014 | - if (mAudioSource != AUDIO_SOURCE_CNT) { |
michael@0 | 2015 | - params |= IMediaPlayerService::kBatteryDataTrackAudio; |
michael@0 | 2016 | - } |
michael@0 | 2017 | - if (mVideoSource != VIDEO_SOURCE_LIST_END) { |
michael@0 | 2018 | - params |= IMediaPlayerService::kBatteryDataTrackVideo; |
michael@0 | 2019 | - } |
michael@0 | 2020 | - |
michael@0 | 2021 | - addBatteryData(params); |
michael@0 | 2022 | } |
michael@0 | 2023 | |
michael@0 | 2024 | |
michael@0 | 2025 | return err; |
michael@0 | 2026 | } |
michael@0 | 2027 | |
michael@0 | 2028 | -status_t StagefrightRecorder::close() { |
michael@0 | 2029 | +status_t GonkRecorder::close() { |
michael@0 | 2030 | LOGV("close"); |
michael@0 | 2031 | stop(); |
michael@0 | 2032 | |
michael@0 | 2033 | return OK; |
michael@0 | 2034 | } |
michael@0 | 2035 | |
michael@0 | 2036 | -status_t StagefrightRecorder::reset() { |
michael@0 | 2037 | +status_t GonkRecorder::reset() { |
michael@0 | 2038 | LOGV("reset"); |
michael@0 | 2039 | stop(); |
michael@0 | 2040 | |
michael@0 | 2041 | @@ -1858,9 +1561,9 @@ |
michael@0 | 2042 | mVideoHeight = 144; |
michael@0 | 2043 | mFrameRate = -1; |
michael@0 | 2044 | mVideoBitRate = 192000; |
michael@0 | 2045 | - mSampleRate = 0; |
michael@0 | 2046 | - mAudioChannels = 0; |
michael@0 | 2047 | - mAudioBitRate = 0; |
michael@0 | 2048 | + mSampleRate = 8000; |
michael@0 | 2049 | + mAudioChannels = 1; |
michael@0 | 2050 | + mAudioBitRate = 12200; |
michael@0 | 2051 | mInterleaveDurationUs = 0; |
michael@0 | 2052 | mIFramesIntervalSec = 2; |
michael@0 | 2053 | mAudioSourceNode = 0; |
michael@0 | 2054 | @@ -1875,9 +1578,6 @@ |
michael@0 | 2055 | mMaxFileDurationUs = 0; |
michael@0 | 2056 | mMaxFileSizeBytes = 0; |
michael@0 | 2057 | mTrackEveryTimeDurationUs = 0; |
michael@0 | 2058 | - mCaptureTimeLapse = false; |
michael@0 | 2059 | - mTimeBetweenTimeLapseFrameCaptureUs = -1; |
michael@0 | 2060 | - mCameraSourceTimeLapse = NULL; |
michael@0 | 2061 | mIsMetaDataStoredInVideoBuffers = false; |
michael@0 | 2062 | mEncoderProfiles = MediaProfiles::getInstance(); |
michael@0 | 2063 | mRotationDegrees = 0; |
michael@0 | 2064 | @@ -1885,6 +1585,11 @@ |
michael@0 | 2065 | mLongitudex10000 = -3600000; |
michael@0 | 2066 | |
michael@0 | 2067 | mOutputFd = -1; |
michael@0 | 2068 | + mCameraHandle = -1; |
michael@0 | 2069 | + //TODO: May need to register a listener eventually |
michael@0 | 2070 | + //if someone is interested in recorder events for now |
michael@0 | 2071 | + //default to no listener registered |
michael@0 | 2072 | + mListener = NULL; |
michael@0 | 2073 | |
michael@0 | 2074 | // Disable Audio Encoding |
michael@0 | 2075 | char value[PROPERTY_VALUE_MAX]; |
michael@0 | 2076 | @@ -1894,7 +1599,7 @@ |
michael@0 | 2077 | return OK; |
michael@0 | 2078 | } |
michael@0 | 2079 | |
michael@0 | 2080 | -status_t StagefrightRecorder::getMaxAmplitude(int *max) { |
michael@0 | 2081 | +status_t GonkRecorder::getMaxAmplitude(int *max) { |
michael@0 | 2082 | LOGV("getMaxAmplitude"); |
michael@0 | 2083 | |
michael@0 | 2084 | if (max == NULL) { |
michael@0 | 2085 | @@ -1911,7 +1616,7 @@ |
michael@0 | 2086 | return OK; |
michael@0 | 2087 | } |
michael@0 | 2088 | |
michael@0 | 2089 | -status_t StagefrightRecorder::dump( |
michael@0 | 2090 | +status_t GonkRecorder::dump( |
michael@0 | 2091 | int fd, const Vector<String16>& args) const { |
michael@0 | 2092 | LOGV("dump"); |
michael@0 | 2093 | const size_t SIZE = 256; |
michael@0 | 2094 | @@ -1958,6 +1663,8 @@ |
michael@0 | 2095 | result.append(buffer); |
michael@0 | 2096 | snprintf(buffer, SIZE, " Camera Id: %d\n", mCameraId); |
michael@0 | 2097 | result.append(buffer); |
michael@0 | 2098 | + snprintf(buffer, SIZE, " Camera Handle: %d\n", mCameraHandle); |
michael@0 | 2099 | + result.append(buffer); |
michael@0 | 2100 | snprintf(buffer, SIZE, " Start time offset (ms): %d\n", mStartTimeOffsetMs); |
michael@0 | 2101 | result.append(buffer); |
michael@0 | 2102 | snprintf(buffer, SIZE, " Encoder: %d\n", mVideoEncoder); |
michael@0 | 2103 | @@ -1978,45 +1685,12 @@ |
michael@0 | 2104 | return OK; |
michael@0 | 2105 | } |
michael@0 | 2106 | |
michael@0 | 2107 | -status_t StagefrightRecorder::startExtendedRecording() { |
michael@0 | 2108 | - CHECK(mOutputFormat == OUTPUT_FORMAT_QCP); |
michael@0 | 2109 | - |
michael@0 | 2110 | - if (mSampleRate != 8000) { |
michael@0 | 2111 | - LOGE("Invalid sampling rate %d used for recording", |
michael@0 | 2112 | - mSampleRate); |
michael@0 | 2113 | - return BAD_VALUE; |
michael@0 | 2114 | - } |
michael@0 | 2115 | - if (mAudioChannels != 1) { |
michael@0 | 2116 | - LOGE("Invalid number of audio channels %d used for recording", |
michael@0 | 2117 | - mAudioChannels); |
michael@0 | 2118 | - return BAD_VALUE; |
michael@0 | 2119 | - } |
michael@0 | 2120 | - |
michael@0 | 2121 | - if (mAudioSource >= AUDIO_SOURCE_CNT) { |
michael@0 | 2122 | - LOGE("Invalid audio source: %d", mAudioSource); |
michael@0 | 2123 | - return BAD_VALUE; |
michael@0 | 2124 | - } |
michael@0 | 2125 | - |
michael@0 | 2126 | - sp<MediaSource> audioEncoder = createAudioSource(); |
michael@0 | 2127 | - |
michael@0 | 2128 | - if (audioEncoder == NULL) { |
michael@0 | 2129 | - LOGE("AudioEncoder NULL"); |
michael@0 | 2130 | - return UNKNOWN_ERROR; |
michael@0 | 2131 | - } |
michael@0 | 2132 | - |
michael@0 | 2133 | - mWriter = new ExtendedWriter(dup(mOutputFd)); |
michael@0 | 2134 | - mWriter->addSource(audioEncoder); |
michael@0 | 2135 | - |
michael@0 | 2136 | - if (mMaxFileDurationUs != 0) { |
michael@0 | 2137 | - mWriter->setMaxFileDuration(mMaxFileDurationUs); |
michael@0 | 2138 | - } |
michael@0 | 2139 | - if (mMaxFileSizeBytes != 0) { |
michael@0 | 2140 | - mWriter->setMaxFileSize(mMaxFileSizeBytes); |
michael@0 | 2141 | - } |
michael@0 | 2142 | - mWriter->setListener(mListener); |
michael@0 | 2143 | - mWriter->start(); |
michael@0 | 2144 | - |
michael@0 | 2145 | - return OK; |
michael@0 | 2146 | +status_t GonkRecorder::setCameraHandle(int32_t handle) { |
michael@0 | 2147 | + if (handle < 0) { |
michael@0 | 2148 | + return BAD_VALUE; |
michael@0 | 2149 | + } |
michael@0 | 2150 | + mCameraHandle = handle; |
michael@0 | 2151 | + return OK; |
michael@0 | 2152 | } |
michael@0 | 2153 | |
michael@0 | 2154 | } // namespace android |
michael@0 | 2155 | diff --git a/GonkRecorder.h b/GonkRecorder.h |
michael@0 | 2156 | index dba6110..fa948af 100644 |
michael@0 | 2157 | --- a/GonkRecorder.h |
michael@0 | 2158 | +++ b/GonkRecorder.h |
michael@0 | 2159 | @@ -14,11 +14,11 @@ |
michael@0 | 2160 | * limitations under the License. |
michael@0 | 2161 | */ |
michael@0 | 2162 | |
michael@0 | 2163 | -#ifndef STAGEFRIGHT_RECORDER_H_ |
michael@0 | 2164 | +#ifndef GONK_RECORDER_H_ |
michael@0 | 2165 | |
michael@0 | 2166 | -#define STAGEFRIGHT_RECORDER_H_ |
michael@0 | 2167 | +#define GONK_RECORDER_H_ |
michael@0 | 2168 | |
michael@0 | 2169 | -#include <media/MediaRecorderBase.h> |
michael@0 | 2170 | +#include <media/mediarecorder.h> |
michael@0 | 2171 | #include <camera/CameraParameters.h> |
michael@0 | 2172 | #include <utils/String8.h> |
michael@0 | 2173 | |
michael@0 | 2174 | @@ -26,21 +26,16 @@ |
michael@0 | 2175 | |
michael@0 | 2176 | namespace android { |
michael@0 | 2177 | |
michael@0 | 2178 | -class Camera; |
michael@0 | 2179 | -class ICameraRecordingProxy; |
michael@0 | 2180 | -class CameraSource; |
michael@0 | 2181 | -class CameraSourceTimeLapse; |
michael@0 | 2182 | +class GonkCameraSource; |
michael@0 | 2183 | struct MediaSource; |
michael@0 | 2184 | struct MediaWriter; |
michael@0 | 2185 | class MetaData; |
michael@0 | 2186 | struct AudioSource; |
michael@0 | 2187 | class MediaProfiles; |
michael@0 | 2188 | -class ISurfaceTexture; |
michael@0 | 2189 | -class SurfaceMediaSource; |
michael@0 | 2190 | |
michael@0 | 2191 | -struct StagefrightRecorder : public MediaRecorderBase { |
michael@0 | 2192 | - StagefrightRecorder(); |
michael@0 | 2193 | - virtual ~StagefrightRecorder(); |
michael@0 | 2194 | +struct GonkRecorder { |
michael@0 | 2195 | + GonkRecorder(); |
michael@0 | 2196 | + virtual ~GonkRecorder(); |
michael@0 | 2197 | |
michael@0 | 2198 | virtual status_t init(); |
michael@0 | 2199 | virtual status_t setAudioSource(audio_source_t as); |
michael@0 | 2200 | @@ -50,11 +45,10 @@ |
michael@0 | 2201 | virtual status_t setVideoEncoder(video_encoder ve); |
michael@0 | 2202 | virtual status_t setVideoSize(int width, int height); |
michael@0 | 2203 | virtual status_t setVideoFrameRate(int frames_per_second); |
michael@0 | 2204 | - virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy); |
michael@0 | 2205 | - virtual status_t setPreviewSurface(const sp<Surface>& surface); |
michael@0 | 2206 | virtual status_t setOutputFile(const char *path); |
michael@0 | 2207 | virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); |
michael@0 | 2208 | virtual status_t setParameters(const String8& params); |
michael@0 | 2209 | + virtual status_t setCameraHandle(int32_t handle); |
michael@0 | 2210 | virtual status_t setListener(const sp<IMediaRecorderClient>& listener); |
michael@0 | 2211 | virtual status_t prepare(); |
michael@0 | 2212 | virtual status_t start(); |
michael@0 | 2213 | @@ -65,12 +59,8 @@ |
michael@0 | 2214 | virtual status_t getMaxAmplitude(int *max); |
michael@0 | 2215 | virtual status_t dump(int fd, const Vector<String16>& args) const; |
michael@0 | 2216 | // Querying a SurfaceMediaSourcer |
michael@0 | 2217 | - virtual sp<ISurfaceTexture> querySurfaceMediaSource() const; |
michael@0 | 2218 | |
michael@0 | 2219 | private: |
michael@0 | 2220 | - sp<ICamera> mCamera; |
michael@0 | 2221 | - sp<ICameraRecordingProxy> mCameraProxy; |
michael@0 | 2222 | - sp<Surface> mPreviewSurface; |
michael@0 | 2223 | sp<IMediaRecorderClient> mListener; |
michael@0 | 2224 | sp<MediaWriter> mWriter; |
michael@0 | 2225 | int mOutputFd; |
michael@0 | 2226 | @@ -104,11 +94,6 @@ |
michael@0 | 2227 | int32_t mLongitudex10000; |
michael@0 | 2228 | int32_t mStartTimeOffsetMs; |
michael@0 | 2229 | |
michael@0 | 2230 | - bool mCaptureTimeLapse; |
michael@0 | 2231 | - int64_t mTimeBetweenTimeLapseFrameCaptureUs; |
michael@0 | 2232 | - sp<CameraSourceTimeLapse> mCameraSourceTimeLapse; |
michael@0 | 2233 | - |
michael@0 | 2234 | - |
michael@0 | 2235 | String8 mParams; |
michael@0 | 2236 | |
michael@0 | 2237 | bool mIsMetaDataStoredInVideoBuffers; |
michael@0 | 2238 | @@ -119,8 +104,8 @@ |
michael@0 | 2239 | // An <ISurfaceTexture> pointer |
michael@0 | 2240 | // will be sent to the client side using which the |
michael@0 | 2241 | // frame buffers will be queued and dequeued |
michael@0 | 2242 | - sp<SurfaceMediaSource> mSurfaceMediaSource; |
michael@0 | 2243 | bool mDisableAudio; |
michael@0 | 2244 | + int32_t mCameraHandle; |
michael@0 | 2245 | |
michael@0 | 2246 | status_t setupMPEG4Recording( |
michael@0 | 2247 | int outputFd, |
michael@0 | 2248 | @@ -132,10 +117,7 @@ |
michael@0 | 2249 | sp<MetaData> *meta); |
michael@0 | 2250 | status_t startMPEG4Recording(); |
michael@0 | 2251 | status_t startAMRRecording(); |
michael@0 | 2252 | - status_t startFMA2DPWriter(); |
michael@0 | 2253 | - status_t startAACRecording(); |
michael@0 | 2254 | status_t startRawAudioRecording(); |
michael@0 | 2255 | - status_t startRTPRecording(); |
michael@0 | 2256 | status_t startMPEG2TSRecording(); |
michael@0 | 2257 | sp<MediaSource> createAudioSource(); |
michael@0 | 2258 | status_t checkVideoEncoderCapabilities(); |
michael@0 | 2259 | @@ -144,9 +126,8 @@ |
michael@0 | 2260 | // source (CameraSource or SurfaceMediaSource) |
michael@0 | 2261 | // depending on the videosource type |
michael@0 | 2262 | status_t setupMediaSource(sp<MediaSource> *mediaSource); |
michael@0 | 2263 | - status_t setupCameraSource(sp<CameraSource> *cameraSource); |
michael@0 | 2264 | + status_t setupCameraSource(sp<GonkCameraSource> *cameraSource); |
michael@0 | 2265 | // setup the surfacemediasource for the encoder |
michael@0 | 2266 | - status_t setupSurfaceMediaSource(); |
michael@0 | 2267 | |
michael@0 | 2268 | status_t setupAudioEncoder(const sp<MediaWriter>& writer); |
michael@0 | 2269 | status_t setupVideoEncoder( |
michael@0 | 2270 | @@ -160,8 +141,6 @@ |
michael@0 | 2271 | status_t setParamAudioNumberOfChannels(int32_t channles); |
michael@0 | 2272 | status_t setParamAudioSamplingRate(int32_t sampleRate); |
michael@0 | 2273 | status_t setParamAudioTimeScale(int32_t timeScale); |
michael@0 | 2274 | - status_t setParamTimeLapseEnable(int32_t timeLapseEnable); |
michael@0 | 2275 | - status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs); |
michael@0 | 2276 | status_t setParamVideoEncodingBitRate(int32_t bitRate); |
michael@0 | 2277 | status_t setParamVideoIFramesInterval(int32_t seconds); |
michael@0 | 2278 | status_t setParamVideoEncoderProfile(int32_t profile); |
michael@0 | 2279 | @@ -186,14 +165,10 @@ |
michael@0 | 2280 | void clipNumberOfAudioChannels(); |
michael@0 | 2281 | void setDefaultProfileIfNecessary(); |
michael@0 | 2282 | |
michael@0 | 2283 | - |
michael@0 | 2284 | - StagefrightRecorder(const StagefrightRecorder &); |
michael@0 | 2285 | - StagefrightRecorder &operator=(const StagefrightRecorder &); |
michael@0 | 2286 | - |
michael@0 | 2287 | - /* extension */ |
michael@0 | 2288 | - status_t startExtendedRecording(); |
michael@0 | 2289 | + GonkRecorder(const GonkRecorder &); |
michael@0 | 2290 | + GonkRecorder &operator=(const GonkRecorder &); |
michael@0 | 2291 | }; |
michael@0 | 2292 | |
michael@0 | 2293 | } // namespace android |
michael@0 | 2294 | |
michael@0 | 2295 | -#endif // STAGEFRIGHT_RECORDER_H_ |
michael@0 | 2296 | +#endif // GONK_RECORDER_H_ |