Skip to content

Commit d0d19db

Browse files
committed
Fix ANRs due to Widevine DRM plugin sniff taking too long.
Add a Widevine-specific format sniffer to avoid having to refetch data from the remote server. Change-Id: I5fdb21fe7a0d6e74f2a6f06e6fbf8070b068ac60 related-to-bug: 5725548
1 parent 5a7c917 commit d0d19db

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
@@ -2055,14 +2055,16 @@ status_t AwesomePlayer::finishSetDataSource_l() {
20552055
String8 mimeType;
20562056
float confidence;
20572057
sp<AMessage> dummy;
2058-
bool success = SniffDRM(dataSource, &mimeType, &confidence, &dummy);
2058+
bool success = SniffWVM(dataSource, &mimeType, &confidence, &dummy);
20592059

20602060
if (!success
20612061
|| strcasecmp(
20622062
mimeType.string(), MEDIA_MIMETYPE_CONTAINER_WVM)) {
20632063
return ERROR_UNSUPPORTED;
20642064
}
20652065

2066+
dataSource->DrmInitialization();
2067+
20662068
mWVMExtractor = new WVMExtractor(dataSource);
20672069
mWVMExtractor->setAdaptiveStreamingMode(true);
20682070
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
@@ -27,6 +27,7 @@
2727
#include "include/DRMExtractor.h"
2828
#include "include/FLACExtractor.h"
2929
#include "include/AACExtractor.h"
30+
#include "include/WVMExtractor.h"
3031

3132
#include "matroska/MatroskaExtractor.h"
3233

@@ -115,6 +116,7 @@ void DataSource::RegisterDefaultSniffers() {
115116
RegisterSniffer(SniffAAC);
116117
RegisterSniffer(SniffAVI);
117118
RegisterSniffer(SniffMPEG2PS);
119+
RegisterSniffer(SniffWVM);
118120

119121
char value[PROPERTY_VALUE_MAX];
120122
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)