aboutsummaryrefslogtreecommitdiffstats
path: root/libav/avidec.c
diff options
context:
space:
mode:
authorZdenek Kabelac <kabi@informatics.muni.cz>2002-11-11 09:21:59 +0000
committerZdenek Kabelac <kabi@informatics.muni.cz>2002-11-11 09:21:59 +0000
commit1101abfe775b2efe82964064b68a84a4c81063dc (patch)
tree6db3387295f424a9cbd265d67504867f0f6652b8 /libav/avidec.c
parent0570bf06d45ae3e5c73cb0b32b2101e2668f91e9 (diff)
downloadffmpeg-1101abfe775b2efe82964064b68a84a4c81063dc.tar.gz
* cleanup statics & const
* some minor initial parsing fixes (yet it's very simple parser at this moment) Originally committed as revision 1189 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libav/avidec.c')
-rw-r--r--libav/avidec.c79
1 files changed, 38 insertions, 41 deletions
diff --git a/libav/avidec.c b/libav/avidec.c
index 80ea928ffa..eb3774eee4 100644
--- a/libav/avidec.c
+++ b/libav/avidec.c
@@ -31,10 +31,11 @@ typedef struct {
INT64 movi_end;
offset_t movi_list;
AVIIndex *first, *last;
+ int framenum;
} AVIContext;
#ifdef DEBUG
-void print_tag(const char *str, unsigned int tag, int size)
+static void print_tag(const char *str, unsigned int tag, int size)
{
printf("%s: tag=%c%c%c%c size=0x%x\n",
str, tag & 0xff,
@@ -45,7 +46,7 @@ void print_tag(const char *str, unsigned int tag, int size)
}
#endif
-int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
+static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
AVIContext *avi = s->priv_data;
ByteIOContext *pb = &s->pb;
@@ -63,11 +64,12 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
tag = get_le32(pb);
if (tag != MKTAG('A', 'V', 'I', ' '))
return -1;
-
+
/* first list tag */
stream_index = -1;
codec_type = -1;
frame_period = 0;
+ avi->framenum = 0;
for(;;) {
if (url_feof(pb))
goto fail;
@@ -93,19 +95,18 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
break;
case MKTAG('a', 'v', 'i', 'h'):
- /* avi header */
+ /* avi header */
+ /* using frame_period is bad idea */
frame_period = get_le32(pb);
bit_rate = get_le32(pb) * 8;
- url_fskip(pb, 4 * 4);
+ url_fskip(pb, 4 * 4);
s->nb_streams = get_le32(pb);
for(i=0;i<s->nb_streams;i++) {
- AVStream *st;
- st = av_malloc(sizeof(AVStream));
+ AVStream *st = av_mallocz(sizeof(AVStream));
if (!st)
goto fail;
- memset(st, 0, sizeof(AVStream));
s->streams[i] = st;
- }
+ }
url_fskip(pb, size - 7 * 4);
break;
case MKTAG('s', 't', 'r', 'h'):
@@ -122,16 +123,13 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_le32(pb); /* XXX: initial frame ? */
get_le32(pb); /* scale */
get_le32(pb); /* rate */
- url_fskip(pb, size - 7 * 4);
+ size -= 6 * 4;
break;
case MKTAG('a', 'u', 'd', 's'):
codec_type = CODEC_TYPE_AUDIO;
/* nothing really useful */
- url_fskip(pb, size - 4);
- break;
- default:
- goto fail;
}
+ url_fskip(pb, size - 4);
break;
case MKTAG('s', 't', 'r', 'f'):
/* stream header */
@@ -159,7 +157,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
url_fskip(pb, size - 5 * 4);
break;
- case CODEC_TYPE_AUDIO:
+ case CODEC_TYPE_AUDIO:
get_wav_header(pb, &st->codec, (size >= 18));
break;
default:
@@ -184,49 +182,48 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
return -1;
}
-
+
return 0;
}
-int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
+static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
{
AVIContext *avi = s->priv_data;
ByteIOContext *pb = &s->pb;
int n, d1, d2, size;
-
- find_next:
- if (url_feof(pb) || url_ftell(pb) >= avi->movi_end)
- return -1;
- d1 = get_byte(pb);
- if (d1 < '0' || d1 > '9')
- goto find_next;
- d2 = get_byte(pb);
- if (d2 < '0' || d2 > '9')
- goto find_next;
- n = (d1 - '0') * 10 + (d2 - '0');
-
- if (n < 0 || n >= s->nb_streams)
- goto find_next;
-
- d1 = get_byte(pb);
- d2 = get_byte(pb);
- if ((d1 != 'd' && d2 != 'c') &&
- (d1 != 'w' && d2 != 'b'))
- goto find_next;
-
+
+ for(;;) {
+ if (url_feof(pb) || url_ftell(pb) >= avi->movi_end)
+ return -1;
+ d1 = get_byte(pb) - '0';
+ d2 = get_byte(pb) - '0';
+ if (d1 < 0 || d1 > 9 || d2 < 0 || d2 > 9)
+ continue;
+
+ n = d1 * 10 + d2;
+ if (n < 0 || n >= s->nb_streams)
+ continue;
+
+ d1 = get_byte(pb);
+ d2 = get_byte(pb);
+ if ((d1 == 'd' && d2 == 'c')
+ || (d1 == 'w' && d2 == 'b'))
+ break;
+ }
size = get_le32(pb);
av_new_packet(pkt, size);
pkt->stream_index = n;
+ pkt->pts = avi->framenum++;
get_buffer(pb, pkt->data, pkt->size);
-
+
if (size & 1)
get_byte(pb);
-
+
return 0;
}
-int avi_read_close(AVFormatContext *s)
+static int avi_read_close(AVFormatContext *s)
{
return 0;
}