libtriple: convert cRecord to lt_debug()

This commit is contained in:
Stefan Seyfried
2011-10-02 22:43:39 +02:00
parent 9cbede9fec
commit b32df67a60

View File

@@ -7,18 +7,9 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include "record_td.h" #include "record_td.h"
#include "lt_debug.h"
#if 0 #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_RECORD, this, args)
#include <libeventserver/eventserver.h> #define lt_info(args...) _lt_info(TRIPLE_DEBUG_RECORD, this, args)
#include <neutrinoMessages.h>
#endif
#define INFO(fmt, args...) fprintf(stderr, "[cRecord:%s:%d] " fmt, __FUNCTION__, __LINE__, ##args)
#if 0 // change for verbose debug output
#define DBG INFO
#else
#define DBG(args...)
#endif
/* helper function to call the cpp thread loop */ /* helper function to call the cpp thread loop */
void *execute_record_thread(void *c) void *execute_record_thread(void *c)
@@ -30,7 +21,7 @@ void *execute_record_thread(void *c)
cRecord::cRecord(int /*num*/) cRecord::cRecord(int /*num*/)
{ {
INFO("\n"); lt_info("%s\n", __func__);
dmx = NULL; dmx = NULL;
record_thread_running = false; record_thread_running = false;
file_fd = -1; file_fd = -1;
@@ -39,14 +30,14 @@ cRecord::cRecord(int /*num*/)
cRecord::~cRecord() cRecord::~cRecord()
{ {
INFO("calling ::Stop()\n"); lt_info("%s: calling ::Stop()\n", __func__);
Stop(); Stop();
INFO("end\n"); lt_info("%s: end\n", __func__);
} }
bool cRecord::Open(void) bool cRecord::Open(void)
{ {
INFO("\n"); lt_info("%s\n", __func__);
exit_flag = RECORD_STOPPED; exit_flag = RECORD_STOPPED;
return true; return true;
} }
@@ -55,13 +46,13 @@ bool cRecord::Open(void)
// unused // unused
void cRecord::Close(void) void cRecord::Close(void)
{ {
INFO("\n"); lt_info("%s: \n", __func__);
} }
#endif #endif
bool cRecord::Start(int fd, unsigned short vpid, unsigned short * apids, int numpids) bool cRecord::Start(int fd, unsigned short vpid, unsigned short * apids, int numpids)
{ {
INFO("fd %d, vpid 0x%02x\n", fd, vpid); lt_info("%s: fd %d, vpid 0x%03x\n", __func__, fd, vpid);
int i; int i;
if (!dmx) if (!dmx)
@@ -83,7 +74,7 @@ bool cRecord::Start(int fd, unsigned short vpid, unsigned short * apids, int num
{ {
exit_flag = RECORD_FAILED_READ; exit_flag = RECORD_FAILED_READ;
errno = i; errno = i;
INFO("error creating thread! (%m)\n"); lt_info("%s: error creating thread! (%m)\n", __func__);
delete dmx; delete dmx;
dmx = NULL; dmx = NULL;
return false; return false;
@@ -94,10 +85,10 @@ bool cRecord::Start(int fd, unsigned short vpid, unsigned short * apids, int num
bool cRecord::Stop(void) bool cRecord::Stop(void)
{ {
INFO("\n"); lt_info("%s\n", __func__);
if (exit_flag != RECORD_RUNNING) if (exit_flag != RECORD_RUNNING)
INFO("status not RUNNING? (%d)\n", exit_flag); lt_info("%s: status not RUNNING? (%d)\n", __func__, exit_flag);
exit_flag = RECORD_STOPPED; exit_flag = RECORD_STOPPED;
if (record_thread_running) if (record_thread_running)
@@ -106,7 +97,7 @@ bool cRecord::Stop(void)
/* We should probably do that from the destructor... */ /* We should probably do that from the destructor... */
if (!dmx) if (!dmx)
INFO("dmx == NULL?\n"); lt_info("%s: dmx == NULL?\n", __func__);
else else
delete dmx; delete dmx;
dmx = NULL; dmx = NULL;
@@ -114,7 +105,7 @@ bool cRecord::Stop(void)
if (file_fd != -1) if (file_fd != -1)
close(file_fd); close(file_fd);
else else
INFO("file_fd not open??\n"); lt_info("%s: file_fd not open??\n", __func__);
file_fd = -1; file_fd = -1;
return true; return true;
} }
@@ -125,9 +116,9 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num
int j; int j;
bool found; bool found;
unsigned short pid; unsigned short pid;
INFO("\n"); lt_info("%s\n", __func__);
if (!dmx) { if (!dmx) {
INFO("DMX = NULL\n"); lt_info("%s: DMX = NULL\n", __func__);
return false; return false;
} }
pids = dmx->getPesPids(); pids = dmx->getPesPids();
@@ -161,9 +152,9 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num
bool cRecord::AddPid(unsigned short pid) bool cRecord::AddPid(unsigned short pid)
{ {
std::vector<pes_pids> pids; std::vector<pes_pids> pids;
INFO("\n"); lt_info("%s: \n", __func__);
if (!dmx) { if (!dmx) {
INFO("DMX = NULL\n"); lt_info("%s: DMX = NULL\n", __func__);
return false; return false;
} }
pids = dmx->getPesPids(); pids = dmx->getPesPids();
@@ -176,7 +167,7 @@ bool cRecord::AddPid(unsigned short pid)
void cRecord::RecordThread() void cRecord::RecordThread()
{ {
INFO("begin\n"); lt_info("%s: begin\n", __func__);
#define BUFSIZE (1 << 19) /* 512 kB */ #define BUFSIZE (1 << 19) /* 512 kB */
ssize_t r = 0; ssize_t r = 0;
int buf_pos = 0; int buf_pos = 0;
@@ -186,7 +177,7 @@ void cRecord::RecordThread()
if (!buf) if (!buf)
{ {
exit_flag = RECORD_FAILED_MEMORY; exit_flag = RECORD_FAILED_MEMORY;
INFO("unable to allocate buffer! (out of memory)\n"); lt_info("%s: unable to allocate buffer! (out of memory)\n", __func__);
} }
dmx->Start(); dmx->Start();
@@ -195,22 +186,23 @@ void cRecord::RecordThread()
if (buf_pos < BUFSIZE) if (buf_pos < BUFSIZE)
{ {
r = dmx->Read(buf + buf_pos, BUFSIZE - 1 - buf_pos, 100); r = dmx->Read(buf + buf_pos, BUFSIZE - 1 - buf_pos, 100);
DBG("buf_pos %6d r %6d / %6d\n", buf_pos, (int)r, BUFSIZE - 1 - buf_pos); lt_debug("%s: buf_pos %6d r %6d / %6d\n", __func__,
buf_pos, (int)r, BUFSIZE - 1 - buf_pos);
if (r < 0) if (r < 0)
{ {
if (errno != EAGAIN) if (errno != EAGAIN)
{ {
INFO("read failed: %m\n"); lt_info("%s: read failed: %m\n", __func__);
exit_flag = RECORD_FAILED_READ; exit_flag = RECORD_FAILED_READ;
break; break;
} }
INFO("EAGAIN\n"); lt_info("%s: EAGAIN\n", __func__);
} }
else else
buf_pos += r; buf_pos += r;
} }
else else
INFO("buffer full! Overflow?\n"); lt_info("%s: buffer full! Overflow?\n", __func__);
if (buf_pos > (BUFSIZE / 3)) /* start writeout */ if (buf_pos > (BUFSIZE / 3)) /* start writeout */
{ {
size_t towrite = BUFSIZE / 2; size_t towrite = BUFSIZE / 2;
@@ -220,12 +212,12 @@ void cRecord::RecordThread()
if (r < 0) if (r < 0)
{ {
exit_flag = RECORD_FAILED_FILE; exit_flag = RECORD_FAILED_FILE;
INFO("write error: %m\n"); lt_info("%s: write error: %m\n", __func__);
break; break;
} }
buf_pos -= r; buf_pos -= r;
memmove(buf, buf + r, buf_pos); memmove(buf, buf + r, buf_pos);
DBG("buf_pos %6d w %6d / %6d\n", buf_pos, (int)r, (int)towrite); lt_debug("%s: buf_pos %6d w %6d / %6d\n", __func__, buf_pos, (int)r, (int)towrite);
#if 0 #if 0
if (fdatasync(file_fd)) if (fdatasync(file_fd))
perror("cRecord::FileThread() fdatasync"); perror("cRecord::FileThread() fdatasync");
@@ -241,7 +233,7 @@ void cRecord::RecordThread()
if (r < 0) if (r < 0)
{ {
exit_flag = RECORD_FAILED_FILE; exit_flag = RECORD_FAILED_FILE;
INFO("write error: %m\n"); lt_info("%s: write error: %m\n", __func__);
break; break;
} }
buf_pos -= r; buf_pos -= r;
@@ -263,7 +255,7 @@ void cRecord::RecordThread()
printf("[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename); printf("[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename);
#endif #endif
INFO("end"); lt_info("%s: end", __func__);
pthread_exit(NULL); pthread_exit(NULL);
} }