4package org.qtproject.qt.android.multimedia;
6import android.hardware.Camera;
7import android.hardware.Camera.CameraInfo;
9import android.graphics.ImageFormat;
10import android.graphics.SurfaceTexture;
11import android.util.Log;
15 Camera.PictureCallback,
16 Camera.AutoFocusCallback,
17 Camera.PreviewCallback
19 private static final String TAG =
"Qt Camera";
21 private static final int BUFFER_POOL_SIZE = 2;
23 private int m_cameraId = -1;
25 private boolean m_notifyNewFrames =
false;
26 private boolean m_notifyWhenFrameAvailable =
false;
27 private byte[][] m_previewBuffers =
null;
28 private byte[] m_lastPreviewBuffer =
null;
29 private Camera.Size m_previewSize =
null;
30 private int m_previewFormat = ImageFormat.NV21;
31 private int m_previewBytesPerLine = -1;
40 m_notifyNewFrames = notify;
45 m_notifyWhenFrameAvailable = notify;
50 return m_lastPreviewBuffer;
55 if (m_previewSize ==
null)
58 return m_previewSize.width;
63 if (m_previewSize ==
null)
66 return m_previewSize.height;
71 return m_previewFormat;
76 return m_previewBytesPerLine;
81 camera.setPreviewCallbackWithBuffer(
null);
88 m_lastPreviewBuffer =
null;
91 m_previewSize =
params.getPreviewSize();
92 m_previewFormat =
params.getPreviewFormat();
94 int bufferSizeNeeded = 0;
95 if (m_previewFormat == ImageFormat.YV12) {
97 final int yStride = (int) Math.ceil(m_previewSize.width / 16.0) * 16;
98 final int uvStride = (int) Math.ceil((yStride / 2) / 16.0) * 16;
99 final int ySize = yStride * m_previewSize.height;
100 final int uvSize = uvStride * m_previewSize.height / 2;
101 bufferSizeNeeded = ySize + uvSize * 2;
103 m_previewBytesPerLine = yStride;
106 double bytesPerPixel = ImageFormat.getBitsPerPixel(m_previewFormat) / 8.0;
107 bufferSizeNeeded = (int) Math.ceil(bytesPerPixel * m_previewSize.width * m_previewSize.height);
110 switch (m_previewFormat) {
111 case ImageFormat.NV21:
112 m_previewBytesPerLine = m_previewSize.width;
114 case ImageFormat.RGB_565:
115 case ImageFormat.YUY2:
116 m_previewBytesPerLine = m_previewSize.width * 2;
119 m_previewBytesPerLine = -1;
126 if (m_previewBuffers ==
null || m_previewBuffers[0].
length != bufferSizeNeeded)
127 m_previewBuffers =
new byte[BUFFER_POOL_SIZE][bufferSizeNeeded];
130 camera.setPreviewCallbackWithBuffer(
this);
131 for (
byte[]
buffer : m_previewBuffers)
139 if (m_lastPreviewBuffer !=
null)
140 camera.addCallbackBuffer(m_lastPreviewBuffer);
142 m_lastPreviewBuffer =
data;
145 if (m_notifyWhenFrameAvailable) {
146 m_notifyWhenFrameAvailable =
false;
147 notifyFrameAvailable(m_cameraId);
149 if (m_notifyNewFrames) {
150 notifyNewPreviewFrame(m_cameraId,
data,
151 m_previewSize.width, m_previewSize.height,
153 m_previewBytesPerLine);
161 notifyPictureExposed(m_cameraId);
167 notifyPictureCaptured(m_cameraId,
data);
173 notifyAutoFocusComplete(m_cameraId, success);
176 private static native
void notifyAutoFocusComplete(
int id,
boolean success);
177 private static native
void notifyPictureExposed(
int id);
178 private static native
void notifyPictureCaptured(
int id,
byte[]
data);
179 private static native
void notifyNewPreviewFrame(
int id,
byte[]
data,
int width,
int height,
180 int pixelFormat,
int bytesPerLine);
181 private static native
void notifyFrameAvailable(
int id);
GLint GLsizei GLsizei height
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data