### Interleaved Media Data Layout Example Source: https://developer.apple.com/documentation/quicktime-file-format/using_quicktime_files_and_media_layouts Illustrates the optimal ordering of hint track (H) samples and media (A for audio, V for visual) samples within a QuickTime file to minimize file seeks during playback. Hint samples must precede the media data they reference. ```text H0 A0 H1 V1 H2 V2 H3 A1 H4 A2 V3 H5 V4 ``` -------------------------------- ### Insert Second Atom Before First Atom Source: https://developer.apple.com/documentation/quicktime-file-format/creating_new_atoms This example shows how to insert a second child atom into an existing container. By specifying an index of 1, the new atom is inserted before the first atom, shifting the index of the first atom. ```c QTAtom secondAtom; FailOSErr (QTInsertChild (container, kParentAtomIsContainer, 'abcd', 2000, 1, 0, nil, &secondAtom)); ``` -------------------------------- ### Implementing a QTVR Intercept Procedure Source: https://developer.apple.com/documentation/quicktime-file-format/adding_custom_atoms_in_a_quicktime_vr_movie This C code defines an intercept procedure for handling custom hot spot clicks in a QuickTime VR movie. It checks for a specific custom hot spot type, extracts custom data, and processes it. Install this procedure when opening the movie and uninstall it when no longer needed. ```c QTVRInterceptProc MyProc = NewQTVRInterceptProc (MyHotSpot); QTVRInstallInterceptProc (qtvr, kQTVRTriggerHotSpotSelector, myProc, 0, 0); pascal void MyHotSpot (QTVRInstance qtvr, QTVRInterceptPtr qtvrMsg, SInt32 refCon, Boolean *cancel) { UInt32 hotSpotID = (UInt32) qtvrMsg->parameter[0]; QTAtomContainer nodeInfo = (QTAtomContainer) qtvrMsg->parameter[1]; QTAtom hotSpotAtom = (QTAtom) qtvrMsg->parameter[2]; OSType hotSpotType; CustomData myCustomData; QTAtom myAtom; QTVRGetHotSpotType (qtvr, hotSpotID, &hotSpotType); if (hotSpotType != kMyAtomType) return; // It's our type of hot spot - don't let anyone else handle it *cancel = true; // Find our custom atom myAtom = QTFindChildByID (nodeInfo, hotSpotAtom, kMyAtomType, 1, nil); if (myAtom != 0) { OSErr err; // Copy the custom data into our structure err = QTCopyAtomDataToPtr (nodeInfo, myAtom, false, sizeof(CustomData), &myCustomData, nil); if (err == noErr) // Do something with it DoMyHotSpotStuff (hotSpotID, &myCustomData); } } ``` -------------------------------- ### Hypertext Range Definition Atoms Source: https://developer.apple.com/documentation/quicktime-file-format/hypertext_and_wired_text Defines the start and end offsets for hypertext within a text stream. These are unsigned long integers. ```text kRangeStart strt // unsigned long kRangeEnd end // unsigned long ``` -------------------------------- ### Create a New QTAtomContainer for Input Map Source: https://developer.apple.com/documentation/quicktime-file-format/creating_an_input_map Initializes a new QuickTime atom container to hold the input map. This is the first step in building an input map. ```c QTNewAtomContainer(&inputMap); ``` -------------------------------- ### Remove all atoms from containers Source: https://developer.apple.com/documentation/quicktime-file-format/removing_atoms_from_an_atom_container Use `QTRemoveChildren` with `kParentAtomIsContainer` to clear all atoms from an atom container. This is useful for resetting containers before adding new data, as shown in the example for updating sprite animations. ```c QTAtomContainer sample, spriteData; // ... // Add the sprite key sample. // ... // Add override samples to make the sprites spin and move. for (i = 1; i <= kNumOverrideSamples; i++) { QTRemoveChildren (sample, kParentAtomIsContainer); QTRemoveChildren (spriteData, kParentAtomIsContainer); // ... // Update the sprite: // - Update the imageIndex. // - Update the location. // ... // Add atoms to spriteData atom container. SetSpriteData (spriteData, &location, nil, nil, &imageIndex); // Add the spriteData atom container to sample. err = AddSpriteToSample (sample, spriteData, 2); // ... // Update other sprites. // ... // Add the sample to the media. err = AddSpriteSampleToMedia (newMedia, sample, kSpriteMediaFrameDuration, false); } ``` -------------------------------- ### Update Media Input Map for Modifier Track Source: https://developer.apple.com/documentation/quicktime-file-format/creating_movies_with_modifier_tracks After adding a track reference, update the receiving track's media input map to describe how the modifier data should be interpreted. This example sets the input type to kTrackModifierTypeClip. ```c QTAtomContainer inputMap; QTAtom inputAtom; OSType inputType; Media aVideoMedia = GetTrackMedia(aVideoTrack); GetMediaInputMap (aVideoMedia, &inputMap); QTInsertChild(inputMap, kParentAtomIsContainer, kTrackModifierInput, addedIndex, 0,0, nil, &inputAtom); inputType = kTrackModifierTypeClip; QTInsertChild (inputMap, inputAtom, kTrackModifierType, 1, 0, sizeof(inputType), &inputType, nil); SetMediaInputMap(aVideoMedia, inputMap); QTDisposeAtomContainer(inputMap); ``` -------------------------------- ### Create Atom Container for QTVR Import Preview Source: https://developer.apple.com/documentation/quicktime-file-format/sample_atom_container_for_the_qtvr_flattener Use this code to create an atom container and add atoms that indicate an import preview file for the QTVR flattener. Ensure `previewSpec` is defined elsewhere. ```c Boolean yes = true; QTAtomContainer exportData; QTAtom parent; err = QTNewAtomContainer(&exportData); // create a parent for the other settings atoms err = QTInsertChild (exportData, kParentAtomIsContainer, QTVRFlattenerParentAtomType, 1, 0, 0, nil, &parent); // Add child atom to indicate we want to import the preview from a file err = QTInsertChild (exportData, parent, QTVRImportPreviewAtomType, 1, 0, sizeof (yes), &yes, nil); // Add child atom to tell which file to import err = QTInsertChild (exportData, parent, QTVRImportSpecAtomType, 1, 0, sizeof (previewSpec), &previewSpec, nil); // Tell the export component MovieExportSetSettingsFromAtomContainer (qtvrExport, exportData); ``` -------------------------------- ### Insert New Parent Atom and Then Its Children Source: https://developer.apple.com/documentation/quicktime-file-format/copying_existing_atoms First, insert a new parent atom into a container using QTInsertChild. Then, use QTInsertChildren to insert another container as children of the newly created parent atom. Error checking is done via FailOSErr. ```c FailOSErr (QTInsertChild (theSample, kParentAtomIsContainer, kSpriteAtomType, spriteID, 0, 0, nil, &newSpriteAtom)); FailOSErr (QTInsertChildren (theSample, newSpriteAtom, theSprite)); ``` -------------------------------- ### QuickTime VR Sample Description Structure Source: https://developer.apple.com/documentation/quicktime-file-format/quicktime_vr_sample_description Defines the structure for QuickTime VR sample descriptions. This structure is required by QuickTime for the first several bytes of sample descriptions. ```c typedef struct QTVRSampleDescription { UInt32 size; UInt32 type; UInt32 reserved1; UInt16 reserved2; UInt16 dataRefIndex; UInt32 data; } QTVRSampleDescription, *QTVRSampleDescriptionPtr, **QTVRSampleDescriptionHandle; ``` -------------------------------- ### Adjust Display Offsets for Composition Source: https://developer.apple.com/documentation/quicktime-file-format/using_composition_offset_and_composition_shift_least_greatest_atoms Write a composition offset table atom by adjusting each display offset. Subtract the calculated composition offset shift from the original display offset to get the new composition offset. If a composition shift least greatest atom is absent, assume the shift is zero. ```pseudocode compositionOffset[n] = displayOffset[n] - compositionOffsetToDisplayOffsetShift; ``` -------------------------------- ### QuickTime Streaming Media Sample Description Structure Source: https://developer.apple.com/documentation/quicktime-file-format/streaming_media Defines the structure for interpreting streaming media data in QuickTime. The 'dataFormat' field specifies how to interpret the sample, with 'rtsp' and 'sdp ' being currently defined values. ```c struct QTSSampleDescription { long descSize; long dataFormat; long resvd1; /* set to 0*/ short resvd2; /* set to 0*/ short dataRefIndex; UInt32 version; UInt32 resvd3; /* set to 0*/ SInt32 flags; /* qt atoms follow:*/ /* long size, long type, some data*/ /* repeat as necessary*/ }; typedef struct QTSSampleDescription QTSSampleDescription; ``` -------------------------------- ### Create an Atom Container Source: https://developer.apple.com/documentation/quicktime-file-format/creating_copying_and_disposing_of_atom_containers Call `QTNewAtomContainer` to create a new atom container. Ensure you have a valid `OSErr` variable to capture potential errors. ```c QTAtomContainer spriteData; OSErr err // Create an atom container to hold a sprite’s data. err=QTNewAtomContainer (&spriteData); ```