public final class MediaStream extends java.lang.Object implements MediaStreamInterface
The Media Stream class provides access to Marlin DRM protected application data of arbitrary and generic type. There are three mostly independent aspects of setting up a Media Stream object to gain access to the underlying clear data:
Support for each of these three items in Media Stream class is described in the following. Afterwards, a few common pseudo-code examples are provided.
The following Media Stream class usage examples illustrate some of the common use cases:
// Initialize the run-time
Runtime.initialize(...);
// perform personalization if necessary...
// The token must be acquired from HMS or other similar Marlin
// server.
String token = AcquireBbLicenseToken();
// Load the BB license.
Runtime.processServiceToken(token);
MediaStream media_stream;
int read_count;
long size;
media_stream = new MediaStream("/data/my-file.dcf",
MediaStream.SourceType.DCF,
null); // no format_info needed
size = media_stream.getSize();
byte[] buffer = new byte[BUF_SIZE];
while (size > 0) {
read_count = media_stream.read(buffer);
ProcessData(buffer, read_count); // read_count is set to the
// number of actually read
// bytes
size -= read_count;
}
media_stream.close();
Runtime.shutdown();
// Initialize the run-time
Runtime.initialize(...);
// perform personalization if necessary...
FormatInfoGeneric format_info = new FormatInfoGeneric();
MediaStream media_stream;
int read_count;
long size;
// Application must acquire an MS3 URL.
String ms3_url = AcquireMs3Url();
// Application must know the content ID
format_info.content_id = "test-content-id-or-some-such";
// Application should set clear text size when accessing over HTTP
format_info.clear_text_size = 12345;
media_stream = new MediaStream(ms3_url,
MediaStream.SourceType.AES128CBC,
format_info);
size = media_stream.getSize();
byte[] buffer = new byte[BUF_SIZE];
while (size > 0) {
read_count = media_stream.read(buffer);
ProcessData(buffer, read_count); // read_count is set to the
// number of actually read
// bytes
size -= read_count;
}
media_stream.close();
Runtime.shutdown();
// Initialize the run-time
Runtime.initialize(...);
// perform personalization if necessary...
FormatInfoGeneric format_info = new FormatInfoGeneric();
MediaStream first_media_stream;
int read_count;
long size;
String ms3_url;
// The first decrypting Media Stream object acquires content keys
// from the MS3 URL
// Application must acquire an MS3 URL.
format_info.ms3_url = AcquireMs3Url();
// Application must know the content ID
format_info.content_id = "test-content-id-or-some-such";
// Application must know the IV
format_info.iv = new byte[16]{...};
// CENC counter size is 8
format_info.counter_size = 8;
// Application must instantiate an object that implements the
// MediaStreamInterface that can read encrypted media sample data.
// The GetContentType must return
// MediaStreamInterface.CONTENT_TYPE_AES128CTR in this case.
MediaStream media_sample_reader = new ApplicationMediaStream(...);
first_media_stream = new MediaStream(media_sample_reader, format_info);
size = first_media_stream.getSize();
byte[] buffer = new byte[BUF_SIZE];
while (size > 0) {
read_count = first_media_stream.read(buffer);
ProcessData(buffer, read_count); // read_count is set to the
// number of actually read
// bytes
size -= read_count;
}
// Must not close the first decrypting Media Stream object until
// all media samples have been processed, as the first Media Stream
// object owns the content keys.
// Subsequent decrypting Media Stream objects reuse the content
// keys from the first Media Stream
MediaStream media_stream;
// Reuse the content keys from the first Media Stream object, no
// license processing involved, fast Media Stream instantiation
format_info.key = first_media_stream.getKey();
// Application must know the content ID
format_info.content_id = "test-content-id-or-some-such";
// Application must know the IV
format_info.iv = new byte[16]{...};
// CENC counter size is 8
format_info.counter_size = 8;
// Application must create an object that implements the
// MediaStreamInterface that can read encrypted media sample data.
// The MediaStreamInterface.getContentType must return
// MediaStreamInterface.CONTENT_TYPE_AES128CTR in this case.
media_sample_reader = new ApplicationMediaStream(...);
media_stream = new MediaStream(media_sample_reader, format_info);
size = media_stream.getSize();
while (size > 0) {
read_count = media_stream.read(buffer);
ProcessData(buffer, read_count); // read_count is set to the
// number of actually read
// bytes
size -= read_count;
}
media_stream.close();
// Repeat media sample decryption with new Media Stream objects
// ...
// At the end, close the first Media Stream object.
first_media_stream.close();
Runtime.shutdown();
Modifier and Type | Class and Description |
---|---|
static class |
MediaStream.FormatInfo
The base class for the additional format information that may
be SourceType specific.
|
static class |
MediaStream.FormatInfoGeneric
Additional format information that may be needed when
constructing a Media Stream object.
|
static class |
MediaStream.SourceType
The source type.
|
CONTENT_TYPE_AES128CBC, CONTENT_TYPE_AES128CTR, CONTENT_TYPE_DCF
Constructor and Description |
---|
MediaStream(MediaStreamInterface sourceInput,
MediaStream.FormatInfo format_info)
Access an encrypted source through an input object that
implements the MediaStreamInterface.
|
MediaStream(java.lang.String sourceName,
MediaStream.SourceType sourceType,
MediaStream.FormatInfo format_info)
Access an encrypted source through a URL.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Release the Media Stream resources.
|
java.lang.String |
getContentType()
Get Media Stream content type.
|
java.lang.Object |
getKey()
Access the crypto context for sharing with another Media
Stream object to avoid re-evaluation of the same license.
|
long |
getSize()
Get Media Stream size.
|
int |
read(byte[] buffer)
Read data from a media stream object.
|
int |
read(byte[] buffer,
int offset,
int length)
Read data from a media stream object.
|
void |
seek(long position)
Change the current read position.
|
long |
tell()
Get the current read position.
|
public MediaStream(java.lang.String sourceName, MediaStream.SourceType sourceType, MediaStream.FormatInfo format_info) throws ErrorCodeException, java.lang.NullPointerException
sourceName
- either an ms3:// URL or directly a source file
URL (http:// or file://) for BB.sourceType
- the type of the source data.format_info
- additional format information about the
source data that. Ignored if sourceType is
DCF. Can be null.ErrorCodeException
java.lang.NullPointerException
public MediaStream(MediaStreamInterface sourceInput, MediaStream.FormatInfo format_info) throws ErrorCodeException, java.lang.NullPointerException
sourceInput
- source data random access object.format_info
- additional format information about the
source data that. Can be null.ErrorCodeException
java.lang.NullPointerException
public int read(byte[] buffer) throws ErrorCodeException
read
in interface MediaStreamInterface
buffer
- the data buffer to read into.ErrorCodeException
public int read(byte[] buffer, int offset, int length) throws ErrorCodeException
read
in interface MediaStreamInterface
buffer
- the data buffer to read into.offset
- the number of buffer locations to skiplength
- the number of bytes to readErrorCodeException
public void seek(long position) throws ErrorCodeException
seek
in interface MediaStreamInterface
position
- the number of bytes from the start of the media
stream.ErrorCodeException
public long tell() throws ErrorCodeException
tell
in interface MediaStreamInterface
ErrorCodeException
public long getSize() throws ErrorCodeException
getSize
in interface MediaStreamInterface
ErrorCodeException
public java.lang.String getContentType() throws ErrorCodeException
getContentType
in interface MediaStreamInterface
ErrorCodeException
public java.lang.Object getKey() throws ErrorCodeException
ErrorCodeException
public void close()
close
in interface MediaStreamInterface