MMSSTV Engine in C#

How to use the MMSSTV Engine to develop a C# SSTV application

Introduction

Recently, for no particular reason, I renewed my interest in slow scan television (SSTV). This was brought on by a press release I saw regarding a special event SSTV transmission from the International Space Station (ISS). I decided I wanted to attempt to receive and decode the image. I planned to use my SDRplay RSP1A and the SDRUno application to receive the transmission. Using a virtual audio cable application I could send the audio to an SSTV application to decode the image. I set everything up and waited for the ISS to pass overhead. Due to limitations with my antenna, I was only able to hear the transmission for about 10 seconds. This wasn't even close to sufficient duration to enable decoding the image the ISS crew was sending. However it did get me looking at software packages for sending and receiving SSTV so that I could compare them. While researching SSTV applications, I remembered that the author of MMSSTV, Makoto Mori JE3HHT, graciously provided an SSTV engine in a dynamic link library (DLL) that could be used by other application developers to send and receive SSTV images. I started looking at the documentation for that engine and down the rabbit hole I went. 

What is SSTV?

SSTV is a method for transmitting static images via radio, most commonly used by amateur radio operators (HAMs). Because HAMs transmit SSTV over frequencies also used for voice transmissions, there are bandwidth limitations and regulations that they must comply with.This means that SSTV used by HAMs is narrow banded when compared to broadcast television. Broadcast television uses a much wider bandwidth and can transmit a number of picture frames per second to create a moving image. In contrast, SSTV sends one static image in a few seconds or even up to several minutes, depending on the SSTV mode used by the sender. The SSTV mode in use determines the image resolution, transmission time, and color depth.

Anyone interested in learning more about SSTV can do a web search which will turn up a wealth of information and history. A form of SSTV was even used by the early Apollo missions to send images from the far side of the moon.

What is the MMSSTV Engine?

Makoto Mori JE3HHT developed and released an SSTV application for HAMs called MMSSTV. Although the application hasn't been updated by Mako in a number of years it is still one of the more popular SSTV applications. Mako decided the next logical step was to release an SSTV engine consisting of a library of functions that could be used by application developers to integrate SSTV into their applications. Along with the engine, Mako provided several sample applications to demonstrate how to use the library functions. These sample applications were written using C++ and Visual Basic 6. No examples using a .NET programming language were provided as .NET 1.0 was released around the same time that the library was released.

What is the issue using the MMSSTV Engine in C#?

Since the time the MMSSTV engine was developed, Microsoft has moved to a model where code execution is managed by a Common Language Runtime (CLR) and is known as managed code. Managed code compilers generate an intermediate language (IL) that is then executed by the CLR. The C++ and VB6 compilers used for the sample applications generate unmanaged code that is executed directly by the operating system rather than by the CLR. In order to use the MMSSTV engine from a .net application using C# we need to develop a bridge between the managed code and the unmanaged MMSSTV engine.

The MMSSTV Engine library was written as a Windows 32 bit DLL and uses the stdcall calling convention that is also used by the Windows API. This means that programming languages that are able to directly use the Windows API can also use the SSTV engine. Since there are still some things that can't be done in a pure .NET application, .NET provides the Platform Invoke (PInvoke) functionality to permit .NET applications to directly call the Windows API. Therefore we can use PInvoke to access the MMSTV Engine. All that is required is to create the proper signatures so that C# knows how to call the functions, pass in the arguments, and get back the results.

My Solution

I created a file with the C# PInvoke signatures for all of the MMSSTV Engine library functions. Since I created these signatures by hand there is a high likelihood that some errors were made. To help test my signatures I wrote a basic SSTV client application using the MMSSTV Engine. I based my demo/test application on the examples provided by Mako. The demo application doesn't verify every one of my PInvoke signatures, but it does test most of the more commonly used functionality.

I have uploaded the PInvoke signatures and the demo application to Github so that anybody desiring to write a C# SSTV client application using the MMSSTV Engine can use it as an example. I hope that somebody benefits from it and develops a really cool SSTV application.

You can find the PInvoke signatures and the demo application on Github at MMSSTV.Net (github.com)

Written by Seth Cohen on 16-Dec-2021

If you want to encourage me to continue developing software you can