2014-10-13 07:37:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MediaEngineCameraVideoSource_h
|
|
|
|
#define MediaEngineCameraVideoSource_h
|
|
|
|
|
|
|
|
#include "MediaEngine.h"
|
|
|
|
#include "MediaTrackConstraints.h"
|
|
|
|
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
|
|
|
|
// conflicts with #include of scoped_ptr.h
|
|
|
|
#undef FF
|
|
|
|
#include "webrtc/video_engine/include/vie_capture.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class MediaEngineCameraVideoSource : public MediaEngineVideoSource
|
|
|
|
{
|
|
|
|
public:
|
2014-10-11 01:28:35 +04:00
|
|
|
explicit MediaEngineCameraVideoSource(int aIndex,
|
|
|
|
const char* aMonitorName = "Camera.Monitor")
|
2014-10-13 07:37:37 +04:00
|
|
|
: MediaEngineVideoSource(kReleased)
|
|
|
|
, mMonitor(aMonitorName)
|
|
|
|
, mWidth(0)
|
|
|
|
, mHeight(0)
|
|
|
|
, mInitDone(false)
|
|
|
|
, mHasDirectListeners(false)
|
|
|
|
, mCaptureIndex(aIndex)
|
2014-10-24 16:57:03 +04:00
|
|
|
, mTrackID(0)
|
2014-10-13 07:37:37 +04:00
|
|
|
, mFps(-1)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void GetName(nsAString& aName) override;
|
|
|
|
virtual void GetUUID(nsAString& aUUID) override;
|
|
|
|
virtual void SetDirectListeners(bool aHasListeners) override;
|
2014-10-13 07:37:37 +04:00
|
|
|
virtual nsresult Config(bool aEchoOn, uint32_t aEcho,
|
|
|
|
bool aAgcOn, uint32_t aAGC,
|
|
|
|
bool aNoiseOn, uint32_t aNoise,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aPlayoutDelay) override
|
2014-10-13 07:37:37 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsFake() override
|
2014-10-13 07:37:37 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual const dom::MediaSourceEnum GetMediaSource() override {
|
2015-01-20 18:31:59 +03:00
|
|
|
return dom::MediaSourceEnum::Camera;
|
2014-10-13 07:37:37 +04:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult TakePhoto(PhotoCallback* aCallback) override
|
2014-10-13 07:37:37 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:06:26 +03:00
|
|
|
uint32_t GetBestFitnessDistance(
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets) override;
|
2015-02-18 21:06:01 +03:00
|
|
|
|
2014-10-13 07:37:37 +04:00
|
|
|
protected:
|
2015-02-21 01:06:26 +03:00
|
|
|
struct CapabilityCandidate {
|
2015-02-21 03:02:03 +03:00
|
|
|
explicit CapabilityCandidate(uint8_t index, uint32_t distance = 0)
|
2015-02-21 01:06:26 +03:00
|
|
|
: mIndex(index), mDistance(distance) {}
|
|
|
|
|
|
|
|
size_t mIndex;
|
|
|
|
uint32_t mDistance;
|
|
|
|
};
|
|
|
|
typedef nsTArray<CapabilityCandidate> CapabilitySet;
|
2015-02-18 21:06:01 +03:00
|
|
|
|
2014-10-13 07:37:37 +04:00
|
|
|
~MediaEngineCameraVideoSource() {}
|
|
|
|
|
2014-10-24 16:57:03 +04:00
|
|
|
// guts for appending data to the MSG track
|
|
|
|
virtual bool AppendToTrack(SourceMediaStream* aSource,
|
|
|
|
layers::Image* aImage,
|
|
|
|
TrackID aID,
|
2014-09-18 09:20:43 +04:00
|
|
|
StreamTime delta);
|
2015-02-21 01:06:26 +03:00
|
|
|
template<class ValueType, class ConstrainRange>
|
|
|
|
static uint32_t FitnessDistance(ValueType n, const ConstrainRange& aRange);
|
2015-05-07 06:01:17 +03:00
|
|
|
static uint32_t FitnessDistance(int32_t n,
|
|
|
|
const dom::OwningLongOrConstrainLongRange& aConstraint, bool aAdvanced);
|
|
|
|
static uint32_t FitnessDistance(double n,
|
|
|
|
const dom::OwningDoubleOrConstrainDoubleRange& aConstraint, bool aAdvanced);
|
|
|
|
|
2015-02-21 01:06:26 +03:00
|
|
|
static uint32_t GetFitnessDistance(const webrtc::CaptureCapability& aCandidate,
|
2015-05-07 06:01:17 +03:00
|
|
|
const dom::MediaTrackConstraintSet &aConstraints,
|
|
|
|
bool aAdvanced);
|
2015-02-21 01:06:26 +03:00
|
|
|
static void TrimLessFitCandidates(CapabilitySet& set);
|
2015-04-08 19:06:39 +03:00
|
|
|
static void LogConstraints(const dom::MediaTrackConstraintSet& aConstraints,
|
|
|
|
bool aAdvanced);
|
2015-02-18 21:06:01 +03:00
|
|
|
virtual size_t NumCapabilities();
|
|
|
|
virtual void GetCapability(size_t aIndex, webrtc::CaptureCapability& aOut);
|
2015-02-21 01:06:26 +03:00
|
|
|
bool ChooseCapability(const dom::MediaTrackConstraints &aConstraints,
|
2015-02-18 21:06:01 +03:00
|
|
|
const MediaEnginePrefs &aPrefs);
|
2014-10-13 07:37:37 +04:00
|
|
|
|
|
|
|
// Engine variables.
|
|
|
|
|
|
|
|
// mMonitor protects mImage access/changes, and transitions of mState
|
|
|
|
// from kStarted to kStopped (which are combined with EndTrack() and
|
2015-01-17 00:27:56 +03:00
|
|
|
// image changes).
|
|
|
|
// mMonitor also protects mSources[] access/changes.
|
|
|
|
// mSources[] is accessed from webrtc threads.
|
|
|
|
|
2014-10-13 07:37:37 +04:00
|
|
|
// All the mMonitor accesses are from the child classes.
|
|
|
|
Monitor mMonitor; // Monitor for processing Camera frames.
|
2015-03-10 08:08:03 +03:00
|
|
|
nsTArray<nsRefPtr<SourceMediaStream>> mSources; // When this goes empty, we shut down HW
|
2014-10-13 07:37:37 +04:00
|
|
|
nsRefPtr<layers::Image> mImage;
|
|
|
|
nsRefPtr<layers::ImageContainer> mImageContainer;
|
|
|
|
int mWidth, mHeight; // protected with mMonitor on Gonk due to different threading
|
|
|
|
// end of data protected by mMonitor
|
|
|
|
|
|
|
|
|
|
|
|
bool mInitDone;
|
|
|
|
bool mHasDirectListeners;
|
|
|
|
int mCaptureIndex;
|
2014-10-24 16:57:03 +04:00
|
|
|
TrackID mTrackID;
|
2014-10-13 07:37:37 +04:00
|
|
|
int mFps; // Track rate (30 fps by default)
|
|
|
|
|
|
|
|
webrtc::CaptureCapability mCapability; // Doesn't work on OS X.
|
|
|
|
|
2015-02-18 21:06:01 +03:00
|
|
|
nsTArray<webrtc::CaptureCapability> mHardcodedCapabilities; // For OSX & B2G
|
2014-10-13 07:37:37 +04:00
|
|
|
nsString mDeviceName;
|
|
|
|
nsString mUniqueId;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif // MediaEngineCameraVideoSource_h
|