[mythtv] [PATCH] audio sync adjustment

Neale Swinnerton mythtv-dev.spam at isismanor.com
Tue May 31 06:27:16 UTC 2005


Here's my version of the patch....

You'll probably notice that this isn't a cvs diff

it's a patch against a cvs export -D "2005-05-30", but from the commits
list there aren't any changes to that file since.

Neale



Mark Spieth wrote:
> can you do a diff on yours for this file and post please. Im not sure what
> Im doing wrong but obviously I have too many changes in my
> NuppelVideoPlay.cpp to edit them out correctly.
> thanks
> mark
> ----- Original Message ----- 
> From: "Neale Swinnerton" <mythtv-dev.spam at isismanor.com>
> To: "Development of mythtv" <mythtv-dev at mythtv.org>
> Sent: Tuesday, May 31, 2005 3:45 PM
> Subject: Re: [mythtv] [PATCH] audio sync adjustment
> 
> 
> 
>>Hi Mark,
>>
>>I was still getting rejects in NuppelVideoPlayer.cpp, but I fixed them
>>by hand and this is working really well now. This has been the last real
>>problem for me, so you work is very much appreciated.
>>
>>Thanks
>>
>>Neale.
>>
>>
>>Mark Spieth wrote:
>>
>>>>Hi Mark,
>>>>
>>>>Did you edit this patch? it was coming up as malformed when I tried to
>>>>apply it. I added a blank line at line 54 to 'fix' it, so that it'd
> 
> apply.
> 
>>>>Neale.
>>>>
>>>
>>>yes I did. sorry about this. should have checked its integrity. have
> 
> now.
> 
>>>had to remove the irrelevant bits from other things Im working on.
>>>
>>>attached is a patched patch.
>>>
>>>also the keys it uses is left/right adjust by 10ms
>>>up/down adjust by 100ms.
>>>cheers
>>>mark
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>_______________________________________________
>>>mythtv-dev mailing list
>>>mythtv-dev at mythtv.org
>>>http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>>
>>_______________________________________________
>>mythtv-dev mailing list
>>mythtv-dev at mythtv.org
>>http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>>
> 
> 
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
> 
-------------- next part --------------
diff -ruw mythtv-20050530/libs/libmythtv/NuppelVideoPlayer.cpp mythtv-20050530.patched/libs/libmythtv/NuppelVideoPlayer.cpp
--- mythtv-20050530/libs/libmythtv/NuppelVideoPlayer.cpp	2005-05-24 03:59:13.000000000 +0100
+++ mythtv-20050530.patched/libs/libmythtv/NuppelVideoPlayer.cpp	2005-05-30 08:30:10.960442423 +0100
@@ -211,6 +211,7 @@
     videosync = NULL;
 
     errored = false;
+    audio_timecode_offset = 0;
 }
 
 NuppelVideoPlayer::~NuppelVideoPlayer(void)
