Skip to content

Commit

Permalink
tidy: Convert demuxstr->buf to a std::vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Aug 28, 2020
1 parent 5e5c7e5 commit 671b066
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
42 changes: 19 additions & 23 deletions mythtv/libs/libmythtv/captions/xine_demux_sputext.cpp
Expand Up @@ -82,34 +82,29 @@ static char *read_line_from_input(demux_sputext_t *demuxstr, std::string& line)
off_t nread = 0;

line.reserve(LINE_LEN);
if ((line.capacity() - demuxstr->buflen) > 512) {
nread = line.capacity() - demuxstr->buflen;
if ((line.capacity() - demuxstr->buf.size()) > 512) {
nread = line.capacity() - demuxstr->buf.size();
nread = std::min(nread, demuxstr->rbuffer_len - demuxstr->rbuffer_cur);
if (nread < 0) {
printf("read failed.\n");
return nullptr;
}
memcpy(&demuxstr->buf[demuxstr->buflen],
&demuxstr->rbuffer_text[demuxstr->rbuffer_cur],
nread);
demuxstr->rbuffer_cur += nread;
demuxstr->buflen += nread;
demuxstr->buf[demuxstr->buflen] = '\0';
if (nread > 0) {
demuxstr->buf.append(&demuxstr->rbuffer_text[demuxstr->rbuffer_cur],
nread);
demuxstr->rbuffer_cur += nread;
}
}

char *s = strchr(demuxstr->buf, '\n');

if (s || (demuxstr->buflen > 0)) {

size_t linelen = s ? (s - demuxstr->buf) + 1 : demuxstr->buflen;
linelen = std::min(linelen, line.capacity());

line.resize(linelen);
memcpy(line.data(), demuxstr->buf, linelen);

memmove(demuxstr->buf, &demuxstr->buf[linelen], SUB_BUFSIZE - linelen);
demuxstr->buflen -= linelen;

size_t index = demuxstr->buf.find('\n');
if (index != std::string::npos) {
line.assign(demuxstr->buf, 0, index+1);
demuxstr->buf.erase(0, index+1);
return line.data();
}
if (!demuxstr->buf.empty()) {
line = demuxstr->buf;
demuxstr->buf.clear();
return line.data();
}

Expand Down Expand Up @@ -1039,7 +1034,8 @@ bool sub_read_file (demux_sputext_t *demuxstr) {

/* Rewind (sub_autodetect() needs to read input from the beginning) */
demuxstr->rbuffer_cur = 0;
demuxstr->buflen = 0;
demuxstr->buf.clear();
demuxstr->buf.reserve(SUB_BUFSIZE);

demuxstr->format=sub_autodetect (demuxstr);
if (demuxstr->format==FORMAT_UNKNOWN) {
Expand All @@ -1050,7 +1046,7 @@ bool sub_read_file (demux_sputext_t *demuxstr) {

/* Rewind */
demuxstr->rbuffer_cur = 0;
demuxstr->buflen = 0;
demuxstr->buf.clear();

demuxstr->num=0;
int timeout = MAX_TIMEOUT;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/captions/xine_demux_sputext.h
Expand Up @@ -42,7 +42,7 @@ struct demux_sputext_t {

int status;

char buf[SUB_BUFSIZE];
std::string buf;
off_t buflen;

float mpsub_position;
Expand Down

0 comments on commit 671b066

Please sign in to comment.