void QVideoSurfaceGstSink::setFrameTimeStamps(QVideoFrame *frame, GstBuffer *buffer)
{
+ // GStreamer uses nanoseconds, Qt uses microseconds
qint64 startTime = GST_BUFFER_TIMESTAMP(buffer);
if (startTime >= 0) {
- frame->setStartTime(startTime/G_GINT64_CONSTANT (1000000));
+ frame->setStartTime(startTime/G_GINT64_CONSTANT (1000));
qint64 duration = GST_BUFFER_DURATION(buffer);
if (duration >= 0)
- frame->setEndTime((startTime + duration)/G_GINT64_CONSTANT (1000000));
+ frame->setEndTime((startTime + duration)/G_GINT64_CONSTANT (1000));
}
}
}
if (surface && updateTexture(surface)) {
- m_surface->present(QVideoFrame(new TextureVideoBuffer(m_glTexture),
- m_surfaceFormat.frameSize(),
- m_surfaceFormat.pixelFormat()));
+ QVideoFrame frame = QVideoFrame(new TextureVideoBuffer(m_glTexture),
+ m_surfaceFormat.frameSize(),
+ m_surfaceFormat.pixelFormat());
+
+ // WMF uses 100-nanosecond units, Qt uses microseconds
+ LONGLONG startTime = -1;
+ if (SUCCEEDED(sample->GetSampleTime(&startTime))) {
+ frame.setStartTime(startTime * 0.1);
+
+ LONGLONG duration = -1;
+ if (SUCCEEDED(sample->GetSampleDuration(&duration)))
+ frame.setEndTime((startTime + duration) * 0.1);
+ }
+
+ m_surface->present(frame);
}
done:
// That is why we copy data from IMFMediaBuffer here.
frame = QVideoFrame(new QMemoryVideoBuffer(array, m_bytesPerLine), m_format.frameSize(), m_format.pixelFormat());
+ // WMF uses 100-nanosecond units, Qt uses microseconds
LONGLONG startTime = -1;
if (SUCCEEDED(m_sample->GetSampleTime(&startTime))) {
- frame.setStartTime(startTime);
+ frame.setStartTime(startTime * 0.1);
LONGLONG duration = -1;
if (SUCCEEDED(m_sample->GetSampleDuration(&duration)))
- frame.setEndTime(startTime + duration);
+ frame.setEndTime((startTime + duration) * 0.1);
}
} while (false);
, m_workQueueCB(this, &MediaStream::onDispatchWorkItem)
, m_finalizeResult(0)
, m_scheduledBuffer(0)
+ , m_bufferStartTime(-1)
+ , m_bufferDuration(-1)
, m_presentationClock(0)
, m_currentMediaType(0)
, m_prerolling(false)
QMutexLocker locker(&m_mutex);
if (!m_scheduledBuffer)
return;
- m_surface->present(QVideoFrame(
- new MediaSampleVideoBuffer(m_scheduledBuffer, m_bytesPerLine),
- m_surfaceFormat.frameSize(),
- m_surfaceFormat.pixelFormat()));
+ QVideoFrame frame = QVideoFrame(
+ new MediaSampleVideoBuffer(m_scheduledBuffer, m_bytesPerLine),
+ m_surfaceFormat.frameSize(),
+ m_surfaceFormat.pixelFormat());
+ frame.setStartTime(m_bufferStartTime * 0.1);
+ frame.setEndTime((m_bufferStartTime + m_bufferDuration) * 0.1);
+ m_surface->present(frame);
m_scheduledBuffer->Release();
m_scheduledBuffer = NULL;
if (m_rate != 0)
HRESULT processSampleData(IMFSample *pSample)
{
- LONGLONG time;
+ LONGLONG time, duration = -1;
HRESULT hr = pSample->GetSampleTime(&time);
+ if (SUCCEEDED(hr))
+ pSample->GetSampleDuration(&duration);
if (m_prerolling) {
if (SUCCEEDED(hr) && time >= m_prerollTargetTime) {
SampleBuffer sb;
sb.m_buffer = pBuffer;
sb.m_time = time;
+ sb.m_duration = duration;
m_bufferCache.push_back(sb);
endPreroll(S_OK);
}
SampleBuffer sb;
sb.m_buffer = pBuffer;
sb.m_time = time;
+ sb.m_duration = duration;
m_bufferCache.push_back(sb);
}
if (m_rate == 0)
public:
IMFMediaBuffer *m_buffer;
LONGLONG m_time;
+ LONGLONG m_duration;
};
QList<SampleBuffer> m_bufferCache;
static const int BUFFER_CACHE_SIZE = 2;
continue;
}
m_scheduledBuffer = sb.m_buffer;
+ m_bufferStartTime = sb.m_time;
+ m_bufferDuration = sb.m_duration;
QCoreApplication::postEvent(m_rendererControl, new PresentEvent(sb.m_time));
if (m_rate == 0)
queueEvent(MEStreamSinkScrubSampleComplete, GUID_NULL, S_OK, NULL);
queueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, NULL);
}
IMFMediaBuffer *m_scheduledBuffer;
+ MFTIME m_bufferStartTime;
+ MFTIME m_bufferDuration;
IMFPresentationClock *m_presentationClock;
float m_rate;
};