From patchwork Wed Jun 2 11:28:57 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: 28053 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp456796iof; Wed, 2 Jun 2021 04:29:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxio8IPEC3gO2XofCFbDOr16ccUk+p66iLO4kMUerg+AcR4aXJORbt7q9QuUjxm6Jg09Lzm X-Received: by 2002:a17:906:757:: with SMTP id z23mr24468519ejb.537.1622633392751; Wed, 02 Jun 2021 04:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622633392; cv=none; d=google.com; s=arc-20160816; b=cTn+ln4wsNVl9vfjP67lRA10zLnc0k6XAgc/JC0qbPnlHwwd/m/t5LMz9zxdQwv8P7 lkkythePl+kqc/3gqSdGCqE5sqor04N1L4G11nok7RZUt+cXtEJudHiSNMqBGrWSpRkf TBmeVLhwNu4Ztk6TzXfij/Uogw1Gn2qY3ZqcpxpO9mkWEUvzgRz6SP/vQY9gEgrcedjF SvHETGOM/h3mlpT1ucphREzJi1ZhXR1eF8bZ77KeJ5ETkyoevw636AWcZvbMsc7WaVoq Z7snAhvhR0Z5WS4M+NpcOxcZMip62Hc+4OfCywxQlsQ+cZbAwlTMw5sr2sYuZFSGIte1 lBsQ== 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=OfKMVgVkNmnDGk/e/wwew1owY9r9dKqbJ9B8xLV8dqw=; b=qtqhp9I7HHrU0gSDasZWPQLhTVzQEbhdGQfTaRgBtib8no5VIpIQ47sUmGc6ZYdT0V 5vFpfl9reZ9jQjJrlXVvpyAgLDc5txuuclEwZSvsMtbY8NlI81OBt+gwMRpVt1ubiqh9 RMlmGWFGd+G5fxP2+pgzdUQuMvWiFRbgtdU6x9/xaYb+mdiuuOfjlMy0bPYyhF9mS6iK fgf+imwafcEXvYhvelfVydeBSgweACCmNjV+4CE5J0vIXxeaByeROxMAotPQgkQxLqIZ BQAd9YrYEhvJb/dz28+qzIzIJozzz2DpscNX459iVipQERJjFzLtVbb/3XQ9HTtOAMa8 GWIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=W58Psjcy; 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 j10si18586189ejd.87.2021.06.02.04.29.52; Wed, 02 Jun 2021 04:29:52 -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=W58Psjcy; 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 2CF2D68A046; Wed, 2 Jun 2021 14:29:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5B58689DAB for ; Wed, 2 Jun 2021 14:29:21 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id j10so2786821lfb.12 for ; Wed, 02 Jun 2021 04:29:21 -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=NZOBSLBHMHm3wos2u3cHUBvplpkk2bSMror5SpJDB/o=; b=W58PsjcyGdHt8cEoVRHBkt6xHrFcISf1fDKeYjsdznu92WqoteVH7NymN/qFGN1fpz rj5SwqVW96pQF9kQfpij+RHt2DNSwLwv6lMQBRYiqhBY71vAau+xPxQmi3NlweMIBHBv Bvqpr3zpgmVIv3+cevQpn9AKIIA/28H/yQ+rC0Hq4eFDg0tOXJbYaPcj/jJi0O2eM6FN I5fqjBhQfbWGK9tvGGjTyUSrh8+LJ1yJ6S6Osoz4DO+lmQx0FyVuLZpquMQGB/7khs/v z2leQHpg/xjUeBJceeMulSdSteLD/1mx0FIDQre+FEQMqWgTfiauE2k9Pe5iZfrSX6el JXQA== 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=NZOBSLBHMHm3wos2u3cHUBvplpkk2bSMror5SpJDB/o=; b=cHzx8bPJA00bq/Wd7WE+S7Y4PtH3nonDqjlNtdNYF2eJ8DQMDoxmzsMorN6JT8bhsI SRvBedw/2UmK8MM3ee+lncWEaju8pk1v71AD6JObPs5NP34q9gHwKDQSn+g15AFcKmaX yR2gfN3N2HQAoibtOqF+TyNCfzNodf1PZyIg4ACIkLwMt/aHoLM1N+Rc/jrQdghlL7C+ XYjPb1xRPvQqOlUV3Z8fM8kWY6i6H3TxC7O6iP05HNPAlWBqnTRuWSShqDJENwLy6GR1 uNIlMyQgUtkDgwjS+cBimWeyWH9espML8WSKjkFoRv0el2j6yhvbj6iyQ6H06zHj2tid wAXA== X-Gm-Message-State: AOAM531PWUHdKHqAqPAmLz1pNcH3CU9lUUDO79NBfc22f1rRLTZhn74h oAKiYPZ9Gx6bnecxpyYtqpdC/YjNBXqxXw== X-Received: by 2002:ac2:5c03:: with SMTP id r3mr21359122lfp.504.1622633361003; Wed, 02 Jun 2021 04:29:21 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id v6sm1249497lfr.182.2021.06.02.04.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 04:29:20 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Jun 2021 13:28:57 +0200 Message-Id: <20210602112901.2163-3-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210602112901.2163-1-dcnieho@gmail.com> References: <20210602112901.2163-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] 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: 1vv/wLtfq3gC 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 | 41 +++++++++++++++++++++++++++++++++++++ libavdevice/dshow_capture.h | 1 + 2 files changed, 42 insertions(+) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 8d0a6fcc09..6e0147aed7 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -912,6 +912,44 @@ 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; + int r; + + 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 (run_state != ctx->is_running) { + if (run_state) + r = IMediaControl_Run(ctx->control); + else + r = IMediaControl_Pause(ctx->control); + + if (r == S_FALSE) { + OAFilterState pfs; + r = IMediaControl_GetState(ctx->control, 0, &pfs); + } + if (r != 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) { @@ -1152,6 +1190,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) { @@ -1225,6 +1264,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; @@ -1335,6 +1375,7 @@ const AVInputFormat ff_dshow_demuxer = { .read_header = dshow_read_header, .read_packet = dshow_read_packet, .read_close = dshow_read_close, + .control_message = dshow_control_message, .flags = AVFMT_NOFILE, .priv_class = &dshow_class, }; diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 06ded2ba96..b7ef3770df 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -330,6 +330,7 @@ struct dshow_ctx { IMediaControl *control; IMediaEvent *media_event; + int is_running; enum AVPixelFormat pixel_format; enum AVCodecID video_codec_id;