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
|
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef QCAMERA_TEST_H
#define QCAMERA_TEST_H
#include <SkData.h>
#include <SkBitmap.h>
#include <SkStream.h>
namespace qcamera {
using namespace android;
#define MAX_CAM_INSTANCES 3
class TestContext;
class CameraContext : public CameraListener,
public ICameraRecordingProxyListener{
public:
typedef enum {
READ_METADATA = 1,
READ_IMAGE = 2,
READ_ALL = 3
} ReadMode_t;
// This structure is used to store jpeg file sections in memory.
typedef struct {
unsigned char * Data;
int Type;
size_t Size;
} Sections_t;
public:
static const char KEY_ZSL[];
CameraContext(int cameraIndex);
virtual ~CameraContext();
status_t openCamera();
status_t closeCamera();
status_t startPreview();
status_t stopPreview();
status_t resumePreview();
status_t autoFocus();
status_t enablePreviewCallbacks();
status_t takePicture();
status_t startRecording();
status_t stopRecording();
status_t startViVRecording();
status_t stopViVRecording();
status_t configureViVRecording();
status_t nextPreviewSize();
status_t setPreviewSize(const char *format);
status_t getCurrentPreviewSize(Size &previewSize);
status_t nextPictureSize();
status_t getCurrentPictureSize(Size &pictureSize);
status_t setPictureSize(const char *format);
status_t nextVideoSize();
status_t setVideoSize(const char *format);
status_t getCurrentVideoSize(Size &videoSize);
status_t configureRecorder();
status_t unconfigureRecorder();
Sections_t *FindSection(int SectionType);
status_t ReadSectionsFromBuffer (unsigned char *buffer,
size_t buffer_size, ReadMode_t ReadMode);
virtual IBinder* onAsBinder();
void setTestCtxInstance(TestContext *instance);
void printMenu(sp<CameraContext> currentCamera);
void printSupportedParams();
const char *getZSL();
void setZSL(const char *value);
int getCameraIndex() { return mCameraIndex; }
int getNumberOfCameras();
void enablePrintPreview();
void disablePrintPreview();
void enablePiPCapture();
void disablePiPCapture();
void CheckSectionsAllocated();
void DiscardData();
void DiscardSections();
size_t calcBufferSize(int width, int height);
size_t calcStride(int width);
size_t calcYScanLines(int height);
size_t calcUVScanLines(int height);
virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2);
virtual void postData(int32_t msgType,
const sp<IMemory>& dataPtr,
camera_frame_metadata_t *metadata);
virtual void postDataTimestamp(nsecs_t timestamp,
int32_t msgType,
const sp<IMemory>& dataPtr);
virtual void dataCallbackTimestamp(nsecs_t timestamp,
int32_t msgType,
const sp<IMemory>& dataPtr);
private:
status_t createPreviewSurface(int width, int height, int32_t pixFormat);
status_t destroyPreviewSurface();
status_t saveFile(const sp<IMemory>& mem, String8 path);
SkBitmap * PiPCopyToOneFile(SkBitmap *bitmap0, SkBitmap *bitmap1);
status_t decodeJPEG(const sp<IMemory>& mem, SkBitmap *skBM);
status_t encodeJPEG(SkWStream * stream, const SkBitmap *bitmap,
String8 path);
void previewCallback(const sp<IMemory>& mem);
static int JpegIdx;
int mCameraIndex;
bool mResizePreview;
bool mHardwareActive;
bool mPreviewRunning;
bool mRecordRunning;
int mVideoFd;
int mVideoIdx;
bool mRecordingHint;
bool mDoPrintMenu;
bool mPiPCapture;
static int mPiPIdx;
unsigned int mfmtMultiplier;
int mWidthTmp;
int mHeightTmp;
size_t mSectionsRead;
size_t mSectionsAllocated;
Sections_t * mSections;
Sections_t * mJEXIFTmp;
Sections_t mJEXIFSection;
int mHaveAll;
TestContext *mInterpr;
sp<Camera> mCamera;
sp<SurfaceComposerClient> mClient;
sp<SurfaceControl> mSurfaceControl;
sp<Surface> mPreviewSurface;
sp<MediaRecorder> mRecorder;
CameraParameters mParams;
SkBitmap *skBMDec;
SkImageEncoder* skJpegEnc;
SkBitmap skBMtmp;
sp<IMemory> PiPPtrTmp;
size_t mCurrentPreviewSizeIdx;
Size getPreviewSizeFromVideoSizes(Size currentVideoSize);
size_t mCurrentPictureSizeIdx;
size_t mCurrentVideoSizeIdx;
Vector<Size> mSupportedPreviewSizes;
Vector<Size> mSupportedPictureSizes;
Vector<Size> mSupportedVideoSizes;
bool mInUse;
Mutex mLock;
Condition mCond;
void useLock();
void signalFinished();
//------------------------------------------------------------------------
// JPEG markers consist of one or more 0xFF bytes, followed by a marker
// code byte (which is not an FF). Here are the marker codes of interest
// in this program. (See jdmarker.c for a more complete list.)
//------------------------------------------------------------------------
#define M_SOF0 0xC0 // Start Of Frame N
#define M_SOF1 0xC1 // N indicates which compression process
#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use
#define M_SOF3 0xC3
#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers
#define M_SOF6 0xC6
#define M_SOF7 0xC7
#define M_SOF9 0xC9
#define M_SOF10 0xCA
#define M_SOF11 0xCB
#define M_SOF13 0xCD
#define M_SOF14 0xCE
#define M_SOF15 0xCF
#define M_SOI 0xD8 // Start Of Image (beginning of datastream)
#define M_EOI 0xD9 // End Of Image (end of datastream)
#define M_SOS 0xDA // Start Of Scan (begins compressed data)
#define M_JFIF 0xE0 // Jfif marker
#define M_EXIF 0xE1 // Exif marker. Also used for XMP data!
#define M_XMP 0x10E1 // Not a real tag same value as Exif!
#define M_COM 0xFE // COMment
#define M_DQT 0xDB
#define M_DHT 0xC4
#define M_DRI 0xDD
#define M_IPTC 0xED // IPTC marker
#define PSEUDO_IMAGE_MARKER 0x123; // Extra value.
};
class Interpreter
{
public:
enum Commands_e {
SWITCH_CAMERA_CMD = 'A',
RESUME_PREVIEW_CMD = '[',
START_PREVIEW_CMD = '1',
STOP_PREVIEW_CMD = '2',
CHANGE_VIDEO_SIZE_CMD = '3',
CHANGE_PREVIEW_SIZE_CMD = '4',
CHANGE_PICTURE_SIZE_CMD = '5',
START_RECORD_CMD = '6',
STOP_RECORD_CMD = '7',
START_VIV_RECORD_CMD = '8',
STOP_VIV_RECORD_CMD = '9',
DUMP_CAPS_CMD = 'E',
AUTOFOCUS_CMD = 'f',
TAKEPICTURE_CMD = 'p',
TAKEPICTURE_IN_PICTURE_CMD = 'P',
ENABLE_PRV_CALLBACKS_CMD = '&',
EXIT_CMD = 'q',
DELAY = 'd',
ZSL_CMD = 'z',
INVALID_CMD = '0'
};
struct Command {
Command( Commands_e cmd_, char *arg_ = NULL)
: cmd(cmd_)
, arg(arg_) {}
Command()
: cmd(INVALID_CMD)
, arg(NULL) {}
Commands_e cmd;
char *arg;
};
/* API */
Interpreter()
: mUseScript(false)
, mScript(NULL) {}
Interpreter(const char *file);
~Interpreter();
Command getCommand(sp<CameraContext> currentCamera);
void releasePiPBuff();
status_t configureViVCodec();
void setViVSize(Size VideoSize, int camIndex);
void setTestCtxInst(TestContext *instance);
status_t unconfigureViVCodec();
status_t ViVEncoderThread();
void ViVEncode();
static void *ThreadWrapper(void *context);
private:
static const int numberOfCommands;
bool mUseScript;
size_t mCmdIndex;
char *mScript;
Vector<Command> mCommands;
TestContext *mTestContext;
pthread_t mViVEncThread;
};
class TestContext
{
friend class CameraContext;
friend class Interpreter;
public:
TestContext();
~TestContext();
size_t GetCamerasNum();
status_t FunctionalTest();
status_t AddScriptFromFile(const char *scriptFile);
void setViVSize(Size VideoSize, int camIndex);
void PiPLock();
void PiPUnlock();
void ViVLock();
void ViVUnlock();
private:
sp<CameraContext> camera[MAX_CAM_INSTANCES];
char GetNextCmd(sp<qcamera::CameraContext> currentCamera);
size_t mCurrentCameraIndex;
size_t mSaveCurrentCameraIndex;
Vector< sp<qcamera::CameraContext> > mAvailableCameras;
bool mTestRunning;
Interpreter *mInterpreter;
Mutex mPiPLock;
Condition mPiPCond;
bool mPiPinUse;
Mutex mViVLock;
Condition mViVCond;
bool mViVinUse;
bool mIsZSLOn;
typedef struct ViVBuff_t{
void *buff;
size_t buffSize;
size_t YStride;
size_t UVStride;
size_t YScanLines;
size_t UVScanLines;
size_t srcWidth;
size_t srcHeight;
} ViVBuff_t;
typedef struct ViVVid_t{
sp<IGraphicBufferProducer> bufferProducer;
sp<Surface> surface;
sp<MediaCodec> codec;
sp<MediaMuxer> muxer;
sp<ANativeWindow> ANW;
Vector<sp<ABuffer> > buffers;
Size VideoSizes[2];
int ViVIdx;
size_t buff_cnt;
sp<GraphicBuffer> graphBuf;
void * mappedBuff;
bool isBuffValid;
int sourceCameraID;
int destinationCameraID;
} vidPiP_t;
ViVVid_t mViVVid;
ViVBuff_t mViVBuff;
};
}; //namespace qcamera
#endif
|