diff --git a/osd/main.c b/osd/main.c index 7a6f06e..951614d 100644 --- a/osd/main.c +++ b/osd/main.c @@ -149,7 +149,6 @@ void overlays() { char img[32]; sprintf(img, "/tmp/osd%d.bmp", id); - fprintf(stderr, "access=%s %d\n", img, access(img, F_OK)); if (!access(img, F_OK)) load_region(id, PIXEL_FORMAT_1555); else diff --git a/osd/net.c b/osd/net.c index 2331c01..50015d3 100644 --- a/osd/net.c +++ b/osd/net.c @@ -7,10 +7,6 @@ int *clients; static void start_server(); static void respond(int); -typedef struct -{ - char *name, *value; -} header_t; static header_t reqhdr[17] = {{"\0", "\0"}}; char *method, @@ -65,12 +61,9 @@ void serve_forever() char *request_header(const char *name) { header_t *h = reqhdr; - while (h->name) - { + for (; h->name; h++) if (!strcmp(h->name, name)) return h->value; - h++; - } return NULL; } @@ -78,7 +71,6 @@ header_t *request_headers(void) { return reqhdr; } static void unescape_uri(char *uri) { - char chr = 0; char *src = uri; char *dst = uri; @@ -88,18 +80,10 @@ static void unescape_uri(char *uri) dst = src; while (*src && !isspace((int)(*src))) { - if (*src == '+') - chr = ' '; - else if ((*src == '%') && src[1] && src[2]) - { - src++; - chr = ((*src & 0x0F) + 9 * (*src > '9')) * 16; - src++; - chr += ((*src & 0x0F) + 9 * (*src > '9')); - } - else - chr = *src; - *dst++ = chr; + *dst++ = (*src == '+') ? ' ' : + ((*src == '%') && src[1] && src[2]) ? + ((*++src & 0x0F) + 9 * (*src > '9')) * 16 + ((*++src & 0x0F) + 9 * (*src > '9')) : + *src; src++; } *dst = '\0'; @@ -153,15 +137,14 @@ void start_server() void respond(int slot) { - int rcvd; - int total = 0; + int rcvd, total = 0; buf = malloc(BUF_SIZE); rcvd = recv(clients[slot], buf + total, BUF_SIZE - total, 0); if (rcvd < 0) - goto finish; + fputs("recv() error\n", stderr); else if (rcvd == 0) fputs("Client disconnected unexpectedly.\n", stderr); @@ -189,11 +172,9 @@ void respond(int slot) if (!k) break; v = strtok(NULL, "\r\n"); - while (*v && *v == ' ') - v++; + while (*v && *v == ' ' && v++); h->name = k; - h->value = v; - h++; + h++->value = v; fprintf(stderr, "[H] %s: %s\n", k, v); e = v + 1 + strlen(v); if (e[1] == '\r' && e[2] == '\n') @@ -224,12 +205,8 @@ void respond(int slot) } if (!t) - { - t = strtok(NULL, "\r\n"); - payload = t; - } + payload = t = strtok(NULL, "\r\n"); -finish: int clientfd = clients[slot]; dup2(clientfd, STDOUT_FILENO); close(clientfd); diff --git a/osd/net.h b/osd/net.h index ea884d6..aede34d 100644 --- a/osd/net.h +++ b/osd/net.h @@ -10,6 +10,11 @@ extern "C" #include "common.h" + typedef struct + { + char *name, *value; + } header_t; + extern char *method, // "GET" or "POST" *uri, // "/index.html" things before '?' *query, // "a=1&b=2" things after '?' diff --git a/osd/region.c b/osd/region.c index e5a2ce8..6b52d3d 100644 --- a/osd/region.c +++ b/osd/region.c @@ -127,7 +127,7 @@ int create_region(int handle, int x, int y, int width, int height) stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.eAlphaMode = E_MI_RGN_PIXEL_ALPHA; stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.stAlphaPara.stArgb1555Alpha.u8BgAlpha = 0; stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.stAlphaPara.stArgb1555Alpha.u8FgAlpha = 255; - stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.bEnableColorInv = 0; + // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.bEnableColorInv = 0; // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.eInvertColorMode = E_MI_RGN_BELOW_LUMA_THRESHOLD; // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.u16LumaThreshold = 128; // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.u16WDivNum = stRegion.stOsdInitParam.stSize.u32Width * inv16; @@ -141,11 +141,11 @@ int create_region(int handle, int x, int y, int width, int height) stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bQpDisable = 0; stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bAbsQp = 0; stChnAttr.unChnAttr.stOverlayChn.stQpInfo.s32Qp = 0; - //stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Height = width; - //stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Width = height; - //stChnAttr.unChnAttr.stOverlayChn.stInvertColor.u32LumThresh = 128; - //stChnAttr.unChnAttr.stOverlayChn.stInvertColor.enChgMod = LESSTHAN_LUM_THRESH; - //stChnAttr.unChnAttr.stOverlayChn.stInvertColor.bInvColEn = 0; + // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Height = width; + // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Width = height; + // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.u32LumThresh = 128; + // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.enChgMod = LESSTHAN_LUM_THRESH; + // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.bInvColEn = 0; #ifndef __16CV300__ stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[0] = 0x3e0; stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[1] = 0x7FFF; @@ -207,8 +207,7 @@ int prepare_bitmap(const char *filename, BITMAP *bitmap, int bFil, unsigned int return -1; } - bitmap->pData = malloc(s32BytesPerPix * (bmpInfo.bmiHeader.biWidth) * (bmpInfo.bmiHeader.biHeight)); - if (bitmap->pData == NULL) + if (!(bitmap->pData = malloc(s32BytesPerPix * bmpInfo.bmiHeader.biWidth * bmpInfo.bmiHeader.biHeight))) { fprintf(stderr, "malloc osd memory err!\n"); return -1; @@ -227,7 +226,7 @@ int prepare_bitmap(const char *filename, BITMAP *bitmap, int bFil, unsigned int if (enPixelFmt == PIXEL_FORMAT_2BPP) { s32Width = DIV_UP(bmpInfo.bmiHeader.biWidth, 4); - pu8Data = malloc((s32Width) * (bmpInfo.bmiHeader.biHeight)); + pu8Data = malloc(s32Width * bmpInfo.bmiHeader.biHeight); if (NULL == pu8Data) { fprintf(stderr, "malloc osd memory err!\n"); @@ -311,13 +310,15 @@ int set_bitmap(unsigned int handle, BITMAP *bitmap) int load_region(unsigned int handle, int enPixelFmt) { - BITMAP* bitmap; + BITMAP bitmap; + int s32Ret; char path[32]; sprintf(path, "/tmp/osd%d.bmp", handle); - prepare_bitmap(path, bitmap, 0, 0, enPixelFmt); - - int s32Ret = set_bitmap(handle, bitmap); - free(bitmap->pData); + if (!(s32Ret = prepare_bitmap(path, &bitmap, 0, 0, enPixelFmt))) + { + s32Ret = set_bitmap(handle, &bitmap); + free(bitmap.pData); + } return s32Ret; }