1 /*
2 
3 File: AIFFWriter.h
4 
5 Author: QuickTime DTS
6 
7 Change History (most recent first): <1> 11/10/05 initial release
8 
9 � Copyright 2005 - 2006 Apple Computer, Inc. All rights reserved.
10 
11 IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in
12 consideration of your agreement to the following terms, and your use, installation,
13 modification or redistribution of this Apple software constitutes acceptance of these
14 terms.  If you do not agree with these terms, please do not use, install, modify or
15 redistribute this Apple software.
16 
17 In consideration of your agreement to abide by the following terms, and subject to these
18 terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in
19 this original Apple software (the "Apple Software"), to use, reproduce, modify and
20 redistribute the Apple Software, with or without modifications, in source and/or binary
21 forms; provided that if you redistribute the Apple Software in its entirety and without
22 modifications, you must retain this notice and the following text and disclaimers in all
23 such redistributions of the Apple Software. Neither the name, trademarks, service marks
24 or logos of Apple Computer, Inc. may be used to endorse or promote products derived from
25 the Apple Software without specific prior written permission from Apple.  Except as
26 expressly stated in this notice, no other rights or licenses, express or implied, are
27 granted by Apple herein, including but not limited to any patent rights that may be
28 infringed by your derivative works or by other works in which the Apple Software may be
29 incorporated.
30 
31 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO WARRANTIES,
32 EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
33 NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE
34 APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
35 
36 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
37 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE
39 USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER
40 CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT
41 LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 
43 */
44 
45 #import <Cocoa/Cocoa.h>
46 
47 #import <AudioToolbox/AudioToolbox.h>
48 #import <QTKit/QTKit.h>
49 #import <QuickTime/QuickTime.h>
50 
51 // maximum size in frames of the MovieAudioExtractionFillBuffer calls
52 #define kMaxExtractionPacketCount 4096
53 
54 // this object is busy exporting error code
55 #define kObjectInUseErr 1000
56 
57 // constants for shouldContinueOperation delegate method
58 typedef enum {
59 	AIFFWriterExportBegin	 = 0,
60 	AIFFWriterExportPercent  = 10,
61 	AIFFWriterExportEnd		 = 20
62 } AIFFWriterExportOperationPhase;
63 
64 // ProgressInfo object passed back to the delegate
65 // if it implements shouldContinueOperationWithProgressInfo:
66 // progressValue will contain a valid NSNumber object with a
67 // value between 0 and 1.0 when phase is AIFFWriterExportPercent
68 @interface AIFFWriterProgressInfo : NSObject
69 {
70 @private
71     AIFFWriterExportOperationPhase  phase;	// one of the state enums
72     NSNumber *progressValue;				// value is between 0 and 1.0 valid only for AIFFWriterExportPercent phase
73     NSError  *exportStatus;
74 }
75 
76 - (AIFFWriterExportOperationPhase)phase;
77 - (NSNumber *)progressValue;
78 - (NSError *)exportStatus;
79 
80 @end
81 
82 // invoked on a delegate to provide progress
83 @interface NSObject (AIFFWriterExportDelegate)
84 
85 - (BOOL)shouldContinueOperationWithProgressInfo:(id)inProgressInfo;
86 
87 @end
88 
89 // AIFFWriter object
90 // A single instance of this object can be used to extract audio
91 // from a QuickTime movie (via a QTKit Movie object) and will write
92 // an AIFF file preserving the audio layout from the Movie
93 @interface AIFFWriter : NSObject
94 {
95 @private
96 	NSString 					*mFileName;                     // file name for the new .aiff file
97     FSRef	  					mFileRef;                       // file reference for this file
98     FSRef	  					mParentRef;
99 
100     QTMovie						*mQTMovie;                      // movie to extract audio from
101     Float64						mMovieDuration;                 // movie duration
102     Movie						mCloneMovie;                    // copy of the source movie for thread migration
103 
104 	MovieAudioExtractionRef     mAudioExtractionSession;        // QT Audio Extraction Session Reference
105     BOOL                        mExtractionComplete;            // are we done yet?
106     BOOL                        mIsExporting;                   // is the object busy
107     SInt64						mLocationInFile;                // location to write new data
108     SInt64						mSamplesRemaining;              // how much more do we need to pull from the source?
109     SInt64						mSamplesCompleated;             // hom much have we done - used to drive progress UI
110     SInt64						mTotalNumberOfSamples;          // total number of samples to extract
111 
112 	AudioStreamBasicDescription	mSourceASBD;                    // audio stream basic description of the source movie
113     AudioStreamBasicDescription	mOutputASBD;                    // the asbd we're asking for
114     AudioChannelLayout *		mExtractionLayoutPtr;           // the audio channel layout of the source
115     UInt32                      mExtractionLayoutSize;          // the size of the audio chanel layout
116     AudioFileID					mExportFileID;                  // file identifier for the new .aiff file
117 
118     NSLock *					mLock;                          // lock protecting reentrance
119 
120     AIFFWriterProgressInfo *    mProgressInfo;                  // progress info object passed to the progress callback
121 
122     id							mDelegate;                      // a delegate object to call with progress info...
123     BOOL						mDelegateShouldContinueOp;      // ...but only if it actually implemented the callback
124 }
125 
126 - (OSStatus)exportFromMovie:(QTMovie *)inMovie toFile:(NSString *)inFullPath;
127 - (BOOL)isExporting;
128 
129 @end
130 
131 // the client of AIFFWriter should set itself as a delegate if it
132 // wants to handle shouldContinueOperationWithProgressInfo
133 @interface AIFFWriter (AIFFWriterDelegate)
134 
135 - (id)delegate;
136 - (void)setDelegate:(id)delegate;
137 
138 @end
139