OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 public static class CaptureFormat { | 65 public static class CaptureFormat { |
66 public final int width; | 66 public final int width; |
67 public final int height; | 67 public final int height; |
68 public final int maxFramerate; | 68 public final int maxFramerate; |
69 public final int minFramerate; | 69 public final int minFramerate; |
70 // TODO(hbos): If VideoCapturerAndroid.startCapture is updated to support | 70 // TODO(hbos): If VideoCapturerAndroid.startCapture is updated to support |
71 // other image formats then this needs to be updated and | 71 // other image formats then this needs to be updated and |
72 // VideoCapturerAndroid.getSupportedFormats need to return CaptureFormats of | 72 // VideoCapturerAndroid.getSupportedFormats need to return CaptureFormats of |
73 // all imageFormats. | 73 // all imageFormats. |
74 public final int imageFormat = ImageFormat.YV12; | 74 public final int imageFormat = ImageFormat.NV21; |
75 | 75 |
76 public CaptureFormat(int width, int height, int minFramerate, | 76 public CaptureFormat(int width, int height, int minFramerate, |
77 int maxFramerate) { | 77 int maxFramerate) { |
78 this.width = width; | 78 this.width = width; |
79 this.height = height; | 79 this.height = height; |
80 this.minFramerate = minFramerate; | 80 this.minFramerate = minFramerate; |
81 this.maxFramerate = maxFramerate; | 81 this.maxFramerate = maxFramerate; |
82 } | 82 } |
83 | 83 |
84 // Calculates the frame size of this capture format. | 84 // Calculates the frame size of this capture format. |
85 public int frameSize() { | 85 public int frameSize() { |
86 return frameSize(width, height, imageFormat); | 86 return frameSize(width, height, imageFormat); |
87 } | 87 } |
88 | 88 |
89 // Calculates the frame size of the specified image format. Currently only | 89 // Calculates the frame size of the specified image format. Currently only |
90 // supporting ImageFormat.YV12. The YV12's stride is the closest rounded up | 90 // supporting ImageFormat.NV21. |
91 // multiple of 16 of the width and width and height are always even. | 91 // The size is width * height * number of bytes per pixel. |
92 // Android guarantees this: | 92 // http://developer.android.com/reference/android/hardware/Camera.html#addCa
llbackBuffer(byte[]) |
93 // http://developer.android.com/reference/android/hardware/Camera.Parameters
.html#setPreviewFormat%28int%29 | |
94 public static int frameSize(int width, int height, int imageFormat) { | 93 public static int frameSize(int width, int height, int imageFormat) { |
95 if (imageFormat != ImageFormat.YV12) { | 94 if (imageFormat != ImageFormat.NV21) { |
96 throw new UnsupportedOperationException("Don't know how to calculate " | 95 throw new UnsupportedOperationException("Don't know how to calculate " |
97 + "the frame size of non-YV12 image formats."); | 96 + "the frame size of non-NV21 image formats."); |
98 } | 97 } |
99 int yStride = roundUp(width, 16); | 98 return (width * height * ImageFormat.getBitsPerPixel(imageFormat)) / 8; |
100 int uvStride = roundUp(yStride / 2, 16); | |
101 int ySize = yStride * height; | |
102 int uvSize = uvStride * height / 2; | |
103 return ySize + uvSize * 2; | |
104 } | |
105 | |
106 // Rounds up |x| to the closest value that is a multiple of |alignment|. | |
107 private static int roundUp(int x, int alignment) { | |
108 return (int)ceil(x / (double)alignment) * alignment; | |
109 } | 99 } |
110 | 100 |
111 @Override | 101 @Override |
112 public String toString() { | 102 public String toString() { |
113 return width + "x" + height + "@[" + minFramerate + ":" + maxFramerate + "
]"; | 103 return width + "x" + height + "@[" + minFramerate + ":" + maxFramerate + "
]"; |
114 } | 104 } |
115 | 105 |
116 public boolean isSameFormat(final CaptureFormat that) { | 106 public boolean isSameFormat(final CaptureFormat that) { |
117 if (that == null) { | 107 if (that == null) { |
118 return false; | 108 return false; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (info.facing == facing) { | 218 if (info.facing == facing) { |
229 return getDeviceName(i); | 219 return getDeviceName(i); |
230 } | 220 } |
231 } catch (Exception e) { | 221 } catch (Exception e) { |
232 Logging.e(TAG, "getCameraInfo() failed on index " + i, e); | 222 Logging.e(TAG, "getCameraInfo() failed on index " + i, e); |
233 } | 223 } |
234 } | 224 } |
235 return null; | 225 return null; |
236 } | 226 } |
237 } | 227 } |
OLD | NEW |