A Quick Little Primer on JMF 2.0
|"As an enterprisewide business tool, JMF is an excellent proposition. It's a perfect Swiss-army knife that can handle a company's media over extranets and intranets. "|
Let's get a little superficial here. I mean, databases teeming with knowledge, tables full of figures, and frames full of text are all well and good. These things may even be the soul of the information age. But it's the graphics, sounds, and animations that are the hot bod the components that really create love at first site. The Java Media Framework (JMF) is an attempt to collide the portability and ease of Java with the appeal of multimedia. The idea is to have a one-size-fits-all way of easily capturing, processing, converting, and playing media data smack within Java programs. JMF 2.0 was developed by Sun and IBM, letting application developers control every step of the recording and playback of audio and video files or streams.
|"If you have a strong enough system, you can record and transmit video at the same time as you playback, allowing for full two-way video-conferencing. "|
Unfortunately, JMF 2.0 does not work easily with most browsers. JMF 2.0 only works with Java 1.1 or greater and, thus, is only compatible with Netscape 4.06, Netscape 4.03 with the JDK 1.1 plug-in, or IE 4.01. Even then, users will need to download the weighty JMF classes (about 5 megs) and install them more than casual surfers are willing to do. In addition, unsigned applets written with JMF cannot capture media data or save data to disk due to security restrictions. For now and the foreseeable future, RealPlayer and Windows Media Player remain as the standard for streaming media within personal Web browsers.
As an enterprisewide business tool, however, JMF is an excellent proposition. It's a perfect Swiss-army knife that can handle a company's media over extranets and intranets. Let's say you have offices across the world and want to create your own video-conferencing tool with its own custom interface. You can have an animated presentation playing in one frame and a video of the presenter's pretty face bopping along in the other frame. The Denver office might use Solaris workstations with SunVideo while the Tokyo office uses Windows NT with QuickCams. Writing a cross-platform application to tie everything together would be a big headache, involving endless integration tasks. And there's no guaranteeing the application would work in the future, when offices upgrade to better operating systems, different video or audio standards, or snazzier hardware.
JMF to the rescue! Using Java and JMF as your company's main application programming environment makes it easy to share music, voice, animations, and video simply install JDK 2.0 or better and JMF 2.0 onto all relevant machines across your enterprise and you're good to go. Currently JMF only really works for Solaris and Windows 32, but theoretically, there will eventually be implementations for every platform, including set-top boxes, handheld devices, etc.
Let's take a quick tour of how digital multimedia flows and how JMF is there every step of the way.
Media has many faces. Media may come to your computer via the Internet, from your hard drive, or from a DVD-ROM player. Media may also come directly from any sort of media device a TV, VCR, video camera, CD player, etc. JMF has built-in support for most major media devices. For instance, it handles all SunVideo devices on Solaris. And on Windows, you can easily connect with any hardware that uses the standard VFW drivers, such as Create & Share, QuickCam, and Creative's Web Cam. Not a bad selection. And support classes for other types of hardware can easily be built in to the JMF framework. To access these devices, create a new DataSource object.
Whether your computer is outputting or recording, a process known as digital signal processing (DSP) must occur. JMF 2.0 includes a special type of player class known as the Processor, which allows you to customize DSP. There are five steps that make up DSP, each of which can be customized with plug-ins:
- Demultiplexer: This sounds like some sort of monster that goes around smashing oversized movie theaters. In actuality, though, it is a way of separating one stream of data into different streams. For example, Quicktime video is generally separated into audio, video, and text streams.
- Preprocessing Effects: This tweaks the stream, often to remove noise or balance out colors. If you are taking in uncompressed media and compressing it, then the effect usually happens here, before the compression step.
- Codec: This stands for compression/decompression. Common codecs are Cinepak and MPEG, which are included in the JMF package. But oftentimes companies will use their own proprietary algorithms. JMF makes this easy to tailor.
- Postprocessing Effects: If you just decompressed audio or video, now is a good time to run any effects.
- Renderer or Multiplexer: Now that the multimedia data is in a suitable format, the computer can output it somewhere. A renderer actually pumps the stream to an audio player as pulses of sound or a video player as a slide-show of bitmaps. If you are recording in two separate streams of audio and video data, however, your last step of DSP should be a multiplexer, which combines the two streams into one, suitable for saving to disk or pumping out over the Internet.
By modifying a processor's
object, you can indicate which of the plug-ins you want to use and in what order they should execute. The processor will then go through the steps you indicate. If you don't need to customize DSP, you can just call the processor's
method. The processor will automatically jump through the standard steps. As processing takes place, you will have a new, corresponding DataSource object to work with.
Most streaming on the Internet is done using the Real-Time Protocol (RTP) a special protocol built atop UDP that synchronizes packets and keeps track of the exact time, allowing a data stream to be synchronized. The JMF Manager contains a special object called the RTP Session Manager that allows RTP content to be created and played without mush fuss:
DataSource mydsource = processor.getDataOutput(); SessionManager myrtpsm = new com.sun.media.rtp.RTPSessionMgr(); myrtpsm.initSession(...); myrtpsm.startSession(...); myrtpsm.createSendStream(ds,0);
This broadcasts the data to everyone subscribed to the current RTP session.
JMF uses the Player class to actually bring the media to your eyes and/or ears. JMF 2.0 uses the JavaSound API to support nearly every type of digital audio AIFF, AU, AVI, GSM, MIDI, MP2, MP3, QT, RMF, and WAV, to be exact. As for video, it covers the AVI, MPEG-1, and QuickTime formats. There is also support for Flash 2 and IBM's HotMedia. You can use the standard user interface for various players or easily customize the GUI yourself.
If you are registered with an RTP session, you should create an RTP Session Manager and add a
to it. You can then easily handle the
object in the
mystream = ((NewReceiveStreamEvent)theevent).getReceiveStream(); DataSource mydsource = mystream.getDataSource(); myplayer = Manager.createPlayer(mydsource);
Putting It Together
You can get pretty fancy with this. For example, you can write a demultiplexer to split your video feed into two streams one to be transmitted using a RTPSessionMgr and one to be sent to the default JMF player so you can see your own video at the same time as it streams. You can even pipe a separate stream to a
object, which allows you to save the media to disk in any supported format. If you have a strong enough system, you can record and transmit video at the same time as you playback, allowing for full two-way video-conferencing.
Check out the JMF API Guide and the VideoTransmit sample class, both available for free on Sun's site, for a clearer idea of how to accomplish all this multimedia magic.
About the AuthorDavid Fox is vice president of Games at PlayLink, Inc. He's also the author of numerous books and articles about cyberculture and technology.