[MPlayer-cvslog] r36604 - trunk/libvo/vo_bl.c
reimar
subversion at mplayerhq.hu
Sat Jan 18 14:43:11 CET 2014
Author: reimar
Date: Sat Jan 18 14:43:10 2014
New Revision: 36604
Log:
vo_bl: Do memory allocation only in one place.
This avoids duplicating code.
Modified:
trunk/libvo/vo_bl.c
Modified: trunk/libvo/vo_bl.c
==============================================================================
--- trunk/libvo/vo_bl.c Sat Jan 18 14:36:37 2014 (r36603)
+++ trunk/libvo/vo_bl.c Sat Jan 18 14:43:10 2014 (r36604)
@@ -237,11 +237,9 @@ static int config(uint32_t width, uint32
if (reset_width || reset_height) {
if (reset_width) { /* use width of movie */
bl->width = width;
- bl_packet->width = htons(bl->width);
}
if (reset_height) { /* use height of movie */
bl->height = height;
- bl_packet->height = htons(bl->height);
}
/* check for maximum size of UDP packet */
if (12 + bl->width*bl->height*bl->channels > 65507) {
@@ -249,7 +247,9 @@ static int config(uint32_t width, uint32
bl->width, bl->height, bl->channels);
goto err_out;
}
- /* resize frame and tmp buffers */
+ }
+
+ /* resize or allocate frame and tmp buffers */
bl_size = 12 + bl->width*bl->height*bl->channels;
ptr = realloc(bl_packet, 12 + bl->width*bl->height*3); /* space for header and image data */
if (ptr)
@@ -266,7 +266,12 @@ static int config(uint32_t width, uint32
mp_msg(MSGT_VO, MSGL_ERR, "bl: out of memory error\n");
goto err_out;
}
- }
+
+ bl_packet->magic = htonl(0x23542666);
+ bl_packet->width = htons(bl->width);
+ bl_packet->height = htons(bl->height);
+ bl_packet->channels = htons(bl->channels);
+ bl_packet->maxval = htons((1 << bl->bpc) - 1);
framenum = 0;
if (format != IMGFMT_Y8) {
@@ -436,29 +441,6 @@ static int preinit(const char *arg) {
p = ++q;
}
- if (bl->width >= 0 && bl->height >= 0) { /* size already known */
- bl_size = 12 + bl->width*bl->height*bl->channels;
- bl_packet = malloc(12 + bl->width*bl->height*3); /* space for header and image data */
- image = ((unsigned char*)bl_packet + 12); /* pointer to image data */
- tmp = malloc(bl->width*bl->height*3); /* space for image data only */
- }
- else { /* size unknown yet */
- bl_size = 12;
- bl_packet = malloc(12 + 3); /* space for header and a pixel */
- image = ((unsigned char*)bl_packet + 12); /* pointer to image data */
- tmp = malloc(3); /* space for a pixel only */
- }
-
- if (!bl_packet || !tmp) {
- mp_msg(MSGT_VO, MSGL_ERR, "bl: out of memory error\n");
- return 1;
- }
- bl_packet->magic = htonl(0x23542666);
- bl_packet->width = htons(bl->width);
- bl_packet->height = htons(bl->height);
- bl_packet->channels = htons(bl->channels);
- bl_packet->maxval = htons((1 << bl->bpc) - 1);
-
/* open all files */
for (i = 0; i < no_bl_files; i++)
if (bl->init_file(&bl_files[i])) return 1;
More information about the MPlayer-cvslog
mailing list