Microsoft DirectX 9.0

DMO Sample


DMO Sample is a sample Microsoft® DirectX® Media Object (DMO). It takes MPEG-1 video packets as input and produces two output streams. The first output stream contains video frames in RGB 565 format. Each frame displays the time code taken from the MPEG-1 video, and is otherwise blank. The second output stream is an optional text stream with the time code.

DMO Sample uses the IMediaObjectImpl class template to implement the IMediaObject interface. The Active Template Library (ATL) handles various COM details, including registration, aggregation, IUnknown, and the DLL entry points.


Source: (SDK root)\Samples\C++\DirectShow\DMO\DMOSample

User's Guide

The project workspace builds a DLL named Dmosample.dll. Use the Regsvr32 utility to register the DLL. To see the DMO in action, you can use the Microsoft® DirectShow® GraphEdit utility. You will need an MPEG-1 video file. Perform the following steps:

  1. Run GraphEdit.
  2. Render an MPEG-1 file:
  3. Remove the MPEG-1 Video Decoder filter from the filter graph by selecting the filter and pressing DELETE.
  4. Insert the DMO Sample in the graph:
  5. Connect the MPEG-1 Stream Splitter to the DMO Sample by dragging the mouse from the small box labeled Video on the MPEG-1 Stream Splitter to the box labeled in0 on the DMO Sample. (See illustration.)
  6. Connect the DMO Sample to the Video Renderer:
  7. Press the play button on the GraphEdit toolbar, or click Play from the Graph menu.

When the graph runs, a video window appears that displays the time codes.

Connecting the DMO Sample

Programming Notes

The DMO Sample contains the following source files:

File Description
Dmosample.cpp Code for implementing basic COM functionality in ATL.
Resource.h Defines resource constants.
Sample.h, Sample.cpp Defined the CSample class, which implements the DMO.
State.h, State.cpp Defines the CStreamState class, a helper class that generates time stamps from the MPEG data.
Stdafx.h, Stdafx.cpp Generates the precompiled header.
Util.h, Util.cpp Contains utility functions for drawing the output image.
Dmosample.rc Defines a resource with version information, and links to the Sample.rgs file.
Sample.rgs Defines a text resource with registry information. ATL uses this resource to create registry entries when it registers the DLL.

The following remarks describe the implementation in greater detail.


The file contains the object map that ATL uses to create and register the DMO object. It also contains the exported DLL functions. These include the entry-point function (DllMain), and the functions that COM requires (DllCanUnloadNow, DllGetClassObject, DllRegisterServer, and DllUnregisterServer).

The ATL COM AppWizard automatically generates most of the code contained in this file. Two things are added:


The one constant declared in this header file, IDR_SAMPLE, is used by ATL's self-registration mechanism. The constant IDR_SAMPLE identifies a text resource, which is defined in the resource file Sample.rgs and imported by the resource file Dmosample.rc. The header file Sample.h contains the following line:


This causes ATL to use the registration information declared in the IDR_SAMPLE resource.


The DEFINE_GUID macro declares the class identifier (CLSID) of the DMO.

The CSample class derives from the following classes:

CSample aggregates the Free Threaded Marshaler, which is an object that performs custom marshaling. If the COM library marshals a CSample pointer across threads within the sample process, the exact same pointer is returned. If the COM library tries to marshal the object across processes or across machines, it fails. ATL adds all of the code need to aggregrate the Free Threaded Marshaler. This code appears in the FinalConstruct and FinalRelease methods. The COM_INTERFACE_ENTRY_AGGREGATE entry in the COM map delegates the IMarshal interface to the Free Threaded Marshaler.

The CSample class declares the following member variables:

Variable Description
m_pUnkMarshaler Pointer to the Free Threaded Marshaler object.
m_pBuffer Pointer to the input buffer. The DMO holds a reference count on the buffer until it processes all of the input.
m_pbData Pointer to the next byte in the input buffer.
m_cbData Number of bytes remaining to process.
m_rtFrame Time stamp from the most recent output frame.
m_StreamState Instance of the CStreamState helper class, which parses MPEG data.
m_bPicture Boolean flag that indicates whether the DMO has picture information to output.


This file implements the methods in the CSample class.