changeset 389:e14fcd57ad2f libavformat

decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
author michael
date Mon, 15 Mar 2004 03:29:32 +0000
parents 9af30d452a0a
children 3a40642dc4df
files avio.h aviobuf.c raw.c
diffstat 3 files changed, 42 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/avio.h	Sun Mar 14 19:40:43 2004 +0000
+++ b/avio.h	Mon Mar 15 03:29:32 2004 +0000
@@ -119,6 +119,7 @@
 void put_flush_packet(ByteIOContext *s);
 
 int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
+int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size);
 int get_byte(ByteIOContext *s);
 unsigned int get_le32(ByteIOContext *s);
 uint64_t get_le64(ByteIOContext *s);
--- a/aviobuf.c	Sun Mar 14 19:40:43 2004 +0000
+++ b/aviobuf.c	Mon Mar 15 03:29:32 2004 +0000
@@ -309,6 +309,22 @@
     return size1 - size;
 }
 
+int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size)
+{
+    int len;
+
+    len = s->buf_end - s->buf_ptr;
+    if (len == 0) {
+        fill_buffer(s);
+        len = s->buf_end - s->buf_ptr;
+    }
+    if (len > size)
+        len = size;
+    memcpy(buf, s->buf_ptr, len);
+    s->buf_ptr += len;
+    return len;
+}
+
 unsigned int get_le16(ByteIOContext *s)
 {
     unsigned int val;
--- a/raw.c	Sun Mar 14 19:40:43 2004 +0000
+++ b/raw.c	Mon Mar 15 03:29:32 2004 +0000
@@ -102,6 +102,25 @@
     return ret;
 }
 
+static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    int ret, size;
+
+    size = RAW_PACKET_SIZE;
+
+    if (av_new_packet(pkt, size) < 0)
+        return -EIO;
+
+    pkt->stream_index = 0;
+    ret = get_partial_buffer(&s->pb, pkt->data, size);
+    if (ret <= 0) {
+        av_free_packet(pkt);
+        return -EIO;
+    }
+    pkt->size = ret;
+    return ret;
+}
+
 static int raw_read_close(AVFormatContext *s)
 {
     return 0;
@@ -247,7 +266,7 @@
     0,
     NULL,
     ac3_read_header,
-    raw_read_packet,
+    raw_read_partial_packet,
     raw_read_close,
     .extensions = "ac3",
 };
@@ -273,7 +292,7 @@
     0,
     h263_probe,
     video_read_header,
-    raw_read_packet,
+    raw_read_partial_packet,
     raw_read_close,
 //    .extensions = "h263", //FIXME remove after writing mpeg4_probe
     .value = CODEC_ID_H263,
@@ -300,7 +319,7 @@
     0,
     NULL /*mpegvideo_probe*/,
     video_read_header,
-    raw_read_packet,
+    raw_read_partial_packet,
     raw_read_close,
     .extensions = "m4v", //FIXME remove after writing mpeg4_probe
     .value = CODEC_ID_MPEG4,
@@ -327,7 +346,7 @@
     0,
     NULL /*mpegvideo_probe*/,
     video_read_header,
-    raw_read_packet,
+    raw_read_partial_packet,
     raw_read_close,
     .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe
     .value = CODEC_ID_H264,
@@ -354,7 +373,7 @@
     0,
     mpegvideo_probe,
     video_read_header,
-    raw_read_packet,
+    raw_read_partial_packet,
     raw_read_close,
     .value = CODEC_ID_MPEG1VIDEO,
 };
@@ -380,7 +399,7 @@
     0,
     NULL,
     video_read_header,
-    raw_read_packet,
+    raw_read_partial_packet,
     raw_read_close,
     .extensions = "mjpg,mjpeg",
     .value = CODEC_ID_MJPEG,