this repo has no description
at fixPythonPipStalling 128 lines 5.5 kB view raw
1/* Copyright: � Copyright 2005 Apple Computer, Inc. All rights reserved. 2 3 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. 4 ("Apple") in consideration of your agreement to the following terms, and your 5 use, installation, modification or redistribution of this Apple software 6 constitutes acceptance of these terms. If you do not agree with these terms, 7 please do not use, install, modify or redistribute this Apple software. 8 9 In consideration of your agreement to abide by the following terms, and subject 10 to these terms, Apple grants you a personal, non-exclusive license, under Apple�s 11 copyrights in this original Apple software (the "Apple Software"), to use, 12 reproduce, modify and redistribute the Apple Software, with or without 13 modifications, in source and/or binary forms; provided that if you redistribute 14 the Apple Software in its entirety and without modifications, you must retain 15 this notice and the following text and disclaimers in all such redistributions of 16 the Apple Software. Neither the name, trademarks, service marks or logos of 17 Apple Computer, Inc. may be used to endorse or promote products derived from the 18 Apple Software without specific prior written permission from Apple. Except as 19 expressly stated in this notice, no other rights or licenses, express or implied, 20 are granted by Apple herein, including but not limited to any patent rights that 21 may be infringed by your derivative works or by other works in which the Apple 22 Software may be incorporated. 23 24 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 25 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 26 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 28 COMBINATION WITH YOUR PRODUCTS. 29 30 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 32 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION 34 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT 35 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN 36 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37*/ 38/*============================================================================= 39 CAAudioFileStreamer.h 40 41=============================================================================*/ 42 43#ifndef __CAAudioFileStreamer_h__ 44#define __CAAudioFileStreamer_h__ 45 46#include "CABufferQueue.h" 47#include "CAAudioFile.h" 48 49// ____________________________________________________________________________ 50// Base class for CAAudioFileReader and CAAudioFileWriter 51class CAAudioFileStreamer { 52public: 53 CAAudioFileStreamer() : mRunning(false), mFile(NULL) { } 54 virtual ~CAAudioFileStreamer() { delete mFile; } 55 56 CAAudioFile & GetFile() { return *mFile; } 57 const CAAudioFile & GetFile() const { return *mFile; } 58 59 bool IsRunning() { return mRunning; } 60 61protected: 62 bool mRunning; 63 CAAudioFile * mFile; 64}; 65 66// ____________________________________________________________________________ 67 68class CAAudioFileReader : public CAPullBufferQueue, public CAAudioFileStreamer { 69public: 70 CAAudioFileReader(int nBuffers, UInt32 bufferSizeFrames) : 71 CAPullBufferQueue(nBuffers, bufferSizeFrames) { } 72 73 void SetFile(const FSRef &inFile); 74 virtual void Start(); 75 virtual void Stop(); 76 double GetCurrentPosition() const; // 0-1 77 SInt64 GetCurrentFrame() const;// { return mFile->Tell(); } 78 SInt64 GetNumberFrames() const { return mFile->GetNumberFrames(); } 79 80 void SetCurrentPosition(double loc); // 0-1 81 82private: 83 class FileReadBuffer : public CABufferQueue::Buffer { 84 public: 85 FileReadBuffer(CABufferQueue *queue, const CAStreamBasicDescription &fmt, UInt32 nBytes) : 86 CABufferQueue::Buffer(queue, fmt, nBytes) 87 { } 88 89 void UpdateAfterRead(SInt64 curFrame, UInt32 nFramesRead); 90 void GetLocation(UInt32 &frm0, UInt32 &frame1) const { 91 frm0 = mStartFrame; frame1 = mEndFrame; 92 } 93 94 SInt64 mBufferStartFileFrame; 95 }; 96 97 virtual CABufferQueue::Buffer * CreateBuffer(const CAStreamBasicDescription &fmt, UInt32 nBytes) { 98 return new FileReadBuffer(this, fmt, nBytes); 99 } 100 virtual void ProcessBuffer(CABufferQueue::Buffer *b) { 101 ReadBuffer(static_cast<FileReadBuffer *>(b)); 102 } 103 void ReadBuffer(FileReadBuffer *b); 104}; 105 106// ____________________________________________________________________________ 107 108class CAAudioFileWriter : public CAPushBufferQueue, public CAAudioFileStreamer { 109public: 110 CAAudioFileWriter(int nBuffers, UInt32 bufferSizeFrames) : 111 CAPushBufferQueue(nBuffers, bufferSizeFrames) { } 112 113 void SetFile(AudioFileID file); 114 void SetFile(const FSRef &parentDir, CFStringRef filename, AudioFileTypeID filetype, const CAStreamBasicDescription &dataFormat, const CAAudioChannelLayout *layout); 115 virtual void Start(); 116 virtual void Stop(); 117 118private: 119 virtual CABufferQueue::Buffer * CreateBuffer(const CAStreamBasicDescription &fmt, UInt32 nBytes) { 120 return new CABufferQueue::Buffer(this, fmt, nBytes); 121 } 122 virtual void ProcessBuffer(CABufferQueue::Buffer *b) { 123 WriteBuffer(b); 124 } 125 void WriteBuffer(CABufferQueue::Buffer *b); 126}; 127 128#endif // __CAAudioFileStreamer_h__