Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Working with Stream Buffer engine - TIME SHIFT on Windows XP Service Pack 1

0.00/5 (No votes)
7 Jun 2004 1  
The new generation of capture device - MPEG2 capture that does time shift.

Introduction

This article refers to Microsoft Windows XP with Service Pack 1 only. The SBE.dll will be only in Windows XP with DirectShow 9, with Service Pack 1 installed. The documentation for the SBE can be found at Microsoft.

New generation of capture devices (the old ones are raw capture devices) consist of MPEG1,2 hardware encoder. The capture devices are divided today into two main categories:

  • Raw Capture Device -> Video Renderer
  • MPEG2 Capture Device -> MPEG2 Demultiplxer ->MPEG2 Video Decoder -> Video Renderer.

One big difference between Raw capture device � (TV Tuner boards) and the MPEG2 capture device is the graph edit and the ability to render. Any USB Camera device, TV Tuner Capture device (WDM capture device) can be built in the graph in a simple way by adding the device into graph and then trying to render its output pin (capture pin or preview pin).

For example - raw capture device:

Sample screenshot

Up till today (when this article is being published), almost all the third party applications and even Microsoft Windows Movie Maker (WMM), MSN Messenger, Yahoo Messenger, etc. do not support building graph for MPEG2 devices in their software. (I hope, after they read this article every one will add it.).

An example of graph of MPEG2 will look like this:

Sample screenshot

Today you can choose to watch TV in you computer in two different ways:

  • Using TV Tuner Raw Capture device.
  • Using MPEG Capture device.

Using MPEG2 capture device has several advantages over Raw capture device. One of them is the ability to use latest technology of TIME SHIFT using SBE.dll (Stream Buffer Engine).

Stream Buffer Engine � TIME SHIFT.

The two filters inside of this DLL enable to build a special graph that will let you do time shift on your computer. Time shift is the ability to stop the preview of a movie, while the movie is always being recorded to file. This lets you watch your TV Show in your own time without missing one second of the movie.

..One step before we go into the source code.

Two notes:

  1. The SBE Sync converts the multiplexing of the MPEG2 Program Stream into ASF. So, the result of this is that the source graph uses different source � the Stream Buffer source:

    Sample screenshot

    Stream Buffer Source and Stream Buffer Engine in the graph edit tool.

    An example of Stream Buffer Source graph:

    Sample screenshot

  2. The time shift sync engine creates files under system hidden directory at one of your hard drives, under directory TEMP_SBE.

    The files have an extension .tmp.

    In order to play those files under Windows XP outside the application, you should do the following:

    • Convert the file extension to dvr-ms extension.
    • Download � if you did not do it already, a patch from Microsoft site that fixes the audio problem inside this SBE.DLL. ( Q810243_WXP_SP2_x86_ENU.exe)

The Example Code

The first version of this code will enable to do TIME SHIFT using MPEG2 hardware device.

Sample screenshot

The code has the following classes:

  • CSBESource
  • CSBESync
  • CDirectShowGraph

Stream Buffer graph works as two building graphs, one for the capture device and one for the preview. The CSBESync is the graph of the WDM MPEG capture device, and the CSBESource is the player graph.

CSBESync is building the following graph:

Sample screenshot

The code shows how to configure the MPEG2 Demultiplxer using code in CDirectShowGraph::AddMpeg2Demultiplex.

The two classes, source and sync, build the two graphs manually including selecting of the MPEG2 video decoder, and why, I think it is the best to configure it manually and not just rendering. This assures that the graph will connect and it verifies that the components are in the system. From experience, rendering does not work most of the time, there are times where the rendering fails, and using manual connection, it succeeds. And there are times even that the computer will crash for bad video decoder (for example � hardware decoder).

Using the code in your application

SBESyncHandler = new CSBESync(this);

try {
    SBESyncHandler->Preview();
}

catch (int v) {
    AfxMessageBox("Error in preview"); 
}

