blob: f99a8610b01c7e3e0a59c8d28499a050fb5d160f [file] [log] [blame]
Dongwon Kang9c6f7902019-10-14 11:16:39 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "PlayerServiceMediaHTTP"
19#include <utils/Log.h>
20
21#include <datasource/PlayerServiceMediaHTTP.h>
22
23#include <binder/IServiceManager.h>
24#include <media/stagefright/foundation/ADebug.h>
25#include <media/stagefright/foundation/ALooper.h>
26#include <media/stagefright/FoundationUtils.h>
27
28#include <media/MediaHTTPConnection.h>
29
30namespace android {
31
32PlayerServiceMediaHTTP::PlayerServiceMediaHTTP(const sp<MediaHTTPConnection> &conn)
33 : MediaHTTP(conn),
34 mDrmManagerClient(NULL) {
Marco Nelissen19b0be62019-11-15 07:51:15 -080035 (void) DrmInitialization(nullptr);
Dongwon Kang9c6f7902019-10-14 11:16:39 -070036}
37
38PlayerServiceMediaHTTP::~PlayerServiceMediaHTTP() {
39 clearDRMState_l();
40}
41
42// DRM...
43
Marco Nelissen19b0be62019-11-15 07:51:15 -080044sp<DecryptHandle> PlayerServiceMediaHTTP::DrmInitialization(const char *mime) {
Dongwon Kang9c6f7902019-10-14 11:16:39 -070045 if (mDrmManagerClient == NULL) {
46 mDrmManagerClient = new DrmManagerClient();
47 }
48
49 if (mDrmManagerClient == NULL) {
50 return NULL;
51 }
52
53 if (mDecryptHandle == NULL) {
54 mDecryptHandle = mDrmManagerClient->openDecryptSession(
55 String8(mLastURI.c_str()), mime);
56 }
57
58 if (mDecryptHandle == NULL) {
59 delete mDrmManagerClient;
60 mDrmManagerClient = NULL;
61 }
62
63 return mDecryptHandle;
64}
65
66void PlayerServiceMediaHTTP::clearDRMState_l() {
67 if (mDecryptHandle != NULL) {
68 // To release mDecryptHandle
69 CHECK(mDrmManagerClient);
70 mDrmManagerClient->closeDecryptSession(mDecryptHandle);
71 mDecryptHandle = NULL;
72 }
73}
74
75} // namespace android