[PATCH 2/2] quartz: Use nAvgBytesPerSec to calculate length.

Zebediah Figura z.figura12 at gmail.com
Mon Jun 19 14:15:32 CDT 2017


The current method fails for formats which do not
have a constant sample length, e.g. MPEG.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/quartz/dsoundrender.c |  6 +++---
 dlls/quartz/waveparser.c   | 18 +++++++-----------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/dlls/quartz/dsoundrender.c b/dlls/quartz/dsoundrender.c
index 9e8f69c9fc2..79029554819 100644
--- a/dlls/quartz/dsoundrender.c
+++ b/dlls/quartz/dsoundrender.c
@@ -115,9 +115,9 @@ static REFERENCE_TIME time_from_pos(DSoundRenderImpl *This, DWORD pos) {
 static DWORD pos_from_time(DSoundRenderImpl *This, REFERENCE_TIME time) {
     WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
     REFERENCE_TIME ret = time;
-    ret *= wfx->nSamplesPerSec;
+    ret *= wfx->nAvgBytesPerSec;
     ret /= 10000000;
-    ret *= wfx->nBlockAlign;
+    ret -= ret % wfx->nBlockAlign;
     return ret;
 }
 
@@ -424,7 +424,7 @@ static HRESULT WINAPI DSoundRender_CheckMediaType(BaseRenderer *iface, const AM_
     TRACE("Format = %p\n", format);
     TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
     TRACE("nChannels = %d\n", format->nChannels);
-    TRACE("nSamplesPerSec = %d\n", format->nAvgBytesPerSec);
+    TRACE("nSamplesPerSec = %d\n", format->nSamplesPerSec);
     TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
     TRACE("nBlockAlign = %d\n", format->nBlockAlign);
     TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
diff --git a/dlls/quartz/waveparser.c b/dlls/quartz/waveparser.c
index 6e8c6641e5a..f6bea2c7043 100644
--- a/dlls/quartz/waveparser.c
+++ b/dlls/quartz/waveparser.c
@@ -43,9 +43,8 @@ typedef struct WAVEParserImpl
     ParserImpl Parser;
     LONGLONG StartOfFile; /* in media time */
     LONGLONG EndOfFile;
-    DWORD dwSampleSize;
-    DWORD nSamplesPerSec;
-    DWORD dwLength;
+    DWORD nAvgBytesPerSec;
+    DWORD nBlockAlign;
 } WAVEParserImpl;
 
 static inline WAVEParserImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
@@ -62,7 +61,7 @@ static LONGLONG bytepos_to_duration(WAVEParserImpl *This, LONGLONG bytepos)
 {
     LONGLONG duration = BYTES_FROM_MEDIATIME(bytepos - This->StartOfFile);
     duration *= 10000000;
-    duration /= (This->dwSampleSize * This->nSamplesPerSec);
+    duration /= This->nAvgBytesPerSec;
 
     return duration;
 }
@@ -71,11 +70,11 @@ static LONGLONG duration_to_bytepos(WAVEParserImpl *This, LONGLONG duration)
 {
     LONGLONG bytepos;
 
-    bytepos = (This->dwSampleSize * This->nSamplesPerSec);
+    bytepos = This->nAvgBytesPerSec;
     bytepos *= duration;
     bytepos /= 10000000;
+    bytepos -= bytepos % This->nBlockAlign;
     bytepos += BYTES_FROM_MEDIATIME(This->StartOfFile);
-    bytepos -= bytepos % This->dwSampleSize;
 
     return MEDIATIME_FROM_BYTES(bytepos);
 }
@@ -252,7 +251,6 @@ static HRESULT WAVEParser_InputPin_PreConnect(IPin * iface, IPin * pConnectPin,
     PIN_INFO piOutput;
     AM_MEDIA_TYPE amt;
     WAVEParserImpl * pWAVEParser = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
-    LONGLONG length, avail;
 
     piOutput.dir = PINDIR_OUTPUT;
     piOutput.pFilter = &pWAVEParser->Parser.filter.IBaseFilter_iface;
@@ -321,10 +319,8 @@ static HRESULT WAVEParser_InputPin_PreConnect(IPin * iface, IPin * pConnectPin,
     props->cbPrefix = 0;
     props->cbBuffer = 4096;
     props->cBuffers = 3;
-    pWAVEParser->dwSampleSize = ((WAVEFORMATEX*)amt.pbFormat)->nBlockAlign;
-    IAsyncReader_Length(This->pReader, &length, &avail);
-    pWAVEParser->dwLength = length / (ULONGLONG)pWAVEParser->dwSampleSize;
-    pWAVEParser->nSamplesPerSec = ((WAVEFORMATEX*)amt.pbFormat)->nSamplesPerSec;
+    pWAVEParser->nBlockAlign = ((WAVEFORMATEX*)amt.pbFormat)->nBlockAlign;
+    pWAVEParser->nAvgBytesPerSec = ((WAVEFORMATEX*)amt.pbFormat)->nAvgBytesPerSec;
     hr = Parser_AddPin(&(pWAVEParser->Parser), &piOutput, props, &amt);
     CoTaskMemFree(amt.pbFormat);
 
-- 
2.13.1




More information about the wine-patches mailing list