tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaInfo.cpp (6090B)


      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/. */
      6 
      7 #include "MediaInfo.h"
      8 
      9 #include "MediaData.h"
     10 
     11 namespace mozilla {
     12 
     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";
     25  }
     26 }
     27 
     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);
     41 }
     42 
     43 nsCString TrackInfo::ToString() const {
     44  nsAutoCString rv;
     45  rv.AppendPrintf(
     46      "(TrackInfo: id:%s kind:%s label:%s language:%s enabled:%s trackid: %d "
     47      "mimetype:%s duration:%s media time:%s crypto:%s rendered externaly: %s "
     48      "type:%s)",
     49      NS_ConvertUTF16toUTF8(mId).get(), NS_ConvertUTF16toUTF8(mKind).get(),
     50      NS_ConvertUTF16toUTF8(mLabel).get(),
     51      NS_ConvertUTF16toUTF8(mLanguage).get(), mEnabled ? "true" : "false",
     52      mTrackId, mMimeType.get(), mDuration.ToString().get(),
     53      mMediaTime.ToString().get(), EnumValueToString(mCrypto.mCryptoScheme),
     54      mIsRenderedExternally ? "true" : "false", TrackTypeToStr(mType));
     55  if (!mTags.IsEmpty()) {
     56    rv.AppendPrintf("\n");
     57    for (const auto& tag : mTags) {
     58      rv.AppendPrintf("%s:%s", tag.mKey.get(), tag.mValue.get());
     59    }
     60  }
     61  return std::move(rv);
     62 }
     63 
     64 bool VideoInfo::operator==(const VideoInfo& rhs) const {
     65  return (TrackInfo::IsEqualTo(rhs) && mDisplay == rhs.mDisplay &&
     66          mStereoMode == rhs.mStereoMode && mImage == rhs.mImage &&
     67          *mCodecSpecificConfig == *rhs.mCodecSpecificConfig &&
     68          *mExtraData == *rhs.mExtraData && mRotation == rhs.mRotation &&
     69          mColorDepth == rhs.mColorDepth && mImageRect == rhs.mImageRect &&
     70          mAlphaPresent == rhs.mAlphaPresent);
     71 }
     72 
     73 nsCString VideoInfo::ToString() const {
     74  std::array YUVColorSpaceStrings = {"BT601", "BT709", "BT2020", "Identity",
     75                                     "Default"};
     76 
     77  std::array ColorDepthStrings = {
     78      "COLOR_8",
     79      "COLOR_10",
     80      "COLOR_12",
     81      "COLOR_16",
     82  };
     83 
     84  std::array TransferFunctionStrings = {
     85      "BT709",
     86      "SRGB",
     87      "PQ",
     88      "HLG",
     89  };
     90 
     91  std::array ColorRangeStrings = {
     92      "LIMITED",
     93      "FULL",
     94  };
     95 
     96  // From gfx::ColorSpace2
     97  std::array ColorPrimariesStrings = {
     98      "Display",     // 0 (Display / UNKNOWN)
     99      "SRGB",        // 1
    100      "DISPLAY_P3",  // 2
    101      "BT601_525",   // 3
    102      "BT709",       // 4 (also BT601_625)
    103      "BT2020",      // 5
    104  };
    105 
    106  nsAutoCString rv;
    107  rv.Append(TrackInfo::ToString());
    108  rv.AppendLiteral(" VideoInfo: ");
    109  rv.AppendPrintf("display size: %dx%d", mDisplay.Width(), mDisplay.Height());
    110  rv.AppendPrintf(", stereo mode: %d", static_cast<int>(mStereoMode));
    111  rv.AppendPrintf(", image size: %dx%d", mImage.Width(), mImage.Height());
    112  if (mCodecSpecificConfig) {
    113    rv.AppendPrintf(", codec specific config: %zu bytes",
    114                    mCodecSpecificConfig->Length());
    115  }
    116  if (mExtraData) {
    117    rv.AppendPrintf(", extra data: %zu bytes", mExtraData->Length());
    118  }
    119  rv.AppendPrintf(", rotation: %d", static_cast<int>(mRotation));
    120  rv.AppendPrintf(", colors: %s",
    121                  ColorDepthStrings[static_cast<int>(mColorDepth)]);
    122  if (mColorSpace) {
    123    rv.AppendPrintf(
    124        ", YUV colorspace: %s",
    125        YUVColorSpaceStrings[static_cast<int>(mColorSpace.value())]);
    126  }
    127  if (mColorPrimaries) {
    128    rv.AppendPrintf(
    129        ", color primaries: %s",
    130        ColorPrimariesStrings[static_cast<int>(mColorPrimaries.value())]);
    131  }
    132  if (mTransferFunction) {
    133    rv.AppendPrintf(
    134        ", transfer function %s",
    135        TransferFunctionStrings[static_cast<int>(mTransferFunction.value())]);
    136  }
    137  rv.AppendPrintf(", color range: %s",
    138                  ColorRangeStrings[static_cast<int>(mColorRange)]);
    139  if (mImageRect) {
    140    rv.AppendPrintf(", image rect: %dx%d", mImageRect->Width(),
    141                    mImageRect->Height());
    142  }
    143  rv.AppendPrintf(", alpha present: %s", mAlphaPresent ? "true" : "false");
    144  if (mFrameRate) {
    145    rv.AppendPrintf(", frame rate: %dHz", mFrameRate.value());
    146  }
    147  return std::move(rv);
    148 }
    149 
    150 bool AudioInfo::operator==(const AudioInfo& rhs) const {
    151  return (TrackInfo::IsEqualTo(rhs) && mRate == rhs.mRate &&
    152          mChannels == rhs.mChannels && mChannelMap == rhs.mChannelMap &&
    153          mBitDepth == rhs.mBitDepth && mProfile == rhs.mProfile &&
    154          mExtendedProfile == rhs.mExtendedProfile &&
    155          mCodecSpecificConfig == rhs.mCodecSpecificConfig);
    156 }
    157 
    158 nsCString AudioInfo::ToString() const {
    159  nsAutoCString rv;
    160  rv.Append(TrackInfo::ToString());
    161  rv.AppendPrintf(
    162      " AudioInfo: %s, %" PRIu32 "Hz, %" PRIu32 "ch (%s) %" PRIu32
    163      "-bits, profile: %" PRIu8 ", extended profile: %" PRIu8 ", %s extradata",
    164      mMimeType.get(), mRate, mChannels,
    165      AudioConfig::ChannelLayout::ChannelMapToString(mChannelMap).get(),
    166      mBitDepth, mProfile, mExtendedProfile,
    167      mCodecSpecificConfig.is<NoCodecSpecificData>() ? "no" : "with");
    168  return std::move(rv);
    169 }
    170 
    171 }  // namespace mozilla