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 {
|
|
|
|
|
2015-07-03 01:01:52 +03:00
|
|
|
class MediaEngineCameraVideoSource : public MediaEngineVideoSource,
|
|
|
|
private MediaConstraintsHelper
|
2014-10-13 07:37:37 +04:00
|
|
|
{
|
|
|
|
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)
|
2015-10-14 20:08:33 +03:00
|
|
|
, mNrAllocations(0)
|
2014-10-13 07:37:37 +04:00
|
|
|
, mCaptureIndex(aIndex)
|
2014-10-24 16:57:03 +04:00
|
|
|
, mTrackID(0)
|
2014-10-13 07:37:37 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2016-01-18 06:25:30 +03:00
|
|
|
void GetName(nsAString& aName) override;
|
|
|
|
void GetUUID(nsACString& aUUID) override;
|
|
|
|
void SetDirectListeners(bool aHasListeners) override;
|
2014-10-13 07:37:37 +04:00
|
|
|
|
2016-01-18 06:25:30 +03:00
|
|
|
bool IsFake() override
|
2014-10-13 07:37:37 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:25:30 +03:00
|
|
|
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-07-03 01:01:52 +03:00
|
|
|
const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets,
|
|
|
|
const nsString& aDeviceId) override;
|
2015-02-18 21:06:01 +03:00
|
|
|
|
2016-01-18 06:25:30 +03:00
|
|
|
void Shutdown() override {};
|
2015-05-29 21:28:03 +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-06-18 18:46:36 +03:00
|
|
|
uint32_t GetFitnessDistance(const webrtc::CaptureCapability& aCandidate,
|
|
|
|
const dom::MediaTrackConstraintSet &aConstraints,
|
2015-07-03 01:01:52 +03:00
|
|
|
bool aAdvanced,
|
|
|
|
const nsString& aDeviceId);
|
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);
|
2016-01-18 06:25:30 +03:00
|
|
|
static void LogCapability(const char* aHeader,
|
|
|
|
const webrtc::CaptureCapability &aCapability,
|
|
|
|
uint32_t aDistance);
|
2015-02-18 21:06:01 +03:00
|
|
|
virtual size_t NumCapabilities();
|
|
|
|
virtual void GetCapability(size_t aIndex, webrtc::CaptureCapability& aOut);
|
2015-10-05 18:05:00 +03:00
|
|
|
virtual bool ChooseCapability(const dom::MediaTrackConstraints &aConstraints,
|
2015-07-03 01:01:52 +03:00
|
|
|
const MediaEnginePrefs &aPrefs,
|
|
|
|
const nsString& aDeviceId);
|
2015-06-18 18:46:36 +03:00
|
|
|
void SetName(nsString aName);
|
|
|
|
void SetUUID(const char* aUUID);
|
|
|
|
const nsCString& GetUUID(); // protected access
|
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-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<SourceMediaStream>> mSources; // When this goes empty, we shut down HW
|
|
|
|
RefPtr<layers::Image> mImage;
|
|
|
|
RefPtr<layers::ImageContainer> mImageContainer;
|
2014-10-13 07:37:37 +04:00
|
|
|
int mWidth, mHeight; // protected with mMonitor on Gonk due to different threading
|
|
|
|
// end of data protected by mMonitor
|
|
|
|
|
|
|
|
|
|
|
|
bool mInitDone;
|
|
|
|
bool mHasDirectListeners;
|
2015-10-14 20:08:33 +03:00
|
|
|
int mNrAllocations; // When this becomes 0, we shut down HW
|
2014-10-13 07:37:37 +04:00
|
|
|
int mCaptureIndex;
|
2014-10-24 16:57:03 +04:00
|
|
|
TrackID mTrackID;
|
2014-10-13 07:37:37 +04:00
|
|
|
|
2015-10-05 18:05:00 +03:00
|
|
|
webrtc::CaptureCapability mCapability;
|
2014-10-13 07:37:37 +04:00
|
|
|
|
2015-02-18 21:06:01 +03:00
|
|
|
nsTArray<webrtc::CaptureCapability> mHardcodedCapabilities; // For OSX & B2G
|
2015-06-18 18:46:36 +03:00
|
|
|
private:
|
2014-10-13 07:37:37 +04:00
|
|
|
nsString mDeviceName;
|
2015-06-18 18:46:36 +03:00
|
|
|
nsCString mUniqueId;
|
|
|
|
nsString mFacingMode;
|
2014-10-13 07:37:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2014-10-13 07:37:37 +04:00
|
|
|
#endif // MediaEngineCameraVideoSource_h
|