2012-05-21 15:12: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/. */
|
2010-08-18 06:17:50 +04:00
|
|
|
|
2010-08-13 06:28:15 +04:00
|
|
|
#include "VideoUtils.h"
|
2015-07-16 21:52:43 +03:00
|
|
|
|
2018-03-27 12:27:08 +03:00
|
|
|
#include <functional>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-04-09 13:07:58 +03:00
|
|
|
#include "CubebUtils.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "ImageContainer.h"
|
2017-01-18 03:59:03 +03:00
|
|
|
#include "MediaContainerType.h"
|
2012-09-03 02:56:29 +04:00
|
|
|
#include "MediaResource.h"
|
2015-05-18 09:15:47 +03:00
|
|
|
#include "TimeUnits.h"
|
2013-09-26 23:06:59 +04:00
|
|
|
#include "VorbisUtils.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "mozilla/Base64.h"
|
2019-05-07 01:41:25 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2015-08-03 21:44:10 +03:00
|
|
|
#include "mozilla/SharedThreadPool.h"
|
2018-03-20 01:48:56 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2017-09-18 14:34:43 +03:00
|
|
|
#include "mozilla/SystemGroup.h"
|
|
|
|
#include "mozilla/TaskCategory.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "mozilla/TaskQueue.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
|
|
#include "nsContentTypeParser.h"
|
|
|
|
#include "nsIConsoleService.h"
|
2019-05-07 01:41:25 +03:00
|
|
|
#include "nsINetworkLinkService.h"
|
2014-10-13 02:53:43 +04:00
|
|
|
#include "nsIRandomGenerator.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "nsMathUtils.h"
|
2019-05-07 01:41:25 +03:00
|
|
|
#include "nsNetCID.h"
|
2015-09-29 03:06:14 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2014-12-09 22:34:00 +03:00
|
|
|
|
2013-11-04 02:45:19 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
using layers::PlanarYCbCrImage;
|
2017-04-17 11:35:04 +03:00
|
|
|
using media::TimeUnit;
|
2014-02-04 05:49:21 +04:00
|
|
|
|
2018-03-27 12:27:08 +03:00
|
|
|
CheckedInt64 SaferMultDiv(int64_t aValue, uint64_t aMul, uint64_t aDiv) {
|
|
|
|
if (aMul > INT64_MAX || aDiv > INT64_MAX) {
|
|
|
|
return CheckedInt64(INT64_MAX) + 1; // Return an invalid checked int.
|
|
|
|
}
|
|
|
|
int64_t mul = aMul;
|
|
|
|
int64_t div = aDiv;
|
|
|
|
int64_t major = aValue / div;
|
|
|
|
int64_t remainder = aValue % div;
|
|
|
|
return CheckedInt64(remainder) * mul / div + CheckedInt64(major) * mul;
|
2015-09-24 03:42:54 +03:00
|
|
|
}
|
|
|
|
|
2011-09-27 07:31:18 +04:00
|
|
|
// Converts from number of audio frames to microseconds, given the specified
|
2010-08-13 06:28:15 +04:00
|
|
|
// audio rate.
|
2012-08-22 19:56:38 +04:00
|
|
|
CheckedInt64 FramesToUsecs(int64_t aFrames, uint32_t aRate) {
|
2015-09-24 03:42:54 +03:00
|
|
|
return SaferMultDiv(aFrames, USECS_PER_S, aRate);
|
2010-08-13 06:28:15 +04:00
|
|
|
}
|
|
|
|
|
2017-04-17 11:35:04 +03:00
|
|
|
TimeUnit FramesToTimeUnit(int64_t aFrames, uint32_t aRate) {
|
2019-07-23 03:57:27 +03:00
|
|
|
if (MOZ_UNLIKELY(!aRate)) {
|
|
|
|
return TimeUnit::Invalid();
|
|
|
|
}
|
2015-09-24 03:42:54 +03:00
|
|
|
int64_t major = aFrames / aRate;
|
|
|
|
int64_t remainder = aFrames % aRate;
|
2017-04-17 11:35:04 +03:00
|
|
|
return TimeUnit::FromMicroseconds(major) * USECS_PER_S +
|
|
|
|
(TimeUnit::FromMicroseconds(remainder) * USECS_PER_S) / aRate;
|
2015-07-01 09:50:27 +03:00
|
|
|
}
|
|
|
|
|
2011-09-27 07:31:18 +04:00
|
|
|
// Converts from microseconds to number of audio frames, given the specified
|
2010-08-13 06:28:15 +04:00
|
|
|
// audio rate.
|
2012-08-22 19:56:38 +04:00
|
|
|
CheckedInt64 UsecsToFrames(int64_t aUsecs, uint32_t aRate) {
|
2015-09-24 03:42:54 +03:00
|
|
|
return SaferMultDiv(aUsecs, aRate, USECS_PER_S);
|
2010-08-13 06:28:15 +04:00
|
|
|
}
|
2011-06-24 02:08:54 +04:00
|
|
|
|
2015-06-18 17:45:05 +03:00
|
|
|
// Format TimeUnit as number of frames at given rate.
|
2017-04-17 11:35:04 +03:00
|
|
|
CheckedInt64 TimeUnitToFrames(const TimeUnit& aTime, uint32_t aRate) {
|
2019-04-16 21:22:51 +03:00
|
|
|
return aTime.IsValid() ? UsecsToFrames(aTime.ToMicroseconds(), aRate)
|
|
|
|
: CheckedInt64(INT64_MAX) + 1;
|
2015-06-18 17:45:05 +03:00
|
|
|
}
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
nsresult SecondsToUsecs(double aSeconds, int64_t& aOutUsecs) {
|
|
|
|
if (aSeconds * double(USECS_PER_S) > INT64_MAX) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
aOutUsecs = int64_t(aSeconds * double(USECS_PER_S));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t ConditionDimension(float aValue) {
|
2011-06-24 02:08:54 +04:00
|
|
|
// This will exclude NaNs and too-big values.
|
2012-09-28 10:57:33 +04:00
|
|
|
if (aValue > 1.0 && aValue <= INT32_MAX) return int32_t(NS_round(aValue));
|
2011-06-24 02:08:54 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:00:33 +03:00
|
|
|
void ScaleDisplayByAspectRatio(gfx::IntSize& aDisplay, float aAspectRatio) {
|
2011-06-24 02:08:54 +04:00
|
|
|
if (aAspectRatio > 1.0) {
|
|
|
|
// Increase the intrinsic width
|
|
|
|
aDisplay.width = ConditionDimension(aAspectRatio * aDisplay.width);
|
|
|
|
} else {
|
|
|
|
// Increase the intrinsic height
|
|
|
|
aDisplay.height = ConditionDimension(aDisplay.height / aAspectRatio);
|
|
|
|
}
|
|
|
|
}
|
2012-09-03 02:56:29 +04:00
|
|
|
|
|
|
|
static int64_t BytesToTime(int64_t offset, int64_t length, int64_t durationUs) {
|
|
|
|
NS_ASSERTION(length > 0, "Must have positive length");
|
|
|
|
double r = double(offset) / double(length);
|
|
|
|
if (r > 1.0) r = 1.0;
|
|
|
|
return int64_t(double(durationUs) * r);
|
|
|
|
}
|
|
|
|
|
2015-05-18 09:15:47 +03:00
|
|
|
media::TimeIntervals GetEstimatedBufferedTimeRanges(
|
|
|
|
mozilla::MediaResource* aStream, int64_t aDurationUsecs) {
|
|
|
|
media::TimeIntervals buffered;
|
2012-09-03 02:56:29 +04:00
|
|
|
// Nothing to cache if the media takes 0us to play.
|
2015-05-18 09:15:47 +03:00
|
|
|
if (aDurationUsecs <= 0 || !aStream) return buffered;
|
2012-09-03 02:56:29 +04:00
|
|
|
|
|
|
|
// Special case completely cached files. This also handles local files.
|
|
|
|
if (aStream->IsDataCachedToEndOfResource(0)) {
|
2017-04-17 11:35:04 +03:00
|
|
|
buffered += media::TimeInterval(TimeUnit::Zero(),
|
|
|
|
TimeUnit::FromMicroseconds(aDurationUsecs));
|
2015-05-18 09:15:47 +03:00
|
|
|
return buffered;
|
2012-09-03 02:56:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t totalBytes = aStream->GetLength();
|
|
|
|
|
|
|
|
// If we can't determine the total size, pretend that we have nothing
|
|
|
|
// buffered. This will put us in a state of eternally-low-on-undecoded-data
|
|
|
|
// which is not great, but about the best we can do.
|
|
|
|
if (totalBytes <= 0) return buffered;
|
|
|
|
|
|
|
|
int64_t startOffset = aStream->GetNextCachedData(0);
|
|
|
|
while (startOffset >= 0) {
|
|
|
|
int64_t endOffset = aStream->GetCachedDataEnd(startOffset);
|
|
|
|
// Bytes [startOffset..endOffset] are cached.
|
|
|
|
NS_ASSERTION(startOffset >= 0, "Integer underflow in GetBuffered");
|
|
|
|
NS_ASSERTION(endOffset >= 0, "Integer underflow in GetBuffered");
|
|
|
|
|
|
|
|
int64_t startUs = BytesToTime(startOffset, totalBytes, aDurationUsecs);
|
|
|
|
int64_t endUs = BytesToTime(endOffset, totalBytes, aDurationUsecs);
|
|
|
|
if (startUs != endUs) {
|
2017-04-17 11:35:04 +03:00
|
|
|
buffered += media::TimeInterval(TimeUnit::FromMicroseconds(startUs),
|
|
|
|
TimeUnit::FromMicroseconds(endUs));
|
2012-09-03 02:56:29 +04:00
|
|
|
}
|
|
|
|
startOffset = aStream->GetNextCachedData(endOffset);
|
|
|
|
}
|
2015-05-18 09:15:47 +03:00
|
|
|
return buffered;
|
2012-09-03 02:56:29 +04:00
|
|
|
}
|
|
|
|
|
2015-08-06 09:30:22 +03:00
|
|
|
void DownmixStereoToMono(mozilla::AudioDataValue* aBuffer, uint32_t aFrames) {
|
|
|
|
MOZ_ASSERT(aBuffer);
|
|
|
|
const int channels = 2;
|
|
|
|
for (uint32_t fIdx = 0; fIdx < aFrames; ++fIdx) {
|
|
|
|
#ifdef MOZ_SAMPLE_TYPE_FLOAT32
|
|
|
|
float sample = 0.0;
|
|
|
|
#else
|
|
|
|
int sample = 0;
|
|
|
|
#endif
|
|
|
|
// The sample of the buffer would be interleaved.
|
|
|
|
sample = (aBuffer[fIdx * channels] + aBuffer[fIdx * channels + 1]) * 0.5;
|
|
|
|
aBuffer[fIdx * channels] = aBuffer[fIdx * channels + 1] = sample;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 13:07:58 +03:00
|
|
|
uint32_t DecideAudioPlaybackChannels(const AudioInfo& info) {
|
2018-03-20 01:48:56 +03:00
|
|
|
if (StaticPrefs::accessibility_monoaudio_enable()) {
|
2018-03-15 19:28:14 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-06-28 07:09:05 +03:00
|
|
|
if (StaticPrefs::media_forcestereo_enabled()) {
|
2018-03-15 19:28:14 +03:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info.mChannels;
|
|
|
|
}
|
|
|
|
|
2018-04-09 13:07:58 +03:00
|
|
|
bool IsDefaultPlaybackDeviceMono() {
|
|
|
|
return CubebUtils::MaxNumberOfChannels() == 1;
|
|
|
|
}
|
|
|
|
|
2013-11-04 02:45:19 +04:00
|
|
|
bool IsVideoContentType(const nsCString& aContentType) {
|
|
|
|
NS_NAMED_LITERAL_CSTRING(video, "video");
|
|
|
|
if (FindInReadable(video, aContentType)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:00:33 +03:00
|
|
|
bool IsValidVideoRegion(const gfx::IntSize& aFrame,
|
|
|
|
const gfx::IntRect& aPicture,
|
|
|
|
const gfx::IntSize& aDisplay) {
|
2014-02-04 05:49:21 +04:00
|
|
|
return aFrame.width <= PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aFrame.height <= PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aFrame.width * aFrame.height <= MAX_VIDEO_WIDTH * MAX_VIDEO_HEIGHT &&
|
|
|
|
aFrame.width * aFrame.height != 0 &&
|
2018-02-19 23:15:23 +03:00
|
|
|
aPicture.width <= PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aPicture.x < PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aPicture.x + aPicture.width < PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aPicture.height <= PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aPicture.y < PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aPicture.y + aPicture.height < PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aPicture.width * aPicture.height <=
|
|
|
|
MAX_VIDEO_WIDTH * MAX_VIDEO_HEIGHT &&
|
|
|
|
aPicture.width * aPicture.height != 0 &&
|
2014-02-04 05:49:21 +04:00
|
|
|
aDisplay.width <= PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aDisplay.height <= PlanarYCbCrImage::MAX_DIMENSION &&
|
|
|
|
aDisplay.width * aDisplay.height <=
|
|
|
|
MAX_VIDEO_WIDTH * MAX_VIDEO_HEIGHT &&
|
|
|
|
aDisplay.width * aDisplay.height != 0;
|
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SharedThreadPool> GetMediaThreadPool(MediaThreadType aType) {
|
2015-05-07 07:01:43 +03:00
|
|
|
const char* name;
|
2019-06-11 10:36:29 +03:00
|
|
|
uint32_t threads = 4;
|
2015-05-07 07:01:43 +03:00
|
|
|
switch (aType) {
|
|
|
|
case MediaThreadType::PLATFORM_DECODER:
|
|
|
|
name = "MediaPDecoder";
|
|
|
|
break;
|
2017-12-15 20:39:33 +03:00
|
|
|
case MediaThreadType::MSG_CONTROL:
|
|
|
|
name = "MSGControl";
|
|
|
|
break;
|
|
|
|
case MediaThreadType::WEBRTC_DECODER:
|
|
|
|
name = "WebRTCPD";
|
|
|
|
break;
|
2019-06-11 10:36:29 +03:00
|
|
|
case MediaThreadType::MDSM:
|
|
|
|
name = "MediaDecoderStateMachine";
|
|
|
|
threads = 1;
|
|
|
|
break;
|
2015-05-07 07:01:43 +03:00
|
|
|
default:
|
2016-01-14 12:42:18 +03:00
|
|
|
MOZ_FALLTHROUGH_ASSERT("Unexpected MediaThreadType");
|
2015-05-07 07:01:43 +03:00
|
|
|
case MediaThreadType::PLAYBACK:
|
|
|
|
name = "MediaPlayback";
|
|
|
|
break;
|
|
|
|
}
|
2017-11-13 09:16:06 +03:00
|
|
|
|
2019-06-11 10:36:29 +03:00
|
|
|
RefPtr<SharedThreadPool> pool =
|
|
|
|
SharedThreadPool::Get(nsDependentCString(name), threads);
|
2018-07-18 19:47:45 +03:00
|
|
|
|
|
|
|
// Ensure a larger stack for platform decoder threads
|
|
|
|
if (aType == MediaThreadType::PLATFORM_DECODER) {
|
|
|
|
const uint32_t minStackSize = 512 * 1024;
|
|
|
|
uint32_t stackSize;
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(pool->GetThreadStackSize(&stackSize));
|
|
|
|
if (stackSize < minStackSize) {
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(pool->SetThreadStackSize(minStackSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 15:39:50 +03:00
|
|
|
return pool.forget();
|
2014-06-18 09:07:02 +04:00
|
|
|
}
|
|
|
|
|
2017-10-13 08:55:05 +03:00
|
|
|
bool ExtractVPXCodecDetails(const nsAString& aCodec, uint8_t& aProfile,
|
|
|
|
uint8_t& aLevel, uint8_t& aBitDepth) {
|
|
|
|
uint8_t dummyChromaSubsampling = 1;
|
|
|
|
VideoColorSpace dummyColorspace;
|
|
|
|
return ExtractVPXCodecDetails(aCodec, aProfile, aLevel, aBitDepth,
|
|
|
|
dummyChromaSubsampling, dummyColorspace);
|
|
|
|
}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2017-10-13 08:55:05 +03:00
|
|
|
bool ExtractVPXCodecDetails(const nsAString& aCodec, uint8_t& aProfile,
|
|
|
|
uint8_t& aLevel, uint8_t& aBitDepth,
|
|
|
|
uint8_t& aChromaSubsampling,
|
|
|
|
VideoColorSpace& aColorSpace) {
|
|
|
|
// Assign default value.
|
|
|
|
aChromaSubsampling = 1;
|
|
|
|
auto splitter = aCodec.Split(u'.');
|
|
|
|
auto fieldsItr = splitter.begin();
|
|
|
|
auto fourCC = *fieldsItr;
|
|
|
|
|
|
|
|
if (!fourCC.EqualsLiteral("vp09") && !fourCC.EqualsLiteral("vp08")) {
|
|
|
|
// Invalid 4CC
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
++fieldsItr;
|
|
|
|
uint8_t* fields[] = {&aProfile,
|
|
|
|
&aLevel,
|
|
|
|
&aBitDepth,
|
|
|
|
&aChromaSubsampling,
|
|
|
|
&aColorSpace.mPrimaryId,
|
|
|
|
&aColorSpace.mTransferId,
|
|
|
|
&aColorSpace.mMatrixId,
|
|
|
|
&aColorSpace.mRangeId};
|
|
|
|
int fieldsCount = 0;
|
|
|
|
nsresult rv;
|
|
|
|
for (; fieldsItr != splitter.end(); ++fieldsItr, ++fieldsCount) {
|
|
|
|
if (fieldsCount > 7) {
|
|
|
|
// No more than 8 fields are expected.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*(fields[fieldsCount]) = static_cast<uint8_t>(
|
|
|
|
PromiseFlatString((*fieldsItr)).ToInteger(&rv, 10));
|
|
|
|
// We got invalid field value, parsing error.
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
}
|
|
|
|
// Mandatory Fields
|
|
|
|
// <sample entry 4CC>.<profile>.<level>.<bitDepth>.
|
|
|
|
// Optional Fields
|
|
|
|
// <chromaSubsampling>.<colourPrimaries>.<transferCharacteristics>.
|
|
|
|
// <matrixCoefficients>.<videoFullRangeFlag>
|
|
|
|
// First three fields are mandatory(we have parsed 4CC).
|
|
|
|
if (fieldsCount < 3) {
|
|
|
|
// Invalid number of fields.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Start to validate the parsing value.
|
|
|
|
|
|
|
|
// profile should be 0,1,2 or 3.
|
|
|
|
// See https://www.webmproject.org/vp9/profiles/
|
|
|
|
// We don't support more than profile 2
|
|
|
|
if (aProfile > 2) {
|
|
|
|
// Invalid profile.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// level, See https://www.webmproject.org/vp9/mp4/#semantics_1
|
|
|
|
switch (aLevel) {
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
case 20:
|
|
|
|
case 21:
|
|
|
|
case 30:
|
|
|
|
case 31:
|
|
|
|
case 40:
|
|
|
|
case 41:
|
|
|
|
case 50:
|
|
|
|
case 51:
|
|
|
|
case 52:
|
|
|
|
case 60:
|
|
|
|
case 61:
|
|
|
|
case 62:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Invalid level.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aBitDepth != 8 && aBitDepth != 10 && aBitDepth != 12) {
|
|
|
|
// Invalid bitDepth:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fieldsCount == 3) {
|
|
|
|
// No more options.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// chromaSubsampling should be 0,1,2,3...4~7 are reserved.
|
|
|
|
if (aChromaSubsampling > 3) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fieldsCount == 4) {
|
|
|
|
// No more options.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is an integer that is defined by the "Colour primaries"
|
|
|
|
// section of ISO/IEC 23001-8:2016 Table 2.
|
|
|
|
// We treat reserved value as false case.
|
|
|
|
const auto& primaryId = aColorSpace.mPrimaryId;
|
|
|
|
if (primaryId == 0 || primaryId == 3 || primaryId > 22) {
|
|
|
|
// reserved value.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (primaryId > 12 && primaryId < 22) {
|
|
|
|
// 13~21 are reserved values.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fieldsCount == 5) {
|
|
|
|
// No more options.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is an integer that is defined by the
|
|
|
|
// "Transfer characteristics" section of ISO/IEC 23001-8:2016 Table 3.
|
|
|
|
// We treat reserved value as false case.
|
|
|
|
const auto& transferId = aColorSpace.mTransferId;
|
|
|
|
if (transferId == 0 || transferId == 3 || transferId > 18) {
|
|
|
|
// reserved value.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fieldsCount == 6) {
|
|
|
|
// No more options.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is an integer that is defined by the
|
|
|
|
// "Matrix coefficients" section of ISO/IEC 23001-8:2016 Table 4.
|
|
|
|
// We treat reserved value as false case.
|
|
|
|
const auto& matrixId = aColorSpace.mMatrixId;
|
|
|
|
if (matrixId == 3 || matrixId > 11) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If matrixCoefficients is 0 (RGB), then chroma subsampling MUST be 3
|
|
|
|
// (4:4:4).
|
|
|
|
if (matrixId == 0 && aChromaSubsampling != 3) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fieldsCount == 7) {
|
|
|
|
// No more options.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// videoFullRangeFlag indicates the black level and range of the luma and
|
|
|
|
// chroma signals. 0 = legal range (e.g. 16-235 for 8 bit sample depth);
|
|
|
|
// 1 = full range (e.g. 0-255 for 8-bit sample depth).
|
|
|
|
const auto& rangeId = aColorSpace.mRangeId;
|
|
|
|
return rangeId <= 1;
|
|
|
|
}
|
|
|
|
|
2014-08-28 07:32:34 +04:00
|
|
|
bool ExtractH264CodecDetails(const nsAString& aCodec, uint8_t& aProfile,
|
2018-06-20 03:23:05 +03:00
|
|
|
uint8_t& aConstraint, uint8_t& aLevel) {
|
2014-12-23 06:42:55 +03:00
|
|
|
// H.264 codecs parameters have a type defined as avcN.PPCCLL, where
|
2018-06-20 03:23:05 +03:00
|
|
|
// N = avc type. avc3 is avcc with SPS & PPS implicit (within stream)
|
2014-08-28 07:32:34 +04:00
|
|
|
// PP = profile_idc, CC = constraint_set flags, LL = level_idc.
|
|
|
|
// We ignore the constraint_set flags, as it's not clear from any
|
|
|
|
// documentation what constraints the platform decoders support.
|
|
|
|
// See
|
|
|
|
// http://blog.pearce.org.nz/2013/11/what-does-h264avc1-codecs-parameters.html
|
|
|
|
// for more details.
|
|
|
|
if (aCodec.Length() != strlen("avc1.PPCCLL")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-23 06:42:55 +03:00
|
|
|
// Verify the codec starts with "avc1." or "avc3.".
|
2014-08-28 07:32:34 +04:00
|
|
|
const nsAString& sample = Substring(aCodec, 0, 5);
|
2014-12-23 06:42:55 +03:00
|
|
|
if (!sample.EqualsASCII("avc1.") && !sample.EqualsASCII("avc3.")) {
|
2014-08-28 07:32:34 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-20 03:23:05 +03:00
|
|
|
// Extract the profile_idc, constraint_flags and level_idc.
|
2014-08-28 07:32:34 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
aProfile = PromiseFlatString(Substring(aCodec, 5, 2)).ToInteger(&rv, 16);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2018-06-20 03:23:05 +03:00
|
|
|
// Constraint flags are stored on the 6 most significant bits, first two bits
|
|
|
|
// are reserved_zero_2bits.
|
|
|
|
aConstraint = PromiseFlatString(Substring(aCodec, 7, 2)).ToInteger(&rv, 16);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2014-08-28 07:32:34 +04:00
|
|
|
aLevel = PromiseFlatString(Substring(aCodec, 9, 2)).ToInteger(&rv, 16);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2015-03-18 06:10:57 +03:00
|
|
|
if (aLevel == 9) {
|
|
|
|
aLevel = H264_LEVEL_1_b;
|
|
|
|
} else if (aLevel <= 5) {
|
|
|
|
aLevel *= 10;
|
|
|
|
}
|
|
|
|
|
2018-06-20 03:23:05 +03:00
|
|
|
// We only make sure constraints is above 4 for collection perspective
|
2015-03-03 16:54:00 +03:00
|
|
|
// otherwise collect 0 for unknown.
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_CANPLAYTYPE_H264_CONSTRAINT_SET_FLAG,
|
2018-06-20 03:23:05 +03:00
|
|
|
aConstraint >= 4 ? aConstraint : 0);
|
2015-02-11 11:09:00 +03:00
|
|
|
// 244 is the highest meaningful profile value (High 4:4:4 Intra Profile)
|
|
|
|
// that can be represented as single hex byte, otherwise collect 0 for
|
|
|
|
// unknown.
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_CANPLAYTYPE_H264_PROFILE,
|
|
|
|
aProfile <= 244 ? aProfile : 0);
|
|
|
|
|
|
|
|
// Make sure aLevel represents a value between levels 1 and 5.2,
|
|
|
|
// otherwise collect 0 for unknown.
|
|
|
|
Telemetry::Accumulate(Telemetry::VIDEO_CANPLAYTYPE_H264_LEVEL,
|
|
|
|
(aLevel >= 10 && aLevel <= 52) ? aLevel : 0);
|
|
|
|
|
2014-08-28 07:32:34 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-03 17:51:05 +03:00
|
|
|
nsresult GenerateRandomName(nsCString& aOutSalt, uint32_t aLength) {
|
2014-10-13 02:53:43 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIRandomGenerator> rg =
|
|
|
|
do_GetService("@mozilla.org/security/random-generator;1", &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2015-03-03 17:51:05 +03:00
|
|
|
// For each three bytes of random data we will get four bytes of ASCII.
|
2014-10-13 02:53:43 +04:00
|
|
|
const uint32_t requiredBytesLength =
|
2015-03-03 17:51:05 +03:00
|
|
|
static_cast<uint32_t>((aLength + 3) / 4 * 3);
|
2014-10-13 02:53:43 +04:00
|
|
|
|
|
|
|
uint8_t* buffer;
|
|
|
|
rv = rg->GenerateRandomBytes(requiredBytesLength, &buffer);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsAutoCString temp;
|
|
|
|
nsDependentCSubstring randomData(reinterpret_cast<const char*>(buffer),
|
|
|
|
requiredBytesLength);
|
|
|
|
rv = Base64Encode(randomData, temp);
|
2015-04-01 08:29:55 +03:00
|
|
|
free(buffer);
|
2014-10-13 02:53:43 +04:00
|
|
|
buffer = nullptr;
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2015-03-03 17:51:05 +03:00
|
|
|
aOutSalt = temp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength) {
|
|
|
|
nsresult rv = GenerateRandomName(aOutSalt, aLength);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2014-10-13 02:53:43 +04:00
|
|
|
|
|
|
|
// Base64 characters are alphanumeric (a-zA-Z0-9) and '+' and '/', so we need
|
|
|
|
// to replace illegal characters -- notably '/'
|
2015-03-03 17:51:05 +03:00
|
|
|
aOutSalt.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
|
2014-10-13 02:53:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-04-25 09:57:55 +03:00
|
|
|
already_AddRefed<TaskQueue> CreateMediaDecodeTaskQueue(const char* aName) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TaskQueue> queue = new TaskQueue(
|
2017-04-25 09:57:55 +03:00
|
|
|
GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER), aName);
|
2015-07-20 09:07:25 +03:00
|
|
|
return queue.forget();
|
2014-12-09 22:34:00 +03:00
|
|
|
}
|
2014-10-13 02:53:43 +04:00
|
|
|
|
2015-09-29 03:06:11 +03:00
|
|
|
void SimpleTimer::Cancel() {
|
|
|
|
if (mTimer) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIEventTarget> target;
|
|
|
|
mTimer->GetTarget(getter_AddRefs(target));
|
2017-06-01 23:41:18 +03:00
|
|
|
bool onCurrent;
|
|
|
|
nsresult rv = target->IsOnCurrentThread(&onCurrent);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv) && onCurrent);
|
2015-09-29 03:06:11 +03:00
|
|
|
#endif
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = nullptr;
|
|
|
|
}
|
|
|
|
mTask = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SimpleTimer::Notify(nsITimer* timer) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SimpleTimer> deathGrip(this);
|
2015-09-29 03:06:11 +03:00
|
|
|
if (mTask) {
|
|
|
|
mTask->Run();
|
|
|
|
mTask = nullptr;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SimpleTimer::GetName(nsACString& aName) {
|
|
|
|
aName.AssignLiteral("SimpleTimer");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-01 23:41:18 +03:00
|
|
|
nsresult SimpleTimer::Init(nsIRunnable* aTask, uint32_t aTimeoutMs,
|
|
|
|
nsIEventTarget* aTarget) {
|
2015-09-29 03:06:11 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Get target thread first, so we don't have to cancel the timer if it fails.
|
2017-06-01 23:41:18 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> target;
|
2015-09-29 03:06:11 +03:00
|
|
|
if (aTarget) {
|
|
|
|
target = aTarget;
|
|
|
|
} else {
|
2017-06-01 23:41:18 +03:00
|
|
|
target = GetMainThreadEventTarget();
|
|
|
|
if (!target) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2015-09-29 03:06:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-16 09:15:40 +03:00
|
|
|
rv = NS_NewTimerWithCallback(getter_AddRefs(mTimer), this, aTimeoutMs,
|
|
|
|
nsITimer::TYPE_ONE_SHOT, target);
|
2015-09-29 03:06:11 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTask = aTask;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_IMPL_ISUPPORTS(SimpleTimer, nsITimerCallback, nsINamed)
|
2015-09-29 03:06:11 +03:00
|
|
|
|
2017-06-01 23:41:18 +03:00
|
|
|
already_AddRefed<SimpleTimer> SimpleTimer::Create(nsIRunnable* aTask,
|
|
|
|
uint32_t aTimeoutMs,
|
|
|
|
nsIEventTarget* aTarget) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SimpleTimer> t(new SimpleTimer());
|
2015-09-29 03:06:11 +03:00
|
|
|
if (NS_FAILED(t->Init(aTask, aTimeoutMs, aTarget))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return t.forget();
|
|
|
|
}
|
|
|
|
|
2015-09-29 03:06:14 +03:00
|
|
|
void LogToBrowserConsole(const nsAString& aMsg) {
|
|
|
|
if (!NS_IsMainThread()) {
|
2015-11-19 12:00:39 +03:00
|
|
|
nsString msg(aMsg);
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
|
|
|
|
"LogToBrowserConsole", [msg]() { LogToBrowserConsole(msg); });
|
2017-07-26 11:13:35 +03:00
|
|
|
SystemGroup::Dispatch(TaskCategory::Other, task.forget());
|
2015-09-29 03:06:14 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
if (!console) {
|
|
|
|
NS_WARNING("Failed to log message to console.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsAutoString msg(aMsg);
|
|
|
|
console->LogStringMessage(msg.get());
|
|
|
|
}
|
|
|
|
|
2015-10-05 05:03:48 +03:00
|
|
|
bool ParseCodecsString(const nsAString& aCodecs,
|
|
|
|
nsTArray<nsString>& aOutCodecs) {
|
|
|
|
aOutCodecs.Clear();
|
|
|
|
bool expectMoreTokens = false;
|
|
|
|
nsCharSeparatedTokenizer tokenizer(aCodecs, ',');
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& token = tokenizer.nextToken();
|
2015-10-05 05:03:48 +03:00
|
|
|
expectMoreTokens = tokenizer.separatorAfterCurrentToken();
|
|
|
|
aOutCodecs.AppendElement(token);
|
|
|
|
}
|
|
|
|
if (expectMoreTokens) {
|
|
|
|
// Last codec name was empty
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-01 04:36:57 +03:00
|
|
|
bool ParseMIMETypeString(const nsAString& aMIMEType,
|
|
|
|
nsString& aOutContainerType,
|
|
|
|
nsTArray<nsString>& aOutCodecs) {
|
|
|
|
nsContentTypeParser parser(aMIMEType);
|
|
|
|
nsresult rv = parser.GetType(aOutContainerType);
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-10-05 05:03:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString codecsStr;
|
|
|
|
parser.GetParameter("codecs", codecsStr);
|
2016-07-01 04:36:57 +03:00
|
|
|
return ParseCodecsString(codecsStr, aOutCodecs);
|
2015-10-05 05:03:48 +03:00
|
|
|
}
|
|
|
|
|
2017-10-13 09:18:29 +03:00
|
|
|
template <int N>
|
|
|
|
static bool StartsWith(const nsACString& string, const char (&prefix)[N]) {
|
|
|
|
if (N - 1 > string.Length()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return memcmp(string.Data(), prefix, N - 1) == 0;
|
|
|
|
}
|
|
|
|
|
2016-07-01 04:36:57 +03:00
|
|
|
bool IsH264CodecString(const nsAString& aCodec) {
|
2018-06-20 03:23:05 +03:00
|
|
|
uint8_t profile = 0;
|
|
|
|
uint8_t constraint = 0;
|
|
|
|
uint8_t level = 0;
|
|
|
|
return ExtractH264CodecDetails(aCodec, profile, constraint, level);
|
2015-10-05 05:03:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 04:36:57 +03:00
|
|
|
bool IsAACCodecString(const nsAString& aCodec) {
|
|
|
|
return aCodec.EqualsLiteral("mp4a.40.2") || // MPEG4 AAC-LC
|
2017-07-20 10:35:41 +03:00
|
|
|
aCodec.EqualsLiteral(
|
|
|
|
"mp4a.40.02") || // MPEG4 AAC-LC(for compatibility)
|
2016-07-01 04:36:57 +03:00
|
|
|
aCodec.EqualsLiteral("mp4a.40.5") || // MPEG4 HE-AAC
|
2017-07-20 10:35:41 +03:00
|
|
|
aCodec.EqualsLiteral(
|
|
|
|
"mp4a.40.05") || // MPEG4 HE-AAC(for compatibility)
|
2016-07-01 04:36:57 +03:00
|
|
|
aCodec.EqualsLiteral("mp4a.67") || // MPEG2 AAC-LC
|
|
|
|
aCodec.EqualsLiteral("mp4a.40.29"); // MPEG4 HE-AACv2
|
2016-06-08 05:07:09 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 04:36:57 +03:00
|
|
|
bool IsVP8CodecString(const nsAString& aCodec) {
|
2017-10-13 09:18:29 +03:00
|
|
|
uint8_t profile = 0;
|
|
|
|
uint8_t level = 0;
|
|
|
|
uint8_t bitDepth = 0;
|
2016-07-01 04:36:57 +03:00
|
|
|
return aCodec.EqualsLiteral("vp8") || aCodec.EqualsLiteral("vp8.0") ||
|
2017-10-13 09:18:29 +03:00
|
|
|
(StartsWith(NS_ConvertUTF16toUTF8(aCodec), "vp08") &&
|
|
|
|
ExtractVPXCodecDetails(aCodec, profile, level, bitDepth));
|
2016-06-08 05:07:09 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 04:36:57 +03:00
|
|
|
bool IsVP9CodecString(const nsAString& aCodec) {
|
2017-10-13 09:18:29 +03:00
|
|
|
uint8_t profile = 0;
|
|
|
|
uint8_t level = 0;
|
|
|
|
uint8_t bitDepth = 0;
|
2016-07-01 04:36:57 +03:00
|
|
|
return aCodec.EqualsLiteral("vp9") || aCodec.EqualsLiteral("vp9.0") ||
|
2017-10-13 09:18:29 +03:00
|
|
|
(StartsWith(NS_ConvertUTF16toUTF8(aCodec), "vp09") &&
|
|
|
|
ExtractVPXCodecDetails(aCodec, profile, level, bitDepth));
|
2016-10-07 09:39:32 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 11:24:56 +03:00
|
|
|
bool IsAV1CodecString(const nsAString& aCodec) {
|
2018-08-21 02:56:39 +03:00
|
|
|
return aCodec.EqualsLiteral("av1") ||
|
|
|
|
StartsWith(NS_ConvertUTF16toUTF8(aCodec), "av01");
|
2018-07-20 11:24:56 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 09:39:32 +03:00
|
|
|
UniquePtr<TrackInfo> CreateTrackInfoWithMIMEType(
|
|
|
|
const nsACString& aCodecMIMEType) {
|
|
|
|
UniquePtr<TrackInfo> trackInfo;
|
|
|
|
if (StartsWith(aCodecMIMEType, "audio/")) {
|
|
|
|
trackInfo.reset(new AudioInfo());
|
|
|
|
trackInfo->mMimeType = aCodecMIMEType;
|
|
|
|
} else if (StartsWith(aCodecMIMEType, "video/")) {
|
|
|
|
trackInfo.reset(new VideoInfo());
|
|
|
|
trackInfo->mMimeType = aCodecMIMEType;
|
|
|
|
}
|
|
|
|
return trackInfo;
|
|
|
|
}
|
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
UniquePtr<TrackInfo> CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters(
|
2016-10-07 09:39:32 +03:00
|
|
|
const nsACString& aCodecMIMEType,
|
2017-01-18 03:59:03 +03:00
|
|
|
const MediaContainerType& aContainerType) {
|
2016-10-07 09:39:32 +03:00
|
|
|
UniquePtr<TrackInfo> trackInfo = CreateTrackInfoWithMIMEType(aCodecMIMEType);
|
|
|
|
if (trackInfo) {
|
|
|
|
VideoInfo* videoInfo = trackInfo->GetAsVideoInfo();
|
|
|
|
if (videoInfo) {
|
2017-01-18 03:59:03 +03:00
|
|
|
Maybe<int32_t> maybeWidth = aContainerType.ExtendedType().GetWidth();
|
2016-10-07 09:39:32 +03:00
|
|
|
if (maybeWidth && *maybeWidth > 0) {
|
|
|
|
videoInfo->mImage.width = *maybeWidth;
|
2018-08-20 18:47:21 +03:00
|
|
|
videoInfo->mDisplay.width = *maybeWidth;
|
2016-10-07 09:39:32 +03:00
|
|
|
}
|
2017-01-18 03:59:03 +03:00
|
|
|
Maybe<int32_t> maybeHeight = aContainerType.ExtendedType().GetHeight();
|
2016-10-07 09:39:32 +03:00
|
|
|
if (maybeHeight && *maybeHeight > 0) {
|
|
|
|
videoInfo->mImage.height = *maybeHeight;
|
2018-08-20 18:47:21 +03:00
|
|
|
videoInfo->mDisplay.height = *maybeHeight;
|
2016-10-07 09:39:32 +03:00
|
|
|
}
|
2018-06-07 17:47:41 +03:00
|
|
|
} else if (trackInfo->GetAsAudioInfo()) {
|
|
|
|
AudioInfo* audioInfo = trackInfo->GetAsAudioInfo();
|
|
|
|
Maybe<int32_t> maybeChannels =
|
|
|
|
aContainerType.ExtendedType().GetChannels();
|
|
|
|
if (maybeChannels && *maybeChannels > 0) {
|
|
|
|
audioInfo->mChannels = *maybeChannels;
|
|
|
|
}
|
|
|
|
Maybe<int32_t> maybeSamplerate =
|
|
|
|
aContainerType.ExtendedType().GetSamplerate();
|
|
|
|
if (maybeSamplerate && *maybeSamplerate > 0) {
|
|
|
|
audioInfo->mRate = *maybeSamplerate;
|
|
|
|
}
|
2016-10-07 09:39:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return trackInfo;
|
|
|
|
}
|
|
|
|
|
2019-05-07 01:41:25 +03:00
|
|
|
bool OnCellularConnection() {
|
|
|
|
uint32_t linkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN;
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
mozilla::dom::ContentChild* cpc =
|
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
if (!cpc) {
|
|
|
|
NS_WARNING("Can't get ContentChild singleton in content process!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
linkType = cpc->NetworkLinkType();
|
|
|
|
} else {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsINetworkLinkService> nls =
|
|
|
|
do_GetService(NS_NETWORK_LINK_SERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Can't get nsINetworkLinkService.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nls->GetLinkType(&linkType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Can't get network link type.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (linkType) {
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_UNKNOWN:
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_ETHERNET:
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_USB:
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_WIFI:
|
|
|
|
return false;
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_WIMAX:
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_2G:
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_3G:
|
|
|
|
case nsINetworkLinkService::LINK_TYPE_4G:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
} // end namespace mozilla
|