From patchwork Mon Jun 7 23:03:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28149 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp3891271iof; Mon, 7 Jun 2021 16:12:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/1Q0YiiVoIJmlhD6KO9kb06OvTgBrgB2lR5q0bGXoF0qYP6DFdGGaamWmabrtmJFpxwLw X-Received: by 2002:a17:907:2059:: with SMTP id pg25mr19027892ejb.130.1623107569612; Mon, 07 Jun 2021 16:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623107569; cv=none; d=google.com; s=arc-20160816; b=kyOynSgau6DstGmEc+jJPbzpmq5OaTeTef1thZjkZklkB7QgHwlTz5eROtbwIOzC/R XODq7g/5V3mM99B1NKXk98lJGwG1pHcM+NGlOI9+s990QOoDqop82RewlaLZokgOha1O voGTtgghyfDY9HCREDBUne9wi2V9nprv7l8VUulBvxJATiwt1MhrqaKTjxip8htHgaor 81LvN8lb1kL7VV8kfZGQyFgR98u067nxsejEq2vLcAY+kVti9dEFza8lbfU7Q81YNVKH DH+dsDp8nKulbl3t94zMtbNDZ6s6TZa/0tV4XQauq/LlnBTqkKXuPLLg/Ns4qpYCVM5h gy1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=bMIwGhjd+cjSoVWar3CDKf/Pn7HxRTW4PpJrPG9NKXI=; b=gwuq0Gah5lKfujqBO3H+PhZsMulGBDCBTQsaf9Ror7PomoCXXKJcOLko+6tZ2E95Sp rLop0PRXFp6hBJyNfXItiovR+bYWVLlmtqstMjujnmDg/DE66Pl7XBMhaRTNxFlNFQ6b Dp1BSGkHbtNRtsTJGnmW3rH6JmhlaJtrdzuhUiiO+FqyJx9vYxUNCCb6qY5haTCxxBOn WWU6WDg29t4qF88ktDPdVDYH64ZrTUMdWmc2KDd4rte1IXA4AE4Lb2dgH+h4CyrJzwLK NQKnAVNtK6Bqm0PbV1RxAT0kpek0PYkWgPcuwxD56ofn3Bej0ksZj5/YhYbKQncu6vaO ATaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eegsU5Hq; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 5si8724043ejh.625.2021.06.07.16.12.49; Mon, 07 Jun 2021 16:12:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eegsU5Hq; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A12DA689888; Tue, 8 Jun 2021 02:12:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 736AE6897E8 for ; Tue, 8 Jun 2021 02:12:35 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id v8so28986149lft.8 for ; Mon, 07 Jun 2021 16:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yw4pbT+q6JVdOQPqoVouNRAO798uCbdtWjU9nA/l3ls=; b=eegsU5HqRGViXJaqrZSziLUb4D22/1PWP+CpOflw4939zxLzrTR/Qz7/TMHARPq/T0 jayiBDT8UvtgggPp8T1pYUp4w5p9w9yZVHpCWv7V6ZijSOpnbULwdqsZXIvAw5JRtUyt Kp1GPTrX53fWKVgBP0h+KflfkEkUXgdXP6VLeRvdoz+AGltO2Kt+4oqTKaVCAvXC54PR xAaEbsd4IHtaw5SZ0iINdiC3rorQykn/Vb7zLVIcLDG2q2eKd3NKRw2AfOVMqntWwRYy 15zf7SjP/G4ZvVh+TQ58HHhG0h2MSx5wx+M4eYu3Ip3zF/V6hv59Lo9V6XQ9Z9VxDHyd g+MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yw4pbT+q6JVdOQPqoVouNRAO798uCbdtWjU9nA/l3ls=; b=ccOks4tuXvdEY/PmYSdTXJYtke+SepooQ9HoF001r+JN25vj5wHPe4YkfJi4oBYgGv Wqn0ABafD0568FoSux3nqSvNSiselCyE8jNEw5ZlCJIPPVkzPSvMvSBu+l92jTA+GUVW uDWTRuSu9a1WuV+8aQFeNK0/8+TXxsyWIqD5RKn2MnkT14P/3cS08rZafo8mB5eo/vMt ryqq0Jd5Xx1z0FjG/EsvRereKozMXEcV1h++58rajyXQKzo7SA1sSSIFYTSTOazUUWla 1crozAlQcZBRen9JLYv5uP9sugypzlfekKg3kIVjztkK8iT/wnpZTZlxtgl2YVF+ewcl 49cw== X-Gm-Message-State: AOAM5328V42PdLkMtO7f6XzDTwqZlTRla5pzBHTbWGUul4BabdfbpIiE VxTaXo2cY+keIp0gHiwNKngt2WEm3/eJjQ== X-Received: by 2002:a19:c793:: with SMTP id x141mr13515098lff.151.1623107078225; Mon, 07 Jun 2021 16:04:38 -0700 (PDT) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id v9sm1999563ljv.131.2021.06.07.16.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 16:04:37 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Jun 2021 01:03:51 +0200 Message-Id: <20210607230414.612-13-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210607230414.612-1-dcnieho@gmail.com> References: <20210607230414.612-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/35] avdevice/dshow: implement control_message interface X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Diederick Niehorster Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lMDwRVklIxAW This allows programmatic users of avdevice to start and stop the DirectShow Capture graph (i.e. receive frames or not). This is important because now the buffer fills up and starts dropping samples when enqueued packets are not read out immediately after the demuxer is opened. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 42 +++++++++++++++++++++++++++++++++++++ libavdevice/dshow_capture.h | 1 + 2 files changed, 43 insertions(+) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 3e41f4f99f..9f041e90f8 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1079,6 +1079,45 @@ error: return ret; } +static int dshow_control_message(AVFormatContext *avctx, int type, void *data, size_t data_size) +{ + struct dshow_ctx *ctx = avctx->priv_data; + int run_state = ctx->is_running; + HRESULT hr; + + switch (type) { + case AV_APP_TO_DEV_PAUSE: + run_state = 0; + break; + case AV_APP_TO_DEV_PLAY: + run_state = 1; + break; + case AV_APP_TO_DEV_TOGGLE_PAUSE: + run_state = !run_state; + break; + } + + // if play state change requested, apply + if (run_state != ctx->is_running) { + if (run_state) + hr = IMediaControl_Run(ctx->control); + else + hr = IMediaControl_Pause(ctx->control); + + if (hr == S_FALSE) { + OAFilterState pfs; + hr = IMediaControl_GetState(ctx->control, 0, &pfs); + } + if (hr != S_OK) { + av_log(avctx, AV_LOG_ERROR, "Could not run/pause graph\n"); + return AVERROR(EIO); + } + ctx->is_running = run_state; + } + + return 0; +} + static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) { switch (sample_fmt) { @@ -1317,6 +1356,7 @@ static int dshow_read_header(AVFormatContext *avctx) } } } + ctx->is_running = 0; if (ctx->device_name[VideoDevice]) { if ((r = dshow_open_device(avctx, devenum, VideoDevice, VideoSourceDevice)) < 0 || (r = dshow_add_device(avctx, VideoDevice)) < 0) { @@ -1390,6 +1430,7 @@ static int dshow_read_header(AVFormatContext *avctx) av_log(avctx, AV_LOG_ERROR, "Could not run graph (sometimes caused by a device already in use by other application)\n"); goto error; } + ctx->is_running = 1; ret = 0; @@ -1502,6 +1543,7 @@ const AVInputFormat ff_dshow_demuxer = { .read_packet = dshow_read_packet, .read_close = dshow_read_close, .get_device_list= dshow_get_device_list, + .control_message = dshow_control_message, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 5a2691518c..bb0f76a8f2 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -331,6 +331,7 @@ struct dshow_ctx { IMediaControl *control; IMediaEvent *media_event; + int is_running; enum AVPixelFormat pixel_format; enum AVCodecID video_codec_id;