Mailing List Archive

[PATCH] Allow recording of shows that have already started
Hi Isaac,

I like being able to record shows that have already started.
Sometimes I remember just a little too late and I can't see how it
hurts. Plus is makes it easier to test the scheduler. :-)

Also I consolidated some repeated code from the frontend main loop.

-Jim

Index: main.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/main.cpp,v
retrieving revision 1.37
diff -u -r1.37 main.cpp
--- main.cpp 15 Oct 2002 16:24:42 -0000 1.37
+++ main.cpp 16 Oct 2002 09:16:16 -0000
@@ -117,114 +117,70 @@

Scheduler *sched = new Scheduler(db);

- sched->FillRecordLists();
-
- int secsleft = -1;
- int asksecs = -1;
bool asked = false;
-
TV *nexttv = NULL;
-
- ProgramInfo *nextRecording = sched->GetNextRecording();
+ ProgramInfo *nextRecording = NULL;
QDateTime nextrectime;
- if (nextRecording)
- {
- nextrectime = nextRecording->startts;
- asked = false;
- if (tvList.find(nextRecording->cardid) == tvList.end())
- {
- cerr << "cardid: " << nextRecording->cardid
- << " isn't in the databae of capture cards.\n";
- exit(0);
- }
- nexttv = tvList[nextRecording->cardid];
- }
- QDateTime curtime = QDateTime::currentDateTime();
-
- QDateTime lastupdate = curtime;
+ QDateTime lastupdate = QDateTime::currentDateTime().addDays(-1);

while (1)
{
sleep(1);

- if (sched->CheckForChanges() ||
- (lastupdate.date().day() != curtime.date().day()))
+ QDateTime curtime = QDateTime::currentDateTime();
+
+ if(sched->CheckForChanges() || (lastupdate.date().day() != curtime.date().day())) {
+ sched->FillRecordLists();
+ cout << "Found changes in the todo list." << endl;
+ nextRecording = NULL;
+ }
+
+ if(!nextRecording)
{
lastupdate = curtime;
- sched->FillRecordLists();
nextRecording = sched->GetNextRecording();
if (nextRecording)
{
nextrectime = nextRecording->startts;
+ cout << "Will record " << nextRecording->title
+ << " in " << curtime.secsTo(nextrectime) << " secs." << endl;
asked = false;
if (tvList.find(nextRecording->cardid) == tvList.end())
- {
+ {
cerr << "invalid cardid " << nextRecording->cardid << endl;
exit(0);
- }
+ }
nexttv = tvList[nextRecording->cardid];
- }
+ }
}

- curtime = QDateTime::currentDateTime();
if (nextRecording)
{
- secsleft = curtime.secsTo(nextrectime);
- asksecs = secsleft - 30;
-
- if (nexttv->GetState() == kState_WatchingLiveTV && asksecs <= 0)
+ int secsleft = curtime.secsTo(nextrectime);
+ // cout << "secs left " << secsleft << " until " << nextRecording->title << endl;
+ if (nexttv->GetState() == kState_WatchingLiveTV && secsleft <= 30 && !asked)
{
- if (!asked)
+ asked = true;
+ int result = askRecording(nexttv, nextRecording, secsleft);
+
+ if (result == 3)
{
- asked = true;
- int result = askRecording(nexttv, nextRecording, secsleft);
-
- if (result == 3)
- {
- sched->RemoveFirstRecording();
- nextRecording = sched->GetNextRecording();
- }
-
- if (nextRecording)
- {
- nextrectime = nextRecording->startts;
- curtime = QDateTime::currentDateTime();
- secsleft = curtime.secsTo(nextrectime);
- if (tvList.find(nextRecording->cardid) == tvList.end())
- {
- cerr << "invalid cardid " << nextRecording->cardid
- << endl;
- exit(0);
- }
- nexttv = tvList[nextRecording->cardid];
- }
+ cout << "Skipping " << nextRecording->title << endl;
+ sched->RemoveFirstRecording();
+ nextRecording = NULL;
+ continue;
}
}
if (secsleft <= -2)
{
- // don't record stuff that's already started..
- if (secsleft > -30)
- startRecording(nexttv, nextRecording);
-
+ // FIXME: How can we test to see if this is already recording?
+ // Say nextRecording got set back to the same thing after CheckForChanges.
+ startRecording(nexttv, nextRecording);
+ cout << "Started recording " << nextRecording->title << endl;
sched->RemoveFirstRecording();
- nextRecording = sched->GetNextRecording();
-
- if (nextRecording)
- {
- nextrectime = nextRecording->startts;
- curtime = QDateTime::currentDateTime();
- secsleft = curtime.secsTo(nextrectime);
- if (tvList.find(nextRecording->cardid) == tvList.end())
- {
- cerr << "invalid cardid " << nextRecording->cardid
- << endl;
- exit(0);
- }
- nexttv = tvList[nextRecording->cardid];
- }
+ nextRecording = NULL;
+ continue;
}
-// else
-// cout << secsleft << " secs left until " << nextRecording->title << endl;
}
}

Index: scheduler.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/scheduler.cpp,v
retrieving revision 1.27
diff -u -r1.27 scheduler.cpp
--- scheduler.cpp 12 Oct 2002 16:15:16 -0000 1.27
+++ scheduler.cpp 16 Oct 2002 09:16:16 -0000
@@ -194,7 +194,7 @@
if (proginfo->description == QString::null)
proginfo->description = "";

- if (proginfo->startts < curDateTime)
+ if (proginfo->endts < curDateTime)
delete proginfo;
else
recordingList.push_back(proginfo);
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On Wednesday 16 October 2002 05:29 am, Jim Radford wrote:
> Hi Isaac,
>
> I like being able to record shows that have already started.
> Sometimes I remember just a little too late and I can't see how it
> hurts. Plus is makes it easier to test the scheduler. :-)
>
> Also I consolidated some repeated code from the frontend main loop.

I applied everything except the ability to record already started shows --
like your FIXME says, there's a hole there where it could tell it to start
recording something when it already is.. If you fix that (and test it), I'll
be happy to have the rest in.. Should be just a matter of adding a check for
tv->IsRecording() before telling it to record something, but I may be
forgetting something.

Thanks for the patch, btw =)

Isaac
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On Wed, Oct 16, 2002 at 11:21:53PM -0400, Isaac Richards wrote:
> On Wednesday 16 October 2002 05:29 am, Jim Radford wrote:
> > I like being able to record shows that have already started.
> > Sometimes I remember just a little too late and I can't see how it
> > hurts. Plus is makes it easier to test the scheduler. :-)

> I applied everything except the ability to record already started shows --
> like your FIXME says, there's a hole there where it could tell it to start
> recording something when it already is.. If you fix that (and test it), I'll
> be happy to have the rest in.. Should be just a matter of adding a check for
> tv->IsRecording() before telling it to record something, but I may be
> forgetting something.

Hi Isaac,

It turns out that StartRecording currently does nothing when it is
already recording. There was a memory leak in that case, so I moved
the allocation to tv.cpp where the delete was anyway. So with this
patch it does the right thing. I also moved the sleep to a more
logical place and added continues so that we don't use nextRecording
when it's NULL.

Currently there are no

recording -> recording

transitions in tv.cpp so adding a second conflicting but higher
priority show for the current time will not change what is currently
recording. If this is added then a special check for a noop when
transitioning to recording the "same" show needs to be added.

Would you accept a patch to save partially recorded shows?

> Thanks for the patch, btw =)

You're welcome. :-)

-Jim

Index: libs/libmythtv/tv.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv.cpp,v
retrieving revision 1.82
diff -u -r1.82 tv.cpp
--- libs/libmythtv/tv.cpp 16 Oct 2002 02:58:32 -0000 1.82
+++ libs/libmythtv/tv.cpp 18 Oct 2002 16:06:48 -0000
@@ -241,7 +242,7 @@
{
outputFilename = rcinfo->GetRecordFilename(recprefix);
recordEndTime = rcinfo->endts;
- curRecording = rcinfo;
+ curRecording = new ProgramInfo(*rcinfo);

if (internalState == kState_None)
nextState = kState_RecordingOnly;
@@ -261,7 +262,7 @@

outputFilename = rcinfo->GetRecordFilename(recprefix);
recordEndTime = rcinfo->endts;
- curRecording = rcinfo;
+ curRecording = new ProgramInfo(*rcinfo);

nextState = kState_RecordingOnly;
changeState = true;
@@ -270,7 +271,7 @@
{
outputFilename = rcinfo->GetRecordFilename(recprefix);
recordEndTime = rcinfo->endts;
- curRecording = rcinfo;
+ curRecording = new ProgramInfo(*rcinfo);

nextState = kState_WatchingRecording;
changeState = true;
Index: programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/main.cpp,v
retrieving revision 1.38
diff -u -r1.38 main.cpp
--- programs/mythfrontend/main.cpp 17 Oct 2002 03:05:16 -0000 1.38
+++ programs/mythfrontend/main.cpp 18 Oct 2002 16:06:48 -0000
@@ -94,21 +94,6 @@
}
}

-void startRecording(TV *tv, ProgramInfo *rec)
-{
- ProgramInfo *tvrec = new ProgramInfo(*rec);
- tv->StartRecording(tvrec);
-}
-
-int askRecording(TV *tv, ProgramInfo *rec, int timeuntil)
-{
- ProgramInfo *tvrec = new ProgramInfo(*rec);
- int retval = tv->AllowRecording(tvrec, timeuntil);
-
- delete tvrec;
- return retval;
-}
-
void *runScheduler(void *dummy)
{
dummy = dummy;
@@ -118,19 +103,15 @@
Scheduler *sched = new Scheduler(db);

bool asked = false;
- int secsleft;
TV *nexttv = NULL;

ProgramInfo *nextRecording = NULL;
QDateTime nextrectime;
- QDateTime curtime;
QDateTime lastupdate = QDateTime::currentDateTime().addDays(-1);

while (1)
{
- sleep(1);
-
- curtime = QDateTime::currentDateTime();
+ QDateTime curtime = QDateTime::currentDateTime();

if (sched->CheckForChanges() ||
(lastupdate.date().day() != curtime.date().day()))
@@ -161,7 +142,7 @@

if (nextRecording)
{
- secsleft = curtime.secsTo(nextrectime);
+ int secsleft = curtime.secsTo(nextrectime);

//cout << secsleft << " seconds until " << nextRecording->title
// << endl;
@@ -170,26 +151,28 @@
secsleft <= 30 && !asked)
{
asked = true;
- int result = askRecording(nexttv, nextRecording, secsleft);
+ int result = nexttv->AllowRecording(nextRecording, secsleft);

if (result == 3)
{
//cout << "Skipping " << nextRecording->title << endl;
sched->RemoveFirstRecording();
nextRecording = NULL;
+ continue;
}
}

if (secsleft <= -2)
{
- // don't record stuff that's already started..
- if (secsleft > -30)
- startRecording(nexttv, nextRecording);
-
+ nexttv->StartRecording(nextRecording);
+ //cout << "Started recording " << nextRecording->title << endl;
sched->RemoveFirstRecording();
nextRecording = NULL;
+ continue;
}
}
+
+ sleep(1);
}

return NULL;
Index: programs/mythfrontend/scheduler.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/scheduler.cpp,v
retrieving revision 1.28
diff -u -r1.28 scheduler.cpp
--- programs/mythfrontend/scheduler.cpp 17 Oct 2002 20:35:13 -0000 1.28
+++ programs/mythfrontend/scheduler.cpp 18 Oct 2002 16:06:49 -0000
@@ -194,7 +194,7 @@
if (proginfo->description == QString::null)
proginfo->description = "";

- if (proginfo->startts < curDateTime)
+ if (proginfo->endts < curDateTime)
delete proginfo;
else
recordingList.push_back(proginfo);
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On Friday 18 October 2002 12:28 pm, Jim Radford wrote:
> Hi Isaac,
>
> It turns out that StartRecording currently does nothing when it is
> already recording. There was a memory leak in that case, so I moved
> the allocation to tv.cpp where the delete was anyway. So with this
> patch it does the right thing. I also moved the sleep to a more
> logical place and added continues so that we don't use nextRecording
> when it's NULL.
>
> Currently there are no
>
> recording -> recording
>
> transitions in tv.cpp so adding a second conflicting but higher
> priority show for the current time will not change what is currently
> recording. If this is added then a special check for a noop when
> transitioning to recording the "same" show needs to be added.
>
> Would you accept a patch to save partially recorded shows?

Yup. I'll commit this current patch once I get back from vacation.

Isaac
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On Friday 18 October 2002 12:28 pm, Jim Radford wrote:
> Hi Isaac,
>
> It turns out that StartRecording currently does nothing when it is
> already recording. There was a memory leak in that case, so I moved
> the allocation to tv.cpp where the delete was anyway. So with this
> patch it does the right thing. I also moved the sleep to a more
> logical place and added continues so that we don't use nextRecording
> when it's NULL.
>
> Currently there are no
>
> recording -> recording
>
> transitions in tv.cpp so adding a second conflicting but higher
> priority show for the current time will not change what is currently
> recording. If this is added then a special check for a noop when
> transitioning to recording the "same" show needs to be added.
>
> Would you accept a patch to save partially recorded shows?

I just applied this to the CVS tree, thanks again. And yeah, in-case I wasn't
clear in my last email, I'd accep a patch to save partially recorded shows =)

Isaac
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On Sun, Oct 27, 2002 at 10:40:52AM -0400, Isaac Richards wrote:
> On Friday 18 October 2002 12:28 pm, Jim Radford wrote:
> > Would you accept a patch to save partially recorded shows?

