LoginSignup
2
6

More than 5 years have passed since last update.

NanoPiで、shairport-sync

Last updated at Posted at 2018-02-18

同期機能付きAirplayクライアントを、nanoPiに入れたお話

以下の投稿の、続き?です。

さて、まあ。
shairportは、だいぶ古いらしいし、同期も無いので、サクッとshairport-syncに載せかえてみました。
ポイントは、以下な感じ。

  • SPDIF対応ののため、サウンドデバイスの変更
  • 自動制御のため、再生/停止時にファイル操作埋め込み
  • リモコン操作のため、active-remoteの取り出し

サクっとコンパイル

以下なページを参考に。
config設定までは、NanoPiでも、このままな感じでした。
https://qiita.com/yuyakato/items/600f499cf0610bfc1a16

オーディオデバイス設定

まず、オーディオデバイス一覧を取得。
ALSA入っているので、まあaplayで。

root@nanopineo:/# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: audiocodec [audiocodec], device 0: SUNXI-CODEC sndcodec-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sndhdmi [sndhdmi], device 0: SUNXI-HDMIAUDIO sndhdmi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: sndspdif [sndspdif], device 0: SUNXI-SPDIF sndspdif-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0

ALSAデバイス的には、hw:0,0 とか指定するのですが。
前の数字がカード番号、後ろの数字がサブデバイス番号ぽいです。
今回は、カード2なspdifを使いたいので、カードが2で、サブデバイスが0、つまりhw:2,0を指定すればOKな感じ。

shairport-sync config周り

confは、上記なURLの手順で入れると、/usr/local/etc/shairport-sync.confに入るみたいです。
弄りポイントは、nameoutput_devicerun_this_before_play_beginsrun_this_after_play_ends、あとmetadata周りのenabledpipe_name
それぞれ、内容は以下の感じ。

名称 役割
name iTunesなどに表示されるお名前
output_device 出力、上記hw:2,0を設定
run_this_before_play_begins 実行時スクリプトキック
run_this_after_play_ends 停止時スクリプトキック
metadata:enabled メタデータ出力
metadata:pipe_name メタデータパイプ設定

ま、ウチの設定は、以下な感じに。

root@nanopineo:/usr/local/etc# diff shairport-sync.conf.sample shairport-sync.conf
7c7
< //    name = "%H"; // This means "Hostname" -- see below. This is the name the service will advertise to iTunes.
---
>       name = "AirSelect"; // This means "Hostname" -- see below. This is the name the service will advertise to iTunes.
54,55c54,55
< //    run_this_before_play_begins = "/full/path/to/application and args"; // make sure the application has executable permission. It it's a script, include the #!... stuff on the first line
< //    run_this_after_play_ends = "/full/path/to/application and args"; // make sure the application has executable permission. It it's a script, include the #!... stuff on the first line
---
>       run_this_before_play_begins = "/bin/touch /ramdisk/airplay_enable"; // make sure the application has executable permission. It it's a script, include the #!... stuff on the first line
>       run_this_after_play_ends = "/bin/rm /ramdisk/airplay_enable"; // make sure the application has executable permission. It it's a script, include the #!... stuff on the first line
66c66
< //  output_device = "default"; // the name of the alsa output device. Use "alsamixer" or "aplay" to find out the names of devices, mixers, etc.
---
>   output_device = "hw:2,0"; // the name of the alsa output device. Use "alsamixer" or "aplay" to find out the names of devices, mixers, etc.
69c69
< //  output_rate = 44100; // can be 44100, 88200, 176400 or 352800, but the device must have the capability.
---
>   output_rate = 88200; // can be 44100, 88200, 176400 or 352800, but the device must have the capability.
138c138
< //    enabled = "no"; // set this to yes to get Shairport Sync to solicit metadata from the source and to pass it on via a pipe
---
>       enabled = "yes"; // set this to yes to get Shairport Sync to solicit metadata from the source and to pass it on via a pipe
140c140
< //    pipe_name = "/tmp/shairport-sync-metadata";
---
>       pipe_name = "/ramdisk/shairport-sync-metadata";

