From patchwork Sun Jan 26 16:42:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Federico Simoncelli X-Patchwork-Id: 17564 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2A1EC449DA2 for ; Sun, 26 Jan 2020 19:13:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1305468AAF0; Sun, 26 Jan 2020 19:13:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C1E2C6805A2 for ; Sun, 26 Jan 2020 19:13:01 +0200 (EET) Received: by mail-ed1-f68.google.com with SMTP id m13so8389484edb.6 for ; Sun, 26 Jan 2020 09:13:01 -0800 (PST) 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=G9E5ARku69QeFEKuciPAUGLu33Gg7CQeKMTVHCbeRco=; b=tDiBFhd9J489U8aeyn0r1EK234ruTZuQ1MORj7oxvn/U7aSij/EE0dBUk+oNpUfW7Q EXAKYlxpN1AHYB1V05AY4bshss893SB1FeSEhpHq+WID8dTGk/ysf+jdBgbmFR4SIVn/ 4KObF/1yHg5KmP7/S6fvQgghOhdRr09gQxHnUwHdQVLOrDactttQQ797u31aaFXnW3wm +lXgk2tROZfQ+luramx4hNY25dqIQb7Wh+nwbJ4Xt1kcFcqEuKe2C6DZAXHViBwvY4sd +wEXmOaLYx7fouNDAW3rtIC75353vnMVytHG7po0QXiIbmsp1xxlnrgzpSPPtHx7a16m 4VrA== 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=G9E5ARku69QeFEKuciPAUGLu33Gg7CQeKMTVHCbeRco=; b=EXVZ4LL/FgDcSJGtYMWCjm7Rdgs1SuopVh1mr2iJml0t48585apFYgFlO5dNlUvfya JrbZy0jBHxGa0fqqJ4ecYGVAVtnKsOOJJZF5W8bYeIork1GCerA/+7teFKKWeHgkLw3X n71fU3xoZTW1KyQfP2A6MkHe5CY72q3EWMa849RgH8FdcJbD6sHjWT4HZnlBhh8ddbOj VxpwTnpAwEAnyaBCO/fi7pBMwX8h0LHQDDSMrIR0SGGQK3xWLIV++lS/x7vTaLlot1sc HVaLNn0I+dzgdFttqdK5fcEcgjq/dtplSUXzkIOBjc+7bSFjuBLvIDy5EuHUh5/uLC2k kBJw== X-Gm-Message-State: APjAAAUdHDaUIHAU1YKAto1HX9pYQzFMY4ZI1xNPrfBmpUwGIOMc35ZS 1Cf4GW9FLcD3cDsjeoVaTCyDRYGKLm8= X-Google-Smtp-Source: APXvYqxdkClxNLarQWFijuLo4qhLHoZHiD7+VdxIGqLyrTk7wSUrXORlSOxjUXNgeNiK/WbdnyA1Yg== X-Received: by 2002:a5d:640d:: with SMTP id z13mr15554175wru.181.1580057044369; Sun, 26 Jan 2020 08:44:04 -0800 (PST) Received: from nipah.in1.bytenix.com (host248-61-dynamic.26-79-r.retail.telecomitalia.it. [79.26.61.248]) by smtp.gmail.com with ESMTPSA id d12sm16686301wrp.62.2020.01.26.08.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 08:44:03 -0800 (PST) From: Federico Simoncelli To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Jan 2020 17:42:20 +0100 Message-Id: <20200126164220.78268-2-federico.simoncelli@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200126164220.78268-1-federico.simoncelli@gmail.com> References: <20200126164220.78268-1-federico.simoncelli@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avdevice/pulse_audio_dec: identify channel layout 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: Federico Simoncelli Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This patch adds the attempt to identify the pulseaudio channel map and when possible set the relevant channel_layout parameter of the codec. The result is an improvement over the current behavior of guessing the layout based on the number of channels (for more information see guess_layout_max). --- libavdevice/pulse_audio_dec.c | 40 +++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c index 50a3c971ae..12f2d15680 100644 --- a/libavdevice/pulse_audio_dec.c +++ b/libavdevice/pulse_audio_dec.c @@ -135,6 +135,37 @@ static av_cold int pulse_close(AVFormatContext *s) return 0; } +static int pulse_map_to_layout(pa_channel_map *cmap) +{ + const char *map_name = pa_channel_map_to_name(cmap); + + if (map_name == NULL) + return 0; + + if (strcmp(map_name, "mono") == 0) + return AV_CH_LAYOUT_MONO; + + if (strcmp(map_name, "stereo") == 0) + return AV_CH_LAYOUT_STEREO; + + if (strcmp(map_name, "surround-40") == 0) + return AV_CH_LAYOUT_4POINT0; + + if (strcmp(map_name, "surround-41") == 0) + return AV_CH_LAYOUT_4POINT1; + + if (strcmp(map_name, "surround-50") == 0) + return AV_CH_LAYOUT_5POINT0; + + if (strcmp(map_name, "surround-51") == 0) + return AV_CH_LAYOUT_5POINT1; + + if (strcmp(map_name, "surround-71") == 0) + return AV_CH_LAYOUT_7POINT1; + + return 0; +} + static av_cold int pulse_read_header(AVFormatContext *s) { PulseData *pd = s->priv_data; @@ -245,10 +276,11 @@ static av_cold int pulse_read_header(AVFormatContext *s) pa_threaded_mainloop_unlock(pd->mainloop); /* take real parameters */ - st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - st->codecpar->codec_id = codec_id; - st->codecpar->sample_rate = pd->sample_rate; - st->codecpar->channels = pd->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = codec_id; + st->codecpar->sample_rate = pd->sample_rate; + st->codecpar->channels = pd->channels; + st->codecpar->channel_layout = pulse_map_to_layout(&cmap); avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ pd->timefilter = ff_timefilter_new(1000000.0 / pd->sample_rate,