Implement WV side of the separation of sniffing and decrypt session initialization.

Further optimization may be done to further speed up a drm content playback session

related-to-bug: 5725548

Change-Id: Ife69deaf5d2d70bba812fe1a48d9268d8e9530f7
This commit is contained in:
James Dong
2012-01-10 08:26:13 -08:00
parent 7284b7e7f3
commit 9fd21a7798
4 changed files with 72 additions and 46 deletions

View File

@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_NDEBUG 0
//#define LOG_NDEBUG 0
#define LOG_TAG "WVMDrmPlugIn"
#include <utils/Log.h>
#include <vector>
@@ -704,77 +705,68 @@ status_t WVMDrmPlugin::onRemoveAllRights(int uniqueId) {
* @param[in] fd File descriptor of the protected content to be decrypted
* @param[in] offset Start position of the content
* @param[in] length The length of the protected content
* @param[in] mime Mime type of the protected content.
* @return
* DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
*/
status_t WVMDrmPlugin::onOpenDecryptSession(
int uniqueId, DecryptHandle *decryptHandle, int fd, off64_t offset, off64_t length)
int uniqueId, DecryptHandle *decryptHandle,
int fd, off64_t offset, off64_t length, const char* mime)
{
status_t result = DRM_ERROR_CANNOT_HANDLE;
ALOGV("onOpenDecryptSession: id=%d,fd=%d", uniqueId, fd);
//ALOGD("onOpenDecryptSession: fd=%d, offset=%lld, length=%lld", fd, offset, length);
char buffer[64 * 1024];
int dupfd = dup(fd);
if (dupfd == -1)
return result;
FILE *f = fdopen(dupfd, "rb");
if (f) {
fseek(f, 0, SEEK_SET);
if (fread(buffer, 1, sizeof(buffer), f) != sizeof(buffer)) {
fclose(f);
return DRM_ERROR_CANNOT_HANDLE;
}
fclose(f);
} else {
close(dupfd);
return result;
if (!isSupportedMimeType(mime)) {
return DRM_ERROR_CANNOT_HANDLE;
}
if (WV_IsWidevineMedia(buffer, sizeof(buffer))) {
//ALOGD("WVMDrmPlugin::onOpenDecryptSession - WV_IsWidevineMedia: true");
decryptHandle->mimeType = String8("video/wvm");
decryptHandle->decryptApiType = DecryptApiType::WV_BASED;
decryptHandle->status = DRM_NO_ERROR;
decryptHandle->decryptInfo = NULL;
// For efficiency, we rely on the WVMExtractor's sniff result instead of
// setting mimeType and decryptApiType here for the DRMExtractor's sniff.
// WVMExtractor's sniff uses the cached data source for the sniff.
decryptHandle->decryptInfo = NULL;
decryptHandle->status = DRM_NO_ERROR;
mDrmPluginImpl->OpenSession(NULL);
result = DRM_NO_ERROR;
} else {
//ALOGD("WVMDrmPlugin::onOpenDecryptSession - not Widevine media");
if (mDrmPluginImpl->OpenSession(NULL)) {
return DRM_NO_ERROR;
}
return result;
return DRM_ERROR_CANNOT_HANDLE;
}
bool WVMDrmPlugin::isSupportedMimeType(const char* mime) {
ALOGV("isSupportedMimeType: mime = %s", mime? mime: "NULL");
return strcasecmp("video/wvm", mime) == 0;
}
/**
* Open the decrypt session to decrypt the given protected content
*
* @param[in] uniqueId Unique identifier for a session
* @param[in] decryptHandle Handle for the current decryption session
* @param[in] uri Path of the protected content to be decrypted
* @param[in] mime Mime type of the protected content
* @return
* DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
*/
status_t WVMDrmPlugin::onOpenDecryptSession(
int uniqueId, DecryptHandle* decryptHandle, const char* uri)
int uniqueId, DecryptHandle* decryptHandle,
const char* uri, const char* mime)
{
ALOGV("onOpenDecryptSession: id=%d,uri=%s",uniqueId,uri);
if (!isSupportedMimeType(mime)) {
return DRM_ERROR_CANNOT_HANDLE;
}
// For efficiency, we rely on the WVMExtractor's sniff result instead of
// setting mimeType and decryptApiType here for the DRMExtractor's sniff.
// WVMExtractor's sniff uses the cached data source for the sniff.
status_t result = DRM_ERROR_CANNOT_HANDLE;
if (!uri)
return result;
if (mDrmPluginImpl->IsSupportedMediaType(uri)) {
//ALOGD("WVMDrmPlugin::onOpenDecryptSession(uri) : %d - match", uniqueId);
decryptHandle->mimeType = String8("video/wvm");
decryptHandle->decryptApiType = DecryptApiType::WV_BASED;
decryptHandle->status = DRM_NO_ERROR;
decryptHandle->decryptInfo = NULL;
decryptHandle->decryptInfo = NULL;
decryptHandle->status = DRM_NO_ERROR;
if (mDrmPluginImpl->OpenSession(uri)) {
result = DRM_NO_ERROR;
}
if (mDrmPluginImpl->OpenSession(uri)) {
result = DRM_NO_ERROR;
} else {
//ALOGD("WVMDrmPlugin::onOpenDecryptSession(uri) - not Widevine media");
}