Permalink
Browse files

Fix Live TV channel changing when using Input Groups.

When trying to change channels (either directly or through the program
guide), an idle tuner in the same input group as the current tuner
would not be considered available.

This is fixed by adding the excluded_cardids argument to
RemoteRequestFreeRecorderList() and
RemoteRequestFreeRecorderFromList().

Doing this the "right" way would require a protocol change for the
GET_FREE_RECORDER_LIST command.  This is better done closer to the end
of the 0.26 release cycle, so the current implementation is less
efficient and makes multiple queries.

There is also a lot of vector<> code here that could stand to be
converted to QVector<>.
  • Loading branch information...
1 parent ba9bcba commit dc6a18af542c9de80f06cc22485d6ac8b932dfeb @stichnot stichnot committed Apr 15, 2012
@@ -208,22 +208,6 @@ vector<ProgramInfo *> *RemoteGetConflictList(const ProgramInfo *pginfo)
return retlist;
}
-vector<uint> RemoteRequestFreeRecorderList(void)
-{
- vector<uint> list;
-
- QStringList strlist("GET_FREE_RECORDER_LIST");
-
- if (!gCoreContext->SendReceiveStringList(strlist, true))
- return list;
-
- QStringList::const_iterator it = strlist.begin();
- for (; it != strlist.end(); ++it)
- list.push_back((*it).toUInt());
-
- return list;
-}
-
QDateTime RemoteGetPreviewLastModified(const ProgramInfo *pginfo)
{
QDateTime retdatetime;
@@ -31,7 +31,6 @@ void RemoteGetAllExpiringRecordings(vector<ProgramInfo *> &expiringlist);
MPUBLIC uint RemoteGetRecordingList(vector<ProgramInfo *> &reclist,
QStringList &strList);
MPUBLIC vector<ProgramInfo *> *RemoteGetConflictList(const ProgramInfo *pginfo);
-MPUBLIC vector<uint> RemoteRequestFreeRecorderList(void);
MPUBLIC QDateTime RemoteGetPreviewLastModified(const ProgramInfo *pginfo);
MPUBLIC QDateTime RemoteGetPreviewIfModified(
const ProgramInfo &pginfo, const QString &cachefile);
@@ -2174,7 +2174,9 @@ void TV::HandleStateChange(PlayerContext *mctx, PlayerContext *ctx)
if (reclist.size())
{
RemoteEncoder *testrec = NULL;
- testrec = RemoteRequestFreeRecorderFromList(reclist);
+ vector<uint> excluded_cardids;
+ testrec = RemoteRequestFreeRecorderFromList(reclist,
+ excluded_cardids);
if (testrec && testrec->IsValidRecorder())
{
ctx->SetRecorder(testrec);
@@ -6410,13 +6412,11 @@ void TV::DoSkipCommercials(PlayerContext *ctx, int direction)
void TV::SwitchSource(PlayerContext *ctx, uint source_direction)
{
QMap<uint,InputInfo> sources;
- vector<uint> cardids = RemoteRequestFreeRecorderList();
uint cardid = ctx->GetCardID();
- cardids.push_back(cardid);
- stable_sort(cardids.begin(), cardids.end());
-
vector<uint> excluded_cardids;
excluded_cardids.push_back(cardid);
+ vector<uint> cardids = RemoteRequestFreeRecorderList(excluded_cardids);
+ stable_sort(cardids.begin(), cardids.end());
InfoMap info;
ctx->recorder->GetChannelInfo(info);
@@ -6535,7 +6535,11 @@ void TV::SwitchCards(PlayerContext *ctx,
}
if (!reclist.empty())
- testrec = RemoteRequestFreeRecorderFromList(reclist);
+ {
+ vector<uint> excluded_cardids;
+ excluded_cardids.push_back(ctx->GetCardID());
+ testrec = RemoteRequestFreeRecorderFromList(reclist, excluded_cardids);
+ }
if (testrec && testrec->IsValidRecorder())
{
@@ -7172,7 +7176,9 @@ void TV::ChangeChannel(PlayerContext *ctx, uint chanid, const QString &chan)
if (reclist.size())
{
RemoteEncoder *testrec = NULL;
- testrec = RemoteRequestFreeRecorderFromList(reclist);
+ vector<uint> excluded_cardids;
+ excluded_cardids.push_back(ctx->GetCardID());
+ testrec = RemoteRequestFreeRecorderFromList(reclist, excluded_cardids);
if (!testrec || !testrec->IsValidRecorder())
{
ClearInputQueues(ctx, true);
@@ -7883,7 +7889,7 @@ QSet<uint> TV::IsTunableOn(
excluded_cards.push_back(ctx->GetCardID());
uint sourceid = ChannelUtil::GetSourceIDForChannel(chanid);
- vector<uint> connected = RemoteRequestFreeRecorderList();
+ vector<uint> connected = RemoteRequestFreeRecorderList(excluded_cards);
vector<uint> interesting = CardUtil::GetCardIDs(sourceid);
// filter disconnected cards
@@ -147,9 +147,46 @@ RemoteEncoder *RemoteRequestNextFreeRecorder(int curr)
/**
* Given a list of recorder numbers, return the first available.
*/
-RemoteEncoder *RemoteRequestFreeRecorderFromList(
- const QStringList &qualifiedRecorders)
+vector<uint> RemoteRequestFreeRecorderList(const vector<uint> &excluded_cardids)
{
+#if 0
+ vector<uint> list;
+
+ QStringList strlist("GET_FREE_RECORDER_LIST");
+
+ if (!gCoreContext->SendReceiveStringList(strlist, true))
+ return list;
+
+ QStringList::const_iterator it = strlist.begin();
+ for (; it != strlist.end(); ++it)
+ list.push_back((*it).toUInt());
+
+ return list;
+#endif
+ QVector<uint> result;
+ vector<uint> cards = CardUtil::GetCardList();
+ for (uint i = 0; i < cards.size(); i++)
+ {
+ vector<InputInfo> inputs =
+ RemoteRequestFreeInputList(cards[i], excluded_cardids);
+ for (uint j = 0; j < inputs.size(); j++)
+ {
+ if (!result.contains(inputs[j].cardid))
+ result.push_back(inputs[j].cardid);
+ }
+ }
+ QString msg("RemoteRequestFreeRecorderList returned {");
+ for (int k = 0; k < result.size(); k++)
+ msg += QString(" %1").arg(result[k]);
+ msg += "}";
+ LOG(VB_CHANNEL, LOG_INFO, msg);
+ return result.toStdVector();
+}
+
+RemoteEncoder *RemoteRequestFreeRecorderFromList
+(const QStringList &qualifiedRecorders, const vector<uint> &excluded_cardids)
+{
+#if 0
QStringList strlist( "GET_FREE_RECORDER_LIST" );
if (!gCoreContext->SendReceiveStringList(strlist, true))
@@ -169,6 +206,18 @@ RemoteEncoder *RemoteRequestFreeRecorderFromList(
}
// didn't find anything. just return NULL.
return NULL;
+#endif
+ vector<uint> freeRecorders =
+ RemoteRequestFreeRecorderList(excluded_cardids);
+ for (QStringList::const_iterator recIter = qualifiedRecorders.begin();
+ recIter != qualifiedRecorders.end(); ++recIter)
+ {
+ if (find(freeRecorders.begin(),
+ freeRecorders.end(),
+ (*recIter).toUInt()) != freeRecorders.end())
+ return RemoteGetExistingRecorder((*recIter).toInt());
+ }
+ return NULL;
}
RemoteEncoder *RemoteRequestRecorder(void)
@@ -37,11 +37,12 @@ MTV_PUBLIC void RemoteStopRecording(const ProgramInfo *pginfo);
MTV_PUBLIC void RemoteCancelNextRecording(uint cardid, bool cancel);
MTV_PUBLIC RemoteEncoder *RemoteRequestRecorder(void);
MTV_PUBLIC RemoteEncoder *RemoteRequestNextFreeRecorder(int curr);
-MTV_PUBLIC
-RemoteEncoder *RemoteRequestFreeRecorderFromList(
- const QStringList &qualifiedRecorders);
+MTV_PUBLIC RemoteEncoder *RemoteRequestFreeRecorderFromList
+(const QStringList &qualifiedRecorders, const vector<uint> &excluded_cardids);
MTV_PUBLIC RemoteEncoder *RemoteGetExistingRecorder(const ProgramInfo *pginfo);
MTV_PUBLIC RemoteEncoder *RemoteGetExistingRecorder(int recordernum);
+MTV_PUBLIC vector<uint>
+RemoteRequestFreeRecorderList(const vector<uint> &excluded_cardids);
MTV_PUBLIC vector<InputInfo> RemoteRequestFreeInputList(
uint cardid, const vector<uint> &excluded_cardids);
MTV_PUBLIC InputInfo RemoteRequestBusyInputID(uint cardid);

0 comments on commit dc6a18a

Please sign in to comment.