librecast 2.71 KB
Newer Older
Carlos Remuzzi's avatar
Carlos Remuzzi committed
1
2
#!/usr/bin/env bash

3
4
AP_ADDRESS=192.168.12.1
# legacy, porque hemos empezado con la sala llamada libreCast-s1
5
if [ $# -eq 1 ];then
6
7
8
9
10
  AP_ADDRESS=$1
fi

if [ $# -eq 2 ];then
  AP_NAME=$2
11
12
fi

13
14
15
16
17
18
19
invocar_nmcli() {
  echo "conectando a $AP_NAME"
  nmcli con up $AP_NAME
  if [ $? -eq 1 ];then
    exit 1
  fi
}
20

21
22
main() {
  if [ -z "$(pidof gst-launch-1.0)" ] ;then
Carlos Remuzzi's avatar
Carlos Remuzzi committed
23

24
    pkill -15 gst-launch-1.0
Carlos Remuzzi's avatar
Carlos Remuzzi committed
25

26
27
28
    # AP_NAME es necesario solo si se quiere usar Network Manager
    # para la conexion automatica al AP wifi  
    if [ -n "$AP_NAME" ] ;then
Carlos Remuzzi's avatar
Carlos Remuzzi committed
29
      if which nmcli >/dev/null 2>&1 ; then
30
31
32
33
        invocar_nmcli
       else
        echo "utilizando conexion manual"
      fi
34
    fi
Carlos Remuzzi's avatar
Carlos Remuzzi committed
35

36
37
38
39
40
41
    SIZE_STRING=$(xdpyinfo | awk '/dimensions/{print $2}')
    SCREEN_WIDTH="$(cut -d'x' -f1 <<<"$SIZE_STRING")"
    SCREEN_HEIGHT="$(cut -d'x' -f2 <<<"$SIZE_STRING")"
    # por defecto no realizamos ningun recorte
    CROP_STRING_X=""
    CROP_STRING_Y=""
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    # en caso el ancho supere lo maximo consentido de 1920
    if [ "$SCREEN_WIDTH" -gt 1920 ];then
      echo "recortando el ancho de la pantalla ..."
      SCREEN_WIDTH=1920
      CROP_STRING_X="startx=0 endx=1919"
      CROP_STRING_Y="starty=0 endy=$(( $SCREEN_HEIGHT-1 ))"
    fi

    # en caso el alto supere lo maximo consentido de 1080
    if [ "$SCREEN_HEIGHT" -gt 1080 ];then
      echo "recortando el alto de la pantalla..."
      SCREEN_HEIGHT=1080
      CROP_STRING_X="startx=0 endx=$(( $SCREEN_WIDTH-1 ))"
      CROP_STRING_Y="starty=0 endy=1079"
    fi

    curl --connect-timeout 3 -s -k -X GET https://$AP_ADDRESS:5443/player/start | grep 'Player iniciado'
    if [ $? -eq 0 ];then

      pacmd unload-module module-null-sink
      pacmd load-module module-null-sink sink_name=libreCast
      pacmd update-sink-proplist libreCast device.description=libreCast
      pacmd set-default-sink libreCast

      gst-launch-1.0 ximagesrc use-damage=false $CROP_STRING_X $CROP_STRING_Y ! videoconvert ! videoscale ! video/x-raw,format=I420,width=$SCREEN_WIDTH,height=$SCREEN_HEIGHT,framerate=24/1,bitrate=6000 ! jpegenc quality=80 ! rtpjpegpay ! udpsink host=$AP_ADDRESS port=1234 sync=false &
      gst-launch-1.0 -v pulsesrc device="libreCast.monitor" ! "audio/x-raw,rate=11500,channels=2,depth=16" ! udpsink host=$AP_ADDRESS port=5678 sync=false &
      exit 0
    else
      # the player is already running or the player is not reachable
      exit 1
    fi
74

Carlos Remuzzi's avatar
Carlos Remuzzi committed
75
76
  else

77
78
79
80
    echo "stopping ..."
    curl --connect-timeout 3 -s -k -X GET https://$AP_ADDRESS:5443/player/stop
    pkill -15 gst-launch-1.0
    pacmd unload-module module-null-sink
Carlos Remuzzi's avatar
Carlos Remuzzi committed
81

82
    if [ -n "$AP_NAME" ] ;then
Carlos Remuzzi's avatar
Carlos Remuzzi committed
83
      if which nmcli >/dev/null 2>&1 ; then
84
85
86
87
88
         nmcli con down $AP_NAME
       else
         echo "Por favor desconectarse de $AP_NAME"
      fi
    fi
89
  fi
90
}
91

92
main