static void discover_descriptor_cb(guint8 status, const guint8 *pdu, guint16 len, gpointer user_data) { struct scan *scan = user_data; struct att_data_list *list; uint8_t *ptr; uint16_t uuid16, handle; uint8_t value[2]; uint8_t format; list = dec_find_info_resp(pdu, len, &format); if (list == NULL) return; if (format != ATT_FIND_INFO_RESP_FMT_16BIT) goto done; ptr = list->data[0]; handle = get_le16(ptr); uuid16 = get_le16(&ptr[2]); if (uuid16 != GATT_CLIENT_CHARAC_CFG_UUID) goto done; put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value); gatt_write_char(scan->attrib, handle, value, sizeof(value), ccc_written_cb, user_data); done: att_data_list_free(list); }
static int read_header(AVFormatContext *s, AVFormatParameters *ap) { MviDemuxContext *mvi = s->priv_data; ByteIOContext *pb = s->pb; AVStream *ast, *vst; unsigned int version, frames_count, msecs_per_frame, player_version; ast = av_new_stream(s, 0); if (!ast) return AVERROR(ENOMEM); vst = av_new_stream(s, 0); if (!vst) return AVERROR(ENOMEM); vst->codec->extradata_size = 2; vst->codec->extradata = av_mallocz(2 + FF_INPUT_BUFFER_PADDING_SIZE); version = get_byte(pb); vst->codec->extradata[0] = get_byte(pb); vst->codec->extradata[1] = get_byte(pb); frames_count = get_le32(pb); msecs_per_frame = get_le32(pb); vst->codec->width = get_le16(pb); vst->codec->height = get_le16(pb); get_byte(pb); ast->codec->sample_rate = get_le16(pb); mvi->audio_data_size = get_le32(pb); get_byte(pb); player_version = get_le32(pb); get_le16(pb); get_byte(pb); if (frames_count == 0 || mvi->audio_data_size == 0) return AVERROR_INVALIDDATA; if (version != 7 || player_version > 213) { av_log(s, AV_LOG_ERROR, "unhandled version (%d,%d)\n", version, player_version); return AVERROR_INVALIDDATA; } av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); ast->codec->codec_type = CODEC_TYPE_AUDIO; ast->codec->codec_id = CODEC_ID_PCM_U8; ast->codec->channels = 1; ast->codec->bits_per_coded_sample = 8; ast->codec->bit_rate = ast->codec->sample_rate * 8; av_set_pts_info(vst, 64, msecs_per_frame, 1000000); vst->codec->codec_type = CODEC_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_MOTIONPIXELS; mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? get_le16 : get_le24; mvi->audio_frame_size = ((uint64_t)mvi->audio_data_size << MVI_FRAC_BITS) / frames_count; mvi->audio_size_counter = (ast->codec->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size; mvi->audio_size_left = mvi->audio_data_size; return 0; }
blargg_err_t Sap_Emu::start_track_( int track ) { RETURN_ERR( Classic_Emu::start_track_( track ) ); core.setup_ram(); // Copy file data to RAM byte const* in = info_.rom_data; while ( file_end - in >= 5 ) { int start = get_le16( in ); int end = get_le16( in + 2 ); //dprintf( "Block $%04X-$%04X\n", start, end ); in += 4; int len = end - start + 1; if ( (unsigned) len > (unsigned) (file_end - in) ) { set_warning( "Invalid file data block" ); break; } memcpy( core.ram() + start, in, len ); in += len; if ( file_end - in >= 2 && in [0] == 0xFF && in [1] == 0xFF ) in += 2; } return core.start_track( track, info_ ); }
void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size) { int id; id = get_le16(pb); codec->codec_type = CODEC_TYPE_AUDIO; codec->codec_tag = id; codec->channels = get_le16(pb); codec->sample_rate = get_le32(pb); codec->bit_rate = get_le32(pb) * 8; codec->block_align = get_le16(pb); if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */ codec->bits_per_sample = 8; }else codec->bits_per_sample = get_le16(pb); codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample); if (size > 16) { /* We're obviously dealing with WAVEFORMATEX */ codec->extradata_size = get_le16(pb); if (codec->extradata_size > 0) { if (codec->extradata_size > size - 18) codec->extradata_size = size - 18; codec->extradata = malloc(codec->extradata_size); get_buffer(pb, codec->extradata, codec->extradata_size); } else codec->extradata_size = 0; /* It is possible for the chunk to contain garbage at the end */ if (size - codec->extradata_size - 18 > 0) url_fskip(pb, size - codec->extradata_size - 18); } }
/** * HCI write suggested default data length command. * * This command is used by the host to change the initial max tx octets/time * for all connections. Note that if the controller does not support the * requested times no error is returned; the controller simply ignores the * request (but remembers what the host requested for the read suggested * default data length command). The spec allows for the controller to * disregard the host. * * @param rspbuf Pointer to response buffer * @param rsplen Length of response buffer * * @return int BLE error code */ static int ble_ll_hci_le_wr_sugg_data_len(uint8_t *cmdbuf) { int rc; uint16_t tx_oct; uint16_t tx_time; /* Get suggested octets and time */ tx_oct = get_le16(cmdbuf); tx_time = get_le16(cmdbuf + 2); /* If valid, write into suggested and change connection initial times */ if (ble_ll_chk_txrx_octets(tx_oct) && ble_ll_chk_txrx_time(tx_time)) { g_ble_ll_conn_params.sugg_tx_octets = (uint8_t)tx_oct; g_ble_ll_conn_params.sugg_tx_time = tx_time; if ((tx_time <= g_ble_ll_conn_params.supp_max_tx_time) && (tx_oct <= g_ble_ll_conn_params.supp_max_tx_octets)) { g_ble_ll_conn_params.conn_init_max_tx_octets = tx_oct; g_ble_ll_conn_params.conn_init_max_tx_time = tx_time; } rc = BLE_ERR_SUCCESS; } else { rc = BLE_ERR_INV_HCI_CMD_PARMS; } return rc; }
bool gatt_db_attribute_get_incl_data(const struct gatt_db_attribute *attrib, uint16_t *handle, uint16_t *start_handle, uint16_t *end_handle) { if (!attrib) return false; if (bt_uuid_cmp(&included_service_uuid, &attrib->uuid)) return false; /* * Include definition value: * 2 octets: start handle of included service * 2 octets: end handle of included service * optional 2 octets: 16-bit Bluetooth UUID */ if (!attrib->value || attrib->value_len < 4 || attrib->value_len > 6) return false; /* * We only return the handles since the UUID can be easily obtained * from the corresponding attribute. */ if (handle) *handle = attrib->handle; if (start_handle) *start_handle = get_le16(attrib->value); if (end_handle) *end_handle = get_le16(attrib->value + 2); return true; }
static void prep_write_complete_cb(struct gatt_db_attribute *attr, int err, void *user_data) { struct prep_write_complete_data *pwcd = user_data; uint16_t handle = 0; uint16_t offset; handle = get_le16(pwcd->pdu); if (err) { bt_att_send_error_rsp(pwcd->server->att, BT_ATT_OP_PREP_WRITE_REQ, handle, err); free(pwcd->pdu); free(pwcd); return; } offset = get_le16(pwcd->pdu + 2); if (!store_prep_data(pwcd->server, handle, offset, pwcd->length - 4, &((uint8_t *) pwcd->pdu)[4])) bt_att_send_error_rsp(pwcd->server->att, BT_ATT_OP_PREP_WRITE_RSP, handle, BT_ATT_ERROR_INSUFFICIENT_RESOURCES); bt_att_send(pwcd->server->att, BT_ATT_OP_PREP_WRITE_RSP, pwcd->pdu, pwcd->length, NULL, NULL, NULL); free(pwcd->pdu); free(pwcd); }
uint16_t dec_prep_write_resp(const uint8_t *pdu, size_t len, uint16_t *handle, uint16_t *offset, uint8_t *value, size_t *vlen) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle) + sizeof(*offset); if (pdu == NULL) return 0; if (handle == NULL || offset == NULL || value == NULL || vlen == NULL) return 0; if (len < min_len) return 0; if (pdu[0] != ATT_OP_PREP_WRITE_REQ) return 0; *handle = get_le16(&pdu[1]); *offset = get_le16(&pdu[3]); *vlen = len - min_len; if (*vlen > 0) memcpy(value, pdu + min_len, *vlen); return len; }
/* We could be given one of the three possible structures here: * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure * is an expansion of the previous one with the fields added * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself * an openended structure. */ void WMA_File::getWavHeader(int size) { if ( wmaProperties ) { get_le16(this); // id wmaProperties->m_channels = get_le16(this); wmaProperties->m_sampleRate = get_le32(this); wmaProperties->m_bitrate = (get_le32(this) * 8) / 1000; // in kb/s /*codec->block_align = */get_le16(this); } else { Seek(2 + 2 + 4 + 4 + 2, SJ_SEEK_CUR); } if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */ // codec->bits_per_sample = 8; } else /* codec->bits_per_sample = */ get_le16(this); if (size > 16) { /* We're obviously dealing with WAVEFORMATEX */ unsigned int extradata_size = get_le16(this); if (extradata_size > 0) { if (extradata_size > (unsigned int)size - 18) extradata_size = size - 18; Seek(extradata_size, SJ_SEEK_CUR); // Just skip the extra data } else { extradata_size = 0; } /* It is possible for the chunk to contain garbage at the end */ if (size - extradata_size - 18 > 0) Seek(size - extradata_size - 18, SJ_SEEK_CUR); } }
uint16_t dec_read_blob_req(const uint8_t *pdu, size_t len, uint16_t *handle, uint16_t *offset) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle) + sizeof(*offset); if (pdu == NULL) return 0; if (handle == NULL) return 0; if (offset == NULL) return 0; if (len < min_len) return 0; if (pdu[0] != ATT_OP_READ_BLOB_REQ) return 0; *handle = get_le16(&pdu[1]); *offset = get_le16(&pdu[3]); return min_len; }
GSList *dec_find_by_type_resp(const uint8_t *pdu, size_t len) { struct att_range *range; GSList *matches; off_t offset; /* PDU should contain at least: * - Attribute Opcode (1 octet) * - Handles Information List (at least one entry): * - Found Attribute Handle (2 octets) * - Group End Handle (2 octets) */ if (pdu == NULL || len < 5) return NULL; if (pdu[0] != ATT_OP_FIND_BY_TYPE_RESP) return NULL; /* Reject incomplete Handles Information List */ if ((len - 1) % 4) return NULL; for (offset = 1, matches = NULL; len >= (offset + sizeof(uint16_t) * 2); offset += sizeof(uint16_t) * 2) { range = g_new0(struct att_range, 1); range->start = get_le16(&pdu[offset]); range->end = get_le16(&pdu[offset + 2]); matches = g_slist_append(matches, range); } return matches; }
uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start, uint16_t *end, bt_uuid_t *uuid) { const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end); uint8_t type; if (pdu == NULL) return 0; if (start == NULL || end == NULL || uuid == NULL) return 0; if (len == (min_len + 2)) type = BT_UUID16; else if (len == (min_len + 16)) type = BT_UUID128; else return 0; if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ) return 0; *start = get_le16(&pdu[1]); *end = get_le16(&pdu[3]); get_uuid(type, &pdu[5], uuid); return len; }
static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len, gpointer user_data) { struct characteristic *ch = user_data; uint8_t value[PNP_ID_SIZE]; ssize_t vlen; if (status != 0) { error("Error reading PNP_ID value: %s", att_ecode2str(status)); return; } vlen = dec_read_resp(pdu, len, value, sizeof(value)); if (vlen < 0) { error("Error reading PNP_ID: Protocol error"); return; } if (vlen < 7) { error("Error reading PNP_ID: Invalid pdu length received"); return; } btd_device_set_pnpid(ch->d->dev, value[0], get_le16(&value[1]), get_le16(&value[3]), get_le16(&value[5])); }
void PackSys::patchLoader(OutputFile *fo, upx_byte *loader, int lsize, unsigned calls) { const int e_len = getLoaderSectionStart("SYSCUTPO"); const int d_len = lsize - e_len; assert(e_len > 0 && e_len < 128); assert(d_len > 0 && d_len < 256); if (ph.u_len + d_len + ph.overlap_overhead > 0xfffe) throwNotCompressible(); // use some fields of the original file linker->defineSymbol("attribute", get_le16(ibuf + 4)); linker->defineSymbol("interrupt", get_le16(ibuf + 8)); unsigned copy_to = ph.u_len + d_len + ph.overlap_overhead; linker->defineSymbol("calltrick_calls", calls); linker->defineSymbol("copy_source", ph.c_len + lsize - 1); linker->defineSymbol("copy_destination", copy_to); linker->defineSymbol("neg_e_len", 0 - e_len); linker->defineSymbol("NRV2B160", ph.u_len + ph.overlap_overhead + 1); linker->defineSymbol("original_strategy", get_le16(ibuf + 6)); relocateLoader(); loader = getLoader(); patchPackHeader(loader,e_len); // write loader + compressed file fo->write(loader,e_len); // entry fo->write(obuf,ph.c_len); fo->write(loader+e_len,d_len); // decompressor }
static int read_header(AVFormatContext *s, AVFormatParameters *ap) { AVStream *st; AVRational time_base; get_le32(s->pb); // DKIF get_le16(s->pb); // version get_le16(s->pb); // header size st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_tag = get_le32(s->pb); st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag); st->codec->width = get_le16(s->pb); st->codec->height = get_le16(s->pb); time_base.den = get_le32(s->pb); time_base.num = get_le32(s->pb); st->duration = get_le64(s->pb); st->need_parsing = AVSTREAM_PARSE_HEADERS; if (!time_base.den || !time_base.num) { av_log(s, AV_LOG_ERROR, "Invalid frame rate\n"); return AVERROR_INVALIDDATA; } av_set_pts_info(st, 64, time_base.num, time_base.den); return 0; }
static int xa_read_header(AVFormatContext *s, AVFormatParameters *ap) { MaxisXADemuxContext *xa = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st; /*Set up the XA Audio Decoder*/ st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_EA_MAXIS_XA; url_fskip(pb, 4); /* Skip the XA ID */ xa->out_size = get_le32(pb); url_fskip(pb, 2); /* Skip the tag */ st->codec->channels = get_le16(pb); st->codec->sample_rate = get_le32(pb); /* Value in file is average byte rate*/ st->codec->bit_rate = get_le32(pb) * 8; st->codec->block_align = get_le16(pb); st->codec->bits_per_coded_sample = get_le16(pb); av_set_pts_info(st, 64, 1, st->codec->sample_rate); return 0; }
// http://www.artificis.hu/files/texts/ingenient.txt static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size, w, h, unk1, unk2; if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G')) return AVERROR(EIO); // FIXME size = get_le32(s->pb); w = get_le16(s->pb); h = get_le16(s->pb); url_fskip(s->pb, 8); // zero + size (padded?) url_fskip(s->pb, 2); unk1 = get_le16(s->pb); unk2 = get_le16(s->pb); url_fskip(s->pb, 22); // ASCII timestamp av_log(s, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n", size, w, h, unk1, unk2); if (av_new_packet(pkt, size) < 0) return AVERROR(ENOMEM); pkt->pos = url_ftell(s->pb); pkt->stream_index = 0; ret = get_buffer(s->pb, pkt->data, size); if (ret < 0) { av_free_packet(pkt); return ret; } pkt->size = ret; return ret; }
static int ble_hs_hci_evt_num_completed_pkts(uint8_t event_code, uint8_t *data, int len) { uint16_t num_pkts; uint16_t handle; uint8_t num_handles; int off; int i; if (len < BLE_HCI_EVENT_HDR_LEN + BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN) { return BLE_HS_ECONTROLLER; } off = BLE_HCI_EVENT_HDR_LEN; num_handles = data[off]; if (len < BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN + num_handles * BLE_HCI_EVENT_NUM_COMP_PKTS_ENT_LEN) { return BLE_HS_ECONTROLLER; } off++; for (i = 0; i < num_handles; i++) { handle = get_le16(data + off + 2 * i); num_pkts = get_le16(data + off + 2 * num_handles + 2 * i); /* XXX: Do something with these values. */ (void)handle; (void)num_pkts; } return 0; }
static void read_verbose_version_info_rsp(const void *data, uint8_t size) { uint8_t status = get_u8(data); uint8_t chip_id = get_u8(data + 1); uint8_t target_id = get_u8(data + 2); uint16_t build_base = get_le16(data + 3); uint16_t build_num = get_le16(data + 5); const char *str; print_status(status); print_field("Chip ID: %u (0x%2.2x)", chip_id, chip_id); switch (target_id) { case 254: str = "Invalid"; break; case 255: str = "Undefined"; break; default: str = "Reserved"; break; } print_field("Build target: %s (%u)", str, target_id); print_field("Build baseline: %u (0x%4.4x)", build_base, build_base); print_field("Build number: %u (0x%4.4x)", build_num, build_num); }
uint16_t dec_find_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start, uint16_t *end, bt_uuid_t *uuid, uint8_t *value, size_t *vlen) { if (pdu == NULL) return 0; if (len < 7) return 0; /* Attribute Opcode (1 octet) */ if (pdu[0] != ATT_OP_FIND_BY_TYPE_REQ) return 0; /* First requested handle number (2 octets) */ *start = get_le16(&pdu[1]); /* Last requested handle number (2 octets) */ *end = get_le16(&pdu[3]); /* 16-bit UUID to find (2 octets) */ bt_uuid16_create(uuid, get_le16(&pdu[5])); /* Attribute value to find */ *vlen = len - 7; if (*vlen > 0) memcpy(value, pdu + 7, *vlen); return len; }
static int seq_parse_frame_data(SeqDemuxContext *seq, ByteIOContext *pb) { unsigned int offset_table[4], buffer_num[4]; TiertexSeqFrameBuffer *seq_buffer; int i, e, err; seq->current_frame_offs += SEQ_FRAME_SIZE; url_fseek(pb, seq->current_frame_offs, SEEK_SET); /* sound data */ seq->current_audio_data_offs = get_le16(pb); if (seq->current_audio_data_offs != 0) { seq->current_audio_data_size = SEQ_AUDIO_BUFFER_SIZE * 2; } else { seq->current_audio_data_size = 0; } /* palette data */ seq->current_pal_data_offs = get_le16(pb); if (seq->current_pal_data_offs != 0) { seq->current_pal_data_size = 768; } else { seq->current_pal_data_size = 0; } /* video data */ for (i = 0; i < 4; i++) buffer_num[i] = get_byte(pb); for (i = 0; i < 4; i++) offset_table[i] = get_le16(pb); for (i = 0; i < 3; i++) { if (offset_table[i] != 0) { for (e = i + 1; e < 4 && offset_table[e] == 0; e++); err = seq_fill_buffer(seq, pb, buffer_num[1 + i], offset_table[i], offset_table[e] - offset_table[i]); if (err != 0) return err; } } if (buffer_num[0] != 255) { if (buffer_num[0] >= SEQ_NUM_FRAME_BUFFERS) return AVERROR_INVALIDDATA; seq_buffer = &seq->frame_buffers[buffer_num[0]]; seq->current_video_data_size = seq_buffer->fill_size; seq->current_video_data_ptr = seq_buffer->data; seq_buffer->fill_size = 0; } else { seq->current_video_data_size = 0; seq->current_video_data_ptr = 0; } return 0; }
static void read_vid_pid_rsp(const void *data, uint8_t size) { uint8_t status = get_u8(data); uint16_t vid = get_le16(data + 1); uint16_t pid = get_le16(data + 3); print_status(status); print_field("Product: %4.4x:%4.4x", vid, pid); }
static void prep_write_cb(uint8_t opcode, const void *pdu, uint16_t length, void *user_data) { struct bt_gatt_server *server = user_data; uint16_t handle = 0; uint16_t offset; struct gatt_db_attribute *attr; struct prep_write_complete_data *pwcd; uint8_t ecode, status; if (length < 4) { ecode = BT_ATT_ERROR_INVALID_PDU; goto error; } if (queue_length(server->prep_queue) >= server->max_prep_queue_len) { ecode = BT_ATT_ERROR_PREPARE_QUEUE_FULL; goto error; } handle = get_le16(pdu); offset = get_le16(pdu + 2); attr = gatt_db_get_attribute(server->db, handle); if (!attr) { ecode = BT_ATT_ERROR_INVALID_HANDLE; goto error; } util_debug(server->debug_callback, server->debug_data, "Prep Write Req - handle: 0x%04x", handle); ecode = check_permissions(server, attr, BT_ATT_PERM_WRITE | BT_ATT_PERM_WRITE_AUTHEN | BT_ATT_PERM_WRITE_ENCRYPT); if (ecode) goto error; pwcd = new0(struct prep_write_complete_data, 1); pwcd->pdu = malloc(length); memcpy(pwcd->pdu, pdu, length); pwcd->length = length; pwcd->server = server; status = gatt_db_attribute_write(attr, offset, NULL, 0, BT_ATT_OP_PREP_WRITE_REQ, server->att, prep_write_complete_cb, pwcd); if (status) return; ecode = BT_ATT_ERROR_UNLIKELY; error: bt_att_send_error_rsp(server->att, opcode, handle, ecode); }
static void get_guid(WMA_File *f, TAGGER_GUID *g) { int i; g->v1 = get_le32(f); g->v2 = get_le16(f); g->v3 = get_le16(f); for(i=0; i<8; i++) g->v4[i] = get_byte(f); }
static int ble_hs_hci_evt_le_conn_complete(uint8_t subevent, uint8_t *data, int len) { struct hci_le_conn_complete evt; int extended_offset = 0; int rc; if (len < BLE_HCI_LE_CONN_COMPLETE_LEN) { return BLE_HS_ECONTROLLER; } /* this code processes two different events that are really similar */ if ((subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) && ( len < BLE_HCI_LE_ENH_CONN_COMPLETE_LEN)) { return BLE_HS_ECONTROLLER; } evt.subevent_code = data[0]; evt.status = data[1]; evt.connection_handle = get_le16(data + 2); evt.role = data[4]; evt.peer_addr_type = data[5]; memcpy(evt.peer_addr, data + 6, BLE_DEV_ADDR_LEN); /* enhanced connection event has the same information with these * extra fields stuffed into the middle */ if (subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) { memcpy(evt.local_rpa, data + 12, BLE_DEV_ADDR_LEN); memcpy(evt.peer_rpa, data + 18, BLE_DEV_ADDR_LEN); extended_offset = 12; } else { memset(evt.local_rpa, 0, BLE_DEV_ADDR_LEN); memset(evt.peer_rpa, 0, BLE_DEV_ADDR_LEN); } evt.conn_itvl = get_le16(data + 12 + extended_offset); evt.conn_latency = get_le16(data + 14 + extended_offset); evt.supervision_timeout = get_le16(data + 16 + extended_offset); evt.master_clk_acc = data[18 + extended_offset]; if (evt.status == 0) { if (evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER && evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) { return BLE_HS_EBADDATA; } } rc = ble_gap_rx_conn_complete(&evt); if (rc != 0) { return rc; } return 0; }
int CEASpliterFilter::process_video_header_mdec() { EaDemuxContext *ea = (EaDemuxContext *)m_pea; url_fskip(pb, 4); ea->width = get_le16(pb); ea->height = get_le16(pb); ea->time_base.num = 1; ea->time_base.den = 15; ea->video_codec = CODEC_ID_MDEC; return 1; }
static int process_video_header_mdec(AVFormatContext *s) { EaDemuxContext *ea = s->priv_data; ByteIOContext *pb = s->pb; url_fskip(pb, 4); ea->width = get_le16(pb); ea->height = get_le16(pb); ea->time_base = (AVRational){1,15}; ea->video_codec = CODEC_ID_MDEC; return 1; }
static int vid_read_packet(AVFormatContext *s, AVPacket *pkt) { BVID_DemuxContext *vid = s->priv_data; ByteIOContext *pb = s->pb; unsigned char block_type; int audio_length; int ret_value; if(vid->is_finished || url_feof(pb)) return AVERROR(EIO); block_type = get_byte(pb); switch(block_type) { case PALETTE_BLOCK: url_fseek(pb, -1, SEEK_CUR); // include block type ret_value = av_get_packet(pb, pkt, 3 * 256 + 1); if(ret_value != 3 * 256 + 1) { av_free_packet(pkt); return AVERROR(EIO); } pkt->stream_index = 0; return ret_value; case FIRST_AUDIO_BLOCK: get_le16(pb); // soundblaster DAC used for sample rate, as on specification page (link above) s->streams[1]->codec->sample_rate = 1000000 / (256 - get_byte(pb)); s->streams[1]->codec->bit_rate = s->streams[1]->codec->channels * s->streams[1]->codec->sample_rate * s->streams[1]->codec->bits_per_sample; case AUDIO_BLOCK: audio_length = get_le16(pb); ret_value = av_get_packet(pb, pkt, audio_length); pkt->stream_index = 1; return ret_value != audio_length ? AVERROR(EIO) : ret_value; case VIDEO_P_FRAME: case VIDEO_YOFF_P_FRAME: case VIDEO_I_FRAME: return read_frame(vid, pb, pkt, block_type, s, s->streams[0]->codec->width * s->streams[0]->codec->height); case EOF_BLOCK: if(vid->nframes != 0) av_log(s, AV_LOG_VERBOSE, "reached terminating character but not all frames read.\n"); vid->is_finished = 1; return AVERROR(EIO); default: av_log(s, AV_LOG_ERROR, "unknown block (character = %c, decimal = %d, hex = %x)!!!\n", block_type, block_type, block_type); return -1; } return 0; }
static void find_by_type_val_cb(uint8_t opcode, const void *pdu, uint16_t length, void *user_data) { struct bt_gatt_server *server = user_data; uint16_t start, end, uuid16; struct find_by_type_val_data data; uint16_t mtu = bt_att_get_mtu(server->att); uint8_t rsp_pdu[mtu]; uint16_t ehandle = 0; bt_uuid_t uuid; if (length < 6) { data.ecode = BT_ATT_ERROR_INVALID_PDU; goto error; } data.pdu = rsp_pdu; data.len = 0; data.mtu = mtu; data.ecode = 0; start = get_le16(pdu); end = get_le16(pdu + 2); uuid16 = get_le16(pdu + 4); util_debug(server->debug_callback, server->debug_data, "Find By Type Value - start: 0x%04x end: 0x%04x uuid: 0x%04x", start, end, uuid16); ehandle = start; if (start > end) { data.ecode = BT_ATT_ERROR_INVALID_HANDLE; goto error; } bt_uuid16_create(&uuid, uuid16); gatt_db_find_by_type_value(server->db, start, end, &uuid, pdu + 6, length - 6, find_by_type_val_att_cb, &data); if (!data.len) data.ecode = BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND; if (data.ecode) goto error; bt_att_send(server->att, BT_ATT_OP_FIND_BY_TYPE_VAL_RSP, data.pdu, data.len, NULL, NULL, NULL); return; error: bt_att_send_error_rsp(server->att, opcode, ehandle, data.ecode); }
static int qcp_read_header(AVFormatContext *s, AVFormatParameters *ap) { ByteIOContext *pb = s->pb; QCPContext *c = s->priv_data; AVStream *st = av_new_stream(s, 0); uint8_t buf[16]; int i, nb_rates; if (!st) return AVERROR(ENOMEM); get_be32(pb); // "RIFF" s->file_size = get_le32(pb) + 8; url_fskip(pb, 8 + 4 + 1 + 1); // "QLCMfmt " + chunk-size + major-version + minor-version st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->channels = 1; get_buffer(pb, buf, 16); if (is_qcelp_13k_guid(buf)) { st->codec->codec_id = CODEC_ID_QCELP; } else if (!memcmp(buf, guid_evrc, 16)) { av_log(s, AV_LOG_ERROR, "EVRC codec is not supported.\n"); return AVERROR_PATCHWELCOME; } else if (!memcmp(buf, guid_smv, 16)) { av_log(s, AV_LOG_ERROR, "SMV codec is not supported.\n"); return AVERROR_PATCHWELCOME; } else { av_log(s, AV_LOG_ERROR, "Unknown codec GUID.\n"); return AVERROR_INVALIDDATA; } url_fskip(pb, 2 + 80); // codec-version + codec-name st->codec->bit_rate = get_le16(pb); s->packet_size = get_le16(pb); url_fskip(pb, 2); // block-size st->codec->sample_rate = get_le16(pb); url_fskip(pb, 2); // sample-size memset(c->rates_per_mode, -1, sizeof(c->rates_per_mode)); nb_rates = get_le32(pb); nb_rates = FFMIN(nb_rates, 8); for (i=0; i<nb_rates; i++) { int size = get_byte(pb); int mode = get_byte(pb); if (mode > QCP_MAX_MODE) { av_log(s, AV_LOG_WARNING, "Unknown entry %d=>%d in rate-map-table.\n ", mode, size); } else c->rates_per_mode[mode] = size; } url_fskip(pb, 16 - 2*nb_rates + 20); // empty entries of rate-map-table + reserved return 0; }