ssize_t FAST_FUNC open_read_close(const char *filename, void *buf, size_t size) { int fd = open(filename, O_RDONLY); if (fd < 0) return fd; return read_close(fd, buf, size); }
static void tftp_xmitfile(int peer, const char *mode) { uint16_t block; time_t now; struct tftp_stats ts; now = time(NULL); if (debug&DEBUG_SIMPLE) tftp_log(LOG_DEBUG, "Transmitting file"); read_init(0, file, mode); block = 1; tftp_send(peer, &block, &ts); read_close(); if (debug&DEBUG_SIMPLE) tftp_log(LOG_INFO, "Sent %jd bytes in %jd seconds", (intmax_t)ts.amount, (intmax_t)time(NULL) - now); }
// Read (potentially big) files in one go. File size is estimated by // lseek to end. void *xmalloc_open_read_close(const char *filename, size_t *sizep) { char *buf; size_t size = sizep ? *sizep : INT_MAX; int fd; off_t len; fd = xopen(filename, O_RDONLY); /* /proc/N/stat files report len 0 here */ /* In order to make such files readable, we add small const */ len = xlseek(fd, 0, SEEK_END) | 0x3ff; /* + up to 1k */ xlseek(fd, 0, SEEK_SET); if (len < size) size = len; buf = xmalloc(size + 1); size = read_close(fd, buf, size); if ((ssize_t)size < 0) bb_perror_msg_and_die("'%s'", filename); xrealloc(buf, size + 1); buf[size] = '\0'; if (sizep) *sizep = size; return buf; }
static int read_header(AVFormatContext *s) { PAFDemuxContext *p = s->priv_data; AVIOContext *pb = s->pb; AVStream *ast, *vst; int ret = 0; avio_skip(pb, 132); vst = avformat_new_stream(s, 0); if (!vst) return AVERROR(ENOMEM); vst->start_time = 0; vst->nb_frames = vst->duration = p->nb_frames = avio_rl32(pb); avio_skip(pb, 4); vst->codec->width = avio_rl32(pb); vst->codec->height = avio_rl32(pb); avio_skip(pb, 4); vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_tag = 0; vst->codec->codec_id = AV_CODEC_ID_PAF_VIDEO; avpriv_set_pts_info(vst, 64, 1, 10); ast = avformat_new_stream(s, 0); if (!ast) return AVERROR(ENOMEM); ast->start_time = 0; ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_tag = 0; ast->codec->codec_id = AV_CODEC_ID_PAF_AUDIO; ast->codec->channels = 2; ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; ast->codec->sample_rate = 22050; avpriv_set_pts_info(ast, 64, 1, 22050); p->buffer_size = avio_rl32(pb); p->preload_count = avio_rl32(pb); p->frame_blks = avio_rl32(pb); p->start_offset = avio_rl32(pb); p->max_video_blks = avio_rl32(pb); p->max_audio_blks = avio_rl32(pb); if (p->buffer_size < 175 || p->max_audio_blks < 2 || p->max_video_blks < 1 || p->frame_blks < 1 || p->nb_frames < 1 || p->preload_count < 1 || p->buffer_size > 2048 || p->max_video_blks > 2048 || p->max_audio_blks > 2048 || p->nb_frames > INT_MAX / sizeof(uint32_t) || p->frame_blks > INT_MAX / sizeof(uint32_t)) return AVERROR_INVALIDDATA; p->blocks_count_table = av_mallocz(p->nb_frames * sizeof(*p->blocks_count_table)); p->frames_offset_table = av_mallocz(p->nb_frames * sizeof(*p->frames_offset_table)); p->blocks_offset_table = av_mallocz(p->frame_blks * sizeof(*p->blocks_offset_table)); p->video_size = p->max_video_blks * p->buffer_size; p->video_frame = av_mallocz(p->video_size); p->audio_size = p->max_audio_blks * p->buffer_size; p->audio_frame = av_mallocz(p->audio_size); p->temp_audio_frame = av_mallocz(p->audio_size); if (!p->blocks_count_table || !p->frames_offset_table || !p->blocks_offset_table || !p->video_frame || !p->audio_frame || !p->temp_audio_frame) { ret = AVERROR(ENOMEM); goto fail; } avio_seek(pb, p->buffer_size, SEEK_SET); read_table(s, p->blocks_count_table, p->nb_frames); read_table(s, p->frames_offset_table, p->nb_frames); read_table(s, p->blocks_offset_table, p->frame_blks); p->got_audio = 0; p->current_frame = 0; p->current_frame_block = 0; avio_seek(pb, p->start_offset, SEEK_SET); return 0; fail: read_close(s); return ret; }
static int read_header(AVFormatContext *s) { BRSTMDemuxContext *b = s->priv_data; int bom, major, minor, codec, chunk; int64_t pos, h1offset, toffset; uint32_t size, start, asize; AVStream *st; int ret = AVERROR_EOF; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; avio_skip(s->pb, 4); bom = avio_rb16(s->pb); if (bom != 0xFEFF && bom != 0xFFFE) { av_log(s, AV_LOG_ERROR, "invalid byte order: %X\n", bom); return AVERROR_INVALIDDATA; } if (bom == 0xFFFE) { avpriv_request_sample(s, "little endian byte order"); return AVERROR_PATCHWELCOME; } major = avio_r8(s->pb); minor = avio_r8(s->pb); avio_skip(s->pb, 4); // size of file size = avio_rb16(s->pb); if (size < 14) return AVERROR_INVALIDDATA; avio_skip(s->pb, size - 14); pos = avio_tell(s->pb); if (avio_rl32(s->pb) != MKTAG('H','E','A','D')) return AVERROR_INVALIDDATA; size = avio_rb32(s->pb); if (size < 256) return AVERROR_INVALIDDATA; avio_skip(s->pb, 4); // unknown h1offset = avio_rb32(s->pb); if (h1offset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, 12); toffset = avio_rb32(s->pb) + LLN(16); if (toffset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, pos + h1offset + 8 - avio_tell(s->pb)); codec = avio_r8(s->pb); switch (codec) { case 0: codec = AV_CODEC_ID_PCM_S8_PLANAR; break; case 1: codec = AV_CODEC_ID_PCM_S16BE_PLANAR; break; case 2: codec = AV_CODEC_ID_ADPCM_THP; break; default: avpriv_request_sample(s, "codec %d", codec); return AVERROR_PATCHWELCOME; } avio_skip(s->pb, 1); // loop flag st->codec->codec_id = codec; st->codec->channels = avio_r8(s->pb); if (!st->codec->channels) return AVERROR_INVALIDDATA; avio_skip(s->pb, 1); // padding st->codec->sample_rate = avio_rb16(s->pb); if (!st->codec->sample_rate) return AVERROR_INVALIDDATA; avio_skip(s->pb, 2); // padding avio_skip(s->pb, 4); // loop start sample st->start_time = 0; st->duration = avio_rb32(s->pb); avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); start = avio_rb32(s->pb); b->current_block = 0; b->block_count = avio_rb32(s->pb); if (b->block_count > UINT16_MAX) { av_log(s, AV_LOG_WARNING, "too many blocks: %u\n", b->block_count); return AVERROR_INVALIDDATA; } b->block_size = avio_rb32(s->pb); if (b->block_size > UINT16_MAX / st->codec->channels) return AVERROR_INVALIDDATA; b->block_size *= st->codec->channels; b->samples_per_block = avio_rb32(s->pb); b->last_block_used_bytes = avio_rb32(s->pb); if (b->last_block_used_bytes > UINT16_MAX / st->codec->channels) return AVERROR_INVALIDDATA; b->last_block_used_bytes *= st->codec->channels; avio_skip(s->pb, 4); // last block samples avio_skip(s->pb, 4); // last block size if (codec == AV_CODEC_ID_ADPCM_THP) { int ch; avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); toffset = avio_rb32(s->pb) + LLN(16); if (toffset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); b->table = av_mallocz(32 * st->codec->channels); if (!b->table) return AVERROR(ENOMEM); for (ch = 0; ch < st->codec->channels; ch++) { if (avio_read(s->pb, b->table + ch * 32, 32) != 32) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, 24); } } if (size < (avio_tell(s->pb) - pos)) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, size - (avio_tell(s->pb) - pos)); while (!avio_feof(s->pb)) { chunk = avio_rl32(s->pb); size = avio_rb32(s->pb); if (size < 8) { ret = AVERROR_INVALIDDATA; goto fail; } size -= 8; switch (chunk) { case MKTAG('A','D','P','C'): if (codec != AV_CODEC_ID_ADPCM_THP) goto skip; asize = b->block_count * st->codec->channels * 4; if (size < asize) { ret = AVERROR_INVALIDDATA; goto fail; } if (b->adpc) { av_log(s, AV_LOG_WARNING, "skipping additional ADPC chunk\n"); goto skip; } else { b->adpc = av_mallocz(asize); if (!b->adpc) { ret = AVERROR(ENOMEM); goto fail; } avio_read(s->pb, b->adpc, asize); avio_skip(s->pb, size - asize); } break; case MKTAG('D','A','T','A'): if ((start < avio_tell(s->pb)) || (!b->adpc && codec == AV_CODEC_ID_ADPCM_THP)) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, start - avio_tell(s->pb)); if (major != 1 || minor) avpriv_request_sample(s, "Version %d.%d", major, minor); return 0; default: av_log(s, AV_LOG_WARNING, "skipping unknown chunk: %X\n", chunk); skip: avio_skip(s->pb, size); } } fail: read_close(s); return ret; }
static int read_header(AVFormatContext *s) { BRSTMDemuxContext *b = s->priv_data; int bom, major, minor, codec, chunk; int64_t h1offset, pos, toffset, data_offset = 0; uint32_t size, start, asize; AVStream *st; int ret = AVERROR_EOF; b->bfstm = !strcmp("bfstm", s->iformat->name); st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; avio_skip(s->pb, 4); bom = avio_rb16(s->pb); if (bom != 0xFEFF && bom != 0xFFFE) { av_log(s, AV_LOG_ERROR, "invalid byte order: %X\n", bom); return AVERROR_INVALIDDATA; } if (bom == 0xFFFE) b->little_endian = 1; if (!b->bfstm) { major = avio_r8(s->pb); minor = avio_r8(s->pb); avio_skip(s->pb, 4); // size of file size = read16(s); if (size < 14) return AVERROR_INVALIDDATA; avio_skip(s->pb, size - 14); pos = avio_tell(s->pb); if (avio_rl32(s->pb) != MKTAG('H','E','A','D')) return AVERROR_INVALIDDATA; } else { uint32_t info_offset = 0, info_size; uint16_t section_count, header_size, i; header_size = read16(s); // 6 avio_skip(s->pb, 4); // Unknown constant 0x00030000 avio_skip(s->pb, 4); // size of file section_count = read16(s); avio_skip(s->pb, 2); // padding for (i = 0; avio_tell(s->pb) < header_size && !(data_offset && info_offset) && i < section_count; i++) { uint16_t flag = read16(s); avio_skip(s->pb, 2); switch (flag) { case 0x4000: info_offset = read32(s); info_size = read32(s); break; case 0x4001: avio_skip(s->pb, 4); // seek offset avio_skip(s->pb, 4); // seek size break; case 0x4002: data_offset = read32(s); avio_skip(s->pb, 4); //data_size = read32(s); break; case 0x4003: avio_skip(s->pb, 4); // REGN offset avio_skip(s->pb, 4); // REGN size break; } } if (!info_offset || !data_offset) return AVERROR_INVALIDDATA; start = data_offset + 8; avio_skip(s->pb, info_offset - avio_tell(s->pb)); pos = avio_tell(s->pb); if (avio_rl32(s->pb) != MKTAG('I','N','F','O')) return AVERROR_INVALIDDATA; } size = read32(s); if (size < 192) return AVERROR_INVALIDDATA; avio_skip(s->pb, 4); // unknown h1offset = read32(s); if (h1offset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, 12); toffset = read32(s) + 16LL; if (toffset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, pos + h1offset + 8 - avio_tell(s->pb)); codec = avio_r8(s->pb); switch (codec) { case 0: codec = AV_CODEC_ID_PCM_S8_PLANAR; break; case 1: codec = AV_CODEC_ID_PCM_S16BE_PLANAR; break; case 2: codec = b->little_endian ? AV_CODEC_ID_ADPCM_THP_LE : AV_CODEC_ID_ADPCM_THP; break; default: avpriv_request_sample(s, "codec %d", codec); return AVERROR_PATCHWELCOME; } avio_skip(s->pb, 1); // loop flag st->codec->codec_id = codec; st->codec->channels = avio_r8(s->pb); if (!st->codec->channels) return AVERROR_INVALIDDATA; avio_skip(s->pb, 1); // padding st->codec->sample_rate = b->bfstm ? read32(s) : read16(s); if (!st->codec->sample_rate) return AVERROR_INVALIDDATA; if (!b->bfstm) avio_skip(s->pb, 2); // padding avio_skip(s->pb, 4); // loop start sample st->start_time = 0; st->duration = read32(s); avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); if (!b->bfstm) start = read32(s); b->current_block = 0; b->block_count = read32(s); if (b->block_count > UINT16_MAX) { av_log(s, AV_LOG_WARNING, "too many blocks: %u\n", b->block_count); return AVERROR_INVALIDDATA; } b->block_size = read32(s); if (b->block_size > UINT32_MAX / st->codec->channels) return AVERROR_INVALIDDATA; b->block_size *= st->codec->channels; b->samples_per_block = read32(s); b->last_block_used_bytes = read32(s); if (b->last_block_used_bytes > UINT16_MAX / st->codec->channels) return AVERROR_INVALIDDATA; b->last_block_used_bytes *= st->codec->channels; avio_skip(s->pb, 4); // last block samples avio_skip(s->pb, 4); // last block size if (codec == AV_CODEC_ID_ADPCM_THP || codec == AV_CODEC_ID_ADPCM_THP_LE) { int ch; avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); if (!b->bfstm) toffset = read32(s) + 16LL; else toffset = toffset + read32(s) + st->codec->channels * 8 - 8; if (toffset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); b->table = av_mallocz(32 * st->codec->channels); if (!b->table) return AVERROR(ENOMEM); for (ch = 0; ch < st->codec->channels; ch++) { if (avio_read(s->pb, b->table + ch * 32, 32) != 32) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, b->bfstm ? 14 : 24); } if (b->bfstm) { st->codec->extradata_size = 32 * st->codec->channels; st->codec->extradata = av_malloc(st->codec->extradata_size); if (!st->codec->extradata) return AVERROR(ENOMEM); memcpy(st->codec->extradata, b->table, st->codec->extradata_size); } } if (size < (avio_tell(s->pb) - pos)) { ret = AVERROR_INVALIDDATA; goto fail; } if (!b->bfstm) avio_skip(s->pb, size - (avio_tell(s->pb) - pos)); else avio_skip(s->pb, data_offset - avio_tell(s->pb)); while (!avio_feof(s->pb)) { chunk = avio_rl32(s->pb); size = read32(s); if (size < 8) { ret = AVERROR_INVALIDDATA; goto fail; } size -= 8; switch (chunk) { case MKTAG('A','D','P','C'): if (codec != AV_CODEC_ID_ADPCM_THP && codec != AV_CODEC_ID_ADPCM_THP_LE) goto skip; asize = b->block_count * st->codec->channels * 4; if (size < asize) { ret = AVERROR_INVALIDDATA; goto fail; } if (b->adpc) { av_log(s, AV_LOG_WARNING, "skipping additional ADPC chunk\n"); goto skip; } else { b->adpc = av_mallocz(asize); if (!b->adpc) { ret = AVERROR(ENOMEM); goto fail; } avio_read(s->pb, b->adpc, asize); avio_skip(s->pb, size - asize); } break; case MKTAG('D','A','T','A'): if ((start < avio_tell(s->pb)) || (!b->adpc && (codec == AV_CODEC_ID_ADPCM_THP || codec == AV_CODEC_ID_ADPCM_THP_LE) && !b->bfstm)) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, start - avio_tell(s->pb)); if ((major != 1 || minor) && !b->bfstm) avpriv_request_sample(s, "Version %d.%d", major, minor); return 0; default: av_log(s, AV_LOG_WARNING, "skipping unknown chunk: %X\n", chunk); skip: avio_skip(s->pb, size); } } fail: read_close(s); return ret; }
static int read_header(AVFormatContext *s) { int i, len, header_remaining; ASSContext *ass = s->priv_data; AVIOContext *pb = s->pb; AVStream *st; int allocated[2]= {0}; uint8_t *p, **dst[2]= {0}; int pos[2]= {0}; st = avformat_new_stream(s, NULL); if (!st) return -1; avpriv_set_pts_info(st, 64, 1, 100); st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_id= AV_CODEC_ID_SSA; header_remaining= INT_MAX; dst[0] = &st->codec->extradata; dst[1] = &ass->event_buffer; while(!pb->eof_reached) { uint8_t line[MAX_LINESIZE]; len = ff_get_line(pb, line, sizeof(line)); if(!memcmp(line, "[Events]", 8)) header_remaining= 2; else if(line[0]=='[') header_remaining= INT_MAX; i= header_remaining==0; if(i && get_pts(line) == AV_NOPTS_VALUE) continue; p = av_fast_realloc(*(dst[i]), &allocated[i], pos[i]+MAX_LINESIZE); if(!p) goto fail; *(dst[i])= p; memcpy(p + pos[i], line, len+1); pos[i] += len; if(i) ass->event_count++; else header_remaining--; } st->codec->extradata_size= pos[0]; if(ass->event_count >= UINT_MAX / sizeof(*ass->event)) goto fail; ass->event= av_malloc(ass->event_count * sizeof(*ass->event)); p= ass->event_buffer; for(i=0; i<ass->event_count; i++) { ass->event[i]= p; while(*p && *p != '\n') p++; p++; } qsort(ass->event, ass->event_count, sizeof(*ass->event), (void*)event_cmp); return 0; fail: read_close(s); return -1; }
void connection_engine::disconnected(const proton::error_condition& err) { set_error_condition(err, pn_transport_condition(unwrap(transport_))); read_close(); write_close(); }
static int read_header(AVFormatContext *s, AVFormatParameters *ap) { int i, header_remaining; ASSContext *ass = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st; int allocated[2]={0}; uint8_t *p, **dst[2]={0}; int pos[2]={0}; st = av_new_stream(s, 0); if (!st) return -1; av_set_pts_info(st, 64, 1, 100); st->codec->codec_type = CODEC_TYPE_SUBTITLE; st->codec->codec_id= CODEC_ID_SSA; header_remaining= INT_MAX; dst[0] = &st->codec->extradata; dst[1] = &ass->event_buffer; while(!url_feof(pb)){ uint8_t line[MAX_LINESIZE]; get_line(pb, line, sizeof(line)); if(!memcmp(line, "[Events]", 8)) header_remaining= 2; else if(line[0]=='[') header_remaining= INT_MAX; i= header_remaining==0; if(i && get_pts(line, NULL) == AV_NOPTS_VALUE) continue; p = av_fast_realloc(*(dst[i]), &allocated[i], pos[i]+MAX_LINESIZE); if(!p) goto fail; *(dst[i])= p; memcpy(p + pos[i], line, strlen(line)+1); pos[i] += strlen(line); if(i) ass->event_count++; else { header_remaining--; #if 0 if (!header_remaining) { /* write the header into extrada section */ int len = url_ftell(pb); st->codec->extradata = av_mallocz(len + 1); st->codec->extradata_size = len; url_fseek(pb, 0, SEEK_SET); get_buffer(pb, st->codec->extradata, len); } #endif } } st->codec->extradata_size= pos[0]; if(ass->event_count >= UINT_MAX / sizeof(*ass->event)) goto fail; ass->event= av_malloc(ass->event_count * sizeof(*ass->event)); p= ass->event_buffer; for(i=0; i<ass->event_count; i++){ ass->event[i].text= p; ass->event[i].start_time= get_pts(p, &ass->event[i].end_time); while(*p && *p != '\n') p++; p++; } qsort(ass->event, ass->event_count, sizeof(*ass->event), event_cmp); return 0; fail: read_close(s); return -1; }
/* * Send the requested file. */ void xmitfile(int peer, char *port, int fd, char *name, char *mode) { struct tftphdr *rp; int n, i; uint16_t block; struct sockaddr_storage serv; /* valid server port number */ char recvbuffer[MAXPKTSIZE]; struct tftp_stats tftp_stats; stats_init(&tftp_stats); memset(&serv, 0, sizeof(serv)); rp = (struct tftphdr *)recvbuffer; if (port == NULL) { struct servent *se; se = getservbyname("tftp", "udp"); ((struct sockaddr_in *)&peer_sock)->sin_port = se->s_port; } else ((struct sockaddr_in *)&peer_sock)->sin_port = htons(atoi(port)); for (i = 0; i < 12; i++) { struct sockaddr_storage from; /* Tell the other side what we want to do */ if (debug&DEBUG_SIMPLE) printf("Sending %s\n", name); n = send_wrq(peer, name, mode); if (n > 0) { printf("Cannot send WRQ packet\n"); return; } /* * The first packet we receive has the new destination port * we have to send the next packets to. */ n = receive_packet(peer, recvbuffer, MAXPKTSIZE, &from, timeoutpacket); /* We got some data! */ if (n >= 0) { ((struct sockaddr_in *)&peer_sock)->sin_port = ((struct sockaddr_in *)&from)->sin_port; break; } /* This should be retried */ if (n == RP_TIMEOUT) { printf("Try %d, didn't receive answer from remote.\n", i + 1); continue; } /* Everything else is fatal */ break; } if (i == 12) { printf("Transfer timed out.\n"); return; } if (rp->th_opcode == ERROR) { printf("Got ERROR, aborted\n"); return; } /* * If the first packet is an OACK instead of an ACK packet, * handle it different. */ if (rp->th_opcode == OACK) { if (!options_rfc_enabled) { printf("Got OACK while options are not enabled!\n"); send_error(peer, EBADOP); return; } parse_options(peer, rp->th_stuff, n + 2); } if (read_init(fd, NULL, mode) < 0) { warn("read_init()"); return; } block = 1; tftp_send(peer, &block, &tftp_stats); read_close(); if (tftp_stats.amount > 0) printstats("Sent", verbose, &tftp_stats); txrx_error = 1; }
static int read_header(AVFormatContext *s) { JVDemuxContext *jv = s->priv_data; AVIOContext *pb = s->pb; AVStream *vst, *ast; int64_t audio_pts = 0; int64_t offset; int i; avio_skip(pb, 80); ast = avformat_new_stream(s, NULL); vst = avformat_new_stream(s, NULL); if (!ast || !vst) return AVERROR(ENOMEM); vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = AV_CODEC_ID_JV; vst->codec->codec_tag = 0; /* no fourcc */ vst->codec->width = avio_rl16(pb); vst->codec->height = avio_rl16(pb); vst->duration = vst->nb_frames = ast->nb_index_entries = avio_rl16(pb); avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000); avio_skip(pb, 4); ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_id = AV_CODEC_ID_PCM_U8; ast->codec->codec_tag = 0; /* no fourcc */ ast->codec->sample_rate = avio_rl16(pb); ast->codec->channels = 1; ast->codec->channel_layout = AV_CH_LAYOUT_MONO; avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); avio_skip(pb, 10); ast->index_entries = av_malloc(ast->nb_index_entries * sizeof(*ast->index_entries)); if (!ast->index_entries) return AVERROR(ENOMEM); jv->frames = av_malloc(ast->nb_index_entries * sizeof(JVFrame)); if (!jv->frames) return AVERROR(ENOMEM); offset = 0x68 + ast->nb_index_entries * 16; for (i = 0; i < ast->nb_index_entries; i++) { AVIndexEntry *e = ast->index_entries + i; JVFrame *jvf = jv->frames + i; /* total frame size including audio, video, palette data and padding */ e->size = avio_rl32(pb); e->timestamp = i; e->pos = offset; offset += e->size; jvf->audio_size = avio_rl32(pb); jvf->video_size = avio_rl32(pb); jvf->palette_size = avio_r8(pb) ? 768 : 0; if ((jvf->video_size | jvf->audio_size) & ~0xFFFFFF || e->size - jvf->audio_size - jvf->video_size - jvf->palette_size < 0) { if (s->error_recognition & AV_EF_EXPLODE) { read_close(s); return AVERROR_INVALIDDATA; } jvf->audio_size = jvf->video_size = jvf->palette_size = 0; } if (avio_r8(pb)) av_log(s, AV_LOG_WARNING, "unsupported audio codec\n"); jvf->video_type = avio_r8(pb); avio_skip(pb, 1); e->timestamp = jvf->audio_size ? audio_pts : AV_NOPTS_VALUE; audio_pts += jvf->audio_size; e->flags = jvf->video_type != 1 ? AVINDEX_KEYFRAME : 0; } jv->state = JV_AUDIO; return 0; }