Revision b9edbe99 libavformat/ffmdec.c

View differences:

libavformat/ffmdec.c
66 66
    if (size <= len)
67 67
        return 1;
68 68
    pos = url_ftell(s->pb);
69
    if (!ffm->write_index) {
70
        if (pos == ffm->file_size);
71
            return AVERROR_EOF;
72
        avail_size = ffm->file_size - pos;
73
    } else {
69 74
    if (pos == ffm->write_index) {
70 75
        /* exactly at the end of stream */
71
        return 0;
76
        return AVERROR(EAGAIN);
72 77
    } else if (pos < ffm->write_index) {
73 78
        avail_size = ffm->write_index - pos;
74 79
    } else {
75 80
        avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
76 81
    }
82
    }
77 83
    avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
78 84
    if (size <= avail_size)
79 85
        return 1;
80 86
    else
81
        return 0;
87
        return AVERROR(EAGAIN);
82 88
}
83 89

  
84 90
/* first is true if we read the frame header */
......
251 257
    /* get also filesize */
252 258
    if (!url_is_streamed(pb)) {
253 259
        ffm->file_size = url_fsize(pb);
254
        adjust_write_index(s);
260
        if (ffm->write_index)
261
            adjust_write_index(s);
255 262
    } else {
256 263
        ffm->file_size = (UINT64_C(1) << 63) - 1;
257 264
    }
......
360 367
{
361 368
    int size;
362 369
    FFMContext *ffm = s->priv_data;
363
    int duration;
364

  
365
    if (url_fsize(s->pb) == FFM_PACKET_SIZE)
366
        return -1;
370
    int duration, ret;
367 371

  
368 372
    switch(ffm->read_state) {
369 373
    case READ_HEADER:
370
        if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) {
371
            return AVERROR(EAGAIN);
372
        }
374
        if ((ret = ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) < 0)
375
            return ret;
376

  
373 377
        dprintf(s, "pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n",
374 378
               url_ftell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size);
375 379
        if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
376 380
            FRAME_HEADER_SIZE)
377
            return AVERROR(EAGAIN);
381
            return -1;
378 382
        if (ffm->header[1] & FLAG_DTS)
379 383
            if (ffm_read_data(s, ffm->header+16, 4, 1) != 4)
380
                return AVERROR(EAGAIN);
384
                return -1;
381 385
#if 0
382 386
        av_hexdump_log(s, AV_LOG_DEBUG, ffm->header, FRAME_HEADER_SIZE);
383 387
#endif
......
385 389
        /* fall thru */
386 390
    case READ_DATA:
387 391
        size = AV_RB24(ffm->header + 2);
388
        if (!ffm_is_avail_data(s, size)) {
389
            return AVERROR(EAGAIN);
390
        }
392
        if ((ret = ffm_is_avail_data(s, size)) < 0)
393
            return ret;
391 394

  
392 395
        duration = AV_RB24(ffm->header + 5);
393 396

  
......
397 400
            av_log(s, AV_LOG_ERROR, "invalid stream index %d\n", pkt->stream_index);
398 401
            av_free_packet(pkt);
399 402
            ffm->read_state = READ_HEADER;
400
            return AVERROR(EAGAIN);
403
            return -1;
401 404
        }
402 405
        pkt->pos = url_ftell(s->pb);
403 406
        if (ffm->header[1] & FLAG_KEY_FRAME)
......
407 410
        if (ffm_read_data(s, pkt->data, size, 0) != size) {
408 411
            /* bad case: desynchronized packet. we cancel all the packet loading */
409 412
            av_free_packet(pkt);
410
            return AVERROR(EAGAIN);
413
            return -1;
411 414
        }
412 415
        pkt->pts = AV_RB64(ffm->header+8);
413 416
        if (ffm->header[1] & FLAG_DTS)

Also available in: Unified diff