DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1a169f1e113d)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
/* -*- 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/. */

#ifndef mozilla_dom_media_MediaIPCUtils_h
#define mozilla_dom_media_MediaIPCUtils_h

#include "PlatformDecoderModule.h"
#include "ipc/IPCMessageUtils.h"
#include "mozilla/GfxMessageUtils.h"
#include "mozilla/gfx/Rect.h"

namespace IPC {
template <>
struct ParamTraits<mozilla::VideoInfo> {
  typedef mozilla::VideoInfo paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    // TrackInfo
    WriteParam(aMsg, aParam.mMimeType);

    // VideoInfo
    WriteParam(aMsg, aParam.mDisplay);
    WriteParam(aMsg, aParam.mStereoMode);
    WriteParam(aMsg, aParam.mImage);
    WriteParam(aMsg, aParam.ImageRect());
    WriteParam(aMsg, *aParam.mCodecSpecificConfig);
    WriteParam(aMsg, *aParam.mExtraData);
    WriteParam(aMsg, aParam.mRotation);
    WriteParam(aMsg, aParam.mColorDepth);
    WriteParam(aMsg, aParam.mColorSpace);
    WriteParam(aMsg, aParam.mColorRange);
    WriteParam(aMsg, aParam.HasAlpha());
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    mozilla::gfx::IntRect imageRect;
    bool alphaPresent;
    if (ReadParam(aMsg, aIter, &aResult->mMimeType) &&
        ReadParam(aMsg, aIter, &aResult->mDisplay) &&
        ReadParam(aMsg, aIter, &aResult->mStereoMode) &&
        ReadParam(aMsg, aIter, &aResult->mImage) &&
        ReadParam(aMsg, aIter, &imageRect) &&
        ReadParam(aMsg, aIter, aResult->mCodecSpecificConfig.get()) &&
        ReadParam(aMsg, aIter, aResult->mExtraData.get()) &&
        ReadParam(aMsg, aIter, &aResult->mRotation) &&
        ReadParam(aMsg, aIter, &aResult->mColorDepth) &&
        ReadParam(aMsg, aIter, &aResult->mColorSpace) &&
        ReadParam(aMsg, aIter, &aResult->mColorRange) &&
        ReadParam(aMsg, aIter, &alphaPresent)) {
      aResult->SetImageRect(imageRect);
      aResult->SetAlpha(alphaPresent);
      return true;
    }
    return false;
  }
};

template <>
struct ParamTraits<mozilla::TrackInfo::TrackType>
    : public ContiguousEnumSerializerInclusive<
          mozilla::TrackInfo::TrackType,
          mozilla::TrackInfo::TrackType::kUndefinedTrack,
          mozilla::TrackInfo::TrackType::kTextTrack> {};

template <>
struct ParamTraits<mozilla::VideoInfo::Rotation>
    : public ContiguousEnumSerializerInclusive<
          mozilla::VideoInfo::Rotation, mozilla::VideoInfo::Rotation::kDegree_0,
          mozilla::VideoInfo::Rotation::kDegree_270> {};

template <>
struct ParamTraits<mozilla::MediaByteBuffer>
    : public ParamTraits<nsTArray<uint8_t>> {
  typedef mozilla::MediaByteBuffer paramType;
};

template <>
struct ParamTraits<mozilla::AudioInfo> {
  typedef mozilla::AudioInfo paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    // TrackInfo
    WriteParam(aMsg, aParam.mMimeType);

    // AudioInfo
    WriteParam(aMsg, aParam.mRate);
    WriteParam(aMsg, aParam.mChannels);
    WriteParam(aMsg, aParam.mChannelMap);
    WriteParam(aMsg, aParam.mBitDepth);
    WriteParam(aMsg, aParam.mProfile);
    WriteParam(aMsg, aParam.mExtendedProfile);
    WriteParam(aMsg, *aParam.mCodecSpecificConfig);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    if (ReadParam(aMsg, aIter, &aResult->mMimeType) &&
        ReadParam(aMsg, aIter, &aResult->mRate) &&
        ReadParam(aMsg, aIter, &aResult->mChannels) &&
        ReadParam(aMsg, aIter, &aResult->mChannelMap) &&
        ReadParam(aMsg, aIter, &aResult->mBitDepth) &&
        ReadParam(aMsg, aIter, &aResult->mProfile) &&
        ReadParam(aMsg, aIter, &aResult->mExtendedProfile) &&
        ReadParam(aMsg, aIter, aResult->mCodecSpecificConfig.get())) {
      return true;
    }
    return false;
  }
};

template <>
struct ParamTraits<mozilla::MediaDataDecoder::ConversionRequired>
    : public ContiguousEnumSerializerInclusive<
          mozilla::MediaDataDecoder::ConversionRequired,
          mozilla::MediaDataDecoder::ConversionRequired(0),
          mozilla::MediaDataDecoder::ConversionRequired(
              mozilla::MediaDataDecoder::ConversionRequired::kNeedAnnexB)> {};

template <>
struct ParamTraits<mozilla::media::TimeUnit> {
  typedef mozilla::media::TimeUnit paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.IsValid());
    WriteParam(aMsg, aParam.IsValid() ? aParam.ToMicroseconds() : 0);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    bool valid;
    int64_t value;
    if (ReadParam(aMsg, aIter, &valid) && ReadParam(aMsg, aIter, &value)) {
      if (!valid) {
        *aResult = mozilla::media::TimeUnit::Invalid();
      } else {
        *aResult = mozilla::media::TimeUnit::FromMicroseconds(value);
      }
      return true;
    }
    return false;
  };
};

template <>
struct ParamTraits<mozilla::media::TimeInterval> {
  typedef mozilla::media::TimeInterval paramType;

  static void Write(Message* aMsg, const paramType& aParam) {
    WriteParam(aMsg, aParam.mStart);
    WriteParam(aMsg, aParam.mEnd);
    WriteParam(aMsg, aParam.mFuzz);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter,
                   paramType* aResult) {
    if (ReadParam(aMsg, aIter, &aResult->mStart) &&
        ReadParam(aMsg, aIter, &aResult->mEnd) &&
        ReadParam(aMsg, aIter, &aResult->mFuzz)) {
      return true;
    }
    return false;
  }
};

}  // namespace IPC

#endif  // mozilla_dom_media_MediaIPCUtils_h