Skip to content

Commit a693a4b

Browse files
jefftinkerAndroid (Google) Code Review
authored andcommitted
Merge "Fix ANRs due to Widevine DRM plugin sniff taking too long." into ics-mr1
2 parents 8e0ecbf + d0d19db commit a693a4b

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

media/libstagefright/AwesomePlayer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,14 +2091,16 @@ status_t AwesomePlayer::finishSetDataSource_l() {
20912091
String8 mimeType;
20922092
float confidence;
20932093
sp<AMessage> dummy;
2094-
bool success = SniffDRM(dataSource, &mimeType, &confidence, &dummy);
2094+
bool success = SniffWVM(dataSource, &mimeType, &confidence, &dummy);
20952095

20962096
if (!success
20972097
|| strcasecmp(
20982098
mimeType.string(), MEDIA_MIMETYPE_CONTAINER_WVM)) {
20992099
return ERROR_UNSUPPORTED;
21002100
}
21012101

2102+
dataSource->DrmInitialization();
2103+
21022104
mWVMExtractor = new WVMExtractor(dataSource);
21032105
mWVMExtractor->setAdaptiveStreamingMode(true);
21042106
extractor = mWVMExtractor;

media/libstagefright/DRMExtractor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ bool SniffDRM(
282282
if (decryptHandle != NULL) {
283283
if (decryptHandle->decryptApiType == DecryptApiType::CONTAINER_BASED) {
284284
*mimeType = String8("drm+container_based+") + decryptHandle->mimeType;
285+
*confidence = 10.0f;
285286
} else if (decryptHandle->decryptApiType == DecryptApiType::ELEMENTARY_STREAM_BASED) {
286287
*mimeType = String8("drm+es_based+") + decryptHandle->mimeType;
287-
} else if (decryptHandle->decryptApiType == DecryptApiType::WV_BASED) {
288-
*mimeType = MEDIA_MIMETYPE_CONTAINER_WVM;
289-
LOGW("SniffWVM: found match\n");
288+
*confidence = 10.0f;
289+
} else {
290+
return false;
290291
}
291-
*confidence = 10.0f;
292292

293293
return true;
294294
}

media/libstagefright/DataSource.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "include/DRMExtractor.h"
2727
#include "include/FLACExtractor.h"
2828
#include "include/AACExtractor.h"
29+
#include "include/WVMExtractor.h"
2930

3031
#include "matroska/MatroskaExtractor.h"
3132

@@ -113,6 +114,7 @@ void DataSource::RegisterDefaultSniffers() {
113114
RegisterSniffer(SniffMP3);
114115
RegisterSniffer(SniffAAC);
115116
RegisterSniffer(SniffMPEG2PS);
117+
RegisterSniffer(SniffWVM);
116118

117119
char value[PROPERTY_VALUE_MAX];
118120
if (property_get("drm.service.enabled", value, NULL)

media/libstagefright/WVMExtractor.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,12 @@ namespace android {
4545
static Mutex gWVMutex;
4646

4747
WVMExtractor::WVMExtractor(const sp<DataSource> &source)
48-
: mDataSource(source) {
49-
{
50-
Mutex::Autolock autoLock(gWVMutex);
51-
if (gVendorLibHandle == NULL) {
52-
gVendorLibHandle = dlopen("libwvm.so", RTLD_NOW);
53-
}
48+
: mDataSource(source)
49+
{
50+
Mutex::Autolock autoLock(gWVMutex);
5451

55-
if (gVendorLibHandle == NULL) {
56-
LOGE("Failed to open libwvm.so");
57-
return;
58-
}
52+
if (!getVendorLibHandle()) {
53+
return;
5954
}
6055

6156
typedef WVMLoadableExtractor *(*GetInstanceFunc)(sp<DataSource>);
@@ -71,6 +66,19 @@ WVMExtractor::WVMExtractor(const sp<DataSource> &source)
7166
}
7267
}
7368

69+
bool WVMExtractor::getVendorLibHandle()
70+
{
71+
if (gVendorLibHandle == NULL) {
72+
gVendorLibHandle = dlopen("libwvm.so", RTLD_NOW);
73+
}
74+
75+
if (gVendorLibHandle == NULL) {
76+
LOGE("Failed to open libwvm.so");
77+
}
78+
79+
return gVendorLibHandle != NULL;
80+
}
81+
7482
WVMExtractor::~WVMExtractor() {
7583
}
7684

@@ -113,5 +121,33 @@ void WVMExtractor::setAdaptiveStreamingMode(bool adaptive) {
113121
}
114122
}
115123

124+
bool SniffWVM(
125+
const sp<DataSource> &source, String8 *mimeType, float *confidence,
126+
sp<AMessage> *) {
127+
128+
Mutex::Autolock autoLock(gWVMutex);
129+
130+
if (!WVMExtractor::getVendorLibHandle()) {
131+
return false;
132+
}
133+
134+
typedef WVMLoadableExtractor *(*SnifferFunc)(sp<DataSource>);
135+
SnifferFunc snifferFunc =
136+
(SnifferFunc) dlsym(gVendorLibHandle,
137+
"_ZN7android15IsWidevineMediaENS_2spINS_10DataSourceEEE");
138+
139+
if (snifferFunc) {
140+
if ((*snifferFunc)(source)) {
141+
*mimeType = MEDIA_MIMETYPE_CONTAINER_WVM;
142+
*confidence = 10.0f;
143+
return true;
144+
}
145+
} else {
146+
LOGE("IsWidevineMedia not found in libwvm.so");
147+
}
148+
149+
return false;
150+
}
151+
116152
} //namespace android
117153

media/libstagefright/include/WVMExtractor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace android {
2525

26+
struct AMessage;
27+
class String8;
2628
class DataSource;
2729

2830
class WVMLoadableExtractor : public MediaExtractor {
@@ -58,6 +60,8 @@ class WVMExtractor : public MediaExtractor {
5860
// is used.
5961
void setAdaptiveStreamingMode(bool adaptive);
6062

63+
static bool getVendorLibHandle();
64+
6165
protected:
6266
virtual ~WVMExtractor();
6367

@@ -69,6 +73,10 @@ class WVMExtractor : public MediaExtractor {
6973
WVMExtractor &operator=(const WVMExtractor &);
7074
};
7175

76+
bool SniffWVM(
77+
const sp<DataSource> &source, String8 *mimeType, float *confidence,
78+
sp<AMessage> *);
79+
7280
} // namespace android
7381

7482
#endif // DRM_EXTRACTOR_H_

0 commit comments

Comments
 (0)