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