pWindow = new CActiveWindowDlg (this); 
pWindow->Create(IDD_ACTIVE_WINDOW_DLG , this);

SBESourceHandler = new CSBESource(this);
try { 
  SBESourceHandler->SetVideoWindow(pWindow->GetSafeHwnd());
  SBESourceHandler->PlaySync(SBESyncHandler->dsGraph->pStreamBufferSyncInterface,
                    SBESyncHandler->dsGraph->pStreamBufferSyncFilter);
}
catch (int v) { 
  AfxMessageBox("Error in preview"); 
}
 
SBESyncHandler->Run();
Sleep(100); 
pWindow->ShowWindow(SW_SHOW);
SBESourceHandler->Run();

More points..

  • You can easily create different audio or video decoder classes, copy the eVideoDecoder or the mAudioDecoder to a different name and change the class name.

    Then, change the CLSID and the pin name. This is not an infinite job, there aren�t too much audio and video decoders. Here is a list: Microsoft Audio Decoder, CyberLink, Elecard (Moonlight), InterVideo, Ligus.

  • If existing do not correct any SBE graphs, like SHIFT+F5, or if a bug is being detected and the application does not exit correctly, Windows will start moving the mouse heavily and it will require a reboot. Therefore, when debugging SBE graph application, don�t leave any open files, application or documents, because in a problem, you will not be able to close them and could lose data.

Playing DVR-MS Files.

The output files of the stream buffer engine are basically MPEG2 video + MPEG audio multiplex into ASF. The Stream Buffer sync converts in real time the MPEG2 Program stream into ASF (here, I will ask why Microsoft did not give an option to leave it as program stream, cause if you want to burn MPEG2 file into DVD, it becomes complex). There is an option to play those files individually under any Windows XP machine. For that, you need to do several steps:

  1. Download Microsoft Windows Media Player 9 - (if you wish to play it under WMP)
  2. Download Microsoft latest hot fix for this specific issue here (Windows XP SP1 Update: Watch TV Shows Recorded by Media Center PCs on Other Windows XP PCs).
  3. Change the file name into extension DVR-MS instead of MPEG or tmp (as it saves automatically at this extension.)

Then, you can, or build your own graph as described in this document or play it under Windows Media Player 9. Again, only if you change it into DVR-MS, Windows Media Player will play it correct.

Playing DVR-MS files using those classes

pWindow = new CActiveWindowDlg (this); 
    pWindow->Create(IDD_ACTIVE_WINDOW_DLG , this);
    SBESourceHandler = new CSBESource(this);
try {
  SBESourceHandler->SetVideoWindow(pWindow->GetSafeHwnd());
  SBESourceHandler->PlayFile(name); 
}
catch (int v) { 
   AfxMessageBox("Error in PlayFile"); 
   dsDelete();
   return ; 
}
   pWindow->ShowWindow(SW_SHOW); 
   SBESourceHandler->Run();

And..

I am using a CActiveWindowDlg class to host the video window. This class is warped under CBitmapButton class that is a full skin dialog bitmap class (I think it was taken from The Code Project � it was years ago).

Feedback and Improvements

Post comments, questions, and stories to the forum below, so all can benefit. I will try to keep an eye on the forums. Feel free to send me a copy of the post or reminder if I haven't checked the forums for a while.

Feel free to submit your patches and improvements to support@becapture.com. If they fit within the scope of the project, I'll integrate them, give you credit for your work, and post the updated project on this page for everyone.

If I see involvement and good participation and request, I will submit more versions.

Goals:

My main goal is to push in the MPEG2 capture device and to convince many software manufactures to support building of MPEG2 graph in their software. After all, the MPEG2 WDM capture device is in the same category of the USB Camera and WDM TV Tuner, but it is not yet supported in DVD Authoring software, Windows Movie Maker and more.

Profile:

My profile is my home page.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here