Skip to content

Commit

Permalink
rework FindUnusedPID after heads up from Coverty
Browse files Browse the repository at this point in the history
Avoid the special purpose Null PID while here.
Its still not perfect, but should be good enough for its intended use
when recording radio.
  • Loading branch information
dekarl committed May 28, 2013
1 parent 3247383 commit bef8fc8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 11 additions & 8 deletions mythtv/libs/libmythtv/mpeg/mpegtables.cpp
Expand Up @@ -717,24 +717,27 @@ uint ProgramMapTable::FindPIDs(uint type,
uint ProgramMapTable::FindUnusedPID(uint desired_pid)
{
uint pid = desired_pid;
while (FindPID(pid) >= 0)
if (pid >= MPEG_NULL_PID)
pid = 0x20;

while (FindPID(pid) != -1)
pid += 0x10;

if (desired_pid <= 0x1fff)
if (pid < MPEG_NULL_PID)
return pid;

pid = desired_pid;
while (FindPID(desired_pid) >= 0)
desired_pid += 1;
while (FindPID(pid) != -1)
pid += 1;

if (desired_pid <= 0x1fff)
if (pid < MPEG_NULL_PID)
return pid;

pid = 0x20;
while (FindPID(desired_pid) >= 0)
desired_pid += 1;
while (FindPID(pid) != -1)
pid += 1;

return desired_pid & 0x1fff;
return pid & 0x1fff;
}

QString PSIPTable::toString(void) const
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythtv/mpeg/mpegtables.h
Expand Up @@ -225,6 +225,10 @@ enum
FREESAT_SI_PID = 0x0f01,
FREESAT_EIT_PID = 0x0f02,
FREESAT_ST_EIT_PID = 0x0f03,

/// The all-ones PID value 0x1FFF indicates a Null TS Packet
/// introduced to maintain a constant bit rate of a TS Multiplex.
MPEG_NULL_PID = 0x1fff,
};

/** \class TableID
Expand Down

0 comments on commit bef8fc8

Please sign in to comment.