OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.media; | 5 package org.chromium.media; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.ImageFormat; | 8 import android.graphics.ImageFormat; |
9 import android.graphics.SurfaceTexture; | 9 import android.graphics.SurfaceTexture; |
10 import android.graphics.SurfaceTexture.OnFrameAvailableListener; | 10 import android.graphics.SurfaceTexture.OnFrameAvailableListener; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 static int getImageFormat() { | 44 static int getImageFormat() { |
45 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODE
S.JELLY_BEAN) { | 45 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODE
S.JELLY_BEAN) { |
46 return ImageFormat.NV21; | 46 return ImageFormat.NV21; |
47 } | 47 } |
48 | 48 |
49 for (String buggyDevice : sBUGGY_DEVICE_LIST) { | 49 for (String buggyDevice : sBUGGY_DEVICE_LIST) { |
50 if (buggyDevice.contentEquals(android.os.Build.MODEL)) { | 50 if (buggyDevice.contentEquals(android.os.Build.MODEL)) { |
51 return ImageFormat.NV21; | 51 return ImageFormat.NV21; |
52 } | 52 } |
53 } | 53 } |
54 | |
55 return ImageFormat.YV12; | 54 return ImageFormat.YV12; |
56 } | 55 } |
57 } | 56 } |
58 | 57 |
59 private Camera mCamera; | 58 private Camera mCamera; |
60 public ReentrantLock mPreviewBufferLock = new ReentrantLock(); | 59 public ReentrantLock mPreviewBufferLock = new ReentrantLock(); |
61 private int mImageFormat = ImageFormat.YV12; | 60 private int mImageFormat = ImageFormat.YV12; |
62 private byte[] mColorPlane = null; | 61 private byte[] mColorPlane = null; |
63 private Context mContext = null; | 62 private Context mContext = null; |
64 // True when native code has started capture. | 63 // True when native code has started capture. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 public int queryHeight() { | 230 public int queryHeight() { |
232 return mCurrentCapability.mHeight; | 231 return mCurrentCapability.mHeight; |
233 } | 232 } |
234 | 233 |
235 @CalledByNative | 234 @CalledByNative |
236 public int queryFrameRate() { | 235 public int queryFrameRate() { |
237 return mCurrentCapability.mDesiredFps; | 236 return mCurrentCapability.mDesiredFps; |
238 } | 237 } |
239 | 238 |
240 @CalledByNative | 239 @CalledByNative |
| 240 public int getColorspace() { |
| 241 switch (mImageFormat){ |
| 242 case ImageFormat.YV12: |
| 243 return AndroidImageFormatList.ANDROID_IMAGEFORMAT_YV12; |
| 244 case ImageFormat.NV21: |
| 245 return AndroidImageFormatList.ANDROID_IMAGEFORMAT_NV21; |
| 246 case ImageFormat.YUY2: |
| 247 return AndroidImageFormatList.ANDROID_IMAGEFORMAT_YUY2; |
| 248 case ImageFormat.NV16: |
| 249 return AndroidImageFormatList.ANDROID_IMAGEFORMAT_NV16; |
| 250 case ImageFormat.JPEG: |
| 251 return AndroidImageFormatList.ANDROID_IMAGEFORMAT_JPEG; |
| 252 case ImageFormat.RGB_565: |
| 253 return AndroidImageFormatList.ANDROID_IMAGEFORMAT_RGB_565; |
| 254 case ImageFormat.UNKNOWN: |
| 255 default: |
| 256 return AndroidImageFormatList.ANDROID_IMAGEFORMAT_UNKNOWN; |
| 257 } |
| 258 } |
| 259 |
| 260 @CalledByNative |
241 public int startCapture() { | 261 public int startCapture() { |
242 if (mCamera == null) { | 262 if (mCamera == null) { |
243 Log.e(TAG, "startCapture: camera is null"); | 263 Log.e(TAG, "startCapture: camera is null"); |
244 return -1; | 264 return -1; |
245 } | 265 } |
246 | 266 |
247 mPreviewBufferLock.lock(); | 267 mPreviewBufferLock.lock(); |
248 try { | 268 try { |
249 if (mIsRunning) { | 269 if (mIsRunning) { |
250 return 0; | 270 return 0; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 boolean flipVertical = false; | 338 boolean flipVertical = false; |
319 boolean flipHorizontal = false; | 339 boolean flipHorizontal = false; |
320 if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) { | 340 if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) { |
321 rotation = (mCameraOrientation + rotation) % 360; | 341 rotation = (mCameraOrientation + rotation) % 360; |
322 rotation = (360 - rotation) % 360; | 342 rotation = (360 - rotation) % 360; |
323 flipHorizontal = (rotation == 270 || rotation == 90); | 343 flipHorizontal = (rotation == 270 || rotation == 90); |
324 flipVertical = flipHorizontal; | 344 flipVertical = flipHorizontal; |
325 } else { | 345 } else { |
326 rotation = (mCameraOrientation - rotation + 360) % 360; | 346 rotation = (mCameraOrientation - rotation + 360) % 360; |
327 } | 347 } |
328 if (mImageFormat == ImageFormat.NV21) { | |
329 convertNV21ToYV12(data); | |
330 } | |
331 nativeOnFrameAvailable(mNativeVideoCaptureDeviceAndroid, | 348 nativeOnFrameAvailable(mNativeVideoCaptureDeviceAndroid, |
332 data, mExpectedFrameSize, | 349 data, mExpectedFrameSize, |
333 rotation, flipVertical, flipHorizontal); | 350 rotation, flipVertical, flipHorizontal); |
334 } | 351 } |
335 } finally { | 352 } finally { |
336 mPreviewBufferLock.unlock(); | 353 mPreviewBufferLock.unlock(); |
337 if (camera != null) { | 354 if (camera != null) { |
338 camera.addCallbackBuffer(data); | 355 camera.addCallbackBuffer(data); |
339 } | 356 } |
340 } | 357 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 default: | 427 default: |
411 orientation = 0; | 428 orientation = 0; |
412 break; | 429 break; |
413 } | 430 } |
414 } | 431 } |
415 return orientation; | 432 return orientation; |
416 } | 433 } |
417 | 434 |
418 private void calculateImageFormat(int width, int height) { | 435 private void calculateImageFormat(int width, int height) { |
419 mImageFormat = DeviceImageFormatHack.getImageFormat(); | 436 mImageFormat = DeviceImageFormatHack.getImageFormat(); |
420 if (mImageFormat == ImageFormat.NV21) { | |
421 mColorPlane = new byte[width * height / 4]; | |
422 } | |
423 } | |
424 | |
425 private void convertNV21ToYV12(byte[] data) { | |
426 final int ySize = mCurrentCapability.mWidth * mCurrentCapability.mHeight
; | |
427 final int uvSize = ySize / 4; | |
428 for (int i = 0; i < uvSize; i++) { | |
429 final int index = ySize + i * 2; | |
430 data[ySize + i] = data[index]; | |
431 mColorPlane[i] = data[index + 1]; | |
432 } | |
433 System.arraycopy(mColorPlane, 0, data, ySize + uvSize, uvSize); | |
434 } | 437 } |
435 } | 438 } |
OLD | NEW |