Backed out changeset f594e6f00208 (bug 1940883) for causing crashes in bug 1941164.
[gecko.git] / dom / media / MediaInfo.cpp
blob5433bd4aba3f0db901360ad650e469bed6d9845c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "MediaInfo.h"
9 #include "MediaData.h"
11 namespace mozilla {
13 const char* TrackTypeToStr(TrackInfo::TrackType aTrack) {
14 switch (aTrack) {
15 case TrackInfo::kUndefinedTrack:
16 return "Undefined";
17 case TrackInfo::kAudioTrack:
18 return "Audio";
19 case TrackInfo::kVideoTrack:
20 return "Video";
21 case TrackInfo::kTextTrack:
22 return "Text";
23 default:
24 return "Unknown";
28 bool TrackInfo::IsEqualTo(const TrackInfo& rhs) const {
29 return (
30 mId == rhs.mId && mKind == rhs.mKind && mLabel == rhs.mLabel &&
31 mLanguage == rhs.mLanguage && mEnabled == rhs.mEnabled &&
32 mTrackId == rhs.mTrackId && mMimeType == rhs.mMimeType &&
33 mDuration == rhs.mDuration && mMediaTime == rhs.mMediaTime &&
34 mCrypto.mCryptoScheme == rhs.mCrypto.mCryptoScheme &&
35 mCrypto.mIVSize == rhs.mCrypto.mIVSize &&
36 mCrypto.mKeyId == rhs.mCrypto.mKeyId &&
37 mCrypto.mCryptByteBlock == rhs.mCrypto.mCryptByteBlock &&
38 mCrypto.mSkipByteBlock == rhs.mCrypto.mSkipByteBlock &&
39 mCrypto.mConstantIV == rhs.mCrypto.mConstantIV && mTags == rhs.mTags &&
40 mIsRenderedExternally == rhs.mIsRenderedExternally && mType == rhs.mType);
43 nsCString TrackInfo::ToString() const {
44 nsCString rv;
46 rv.AppendPrintf(
47 "TrackInfo: id:%s kind:%s label:%s language:%s enabled:%s trackid: %d "
48 "mimetype:%s duration:%s media time:%s crypto:%s rendered externaly: %s "
49 "type:%s",
50 NS_ConvertUTF16toUTF8(mId).get(), NS_ConvertUTF16toUTF8(mKind).get(),
51 NS_ConvertUTF16toUTF8(mLabel).get(),
52 NS_ConvertUTF16toUTF8(mLanguage).get(), mEnabled ? "true" : "false",
53 mTrackId, mMimeType.get(), mDuration.ToString().get(),
54 mMediaTime.ToString().get(), EnumValueToString(mCrypto.mCryptoScheme),
55 mIsRenderedExternally ? "true" : "false", TrackTypeToStr(mType));
57 if (!mTags.IsEmpty()) {
58 rv.AppendPrintf("\n");
59 for (const auto& tag : mTags) {
60 rv.AppendPrintf("%s:%s", tag.mKey.get(), tag.mValue.get());
64 return rv;
67 bool VideoInfo::operator==(const VideoInfo& rhs) const {
68 return (TrackInfo::IsEqualTo(rhs) && mDisplay == rhs.mDisplay &&
69 mStereoMode == rhs.mStereoMode && mImage == rhs.mImage &&
70 *mCodecSpecificConfig == *rhs.mCodecSpecificConfig &&
71 *mExtraData == *rhs.mExtraData && mRotation == rhs.mRotation &&
72 mColorDepth == rhs.mColorDepth && mImageRect == rhs.mImageRect &&
73 mAlphaPresent == rhs.mAlphaPresent);
76 bool AudioInfo::operator==(const AudioInfo& rhs) const {
77 return (TrackInfo::IsEqualTo(rhs) && mRate == rhs.mRate &&
78 mChannels == rhs.mChannels && mChannelMap == rhs.mChannelMap &&
79 mBitDepth == rhs.mBitDepth && mProfile == rhs.mProfile &&
80 mExtendedProfile == rhs.mExtendedProfile &&
81 mCodecSpecificConfig == rhs.mCodecSpecificConfig);
84 nsCString AudioInfo::ToString() const {
85 nsCString rv;
87 rv.AppendPrintf(
88 "AudioInfo: %s, %" PRIu32 "Hz, %" PRIu32 "ch (%s) %" PRIu32
89 "-bits, profile: %" PRIu8 ", extended profile: %" PRIu8 ", %s extradata",
90 mMimeType.get(), mRate, mChannels,
91 AudioConfig::ChannelLayout::ChannelMapToString(mChannelMap).get(),
92 mBitDepth, mProfile, mExtendedProfile,
93 mCodecSpecificConfig.is<NoCodecSpecificData>() ? "no" : "with");
95 return rv;
98 } // namespace mozilla