Bumping manifests a=b2g-bump
[gecko.git] / media / gmp-clearkey / 0.1 / ClearKeySession.cpp
blob05cb29a61dba50898b75909f9a5a7620ee4ef9e1
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "ClearKeyDecryptionManager.h"
6 #include "ClearKeySession.h"
7 #include "ClearKeyUtils.h"
8 #include "ClearKeyStorage.h"
9 #include "gmp-task-utils.h"
11 #include "gmp-api/gmp-decryption.h"
12 #include "mozilla/Endian.h"
14 using namespace mozilla;
16 ClearKeySession::ClearKeySession(const std::string& aSessionId,
17 GMPDecryptorCallback* aCallback,
18 GMPSessionType aSessionType)
19 : mSessionId(aSessionId)
20 , mCallback(aCallback)
21 , mSessionType(aSessionType)
23 CK_LOGD("ClearKeySession ctor %p", this);
26 ClearKeySession::~ClearKeySession()
28 CK_LOGD("ClearKeySession dtor %p", this);
30 auto& keyIds = GetKeyIds();
31 for (auto it = keyIds.begin(); it != keyIds.end(); it++) {
32 MOZ_ASSERT(ClearKeyDecryptionManager::Get()->HasKeyForKeyId(*it));
34 ClearKeyDecryptionManager::Get()->ReleaseKeyId(*it);
35 mCallback->KeyStatusChanged(&mSessionId[0], mSessionId.size(),
36 &(*it)[0], it->size(),
37 kGMPUnknown);
41 void
42 ClearKeySession::Init(uint32_t aCreateSessionToken,
43 uint32_t aPromiseId,
44 const uint8_t* aInitData, uint32_t aInitDataSize)
46 CK_LOGD("ClearKeySession::Init");
48 ClearKeyUtils::ParseInitData(aInitData, aInitDataSize, mKeyIds);
49 if (!mKeyIds.size()) {
50 const char message[] = "Couldn't parse cenc key init data";
51 mCallback->RejectPromise(aPromiseId, kGMPAbortError, message, strlen(message));
52 return;
55 mCallback->SetSessionId(aCreateSessionToken, &mSessionId[0], mSessionId.length());
57 mCallback->ResolvePromise(aPromiseId);
60 GMPSessionType
61 ClearKeySession::Type() const
63 return mSessionType;
66 void
67 ClearKeySession::AddKeyId(const KeyId& aKeyId)
69 mKeyIds.push_back(aKeyId);