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

Unified Diff: webrtc/api/androidvideotracksource.cc

Issue 2332213011: Reland of Optimize Android NV12 capture (Closed)
Patch Set: Fix dst vs src width/height bug Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/api/androidvideotracksource.h ('k') | webrtc/common_video/libyuv/include/webrtc_libyuv.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/api/androidvideotracksource.cc
diff --git a/webrtc/api/androidvideotracksource.cc b/webrtc/api/androidvideotracksource.cc
index 7fd033efec55ba63c1b592d7aa17b60167c7c36c..f0bd26a510e647d0156193f8e59e91ccbdf44f78 100644
--- a/webrtc/api/androidvideotracksource.cc
+++ b/webrtc/api/androidvideotracksource.cc
@@ -12,6 +12,8 @@
#include <utility>
+#include "third_party/libyuv/include/libyuv/rotate.h"
+
namespace webrtc {
AndroidVideoTrackSource::AndroidVideoTrackSource(rtc::Thread* signaling_thread,
@@ -106,42 +108,51 @@ void AndroidVideoTrackSource::OnByteBufferFrameCaptured(const void* frame_data,
return;
}
- int rotated_width = crop_width;
- int rotated_height = crop_height;
-
- rtc::CritScope lock(&apply_rotation_crit_);
- if (apply_rotation_ && (rotation == 90 || rotation == 270)) {
- std::swap(adapted_width, adapted_height);
- std::swap(rotated_width, rotated_height);
- }
-
- rtc::scoped_refptr<webrtc::I420Buffer> buffer =
- pre_scale_pool_.CreateBuffer(rotated_width, rotated_height);
-
const uint8_t* y_plane = static_cast<const uint8_t*>(frame_data);
const uint8_t* uv_plane = y_plane + width * height;
- int uv_width = (width + 1) / 2;
+ const int uv_width = (width + 1) / 2;
RTC_CHECK_GE(length, width * height + 2 * uv_width * ((height + 1) / 2));
// Can only crop at even pixels.
crop_x &= ~1;
crop_y &= ~1;
+ // Crop just by modifying pointers.
+ y_plane += width * crop_y + crop_x;
+ uv_plane += uv_width * crop_y + crop_x;
+
+ rtc::scoped_refptr<webrtc::I420Buffer> buffer =
+ buffer_pool_.CreateBuffer(adapted_width, adapted_height);
- libyuv::NV12ToI420Rotate(
- y_plane + width * crop_y + crop_x, width,
- uv_plane + uv_width * crop_y + crop_x, width, buffer->MutableDataY(),
- buffer->StrideY(),
+ nv12toi420_scaler_.NV12ToI420Scale(
+ y_plane, width,
+ uv_plane, uv_width * 2,
+ crop_width, crop_height,
+ buffer->MutableDataY(), buffer->StrideY(),
// Swap U and V, since we have NV21, not NV12.
- buffer->MutableDataV(), buffer->StrideV(), buffer->MutableDataU(),
- buffer->StrideU(), crop_width, crop_height,
- static_cast<libyuv::RotationMode>(apply_rotation_ ? rotation : 0));
-
- if (adapted_width != buffer->width() || adapted_height != buffer->height()) {
- rtc::scoped_refptr<webrtc::I420Buffer> scaled_buffer(
- post_scale_pool_.CreateBuffer(adapted_width, adapted_height));
- scaled_buffer->ScaleFrom(buffer);
- buffer = scaled_buffer;
+ buffer->MutableDataV(), buffer->StrideV(),
+ buffer->MutableDataU(), buffer->StrideU(),
+ buffer->width(), buffer->height());
+
+ // Applying rotation is only supported for legacy reasons, and the performance
+ // for this path is not critical.
+ rtc::CritScope lock(&apply_rotation_crit_);
+ if (apply_rotation_ && rotation != 0) {
+ rtc::scoped_refptr<I420Buffer> rotated_buffer =
+ rotation == 180 ? I420Buffer::Create(buffer->width(), buffer->height())
+ : I420Buffer::Create(buffer->height(), buffer->width());
+
+ libyuv::I420Rotate(
+ buffer->DataY(), buffer->StrideY(),
+ buffer->DataU(), buffer->StrideU(),
+ buffer->DataV(), buffer->StrideV(),
+ rotated_buffer->MutableDataY(), rotated_buffer->StrideY(),
+ rotated_buffer->MutableDataU(), rotated_buffer->StrideU(),
+ rotated_buffer->MutableDataV(), rotated_buffer->StrideV(),
+ buffer->width(), buffer->height(),
+ static_cast<libyuv::RotationMode>(rotation));
+
+ buffer = rotated_buffer;
}
OnFrame(cricket::WebRtcVideoFrame(
« no previous file with comments | « webrtc/api/androidvideotracksource.h ('k') | webrtc/common_video/libyuv/include/webrtc_libyuv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698