mirror of
				https://github.com/mozilla/gecko-dev.git
				synced 2025-11-04 10:18:41 +02:00 
			
		
		
		
	# skip-blame Differential Revision: https://phabricator.services.mozilla.com/D12251 --HG-- extra : moz-landing-system : lando
		
			
				
	
	
		
			46 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 | 
						|
/* 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/. */
 | 
						|
 | 
						|
#include "DecryptJob.h"
 | 
						|
#include "mozilla/Atomics.h"
 | 
						|
 | 
						|
namespace mozilla {
 | 
						|
 | 
						|
static Atomic<uint32_t> sDecryptJobInstanceCount(0u);
 | 
						|
 | 
						|
DecryptJob::DecryptJob(MediaRawData* aSample)
 | 
						|
    : mId(++sDecryptJobInstanceCount), mSample(aSample) {}
 | 
						|
 | 
						|
RefPtr<DecryptPromise> DecryptJob::Ensure() {
 | 
						|
  return mPromise.Ensure(__func__);
 | 
						|
}
 | 
						|
 | 
						|
void DecryptJob::PostResult(DecryptStatus aResult) {
 | 
						|
  nsTArray<uint8_t> empty;
 | 
						|
  PostResult(aResult, empty);
 | 
						|
}
 | 
						|
 | 
						|
void DecryptJob::PostResult(DecryptStatus aResult,
 | 
						|
                            Span<const uint8_t> aDecryptedData) {
 | 
						|
  if (aDecryptedData.Length() != mSample->Size()) {
 | 
						|
    NS_WARNING("CDM returned incorrect number of decrypted bytes");
 | 
						|
  }
 | 
						|
  if (aResult == eme::Ok) {
 | 
						|
    UniquePtr<MediaRawDataWriter> writer(mSample->CreateWriter());
 | 
						|
    PodCopy(writer->Data(), aDecryptedData.Elements(),
 | 
						|
            std::min<size_t>(aDecryptedData.Length(), mSample->Size()));
 | 
						|
  } else if (aResult == eme::NoKeyErr) {
 | 
						|
    NS_WARNING("CDM returned NoKeyErr");
 | 
						|
    // We still have the encrypted sample, so we can re-enqueue it to be
 | 
						|
    // decrypted again once the key is usable again.
 | 
						|
  } else {
 | 
						|
    nsAutoCString str("CDM returned decode failure DecryptStatus=");
 | 
						|
    str.AppendInt(aResult);
 | 
						|
    NS_WARNING(str.get());
 | 
						|
  }
 | 
						|
  mPromise.Resolve(DecryptResult(aResult, mSample), __func__);
 | 
						|
}
 | 
						|
 | 
						|
}  // namespace mozilla
 |