Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
2801bd5a
Commit
2801bd5a
authored
Nov 20, 2014
by
Francois Cartegnie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stream_filter: dash: refactor the HTTP thing
parent
06a57693
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
76 deletions
+96
-76
modules/stream_filter/dash/http/HTTPConnection.cpp
modules/stream_filter/dash/http/HTTPConnection.cpp
+10
-23
modules/stream_filter/dash/http/HTTPConnection.h
modules/stream_filter/dash/http/HTTPConnection.h
+1
-12
modules/stream_filter/dash/http/IHTTPConnection.cpp
modules/stream_filter/dash/http/IHTTPConnection.cpp
+47
-14
modules/stream_filter/dash/http/IHTTPConnection.h
modules/stream_filter/dash/http/IHTTPConnection.h
+13
-3
modules/stream_filter/dash/http/PersistentConnection.cpp
modules/stream_filter/dash/http/PersistentConnection.cpp
+24
-24
modules/stream_filter/dash/http/PersistentConnection.h
modules/stream_filter/dash/http/PersistentConnection.h
+1
-0
No files found.
modules/stream_filter/dash/http/HTTPConnection.cpp
View file @
2801bd5a
...
@@ -26,12 +26,14 @@
...
@@ -26,12 +26,14 @@
#endif
#endif
#include "HTTPConnection.h"
#include "HTTPConnection.h"
#include <vlc_network.h>
#include <sstream>
using
namespace
dash
::
http
;
using
namespace
dash
::
http
;
HTTPConnection
::
HTTPConnection
(
stream_t
*
stream
)
:
HTTPConnection
::
HTTPConnection
(
stream_t
*
stream
)
:
httpSocket
(
-
1
),
IHTTPConnection
(
stream
),
stream
(
stream
),
peekBufferLen
(
0
),
peekBufferLen
(
0
),
contentLength
(
0
)
contentLength
(
0
)
{
{
...
@@ -81,20 +83,12 @@ std::string HTTPConnection::getRequestHeader (const Chunk *chunk) const
...
@@ -81,20 +83,12 @@ std::string HTTPConnection::getRequestHeader (const Chunk *chunk) const
bool
HTTPConnection
::
init
(
Chunk
*
chunk
)
bool
HTTPConnection
::
init
(
Chunk
*
chunk
)
{
{
if
(
!
chunk
->
hasHostname
())
if
(
IHTTPConnection
::
init
(
chunk
))
if
(
!
this
->
setUrlRelative
(
chunk
))
return
parseHeader
();
return
false
;
else
this
->
httpSocket
=
net_ConnectTCP
(
this
->
stream
,
chunk
->
getHostname
().
c_str
(),
chunk
->
getPort
());
if
(
this
->
httpSocket
==
-
1
)
return
false
;
return
false
;
if
(
this
->
sendData
(
this
->
getRequestHeader
(
chunk
).
append
(
"
\r\n
"
)))
return
this
->
parseHeader
();
return
false
;
}
}
bool
HTTPConnection
::
parseHeader
()
bool
HTTPConnection
::
parseHeader
()
{
{
std
::
string
line
=
this
->
readLine
();
std
::
string
line
=
this
->
readLine
();
...
@@ -135,7 +129,7 @@ std::string HTTPConnection::readLine ()
...
@@ -135,7 +129,7 @@ std::string HTTPConnection::readLine ()
return
""
;
return
""
;
}
}
bool
HTTPConnection
::
send
Data
(
const
std
::
string
&
data
)
bool
HTTPConnection
::
send
(
const
std
::
string
&
data
)
{
{
ssize_t
size
=
net_Write
(
this
->
stream
,
this
->
httpSocket
,
NULL
,
data
.
c_str
(),
data
.
size
());
ssize_t
size
=
net_Write
(
this
->
stream
,
this
->
httpSocket
,
NULL
,
data
.
c_str
(),
data
.
size
());
if
(
size
==
-
1
)
if
(
size
==
-
1
)
...
@@ -144,7 +138,7 @@ bool HTTPConnection::sendData (const std::string& data)
...
@@ -144,7 +138,7 @@ bool HTTPConnection::sendData (const std::string& data)
}
}
if
((
size_t
)
size
!=
data
.
length
())
if
((
size_t
)
size
!=
data
.
length
())
{
{
this
->
send
Data
(
data
.
substr
(
size
,
data
.
size
()));
this
->
send
(
data
.
substr
(
size
,
data
.
size
()));
}
}
return
true
;
return
true
;
...
@@ -154,11 +148,4 @@ void HTTPConnection::closeSocket ()
...
@@ -154,11 +148,4 @@ void HTTPConnection::closeSocket ()
if
(
httpSocket
>=
0
)
if
(
httpSocket
>=
0
)
net_Close
(
httpSocket
);
net_Close
(
httpSocket
);
}
}
bool
HTTPConnection
::
setUrlRelative
(
Chunk
*
chunk
)
{
std
::
stringstream
ss
;
ss
<<
stream
->
psz_access
<<
"://"
<<
Helper
::
combinePaths
(
Helper
::
getDirectoryPath
(
stream
->
psz_path
),
chunk
->
getUrl
());
chunk
->
setUrl
(
ss
.
str
());
return
chunk
->
hasHostname
();
}
modules/stream_filter/dash/http/HTTPConnection.h
View file @
2801bd5a
...
@@ -25,15 +25,7 @@
...
@@ -25,15 +25,7 @@
#ifndef HTTPCONNECTION_H_
#ifndef HTTPCONNECTION_H_
#define HTTPCONNECTION_H_
#define HTTPCONNECTION_H_
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_stream.h>
#include <vlc_network.h>
#include <string>
#include <string>
#include <stdint.h>
#include <iostream>
#include <sstream>
#include "http/IHTTPConnection.h"
#include "http/IHTTPConnection.h"
#include "http/Chunk.h"
#include "http/Chunk.h"
...
@@ -57,17 +49,14 @@ namespace dash
...
@@ -57,17 +49,14 @@ namespace dash
virtual
int
peek
(
const
uint8_t
**
pp_peek
,
size_t
i_peek
);
virtual
int
peek
(
const
uint8_t
**
pp_peek
,
size_t
i_peek
);
protected:
protected:
int
httpSocket
;
stream_t
*
stream
;
uint8_t
*
peekBuffer
;
uint8_t
*
peekBuffer
;
size_t
peekBufferLen
;
size_t
peekBufferLen
;
int
contentLength
;
int
contentLength
;
bool
sendData
(
const
std
::
string
&
data
);
virtual
bool
send
(
const
std
::
string
&
data
);
bool
parseHeader
();
bool
parseHeader
();
std
::
string
readLine
();
std
::
string
readLine
();
virtual
std
::
string
getRequestHeader
(
const
Chunk
*
chunk
)
const
;
/* reimpl */
virtual
std
::
string
getRequestHeader
(
const
Chunk
*
chunk
)
const
;
/* reimpl */
bool
setUrlRelative
(
Chunk
*
chunk
);
};
};
}
}
}
}
...
...
modules/stream_filter/dash/http/IHTTPConnection.cpp
View file @
2801bd5a
...
@@ -20,27 +20,60 @@
...
@@ -20,27 +20,60 @@
#include "IHTTPConnection.h"
#include "IHTTPConnection.h"
#include "Chunk.h"
#include "Chunk.h"
#include "Helper.h"
#include <vlc_network.h>
#include <sstream>
#include <sstream>
using
namespace
dash
::
http
;
using
namespace
dash
::
http
;
std
::
string
IHTTPConnection
::
getRequestHeader
(
const
Chunk
*
chunk
)
const
IHTTPConnection
::
IHTTPConnection
(
stream_t
*
stream_
)
{
stream
=
stream_
;
httpSocket
=
-
1
;
}
IHTTPConnection
::~
IHTTPConnection
()
{
}
bool
IHTTPConnection
::
init
(
Chunk
*
chunk
)
{
{
std
::
string
request
;
if
(
chunk
==
NULL
)
if
(
!
chunk
->
usesByteRange
())
return
false
;
if
(
!
chunk
->
hasHostname
())
{
{
request
=
"GET "
+
chunk
->
getPath
()
+
" HTTP/1.1"
+
"
\r\n
"
+
chunk
->
setUrl
(
getUrlRelative
(
chunk
));
"Host: "
+
chunk
->
getHostname
()
+
"
\r\n
"
;
if
(
!
chunk
->
hasHostname
())
return
false
;
}
}
else
{
std
::
stringstream
req
;
req
<<
"GET "
<<
chunk
->
getPath
()
<<
" HTTP/1.1
\r\n
"
<<
"Host: "
<<
chunk
->
getHostname
()
<<
"
\r\n
"
<<
"Range: bytes="
<<
chunk
->
getStartByte
()
<<
"-"
<<
chunk
->
getEndByte
()
<<
"
\r\n
"
;
request
=
req
.
str
();
httpSocket
=
net_ConnectTCP
(
stream
,
chunk
->
getHostname
().
c_str
(),
chunk
->
getPort
());
}
return
request
;
if
(
httpSocket
==
-
1
)
return
false
;
return
send
(
getRequestHeader
(
chunk
).
append
(
"
\r\n
"
));
}
std
::
string
IHTTPConnection
::
getRequestHeader
(
const
Chunk
*
chunk
)
const
{
std
::
stringstream
req
;
req
<<
"GET "
<<
chunk
->
getPath
()
<<
" HTTP/1.1
\r\n
"
<<
"Host: "
<<
chunk
->
getHostname
()
<<
"
\r\n
"
;
if
(
chunk
->
usesByteRange
())
req
<<
"Range: bytes="
<<
chunk
->
getStartByte
()
<<
"-"
<<
chunk
->
getEndByte
()
<<
"
\r\n
"
;
return
req
.
str
();
}
std
::
string
IHTTPConnection
::
getUrlRelative
(
const
Chunk
*
chunk
)
const
{
std
::
stringstream
ss
;
ss
<<
stream
->
psz_access
<<
"://"
<<
Helper
::
combinePaths
(
Helper
::
getDirectoryPath
(
stream
->
psz_path
),
chunk
->
getUrl
());
return
ss
.
str
();
}
}
modules/stream_filter/dash/http/IHTTPConnection.h
View file @
2801bd5a
...
@@ -25,8 +25,12 @@
...
@@ -25,8 +25,12 @@
#ifndef IHTTPCONNECTION_H_
#ifndef IHTTPCONNECTION_H_
#define IHTTPCONNECTION_H_
#define IHTTPCONNECTION_H_
#include <stdint.h>
#ifdef HAVE_CONFIG_H
#include <unistd.h>
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_stream.h>
#include <string>
#include <string>
namespace
dash
namespace
dash
...
@@ -37,11 +41,17 @@ namespace dash
...
@@ -37,11 +41,17 @@ namespace dash
class
IHTTPConnection
class
IHTTPConnection
{
{
public:
public:
IHTTPConnection
(
stream_t
*
stream
);
virtual
~
IHTTPConnection
();
virtual
bool
init
(
Chunk
*
chunk
);
virtual
bool
send
(
const
std
::
string
&
data
)
=
0
;
virtual
int
read
(
void
*
p_buffer
,
size_t
len
)
=
0
;
virtual
int
read
(
void
*
p_buffer
,
size_t
len
)
=
0
;
virtual
int
peek
(
const
uint8_t
**
pp_peek
,
size_t
i_peek
)
=
0
;
virtual
int
peek
(
const
uint8_t
**
pp_peek
,
size_t
i_peek
)
=
0
;
virtual
~
IHTTPConnection
()
{}
protected:
protected:
virtual
std
::
string
getRequestHeader
(
const
Chunk
*
chunk
)
const
;
virtual
std
::
string
getRequestHeader
(
const
Chunk
*
chunk
)
const
;
virtual
std
::
string
getUrlRelative
(
const
Chunk
*
chunk
)
const
;
stream_t
*
stream
;
int
httpSocket
;
};
};
}
}
}
}
...
...
modules/stream_filter/dash/http/PersistentConnection.cpp
View file @
2801bd5a
...
@@ -27,6 +27,8 @@
...
@@ -27,6 +27,8 @@
#include "PersistentConnection.h"
#include "PersistentConnection.h"
#include <vlc_network.h>
using
namespace
dash
::
http
;
using
namespace
dash
::
http
;
const
int
PersistentConnection
::
RETRY
=
5
;
const
int
PersistentConnection
::
RETRY
=
5
;
...
@@ -88,28 +90,17 @@ int PersistentConnection::read (void *p_buffer, siz
...
@@ -88,28 +90,17 @@ int PersistentConnection::read (void *p_buffer, siz
bool
PersistentConnection
::
init
(
Chunk
*
chunk
)
bool
PersistentConnection
::
init
(
Chunk
*
chunk
)
{
{
if
(
this
->
isInit
)
if
(
isInit
)
return
true
;
return
true
;
if
(
chunk
==
NULL
)
if
(
IHTTPConnection
::
init
(
chunk
))
return
false
;
{
isInit
=
true
;
if
(
!
chunk
->
hasHostname
())
chunkQueue
.
push_back
(
chunk
);
if
(
!
this
->
setUrlRelative
(
chunk
))
hostname
=
chunk
->
getHostname
();
return
false
;
}
this
->
httpSocket
=
net_ConnectTCP
(
this
->
stream
,
chunk
->
getHostname
().
c_str
(),
chunk
->
getPort
());
if
(
this
->
httpSocket
==
-
1
)
return
false
;
if
(
this
->
sendData
(
this
->
getRequestHeader
(
chunk
).
append
(
"
\r\n
"
)))
this
->
isInit
=
true
;
this
->
chunkQueue
.
push_back
(
chunk
);
this
->
hostname
=
chunk
->
getHostname
();
return
this
->
isInit
;
return
isInit
;
}
}
bool
PersistentConnection
::
addChunk
(
Chunk
*
chunk
)
bool
PersistentConnection
::
addChunk
(
Chunk
*
chunk
)
{
{
...
@@ -120,13 +111,16 @@ bool PersistentConnection::addChunk (Chunk *chunk)
...
@@ -120,13 +111,16 @@ bool PersistentConnection::addChunk (Chunk *chunk)
return
this
->
init
(
chunk
);
return
this
->
init
(
chunk
);
if
(
!
chunk
->
hasHostname
())
if
(
!
chunk
->
hasHostname
())
if
(
!
this
->
setUrlRelative
(
chunk
))
{
chunk
->
setUrl
(
getUrlRelative
(
chunk
));
if
(
!
chunk
->
hasHostname
())
return
false
;
return
false
;
}
if
(
chunk
->
getHostname
().
compare
(
this
->
hostname
))
if
(
chunk
->
getHostname
().
compare
(
this
->
hostname
))
return
false
;
return
false
;
if
(
this
->
sendData
(
this
->
getRequestHeader
(
chunk
).
append
(
"
\r\n
"
)))
if
(
send
(
getRequestHeader
(
chunk
).
append
(
"
\r\n
"
)))
{
{
this
->
chunkQueue
.
push_back
(
chunk
);
this
->
chunkQueue
.
push_back
(
chunk
);
return
true
;
return
true
;
...
@@ -156,7 +150,7 @@ bool PersistentConnection::initChunk (Chunk *chunk)
...
@@ -156,7 +150,7 @@ bool PersistentConnection::initChunk (Chunk *chunk)
bool
PersistentConnection
::
reconnect
(
Chunk
*
chunk
)
bool
PersistentConnection
::
reconnect
(
Chunk
*
chunk
)
{
{
int
count
=
0
;
int
count
=
0
;
std
::
string
request
=
this
->
getRequestHeader
(
chunk
).
append
(
"
\r\n
"
);
std
::
string
request
=
getRequestHeader
(
chunk
).
append
(
"
\r\n
"
);
while
(
count
<
this
->
RETRY
)
while
(
count
<
this
->
RETRY
)
{
{
...
@@ -180,9 +174,15 @@ bool PersistentConnection::isConnected () const
...
@@ -180,9 +174,15 @@ bool PersistentConnection::isConnected () const
}
}
bool
PersistentConnection
::
resendAllRequests
()
bool
PersistentConnection
::
resendAllRequests
()
{
{
for
(
size_t
i
=
0
;
i
<
this
->
chunkQueue
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
chunkQueue
.
size
();
i
++
)
if
(
!
this
->
sendData
(
this
->
getRequestHeader
(
this
->
chunkQueue
.
at
(
i
)).
append
(
"
\r\n
"
)))
if
(
!
send
(
getRequestHeader
(
chunkQueue
.
at
(
i
)).
append
(
"
\r\n
"
)))
return
false
;
return
false
;
return
true
;
return
true
;
}
}
std
::
string
PersistentConnection
::
getRequestHeader
(
const
Chunk
*
chunk
)
const
{
/* can clearly see here that inheritance is reversed :/ */
return
IHTTPConnection
::
getRequestHeader
(
chunk
);
}
modules/stream_filter/dash/http/PersistentConnection.h
View file @
2801bd5a
...
@@ -55,6 +55,7 @@ namespace dash
...
@@ -55,6 +55,7 @@ namespace dash
bool
initChunk
(
Chunk
*
chunk
);
bool
initChunk
(
Chunk
*
chunk
);
bool
reconnect
(
Chunk
*
chunk
);
bool
reconnect
(
Chunk
*
chunk
);
bool
resendAllRequests
();
bool
resendAllRequests
();
virtual
std
::
string
getRequestHeader
(
const
Chunk
*
chunk
)
const
;
/* reimpl */
};
};
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment