2018-08-24 03:55:36 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
parseurl.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHOR
|
2018-09-07 06:00:25 +03:00
|
|
|
Dan Kortschak <dan@ausocean.org>
|
2018-08-24 03:55:36 +03:00
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
parseurl.go is Copyright (C) 2017-2018 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2018-08-30 14:01:19 +03:00
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
2018-08-24 03:55:36 +03:00
|
|
|
|
2018-08-30 14:01:19 +03:00
|
|
|
Derived from librtmp under the GNU Lesser General Public License 2.1
|
|
|
|
Copyright (C) 2005-2008 Team XBMC http://www.xbmc.org
|
|
|
|
Copyright (C) 2008-2009 Andrej Stepanchuk
|
|
|
|
Copyright (C) 2009-2010 Howard Chu
|
2018-08-24 03:55:36 +03:00
|
|
|
*/
|
2018-08-24 00:34:01 +03:00
|
|
|
package rtmp
|
|
|
|
|
2018-08-24 03:03:05 +03:00
|
|
|
import (
|
|
|
|
"log"
|
2018-09-07 06:00:25 +03:00
|
|
|
"net/url"
|
|
|
|
"path"
|
2018-08-24 03:03:05 +03:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2018-09-07 00:31:59 +03:00
|
|
|
// int RTMP_ParseURL(const char *url, int *protocol, AVal *host, unsigned int *port, AVal *playpath, AVal *app);
|
2018-08-24 00:34:01 +03:00
|
|
|
// parseurl.c +33
|
2018-09-07 14:10:46 +03:00
|
|
|
func C_RTMP_ParseURL(addr string) (protocol int32, host string, port uint16, app, playpath string, ok bool) {
|
2018-09-07 06:00:25 +03:00
|
|
|
u, err := url.Parse(addr)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("failed to parse addr: %v", err)
|
|
|
|
return protocol, host, port, app, playpath, false
|
2018-08-24 00:34:01 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 06:00:25 +03:00
|
|
|
switch u.Scheme {
|
|
|
|
case "rtmp":
|
|
|
|
protocol = RTMP_PROTOCOL_RTMP
|
|
|
|
case "rtmpt":
|
|
|
|
protocol = RTMP_PROTOCOL_RTMPT
|
|
|
|
case "rtmps":
|
|
|
|
protocol = RTMP_PROTOCOL_RTMPS
|
|
|
|
case "rtmpe":
|
|
|
|
protocol = RTMP_PROTOCOL_RTMPE
|
|
|
|
case "rtmfp":
|
|
|
|
protocol = RTMP_PROTOCOL_RTMFP
|
|
|
|
case "rtmpte":
|
|
|
|
protocol = RTMP_PROTOCOL_RTMPTE
|
|
|
|
case "rtmpts":
|
|
|
|
protocol = RTMP_PROTOCOL_RTMPTS
|
|
|
|
default:
|
|
|
|
log.Printf("unknown scheme: %q", u.Scheme)
|
|
|
|
return protocol, host, port, app, playpath, false
|
2018-08-24 00:34:01 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 14:10:46 +03:00
|
|
|
host = u.Host
|
2018-09-07 06:00:25 +03:00
|
|
|
if p := u.Port(); p != "" {
|
|
|
|
pi, err := strconv.Atoi(p)
|
2018-09-07 00:31:59 +03:00
|
|
|
if err != nil {
|
2018-09-07 06:00:25 +03:00
|
|
|
return protocol, host, port, app, playpath, false
|
2018-09-07 00:31:59 +03:00
|
|
|
}
|
2018-09-07 06:00:25 +03:00
|
|
|
port = uint16(pi)
|
2018-08-24 00:34:01 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 06:00:25 +03:00
|
|
|
if !path.IsAbs(u.Path) {
|
2018-09-07 14:10:46 +03:00
|
|
|
return protocol, host, port, app, playpath, true
|
2018-08-24 00:34:01 +03:00
|
|
|
}
|
2018-09-07 06:00:25 +03:00
|
|
|
elems := strings.SplitN(u.Path[1:], "/", 3)
|
2018-09-07 14:10:46 +03:00
|
|
|
app = elems[0]
|
|
|
|
playpath = elems[1]
|
2018-09-07 06:00:25 +03:00
|
|
|
if len(elems) == 3 && len(elems[2]) != 0 {
|
2018-09-07 14:10:46 +03:00
|
|
|
playpath = path.Join(elems[1:]...)
|
|
|
|
switch ext := path.Ext(playpath); ext {
|
2018-09-07 06:00:25 +03:00
|
|
|
case ".f4v", ".mp4":
|
2018-09-07 14:10:46 +03:00
|
|
|
playpath = "mp4:" + playpath[:len(playpath)-len(ext)]
|
2018-09-07 06:00:25 +03:00
|
|
|
case ".mp3":
|
2018-09-07 14:10:46 +03:00
|
|
|
playpath = "mp3:" + playpath[:len(playpath)-len(ext)]
|
2018-09-07 06:00:25 +03:00
|
|
|
case ".flv":
|
2018-09-07 14:10:46 +03:00
|
|
|
playpath = playpath[:len(playpath)-len(ext)]
|
2018-09-07 06:00:25 +03:00
|
|
|
}
|
|
|
|
if u.RawQuery != "" {
|
2018-09-07 14:10:46 +03:00
|
|
|
playpath += "?" + u.RawQuery
|
2018-09-07 06:00:25 +03:00
|
|
|
}
|
2018-08-24 00:34:01 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 06:00:25 +03:00
|
|
|
return protocol, host, port, app, playpath, true
|
2018-08-24 00:34:01 +03:00
|
|
|
}
|