@@ -1439,9 +1440,31 @@
     if (audioOutput && normal_speed)
     {
         // ms, same scale as timecodes
-        lastaudiotime = audioOutput->GetAudiotime();
+         lastaudiotime = audioOutput->GetAudiotime() + audio_timecode_offset;
+         VERBOSE(VB_PLAYBACK, QString("A/V timecodes audio %1 video %2 frameinterval %3 avdel %4 avg %5 tcoffset %6")
+                 .arg(lastaudiotime)
+                 .arg(buffer->timecode)
+                 .arg(frame_interval)
+                 .arg(buffer->timecode - lastaudiotime)
+                 .arg(avsync_avg)
+                 .arg(audio_timecode_offset)
+                 );
         if (lastaudiotime != 0 && buffer->timecode != 0)
-        { // lastaudiotime = 0 after a seek
+          { // lastaudiotime == 0 after a seek
+             if (labs(buffer->timecode - lastaudiotime)>1000000)
+             {
+                 VERBOSE(VB_IMPORTANT, QString("A/V timecodes audio %1 video %2 frameinterval %3 avdel %4 avg %5")
+                         .arg(lastaudiotime)
+                         .arg(buffer->timecode)
+                         .arg(frame_interval)
+                         .arg(buffer->timecode - lastaudiotime)
+                         .arg(avsync_avg)
+                         );
+                 lastaudiotime = audioOutput->GetAudiotime();
+                 audio_timecode_offset = buffer->timecode - lastaudiotime;
+                 VERBOSE(VB_IMPORTANT, QString("A/V audio timecode instantaneously diverged by %1")
+                         .arg(audio_timecode_offset));
+             }
             // The time at the start of this frame (ie, now) is given by
             // last->timecode
             int delta = buffer->timecode - prevtc - (frame_interval / 1000);
diff -ruw mythtv-20050530/libs/libmythtv/NuppelVideoPlayer.h mythtv-20050530.patched/libs/libmythtv/NuppelVideoPlayer.h
--- mythtv-20050530/libs/libmythtv/NuppelVideoPlayer.h	2005-05-05 03:51:15.000000000 +0100
+++ mythtv-20050530.patched/libs/libmythtv/NuppelVideoPlayer.h	2005-05-30 08:28:07.182032776 +0100
@@ -209,6 +209,12 @@
 
     bool IsErrored() { return errored; }
 
+    long long GetAudioTimecodeOffset() { return audio_timecode_offset; }
+    long long AdjustAudioTimecodeOffset(long long v) { 
+        audio_timecode_offset += v;
+        return audio_timecode_offset; 
+    }
+
  protected:
     void DisplayPauseFrame(void);
     void DisplayNormalFrame(void);
@@ -425,13 +431,14 @@
     DecoderBase *decoder;
 
     /* avsync stuff */
-    int lastaudiotime;
+    long long lastaudiotime;
     int delay;
     int avsync_delay;
     int avsync_adjustment;
     int avsync_avg;
     int avsync_oldavg;
     int refreshrate;
+    long long audio_timecode_offset;
 
     QMutex decoder_lock;
     int frame_interval; // always adjusted for play_speed
diff -ruw mythtv-20050530/libs/libmythtv/osd.h mythtv-20050530.patched/libs/libmythtv/osd.h
--- mythtv-20050530/libs/libmythtv/osd.h	2005-04-01 03:38:31.000000000 +0100
+++ mythtv-20050530.patched/libs/libmythtv/osd.h	2005-05-30 08:28:07.185032277 +0100
@@ -21,7 +21,8 @@
     kOSDFunctionalType_PictureAdjust,
     kOSDFunctionalType_RecPictureAdjust,
     kOSDFunctionalType_SmartForward,
-    kOSDFunctionalType_TimeStretchAdjust
+    kOSDFunctionalType_TimeStretchAdjust,
+    kOSDFunctionalType_AudioSyncAdjust
 };
 
 class QImage;
diff -ruw mythtv-20050530/libs/libmythtv/tv_play.cpp mythtv-20050530.patched/libs/libmythtv/tv_play.cpp
--- mythtv-20050530/libs/libmythtv/tv_play.cpp	2005-05-27 01:59:21.000000000 +0100
+++ mythtv-20050530.patched/libs/libmythtv/tv_play.cpp	2005-05-30 08:28:07.184032443 +0100
@@ -185,7 +185,9 @@
       internalState(kState_None), nextState(kState_None), changeState(false),
       menurunning(false), runMainLoop(false), wantsToQuit(true), 
       exitPlayer(false), paused(false), errored(false),
-      stretchAdjustment(false), editmode(false), zoomMode(false),
+      stretchAdjustment(false), 
+      audiosyncAdjustment(false),
+      editmode(false), zoomMode(false),
       update_osd_pos(false), endOfRecording(false), requestDelete(false),
       doSmartForward(false), switchingCards(false), lastRecorderNum(-1),
       queuedTranscode(false), getRecorderPlaybackInfo(false), 
@@ -1591,6 +1593,28 @@
         }
     }
    
