Skip to content

Instantly share code, notes, and snippets.

@blurbdust
Last active August 21, 2024 00:49
Show Gist options
  • Save blurbdust/5fa38b6e854d4cfe251a466131bd9b0c to your computer and use it in GitHub Desktop.
Save blurbdust/5fa38b6e854d4cfe251a466131bd9b0c to your computer and use it in GitHub Desktop.
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 84db151577..84e6adbaf0 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -1003,10 +1003,28 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
);
goto next;
}
+ if (ctx->sample_rate) {
+ if (ctx->sample_rate > acaps->MaximumSampleFrequency ||
+ ctx->sample_rate < acaps->MinimumSampleFrequency)
+ goto next;
+ fx->nSamplesPerSec = ctx->sample_rate;
+ }
+ if (ctx->sample_size) {
+ if (ctx->sample_size > acaps->MaximumBitsPerSample ||
+ ctx->sample_size < acaps->MinimumBitsPerSample)
+ goto next;
+ fx->wBitsPerSample = ctx->sample_size;
+ }
+ if (ctx->channels) {
+ if (ctx->channels > acaps->MaximumChannels ||
+ ctx->channels < acaps->MinimumChannels)
+ goto next;
+ fx->nChannels = ctx->channels;
+ }
if (
- (requested_sample_rate && requested_sample_rate != fx->nSamplesPerSec) ||
- (requested_sample_size && requested_sample_size != fx->wBitsPerSample) ||
- (requested_channels && requested_channels != fx->nChannels )
+ (ctx->sample_rate && ctx->sample_rate != fx->nSamplesPerSec) ||
+ (ctx->sample_size && ctx->sample_size != fx->wBitsPerSample) ||
+ (ctx->channels && ctx->channels != fx->nChannels )
) {
goto next;
}
@@ -1895,7 +1913,7 @@ static const AVOption options[] = {
{ "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_NONE}, -1, INT_MAX, DEC },
{ "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
{ "sample_rate", "set audio sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
- { "sample_size", "set audio sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 16, DEC },
+ { "sample_size", "set audio sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 32, DEC },
{ "channels", "set number of audio channels, such as 1 or 2", OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "audio_buffer_size", "set audio device buffer latency size in milliseconds (default is the device's default)", OFFSET(audio_buffer_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
{ "list_devices", "list available devices", OFFSET(list_devices), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, DEC },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment