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
|
|
|
|
|
|
|
|
#include "nsSize.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "ImageTypes.h"
|
2014-07-04 07:55:06 +04:00
|
|
|
#include "nsString.h"
|
2015-03-23 05:31:15 +03:00
|
|
|
#include "nsTArray.h"
|
2015-02-24 08:06:54 +03:00
|
|
|
#include "StreamBuffer.h" // for TrackID
|
2014-02-04 05:49:21 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-07-04 07:55:06 +04:00
|
|
|
struct TrackInfo {
|
|
|
|
void Init(const nsAString& aId,
|
|
|
|
const nsAString& aKind,
|
|
|
|
const nsAString& aLabel,
|
|
|
|
const nsAString& aLanguage,
|
2015-02-24 08:06:54 +03:00
|
|
|
bool aEnabled,
|
|
|
|
TrackID aOutputId = TRACK_INVALID)
|
2014-07-04 07:55:06 +04:00
|
|
|
{
|
|
|
|
mId = aId;
|
|
|
|
mKind = aKind;
|
|
|
|
mLabel = aLabel;
|
|
|
|
mLanguage = aLanguage;
|
|
|
|
mEnabled = aEnabled;
|
2015-02-24 08:06:54 +03:00
|
|
|
mOutputId = aOutputId;
|
2014-07-04 07:55:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsString mId;
|
|
|
|
nsString mKind;
|
|
|
|
nsString mLabel;
|
|
|
|
nsString mLanguage;
|
|
|
|
bool mEnabled;
|
2015-02-24 08:06:54 +03:00
|
|
|
TrackID mOutputId;
|
2014-07-04 07:55:06 +04:00
|
|
|
};
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
// Stores info relevant to presenting media frames.
|
|
|
|
class VideoInfo {
|
2015-02-02 11:49:00 +03:00
|
|
|
private:
|
2015-02-10 02:32:21 +03:00
|
|
|
void Init(int32_t aWidth, int32_t aHeight, bool aHasVideo)
|
2015-02-02 11:49:00 +03:00
|
|
|
{
|
2015-02-10 02:32:21 +03:00
|
|
|
mDisplay = nsIntSize(aWidth, aHeight);
|
|
|
|
mStereoMode = StereoMode::MONO;
|
|
|
|
mHasVideo = aHasVideo;
|
|
|
|
|
|
|
|
// TODO: TrackInfo should be initialized by its specific codec decoder.
|
|
|
|
// This following call should be removed once we have that implemented.
|
|
|
|
mTrackInfo.Init(NS_LITERAL_STRING("2"), NS_LITERAL_STRING("main"),
|
2015-02-24 08:06:54 +03:00
|
|
|
EmptyString(), EmptyString(), true, 2);
|
2015-02-02 11:49:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
VideoInfo()
|
2014-07-04 07:55:06 +04:00
|
|
|
{
|
2015-02-10 02:32:21 +03:00
|
|
|
Init(0, 0, false);
|
2014-07-04 07:55:06 +04:00
|
|
|
}
|
2014-02-04 05:49:21 +04:00
|
|
|
|
2015-02-02 11:49:00 +03:00
|
|
|
VideoInfo(int32_t aWidth, int32_t aHeight)
|
|
|
|
{
|
2015-02-10 02:32:21 +03:00
|
|
|
Init(aWidth, aHeight, true);
|
2015-02-02 11:49:00 +03:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
nsIntSize mDisplay;
|
|
|
|
|
|
|
|
// Indicates the frame layout for single track stereo videos.
|
|
|
|
StereoMode mStereoMode;
|
|
|
|
|
|
|
|
// True if we have an active video bitstream.
|
|
|
|
bool mHasVideo;
|
2014-07-04 07:55:06 +04:00
|
|
|
|
|
|
|
TrackInfo mTrackInfo;
|
2014-02-04 05:49:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class AudioInfo {
|
|
|
|
public:
|
|
|
|
AudioInfo()
|
|
|
|
: mRate(44100)
|
|
|
|
, mChannels(2)
|
|
|
|
, mHasAudio(false)
|
2014-07-04 07:55:06 +04:00
|
|
|
{
|
|
|
|
// TODO: TrackInfo should be initialized by its specific codec decoder.
|
|
|
|
// This following call should be removed once we have that implemented.
|
|
|
|
mTrackInfo.Init(NS_LITERAL_STRING("1"), NS_LITERAL_STRING("main"),
|
2015-02-24 08:06:54 +03:00
|
|
|
EmptyString(), EmptyString(), true, 1);
|
2014-07-04 07:55:06 +04:00
|
|
|
}
|
2014-02-04 05:49:21 +04:00
|
|
|
|
|
|
|
// Sample rate.
|
|
|
|
uint32_t mRate;
|
|
|
|
|
|
|
|
// Number of audio channels.
|
|
|
|
uint32_t mChannels;
|
|
|
|
|
|
|
|
// True if we have an active audio bitstream.
|
|
|
|
bool mHasAudio;
|
2014-07-04 07:55:06 +04:00
|
|
|
|
|
|
|
TrackInfo mTrackInfo;
|
2014-02-04 05:49:21 +04:00
|
|
|
};
|
|
|
|
|
2015-03-23 05:31:15 +03:00
|
|
|
class EncryptionInfo {
|
2014-02-04 05:49:21 +04:00
|
|
|
public:
|
2015-04-01 10:36:00 +03:00
|
|
|
struct InitData {
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return !mInitDatas.IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename AInitDatas>
|
|
|
|
void AddInitData(const nsAString& aType, AInitDatas&& aInitData)
|
|
|
|
{
|
|
|
|
mInitDatas.AppendElement(InitData(aType, Forward<AInitDatas>(aInitData)));
|
|
|
|
}
|
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-03-23 05:31:15 +03:00
|
|
|
|
2015-04-01 10:36:00 +03:00
|
|
|
// One 'InitData' per encrypted buffer.
|
|
|
|
InitDatas mInitDatas;
|
2015-03-23 05:31:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class MediaInfo {
|
|
|
|
public:
|
2014-02-04 05:49:21 +04:00
|
|
|
bool HasVideo() const
|
|
|
|
{
|
|
|
|
return mVideo.mHasVideo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasAudio() const
|
|
|
|
{
|
|
|
|
return mAudio.mHasAudio;
|
|
|
|
}
|
|
|
|
|
2015-03-23 05:31:15 +03:00
|
|
|
bool IsEncrypted() const
|
|
|
|
{
|
2015-04-01 10:36:00 +03:00
|
|
|
return mCrypto.IsEncrypted();
|
2015-03-23 05:31:15 +03:00
|
|
|
}
|
|
|
|
|
2014-02-04 05:49:21 +04:00
|
|
|
bool HasValidMedia() const
|
|
|
|
{
|
|
|
|
return HasVideo() || HasAudio();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
EncryptionInfo mCrypto;
|
2014-02-04 05:49:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MediaInfo_h
|