Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Semi-correct audio/video timing info for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
anantn committed Apr 15, 2011
1 parent a110cd5 commit 8b8dd63
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
1 change: 1 addition & 0 deletions components/MediaRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 345,7 @@ MediaRecorder::Encode()
}
if (!(v_frame = GetVideoPacket(&vlen, &vtime))) {
fprintf(stderr, "GetVideoPacket returned NULL\n");
goto finish;
}
delta = vtime - current_audio_time;
}
Expand Down
20 changes: 3 additions & 17 deletions components/WINNT/AudioSourceWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 95,11 @@ AudioSourceWin::Start(nsIOutputStream *pipe)
}

/* Establish baseline stream time with absolute time since epoch */
PRUint32 wr;
PRTime epoch_c = PR_Now();
start = PR_IntervalNow();
epoch = (PRFloat64)(epoch_c / MICROSECONDS);
PRFloat64 epoch = (PRFloat64)(epoch_c / MICROSECONDS);
epoch = ((PRFloat64)(epoch_c % MICROSECONDS)) / MICROSECONDS;
pipe->Write((const char *)&epoch, sizeof(PRFloat64), &wr);

/* Go! */
if (waveInStart(handle)) {
Expand Down Expand Up @@ -140,13 141,6 @@ AudioSourceWin::Callback(void *data)
WAVEHDR *hdr;
AudioSourceWin *asw = static_cast<AudioSourceWin*>(data);

/* Calculate time delta
PRUint64 delta = PR_IntervalToMilliseconds(
PR_IntervalNow() - asw->start
) * 1000;
PRFloat64 current = asw->epoch (PRFloat64)(delta/MICROSECONDS)
((PRFloat64)(delta % MICROSECONDS)) / MICROSECONDS;
*/
PRFloat64 current = 0.0;

/* This MSG comes from the audio driver */
Expand All @@ -156,14 150,6 @@ AudioSourceWin::Callback(void *data)
/* A buffer has been filled by the driver */
hdr = (WAVEHDR *)msg.lParam;
if (hdr->dwBytesRecorded) {
/* Write timestamp and length */
rv = asw->output->Write(
(const char *)&current, sizeof(PRFloat64), &wr
);
rv = asw->output->Write(
(const char *)&hdr->dwBytesRecorded, sizeof(PRUint32), &wr
);

/* Write samples to pipe */
rv = asw->output->Write(
(const char *)((WAVEHDR *)msg.lParam)->lpData,
Expand Down
2 changes: 0 additions & 2 deletions components/WINNT/AudioSourceWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 58,6 @@ class AudioSourceWin : public AudioSource {
WAVEFORMATEX format;
WAVEHDR buffer[NUM_BUFFERS];

PRTime epoch;
PRIntervalTime start;
nsIOutputStream *output;
static DWORD WINAPI Callback(void *arg);

Expand Down
9 changes: 7 additions & 2 deletions components/WINNT/VideoSourceWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 471,14 @@ VideoSourceWin::SampleCB(double Time, IMediaSample *pSample)
if (is_rec != PR_TRUE)
return S_OK;

PRFloat64 current = epoch Time;
//PRFloat64 current = epoch Time;
PRTime epoch_c = PR_Now();
PRFloat64 epoch = (PRFloat64)(epoch_c / MICROSECONDS);
epoch = ((PRFloat64)(epoch_c % MICROSECONDS)) / MICROSECONDS;
epoch -= Time;

rv = output->Write(
(const char *)&current, sizeof(PRFloat64), &wr
(const char *)&epoch, sizeof(PRFloat64), &wr
);
rv = output->Write(
(const char *)&isize, sizeof(PRUint32), &wr
Expand Down

0 comments on commit 8b8dd63

Please sign in to comment.