Skip to content

ContentFilterEncryptedMedia

danielweck edited this page Nov 20, 2014 · 13 revisions

For a quick turnaround when experimenting with encrypted media resources, you may use the existing ContentFilter called "PassThroughFilter" (which by default simply passes the raw data extracted from the zip archive, no byte transformation involved).

1) First, register the filter in the PopulateFilterManager() initialisation function, so that the filter can be included in the processing chain:

https://github.com/readium/readium-sdk/blob/develop/ePub3/ePub/initialization.cpp#L40

PassThroughFilter::Register();

2) Secondly, make sure that the SniffPassThroughContent method correctly tests your resource. For example, your content filter may need to decode only certain types of audio and video files:

https://github.com/readium/readium-sdk/blob/feature/ByteRangeStreams/ePub3/ePub/PassThroughFilter.cpp#L37

// "item" is a ManifestItem pointer
auto mediaType = item->MediaType();
return (mediaType == "audio/mp4" || mediaType == "audio/mpeg" || mediaType == "video/mp4" || mediaType == "video/mpeg");

3) Thirdly, you now need to implement the FilterData() decryption routine, which should consume raw bytes (provided by the PassThroughContext instance) and transform them into their decoded form:

https://github.com/readium/readium-sdk/blob/feature/ByteRangeStreams/ePub3/ePub/PassThroughFilter.cpp#L113

Note that by default, the PassThroughFilter returns "OperatingMode::SupportsByteRanges" in the GetOperatingMode() method, which means that your implementation must support arbitrary HTTP byte range requests (i.e. query of bytes within the stream, from a given offset, for a given length).

https://github.com/readium/readium-sdk/blob/feature/ByteRangeStreams/ePub3/ePub/PassThroughFilter.h#L47

Should your de-encryption algorithm not support byte ranges, you may need to disable support for "OperatingMode::SupportsByteRanges", and instead use the "OperatingMode::RequiresCompleteData" variant (which implies that your encrypted media resources will be entirely loaded in memory).

3) Fourthly,

https://github.com/readium/readium-sdk/blob/feature/ByteRangeStreams/ePub3/ePub/PassThroughFilter.cpp#L71

Clone this wiki locally