do not write ffm write index by default, detect if file is being written and return EOF

Originally committed as revision 18063 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Baptiste Coudurier 2009-03-20 01:23:33 +00:00
parent cf16c17a69
commit b9edbe9953
4 changed files with 24 additions and 31 deletions

View File

@ -2121,7 +2121,7 @@ static int av_encode(AVFormatContext **output_files,
/* read a frame from it and output it in the fifo */
is = input_files[file_index];
ret= av_read_frame(is, &pkt);
if(ret == AVERROR(EAGAIN) && strcmp(is->iformat->name, "ffm")){
if(ret == AVERROR(EAGAIN)){
no_packet[file_index]=1;
no_packet_count++;
continue;

View File

@ -66,19 +66,25 @@ static int ffm_is_avail_data(AVFormatContext *s, int size)
if (size <= len)
return 1;
pos = url_ftell(s->pb);
if (!ffm->write_index) {
if (pos == ffm->file_size);
return AVERROR_EOF;
avail_size = ffm->file_size - pos;
} else {
if (pos == ffm->write_index) {
/* exactly at the end of stream */
return 0;
return AVERROR(EAGAIN);
} else if (pos < ffm->write_index) {
avail_size = ffm->write_index - pos;
} else {
avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
}
}
avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
if (size <= avail_size)
return 1;
else
return 0;
return AVERROR(EAGAIN);
}
/* first is true if we read the frame header */
@ -251,7 +257,8 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* get also filesize */
if (!url_is_streamed(pb)) {
ffm->file_size = url_fsize(pb);
adjust_write_index(s);
if (ffm->write_index)
adjust_write_index(s);
} else {
ffm->file_size = (UINT64_C(1) << 63) - 1;
}
@ -360,24 +367,21 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int size;
FFMContext *ffm = s->priv_data;
int duration;
if (url_fsize(s->pb) == FFM_PACKET_SIZE)
return -1;
int duration, ret;
switch(ffm->read_state) {
case READ_HEADER:
if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) {
return AVERROR(EAGAIN);
}
if ((ret = ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) < 0)
return ret;
dprintf(s, "pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n",
url_ftell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size);
if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
FRAME_HEADER_SIZE)
return AVERROR(EAGAIN);
return -1;
if (ffm->header[1] & FLAG_DTS)
if (ffm_read_data(s, ffm->header+16, 4, 1) != 4)
return AVERROR(EAGAIN);
return -1;
#if 0
av_hexdump_log(s, AV_LOG_DEBUG, ffm->header, FRAME_HEADER_SIZE);
#endif
@ -385,9 +389,8 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
/* fall thru */
case READ_DATA:
size = AV_RB24(ffm->header + 2);
if (!ffm_is_avail_data(s, size)) {
return AVERROR(EAGAIN);
}
if ((ret = ffm_is_avail_data(s, size)) < 0)
return ret;
duration = AV_RB24(ffm->header + 5);
@ -397,7 +400,7 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_ERROR, "invalid stream index %d\n", pkt->stream_index);
av_free_packet(pkt);
ffm->read_state = READ_HEADER;
return AVERROR(EAGAIN);
return -1;
}
pkt->pos = url_ftell(s->pb);
if (ffm->header[1] & FLAG_KEY_FRAME)
@ -407,7 +410,7 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ffm_read_data(s, pkt->data, size, 0) != size) {
/* bad case: desynchronized packet. we cancel all the packet loading */
av_free_packet(pkt);
return AVERROR(EAGAIN);
return -1;
}
pkt->pts = AV_RB64(ffm->header+8);
if (ffm->header[1] & FLAG_DTS)

View File

@ -93,8 +93,7 @@ static int ffm_write_header(AVFormatContext *s)
/* header */
put_le32(pb, MKTAG('F', 'F', 'M', '1'));
put_be32(pb, ffm->packet_size);
/* XXX: store write position in other file ? */
put_be64(pb, ffm->packet_size); /* current write position */
put_be64(pb, 0); /* current write position */
put_be32(pb, s->nb_streams);
bit_rate = 0;
@ -224,15 +223,6 @@ static int ffm_write_trailer(AVFormatContext *s)
put_flush_packet(pb);
if (!url_is_streamed(pb)) {
int64_t size;
/* update the write offset */
size = url_ftell(pb);
url_fseek(pb, 8, SEEK_SET);
put_be64(pb, size);
put_flush_packet(pb);
}
return 0;
}

View File

@ -21,9 +21,9 @@ c0cc2ae4df6a8b3df84986929a393116 *./tests/data/b-libav.ts
1b28a16652bb8ac528b33f7478ca18b6 *./tests/data/b-libav.swf
335771 ./tests/data/b-libav.swf
./tests/data/b-libav.swf CRC=0xe14e8847
3dbacdc3fccb551f8ab54c32f648e7a8 *./tests/data/b-libav.ffm
49d04c063b7741d3ee8f85c92baa69bf *./tests/data/b-libav.ffm
380928 ./tests/data/b-libav.ffm
./tests/data/b-libav.ffm CRC=0x2b71a386
./tests/data/b-libav.ffm CRC=0x00000001
8617c30b4e862199555fd75890473e66 *./tests/data/b-libav.flv
335833 ./tests/data/b-libav.flv
./tests/data/b-libav.flv CRC=0xe14e8847