Mercurial > pt1
changeset 139:61ff9cabf962
fix for split buffer shortage
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 25 Apr 2013 15:08:35 +0900 |
parents | 45b4afa656d2 |
children | c9b1d21c5035 |
files | recpt1/recpt1.c recpt1/tssplitter_lite.c recpt1/tssplitter_lite.h |
diffstat | 3 files changed, 28 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/recpt1/recpt1.c Thu Apr 25 15:08:34 2013 +0900 +++ b/recpt1/recpt1.c Thu Apr 25 15:08:35 2013 +0900 @@ -375,7 +375,8 @@ buf.size = 0; buf.data = NULL; - splitbuf.size = 0; + splitbuf.buffer_size = 0; + splitbuf.buffer = NULL; if(wfd == -1) fileless = TRUE; @@ -411,7 +412,17 @@ if(use_splitter) { - splitbuf.size = 0; + splitbuf.buffer_filled = 0; + + /* allocate split buffer */ + if(splitbuf.buffer_size < buf.size && buf.size > 0) { + splitbuf.buffer = realloc(splitbuf.buffer, buf.size); + if(splitbuf.buffer == NULL) { + fprintf(stderr, "split buffer allocation failed\n"); + use_splitter = FALSE; + goto fin; + } + } while(buf.size) { /* $BJ,N%BP>](BPID$B$NCj=P(B */ @@ -436,6 +447,7 @@ break; } } + /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */ code = split_ts(splitter, &buf, &splitbuf); if(code == TSS_NULL) { @@ -449,7 +461,7 @@ break; } /* while */ - buf.size = splitbuf.size; + buf.size = splitbuf.buffer_filled; buf.data = splitbuf.buffer; fin: ; @@ -523,7 +535,7 @@ } buf.data = splitbuf.buffer; - buf.size = splitbuf.size; + buf.size = splitbuf.buffer_size; } if(!fileless && !file_err) { @@ -544,6 +556,12 @@ } } + if(use_splitter) { + free(splitbuf.buffer); + splitbuf.buffer = NULL; + splitbuf.buffer_size = 0; + } + break; } }
--- a/recpt1/tssplitter_lite.c Thu Apr 25 15:08:34 2013 +0900 +++ b/recpt1/tssplitter_lite.c Thu Apr 25 15:08:35 2013 +0900 @@ -314,7 +314,7 @@ int version = 0; /* 初期化 */ - dbuf->size = 0; + dbuf->buffer_filled = 0; if (sbuf->size < 0) { return TSS_ERROR; } @@ -342,7 +342,7 @@ memcpy(dptr + d_offset, splitter->pat, LENGTH_PACKET); d_offset += LENGTH_PACKET; - dbuf->size += LENGTH_PACKET; + dbuf->buffer_filled += LENGTH_PACKET; break; default: if(0 != splitter->pmt_pids[pid]) { @@ -372,7 +372,7 @@ if(0 != splitter->pids[pid]) { memcpy(dptr + d_offset, sptr + s_offset, LENGTH_PACKET); d_offset += LENGTH_PACKET; - dbuf->size += LENGTH_PACKET; + dbuf->buffer_filled += LENGTH_PACKET; } break; } /* switch */
--- a/recpt1/tssplitter_lite.h Thu Apr 25 15:08:34 2013 +0900 +++ b/recpt1/tssplitter_lite.h Thu Apr 25 15:08:35 2013 +0900 @@ -61,11 +61,11 @@ uint8_t packet_seq[MAX_PID]; // 巡回カウンタ } splitter; -/* b25 decoder would hoard up large chank */ typedef struct _splitbuf_t { - int size; - u_char buffer[1024*1024]; + u_char* buffer; + int buffer_size; + int buffer_filled; } splitbuf_t; splitter* split_startup(char *sid);