aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/video_capture/video_capture_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webrtc/modules/video_capture/video_capture_impl.cc')
-rw-r--r--webrtc/modules/video_capture/video_capture_impl.cc59
1 files changed, 47 insertions, 12 deletions
diff --git a/webrtc/modules/video_capture/video_capture_impl.cc b/webrtc/modules/video_capture/video_capture_impl.cc
index d7a6642044..ec88ecd6ee 100644
--- a/webrtc/modules/video_capture/video_capture_impl.cc
+++ b/webrtc/modules/video_capture/video_capture_impl.cc
@@ -24,6 +24,23 @@
namespace webrtc
{
+
+// Converting the rotation mode from capturemodule's to I420VideoFrame's define.
+VideoRotation ConvertRotation(VideoRotationMode rotation) {
+ switch (rotation) {
+ case kRotateNone:
+ return kVideoRotation_0;
+ case kRotate90:
+ return kVideoRotation_90;
+ case kRotate180:
+ return kVideoRotation_180;
+ case kRotate270:
+ return kVideoRotation_270;
+ }
+ assert(false);
+ return kVideoRotation_0;
+}
+
namespace videocapturemodule
{
VideoCaptureModule* VideoCaptureImpl::Create(
@@ -159,7 +176,8 @@ VideoCaptureImpl::VideoCaptureImpl(const int32_t id)
last_capture_time_(0),
delta_ntp_internal_ms_(
Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() -
- TickTime::MillisecondTimestamp()) {
+ TickTime::MillisecondTimestamp()),
+ apply_rotation_(true) {
_requestedCapability.width = kDefaultWidth;
_requestedCapability.height = kDefaultHeight;
_requestedCapability.maxFPS = 30;
@@ -278,11 +296,15 @@ int32_t VideoCaptureImpl::IncomingFrame(
int stride_uv = (width + 1) / 2;
int target_width = width;
int target_height = height;
- // Rotating resolution when for 90/270 degree rotations.
- if (_rotateFrame == kRotate90 || _rotateFrame == kRotate270) {
- target_width = abs(height);
- target_height = width;
+
+ if (apply_rotation_) {
+ // Rotating resolution when for 90/270 degree rotations.
+ if (_rotateFrame == kRotate90 || _rotateFrame == kRotate270) {
+ target_width = abs(height);
+ target_height = width;
+ }
}
+
// TODO(mikhal): Update correct aligned stride values.
//Calc16ByteAlignedStride(target_width, &stride_y, &stride_uv);
// Setting absolute height (in case it was negative).
@@ -298,19 +320,24 @@ int32_t VideoCaptureImpl::IncomingFrame(
"happen due to bad parameters.";
return -1;
}
- const int conversionResult = ConvertToI420(commonVideoType,
- videoFrame,
- 0, 0, // No cropping
- width, height,
- videoFrameLength,
- _rotateFrame,
- &_captureFrame);
+ const int conversionResult = ConvertToI420(
+ commonVideoType, videoFrame, 0, 0, // No cropping
+ width, height, videoFrameLength,
+ apply_rotation_ ? _rotateFrame : kRotateNone,
+ &_captureFrame);
if (conversionResult < 0)
{
LOG(LS_ERROR) << "Failed to convert capture frame from type "
<< frameInfo.rawType << "to I420.";
return -1;
}
+
+ if (!apply_rotation_) {
+ _captureFrame.set_rotation(ConvertRotation(_rotateFrame));
+ } else {
+ _captureFrame.set_rotation(kVideoRotation_0);
+ }
+
DeliverCapturedFrame(_captureFrame, captureTime);
}
else // Encoded format
@@ -364,6 +391,14 @@ void VideoCaptureImpl::EnableFrameRateCallback(const bool enable) {
}
}
+bool VideoCaptureImpl::SetApplyRotation(bool enable) {
+ CriticalSectionScoped cs(&_apiCs);
+ CriticalSectionScoped cs2(&_callBackCs);
+ // The effect of this is the last caller wins.
+ apply_rotation_ = enable;
+ return true;
+}
+
void VideoCaptureImpl::EnableNoPictureAlarm(const bool enable) {
CriticalSectionScoped cs(&_apiCs);
CriticalSectionScoped cs2(&_callBackCs);