static void service_rsp(const struct l2cap_frame *frame, struct tid_data *tid) { uint16_t count; int i; clear_tid(tid); if (frame->size < 4) { print_text(COLOR_ERROR, "invalid size"); packet_hexdump(frame->data, frame->size); return; } count = get_be16(frame->data + 2); if (count * 4 > frame->size) { print_text(COLOR_ERROR, "invalid record count"); return; } print_field("Total record count: %d", get_be16(frame->data)); print_field("Current record count: %d", count); for (i = 0; i < count; i++) print_field("Record handle: 0x%4.4x", get_be32(frame->data + 4 + (i * 4))); print_continuation(frame->data + 4 + (count * 4), frame->size - 4 - (count * 4)); }
/* read sgi header fields */ static void read_sgi_header(ByteIOContext *f, SGIInfo *info) { info->magic = (unsigned short) get_be16(f); info->rle = get_byte(f); info->bytes_per_channel = get_byte(f); info->dimension = (unsigned short)get_be16(f); info->xsize = (unsigned short) get_be16(f); info->ysize = (unsigned short) get_be16(f); info->zsize = (unsigned short) get_be16(f); if(info->zsize > 4096) info->zsize= 0; #ifdef DEBUG printf("sgi header fields:\n"); printf(" magic: %d\n", info->magic); printf(" rle: %d\n", info->rle); printf(" bpc: %d\n", info->bytes_per_channel); printf(" dim: %d\n", info->dimension); printf(" xsize: %d\n", info->xsize); printf(" ysize: %d\n", info->ysize); printf(" zsize: %d\n", info->zsize); #endif return; }
static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size) { switch (size) { case 2: print_field("%*c%s (0x%4.4x)", indent, ' ', bt_uuid16_to_str(get_be16(data)), get_be16(data)); break; case 4: print_field("%*c%s (0x%8.8x)", indent, ' ', bt_uuid32_to_str(get_be32(data)), get_be32(data)); break; case 16: /* BASE_UUID = 00000000-0000-1000-8000-00805F9B34FB */ print_field("%*c%8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.4x", indent, ' ', get_be32(data), get_be16(data + 4), get_be16(data + 6), get_be16(data + 8), get_be16(data + 10), get_be32(data + 12)); if (get_be16(data + 4) == 0x0000 && get_be16(data + 6) == 0x1000 && get_be16(data + 8) == 0x8000 && get_be16(data + 10) == 0x0080 && get_be32(data + 12) == 0x5F9B34FB) print_field("%*c%s", indent, ' ', bt_uuid32_to_str(get_be32(data))); break; default: packet_hexdump(data, size); break; } }
static int read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size, pts, type; retry: type= get_be16(s->pb); // 257 or 258 size= get_be16(s->pb); get_be16(s->pb); //some flags, 0x80 indicates end of frame get_be16(s->pb); //packet number pts=get_be32(s->pb); get_be32(s->pb); //6A 13 E3 88 size -= 12; if(size<1) return -1; if(type==258){ url_fskip(s->pb, size); goto retry; } ret= av_get_packet(s->pb, pkt, size); pkt->pts= pts; pkt->pos-=16; pkt->stream_index = 0; return ret; }
static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap) { CdataDemuxContext *cdata = s->priv_data; ByteIOContext *pb = s->pb; unsigned int sample_rate, header; AVStream *st; header = get_be16(pb); switch (header) { case 0x0400: cdata->channels = 1; break; case 0x0404: cdata->channels = 2; break; case 0x040C: cdata->channels = 4; break; default: av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header); return -1; }; sample_rate = get_be16(pb); url_fskip(pb, 12); st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS; st->codec->channels = cdata->channels; st->codec->sample_rate = sample_rate; av_set_pts_info(st, 64, 1, sample_rate); cdata->audio_pts = 0; return 0; }
static int read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size, pts; get_be16(s->pb); // 257 size= get_be16(s->pb); get_be16(s->pb); //some flags, 0x80 indicates end of frame get_be16(s->pb); //packet number pts=get_be32(s->pb); get_be32(s->pb); //6A 13 E3 88 size -= 12; if(size<1) return -1; ret= av_get_packet(s->pb, pkt, size); pkt->pts= pkt->dts= pts; pkt->pos-=16; pkt->stream_index = 0; return ret; }
static void avrcp_cid_hook_cb(const void *data, uint16_t len, void *user_data) { struct step *step; uint8_t pdu, event; util_hexdump('>', data, len, print_avrcp, NULL); pdu = ((uint8_t *) data)[9]; switch (pdu) { case AVRCP_GET_PLAY_STATUS: step = g_new0(struct step, 1); step->callback = CB_AVRCP_PLAY_STATUS_RSP; step->callback_result.song_length = get_be32(data + 13); step->callback_result.song_position = get_be32(data + 17); step->callback_result.play_status = ((uint8_t *) data)[21]; schedule_callback_verification(step); break; case AVRCP_REGISTER_NOTIFICATION: event = ((uint8_t *) data)[13]; switch (event) { case 0x01: step = g_new0(struct step, 1); step->callback = CB_AVRCP_REG_NOTIF_RSP; step->callback_result.play_status = ((uint8_t *) data)[14]; schedule_callback_verification(step); break; case 0x02: step = g_new0(struct step, 1); step->callback = CB_AVRCP_REG_NOTIF_RSP; step->callback_result.rc_index = get_be64(data + 14); schedule_callback_verification(step); break; case 0x05: step = g_new0(struct step, 1); step->callback = CB_AVRCP_REG_NOTIF_RSP; step->callback_result.song_position = get_be32(data + 14); schedule_callback_verification(step); break; } break; case AVRCP_GET_ELEMENT_ATTRIBUTES: step = g_new0(struct step, 1); step->callback = CB_AVRCP_GET_ATTR_RSP; step->callback_result.num_of_attrs = ((uint8_t *) data)[13]; memset(exp_attrs, 0, 2 * sizeof(btrc_element_attr_val_t)); exp_attrs[0].attr_id = get_be16(data + 16); memcpy(exp_attrs[0].text, data + 22, 19); exp_attrs[1].attr_id = get_be16(data + 43); memcpy(exp_attrs[1].text, data + 49, 6); step->callback_result.attrs = exp_attrs; schedule_callback_verification(step); break; } }
static int r3d_read_red1(AVFormatContext *s) { AVStream *st = av_new_stream(s, 0); char filename[258]; int tmp, tmp2; if (!st) return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_JPEG2000; tmp = get_byte(s->pb); // major version tmp2 = get_byte(s->pb); // minor version dprintf(s, "version %d.%d\n", tmp, tmp2); tmp = get_be16(s->pb); // unknown dprintf(s, "unknown1 %d\n", tmp); tmp = get_be32(s->pb); av_set_pts_info(st, 32, 1, tmp); tmp = get_be32(s->pb); // filenum dprintf(s, "filenum %d\n", tmp); url_fskip(s->pb, 32); // unknown st->codec->width = get_be32(s->pb); st->codec->height = get_be32(s->pb); tmp = get_be16(s->pb); // unknown dprintf(s, "unknown2 %d\n", tmp); st->codec->time_base.den = get_be16(s->pb); st->codec->time_base.num = get_be16(s->pb); tmp = get_byte(s->pb); // audio channels dprintf(s, "audio channels %d\n", tmp); if (tmp > 0) { AVStream *ast = av_new_stream(s, 1); if (!ast) return AVERROR(ENOMEM); ast->codec->codec_type = CODEC_TYPE_AUDIO; ast->codec->codec_id = CODEC_ID_PCM_S32BE; ast->codec->channels = tmp; av_set_pts_info(ast, 32, 1, st->time_base.den); } get_buffer(s->pb, filename, 257); filename[sizeof(filename)-1] = 0; av_metadata_set(&st->metadata, "filename", filename); dprintf(s, "filename %s\n", filename); dprintf(s, "resolution %dx%d\n", st->codec->width, st->codec->height); dprintf(s, "timescale %d\n", st->time_base.den); dprintf(s, "frame rate %d/%d\n", st->codec->time_base.num, st->codec->time_base.den); return 0; }
static int daud_packet(AVFormatContext *s, AVPacket *pkt) { ByteIOContext *pb = &s->pb; int ret, size; if (url_feof(pb)) return AVERROR_IO; size = get_be16(pb); get_be16(pb); // unknown ret = av_get_packet(pb, pkt, size); pkt->stream_index = 0; return ret; }
static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom) { AVStream *st = s->streams[0]; int tmp, tmp2; uint64_t pos = url_ftell(s->pb); unsigned dts; int ret; dts = get_be32(s->pb); tmp = get_be32(s->pb); dprintf(s, "frame num %d\n", tmp); tmp = get_byte(s->pb); // major version tmp2 = get_byte(s->pb); // minor version dprintf(s, "version %d.%d\n", tmp, tmp2); tmp = get_be16(s->pb); // unknown dprintf(s, "unknown %d\n", tmp); if (tmp > 4) { tmp = get_be16(s->pb); // unknown dprintf(s, "unknown %d\n", tmp); tmp = get_be16(s->pb); // unknown dprintf(s, "unknown %d\n", tmp); tmp = get_be32(s->pb); dprintf(s, "width %d\n", tmp); tmp = get_be32(s->pb); dprintf(s, "height %d\n", tmp); tmp = get_be32(s->pb); dprintf(s, "metadata len %d\n", tmp); } tmp = atom->size - 8 - (url_ftell(s->pb) - pos); if (tmp < 0) return -1; ret = av_get_packet(s->pb, pkt, tmp); if (ret < 0) { av_log(s, AV_LOG_ERROR, "error reading video packet\n"); return -1; } pkt->stream_index = 0; pkt->dts = dts; if (st->codec->time_base.den) pkt->duration = (uint64_t)st->time_base.den* st->codec->time_base.num/st->codec->time_base.den; dprintf(s, "pkt dts %lld duration %d\n", pkt->dts, pkt->duration); return 0; }
static int rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr) { ByteIOContext pb; int size; uint32_t tag; /** * Layout of the MLTI chunk: * 4:MLTI * 2:<number of streams> * Then for each stream ([number_of_streams] times): * 2:<mdpr index> * 2:<number of mdpr chunks> * Then for each mdpr chunk ([number_of_mdpr_chunks] times): * 4:<size> * [size]:<data> * we skip MDPR chunks until we reach the one of the stream * we're interested in, and forward that ([size]+[data]) to * the RM demuxer to parse the stream-specific header data. */ if (!rdt->mlti_data) return -1; init_put_byte(&pb, rdt->mlti_data, rdt->mlti_data_size, 0, NULL, NULL, NULL, NULL); tag = get_le32(&pb); if (tag == MKTAG('M', 'L', 'T', 'I')) { int num, chunk_nr; /* read index of MDPR chunk numbers */ num = get_be16(&pb); if (rule_nr < 0 || rule_nr >= num) return -1; url_fskip(&pb, rule_nr * 2); chunk_nr = get_be16(&pb); url_fskip(&pb, (num - 1 - rule_nr) * 2); /* read MDPR chunks */ num = get_be16(&pb); if (chunk_nr >= num) return -1; while (chunk_nr--) url_fskip(&pb, get_be32(&pb)); size = get_be32(&pb); } else { size = rdt->mlti_data_size; url_fseek(&pb, 0, SEEK_SET); } if (ff_rm_read_mdpr_codecdata(rdt->rmctx, &pb, st, rdt->rmst[st->index], size) < 0) return -1; return 0; }
/* Returns the number of sound data frames or negative on error */ unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec, int size, unsigned version) { AVExtFloat ext; double sample_rate; unsigned int num_frames; if (size & 1) size++; codec->codec_type = CODEC_TYPE_AUDIO; codec->channels = get_be16(pb); num_frames = get_be32(pb); codec->bits_per_sample = get_be16(pb); get_buffer(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */ sample_rate = av_ext2dbl(ext); /* 80 bits BE IEEE extended float */ codec->sample_rate = sample_rate; size -= 18; /* Got an AIFF-C? */ if (version == AIFF_C_VERSION1) { codec->codec_tag = get_le32(pb); codec->codec_id = codec_get_id (codec_aiff_tags, codec->codec_tag); if (codec->codec_id == CODEC_ID_PCM_S16BE) { codec->codec_id = aiff_codec_get_id (codec->bits_per_sample); codec->bits_per_sample = fix_bps(codec->codec_id); } size -= 4; } else { /* Need the codec type */ codec->codec_id = aiff_codec_get_id (codec->bits_per_sample); codec->bits_per_sample = fix_bps(codec->codec_id); } if (!codec->codec_id) return AVERROR_INVALIDDATA; /* Block align needs to be computed in all cases, as the definition * is specific to applications -> here we use the WAVE format definition */ codec->block_align = (codec->bits_per_sample * codec->channels) >> 3; codec->bit_rate = codec->sample_rate * codec->block_align; /* Chunk is over */ if (size) url_fseek(pb, size, SEEK_CUR); return num_frames; }
static void attr_req(const struct l2cap_frame *frame, struct tid_data *tid) { uint32_t attr_bytes; if (frame->size < 6) { print_text(COLOR_ERROR, "invalid size"); packet_hexdump(frame->data, frame->size); return; } print_field("Record handle: 0x%4.4x", get_be32(frame->data)); print_field("Max attribute bytes: %d", get_be16(frame->data + 4)); attr_bytes = get_bytes(frame->data + 6, frame->size - 6); print_field("Attribute list: [len %d]", attr_bytes); if (attr_bytes + 6 > frame->size) { print_text(COLOR_ERROR, "invalid attribute list length"); packet_hexdump(frame->data, frame->size); return; } decode_data_elements(0, 2, frame->data + 6, attr_bytes, NULL); store_continuation(tid, frame->data + 6 + attr_bytes, frame->size - 6 - attr_bytes); }
static void print_attr(uint32_t position, uint8_t indent, uint8_t type, const uint8_t *data, uint32_t size) { int i; if ((position % 2) == 0) { uint16_t id = get_be16(data); const char *str = "Unknown"; for (i = 0; attribute_table[i].str; i++) { if (attribute_table[i].id == id) str = attribute_table[i].str; } print_field("%*cAttribute: %s (0x%4.4x) [len %d]", indent, ' ', str, id, size); return; } for (i = 0; type_table[i].str; i++) { if (type_table[i].value != type) continue; if (type_table[i].recurse) decode_data_elements(0, indent + 2, data, size, NULL); else if (type_table[i].print) type_table[i].print(indent + 2, data, size); break; } }
static uint32_t get_size(const uint8_t *data, uint32_t size) { int i; for (i = 0; size_table[i].str; i++) { if (size_table[i].index == (data[0] & 0x07)) { switch (size_table[i].bits) { case 0: if ((data[0] & 0xf8) == 0) return 0; else return size_table[i].size; case 8: return data[1]; case 16: return get_be16(data + 1); case 32: return get_be32(data + 1); default: return 0; } } } return 0; }
static void connect_req(struct sap_server *server, struct sap_parameter *param) { struct sap_connection *conn = server->conn; uint16_t maxmsgsize; DBG("conn %p state %d", conn, conn->state); if (!param) goto error_rsp; if (conn->state != SAP_STATE_DISCONNECTED) goto error_rsp; stop_guard_timer(server); maxmsgsize = get_be16(¶m->val); DBG("Connect MaxMsgSize: 0x%04x", maxmsgsize); conn->state = SAP_STATE_CONNECT_IN_PROGRESS; if (maxmsgsize <= SAP_BUF_SIZE) { conn->processing_req = SAP_CONNECT_REQ; sap_connect_req(server, maxmsgsize); } else { sap_connect_rsp(server, SAP_STATUS_MAX_MSG_SIZE_NOT_SUPPORTED); } return; error_rsp: sap_error_rsp(conn); }
void close_eraseblks(fs_context& fs) { /* TODO: Error handling missing! */ for (eb_id_t eb_id = 1; eb_id < fs.neraseblocks; ++eb_id) { if (fs.eb_usage[eb_id].e_type == eraseblock_type::ebin) continue; /* can never be "open" */ if (fs.eb_usage[eb_id].e_type == eraseblock_type::empty) continue; /* can never be "open" */ eraseblock_type eb_type = fs.eb_usage[eb_id].e_type; unsigned int writeops = get_be16(fs.eb_usage[eb_id].e_writeops); unsigned int max_writeops = fs.erasesize / fs.clustersize; if (writeops == max_writeops) continue; /* erase block is already finalized/closed */ fs.eb_usage[eb_id].e_writeops = put_be16(max_writeops); if (!summary_required(fs, eb_type)) continue; summary* eb_summary = summary_get(*fs.summary_cache, eb_type); summary_write(fs, eb_summary, eb_id); summary_close(*fs.summary_cache, eb_summary); /* tell gcinfo an erase block of a specific type was written */ unsigned int write_time = gcinfo_update_writetime(fs, eb_type); fs.eb_usage[eb_id].e_lastwrite = put_be16(write_time); } }
static bool free_eraseblk(eraseblock& eb) { if ( eb.e_type == eraseblock_type::dentry_inode || eb.e_type == eraseblock_type::dentry_clin || eb.e_type == eraseblock_type::file_inode || eb.e_type == eraseblock_type::file_clin) { // The given erase block contains inodes or indirect pointers // and therefore tracks it's valid cluster count. // Set it to "free" if it doesn't contain any valid clusters. if (get_be16(eb.e_cvalid) == 0) { eb.e_type = eraseblock_type::empty; eb.e_lastwrite = put_be16(0); eb.e_writeops = put_be16(0); return true; } } else if (eb.e_type == eraseblock_type::ebin) { // TODO: implement me! log().error("Unable to free ebin erase block {}", eb); } // the given erase block cannot be freed return false; }
static void search_attr_req(const struct l2cap_frame *frame, struct tid_data *tid) { uint32_t search_bytes, attr_bytes; search_bytes = get_bytes(frame->data, frame->size); print_field("Search pattern: [len %d]", search_bytes); if (search_bytes + 2 > frame->size) { print_text(COLOR_ERROR, "invalid search list length"); packet_hexdump(frame->data, frame->size); return; } decode_data_elements(0, 2, frame->data, search_bytes, NULL); print_field("Max record count: %d", get_be16(frame->data + search_bytes)); attr_bytes = get_bytes(frame->data + search_bytes + 2, frame->size - search_bytes - 2); print_field("Attribute list: [len %d]", attr_bytes); if (search_bytes + attr_bytes > frame->size) { print_text(COLOR_ERROR, "invalid attribute list length"); return; } decode_data_elements(0, 2, frame->data + search_bytes + 2, attr_bytes, NULL); store_continuation(tid, frame->data + search_bytes + 2 + attr_bytes, frame->size - search_bytes - 2 - attr_bytes); }
static void get_subfield(int n_bits, const void **p, struct mf_subfield *sf) { sf->field = mf_from_nxm_header(ntohl(get_be32(p))); sf->ofs = ntohs(get_be16(p)); sf->n_bits = n_bits; }
uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst, uint16_t *src) { const uint8_t bt_base[] = { 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB }; uint8_t *dest, *source; uint32_t val; dest = req->service; source = req->service + req->uuid_size; switch (req->uuid_size) { case 2: /* UUID16 */ *dst = get_be16(dest); *src = get_be16(source); break; case 16: /* UUID128 */ /* Check that the bytes in the UUID, except the service ID * itself, are correct. The service ID is checked in * bnep_setup_chk(). */ if (memcmp(&dest[4], bt_base, sizeof(bt_base)) != 0) return BNEP_CONN_INVALID_DST; if (memcmp(&source[4], bt_base, sizeof(bt_base)) != 0) return BNEP_CONN_INVALID_SRC; /* Intentional no-break */ case 4: /* UUID32 */ val = get_be32(dest); if (val > 0xffff) return BNEP_CONN_INVALID_DST; *dst = val; val = get_be32(source); if (val > 0xffff) return BNEP_CONN_INVALID_SRC; *src = val; break; default: return BNEP_CONN_INVALID_SVC; } return BNEP_SUCCESS; }
std::string RTMPSession::parseStatusCode(uint8_t *p) { //uint8_t *start = p; std::map<std::string, std::string> props; // skip over the packet id get_double(p+1); // num p += sizeof(double) + 1; // keep reading until we find an AMF Object bool foundObject = false; while (!foundObject) { if (p[0] == AMF_DATA_TYPE_OBJECT) { p += 1; foundObject = true; continue; } else { p += amfPrimitiveObjectSize(p); } } // read the properties of the object uint16_t nameLen, valLen; char propName[128], propVal[128]; do { nameLen = get_be16(p); p += sizeof(nameLen); strncpy(propName, (char*)p, nameLen); propName[nameLen] = '\0'; p += nameLen; if (p[0] == AMF_DATA_TYPE_STRING) { valLen = get_be16(p+1); p += sizeof(valLen) + 1; strncpy(propVal, (char*)p, valLen); propVal[valLen] = '\0'; p += valLen; props[propName] = propVal; } else { // treat non-string property values as empty p += amfPrimitiveObjectSize(p); props[propName] = ""; } } while (get_be24(p) != AMF_DATA_TYPE_OBJECT_END); //p = start; return props["code"]; }
static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const char *key) { char *q, dst[512]; const char *val = NULL; int len, dstlen = sizeof(dst) - 1; unsigned genre; unsigned int (*get)(ByteIOContext*) = get_be16; dst[0] = 0; if (taglen < 1) return; taglen--; /* account for encoding type byte */ switch (get_byte(pb)) { /* encoding type */ case 0: /* ISO-8859-1 (0 - 255 maps directly into unicode) */ q = dst; while (taglen-- && q - dst < dstlen - 7) { uint8_t tmp; PUT_UTF8(get_byte(pb), tmp, *q++ = tmp;) } *q = 0; break; case 1: /* UTF-16 with BOM */ taglen -= 2; switch (get_be16(pb)) { case 0xfffe: get = get_le16; case 0xfeff: break; default: av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key); return; } // fall-through case 2: /* UTF-16BE without BOM */ q = dst; while (taglen > 1 && q - dst < dstlen - 7) { uint32_t ch; uint8_t tmp; GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(pb) : 0), break;) PUT_UTF8(ch, tmp, *q++ = tmp;) } *q = 0; break; case 3: /* UTF-8 */ len = FFMIN(taglen, dstlen); get_buffer(pb, dst, len); dst[len] = 0; break; default: av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key); }
/** * Try to find Xing/Info/VBRI tags and compute duration from info therein */ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base) { uint32_t v, spf; unsigned frames = 0; /* Total number of frames in file */ unsigned size = 0; /* Total number of bytes in the stream */ const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; MPADecodeHeader c; int vbrtag_size = 0; v = get_be32(s->pb); if(ff_mpa_check_header(v) < 0) return -1; if (ff_mpegaudio_decode_header(&c, v) == 0) vbrtag_size = c.frame_size; if(c.layer != 3) return -1; /* Check for Xing / Info tag */ url_fseek(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1], SEEK_CUR); v = get_be32(s->pb); if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) { v = get_be32(s->pb); if(v & 0x1) frames = get_be32(s->pb); if(v & 0x2) size = get_be32(s->pb); } /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */ url_fseek(s->pb, base + 4 + 32, SEEK_SET); v = get_be32(s->pb); if(v == MKBETAG('V', 'B', 'R', 'I')) { /* Check tag version */ if(get_be16(s->pb) == 1) { /* skip delay and quality */ url_fseek(s->pb, 4, SEEK_CUR); frames = get_be32(s->pb); size = get_be32(s->pb); } } if(!frames && !size) return -1; /* Skip the vbr tag frame */ url_fseek(s->pb, base + vbrtag_size, SEEK_SET); spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */ if(frames) st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate}, st->time_base); if(size && frames) st->codec->bit_rate = av_rescale(size, 8 * c.sample_rate, frames * (int64_t)spf); return 0; }
int32_t RTMPSession::amfPrimitiveObjectSize(uint8_t* p) { switch(p[0]) { case AMF_DATA_TYPE_NUMBER: return 9; case AMF_DATA_TYPE_BOOL: return 2; case AMF_DATA_TYPE_NULL: return 1; case AMF_DATA_TYPE_STRING: return 3 + get_be16(p); case AMF_DATA_TYPE_LONG_STRING: return 5 + get_be32(p); } return -1; // not a primitive, likely an object }
static void copy_ay_fields( Ay_Emu::file_t const& file, track_info_t* out, int track ) { Gme_File::copy_field_( out->song, (char const*) get_data( file, file.tracks + track * 4, 1 ) ); byte const* track_info = get_data( file, file.tracks + track * 4 + 2, 6 ); if ( track_info ) out->length = get_be16( track_info + 4 ) * (1000L / 50); // frames to msec Gme_File::copy_field_( out->author, (char const*) get_data( file, file.header->author, 1 ) ); Gme_File::copy_field_( out->comment, (char const*) get_data( file, file.header->comment, 1 ) ); }
static byte const* get_data( Ay_Emu::file_t const& file, byte const* ptr, int min_size ) { long pos = ptr - (byte const*) file.header; long file_size = file.end - (byte const*) file.header; assert( (unsigned long) pos <= (unsigned long) file_size - 2 ); int offset = (BOOST::int16_t) get_be16( ptr ); if ( !offset || blargg_ulong (pos + offset) > blargg_ulong (file_size - min_size) ) return 0; return ptr + offset; }
// Given pointer to 2-byte offset of data, returns pointer to data, or NULL if // offset is 0 or there is less than min_size bytes of data available. static byte const* get_data( Ay_Emu::file_t const& file, byte const ptr [], int min_size ) { int offset = (BOOST::int16_t) get_be16( ptr ); int pos = ptr - (byte const*) file.header; int size = file.end - (byte const*) file.header; assert( (unsigned) pos <= (unsigned) size - 2 ); int limit = size - min_size; if ( limit < 0 || !offset || (unsigned) (pos + offset) > (unsigned) limit ) return NULL; return ptr + offset; }
static uint64_t get_bits(int n_bits, const void **p) { int n_segs = DIV_ROUND_UP(n_bits, 16); uint64_t value; value = 0; while (n_segs-- > 0) { value = (value << 16) | ntohs(get_be16(p)); } return value; }
static int read_header(AVFormatContext *s, AVFormatParameters *ap) { FilmstripDemuxContext *film = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st; if (url_is_streamed(s->pb)) return AVERROR(EIO); url_fseek(pb, url_fsize(pb) - 36, SEEK_SET); if (get_be32(pb) != RAND_TAG) { av_log(s, AV_LOG_ERROR, "magic number not found"); return AVERROR_INVALIDDATA; } st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->nb_frames = get_be32(pb); if (get_be16(pb) != 0) { av_log_ask_for_sample(s, "unsupported packing method\n"); return AVERROR_INVALIDDATA; } url_fskip(pb, 2); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; st->codec->pix_fmt = PIX_FMT_RGBA; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = get_be16(pb); st->codec->height = get_be16(pb); film->leading = get_be16(pb); av_set_pts_info(st, 64, 1, get_be16(pb)); url_fseek(pb, 0, SEEK_SET); return 0; }