Many users routinely stream audio and video content over the Internet, but few administrators have managed streaming-media servers. With the release of Windows Server 2003, Microsoft Windows Media Services (WMS) has been revamped to make it easier to administer and use. It's so easy, in fact, that companies both large and small are now beginning to stream training videos, company meetings, daily briefings, and other content. This type of content distribution to the workforce has resulted in large cost savings and a more productive workforce. To improve productivity even further, you can use Perl scripts to manage WMS.
For those of you who aren't familiar with streaming media and WMS, let me introduce them to you. Then I'll show you how to write scripts that retrieve WMS information and manage WMS.
What Is Streaming Media?
Streaming media is audio, video, or data delivered over a network in real time. You can broadcast the content or deliver it on demand.
Streamed broadcasts. Streamed broadcasts are like a cable television broadcast. When you want to watch your favorite show, you tune your TV or cable box to the particular station and you begin to receive the broadcast almost instantly. You don't have to wait a long time to download the broadcast to disk first; it simply plays while you receive the data.
The real-time nature of streaming media makes it ideal for sharing presentations (e.g., concerts, news events, speeches) over a network. The presentations might or might not be live, but they're considered to be a shared experience. Just as with a cable television broadcast, a streamed broadcast can be viewed by multiple people at the same time. Therefore, all viewers observe the same content at the same time.
Many online radio stations and music services have eagerly taken advantage of streamed broadcasts to provide music, talk shows, or other types of content. Other types of businesses have also been leveraging streamed broadcasts to cut costs and provide useful media solutions to employees. For example, instead of flying in employees from various regional offices around the world and putting them in hotels for a conference or meeting, many companies are streaming such events over a secured corporate network or even over the Internet.
On-demand streams. If watching a streamed broadcast is like watching a cable television show, then watching an on-demand stream is like watching a DVD movie. You can watch an on-demand stream whenever you want and in whatever way you want. For example, you can pause playback so that you can get up and take a break.
Some companies use on-demand streams for training classes. Scheduling everyone to meet in a class at the same time for specialized training can be difficult, so it makes sense to let employees view the content when they can. Thus, they can view the training not only during business hours but also after hours and on weekends. And because the training is on demand, users can pause the training to answer the phone, stop the training to get some lunch, rewind to hear a confusing section again, and even speed up playback of slow-paced content.
In WMS, there's a new feature called FastCache that enables on-demand streaming that's faster than real time. With FastCache streaming, the client cache receives content to disk while that content is playing. Because the receive rate is faster than the playback rate, you might end up caching the entire content before you've finished playing it. In this case, the remainder of the content plays back from the disk cache. There's no longer any content flowing from the server, even if you pause, play, or rewind.
What Is WMS?
As part of the Windows 2003 platform, WMS (also known as the WMS 9 Series) offers an easy-to-use interface coupled with a powerful streaming-media server. In contrast to its predecessor (WMS 4.1, which shipped with Windows 2000 Server), the WMS 9 Series is easier to use, more flexible, and scales far better.
The version of WMS that comes with Windows 2003, Standard Edition, differs from the version that comes with Windows 2003, Enterprise Edition. The enterprise version of WMS provides more features, such as event scripting plug-in support. Regardless of which version you use, you can still use Perl to interact with WMS.
All the Windows Media tools you need to create, distribute, and play audio and video content are free and easily accessible. You create content with tools such as Windows Movie Maker and Windows Media Encoder. After you create the content, you use WMS to distribute it directly to a player or to another server (for purposes of distribution). Alternatively, you can receive a live broadcast from an encoder and distribute that broadcast to servers and players. You use Windows Media Player (WMP) to receive and render the content. The entire system is available without the need to purchase additional licenses per stream. For more details about the various Windows Media tools, go to http://www.windowsmedia.com.
Scripting WMS
One nice feature about WMS is that the entire WMS 9 Series object model is scriptable, which means that you can use scripting languages such as Perl, VBScript, and JavaScript to interact with WMS. Such scripting support is ideal. You can write scripts that you can run from a command line or write Active Server Pages (ASP)based Web pages that can interact with your WMS server.
The WMS 9 Series software development kit (SDK) contains everything you need to start writing code that interacts with WMS. The SDK is available on the Microsoft Developer Network (MSDN) Web site at http://
msdn.microsoft.com/library/en-us/wmsrvsdk/htm/aboutwindowsmediasdk.asp.
The most important thing a WMS scripter needs to know is how to get started. When using Perl, you need to begin by including the code that Listing 1 shows in your script. This code first loads the Win32::OLE extension so that the script can use COM. The code then loads the WMS type library so that the script has access to WMS constant values. Finally, the code at callout A in Listing 1 creates a connection to WMS. When this code runs, the $Server variable represents the IWMSServer interface, which is the entry point into the WMS server. The various properties and methods of the IWMSServer object let you retrieve information about the WMS server and manage WMS. (You can find details about the various methods and properties that this interface provides at http://msdn.microsoft.com/library/en-us/wmsrvsdk/htm/iwmsserverobject.asp.)
Note that the code at callout A works only when your user account has permissions to act as a WMS administrator and when the script is running on the same local Windows 2003 server as WMS. If you need to connect to WMS on a remote Windows 2003 server, you can use Distributed COM (DCOM). You also need to delete the code at callout A and uncomment the code that callout B shows. The $Machine variable can be the remote WMS server's name, DNS name, or IP address. Because the code at callout B works for local machines as well as remote machines, it's the code I use in my Perl scripts. Note, however, that you'll need to define the $Machine variable so that it points to your local machine.
Obtaining WMS Server Information
After you've created the $Server variable, you can interact with your WMS server as much as you like. Two scriptswmServerStatus.pl and wmServerLimits.plprovide examples of how to do so.
The wmServerStatus.pl script demonstrates a simple interaction. This script retrieves the current status of the specified WMS server. You specify the server when you launch the script. The syntax for the launch command is
perl wmServerStatus.pl
[machine name]
where machine name is the name of the remote WMS server on which you want to run the script. If you want to run the script on the local WMS server, you don't need to include this optional argument. (Although this command appears on several lines here, you need to enter it on one line in the command window. The same holds true for the other multiline commands in this article.)