TOC Prev Next
The JMF architecture allows advanced developers to create and integrate new
types of controllers and data sources. For example, you might implement a new
Player that supports a special media format.
This section introduces the JMF Player architecture and describes how new Players
and DataSources can be integrated into JMF.
9.1 Understanding the Player Architecture
As described in "Creating a Player" on page 14, a client programmer calls
Manager.createPlayer to get a new Player for a particular media source. When
createPlayer is called, an appropriate Player is created and returned to the
caller.
Manager constructs Players for particular media sources. A DataSource is first
constructed from a URL or MediaLocator and then used to create a Player. (A
DataSource is a protocol-specific source of media data. Players usually use
DataSources to manage the transfer of media-content.)
When creating a Player, Manager:
- Obtains the connected
DataSource for the specified protocol
- Obtains the
Player for the content-type specified by the DataSource
- Attaches the
DataSource to the Player
9.1.1 Locating a DataSource
The createDataSource method locates and instantiates an appropriate DataSource
for a specified MediaLocator. To do this, it first creates a search list of
DataSource class names and then steps through each class in the list until a
usable data source is found. To construct the search list of DataSource class
names, createDataSource:
- Obtains a vector of protocol package-prefixes from
PackageManager.
- Adds a class name of the form:
<package-prefix>.media.protocol.<protocol>.DataSource
for each <package-prefix> in the protocol package-prefix-vector.
Manager steps through each class in the list until it finds a DataSource that it can
instantiate and to which it can attach the MediaLocator.
9.1.2 Locating a Player
The createPlayer method uses a similar mechanism to locate and instantiate an
appropriate Player for a particular DataSource. A Player is a type of MediaHandler
, an object that reads data from a DataSource. MediaHandlers are identified
by the content type that they support. Manager uses the content type name
obtained from a DataSource to find MediaHandler objects. JMF supports two
types of MediaHandlers, Player and MediaProxy.
A MediaProxy processes content from one DataSource to create another. Typically,
a MediaProxy reads a text configuration file that contains all of the information
needed to make a connection to a server and obtain media data.
When createPlayer is called, Manager first creates a search list of class names
using the content name from the DataSource and the list of installed packages
returned by the PackageManager. It then steps through each class in the list until
it finds a MediaHandler that can be constructed and to which it can attach the
DataSource.
If the MediaHandler is a Player, the process is finished and Manager returns the
new Player. If the MediaHandler is a MediaProxy, Manager obtains a new DataSource
from the MediaProxy, creates a new list for the content type that the
DataSource supports and repeats the search process.
If an appropriate Player cannot be found, the procedure is repeated, substituting
"unknown" for the content type name. The "unknown" content type is supported
by generic Players that are capable of handling a large variety of media types,
often in a platform dependent way.
To construct the search list of MediaHandler class names, createPlayer:
- Obtains a vector of content package-prefixes from
PackageManager.
- Adds a class name of the form:
<package-prefix>.media.content.<content-type>.Handler
for each <package-prefix> in the content package-prefix-vector.
9.2 Integrating a New Player Implementation
You can create custom implementations of Player that can work seamlessly with
the rest of JMF. To integrate a Player with JMF, you need to:
- Implement
Player.setSource to check the DataSource and determine
whether or not the Player can handle that type of source. When the client
programmer calls createPlayer, setSource is called as the Manager
searches for an appropriate Player.
- Install the package containing the new
Player class.
- Add the package prefix to the content package-prefix list controlled by the
PackageManager. The Manager queries the PackageManager for the list of
content package-prefixes it uses to search for a Player.
For example, to integrate a new Player for the content type mpeg.sys, you would
create and install a package called:
<package-prefix>.media.content.mpeg.sys
that contains the new Player class. The package prefix is an identifier for your
code, such as COM.yourbiz. Your installation program also needs to add your
package prefix to the content package-prefix list managed by the PackageManage
r.
Vector packagePrefix = PackageManager.getContentPrefixList();
string myPackagePrefix = new String("COM.yourbiz");
// Add new package prefix to end of the package prefix list.
packagePrefix.addElement(myPackagePrefix);
PackageManager.setContentPrefixList();
// Save the changes to the package prefix list.
PackageManager.commitContentPrefixList();
|
9.3 Implementing a New Data Source
A DataSource is an abstraction of a media protocol-handler. You can implement
new types of DataSources to support additional protocols by extending
PullDataSource or PushDataSource. If your DataSource supports changing the
media position within the stream to a specified time, it should implement the
Positionable interface. If the DataSource supports seeking to a particular point
in the stream, the corresponding SourceStream should implement the Seekable
interface.
A DataSource manages a collection of SourceStreams. A PullDataSource only
supports pull data-streams; it manages a collection of PullSourceStreams. A
PushDataSource only supports push data-streams; it manages a collection of
PushSourceStreams. When you implement a new DataSource, you also need to
implement the corresponding source stream, PullSourceStream or PushSourceStream
.
See "Appendix B: Sample Data Source Implementation" on page 43 for an example
illustrating how a new PullDataSource, FTPDataSource, could be implemented.
9.4 Integrating a New Data Source Implementation
The mechanism for integrating a custom DataSource implementation with JMF
is similar to the one used for integrating a Player. You need to:
- Install the package containing the new
DataSource class.
- Add the package prefix to the protocol package-prefix list controlled by the
PackageManager. The Manager queries the PackageManager for the list of
protocol package prefixes it uses to search for a DataSource.
TOC Prev Next
|