Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 1 | /* |
| 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 Nelissen | fa8be7d | 2019-09-23 12:15:57 -0700 | [diff] [blame^] | 21 | #include <datasource/MediaHTTP.h> |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 22 | |
| 23 | #include <binder/IServiceManager.h> |
| 24 | #include <media/stagefright/foundation/ADebug.h> |
| 25 | #include <media/stagefright/foundation/ALooper.h> |
Marco Nelissen | fa8be7d | 2019-09-23 12:15:57 -0700 | [diff] [blame^] | 26 | #include <media/stagefright/FoundationUtils.h> |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 27 | |
Wei Jia | 73feb8c | 2017-12-05 14:07:27 -0800 | [diff] [blame] | 28 | #include <media/MediaHTTPConnection.h> |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Wei Jia | 73feb8c | 2017-12-05 14:07:27 -0800 | [diff] [blame] | 32 | MediaHTTP::MediaHTTP(const sp<MediaHTTPConnection> &conn) |
Dongwon Kang | 1e1bcaa | 2018-08-01 12:44:46 -0700 | [diff] [blame] | 33 | : ClearMediaHTTP(conn), |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 34 | mDrmManagerClient(NULL) { |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | MediaHTTP::~MediaHTTP() { |
| 38 | clearDRMState_l(); |
| 39 | } |
| 40 | |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 41 | // DRM... |
| 42 | |
| 43 | sp<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 Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 65 | void 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 |