Add Input Source to Media Streaming Server - Windows C++

This tutorial shows how to add an input file and stream it using the LEADTOOLS Media Streaming SDK in a C++ Windows API application.

Overview  
Summary This tutorial covers how to add input source to streaming server in a C++ Windows application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (18 KB)
Platform Windows C++ Application
IDE Visual Studio 2019
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Before working on the Add Input Source to Media Streaming Server - Windows C++ tutorial, get familiar with the steps to create a C++ project by reviewing the Add References and Set a License tutorial.

Create the Project and Add LEADTOOLS References

Start with a copy of the 64-bit Windows API project created in the Add References and Set a License tutorial. If the project is not available, create it by following the steps in that tutorial.

In order to use the streaming server, LEADTOOLS requires additional references. Add the required library reference by opening the pre-compiled header file, either pch.h or stdafx.h depending on the Visual Studio version used, and add the following line:

// Add LEADTOOLS Media Streaming reference 
#include "C:\LEADTOOLS22\Include\ltms.h" // use actual path where you installed LEADTOOLS 

Note

For a complete list of which DLLs are required for specific media streaming features, refer to Media Streaming Files You Must Include With Your Application.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:

Note

Adding LEADTOOLS references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Add the Streaming Server Code

Now that the LEADTOOLS references have been added and the license has been set, coding can begin.

The steps below are for Visual Studio 2019; they could be different for other versions of Visual Studio.

Go to the Solution Explorer and double-click the resources file (.rc). Expand the menu tab in the resources tree and double-click the menu resource to open it in the designer interface. In the empty item below the Exit item, click and type &Start Streaming. Drag the new item above Exit. Ensure the item's ID is ID_FILE_STARTSTREAMING.

Open the project's CPP file and navigate to the WndProc function and under the switch (wmId) statement, that is below the WM_COMMAND case, add the new case below.

// In WndProc(), under "case WM_COMMAND:" 
switch (wmId) 
{ 
   case ID_FILE_STARTSTREAMING: 
   { 
      CoInitialize(0); 
      IltmsServer* pServer = NULL; 
      CoCreateInstance(__uuidof(ltmsServer), NULL, CLSCTX_ALL, __uuidof(IltmsServer), (void**)&pServer); 
      IltmsNetworkProperties* pProps; 
      pServer->GetNetworkProperties(&pProps); 
      BSTR szIpAddress; 
      pProps->get_ActualIPAddress(&szIpAddress); 
      long lPort; 
      pProps->get_Port(&lPort); 
      WCHAR szHttpUrl[1024] = { 0 }; 
      swprintf_s(szHttpUrl, ARRAYSIZE(szHttpUrl), L"http://%ls:%ld/DaDa_H264.mp4", szIpAddress, lPort); 
      SysFreeString(szIpAddress); 
      BSTR szMediaFolder = SysAllocString(L"C:\\LEADTOOLS22\\Resources\\Media"); 
      pProps->put_MediaFolder(szMediaFolder); 
      SysFreeString(szMediaFolder); 
      pServer->SetNetworkProperties(pProps); 
      pProps->Release(); 
      pServer->Start(); 
      ShellExecuteW(hWnd, L"open", szHttpUrl, NULL, NULL, SW_SHOWNORMAL); 
      MessageBoxW(hWnd, L"Streaming server started.\nAttempting to playback stream in default browser.\n" 
         "Click OK to stop server", szHttpUrl, MB_ICONINFORMATION); 
      pServer->Stop(); 
      pServer->Release(); 
      CoUninitialize(); 
   } 
   break; 
   // Keep rest of the code as is 

Prepare the Media Folder and File

Make sure to pass a valid folder name to put_MediaFolder(). In the code above, "C:\LEADTOOLS22\Resources\Media" is used, but it can be changed to a different location.

Also, place a valid MP4 video file in that folder to use it for testing. For this tutorial, the file DaDa_H264.mp4 can be used, which is shipped with LEADTOOLS 22 Multimedia SDK in the <INSTALL_DIR>\LEADTOOLS22\Resources\Media folder.

Run the Project

Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps are followed correctly, the application runs. Choose Start Streaming from the File menu to let the program start streaming the video and attempt to launch the default web browser to play back the video on it.

Wrap-up

This tutorial showed how to add a video source and stream it using the ltmsServer object.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.


Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.