Pushing a Stream to a Windows Media Server
You can broadcast a stream by pushing it to a Windows Media server, which is useful when you want to initiate the connection from the encoding application. This method is also a way to broadcast a stream when a firewall separates the computers hosting an encoding application and a Windows Media server.
When pushing a stream to a Windows Media server, you need to know the following:
- The name of the Windows Media server. This can be an alias, a fully qualified domain name, or an IP address.
- The name of a new or existing publishing point.
- Optionally, the name of an existing publishing point from which to use settings. For example, on the Windows Media server, you can configure a publishing point with the settings you would like to use each time you push a stream, and then you can use that publishing point as a template.
The following requirements must be met on the Windows Media server:
- HTTP must be enabled on the Windows Media server:
- On the Windows Media server, in the console tree, click the server that you want to use for this stream.
- In the details pane, click the Properties tab.
- In Category, click Control protocol.
- Enable the WMS HTTP Server Control Protocol plug-in.
- You must have write-access permissions on the Windows Media server through the WMS Publishing Points ACL Authorization plug-in. If you want to add publishing points using the Windows Media Encoder SDK API (rather than from the server) you must have create-access permissions for the plug-in. (Local administrators on the server automatically have both write- and create-access permissions on the server.)
- You must have access to the Windows Media Services service through DCOM.
If you are delivering the stream as a unicast from the Windows Media server, you can share the URL to the content in the format mms://server_name/publishing_point_name.
If you are delivering the stream as a multicast from the Windows Media server, you must do the following before you begin encoding:
Specify the Windows Media server port number by setting the PortNumber property using IWMEncBroadcast. This value defaults to 8080. The encoding process autodetects the port number, however, if you have access to the server through DCOM.
You can also specify the port number by appending it to the server name using the format YourServerName:PortNumber.
Generate a multicast information (.nsc) file, which contains information that enables players to access and decode the multicast stream, including the IP address, port, and stream format information.
Generate an announcement (.asx) file, which is a redirector file that points players to the multicast information file.
Distribute the announcement file to your audience, for example, by sending the announcement in an e-mail message or by placing a link to it on a Web page. When users open the file, the player downloads the multicast information file and begins playing the content.
The following examples show how to set up a multicast broadcast using IWMEncPushDistribution. For end-to-end code examples, see Complete Code Examples.
Visual Basic Example
' Create a WMEncoder object.
Dim Encoder As WMEncoder
Set Encoder = New WMEncoder
' Configure the encoding session including the input sources and profile.
' Create a push distribution object.
Dim PushDist As IWMEncPushDistribution
Set PushDist = Encoder.Broadcast
' Declare variables.
Dim sServerName As String
Dim sPubPoint As String
Dim sPubTemplate As String
Dim sMyNSCFile As String
Dim sMyNSCURL As String
Dim sMyASXFile As String
Dim sBrdcstInfo As String
' Provide values for the following variables.
sServerName = "YOURSERVERNAME:PORTNUMBER"
sPubPoint = "PUBLISHING_POINT_NAME"
sPubTemplate = "EXISTING_PUBLISHING_POINT_NAME"
sMyNSCFile = "NAME OF THE NSC FILE TO CREATE"
sMyNSCURL = "URL TO THE NSC FILE YOU CREATE"
sMyASXFile = "NAME OF THE ANNOUNCMENT FILE"
sBrdcstInfo = "NAME OF THE BROACAST INFORMATION FILE"
' Specify the server name, publishing point, an existing publishing point,
' and then generate an NSC file and announcement file.
PushDist.ServerName = sServerName
PushDist.PublishingPoint = sPubPoint
PushDist.Template = sPubTemplate
' Specify whether to destroy the publishing point.
PushDist.AutoRemovePublishingPoint = True
' Initialize the encoding session.
Encoder.PrepareToEncode True
' Generate the announcement file.
PushDist.GenerateMulticastInfoFile sMyNSCFile
PushDist.GenerateAnnouncementFile sMyNSCURL, sMyASXFile
' Start encoding.
Encoder.Start
C++ Example
// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include <comdef.h>
#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"
HRESULT hr;
IWMEncoder2* pEncoder;
IWMEncBroadcast* pBrdcst;
IWMEncPushDistribution* pPushDist;
// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder2,
(void**) &pEncoder);
}
// Specify the push distribution variables, including the Windows Media
// server name, publishing point, and announcement files.
// Provide real values for the following placeholders.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_Broadcast(&pBrdcst);
}
if ( SUCCEEDED( hr ) )
{
hr = pBrdcst->QueryInterface(IID_IWMEncPushDistribution, (void**)&pPushDist);
}
if ( SUCCEEDED( hr ) )
{
hr = pPushDist->put_PortNumber(WMENC_PROTOCOL_PUSH_DISTRIBUTION, 70);
}
CComBSTR strServerName("MyWMServer");
CComBSTR strPubPoint("MyPubPoint");
CComBSTR strPubTemplate("AnotherPubPoint");
CComBSTR MyNSCFile("\\\\servername\\share\\MyPubPoint.nsc");
CComBSTR MyNSCURL("\\\\servername\\share\\PubPoint.nsc");
CComBSTR MyASXFile("\\\\servername\\share\\MyPubPoint.asx");
// Remove the publishing point when the broadcast is over.
if ( SUCCEEDED( hr ) )
{
hr = pPushDist->put_AutoRemovePublishingPoint(VARIANT_TRUE);
}
// Set the push distribution variables.
if ( SUCCEEDED( hr ) )
{
hr = pPushDist->put_ServerName(strServerName);
}
if ( SUCCEEDED( hr ) )
{
hr = pPushDist->put_PublishingPoint(strPubPoint);
}
if ( SUCCEEDED( hr ) )
{
hr = pPushDist->put_Template(strPubTemplate);
}
// Initialize the encoding session.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}
// Generate the announcement file.
if ( SUCCEEDED( hr ) )
{
hr = pPushDist->GenerateMulticastInfoFile(MyNSCFile);
}
if ( SUCCEEDED( hr ) )
{
hr = pPushDist->GenerateAnnouncementFile(MyNSCURL, MyASXFile);
}
// Start the encoding process.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
}
// Release pointers.
if ( pBrdcst )
{
pBrdcst->Release();
pBrdcst = NULL;
}
if ( pPushDist )
{
pPushDist->Release();
pPushDist = NULL;
}
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
C# Example
using WMEncoderLib;
try
{
// Create a WMEncoder object.
WMEncoder Encoder = new WMEncoder();
// Configure the encoding session including the input sources and profile.
// Create a push distribution object.
IWMEncPushDistribution PushDist = (IWMEncPushDistribution)Encoder.Broadcast;
// Declare variables.
string sServerName;
string sPubPoint;
string sPubTemplate;
string sBrdcstInfo;
string sMyNSCFile;
string sMyNSCURL;
string sMyASXFile;
// Provide values for the following variables.
sServerName = "YOURSERVERNAME:PORTNUMBER";
sPubPoint = "PUBLISHING_POINT_NAME";
sPubTemplate = "EXISTING_PUBLISHING_POINT_NAME";
sBrdcstInfo = "NAME OF THE BROACAST INFORMATION FILE";
sMyNSCFile = "NAME OF THE NSC FILE TO CREATE";
sMyNSCURL = "URL TO THE NSC FILE YOU CREATE";
sMyASXFile = "NAME OF THE ANNOUNCMENT FILE";
// Specify the server name, publishing point, an existing publishing
// point, and then generate an NSC file and announcement file.
PushDist.ServerName = sServerName;
PushDist.PublishingPoint = sPubPoint;
PushDist.Template = sPubTemplate;
// Specify whether to destroy the publishing point.
PushDist.AutoRemovePublishingPoint = true;
// Initialize the encoding session.
Encoder.PrepareToEncode(true);
// Generate the announcement file.
PushDist.GenerateMulticastInfoFile(sMyNSCFile);
PushDist.GenerateAnnouncementFile(sMyNSCURL, sMyASXFile);
// Start encoding.
Encoder.Start();
}
catch (Exception e)
{
// TODO: Handle exceptions.
}
See Also