void handle_block_() { for( iterator_ it = voxel_map_.begin(); it != voxel_map_.end(); ++it ) { voxel_map_t_::index_type i; i[0] = it->first[0] + 1; i[1] = it->first[1]; iterator_ right = voxel_map_.find( i ); i[0] = it->first[0]; i[1] = it->first[1] + 1; iterator_ up = voxel_map_.find( i ); i[0] = it->first[0] + 1; i[1] = it->first[1] + 1; iterator_ right_up = voxel_map_.find( i ); if( right_up == voxel_map_.end() ) { if( right != voxel_map_.end() && up != voxel_map_.end() ) { output_( it, up, right ); } } else { if( right != voxel_map_.end() ) { output_( it, right_up, right ); } if( up != voxel_map_.end() ) { output_( it, up, right_up ); } } } voxel_map_.clear(); }
/////////////////////////////////////////////////////////////////////////////// // test_dynamic void test_dynamic() { typedef std::vector<UChar>::const_iterator uchar_iterator; typedef basic_regex<uchar_iterator> uregex; typedef match_results<uchar_iterator> umatch; typedef regex_compiler<uchar_iterator, UChar_traits> uregex_compiler; std::string pattern_("b.*r"), str_("foobarboo"); std::vector<UChar> pattern(pattern_.begin(), pattern_.end()); std::vector<UChar> str(str_.begin(), str_.end()); UChar_traits tr; uregex_compiler compiler(tr); uregex urx = compiler.compile(pattern); umatch what; if(!regex_search(str, what, urx)) { BOOST_ERROR("regex_search on UChar failed"); } else { BOOST_CHECK_EQUAL(3, what.position()); BOOST_CHECK_EQUAL(3, what.length()); } // test for range-based regex_replace std::vector<UChar> output = regex_replace(str, urx, pattern_); std::string output_(output.begin(), output.end()); std::string expected("foob.*rboo"); BOOST_CHECK_EQUAL(output_, expected); }
void tick() { try { auto format_desc = video_format_desc(); boost::timer frame_timer; // Produce auto stage_frames = stage_(format_desc); // Mix auto mixed_frame = mixer_(std::move(stage_frames), format_desc); // Consume output_(std::move(mixed_frame), format_desc); graph_->set_value("tick-time", frame_timer.elapsed()*format_desc.fps*0.5); event_subject_ << monitor::event("profiler/time") % frame_timer.elapsed() % (1.0/format_desc_.fps) << monitor::event("format") % format_desc.name; } catch(...) { CASPAR_LOG_CURRENT_EXCEPTION(); } executor_.begin_invoke([=]{tick();}); }
void finish () { check (!empty(), "empty stack in finish()"); auto isarray = stack_.top().type == array; auto ch = isarray ? closebracket : closebrace; output_ ({&ch, 1}); stack_.pop(); }
void writeobjecttag (std::string const& tag) { #ifdef debug // make sure we haven't already seen this tag. auto& tags = stack_.top ().tags; check (tags.find (tag) == tags.end (), "already seen tag " + tag); tags.insert (tag); #endif stringoutput (tag); output_ ({&colon, 1}); }
void writeObjectTag (std::string const& tag) { #ifndef NDEBUG // Make sure we haven't already seen this tag. auto& tags = stack_.top ().tags; check (tags.find (tag) == tags.end (), "Already seen tag " + tag); tags.insert (tag); #endif stringOutput (tag); output_ ({&colon, 1}); }
void nextcollectionentry (collectiontype type, std::string const& message) { check (!empty() , "empty () in " + message); auto t = stack_.top ().type; if (t != type) { check (false, "not an " + ((type == array ? "array: " : "object: ") + message)); } if (stack_.top ().isfirst) stack_.top ().isfirst = false; else output_ ({&comma, 1}); }
void stringoutput (boost::string_ref const& bytes) { markstarted (); std::size_t position = 0, writtenuntil = 0; output_ ({"e, 1}); auto data = bytes.data(); for (; position < bytes.size(); ++position) { auto i = jsonspecialcharacterescape.find (data[position]); if (i != jsonspecialcharacterescape.end ()) { if (writtenuntil < position) { output_ ({data + writtenuntil, position - writtenuntil}); } output_ ({i->second, jsonescapelength}); writtenuntil = position + 1; }; } if (writtenuntil < position) output_ ({data + writtenuntil, position - writtenuntil}); output_ ({"e, 1}); }
void stringOutput (boost::beast::string_view const& bytes) { markStarted (); std::size_t position = 0, writtenUntil = 0; output_ ({"e, 1}); auto data = bytes.data(); for (; position < bytes.size(); ++position) { auto i = jsonSpecialCharacterEscape.find (data[position]); if (i != jsonSpecialCharacterEscape.end ()) { if (writtenUntil < position) { output_ ({data + writtenUntil, position - writtenUntil}); } output_ ({i->second, jsonEscapeLength}); writtenUntil = position + 1; }; } if (writtenUntil < position) output_ ({data + writtenUntil, position - writtenUntil}); output_ ({"e, 1}); }
/*---------------------------------------------------------------------------* * NAME: xml_parsing * DESC: Main xml parsing function *---------------------------------------------------------------------------*/ void xml_parsing(config *conf) { /* open the file using the libxml2 library */ debug(3, "xml parsing of the file: %s\n", conf->xml_filename); conf->doc = xmlParseFile(conf->xml_filename); if (conf->doc == NULL) { error_("Document not parsed successfully!\n"); return; } verbose_("[*] parsing the file: %s\n", conf->xml_filename); /* point on the root element of the tree */ conf->cur = xmlDocGetRootElement(conf->doc); if (conf->cur == NULL) { error_("Empty Document!\n"); xmlFreeDoc(conf->doc); return; } /* check if the format seems to be PDML: ie root = pdml */ debug(3,"name of the root: %s\n", conf->cur->name); if (xmlStrcmp(conf->cur->name, (const xmlChar *) "pdml")) { error_("Document NOT a PDML file!\n"); xmlFreeDoc(conf->doc); return; } /* start the autodafe's script language */ output_("/*--------------------------------------------------------------------------*\n"); output_(" * xml autodafe's parser v.%d.%d (c) Martin Vuagnoux - 2004-2006 *\n", MAJOR_VERSION, MINOR_VERSION); output_(" * auto-generated script using PDML (Packet Details Markup Language) source *\n"); output_(" *--------------------------------------------------------------------------*/\n\n"); /* the file is good, check for the packet entry (child) */ conf->cur = conf->cur->xmlChildrenNode; while (conf->cur != NULL) { if (!xmlStrcmp(conf->cur->name, (const xmlChar *) "packet")) { debug(3, "packet field found\n"); /* open the block */ output_(AD_F_BLOCK_BEGIN"(\"packet_%d\");\n", conf->packet_counter); /* parse the internal data of the packet block */ xml_parse_packet(conf); /* close the block */ output_(AD_F_BLOCK_END"(\"packet_%d\");\n", conf->packet_counter); /* client send/recv */ if ((conf->ip_pkt == conf->ip_client) && (conf->port_pkt == conf->port_client)) { debug(3, "check client\n"); if (conf->transport_type == 1) { if (conf->invert == 0) output_(AD_F_SEND"(\"packet_%d\"); /* tcp */\n\n", conf->packet_counter); else output_(AD_F_RECV"(\"packet_%d\"); /* tcp */\n\n", conf->packet_counter); } else if (conf->transport_type == 2) { if (conf->invert == 0) output_(AD_F_SEND"(\"packet_%d\"); /* udp */\n\n", conf->packet_counter); else output_(AD_F_RECV"(\"packet_%d\"); /* udp */\n\n", conf->packet_counter); } } /* server send/recv */ else if ((conf->ip_pkt == conf->ip_server) && (conf->port_pkt == conf->port_server)) { debug(3, "check server\n"); if (conf->transport_type == 1) { if (conf->invert == 1) output_(AD_F_SEND"(\"packet_%d\"); /* tcp */\n\n", conf->packet_counter); else output_(AD_F_RECV"(\"packet_%d\"); /* tcp */\n\n", conf->packet_counter); } else if (conf->transport_type == 2) { if (conf->invert == 1) output_(AD_F_SEND"(\"packet_%d\"); /* udp */\n\n", conf->packet_counter); else output_(AD_F_RECV"(\"packet_%d\"); /* udp */\n\n", conf->packet_counter); } } else { error_("too much different packets?! Check your Ethereal logs!\n"); error_("client: ip->%d, port->%d\n", conf->ip_client, conf->port_client); error_("server: ip->%d, port->%d\n", conf->ip_server, conf->port_server); error_("packet: ip->%d, port->%d\n", conf->ip_pkt, conf->port_pkt); exit(-1); } conf->packet_counter++; } conf->cur = conf->cur->next; } /* free */ xmlFreeDoc(conf->doc); }
int sort( const comma::command_line_options& options ) { input_t::map sorted_map; input_t default_input; std::vector< std::string > v = comma::split( stdin_csv.fields, ',' ); std::vector< std::string > order = options.exists("--order") ? comma::split( options.value< std::string >( "--order" ), ',' ) : v; std::vector< std::string > w (v.size()); bool unique = options.exists("--unique,-u"); std::string first_line; comma::csv::format f; if( stdin_csv.binary() ) { f = stdin_csv.format(); } else if( options.exists( "--format" ) ) { f = comma::csv::format( options.value< std::string >( "--format" ) ); } else { while( std::cin.good() && first_line.empty() ) { std::getline( std::cin, first_line ); } if( first_line.empty() ) { return 0; } f = comma::csv::impl::unstructured::guess_format( first_line, stdin_csv.delimiter ); if( verbose ) { std::cerr << "csv-sort: guessed format: " << f.string() << std::endl; } } for( std::size_t i = 0; i < order.size(); ++i ) // quick and dirty, wasteful, but who cares { if (order[i].empty()) continue; for( std::size_t k = 0; k < v.size(); ++k ) { if( v[k].empty() || v[k] != order[i] ) { if ( k + 1 == v.size()) { std::cerr << "csv-sort: order field name \"" << order[i] << "\" not found in input fields \"" << stdin_csv.fields << "\"" << std::endl; return 1; } continue; } std::string type = default_input.keys.append( f.offset( k ).type ); w[k] = "keys/" + type; ordering_t o; if ( type[0] == 's' ) { o.type = ordering_t::str_type; o.index = default_input.keys.strings.size() - 1; } else if ( type[0] == 'l' ) { o.type = ordering_t::long_type; o.index = default_input.keys.longs.size() - 1; } else if ( type[0] == 'd' ) { o.type = ordering_t::double_type; o.index = default_input.keys.doubles.size() - 1; } else if ( type[0] == 't' ) { o.type = ordering_t::time_type; o.index = default_input.keys.time.size() - 1; } else { std::cerr << "csv-sort: cannot sort on field " << v[k] << " of type \"" << type << "\"" << std::endl; return 1; } ordering.push_back(o); break; } } stdin_csv.fields = comma::join( w, ',' ); if ( verbose ) { std::cerr << "csv-sort: fields: " << stdin_csv.fields << std::endl; } comma::csv::input_stream< input_t > stdin_stream( std::cin, stdin_csv, default_input ); #ifdef WIN32 if( stdin_stream.is_binary() ) { _setmode( _fileno( stdout ), _O_BINARY ); } #endif if (!first_line.empty()) { input_t::map::mapped_type& d = sorted_map[ comma::csv::ascii< input_t >(stdin_csv,default_input).get(first_line) ]; d.push_back( first_line + "\n" ); } while( stdin_stream.ready() || ( std::cin.good() && !std::cin.eof() ) ) { const input_t* p = stdin_stream.read(); if( !p ) { break; } if( stdin_stream.is_binary() ) { input_t::map::mapped_type& d = sorted_map[ *p ]; if (unique && !d.empty()) continue; d.push_back( std::string() ); d.back().resize( stdin_csv.format().size() ); ::memcpy( &d.back()[0], stdin_stream.binary().last(), stdin_csv.format().size() ); } else { input_t::map::mapped_type& d = sorted_map[ *p ]; if (unique && !d.empty()) continue; d.push_back( comma::join( stdin_stream.ascii().last(), stdin_csv.delimiter ) + "\n" ); } } if( options.exists( "--reverse,-r" ) ) { output_( sorted_map.rbegin(), sorted_map.rend() ); } else { output_( sorted_map.begin(), sorted_map.end() ); } return 0; }
bool video_decoder::run() { run_ = true; AVFormatContext *pFormatCtx; int i, videoindex; AVCodecContext *pCodecCtx; AVCodec *pCodec; //char filepath[] = "src01_480x272_22.h265"; av_register_all(); avformat_network_init(); pFormatCtx = avformat_alloc_context(); if (avformat_open_input(&pFormatCtx, name_.c_str(), NULL, NULL) != 0){ printf("Couldn't open input stream.(无法打开输入流)\n"); return -1; } if (av_find_stream_info(pFormatCtx) < 0) { printf("Couldn't find stream information.(无法获取流信息)\n"); return -1; } videoindex = -1; for (i = 0; i < pFormatCtx->nb_streams; i++) if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { videoindex = i; break; } if (videoindex == -1) { printf("Didn't find a video stream.(没有找到视频流)\n"); return -1; } pCodecCtx = pFormatCtx->streams[videoindex]->codec; pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if (pCodec == NULL) { printf("Codec not found.(没有找到解码器)\n"); return -1; } if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { printf("Could not open codec.(无法打开解码器)\n"); return -1; } AVFrame *pFrame, *pFrameYUV; pFrame = avcodec_alloc_frame(); pFrameYUV = avcodec_alloc_frame(); uint8_t *out_buffer = (uint8_t *)av_malloc(avpicture_get_size(PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height)); avpicture_fill((AVPicture *)pFrameYUV, out_buffer, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height); //IYUV: Y + U + V (3 planes) //YV12: Y + V + U (3 planes) int ret, got_picture; AVPacket *packet = (AVPacket *)av_malloc(sizeof(AVPacket)); //printf("File Information(文件信息)---------------------\n"); av_dump_format(pFormatCtx, 0, name_.c_str(), 0); #if OUTPUT_YUV420P FILE *fp_yuv = fopen("output.yuv", "wb+"); #endif struct SwsContext *img_convert_ctx; img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL); while (av_read_frame(pFormatCtx, packet) >= 0) { if (packet->stream_index == videoindex) { ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet); if (ret < 0) { printf("Decode Error.(解码错误)\n"); return -1; } if (got_picture) { sws_scale(img_convert_ctx, (const uint8_t* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize); if (output_) { output_(pFrameYUV->data, pCodecCtx->width, pCodecCtx->height, pFrameYUV->linesize); } #if OUTPUT_YUV420P int y_size = pCodecCtx->width*pCodecCtx->height; fwrite(pFrameYUV->data[0], 1, y_size, fp_yuv); //Y fwrite(pFrameYUV->data[1], 1, y_size / 4, fp_yuv); //U fwrite(pFrameYUV->data[2], 1, y_size / 4, fp_yuv); //V #endif } } av_free_packet(packet); } sws_freeContext(img_convert_ctx); #if OUTPUT_YUV420P fclose(fp_yuv); #endif av_free(out_buffer); av_free(pFrameYUV); avcodec_close(pCodecCtx); avformat_close_input(&pFormatCtx); return 0; }
void output (boost::string_ref const& bytes) { markstarted (); output_ (bytes); }
void output (boost::beast::string_view const& bytes) { markStarted (); output_ (bytes); }