Finally... Software MPEG Video Playback!

From EDM2
Jump to: navigation, search

by Lauren Post

In delivering video subsystem support, starting in OS/2 2.1 and also in OS/2 Warp Version 3, the OS/2 video developers identified enhancements that are needed to make the OS/2 software video subsystem flexible enough for software playback of Motion Picture Expert Group (MPEG) multimedia files. In Volume 9 of the Developer Connection for OS/2, we delivered the Beta of OpenMPEG for OS/2, which provided software MPEG playback through an OS/2 subsystem for the first time.

At the same time, an organization was forming: the OpenMPEG Consortium. This group, MPEG hardware manufacturers and application developers, is striving to develop a standard for MPEG playback. Although the MPEG compression algorithm is a standard, there currently is no consistent definition for MPEG playback and, as a result, few applications play the same way on different systems, especially with different MPEG cards. This eventually limits the market for MPEG applications and hardware.

OpenMPEG Consortium

The OpenMPEG Consortium is working on many levels to push MPEG technology into the marketplace. By defining MPEG playback behavior, the consortium is helping MPEG manufacturers, MPEG device driver developers, and application developers provide a common look to MPEG applications. The Compliance subcommittee of the consortium decides the functions that make MPEG hardware OpenMPEG compliant. You can check out the OpenMPEG Consortium's site on the World Wide Web.

OpenMPEG Multiplatform Subcommittee

The goal of the OpenMPEG Consortium is to define an API and behaviors for MPEG playback on various platforms such as OS/2, UNIX, Quicktime, and Windows. IBM is participating in the consortium through board representation and by chairing the OpenMPEG Multiplatform subcommittee, which is responsible for platforms beyond DOS and the media control interface used by Windows. The OpenMPEG Multiplatform subcommittee was started in early 1995 and by year end completed the OpenMPEG Multiplatform MPEG Interactive API specification. The Beta of OpenMPEG for OS/2 that was delivered on Volume 9 of the Developer Connection was based on version 0.87 of the OpenMPEG Multiplatform specification.

Now, Volume 10 of DevCon includes these updates to OpenMPEG for OS/2 subsystem for software and hardware MPEG playback based on version 1.0 of the OpenMPEG Multiplatform specification:

  • Support for the newly defined APIs.
  • OpenMPEG media control device (MCD) for backward compatibility with existing media control interface applications.
  • OpenMPEG playback sample on using the OpenMPEG APIs.
  • Headers and libraries for creating OpenMPEG applications.
  • Online documentation.

OM1_OPEN_INPUT    OpenInput; 
OM1_OPEN_OUTPUT   OpenOutput; 
OM1STREAM         hStream; 
CHAR              szFilename[20]; 
HWND              hwndMPEG; 
APIRET            rc;
                  /* rc not defined) */ 
/* Create a 0 sized window */
hwndMPEG = WinCreateWindow(hwndFrame, 
                           "Window", NULL, 
                           WS_VISIBLE, 0, 0, 0, 
                           hwndFrame, HWND_TOP, ID_MOVIE, NULL, NULL);  
