Files
platform-external-webrtc/webrtc/modules/video_capture/video_capture_impl.h
mallinath@webrtc.org 7433a088d2 Revert 5444 "Revert 5421 "Fix deadlock on register/unregister ob..."
We reverted the r5421 to allow us roll webrtc to chrome without any modifications
to libjingle. Since webrtc is rolled with r5444, we can add back the original CL
and changes to libjingle will be upstreamed in the next roll.

TBR=andresp@webrtc.org

> Revert 5421 "Fix deadlock on register/unregister observer while ..."
> 
> Failure to compile on Chromium Internal bots, because of API changes.
> 
> http://chromegw.corp.google.com/i/internal.chromium.webrtc.fyi/builders/Mac/builds/2805/steps/compile/logs/stdio
> 
> You need to follow the steps mentioned in 
> https://docs.google.com/a/google.com/document/d/1aHrmXECnu3-Jovc2-zYI267EaQCYz-IclYyBp9iA9Fc/edit that of a API changer.
> 
> Since I will be rolling the libjingle this week, I can push your changes along with libjingle roll, if you prepare the CLs
> as mentioned in the doc.
> 
> > Fix deadlock on register/unregister observer while there is a an going callback.
> > 
> > BUG=2835
> > R=mallinath@webrtc.org
> > 
> > Review URL: https://webrtc-codereview.appspot.com/7119005
> 
> TBR=andresp@webrtc.org
> 
> Review URL: https://webrtc-codereview.appspot.com/7679004

TBR=mallinath@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/7729005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5453 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-01-29 00:56:02 +00:00

150 lines
5.8 KiB
C++

/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
/*
* video_capture_impl.h
*/
#include "webrtc/common_video/interface/i420_video_frame.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_capture/include/video_capture.h"
#include "webrtc/modules/video_capture/video_capture_config.h"
#include "webrtc/system_wrappers/interface/tick_util.h"
namespace webrtc
{
class CriticalSectionWrapper;
namespace videocapturemodule {
// Class definitions
class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal
{
public:
/*
* Create a video capture module object
*
* id - unique identifier of this video capture module object
* deviceUniqueIdUTF8 - name of the device. Available names can be found by using GetDeviceName
*/
static VideoCaptureModule* Create(const int32_t id,
const char* deviceUniqueIdUTF8);
/*
* Create a video capture module object used for external capture.
*
* id - unique identifier of this video capture module object
* externalCapture - [out] interface to call when a new frame is captured.
*/
static VideoCaptureModule* Create(const int32_t id,
VideoCaptureExternal*& externalCapture);
static DeviceInfo* CreateDeviceInfo(const int32_t id);
// Helpers for converting between (integral) degrees and
// VideoCaptureRotation values. Return 0 on success.
static int32_t RotationFromDegrees(int degrees,
VideoCaptureRotation* rotation);
static int32_t RotationInDegrees(VideoCaptureRotation rotation,
int* degrees);
// Implements Module declared functions.
virtual int32_t ChangeUniqueId(const int32_t id);
//Call backs
virtual void RegisterCaptureDataCallback(
VideoCaptureDataCallback& dataCallback);
virtual void DeRegisterCaptureDataCallback();
virtual void RegisterCaptureCallback(VideoCaptureFeedBack& callBack);
virtual void DeRegisterCaptureCallback();
virtual void SetCaptureDelay(int32_t delayMS);
virtual int32_t CaptureDelay();
virtual int32_t SetCaptureRotation(VideoCaptureRotation rotation);
virtual void EnableFrameRateCallback(const bool enable);
virtual void EnableNoPictureAlarm(const bool enable);
virtual const char* CurrentDeviceName() const;
// Module handling
virtual int32_t TimeUntilNextProcess();
virtual int32_t Process();
// Implement VideoCaptureExternal
// |capture_time| must be specified in the NTP time format in milliseconds.
virtual int32_t IncomingFrame(uint8_t* videoFrame,
int32_t videoFrameLength,
const VideoCaptureCapability& frameInfo,
int64_t captureTime = 0);
virtual int32_t IncomingI420VideoFrame(I420VideoFrame* video_frame,
int64_t captureTime = 0);
// Platform dependent
virtual int32_t StartCapture(const VideoCaptureCapability& capability)
{
_requestedCapability = capability;
return -1;
}
virtual int32_t StopCapture() { return -1; }
virtual bool CaptureStarted() {return false; }
virtual int32_t CaptureSettings(VideoCaptureCapability& /*settings*/)
{ return -1; }
VideoCaptureEncodeInterface* GetEncodeInterface(const VideoCodec& /*codec*/)
{ return NULL; }
protected:
VideoCaptureImpl(const int32_t id);
virtual ~VideoCaptureImpl();
int32_t DeliverCapturedFrame(I420VideoFrame& captureFrame,
int64_t capture_time);
int32_t _id; // Module ID
char* _deviceUniqueId; // current Device unique name;
CriticalSectionWrapper& _apiCs;
int32_t _captureDelay; // Current capture delay. May be changed of platform dependent parts.
VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture.
private:
void UpdateFrameCount();
uint32_t CalculateFrameRate(const TickTime& now);
CriticalSectionWrapper& _callBackCs;
TickTime _lastProcessTime; // last time the module process function was called.
TickTime _lastFrameRateCallbackTime; // last time the frame rate callback function was called.
bool _frameRateCallBack; // true if EnableFrameRateCallback
bool _noPictureAlarmCallBack; //true if EnableNoPictureAlarm
VideoCaptureAlarm _captureAlarm; // current value of the noPictureAlarm
int32_t _setCaptureDelay; // The currently used capture delay
VideoCaptureDataCallback* _dataCallBack;
VideoCaptureFeedBack* _captureCallBack;
TickTime _lastProcessFrameCount;
TickTime _incomingFrameTimes[kFrameRateCountHistorySize];// timestamp for local captured frames
VideoRotationMode _rotateFrame; //Set if the frame should be rotated by the capture module.
I420VideoFrame _captureFrame;
VideoFrame _capture_encoded_frame;
// Used to make sure incoming timestamp is increasing for every frame.
int64_t last_capture_time_;
// Delta used for translating between NTP and internal timestamps.
const int64_t delta_ntp_internal_ms_;
};
} // namespace videocapturemodule
} // namespace webrtc
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_