> I just applied this to the CVS tree, thanks again. And yeah,
> in-case I wasn't clear in my last email, I'd accep a patch to save
> partially recorded shows =)

You were. :-) I've been using your vacation as a chance to get other
parts of my system, like sound, working. It still doesn't work (the
echos are gone but the quality still sucks), but it's better (I had to
switch to alsa to be able record the line-in without getting the PCM
output fed back as well). I have yet to be able to watch (listen to)
a show I've recorded. :-( I'm using the cmpci and snd-cmipci drivers.
Anyone else having sound problems?

The number one thing on my mythtv TODO list right now (beside PGUP and
PGDOWN which someone just mentioned) is channel changing speed. In
other programs like xawtv and avview the channel changing is zippy.
In mythtv it's a dog. Any thoughts before I dig in?

-Jim
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On Sun, Oct 27, 2002 at 10:40:52AM -0400, Isaac Richards wrote:
> On Friday 18 October 2002 12:28 pm, Jim Radford wrote:
> > Would you accept a patch to save partially recorded shows?

> I just applied this to the CVS tree, thanks again. And yeah,
> in-case I wasn't clear in my last email, I'd accep a patch to save
> partially recorded shows =)

You were. :-) I've been using your vacation as a chance to get other
parts of my system, like sound, working. It still doesn't work (the
echos are gone but the quality still sucks), but it's better (I had to
switch to alsa to be able record the line-in without getting the PCM
output fed back as well). I have yet to be able to watch (listen to)
a show I've recorded without cringing. :-( I'm using the cmpci and
snd-cmipci drivers. Anyone else having these sound problems?

The number one thing on my mythtv TODO list right now (beside PGUP and
PGDOWN which someone just mentioned) is channel changing speed. In
other programs like xawtv and avview the channel changing is zippy.
In mythtv it's a dog. Any thoughts before I dig in?

-Jim
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On 27 Oct 2002 at 8:31, Jim Radford wrote:

> output fed back as well). I have yet to be able to watch (listen to)
> a show I've recorded. :-( I'm using the cmpci and snd-cmipci drivers.
> Anyone else having sound problems?
Yup, no sound in recorded shows actually. I just got mythtv working yesterday
so haven't had time to delve into it. I also get a/v sync errors in the
terminal I start it from. I plan to install it on my fastest machine with an
ATI AIW Radeon on MDK 8.1 today and see if I get similar/different results.


--
Harondel J. Sibble
Sibble Computer Consulting
Creating solutions for the small business and home computer user.
help@pdscc.com (use pgp keyid 0x3AD5C11D) http://www.pdscc.com
(604) 739-3709 (voice/fax) (604) 686-2253 (pager)
Re: [PATCH] Allow recording of shows that have already started [ In reply to ]
On Sunday 27 October 2002 11:31 am, Jim Radford wrote:
> On Sun, Oct 27, 2002 at 10:40:52AM -0400, Isaac Richards wrote:
> > On Friday 18 October 2002 12:28 pm, Jim Radford wrote:
> > > Would you accept a patch to save partially recorded shows?
> >
> > I just applied this to the CVS tree, thanks again. And yeah,
> > in-case I wasn't clear in my last email, I'd accep a patch to save
> > partially recorded shows =)
>
> You were. :-)

Heh, well, I wasn't sure when I read it over, so =)

> I've been using your vacation as a chance to get other
> parts of my system, like sound, working. It still doesn't work (the
> echos are gone but the quality still sucks), but it's better (I had to
> switch to alsa to be able record the line-in without getting the PCM
> output fed back as well). I have yet to be able to watch (listen to)
> a show I've recorded. :-( I'm using the cmpci and snd-cmipci drivers.
> Anyone else having sound problems?

Someone else had said they were really unhappy with the recording quality of
their built-in soundcard and just bought a cheap sblive to replace it.

> The number one thing on my mythtv TODO list right now (beside PGUP and
> PGDOWN which someone just mentioned) is channel changing speed. In
> other programs like xawtv and avview the channel changing is zippy.
> In mythtv it's a dog. Any thoughts before I dig in?

Well, xawtv isn't doing stuff like pulling program info out of a database,
verifying that the channel actually exists, and most importantly, it's not
recording and playing back that recording =) Most of the delay is waiting
for the record threads to get a little bit ahead of the playback threads..
There's a couple usleep() calls in tv.cpp that you can remove to speed things
up a bit, but then you'll be playing back _right_ behind the recording, and
that doesn't work all that well for some people (though it does for others).

Isaac