• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "media_key_system_mock.h"
17 #include "native_mediakeysession.h"
18 #include "native_mediakeysystem.h"
19 
20 namespace OHOS {
21 namespace MediaAVCodec {
22 #define CLEARPLAY_NAME "com.clearplay.drm"
23 #define WISEPLAY_NAME "com.wiseplay.drm"
24 #define UKNOWN_NAME "unknown_name"
25 
GetDrmUuid()26 static const char *GetDrmUuid()
27 {
28     if (OH_MediaKeySystem_IsSupported(CLEARPLAY_NAME)) {
29         return CLEARPLAY_NAME;
30     } else if (OH_MediaKeySystem_IsSupported(WISEPLAY_NAME)) {
31         return WISEPLAY_NAME;
32     }
33     return UKNOWN_NAME;
34 }
35 
MediaKeySystemCapiMock()36 MediaKeySystemCapiMock::MediaKeySystemCapiMock()
37 {}
38 
~MediaKeySystemCapiMock()39 MediaKeySystemCapiMock::~MediaKeySystemCapiMock()
40 {
41     (void)OH_MediaKeySession_Destroy(mediaKeySession_);
42     (void)OH_MediaKeySystem_Destroy(mediaKeySystem_);
43 }
44 
CreateMediaKeySystem()45 int32_t MediaKeySystemCapiMock::CreateMediaKeySystem()
46 {
47     return OH_MediaKeySystem_Create(GetDrmUuid(), &mediaKeySystem_);
48 }
49 
CreateMediaKeySession()50 int32_t MediaKeySystemCapiMock::CreateMediaKeySession()
51 {
52     int32_t ret = AV_ERR_UNKNOWN;
53     if (mediaKeySystem_ == nullptr) {
54         return ret;
55     }
56     DRM_ContentProtectionLevel contentProtectionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
57     ret = OH_MediaKeySystem_CreateMediaKeySession(mediaKeySystem_, &contentProtectionLevel, &mediaKeySession_);
58     return ret;
59 }
60 
GetMediaKeySystem()61 MediaKeySystem *MediaKeySystemCapiMock::GetMediaKeySystem()
62 {
63     return mediaKeySystem_;
64 }
65 
GetMediaKeySession()66 MediaKeySession *MediaKeySystemCapiMock::GetMediaKeySession()
67 {
68     return mediaKeySession_;
69 }
70 
71 } // namespace MediaAVCodec
72 } // namespace OHOS