forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.patch
2296 lines (2076 loc) · 75.6 KB
/
update.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/GonkCameraListener.h b/GonkCameraListener.h
index 67eeef3..243264c 100644
--- a/GonkCameraListener.h
+++ b/GonkCameraListener.h
@@ -14,49 +14,16 @@
* limitations under the License.
*/
-#ifndef ANDROID_HARDWARE_CAMERA_H
-#define ANDROID_HARDWARE_CAMERA_H
+#ifndef GONK_CAMERA_LISTENER_H
+#define GONK_CAMERA_LISTENER_H
#include <utils/Timers.h>
-#include <gui/ISurfaceTexture.h>
-#include <system/camera.h>
-#include <camera/ICameraClient.h>
-#include <camera/ICameraRecordingProxy.h>
-#include <camera/ICameraRecordingProxyListener.h>
+#include "libcameraservice/CameraHardwareInterface.h"
namespace android {
-struct CameraInfo {
- /**
- * The direction that the camera faces to. It should be CAMERA_FACING_BACK
- * or CAMERA_FACING_FRONT.
- */
- int facing;
-
- /**
- * The orientation of the camera image. The value is the angle that the
- * camera image needs to be rotated clockwise so it shows correctly on the
- * display in its natural orientation. It should be 0, 90, 180, or 270.
- *
- * For example, suppose a device has a naturally tall screen. The
- * back-facing camera sensor is mounted in landscape. You are looking at
- * the screen. If the top side of the camera sensor is aligned with the
- * right edge of the screen in natural orientation, the value should be
- * 90. If the top side of a front-facing camera sensor is aligned with the
- * right of the screen, the value should be 270.
- */
- int orientation;
- int mode;
-};
-
-class ICameraService;
-class ICamera;
-class Surface;
-class Mutex;
-class String8;
-
// ref-counted object for callbacks
-class CameraListener: virtual public RefBase
+class GonkCameraListener: virtual public RefBase
{
public:
virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
@@ -65,133 +32,6 @@ public:
virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
};
-class Camera : public BnCameraClient, public IBinder::DeathRecipient
-{
-public:
- // construct a camera client from an existing remote
- static sp<Camera> create(const sp<ICamera>& camera);
- static int32_t getNumberOfCameras();
- static status_t getCameraInfo(int cameraId,
- struct CameraInfo* cameraInfo);
- static sp<Camera> connect(int cameraId);
- virtual ~Camera();
- void init();
-
- status_t reconnect();
- void disconnect();
- status_t lock();
- status_t unlock();
-
- status_t getStatus() { return mStatus; }
-
- // pass the buffered Surface to the camera service
- status_t setPreviewDisplay(const sp<Surface>& surface);
-
- // pass the buffered ISurfaceTexture to the camera service
- status_t setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
-
- // start preview mode, must call setPreviewDisplay first
- status_t startPreview();
-
- // stop preview mode
- void stopPreview();
-
- // get preview state
- bool previewEnabled();
-
- // start recording mode, must call setPreviewDisplay first
- status_t startRecording();
-
- // stop recording mode
- void stopRecording();
-
- // get recording state
- bool recordingEnabled();
-
- // release a recording frame
- void releaseRecordingFrame(const sp<IMemory>& mem);
-
- // autoFocus - status returned from callback
- status_t autoFocus();
-
- // cancel auto focus
- status_t cancelAutoFocus();
-
- // take a picture - picture returned from callback
- status_t takePicture(int msgType);
-
- // set preview/capture parameters - key/value pairs
- status_t setParameters(const String8& params);
-
- // get preview/capture parameters - key/value pairs
- String8 getParameters() const;
-
- // send command to camera driver
- status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
-
- // tell camera hal to store meta data or real YUV in video buffers.
- status_t storeMetaDataInBuffers(bool enabled);
-
- void setListener(const sp<CameraListener>& listener);
- void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener);
- void setPreviewCallbackFlags(int preview_callback_flag);
-
- sp<ICameraRecordingProxy> getRecordingProxy();
-
- // ICameraClient interface
- virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
- virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
- camera_frame_metadata_t *metadata);
- virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
-
- sp<ICamera> remote();
-
- class RecordingProxy : public BnCameraRecordingProxy
- {
- public:
- RecordingProxy(const sp<Camera>& camera);
-
- // ICameraRecordingProxy interface
- virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
- virtual void stopRecording();
- virtual void releaseRecordingFrame(const sp<IMemory>& mem);
-
- private:
- sp<Camera> mCamera;
- };
-
-private:
- Camera();
- Camera(const Camera&);
- Camera& operator=(const Camera);
- virtual void binderDied(const wp<IBinder>& who);
-
- class DeathNotifier: public IBinder::DeathRecipient
- {
- public:
- DeathNotifier() {
- }
-
- virtual void binderDied(const wp<IBinder>& who);
- };
-
- static sp<DeathNotifier> mDeathNotifier;
-
- // helper function to obtain camera service handle
- static const sp<ICameraService>& getCameraService();
-
- sp<ICamera> mCamera;
- status_t mStatus;
-
- sp<CameraListener> mListener;
- sp<ICameraRecordingProxyListener> mRecordingProxyListener;
-
- friend class DeathNotifier;
-
- static Mutex mLock;
- static sp<ICameraService> mCameraService;
-};
-
}; // namespace android
#endif
diff --git a/GonkCameraSource.cpp b/GonkCameraSource.cpp
index af6b340..9dba596 100644
--- a/GonkCameraSource.cpp
+++ b/GonkCameraSource.cpp
@@ -14,29 +14,34 @@
* limitations under the License.
*/
-//#define LOG_NDEBUG 0
-#define LOG_TAG "CameraSource"
-#include <utils/Log.h>
+#include <base/basictypes.h>
+#include "nsDebug.h"
+#define DOM_CAMERA_LOG_LEVEL 3
+#include "CameraCommon.h"
+#define LOGD DOM_CAMERA_LOGA
+#define LOGV DOM_CAMERA_LOGI
+#define LOGI DOM_CAMERA_LOGI
+#define LOGW DOM_CAMERA_LOGW
+#define LOGE DOM_CAMERA_LOGE
#include <OMX_Component.h>
-#include <binder/IPCThreadState.h>
-#include <media/stagefright/CameraSource.h>
+#include "GonkCameraSource.h"
+#include "GonkCameraListener.h"
+#include "GonkCameraHwMgr.h"
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
-#include <camera/Camera.h>
-#include <camera/CameraParameters.h>
-#include <surfaceflinger/Surface.h>
#include <utils/String8.h>
#include <cutils/properties.h>
+using namespace mozilla;
namespace android {
static const int64_t CAMERA_SOURCE_TIMEOUT_NS = 3000000000LL;
-struct CameraSourceListener : public CameraListener {
- CameraSourceListener(const sp<CameraSource> &source);
+struct GonkCameraSourceListener : public GonkCameraListener {
+ GonkCameraSourceListener(const sp<GonkCameraSource> &source);
virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2);
virtual void postData(int32_t msgType, const sp<IMemory> &dataPtr,
@@ -46,41 +51,41 @@ struct CameraSourceListener : public CameraListener {
nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
protected:
- virtual ~CameraSourceListener();
+ virtual ~GonkCameraSourceListener();
private:
- wp<CameraSource> mSource;
+ wp<GonkCameraSource> mSource;
- CameraSourceListener(const CameraSourceListener &);
- CameraSourceListener &operator=(const CameraSourceListener &);
+ GonkCameraSourceListener(const GonkCameraSourceListener &);
+ GonkCameraSourceListener &operator=(const GonkCameraSourceListener &);
};
-CameraSourceListener::CameraSourceListener(const sp<CameraSource> &source)
+GonkCameraSourceListener::GonkCameraSourceListener(const sp<GonkCameraSource> &source)
: mSource(source) {
}
-CameraSourceListener::~CameraSourceListener() {
+GonkCameraSourceListener::~GonkCameraSourceListener() {
}
-void CameraSourceListener::notify(int32_t msgType, int32_t ext1, int32_t ext2) {
+void GonkCameraSourceListener::notify(int32_t msgType, int32_t ext1, int32_t ext2) {
LOGV("notify(%d, %d, %d)", msgType, ext1, ext2);
}
-void CameraSourceListener::postData(int32_t msgType, const sp<IMemory> &dataPtr,
+void GonkCameraSourceListener::postData(int32_t msgType, const sp<IMemory> &dataPtr,
camera_frame_metadata_t *metadata) {
LOGV("postData(%d, ptr:%p, size:%d)",
msgType, dataPtr->pointer(), dataPtr->size());
- sp<CameraSource> source = mSource.promote();
+ sp<GonkCameraSource> source = mSource.promote();
if (source.get() != NULL) {
source->dataCallback(msgType, dataPtr);
}
}
-void CameraSourceListener::postDataTimestamp(
+void GonkCameraSourceListener::postDataTimestamp(
nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) {
- sp<CameraSource> source = mSource.promote();
+ sp<GonkCameraSource> source = mSource.promote();
if (source.get() != NULL) {
source->dataCallbackTimestamp(timestamp/1000, msgType, dataPtr);
}
@@ -114,48 +119,30 @@ static int32_t getColorFormat(const char* colorFormat) {
}
LOGE("Uknown color format (%s), please add it to "
- "CameraSource::getColorFormat", colorFormat);
+ "GonkCameraSource::getColorFormat", colorFormat);
CHECK_EQ(0, "Unknown color format");
}
-CameraSource *CameraSource::Create() {
- Size size;
- size.width = -1;
- size.height = -1;
-
- sp<ICamera> camera;
- return new CameraSource(camera, NULL, 0, size, -1, NULL, false);
-}
-
-// static
-CameraSource *CameraSource::CreateFromCamera(
- const sp<ICamera>& camera,
- const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId,
+GonkCameraSource *GonkCameraSource::Create(
+ int32_t cameraHandle,
Size videoSize,
int32_t frameRate,
- const sp<Surface>& surface,
bool storeMetaDataInVideoBuffers) {
- CameraSource *source = new CameraSource(camera, proxy, cameraId,
- videoSize, frameRate, surface,
+ GonkCameraSource *source = new GonkCameraSource(cameraHandle,
+ videoSize, frameRate,
storeMetaDataInVideoBuffers);
return source;
}
-CameraSource::CameraSource(
- const sp<ICamera>& camera,
- const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId,
+GonkCameraSource::GonkCameraSource(
+ int32_t cameraHandle,
Size videoSize,
int32_t frameRate,
- const sp<Surface>& surface,
bool storeMetaDataInVideoBuffers)
: mCameraFlags(0),
mVideoFrameRate(-1),
- mCamera(0),
- mSurface(surface),
mNumFramesReceived(0),
mLastFrameTimestampUs(0),
mStarted(false),
@@ -169,43 +156,19 @@ CameraSource::CameraSource(
mVideoSize.width = -1;
mVideoSize.height = -1;
- mInitCheck = init(camera, proxy, cameraId,
+ mCameraHandle = cameraHandle;
+
+ mInitCheck = init(
videoSize, frameRate,
storeMetaDataInVideoBuffers);
if (mInitCheck != OK) releaseCamera();
}
-status_t CameraSource::initCheck() const {
+status_t GonkCameraSource::initCheck() const {
return mInitCheck;
}
-status_t CameraSource::isCameraAvailable(
- const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId) {
-
- if (camera == 0) {
- mCamera = Camera::connect(cameraId);
- if (mCamera == 0) return -EBUSY;
- mCameraFlags &= ~FLAGS_HOT_CAMERA;
- } else {
- // We get the proxy from Camera, not ICamera. We need to get the proxy
- // to the remote Camera owned by the application. Here mCamera is a
- // local Camera object created by us. We cannot use the proxy from
- // mCamera here.
- mCamera = Camera::create(camera);
- if (mCamera == 0) return -EBUSY;
- mCameraRecordingProxy = proxy;
- mCameraFlags |= FLAGS_HOT_CAMERA;
- mDeathNotifier = new DeathNotifier();
- // isBinderAlive needs linkToDeath to work.
- mCameraRecordingProxy->asBinder()->linkToDeath(mDeathNotifier);
- }
-
- mCamera->lock();
-
- return OK;
-}
-
+//TODO: Do we need to reimplement isCameraAvailable?
/*
* Check to see whether the requested video width and height is one
@@ -267,7 +230,7 @@ static void getSupportedVideoSizes(
* @param params CameraParameters to retrieve the information
* @return OK if no error.
*/
-status_t CameraSource::isCameraColorFormatSupported(
+status_t GonkCameraSource::isCameraColorFormatSupported(
const CameraParameters& params) {
mColorFormat = getColorFormat(params.get(
CameraParameters::KEY_VIDEO_FRAME_FORMAT));
@@ -292,7 +255,7 @@ status_t CameraSource::isCameraColorFormatSupported(
* @param frameRate the target frame rate in frames per second.
* @return OK if no error.
*/
-status_t CameraSource::configureCamera(
+status_t GonkCameraSource::configureCamera(
CameraParameters* params,
int32_t width, int32_t height,
int32_t frameRate) {
@@ -347,10 +310,9 @@ status_t CameraSource::configureCamera(
if (isCameraParamChanged) {
// Either frame rate or frame size needs to be changed.
- String8 s = params->flatten();
- if (OK != mCamera->setParameters(s)) {
+ if (OK != GonkCameraHardware::PushParameters(mCameraHandle,*params)) {
LOGE("Could not change settings."
- " Someone else is using camera %p?", mCamera.get());
+ " Someone else is using camera ?");
return -EBUSY;
}
}
@@ -368,7 +330,7 @@ status_t CameraSource::configureCamera(
* @param the target video frame height in pixels to check against
* @return OK if no error
*/
-status_t CameraSource::checkVideoSize(
+status_t GonkCameraSource::checkVideoSize(
const CameraParameters& params,
int32_t width, int32_t height) {
@@ -420,7 +382,7 @@ status_t CameraSource::checkVideoSize(
* @param the target video frame rate to check against
* @return OK if no error.
*/
-status_t CameraSource::checkFrameRate(
+status_t GonkCameraSource::checkFrameRate(
const CameraParameters& params,
int32_t frameRate) {
@@ -462,39 +424,17 @@ status_t CameraSource::checkFrameRate(
*
* @return OK if no error.
*/
-status_t CameraSource::init(
- const sp<ICamera>& camera,
- const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId,
+status_t GonkCameraSource::init(
Size videoSize,
int32_t frameRate,
bool storeMetaDataInVideoBuffers) {
LOGV("init");
status_t err = OK;
- int64_t token = IPCThreadState::self()->clearCallingIdentity();
- err = initWithCameraAccess(camera, proxy, cameraId,
- videoSize, frameRate,
- storeMetaDataInVideoBuffers);
- IPCThreadState::self()->restoreCallingIdentity(token);
- return err;
-}
-
-status_t CameraSource::initWithCameraAccess(
- const sp<ICamera>& camera,
- const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId,
- Size videoSize,
- int32_t frameRate,
- bool storeMetaDataInVideoBuffers) {
- LOGV("initWithCameraAccess");
- status_t err = OK;
+ //TODO: need to do something here to check the sanity of camera
- if ((err = isCameraAvailable(camera, proxy, cameraId)) != OK) {
- LOGE("Camera connection could not be established.");
- return err;
- }
- CameraParameters params(mCamera->getParameters());
+ CameraParameters params;
+ GonkCameraHardware::PullParameters(mCameraHandle, params);
if ((err = isCameraColorFormatSupported(params)) != OK) {
return err;
}
@@ -508,7 +448,8 @@ status_t CameraSource::initWithCameraAccess(
}
// Check on video frame size and frame rate.
- CameraParameters newCameraParams(mCamera->getParameters());
+ CameraParameters newCameraParams;
+ GonkCameraHardware::PullParameters(mCameraHandle, newCameraParams);
if ((err = checkVideoSize(newCameraParams,
videoSize.width, videoSize.height)) != OK) {
return err;
@@ -517,15 +458,11 @@ status_t CameraSource::initWithCameraAccess(
return err;
}
- // This CHECK is good, since we just passed the lock/unlock
- // check earlier by calling mCamera->setParameters().
- CHECK_EQ(OK, mCamera->setPreviewDisplay(mSurface));
-
// By default, do not store metadata in video buffers
mIsMetaDataStoredInVideoBuffers = false;
- mCamera->storeMetaDataInBuffers(false);
+ GonkCameraHardware::StoreMetaDataInBuffers(mCameraHandle, false);
if (storeMetaDataInVideoBuffers) {
- if (OK == mCamera->storeMetaDataInBuffers(true)) {
+ if (OK == GonkCameraHardware::StoreMetaDataInBuffers(mCameraHandle, true)) {
mIsMetaDataStoredInVideoBuffers = true;
}
}
@@ -568,40 +505,28 @@ status_t CameraSource::initWithCameraAccess(
return OK;
}
-CameraSource::~CameraSource() {
+GonkCameraSource::~GonkCameraSource() {
if (mStarted) {
stop();
} else if (mInitCheck == OK) {
// Camera is initialized but because start() is never called,
// the lock on Camera is never released(). This makes sure
// Camera's lock is released in this case.
+ // TODO: Don't think I need to do this
releaseCamera();
}
}
-void CameraSource::startCameraRecording() {
+void GonkCameraSource::startCameraRecording() {
LOGV("startCameraRecording");
- // Reset the identity to the current thread because media server owns the
- // camera and recording is started by the applications. The applications
- // will connect to the camera in ICameraRecordingProxy::startRecording.
- int64_t token = IPCThreadState::self()->clearCallingIdentity();
- if (mCameraFlags & FLAGS_HOT_CAMERA) {
- mCamera->unlock();
- mCamera.clear();
- CHECK_EQ(OK, mCameraRecordingProxy->startRecording(new ProxyListener(this)));
- } else {
- mCamera->setListener(new CameraSourceListener(this));
- mCamera->startRecording();
- CHECK(mCamera->recordingEnabled());
- }
- IPCThreadState::self()->restoreCallingIdentity(token);
+ CHECK_EQ(OK, GonkCameraHardware::StartRecording(mCameraHandle));
}
-status_t CameraSource::start(MetaData *meta) {
+status_t GonkCameraSource::start(MetaData *meta) {
LOGV("start");
CHECK(!mStarted);
if (mInitCheck != OK) {
- LOGE("CameraSource is not initialized yet");
+ LOGE("GonkCameraSource is not initialized yet");
return mInitCheck;
}
@@ -614,58 +539,34 @@ status_t CameraSource::start(MetaData *meta) {
mStartTimeUs = 0;
int64_t startTimeUs;
if (meta && meta->findInt64(kKeyTime, &startTimeUs)) {
+ LOGV("Metadata enabled, startime: %lld us", startTimeUs);
mStartTimeUs = startTimeUs;
}
+ // Register a listener with GonkCameraHardware so that we can get callbacks
+ GonkCameraHardware::SetListener(mCameraHandle, new GonkCameraSourceListener(this));
+
startCameraRecording();
mStarted = true;
return OK;
}
-void CameraSource::stopCameraRecording() {
+void GonkCameraSource::stopCameraRecording() {
LOGV("stopCameraRecording");
- if (mCameraFlags & FLAGS_HOT_CAMERA) {
- mCameraRecordingProxy->stopRecording();
- } else {
- mCamera->setListener(NULL);
- mCamera->stopRecording();
- }
+ GonkCameraHardware::StopRecording(mCameraHandle);
}
-void CameraSource::releaseCamera() {
+void GonkCameraSource::releaseCamera() {
LOGV("releaseCamera");
- if (mCamera != 0) {
- int64_t token = IPCThreadState::self()->clearCallingIdentity();
- if ((mCameraFlags & FLAGS_HOT_CAMERA) == 0) {
- LOGV("Camera was cold when we started, stopping preview");
- mCamera->stopPreview();
- mCamera->disconnect();
- }
- mCamera->unlock();
- mCamera.clear();
- mCamera = 0;
- IPCThreadState::self()->restoreCallingIdentity(token);
- }
- if (mCameraRecordingProxy != 0) {
- mCameraRecordingProxy->asBinder()->unlinkToDeath(mDeathNotifier);
- mCameraRecordingProxy.clear();
- }
- mCameraFlags = 0;
}
-status_t CameraSource::stop() {
- LOGD("stop: E");
+status_t GonkCameraSource::stop() {
+ LOGV("stop: E");
Mutex::Autolock autoLock(mLock);
mStarted = false;
mFrameAvailableCondition.signal();
- int64_t token;
- bool isTokenValid = false;
- if (mCamera != 0) {
- token = IPCThreadState::self()->clearCallingIdentity();
- isTokenValid = true;
- }
releaseQueuedFrames();
while (!mFramesBeingEncoded.empty()) {
if (NO_ERROR !=
@@ -675,11 +576,9 @@ status_t CameraSource::stop() {
mFramesBeingEncoded.size());
}
}
+ LOGV("Calling stopCameraRecording");
stopCameraRecording();
releaseCamera();
- if (isTokenValid) {
- IPCThreadState::self()->restoreCallingIdentity(token);
- }
if (mCollectStats) {
LOGI("Frames received/encoded/dropped: %d/%d/%d in %lld us",
@@ -692,22 +591,16 @@ status_t CameraSource::stop() {
}
CHECK_EQ(mNumFramesReceived, mNumFramesEncoded + mNumFramesDropped);
- LOGD("stop: X");
+ LOGV("stop: X");
return OK;
}
-void CameraSource::releaseRecordingFrame(const sp<IMemory>& frame) {
+void GonkCameraSource::releaseRecordingFrame(const sp<IMemory>& frame) {
LOGV("releaseRecordingFrame");
- if (mCameraRecordingProxy != NULL) {
- mCameraRecordingProxy->releaseRecordingFrame(frame);
- } else if (mCamera != NULL) {
- int64_t token = IPCThreadState::self()->clearCallingIdentity();
- mCamera->releaseRecordingFrame(frame);
- IPCThreadState::self()->restoreCallingIdentity(token);
- }
+ GonkCameraHardware::ReleaseRecordingFrame(mCameraHandle, frame);
}
-void CameraSource::releaseQueuedFrames() {
+void GonkCameraSource::releaseQueuedFrames() {
List<sp<IMemory> >::iterator it;
while (!mFramesReceived.empty()) {
it = mFramesReceived.begin();
@@ -717,15 +610,15 @@ void CameraSource::releaseQueuedFrames() {
}
}
-sp<MetaData> CameraSource::getFormat() {
+sp<MetaData> GonkCameraSource::getFormat() {
return mMeta;
}
-void CameraSource::releaseOneRecordingFrame(const sp<IMemory>& frame) {
+void GonkCameraSource::releaseOneRecordingFrame(const sp<IMemory>& frame) {
releaseRecordingFrame(frame);
}
-void CameraSource::signalBufferReturned(MediaBuffer *buffer) {
+void GonkCameraSource::signalBufferReturned(MediaBuffer *buffer) {
LOGV("signalBufferReturned: %p", buffer->data());
Mutex::Autolock autoLock(mLock);
for (List<sp<IMemory> >::iterator it = mFramesBeingEncoded.begin();
@@ -743,7 +636,7 @@ void CameraSource::signalBufferReturned(MediaBuffer *buffer) {
CHECK_EQ(0, "signalBufferReturned: bogus buffer");
}
-status_t CameraSource::read(
+status_t GonkCameraSource::read(
MediaBuffer **buffer, const ReadOptions *options) {
LOGV("read");
@@ -764,11 +657,7 @@ status_t CameraSource::read(
if (NO_ERROR !=
mFrameAvailableCondition.waitRelative(mLock,
mTimeBetweenFrameCaptureUs * 1000LL + CAMERA_SOURCE_TIMEOUT_NS)) {
- if (mCameraRecordingProxy != 0 &&
- !mCameraRecordingProxy->asBinder()->isBinderAlive()) {
- LOGW("camera recording proxy is gone");
- return ERROR_END_OF_STREAM;
- }
+ //TODO: check sanity of camera?
LOGW("Timed out waiting for incoming camera video frames: %lld us",
mLastFrameTimestampUs);
}
@@ -790,9 +679,10 @@ status_t CameraSource::read(
return OK;
}
-void CameraSource::dataCallbackTimestamp(int64_t timestampUs,
+void GonkCameraSource::dataCallbackTimestamp(int64_t timestampUs,
int32_t msgType, const sp<IMemory> &data) {
LOGV("dataCallbackTimestamp: timestamp %lld us", timestampUs);
+ //LOGV("dataCallbackTimestamp: data %x size %d", data->pointer(), data->size());
Mutex::Autolock autoLock(mLock);
if (!mStarted || (mNumFramesReceived == 0 && timestampUs < mStartTimeUs)) {
LOGV("Drop frame at %lld/%lld us", timestampUs, mStartTimeUs);
@@ -808,7 +698,7 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs,
}
// May need to skip frame or modify timestamp. Currently implemented
- // by the subclass CameraSourceTimeLapse.
+ // by the subclass GonkCameraSourceTimeLapse.
if (skipCurrentFrame(timestampUs)) {
releaseOneRecordingFrame(data);
return;
@@ -839,22 +729,9 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs,
mFrameAvailableCondition.signal();
}
-bool CameraSource::isMetaDataStoredInVideoBuffers() const {
+bool GonkCameraSource::isMetaDataStoredInVideoBuffers() const {
LOGV("isMetaDataStoredInVideoBuffers");
return mIsMetaDataStoredInVideoBuffers;
}
-CameraSource::ProxyListener::ProxyListener(const sp<CameraSource>& source) {
- mSource = source;
-}
-
-void CameraSource::ProxyListener::dataCallbackTimestamp(
- nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) {
- mSource->dataCallbackTimestamp(timestamp / 1000, msgType, dataPtr);
-}
-
-void CameraSource::DeathNotifier::binderDied(const wp<IBinder>& who) {
- LOGI("Camera recording proxy died");
-}
-
-} // namespace android
+} // namespace android
diff --git a/GonkCameraSource.h b/GonkCameraSource.h
index 446720b..fe58f96 100644
--- a/GonkCameraSource.h
+++ b/GonkCameraSource.h
@@ -14,69 +14,31 @@
* limitations under the License.
*/
-#ifndef CAMERA_SOURCE_H_
+#ifndef GONK_CAMERA_SOURCE_H_
-#define CAMERA_SOURCE_H_
+#define GONK_CAMERA_SOURCE_H_
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaSource.h>
-#include <camera/ICamera.h>
-#include <camera/ICameraRecordingProxyListener.h>
#include <camera/CameraParameters.h>
#include <utils/List.h>
#include <utils/RefBase.h>
+#include <utils/threads.h>
namespace android {
class IMemory;
-class Camera;
-class Surface;
+class GonkCameraSourceListener;
-class CameraSource : public MediaSource, public MediaBufferObserver {
+class GonkCameraSource : public MediaSource, public MediaBufferObserver {
public:
- /**
- * Factory method to create a new CameraSource using the current
- * settings (such as video size, frame rate, color format, etc)
- * from the default camera.
- *
- * @return NULL on error.
- */
- static CameraSource *Create();
- /**
- * Factory method to create a new CameraSource.
- *
- * @param camera the video input frame data source. If it is NULL,
- * we will try to connect to the camera with the given
- * cameraId.
- *
- * @param cameraId the id of the camera that the source will connect
- * to if camera is NULL; otherwise ignored.
- *
- * @param videoSize the dimension (in pixels) of the video frame
- * @param frameRate the target frames per second
- * @param surface the preview surface for display where preview
- * frames are sent to
- * @param storeMetaDataInVideoBuffers true to request the camera
- * source to store meta data in video buffers; false to
- * request the camera source to store real YUV frame data
- * in the video buffers. The camera source may not support
- * storing meta data in video buffers, if so, a request
- * to do that will NOT be honored. To find out whether
- * meta data is actually being stored in video buffers
- * during recording, call isMetaDataStoredInVideoBuffers().
- *
- * @return NULL on error.
- */
- static CameraSource *CreateFromCamera(const sp<ICamera> &camera,
- const sp<ICameraRecordingProxy> &proxy,
- int32_t cameraId,
- Size videoSize,
- int32_t frameRate,
- const sp<Surface>& surface,
- bool storeMetaDataInVideoBuffers = false);
+ static GonkCameraSource *Create(int32_t cameraHandle,
+ Size videoSize,
+ int32_t frameRate,
+ bool storeMetaDataInVideoBuffers = false);
- virtual ~CameraSource();
+ virtual ~GonkCameraSource();
virtual status_t start(MetaData *params = NULL);
virtual status_t stop();
@@ -84,14 +46,14 @@ public:
MediaBuffer **buffer, const ReadOptions *options = NULL);
/**
- * Check whether a CameraSource object is properly initialized.
+ * Check whether a GonkCameraSource object is properly initialized.
* Must call this method before stop().
* @return OK if initialization has successfully completed.
*/
virtual status_t initCheck() const;
/**
- * Returns the MetaData associated with the CameraSource,
+ * Returns the MetaData associated with the GonkCameraSource,
* including:
* kKeyColorFormat: YUV color format of the video frames
* kKeyWidth, kKeyHeight: dimension (in pixels) of the video frames
@@ -113,22 +75,6 @@ public:
virtual void signalBufferReturned(MediaBuffer* buffer);
protected:
- class ProxyListener: public BnCameraRecordingProxyListener {
- public:
- ProxyListener(const sp<CameraSource>& source);
- virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType,
- const sp<IMemory> &data);
-
- private:
- sp<CameraSource> mSource;
- };
-
- // isBinderAlive needs linkToDeath to work.
- class DeathNotifier: public IBinder::DeathRecipient {
- public:
- DeathNotifier() {}
- virtual void binderDied(const wp<IBinder>& who);
- };
enum CameraFlags {
FLAGS_SET_CAMERA = 1L << 0,
@@ -141,10 +87,6 @@ protected:
int32_t mColorFormat;
status_t mInitCheck;
- sp<Camera> mCamera;
- sp<ICameraRecordingProxy> mCameraRecordingProxy;
- sp<DeathNotifier> mDeathNotifier;
- sp<Surface> mSurface;
sp<MetaData> mMeta;
int64_t mStartTimeUs;
@@ -156,11 +98,9 @@ protected:
// Time between capture of two frames.
int64_t mTimeBetweenFrameCaptureUs;
- CameraSource(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId,
+ GonkCameraSource(int32_t cameraHandle,
Size videoSize, int32_t frameRate,
- const sp<Surface>& surface,
- bool storeMetaDataInVideoBuffers);
+ bool storeMetaDataInVideoBuffers = false);
virtual void startCameraRecording();
virtual void stopCameraRecording();
@@ -170,6 +110,7 @@ protected:
// Called from dataCallbackTimestamp.
virtual bool skipCurrentFrame(int64_t timestampUs) {return false;}
+ friend class GonkCameraSourceListener;
// Callback called when still camera raw data is available.
virtual void dataCallback(int32_t msgType, const sp<IMemory> &data) {}
@@ -177,7 +118,6 @@ protected:
const sp<IMemory> &data);
private:
- friend class CameraSourceListener;
Mutex mLock;
Condition mFrameAvailableCondition;
@@ -192,23 +132,13 @@ private:
int64_t mGlitchDurationThresholdUs;
bool mCollectStats;
bool mIsMetaDataStoredInVideoBuffers;
+ int32_t mCameraHandle;
void releaseQueuedFrames();
void releaseOneRecordingFrame(const sp<IMemory>& frame);
-
- status_t init(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId, Size videoSize, int32_t frameRate,
- bool storeMetaDataInVideoBuffers);
-
- status_t initWithCameraAccess(
- const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId, Size videoSize, int32_t frameRate,
+ status_t init(Size videoSize, int32_t frameRate,
bool storeMetaDataInVideoBuffers);
-
- status_t isCameraAvailable(const sp<ICamera>& camera,
- const sp<ICameraRecordingProxy>& proxy,
- int32_t cameraId);
status_t isCameraColorFormatSupported(const CameraParameters& params);
status_t configureCamera(CameraParameters* params,
int32_t width, int32_t height,
@@ -222,10 +152,10 @@ private:
void releaseCamera();
- CameraSource(const CameraSource &);
- CameraSource &operator=(const CameraSource &);
+ GonkCameraSource(const GonkCameraSource &);
+ GonkCameraSource &operator=(const GonkCameraSource &);
};
} // namespace android
-#endif // CAMERA_SOURCE_H_
+#endif // GONK_CAMERA_SOURCE_H_
diff --git a/GonkRecorder.cpp b/GonkRecorder.cpp
index b20ca9d..2dc625c 100644
--- a/GonkRecorder.cpp
+++ b/GonkRecorder.cpp
@@ -16,35 +16,23 @@
*/
//#define LOG_NDEBUG 0
-#define LOG_TAG "StagefrightRecorder"
+#define LOG_TAG "GonkRecorder"
+
#include <utils/Log.h>
#include <media/AudioParameter.h>
-#include "StagefrightRecorder.h"
-
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
+#include "GonkRecorder.h"
-#include <media/IMediaPlayerService.h>
#include <media/stagefright/AudioSource.h>
#include <media/stagefright/AMRWriter.h>
-#include <media/stagefright/AACWriter.h>
-#include <media/stagefright/ExtendedWriter.h>
-#include <media/stagefright/FMA2DPWriter.h>
-#include <media/stagefright/CameraSource.h>
-#include <media/stagefright/CameraSourceTimeLapse.h>
#include <media/stagefright/ExtendedWriter.h>
#include <media/stagefright/MPEG2TSWriter.h>
#include <media/stagefright/MPEG4Writer.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MetaData.h>