this repo has no description
at fixPythonPipStalling 217 lines 8.3 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 afinfo.cpp 40 41=============================================================================*/ 42 43#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__) 44 #include <AudioToolbox/AudioToolbox.h> 45#else 46 #include <AudioToolbox.h> 47#endif 48 49#if TARGET_OS_WIN32 50 #include <QTML.h> 51#endif 52 53#include <stdio.h> 54#include "CAStreamBasicDescription.h" 55#include <stdlib.h> 56#include <CarbonCore/Endian.h> 57 58//using namespace std; 59 60int main (int argc, const char * argv[]) 61{ 62#if TARGET_OS_WIN32 63 InitializeQTML(0L); 64#endif 65 int enc = kCFStringEncodingUTF8; 66 67 for (int i=1; i<argc; ++i) 68 { 69 OSStatus err; 70 CAStreamBasicDescription asbd; 71 AudioChannelLayout *acl = 0; 72 UInt32 propertySize; 73 UInt32 specifierSize; 74 AudioFileID afid; 75 Boolean res; 76 FSRef fsRef; 77 AudioFileTypeID filetype; 78 CFStringRef filename = CFStringCreateWithCString(NULL, argv[i], enc); 79 if (!filename) continue; 80 81 CFURLRef url = CFURLCreateWithFileSystemPath(NULL, filename, kCFURLPOSIXPathStyle, true); 82 if (!url) { 83 fprintf(stderr, "Can't create CFURL for '%s'\n", argv[i]); 84 goto Bail3; 85 } 86 87 res = CFURLGetFSRef(url, &fsRef); 88 if (!res) { 89 fprintf(stderr, "Can't get FSRef for '%s'\n", argv[i]); 90 goto Bail2; 91 } 92 93 err = AudioFileOpen(&fsRef, fsRdPerm, 0, &afid); 94 if (err) { 95 fprintf(stderr, "AudioFileOpen failed for '%s'\n", argv[i]); 96 goto Bail2; 97 } 98 99 propertySize = sizeof(AudioFileTypeID); 100 err = AudioFileGetProperty(afid, kAudioFilePropertyFileFormat, &propertySize, &filetype); 101 if (err) { 102 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyFileFormat failed for '%s'\n", argv[i]); 103 goto Bail1; 104 } 105 filetype = EndianU32_NtoB(filetype); // for display purposes 106 107 propertySize = sizeof(asbd); 108 err = AudioFileGetProperty(afid, kAudioFilePropertyDataFormat, &propertySize, &asbd); 109 if (err) { 110 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyDataFormat failed for '%s'\n", argv[i]); 111 goto Bail1; 112 } 113 114 printf("File: %s\n", argv[i]); 115 printf("File type ID: %-4.4s\n", (char *)&filetype); 116 asbd.PrintFormat(stdout, "", "Data format: "); 117 118 UInt32 writable; 119 err = AudioFileGetPropertyInfo(afid, kAudioFilePropertyChannelLayout, &propertySize, &writable); 120 if (err) { 121 //fprintf(stderr, "AudioFileGetPropertyInfo kAudioFilePropertyChannelLayout failed for '%s'\n", argv[i]); 122 printf(" no channel layout.\n"); 123 } else { 124 125 acl = (AudioChannelLayout*)calloc(1, propertySize); 126 err = AudioFileGetProperty(afid, kAudioFilePropertyChannelLayout, &propertySize, acl); 127 if (err) { 128 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyChannelLayout failed for '%s'\n", argv[i]); 129 goto Bail1; 130 } 131 132 CFStringRef aclname; 133 char aclstr[512]; 134 specifierSize = propertySize; 135 propertySize = sizeof(aclname); 136 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutName, specifierSize, acl, &propertySize, &aclname); 137 if (err) { 138 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyChannelLayout failed for '%s'\n", argv[i]); 139 goto Bail1; 140 } 141 CFStringGetCString(aclname, aclstr, 512, kCFStringEncodingUTF8); 142 143 printf("Channel layout: %s\n", aclstr); 144 } 145 146 UInt64 dataByteCount; 147 propertySize = sizeof(dataByteCount); 148 err = AudioFileGetProperty(afid, kAudioFilePropertyAudioDataByteCount, &propertySize, &dataByteCount); 149 if (err) { 150 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyAudioDataByteCount failed for '%s'\n", argv[i]); 151 } else { 152 printf("audio bytes: %llu\n", dataByteCount); 153 } 154 155 UInt64 dataPacketCount; 156 UInt64 totalFrames; 157 totalFrames = 0; 158 propertySize = sizeof(dataPacketCount); 159 err = AudioFileGetProperty(afid, kAudioFilePropertyAudioDataPacketCount, &propertySize, &dataPacketCount); 160 if (err) { 161 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyAudioDataPacketCount failed for '%s'\n", argv[i]); 162 } else { 163 printf("audio packets: %llu\n", dataPacketCount); 164 if (asbd.mFramesPerPacket) 165 totalFrames = asbd.mFramesPerPacket * dataPacketCount; 166 } 167 168 AudioFilePacketTableInfo pti; 169 propertySize = sizeof(pti); 170 err = AudioFileGetProperty(afid, kAudioFilePropertyPacketTableInfo, &propertySize, &pti); 171 if (err == noErr) { 172 totalFrames = pti.mNumberValidFrames; 173 printf("audio %qd valid frames + %ld priming + %ld remainder = %qd\n", pti.mNumberValidFrames, pti.mPrimingFrames, pti.mRemainderFrames, pti.mNumberValidFrames + pti.mPrimingFrames + pti.mRemainderFrames); 174 } 175 176 if (totalFrames != 0) 177 printf("duration: %.4f seconds\n", (double)totalFrames / (double)asbd.mSampleRate ); 178 179 UInt32 maxPacketSize; 180 propertySize = sizeof(maxPacketSize); 181 err = AudioFileGetProperty(afid, kAudioFilePropertyMaximumPacketSize, &propertySize, &maxPacketSize); 182 if (err) { 183 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyMaximumPacketSize failed for '%s'\n", argv[i]); 184 } else { 185 printf("maximum packet size: %lu\n", maxPacketSize); 186 } 187 188 UInt64 dataOffset; 189 propertySize = sizeof(dataOffset); 190 err = AudioFileGetProperty(afid, kAudioFilePropertyDataOffset, &propertySize, &dataOffset); 191 if (err) { 192 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyDataOffset failed for '%s'\n", argv[i]); 193 } else { 194 printf("audio data file offset: %llu\n", dataOffset); 195 } 196 197 UInt32 isOptimized; 198 propertySize = sizeof(isOptimized); 199 err = AudioFileGetProperty(afid, kAudioFilePropertyIsOptimized, &propertySize, &isOptimized); 200 if (err) { 201 fprintf(stderr, "AudioFileGetProperty kAudioFilePropertyIsOptimized failed for '%s'\n", argv[i]); 202 } else { 203 printf(isOptimized ? "optimized\n" : "not optimized\n"); 204 } 205 206 Bail1: 207 AudioFileClose(afid); 208 Bail2: 209 CFRelease(url); 210 Bail3: 211 CFRelease(filename); 212 free(acl); 213 214 printf("----\n"); 215 } 216 return 0; 217}