snapcast icon indicating copy to clipboard operation
snapcast copied to clipboard

Snapcast emits stream notifications for streams with `codec=null`

Open mill1000 opened this issue 4 months ago • 1 comments

Describe the bug Snapcast is emitting Stream.OnUpdate notifications for streams that are set as codec=null. These streams are not part of the Server.GetStatus response, and not visible in the web interface.

This causes a problem in python-snapcast because it attempts to lookup the codec=null stream via it's name, throwing a KeyError.

Steps to Reproduce

  1. Define a input-only stream with codec=null, define a meta stream with the input-only stream as a source.
  2. Listen for notifications from the server. e.g. telnet localhost 1705
  3. Start playback on the input-only stream
  4. Observe 2 Stream.OnUpdate notifications. 1 from the meta stream, 1 from the input-only stream.

Environment details

  • OS: Docker w/ Alpine
  • Snapserver 0.27.0
  • Built via Dockerfile

Server.GetStatus response trimmed for brevity

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "server": {
      "streams": [
        {
          "id": "Bedroom",
          "status": "playing",
          "uri": {
            "fragment": "",
            "host": "",
            "path": "/upnp-bedroom/airplay-bedroom/spotify-bedroom/upnp-all-rooms/airplay-all-rooms/spotify-all-rooms",
            "query": {
              "chunk_ms": "40",
              "codec": "flac",
              "name": "Bedroom",
              "sampleformat": "44100:16:2"
            },
            "raw": "meta:////upnp-bedroom/airplay-bedroom/spotify-bedroom/upnp-all-rooms/airplay-all-rooms/spotify-all-rooms?chunk_ms=40&codec=flac&name=Bedroom&sampleformat=44100:16:2",
            "scheme": "meta"
          }
        },
        {
          "id": "Living Room",
          "status": "idle",
          "uri": {
            "fragment": "",
            "host": "",
            "path": "/upnp-living-room/airplay-living-room/spotify-living-room/upnp-all-rooms/airplay-all-rooms/spotify-all-rooms",
            "query": {
              "chunk_ms": "40",
              "codec": "flac",
              "name": "Living Room",
              "sampleformat": "44100:16:2"
            },
            "raw": "meta:////upnp-living-room/airplay-living-room/spotify-living-room/upnp-all-rooms/airplay-all-rooms/spotify-all-rooms?chunk_ms=40&codec=flac&name=Living Room&sampleformat=44100:16:2",
            "scheme": "meta"
          }
        }
      ]
    }
  }
}

Stream.OnUpdate notification trimmed for brevity

{
  "jsonrpc": "2.0",
  "method": "Stream.OnUpdate",
  "params": {
    "id": "upnp-bedroom",
    "stream": {
      "id": "upnp-bedroom",
      "status": "playing",
      "uri": {
        "fragment": "",
        "host": "",
        "path": "/streams/gmrender-resurrect-bedroom",
        "query": {
          "chunk_ms": "40",
          "codec": "null",
          "name": "upnp-bedroom",
          "sampleformat": "44100:16:2"
        },
        "raw": "pipe:////streams/gmrender-resurrect-bedroom?chunk_ms=40&codec=null&name=upnp-bedroom&sampleformat=44100:16:2",
        "scheme": "pipe"
      }
    }
  }
}
{
  "jsonrpc": "2.0",
  "method": "Stream.OnUpdate",
  "params": {
    "id": "Bedroom",
    "stream": {
      "id": "Bedroom",
      "status": "playing",
      "uri": {
        "fragment": "",
        "host": "",
        "path": "/upnp-bedroom/airplay-bedroom/spotify-bedroom/upnp-all-rooms/airplay-all-rooms/spotify-all-rooms",
        "query": {
          "chunk_ms": "40",
          "codec": "flac",
          "name": "Bedroom",
          "sampleformat": "44100:16:2"
        },
        "raw": "meta:////upnp-bedroom/airplay-bedroom/spotify-bedroom/upnp-all-rooms/airplay-all-rooms/spotify-all-rooms?chunk_ms=40&codec=flac&name=Bedroom&sampleformat=44100:16:2",
        "scheme": "meta"
      }
    }
  }
}

mill1000 avatar Feb 16 '24 20:02 mill1000

Feels a little hacky but we could add a check for the codec here:

https://github.com/badaix/snapcast/blob/6a428328aa3a7f2ece91895466b2690a5e454b17/server/server.cpp#L69-L79

e.g.

if (pcmStream->getCodec() == "null")
        return;

mill1000 avatar Feb 16 '24 21:02 mill1000

Should be fixed with 6451ab5b8d74b33fb5c09a2840ab00151b7ecf46 You can find packages here: https://github.com/badaix/snapcast/actions/runs/8436966658

badaix avatar Mar 26 '24 14:03 badaix

Ran some quick tests and it looked good

mill1000 avatar Mar 27 '24 01:03 mill1000

Fixed in version 0.28.0

badaix avatar Apr 19 '24 16:04 badaix