Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
sources/QTSSampleCodeUtils.h
/* |
File: QTSSampleCodeUtils.h |
Copyright: © 2000-2001 by Apple Computer, Inc., all rights reserved. |
*/ |
#ifndef __QTSSAMPLECODEUTILS__ |
#define __QTSSAMPLECODEUTILS__ |
#pragma once |
#if PRAGMA_STRUCT_ALIGN |
#pragma options align=power |
#elif PRAGMA_STRUCT_PACKPUSH |
#pragma pack(push, 2) |
#elif PRAGMA_STRUCT_PACK |
#pragma pack(2) |
#endif |
#ifdef __cplusplus |
extern "C" { |
#endif |
#include <Movies.h> |
#include <QuickTimeStreaming.h> |
// --------------------------------------------------------------------------- |
// D E F I N I T I O N S |
// --------------------------------------------------------------------------- |
#define kMillisecondsTimeScale 1000 |
#define EXITERR(_e) (_e); goto exit |
#define EXITIFERR(_e) if ((_e) != noErr) { goto exit; } |
#define EMPTY_PSTR "\p" |
#define MYHIWORD(_l) ((_l) >> 16) |
#define MYLOWORD(_l) ((_l) & 0x0000FFFF) |
#define DISPOSEIFRGN(_r) do { if ((_r) != NULL) { DisposeRgn(_r); } } while (false) |
#define kFileNotOpen -1 |
#define kAllFlags 0xFFFFFFFF |
// MPW defines /r and /n differently than everyone else |
// unless you set some compile options |
// get around this by defining it as hard coded numbers |
#define CR 0x0d |
#define LF 0x0a |
#if !TARGET_API_MAC_CARBON |
#define CopyPortBounds(port, bounds) do { *(bounds) = (port)->portRect; } while (false) |
#else // TARGET_API_MAC_CARBON |
#define CopyPortBounds(port, bounds) GetPortBounds(port, bounds) |
#endif // TARGET_API_MAC_CARBON |
#define DATE_STRING( _secs, _str) DateString( _secs, shortDate, _str, NULL) |
#define TIME_STRING( _secs, _str) TimeString( _secs, true, _str, NULL) |
// --------------------------------------------------------------------------- |
// memory |
// --------------------------------------------------------------------------- |
OSErr SafeHandToHand(Handle inOrigHandle, Handle *outNewHandle); |
// --------------------------------------------------------------------------- |
// media params |
// --------------------------------------------------------------------------- |
OSErr QTSCopyMediaParams(QTSMediaParams *inSourceMediaParams, |
QTSMediaParams *inDestMediaParams); |
void QTSDisposeMediaParams(QTSMediaParams *inMediaParams); |
OSErr CopyRgnUtil(RgnHandle inRgn, RgnHandle *ioRgn); |
// --------------------------------------------------------------------------- |
// time |
// --------------------------------------------------------------------------- |
UInt32 QTSGetTimeBaseTime(TimeBase inTimeBase, TimeScale inTimeScale); |
void QTSGetTimeBaseTime64(TimeBase inTimeBase, TimeScale inTimeScale, TimeValue64 *outTime); |
UInt32 QTSConvertDuration(UInt32 inOriginalDuration, |
TimeScale inOriginalTimeScale, TimeScale inNewTimeScale); |
void QTSConvertDuration64(const TimeValue64 *inOriginalDuration, TimeScale inOriginalTimeScale, |
TimeScale inNewTimeScale, TimeValue64 *outConvertedDuration); |
void TimeValue64ToDateTimeRec(const TimeValue64 *inTime64, TimeScale inTimeScale, DateTimeRec *outRec); |
void TimeValue64ToString(const TimeValue64 *inTime64, TimeScale inTimeScale, char *outString); |
void DateTimeRecToString(const DateTimeRec *inRec, char *outString); |
// --------------------------------------------------------------------------- |
// strings |
// --------------------------------------------------------------------------- |
void CopyCToPStr(const char *inCString, unsigned char *outPString); |
void CopyCToPStrn(const char *inCString, unsigned char *outPString, UInt32 inMaxLength); |
void CopyPToCStr(const unsigned char *inPString, char *outCString); |
void CopyPToCStrn(const unsigned char *inPString, char *outCString, UInt32 inMaxLength); |
Boolean EqualChars(const char *inCharsA, UInt32 inCharsALength, |
const char *inCharsB, UInt32 inCharsBLength); |
unsigned char *pstrcpy(unsigned char *dest, const unsigned char *source); |
unsigned char *pstrncpy(unsigned char *dest, const unsigned char *source, long maxLength); |
unsigned char *pstrcat(unsigned char *dest, const unsigned char *source); |
unsigned char *pstrncat(unsigned char *dest, const unsigned char *source, long maxLength); |
typedef char *CStringPtr; |
OSErr CStringToCStringPtr(const char *inString, CStringPtr *outCStringPtr); |
OSErr PStringToCStringPtr(const unsigned char *inString, CStringPtr *outCStringPtr); |
OSErr StringToCStringPtr(const char *inString, UInt32 inStringLength, CStringPtr *outCStringPtr); |
char *ScanTo(const char *inText, char inChar, UInt32 inTextLength); |
const char *ScanToString(const char *inText, UInt32 inTextLength, |
const char *inMatchString, UInt32 inMatchStringLength); |
Boolean StartsWith(const char *inLine, UInt32 inMaxLineLength, |
const char *inMatchString, UInt32 inMatchStringLength); |
Boolean EndsWith(const char *inLine, UInt32 inMaxLineLength, |
const char *inMatchString, UInt32 inMatchStringLength); |
const char *GetLineEnd(const char *inChars, UInt32 inMaxLength); |
const char *GetNextLineStart(const char *inChars, UInt32 inMaxLength); |
Boolean IsEOLChar(char inChar); |
void GetShortDateTimeString(char *outString, UInt32 inRandomNum); |
// --------------------------------------------------------------------------- |
// files and folders |
// --------------------------------------------------------------------------- |
OSErr GetFileContents(const FSSpec *inSpec, UInt32 inMaxHandleSize, |
Handle *outContents, UInt32 *outFileSize); |
OSErr MakeFolderIfNecessary(short inVRefNum, long inParentDirID, |
const StringPtr inName, long *outFolderDirID); |
Boolean FolderExists(const short inVRefNum, const long inParentDirID, |
const StringPtr inName, long *outFolderDirID); |
OSErr GetAppRelativeFolderSpec(const StringPtr inFolderName, FSSpec *outFolderSpec); |
// --------------------------------------------------------------------------- |
// dialogs |
// --------------------------------------------------------------------------- |
void DialogGetItemHandle( DialogPtr inDialog, DialogItemIndex inItemIndex, Handle* handle); |
void DialogSetItemHandle( DialogPtr inDialog, DialogItemIndex inItemIndex, Handle handle); |
void DialogSetControlValue( DialogPtr inDialog, DialogItemIndex inItemIndex, SInt16 value); |
SInt16 DialogGetControlValue( DialogPtr inDialog, DialogItemIndex inItemIndex); |
void DialogSetControlTitle( DialogPtr inDialog, DialogItemIndex inItemIndex, StringPtr title); |
void DialogGetControlTitle( DialogPtr inDialog, DialogItemIndex inItemIndex, StringPtr title); |
void DialogSetRadioButton( DialogPtr inDialog, DialogItemIndex inItemIndex, Boolean enable); |
void DialogGetRadioButton( DialogPtr inDialog, DialogItemIndex inItemIndex, Boolean* enabled); |
void DialogSetCheckBox( DialogPtr inDialog, DialogItemIndex inItemIndex, Boolean enable); |
void DialogGetCheckBox( DialogPtr inDialog, DialogItemIndex inItemIndex, Boolean* enabled); |
void DialogGetItemRect( DialogPtr inDialog, DialogItemIndex inItemIndex, Rect* rect); |
void DialogSetItemRect( DialogPtr inDialog, DialogItemIndex inItemIndex, Rect* rect); |
void DialogSetTextInteger( DialogPtr inDialog, DialogItemIndex inItemIndex, SInt32 number); |
SInt32 DialogGetTextInteger( DialogPtr inDialog, DialogItemIndex inItemIndex); |
void DialogSetText( DialogPtr inDialog, DialogItemIndex inItemIndex, StringPtr text, Boolean inSelectText); |
void DialogGetText( DialogPtr inDialog, DialogItemIndex inItemIndex, StringPtr text); |
void DialogSelectText( DialogPtr inDialog, DialogItemIndex inItemIndex); |
void DialogRefreshItemRect( DialogPtr inDialog, DialogItemIndex inItemIndex); |
void DialogEnableItem( DialogPtr inDialog, DialogItemIndex inItemIndex, Boolean enable); |
void DialogShowItem( DialogPtr inDialog, DialogItemIndex inItemIndex, Boolean show); |
void DialogOffsetControl( DialogPtr inDialog, DialogItemIndex inItemIndex, SInt16 xOffset, SInt16 yOffset); |
void DialogSetControlProc( DialogPtr inDialog, DialogItemIndex inItemIndex, ControlActionUPP proc); |
void DialogSetControlRange( DialogPtr inDialog, DialogItemIndex inItemIndex, SInt16 min, SInt16 max); |
void DialogAnimateControl( DialogPtr inDialog, DialogItemIndex inItemIndex); |
void MenuEnableItem( MenuHandle menu, MenuItemIndex index, Boolean enable); |
void DITLGetItemRect(Handle inDITLHandle, DialogItemIndex inItemIndex, Rect *outRect); |
void DITLSetItemRect(Handle inDITLHandle, DialogItemIndex inItemIndex, Rect *inRect); |
// --------------------------------------------------------------------------- |
// debugging and logging |
// --------------------------------------------------------------------------- |
// set USHER_DEBUG to 0 to turn off all debugstrs |
#ifdef USHER_DEBUG |
#undef USHER_DEBUG |
#endif |
#define USHER_DEBUG 1 |
#if USHER_DEBUG |
#define DEBUGF(x) samplecodeutilsdebugf x |
void samplecodeutilsdebugf (const char *format, ...); |
#else |
#define DEBUGF(x) |
#endif |
struct LoggerRecord { |
FSSpec fileSpec; |
SInt32 flags; |
OSType fileCreator; |
OSType fileType; |
short fileRefNum; |
long fileLength; |
}; |
typedef struct LoggerRecord LoggerRecord, *LoggerPtr, **Logger; |
// debug flags |
enum { |
kDebugFlag_WriteToLog = 0x00000001, |
kDebugFlag_DebugStr = 0x00000002 |
}; |
void SetDebugLog(Logger inLog); |
void SetDebugFlags(SInt32 inFlags, SInt32 inFlagsMask); |
// logging flags |
enum { |
kLoggerWriteFlag_AddEOL = 0x00000001, |
kLoggerWriteFlag_AddDateTime = 0x00000002 |
}; |
OSErr Logger_New(const FSSpec *inFileSpec, SInt32 inFlags, |
OSType inFileCreator, OSType inFileType, Logger *outLog); |
void Logger_Dispose(Logger inLog); |
OSErr Logger_OpenFile(Logger inLog); |
void Logger_CloseFile(Logger inLog); |
OSErr Logger_Flush(Logger inLog); |
OSErr Logger_Write(Logger inLog, SInt32 inFlags, const char *inData, UInt32 inLength); |
OSErr Logger_Printf(Logger inLog, SInt32 inFlags, const char *format, ...); |
OSErr Logger_WriteDateTime(Logger inLog); |
OSErr Logger_WriteEOL(Logger inLog); |
#ifdef __cplusplus |
} |
#endif |
#if PRAGMA_STRUCT_ALIGN |
#pragma options align=reset |
#elif PRAGMA_STRUCT_PACKPUSH |
#pragma pack(pop) |
#elif PRAGMA_STRUCT_PACK |
#pragma pack() |
#endif |
#endif /* __QTSSAMPLECODEUTILS__ */ |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14