• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 
30 namespace android {
31 
PlayerServiceMediaHTTP(const sp<MediaHTTPConnection> & conn)32 PlayerServiceMediaHTTP::PlayerServiceMediaHTTP(const sp<MediaHTTPConnection> &conn)
33     : MediaHTTP(conn),
34       mDrmManagerClient(NULL) {
35     (void) DrmInitialization(nullptr);
36 }
37 
~PlayerServiceMediaHTTP()38 PlayerServiceMediaHTTP::~PlayerServiceMediaHTTP() {
39     clearDRMState_l();
40 }
41 
42 // DRM...
43 
DrmInitialization(const char * mime)44 sp<DecryptHandle> PlayerServiceMediaHTTP::DrmInitialization(const char *mime) {
45     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 
clearDRMState_l()66 void 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
76