Commit 44688419cd4ae29c38488553465f1c35fd2fd784
1 parent
94f5fffe
--no commit message
Showing
2 changed files
with
209 additions
and
45 deletions
hls_script.sh
0 → 100755
1 | +#!/bin/bash | ||
2 | + | ||
3 | +# WIFLY VARIABLES | ||
4 | + | ||
5 | +SSID=PBE | ||
6 | +#SSID=SERVER_WLAN | ||
7 | +ROUTE=$1 | ||
8 | +DEST_IP=10.0.2.100 | ||
9 | +#DEST_IP=192.168.1.1 | ||
10 | +PORT=80 | ||
11 | +WIFLY=/dev/ttyUSB0 | ||
12 | +SERIAL_OPTS="ispeed $SPEED ospeed $SPEED" | ||
13 | +SPEED=9600 | ||
14 | +STARTWORD="Content-Type: application/vnd.apple.mpegurl" | ||
15 | +ENDWORD="*CLOS*" | ||
16 | +WRITE=0 | ||
17 | + | ||
18 | +# PARSING VARIABLES | ||
19 | + | ||
20 | +M3U8_VALIDATED=0 | ||
21 | +SEQUENCE_FIRST=0 | ||
22 | +MAX_DURATION=-1 | ||
23 | +CURRENT_SEGMENT=0 | ||
24 | +CURRENT_LINE=1 | ||
25 | +EXTINF=0 | ||
26 | +CODECS="" | ||
27 | +RESOLUTION="" | ||
28 | +BANDWIDTH="" | ||
29 | +PROGRAMID="" | ||
30 | +EXTXSTREAM=0 | ||
31 | + | ||
32 | +# FUNCTIONS | ||
33 | + | ||
34 | +parse() | ||
35 | +{ | ||
36 | + if [[ $line == "" ]];then | ||
37 | + ((CURRENT_LINE++)) | ||
38 | + return | ||
39 | + else | ||
40 | + if [[ $M3U8_VALIDATED -eq 0 ]]; then | ||
41 | + if [[ $line == "#EXTM3U" ]]; then | ||
42 | + M3U8_VALIDATED=1 | ||
43 | + else | ||
44 | + echo "ERROR: This is not an m3u8 file!!" | ||
45 | + exit 1 | ||
46 | + fi | ||
47 | + else | ||
48 | + if [[ `echo $line | head -c1` == "#" ]]; then | ||
49 | + if [[ `echo $line | head -c4` == "#EXT" ]]; then | ||
50 | + case `echo $line | cut -d':' -f 1` in | ||
51 | + "#EXT-X-MEDIA-SEQUENCE") | ||
52 | + SEQUENCE_FIRST=`echo $line | cut -d':' -f 2`; | ||
53 | + echo "INFO: First element to be played is: $SEQUENCE_FIRST";; | ||
54 | + "#EXT-X-TARGETDURATION") | ||
55 | + MAX_DURATION=`echo $line | cut -d':' -f 2`; | ||
56 | + echo "INFO: Maximum segment duration is: $MAX_DURATION";; | ||
57 | + "#EXTINF") | ||
58 | + DURATION=`echo $line | cut -d':' -f 2 | cut -d',' -f 1` | ||
59 | + if [[ $DURATION > $MAX_DURATION ]]; then | ||
60 | + echo "ERROR: Segment $CURRENT_SEGMENT on line $CURRENT_LINE is larger than EXT-X-TARGETDURATION" | ||
61 | + exit 1 | ||
62 | + else | ||
63 | + NAME=`echo $line | cut -d':' -f 2 | cut -d',' -f 2` | ||
64 | + EXTINF=1 | ||
65 | + fi;; | ||
66 | + "#EXT-X-STREAM-INF") | ||
67 | + EXTXSTREAM=1 | ||
68 | + PROGRAMID="" | ||
69 | + CODECS="" | ||
70 | + RESOLUTION="" | ||
71 | + ARGUMENTS=`echo $line | cut -d':' -f 2` | ||
72 | + i=1 | ||
73 | + while [[ `echo $ARGUMENTS | cut -d',' -f $i` != "" ]]; do | ||
74 | + PARAMETER=`echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 2` | ||
75 | + case `echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 1` in | ||
76 | + "PROGRAM-ID") | ||
77 | + PROGRAMID=$PARAMETER;; | ||
78 | + "BANDWIDTH") | ||
79 | + BANDWIDTH=$PARAMETER;; | ||
80 | + "RESOLUTION") | ||
81 | + RESOLUTION=$PARAMETER;; | ||
82 | + "CODECS") | ||
83 | + CODECS=$PARAMETER;; | ||
84 | + esac | ||
85 | + ((i++)) | ||
86 | + done;; | ||
87 | + "#EXT-X-ENDLIST") | ||
88 | + echo "INFO: Playlist end reached";; | ||
89 | + esac | ||
90 | + else | ||
91 | + echo "INFO: Comment found on line $CURRENT_LINE: \"`echo $line | cut -d'#' -f 2`\"" | ||
92 | + fi; | ||
93 | + else | ||
94 | + if [[ $EXTINF -eq 1 ]]; then | ||
95 | + echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" | ||
96 | + EXTINF=0 | ||
97 | + if [[ $CURRENT_SEGMENT -eq $SEQUENCE_FIRST ]]; then | ||
98 | + echo " (first element)" | ||
99 | + else | ||
100 | + echo "" | ||
101 | + fi; | ||
102 | + ((CURRENT_SEGMENT++)) | ||
103 | + elif [[ $EXTXSTREAM -eq 1 ]]; then | ||
104 | + echo "PLAYLIST: $line [PROGRAM-ID=$PROGRAMID,BANDWIDTH=$BANDWIDTH,RESOLUTION=$RESOLUTION,CODECS=$CODECS]" | ||
105 | + EXTXSTREAM=0 | ||
106 | + else | ||
107 | + echo "ERROR: Unexpected string \"$line\"" | ||
108 | + exit 1 | ||
109 | + fi | ||
110 | + fi | ||
111 | + fi | ||
112 | + fi | ||
113 | + ((CURRENT_LINE++)) | ||
114 | +} | ||
115 | + | ||
116 | +fetch() | ||
117 | +{ | ||
118 | + echo -ne "set com remote GET\$$1\r" >> $WIFLY | ||
119 | + echo -ne "open $DEST_IP $PORT\r" >> $WIFLY | ||
120 | + | ||
121 | + # PARSE | ||
122 | + | ||
123 | + cat $WIFLY | while read line; do | ||
124 | + line=`echo $line | tr -d '\r' | sed 's/\*CLOS\*CMD/\*CLOS\*/g'` # STRIP EXTRA CR AND DETECT EOF | ||
125 | + if [[ "$line" == "$STARTWORD" && $WRITE == 0 ]]; then | ||
126 | + echo "INFO: Playlist $1 START:" | ||
127 | + WRITE=1; | ||
128 | + continue; | ||
129 | + fi | ||
130 | + if [[ "$line" == "$ENDWORD" ]]; then | ||
131 | + echo "INFO: EOF" | ||
132 | + break; | ||
133 | + fi | ||
134 | + if [[ $WRITE -eq 0 ]]; then | ||
135 | + continue; | ||
136 | + else | ||
137 | + parse $line | ||
138 | + fi | ||
139 | + done | ||
140 | +} | ||
141 | + | ||
142 | +initialize() | ||
143 | +{ | ||
144 | + echo -n "\$\$\$" >> $WIFLY | ||
145 | + # IF ANY CHARACTER GETS INTO THE BUFFER 250 ms AFTER THE $$$ SEQUENCE IT WILL NOT ENTER COMMAND MODE | ||
146 | + sleep 0.300 # TO BE SAFE | ||
147 | +} | ||
148 | + | ||
149 | +if [[ -z $1 ]]; then | ||
150 | + echo "ERROR: Missing path" | ||
151 | + echo -e "\nUSAGE: $0 <RELATIVE_PATH> (i.e /playlist.m3u8)" | ||
152 | + exit 1 | ||
153 | +fi | ||
154 | + | ||
155 | +# SERIAL PORT CONFIGURATION | ||
156 | + | ||
157 | +stty -F $WIFLY $SERIAL_OPTS | ||
158 | + | ||
159 | +# INPUT COMMANDS | ||
160 | + | ||
161 | +initialize | ||
162 | +echo -ne "set wlan join 1\r" >> $WIFLY | ||
163 | +echo -ne "set wlan auth 0\r" >> $WIFLY | ||
164 | +echo -ne "set wlan ssid $SSID\r" >> $WIFLY | ||
165 | +echo -ne "join $SSID\r" >> $WIFLY | ||
166 | +sleep 5 # GIVE TIME TO THE DHCP CLIENT | ||
167 | +echo -ne "set ip proto 18\r" >> $WIFLY | ||
168 | +fetch $ROUTE | ||
169 | + | ||
170 | +#cat $1 | while read line; do | ||
171 | +# parse $line | ||
172 | +#done | ||
173 | + | ||
174 | +exit 0 |
src/com/upc/pbe/upcnews/Parser.java
@@ -86,7 +86,27 @@ public class Parser | @@ -86,7 +86,27 @@ public class Parser | ||
86 | 86 | ||
87 | else if(extTag[0].equals("#EXT-X-STREAM-INF")) | 87 | else if(extTag[0].equals("#EXT-X-STREAM-INF")) |
88 | { | 88 | { |
89 | - | 89 | + /*"#EXT-X-STREAM-INF") |
90 | + EXTXSTREAM=1 | ||
91 | + PROGRAMID="" | ||
92 | + CODECS="" | ||
93 | + RESOLUTION="" | ||
94 | + ARGUMENTS=`echo $line | cut -d':' -f 2` | ||
95 | + i=1 | ||
96 | + while [[ `echo $ARGUMENTS | cut -d',' -f $i` != "" ]]; do | ||
97 | + PARAMETER=`echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 2` | ||
98 | + case `echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 1` in | ||
99 | + "PROGRAM-ID") | ||
100 | + PROGRAMID=$PARAMETER;; | ||
101 | + "BANDWIDTH") | ||
102 | + BANDWIDTH=$PARAMETER;; | ||
103 | + "RESOLUTION") | ||
104 | + RESOLUTION=$PARAMETER;; | ||
105 | + "CODECS") | ||
106 | + CODECS=$PARAMETER;; | ||
107 | + esac | ||
108 | + ((i++)) | ||
109 | + done;;*/ | ||
90 | } | 110 | } |
91 | 111 | ||
92 | else if(extTag[0].equals("#EXT-X-ENDLIST")) | 112 | else if(extTag[0].equals("#EXT-X-ENDLIST")) |
@@ -100,42 +120,16 @@ public class Parser | @@ -100,42 +120,16 @@ public class Parser | ||
100 | } | 120 | } |
101 | } | 121 | } |
102 | 122 | ||
103 | - } | ||
104 | - | ||
105 | - } | ||
106 | - } | ||
107 | - | ||
108 | - | ||
109 | - /* | ||
110 | - "#EXT-X-STREAM-INF") | ||
111 | - EXTXSTREAM=1 | ||
112 | - PROGRAMID="" | ||
113 | - CODECS="" | ||
114 | - RESOLUTION="" | ||
115 | - ARGUMENTS=`echo $line | cut -d':' -f 2` | ||
116 | - i=1 | ||
117 | - while [[ `echo $ARGUMENTS | cut -d',' -f $i` != "" ]]; do | ||
118 | - PARAMETER=`echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 2` | ||
119 | - case `echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 1` in | ||
120 | - "PROGRAM-ID") | ||
121 | - PROGRAMID=$PARAMETER;; | ||
122 | - "BANDWIDTH") | ||
123 | - BANDWIDTH=$PARAMETER;; | ||
124 | - "RESOLUTION") | ||
125 | - RESOLUTION=$PARAMETER;; | ||
126 | - "CODECS") | ||
127 | - CODECS=$PARAMETER;; | ||
128 | - esac | ||
129 | - ((i++)) | ||
130 | - done;; | ||
131 | - "#EXT-X-ENDLIST") | ||
132 | - echo "INFO: Playlist end reached";; | ||
133 | - esac | ||
134 | - else | 123 | + /*else |
135 | echo "INFO: Comment found on line $CURRENT_LINE: \"`echo $line | cut -d'#' -f 2`\"" | 124 | echo "INFO: Comment found on line $CURRENT_LINE: \"`echo $line | cut -d'#' -f 2`\"" |
136 | - fi; | ||
137 | - else | ||
138 | - if [[ $EXTINF -eq 1 ]]; then | 125 | + fi;*/ |
126 | + | ||
127 | + | ||
128 | + } //es tag | ||
129 | + else | ||
130 | + { | ||
131 | + | ||
132 | + /*if [[ $EXTINF -eq 1 ]]; then | ||
139 | echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" | 133 | echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" |
140 | EXTINF=0 | 134 | EXTINF=0 |
141 | if [[ $CURRENT_SEGMENT -eq $SEQUENCE_FIRST ]]; then | 135 | if [[ $CURRENT_SEGMENT -eq $SEQUENCE_FIRST ]]; then |
@@ -150,15 +144,11 @@ public class Parser | @@ -150,15 +144,11 @@ public class Parser | ||
150 | else | 144 | else |
151 | echo "ERROR: Unexpected string \"$line\"" | 145 | echo "ERROR: Unexpected string \"$line\"" |
152 | exit 1 | 146 | exit 1 |
153 | - fi | ||
154 | - fi | ||
155 | - fi | ||
156 | - fi | ||
157 | - ((CURRENT_LINE++)) | ||
158 | -} | ||
159 | - | ||
160 | - */ | ||
161 | - | 147 | + */ |
148 | + } //no es tag | ||
149 | + } //ya validado | ||
150 | + } | ||
151 | + currentLine++; | ||
162 | } | 152 | } |
163 | 153 | ||
164 | } | 154 | } |