avdevice/dshow: handle unknown sample time
GetTime may return an error indication that the sample has not timestamps, or may return a NULL start time. In those cases, fall back to graph time. Emit log when that happens. Improve logging in the frame receive function: now logged against correct avclass instead of NULL. Better debug message in case sample dropped: could now be audio or video frame. Signed-off-by: Diederick Niehorster <dcnieho@gmail.com> Reviewed-by: Roger Pack <rogerdpack2@gmail.com>
This commit is contained in:
committed by
Gyan Doshi
parent
584b0fbe4b
commit
271e55987f
@@ -295,14 +295,15 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample)
|
|||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
int buf_size; /* todo should be a long? */
|
int buf_size; /* todo should be a long? */
|
||||||
int index;
|
int index;
|
||||||
int64_t chosentime;
|
int64_t chosentime = 0;
|
||||||
int64_t sampletime;
|
int64_t sampletime = 0;
|
||||||
int64_t graphtime;
|
int64_t graphtime = 0;
|
||||||
int use_sample_time = 1;
|
int use_sample_time = 1;
|
||||||
const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
|
const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
|
||||||
IReferenceClock *clock = pin->filter->clock;
|
IReferenceClock *clock = pin->filter->clock;
|
||||||
int64_t dummy;
|
int64_t dummy;
|
||||||
struct dshow_ctx *ctx;
|
struct dshow_ctx *ctx;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
|
||||||
dshowdebug("ff_dshow_meminputpin_Receive(%p)\n", this);
|
dshowdebug("ff_dshow_meminputpin_Receive(%p)\n", this);
|
||||||
@@ -314,22 +315,28 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample)
|
|||||||
s = priv_data;
|
s = priv_data;
|
||||||
ctx = s->priv_data;
|
ctx = s->priv_data;
|
||||||
|
|
||||||
IMediaSample_GetTime(sample, &sampletime, &dummy);
|
hr = IMediaSample_GetTime(sample, &sampletime, &dummy);
|
||||||
IReferenceClock_GetTime(clock, &graphtime);
|
IReferenceClock_GetTime(clock, &graphtime);
|
||||||
if (devtype == VideoDevice && !ctx->use_video_device_timestamps) {
|
if (devtype == VideoDevice && !ctx->use_video_device_timestamps) {
|
||||||
/* PTS from video devices is unreliable. */
|
/* PTS from video devices is unreliable. */
|
||||||
chosentime = graphtime;
|
chosentime = graphtime;
|
||||||
use_sample_time = 0;
|
use_sample_time = 0;
|
||||||
} else {
|
} else {
|
||||||
if (sampletime > 400000000000000000LL) {
|
if (hr == VFW_E_SAMPLE_TIME_NOT_SET || sampletime == 0) {
|
||||||
|
chosentime = graphtime;
|
||||||
|
use_sample_time = 0;
|
||||||
|
av_log(s, AV_LOG_DEBUG,
|
||||||
|
"frame with missing sample timestamp encountered, falling back to graph timestamp\n");
|
||||||
|
}
|
||||||
|
else if (sampletime > 400000000000000000LL) {
|
||||||
/* initial frames sometimes start < 0 (shown as a very large number here,
|
/* initial frames sometimes start < 0 (shown as a very large number here,
|
||||||
like 437650244077016960 which FFmpeg doesn't like).
|
like 437650244077016960 which FFmpeg doesn't like).
|
||||||
TODO figure out math. For now just drop them. */
|
TODO figure out math. For now just drop them. */
|
||||||
av_log(NULL, AV_LOG_DEBUG,
|
av_log(s, AV_LOG_DEBUG,
|
||||||
"dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", sampletime);
|
"dropping initial (or ending) sample with odd PTS too high %"PRId64"\n", sampletime);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
} else
|
||||||
chosentime = sampletime;
|
chosentime = sampletime;
|
||||||
}
|
}
|
||||||
// media sample time is relative to graph start time
|
// media sample time is relative to graph start time
|
||||||
sampletime += pin->filter->start_time;
|
sampletime += pin->filter->start_time;
|
||||||
@@ -340,7 +347,7 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample)
|
|||||||
IMediaSample_GetPointer(sample, &buf);
|
IMediaSample_GetPointer(sample, &buf);
|
||||||
index = pin->filter->stream_index;
|
index = pin->filter->stream_index;
|
||||||
|
|
||||||
av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d "
|
av_log(s, AV_LOG_VERBOSE, "passing through packet of type %s size %8d "
|
||||||
"timestamp %"PRId64" orig timestamp %"PRId64" graph timestamp %"PRId64" diff %"PRId64" %s\n",
|
"timestamp %"PRId64" orig timestamp %"PRId64" graph timestamp %"PRId64" diff %"PRId64" %s\n",
|
||||||
devtypename, buf_size, chosentime, sampletime, graphtime, graphtime - sampletime, ctx->device_name[devtype]);
|
devtypename, buf_size, chosentime, sampletime, graphtime, graphtime - sampletime, ctx->device_name[devtype]);
|
||||||
pin->filter->callback(priv_data, index, buf, buf_size, chosentime, devtype);
|
pin->filter->callback(priv_data, index, buf, buf_size, chosentime, devtype);
|
||||||
|
Reference in New Issue
Block a user