Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: talk/app/webrtc/java/jni/androidvideocapturer_jni.cc

Issue 1377783002: Revert of Android VideoCapturer: Send ByteBuffer instead of byte[] (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/app/webrtc/java/jni/androidvideocapturer_jni.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return JavaToStdString(jni(), j_json_caps); 169 return JavaToStdString(jni(), j_json_caps);
170 } 170 }
171 171
172 void AndroidVideoCapturerJni::OnCapturerStarted(bool success) { 172 void AndroidVideoCapturerJni::OnCapturerStarted(bool success) {
173 LOG(LS_INFO) << "AndroidVideoCapturerJni capture started: " << success; 173 LOG(LS_INFO) << "AndroidVideoCapturerJni capture started: " << success;
174 AsyncCapturerInvoke("OnCapturerStarted", 174 AsyncCapturerInvoke("OnCapturerStarted",
175 &webrtc::AndroidVideoCapturer::OnCapturerStarted, 175 &webrtc::AndroidVideoCapturer::OnCapturerStarted,
176 success); 176 success);
177 } 177 }
178 178
179 void AndroidVideoCapturerJni::OnIncomingFrame(const uint8_t* video_frame, 179 void AndroidVideoCapturerJni::OnIncomingFrame(void* video_frame,
180 int length, 180 int length,
181 int width, 181 int width,
182 int height, 182 int height,
183 int rotation, 183 int rotation,
184 int64 time_stamp) { 184 int64 time_stamp) {
185 const uint8_t* y_plane = video_frame; 185 const uint8_t* y_plane = static_cast<uint8_t*>(video_frame);
186 // Android guarantees that the stride is a multiple of 16. 186 // Android guarantees that the stride is a multiple of 16.
187 // http://developer.android.com/reference/android/hardware/Camera.Parameters.h tml#setPreviewFormat%28int%29 187 // http://developer.android.com/reference/android/hardware/Camera.Parameters.h tml#setPreviewFormat%28int%29
188 int y_stride; 188 int y_stride;
189 int uv_stride; 189 int uv_stride;
190 webrtc::Calc16ByteAlignedStride(width, &y_stride, &uv_stride); 190 webrtc::Calc16ByteAlignedStride(width, &y_stride, &uv_stride);
191 const uint8_t* v_plane = y_plane + y_stride * height; 191 const uint8_t* v_plane = y_plane + y_stride * height;
192 const uint8_t* u_plane = 192 const uint8_t* u_plane =
193 v_plane + uv_stride * webrtc::AlignInt(height, 2) / 2; 193 v_plane + uv_stride * webrtc::AlignInt(height, 2) / 2;
194 194
195 // Wrap the Java buffer, and call ReturnBuffer() in the wrapped 195 // Wrap the Java buffer, and call ReturnBuffer() in the wrapped
(...skipping 12 matching lines...) Expand all
208 int height, 208 int height,
209 int fps) { 209 int fps) {
210 AsyncCapturerInvoke("OnOutputFormatRequest", 210 AsyncCapturerInvoke("OnOutputFormatRequest",
211 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, 211 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest,
212 width, height, fps); 212 width, height, fps);
213 } 213 }
214 214
215 JNIEnv* AndroidVideoCapturerJni::jni() { return AttachCurrentThreadIfNeeded(); } 215 JNIEnv* AndroidVideoCapturerJni::jni() { return AttachCurrentThreadIfNeeded(); }
216 216
217 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnFrameCaptured) 217 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnFrameCaptured)
218 (JNIEnv* jni, jclass, jlong j_capturer, jobject j_byte_buffer, 218 (JNIEnv* jni, jclass, jlong j_capturer, jbyteArray j_frame, jint length,
219 jint width, jint height, jint rotation, jlong ts) { 219 jint width, jint height, jint rotation, jlong ts) {
220 const uint8_t* bytes = 220 jboolean is_copy = true;
221 static_cast<uint8_t*>(jni->GetDirectBufferAddress(j_byte_buffer)); 221 jbyte* bytes = jni->GetByteArrayElements(j_frame, &is_copy);
222 const int length = jni->GetDirectBufferCapacity(j_byte_buffer); 222 // If this is a copy of the original frame, it means that the memory
223 RTC_CHECK(bytes != nullptr && length != -1) << "ByteBuffer is not direct"; 223 // is not direct memory and thus VideoCapturerAndroid does not guarantee
224 // that the memory is valid when we have released |j_frame|.
225 // TODO(magjed): Move ReleaseByteArrayElements() into ReturnBuffer() and
226 // remove this check.
227 RTC_CHECK(!is_copy)
228 << "NativeObserver_nativeOnFrameCaptured: frame is a copy";
224 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) 229 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)
225 ->OnIncomingFrame(bytes, length, width, height, rotation, ts); 230 ->OnIncomingFrame(bytes, length, width, height, rotation, ts);
231 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT);
226 } 232 }
227 233
228 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted) 234 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted)
229 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) { 235 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) {
230 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted"; 236 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted";
231 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted( 237 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted(
232 j_success); 238 j_success);
233 } 239 }
234 240
235 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest) 241 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest)
236 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, 242 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height,
237 jint j_fps) { 243 jint j_fps) {
238 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; 244 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest";
239 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( 245 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest(
240 j_width, j_height, j_fps); 246 j_width, j_height, j_fps);
241 } 247 }
242 248
243 } // namespace webrtc_jni 249 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « talk/app/webrtc/java/jni/androidvideocapturer_jni.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698