void ClassHierarchyDCmd::execute(DCmdSource source, TRAPS) { VM_PrintClassHierarchy printClassHierarchyOp(output(), _print_interfaces.value(), _print_subclasses.value(), _classname.value()); VMThread::execute(&printClassHierarchyOp); }
string CCJSONArray::toString() { CCMemoryOutputStream mos; output(&mos); return string(mos.getBuffer(), mos.getLength()); }
void sort_frequency( void ) /*************************/ { letter_t previous; letter_t after_c; letter_t c; char prt_c; boolean change; /* find the alphabetic character that occurs the most in the keywords */ most_used_character = LETTER_MIN; for( c = LETTER_MIN; c <= LETTER_MAX; ++c ) { if( c == LETTER__ ) continue; if( freq[ c ] > freq[ most_used_character ] ) { most_used_character = c; } } /* make the next[] links into a ring */ for( c = LETTER_MIN; c < LETTER_MAX; ++c ) { next[ c ] = c + 1; } next[ LETTER_MAX ] = LETTER_MIN; /* sort the list of characters in descending order of frequency */ do { change = FALSE; c = most_used_character; for(;;) { previous = c; c = next[ previous ]; after_c = next[ c ]; if( after_c == most_used_character ) break; if( freq[ c ] < freq[ after_c ] ) { /* exchange 'c' and 'after_c' */ next[ c ] = next[ after_c ]; next[ after_c ] = c; next[ previous ] = after_c; change = TRUE; } } } while( change ); /* sort lists of equal frequency characters in ascending order */ do { change = FALSE; c = most_used_character; for(;;) { previous = c; c = next[ previous ]; after_c = next[ c ]; if( after_c == most_used_character ) break; if( freq[ c ] == freq[ after_c ] ) { if( c > after_c ) { /* exchange 'c' and 'after_c' */ next[ c ] = next[ after_c ]; next[ after_c ] = c; next[ previous ] = after_c; change = TRUE; } } } } while( change ); output( "frequency ordering of characters: " ); /* update the prev pointers to reflect the new ordering */ c = most_used_character; do { if( freq[ c ] != 0 ) { prt_c = make_char( c ); if( isprint( prt_c ) ) { output( "%c", prt_c ); } else { output( "\\x%02x", prt_c ); } } after_c = next[ c ]; prev[ after_c ] = c; c = after_c; } while( c != most_used_character ); output( "\n" ); }
static ngx_int_t ngx_http_image_handler(ngx_http_request_t *r) { u_char *last; size_t root; ngx_int_t rc; ngx_str_t path; char request_uri[255]; int request_uri_len; ngx_image_conf_t *conf; conf = ngx_http_get_module_loc_conf(r, ngx_http_image_module); if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) { return NGX_HTTP_NOT_ALLOWED; } if (r->headers_in.if_modified_since) { return NGX_HTTP_NOT_MODIFIED; } if (r->uri.data[r->uri.len - 1] == '/') { return NGX_DECLINED; } rc = ngx_http_discard_request_body(r); if (rc != NGX_OK) { return rc; } last = ngx_http_map_uri_to_path(r, &path, &root, 0); if (last == NULL) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } if(file_exists((char*) path.data) == -1) { request_uri_len = strlen((char *)r->uri_start) - strlen((char *)r->uri_end); strncpy(request_uri, (char *)r->uri_start, request_uri_len); request_uri[request_uri_len] = '\0'; conf->request_dir = dirname(request_uri); conf->url = request_uri;//请求的URL地址 conf->dest_file = (char *)path.data; check_image_type(conf);//检查图片类型(根据后缀进行简单判断) if( conf->dest_type > 0 ) { if (parse_image_info(conf) == 0)//解析并处理请求的图片URL { make_thumb(conf);//生成图片缩略图 water_mark(conf);//图片打上水印 thumb_to_string(conf);//GD对象转换成二进制字符串 if(conf->image_output == 0) { write_img(conf);//保存图片缩略图到文件 } if(conf->src_im != NULL){ gdImageDestroy(conf->src_im); } if(conf->dst_im != NULL) { gdImageDestroy(conf->dst_im); } if(conf->water_im != NULL) { gdImageDestroy(info->water_im); } if(conf->w_margin > 0 && conf->w_im != NULL) { gdImageDestroy(conf->w_im);//释放补白边的对象 } if(conf->image_output == 1) { return output(r,conf,ngx_http_image_types[conf->dest_type]); } } } } return NGX_DECLINED; }
le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le_int32 scriptCode, LEUnicode *outChars, LEGlyphStorage &glyphStorage, MPreFixups **outMPreFixups, LEErrorCode& success) { if (LE_FAILURE(success)) { return 0; } MPreFixups *mpreFixups = NULL; const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode); if (classTable==NULL) { success = LE_INTERNAL_ERROR; return 0; } if (classTable->scriptFlags & SF_MPRE_FIXUP) { mpreFixups = new MPreFixups(charCount); if (mpreFixups == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; return 0; } } IndicReorderingOutput output(outChars, glyphStorage, mpreFixups); le_int32 i, prev = 0; le_bool lastInWord = FALSE; while (prev < charCount) { le_int32 syllable = findSyllable(classTable, chars, prev, charCount); le_int32 matra, markStart = syllable; output.reset(); if (classTable->isStressMark(chars[markStart - 1])) { markStart -= 1; output.noteStressMark(classTable, chars[markStart], markStart, tagArray1); } if (markStart != prev && classTable->isVowelModifier(chars[markStart - 1])) { markStart -= 1; output.noteVowelModifier(classTable, chars[markStart], markStart, tagArray1); } matra = markStart - 1; while (output.noteMatra(classTable, chars[matra], matra, tagArray1, !lastInWord) && matra != prev) { matra -= 1; } lastInWord = TRUE; switch (classTable->getCharClass(chars[prev]) & CF_CLASS_MASK) { case CC_RESERVED: lastInWord = FALSE; /* fall through */ case CC_INDEPENDENT_VOWEL: case CC_ZERO_WIDTH_MARK: for (i = prev; i < syllable; i += 1) { output.writeChar(chars[i], i, tagArray1); } break; case CC_AL_LAKUNA: case CC_NUKTA: output.writeChar(C_DOTTED_CIRCLE, prev, tagArray1); output.writeChar(chars[prev], prev, tagArray1); break; case CC_VIRAMA: // A lone virama is illegal unless it follows a // MALAYALAM_VOWEL_SIGN_U. Such a usage is called // "samvruthokaram". if (chars[prev - 1] != C_MALAYALAM_VOWEL_SIGN_U) { output.writeChar(C_DOTTED_CIRCLE, prev, tagArray1); } output.writeChar(chars[prev], prev, tagArray1); break; case CC_DEPENDENT_VOWEL: case CC_SPLIT_VOWEL_PIECE_1: case CC_SPLIT_VOWEL_PIECE_2: case CC_SPLIT_VOWEL_PIECE_3: case CC_VOWEL_MODIFIER: case CC_STRESS_MARK: output.writeMpre(); output.writeChar(C_DOTTED_CIRCLE, prev, tagArray1); output.writeMbelow(); output.writeSMbelow(); output.writeMabove(); if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) != 0) { output.writeMpost(); } if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) != 0) { output.writeVMabove(); output.writeSMabove(); // FIXME: there are no SM's in these scripts... } if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) == 0) { output.writeMpost(); } output.writeLengthMark(); output.writeAlLakuna(); if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) == 0) { output.writeVMabove(); output.writeSMabove(); } output.writeVMpost(); break; case CC_INDEPENDENT_VOWEL_2: case CC_INDEPENDENT_VOWEL_3: case CC_CONSONANT: case CC_CONSONANT_WITH_NUKTA: { le_uint32 length = markStart - prev; le_int32 lastConsonant = markStart - 1; le_int32 baseLimit = prev; // Check for REPH at front of syllable if (length > 2 && classTable->isReph(chars[prev]) && classTable->isVirama(chars[prev + 1]) && chars[prev + 2] != C_SIGN_ZWNJ) { baseLimit += 2; // Check for eyelash RA, if the script supports it if ((classTable->scriptFlags & SF_EYELASH_RA) != 0 && chars[baseLimit] == C_SIGN_ZWJ) { if (length > 3) { baseLimit += 1; } else { baseLimit -= 2; } } } while (lastConsonant > baseLimit && !classTable->isConsonant(chars[lastConsonant])) { lastConsonant -= 1; } IndicClassTable::CharClass charClass = CC_RESERVED; IndicClassTable::CharClass nextClass = CC_RESERVED; le_int32 baseConsonant = lastConsonant; le_int32 postBase = lastConsonant + 1; le_int32 postBaseLimit = classTable->scriptFlags & SF_POST_BASE_LIMIT_MASK; le_bool seenVattu = FALSE; le_bool seenBelowBaseForm = FALSE; le_bool seenPreBaseForm = FALSE; le_bool hasNukta = FALSE; le_bool hasBelowBaseForm = FALSE; le_bool hasPostBaseForm = FALSE; le_bool hasPreBaseForm = FALSE; if (postBase < markStart && classTable->isNukta(chars[postBase])) { charClass = CC_NUKTA; postBase += 1; } while (baseConsonant > baseLimit) { nextClass = charClass; hasNukta = IndicClassTable::isNukta(nextClass); charClass = classTable->getCharClass(chars[baseConsonant]); hasBelowBaseForm = IndicClassTable::hasBelowBaseForm(charClass) && !hasNukta; hasPostBaseForm = IndicClassTable::hasPostBaseForm(charClass) && !hasNukta; hasPreBaseForm = IndicClassTable::hasPreBaseForm(charClass) && !hasNukta; if (IndicClassTable::isConsonant(charClass)) { if (postBaseLimit == 0 || seenVattu || (baseConsonant > baseLimit && !classTable->isVirama(chars[baseConsonant - 1])) || !(hasBelowBaseForm || hasPostBaseForm || hasPreBaseForm)) { break; } // Note any pre-base consonants if ( baseConsonant == lastConsonant && lastConsonant > 0 && hasPreBaseForm && classTable->isVirama(chars[baseConsonant - 1])) { output.notePreBaseConsonant(lastConsonant,chars[lastConsonant],chars[lastConsonant-1],tagArray2); seenPreBaseForm = TRUE; } // consonants with nuktas are never vattus seenVattu = IndicClassTable::isVattu(charClass) && !hasNukta; // consonants with nuktas never have below- or post-base forms if (hasPostBaseForm) { if (seenBelowBaseForm) { break; } postBase = baseConsonant; } else if (hasBelowBaseForm) { seenBelowBaseForm = TRUE; } postBaseLimit -= 1; } baseConsonant -= 1; } // Write Mpre output.writeMpre(); // Write eyelash RA // NOTE: baseLimit == prev + 3 iff eyelash RA present... if (baseLimit == prev + 3) { output.writeChar(chars[prev], prev, tagArray2); output.writeChar(chars[prev + 1], prev + 1, tagArray2); output.writeChar(chars[prev + 2], prev + 2, tagArray2); } // write any pre-base consonants output.writePreBaseConsonant(); le_bool supressVattu = TRUE; for (i = baseLimit; i < baseConsonant; i += 1) { LEUnicode ch = chars[i]; // Don't put 'pstf' or 'blwf' on anything before the base consonant. FeatureMask features = tagArray1 & ~( pstfFeatureMask | blwfFeatureMask ); charClass = classTable->getCharClass(ch); nextClass = classTable->getCharClass(chars[i + 1]); hasNukta = IndicClassTable::isNukta(nextClass); if (IndicClassTable::isConsonant(charClass)) { if (IndicClassTable::isVattu(charClass) && !hasNukta && supressVattu) { features = tagArray4; } supressVattu = IndicClassTable::isVattu(charClass) && !hasNukta; } else if (IndicClassTable::isVirama(charClass) && chars[i + 1] == C_SIGN_ZWNJ) { features = tagArray4; } output.writeChar(ch, i, features); } le_int32 bcSpan = baseConsonant + 1; if (bcSpan < markStart && classTable->isNukta(chars[bcSpan])) { bcSpan += 1; } if (baseConsonant == lastConsonant && bcSpan < markStart && (classTable->isVirama(chars[bcSpan]) || classTable->isAlLakuna(chars[bcSpan]))) { bcSpan += 1; if (bcSpan < markStart && chars[bcSpan] == C_SIGN_ZWNJ) { bcSpan += 1; } } // note the base consonant for post-GSUB fixups output.noteBaseConsonant(); // write base consonant for (i = baseConsonant; i < bcSpan; i += 1) { output.writeChar(chars[i], i, tagArray4); } if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) != 0) { output.writeMbelow(); output.writeSMbelow(); // FIXME: there are no SMs in these scripts... output.writeMabove(); output.writeMpost(); } // write below-base consonants if (baseConsonant != lastConsonant && !seenPreBaseForm) { for (i = bcSpan + 1; i < postBase; i += 1) { output.writeChar(chars[i], i, tagArray1); } if (postBase > lastConsonant) { // write halant that was after base consonant output.writeChar(chars[bcSpan], bcSpan, tagArray1); } } // write Mbelow, SMbelow, Mabove if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) == 0) { output.writeMbelow(); output.writeSMbelow(); output.writeMabove(); } if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) != 0) { if (baseLimit == prev + 2) { output.writeChar(chars[prev], prev, tagArray0); output.writeChar(chars[prev + 1], prev + 1, tagArray0); } output.writeVMabove(); output.writeSMabove(); // FIXME: there are no SM's in these scripts... } // write post-base consonants // FIXME: does this put the right tags on post-base consonants? if (baseConsonant != lastConsonant && !seenPreBaseForm) { if (postBase <= lastConsonant) { for (i = postBase; i <= lastConsonant; i += 1) { output.writeChar(chars[i], i, tagArray3); } // write halant that was after base consonant output.writeChar(chars[bcSpan], bcSpan, tagArray1); } // write the training halant, if there is one if (lastConsonant < matra && classTable->isVirama(chars[matra])) { output.writeChar(chars[matra], matra, tagArray4); } } // write Mpost if ((classTable->scriptFlags & SF_MATRAS_AFTER_BASE) == 0) { output.writeMpost(); } output.writeLengthMark(); output.writeAlLakuna(); // write reph if ((classTable->scriptFlags & SF_REPH_AFTER_BELOW) == 0) { if (baseLimit == prev + 2) { output.writeChar(chars[prev], prev, tagArray0); output.writeChar(chars[prev + 1], prev + 1, tagArray0); } output.writeVMabove(); output.writeSMabove(); } output.writeVMpost(); break; } default: break; } prev = syllable; } *outMPreFixups = mpreFixups; return output.getOutputIndex(); }
int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) { struct sk_buff *frag; struct rt6_info *rt = (struct rt6_info*)skb_dst(skb); struct ipv6_pinfo *np = skb->sk ? inet6_sk(skb->sk) : NULL; struct ipv6hdr *tmp_hdr; struct frag_hdr *fh; unsigned int mtu, hlen, left, len; int hroom, troom; __be32 frag_id = 0; int ptr, offset = 0, err=0; u8 *prevhdr, nexthdr = 0; struct net *net = dev_net(skb_dst(skb)->dev); hlen = ip6_find_1stfragopt(skb, &prevhdr); nexthdr = *prevhdr; mtu = ip6_skb_dst_mtu(skb); /* We must not fragment if the socket is set to force MTU discovery * or if the skb it not generated by a local socket. */ if (unlikely(!skb->local_df && skb->len > mtu) || (IP6CB(skb)->frag_max_size && IP6CB(skb)->frag_max_size > mtu)) { if (skb->sk && dst_allfrag(skb_dst(skb))) sk_nocaps_add(skb->sk, NETIF_F_GSO_MASK); skb->dev = skb_dst(skb)->dev; icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS); kfree_skb(skb); return -EMSGSIZE; } if (np && np->frag_size < mtu) { if (np->frag_size) mtu = np->frag_size; } mtu -= hlen + sizeof(struct frag_hdr); if (skb_has_frag_list(skb)) { int first_len = skb_pagelen(skb); struct sk_buff *frag2; if (first_len - hlen > mtu || ((first_len - hlen) & 7) || skb_cloned(skb)) goto slow_path; skb_walk_frags(skb, frag) { /* Correct geometry. */ if (frag->len > mtu || ((frag->len & 7) && frag->next) || skb_headroom(frag) < hlen) goto slow_path_clean; /* Partially cloned skb? */ if (skb_shared(frag)) goto slow_path_clean; BUG_ON(frag->sk); if (skb->sk) { frag->sk = skb->sk; frag->destructor = sock_wfree; } skb->truesize -= frag->truesize; } err = 0; offset = 0; frag = skb_shinfo(skb)->frag_list; skb_frag_list_init(skb); /* BUILD HEADER */ *prevhdr = NEXTHDR_FRAGMENT; tmp_hdr = kmemdup(skb_network_header(skb), hlen, GFP_ATOMIC); if (!tmp_hdr) { IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS); return -ENOMEM; } __skb_pull(skb, hlen); fh = (struct frag_hdr*)__skb_push(skb, sizeof(struct frag_hdr)); __skb_push(skb, hlen); skb_reset_network_header(skb); memcpy(skb_network_header(skb), tmp_hdr, hlen); ipv6_select_ident(fh, rt); fh->nexthdr = nexthdr; fh->reserved = 0; fh->frag_off = htons(IP6_MF); frag_id = fh->identification; first_len = skb_pagelen(skb); skb->data_len = first_len - skb_headlen(skb); skb->len = first_len; ipv6_hdr(skb)->payload_len = htons(first_len - sizeof(struct ipv6hdr)); dst_hold(&rt->dst); for (;;) { /* Prepare header of the next frame, * before previous one went down. */ if (frag) { frag->ip_summed = CHECKSUM_NONE; skb_reset_transport_header(frag); fh = (struct frag_hdr*)__skb_push(frag, sizeof(struct frag_hdr)); __skb_push(frag, hlen); skb_reset_network_header(frag); memcpy(skb_network_header(frag), tmp_hdr, hlen); offset += skb->len - hlen - sizeof(struct frag_hdr); fh->nexthdr = nexthdr; fh->reserved = 0; fh->frag_off = htons(offset); if (frag->next != NULL) fh->frag_off |= htons(IP6_MF); fh->identification = frag_id; ipv6_hdr(frag)->payload_len = htons(frag->len - sizeof(struct ipv6hdr)); ip6_copy_metadata(frag, skb); } err = output(skb); if(!err) IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), IPSTATS_MIB_FRAGCREATES); if (err || !frag) break; skb = frag; frag = skb->next; skb->next = NULL; } kfree(tmp_hdr); if (err == 0) { IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), IPSTATS_MIB_FRAGOKS); ip6_rt_put(rt); return 0; } while (frag) { skb = frag->next; kfree_skb(frag); frag = skb; } IP6_INC_STATS(net, ip6_dst_idev(&rt->dst), IPSTATS_MIB_FRAGFAILS); ip6_rt_put(rt); return err; slow_path_clean: skb_walk_frags(skb, frag2) { if (frag2 == frag) break; frag2->sk = NULL; frag2->destructor = NULL; skb->truesize += frag2->truesize; } } slow_path: if ((skb->ip_summed == CHECKSUM_PARTIAL) && skb_checksum_help(skb)) goto fail; left = skb->len - hlen; /* Space per frame */ ptr = hlen; /* Where to start from */ /* * Fragment the datagram. */ *prevhdr = NEXTHDR_FRAGMENT; hroom = LL_RESERVED_SPACE(rt->dst.dev); troom = rt->dst.dev->needed_tailroom; /* * Keep copying data until we run out. */ while(left > 0) { len = left; /* IF: it doesn't fit, use 'mtu' - the data space left */ if (len > mtu) len = mtu; /* IF: we are not sending up to and including the packet end then align the next start on an eight byte boundary */ if (len < left) { len &= ~7; } /* * Allocate buffer. */ if ((frag = alloc_skb(len + hlen + sizeof(struct frag_hdr) + hroom + troom, GFP_ATOMIC)) == NULL) { NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n"); IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS); err = -ENOMEM; goto fail; } /* * Set up data on packet */ ip6_copy_metadata(frag, skb); skb_reserve(frag, hroom); skb_put(frag, len + hlen + sizeof(struct frag_hdr)); skb_reset_network_header(frag); fh = (struct frag_hdr *)(skb_network_header(frag) + hlen); frag->transport_header = (frag->network_header + hlen + sizeof(struct frag_hdr)); /* * Charge the memory for the fragment to any owner * it might possess */ if (skb->sk) skb_set_owner_w(frag, skb->sk); /* * Copy the packet header into the new buffer. */ skb_copy_from_linear_data(skb, skb_network_header(frag), hlen); /* * Build fragment header. */ fh->nexthdr = nexthdr; fh->reserved = 0; if (!frag_id) { ipv6_select_ident(fh, rt); frag_id = fh->identification; } else fh->identification = frag_id; /* * Copy a block of the IP datagram. */ if (skb_copy_bits(skb, ptr, skb_transport_header(frag), len)) BUG(); left -= len; fh->frag_off = htons(offset); if (left > 0) fh->frag_off |= htons(IP6_MF); ipv6_hdr(frag)->payload_len = htons(frag->len - sizeof(struct ipv6hdr)); ptr += len; offset += len; /* * Put this fragment into the sending queue. */ err = output(frag); if (err) goto fail; IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGCREATES); } IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGOKS); consume_skb(skb); return err; fail: IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS); kfree_skb(skb); return err; }
int main(void){ output(); return 0; }
// // Maya calls this method to have the translator write out a file. // MStatus maTranslator::writer( const MFileObject& file, const MString& /* options */, MPxFileTranslator::FileAccessMode mode ) { // // For simplicity, we only do full saves/exports. // if ((mode != kSaveAccessMode) && (mode != kExportAccessMode)) return MS::kNotImplemented; // // Let's see if we can open the output file. // fstream output(file.fullName().asChar(), ios::out | ios::trunc); if (!output.good()) return MS::kNotFound; // // Get some node flags to keep track of those nodes for which we // have already done various stages of processing. // MStatus status; fCreateFlag = MFnDependencyNode::allocateFlag(fPluginName, &status); if (status) fAttrFlag = MFnDependencyNode::allocateFlag(fPluginName, &status); if (status) fConnectionFlag = MFnDependencyNode::allocateFlag(fPluginName, &status); if (!status) { MGlobal::displayError( "Could not allocate three free node flags." " Try unloading some other plugins." ); return MS::kFailure; } // // Run through all of the nodes in the scene and clear their flags. // MItDependencyNodes nodesIter; for (; !nodesIter.isDone(); nodesIter.next()) { MObject node = nodesIter.item(); MFnDependencyNode nodeFn(node); nodeFn.setFlag(fCreateFlag, false); nodeFn.setFlag(fAttrFlag, false); nodeFn.setFlag(fConnectionFlag, false); } // // Write out the various sections of the file. // writeHeader(output, file.name()); writeFileInfo(output); writeReferences(output); writeRequirements(output); writeUnits(output); writeDagNodes(output); writeNonDagNodes(output); writeDefaultNodes(output); writeReferenceNodes(output); writeConnections(output); writeFooter(output, file.name()); output.close(); MFnDependencyNode::deallocateFlag(fPluginName, fCreateFlag); return MS::kSuccess; }
void KonfUpdate::gotScript(const QString &_script) { QString script, interpreter; int i = _script.indexOf(','); if (i == -1) { script = _script.trimmed(); } else { script = _script.left(i).trimmed(); interpreter = _script.mid(i + 1).trimmed(); } if (script.isEmpty()) { logFileError() << "Script fails to specify filename"; m_skip = true; return; } QString path = KStandardDirs::locate("data", "kconf_update/" + script); if (path.isEmpty()) { if (interpreter.isEmpty()) { path = KStandardDirs::locate("lib", "kconf_update_bin/" + script); } if (path.isEmpty()) { logFileError() << "Script '" << script << "' not found" << endl; m_skip = true; return; } } if (!m_arguments.isNull()) { log() << m_currentFilename << ": Running script '" << script << "' with arguments '" << m_arguments << "'" << endl; } else { log() << m_currentFilename << ": Running script '" << script << "'" << endl; } QString cmd; if (interpreter.isEmpty()) { cmd = path; } else { cmd = interpreter + ' ' + path; } if (!m_arguments.isNull()) { cmd += ' '; cmd += m_arguments; } KTemporaryFile scriptIn; scriptIn.open(); KTemporaryFile scriptOut; scriptOut.open(); KTemporaryFile scriptErr; scriptErr.open(); int result; if (m_oldConfig1) { if (m_debug) { scriptIn.setAutoRemove(false); log() << "Script input stored in " << scriptIn.fileName() << endl; } KConfig cfg(scriptIn.fileName(), KConfig::SimpleConfig); if (m_oldGroup.isEmpty()) { // Write all entries to tmpFile; const QStringList grpList = m_oldConfig1->groupList(); for (QStringList::ConstIterator it = grpList.begin(); it != grpList.end(); ++it) { copyGroup(m_oldConfig1, *it, &cfg, *it); } } else { KConfigGroup cg1 = KConfigUtils::openGroup(m_oldConfig1, m_oldGroup); KConfigGroup cg2(&cfg, QString()); copyGroup(cg1, cg2); } cfg.sync(); #ifndef _WIN32_WCE result = system(QFile::encodeName(QString("%1 < %2 > %3 2> %4").arg(cmd, scriptIn.fileName(), scriptOut.fileName(), scriptErr.fileName()))); #else QString path_ = QDir::convertSeparators ( QFileInfo ( cmd ).absoluteFilePath() ); QString file_ = QFileInfo ( cmd ).fileName(); SHELLEXECUTEINFO execInfo; memset ( &execInfo,0,sizeof ( execInfo ) ); execInfo.cbSize = sizeof ( execInfo ); execInfo.fMask = SEE_MASK_FLAG_NO_UI; execInfo.lpVerb = L"open"; execInfo.lpFile = (LPCWSTR) path_.utf16(); execInfo.lpDirectory = (LPCWSTR) file_.utf16(); execInfo.lpParameters = (LPCWSTR) QString(" < %1 > %2 2> %3").arg( scriptIn.fileName(), scriptOut.fileName(), scriptErr.fileName()).utf16(); result = ShellExecuteEx ( &execInfo ); if (result != 0) { result = 0; } else { result = -1; } #endif } else { // No config file #ifndef _WIN32_WCE result = system(QFile::encodeName(QString("%1 2> %2").arg(cmd, scriptErr.fileName()))); #else QString path_ = QDir::convertSeparators ( QFileInfo ( cmd ).absoluteFilePath() ); QString file_ = QFileInfo ( cmd ).fileName(); SHELLEXECUTEINFO execInfo; memset ( &execInfo,0,sizeof ( execInfo ) ); execInfo.cbSize = sizeof ( execInfo ); execInfo.fMask = SEE_MASK_FLAG_NO_UI; execInfo.lpVerb = L"open"; execInfo.lpFile = (LPCWSTR) path_.utf16(); execInfo.lpDirectory = (LPCWSTR) file_.utf16(); execInfo.lpParameters = (LPCWSTR) QString(" 2> %1").arg( scriptErr.fileName()).utf16(); result = ShellExecuteEx ( &execInfo ); if (result != 0) { result = 0; } else { result = -1; } #endif } // Copy script stderr to log file { QFile output(scriptErr.fileName()); if (output.open(QIODevice::ReadOnly)) { QTextStream ts(&output); ts.setCodec(QTextCodec::codecForName("UTF-8")); while (!ts.atEnd()) { QString line = ts.readLine(); log() << "[Script] " << line << endl; } } } if (result) { log() << m_currentFilename << ": !! An error occurred while running '" << cmd << "'" << endl; return; } if (!m_oldConfig1) { return; // Nothing to merge } if (m_debug) { scriptOut.setAutoRemove(false); log() << "Script output stored in " << scriptOut.fileName() << endl; } // Deleting old entries { QStringList group = m_oldGroup; QFile output(scriptOut.fileName()); if (output.open(QIODevice::ReadOnly)) { QTextStream ts(&output); ts.setCodec(QTextCodec::codecForName("UTF-8")); while (!ts.atEnd()) { QString line = ts.readLine(); if (line.startsWith('[')) { group = parseGroupString(line); } else if (line.startsWith(QLatin1String("# DELETE "))) { QString key = line.mid(9); if (key[0] == '[') { int j = key.lastIndexOf(']') + 1; if (j > 0) { group = parseGroupString(key.left(j)); key = key.mid(j); } } KConfigGroup cg = KConfigUtils::openGroup(m_oldConfig2, group); cg.deleteEntry(key); log() << m_currentFilename << ": Script removes " << m_oldFile << ":" << group << ":" << key << endl; /*if (m_oldConfig2->deleteGroup(group, KConfig::Normal)) { // Delete group if empty. log() << m_currentFilename << ": Removing empty group " << m_oldFile << ":" << group << endl; } (this should be automatic)*/ } else if (line.startsWith(QLatin1String("# DELETEGROUP"))) { QString str = line.mid(13).trimmed(); if (!str.isEmpty()) { group = parseGroupString(str); } KConfigGroup cg = KConfigUtils::openGroup(m_oldConfig2, group); cg.deleteGroup(); log() << m_currentFilename << ": Script removes group " << m_oldFile << ":" << group << endl; } } } } // Merging in new entries. KConfig scriptOutConfig(scriptOut.fileName(), KConfig::NoGlobals); if (m_newGroup.isEmpty()) { // Copy "default" keys as members of "default" keys copyGroup(&scriptOutConfig, QString(), m_newConfig, QString()); } else { // Copy default keys as members of m_newGroup KConfigGroup srcCg = KConfigUtils::openGroup(&scriptOutConfig, QStringList()); KConfigGroup dstCg = KConfigUtils::openGroup(m_newConfig, m_newGroup); copyGroup(srcCg, dstCg); } Q_FOREACH(const QString &group, scriptOutConfig.groupList()) { copyGroup(&scriptOutConfig, group, m_newConfig, group); } }
int main(int argc,char **argv) { int i,index; FILE *fp, *fp_restore = NULL; char *save_filename = NULL; char *restore_filename = NULL; for(i=1;i<argc;i++) { if(argv[i][0] != '-') break; ++i; switch(argv[i-1][1]) { case 'l': lower = atof(argv[i]); break; case 'u': upper = atof(argv[i]); break; case 'y': y_lower = atof(argv[i]); ++i; y_upper = atof(argv[i]); y_scaling = 1; break; case 's': save_filename = argv[i]; break; case 'r': restore_filename = argv[i]; break; default: fprintf(stderr,"unknown option\n"); exit_with_help(); } } if(!(upper > lower) || (y_scaling && !(y_upper > y_lower))) { fprintf(stderr,"inconsistent lower/upper specification\n"); exit(1); } if(restore_filename && save_filename) { fprintf(stderr,"cannot use -r and -s simultaneously\n"); exit(1); } if(argc != i+1) exit_with_help(); fp=fopen(argv[i],"r"); if(fp==NULL) { fprintf(stderr,"can't open file %s\n", argv[i]); exit(1); } line = (char *) malloc(max_line_len*sizeof(char)); #define SKIP_TARGET\ while(isspace(*p)) ++p;\ while(!isspace(*p)) ++p; #define SKIP_ELEMENT\ while(*p!=':') ++p;\ ++p;\ while(isspace(*p)) ++p;\ while(*p && !isspace(*p)) ++p; max_index = 0; min_index = 1; if(restore_filename) { int idx, c; fp_restore = fopen(restore_filename,"r"); if(fp_restore==NULL) { fprintf(stderr,"can't open file %s\n", restore_filename); exit(1); } c = fgetc(fp_restore); if(c == 'y') { readline(fp_restore); readline(fp_restore); readline(fp_restore); } readline(fp_restore); readline(fp_restore); while(fscanf(fp_restore,"%d %*f %*f\n",&idx) == 1) max_index = max(idx,max_index); rewind(fp_restore); } while(readline(fp)!=NULL) { char *p=line; SKIP_TARGET while(sscanf(p,"%d:%*f",&index)==1) { max_index = max(max_index, index); min_index = min(min_index, index); SKIP_ELEMENT num_nonzeros++; } } if(min_index < 1) fprintf(stderr, "WARNING: minimal feature index is %d, but indices should start from 1\n", min_index); rewind(fp); feature_max = (double *)malloc((max_index+1)* sizeof(double)); feature_min = (double *)malloc((max_index+1)* sizeof(double)); if(feature_max == NULL || feature_min == NULL) { fprintf(stderr,"can't allocate enough memory\n"); exit(1); } for(i=0;i<=max_index;i++) { feature_max[i]=-DBL_MAX; feature_min[i]=DBL_MAX; } while(readline(fp)!=NULL) { char *p=line; int next_index=1; double target; double value; sscanf(p,"%lf",&target); y_max = max(y_max,target); y_min = min(y_min,target); SKIP_TARGET while(sscanf(p,"%d:%lf",&index,&value)==2) { for(i=next_index;i<index;i++) { feature_max[i]=max(feature_max[i],0); feature_min[i]=min(feature_min[i],0); } feature_max[index]=max(feature_max[index],value); feature_min[index]=min(feature_min[index],value); SKIP_ELEMENT next_index=index+1; } for(i=next_index;i<=max_index;i++) { feature_max[i]=max(feature_max[i],0); feature_min[i]=min(feature_min[i],0); } } rewind(fp); if(restore_filename) { int idx, c; double fmin, fmax; int next_index = 1; if((c = fgetc(fp_restore)) == 'y') { fscanf(fp_restore, "%lf %lf\n", &y_lower, &y_upper); fscanf(fp_restore, "%lf %lf\n", &y_min, &y_max); y_scaling = 1; } else ungetc(c, fp_restore); if (fgetc(fp_restore) == 'x') { fscanf(fp_restore, "%lf %lf\n", &lower, &upper); while(fscanf(fp_restore,"%d %lf %lf\n",&idx,&fmin,&fmax)==3) { for(i = next_index;i<idx;i++) if(feature_min[i] != feature_max[i]) fprintf(stderr, "WARNING: feature index %d appeared in file %s was not seen in the scaling factor file %s.\n", i, argv[argc-1], restore_filename); feature_min[idx] = fmin; feature_max[idx] = fmax; next_index = idx + 1; } for(i=next_index;i<=max_index;i++) if(feature_min[i] != feature_max[i]) fprintf(stderr, "WARNING: feature index %d appeared in file %s was not seen in the scaling factor file %s.\n", i, argv[argc-1], restore_filename); } fclose(fp_restore); } if(save_filename) { FILE *fp_save = fopen(save_filename,"w"); if(fp_save==NULL) { fprintf(stderr,"can't open file %s\n", save_filename); exit(1); } if(y_scaling) { fprintf(fp_save, "y\n"); fprintf(fp_save, "%.16g %.16g\n", y_lower, y_upper); fprintf(fp_save, "%.16g %.16g\n", y_min, y_max); } fprintf(fp_save, "x\n"); fprintf(fp_save, "%.16g %.16g\n", lower, upper); for(i=1;i<=max_index;i++) { if(feature_min[i]!=feature_max[i]) fprintf(fp_save,"%d %.16g %.16g\n",i,feature_min[i],feature_max[i]); } if(min_index < 1) fprintf(stderr, "WARNING: scaling factors with indices smaller than 1 are not stored to the file %s.\n", save_filename); fclose(fp_save); } while(readline(fp)!=NULL) { char *p=line; int next_index=1; double target; double value; sscanf(p,"%lf",&target); output_target(target); SKIP_TARGET while(sscanf(p,"%d:%lf",&index,&value)==2) { for(i=next_index;i<index;i++) output(i,0); output(index,value); SKIP_ELEMENT next_index=index+1; } for(i=next_index;i<=max_index;i++) output(i,0); printf("\n"); } if (new_num_nonzeros > num_nonzeros) fprintf(stderr, "WARNING: original #nonzeros %ld\n" " new #nonzeros %ld\n" "Use -l 0 if many original feature values are zeros\n", num_nonzeros, new_num_nonzeros); free(line); free(feature_max); free(feature_min); fclose(fp); return 0; }
void QEglFSKmsEglDeviceWindow::resetSurface() { qCDebug(qLcEglfsKmsDebug, "Creating stream"); EGLDisplay display = screen()->display(); EGLint streamAttribs[3]; int streamAttribCount = 0; int fifoLength = qEnvironmentVariableIntValue("QT_QPA_EGLFS_STREAM_FIFO_LENGTH"); if (fifoLength > 0) { streamAttribs[streamAttribCount++] = EGL_STREAM_FIFO_LENGTH_KHR; streamAttribs[streamAttribCount++] = fifoLength; } streamAttribs[streamAttribCount++] = EGL_NONE; m_egl_stream = m_integration->m_funcs->create_stream(display, streamAttribs); if (m_egl_stream == EGL_NO_STREAM_KHR) { qWarning("resetSurface: Couldn't create EGLStream for native window"); return; } qCDebug(qLcEglfsKmsDebug, "Created stream %p on display %p", m_egl_stream, display); EGLint count; if (m_integration->m_funcs->query_stream(display, m_egl_stream, EGL_STREAM_FIFO_LENGTH_KHR, &count)) { if (count > 0) qCDebug(qLcEglfsKmsDebug, "Using EGLStream FIFO mode with %d frames", count); else qCDebug(qLcEglfsKmsDebug, "Using EGLStream mailbox mode"); } else { qCDebug(qLcEglfsKmsDebug, "Could not query number of EGLStream FIFO frames"); } if (!m_integration->m_funcs->get_output_layers(display, Q_NULLPTR, Q_NULLPTR, 0, &count) || count == 0) { qWarning("No output layers found"); return; } qCDebug(qLcEglfsKmsDebug, "Output has %d layers", count); QVector<EGLOutputLayerEXT> layers; layers.resize(count); EGLint actualCount; if (!m_integration->m_funcs->get_output_layers(display, Q_NULLPTR, layers.data(), count, &actualCount)) { qWarning("Failed to get layers"); return; } QEglFSKmsEglDeviceScreen *cur_screen = static_cast<QEglFSKmsEglDeviceScreen *>(screen()); Q_ASSERT(cur_screen); QKmsOutput &output(cur_screen->output()); const uint32_t wantedId = !output.wants_plane ? output.crtc_id : output.plane_id; qCDebug(qLcEglfsKmsDebug, "Searching for id: %d", wantedId); EGLOutputLayerEXT layer = EGL_NO_OUTPUT_LAYER_EXT; for (int i = 0; i < actualCount; ++i) { EGLAttrib id; if (m_integration->m_funcs->query_output_layer_attrib(display, layers[i], EGL_DRM_CRTC_EXT, &id)) { qCDebug(qLcEglfsKmsDebug, " [%d] layer %p - crtc %d", i, layers[i], (int) id); if (id == EGLAttrib(wantedId)) layer = layers[i]; } else if (m_integration->m_funcs->query_output_layer_attrib(display, layers[i], EGL_DRM_PLANE_EXT, &id)) { qCDebug(qLcEglfsKmsDebug, " [%d] layer %p - plane %d", i, layers[i], (int) id); if (id == EGLAttrib(wantedId)) layer = layers[i]; } else { qCDebug(qLcEglfsKmsDebug, " [%d] layer %p - unknown", i, layers[i]); } } QByteArray reqLayerIndex = qgetenv("QT_QPA_EGLFS_LAYER_INDEX"); if (!reqLayerIndex.isEmpty()) { int idx = reqLayerIndex.toInt(); if (idx >= 0 && idx < layers.count()) { qCDebug(qLcEglfsKmsDebug, "EGLOutput layer index override = %d", idx); layer = layers[idx]; } } if (layer == EGL_NO_OUTPUT_LAYER_EXT) { qWarning("resetSurface: Couldn't get EGLOutputLayer for native window"); return; } qCDebug(qLcEglfsKmsDebug, "Using layer %p", layer); if (!m_integration->m_funcs->stream_consumer_output(display, m_egl_stream, layer)) qWarning("resetSurface: Unable to connect stream"); m_config = QEglFSDeviceIntegration::chooseConfig(display, m_integration->surfaceFormatFor(window()->requestedFormat())); m_format = q_glFormatFromConfig(display, m_config); qCDebug(qLcEglfsKmsDebug) << "Stream producer format is" << m_format; const int w = cur_screen->rawGeometry().width(); const int h = cur_screen->rawGeometry().height(); qCDebug(qLcEglfsKmsDebug, "Creating stream producer surface of size %dx%d", w, h); const EGLint stream_producer_attribs[] = { EGL_WIDTH, w, EGL_HEIGHT, h, EGL_NONE }; m_surface = m_integration->m_funcs->create_stream_producer_surface(display, m_config, m_egl_stream, stream_producer_attribs); if (m_surface == EGL_NO_SURFACE) return; qCDebug(qLcEglfsKmsDebug, "Created stream producer surface %p", m_surface); }
void open_if_block (const char *c_cond) { output ("if (%s)", c_cond); block_begin (); }
void block_end (void) { adjust_indent (-3); output ("}"); }
void block_begin (void) { output ("{"); adjust_indent (+3); }
static void start_i2c(void) { output(1, 1, 0); usleep(1000); // stopped (SCL = 1, SDA = 1) output(1, 0, 0); usleep(1000); // running (SCL = 0) }
int main(int argc, char * argv[]) { pid_t child; pthread_mutex_t mtx; pthread_mutexattr_t ma[4]; pthread_mutexattr_t *pma[5]; int ret=0; int i; int retini[5] = {-1,-1,-1,-1,-1}; int retdtr[5]= {-1,-1,-1,-1,-1}; void * ptr, *ptr_prev=NULL; int sz = 0; struct rlimit rl; int status=0; output_init(); child = fork(); if (child == (pid_t)-1) { UNRESOLVED(errno, "Fork failed"); } if (child != 0) /* We are the father */ { if (child != waitpid(child, &status, 0)) { UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { UNRESOLVED(WTERMSIG(status), "The child process was killed."); } if (WIFEXITED(status)) return WEXITSTATUS(status); UNRESOLVED(0, "Child process neither returned nor was killed."); } /* Only the child goes further */ /* We initialize the different mutex attributes */ for (i=0; (i<4) && (ret == 0); i++) { pma[i] = &ma[i]; ret = pthread_mutexattr_init(pma[i]); } if (ret) { UNRESOLVED(ret, "Mutex attribute init failed"); } pma[4] = (pthread_mutexattr_t *) NULL; if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) { UNRESOLVED(ret, "Mutex attribute NORMAL failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_DEFAULT))) { UNRESOLVED(ret, "Mutex attribute DEFAULT failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_RECURSIVE))) { UNRESOLVED(ret, "Mutex attribute RECURSIVE failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_ERRORCHECK))) { UNRESOLVED(ret, "Mutex attribute ERRORCHECK failed"); } sz = sysconf(_SC_PAGESIZE); /* Limit the process memory to a small value (64Mb for example). */ rl.rlim_max=1024*1024*64; rl.rlim_cur=1024*1024*64; if ((ret = setrlimit(RLIMIT_AS, &rl))) { UNRESOLVED(ret, "Memory limitation failed"); } #if VERBOSE > 1 output("Ready to take over memory. Page size is %d\n", sz); #endif /* Allocate all available memory */ while (1) { ptr = malloc( sz ); /* Allocate one page of memory */ if (ptr == NULL) break; #if VERBOSE > 1 ret++; #endif *(void **)ptr = ptr_prev; /* Write into the allocated page */ ptr_prev = ptr; } #if VERBOSE > 1 output("%d pages were allocated before failure\n", ret); ret = 0; #endif while (1) { ptr = malloc( sizeof(void*) ); /* Allocate every remaining bits of memory */ if (ptr == NULL) break; #if VERBOSE > 1 ret++; #endif *(void **)ptr = ptr_prev; /* Keep track of allocated memory */ ptr_prev = ptr; } #if VERBOSE > 1 output("%d additional spaces were allocated before failure\n", ret); ret = 0; #endif if (errno != ENOMEM) UNRESOLVED(errno, "Memory not full"); /* Now that memory is full, we try to initialize a mutex */ for (i=0; i<5; i++) { retini[i] = pthread_mutex_init(&mtx, pma[i]); if (!retini[i]) /* If mutex has been initialized, we destroy it */ retdtr[i] = pthread_mutex_destroy(&mtx); } /* We can now free the memory */ while (ptr_prev != NULL) { ptr = ptr_prev; ptr_prev = *(void **)ptr; free(ptr); } #if VERBOSE > 1 output("Memory is released\n"); #endif for (i=0; i<4; i++) pthread_mutexattr_destroy(pma[i]); for (i=0; i<5; i++) { if (retini[i] != 0 && retini[i] !=ENOMEM) { FAILED("Mutex init returned a wrong error code when no memory was left"); } if (retini[i] == 0) { #if VERBOSE > 0 output("Mutex initialization for attribute %d succeeds when memory is full\n", i); #endif if (retdtr[i] != 0) { UNRESOLVED( retdtr[i], "Mutex destroy failed on mutex inilialized under heavy loaded memory"); } } #if VERBOSE > 0 else { output("Mutex initialization for attribute %d fails with ENOMEM when memory is full\n", i); } #endif } PASSED; }
static void send_bit_i2c(uint32_t v) { output(1, 0, v); usleep(100); // running (SCL = 0) output(1, 1, v); usleep(100); output(1, 0, v); usleep(100); // running (SCL = 0) }
~MP4FileStream() { if(!bStreamOpened) return; App->EnableSceneSwitching(false); //--------------------------------------------------- //HWND hwndProgressDialog = CreateDialog(hinstMain, MAKEINTRESOURCE(IDD_BUILDINGMP4), hwndMain, (DLGPROC)MP4ProgressDialogProc); //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETRANGE32, 0, 100); mdatStop = fileOut.GetPos(); BufferOutputSerializer output(endBuffer); UINT64 audioFrameSize = App->GetAudioEncoder()->GetFrameSize(); DWORD macTime = fastHtonl(DWORD(GetMacTime())); UINT videoDuration = fastHtonl(lastVideoTimestamp + App->GetFrameTime()); UINT audioDuration = fastHtonl(lastVideoTimestamp + DWORD(double(audioFrameSize)/44.1)); UINT width, height; App->GetOutputSize(width, height); LPCSTR lpVideoTrack = "Video Media Handler"; LPCSTR lpAudioTrack = "Sound Media Handler"; char videoCompressionName[31] = "AVC Coding"; //------------------------------------------- // get video headers DataPacket videoHeaders; App->GetVideoHeaders(videoHeaders); List<BYTE> SPS, PPS; LPBYTE lpHeaderData = videoHeaders.lpPacket+11; SPS.CopyArray(lpHeaderData+2, fastHtons(*(WORD*)lpHeaderData)); lpHeaderData += SPS.Num()+3; PPS.CopyArray(lpHeaderData+2, fastHtons(*(WORD*)lpHeaderData)); //------------------------------------------- // get AAC headers if using AAC List<BYTE> AACHeader; if(!bMP3) { DataPacket data; App->GetAudioHeaders(data); AACHeader.CopyArray(data.lpPacket+2, data.size-2); } //------------------------------------------- EndChunkInfo(videoChunks, videoSampleToChunk, curVideoChunkOffset, numVideoSamples); EndChunkInfo(audioChunks, audioSampleToChunk, curAudioChunkOffset, numAudioSamples); if (numVideoSamples > 1) GetVideoDecodeTime(videoFrames.Last(), true); if (numAudioSamples > 1) GetAudioDecodeTime(audioFrames.Last(), true); UINT audioUnitDuration = fastHtonl(UINT(lastAudioTimeVal)); //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETPOS, 25, 0); //------------------------------------------- // sound descriptor thingy. this part made me die a little inside admittedly. UINT maxBitRate = fastHtonl(App->GetAudioEncoder()->GetBitRate()*1000); List<BYTE> esDecoderDescriptor; BufferOutputSerializer esDecoderOut(esDecoderDescriptor); esDecoderOut.OutputByte(bMP3 ? 107 : 64); esDecoderOut.OutputByte(0x15); //stream/type flags. always 0x15 for my purposes. esDecoderOut.OutputByte(0); //buffer size, just set it to 1536 for both mp3 and aac esDecoderOut.OutputWord(WORD_BE(0x600)); esDecoderOut.OutputDword(maxBitRate); //max bit rate (cue bill 'o reily meme for these two) esDecoderOut.OutputDword(maxBitRate); //avg bit rate if(!bMP3) //if AAC, put in headers { esDecoderOut.OutputByte(0x5); //decoder specific descriptor type /*esDecoderOut.OutputByte(0x80); //some stuff that no one should probably care about esDecoderOut.OutputByte(0x80); esDecoderOut.OutputByte(0x80);*/ esDecoderOut.OutputByte(AACHeader.Num()); esDecoderOut.Serialize((LPVOID)AACHeader.Array(), AACHeader.Num()); } List<BYTE> esDescriptor; BufferOutputSerializer esOut(esDescriptor); esOut.OutputWord(0); //es id esOut.OutputByte(0); //stream priority esOut.OutputByte(4); //descriptor type /*esOut.OutputByte(0x80); //some stuff that no one should probably care about esOut.OutputByte(0x80); esOut.OutputByte(0x80);*/ esOut.OutputByte(esDecoderDescriptor.Num()); esOut.Serialize((LPVOID)esDecoderDescriptor.Array(), esDecoderDescriptor.Num()); esOut.OutputByte(0x6); //config descriptor type /*esOut.OutputByte(0x80); //some stuff that no one should probably care about esOut.OutputByte(0x80); esOut.OutputByte(0x80);*/ esOut.OutputByte(1); //len esOut.OutputByte(2); //SL value(? always 2) //------------------------------------------- PushBox(output, DWORD_BE('moov')); //------------------------------------------------------ // header PushBox(output, DWORD_BE('mvhd')); output.OutputDword(0); //version and flags (none) output.OutputDword(macTime); //creation time output.OutputDword(macTime); //modified time output.OutputDword(DWORD_BE(1000)); //time base (milliseconds, so 1000) output.OutputDword(videoDuration); //duration (in time base units) output.OutputDword(DWORD_BE(0x00010000)); //fixed point playback speed 1.0 output.OutputWord(WORD_BE(0x0100)); //fixed point vol 1.0 output.OutputQword(0); //reserved (10 bytes) output.OutputWord(0); output.OutputDword(DWORD_BE(0x00010000)); output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00000000)); //window matrix row 1 (1.0, 0.0, 0.0) output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00010000)); output.OutputDword(DWORD_BE(0x00000000)); //window matrix row 2 (0.0, 1.0, 0.0) output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x40000000)); //window matrix row 3 (0.0, 0.0, 16384.0) output.OutputDword(0); //prevew start time (time base units) output.OutputDword(0); //prevew duration (time base units) output.OutputDword(0); //still poster frame (timestamp of frame) output.OutputDword(0); //selection(?) start time (time base units) output.OutputDword(0); //selection(?) duration (time base units) output.OutputDword(0); //current time (0, time base units) output.OutputDword(DWORD_BE(3)); //next free track id (1-based rather than 0-based) PopBox(); //mvhd //------------------------------------------------------ // audio track PushBox(output, DWORD_BE('trak')); PushBox(output, DWORD_BE('tkhd')); //track header output.OutputDword(DWORD_BE(0x00000007)); //version (0) and flags (0xF) output.OutputDword(macTime); //creation time output.OutputDword(macTime); //modified time output.OutputDword(DWORD_BE(1)); //track ID output.OutputDword(0); //reserved output.OutputDword(audioDuration); //duration (in time base units) output.OutputQword(0); //reserved output.OutputWord(0); //video layer (0) output.OutputWord(WORD_BE(0)); //quicktime alternate track id output.OutputWord(WORD_BE(0x0100)); //volume output.OutputWord(0); //reserved output.OutputDword(DWORD_BE(0x00010000)); output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00000000)); //window matrix row 1 (1.0, 0.0, 0.0) output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00010000)); output.OutputDword(DWORD_BE(0x00000000)); //window matrix row 2 (0.0, 1.0, 0.0) output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x40000000)); //window matrix row 3 (0.0, 0.0, 16384.0) output.OutputDword(0); //width (fixed point) output.OutputDword(0); //height (fixed point) PopBox(); //tkhd /*PushBox(output, DWORD_BE('edts')); PushBox(output, DWORD_BE('elst')); output.OutputDword(0); //version and flags (none) output.OutputDword(DWORD_BE(1)); //count output.OutputDword(audioDuration); //duration output.OutputDword(0); //start time output.OutputDword(DWORD_BE(0x00010000)); //playback speed (1.0) PopBox(); //elst PopBox(); //tdst*/ PushBox(output, DWORD_BE('mdia')); PushBox(output, DWORD_BE('mdhd')); output.OutputDword(0); //version and flags (none) output.OutputDword(macTime); //creation time output.OutputDword(macTime); //modified time output.OutputDword(DWORD_BE(44100)); //time scale output.OutputDword(audioUnitDuration); output.OutputDword(bMP3 ? DWORD_BE(0x55c40000) : DWORD_BE(0x15c70000)); PopBox(); //mdhd PushBox(output, DWORD_BE('hdlr')); output.OutputDword(0); //version and flags (none) output.OutputDword(0); //quicktime type (none) output.OutputDword(DWORD_BE('soun')); //media type output.OutputDword(0); //manufacturer reserved output.OutputDword(0); //quicktime component reserved flags output.OutputDword(0); //quicktime component reserved mask output.Serialize((LPVOID)lpAudioTrack, (DWORD)strlen(lpAudioTrack)+1); //track name PopBox(); //hdlr PushBox(output, DWORD_BE('minf')); PushBox(output, DWORD_BE('smhd')); output.OutputDword(0); //version and flags (none) output.OutputDword(0); //balance (fixed point) PopBox(); //vdhd PushBox(output, DWORD_BE('dinf')); PushBox(output, DWORD_BE('dref')); output.OutputDword(0); //version and flags (none) output.OutputDword(DWORD_BE(1)); //count PushBox(output, DWORD_BE('url ')); output.OutputDword(DWORD_BE(0x00000001)); //version (0) and flags (1) PopBox(); //url PopBox(); //dref PopBox(); //dinf PushBox(output, DWORD_BE('stbl')); PushBox(output, DWORD_BE('stsd')); output.OutputDword(0); //version and flags (none) output.OutputDword(DWORD_BE(1)); //count PushBox(output, DWORD_BE('mp4a')); output.OutputDword(0); //reserved (6 bytes) output.OutputWord(0); output.OutputWord(WORD_BE(1)); //dref index output.OutputWord(0); //quicktime encoding version output.OutputWord(0); //quicktime encoding revision output.OutputDword(0); //quicktime audio encoding vendor output.OutputWord(0); //channels (ignored) output.OutputWord(WORD_BE(16)); //sample size output.OutputWord(0); //quicktime audio compression id output.OutputWord(0); //quicktime audio packet size output.OutputDword(DWORD_BE(44100<<16)); //sample rate (fixed point) PushBox(output, DWORD_BE('esds')); output.OutputDword(0); //version and flags (none) output.OutputByte(3); //ES descriptor type /*output.OutputByte(0x80); output.OutputByte(0x80); output.OutputByte(0x80);*/ output.OutputByte(esDescriptor.Num()); output.Serialize((LPVOID)esDescriptor.Array(), esDescriptor.Num()); PopBox(); PopBox(); PopBox(); //stsd PushBox(output, DWORD_BE('stts')); //list of keyframe (i-frame) IDs output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(audioDecodeTimes.Num())); for(UINT i=0; i<audioDecodeTimes.Num(); i++) { output.OutputDword(fastHtonl(audioDecodeTimes[i].count)); output.OutputDword(fastHtonl(audioDecodeTimes[i].val)); } PopBox(); //stss PushBox(output, DWORD_BE('stsc')); //sample to chunk list output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(audioSampleToChunk.Num())); for(UINT i=0; i<audioSampleToChunk.Num(); i++) { SampleToChunk &stc = audioSampleToChunk[i]; output.OutputDword(fastHtonl(stc.firstChunkID)); output.OutputDword(fastHtonl(stc.samplesPerChunk)); output.OutputDword(DWORD_BE(1)); } PopBox(); //stsc //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETPOS, 30, 0); //ProcessEvents(); PushBox(output, DWORD_BE('stsz')); //sample sizes output.OutputDword(0); //version and flags (none) output.OutputDword(0); //block size for all (0 if differing sizes) output.OutputDword(fastHtonl(audioFrames.Num())); for(UINT i=0; i<audioFrames.Num(); i++) output.OutputDword(fastHtonl(audioFrames[i].size)); PopBox(); //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETPOS, 40, 0); //ProcessEvents(); if(audioChunks.Num() && audioChunks.Last() > 0xFFFFFFFFLL) { PushBox(output, DWORD_BE('co64')); //chunk offsets output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(audioChunks.Num())); for(UINT i=0; i<audioChunks.Num(); i++) output.OutputQword(fastHtonll(audioChunks[i])); PopBox(); //co64 } else { PushBox(output, DWORD_BE('stco')); //chunk offsets output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(audioChunks.Num())); for(UINT i=0; i<audioChunks.Num(); i++) output.OutputDword(fastHtonl((DWORD)audioChunks[i])); PopBox(); //stco } PopBox(); //stbl PopBox(); //minf PopBox(); //mdia PopBox(); //trak //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETPOS, 50, 0); //ProcessEvents(); //------------------------------------------------------ // video track PushBox(output, DWORD_BE('trak')); PushBox(output, DWORD_BE('tkhd')); //track header output.OutputDword(DWORD_BE(0x00000007)); //version (0) and flags (0x7) output.OutputDword(macTime); //creation time output.OutputDword(macTime); //modified time output.OutputDword(DWORD_BE(2)); //track ID output.OutputDword(0); //reserved output.OutputDword(videoDuration); //duration (in time base units) output.OutputQword(0); //reserved output.OutputWord(0); //video layer (0) output.OutputWord(0); //quicktime alternate track id (0) output.OutputWord(0); //track audio volume (this is video, so 0) output.OutputWord(0); //reserved output.OutputDword(DWORD_BE(0x00010000)); output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00000000)); //window matrix row 1 (1.0, 0.0, 0.0) output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00010000)); output.OutputDword(DWORD_BE(0x00000000)); //window matrix row 2 (0.0, 1.0, 0.0) output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x00000000)); output.OutputDword(DWORD_BE(0x40000000)); //window matrix row 3 (0.0, 0.0, 16384.0) output.OutputDword(fastHtonl(width<<16)); //width (fixed point) output.OutputDword(fastHtonl(height<<16)); //height (fixed point) PopBox(); //tkhd /*PushBox(output, DWORD_BE('edts')); PushBox(output, DWORD_BE('elst')); output.OutputDword(0); //version and flags (none) output.OutputDword(DWORD_BE(1)); //count output.OutputDword(videoDuration); //duration output.OutputDword(0); //start time output.OutputDword(DWORD_BE(0x00010000)); //playback speed (1.0) PopBox(); //elst PopBox(); //tdst*/ PushBox(output, DWORD_BE('mdia')); PushBox(output, DWORD_BE('mdhd')); output.OutputDword(0); //version and flags (none) output.OutputDword(macTime); //creation time output.OutputDword(macTime); //modified time output.OutputDword(DWORD_BE(1000)); //time scale output.OutputDword(videoDuration); output.OutputDword(DWORD_BE(0x55c40000)); PopBox(); //mdhd PushBox(output, DWORD_BE('hdlr')); output.OutputDword(0); //version and flags (none) output.OutputDword(0); //quicktime type (none) output.OutputDword(DWORD_BE('vide')); //media type output.OutputDword(0); //manufacturer reserved output.OutputDword(0); //quicktime component reserved flags output.OutputDword(0); //quicktime component reserved mask output.Serialize((LPVOID)lpVideoTrack, (DWORD)strlen(lpVideoTrack)+1); //track name PopBox(); //hdlr PushBox(output, DWORD_BE('minf')); PushBox(output, DWORD_BE('vmhd')); output.OutputDword(DWORD_BE(0x00000001)); //version (0) and flags (1) output.OutputWord(0); //quickdraw graphic mode (copy = 0) output.OutputWord(0); //quickdraw red value output.OutputWord(0); //quickdraw green value output.OutputWord(0); //quickdraw blue value PopBox(); //vdhd PushBox(output, DWORD_BE('dinf')); PushBox(output, DWORD_BE('dref')); output.OutputDword(0); //version and flags (none) output.OutputDword(DWORD_BE(1)); //count PushBox(output, DWORD_BE('url ')); output.OutputDword(DWORD_BE(0x00000001)); //version (0) and flags (1) PopBox(); //url PopBox(); //dref PopBox(); //dinf PushBox(output, DWORD_BE('stbl')); PushBox(output, DWORD_BE('stsd')); output.OutputDword(0); //version and flags (none) output.OutputDword(DWORD_BE(1)); //count PushBox(output, DWORD_BE('avc1')); output.OutputDword(0); //reserved 6 bytes output.OutputWord(0); output.OutputWord(WORD_BE(1)); //index output.OutputWord(0); //encoding version output.OutputWord(0); //encoding revision level output.OutputDword(0); //encoding vendor output.OutputDword(0); //temporal quality output.OutputDword(0); //spatial quality output.OutputWord(fastHtons(width)); //width output.OutputWord(fastHtons(height)); //height output.OutputDword(DWORD_BE(0x00480000)); //fixed point width pixel resolution (72.0) output.OutputDword(DWORD_BE(0x00480000)); //fixed point height pixel resolution (72.0) output.OutputDword(0); //quicktime video data size output.OutputWord(WORD_BE(1)); //frame count(?) output.OutputByte((BYTE)strlen(videoCompressionName)); //compression name length output.Serialize(videoCompressionName, 31); //31 bytes for the name output.OutputWord(WORD_BE(24)); //bit depth output.OutputWord(0xFFFF); //quicktime video color table id (none = -1) PushBox(output, DWORD_BE('avcC')); output.OutputByte(1); //version output.OutputByte(100); //h264 profile ID output.OutputByte(0); //h264 compatible profiles output.OutputByte(0x1f); //h264 level output.OutputByte(0xff); //reserved output.OutputByte(0xe1); //first half-byte = no clue. second half = sps count output.OutputWord(fastHtons(SPS.Num())); //sps size output.Serialize(SPS.Array(), SPS.Num()); //sps data output.OutputByte(1); //pps count output.OutputWord(fastHtons(PPS.Num())); //pps size output.Serialize(PPS.Array(), PPS.Num()); //pps data PopBox(); //avcC PopBox(); //avc1 PopBox(); //stsd PushBox(output, DWORD_BE('stts')); //frame times output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(videoDecodeTimes.Num())); for(UINT i=0; i<videoDecodeTimes.Num(); i++) { output.OutputDword(fastHtonl(videoDecodeTimes[i].count)); output.OutputDword(fastHtonl(videoDecodeTimes[i].val)); } PopBox(); //stts //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETPOS, 60, 0); //ProcessEvents(); PushBox(output, DWORD_BE('stss')); //list of keyframe (i-frame) IDs output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(IFrameIDs.Num())); output.Serialize(IFrameIDs.Array(), IFrameIDs.Num()*sizeof(UINT)); PopBox(); //stss PushBox(output, DWORD_BE('ctts')); //list of composition time offsets output.OutputDword(0); //version (0) and flags (none) //output.OutputDword(DWORD_BE(0x01000000)); //version (1) and flags (none) output.OutputDword(fastHtonl(compositionOffsets.Num())); for(UINT i=0; i<compositionOffsets.Num(); i++) { output.OutputDword(fastHtonl(compositionOffsets[i].count)); output.OutputDword(fastHtonl(compositionOffsets[i].val)); } PopBox(); //ctts //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETPOS, 70, 0); //ProcessEvents(); PushBox(output, DWORD_BE('stsc')); //sample to chunk list output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(videoSampleToChunk.Num())); for(UINT i=0; i<videoSampleToChunk.Num(); i++) { SampleToChunk &stc = videoSampleToChunk[i]; output.OutputDword(fastHtonl(stc.firstChunkID)); output.OutputDword(fastHtonl(stc.samplesPerChunk)); output.OutputDword(DWORD_BE(1)); } PopBox(); //stsc PushBox(output, DWORD_BE('stsz')); //sample sizes output.OutputDword(0); //version and flags (none) output.OutputDword(0); //block size for all (0 if differing sizes) output.OutputDword(fastHtonl(videoFrames.Num())); for(UINT i=0; i<videoFrames.Num(); i++) output.OutputDword(fastHtonl(videoFrames[i].size)); PopBox(); if(videoChunks.Num() && videoChunks.Last() > 0xFFFFFFFFLL) { PushBox(output, DWORD_BE('co64')); //chunk offsets output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(videoChunks.Num())); for(UINT i=0; i<videoChunks.Num(); i++) output.OutputQword(fastHtonll(videoChunks[i])); PopBox(); //co64 } else { PushBox(output, DWORD_BE('stco')); //chunk offsets output.OutputDword(0); //version and flags (none) output.OutputDword(fastHtonl(videoChunks.Num())); for(UINT i=0; i<videoChunks.Num(); i++) output.OutputDword(fastHtonl((DWORD)videoChunks[i])); PopBox(); //stco } PopBox(); //stbl PopBox(); //minf PopBox(); //mdia PopBox(); //trak //SendMessage(GetDlgItem(hwndProgressDialog, IDC_PROGRESS1), PBM_SETPOS, 80, 0); //ProcessEvents(); //------------------------------------------------------ // info thingy PushBox(output, DWORD_BE('udta')); PushBox(output, DWORD_BE('meta')); output.OutputDword(0); //version and flags (none) PushBox(output, DWORD_BE('hdlr')); output.OutputDword(0); //version and flags (none) output.OutputDword(0); //quicktime type output.OutputDword(DWORD_BE('mdir')); //metadata type output.OutputDword(DWORD_BE('appl')); //quicktime manufacturer reserved thingy output.OutputDword(0); //quicktime component reserved flag output.OutputDword(0); //quicktime component reserved flag mask output.OutputByte(0); //null string PopBox(); //hdlr PushBox(output, DWORD_BE('ilst')); PushBox(output, DWORD_BE('\xa9too')); PushBox(output, DWORD_BE('data')); output.OutputDword(DWORD_BE(1)); //version (1) + flags (0) output.OutputDword(0); //reserved LPSTR lpVersion = OBS_VERSION_STRING_ANSI; output.Serialize(lpVersion, (DWORD)strlen(lpVersion)); PopBox(); //data PopBox(); //@too PopBox(); //ilst PopBox(); //meta PopBox(); //udta PopBox(); //moov fileOut.Serialize(endBuffer.Array(), endBuffer.Num()); fileOut.Close(); XFile file; if(file.Open(strFile, XFILE_WRITE, XFILE_OPENEXISTING)) { #ifdef USE_64BIT_MP4 file.SetPos((INT64)mdatStart+8, XFILE_BEGIN); UINT64 size = fastHtonll(mdatStop-mdatStart); file.Write(&size, 8); #else file.SetPos((INT64)mdatStart, XFILE_BEGIN); UINT size = fastHtonl((DWORD)(mdatStop-mdatStart)); file.Write(&size, 4); #endif file.Close(); } App->EnableSceneSwitching(true); //DestroyWindow(hwndProgressDialog); }
static int stop(sox_effect_t * effp) { priv_t * p = (priv_t *)effp->priv; if (!effp->flow) { double min_runs = 0, max_count = 0, min = 2, max = -2, max_sigma_x = 0, sigma_x = 0, sigma_x2 = 0, min_sigma_x2 = 2, max_sigma_x2 = 0, avg_peak = 0; off_t num_samples = 0, min_count = 0, max_runs = 0; uint32_t mask = 0; unsigned b1, b2, i, n = effp->flows > 1 ? effp->flows : 0; for (i = 0; i < effp->flows; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; min = min(min, q->min); max = max(max, q->max); min_sigma_x2 = min(min_sigma_x2, q->min_sigma_x2); max_sigma_x2 = max(max_sigma_x2, q->max_sigma_x2); sigma_x += q->sigma_x; sigma_x2 += q->sigma_x2; num_samples += q->num_samples; mask |= q->mask; if (fabs(q->sigma_x) > fabs(max_sigma_x)) max_sigma_x = q->sigma_x; min_count += q->min_count; min_runs += q->min_runs; max_count += q->max_count; max_runs += q->max_runs; avg_peak += max(-q->min, q->max); } avg_peak /= effp->flows; if (!num_samples) { lsx_warn("no audio"); return SOX_SUCCESS; } if (n == 2) fprintf(stderr, " Overall Left Right\n"); else if (n) { fprintf(stderr, " Overall"); for (i = 0; i < n; ++i) fprintf(stderr, " Ch%-3i", i + 1); fprintf(stderr, "\n"); } fprintf(stderr, "DC offset "); output(p, max_sigma_x / p->num_samples); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; output(p, q->sigma_x / q->num_samples); } fprintf(stderr, "\nMin level "); output(p, min); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; output(p, q->min); } fprintf(stderr, "\nMax level "); output(p, max); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; output(p, q->max); } fprintf(stderr, "\nPk lev dB %10.2f", linear_to_dB(max(-min, max))); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; fprintf(stderr, "%10.2f", linear_to_dB(max(-q->min, q->max))); } fprintf(stderr, "\nRMS lev dB%10.2f", linear_to_dB(sqrt(sigma_x2 / num_samples))); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; fprintf(stderr, "%10.2f", linear_to_dB(sqrt(q->sigma_x2 / q->num_samples))); } fprintf(stderr, "\nRMS Pk dB %10.2f", linear_to_dB(sqrt(max_sigma_x2))); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; fprintf(stderr, "%10.2f", linear_to_dB(sqrt(q->max_sigma_x2))); } fprintf(stderr, "\nRMS Tr dB "); if (min_sigma_x2 != 1) fprintf(stderr, "%10.2f", linear_to_dB(sqrt(min_sigma_x2))); else fprintf(stderr, " -"); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; if (q->min_sigma_x2 != 1) fprintf(stderr, "%10.2f", linear_to_dB(sqrt(q->min_sigma_x2))); else fprintf(stderr, " -"); } if (effp->flows > 1) fprintf(stderr, "\nCrest factor -"); else fprintf(stderr, "\nCrest factor %7.2f", sigma_x2 ? avg_peak / sqrt(sigma_x2 / num_samples) : 1); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; fprintf(stderr, "%10.2f", q->sigma_x2? max(-q->min, q->max) / sqrt(q->sigma_x2 / q->num_samples) : 1); } fprintf(stderr, "\nFlat factor%9.2f", linear_to_dB((min_runs + max_runs) / (min_count + max_count))); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; fprintf(stderr, " %9.2f", linear_to_dB((q->min_runs + q->max_runs) / (q->min_count + q->max_count))); } fprintf(stderr, "\nPk count %9s", lsx_sigfigs3((min_count + max_count) / effp->flows)); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; fprintf(stderr, " %9s", lsx_sigfigs3((double)(q->min_count + q->max_count))); } b1 = bit_depth(mask, min, max, &b2); fprintf(stderr, "\nBit-depth %2u/%-2u", b1, b2); for (i = 0; i < n; ++i) { priv_t * q = (priv_t *)(effp - effp->flow + i)->priv; b1 = bit_depth(q->mask, q->min, q->max, &b2); fprintf(stderr, " %2u/%-2u", b1, b2); } fprintf(stderr, "\nNum samples%9s", lsx_sigfigs3((double)p->num_samples)); fprintf(stderr, "\nLength s %9.3f", p->num_samples / effp->in_signal.rate); fprintf(stderr, "\nScale max "); output(p, 1.); fprintf(stderr, "\nWindow s %9.3f", p->time_constant); fprintf(stderr, "\n"); } return SOX_SUCCESS; }
int main(int argc, char **argv) { int index; int status = EX_OK; set_program_name(argv[0]); argp_version_setup("cflow", program_authors); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); register_output("gnu", gnu_output_handler, NULL); register_output("posix", posix_output_handler, NULL); symbol_map = SM_FUNCTIONS|SM_STATIC|SM_UNDEFINED; if (getenv("POSIXLY_CORRECT")) { if (select_output_driver("posix")) { error(0, 0, _("INTERNAL ERROR: %s: No such output driver"), "posix"); abort(); } output_init(); } sourcerc(&argc, &argv); if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) exit(EX_USAGE); if (print_option == 0) print_option = PRINT_TREE; init(); if (arglist) { struct linked_list_entry *p; for (p = arglist->head; p; p = p->next) { char *s = (char*)p->data; if (s[0] == '-') pp_option(s); else if (source(s) == 0) yyparse(); } } argc -= index; argv += index; while (argc--) { if (source(*argv++) == 0) yyparse(); else status = EX_SOFT; } if (input_file_count == 0) error(EX_USAGE, 0, _("no input files")); output(); return status; }
bool CSteadyStateTask::process(const bool & useInitialValues) { if (useInitialValues) { mpContainer->applyInitialValues(); } mSteadyState = mpContainer->getState(true); // A steady-state makes only sense in an autonomous model, // i.e., the time of the steady-state must not be changed // during simulation. C_FLOAT64 InitialTime = mSteadyState[mpContainer->getCountFixedEventTargets()]; CSteadyStateMethod* pMethod = dynamic_cast<CSteadyStateMethod *>(mpMethod); assert(pMethod); CSteadyStateProblem* pProblem = dynamic_cast<CSteadyStateProblem *>(mpProblem); assert(pMethod); output(COutputInterface::BEFORE); //call the method mResult = pMethod->process(mSteadyState, mJacobianReduced, mpCallBack); // Reset the time for an autonomous model. if (mpContainer->isAutonomous()) { mSteadyState[mpContainer->getCountFixedEventTargets()] = InitialTime; } if (mResult == CSteadyStateMethod::notFound) restore(); //update Jacobian if (mpContainer->isStateValid()) { if (pProblem->isJacobianRequested() || pProblem->isStabilityAnalysisRequested()) { pMethod->doJacobian(mJacobian, mJacobianReduced); } //mpProblem->getModel()->setState(mpSteadyState); //mpProblem->getModel()->updateRates(); //calculate eigenvalues if (pProblem->isStabilityAnalysisRequested()) { mEigenValues.calcEigenValues(mJacobian); mEigenValuesX.calcEigenValues(mJacobianReduced); mEigenValues.stabilityAnalysis(pMethod->getStabilityResolution()); mEigenValuesX.stabilityAnalysis(pMethod->getStabilityResolution()); } } C_FLOAT64 * pTo; size_t i; // construct Eigenvalues of Jacobian CVector< C_FLOAT64 > vectorEigen_R = mEigenValues.getR(); CVector< C_FLOAT64 > vectorEigen_I = mEigenValues.getI(); #ifdef DEBUG_UI C_INT32 size = vectorEigen_R.size() + vectorEigen_I.size(); std::cout << "vectorEigen_R.size() = " << vectorEigen_R.size() << " + vectorEigen_I.size() = " << vectorEigen_I.size() << " == " << size << std::endl; std::cout << "size = " << mEigenvaluesXMatrix.size() << std::endl; #endif assert(vectorEigen_R.size() == vectorEigen_I.size()); pTo = mEigenvaluesMatrix.array(); for (i = 0; i < vectorEigen_R.size(); ++i) { *pTo = vectorEigen_R[i]; ++pTo; *pTo = vectorEigen_I[i]; ++pTo; } #ifdef DEBUG_UI std::cout << mEigenvaluesMatrix << std::endl; #endif // construct Eigenvalues of Jacobian of reduced system CVector< C_FLOAT64 > vectorEigenX_R = mEigenValuesX.getR(); CVector< C_FLOAT64 > vectorEigenX_I = mEigenValuesX.getI(); #ifdef DEBUG_UI C_INT32 sizeX = vectorEigenX_R.size() + vectorEigenX_I.size(); std::cout << "vectorEigenX_R.size() = " << vectorEigenX_R.size() << " + vectorEigenX_I.size() = " << vectorEigenX_I.size() << " == " << sizeX << std::endl; std::cout << "size = " << mEigenvaluesXMatrix.size() << std::endl; #endif assert(vectorEigenX_R.size() == vectorEigenX_I.size()); pTo = mEigenvaluesXMatrix.array(); for (i = 0; i < vectorEigenX_R.size(); ++i) { *pTo = vectorEigenX_R[i]; ++pTo; *pTo = vectorEigenX_I[i]; ++pTo; } #ifdef DEBUG_UI std::cout << mEigenvaluesXMatrix << std::endl; #endif mpContainer->updateSimulatedValues(true); mpContainer->updateTransientDataValues(); mpContainer->pushAllTransientValues(); output(COutputInterface::AFTER); return (mResult != CSteadyStateMethod::notFound); }
bool runTestType(cl::Context context, cl::CommandQueue queue) { cl_uint size = 64 * 256; std::vector<T> input(size); for(size_t i = 0; i < input.size(); ++i) input[i] = input.size() - i - 1; // create input buffer using pinned memory cl::Buffer bufferIn(context, CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE, sizeof(T) * input.size(), &input[0]) ; magnet::CL::sort<T> sortFunctor; sortFunctor.build(queue, context); sortFunctor(bufferIn); std::cout << "##Testing generic sort ("; switch(sortFunctor.getMode()) { case magnet::CL::sort<T>::CPU: std::cout << "HeapSort"; break; case magnet::CL::sort<T>::NVIDIA: std::cout << "radixNVIDIA"; break; case magnet::CL::sort<T>::AMD: std::cout << "radixAMD"; break; default: M_throw() << "Could not determine which sorting algorithm is being used"; } std::cout << ") for " << input.size() << " elements and type " << magnet::CL::detail::traits<T>::kernel_type(); std::vector<T> output(size); queue.enqueueReadBuffer(bufferIn, CL_TRUE, 0, input.size() * sizeof(T), &output[0]); bool failed = !testOutput(input, output); std::cout << " key(only) " << (failed ? "FAILED" : "PASSED") << ", "; //Now test with some data! //Refresh the input array queue.enqueueWriteBuffer(bufferIn, CL_TRUE, 0, input.size() * sizeof(T), &input[0]); //Write a data array std::vector<cl_uint> data(size); for(size_t i = 0; i < input.size(); ++i) data[i] = i; cl::Buffer dataIn(context, CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_READ_WRITE, sizeof(cl_uint) * data.size(), &data[0]) ; sortFunctor(bufferIn, dataIn); queue.enqueueReadBuffer(dataIn, CL_TRUE, 0, data.size() * sizeof(cl_uint), &data[0]); bool keyfail = false;//!testOutput(input, output); std::cout << " key " << (keyfail ? "FAILED" : "PASSED"); bool datafail = false; for(size_t i = 0; i < input.size(); ++i) if (data[i] != input.size() - 1 - i) datafail = true; std::cout << " data " << (datafail ? "FAILED" : "PASSED") << std::endl; return failed || keyfail || datafail; }
le_int32 IndicReordering::v2process(const LEUnicode *chars, le_int32 charCount, le_int32 scriptCode, LEUnicode *outChars, LEGlyphStorage &glyphStorage) { const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode); if (classTable == NULL) { return 0; } DynamicProperties dynProps[INDIC_BLOCK_SIZE]; IndicReordering::getDynamicProperties(dynProps,classTable); IndicReorderingOutput output(outChars, glyphStorage, NULL); le_int32 i, firstConsonant, baseConsonant, secondConsonant, inv_count = 0, beginSyllable = 0; //le_bool lastInWord = FALSE; while (beginSyllable < charCount) { le_int32 nextSyllable = findSyllable(classTable, chars, beginSyllable, charCount); output.reset(); // Find the First Consonant for ( firstConsonant = beginSyllable ; firstConsonant < nextSyllable ; firstConsonant++ ) { if ( classTable->isConsonant(chars[firstConsonant]) ) { break; } } // Find the base consonant baseConsonant = nextSyllable - 1; secondConsonant = firstConsonant; // TODO: Use Dynamic Properties for hasBelowBaseForm and hasPostBaseForm() while ( baseConsonant > firstConsonant ) { if ( classTable->isConsonant(chars[baseConsonant]) && !classTable->hasBelowBaseForm(chars[baseConsonant]) && !classTable->hasPostBaseForm(chars[baseConsonant]) ) { break; } else { if ( classTable->isConsonant(chars[baseConsonant]) ) { secondConsonant = baseConsonant; } baseConsonant--; } } // If the syllable starts with Ra + Halant ( in a script that has Reph ) and has more than one // consonant, Ra is excluced from candidates for base consonants if ( classTable->isReph(chars[beginSyllable]) && beginSyllable+1 < nextSyllable && classTable->isVirama(chars[beginSyllable+1]) && secondConsonant != firstConsonant) { baseConsonant = secondConsonant; } // Populate the output for ( i = beginSyllable ; i < nextSyllable ; i++ ) { // Handle invalid combinartions if ( classTable->isVirama(chars[beginSyllable]) || classTable->isMatra(chars[beginSyllable]) || classTable->isVowelModifier(chars[beginSyllable]) || classTable->isNukta(chars[beginSyllable]) ) { output.writeChar(C_DOTTED_CIRCLE,beginSyllable,basicShapingFormsMask); inv_count++; } output.writeChar(chars[i],i, basicShapingFormsMask); } // Adjust features and set syllable structure bits for ( i = beginSyllable ; i < nextSyllable ; i++ ) { FeatureMask outMask = output.getFeatures(i+inv_count); FeatureMask saveMask = outMask; // Since reph can only validly occur at the beginning of a syllable // We only apply it to the first 2 characters in the syllable, to keep it from // conflicting with other features ( i.e. rkrf ) // TODO : Use the dynamic property for determining isREPH if ( i == beginSyllable && i < baseConsonant && classTable->isReph(chars[i]) && i+1 < nextSyllable && classTable->isVirama(chars[i+1])) { outMask |= rphfFeatureMask; outMask |= rephConsonantMask; output.setFeatures(i+1+inv_count,outMask); } if ( i == baseConsonant ) { outMask |= baseConsonantMask; } if ( classTable->isMatra(chars[i])) { outMask |= matraMask; if ( classTable->hasAboveBaseForm(chars[i])) { outMask |= aboveBasePosition; } else if ( classTable->hasBelowBaseForm(chars[i])) { outMask |= belowBasePosition; } } // Don't apply half form to virama that stands alone at the end of a syllable // to prevent half forms from forming when syllable ends with virama if ( classTable->isVirama(chars[i]) && (i+1 == nextSyllable) ) { outMask ^= halfFeatureMask; if ( classTable->isConsonant(chars[i-1]) ) { FeatureMask tmp = output.getFeatures(i-1+inv_count); tmp ^= halfFeatureMask; output.setFeatures(i-1+inv_count,tmp); } } if ( outMask != saveMask ) { output.setFeatures(i+inv_count,outMask); } } output.decomposeReorderMatras(classTable,beginSyllable,nextSyllable,inv_count); beginSyllable = nextSyllable; } return output.getOutputIndex(); }
void DpleInternal::init() { const_dim_ = getOption("const_dim"); pos_def_ = getOption("pos_def"); error_unstable_ = getOption("error_unstable"); eps_unstable_ = getOption("eps_unstable"); A_ = st_[Dple_STRUCT_A]; V_ = st_[Dple_STRUCT_V]; // Dimension sanity checks casadi_assert_message(A_.size()==V_.size(), "A and V arguments must be of same length, but got " << A_.size() << " and " << V_.size() << "."); K_ = A_.size(); for (int k=0;k<K_;++k) { casadi_assert_message(V_[k].issymmetric(), "V_i must be symmetric but got " << V_[k].dimString() << " for i = " << k << "."); casadi_assert_message(A_[k].size1()==V_[k].size1(), "First dimension of A (" << A_[k].size1() << ") must match dimension of symmetric V_i (" << V_[k].size1() << ")" << " for i = " << k << "."); } if (const_dim_) { int n = A_[0].size1(); for (int k=1;k<K_;++k) { casadi_assert_message(A_[k].size1()==n, "You have set const_dim option, but found " "an A_i with dimension ( " << A_[k].dimString() << " ) deviating from n = " << n << " at i = " << k << "."); } } // Allocate inputs ibuf_.resize(1+nrhs_); if (const_dim_) { input(0) = DMatrix::zeros(horzcat(A_)); } else { input(0) = DMatrix::zeros(diagcat(A_)); } for (int i=0;i<nrhs_;++i) { if (const_dim_) { input(1+i) = DMatrix::zeros(horzcat(V_)); } else { input(1+i) = DMatrix::zeros(diagcat(V_)); } } // Allocate outputs std::map<std::string, std::vector<Sparsity> > tmp; tmp["a"] = A_; tmp["v"] = V_; std::vector<Sparsity> P = LrDpleInternal::getSparsity(tmp); obuf_.resize(nrhs_); for (int i=0;i<nrhs_;++i) { if (const_dim_) { output(i) = DMatrix::zeros(horzcat(P)); } else { output(i) = DMatrix::zeros(diagcat(P)); } } FunctionInternal::init(); }
/* The main test function. */ int main(int argc, char * argv[]) { int ret; pthread_t ch; /* Initialize output */ output_init(); ret = pthread_mutex_lock(&mtx); if (ret != 0) { UNRESOLVED(ret, "Failed to lock mutex"); } ret = pthread_create(&ch, NULL, threaded, NULL); if (ret != 0) { UNRESOLVED(ret, "Failed to create a thread"); } /* Register the handlers */ ret = pthread_atfork(pre1, par1, chi1); if (ret != 0) { UNRESOLVED(ret, "Failed to register the atfork handlers"); } ret = pthread_atfork(pre2, par2, chi2); if (ret != 0) { UNRESOLVED(ret, "Failed to register the atfork handlers"); } ret = pthread_atfork(pre3, par3, chi3); if (ret != 0) { UNRESOLVED(ret, "Failed to register the atfork handlers"); } /* Let the child go on */ ret = pthread_mutex_unlock(&mtx); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock mutex"); } ret = pthread_join(ch, NULL); if (ret != 0) { UNRESOLVED(ret, "Failed to join the thread"); } /* Test passed */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; }
/* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf(_SC_REALTIME_SIGNALS); if (rts < 0L) { UNTESTED("This test needs the RTS extension"); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset(&sa.sa_mask); if (ret != 0) { UNRESOLVED(ret, "Failed to empty signal set"); } /* Install the signal handler for SIGALRM */ ret = sigaction(SIGNAL, &sa, 0); if (ret != 0) { UNRESOLVED(ret, "Failed to set signal handler"); } if (called) { FAILED("The signal handler has been called when no signal was raised"); } ret = raise(SIGNAL); if (ret != 0) { UNRESOLVED(ret, "Failed to raise SIGALRM"); } if (!called) { FAILED("the sa_handler was not called whereas SA_SIGINFO was not set"); } /* Test passed */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; }
void init_tokens( char **input_file ) /***********************************/ { int c; char *check; keyword_t i,j,k; keyword_t size; unsigned col; unsigned key_len; unsigned tok_len; FILE *fp; auto char keyword[80]; auto char class[80]; tokens[0] = ""; min_len = 80; max_len = 0; size = 1; for( ; *input_file != NULL; ++input_file ) { check = *input_file; if( check[0] == '/' || check[0] == '-' ) { if( tolower( check[1] ) == 'q' && check[2] == '\0' ) { flags.quiet = TRUE; continue; } if( tolower( check[1] ) == 'i' && check[2] == '\0' ) { flags.imperfect = TRUE; continue; } if( tolower( check[1] ) == 'm' && check[2] == '\0' ) { flags.mask_hash = TRUE; continue; } if( tolower( check[1] ) == 't' && check[2] == '\0' ) { flags.tiny_output = TRUE; continue; } if( tolower( check[1] ) == 'a' && check[2] == '\0' ) { flags.align = TRUE; continue; } } fp = fopen( *input_file, "r" ); if( fp == NULL ) { fatal( "cannot open keyword file" ); } for(;;) { c = fgetc( fp ); if( c == '#' ) { for(;;) { c = fgetc( fp ); if( ( c == EOF ) || ( c == '\n' ) ) { break; } } continue; } ungetc( c, fp ); if( fscanf( fp, "%s %s\n", keyword, class ) != 2 ) break; if( size > MAX_KEYWORDS ) { fatal( "too many keywords" ); } key_len = strlen( keyword ); if( key_len < min_len ) { min_len = key_len; } if( key_len > max_len ) { max_len = key_len; } if( key_len >= ( CHAR_BIT * sizeof( len_mask ) ) ) { fatal( "keyword is too long" ); } len_mask |= ( 1L << key_len ); position[size] = size; tokens[size] = strdup( keyword ); if( strcmp( class, "TC_A?" ) == 0 ) { sprintf( class, "TC_A%u", 3 - ( key_len & 0x03 ) ); } token_class[size] = strdup( class ); ++size; } if( !feof( fp ) ) { fatal( "invalid token file" ); } fclose( fp ); } num_keywords = size - 1; if( num_keywords == 0 ) { fatal( "no keywords" ); } qsort( &position[1], num_keywords, sizeof( int ), cmptok ); for( i = 1; i < num_keywords; ++i ) { for( j = i; j < num_keywords; ++j ) { if( position[j] == i ) { break; } } k = position[i]; swap( &tokens[k], &tokens[i] ); swap( &token_class[k], &token_class[i] ); position[j] = k; } col = 1; for( i = 1; i <= num_keywords; ++i ) { tok_len = strlen( tokens[i] ); col += tok_len + 1; if( col > 79 ) { output( "\n" ); col = tok_len + 2; } output( "%s ", tokens[i] ); } output( "\n%u keywords min_len=%u max_len=%u\n", num_keywords, min_len, max_len ); }
bool SerialInterface::getPackets (Telemetry * telemetry) { flush (); ROS_DEBUG ("SerialInterface::getPackets"); char cmd[16]; char spacket[1024]; unsigned char packet_type; unsigned short packet_crc; unsigned short packet_size; unsigned int i; bool result = false; ros::Time packetTime; ROS_DEBUG (" Requesting %04x %zd packets", (short) telemetry->requestPackets_.to_ulong (), telemetry->requestPackets_.count ()); sprintf (cmd, ">*>p%c", (short) telemetry->requestPackets_.to_ulong ()); output (cmd, 6); for (i = 0; i < telemetry->requestPackets_.count (); i++) { packetTime = ros::Time::now(); // Presumes that the AutoPilot is grabbing the data for each packet // immediately prior to each packet being sent, as opposed to gathering // all the data at once and then sending it all. Either way is a guess // unless we get some info from AscTec one way or the other.. bool read_result = getPacket (spacket, packet_type, packet_crc, packet_size); if (read_result) { ROS_DEBUG (" Read successful: type = %d, crc = %d", packet_type, packet_crc); if (packet_type == Telemetry::PD_LLSTATUS) { ROS_DEBUG (" Packet type is LL_STATUS"); memcpy (&telemetry->LL_STATUS_, spacket, packet_size); telemetry->timestamps_[RequestTypes::LL_STATUS] = packetTime; if (crc_valid (packet_crc, &telemetry->LL_STATUS_, sizeof (packet_size))) { result = true; } //telemetry->dumpLL_STATUS(); } else if (packet_type == Telemetry::PD_IMURAWDATA) { ROS_DEBUG (" Packet type is IMU_RAWDATA"); memcpy (&telemetry->IMU_RAWDATA_, spacket, packet_size); telemetry->timestamps_[RequestTypes::IMU_RAWDATA] = packetTime; if (crc_valid (packet_crc, &telemetry->IMU_RAWDATA_, packet_size)) { result = true; } //telemetry->dumpIMU_RAWDATA(); } else if (packet_type == Telemetry::PD_IMUCALCDATA) { ROS_DEBUG (" Packet type is IMU_CALCDATA"); memcpy (&telemetry->IMU_CALCDATA_, spacket, packet_size); telemetry->timestamps_[RequestTypes::IMU_CALCDATA] = packetTime; if (crc_valid (packet_crc, &telemetry->IMU_CALCDATA_, packet_size)) { result = true; } //telemetry->dumpIMU_CALCDATA(); } else if (packet_type == Telemetry::PD_RCDATA) { ROS_DEBUG (" Packet type is RC_DATA"); memcpy (&telemetry->RC_DATA_, spacket, packet_size); telemetry->timestamps_[RequestTypes::RC_DATA] = packetTime; if (crc_valid (packet_crc, &telemetry->RC_DATA_, packet_size)) { result = true; } //telemetry->dumpRC_DATA(); } else if (packet_type == Telemetry::PD_CTRLOUT) { ROS_DEBUG (" Packet type is CONTROLLER_OUTPUT"); memcpy (&telemetry->CONTROLLER_OUTPUT_, spacket, packet_size); telemetry->timestamps_[RequestTypes::CONTROLLER_OUTPUT] = packetTime; if (crc_valid (packet_crc, &telemetry->CONTROLLER_OUTPUT_, packet_size)) { result = true; } //telemetry->dumpCONTROLLER_OUTPUT(); } else if (packet_type == Telemetry::PD_GPSDATA) { ROS_DEBUG (" Packet type is GPS_DATA"); memcpy (&telemetry->GPS_DATA_, spacket, packet_size); telemetry->timestamps_[RequestTypes::GPS_DATA] = packetTime; if (crc_valid (packet_crc, &telemetry->GPS_DATA_, packet_size)) { result = true; } //telemetry->dumpGPS_DATA(); } else if (packet_type == Telemetry::PD_GPSDATAADVANCED) { ROS_DEBUG (" Packet type is GPS_DATA_ADVANCED"); memcpy (&telemetry->GPS_DATA_ADVANCED_, spacket, packet_size); telemetry->timestamps_[RequestTypes::GPS_DATA_ADVANCED] = packetTime; if (crc_valid (packet_crc, &telemetry->GPS_DATA_ADVANCED_, packet_size)) { result = true; } //telemetry->dumpGPS_DATA_ADVANCED(); } else { ROS_ERROR (" Packet type (%#2x) is UNKNOWN", packet_type); } } else { // failed read ROS_ERROR (" Read failed"); break; } } ioctl(dev_,FIONREAD,&i); if (i != 0) { ROS_ERROR (" Unexpected Data: Flushing receive buffer"); flush(); } return result; }
void QMatDraw::cleanUp(){ if ( inputMat() ) inputMat()->cvMat()->copyTo(*output()->cvMat()); emit outputChanged(); update(); }
void CompilerDirectivesAddDCmd::execute(DCmdSource source, TRAPS) { DirectivesParser::parse_from_file(_filename.value(), output()); }