+    if (audiosyncAdjustment)
+    {
+        for (unsigned int i = 0; i < actions.size(); i++)
+        {
+            action = actions[i];
+            handled = true;
+
+            if (action == "LEFT")
+                ChangeAudioSync(-1);
+            else if (action == "RIGHT")
+                ChangeAudioSync(1);
+            else if (action == "UP")
+                ChangeAudioSync(-10);
+            else if (action == "DOWN")
+                ChangeAudioSync(10);
+            else if (action == "TOGGLEAUDIOSYNC")
+                ClearOSD();
+            else
+                handled = false;
+        }
+    }
+   
     if (handled)
         return;
 
@@ -1657,6 +1681,8 @@
         {
             ChangeTimeStretch(0);   // just display
         }
+        else if (action == "TOGGLEAUDIOSYNC")
+            ChangeAudioSync(0);   // just display
         else if (action == "TOGGLEPICCONTROLS")
         {
             if (usePicControls)
@@ -3393,6 +3419,29 @@
     }
 }
 
+// dir in 10ms jumps
+void TV::ChangeAudioSync(int dir, bool allowEdit)
+{
+    if (!audiosyncAdjustment)
+        audiosyncBaseline = activenvp->GetAudioTimecodeOffset();
+
+    audiosyncAdjustment = allowEdit;
+
+    long long newval = activenvp->AdjustAudioTimecodeOffset(dir*10) - 
+                        audiosyncBaseline;
+
+    if (osd && !browsemode)
+    {
+        QString text = QString(" %1 ms").arg(newval);
+        text = tr("Audio Sync") + text;
+
+        int val = (int)newval;
+        osd->StartPause((val/2)+500, false, tr("Adjust Audio Sync"), text, 10, 
+                        kOSDFunctionalType_AudioSyncAdjust);
+        update_osd_pos = false;
+    }
+}
+
 void TV::ToggleMute(void)
 {
     kMuteState mute_status;
@@ -3766,6 +3815,9 @@
         case kOSDFunctionalType_TimeStretchAdjust:
             stretchAdjustment = false;
             break;
+        case kOSDFunctionalType_AudioSyncAdjust:
+            audiosyncAdjustment = false;
+            break;
         case kOSDFunctionalType_Default:
             break;
     }
@@ -3948,6 +4000,8 @@
 
         ChangeTimeStretch(0, !floatRead);   // just display
     }
+    else if (action.left(15) == "TOGGLEAUDIOSYNC")
+        ChangeAudioSync(0);
     else if (action.left(11) == "TOGGLESLEEP")
     {
         ToggleSleepTimer(action.left(13));
@@ -4161,6 +4215,8 @@
     item = new OSDGenericTree(treeMenu, tr("Manual Zoom Mode"), 
                              "TOGGLEMANUALZOOM");
 
+    item = new OSDGenericTree(treeMenu, tr("Adjust Audio Sync"), "TOGGLEAUDIOSYNC");
+
     int speedX100 = (int)(round(normal_speed * 100));
     item = new OSDGenericTree(treeMenu, tr("Adjust Time Stretch"), "TOGGLESTRETCH");
     subitem = new OSDGenericTree(item, tr("Adjust"), "TOGGLESTRETCH");
diff -ruw mythtv-20050530/libs/libmythtv/tv_play.h mythtv-20050530.patched/libs/libmythtv/tv_play.h
--- mythtv-20050530/libs/libmythtv/tv_play.h	2005-05-27 01:59:21.000000000 +0100
+++ mythtv-20050530.patched/libs/libmythtv/tv_play.h	2005-05-30 08:28:07.185032277 +0100
@@ -153,6 +153,7 @@
     void NormalSpeed(void);
     void ChangeSpeed(int direction);
     void ChangeTimeStretch(int dir, bool allowEdit = true);
+    void ChangeAudioSync(int dir, bool allowEdit = true);
     float StopFFRew(void);
     void ChangeFFRew(int direction);
     void SetFFRew(int index);
@@ -245,6 +246,8 @@
     bool paused;
     bool errored;
     bool stretchAdjustment; // is time stretch turned on
+    bool audiosyncAdjustment; // is audiosync turned on
+    long long audiosyncBaseline;
     bool editmode;       // are we in video editing mode
     bool zoomMode;
     bool update_osd_pos; // redisplay osd?


More information about the mythtv-dev mailing list