Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / December 2005



Tip: Looking for answers? Try searching our database.

Lock around DecompressSequenceFrameWhen?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howdy Pierce - 14 Dec 2005 18:55 GMT
I am porting a specialized video plugin to OS/X.  This is a
multithreaded plugin that runs under Safari and Firefox, using the
Netscape API.

To render the video, I have a YUv image that I blit to a graphics port
using the following code snippet:

CodecFlags    returnedCodecFlags;
CGrafPtr        prevGrafPort;
Rect saved_rect, check;
RgnHandle saved_clip;

saved_clip = NewRgn();

// save the current port, port bounds, and clipping rectangle
GetPort (&prevGrafPort);
GetPortBounds(m_port, &saved_rect);
GetClip(saved_clip);

// Make sure (0,0) is at the left-top of the browser window.
SetPort (m_port);
LockPortBits(m_port);  // doc says not to use this with QT, but has no
obvious effect
SetOrigin (0,0);
ClipRect(&m_clipping_rect);

OSErr err = DecompressSequenceFrameWhen(m_sequence, (Ptr) image,
            sizeof(PlanarPixmapInfoYUV420), 0, &returnedCodecFlags, nil);

GetPortBounds(m_port, &check);
if (check.left != 0 || check.top != 0)
    Log("Warning: origin moved to %dx%d during draw operation\n",
                    check.left, check.top);

QDFlushPortBuffer(m_port, NULL);

// Restore previous settings
SetOrigin( saved_rect.left, saved_rect.top );
SetClip( saved_clip );

UnlockPortBits(m_port);
SetPort (prevGrafPort);

The problem is, there doesn't seem to be any way to lock the port from
being simultaneously drawn in another thread, and hence the origin
moves around during my drawing operation (most noticably on a dual-CPU
Mac).

Although we wrote our code independently, in researching this problem I
found that the open-source MPEG player VLC has the same issue (it even
has a comment in the code asking about a lock).

So -- my questions:

1. Is it possible to somehow lock a port so that between a call to
SetOrigin and another call (in this case DecompresSequenceFrameWhen),
the origin won't change?

2. Alternately -- is it possible to somehow get my own port which is a
child of the existing port handed in by the browser?  How would I go
about this?

Thanks very much for your help,
--Howdy Pierce
 howdy@cardinalpeak.com
 www.cardinalpeak.com
Eric Albert - 15 Dec 2005 05:38 GMT
> I am porting a specialized video plugin to OS/X.  This is a
> multithreaded plugin that runs under Safari and Firefox, using the
[quoted text clipped - 9 lines]
>
> saved_clip = NewRgn();

> The problem is, there doesn't seem to be any way to lock the port from
> being simultaneously drawn in another thread, and hence the origin
[quoted text clipped - 14 lines]
> child of the existing port handed in by the browser?  How would I go
> about this?

Quickdraw is not thread-safe.  When using it, you should only draw from
the main thread.

I'd suggest doing all of your calculations on secondary threads and then
queueing the results up for display on the main thread.

Hope this helps,
Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.