TweetFollow Us on Twitter

March 93 - SOMEWHERE IN QUICKTIME

SOMEWHERE IN QUICKTIME

TOP 10 QUICKTIME TIPS

JOHN WANG

[IMAGE 031-033_QuickTime_column1.GIF]



To inaugurate this new column on QuickTime, we'll take a look at ten useful tips for QuickTime application developers. This is certainly not an exhaustive list, but itis  an important one.

Here's the list:
10. Working around data reference limitations.
9. Using GetMovieNextInterestingTime.
8. Not calling ExitMovies.
7. Getting a movie's unscaled size.
6. Avoiding the Movie Toolbox when using the standard movie controller.
5. Prerolling a movie for improved playback.
4. Using CustomGetFilePreview with custom dialogs.
3. Conditionally registering a component that requires a hardware device.
2. Detaching a movie controller properly.
1. Calling MaxApplZone from every application.

Some of the tips describe pitfalls that need to be avoided, while others are simply clarifications. Let's take a closer look at each one.

10. Working around data reference limitations.

A current limitation of QuickTime is that each media can have only one data reference to a media data file. This isn't a problem except when you start cutting and pasting between tracks that refer to different media. You'll then be required to copy the media data from one media data file to another. For example, InsertTrackSegment will copy media data between media if the tracks refer to different media.

Calls like GetMediaDataRefCount, AddMediaDataRef, and GetMediaDataRef will reflect the "one data reference" limitation by only accepting index values of 1. You can't replace an existing media data reference in QuickTime 1.0, but you can in QuickTime 1.5, with a new call, SetMediaDataRef. Using this routine is a common way of manuallyresolving media data references that may have been moved by an application. For example, if you move a movie data file onto a different volume, you can update the alias using the Alias Manager and update the data reference for the movie with SetMediaDataRef.

9. Using GetMovieNextInterestingTime.

Since QuickTime is time based rather than frame-number based in the way it deals with temporal video data, a common question is how to get information about movie frames, such as frame rate. The answer is to use GetMovieNextInterestingTime. This function allows you to step quickly and easily through interesting times in a movie. For example, for an estimate of the frame rate of a movie, you could use GetMovieNextInterestingTime to count the total number of frames in the movie and divide it by the total duration of the movie. Likewise, you could use GetMovieNextInterestingTime to identify the 600th frame in a movie. Since the internal data structure of QuickTime movies is optimized for accessing this type of information, GetMovieNextInterestingTime and the other GetNextInterestingTime calls are very efficient.

8. Not calling ExitMovies.

One recommendation that contradicts QuickTime 1.0 documentation is that applications should not call ExitMovies before quitting. QuickTime calls this function at ExitToShell time, and it's safer to allow QuickTime to release private storage and component connections at that time. This prevents problems such as closing components in the wrong order. For example, the proper way to clean up after a movie that uses a standard movie controller is to dispose of the movie controller first, and then dispose of the movie. If done in the reverse order, there may be adverse consequences.

7. Getting a movie's unscaled size.

An application should save the movie box obtained with GetMovieBox when a movie is loaded so that it can retrieve the intended offset and scaling of the movie for playback. However, some applications may also want to get the unscaled size, and there isn't an intuitive way to get it. Since the programmatical effect of calling SetMovieBox is that the movie matrix is changed to reflect the new offset and scaling, you can easily get the movie box for an unscaled movie by setting the movie matrix to the identity matrix; using the utility routine SetIdentityMatrix along with SetMovieMatrix accomplishes this. Then GetMovieBox will return the unscaled size and offsets.

However, there's a loophole. If a track inside the movie is scaled, there may still be scaling in playback since QuickTime supports transformation matrices for movies and for tracks within a movie. Therefore, when working with scaling, applications need to pay attention not only to the movie's scaling but to the tracks' scaling as well.

6. Avoiding the Movie Toolbox when using the standard movie controller.

When using the standard movie controller, you should almost never use any Movie Toolbox routines that control movie playback or change movie characteristics. For example, it would be a mistake to call StartMovie to start playing a movie. Instead, use the movie controller equivalent, MCDoAction with mcActionPlay. Calling StartMovie directly causes the movie to play but with the controller's button in the pause state, not reflecting that the movie is playing back. Similarly, to set looping, you would use MCDoAction with mcActionSetLooping. Bypassing the movie controller by using the Movie Toolbox routines directly on a movie controlled with a movie controller can have dire consequences. As an example, if you set looping for a movie before creating a controller with NewMovieController, you'll cause the Macintosh to crash. Don't let it happen to you!

5. Prerolling a movie for improved playback.

