2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-16 18:18:21 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-07-12 10:03:52 +00:00
|
|
|
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-04-23 21:24:02 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2016-03-21 16:44:31 +01:00
|
|
|
#include "webrtc/base/refcount.h"
|
2016-05-10 16:31:47 +02:00
|
|
|
#include "webrtc/base/timeutils.h"
|
2015-10-20 23:00:48 -07:00
|
|
|
#include "webrtc/base/trace_event.h"
|
2013-07-12 10:03:52 +00:00
|
|
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2013-07-12 10:03:52 +00:00
|
|
|
#include "webrtc/modules/video_capture/video_capture_config.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/logging.h"
|
2013-07-12 10:03:52 +00:00
|
|
|
|
2016-03-21 16:44:31 +01:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace videocapturemodule {
|
|
|
|
|
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
|
2013-04-10 08:23:13 +00:00
|
|
|
const int32_t id,
|
2016-03-21 16:44:31 +01:00
|
|
|
VideoCaptureExternal*& externalCapture) {
|
|
|
|
|
rtc::scoped_refptr<VideoCaptureImpl> implementation(
|
|
|
|
|
new rtc::RefCountedObject<VideoCaptureImpl>(id));
|
|
|
|
|
externalCapture = implementation.get();
|
|
|
|
|
return implementation;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-01 16:30:40 +00:00
|
|
|
const char* VideoCaptureImpl::CurrentDeviceName() const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return _deviceUniqueId;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 18:23:13 +00:00
|
|
|
// static
|
|
|
|
|
int32_t VideoCaptureImpl::RotationFromDegrees(int degrees,
|
2015-02-13 14:31:26 +00:00
|
|
|
VideoRotation* rotation) {
|
2013-10-03 18:23:13 +00:00
|
|
|
switch (degrees) {
|
|
|
|
|
case 0:
|
2015-02-13 14:31:26 +00:00
|
|
|
*rotation = kVideoRotation_0;
|
2013-10-03 18:23:13 +00:00
|
|
|
return 0;
|
|
|
|
|
case 90:
|
2015-02-13 14:31:26 +00:00
|
|
|
*rotation = kVideoRotation_90;
|
2013-10-03 18:23:13 +00:00
|
|
|
return 0;
|
|
|
|
|
case 180:
|
2015-02-13 14:31:26 +00:00
|
|
|
*rotation = kVideoRotation_180;
|
2013-10-03 18:23:13 +00:00
|
|
|
return 0;
|
|
|
|
|
case 270:
|
2015-02-13 14:31:26 +00:00
|
|
|
*rotation = kVideoRotation_270;
|
2013-10-03 18:23:13 +00:00
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
return -1;;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
2015-02-13 14:31:26 +00:00
|
|
|
int32_t VideoCaptureImpl::RotationInDegrees(VideoRotation rotation,
|
2013-10-03 18:23:13 +00:00
|
|
|
int* degrees) {
|
|
|
|
|
switch (rotation) {
|
2015-02-13 14:31:26 +00:00
|
|
|
case kVideoRotation_0:
|
2013-10-03 18:23:13 +00:00
|
|
|
*degrees = 0;
|
|
|
|
|
return 0;
|
2015-02-13 14:31:26 +00:00
|
|
|
case kVideoRotation_90:
|
2013-10-03 18:23:13 +00:00
|
|
|
*degrees = 90;
|
|
|
|
|
return 0;
|
2015-02-13 14:31:26 +00:00
|
|
|
case kVideoRotation_180:
|
2013-10-03 18:23:13 +00:00
|
|
|
*degrees = 180;
|
|
|
|
|
return 0;
|
2015-02-13 14:31:26 +00:00
|
|
|
case kVideoRotation_270:
|
2013-10-03 18:23:13 +00:00
|
|
|
*degrees = 270;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// returns the number of milliseconds until the module want a worker thread to call Process
|
2014-12-15 22:09:40 +00:00
|
|
|
int64_t VideoCaptureImpl::TimeUntilNextProcess()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-08-08 14:01:09 +00:00
|
|
|
CriticalSectionScoped cs(&_callBackCs);
|
2014-12-15 22:09:40 +00:00
|
|
|
const int64_t kProcessIntervalMs = 300;
|
|
|
|
|
return kProcessIntervalMs -
|
2016-05-10 16:31:47 +02:00
|
|
|
(rtc::TimeNanos() - _lastProcessTimeNanos) /
|
|
|
|
|
rtc::kNumNanosecsPerMillisec;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process any pending tasks such as timeouts
|
2016-02-25 04:50:01 -08:00
|
|
|
void VideoCaptureImpl::Process()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-05-10 16:31:47 +02:00
|
|
|
const int64_t now_ns = rtc::TimeNanos();
|
|
|
|
|
_lastProcessTimeNanos = rtc::TimeNanos();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Handle No picture alarm
|
|
|
|
|
|
2016-05-10 16:31:47 +02:00
|
|
|
if (_lastProcessFrameTimeNanos == _incomingFrameTimesNanos[0] &&
|
2011-07-07 08:21:25 +00:00
|
|
|
_captureAlarm != Raised)
|
|
|
|
|
{
|
|
|
|
|
if (_noPictureAlarmCallBack && _captureCallBack)
|
|
|
|
|
{
|
|
|
|
|
_captureAlarm = Raised;
|
|
|
|
|
_captureCallBack->OnNoPictureAlarm(_id, _captureAlarm);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-10 16:31:47 +02:00
|
|
|
else if (_lastProcessFrameTimeNanos != _incomingFrameTimesNanos[0] &&
|
2011-07-07 08:21:25 +00:00
|
|
|
_captureAlarm != Cleared)
|
|
|
|
|
{
|
|
|
|
|
if (_noPictureAlarmCallBack && _captureCallBack)
|
|
|
|
|
{
|
|
|
|
|
_captureAlarm = Cleared;
|
|
|
|
|
_captureCallBack->OnNoPictureAlarm(_id, _captureAlarm);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle frame rate callback
|
2016-05-10 16:31:47 +02:00
|
|
|
if ((now_ns - _lastFrameRateCallbackTimeNanos) /
|
|
|
|
|
rtc::kNumNanosecsPerMillisec
|
2011-07-07 08:21:25 +00:00
|
|
|
> kFrameRateCallbackInterval)
|
|
|
|
|
{
|
|
|
|
|
if (_frameRateCallBack && _captureCallBack)
|
|
|
|
|
{
|
2016-05-10 16:31:47 +02:00
|
|
|
const uint32_t frameRate = CalculateFrameRate(now_ns);
|
2011-07-07 08:21:25 +00:00
|
|
|
_captureCallBack->OnCaptureFrameRate(_id, frameRate);
|
|
|
|
|
}
|
2016-05-10 16:31:47 +02:00
|
|
|
// Can be set by EnableFrameRateCallback
|
|
|
|
|
_lastFrameRateCallbackTimeNanos = now_ns;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-10 16:31:47 +02:00
|
|
|
_lastProcessFrameTimeNanos = _incomingFrameTimesNanos[0];
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-10 08:23:13 +00:00
|
|
|
VideoCaptureImpl::VideoCaptureImpl(const int32_t id)
|
2013-07-02 10:15:43 +00:00
|
|
|
: _id(id),
|
|
|
|
|
_deviceUniqueId(NULL),
|
|
|
|
|
_apiCs(*CriticalSectionWrapper::CreateCriticalSection()),
|
|
|
|
|
_captureDelay(0),
|
|
|
|
|
_requestedCapability(),
|
2011-07-07 08:21:25 +00:00
|
|
|
_callBackCs(*CriticalSectionWrapper::CreateCriticalSection()),
|
2016-05-10 16:31:47 +02:00
|
|
|
_lastProcessTimeNanos(rtc::TimeNanos()),
|
|
|
|
|
_lastFrameRateCallbackTimeNanos(rtc::TimeNanos()),
|
2013-07-02 10:15:43 +00:00
|
|
|
_frameRateCallBack(false),
|
|
|
|
|
_noPictureAlarmCallBack(false),
|
|
|
|
|
_captureAlarm(Cleared),
|
|
|
|
|
_setCaptureDelay(0),
|
|
|
|
|
_dataCallBack(NULL),
|
|
|
|
|
_captureCallBack(NULL),
|
2016-05-10 16:31:47 +02:00
|
|
|
_lastProcessFrameTimeNanos(rtc::TimeNanos()),
|
2015-03-09 17:07:31 +00:00
|
|
|
_rotateFrame(kVideoRotation_0),
|
2016-03-18 11:38:26 -07:00
|
|
|
apply_rotation_(false) {
|
2011-07-07 08:21:25 +00:00
|
|
|
_requestedCapability.width = kDefaultWidth;
|
|
|
|
|
_requestedCapability.height = kDefaultHeight;
|
|
|
|
|
_requestedCapability.maxFPS = 30;
|
|
|
|
|
_requestedCapability.rawType = kVideoI420;
|
|
|
|
|
_requestedCapability.codecType = kVideoCodecUnknown;
|
2016-05-10 16:31:47 +02:00
|
|
|
memset(_incomingFrameTimesNanos, 0, sizeof(_incomingFrameTimesNanos));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoCaptureImpl::~VideoCaptureImpl()
|
|
|
|
|
{
|
|
|
|
|
DeRegisterCaptureDataCallback();
|
|
|
|
|
DeRegisterCaptureCallback();
|
|
|
|
|
delete &_callBackCs;
|
|
|
|
|
delete &_apiCs;
|
|
|
|
|
|
|
|
|
|
if (_deviceUniqueId)
|
|
|
|
|
delete[] _deviceUniqueId;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 00:56:02 +00:00
|
|
|
void VideoCaptureImpl::RegisterCaptureDataCallback(
|
|
|
|
|
VideoCaptureDataCallback& dataCallBack) {
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
_dataCallBack = &dataCallBack;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 00:56:02 +00:00
|
|
|
void VideoCaptureImpl::DeRegisterCaptureDataCallback() {
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
_dataCallBack = NULL;
|
|
|
|
|
}
|
2014-01-29 00:56:02 +00:00
|
|
|
void VideoCaptureImpl::RegisterCaptureCallback(VideoCaptureFeedBack& callBack) {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
_captureCallBack = &callBack;
|
|
|
|
|
}
|
2014-01-29 00:56:02 +00:00
|
|
|
void VideoCaptureImpl::DeRegisterCaptureCallback() {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
_captureCallBack = NULL;
|
|
|
|
|
}
|
2014-01-29 00:56:02 +00:00
|
|
|
void VideoCaptureImpl::SetCaptureDelay(int32_t delayMS) {
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
_captureDelay = delayMS;
|
|
|
|
|
}
|
2013-04-10 08:23:13 +00:00
|
|
|
int32_t VideoCaptureImpl::CaptureDelay()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
return _setCaptureDelay;
|
|
|
|
|
}
|
2011-10-14 17:16:04 +00:00
|
|
|
|
2015-05-29 17:21:40 -07:00
|
|
|
int32_t VideoCaptureImpl::DeliverCapturedFrame(VideoFrame& captureFrame) {
|
2012-10-11 15:03:53 +00:00
|
|
|
UpdateFrameCount(); // frame count used for local frame rate callback.
|
|
|
|
|
|
|
|
|
|
const bool callOnCaptureDelayChanged = _setCaptureDelay != _captureDelay;
|
|
|
|
|
// Capture delay changed
|
|
|
|
|
if (_setCaptureDelay != _captureDelay) {
|
|
|
|
|
_setCaptureDelay = _captureDelay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_dataCallBack) {
|
|
|
|
|
if (callOnCaptureDelayChanged) {
|
|
|
|
|
_dataCallBack->OnCaptureDelayChanged(_id, _captureDelay);
|
|
|
|
|
}
|
2012-10-29 15:59:40 +00:00
|
|
|
_dataCallBack->OnIncomingCapturedFrame(_id, captureFrame);
|
2012-10-11 15:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-10 08:23:13 +00:00
|
|
|
int32_t VideoCaptureImpl::IncomingFrame(
|
|
|
|
|
uint8_t* videoFrame,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t videoFrameLength,
|
2012-02-23 09:00:26 +00:00
|
|
|
const VideoCaptureCapability& frameInfo,
|
2013-04-10 08:23:13 +00:00
|
|
|
int64_t captureTime/*=0*/)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2014-06-06 18:28:28 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-10 08:23:13 +00:00
|
|
|
const int32_t width = frameInfo.width;
|
|
|
|
|
const int32_t height = frameInfo.height;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 19:54:10 +00:00
|
|
|
TRACE_EVENT1("webrtc", "VC::IncomingFrame", "capture_time", captureTime);
|
|
|
|
|
|
2012-02-23 09:00:26 +00:00
|
|
|
if (frameInfo.codecType == kVideoCodecUnknown)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-02-23 09:00:26 +00:00
|
|
|
// Not encoded, convert to I420.
|
2011-12-27 23:45:30 +00:00
|
|
|
const VideoType commonVideoType =
|
2012-02-23 09:00:26 +00:00
|
|
|
RawVideoTypeToCommonVideoVideoType(frameInfo.rawType);
|
|
|
|
|
|
|
|
|
|
if (frameInfo.rawType != kVideoMJPEG &&
|
2012-04-23 21:24:02 +00:00
|
|
|
CalcBufferSize(commonVideoType, width,
|
|
|
|
|
abs(height)) != videoFrameLength)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2014-05-14 08:42:07 +00:00
|
|
|
LOG(LS_ERROR) << "Wrong incoming frame length.";
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-21 22:18:32 +00:00
|
|
|
int stride_y = width;
|
|
|
|
|
int stride_uv = (width + 1) / 2;
|
2012-11-19 21:15:35 +00:00
|
|
|
int target_width = width;
|
|
|
|
|
int target_height = height;
|
2015-02-11 18:37:54 +00:00
|
|
|
|
2015-04-01 15:33:06 -07:00
|
|
|
// SetApplyRotation doesn't take any lock. Make a local copy here.
|
|
|
|
|
bool apply_rotation = apply_rotation_;
|
|
|
|
|
|
|
|
|
|
if (apply_rotation) {
|
2015-02-11 18:37:54 +00:00
|
|
|
// Rotating resolution when for 90/270 degree rotations.
|
2015-03-09 17:07:31 +00:00
|
|
|
if (_rotateFrame == kVideoRotation_90 ||
|
|
|
|
|
_rotateFrame == kVideoRotation_270) {
|
2015-02-11 18:37:54 +00:00
|
|
|
target_width = abs(height);
|
|
|
|
|
target_height = width;
|
|
|
|
|
}
|
2012-11-19 21:15:35 +00:00
|
|
|
}
|
2015-02-11 18:37:54 +00:00
|
|
|
|
2012-10-24 18:33:04 +00:00
|
|
|
// Setting absolute height (in case it was negative).
|
|
|
|
|
// In Windows, the image starts bottom left, instead of top left.
|
|
|
|
|
// Setting a negative source height, inverts the image (within LibYuv).
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
|
|
|
|
|
// TODO(nisse): Use a pool?
|
|
|
|
|
rtc::scoped_refptr<I420Buffer> buffer = I420Buffer::Create(
|
|
|
|
|
target_width, abs(target_height), stride_y, stride_uv, stride_uv);
|
2015-02-11 18:37:54 +00:00
|
|
|
const int conversionResult = ConvertToI420(
|
|
|
|
|
commonVideoType, videoFrame, 0, 0, // No cropping
|
|
|
|
|
width, height, videoFrameLength,
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
apply_rotation ? _rotateFrame : kVideoRotation_0, buffer.get());
|
2011-12-09 02:46:22 +00:00
|
|
|
if (conversionResult < 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2014-05-14 08:42:07 +00:00
|
|
|
LOG(LS_ERROR) << "Failed to convert capture frame from type "
|
|
|
|
|
<< frameInfo.rawType << "to I420.";
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2015-02-11 18:37:54 +00:00
|
|
|
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
VideoFrame captureFrame(
|
|
|
|
|
buffer, 0, rtc::TimeMillis(),
|
|
|
|
|
!apply_rotation ? _rotateFrame : kVideoRotation_0);
|
|
|
|
|
captureFrame.set_ntp_time_ms(captureTime);
|
2015-02-11 18:37:54 +00:00
|
|
|
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
DeliverCapturedFrame(captureFrame);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
else // Encoded format
|
|
|
|
|
{
|
2013-06-07 13:57:57 +00:00
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2011-10-14 17:16:04 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-02-13 14:31:26 +00:00
|
|
|
int32_t VideoCaptureImpl::SetCaptureRotation(VideoRotation rotation) {
|
2012-11-19 21:15:35 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2015-03-09 17:07:31 +00:00
|
|
|
_rotateFrame = rotation;
|
2012-11-19 21:15:35 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-29 00:56:02 +00:00
|
|
|
void VideoCaptureImpl::EnableFrameRateCallback(const bool enable) {
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
_frameRateCallBack = enable;
|
|
|
|
|
if (enable)
|
|
|
|
|
{
|
2016-05-10 16:31:47 +02:00
|
|
|
_lastFrameRateCallbackTimeNanos = rtc::TimeNanos();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 18:37:54 +00:00
|
|
|
bool VideoCaptureImpl::SetApplyRotation(bool enable) {
|
2015-04-01 15:33:06 -07:00
|
|
|
// We can't take any lock here as it'll cause deadlock with IncomingFrame.
|
|
|
|
|
|
2015-02-11 18:37:54 +00:00
|
|
|
// The effect of this is the last caller wins.
|
|
|
|
|
apply_rotation_ = enable;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 00:56:02 +00:00
|
|
|
void VideoCaptureImpl::EnableNoPictureAlarm(const bool enable) {
|
2012-03-08 08:09:17 +00:00
|
|
|
CriticalSectionScoped cs(&_apiCs);
|
|
|
|
|
CriticalSectionScoped cs2(&_callBackCs);
|
2011-07-07 08:21:25 +00:00
|
|
|
_noPictureAlarmCallBack = enable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoCaptureImpl::UpdateFrameCount()
|
|
|
|
|
{
|
2016-05-10 16:31:47 +02:00
|
|
|
if (_incomingFrameTimesNanos[0] / rtc::kNumNanosecsPerMicrosec == 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
// first no shift
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// shift
|
|
|
|
|
for (int i = (kFrameRateCountHistorySize - 2); i >= 0; i--)
|
|
|
|
|
{
|
2016-05-10 16:31:47 +02:00
|
|
|
_incomingFrameTimesNanos[i + 1] = _incomingFrameTimesNanos[i];
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-05-10 16:31:47 +02:00
|
|
|
_incomingFrameTimesNanos[0] = rtc::TimeNanos();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-10 16:31:47 +02:00
|
|
|
uint32_t VideoCaptureImpl::CalculateFrameRate(int64_t now_ns)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2013-04-10 08:23:13 +00:00
|
|
|
int32_t num = 0;
|
|
|
|
|
int32_t nrOfFrames = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
for (num = 1; num < (kFrameRateCountHistorySize - 1); num++)
|
|
|
|
|
{
|
2016-05-10 16:31:47 +02:00
|
|
|
if (_incomingFrameTimesNanos[num] <= 0 ||
|
|
|
|
|
(now_ns - _incomingFrameTimesNanos[num]) /
|
|
|
|
|
rtc::kNumNanosecsPerMillisec >
|
|
|
|
|
kFrameRateHistoryWindowMs) // don't use data older than 2sec
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nrOfFrames++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (num > 1)
|
|
|
|
|
{
|
2016-05-10 16:31:47 +02:00
|
|
|
int64_t diff = (now_ns - _incomingFrameTimesNanos[num - 1]) /
|
|
|
|
|
rtc::kNumNanosecsPerMillisec;
|
2011-07-07 08:21:25 +00:00
|
|
|
if (diff > 0)
|
|
|
|
|
{
|
2013-04-10 08:23:13 +00:00
|
|
|
return uint32_t((nrOfFrames * 1000.0f / diff) + 0.5f);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nrOfFrames;
|
|
|
|
|
}
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace videocapturemodule
|
|
|
|
|
} // namespace webrtc
|