From 2ad3bb17a7e0e83ae802ef62933325bce8041966 Mon Sep 17 00:00:00 2001 From: "perkj@webrtc.org" Date: Mon, 23 Feb 2015 11:14:57 +0000 Subject: [PATCH] Reland patch for Switch default color format to YV12 on Android. The new since the previous patch is that we ignore all resolutions with width % 16 != 0 since they are not tightly packed. http://developer.android.com/reference/android/graphics/ImageFormat.html#YV12 R=glaznev@webrtc.org Review URL: https://webrtc-codereview.appspot.com/36269004 Cr-Commit-Position: refs/heads/master@{#8459} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8459 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/app/webrtc/androidvideocapturer.cc | 6 +++--- .../java/src/org/webrtc/VideoCapturerAndroid.java | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/talk/app/webrtc/androidvideocapturer.cc b/talk/app/webrtc/androidvideocapturer.cc index 02f77dbb8..d1238b362 100644 --- a/talk/app/webrtc/androidvideocapturer.cc +++ b/talk/app/webrtc/androidvideocapturer.cc @@ -62,7 +62,7 @@ class AndroidVideoCapturer::FrameFactory : public cricket::VideoFrameFactory { int length, int rotation, int64 time_stamp_in_ms) { - captured_frame_.fourcc = static_cast(cricket::FOURCC_NV21); + captured_frame_.fourcc = static_cast(cricket::FOURCC_YV12); captured_frame_.data = frame_data; captured_frame_.elapsed_time = rtc::TimeNanos() - start_time_; captured_frame_.time_stamp = @@ -119,7 +119,7 @@ AndroidVideoCapturer::AndroidVideoCapturer( json_value["width"].asInt(), json_value["height"].asInt(), cricket::VideoFormat::FpsToInterval(json_value["framerate"].asInt()), - cricket::FOURCC_NV21); + cricket::FOURCC_YV12); formats.push_back(format); } SetSupportedFormats(formats); @@ -168,7 +168,7 @@ bool AndroidVideoCapturer::IsRunning() { } bool AndroidVideoCapturer::GetPreferredFourccs(std::vector* fourccs) { - fourccs->push_back(cricket::FOURCC_NV21); + fourccs->push_back(cricket::FOURCC_YV12); return true; } diff --git a/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java b/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java index c68e27008..446535485 100644 --- a/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java +++ b/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java @@ -287,6 +287,13 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba List supportedSizes = parameters.getSupportedPreviewSizes(); for (Camera.Size size : supportedSizes) { + if (size.width % 16 != 0) { + // If the width is not a multiple of 16, The frames received from the + // camera will have a stride != width when YV12 is used. Since we + // currently only support tightly packed images, we simply ignore those + // resolutions. + continue; + } formatList.add(new CaptureFormat(size.width, size.height, range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX])); @@ -324,6 +331,9 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba if (frameObserver == null) { throw new RuntimeException("frameObserver not set."); } + if (width % 16 != 0) { + throw new RuntimeException("widht must be a multiple of 16." ); + } this.width = width; this.height = height; this.framerate = framerate; @@ -398,7 +408,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba } parameters.setPictureSize(width, height); parameters.setPreviewSize(width, height); - int format = ImageFormat.NV21; + int format = ImageFormat.YV12; parameters.setPreviewFormat(format); camera.setParameters(parameters); // Note: setRecordingHint(true) actually decrease frame rate on N5.