2014-02-04 05:49:21 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
#if !defined(MediaInfo_h)
|
|
|
|
#define MediaInfo_h
|
|
|
|
|
2015-05-01 08:26:51 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2017-07-20 04:56:08 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2014-07-04 07:55:06 +04:00
|
|
|
#include "nsString.h"
|
2015-03-23 05:31:15 +03:00
|
|
|
#include "nsTArray.h"
|
2015-04-14 08:15:46 +03:00
|
|
|
#include "ImageTypes.h"
|
|
|
|
#include "MediaData.h"
|
2017-08-30 06:24:54 +03:00
|
|
|
#include "TrackID.h" // for TrackID
|
2015-05-31 07:18:12 +03:00
|
|
|
#include "TimeUnits.h"
|
2017-08-29 05:00:33 +03:00
|
|
|
#include "mozilla/gfx/Point.h" // for gfx::IntSize
|
|
|
|
#include "mozilla/gfx/Rect.h" // for gfx::IntRect
|
2014-02-04 05:49:21 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-05-01 08:26:50 +03:00
|
|
|
class AudioInfo;
|
|
|
|
class VideoInfo;
|
|
|
|
class TextInfo;
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class MetadataTag
|
|
|
|
{
|
2016-01-08 03:22:53 +03:00
|
|
|
public:
|
|
|
|
MetadataTag(const nsACString& aKey,
|
|
|
|
const nsACString& aValue)
|
|
|
|
: mKey(aKey)
|
|
|
|
, mValue(aValue)
|
2017-01-27 15:20:37 +03:00
|
|
|
{
|
|
|
|
}
|
2016-01-08 03:22:53 +03:00
|
|
|
nsCString mKey;
|
|
|
|
nsCString mValue;
|
|
|
|
};
|
|
|
|
|
2017-07-20 04:56:08 +03:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> MetadataTags;
|
|
|
|
|
2016-04-27 10:34:41 +03:00
|
|
|
// Maximum channel number we can currently handle (7.1)
|
|
|
|
#define MAX_AUDIO_CHANNELS 8
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class TrackInfo
|
|
|
|
{
|
2015-04-14 08:15:46 +03:00
|
|
|
public:
|
2017-01-27 15:20:37 +03:00
|
|
|
enum TrackType
|
|
|
|
{
|
2015-04-14 08:15:46 +03:00
|
|
|
kUndefinedTrack,
|
|
|
|
kAudioTrack,
|
|
|
|
kVideoTrack,
|
|
|
|
kTextTrack
|
|
|
|
};
|
|
|
|
TrackInfo(TrackType aType,
|
|
|
|
const nsAString& aId,
|
|
|
|
const nsAString& aKind,
|
|
|
|
const nsAString& aLabel,
|
|
|
|
const nsAString& aLanguage,
|
|
|
|
bool aEnabled,
|
2015-10-30 14:59:26 +03:00
|
|
|
TrackID aTrackId)
|
2015-04-14 08:15:46 +03:00
|
|
|
: mId(aId)
|
|
|
|
, mKind(aKind)
|
|
|
|
, mLabel(aLabel)
|
|
|
|
, mLanguage(aLanguage)
|
|
|
|
, mEnabled(aEnabled)
|
|
|
|
, mTrackId(aTrackId)
|
2015-08-06 09:24:00 +03:00
|
|
|
, mIsRenderedExternally(false)
|
2015-04-14 08:15:46 +03:00
|
|
|
, mType(aType)
|
|
|
|
{
|
2015-05-01 08:26:50 +03:00
|
|
|
MOZ_COUNT_CTOR(TrackInfo);
|
2015-04-14 08:15:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only used for backward compatibility. Do not use in new code.
|
2015-10-30 14:59:26 +03:00
|
|
|
void Init(const nsAString& aId,
|
2014-07-04 07:55:06 +04:00
|
|
|
const nsAString& aKind,
|
|
|
|
const nsAString& aLabel,
|
|
|
|
const nsAString& aLanguage,
|
2015-10-30 14:59:26 +03:00
|
|
|
bool aEnabled)
|
2014-07-04 07:55:06 +04:00
|
|
|
{
|
|
|
|
mId = aId;
|
|
|
|
mKind = aKind;
|
|
|
|
mLabel = aLabel;
|
|
|
|
mLanguage = aLanguage;
|
|
|
|
mEnabled = aEnabled;
|
|
|
|
}
|
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
// Fields common with MediaTrack object.
|
2014-07-04 07:55:06 +04:00
|
|
|
nsString mId;
|
|
|
|
nsString mKind;
|
|
|
|
nsString mLabel;
|
|
|
|
nsString mLanguage;
|
|
|
|
bool mEnabled;
|
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
TrackID mTrackId;
|
|
|
|
|
2015-11-19 12:00:39 +03:00
|
|
|
nsCString mMimeType;
|
2017-04-12 11:41:36 +03:00
|
|
|
media::TimeUnit mDuration;
|
2017-04-12 11:53:09 +03:00
|
|
|
media::TimeUnit mMediaTime;
|
2015-04-14 08:15:46 +03:00
|
|
|
CryptoTrack mCrypto;
|
|
|
|
|
2016-01-08 03:22:53 +03:00
|
|
|
nsTArray<MetadataTag> mTags;
|
|
|
|
|
2015-08-06 09:24:00 +03:00
|
|
|
// True if the track is gonna be (decrypted)/decoded and
|
|
|
|
// rendered directly by non-gecko components.
|
|
|
|
bool mIsRenderedExternally;
|
|
|
|
|
2015-05-01 08:26:50 +03:00
|
|
|
virtual AudioInfo* GetAsAudioInfo()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual VideoInfo* GetAsVideoInfo()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual TextInfo* GetAsTextInfo()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual const AudioInfo* GetAsAudioInfo() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual const VideoInfo* GetAsVideoInfo() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual const TextInfo* GetAsTextInfo() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
bool IsAudio() const
|
|
|
|
{
|
2015-05-01 08:26:50 +03:00
|
|
|
return !!GetAsAudioInfo();
|
2015-04-14 08:15:46 +03:00
|
|
|
}
|
|
|
|
bool IsVideo() const
|
|
|
|
{
|
2015-05-01 08:26:50 +03:00
|
|
|
return !!GetAsVideoInfo();
|
2015-04-14 08:15:46 +03:00
|
|
|
}
|
|
|
|
bool IsText() const
|
|
|
|
{
|
2015-05-01 08:26:50 +03:00
|
|
|
return !!GetAsTextInfo();
|
2015-04-14 08:15:46 +03:00
|
|
|
}
|
|
|
|
TrackType GetType() const
|
2015-02-02 11:49:00 +03:00
|
|
|
{
|
2015-04-14 08:15:46 +03:00
|
|
|
return mType;
|
2015-02-02 11:49:00 +03:00
|
|
|
}
|
2015-05-01 08:26:51 +03:00
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
bool virtual IsValid() const = 0;
|
|
|
|
|
2015-05-01 08:26:51 +03:00
|
|
|
virtual UniquePtr<TrackInfo> Clone() const = 0;
|
|
|
|
|
2015-05-01 08:26:50 +03:00
|
|
|
virtual ~TrackInfo()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TrackInfo);
|
|
|
|
}
|
|
|
|
|
2015-05-01 08:26:51 +03:00
|
|
|
protected:
|
|
|
|
TrackInfo(const TrackInfo& aOther)
|
|
|
|
{
|
|
|
|
mId = aOther.mId;
|
|
|
|
mKind = aOther.mKind;
|
|
|
|
mLabel = aOther.mLabel;
|
|
|
|
mLanguage = aOther.mLanguage;
|
|
|
|
mEnabled = aOther.mEnabled;
|
|
|
|
mTrackId = aOther.mTrackId;
|
|
|
|
mMimeType = aOther.mMimeType;
|
|
|
|
mDuration = aOther.mDuration;
|
|
|
|
mMediaTime = aOther.mMediaTime;
|
|
|
|
mCrypto = aOther.mCrypto;
|
2015-08-06 09:24:00 +03:00
|
|
|
mIsRenderedExternally = aOther.mIsRenderedExternally;
|
2015-05-01 08:26:51 +03:00
|
|
|
mType = aOther.mType;
|
2016-01-08 03:22:53 +03:00
|
|
|
mTags = aOther.mTags;
|
2015-05-01 08:26:51 +03:00
|
|
|
MOZ_COUNT_CTOR(TrackInfo);
|
|
|
|
}
|
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
private:
|
|
|
|
TrackType mType;
|
|
|
|
};
|
2015-02-02 11:49:00 +03:00
|
|
|
|
2017-02-27 09:05:41 +03:00
|
|
|
// String version of track type.
|
2017-02-27 09:15:36 +03:00
|
|
|
const char* TrackTypeToStr(TrackInfo::TrackType aTrack);
|
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
// Stores info relevant to presenting media frames.
|
2017-01-27 15:20:37 +03:00
|
|
|
class VideoInfo : public TrackInfo
|
|
|
|
{
|
2015-02-02 11:49:00 +03:00
|
|
|
public:
|
2017-01-27 15:20:37 +03:00
|
|
|
enum Rotation
|
|
|
|
{
|
2016-05-12 21:17:39 +03:00
|
|
|
kDegree_0 = 0,
|
|
|
|
kDegree_90 = 90,
|
|
|
|
kDegree_180 = 180,
|
|
|
|
kDegree_270 = 270,
|
|
|
|
};
|
2015-02-02 11:49:00 +03:00
|
|
|
VideoInfo()
|
2015-04-14 08:17:51 +03:00
|
|
|
: VideoInfo(-1, -1)
|
2014-07-04 07:55:06 +04:00
|
|
|
{
|
|
|
|
}
|
2014-02-04 05:49:21 +04:00
|
|
|
|
2016-06-28 08:56:55 +03:00
|
|
|
explicit VideoInfo(int32_t aWidth, int32_t aHeight)
|
2017-08-29 05:00:33 +03:00
|
|
|
: VideoInfo(gfx::IntSize(aWidth, aHeight))
|
2016-06-28 08:56:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:00:33 +03:00
|
|
|
explicit VideoInfo(const gfx::IntSize& aSize)
|
|
|
|
: TrackInfo(kVideoTrack,
|
|
|
|
NS_LITERAL_STRING("2"),
|
|
|
|
NS_LITERAL_STRING("main"),
|
|
|
|
EmptyString(),
|
|
|
|
EmptyString(),
|
|
|
|
true,
|
|
|
|
2)
|
2016-06-28 08:56:55 +03:00
|
|
|
, mDisplay(aSize)
|
2015-04-14 08:15:46 +03:00
|
|
|
, mStereoMode(StereoMode::MONO)
|
2016-06-28 08:56:55 +03:00
|
|
|
, mImage(aSize)
|
2015-04-20 16:57:29 +03:00
|
|
|
, mCodecSpecificConfig(new MediaByteBuffer)
|
2015-04-15 08:27:38 +03:00
|
|
|
, mExtraData(new MediaByteBuffer)
|
2016-05-12 21:17:39 +03:00
|
|
|
, mRotation(kDegree_0)
|
2017-08-29 05:00:33 +03:00
|
|
|
, mImageRect(gfx::IntRect(gfx::IntPoint(), aSize))
|
2015-04-14 08:15:46 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-01 08:26:51 +03:00
|
|
|
VideoInfo(const VideoInfo& aOther)
|
|
|
|
: TrackInfo(aOther)
|
|
|
|
, mDisplay(aOther.mDisplay)
|
|
|
|
, mStereoMode(aOther.mStereoMode)
|
|
|
|
, mImage(aOther.mImage)
|
|
|
|
, mCodecSpecificConfig(aOther.mCodecSpecificConfig)
|
|
|
|
, mExtraData(aOther.mExtraData)
|
2016-05-12 21:17:39 +03:00
|
|
|
, mRotation(aOther.mRotation)
|
2017-10-17 06:17:23 +03:00
|
|
|
, mBitDepth(aOther.mBitDepth)
|
2016-04-15 09:10:24 +03:00
|
|
|
, mImageRect(aOther.mImageRect)
|
2016-11-23 01:52:16 +03:00
|
|
|
, mAlphaPresent(aOther.mAlphaPresent)
|
2015-05-01 08:26:51 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
bool IsValid() const override
|
2015-02-02 11:49:00 +03:00
|
|
|
{
|
2016-07-19 08:01:53 +03:00
|
|
|
return mDisplay.width > 0 && mDisplay.height > 0;
|
2015-02-02 11:49:00 +03:00
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
VideoInfo* GetAsVideoInfo() override
|
2015-05-01 08:26:50 +03:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
const VideoInfo* GetAsVideoInfo() const override
|
2015-05-01 08:26:50 +03:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
UniquePtr<TrackInfo> Clone() const override
|
2015-05-01 08:26:51 +03:00
|
|
|
{
|
|
|
|
return MakeUnique<VideoInfo>(*this);
|
|
|
|
}
|
|
|
|
|
2016-11-23 01:52:16 +03:00
|
|
|
void SetAlpha(bool aAlphaPresent)
|
|
|
|
{
|
|
|
|
mAlphaPresent = aAlphaPresent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasAlpha() const
|
|
|
|
{
|
|
|
|
return mAlphaPresent;
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:00:33 +03:00
|
|
|
gfx::IntRect ImageRect() const
|
2016-04-15 09:10:24 +03:00
|
|
|
{
|
2017-08-14 15:30:10 +03:00
|
|
|
if (mImageRect.Width() < 0 || mImageRect.Height() < 0) {
|
2017-08-29 05:00:33 +03:00
|
|
|
return gfx::IntRect(0, 0, mImage.width, mImage.height);
|
2016-04-15 09:10:24 +03:00
|
|
|
}
|
|
|
|
return mImageRect;
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:00:33 +03:00
|
|
|
void SetImageRect(const gfx::IntRect& aRect) { mImageRect = aRect; }
|
2016-04-15 09:10:24 +03:00
|
|
|
|
2016-04-15 09:39:15 +03:00
|
|
|
// Returned the crop rectangle scaled to aWidth/aHeight size relative to
|
|
|
|
// mImage size.
|
|
|
|
// If aWidth and aHeight are identical to the original mImage.width/mImage.height
|
|
|
|
// then the scaling ratio will be 1.
|
|
|
|
// This is used for when the frame size is different from what the container
|
|
|
|
// reports. This is legal in WebM, and we will preserve the ratio of the crop
|
|
|
|
// rectangle as it was reported relative to the picture size reported by the
|
|
|
|
// container.
|
2017-08-29 05:00:33 +03:00
|
|
|
gfx::IntRect ScaledImageRect(int64_t aWidth, int64_t aHeight) const
|
2016-04-15 09:39:15 +03:00
|
|
|
{
|
2017-09-04 12:27:43 +03:00
|
|
|
if ((aWidth == mImage.width && aHeight == mImage.height) ||
|
|
|
|
!mImage.width ||
|
|
|
|
!mImage.height) {
|
2016-04-15 09:39:15 +03:00
|
|
|
return ImageRect();
|
|
|
|
}
|
2017-10-12 11:40:50 +03:00
|
|
|
|
2017-08-29 05:00:33 +03:00
|
|
|
gfx::IntRect imageRect = ImageRect();
|
2017-10-12 11:40:50 +03:00
|
|
|
int64_t w = (aWidth * imageRect.Width()) / mImage.width;
|
|
|
|
int64_t h = (aHeight * imageRect.Height()) / mImage.height;
|
|
|
|
if (!w || !h) {
|
|
|
|
return imageRect;
|
|
|
|
}
|
|
|
|
|
2016-04-15 09:39:15 +03:00
|
|
|
imageRect.x = (imageRect.x * aWidth) / mImage.width;
|
|
|
|
imageRect.y = (imageRect.y * aHeight) / mImage.height;
|
2017-10-12 11:40:50 +03:00
|
|
|
imageRect.SetWidth(w);
|
|
|
|
imageRect.SetHeight(h);
|
2016-04-15 09:39:15 +03:00
|
|
|
return imageRect;
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:49:01 +03:00
|
|
|
Rotation ToSupportedRotation(int32_t aDegree) const
|
2016-05-12 21:17:39 +03:00
|
|
|
{
|
|
|
|
switch (aDegree) {
|
|
|
|
case 90:
|
|
|
|
return kDegree_90;
|
|
|
|
case 180:
|
|
|
|
return kDegree_180;
|
|
|
|
case 270:
|
|
|
|
return kDegree_270;
|
|
|
|
default:
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(aDegree == 0, "Invalid rotation degree, ignored");
|
2016-05-12 21:17:39 +03:00
|
|
|
return kDegree_0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
// Size in pixels at which the video is rendered. This is after it has
|
|
|
|
// been scaled by its aspect ratio.
|
2017-08-29 05:00:33 +03:00
|
|
|
gfx::IntSize mDisplay;
|
2014-02-04 05:49:21 +04:00
|
|
|
|
|
|
|
// Indicates the frame layout for single track stereo videos.
|
|
|
|
StereoMode mStereoMode;
|
|
|
|
|
2016-04-15 09:10:24 +03:00
|
|
|
// Size of the decoded video's image.
|
2017-08-29 05:00:33 +03:00
|
|
|
gfx::IntSize mImage;
|
2016-04-15 09:10:24 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaByteBuffer> mCodecSpecificConfig;
|
|
|
|
RefPtr<MediaByteBuffer> mExtraData;
|
2016-04-15 09:10:24 +03:00
|
|
|
|
2016-05-12 21:17:39 +03:00
|
|
|
// Describing how many degrees video frames should be rotated in clock-wise to
|
|
|
|
// get correct view.
|
|
|
|
Rotation mRotation;
|
|
|
|
|
2017-10-17 06:17:23 +03:00
|
|
|
// Should be 8, 10 or 12. Default value is 8.
|
|
|
|
uint8_t mBitDepth = 8;
|
|
|
|
|
2016-04-15 09:10:24 +03:00
|
|
|
private:
|
|
|
|
// mImage may be cropped; currently only used with the WebM container.
|
|
|
|
// A negative width or height indicate that no cropping is to occur.
|
2017-08-29 05:00:33 +03:00
|
|
|
gfx::IntRect mImageRect;
|
2016-11-23 01:52:16 +03:00
|
|
|
|
|
|
|
// Indicates whether or not frames may contain alpha information.
|
|
|
|
bool mAlphaPresent = false;
|
2014-02-04 05:49:21 +04:00
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class AudioInfo : public TrackInfo
|
|
|
|
{
|
2014-02-04 05:49:21 +04:00
|
|
|
public:
|
|
|
|
AudioInfo()
|
2015-04-14 08:15:46 +03:00
|
|
|
: TrackInfo(kAudioTrack, NS_LITERAL_STRING("1"), NS_LITERAL_STRING("main"),
|
|
|
|
EmptyString(), EmptyString(), true, 1)
|
|
|
|
, mRate(0)
|
|
|
|
, mChannels(0)
|
|
|
|
, mBitDepth(0)
|
|
|
|
, mProfile(0)
|
|
|
|
, mExtendedProfile(0)
|
2015-04-15 08:27:38 +03:00
|
|
|
, mCodecSpecificConfig(new MediaByteBuffer)
|
|
|
|
, mExtraData(new MediaByteBuffer)
|
2014-07-04 07:55:06 +04:00
|
|
|
{
|
|
|
|
}
|
2014-02-04 05:49:21 +04:00
|
|
|
|
2015-05-01 08:26:51 +03:00
|
|
|
AudioInfo(const AudioInfo& aOther)
|
|
|
|
: TrackInfo(aOther)
|
|
|
|
, mRate(aOther.mRate)
|
|
|
|
, mChannels(aOther.mChannels)
|
|
|
|
, mBitDepth(aOther.mBitDepth)
|
|
|
|
, mProfile(aOther.mProfile)
|
|
|
|
, mExtendedProfile(aOther.mExtendedProfile)
|
|
|
|
, mCodecSpecificConfig(aOther.mCodecSpecificConfig)
|
|
|
|
, mExtraData(aOther.mExtraData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-11 13:15:55 +03:00
|
|
|
static const uint32_t MAX_RATE = 640000;
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
bool IsValid() const override
|
2015-05-01 08:26:50 +03:00
|
|
|
{
|
2017-09-04 12:27:43 +03:00
|
|
|
return mChannels > 0 && mChannels <= MAX_AUDIO_CHANNELS &&
|
|
|
|
mRate > 0 && mRate <= MAX_RATE;
|
2015-05-01 08:26:50 +03:00
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
AudioInfo* GetAsAudioInfo() override
|
2015-05-01 08:26:50 +03:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
const AudioInfo* GetAsAudioInfo() const override
|
2015-05-01 08:26:50 +03:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
UniquePtr<TrackInfo> Clone() const override
|
2015-05-01 08:26:51 +03:00
|
|
|
{
|
|
|
|
return MakeUnique<AudioInfo>(*this);
|
|
|
|
}
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
// Sample rate.
|
|
|
|
uint32_t mRate;
|
|
|
|
|
|
|
|
// Number of audio channels.
|
|
|
|
uint32_t mChannels;
|
|
|
|
|
2015-04-14 08:15:46 +03:00
|
|
|
// Bits per sample.
|
|
|
|
uint32_t mBitDepth;
|
|
|
|
|
|
|
|
// Codec profile.
|
|
|
|
int8_t mProfile;
|
|
|
|
|
|
|
|
// Extended codec profile.
|
|
|
|
int8_t mExtendedProfile;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaByteBuffer> mCodecSpecificConfig;
|
|
|
|
RefPtr<MediaByteBuffer> mExtraData;
|
2014-02-04 05:49:21 +04:00
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class EncryptionInfo
|
|
|
|
{
|
2014-02-04 05:49:21 +04:00
|
|
|
public:
|
2015-06-24 03:19:05 +03:00
|
|
|
EncryptionInfo()
|
|
|
|
: mEncrypted(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
struct InitData
|
|
|
|
{
|
2015-04-01 10:36:00 +03:00
|
|
|
template<typename AInitDatas>
|
|
|
|
InitData(const nsAString& aType, AInitDatas&& aInitData)
|
|
|
|
: mType(aType)
|
|
|
|
, mInitData(Forward<AInitDatas>(aInitData))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encryption type to be passed to JS. Usually `cenc'.
|
|
|
|
nsString mType;
|
|
|
|
|
|
|
|
// Encryption data.
|
|
|
|
nsTArray<uint8_t> mInitData;
|
|
|
|
};
|
|
|
|
typedef nsTArray<InitData> InitDatas;
|
2015-03-23 05:31:15 +03:00
|
|
|
|
2015-04-01 10:36:00 +03:00
|
|
|
// True if the stream has encryption metadata
|
|
|
|
bool IsEncrypted() const
|
|
|
|
{
|
2015-06-24 03:19:05 +03:00
|
|
|
return mEncrypted;
|
2015-04-01 10:36:00 +03:00
|
|
|
}
|
|
|
|
|
2017-01-12 06:33:55 +03:00
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mEncrypted = false;
|
|
|
|
mInitDatas.Clear();
|
|
|
|
}
|
|
|
|
|
2015-04-01 10:36:00 +03:00
|
|
|
template<typename AInitDatas>
|
|
|
|
void AddInitData(const nsAString& aType, AInitDatas&& aInitData)
|
|
|
|
{
|
|
|
|
mInitDatas.AppendElement(InitData(aType, Forward<AInitDatas>(aInitData)));
|
2015-06-24 03:19:05 +03:00
|
|
|
mEncrypted = true;
|
2015-04-01 10:36:00 +03:00
|
|
|
}
|
2015-01-27 09:10:11 +03:00
|
|
|
|
2015-04-01 10:36:00 +03:00
|
|
|
void AddInitData(const EncryptionInfo& aInfo)
|
|
|
|
{
|
|
|
|
mInitDatas.AppendElements(aInfo.mInitDatas);
|
2015-06-24 03:19:05 +03:00
|
|
|
mEncrypted = !!mInitDatas.Length();
|
2015-04-01 10:36:00 +03:00
|
|
|
}
|
2015-03-23 05:31:15 +03:00
|
|
|
|
2015-04-01 10:36:00 +03:00
|
|
|
// One 'InitData' per encrypted buffer.
|
|
|
|
InitDatas mInitDatas;
|
2015-06-24 03:19:05 +03:00
|
|
|
private:
|
|
|
|
bool mEncrypted;
|
2015-03-23 05:31:15 +03:00
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class MediaInfo
|
|
|
|
{
|
2015-03-23 05:31:15 +03:00
|
|
|
public:
|
2014-02-04 05:49:21 +04:00
|
|
|
bool HasVideo() const
|
|
|
|
{
|
2015-04-14 08:17:51 +03:00
|
|
|
return mVideo.IsValid();
|
2014-02-04 05:49:21 +04:00
|
|
|
}
|
|
|
|
|
2015-07-16 12:15:06 +03:00
|
|
|
void EnableVideo()
|
|
|
|
{
|
|
|
|
if (HasVideo()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Set dummy values so that HasVideo() will return true;
|
|
|
|
// See VideoInfo::IsValid()
|
2017-08-29 05:00:33 +03:00
|
|
|
mVideo.mDisplay = gfx::IntSize(1, 1);
|
2015-07-16 12:15:06 +03:00
|
|
|
}
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
bool HasAudio() const
|
|
|
|
{
|
2015-04-14 08:17:51 +03:00
|
|
|
return mAudio.IsValid();
|
2014-02-04 05:49:21 +04:00
|
|
|
}
|
|
|
|
|
2015-07-16 12:15:06 +03:00
|
|
|
void EnableAudio()
|
|
|
|
{
|
|
|
|
if (HasAudio()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Set dummy values so that HasAudio() will return true;
|
|
|
|
// See AudioInfo::IsValid()
|
|
|
|
mAudio.mChannels = 2;
|
|
|
|
mAudio.mRate = 44100;
|
|
|
|
}
|
|
|
|
|
2015-03-23 05:31:15 +03:00
|
|
|
bool IsEncrypted() const
|
|
|
|
{
|
2017-09-04 12:27:43 +03:00
|
|
|
return (HasAudio() && mAudio.mCrypto.mValid) ||
|
|
|
|
(HasVideo() && mVideo.mCrypto.mValid);
|
2015-03-23 05:31:15 +03:00
|
|
|
}
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
bool HasValidMedia() const
|
|
|
|
{
|
|
|
|
return HasVideo() || HasAudio();
|
|
|
|
}
|
|
|
|
|
2015-10-30 14:59:26 +03:00
|
|
|
void AssertValid() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!HasAudio() || mAudio.mTrackId != TRACK_INVALID,
|
|
|
|
"Audio track ID must be valid");
|
|
|
|
NS_ASSERTION(!HasVideo() || mVideo.mTrackId != TRACK_INVALID,
|
|
|
|
"Audio track ID must be valid");
|
2017-09-04 12:27:43 +03:00
|
|
|
NS_ASSERTION(!HasAudio() || !HasVideo() ||
|
|
|
|
mAudio.mTrackId != mVideo.mTrackId,
|
2015-10-30 14:59:26 +03:00
|
|
|
"Duplicate track IDs");
|
|
|
|
}
|
|
|
|
|
2014-07-04 07:55:06 +04:00
|
|
|
// TODO: Store VideoInfo and AudioIndo in arrays to support multi-tracks.
|
2014-02-04 05:49:21 +04:00
|
|
|
VideoInfo mVideo;
|
|
|
|
AudioInfo mAudio;
|
2015-03-23 05:31:15 +03:00
|
|
|
|
2015-05-31 07:18:12 +03:00
|
|
|
// If the metadata includes a duration, we store it here.
|
|
|
|
media::NullableTimeUnit mMetadataDuration;
|
|
|
|
|
|
|
|
// The Ogg reader tries to kinda-sorta compute the duration by seeking to the
|
|
|
|
// end and determining the timestamp of the last frame. This isn't useful as
|
|
|
|
// a duration until we know the start time, so we need to track it separately.
|
2015-06-07 00:48:07 +03:00
|
|
|
media::NullableTimeUnit mUnadjustedMetadataEndTime;
|
2015-05-31 07:18:12 +03:00
|
|
|
|
2015-12-02 10:42:32 +03:00
|
|
|
// True if the media is seekable (i.e. supports random access).
|
|
|
|
bool mMediaSeekable = true;
|
|
|
|
|
2016-02-04 07:31:21 +03:00
|
|
|
// True if the media is only seekable within its buffered ranges.
|
|
|
|
bool mMediaSeekableOnlyInBufferedRanges = false;
|
|
|
|
|
2015-03-23 05:31:15 +03:00
|
|
|
EncryptionInfo mCrypto;
|
2016-10-27 10:21:05 +03:00
|
|
|
|
|
|
|
// The minimum of start times of audio and video tracks.
|
|
|
|
// Use to map the zero time on the media timeline to the first frame.
|
|
|
|
media::TimeUnit mStartTime;
|
2014-02-04 05:49:21 +04:00
|
|
|
};
|
|
|
|
|
2017-02-13 21:18:05 +03:00
|
|
|
class TrackInfoSharedPtr
|
2017-01-27 15:20:37 +03:00
|
|
|
{
|
2017-02-13 21:18:05 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TrackInfoSharedPtr)
|
2015-06-12 08:18:05 +03:00
|
|
|
public:
|
2017-02-13 21:18:05 +03:00
|
|
|
TrackInfoSharedPtr(const TrackInfo& aOriginal, uint32_t aStreamID)
|
2015-06-12 08:18:05 +03:00
|
|
|
: mInfo(aOriginal.Clone())
|
|
|
|
, mStreamSourceID(aStreamID)
|
|
|
|
, mMimeType(mInfo->mMimeType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetID() const
|
|
|
|
{
|
|
|
|
return mStreamSourceID;
|
|
|
|
}
|
|
|
|
|
2017-02-13 21:18:05 +03:00
|
|
|
operator const TrackInfo*() const
|
|
|
|
{
|
|
|
|
return mInfo.get();
|
|
|
|
}
|
|
|
|
|
2015-06-12 08:18:05 +03:00
|
|
|
const TrackInfo* operator*() const
|
|
|
|
{
|
|
|
|
return mInfo.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const TrackInfo* operator->() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInfo.get(), "dereferencing a UniquePtr containing nullptr");
|
|
|
|
return mInfo.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const AudioInfo* GetAsAudioInfo() const
|
|
|
|
{
|
|
|
|
return mInfo ? mInfo->GetAsAudioInfo() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VideoInfo* GetAsVideoInfo() const
|
|
|
|
{
|
|
|
|
return mInfo ? mInfo->GetAsVideoInfo() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TextInfo* GetAsTextInfo() const
|
|
|
|
{
|
|
|
|
return mInfo ? mInfo->GetAsTextInfo() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-02-13 21:18:05 +03:00
|
|
|
~TrackInfoSharedPtr() { }
|
2015-06-12 08:18:05 +03:00
|
|
|
UniquePtr<TrackInfo> mInfo;
|
|
|
|
// A unique ID, guaranteed to change when changing streams.
|
|
|
|
uint32_t mStreamSourceID;
|
|
|
|
|
|
|
|
public:
|
2015-11-19 12:00:39 +03:00
|
|
|
const nsCString& mMimeType;
|
2015-06-12 08:18:05 +03:00
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class AudioConfig
|
|
|
|
{
|
2016-04-06 03:20:42 +03:00
|
|
|
public:
|
2017-01-27 15:20:37 +03:00
|
|
|
enum Channel
|
|
|
|
{
|
2016-04-06 03:20:42 +03:00
|
|
|
CHANNEL_INVALID = -1,
|
|
|
|
CHANNEL_MONO = 0,
|
|
|
|
CHANNEL_LEFT,
|
|
|
|
CHANNEL_RIGHT,
|
|
|
|
CHANNEL_CENTER,
|
|
|
|
CHANNEL_LS,
|
|
|
|
CHANNEL_RS,
|
|
|
|
CHANNEL_RLS,
|
|
|
|
CHANNEL_RCENTER,
|
|
|
|
CHANNEL_RRS,
|
|
|
|
CHANNEL_LFE,
|
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
class ChannelLayout
|
|
|
|
{
|
2016-04-06 03:20:42 +03:00
|
|
|
public:
|
2017-01-27 15:20:37 +03:00
|
|
|
ChannelLayout() : mChannelMap(0), mValid(false) { }
|
2016-04-06 03:20:42 +03:00
|
|
|
explicit ChannelLayout(uint32_t aChannels)
|
|
|
|
: ChannelLayout(aChannels, SMPTEDefault(aChannels))
|
2017-01-27 15:20:37 +03:00
|
|
|
{
|
|
|
|
}
|
2016-04-06 03:20:42 +03:00
|
|
|
ChannelLayout(uint32_t aChannels, const Channel* aConfig)
|
2016-04-20 09:18:01 +03:00
|
|
|
: ChannelLayout()
|
2016-04-06 03:20:42 +03:00
|
|
|
{
|
2016-04-16 07:35:32 +03:00
|
|
|
if (!aConfig) {
|
|
|
|
mValid = false;
|
|
|
|
return;
|
|
|
|
}
|
2016-04-06 03:20:42 +03:00
|
|
|
mChannels.AppendElements(aConfig, aChannels);
|
|
|
|
UpdateChannelMap();
|
|
|
|
}
|
|
|
|
bool operator==(const ChannelLayout& aOther) const
|
|
|
|
{
|
|
|
|
return mChannels == aOther.mChannels;
|
|
|
|
}
|
|
|
|
bool operator!=(const ChannelLayout& aOther) const
|
|
|
|
{
|
|
|
|
return mChannels != aOther.mChannels;
|
|
|
|
}
|
|
|
|
const Channel& operator[](uint32_t aIndex) const
|
|
|
|
{
|
|
|
|
return mChannels[aIndex];
|
|
|
|
}
|
|
|
|
uint32_t Count() const
|
|
|
|
{
|
|
|
|
return mChannels.Length();
|
|
|
|
}
|
|
|
|
uint32_t Map() const
|
|
|
|
{
|
|
|
|
return mChannelMap;
|
|
|
|
}
|
2016-04-07 08:11:59 +03:00
|
|
|
// Calculate the mapping table from the current layout to aOther such that
|
|
|
|
// one can easily go from one layout to the other by doing:
|
|
|
|
// out[channel] = in[map[channel]].
|
|
|
|
// Returns true if the reordering is possible or false otherwise.
|
|
|
|
// If true, then aMap, if set, will be updated to contain the mapping table
|
|
|
|
// allowing conversion from the current layout to aOther.
|
|
|
|
// If aMap is nullptr, then MappingTable can be used to simply determine if
|
|
|
|
// the current layout can be easily reordered to aOther.
|
|
|
|
// aMap must be an array of size MAX_AUDIO_CHANNELS.
|
|
|
|
bool MappingTable(const ChannelLayout& aOther, uint8_t* aMap = nullptr) const;
|
2017-01-27 15:20:37 +03:00
|
|
|
bool IsValid() const { return mValid; }
|
2016-04-06 03:20:42 +03:00
|
|
|
bool HasChannel(Channel aChannel) const
|
|
|
|
{
|
|
|
|
return mChannelMap & (1 << aChannel);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void UpdateChannelMap();
|
|
|
|
const Channel* SMPTEDefault(uint32_t aChannels) const;
|
|
|
|
AutoTArray<Channel, MAX_AUDIO_CHANNELS> mChannels;
|
|
|
|
uint32_t mChannelMap;
|
|
|
|
bool mValid;
|
|
|
|
};
|
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
enum SampleFormat
|
|
|
|
{
|
2016-04-06 03:20:42 +03:00
|
|
|
FORMAT_NONE = 0,
|
|
|
|
FORMAT_U8,
|
|
|
|
FORMAT_S16,
|
|
|
|
FORMAT_S24LSB,
|
|
|
|
FORMAT_S24,
|
|
|
|
FORMAT_S32,
|
|
|
|
FORMAT_FLT,
|
|
|
|
#if defined(MOZ_SAMPLE_TYPE_FLOAT32)
|
|
|
|
FORMAT_DEFAULT = FORMAT_FLT
|
|
|
|
#elif defined(MOZ_SAMPLE_TYPE_S16)
|
|
|
|
FORMAT_DEFAULT = FORMAT_S16
|
|
|
|
#else
|
|
|
|
#error "Not supported audio type"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
AudioConfig(const ChannelLayout& aChannelLayout, uint32_t aRate,
|
|
|
|
AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT,
|
|
|
|
bool aInterleaved = true);
|
|
|
|
// Will create a channel configuration from default SMPTE ordering.
|
|
|
|
AudioConfig(uint32_t aChannels, uint32_t aRate,
|
|
|
|
AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT,
|
|
|
|
bool aInterleaved = true);
|
|
|
|
|
|
|
|
const ChannelLayout& Layout() const
|
|
|
|
{
|
|
|
|
return mChannelLayout;
|
|
|
|
}
|
|
|
|
uint32_t Channels() const
|
|
|
|
{
|
|
|
|
if (!mChannelLayout.IsValid()) {
|
|
|
|
return mChannels;
|
|
|
|
}
|
|
|
|
return mChannelLayout.Count();
|
|
|
|
}
|
|
|
|
uint32_t Rate() const
|
|
|
|
{
|
|
|
|
return mRate;
|
|
|
|
}
|
|
|
|
SampleFormat Format() const
|
|
|
|
{
|
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
bool Interleaved() const
|
|
|
|
{
|
|
|
|
return mInterleaved;
|
|
|
|
}
|
2016-04-11 13:57:29 +03:00
|
|
|
bool operator==(const AudioConfig& aOther) const
|
|
|
|
{
|
2017-09-04 12:27:43 +03:00
|
|
|
return mChannelLayout == aOther.mChannelLayout && mRate == aOther.mRate &&
|
|
|
|
mFormat == aOther.mFormat && mInterleaved == aOther.mInterleaved;
|
2016-04-11 13:57:29 +03:00
|
|
|
}
|
|
|
|
bool operator!=(const AudioConfig& aOther) const
|
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
2016-04-06 03:20:42 +03:00
|
|
|
|
2016-04-27 10:34:41 +03:00
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return mChannelLayout.IsValid() && Format() != FORMAT_NONE && Rate() > 0;
|
|
|
|
}
|
|
|
|
|
2016-04-06 03:20:42 +03:00
|
|
|
static const char* FormatToString(SampleFormat aFormat);
|
|
|
|
static uint32_t SampleSize(SampleFormat aFormat);
|
|
|
|
static uint32_t FormatToBits(SampleFormat aFormat);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Channels configuration.
|
|
|
|
ChannelLayout mChannelLayout;
|
|
|
|
|
|
|
|
// Channel count.
|
|
|
|
uint32_t mChannels;
|
|
|
|
|
|
|
|
// Sample rate.
|
|
|
|
uint32_t mRate;
|
|
|
|
|
|
|
|
// Sample format.
|
|
|
|
SampleFormat mFormat;
|
|
|
|
|
|
|
|
bool mInterleaved;
|
|
|
|
};
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MediaInfo_h
|