Axis Decoder DMO Samples - Version 1.0
These code samples were created in order to show how to use Axis video and
audio decoders in a non-DirectShow application. All five Axis decoders
(H.264/MPEG-4/MJPEG/AAC/G7.xx) are so called DirectX Media Objects (DMO).
DMO provides interfaces for simple data transformations and can be used outside
the DirectShow graph. However, the DMO Wrapper Filter
enables DMOs to also be used in an DirectShow graph.
Disclaimer
We highly recommend considering using the AXIS Media Control or the AXIS Media Parser
SDKs. These software developer kits are tested by Axis Communications and full support is offered on the intended usage.
This documentation requires knowledge on how to program with COM interfaces. Axis Communications offers only limited support when using the
DMO decoders directly and is reluctant to advice on generic programming questions.
IMPORTANT NOTICES!
Axis Communications AB (“Axis”) makes no warranties, representations or undertakings about any of the content in this document
and the provided code (including, without limitation, any as to the quality, accuracy, completeness or fitness for any particular purpose of such content). Axis provides no guarantee that any of the examples
will work for any particular application. Axis shall not be held liable for any damage inflicted to any device as a result of the examples or instructions
contained in the sample code. Axis reserves the right to make changes to these
samples without prior notice.
DirectShow is a trademark of Microsoft Corporation.
Sample description
The solution contains two similar examples - one written in C++ and the other
written in C# using the .Net framework. The samples are console applications
that take a media recording as input and decodes the contained media streams one
or several times. For these examples we use media files (.bin) created with the
AXIS Media Parser SDK ('MediaParser' sample). Four test files are included with
mixed payloads (see the MediaFiles directory).
- Usage: MediaParserFileSourceDecodeC++ <AMP_file>
[num iterations]
- Usage: MediaParserFileSourceDecodeCSharp
<AMP_file> [num iterations]
- Example: MediaParserFileSourceDecodeC++
"{root}\MediaFiles\AMP_H264_AAC.bin" 4
Code outline
The sample programs can be outlined in 6 steps:
- Initialize source. In this step we need to find out the
specific properties of the streams we need to decode, e.g. compression type,
frame rate and sample rate, and create an AM_MEDIA_TYPE
structure (which is equivalent to the DMO_MEDIA_TYPE
structure) for each stream. For example if your source is a RTP stream you
might work out this information from the SDP-data. In these examples we open
a file stream from an AMP-bin file and parse the media types of all
contained streams. All code that relates to the source type used in these
examples has been incorporated in the AMPFileSource class.
- Create DMO decoder. We now create instances of the appropriate
decoder types and retrieve the IMediaObject
interface.
- Set input type. Using the media types from step one we can now
setup the input of our decoders using IMediaObject::SetInputType. For
more information on the supported media types the IMediaObject::GetInputType
function could be used or refer to the Axis DirectShow Guide.
- Set output type. We retrieve the preferred output type based on the
configured input from the decoders by calling IMediaObject::GetOutputType.
Then set the retrieved output type by calling IMediaObject::SetOutputType.
- Create input and output buffers. These examples provide two
basic implementations of IMediaBuffer
(the C++ version can be found at MSDN).
We now create two buffers for each decoder based on the requirements
specified by the decoder (IMediaBuffer::GetInputSizeInfo and
IMediaBuffer::GetOutputSizeInfo).
- Run decoding loop (simplified)
- Get one media sample and meta info from source.
- Copy data to input buffer.
- Send input buffer and meta info to decoder (IMediaBuffer::ProcessInput).
- Call IMediaBuffer::ProcessOutput with the output buffer
the get the result.
Remarks
- You may freely use the code contained in these samples. However, please
note that these samples are intended for educational purpose. Do not used
this code directly in an application!
- Please refer to Processing Data with DMOs
for detailed information on how to use DMOs.
- Please refer to the Axis DirectShow Guide for detailed information
on all Axis decoders.
- Note that the Axis H.264, MPEG-4 and AAC decoders are licensed and cannot
be freely distributed.
- The C# sample use DirectShowNET Library
in order to use the DirectShow framework from .Net. DirectShowNET Library
is licensed under LGPL.
- There will be performance penalties using the C# sample compared to the
C++ version due to the marshalling taking place between managed and native
code. The extent of the performance degradation primary depends on the data
size copied to and from the the input and output buffers. Note that by
default the output buffer is not marshalled to manage code, but there is some
code that can be uncommented in order to test this.
- The H.264 and MPEG-4 video decoder supports setting basic decoding quality
using the IAxH264Dec2 and IAxMP4Dec interfaces. These
interfaces are defined in the h-files provided with these samples. This
functionality has not been implemented in the C# sample. To accomplish this
the interfaces must be translated to C#.
- The H.264 decoder uses a one-frame-buffer look-ahead, i.e. the decoder will
output the previously inputted frame. To avoid returning an initial empty frame the
decoder will therefore output the first frame twice. This also means that,
normally, the last frame will not be decoded - but this can be worked around
by sending the last compressed frame to the decoder twice.
- Older H.264 decoder versions return 0x80070057 (E_INVALIDARG - 'One or more arguments are invalid') when a stand-alone SPS/PPS
is inputted.