winlin

fix the http parse bug.

... ... @@ -73,6 +73,19 @@
3C1232E91AAEA5D000CE8F6C /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1232E71AAEA5D000CE8F6C /* libcrypto.a */; };
3C1232EA1AAEA5D000CE8F6C /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1232E81AAEA5D000CE8F6C /* libssl.a */; };
3C1232ED1AAEA70F00CE8F6C /* libhttp_parser.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1232EC1AAEA70F00CE8F6C /* libhttp_parser.a */; };
3C663F0E1AB0155100286D8B /* Makefile in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F011AB0155100286D8B /* Makefile */; };
3C663F0F1AB0155100286D8B /* srs_aac_raw_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F021AB0155100286D8B /* srs_aac_raw_publish.c */; };
3C663F101AB0155100286D8B /* srs_audio_raw_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F031AB0155100286D8B /* srs_audio_raw_publish.c */; };
3C663F111AB0155100286D8B /* srs_bandwidth_check.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F041AB0155100286D8B /* srs_bandwidth_check.c */; };
3C663F121AB0155100286D8B /* srs_detect_rtmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F051AB0155100286D8B /* srs_detect_rtmp.c */; };
3C663F131AB0155100286D8B /* srs_flv_injecter.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F061AB0155100286D8B /* srs_flv_injecter.c */; };
3C663F141AB0155100286D8B /* srs_flv_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F071AB0155100286D8B /* srs_flv_parser.c */; };
3C663F151AB0155100286D8B /* srs_h264_raw_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F081AB0155100286D8B /* srs_h264_raw_publish.c */; };
3C663F161AB0155100286D8B /* srs_ingest_flv.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F091AB0155100286D8B /* srs_ingest_flv.c */; };
3C663F171AB0155100286D8B /* srs_ingest_rtmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F0A1AB0155100286D8B /* srs_ingest_rtmp.c */; };
3C663F181AB0155100286D8B /* srs_play.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F0B1AB0155100286D8B /* srs_play.c */; };
3C663F191AB0155100286D8B /* srs_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F0C1AB0155100286D8B /* srs_publish.c */; };
3C663F1A1AB0155100286D8B /* srs_rtmp_dump.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F0D1AB0155100286D8B /* srs_rtmp_dump.c */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
... ... @@ -245,6 +258,19 @@
3C1232F21AAEAC7000CE8F6C /* srs-api */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "srs-api"; path = "../../../etc/init.d/srs-api"; sourceTree = "<group>"; };
3C1232F31AAEAC7000CE8F6C /* srs-demo */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "srs-demo"; path = "../../../etc/init.d/srs-demo"; sourceTree = "<group>"; };
3C1232F41AAEAC7000CE8F6C /* srs-demo-19350 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "srs-demo-19350"; path = "../../../etc/init.d/srs-demo-19350"; sourceTree = "<group>"; };
3C663F011AB0155100286D8B /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = ../../../research/librtmp/Makefile; sourceTree = "<group>"; };
3C663F021AB0155100286D8B /* srs_aac_raw_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_aac_raw_publish.c; path = ../../../research/librtmp/srs_aac_raw_publish.c; sourceTree = "<group>"; };
3C663F031AB0155100286D8B /* srs_audio_raw_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_audio_raw_publish.c; path = ../../../research/librtmp/srs_audio_raw_publish.c; sourceTree = "<group>"; };
3C663F041AB0155100286D8B /* srs_bandwidth_check.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_bandwidth_check.c; path = ../../../research/librtmp/srs_bandwidth_check.c; sourceTree = "<group>"; };
3C663F051AB0155100286D8B /* srs_detect_rtmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_detect_rtmp.c; path = ../../../research/librtmp/srs_detect_rtmp.c; sourceTree = "<group>"; };
3C663F061AB0155100286D8B /* srs_flv_injecter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_flv_injecter.c; path = ../../../research/librtmp/srs_flv_injecter.c; sourceTree = "<group>"; };
3C663F071AB0155100286D8B /* srs_flv_parser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_flv_parser.c; path = ../../../research/librtmp/srs_flv_parser.c; sourceTree = "<group>"; };
3C663F081AB0155100286D8B /* srs_h264_raw_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_h264_raw_publish.c; path = ../../../research/librtmp/srs_h264_raw_publish.c; sourceTree = "<group>"; };
3C663F091AB0155100286D8B /* srs_ingest_flv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_ingest_flv.c; path = ../../../research/librtmp/srs_ingest_flv.c; sourceTree = "<group>"; };
3C663F0A1AB0155100286D8B /* srs_ingest_rtmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_ingest_rtmp.c; path = ../../../research/librtmp/srs_ingest_rtmp.c; sourceTree = "<group>"; };
3C663F0B1AB0155100286D8B /* srs_play.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_play.c; path = ../../../research/librtmp/srs_play.c; sourceTree = "<group>"; };
3C663F0C1AB0155100286D8B /* srs_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_publish.c; path = ../../../research/librtmp/srs_publish.c; sourceTree = "<group>"; };
3C663F0D1AB0155100286D8B /* srs_rtmp_dump.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_rtmp_dump.c; path = ../../../research/librtmp/srs_rtmp_dump.c; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
... ... @@ -265,9 +291,10 @@
3C1231DC1AAE64A400CE8F6C = {
isa = PBXGroup;
children = (
3C1231E61AAE64A400CE8F6C /* Products */,
3C1232EE1AAEA71C00CE8F6C /* links */,
3C1231E71AAE64A400CE8F6C /* srs_xcode */,
3C1231E61AAE64A400CE8F6C /* Products */,
3C663F001AB014B500286D8B /* research */,
);
sourceTree = "<group>";
};
... ... @@ -529,6 +556,27 @@
name = init.d;
sourceTree = "<group>";
};
3C663F001AB014B500286D8B /* research */ = {
isa = PBXGroup;
children = (
3C663F011AB0155100286D8B /* Makefile */,
3C663F021AB0155100286D8B /* srs_aac_raw_publish.c */,
3C663F031AB0155100286D8B /* srs_audio_raw_publish.c */,
3C663F041AB0155100286D8B /* srs_bandwidth_check.c */,
3C663F051AB0155100286D8B /* srs_detect_rtmp.c */,
3C663F061AB0155100286D8B /* srs_flv_injecter.c */,
3C663F071AB0155100286D8B /* srs_flv_parser.c */,
3C663F081AB0155100286D8B /* srs_h264_raw_publish.c */,
3C663F091AB0155100286D8B /* srs_ingest_flv.c */,
3C663F0A1AB0155100286D8B /* srs_ingest_rtmp.c */,
3C663F0B1AB0155100286D8B /* srs_play.c */,
3C663F0C1AB0155100286D8B /* srs_publish.c */,
3C663F0D1AB0155100286D8B /* srs_rtmp_dump.c */,
);
name = research;
path = srs_xcode;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
... ... @@ -586,9 +634,12 @@
buildActionMask = 2147483647;
files = (
3C1232951AAE81D900CE8F6C /* srs_app_config.cpp in Sources */,
3C663F0F1AB0155100286D8B /* srs_aac_raw_publish.c in Sources */,
3C1232961AAE81D900CE8F6C /* srs_app_conn.cpp in Sources */,
3C12322A1AAE814D00CE8F6C /* srs_kernel_ts.cpp in Sources */,
3C12329E1AAE81D900CE8F6C /* srs_app_hls.cpp in Sources */,
3C663F171AB0155100286D8B /* srs_ingest_rtmp.c in Sources */,
3C663F131AB0155100286D8B /* srs_flv_injecter.c in Sources */,
3C1232971AAE81D900CE8F6C /* srs_app_dvr.cpp in Sources */,
3C1232271AAE814D00CE8F6C /* srs_kernel_log.cpp in Sources */,
3C1232A81AAE81D900CE8F6C /* srs_app_log.cpp in Sources */,
... ... @@ -600,6 +651,8 @@
3C12324A1AAE81A400CE8F6C /* srs_rtsp_stack.cpp in Sources */,
3C1232A51AAE81D900CE8F6C /* srs_app_json.cpp in Sources */,
3C12329F1AAE81D900CE8F6C /* srs_app_http_api.cpp in Sources */,
3C663F101AB0155100286D8B /* srs_audio_raw_publish.c in Sources */,
3C663F111AB0155100286D8B /* srs_bandwidth_check.c in Sources */,
3C1232A11AAE81D900CE8F6C /* srs_app_http_conn.cpp in Sources */,
3C1232AC1AAE81D900CE8F6C /* srs_app_refer.cpp in Sources */,
3C1232991AAE81D900CE8F6C /* srs_app_empty.cpp in Sources */,
... ... @@ -608,9 +661,11 @@
3C1232221AAE814D00CE8F6C /* srs_kernel_codec.cpp in Sources */,
3C1232B71AAE81D900CE8F6C /* srs_app_utility.cpp in Sources */,
3C1232AB1AAE81D900CE8F6C /* srs_app_recv_thread.cpp in Sources */,
3C663F151AB0155100286D8B /* srs_h264_raw_publish.c in Sources */,
3C1231F61AAE652D00CE8F6C /* srs_core_autofree.cpp in Sources */,
3C1232411AAE81A400CE8F6C /* srs_raw_avc.cpp in Sources */,
3C1232491AAE81A400CE8F6C /* srs_rtmp_utility.cpp in Sources */,
3C663F191AB0155100286D8B /* srs_publish.c in Sources */,
3C1232A01AAE81D900CE8F6C /* srs_app_http_client.cpp in Sources */,
3C12329B1AAE81D900CE8F6C /* srs_app_ffmpeg.cpp in Sources */,
3C1232421AAE81A400CE8F6C /* srs_rtmp_amf0.cpp in Sources */,
... ... @@ -620,6 +675,7 @@
3C1232AD1AAE81D900CE8F6C /* srs_app_reload.cpp in Sources */,
3C1231F81AAE652D00CE8F6C /* srs_core.cpp in Sources */,
3C1232A21AAE81D900CE8F6C /* srs_app_http_hooks.cpp in Sources */,
3C663F121AB0155100286D8B /* srs_detect_rtmp.c in Sources */,
3C1232B11AAE81D900CE8F6C /* srs_app_server.cpp in Sources */,
3C1232B31AAE81D900CE8F6C /* srs_app_st_socket.cpp in Sources */,
3C1232061AAE812C00CE8F6C /* srs_main_server.cpp in Sources */,
... ... @@ -630,15 +686,20 @@
3C1232461AAE81A400CE8F6C /* srs_rtmp_msg_array.cpp in Sources */,
3C1232A71AAE81D900CE8F6C /* srs_app_listener.cpp in Sources */,
3C1232261AAE814D00CE8F6C /* srs_kernel_flv.cpp in Sources */,
3C663F1A1AB0155100286D8B /* srs_rtmp_dump.c in Sources */,
3C1232241AAE814D00CE8F6C /* srs_kernel_error.cpp in Sources */,
3C1232441AAE81A400CE8F6C /* srs_rtmp_handshake.cpp in Sources */,
3C1232291AAE814D00CE8F6C /* srs_kernel_stream.cpp in Sources */,
3C663F181AB0155100286D8B /* srs_play.c in Sources */,
3C1232B61AAE81D900CE8F6C /* srs_app_thread.cpp in Sources */,
3C1232A91AAE81D900CE8F6C /* srs_app_mpegts_udp.cpp in Sources */,
3C1232AE1AAE81D900CE8F6C /* srs_app_rtmp_conn.cpp in Sources */,
3C1232B51AAE81D900CE8F6C /* srs_app_statistic.cpp in Sources */,
3C663F161AB0155100286D8B /* srs_ingest_flv.c in Sources */,
3C663F141AB0155100286D8B /* srs_flv_parser.c in Sources */,
3C1232451AAE81A400CE8F6C /* srs_rtmp_io.cpp in Sources */,
3C1232431AAE81A400CE8F6C /* srs_rtmp_buffer.cpp in Sources */,
3C663F0E1AB0155100286D8B /* Makefile in Sources */,
3C1232211AAE814D00CE8F6C /* srs_kernel_buffer.cpp in Sources */,
3C1232471AAE81A400CE8F6C /* srs_rtmp_sdk.cpp in Sources */,
3C1232A61AAE81D900CE8F6C /* srs_app_kbps.cpp in Sources */,
... ...
... ... @@ -53,7 +53,8 @@ int main(int argc, char** argv)
// user option parse index.
int opt = 0;
// user options.
char* in_flv_file; char* out_rtmp_url;
char* in_flv_file = NULL;
char* out_rtmp_url = NULL;
// rtmp handler
srs_rtmp_t ortmp;
// flv handler
... ... @@ -89,6 +90,15 @@ int main(int argc, char** argv)
}
}
if (!in_flv_file) {
srs_human_trace("input invalid, use -i <input>");
return -1;
}
if (!out_rtmp_url) {
srs_human_trace("output invalid, use -y <output>");
return -1;
}
srs_human_trace("input: %s", in_flv_file);
srs_human_trace("output: %s", out_rtmp_url);
... ...
... ... @@ -41,7 +41,8 @@ int main(int argc, char** argv)
// user option parse index.
int opt = 0;
// user options.
char* in_rtmp_url; char* out_rtmp_url;
char* in_rtmp_url = NULL;
char* out_rtmp_url = NULL;
// rtmp handler
srs_rtmp_t irtmp, ortmp;
... ... @@ -74,6 +75,15 @@ int main(int argc, char** argv)
}
}
if (!in_rtmp_url) {
srs_human_trace("input invalid, use -i <input>");
return -1;
}
if (!out_rtmp_url) {
srs_human_trace("output invalid, use -y <output>");
return -1;
}
srs_human_trace("input: %s", in_rtmp_url);
srs_human_trace("output: %s", out_rtmp_url);
... ...
... ... @@ -43,9 +43,6 @@ using namespace std;
#define SRS_DEFAULT_HTTP_PORT 80
#define SRS_HTTP_HEADER_BUFFER 1024
#define SRS_HTTP_BODY_BUFFER 1024
// for http parser macros
#define SRS_CONSTS_HTTP_OPTIONS HTTP_OPTIONS
#define SRS_CONSTS_HTTP_GET HTTP_GET
... ... @@ -1310,9 +1307,18 @@ int SrsHttpParser::parse_message_imp(SrsStSocket* skt)
int ret = ERROR_SUCCESS;
while (true) {
if (buffer->size() <= 0) {
// when empty, only grow 1bytes, but the buffer will cache more.
if ((ret = buffer->grow(skt, 1)) != ERROR_SUCCESS) {
ssize_t nparsed = 0;
// when buffer not empty, parse it.
if (buffer->size() > 0) {
nparsed = http_parser_execute(&parser, &settings, buffer->bytes(), buffer->size());
srs_info("buffer=%d, nparsed=%d, body=%d", buffer->size(), (int)nparsed, body_parsed);
}
// when nothing parsed, read more to parse.
if (nparsed == 0) {
// when requires more, only grow 1bytes, but the buffer will cache more.
if ((ret = buffer->grow(skt, buffer->size() + 1)) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("read body from server failed. ret=%d", ret);
}
... ... @@ -1320,10 +1326,8 @@ int SrsHttpParser::parse_message_imp(SrsStSocket* skt)
}
}
int nb_header = srs_min(SRS_HTTP_HEADER_BUFFER, buffer->size());
ssize_t nparsed = http_parser_execute(&parser, &settings, buffer->bytes(), nb_header);
srs_info("buffer=%d, nparsed=%d, body=%d", buffer->size(), (int)nparsed, body_parsed);
if (nparsed - body_parsed > 0) {
// consume the parsed bytes.
if (nparsed && nparsed - body_parsed > 0) {
buffer->read_slice(nparsed - body_parsed);
}
... ...