pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/multimedia/mpv mpv: Add NetBSD audio support



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3698b9c31df3
branches:  trunk
changeset: 424955:3698b9c31df3
user:      nia <nia%pkgsrc.org@localhost>
date:      Mon Mar 16 20:31:44 2020 +0000

description:
mpv: Add NetBSD audio support

We had some problems with the OSS audio output, this should avoid those.

This maintains pretty perfect audio-video sync and framerates with
autosync=0 and blk_ms=4.

Bump PKGREVISION

diffstat:

 multimedia/mpv/Makefile                             |    9 +-
 multimedia/mpv/distinfo                             |   10 +-
 multimedia/mpv/patches/patch-DOCS_man_ao.rst        |   16 +
 multimedia/mpv/patches/patch-audio_out_ao.c         |   24 +
 multimedia/mpv/patches/patch-audio_out_ao__netbsd.c |  283 ++++++++++++++++++++
 multimedia/mpv/patches/patch-options_options.c      |    8 +-
 multimedia/mpv/patches/patch-wscript                |   28 +-
 multimedia/mpv/patches/patch-wscript__build.py      |   14 +
 8 files changed, 378 insertions(+), 14 deletions(-)

diffs (truncated from 463 to 300 lines):

diff -r da0c1d6d4a66 -r 3698b9c31df3 multimedia/mpv/Makefile
--- a/multimedia/mpv/Makefile   Mon Mar 16 16:55:41 2020 +0000
+++ b/multimedia/mpv/Makefile   Mon Mar 16 20:31:44 2020 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.98 2020/03/10 22:10:41 wiz Exp $
+# $NetBSD: Makefile,v 1.99 2020/03/16 20:31:44 nia Exp $
 
 DISTNAME=      mpv-0.32.0
-PKGREVISION=   3
+PKGREVISION=   4
 CATEGORIES=    multimedia
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=mpv-player/}
 GITHUB_TAG=    v${PKGVERSION_NOREV}
@@ -65,6 +65,11 @@
 .  endif
 .endif
 
+.if ${OPSYS} == "NetBSD"
+# Use audio(4) over ossaudio(4) on NetBSD.
+WAF_CONFIGURE_ARGS+=   --disable-oss-audio
+.endif
+
 post-install:
        cd ${DESTDIR}${PREFIX} && ${MV} etc/mpv/encoding-profiles.conf share/examples/mpv
 
diff -r da0c1d6d4a66 -r 3698b9c31df3 multimedia/mpv/distinfo
--- a/multimedia/mpv/distinfo   Mon Mar 16 16:55:41 2020 +0000
+++ b/multimedia/mpv/distinfo   Mon Mar 16 20:31:44 2020 +0000
@@ -1,12 +1,16 @@
-$NetBSD: distinfo,v 1.59 2020/01/26 21:28:11 leot Exp $
+$NetBSD: distinfo,v 1.60 2020/03/16 20:31:44 nia Exp $
 
 SHA1 (mpv-0.32.0.tar.gz) = 5b69ea34dd5f8d209acd5266415c7bc00ab83341
 RMD160 (mpv-0.32.0.tar.gz) = d1e399fce8985a0399fe627248b87d8537cfefd7
 SHA512 (mpv-0.32.0.tar.gz) = f6426c0254ec0bf2f120e2196904f1e15fe17032b06764abca1d5e074f0cabb452eaf1cd09f8fd9b25b591accee7b881bfc3b06c19d5c98980305c4712486bd6
 Size (mpv-0.32.0.tar.gz) = 3148730 bytes
+SHA1 (patch-DOCS_man_ao.rst) = 5940fe1ad4d4328c03b9e6e5265c517762cfe2d0
+SHA1 (patch-audio_out_ao.c) = 1527c818d0f50801485ad3b90c5d86b30b2ca6f1
 SHA1 (patch-audio_out_ao__alsa.c) = c4661d0d22550d6e4eb2b7a42dd04dbcc58123b0
-SHA1 (patch-options_options.c) = 0c711323e2cd46948852476144ed0e07418394b4
+SHA1 (patch-audio_out_ao__netbsd.c) = 137cd9da82108adc02848954fa72c057a9de7a1e
+SHA1 (patch-options_options.c) = c75fb27140ad21e0a11c6ded976116c544661f56
 SHA1 (patch-player_main.c) = 7d1d62091c327fca698844004ddb9a7871e15fce
 SHA1 (patch-video_out_drm__common.c) = a545a8aec29f1b3c44d26aacbc59b86d3333a0b9
 SHA1 (patch-video_out_wayland__common.c) = d3e72c4ff5426bd8349c15679a47d446c35666b1
-SHA1 (patch-wscript) = 2f082a2d3797234bf56859d95c219f5355382224
+SHA1 (patch-wscript) = 33c81597c1eb25911b13c64a1ba8e47d268bd517
+SHA1 (patch-wscript__build.py) = bbb391be46f6e5c02d1946a07bb5d8bbb442fd5a
diff -r da0c1d6d4a66 -r 3698b9c31df3 multimedia/mpv/patches/patch-DOCS_man_ao.rst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/multimedia/mpv/patches/patch-DOCS_man_ao.rst      Mon Mar 16 20:31:44 2020 +0000
@@ -0,0 +1,16 @@
+$NetBSD: patch-DOCS_man_ao.rst,v 1.1 2020/03/16 20:31:44 nia Exp $
+
+NetBSD audio support.
+
+--- DOCS/man/ao.rst.orig       2020-01-26 20:31:54.000000000 +0000
++++ DOCS/man/ao.rst
+@@ -177,6 +177,9 @@ Available audio output drivers are:
+         Sets the number of extra audio buffers in mpv. Usually needs not be
+         changed.
+ 
++``netbsd``
++    Audio output to the NetBSD sound system
++
+ ``null``
+     Produces no audio output but maintains video playback speed. You can use
+     ``--ao=null --ao-null-untimed`` for benchmarking.
diff -r da0c1d6d4a66 -r 3698b9c31df3 multimedia/mpv/patches/patch-audio_out_ao.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/multimedia/mpv/patches/patch-audio_out_ao.c       Mon Mar 16 20:31:44 2020 +0000
@@ -0,0 +1,24 @@
+$NetBSD: patch-audio_out_ao.c,v 1.1 2020/03/16 20:31:44 nia Exp $
+
+NetBSD audio support.
+
+--- audio/out/ao.c.orig        2020-01-26 20:31:54.000000000 +0000
++++ audio/out/ao.c
+@@ -40,6 +40,7 @@ extern const struct ao_driver audio_out_
+ extern const struct ao_driver audio_out_audiounit;
+ extern const struct ao_driver audio_out_coreaudio;
+ extern const struct ao_driver audio_out_coreaudio_exclusive;
++extern const struct ao_driver audio_out_netbsd;
+ extern const struct ao_driver audio_out_rsound;
+ extern const struct ao_driver audio_out_sndio;
+ extern const struct ao_driver audio_out_pulse;
+@@ -64,6 +65,9 @@ static const struct ao_driver * const au
+ #if HAVE_COREAUDIO
+     &audio_out_coreaudio,
+ #endif
++#if HAVE_NETBSD_AUDIO
++    &audio_out_netbsd,
++#endif
+ #if HAVE_PULSE
+     &audio_out_pulse,
+ #endif
diff -r da0c1d6d4a66 -r 3698b9c31df3 multimedia/mpv/patches/patch-audio_out_ao__netbsd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/multimedia/mpv/patches/patch-audio_out_ao__netbsd.c       Mon Mar 16 20:31:44 2020 +0000
@@ -0,0 +1,283 @@
+$NetBSD: patch-audio_out_ao__netbsd.c,v 1.1 2020/03/16 20:31:44 nia Exp $
+
+NetBSD audio support.
+
+--- audio/out/ao_netbsd.c.orig 2020-03-16 20:20:16.030655720 +0000
++++ audio/out/ao_netbsd.c
+@@ -0,0 +1,276 @@
++/*
++ * Copyright (c) 2020 Nia Alarie <nia%NetBSD.org@localhost>
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted provided that the following conditions
++ * are met:
++ *
++ * 1. Redistributions of source code must retain the above copyright
++ *    notice, this list of conditions and the following disclaimer.
++ * 2. Redistributions in binary form must reproduce the above copyright
++ *    notice, this list of conditions and the following disclaimer in the
++ *    documentation and/or other materials provided with the distribution.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
++ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
++ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
++ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
++ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
++ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
++ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
++ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
++ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGE.
++ */
++#include <sys/audioio.h>
++#include <sys/ioctl.h>
++#include <unistd.h>
++#include <fcntl.h>
++#include <errno.h>
++#include <stdint.h>
++#include <string.h>
++
++#include "options/m_option.h"
++#include "common/msg.h"
++
++#include "audio/format.h"
++#include "ao.h"
++#include "internal.h"
++
++#ifndef NETBSD_MAXDEVS
++#define NETBSD_MAXDEVS (8)
++#endif
++
++struct priv {
++    int fd;
++    uint64_t total_blocks; /* audio blocks output */
++    uint64_t total_bytes; /* bytes sent to the queue */
++};
++
++static int init(struct ao *ao)
++{
++    char device[16] = "/dev/audio";
++    struct priv *p = ao->priv;
++    struct audio_info info;
++    struct audio_prinfo *pinfo;
++    struct mp_chmap_sel sel = {0};
++
++    AUDIO_INITINFO(&info);
++    pinfo = &info.play;
++
++    if (ao->device != NULL) {
++         (void)snprintf(device, sizeof(device), "/dev/audio%s",
++                        ao->device + sizeof("netbsd/") - 1);
++    }
++
++    MP_ERR(ao, "Opening device %s", ao->device);
++    if ((p->fd = open(device, O_WRONLY)) == -1) {
++        MP_ERR(ao, "Can't open audio device %s: %s\n",
++               ao->device, mp_strerror(errno));
++        goto fail;
++    }
++
++    info.mode = AUMODE_PLAY;
++
++    for (int n = 1; n <= 12; n++) {
++        struct mp_chmap map;
++
++        mp_chmap_from_channels(&map, n);
++        mp_chmap_sel_add_map(&sel, &map);
++    }
++
++    if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels)) {
++        MP_ERR(ao, "Failed to select a valid channel map\n");
++        goto fail;
++    }
++
++    pinfo->channels = ao->channels.num;
++    pinfo->sample_rate = ao->samplerate;
++
++    switch (ao->format) {
++    case AF_FORMAT_U8:
++        pinfo->precision = 8;
++        pinfo->encoding = AUDIO_ENCODING_ULINEAR;
++        break;
++    case AF_FORMAT_S16:
++        pinfo->precision = 16;
++        pinfo->encoding = AUDIO_ENCODING_SLINEAR;
++        break;
++    default:
++        pinfo->precision = 32;
++        pinfo->encoding = AUDIO_ENCODING_SLINEAR;
++        break;
++    }
++
++    if (ioctl(p->fd, AUDIO_SETINFO, &info) == -1) {
++        MP_ERR(ao, "AUDIO_SETINFO failed: %s\n", mp_strerror(errno));
++        goto fail;
++    }
++
++    if (ioctl(p->fd, AUDIO_GETINFO, &info) == -1) {
++        MP_ERR(ao, "AUDIO_GETINFO failed: %s\n", mp_strerror(errno));
++        goto fail;
++    }
++
++    ao->samplerate = pinfo->sample_rate;
++
++    switch (pinfo->precision) {
++    case 8:
++        ao->format = AF_FORMAT_U8;
++        break;
++    case 16:
++        ao->format = AF_FORMAT_S16;
++        break;
++    case 32:
++        ao->format = AF_FORMAT_S32;
++        break;
++    default:
++        MP_ERR(ao, "Unsupported precision %d\n", pinfo->precision);
++        goto fail;
++    }
++
++    return 0;
++
++fail:
++    if (p->fd != -1) {
++        close(p->fd);
++    }
++    return -1;
++}
++
++static void uninit(struct ao *ao)
++{
++    struct priv *p = ao->priv;
++
++    (void)ioctl(p->fd, AUDIO_FLUSH, NULL);
++    (void)close(p->fd);
++    p->fd = -1;
++}
++
++static void reset(struct ao *ao)
++{
++    struct priv *p = ao->priv;
++    struct audio_info info;
++    struct audio_offset offset;
++
++    if (ioctl(p->fd, AUDIO_GETINFO, &info) == -1) {
++        MP_ERR(ao, "AUDIO_GETINFO failed: %s\n", mp_strerror(errno));
++        return;
++    }
++
++    (void)ioctl(p->fd, AUDIO_DRAIN, NULL);
++    (void)ioctl(p->fd, AUDIO_GETOOFFS, &offset); /* reset deltablks */
++    p->total_blocks = p->total_bytes / info.blocksize;
++}
++
++static int get_space(struct ao *ao)
++{
++    struct priv *p = ao->priv;
++    struct audio_info info;
++
++    if (ioctl(p->fd, AUDIO_GETINFO, &info) == -1) {
++        MP_ERR(ao, "AUDIO_GETINFO failed: %s\n", mp_strerror(errno));
++        return 0;
++    }
++    return (info.blocksize - info.play.seek) / ao->sstride;
++}
++
++static void audio_pause(struct ao *ao)
++{
++    struct priv *p = ao->priv;
++    struct audio_info info;
++
++    if (ioctl(p->fd, AUDIO_GETINFO, &info) == -1) {
++        MP_ERR(ao, "AUDIO_GETINFO failed: %s\n", mp_strerror(errno));
++        return;
++    }
++    info.play.pause = 1;
++    (void)ioctl(p->fd, AUDIO_SETINFO, &info);
++}
++
++static void audio_resume(struct ao *ao)



Home | Main Index | Thread Index | Old Index