Exemple #1
0
/* raw input */
int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    AVStream *st;
    enum CodecID id;

    st = av_new_stream(s, 0);
    if (!st)
        return AVERROR(ENOMEM);

    id = s->iformat->value;
    if (id == CODEC_ID_RAWVIDEO) {
        st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
    } else {
        st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
    }
    st->codec->codec_id = id;

    switch(st->codec->codec_type) {
    case AVMEDIA_TYPE_AUDIO:
        st->codec->sample_rate = ap->sample_rate;
        if(ap->channels) st->codec->channels = ap->channels;
        else             st->codec->channels = 1;
        st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
        assert(st->codec->bits_per_coded_sample > 0);
        st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
        av_set_pts_info(st, 64, 1, st->codec->sample_rate);
        break;
    case AVMEDIA_TYPE_VIDEO:
        if(ap->time_base.num)
            av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
        else
            av_set_pts_info(st, 64, 1, 25);
        st->r_frame_rate.num = st->time_base.den;
        st->r_frame_rate.den = st->time_base.num;
        st->codec->width = ap->width;
        st->codec->height = ap->height;
        st->codec->pix_fmt = ap->pix_fmt;
        if(st->codec->codec_id == CODEC_ID_RAWVIDEO &&
                st->codec->pix_fmt != PIX_FMT_NONE && !url_is_streamed(s->pb)) {
            int frame_size = avpicture_get_size(st->codec->pix_fmt,
                                                st->codec->width, st->codec->height);
            if (frame_size < 0) {
                av_log(s, AV_LOG_ERROR, "could not get frame size\n");
                return -1;
            }
            if (url_fsize(s->pb) % frame_size)
                av_log(s, AV_LOG_WARNING, "partial file\n");
            st->nb_frames = url_fsize(s->pb) / frame_size;
            st->duration = st->nb_frames;
        }
        if(st->codec->pix_fmt == PIX_FMT_NONE)
            st->codec->pix_fmt= PIX_FMT_YUV420P;
        break;
    default:
        return -1;
    }
    return 0;
}
Exemple #2
0
static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
    VideoData *s = s1->priv_data;
    char filename[1024];
    int i;
    int size[3]={0}, ret[3]={0};
    ByteIOContext f1[3], *f[3]= {&f1[0], &f1[1], &f1[2]};
    AVCodecContext *codec= s1->streams[0]->codec;

    if (!s->is_pipe) {
        /* loop over input */
        if (s1->loop_input && s->img_number > s->img_last) {
            s->img_number = s->img_first;
        }
        if (av_get_frame_filename(filename, sizeof(filename),
                                  s->path, s->img_number)<0 && s->img_number > 1)
            return AVERROR_IO;
        for(i=0; i<3; i++){
            if (url_fopen(f[i], filename, URL_RDONLY) < 0)
                return AVERROR_IO;
            size[i]= url_fsize(f[i]);

            if(codec->codec_id != CODEC_ID_RAWVIDEO)
                break;
            filename[ strlen(filename) - 1 ]= 'U' + i;
        }

        if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
            infer_size(&codec->width, &codec->height, size[0]);
    } else {
        f[0] = &s1->pb;
        if (url_feof(f[0]))
            return AVERROR_IO;
        size[0]= 4096;
    }

    av_new_packet(pkt, size[0] + size[1] + size[2]);
    pkt->stream_index = 0;
    pkt->flags |= PKT_FLAG_KEY;

    pkt->size= 0;
    for(i=0; i<3; i++){
        if(size[i]){
            ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]);
            if (!s->is_pipe)
                url_fclose(f[i]);
            if(ret[i]>0)
                pkt->size += ret[i];
        }
    }

    if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {
        av_free_packet(pkt);
        return AVERROR_IO; /* signal EOF */
    } else {
        s->img_count++;
        s->img_number++;
        return 0;
    }
}
Exemple #3
0
static int read_header(AVFormatContext *avctx,
                       AVFormatParameters *ap)
{
    TtyDemuxContext *s = avctx->priv_data;
    AVStream *st = av_new_stream(avctx, 0);
    if (!st)
        return AVERROR(ENOMEM);
    st->codec->codec_tag   = 0;
    st->codec->codec_type  = AVMEDIA_TYPE_VIDEO;
    st->codec->codec_id    = CODEC_ID_ANSI;
    if (ap->width)  st->codec->width  = ap->width;
    if (ap->height) st->codec->height = ap->height;

    if (!ap->time_base.num) {
        av_set_pts_info(st, 60, 1, 25);
    } else {
        av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den);
    }

    /* simulate tty display speed */
    s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1);

    if (!url_is_streamed(avctx->pb)) {
        s->fsize = url_fsize(avctx->pb);
        st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame;

        if (ff_sauce_read(avctx, &s->fsize, 0, 0) < 0)
            efi_read(avctx, s->fsize - 51);

        url_fseek(avctx->pb, 0, SEEK_SET);
    }

    return 0;
}
Exemple #4
0
static int mp3_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
{
    AVStream *st;
    uint8_t buf[ID3v1_TAG_SIZE];
    int len, ret, filesize;
    offset_t off;

    st = av_new_stream(s, 0);
    if (!st)
        return AVERROR(ENOMEM);

    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_MP3;
    st->need_parsing = AVSTREAM_PARSE_FULL;
    st->start_time = 0;

    /* try to get the TAG */
    if (!url_is_streamed(s->pb)) {
        /* XXX: change that */
        filesize = url_fsize(s->pb);
        if (filesize > 128) {
            url_fseek(s->pb, filesize - 128, SEEK_SET);
            ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE);
            if (ret == ID3v1_TAG_SIZE) {
                id3v1_parse_tag(s, buf);
            }
            url_fseek(s->pb, 0, SEEK_SET);
        }
    }

    /* if ID3v2 header found, skip it */
    ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
    if (ret != ID3v2_HEADER_SIZE)
        return -1;
    if (id3v2_match(buf)) {
        /* parse ID3v2 header */
        len = ((buf[6] & 0x7f) << 21) |
            ((buf[7] & 0x7f) << 14) |
            ((buf[8] & 0x7f) << 7) |
            (buf[9] & 0x7f);
        id3v2_parse(s, len, buf[3], buf[5]);
    } else {
        url_fseek(s->pb, 0, SEEK_SET);
    }

    off = url_ftell(s->pb);
    mp3_parse_vbr_tags(s, st, off);
    url_fseek(s->pb, off, SEEK_SET);

    /* the parameters will be extracted from the compressed bitstream */
    return 0;
}
/* XXX: use llseek */
static int64_t list_seek(URLContext *h, int64_t pos, int whence)
{
	struct list_mgt *mgt = h->priv_data;
	struct list_item *item,*item1;
	if (whence == AVSEEK_BUFFERED_TIME)
	{
		int64_t buffed_time=0;
		if(mgt->current_item && mgt->current_item->duration>0){
			//av_log(NULL, AV_LOG_INFO, "list_seek uui=%ld,size=%lld\n",mgt->cur_uio,url_fsize(mgt->cur_uio));
			if(mgt->cur_uio && url_fsize(mgt->cur_uio)>0)
{
				//av_log(NULL, AV_LOG_INFO, "list_seek start_time=%ld,pos=%lld\n",mgt->current_item->start_time,url_buffed_pos(mgt->cur_uio));
				buffed_time=mgt->current_item->start_time+url_buffed_pos(mgt->cur_uio)*mgt->current_item->duration/url_fsize(mgt->cur_uio);
			}
			else{
				buffed_time=mgt->current_item->start_time;
			}
		}
		av_log(NULL, AV_LOG_INFO, "list current buffed_time=%lld\n",buffed_time);
		return buffed_time;
	}
	
	av_log(NULL, AV_LOG_INFO, "list_seek pos=%lld,whence=%x\n",pos,whence);
	if (whence == AVSEEK_SIZE)
        return mgt->file_size;
	if (whence == AVSEEK_FULLTIME)
	{
		if(mgt->have_list_end)
			return mgt->full_time;
		else
			return -1;
	}
	
	if(whence == AVSEEK_TO_TIME && pos>=0 && pos<mgt->full_time)
	{
		av_log(NULL, AV_LOG_INFO, "list_seek to Time =%lld,whence=%x\n",pos,whence);
		for(item=mgt->item_list;item;item=item->next)
		{
			if(item->start_time<=pos && pos <item->start_time+item->duration)
			{	
				if(mgt->cur_uio)
					url_fclose(mgt->cur_uio);
				mgt->cur_uio=NULL;
				mgt->current_item=item;
				av_log(NULL, AV_LOG_INFO, "list_seek to item->file =%s\n",item->file);
				return item->start_time;/*pos=0;*/
			}
		}
	}
	av_log(NULL, AV_LOG_INFO, "list_seek failed\n");
	return -1;
Exemple #6
0
static int r3d_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    R3DContext *r3d = s->priv_data;
    Atom atom;
    int ret;

    if (read_atom(s, &atom) < 0) {
        av_log(s, AV_LOG_ERROR, "error reading atom\n");
        return -1;
    }
    if (atom.tag == MKTAG('R','E','D','1')) {
        if ((ret = r3d_read_red1(s)) < 0) {
            av_log(s, AV_LOG_ERROR, "error parsing 'red1' atom\n");
            return ret;
        }
    } else {
        av_log(s, AV_LOG_ERROR, "could not find 'red1' atom\n");
        return -1;
    }

    s->data_offset = url_ftell(s->pb);
    dprintf(s, "data offset %#llx\n", s->data_offset);
    if (url_is_streamed(s->pb))
        return 0;
    // find REOB/REOF/REOS to load index
    url_fseek(s->pb, url_fsize(s->pb)-48-8, SEEK_SET);
    if (read_atom(s, &atom) < 0)
        av_log(s, AV_LOG_ERROR, "error reading end atom\n");

    if (atom.tag != MKTAG('R','E','O','B') &&
            atom.tag != MKTAG('R','E','O','F') &&
            atom.tag != MKTAG('R','E','O','S'))
        goto out;

    r3d_read_reos(s);

    if (r3d->rdvo_offset) {
        url_fseek(s->pb, r3d->rdvo_offset, SEEK_SET);
        if (read_atom(s, &atom) < 0)
            av_log(s, AV_LOG_ERROR, "error reading 'rdvo' atom\n");
        if (atom.tag == MKTAG('R','D','V','O')) {
            if (r3d_read_rdvo(s, &atom) < 0)
                av_log(s, AV_LOG_ERROR, "error parsing 'rdvo' atom\n");
        }
    }

out:
    url_fseek(s->pb, s->data_offset, SEEK_SET);
    return 0;
}
Exemple #7
0
static int gxf_write_material_data_section(AVFormatContext *s)
{
    GXFContext *gxf = s->priv_data;
    AVIOContext *pb = s->pb;
    int64_t pos;
    int len;
    const char *filename = strrchr(s->filename, '/');

    pos = url_ftell(pb);
    avio_wb16(pb, 0); /* size */

    /* name */
    if (filename)
        filename++;
    else
        filename = s->filename;
    len = strlen(filename);

    avio_w8(pb, MAT_NAME);
    avio_w8(pb, strlen(SERVER_PATH) + len + 1);
    avio_write(pb, SERVER_PATH, sizeof(SERVER_PATH) - 1);
    avio_write(pb, filename, len);
    avio_w8(pb, 0);

    /* first field */
    avio_w8(pb, MAT_FIRST_FIELD);
    avio_w8(pb, 4);
    avio_wb32(pb, 0);

    /* last field */
    avio_w8(pb, MAT_LAST_FIELD);
    avio_w8(pb, 4);
    avio_wb32(pb, gxf->nb_fields);

    /* reserved */
    avio_w8(pb, MAT_MARK_IN);
    avio_w8(pb, 4);
    avio_wb32(pb, 0);

    avio_w8(pb, MAT_MARK_OUT);
    avio_w8(pb, 4);
    avio_wb32(pb, gxf->nb_fields);

    /* estimated size */
    avio_w8(pb, MAT_SIZE);
    avio_w8(pb, 4);
    avio_wb32(pb, url_fsize(pb) / 1024);

    return updateSize(pb, pos);
}
Exemple #8
0
static int yuv_read(ByteIOContext *f,
                    int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
{
    ByteIOContext pb1, *pb = &pb1;
    int img_size, ret;
    char fname[1024], *p;
    int size;
    URLContext *h;
    AVImageInfo info1, *info = &info1;

    img_size = url_fsize(f);

    /* XXX: hack hack */
    h = url_fileno(f);
    url_get_filename(h, fname, sizeof(fname));

    if (infer_size(&info->width, &info->height, img_size) < 0) {
        return AVERROR_IO;
    }
    info->pix_fmt = PIX_FMT_YUV420P;

    ret = alloc_cb(opaque, info);
    if (ret)
        return ret;

    size = info->width * info->height;

    p = strrchr(fname, '.');
    if (!p || p[1] != 'Y')
        return AVERROR_IO;

    get_buffer(f, info->pict.data[0], size);

    p[1] = 'U';
    if (url_fopen(pb, fname, URL_RDONLY) < 0)
        return AVERROR_IO;

    get_buffer(pb, info->pict.data[1], size / 4);
    url_fclose(pb);

    p[1] = 'V';
    if (url_fopen(pb, fname, URL_RDONLY) < 0)
        return AVERROR_IO;

    get_buffer(pb, info->pict.data[2], size / 4);
    url_fclose(pb);
    return 0;
}
Exemple #9
0
void ff_ape_parse_tag(AVFormatContext *s)
{
    AVIOContext *pb = s->pb;
    int file_size = url_fsize(pb);
    uint32_t val, fields, tag_bytes;
    uint8_t buf[8];
    int i;

    if (file_size < APE_TAG_FOOTER_BYTES)
        return;

    url_fseek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET);

    avio_read(pb, buf, 8);     /* APETAGEX */
    if (strncmp(buf, "APETAGEX", 8)) {
        return;
    }

    val = avio_rl32(pb);       /* APE tag version */
    if (val > APE_TAG_VERSION) {
        av_log(s, AV_LOG_ERROR, "Unsupported tag version. (>=%d)\n", APE_TAG_VERSION);
        return;
    }

    tag_bytes = avio_rl32(pb); /* tag size */
    if (tag_bytes - APE_TAG_FOOTER_BYTES > (1024 * 1024 * 16)) {
        av_log(s, AV_LOG_ERROR, "Tag size is way too big\n");
        return;
    }

    fields = avio_rl32(pb);    /* number of fields */
    if (fields > 65536) {
        av_log(s, AV_LOG_ERROR, "Too many tag fields (%d)\n", fields);
        return;
    }

    val = avio_rl32(pb);       /* flags */
    if (val & APE_TAG_FLAG_IS_HEADER) {
        av_log(s, AV_LOG_ERROR, "APE Tag is a header\n");
        return;
    }

    url_fseek(pb, file_size - tag_bytes, SEEK_SET);

    for (i=0; i<fields; i++)
        if (ape_tag_read_field(s) < 0) break;
}
Exemple #10
0
static int gxf_write_material_data_section(ByteIOContext *pb, GXFContext *ctx)
{
    int64_t pos;
    const char *filename = strrchr(ctx->fc->filename, '/');

    pos = url_ftell(pb);
    put_be16(pb, 0); /* size */

    /* name */
    if (filename)
        filename++;
    else
        filename = ctx->fc->filename;
    put_byte(pb, MAT_NAME);
    put_byte(pb, strlen(SERVER_PATH) + strlen(filename) + 1);
    put_tag(pb, SERVER_PATH);
    put_tag(pb, filename);
    put_byte(pb, 0);

    /* first field */
    put_byte(pb, MAT_FIRST_FIELD);
    put_byte(pb, 4);
    put_be32(pb, 0);

    /* last field */
    put_byte(pb, MAT_LAST_FIELD);
    put_byte(pb, 4);
    put_be32(pb, ctx->nb_frames);

    /* reserved */
    put_byte(pb, MAT_MARK_IN);
    put_byte(pb, 4);
    put_be32(pb, 0);

    put_byte(pb, MAT_MARK_OUT);
    put_byte(pb, 4);
    put_be32(pb, ctx->nb_frames);

    /* estimated size */
    put_byte(pb, MAT_SIZE);
    put_byte(pb, 4);
    put_be32(pb, url_fsize(pb) / 1024);

    return updateSize(pb, pos);
}
Exemple #11
0
void ff_id3v1_read(AVFormatContext *s)
{
    int ret, filesize;
    uint8_t buf[ID3v1_TAG_SIZE];

    if (!url_is_streamed(s->pb)) {
        /* XXX: change that */
        filesize = url_fsize(s->pb);
        if (filesize > 128) {
            avio_seek(s->pb, filesize - 128, SEEK_SET);
            ret = avio_read(s->pb, buf, ID3v1_TAG_SIZE);
            if (ret == ID3v1_TAG_SIZE) {
                parse_tag(s, buf);
            }
            avio_seek(s->pb, 0, SEEK_SET);
        }
    }
}
Exemple #12
0
static int read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    AVStream *vst;
    int ret;

    vst = av_new_stream(s, 0);
    if (!vst)
        return AVERROR(ENOMEM);

    vst->codec->codec_type = CODEC_TYPE_VIDEO;
    vst->codec->codec_id   = CODEC_ID_CDGRAPHICS;

    /// 75 sectors/sec * 4 packets/sector = 300 packets/sec
    av_set_pts_info(vst, 32, 1, 300);

    ret = url_fsize(s->pb);
    if (ret < 0)
        return ret;
    vst->duration = (ret * vst->time_base.den) / (CDG_PACKET_SIZE * 300);
    return 0;
}
Exemple #13
0
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;
}
int sj_index_load(char *filename, SJ_IndexContext *sj_ic)
{
    ByteIOContext pb;
    register_protocol(&file_protocol);

    if (url_fopen(&pb, filename, URL_RDONLY) < 0) {
        // file could not be open
        return -1;
    }
    sj_ic->size = url_fsize(&pb) - HEADER_SIZE;
    sj_ic->index_num = (sj_ic->size / INDEX_SIZE);
    sj_ic->indexes = av_malloc(sj_ic->index_num * sizeof(Index));

    int64_t magic = get_le64(&pb);
    if (magic != 0x534A2D494E444558LL) {
        // not an index file
        url_fclose(&pb);
        return -2;
    }
    sj_ic->version = get_byte(&pb);
    sj_ic->start_pts = get_le64(&pb);
    sj_ic->start_dts = get_le64(&pb);
    sj_ic->start_timecode.frames = get_byte(&pb);
    sj_ic->start_timecode.seconds = get_byte(&pb);
    sj_ic->start_timecode.minutes = get_byte(&pb);
    sj_ic->start_timecode.hours = get_byte(&pb);

    if (!sj_ic->index_num) {
        // empty index
        url_fclose(&pb);
        return -4;
    }

    for(int i = 0; i < sj_ic->index_num; i++) {
        read_index(&sj_ic->indexes[i], &pb);
    }
    url_fclose(&pb);
    return 0;
}
Exemple #15
0
static int yop_read_seek(AVFormatContext *s, int stream_index,
                         int64_t timestamp, int flags)
{
    YopDecContext *yop = s->priv_data;
    int64_t frame_pos, pos_min, pos_max;
    int frame_count;

    av_free_packet(&yop->video_packet);

    if (!stream_index)
        return -1;

    pos_min        = s->data_offset;
    pos_max        = url_fsize(s->pb) - yop->frame_size;
    frame_count    = (pos_max - pos_min) / yop->frame_size;

    timestamp      = FFMAX(0, FFMIN(frame_count, timestamp));

    frame_pos      = timestamp * yop->frame_size + pos_min;
    yop->odd_frame = timestamp & 1;

    avio_seek(s->pb, frame_pos, SEEK_SET);
    return 0;
}
Exemple #16
0
static int read_header(AVFormatContext *s,
                       AVFormatParameters *ap)
{
    ByteIOContext *pb = s->pb;
    CaffContext *caf  = s->priv_data;
    AVStream *st;
    uint32_t tag = 0;
    int found_data, ret;
    int64_t size;

    url_fskip(pb, 8); /* magic, version, file flags */

    /* audio description chunk */
    if (get_be32(pb) != MKBETAG('d','e','s','c')) {
        av_log(s, AV_LOG_ERROR, "desc chunk not present\n");
        return AVERROR_INVALIDDATA;
    }
    size = get_be64(pb);
    if (size != 32)
        return AVERROR_INVALIDDATA;

    ret = read_desc_chunk(s);
    if (ret)
        return ret;
    st = s->streams[0];

    /* parse each chunk */
    found_data = 0;
    while (!url_feof(pb)) {

        /* stop at data chunk if seeking is not supported or
           data chunk size is unknown */
        if (found_data && (caf->data_size < 0 || url_is_streamed(pb)))
            break;

        tag  = get_be32(pb);
        size = get_be64(pb);
        if (url_feof(pb))
            break;

        switch (tag) {
        case MKBETAG('d','a','t','a'):
            url_fskip(pb, 4); /* edit count */
            caf->data_start = url_ftell(pb);
            caf->data_size  = size < 0 ? -1 : size - 4;
            if (caf->data_size > 0 && !url_is_streamed(pb))
                url_fskip(pb, caf->data_size);
            found_data = 1;
            break;

        /* magic cookie chunk */
        case MKBETAG('k','u','k','i'):
            if (read_kuki_chunk(s, size))
                return AVERROR_INVALIDDATA;
            break;

        /* packet table chunk */
        case MKBETAG('p','a','k','t'):
            if (read_pakt_chunk(s, size))
                return AVERROR_INVALIDDATA;
            break;

        case MKBETAG('i','n','f','o'):
            read_info_chunk(s, size);
            break;

        default:
#define _(x) ((x) >= ' ' ? (x) : ' ')
            av_log(s, AV_LOG_WARNING, "skipping CAF chunk: %08X (%c%c%c%c)\n",
                tag, _(tag>>24), _((tag>>16)&0xFF), _((tag>>8)&0xFF), _(tag&0xFF));
#undef _
        case MKBETAG('f','r','e','e'):
            if (size < 0)
                return AVERROR_INVALIDDATA;
            url_fskip(pb, size);
            break;
        }
    }

    if (!found_data)
        return AVERROR_INVALIDDATA;

    if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
        if (caf->data_size > 0)
            st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
    } else if (st->nb_index_entries) {
        st->codec->bit_rate = st->codec->sample_rate * caf->data_size * 8 /
                              st->duration;
    } else {
        av_log(s, AV_LOG_ERROR, "Missing packet table. It is required when "
                                "block size or frame size are variable.\n");
        return AVERROR_INVALIDDATA;
    }
    s->file_size = url_fsize(pb);
    s->file_size = FFMAX(0, s->file_size);

    av_set_pts_info(st, 64, 1, st->codec->sample_rate);
    st->start_time = 0;

    /* position the stream at the start of data */
    if (caf->data_size >= 0)
        url_fseek(pb, caf->data_start, SEEK_SET);

    return 0;
}
Exemple #17
0
/* XXX: use llseek */
static int64_t list_seek(URLContext *h, int64_t pos, int whence)
{
	struct list_mgt *mgt = h->priv_data;
	URLContext *subh;
	struct list_mgt *submgt;
	struct list_item *item,*item1;	
	struct list_item *cur_item;
	int fulltime;

	if (!h->support_time_seek) {
		if(!mgt->have_list_end && mgt->have_sub_list && mgt->cur_uio){
			if(mgt->cur_uio->support_time_seek){
				h->support_time_seek = 1;
				av_log(NULL, AV_LOG_INFO, "sub list support seek\n");
			}
		}		
	}
	if (whence == AVSEEK_BUFFERED_TIME)
	{
		int64_t buffed_time=0;
		if(mgt->current_item ){
			//av_log(NULL, AV_LOG_INFO, "list_seek uui=%ld,size=%lld\n",mgt->cur_uio,url_fsize(mgt->cur_uio));
			if(mgt->cur_uio && url_fsize(mgt->cur_uio)>0 && mgt->current_item->duration>=0){
				//av_log(NULL, AV_LOG_INFO, "list_seek start_time=%ld,pos=%lld\n",mgt->current_item->start_time,url_buffed_pos(mgt->cur_uio));
				buffed_time=mgt->current_item->start_time+url_buffed_pos(mgt->cur_uio)*mgt->current_item->duration/url_fsize(mgt->cur_uio);
			}
			else{
				buffed_time=mgt->current_item->start_time;
				if(mgt->current_item && (mgt->current_item->flags & ENDLIST_FLAG))
					buffed_time=mgt->full_time;/*read to end list, show full bufferd*/
			}
		}
		//av_log(NULL, AV_LOG_INFO, "list current buffed_time=%lld\n",buffed_time);
		return buffed_time;
	}
	
	if (whence == AVSEEK_SIZE)
        return mgt->file_size;
	av_log(NULL, AV_LOG_INFO, "list_seek pos=%lld,whence=%x\n",pos,whence);
	if (whence == AVSEEK_FULLTIME)
	{
		if(mgt->have_list_end){
			av_log(NULL, AV_LOG_INFO, "return mgt->full_timet=%d\n",mgt->full_time);
			return mgt->full_time;
		}else if(mgt->have_sub_list && mgt->cur_uio){
				subh = mgt->cur_uio->opaque;
				av_log(NULL, AV_LOG_INFO, "seek sub file for fulltime\n");
				return list_seek(subh,pos, whence);
		}else
			return -1;
	}
	
	if(whence == AVSEEK_TO_TIME)
	{
		av_log(NULL, AV_LOG_INFO, "list_seek to Time =%lld,whence=%x,have sublist:%d\n",pos,whence,mgt->have_sub_list);
		if (!mgt->have_sub_list) {
			if(pos>=0 && pos<mgt->full_time) {

				for(item=mgt->item_list;item;item=item->next)
				{
					
					if(item->start_time<=pos && pos <item->start_time+item->duration)
					{	
						if(mgt->cur_uio){
							
							url_fclose(mgt->cur_uio);

						}
						
						mgt->cur_uio=NULL;
						mgt->current_item=item;
						av_log(NULL, AV_LOG_INFO, "list_seek to item->file =%s\n",item->file);
						return item->start_time;/*pos=0;*/
					}
				}
			}
		} else {
		    if(!mgt->cur_uio){
   				av_log(NULL, AV_LOG_ERROR, "byteio already close, seek failed!\n");
		        return -1;
		    }
			subh = mgt->cur_uio->opaque;	
			submgt = subh->priv_data;
			if(subh && submgt) {
				av_log(NULL, AV_LOG_INFO, "have sub list, go2 low level, location=%s\n",submgt->location);
				return list_seek(subh, pos, whence);
			}
		}
	}
	av_log(NULL, AV_LOG_INFO, "list_seek failed\n");
	return -1;
}
Exemple #18
0
int
voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
{
    VocDecContext *voc = s->priv_data;
    AVCodecContext *dec = st->codec;
    ByteIOContext *pb = s->pb;
    VocType type;
    int size;
    int sample_rate = 0;
    int channels = 1;

    while (!voc->remaining_size) {
        type = get_byte(pb);
        if (type == VOC_TYPE_EOF)
            return AVERROR(EIO);
        voc->remaining_size = get_le24(pb);
        if (!voc->remaining_size) {
            if (url_is_streamed(s->pb))
                return AVERROR(EIO);
            voc->remaining_size = url_fsize(pb) - url_ftell(pb);
        }
        max_size -= 4;

        switch (type) {
        case VOC_TYPE_VOICE_DATA:
            dec->sample_rate = 1000000 / (256 - get_byte(pb));
            if (sample_rate)
                dec->sample_rate = sample_rate;
            dec->channels = channels;
            dec->codec_id = ff_codec_get_id(ff_voc_codec_tags, get_byte(pb));
            dec->bits_per_coded_sample = av_get_bits_per_sample(dec->codec_id);
            voc->remaining_size -= 2;
            max_size -= 2;
            channels = 1;
            break;

        case VOC_TYPE_VOICE_DATA_CONT:
            break;

        case VOC_TYPE_EXTENDED:
            sample_rate = get_le16(pb);
            get_byte(pb);
            channels = get_byte(pb) + 1;
            sample_rate = 256000000 / (channels * (65536 - sample_rate));
            voc->remaining_size = 0;
            max_size -= 4;
            break;

        case VOC_TYPE_NEW_VOICE_DATA:
            dec->sample_rate = get_le32(pb);
            dec->bits_per_coded_sample = get_byte(pb);
            dec->channels = get_byte(pb);
            dec->codec_id = ff_codec_get_id(ff_voc_codec_tags, get_le16(pb));
            url_fskip(pb, 4);
            voc->remaining_size -= 12;
            max_size -= 12;
            break;

        default:
            url_fskip(pb, voc->remaining_size);
            max_size -= voc->remaining_size;
            voc->remaining_size = 0;
            break;
        }
    }

    dec->bit_rate = dec->sample_rate * dec->bits_per_coded_sample;

    if (max_size <= 0)
        max_size = 2048;
    size = FFMIN(voc->remaining_size, max_size);
    voc->remaining_size -= size;
    return av_get_packet(pb, pkt, size);
}
Exemple #19
0
static void ape_parse_tag(AVFormatContext *s)
{
    ByteIOContext *pb = &s->pb;
    int file_size = url_fsize(pb);
    uint32_t val, fields, tag_bytes;
    uint8_t buf[8];
    int i;

    if (file_size < APE_TAG_FOOTER_BYTES)
        return;

    url_fseek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET);

    get_buffer(pb, buf, 8);    /* APETAGEX */
    if (strncmp(buf, "APETAGEX", 8)) {
        av_log(NULL, AV_LOG_ERROR, "Invalid APE Tags\n");
        return;
    }

    val = get_le32(pb);        /* APE tag version */
    if (val > APE_TAG_VERSION) {
        av_log(NULL, AV_LOG_ERROR, "Unsupported tag version. (>=%d)\n", APE_TAG_VERSION);
        return;
    }

    tag_bytes = get_le32(pb);  /* tag size */
    if (tag_bytes - APE_TAG_FOOTER_BYTES > (1024 * 1024 * 16)) {
        av_log(NULL, AV_LOG_ERROR, "Tag size is way too big\n");
        return;
    }

    fields = get_le32(pb);     /* number of fields */
    if (fields > 65536) {
        av_log(NULL, AV_LOG_ERROR, "Too many tag fields (%d)\n", fields);
        return;
    }

    val = get_le32(pb);        /* flags */
    if (val & APE_TAG_FLAG_IS_HEADER) {
        av_log(NULL, AV_LOG_ERROR, "APE Tag is a header\n");
        return;
    }

    if (val & APE_TAG_FLAG_CONTAINS_HEADER)
        tag_bytes += 2*APE_TAG_FOOTER_BYTES;

    url_fseek(pb, file_size - tag_bytes, SEEK_SET);

    for (i=0; i<fields; i++)
        ape_tag_read_field(s);

#if ENABLE_DEBUG
    av_log(NULL, AV_LOG_DEBUG, "\nAPE Tags:\n\n");
    av_log(NULL, AV_LOG_DEBUG, "title     = %s\n", s->title);
    av_log(NULL, AV_LOG_DEBUG, "author    = %s\n", s->author);
    av_log(NULL, AV_LOG_DEBUG, "copyright = %s\n", s->copyright);
    av_log(NULL, AV_LOG_DEBUG, "comment   = %s\n", s->comment);
    av_log(NULL, AV_LOG_DEBUG, "album     = %s\n", s->album);
    av_log(NULL, AV_LOG_DEBUG, "year      = %d\n", s->year);
    av_log(NULL, AV_LOG_DEBUG, "track     = %d\n", s->track);
    av_log(NULL, AV_LOG_DEBUG, "genre     = %s\n", s->genre);
#endif
}