Prerolling can improve playback performance by allowing QuickTime to do preliminary initialization. Since PrerollMovie is passed the movie time and rate, it can fill buffers and caches optimally to prevent initial stuttering. Normally, QuickTime automatically prerolls the movie for you. For example, if you call StartMovie, you don't need to also call PrerollMovie, since StartMovie prerolls the movie for you. The QuickTime 1.5 documentation describing the StartMovie call states this clearly. Likewise, the standard movie controller is optimized to preroll whenever the user starts a movie with the keyboard or mouse. If you call PrerollMovie in these situations, the second PrerollMovie is redundant and will simply waste time. In all other cases, prerolling by calling PrerollMovie is recommended before initiating playback. For example, you should call PrerollMovie before SetMovieRate.

4. Using CustomGetFilePreview with custom dialogs.

If you use CustomGetFilePreview with custom DLOG and DITL resources, you should be aware of a bug with the System 7 pop-up menu CDEF: pop-up menus used in conjunction with black-and- white grafPorts are shifted to the wrong location within the dialog box. The simple workaround is to force the dialog to be a cGrafPort by adding a 'dctb' resource with the same ID as the DLOG and DITL resources. You can easily create a 'dctb' resource with ResEdit by selecting the Custom color button in the DLOG resource template window. For more information on the 'dctb' resource, see the Dialog Manager chapter inInside Macintosh: Macintosh Toolbox Essentials (or in Inside Macintosh Volume V).

3. Conditionally registering a component that requires a hardware device.

If you write a component that requires a hardware device, you should set the wantsRegisterMessage flag to give your component an opportunity to verify that the specific hardware is properly installed. If the hardware isn't available, you can then indicate to the Component Manager that you don't want the component registered. The register routine, called with selector kComponentRegister, should return FALSE if it does want to be registered and TRUE if it doesn't.

One thing to be aware of is that even during registration, the component will be opened with OpenComponent and closed with CloseComponent. Therefore, you can expect OpenComponent before the ComponentRegister routine is called, and CloseComponent after ComponentRegister is called.

For example, if you have a 'vdig' that works with a NuBus video digitizer card, each time that OpenComponent is called you can check whether the hardware is correctly installed, and then return that status when ComponentRegister is called by the Component Manager.

2. Detaching a movie controller properly.

If you want to place the standard movie controller in a different window or location from its usual placement directly below the movie, you must detach the movie controller. Follow these steps:

  1. First bring up the controller by calling NewMovieController with the flag mcNotVisible so that the controller is initially invisible. If you don't do this, the application will momentarily display the controller in the wrong location.
  2. Call MCSetControllerAttached with FALSE to detach the controller.
  3. Call MCSetControllerPort to move the controller to a different port if you want to place it in a different window. If you only want to move the controller in the same window as the movie, you don't have to call MCSetControllerPort.
  4. Call either MCPositionController or MCSetControllerBoundsRect to move the controller to the new location in the port.
  5. Call MCSetVisible to display the controller.

The movie will remain in whatever port it was assigned to using SetMovieGWorld. If MCSetControllerPort isn't called (step 3), the controller will remain assigned to the movie's port when NewMovieController is called.

For example:

SetMovieGWorld(myMovie, (CGrafPtr) myWindow, 0);
mcMC = NewMovieController(myMovie, &movieBounds,
    mcTopLeftMovie + mcNotVisible);
MCSetControllerAttached(mcMC, FALSE);
MCSetControllerPort(mcMC, myOtherWindow);
MCPositionController(myMC, &movieBounds,
    &newControllerRect, mcTopLeftMovie);
MCSetVisible(myMC, TRUE);

1. Calling MaxApplZone from every application.

Not calling MaxApplZone in an application is the reason why many simple QuickTime playback applications play back movies poorly. Because the Memory Manager grows the heap only if there isn't any purgeable or free space left, QuickTime doesn't have the space it needs to play back a movie optimally. Since there's no penalty or drawback for calling MaxApplZone, all applications should call the routine during initialization. In fact, MaxApplZone should be your first Macintosh Toolbox call, because initializing QuickDraw and other managers could allocate memory.

We hope these tips will help you avoid some of the most common pitfalls of QuickTime development. With so many developers writing QuickTime applications and adding QuickTime support into existing applications, we want the journey to be as smooth as possible. We'll keep you updated and informed by continuing to bring you insightful tips and details about QuickTime in this column. Watch for it!


JOHN WANG (AppleLink WANG.JY) is enjoying his youth in the playpen of the Printing, Imaging, and Graphics (PIGs) group in Developer Technical Support at Apple. When he's not engaged in piglet activities, he can be found on a golf course or hogging the road with his Mazda Miata. No one has trouble identifying John's car, since he often cruises the California highways with his dog, Skate. In return, Skate promises to drive safely. *

For more information on the Component Manager, see the QuickTime or System 7.1 documentation on this subject, and see Gary Woodcock and Casey King's article, "Techniques for Writing and Debugging Components," in develop  Issue 12. *



Thanks to the developers who have made this list possible and to Bill Guschwan, Peter Hoddie, and Guillermo Ortiz for reviewing this column. *

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.