Skip to content

Commit 6fb8538

Browse files
author
Isaac Richards
committed
Now the ringbuffer, well, rings.
git-svn-id: http://svn.mythtv.org/svn/trunk@9 7dbf422c-18fa-0310-86e9-fd20926502f2
1 parent 589164c commit 6fb8538

File tree

6 files changed

+61
-14
lines changed

6 files changed

+61
-14
lines changed

mythtv/libs/libmythtv/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ tv: $(TVOBJ)
4444
@rm -f tv
4545
$(CXXLINK) $(TVOBJ) $(TVLDF)
4646

47-
install: nuvrec nuvplay
48-
strip nuvrec nuvplay
47+
install: nuvrec nuvplay tv
48+
strip nuvrec nuvplay tv
4949
install -m 755 nuvrec nuvplay /usr/local/bin
5050

5151
clean:
52-
rm -f *.o nuvplay nuvrec
52+
rm -f *.o nuvplay nuvrec tv
5353
$(DO_MAKE)

mythtv/libs/libmythtv/RingBuffer.cpp

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ RingBuffer::RingBuffer(const char *lfilename, long long size)
2828
{
2929
normalfile = false;
3030
filename = lfilename;
31-
31+
filesize = size;
32+
3233
fd = -1; fd2 = -1;
3334

3435
fd = open(filename.c_str(), O_WRONLY|O_CREAT|O_LARGEFILE, 0644);
3536
fd2 = open(filename.c_str(), O_RDONLY|O_LARGEFILE);
3637

3738
writestart = writepos = 0;
3839
readstart = readpos = 0;
40+
41+
wrapcount = 0;
3942
}
4043

4144
RingBuffer::~RingBuffer(void)
@@ -62,10 +65,30 @@ int RingBuffer::Read(void *buf, int count)
6265
}
6366
else
6467
{
65-
while (readpos + count >= writepos)
68+
while (readpos + count >= writepos + wrapcount * filesize)
69+
{
6670
usleep(5);
67-
ret = read(fd2, buf, count);
68-
readpos += ret;
71+
}
72+
73+
if (readpos + count > filesize)
74+
{
75+
int toread = filesize - readpos;
76+
77+
ret = read(fd2, buf, toread);
78+
79+
int left = count - toread;
80+
lseek(fd2, 0, SEEK_SET);
81+
82+
ret = read(fd2, (char *)buf + toread, left);
83+
ret += toread;
84+
85+
readpos = left;
86+
}
87+
else
88+
{
89+
ret = read(fd2, buf, count);
90+
readpos += ret;
91+
}
6992
}
7093
return ret;
7194
}
@@ -87,9 +110,27 @@ int RingBuffer::Write(const void *buf, int count)
87110
}
88111
else
89112
{
90-
ret = write(fd, buf, count);
91-
writepos += ret;
113+
if (writepos + count > filesize)
114+
{
115+
int towrite = filesize - writepos;
116+
ret = write(fd, buf, towrite);
117+
118+
int left = count - towrite;
119+
lseek(fd, 0, SEEK_SET);
120+
121+
ret = write(fd, (char *)buf + towrite, left);
122+
writepos = left;
123+
124+
ret += towrite;
125+
wrapcount++;
126+
}
127+
else
128+
{
129+
ret = write(fd, buf, count);
130+
writepos += ret;
131+
}
92132
}
133+
93134
return ret;
94135
}
95136

@@ -103,6 +144,7 @@ long long RingBuffer::Seek(long long pos, int whence)
103144
else
104145
{
105146
ret = lseek(fd2, pos, whence);
147+
readpos = pos;
106148
}
107149
return ret;
108150
}

mythtv/libs/libmythtv/RingBuffer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class RingBuffer
3333

3434
long long readpos;
3535
long long readstart;
36+
37+
long long filesize;
38+
39+
long long wrapcount;
3640
};
3741

3842
#endif

mythtv/libs/libmythtv/tv.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
3030
{
3131
pthread_t encode, decode;
3232

33-
RingBuffer *rbuffer = new RingBuffer("ringbuf.nuv", 1024 * 1024 * 5);
33+
RingBuffer *rbuffer = new RingBuffer("ringbuf.nuv", 1024 * 1024 * 10);
3434

3535
NuppelVideoRecorder *nvr = new NuppelVideoRecorder();
3636
nvr->SetRingBuffer(rbuffer);
@@ -48,6 +48,7 @@ int main(int argc, char *argv[])
4848
usleep(50);
4949

5050
usleep(800000);
51+
5152
pthread_create(&decode, NULL, SpawnDecode, nvp);
5253

5354
while (!nvp->IsPlaying())

mythtv/libs/libmythtv/videoout_xv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ char *XJ_init(int width, int height, char *window_name, char *icon_name)
253253

254254
XJ_started=1;
255255

256-
XJ_toggleFullscreen();
256+
//XJ_toggleFullscreen();
257257

258258
return(sbuf);
259259
}

mythtv/programs/mythtv/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ tv: $(TVOBJ)
4444
@rm -f tv
4545
$(CXXLINK) $(TVOBJ) $(TVLDF)
4646

47-
install: nuvrec nuvplay
48-
strip nuvrec nuvplay
47+
install: nuvrec nuvplay tv
48+
strip nuvrec nuvplay tv
4949
install -m 755 nuvrec nuvplay /usr/local/bin
5050

5151
clean:
52-
rm -f *.o nuvplay nuvrec
52+
rm -f *.o nuvplay nuvrec tv
5353
$(DO_MAKE)

0 commit comments

Comments
 (0)