From patchwork Wed Jun 27 21:05:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 9529 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp1306323jad; Wed, 27 Jun 2018 14:05:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe3vjiw/VIdNRsngPdNmsV6hq77oIrw6QCtwOvIr/dSH1jF2oJ8WM9rLcbqJabJIrTOybyU X-Received: by 2002:a1c:6e19:: with SMTP id j25-v6mr5802935wmc.30.1530133537302; Wed, 27 Jun 2018 14:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530133537; cv=none; d=google.com; s=arc-20160816; b=fJU9wB/Mzysvtp+qtg0mQNHJMu1SzL/mz9ZmgoUUHaFtFek/8f71fX+Y1oh16FeoM4 lSA+wnhv8dflzzkbVcrjDvXJWsCQyyl1/ZYlL5OT7dIiQoAYHUnPuC58y9q1Qw/zwo+Z +DKnOH1fAuqKh3+03dByV1FeqEqsbGpUcuvkDk6kor+tsh90TOHRUTkZ4zOmEpMb8NnS uilsgsXZ+E3TRFJ+myHUSUemutIGNt2sp8+oFq91Z2DNLB+qp1E66jgervrLXppWxLy8 SzxqVLwEzvEH0fYYBozf757BdpgrO9O4VT2g9f7hIRq1OC16poyuvJI2YfZXdjqPzTFQ hC5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=o1U1y12m7xE/9XxvbDDPh08o7yAnIaVRmX15VmZAccI=; b=KGJLSawzqEvdURFqAk9dNKPq/NaYUYVaTACTmI/Foiu01wVSnkdMK7jzqpmggd9Drq DTmpuT9aZcxA2SObatqV1/11OuBsFLKBR8Xs/gzGbUcj8nc/CClIPEM2G7zcQSag4IfR HIYqsL/ORDdtRQsX64XPny1zQtzO29njO+Yw3R/VvcB6IA8jlJN5YgRkCHG8/ETjoVk4 HB2qwJzZa5eiIs5CWOTNK8MA80V1Lifzt+W5ChPjW+VDg0MhQ56E1lp9DvM9WKAq1RpA aq+zbTlSiERtQ5fmFO+boBNrRFmfnuc9lxNsK8xj7fURjwx6F/Kqn8jWaVUqnji75f6y DaRw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r5-v6si4791613wmb.79.2018.06.27.14.05.36; Wed, 27 Jun 2018 14:05:37 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9B48A68A559; Thu, 28 Jun 2018 00:05:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7378468A39E for ; Thu, 28 Jun 2018 00:05:27 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 952FDE103F; Wed, 27 Jun 2018 23:05:28 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Qu-GIfvjdriO; Wed, 27 Jun 2018 23:05:27 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 867F0E1019; Wed, 27 Jun 2018 23:05:27 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 27 Jun 2018 23:05:22 +0200 Message-Id: <20180627210523.22126-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH 1/2] ffmpeg: factorize input thread creation and destruction X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- fftools/ffmpeg.c | 66 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 8d311a9ac8..8f94c5fff2 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4053,49 +4053,63 @@ static void *input_thread(void *arg) return NULL; } +static void free_input_thread(int i) +{ + InputFile *f = input_files[i]; + AVPacket pkt; + + if (!f || !f->in_thread_queue) + return; + av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); + while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0) + av_packet_unref(&pkt); + + pthread_join(f->thread, NULL); + f->joined = 1; + av_thread_message_queue_free(&f->in_thread_queue); +} + static void free_input_threads(void) { int i; - for (i = 0; i < nb_input_files; i++) { - InputFile *f = input_files[i]; - AVPacket pkt; + for (i = 0; i < nb_input_files; i++) + free_input_thread(i); +} - if (!f || !f->in_thread_queue) - continue; - av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); - while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0) - av_packet_unref(&pkt); +static int init_input_thread(int i) +{ + int ret; + InputFile *f = input_files[i]; - pthread_join(f->thread, NULL); - f->joined = 1; + if (nb_input_files == 1) + return 0; + + if (f->ctx->pb ? !f->ctx->pb->seekable : + strcmp(f->ctx->iformat->name, "lavfi")) + f->non_blocking = 1; + ret = av_thread_message_queue_alloc(&f->in_thread_queue, + f->thread_queue_size, sizeof(AVPacket)); + if (ret < 0) + return ret; + + if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { + av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); av_thread_message_queue_free(&f->in_thread_queue); + return AVERROR(ret); } + + return 0; } static int init_input_threads(void) { int i, ret; - if (nb_input_files == 1) - return 0; - for (i = 0; i < nb_input_files; i++) { - InputFile *f = input_files[i]; - - if (f->ctx->pb ? !f->ctx->pb->seekable : - strcmp(f->ctx->iformat->name, "lavfi")) - f->non_blocking = 1; - ret = av_thread_message_queue_alloc(&f->in_thread_queue, - f->thread_queue_size, sizeof(AVPacket)); + ret = init_input_thread(i); if (ret < 0) return ret; - - if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { - av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); - av_thread_message_queue_free(&f->in_thread_queue); - return AVERROR(ret); - } } return 0; }