Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 03 Sep 2003
Offline Last Active Dec 18 2014 10:53 AM

Topics I've Started

[DirectShow] Overriding CBasePin::ReceiveConnection to handle dynamic format changes

11 January 2011 - 05:04 PM

I'm working on an in-place transform filter (CTransInPlaceFilter) and have hit a snag. I have a DVD MPEG-2 decoder which connects at 720x480 then changes to the (correct) 720x576 some time afterwards. The default implementation of CBasePin::ReceiveConnection returns VFW_E_ALREADY_CONNECTED if the pin is already connected, which means that the attempt to change format fails and the video plays back at 720x480. This naturally degrades image quality and also causes rendering issues with DVD menus (compare to the intended appearance).

I have overridden the GetPin method to return my own pin which derives from CTransInPlaceInputPin and overridden its ReceiveConnection method. In doing so I have tried to do what MSDN says I should be doing, but I'm not entirely sure what I'm supposed to be doing. The below code appears to work, but I'm inherently distrustful of code that works first time and without me fully understanding what it's doing.

STDMETHODIMP CNameOfMyInputPin::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt) {
    CheckPointer(pConnector, E_POINTER);
    CheckPointer(pmt, E_POINTER);

    if (!m_Connected) {
        return __super::ReceiveConnection(pConnector, pmt);
    } else {
        HRESULT hr;

        // Fetch my output pin.
        IPin* outputPin = m_pFilter->GetPin(1);
        // Get the downstream input pin it is connected to.
        IPin* downstreamInputPin;
        hr = outputPin->ConnectedTo(&downstreamInputPin);
        if (hr != S_OK) return hr;

        // Call ReceiveConnection on the downstream pin.
        hr = downstreamInputPin->ReceiveConnection(this, pmt);
        if (hr != S_OK) return hr;
        // Call NotifyAllocator on the downstream pin.
        IMemInputPin* memoryInputPin;
        if (downstreamInputPin->QueryInterface<IMemInputPin>(&memoryInputPin) == S_OK) {
            IMemAllocator* allocator;
            if (memoryInputPin->GetAllocator(&allocator) == S_OK) {
                memoryInputPin->NotifyAllocator(allocator, FALSE);

        return hr;
I'd greatly appreciate any feedback!

Correct colour of LaTeX equations against the Classic Black theme (Opera/Firefox)

04 December 2010 - 11:30 AM

If you use the dark theme you may have noticed that equations in posts made by certain users are virtually illegible.

Before and after installation of the UserScript

To correct this, here are two userscripts, one for Opera and another for Firefox (requires Greasemonkey). The lower half of the above screenshot shows the result of the fix; the equations should be coloured according to the current font colour rather than the default black.

[web] Non-blocking file download in PHP

27 October 2010 - 02:52 AM

I need to download a number of files from a number of different web servers. At the moment each file takes around two seconds to download. When each file is downloaded sequentially, this results in about a three minute wait for one hundred files. Most of this time is spent waiting for the file to download rather than any useful work, however.

What I'd like to do is find a non-blocking way to download these files in PHP, so I could (for example) fire off one hundred requests in a very short amount of time and then process the results as they come in rather than waiting for each one in turn. However, I have not been able to find a way to do this in PHP (I'm more familiar with doing this in .NET, but this project is a PHP one). The script performing the requests is not going to be public facing, but running in the background periodically (using scheduled tasks/cron). I'd appreciate any tips!

Integer-only line clipping to y=0, y=x and y=-x

16 October 2010 - 02:07 PM

I need to clip line segments to y>0, y>x and y>-x.

My current prototype uses floating point arithmetic. For y>0 I check if each end of the line's y component is negative and if so use linear interpolation to bring it up to y=0. For y>x and y>-x I substituted y=x or y=-x into y=mx+c to produce a simple calculation to clip the line.

Here's an early version for Evaldraw.
// Stores the line position.
static x1=-50,y1=100,x2=50,y2=100;

// Are we holding either end?
static end_held = 0;



// Get the screen centre and maximum dimension.

// Draw the unclipped line.

// Draw the axes and clipping regions.

// Order so x1<=x2

// Set this to non-zero if the line has been culled.

if (y1 < 0 && y2 < 0) {
culled = 1;
} else {
// Clip against Y=0.
if (y1c < 0) {
x1c = x1c - (x2c - x1c) * (y1c / (y2c - y1c));
y1c = 0;
if (y2c < 0) {
x2c = x2c - (x2c - x1c) * (y2c / (y2c - y1c));
y2c = 0;

// "Out of right bounds" (Y=+X).
or1 = x1c > y1c;
or2 = x2c > y2c;

// "Out of left bounds" (Y=-X).
ol1 = x1c < -y1c;
ol2 = x2c < -y2c;

if (or1 && or2 || ol1 && ol2) {
culled = 1;
} else {
if (ol1) {
// Clip 1 to Y=-X.
c = x1c - (x2c - x1c) * (y1c / (y2c - y1c));
m = (x2 - x1) / (y2 - y1);
x1c = c / (m + 1);
y1c = -x1c;
if (ol2) {
// Clip 2 to Y=-X.
c = x2c - (x2c - x1c) * (y2c / (y2c - y1c));
m = (x2 - x1) / (y2 - y1);
x2c = c / (m + 1);
y2c = -x2c;
if (or1) {
// Clip 1 to Y=+X
c = x1c - (x2c - x1c) * (y1c / (y2c - y1c));
m = (x2 - x1) / (y2 - y1);
x1c = -c / (m - 1);
y1c = x1c;
if (or2) {
// Clip 2 to Y=+X
c = x2c - (x2c - x1c) * (y2c / (y2c - y1c));
m = (x2 - x1) / (y2 - y1);
x2c = -c / (m - 1);
y2c = x2c;

// Draw the clipped line.
if (culled == 0) {

// Update the line position using the mouse.
mx = mousx - cx;
my = mousy - cy;
p1 = (x1-mx)*(x1-mx)+(y1-my)*(y1-my);
p2 = (x2-mx)*(x2-mx)+(y2-my)*(y2-my);

if (end_held == 1) {
p1 = 0;
} else if (end_held == 2) {
p2 = 0;

if (p1 < p2) {
if (p1 < 64) {
drawsph(x1+cx, y1+cy, -10);
if (bstatus) {
end_held = 1;
x1 = mx;
y1 = my;
} else {
end_held = 0;
} else {
if (p2 < 64) {
drawsph(x2+cx, y2+cy, -10);
if (bstatus) {
end_held = 2;
x2 = mx;
y2 = my;
} else {
end_held = 0;

Unfortunately, I intend to transfer this code to a machine that does not support hardware multiplication, division or floating-point arithmetic. I am currently converting it to use fixed-point arithmetic with a variety of workarounds, such as different code paths if the line is steep or shallow. In the interest of improving performance I'd be interested to hear if anyone had any suggestions for an integer-only technique, preferably one that minimises the number of multiplication or division operations.

Type mismatch: 'm_l2Power'

11 October 2010 - 09:01 AM

I keep getting the following error when viewing forum pages (or the journal index):
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'm_l2Power'

/community/forums/lib/md5.asp, line 119

After refreshing the page I am presented with the service agreement which I have to agree to.

Another oddity is that the UserName field on the post page says
UserName: benryves (publicly known as )

I presume this is for people who log in with one name but show up as another, and I also assume it shouldn't be there.

Is anyone else having these issues?