Support port number in stv URL
the new stv URL format is stv://host:port
Change-Id: I9a2ad5ddcde09869386e96d3d123056cba300f2a
diff --git a/libavformat/stv.c b/libavformat/stv.c
index d77c256..771ba78 100755
--- a/libavformat/stv.c
+++ b/libavformat/stv.c
@@ -44,11 +44,11 @@
//#define DEBUG_STV
-#define ASKAHEAD 65536
-
-// OSX doesn't have MSG_NOSIGNAL defined, neither does cygwin
-#if (defined(__APPLE__) || defined(__MINGW32__))
-#define MSG_NOSIGNAL 0
+#define ASKAHEAD 65536
+
+// OSX doesn't have MSG_NOSIGNAL defined, neither does cygwin
+#if (defined(__APPLE__) || defined(__MINGW32__))
+#define MSG_NOSIGNAL 0
#endif
typedef struct {
@@ -161,6 +161,8 @@
struct sockaddr_in* inetAddress;
struct hostent* hostptr;
char data[512];
+ char host[256]; //the same size of STVContext.host
+ int port;
#ifdef __MINGW32__
int strl;
wchar_t* wfilename;
@@ -204,11 +206,34 @@
// {
// return STREAM_ERROR;
// }
+
+ port = 7818; //default port
+ char *pc = strchr( p->host, ':' );
+ if ( pc == NULL )
+ {
+ strncpy( host, p->host, sizeof(host)-1 );
+ host[sizeof(host)-1] = 0x0;
+ } else {
+ int len = pc - p->host;
+ if ( len > sizeof(host)-1 )
+ len = sizeof(host) - 1;
+ strncpy( host, p->host, len );
+ host[len] = 0;
+ port = atoi( pc+1 );
+ if ( port == 0 || len == 0 )
+ {
+ #ifdef DEBUG_STV
+ av_log(NULL, AV_LOG_ERROR,"STV:// wrong host name.%s\n", p->host);
+ #endif
+ return 0;
+ }
+ }
+
inetAddress = (struct sockaddr_in*) ( (void *) &address); // cast it to IPV4 addressing
inetAddress->sin_family = PF_INET;
- inetAddress->sin_port = htons(7818);
+ inetAddress->sin_port = htons(port);
- hostptr = gethostbyname(p->host);
+ hostptr = gethostbyname(host);
if (!hostptr)
{
close(newfd);