Commit 66d2ff2a authored by Fabrice Bellard's avatar Fabrice Bellard

fixed memory free (no free necessary for private data) - added better support for automatic testing

Originally committed as revision 590 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 360d33c9
/* /*
* FFM (ffserver live feed) encoder and decoder * FFM (ffserver live feed) encoder and decoder
* Copyright (c) 2001 Gerard Lantau. * Copyright (c) 2001 Fabrice Bellard.
* *
* This program is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or
* it under the terms of the GNU General Public License as published by * modify it under the terms of the GNU Lesser General Public
* the Free Software Foundation; either version 2 of the License, or * License as published by the Free Software Foundation; either
* (at your option) any later version. * version 2 of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU Lesser General Public
* along with this program; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "avformat.h" #include "avformat.h"
#include <unistd.h> #include <unistd.h>
...@@ -48,7 +48,7 @@ typedef struct FFMContext { ...@@ -48,7 +48,7 @@ typedef struct FFMContext {
int frame_offset; int frame_offset;
INT64 pts; INT64 pts;
UINT8 *packet_ptr, *packet_end; UINT8 *packet_ptr, *packet_end;
UINT8 packet[1]; /* must be last */ UINT8 packet[FFM_PACKET_SIZE];
} FFMContext; } FFMContext;
/* disable pts hack for testing */ /* disable pts hack for testing */
...@@ -249,6 +249,15 @@ static int ffm_write_trailer(AVFormatContext *s) ...@@ -249,6 +249,15 @@ static int ffm_write_trailer(AVFormatContext *s)
put_flush_packet(pb); put_flush_packet(pb);
if (!url_is_streamed(pb)) {
INT64 size;
/* update the write offset */
size = url_ftell(pb);
url_fseek(pb, 8, SEEK_SET);
put_be64(pb, size);
put_flush_packet(pb);
}
for(i=0;i<s->nb_streams;i++) for(i=0;i<s->nb_streams;i++)
av_freep(&s->streams[i]->priv_data); av_freep(&s->streams[i]->priv_data);
return 0; return 0;
...@@ -263,8 +272,11 @@ static int ffm_is_avail_data(AVFormatContext *s, int size) ...@@ -263,8 +272,11 @@ static int ffm_is_avail_data(AVFormatContext *s, int size)
int len; int len;
len = ffm->packet_end - ffm->packet_ptr; len = ffm->packet_end - ffm->packet_ptr;
if (!ffm_nopts) {
/* XXX: I don't understand this test, so I disabled it for testing */
if (size <= len) if (size <= len)
return 1; return 1;
}
pos = url_ftell(&s->pb); pos = url_ftell(&s->pb);
if (pos == ffm->write_index) { if (pos == ffm->write_index) {
/* exactly at the end of stream */ /* exactly at the end of stream */
...@@ -439,15 +451,16 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -439,15 +451,16 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
switch(ffm->read_state) { switch(ffm->read_state) {
case READ_HEADER: case READ_HEADER:
if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) {
return -EAGAIN; return -EAGAIN;
}
#if 0 #if 0
printf("pos=%08Lx spos=%Lx, write_index=%Lx size=%Lx\n", printf("pos=%08Lx spos=%Lx, write_index=%Lx size=%Lx\n",
url_ftell(&s->pb), s->pb.pos, ffm->write_index, ffm->file_size); url_ftell(&s->pb), s->pb.pos, ffm->write_index, ffm->file_size);
#endif #endif
if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) != FRAME_HEADER_SIZE) if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
FRAME_HEADER_SIZE)
return -EAGAIN; return -EAGAIN;
#if 0 #if 0
{ {
int i; int i;
...@@ -604,28 +617,27 @@ static int ffm_read_close(AVFormatContext *s) ...@@ -604,28 +617,27 @@ static int ffm_read_close(AVFormatContext *s)
st = s->streams[i]; st = s->streams[i];
av_freep(&st->priv_data); av_freep(&st->priv_data);
} }
av_freep(&s->priv_data);
return 0; return 0;
} }
static int ffm_probe(AVProbeData *p) static int ffm_probe(AVProbeData *p)
{ {
if (memcmp(p->buf, "FFM", 3) == 0) if (p->buf_size >= 4 &&
p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' &&
p->buf[3] == '1')
return AVPROBE_SCORE_MAX + 1; return AVPROBE_SCORE_MAX + 1;
return 0; return 0;
} }
AVInputFormat ffm_iformat = { AVInputFormat ffm_iformat = {
"ffm", "ffm",
"ffm format", "ffm format",
sizeof(FFMContext) + FFM_PACKET_SIZE, sizeof(FFMContext),
ffm_probe, ffm_probe,
ffm_read_header, ffm_read_header,
ffm_read_packet, ffm_read_packet,
ffm_read_close, ffm_read_close,
ffm_seek, ffm_seek,
extensions: "ffm",
}; };
AVOutputFormat ffm_oformat = { AVOutputFormat ffm_oformat = {
...@@ -633,7 +645,7 @@ AVOutputFormat ffm_oformat = { ...@@ -633,7 +645,7 @@ AVOutputFormat ffm_oformat = {
"ffm format", "ffm format",
"", "",
"ffm", "ffm",
sizeof(FFMContext) + FFM_PACKET_SIZE, sizeof(FFMContext),
/* not really used */ /* not really used */
CODEC_ID_MP2, CODEC_ID_MP2,
CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG1VIDEO,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment