void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer) { GetBitContext gb; init_get_bits(&gb, buffer, FLAC_STREAMINFO_SIZE*8); skip_bits(&gb, 16); /* skip min blocksize */ s->max_blocksize = get_bits(&gb, 16); if (s->max_blocksize < FLAC_MIN_BLOCKSIZE) { av_log(avctx, AV_LOG_WARNING, "invalid max blocksize: %d\n", s->max_blocksize); s->max_blocksize = 16; } skip_bits(&gb, 24); /* skip min frame size */ s->max_framesize = get_bits_long(&gb, 24); s->samplerate = get_bits_long(&gb, 20); s->channels = get_bits(&gb, 3) + 1; s->bps = get_bits(&gb, 5) + 1; avctx->channels = s->channels; avctx->sample_rate = s->samplerate; avctx->bits_per_raw_sample = s->bps; s->samples = get_bits_long(&gb, 32) << 4; s->samples |= get_bits(&gb, 4); skip_bits_long(&gb, 64); /* md5 sum */ skip_bits_long(&gb, 64); /* md5 sum */ dump_headers(avctx, s); }
int main(int argc, char *argv[]) { int r=0; int dump=0; int option=0; FILE *inp=NULL; const char *in=NULL; const char *out=NULL; prog=basename(argv[0]); while((option=getopt(argc, argv, "i:ho:p?"))!=-1) { switch(option) { case 'i': in=optarg; break; case 'o': out=optarg; break; case 'p': dump=1; break; case 'h': case '?': default: usage(); return 1; } } if(open_fp(in, &inp, "rb", stdin)) return 1; if(dump) { r=dump_headers(inp); } else { FILE *outp=NULL; if(open_fp(out, &outp, "wb", stdout)) { fclose(inp); return 1; } r=main_work(inp, outp); if(outp) fclose(outp); } if(inp) fclose(inp); if(r) return 1; return 0; }
void wav_reader_c::parse_file() { int chunk_idx; if (m_in->read(&m_wheader.riff, sizeof(m_wheader.riff)) != sizeof(m_wheader.riff)) throw mtx::input::header_parsing_x(); scan_chunks(); if ((chunk_idx = find_chunk("fmt ")) == -1) throw mtx::input::header_parsing_x(); m_in->setFilePointer(m_chunks[chunk_idx].pos, seek_beginning); try { if (m_in->read(&m_wheader.format, sizeof(m_wheader.format)) != sizeof(m_wheader.format)) throw false; if (static_cast<uint64_t>(m_chunks[chunk_idx].len) >= sizeof(alWAVEFORMATEXTENSIBLE)) { alWAVEFORMATEXTENSIBLE format; if (m_in->read(&format, sizeof(format)) != sizeof(format)) throw false; memcpy(&m_wheader.common, &format, sizeof(m_wheader.common)); m_format_tag = get_uint16_le(&m_wheader.common.wFormatTag); if (0xfffe == m_format_tag) m_format_tag = get_uint32_le(&format.extension.guid.data1); } else if (m_in->read(&m_wheader.common, sizeof(m_wheader.common)) != sizeof(m_wheader.common)) throw false; else m_format_tag = get_uint16_le(&m_wheader.common.wFormatTag); } catch (...) { throw mtx::input::header_parsing_x(); } if ((m_cur_data_chunk_idx = find_chunk("data", 0, false)) == -1) throw mtx::input::header_parsing_x(); if (debugging_c::requested("wav_reader|wav_reader_headers")) dump_headers(); m_in->setFilePointer(m_chunks[m_cur_data_chunk_idx].pos + sizeof(struct chunk_struct), seek_beginning); m_remaining_bytes_in_current_data_chunk = m_chunks[m_cur_data_chunk_idx].len; }
static void output_to_json(nghttp2_hd_deflater *deflater, const uint8_t *buf, size_t len, size_t inputlen, nghttp2_nv *nva, size_t nvlen, int seq) { json_t *obj; char *hex = NULL; if(len > 0) { hex = malloc(len * 2); } obj = json_object(); json_object_set_new(obj, "seq", json_integer(seq)); json_object_set_new(obj, "input_length", json_integer(inputlen)); json_object_set_new(obj, "output_length", json_integer(len)); json_object_set_new(obj, "percentage_of_original_size", json_real((double)len / inputlen * 100)); to_hex(hex, buf, len); if(len == 0) { json_object_set_new(obj, "wire", json_string("")); } else { json_object_set_new(obj, "wire", json_pack("s#", hex, len * 2)); } json_object_set_new(obj, "headers", dump_headers(nva, nvlen)); if(seq == 0) { /* We only change the header table size only once at the beginning */ json_object_set_new(obj, "header_table_size", json_integer(config.table_size)); } if(config.dump_header_table) { json_object_set_new(obj, "header_table", dump_header_table(&deflater->ctx)); } json_dumpf(obj, stdout, JSON_PRESERVE_ORDER | JSON_INDENT(2)); printf("\n"); json_decref(obj); free(hex); }
static int decode_frame(FLACContext *s) { int i, ret; GetBitContext *gb = &s->gb; FLACFrameInfo fi; if ((ret = ff_flac_decode_frame_header(s->avctx, gb, &fi, 0)) < 0) { av_log(s->avctx, AV_LOG_ERROR, "invalid frame header\n"); return ret; } if (s->channels && fi.channels != s->channels && s->got_streaminfo) { s->channels = s->avctx->channels = fi.channels; ff_flac_set_channel_layout(s->avctx); ret = allocate_buffers(s); if (ret < 0) return ret; } s->channels = s->avctx->channels = fi.channels; if (!s->avctx->channel_layout) ff_flac_set_channel_layout(s->avctx); s->ch_mode = fi.ch_mode; if (!s->bps && !fi.bps) { av_log(s->avctx, AV_LOG_ERROR, "bps not found in STREAMINFO or frame header\n"); return AVERROR_INVALIDDATA; } if (!fi.bps) { fi.bps = s->bps; } else if (s->bps && fi.bps != s->bps) { av_log(s->avctx, AV_LOG_ERROR, "switching bps mid-stream is not " "supported\n"); return AVERROR_INVALIDDATA; } if (!s->bps) { s->bps = s->avctx->bits_per_raw_sample = fi.bps; flac_set_bps(s); } if (!s->max_blocksize) s->max_blocksize = FLAC_MAX_BLOCKSIZE; if (fi.blocksize > s->max_blocksize) { av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", fi.blocksize, s->max_blocksize); return AVERROR_INVALIDDATA; } s->blocksize = fi.blocksize; if (!s->samplerate && !fi.samplerate) { av_log(s->avctx, AV_LOG_ERROR, "sample rate not found in STREAMINFO" " or frame header\n"); return AVERROR_INVALIDDATA; } if (fi.samplerate == 0) fi.samplerate = s->samplerate; s->samplerate = s->avctx->sample_rate = fi.samplerate; if (!s->got_streaminfo) { ret = allocate_buffers(s); if (ret < 0) return ret; ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps); s->got_streaminfo = 1; dump_headers(s->avctx, (FLACStreaminfo *)s); } // dump_headers(s->avctx, (FLACStreaminfo *)s); /* subframes */ for (i = 0; i < s->channels; i++) { if ((ret = decode_subframe(s, i)) < 0) return ret; } align_get_bits(gb); /* frame footer */ skip_bits(gb, 16); /* data crc */ return 0; }
static void perform(void) { int rc; time_t last_report; last_report = time(NULL) / REPORT_INTERVAL; // Initialise database db_init(conf.db_server, conf.db_user, conf.db_pass, conf.db_name); log_message(""); log_message(""); log_message("trustdb started."); create_database(); while(run) { stats[ConnectAttempt]++; _log(GENERAL, "Connecting socket ..."); rc=stomp_connect("datafeeds.networkrail.co.uk", 61618); if(rc) { sprintf(zs,"Failed to connect. Error %d %s", rc, report_error(rc)); _log(CRITICAL, zs); } else { _log(GENERAL, "Connected."); holdoff = 0; { strcpy(headers, "CONNECT\n"); strcat(headers, "login:"******"\npasscode:"); strcat(headers, conf.nr_pass); strcat(headers, "\n"); if(debug) { sprintf(zs, "client-id:%s-trustdb-debug\n", conf.nr_user); strcat(headers, zs); } else { sprintf(zs, "client-id:%s-trustdb-%s\n", conf.nr_user, abbreviated_host_id()); strcat(headers, zs); } strcat(headers, "heart-beat:0,20000\n"); strcat(headers, "\n"); rc = stomp_tx(headers); } if(rc) { sprintf(zs,"Failed to transmit CONNECT message. Error %d %s", rc, report_error(rc)); _log(CRITICAL, zs); } else { _log(GENERAL, "Sent CONNECT message. Reading response."); rc = stomp_rx(headers, sizeof(headers), body, sizeof(body)); if(rc) { sprintf(zs,"Failed to receive. Error %d %s", rc, report_error(rc)); _log(CRITICAL, zs); } else { sprintf(zs, "Response: Body=\"%s\", Headers:", body); _log(GENERAL, zs); dump_headers(); { strcpy(headers, "SUBSCRIBE\n"); // Headers strcat(headers, "destination:/topic/TRAIN_MVT_ALL_TOC\n"); if(debug) { sprintf(zs, "activemq.subscriptionName:%s-trustdb-debug\n", conf.nr_user); strcat(headers, zs); } else { sprintf(zs, "activemq.subscriptionName:%s-trustdb-%s\n", conf.nr_user, abbreviated_host_id()); strcat(headers, zs); } strcat(headers, "id:1\n"); strcat(headers, "ack:client\n"); strcat(headers, "\n"); rc = stomp_tx(headers); } if(rc) { sprintf(zs,"Failed to transmit SUBSCRIBE message. Error %d %s", rc, report_error(rc)); _log(CRITICAL, zs); } else { _log(GENERAL, "Sent SUBSCRIBE message. Waiting for messages ..."); int run_receive = 1; while(run && run_receive) { time_t waited = time(NULL); if( waited / REPORT_INTERVAL != last_report) { report_stats(); last_report = waited / REPORT_INTERVAL; } rc = stomp_rx(headers, sizeof(headers), body, sizeof(body)); run_receive = (rc == 0); if(rc && run) { // Don't report if the error is due to an interrupt sprintf(zs, "Error receiving frame: %d %s", rc, report_error(rc)); _log(MAJOR, zs); } if(run_receive) { time_t now = time(NULL); waited = now - waited; if(waited > 1) { last_idle = now; if(high_load) _log(MINOR, "Ceasing task shedding."); high_load = false; } else { if(!high_load && now - last_idle > 64) { // Enter high load high_load = true; _log(MINOR, "High load detected. Shedding tasks."); } } if(debug || waited < 2) { sprintf(zs, "Message receive wait time was %ld seconds.", waited); _log(MINOR, zs); } char message_id[256]; message_id[0] = '\0'; stats[Bytes] += strlen(headers); stats[Bytes] += strlen(body); if(!strstr(headers, "MESSAGE")) { _log(MAJOR, "Frame received is not a MESSAGE:"); dump_headers(); run_receive = false; stats[NotMessage]++; } // Find message ID char * message_id_header = strstr(headers, "message-id:"); if(run_receive) { if(message_id_header) { size_t i = 0; message_id_header += 11; while(*message_id_header != '\n') message_id[i++] = *message_id_header++; message_id[i++] = '\0'; } else { _log(MAJOR, "No message ID found:"); dump_headers(); } } //sprintf(zs, "Message id = \"%s\"", message_id); //_log(GENERAL, zs); // Process the message if(run_receive) process_message(body); // Send ACK if(run_receive && message_id[0]) { strcpy(headers, "ACK\n"); strcat(headers, "subscription:1\n"); strcat(headers, "message-id:"); strcat(headers, message_id); strcat(headers, "\n\n"); rc = stomp_tx(headers); if(rc) { sprintf(zs,"Failed to transmit ACK message. Error %d %s", rc, report_error(rc)); _log(CRITICAL, zs); run_receive = false; } else { //_log(GENERAL, "Ack sent OK."); } //sprintf(zs, "%d messages, total size %ld bytes.", count, size); //_log(GENERAL, zs); } } } // while(run && run_receive) } } } } strcpy(headers, "DISCONNECT\n\n"); rc = stomp_tx(headers); if(rc) { sprintf(zs, "Failed to send DISCONNECT: Error %d %s", rc, report_error(rc)); _log(GENERAL, zs); } else _log(GENERAL, "Sent DISCONNECT."); _log(GENERAL, "Disconnecting socket ..."); rc = stomp_disconnect(); if(rc) { sprintf(zs, "Failed to disconnect: Error %d %s", rc, report_error(rc)); _log(GENERAL, zs); } else _log(GENERAL, "Disconnected."); { word i; if(holdoff < 128) holdoff += 16; else holdoff = 128; for(i = 0; i < holdoff && run; i++) sleep(1); } } // while(run) db_disconnect(); if(interrupt) { _log(CRITICAL, "Terminating due to interrupt."); } report_stats(); }