jetbrains: 2024.1 -> 2024.2.7 (#351041)
[NixPkgs.git] / nixos / tests / mediamtx.nix
blobf40c4a8cb5832cc19099492bf02b649036ed931e
1 import ./make-test-python.nix (
2   { pkgs, lib, ... }:
4   {
5     name = "mediamtx";
6     meta.maintainers = with lib.maintainers; [ fpletz ];
8     nodes = {
9       machine = {
10         services.mediamtx = {
11           enable = true;
12           settings = {
13             metrics = true;
14             paths.all.source = "publisher";
15           };
16         };
18         systemd.services.rtmp-publish = {
19           description = "Publish an RTMP stream to mediamtx";
20           after = [ "mediamtx.service" ];
21           bindsTo = [ "mediamtx.service" ];
22           wantedBy = [ "multi-user.target" ];
23           serviceConfig = {
24             DynamicUser = true;
25             Restart = "on-failure";
26             RestartSec = "1s";
27             TimeoutStartSec = "10s";
28             ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -re -f lavfi -i smptebars=size=800x600:rate=10 -c libx264 -f flv rtmp://localhost:1935/test";
29           };
30         };
32         systemd.services.rtmp-receive = {
33           description = "Receive an RTMP stream from mediamtx";
34           after = [ "rtmp-publish.service" ];
35           bindsTo = [ "rtmp-publish.service" ];
36           wantedBy = [ "multi-user.target" ];
37           serviceConfig = {
38             DynamicUser = true;
39             Restart = "on-failure";
40             RestartSec = "1s";
41             TimeoutStartSec = "10s";
42             ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -y -re -i rtmp://localhost:1935/test -f flv /dev/null";
43           };
44         };
45       };
46     };
48     testScript = ''
49       start_all()
51       machine.wait_for_unit("mediamtx.service")
52       machine.wait_for_unit("rtmp-publish.service")
53       machine.sleep(10)
54       machine.wait_for_unit("rtmp-receive.service")
55       machine.wait_for_open_port(9998)
56       machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"publish\".*1$'")
57       machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"read\".*1$'")
58     '';
59   }