nsresult
GMPAudioDecoderParent::InitDecode(GMPAudioCodecType aCodecType,
                                  uint32_t aChannelCount,
                                  uint32_t aBitsPerChannel,
                                  uint32_t aSamplesPerSecond,
                                  nsTArray<uint8_t>& aExtraData,
                                  GMPAudioDecoderCallbackProxy* aCallback)
{
  if (mIsOpen) {
    NS_WARNING("Trying to re-init an in-use GMP audio decoder!");
    return NS_ERROR_FAILURE;
  }

  MOZ_ASSERT(mPlugin->GMPThread() == NS_GetCurrentThread());

  if (!aCallback) {
    return NS_ERROR_FAILURE;
  }
  mCallback = aCallback;

  GMPAudioCodecData data;
  data.mCodecType() = aCodecType;
  data.mChannelCount() = aChannelCount;
  data.mBitsPerChannel() = aBitsPerChannel;
  data.mSamplesPerSecond() = aSamplesPerSecond;
  data.mExtraData() = aExtraData;
  if (!SendInitDecode(data)) {
    return NS_ERROR_FAILURE;
  }
  mIsOpen = true;

  // Async IPC, we don't have access to a return value.
  return NS_OK;
}
bool
GMPAudioDecoderChild::RecvInitDecode(const GMPAudioCodecData& a)
{
  MOZ_ASSERT(mAudioDecoder);
  if (!mAudioDecoder) {
    return false;
  }

  GMPAudioCodec codec;
  codec.mCodecType = a.mCodecType();
  codec.mChannelCount = a.mChannelCount();
  codec.mBitsPerChannel = a.mBitsPerChannel();
  codec.mSamplesPerSecond = a.mSamplesPerSecond();
  codec.mExtraData = a.mExtraData().Elements();
  codec.mExtraDataLen = a.mExtraData().Length();

  // Ignore any return code. It is OK for this to fail without killing the process.
  mAudioDecoder->InitDecode(codec, this);

  return true;
}