blob: e57510dc3064d60320f54541cb74c3bdf9148b64 [file] [log] [blame]
Andreas Huber1b86fe02014-01-29 11:13:26 -08001/*
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 "MediaHTTP"
19#include <utils/Log.h>
20
Marco Nelissenfa8be7d2019-09-23 12:15:57 -070021#include <datasource/MediaHTTP.h>
Andreas Huber1b86fe02014-01-29 11:13:26 -080022
23#include <binder/IServiceManager.h>
24#include <media/stagefright/foundation/ADebug.h>
25#include <media/stagefright/foundation/ALooper.h>
Marco Nelissenfa8be7d2019-09-23 12:15:57 -070026#include <media/stagefright/FoundationUtils.h>
Andreas Huber1b86fe02014-01-29 11:13:26 -080027
Wei Jia73feb8c2017-12-05 14:07:27 -080028#include <media/MediaHTTPConnection.h>
Andreas Huber1b86fe02014-01-29 11:13:26 -080029
30namespace android {
31
Wei Jia73feb8c2017-12-05 14:07:27 -080032MediaHTTP::MediaHTTP(const sp<MediaHTTPConnection> &conn)
Dongwon Kang1e1bcaa2018-08-01 12:44:46 -070033 : ClearMediaHTTP(conn),
Andreas Huber1b86fe02014-01-29 11:13:26 -080034 mDrmManagerClient(NULL) {
Andreas Huber1b86fe02014-01-29 11:13:26 -080035}
36
37MediaHTTP::~MediaHTTP() {
38 clearDRMState_l();
39}
40
Andreas Huber1b86fe02014-01-29 11:13:26 -080041// DRM...
42
43sp<DecryptHandle> MediaHTTP::DrmInitialization(const char* mime) {
44 if (mDrmManagerClient == NULL) {
45 mDrmManagerClient = new DrmManagerClient();
46 }
47
48 if (mDrmManagerClient == NULL) {
49 return NULL;
50 }
51
52 if (mDecryptHandle == NULL) {
53 mDecryptHandle = mDrmManagerClient->openDecryptSession(
54 String8(mLastURI.c_str()), mime);
55 }
56
57 if (mDecryptHandle == NULL) {
58 delete mDrmManagerClient;
59 mDrmManagerClient = NULL;
60 }
61
62 return mDecryptHandle;
63}
64
Andreas Huber1b86fe02014-01-29 11:13:26 -080065void MediaHTTP::clearDRMState_l() {
66 if (mDecryptHandle != NULL) {
67 // To release mDecryptHandle
68 CHECK(mDrmManagerClient);
69 mDrmManagerClient->closeDecryptSession(mDecryptHandle);
70 mDecryptHandle = NULL;
71 }
72}
73
74} // namespace android