void CAOggFLACDecoder::InitializeCompressionSettings() { if (mCookie != NULL) { if (mCompressionInitialized) ogg_stream_clear(&mO_st); OggSerialNoAtom *atom = reinterpret_cast<OggSerialNoAtom*> (mCookie); if (EndianS32_BtoN(atom->type) == kCookieTypeOggSerialNo && EndianS32_BtoN(atom->size) <= mCookieSize) { ogg_stream_init(&mO_st, EndianS32_BtoN(atom->serialno)); } } ogg_stream_reset(&mO_st); CAFLACDecoder::InitializeCompressionSettings(); }
// Obtain the name of an endpoint, following connections. // The result should be released by the caller. static CFStringRef ConnectedEndpointName(MIDIEndpointRef endpoint) { CFMutableStringRef result = CFStringCreateMutable(NULL, 0); CFStringRef str; OSStatus err; // Does the endpoint have connections? CFDataRef connections = NULL; int nConnected = 0; bool anyStrings = false; err = MIDIObjectGetDataProperty(endpoint, kMIDIPropertyConnectionUniqueID, &connections); if (connections != NULL) { // It has connections, follow them // Concatenate the names of all connected devices nConnected = CFDataGetLength(connections) / sizeof(MIDIUniqueID); if (nConnected) { const SInt32 *pid = reinterpret_cast <const SInt32 *>(CFDataGetBytePtr(connections)); for (int i = 0; i < nConnected; ++i, ++pid) { MIDIUniqueID id = EndianS32_BtoN(*pid); MIDIObjectRef connObject; MIDIObjectType connObjectType; err = MIDIObjectFindByUniqueID(id, &connObject, &connObjectType); if (err == noErr) { if (connObjectType == kMIDIObjectType_ExternalSource || connObjectType == kMIDIObjectType_ExternalDestination) { // Connected to an external device's endpoint (10.3 and later). str = EndpointName(static_cast <MIDIEndpointRef>(connObject), true); } else { // Connected to an external device (10.2) (or something else, catch-all) str = NULL; MIDIObjectGetStringProperty(connObject, kMIDIPropertyName, &str); } if (str != NULL) { if (anyStrings) CFStringAppend(result, CFSTR(", ")); else anyStrings = true; CFStringAppend(result, str); CFRelease(str); } } } } CFRelease(connections); } if (anyStrings) return result; // Here, either the endpoint had no connections, or we failed to obtain names for any of them. return EndpointName(endpoint, false); }
void CAMIDIEndpoints::AddEndpoints(MIDIEndpointRef endpoint, EndpointList &eplist) { Endpoint *ep, *prev; OSStatus err; CFStringRef str; // Add the driver-owned endpoint ep = new Endpoint(endpoint, EndpointName(endpoint, false), NULL); eplist.push_back(ep); prev = ep; // Does the endpoint have connections? CFDataRef connections = NULL; int nConnected = 0; MIDIObjectGetDataProperty(endpoint, kMIDIPropertyConnectionUniqueID, &connections); if (connections != NULL) { // It has connections, follow them nConnected = CFDataGetLength(connections) / sizeof(MIDIUniqueID); if (nConnected) { const SInt32 *pid = reinterpret_cast<const SInt32 *>(CFDataGetBytePtr(connections)); for (int i = 0; i < nConnected; ++i, ++pid) { MIDIUniqueID id = EndianS32_BtoN(*pid); MIDIObjectRef connObject; MIDIObjectType connObjectType; err = MIDIObjectFindByUniqueID(id, &connObject, &connObjectType); if (err == noErr) { if (connObjectType == kMIDIObjectType_ExternalSource || connObjectType == kMIDIObjectType_ExternalDestination) { // Connected to an external device's endpoint (10.3 and later). str = EndpointName(static_cast<MIDIEndpointRef>(connObject), true); } else { // Connected to an external device (10.2) (or something else, catch-all) str = NULL; MIDIObjectGetStringProperty(connObject, kMIDIPropertyName, &str); } if (str != NULL) { ep = new Endpoint(endpoint, str, connObject); eplist.push_back(ep); prev->SetNext(ep); prev = ep; } } } } } }
static void parse_fond( char* fond_data, short* have_sfnt, ResID* sfnt_id, Str255 lwfn_file_name, short face_index ) { AsscEntry* assoc; AsscEntry* base_assoc; FamRec* fond; *sfnt_id = 0; *have_sfnt = 0; lwfn_file_name[0] = 0; fond = (FamRec*)fond_data; assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 ); base_assoc = assoc; /* the maximum faces in a FOND is 48, size of StyleTable.indexes[] */ if ( 47 < face_index ) return; /* Let's do a little range checking before we get too excited here */ if ( face_index < count_faces_sfnt( fond_data ) ) { assoc += face_index; /* add on the face_index! */ /* if the face at this index is not scalable, fall back to the first one (old behavior) */ if ( EndianS16_BtoN( assoc->fontSize ) == 0 ) { *have_sfnt = 1; *sfnt_id = EndianS16_BtoN( assoc->fontID ); } else if ( base_assoc->fontSize == 0 ) { *have_sfnt = 1; *sfnt_id = EndianS16_BtoN( base_assoc->fontID ); } } if ( EndianS32_BtoN( fond->ffStylOff ) ) { unsigned char* p = (unsigned char*)fond_data; StyleTable* style; unsigned short string_count; char ps_name[256]; unsigned char* names[64]; int i; p += EndianS32_BtoN( fond->ffStylOff ); style = (StyleTable*)p; p += sizeof ( StyleTable ); string_count = EndianS16_BtoN( *(short*)(p) ); p += sizeof ( short ); for ( i = 0; i < string_count && i < 64; i++ ) { names[i] = p; p += names[i][0]; p++; } { size_t ps_name_len = (size_t)names[0][0]; if ( ps_name_len != 0 ) { ft_memcpy(ps_name, names[0] + 1, ps_name_len); ps_name[ps_name_len] = 0; } if ( style->indexes[face_index] > 1 && style->indexes[face_index] <= FT_MIN( string_count, 64 ) ) { unsigned char* suffixes = names[style->indexes[face_index] - 1]; for ( i = 1; i <= suffixes[0]; i++ ) { unsigned char* s; size_t j = suffixes[i] - 1; if ( j < string_count && ( s = names[j] ) != NULL ) { size_t s_len = (size_t)s[0]; if ( s_len != 0 && ps_name_len + s_len < sizeof ( ps_name ) ) { ft_memcpy( ps_name + ps_name_len, s + 1, s_len ); ps_name_len += s_len; ps_name[ps_name_len] = 0; } } } } } create_lwfn_name( ps_name, lwfn_file_name ); } }
void CASpeexDecoder::InitializeCompressionSettings() { if (mCookie == NULL) return; if (mCompressionInitialized) { memset(&mSpeexHeader, 0, sizeof(mSpeexHeader)); mSpeexStereoState.balance = 1.0; mSpeexStereoState.e_ratio = 0.5; mSpeexStereoState.smooth_left = 1.0; mSpeexStereoState.smooth_right = 1.0; if (mSpeexDecoderState != NULL) { speex_decoder_destroy(mSpeexDecoderState); mSpeexDecoderState = NULL; } } mCompressionInitialized = false; OggSerialNoAtom *atom = reinterpret_cast<OggSerialNoAtom*> (mCookie); Byte *ptrheader = mCookie + EndianU32_BtoN(atom->size); CookieAtomHeader *aheader = reinterpret_cast<CookieAtomHeader*> (ptrheader); // scan quickly through the cookie, check types and packet sizes if (EndianS32_BtoN(atom->type) != kCookieTypeOggSerialNo || static_cast<UInt32> (ptrheader - mCookie) > mCookieSize) return; ptrheader += EndianU32_BtoN(aheader->size); if (EndianS32_BtoN(aheader->type) != kCookieTypeSpeexHeader || static_cast<UInt32> (ptrheader - mCookie) > mCookieSize) return; // we ignore the rest: comments and extra headers // all OK, back to the first speex packet aheader = reinterpret_cast<CookieAtomHeader*> (mCookie + EndianU32_BtoN(atom->size)); SpeexHeader *inheader = reinterpret_cast<SpeexHeader *> (&aheader->data[0]); // TODO: convert, at some point, mSpeexHeader to a pointer? mSpeexHeader.bitrate = EndianS32_LtoN(inheader->bitrate); mSpeexHeader.extra_headers = EndianS32_LtoN(inheader->extra_headers); mSpeexHeader.frame_size = EndianS32_LtoN(inheader->frame_size); mSpeexHeader.frames_per_packet = EndianS32_LtoN(inheader->frames_per_packet); mSpeexHeader.header_size = EndianS32_LtoN(inheader->header_size); mSpeexHeader.mode = EndianS32_LtoN(inheader->mode); mSpeexHeader.mode_bitstream_version = EndianS32_LtoN(inheader->mode_bitstream_version); mSpeexHeader.nb_channels = EndianS32_LtoN(inheader->nb_channels); mSpeexHeader.rate = EndianS32_LtoN(inheader->rate); mSpeexHeader.reserved1 = EndianS32_LtoN(inheader->reserved1); mSpeexHeader.reserved2 = EndianS32_LtoN(inheader->reserved2); mSpeexHeader.speex_version_id = EndianS32_LtoN(inheader->speex_version_id); mSpeexHeader.vbr = EndianS32_LtoN(inheader->vbr); if (mSpeexHeader.mode >= SPEEX_NB_MODES) CODEC_THROW(kAudioCodecUnsupportedFormatError); //TODO: check bitstream version here mSpeexDecoderState = speex_decoder_init(speex_lib_get_mode(mSpeexHeader.mode)); if (!mSpeexDecoderState) CODEC_THROW(kAudioCodecUnsupportedFormatError); //TODO: fix some of the header fields here int enhzero = 0; speex_decoder_ctl(mSpeexDecoderState, SPEEX_SET_ENH, &enhzero); if (mSpeexHeader.nb_channels == 2) { SpeexCallback callback; callback.callback_id = SPEEX_INBAND_STEREO; callback.func = speex_std_stereo_request_handler; callback.data = &mSpeexStereoState; speex_decoder_ctl(mSpeexDecoderState, SPEEX_SET_HANDLER, &callback); } mCompressionInitialized = true; }
const String getConnectedEndpointName (MIDIEndpointRef endpoint) { String result; // Does the endpoint have connections? CFDataRef connections = 0; int numConnections = 0; MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections); if (connections != 0) { numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID)); if (numConnections > 0) { const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections)); for (int i = 0; i < numConnections; ++i, ++pid) { MIDIUniqueID uid = EndianS32_BtoN (*pid); MIDIObjectRef connObject; MIDIObjectType connObjectType; OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType); if (err == noErr) { String s; if (connObjectType == kMIDIObjectType_ExternalSource || connObjectType == kMIDIObjectType_ExternalDestination) { // Connected to an external device's endpoint (10.3 and later). s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true); } else { // Connected to an external device (10.2) (or something else, catch-all) CFStringRef str = 0; MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str); if (str != 0) { s = PlatformUtilities::cfStringToJuceString (str); CFRelease (str); } } if (s.isNotEmpty()) { if (result.isNotEmpty()) result += ", "; result += s; } } } } CFRelease (connections); } if (result.isNotEmpty()) return result; // Here, either the endpoint had no connections, or we failed to obtain names for any of them. return getEndpointName (endpoint, false); }
ComponentResult write_vorbisPrivateData(GenericStreamPtr as, UInt8 **buf, UInt32 *bufSize) { ComponentResult err = noErr; void *magicCookie = NULL; UInt32 cookieSize = 0; dbg_printf("[WebM] Get Vorbis Private Data\n"); err = QTGetComponentPropertyInfo(as->aud.vorbisComponentInstance, kQTPropertyClass_SCAudio, kQTSCAudioPropertyID_MagicCookie, NULL, &cookieSize, NULL); if (err) return err; dbg_printf("[WebM] Cookie Size %d\n", cookieSize); magicCookie = calloc(1, cookieSize); err = QTGetComponentProperty(as->aud.vorbisComponentInstance, kQTPropertyClass_SCAudio, kQTSCAudioPropertyID_MagicCookie, cookieSize, magicCookie, NULL); if (err) goto bail; UInt8 *ptrheader = (UInt8 *) magicCookie; UInt8 *cend = ptrheader + cookieSize; CookieAtomHeader *aheader = (CookieAtomHeader *) ptrheader; WebMBuffer header, header_vc, header_cb; header.size = header_vc.size = header_cb.size = 0; while (ptrheader < cend) { aheader = (CookieAtomHeader *) ptrheader; ptrheader += EndianU32_BtoN(aheader->size); if (ptrheader > cend || EndianU32_BtoN(aheader->size) <= 0) break; switch (EndianS32_BtoN(aheader->type)) { case kCookieTypeVorbisHeader: header.size = EndianS32_BtoN(aheader->size) - 2 * sizeof(long); header.data = aheader->data; break; case kCookieTypeVorbisComments: header_vc.size = EndianS32_BtoN(aheader->size) - 2 * sizeof(long); header_vc.data = aheader->data; break; case kCookieTypeVorbisCodebooks: header_cb.size = EndianS32_BtoN(aheader->size) - 2 * sizeof(long); header_cb.data = aheader->data; break; default: break; } } if (header.size == 0 || header_vc.size == 0 || header_cb.size == 0) { err = paramErr; goto bail; } //1 + header1 /255 + header2 /255 + idheader.len + *bufSize = 1; //the first byte which is always 0x02 *bufSize += (header.size - 1) / 255 + 1; //the header size lacing *bufSize += (header_vc.size - 1) / 255 + 1; //the comment size lacing *bufSize += header.size + header_vc.size + header_cb.size; //the packets dbg_printf("[WebM]Packet headers %d %d %d -- total buffer %d\n", header.size, header_vc.size , header_cb.size, *bufSize); *buf = malloc(*bufSize); UInt8 *ptr = *buf; *ptr = 0x02; ptr ++; //using ogg lacing write out the size of the first two packets _oggLacing(&ptr, header.size); _oggLacing(&ptr, header_vc.size); _dbg_printVorbisHeader(header.data); memcpy(ptr, header.data, header.size); ptr += header.size; memcpy(ptr, header_vc.data, header_vc.size); ptr += header_vc.size; memcpy(ptr, header_cb.data, header_cb.size); bail: if (magicCookie != NULL) { free(magicCookie); magicCookie = NULL; } return err; }
OSErr init_theora_decoder(Theora_Globals glob, CodecDecompressParams *p) { OSErr err = noErr; Handle ext; //OggSerialNoAtom *atom; Byte *ptrheader, *mCookie, *cend; UInt32 mCookieSize; CookieAtomHeader *aheader; th_comment tc; ogg_packet header, header_tc, header_cb; if (glob->info_initialised) { dbg_printf("--:Theora:- Decoder already initialised, skipping...\n"); return err; } err = GetImageDescriptionExtension(p->imageDescription, &ext, kSampleDescriptionExtensionTheora, 1); if (err != noErr) { dbg_printf("XXX GetImageDescriptionExtension() failed! ('%4.4s')\n", &(*p->imageDescription)->cType); err = codecBadDataErr; return err; } mCookie = (UInt8 *) *ext; mCookieSize = GetHandleSize(ext); ptrheader = mCookie; cend = mCookie + mCookieSize; aheader = (CookieAtomHeader*)ptrheader; header.bytes = header_tc.bytes = header_cb.bytes = 0; while (ptrheader < cend) { aheader = (CookieAtomHeader *) ptrheader; ptrheader += EndianU32_BtoN(aheader->size); if (ptrheader > cend || EndianU32_BtoN(aheader->size) <= 0) break; switch(EndianS32_BtoN(aheader->type)) { case kCookieTypeTheoraHeader: header.b_o_s = 1; header.e_o_s = 0; header.granulepos = 0; header.packetno = 0; header.bytes = EndianS32_BtoN(aheader->size) - 2 * sizeof(long); header.packet = aheader->data; break; case kCookieTypeTheoraComments: header_tc.b_o_s = 0; header_tc.e_o_s = 0; header_tc.granulepos = 0; header_tc.packetno = 1; header_tc.bytes = EndianS32_BtoN(aheader->size) - 2 * sizeof(long); header_tc.packet = aheader->data; break; case kCookieTypeTheoraCodebooks: header_cb.b_o_s = 0; header_cb.e_o_s = 0; header_cb.granulepos = 0; header_cb.packetno = 2; header_cb.bytes = EndianS32_BtoN(aheader->size) - 2 * sizeof(long); header_cb.packet = aheader->data; break; default: break; } } err = codecBadDataErr; if (header.bytes == 0 || header_tc.bytes == 0 || header_cb.bytes == 0) return err; th_info_init(&glob->ti); th_comment_init(&tc); glob->ts = NULL; if (th_decode_headerin(&glob->ti, &tc, &glob->ts, &header) < 0) { if (glob->ts != NULL) th_setup_free (glob->ts); th_comment_clear(&tc); th_info_clear(&glob->ti); return err; } th_decode_headerin(&glob->ti, &tc, &glob->ts, &header_tc); th_decode_headerin(&glob->ti, &tc, &glob->ts, &header_cb); err = noErr; th_comment_clear(&tc); dbg_printf("--:Theora:- OK, managed to initialize the decoder somehow...\n"); glob->info_initialised = true; return err; }