Revision b9edbe99

View differences:

ffmpeg.c
2121 2121
        /* read a frame from it and output it in the fifo */
2122 2122
        is = input_files[file_index];
2123 2123
        ret= av_read_frame(is, &pkt);
2124
        if(ret == AVERROR(EAGAIN) && strcmp(is->iformat->name, "ffm")){
2124
        if(ret == AVERROR(EAGAIN)){
2125 2125
            no_packet[file_index]=1;
2126 2126
            no_packet_count++;
2127 2127
            continue;
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)
libavformat/ffmenc.c
93 93
    /* header */
94 94
    put_le32(pb, MKTAG('F', 'F', 'M', '1'));
95 95
    put_be32(pb, ffm->packet_size);
96
    /* XXX: store write position in other file ? */
97
    put_be64(pb, ffm->packet_size); /* current write position */
96
    put_be64(pb, 0); /* current write position */
98 97

  
99 98
    put_be32(pb, s->nb_streams);
100 99
    bit_rate = 0;
......
224 223

  
225 224
    put_flush_packet(pb);
226 225

  
227
    if (!url_is_streamed(pb)) {
228
        int64_t size;
229
        /* update the write offset */
230
        size = url_ftell(pb);
231
        url_fseek(pb, 8, SEEK_SET);
232
        put_be64(pb, size);
233
        put_flush_packet(pb);
234
    }
235

  
236 226
    return 0;
237 227
}
238 228

  
tests/libav.regression.ref
21 21
1b28a16652bb8ac528b33f7478ca18b6 *./tests/data/b-libav.swf
22 22
335771 ./tests/data/b-libav.swf
23 23
./tests/data/b-libav.swf CRC=0xe14e8847
24
3dbacdc3fccb551f8ab54c32f648e7a8 *./tests/data/b-libav.ffm
24
49d04c063b7741d3ee8f85c92baa69bf *./tests/data/b-libav.ffm
25 25
380928 ./tests/data/b-libav.ffm
26
./tests/data/b-libav.ffm CRC=0x2b71a386
26
./tests/data/b-libav.ffm CRC=0x00000001
27 27
8617c30b4e862199555fd75890473e66 *./tests/data/b-libav.flv
28 28
335833 ./tests/data/b-libav.flv
29 29
./tests/data/b-libav.flv CRC=0xe14e8847

Also available in: Unified diff