[FFmpeg-devel] [PATCH] aviobuf.c cleanup
Reimar Döffinger
Reimar.Doeffinger
Fri Jan 16 11:23:01 CET 2009
Hello,
I just noticed I had these changes lying around.
There is some nonsense in that file like a "return -1234;".
Also this check:
if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
return -1;
Causes a warning for comparing signed and unsigned and I am not
completely sure it is actually working as expected.
I don't want to make a lot of effort, so just cherry-pick the parts
I can apply or that you don't want, I'll apply them separately or remove them
and send the remainder as a new patch.
Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/aviobuf.c
===================================================================
--- libavformat/aviobuf.c (revision 16631)
+++ libavformat/aviobuf.c (working copy)
@@ -20,6 +20,7 @@
*/
#include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "avio.h"
#include <stdarg.h>
@@ -740,7 +741,7 @@
if (new_allocated_size > d->allocated_size) {
d->buffer = av_realloc(d->buffer, new_allocated_size);
if(d->buffer == NULL)
- return -1234;
+ return AVERROR(ENOMEM);
d->allocated_size = new_allocated_size;
}
memcpy(d->buffer + d->pos, buf, buf_size);
@@ -756,10 +757,7 @@
int ret;
/* packetized write: output the header */
- buf1[0] = (buf_size >> 24);
- buf1[1] = (buf_size >> 16);
- buf1[2] = (buf_size >> 8);
- buf1[3] = (buf_size);
+ AV_WB32(buf1, buf_size);
ret= dyn_buf_write(opaque, buf1, 4);
if(ret < 0)
return ret;
@@ -785,28 +783,20 @@
static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size)
{
DynBuffer *d;
- int io_buffer_size, ret;
+ int ret;
+ unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
- if (max_packet_size)
- io_buffer_size = max_packet_size;
- else
- io_buffer_size = 1024;
-
if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
return -1;
- d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
+ d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
if (!d)
- return -1;
+ return AVERROR(ENOMEM);
*s = av_mallocz(sizeof(ByteIOContext));
if(!*s) {
av_free(d);
return AVERROR(ENOMEM);
}
d->io_buffer_size = io_buffer_size;
- d->buffer = NULL;
- d->pos = 0;
- d->size = 0;
- d->allocated_size = 0;
ret = init_put_byte(*s, d->io_buffer, io_buffer_size,
1, d, NULL,
max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
More information about the ffmpeg-devel
mailing list