OpenInput.Flags = OM1F_FILE;
/* Playback from file not buffered playback */
OpenOutput.hStream= 0L;
rc = OM1OpenStream(&OpenInput, &OpenOutput);
if (rc == OM1E_SUCCESS){
  /* Save the hstream which is needed for future OpenMPEG calls */ 
  /* Get the size and reset window size */ 
  /* The width and height are returned in one doubleword */ 
  /* The height is the high word and width is the low word */ 
  ulWidth=GetOutput.Output & 0xffff; 
                  SWP_SIZE | SWP_SHOW | SWP_MOVE); 
  /* Tell OpenMPEG subsystem that the video is ready to be blitted */
  /* Start MPEG playback */ 
  OM1Play(hStream ,0L);
} else {
  /* Error in Open - return error */

The previous example illustrates using the APIs OM1OpenStream and OM1Play. When you install OS/2 OpenMPEG from the DevCon for OS/2 CD-ROMs, you will find a sample application that uses the OpenMPEG API's. The APIs that are needed for a basic OpenMPEG application that plays an MPEG file include:

  • OM1OpenStream - Opens an MPEG stream and returns a handle.
  • OM1Play - Starts playback of an MPEG stream.
  • OM1Get - Based on the index passed, returns the appropriate value.
  • OM1Set - Based on the index passed, sets a value.
  • OM1Stop - Stops playback of an MPEG stream.
  • OM1Close - Closes an opened MPEG stream.
  • OM1Callback - Provides asynchronous notification of position changes and status changes.

Buffered Streams

The OpenMPEG Multiplatform specification defines APIs for MPEG playback in addition to support for interaction. This means applications now can perform their own file I/O and pass buffers to OpenMPEG to be processed. This interactive portion for buffered playback provides a great deal of flexibility in MPEG applications and also allows the use of buffered MPEG streams passed through a network. "Video on demand" may now be within our reach.

Callback Procedures

The following example demonstrates the use of a callback procedure that can receive asynchronous notifications from the OpenMPEG subsystem on error messages, position changes, and buffered data requests. The callback procedure is set in the OpenInput procedure or later with OM1Callback. To set up notifications, after the open is complete, issue the following call:

OM1_SIGNAL_INPUT    SignalInput; 
OM1_SIGNAL_OUTPUT   SignalOutput; 
ULONG               SignalID;
ULONG               rc; 
SignalInput.Flags = OM1F_SIG_AT;
SignalInput.Value = 2000;
Signal.Output.SignalID = 0L;
rc = OM1Signal (hStream, &SignalInput, &SignalOutput);
if (rc == OM1E_SUCCESS) SignalID = SignalOutput.SignalID;

The following callback procedure demonstrates signal notifications and completion notifications:

ULONG APIENTRY Callback(BYTE msg, BYTE hStream, ULONG MessageValue){ 
  OM1_GET_INPUT   GetInput;
  OM1_GET_OUTPUT  GetOutput; 
  ULONG ulPosition; 
    case OM1M_COMPLETED : 
      if (MessageValue == OM1_PLAY) { 
        /* Play is done so close the stream instance and */
        /* destroy the window */ 
    OM1Close (hStream); 
    case OM1M_SIGNAL: 
      if (MessageValue == SignalID) { 
        /* Query position */ 
      GetInput.Index = OM1I_STM_POSITION; 
      OM1Get (hStream, &GetInput, &GetOutput); 
     /* Take above position and update slider if one exists */ 
  return 0; 

Compatibility with Existing Media Control Interface Applications

An OpenMPEG MCD was developed to provide downward compatibility with existing media control interface applications that do MPEG video playback. During installation, the device is installed in the OS/2 Multimedia subsystem. The OpenMPEG MCD calls the OpenMPEG APIs (similar to the previous example).

OpenMPEG for OS/2 Limitations

This Beta of the OpenMPEG for OS/2 video subsystem still has some limitations. Although the OpenMPEG for OS/2 subsystem supports software video, it doesn't support software MPEG audio. Because MPEG audio is compressed, it usually requires hardware for decompression and playback. To use the OpenMPEG video subsystem and get audio support, you must have hardware that supports MPEG audio. Examples of MPEG audio hardware include MWAVE or MPEG cards such as Sigma Design's Reel Magic. To address these limitations, we are working on software MPEG audio. Look for it soon!

Performance Considerations

The recommended hardware configuration for OpenMPEG for OS/2 software MPEG playback is a Pentium processor running at 120 MHz. In smaller configurations, playback might not be smooth because of the high data processing required for decompressing and blitting software MPEG video streams.

What's Left?

There is still more that can be done to enhance the OpenMPEG for OS/2 subsystem. The OpenMPEG for OS/2 development team looks forward to creating APIs for video capture, video overlay, and freeze support. These APIs and the ones for software MPEG audio support may be included in a future volume of DevCon.

We value any feedback you can give us about this Beta release of the OpenMPEG for OS/2 subsystem. If you have any comments about the Beta, please let us know through the IBM forums or in the OS2DF1 Multimedia section on CompuServe.

Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation