[mythtv] [Micropatch] tiny code simplication.

michael at optusnet.com.au michael at optusnet.com.au
Sat May 24 18:29:38 EDT 2003


(I'm just reading through the code trying to get
a feel for how it works. These changes are just tiny
things I noticed while reading).


Micropatch: Changes to reduce code size slightly.

#1. In the EncoderLink object, 'tv' is NULL iff 'local' is false.
The 'local' variable can be removed as it's redundant everywhere.

#2. EncoderLink::getTV() is never used anywhere. removed.

#3. Brief comments added.

diff -c -r mythtv-2/programs/mythbackend/encoderlink.cpp mythtv-3/programs/mythbackend/encoderlink.cpp
*** mythtv-2/programs/mythbackend/encoderlink.cpp	2003-05-23 15:49:55.000000000 +1000
--- mythtv-3/programs/mythbackend/encoderlink.cpp	2003-05-23 16:20:52.000000000 +1000
***************
*** 10,22 ****
  
  #include "libmyth/mythcontext.h"
  
  EncoderLink::EncoderLink(int capturecardnum, PlaybackSock *lsock, 
                           QString lhostname)
  {
      sock = lsock;
      hostname = lhostname;
      tv = NULL;
-     local = false;
      m_capturecardnum = capturecardnum;
  
      endRecordingTime = QDateTime::currentDateTime().addDays(-2);
--- 10,24 ----
  
  #include "libmyth/mythcontext.h"
  
+ /* Create a remote encode link object. */
+ /* 'lsock' is allowed to be NULL? */
+ /* 'lhostname' must be valid. */
  EncoderLink::EncoderLink(int capturecardnum, PlaybackSock *lsock, 
                           QString lhostname)
  {
      sock = lsock;
      hostname = lhostname;
      tv = NULL;
      m_capturecardnum = capturecardnum;
  
      endRecordingTime = QDateTime::currentDateTime().addDays(-2);
***************
*** 24,44 ****
      chanid = "";
  }
  
  EncoderLink::EncoderLink(int capturecardnum, TVRec *ltv)
  {
      sock = NULL;
      tv = ltv;
-     local = true;
      m_capturecardnum = capturecardnum;
  
      endRecordingTime = QDateTime::currentDateTime().addDays(-2);
      startRecordingTime = endRecordingTime;
      chanid = "";
  }
  
  EncoderLink::~EncoderLink()
  {
!     if (local)
          delete tv;
  }
  
--- 26,52 ----
      chanid = "";
  }
  
+ /* Create a local encode link object. */
+ /* 'ltv' must not be NULL. */
  EncoderLink::EncoderLink(int capturecardnum, TVRec *ltv)
  {
+ 
+     if (!ltv)
+          cerr << "Warning: new local EncoderLink but 'tv' is null!\n";
+ 
      sock = NULL;
      tv = ltv;
      m_capturecardnum = capturecardnum;
  
      endRecordingTime = QDateTime::currentDateTime().addDays(-2);
      startRecordingTime = endRecordingTime;
      chanid = "";
+ 
  }
  
  EncoderLink::~EncoderLink()
  {
!     if (tv)
          delete tv;
  }
  
***************
*** 59,65 ****
  
  bool EncoderLink::isConnected(void)
  {
!     if (local)
          return true;
         
      if (sock)
--- 67,73 ----
  
  bool EncoderLink::isConnected(void)
  {
!     if (tv)
          return true;
         
      if (sock)
***************
*** 72,78 ****
  {
      TVState retval = kState_Error;
  
!     if (local)
          retval = tv->GetState();
      else if (sock)
          retval = (TVState)sock->GetEncoderState(m_capturecardnum);
--- 80,86 ----
  {
      TVState retval = kState_Error;
  
!     if (tv)
          retval = tv->GetState();
      else if (sock)
          retval = (TVState)sock->GetEncoderState(m_capturecardnum);
***************
*** 97,103 ****
      bool retval = false;
      ProgramInfo *tvrec = NULL;
  
!     if (local)
      {
          if (isBusy())
              tvrec = tv->GetRecording();
--- 105,111 ----
      bool retval = false;
      ProgramInfo *tvrec = NULL;
  
!     if (tv)
      {
          if (isBusy())
              tvrec = tv->GetRecording();
***************
*** 162,168 ****
      startRecordingTime = rec->startts;
      chanid = rec->chanid;
  
!     if (local)
          tv->StartRecording(rec);
      else if (sock)
          sock->StartRecording(m_capturecardnum, rec);
--- 170,176 ----
      startRecordingTime = rec->startts;
      chanid = rec->chanid;
  
!     if (tv)
          tv->StartRecording(rec);
      else if (sock)
          sock->StartRecording(m_capturecardnum, rec);
***************
*** 177,183 ****
      startRecordingTime = endRecordingTime;
      chanid = "";
  
!     if (local)
      {
          tv->StopRecording();
          return;
--- 185,191 ----
      startRecordingTime = endRecordingTime;
      chanid = "";
  
!     if (tv)
      {
          tv->StopRecording();
          return;
***************
*** 186,192 ****
  
  void EncoderLink::FinishRecording(void)
  {
!     if (local)
      {
          tv->FinishRecording();
          return;
--- 194,200 ----
  
  void EncoderLink::FinishRecording(void)
  {
!     if (tv)
      {
          tv->FinishRecording();
          return;
***************
*** 199,205 ****
  
  bool EncoderLink::IsReallyRecording(void)
  {
!     if (local)
          return tv->IsReallyRecording();
  
      cerr << "Should be local only query: IsReallyRecording\n";
--- 207,213 ----
  
  bool EncoderLink::IsReallyRecording(void)
  {
!     if (tv)
          return tv->IsReallyRecording();
  
      cerr << "Should be local only query: IsReallyRecording\n";
***************
*** 208,214 ****
  
  float EncoderLink::GetFramerate(void)
  {
!     if (local)
          return tv->GetFramerate();
  
      cerr << "Should be local only query: GetFramerate\n";
--- 216,222 ----
  
  float EncoderLink::GetFramerate(void)
  {
!     if (tv)
          return tv->GetFramerate();
  
      cerr << "Should be local only query: GetFramerate\n";
***************
*** 217,223 ****
  
  long long EncoderLink::GetFramesWritten(void)
  {
!     if (local)
          return tv->GetFramesWritten();
  
      cerr << "Should be local only query: GetFramesWritten\n";
--- 225,231 ----
  
  long long EncoderLink::GetFramesWritten(void)
  {
!     if (tv)
          return tv->GetFramesWritten();
  
      cerr << "Should be local only query: GetFramesWritten\n";
***************
*** 226,232 ****
  
  long long EncoderLink::GetFilePosition(void)
  {
!     if (local)
          return tv->GetFilePosition();
  
      cerr << "Should be local only query: GetFilePosition\n";
--- 234,240 ----
  
  long long EncoderLink::GetFilePosition(void)
  {
!     if (tv)
          return tv->GetFilePosition();
  
      cerr << "Should be local only query: GetFilePosition\n";
***************
*** 235,241 ****
  
  long long EncoderLink::GetFreeSpace(long long totalreadpos)
  {
!     if (local)
          return tv->GetFreeSpace(totalreadpos);
  
      cerr << "Should be local only query: GetFreeSpace\n";
--- 243,249 ----
  
  long long EncoderLink::GetFreeSpace(long long totalreadpos)
  {
!     if (tv)
          return tv->GetFreeSpace(totalreadpos);
  
      cerr << "Should be local only query: GetFreeSpace\n";
***************
*** 244,250 ****
  
  long long EncoderLink::GetKeyframePosition(long long desired)
  {
!     if (local)
          return tv->GetKeyframePosition(desired);
  
      cerr << "Should be local only query: GetKeyframePosition\n";
--- 252,258 ----
  
  long long EncoderLink::GetKeyframePosition(long long desired)
  {
!     if (tv)
          return tv->GetKeyframePosition(desired);
  
      cerr << "Should be local only query: GetKeyframePosition\n";
***************
*** 253,259 ****
  
  void EncoderLink::TriggerRecordingTransition(void)
  {
!     if (local)
      {
          tv->TriggerRecordingTransition();
          return;
--- 261,267 ----
  
  void EncoderLink::TriggerRecordingTransition(void)
  {
!     if (tv)
      {
          tv->TriggerRecordingTransition();
          return;
***************
*** 264,270 ****
  
  void EncoderLink::StopPlaying(void)
  {
!     if (local)
      {
          tv->StopPlaying();
          return;
--- 272,278 ----
  
  void EncoderLink::StopPlaying(void)
  {
!     if (tv)
      {
          tv->StopPlaying();
          return;
***************
*** 276,282 ****
  void EncoderLink::SetupRingBuffer(QString &path, long long &filesize,
                                    long long &fillamount, bool pip)
  {
!     if (local)
      {
          tv->SetupRingBuffer(path, filesize, fillamount, pip);
          return;
--- 284,290 ----
  void EncoderLink::SetupRingBuffer(QString &path, long long &filesize,
                                    long long &fillamount, bool pip)
  {
!     if (tv)
      {
          tv->SetupRingBuffer(path, filesize, fillamount, pip);
          return;
***************
*** 287,293 ****
  
  void EncoderLink::SpawnLiveTV(void)
  {
!     if (local)
      {
          tv->SpawnLiveTV();
          return;
--- 295,301 ----
  
  void EncoderLink::SpawnLiveTV(void)
  {
!     if (tv)
      {
          tv->SpawnLiveTV();
          return;
***************
*** 298,304 ****
  
  void EncoderLink::StopLiveTV(void)
  {
!     if (local)
      {
          tv->StopLiveTV();
          return;
--- 306,312 ----
  
  void EncoderLink::StopLiveTV(void)
  {
!     if (tv)
      {
          tv->StopLiveTV();
          return;
***************
*** 309,315 ****
  
  void EncoderLink::PauseRecorder(void)
  {
!     if (local)
      {
          tv->PauseRecorder();
          return;
--- 317,323 ----
  
  void EncoderLink::PauseRecorder(void)
  {
!     if (tv)
      {
          tv->PauseRecorder();
          return;
***************
*** 320,326 ****
  
  void EncoderLink::ToggleInputs(void)
  {
!     if (local)
      {
          tv->ToggleInputs();
          return;
--- 328,334 ----
  
  void EncoderLink::ToggleInputs(void)
  {
!     if (tv)
      {
          tv->ToggleInputs();
          return;
***************
*** 331,337 ****
  
  void EncoderLink::ToggleChannelFavorite(void)
  {
!     if (local)
      {
          tv->ToggleChannelFavorite();
          return;
--- 339,345 ----
  
  void EncoderLink::ToggleChannelFavorite(void)
  {
!     if (tv)
      {
          tv->ToggleChannelFavorite();
          return;
***************
*** 342,348 ****
  
  void EncoderLink::ChangeChannel(int channeldirection)
  {
!     if (local)
      {
          tv->ChangeChannel(channeldirection);
          return;
--- 350,356 ----
  
  void EncoderLink::ChangeChannel(int channeldirection)
  {
!     if (tv)
      {
          tv->ChangeChannel(channeldirection);
          return;
***************
*** 353,359 ****
  
  void EncoderLink::SetChannel(QString name)
  {
!     if (local)
      {
          tv->SetChannel(name);
          return;
--- 361,367 ----
  
  void EncoderLink::SetChannel(QString name)
  {
!     if (tv)
      {
          tv->SetChannel(name);
          return;
***************
*** 366,372 ****
  {
      int ret = 0;
  
!     if (local)
          ret = tv->ChangeContrast(direction);
      else
          cerr << "Should be local only query: ChangeContrast\n";
--- 374,380 ----
  {
      int ret = 0;
  
!     if (tv)
          ret = tv->ChangeContrast(direction);
      else
          cerr << "Should be local only query: ChangeContrast\n";
***************
*** 378,384 ****
  {
      int ret = 0;
  
!     if (local)
          ret = tv->ChangeBrightness(direction);
      else
          cerr << "Should be local only query: ChangeBrightness\n";
--- 386,392 ----
  {
      int ret = 0;
  
!     if (tv)
          ret = tv->ChangeBrightness(direction);
      else
          cerr << "Should be local only query: ChangeBrightness\n";
***************
*** 390,396 ****
  {
      int ret = 0;
  
!     if (local)
          ret = tv->ChangeColour(direction);
      else
          cerr << "Should be local only query: ChangeColor\n";
--- 398,404 ----
  {
      int ret = 0;
  
!     if (tv)
          ret = tv->ChangeColour(direction);
      else
          cerr << "Should be local only query: ChangeColor\n";
***************
*** 400,406 ****
  
  void EncoderLink::ChangeDeinterlacer(int deinterlacer_mode)
  {
!     if (local)
      {
          tv->ChangeDeinterlacer(deinterlacer_mode);
          return;
--- 408,414 ----
  
  void EncoderLink::ChangeDeinterlacer(int deinterlacer_mode)
  {
!     if (tv)
      {
          tv->ChangeDeinterlacer(deinterlacer_mode);
          return;
***************
*** 411,417 ****
  
  bool EncoderLink::CheckChannel(QString name)
  {
!     if (local)
          return tv->CheckChannel(name);
  
      cerr << "Should be local only query: CheckChannel\n";
--- 419,425 ----
  
  bool EncoderLink::CheckChannel(QString name)
  {
!     if (tv)
          return tv->CheckChannel(name);
  
      cerr << "Should be local only query: CheckChannel\n";
***************
*** 425,431 ****
                                   QString &callsign, QString &iconpath,
                                   QString &channelname, QString &chanid)
  {
!     if (local)
      {
          tv->GetNextProgram(direction,
                             title, subtitle, desc, category, starttime,
--- 433,439 ----
                                   QString &callsign, QString &iconpath,
                                   QString &channelname, QString &chanid)
  {
!     if (tv)
      {
          tv->GetNextProgram(direction,
                             title, subtitle, desc, category, starttime,
***************
*** 442,448 ****
                                   QString &callsign, QString &iconpath,
                                   QString &channelname, QString &chanid)
  {
!     if (local)
      {
          tv->GetChannelInfo(title, subtitle, desc, category, starttime,
                             endtime, callsign, iconpath, channelname, chanid);
--- 450,456 ----
                                   QString &callsign, QString &iconpath,
                                   QString &channelname, QString &chanid)
  {
!     if (tv)
      {
          tv->GetChannelInfo(title, subtitle, desc, category, starttime,
                             endtime, callsign, iconpath, channelname, chanid);
***************
*** 454,460 ****
  
  void EncoderLink::GetInputName(QString &inputname)
  {
!     if (local)
      {
          tv->GetInputName(inputname);
          return;
--- 462,468 ----
  
  void EncoderLink::GetInputName(QString &inputname)
  {
!     if (tv)
      {
          tv->GetInputName(inputname);
          return;
***************
*** 465,471 ****
  
  void EncoderLink::SpawnReadThread(QSocket *rsock)
  {
!     if (local)
      {
          tv->SpawnReadThread(rsock);
          return;
--- 473,479 ----
  
  void EncoderLink::SpawnReadThread(QSocket *rsock)
  {
!     if (tv)
      {
          tv->SpawnReadThread(rsock);
          return;
***************
*** 476,482 ****
  
  void EncoderLink::KillReadThread(void)
  {
!     if (local)
      {
          tv->KillReadThread();
          return;
--- 484,490 ----
  
  void EncoderLink::KillReadThread(void)
  {
!     if (tv)
      {
          tv->KillReadThread();
          return;
***************
*** 487,493 ****
  
  QSocket *EncoderLink::GetReadThreadSocket(void)
  {
!     if (local)
          return tv->GetReadThreadSocket();
  
      cerr << "Should be local only query: GetReadThreadSocket\n";
--- 495,501 ----
  
  QSocket *EncoderLink::GetReadThreadSocket(void)
  {
!     if (tv)
          return tv->GetReadThreadSocket();
  
      cerr << "Should be local only query: GetReadThreadSocket\n";
***************
*** 496,502 ****
  
  void EncoderLink::PauseRingBuffer(void)
  {
!     if (local)
      {
          tv->PauseRingBuffer();
          return;
--- 504,510 ----
  
  void EncoderLink::PauseRingBuffer(void)
  {
!     if (tv)
      {
          tv->PauseRingBuffer();
          return;
***************
*** 507,513 ****
  
  void EncoderLink::UnpauseRingBuffer(void)
  {
!     if (local)
      {
          tv->UnpauseRingBuffer();
          return;
--- 515,521 ----
  
  void EncoderLink::UnpauseRingBuffer(void)
  {
!     if (tv)
      {
          tv->UnpauseRingBuffer();
          return;
***************
*** 518,524 ****
  
  void EncoderLink::PauseClearRingBuffer(void)
  {
!     if (local)
      {
          tv->PauseClearRingBuffer();
          return;
--- 526,532 ----
  
  void EncoderLink::PauseClearRingBuffer(void)
  {
!     if (tv)
      {
          tv->PauseClearRingBuffer();
          return;
***************
*** 529,535 ****
  
  void EncoderLink::RequestRingBufferBlock(int size)
  {
!     if (local)
      {
          tv->RequestRingBufferBlock(size);
          return;
--- 537,543 ----
  
  void EncoderLink::RequestRingBufferBlock(int size)
  {
!     if (tv)
      {
          tv->RequestRingBufferBlock(size);
          return;
***************
*** 541,547 ****
  long long EncoderLink::SeekRingBuffer(long long curpos, long long pos, 
                                        int whence)
  {
!     if (local)
          return tv->SeekRingBuffer(curpos, pos, whence);
  
      cerr << "Should be local only query: SeekRingBuffer\n";
--- 549,555 ----
  long long EncoderLink::SeekRingBuffer(long long curpos, long long pos, 
                                        int whence)
  {
!     if (tv)
          return tv->SeekRingBuffer(curpos, pos, whence);
  
      cerr << "Should be local only query: SeekRingBuffer\n";
***************
*** 552,558 ****
                                   int &bufferlen, int &video_width, 
                                   int &video_height)
  {
!     if (local)
          return tv->GetScreenGrab(filename, secondsin, bufferlen, video_width,
                                   video_height);
  
--- 560,566 ----
                                   int &bufferlen, int &video_width, 
                                   int &video_height)
  {
!     if (tv)
          return tv->GetScreenGrab(filename, secondsin, bufferlen, video_width,
                                   video_height);
  
***************
*** 562,568 ****
  
  bool EncoderLink::isParsingCommercials(ProgramInfo *pginfo)
  {
!     if (local)
          return tv->isParsingCommercials(pginfo);
  
      return false;
--- 570,576 ----
  
  bool EncoderLink::isParsingCommercials(ProgramInfo *pginfo)
  {
!     if (tv)
          return tv->isParsingCommercials(pginfo);
  
      return false;
diff -c -r mythtv-2/programs/mythbackend/encoderlink.h mythtv-3/programs/mythbackend/encoderlink.h
*** mythtv-2/programs/mythbackend/encoderlink.h	2003-05-23 15:49:55.000000000 +1000
--- mythtv-3/programs/mythbackend/encoderlink.h	2003-05-23 16:20:03.000000000 +1000
***************
*** 21,29 ****
      PlaybackSock *getSocket() { return sock; }
      QString getHostname() { return hostname; }
  
!     TVRec *getTV() { return tv; }
! 
!     bool isLocal() { return local; }
  
      bool isConnected();
      int getCardId() { return m_capturecardnum; }
--- 21,27 ----
      PlaybackSock *getSocket() { return sock; }
      QString getHostname() { return hostname; }
  
!     bool isLocal() { return (tv != NULL); }
  
      bool isConnected();
      int getCardId() { return m_capturecardnum; }
***************
*** 90,101 ****
    private:
      int m_capturecardnum;
  
!     PlaybackSock *sock;
!     QString hostname;
! 
!     TVRec *tv;
  
!     bool local;
  
      QDateTime endRecordingTime;
      QDateTime startRecordingTime;
--- 88,97 ----
    private:
      int m_capturecardnum;
  
!     PlaybackSock *sock;		/* connection to remote slave backend */
!     QString hostname;		/* hostname of remote slave backend */
  
!     TVRec *tv;			/* handle for local TV object. Only exists for local cards. */
  
      QDateTime endRecordingTime;
      QDateTime startRecordingTime;


More information about the mythtv-dev mailing list