あとはsystemctlでshairport-syncをstartなりenableなりすれば、shairport-sync側はOK!。

メタデータの取り出し

shairpot-syncのメタデータは、shairport-sync-metadata-readerという、同じ作者さんのツールを使えば、テキスト変換してくれます。
URLは以下。
https://github.com/mikebrady/shairport-sync-metadata-reader

ま、導入手順は、以下な感じ。

git clone https://github.com/mikebrady/shairport-sync-metadata-reader.git
cd shairport-sync-metadata-reader
autoreconf -i -f
./configure
make
sudo make install

shairport-sync側の設定で、メタデータをアレしていれば、パイプ繋げてあげれば、情報が出てきます。

root@nanopineo:/usr/local/etc# /usr/local/bin/shairport-sync-metadata-reader < /ramdisk/shairport-sync-metadata
Client's IP: "192.168.24.221".
"ssnc" "svip": "192.168.24.102".
"ssnc" "snua": "iTunes/12.7.1 (Windows; Microsoft Windows 10 x64 Professional Edition (Build 16299); x64)".
"ssnc" "acre": "3500144013".
"ssnc" "daid": "DAABDA49CA0EFA86".
"ssnc" "pbeg": "".
"ssnc" "pfls": "".
"ssnc" "pvol": "0.00,0.00,-96.30,0.00".
"ssnc" "pvol": "0.00,0.00,-96.30,0.00".
"ssnc" "pvol": "0.00,0.00,-96.30,0.00".
"ssnc" "mdst": "1517826157".
Album Name: "交響組曲「ドラゴンクエストX」目覚めし五つの種族".
Artist: "すぎやまこういち; 東京都交響楽団".
Comment: "".
Composer: "すぎやまこういち".
Genre: "Soundtrack".
File kind: "Apple Losslessオーディオファイル".
Title: "花の民プクリポ ~ 地の民ドワーフ ~ トンテンカン ~ あの丘を越えたら".
Sort as: "".
"ssnc" "mden": "1517826157".
"ssnc" "prgr": "1517810797/1517826157/1530326377".
"ssnc" "dapo": "3689".
"ssnc" "mdst": "1517866285".
Album Name: "交響組曲「ドラゴンクエストX」目覚めし五つの種族".
Artist: "すぎやまこういち; 東京都交響楽団".
Comment: "".
Composer: "すぎやまこういち".
Genre: "Soundtrack".
File kind: "Apple Losslessオーディオファイル".
Title: "花の民プクリポ ~ 地の民ドワーフ ~ トンテンカン ~ あの丘を越えたら".
Sort as: "".
"ssnc" "mden": "1517866285".
"ssnc" "prgr": "1517795629/1517866285/1530311209".
"ssnc" "prsm": "".

この中の、"ssnc" "acre": "3500144013".が、ActiveremoteなIDです。
パイプで繋げて、ファイルに保存な感じで。

getactiveremote.pl
#!/usr/bin/perl

$activeremotefile = "/ramdisk/airplay_activeremote";
$| = 1;

while (<STDIN>){
 if ($_ =~ /\"acre\": \"(.+)\"/){
  $adata = $1;
  open (OUTPUTFILE,">$activeremotefile");
  print OUTPUTFILE $adata;
  close (OUTPUTFILE);
 }
}

systemdなファイル作って・・・

/etc/systemd/system/getactiveremote.service
[Unit]
Description = getactiveremote

[Service]
ExecStart=/usr/local/bin/shairport-sync-metadata-reader < /ramdisk/shairport-sync-metadata |/usr/bin/perl /data/airplay_control/getactiveremote.pl
Restart=always
Type=simple

[Install]
WantedBy=multi-user.target

systemctlで登録すればOK!。

ま、見ての通り。
様々な情報が流れてくるので、いろいろヤレる余地ありまくりな感じで。
すが、ウチのNanoPiには、表示系デバイス無いのでまあ、放置!。

以上、作業場の環境プチ入れ替えな、お話でした。

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6