Allow DRM client to pass the FD of an open file to the DRM server.
This allows a DRM client to open a locally-cached file on behalf of the DRM server so the DRM server no longer requires the sdcard_r permission to access the file's metadata. Specifically, this adds an optional attribute FileDescriptorKey to the DrmInfoRequest. This change is dependent on this Widevine CL: https://widevine-internal-review.googlesource.com/#/c/1330/ Relevant bug reports: bug: 6426185 Change-Id: Ia7bcb2455c7a55fa4c7c7061de4d672957c7ac0a
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <iostream>
|
||||
@@ -45,12 +48,14 @@ static void Terminate();
|
||||
void PrintUsage(char *prog)
|
||||
{
|
||||
printf("Usage: %s <options> url\n", prog);
|
||||
printf(" %s <options> -L filename\n", prog);
|
||||
printf(" -o output_file\n");
|
||||
printf(" -b block_size (default: %d)\n", DEFAULT_BLOCK_SIZE);
|
||||
printf(" -p playback_buffer_size (default: %d)\n", (int)DEFAULT_PLAYBACK_BUFFER_SIZE);
|
||||
printf(" -m print PTS -> media time\n");
|
||||
printf(" -s start_time (default: %s)\n", DEFAULT_START_TIME);
|
||||
printf(" -d drm_url\n");
|
||||
printf(" -L open filname on local file system\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -222,33 +227,64 @@ static void CloseDrmPlugin()
|
||||
}
|
||||
}
|
||||
|
||||
static void AcquireRights(IDrmEngine *plugin, string url, string drmUrl)
|
||||
static void AcquireRights(IDrmEngine *plugin, string url, string drmUrl,
|
||||
bool isLocal)
|
||||
{
|
||||
String8 mimeType("video/wvm");
|
||||
DrmInfoRequest rightsAcquisitionInfo(DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO, mimeType);
|
||||
|
||||
int fdNum = -1;
|
||||
|
||||
rightsAcquisitionInfo.put(String8("WVDRMServerKey"), String8(drmUrl.c_str()));
|
||||
rightsAcquisitionInfo.put(String8("WVAssetURIKey"), String8(url.c_str()));
|
||||
if (isLocal) {
|
||||
char fdStr[16];
|
||||
fdNum = open(url.c_str(), O_RDONLY);
|
||||
if (fdNum == -1) {
|
||||
fprintf(stderr, "unable to open local movie file %s for reading.\n",
|
||||
url.c_str());
|
||||
close(fdNum);
|
||||
Terminate();
|
||||
}
|
||||
sprintf(fdStr, "%lu", (unsigned long)fdNum);
|
||||
rightsAcquisitionInfo.put(String8("FileDescriptorKey"), String8(fdStr));
|
||||
}
|
||||
rightsAcquisitionInfo.put(String8("WVDeviceIDKey"), String8("device1234"));
|
||||
rightsAcquisitionInfo.put(String8("WVPortalKey"), String8("OEM"));
|
||||
rightsAcquisitionInfo.put(String8("WVLicenseTypeKey"), String8("1"));
|
||||
|
||||
// Get asset rights from DRM. If it is necessary to
|
||||
// read file metadata to get the asset ID, this can take several seconds.
|
||||
DrmInfo *info = plugin->acquireDrmInfo(0, &rightsAcquisitionInfo);
|
||||
if (info == NULL) {
|
||||
fprintf(stderr, "acquireDrmInfo failed!\n");
|
||||
if (isLocal) {
|
||||
close(fdNum);
|
||||
}
|
||||
Terminate();
|
||||
}
|
||||
|
||||
DrmInfoStatus *status = plugin->processDrmInfo(0, info);
|
||||
if (status == NULL || status->statusCode != DrmInfoStatus::STATUS_OK) {
|
||||
fprintf(stderr, "processDrmInfo failed!\n");
|
||||
if (isLocal) {
|
||||
close(fdNum);
|
||||
}
|
||||
Terminate();
|
||||
}
|
||||
|
||||
if (plugin->checkRightsStatus(0, String8(url.c_str()), Action::DEFAULT) != RightsStatus::RIGHTS_VALID) {
|
||||
fprintf(stderr, "checkValidRights default action failed!\n");
|
||||
if (isLocal) {
|
||||
close(fdNum);
|
||||
}
|
||||
Terminate();
|
||||
}
|
||||
|
||||
if (isLocal) {
|
||||
close(fdNum);
|
||||
}
|
||||
|
||||
delete status;
|
||||
delete info;
|
||||
}
|
||||
@@ -281,10 +317,11 @@ int main( int argc, char *argv[] )
|
||||
unsigned long playbackBufferSize = DEFAULT_PLAYBACK_BUFFER_SIZE;
|
||||
bool ptsToMediaTime = false;
|
||||
string drmUrl = DEFAULT_DRM_URL;
|
||||
bool isLocal = false;
|
||||
|
||||
_ah006(PrintMessage);
|
||||
|
||||
while ((option = getopt(argc, argv, "o:b:p:s:mD:d:")) != -1) {
|
||||
while ((option = getopt(argc, argv, "o:b:p:s:mD:d:L")) != -1) {
|
||||
switch (option) {
|
||||
case 'o':
|
||||
outputFile = optarg;
|
||||
@@ -312,6 +349,10 @@ int main( int argc, char *argv[] )
|
||||
drmUrl = optarg;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
isLocal = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("unknown option: '%c'\n", option);
|
||||
PrintUsage(argv[0]);
|
||||
@@ -327,7 +368,8 @@ int main( int argc, char *argv[] )
|
||||
if (outputFile.size()) {
|
||||
output = fopen(outputFile.c_str(), "wb");
|
||||
if (!output) {
|
||||
fprintf(stderr, "unable to open output file %s for writing\n", argv[2]);
|
||||
fprintf(stderr, "unable to open output file %s for writing\n",
|
||||
argv[2]);
|
||||
Terminate();
|
||||
}
|
||||
}
|
||||
@@ -347,7 +389,9 @@ int main( int argc, char *argv[] )
|
||||
WV_SetLogging(WV_Logging_HTTP);
|
||||
|
||||
OpenDrmPlugin();
|
||||
AcquireRights(sDrmPlugin, url, drmUrl);
|
||||
|
||||
// if isLocal is true, the url param holds a local filesystem filename
|
||||
AcquireRights(sDrmPlugin, url, drmUrl, isLocal);
|
||||
|
||||
_ah002(_cb1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user