summaryrefslogtreecommitdiffstats
path: root/libavdevice/alsa.c
diff options
context:
space:
mode:
authorTimothy Pearson <tpearson@raptorengineering.com>2019-11-16 14:04:22 -0600
committerTimothy Pearson <tpearson@raptorengineering.com>2019-11-16 14:04:22 -0600
commit4c4d573f9986a92aea6fea9febf39665a69f51c1 (patch)
tree45945ad979ba71945e3b1611fb4df79efc4c46de /libavdevice/alsa.c
parent20c5f4d8358e5dab2eb87e611167987a4840122a (diff)
downloadffmpeg-streaming-4c4d573f9986a92aea6fea9febf39665a69f51c1.zip
ffmpeg-streaming-4c4d573f9986a92aea6fea9febf39665a69f51c1.tar.gz
Switch FFmpeg to use raw monotonic timestamps
Use ALSA high resolution hardware timestamps if available
Diffstat (limited to 'libavdevice/alsa.c')
-rw-r--r--libavdevice/alsa.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/libavdevice/alsa.c b/libavdevice/alsa.c
index 117b2ea..10ffe56 100644
--- a/libavdevice/alsa.c
+++ b/libavdevice/alsa.c
@@ -174,6 +174,8 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
snd_pcm_format_t format;
snd_pcm_t *h;
snd_pcm_hw_params_t *hw_params;
+ snd_pcm_sw_params_t *sw_params;
+ snd_pcm_status_t *alsa_pcm_status;
snd_pcm_uframes_t buffer_size, period_size;
uint64_t layout = ctx->streams[0]->codecpar->channel_layout;
@@ -269,6 +271,72 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
goto fail;
}
+ s->use_driver_timestamps = 0;
+ if (snd_pcm_hw_params_supports_audio_ts_type(hw_params, 0)) {
+ av_log(ctx, AV_LOG_INFO, "capture device supports compat timestamps\n");
+ s->use_driver_timestamps |= 1;
+ }
+ if (snd_pcm_hw_params_supports_audio_ts_type(hw_params, 1)) {
+ av_log(ctx, AV_LOG_INFO, "capture device supports default timestamps\n");
+ s->use_driver_timestamps |= 2;
+ }
+ if (snd_pcm_hw_params_supports_audio_ts_type(hw_params, 2)) {
+ av_log(ctx, AV_LOG_INFO, "capture device supports link timestamps\n");
+ s->use_driver_timestamps |= 4;
+ }
+ if (snd_pcm_hw_params_supports_audio_ts_type(hw_params, 3)) {
+ av_log(ctx, AV_LOG_INFO, "capture device supports link absolute timestamps\n");
+ s->use_driver_timestamps |= 8;
+ }
+ if (snd_pcm_hw_params_supports_audio_ts_type(hw_params, 4)) {
+ av_log(ctx, AV_LOG_INFO, "capture device supports link estimated timestamps\n");
+ s->use_driver_timestamps |= 16;
+ }
+ if (snd_pcm_hw_params_supports_audio_ts_type(hw_params, 5)) {
+ av_log(ctx, AV_LOG_INFO, "capture device supports link synchronized timestamps\n");
+ s->use_driver_timestamps |= 32;
+ }
+
+ res = snd_pcm_sw_params_malloc(&sw_params);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "cannot allocate software parameter structure (%s)\n",
+ snd_strerror(res));
+ goto fail;
+ }
+
+ res = snd_pcm_sw_params_current(h, sw_params);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "cannot read parameters from device (%s)\n",
+ snd_strerror(res));
+ snd_pcm_sw_params_free(sw_params);
+ goto fail;
+ }
+
+ res = snd_pcm_sw_params_set_tstamp_mode(h, sw_params, SND_PCM_TSTAMP_ENABLE);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "cannot enable timestamps (%s)\n",
+ snd_strerror(res));
+ snd_pcm_sw_params_free(sw_params);
+ goto fail;
+ }
+
+ res = snd_pcm_sw_params_set_tstamp_type(h, sw_params, SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "cannot set timestamp mode (%s)\n",
+ snd_strerror(res));
+ snd_pcm_sw_params_free(sw_params);
+ goto fail;
+ }
+
+ res = snd_pcm_sw_params(h, sw_params);
+ if (res < 0) {
+ av_log(ctx, AV_LOG_ERROR, "cannot set parameters (%s)\n",
+ snd_strerror(res));
+ snd_pcm_sw_params_free(sw_params);
+ goto fail;
+ }
+
+ snd_pcm_sw_params_free(sw_params);
snd_pcm_hw_params_free(hw_params);
if (channels > 2 && layout) {
@@ -286,7 +354,10 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
}
}
+ snd_pcm_status_malloc(&alsa_pcm_status);
+
s->h = h;
+ s->st = alsa_pcm_status;
return 0;
fail:
@@ -308,6 +379,7 @@ av_cold int ff_alsa_close(AVFormatContext *s1)
if (CONFIG_ALSA_INDEV)
ff_timefilter_destroy(s->timefilter);
snd_pcm_close(s->h);
+ snd_pcm_status_free(s->st);
return 0;
}
OpenPOWER on IntegriCloud