winlin

Merge branch 'srs.master'

... ... @@ -46,8 +46,8 @@ SRS_LIBRTMP_I = $(SRS_OBJS)/include/srs_librtmp.h
SRS_LIBRTMP_L = $(SRS_OBJS)/lib/srs_librtmp.a
# openssl for complex handshake, built by srs.
SRS_LIBSSL_L =
# the research public headers
SRS_RESEARCH_DEPS = Makefile srs_research_public.h
# public depends, the Makefile or public headers.
SRS_RESEARCH_DEPS = Makefile
# for x86/x64 platform
ifeq ($(GCC), gcc)
... ...
... ... @@ -33,7 +33,6 @@ gcc srs_flv_injecter.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_flv_i
#include <fcntl.h>
#include "../../objs/include/srs_librtmp.h"
#include "srs_research_public.h"
#define ERROR_INJECTED 10000
... ... @@ -73,12 +72,12 @@ int main(int argc, char** argv)
tmp_file = (char*)malloc(tmp_file_size);
snprintf(tmp_file, tmp_file_size, "%s.tmp", out_flv_file);
trace("inject flv file keyframes to metadata.");
trace("srs(simple-rtmp-server) client librtmp library.");
trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
trace("input: %s", in_flv_file);
trace("output: %s", out_flv_file);
trace("tmp_file: %s", tmp_file);
srs_trace("inject flv file keyframes to metadata.");
srs_trace("srs(simple-rtmp-server) client librtmp library.");
srs_trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
srs_trace("input: %s", in_flv_file);
srs_trace("output: %s", out_flv_file);
srs_trace("tmp_file: %s", tmp_file);
ret = process(in_flv_file, tmp_file, &ic, &oc);
... ... @@ -89,13 +88,13 @@ int main(int argc, char** argv)
unlink(tmp_file);
if (ret == ERROR_INJECTED) {
ret = 0;
trace("file already injected.");
srs_trace("file already injected.");
} else {
trace("error, remove tmp file.");
srs_trace("error, remove tmp file.");
}
} else {
rename(tmp_file, out_flv_file);
trace("completed, rename to %s", out_flv_file);
srs_trace("completed, rename to %s", out_flv_file);
}
free(tmp_file);
... ... @@ -123,14 +122,14 @@ int process(const char* in_flv_file, const char* out_flv_file, srs_flv_t* pic, s
if ((ic = srs_flv_open_read(in_flv_file)) == NULL) {
ret = 2;
trace("open input flv file failed. ret=%d", ret);
srs_trace("open input flv file failed. ret=%d", ret);
return ret;
}
*pic = ic;
if ((oc = srs_flv_open_write(out_flv_file)) == NULL) {
ret = 2;
trace("open output flv file failed. ret=%d", ret);
srs_trace("open output flv file failed. ret=%d", ret);
return ret;
}
*poc = oc;
... ... @@ -164,13 +163,13 @@ int parse_metadata(char* data, int size, srs_amf0_t* pname, srs_amf0_t* pdata)
*pname = srs_amf0_parse(data, size, &nparsed);
if (*pname == NULL || nparsed >= size) {
trace("invalid amf0 name data.");
srs_trace("invalid amf0 name data.");
return -1;
}
*pdata = srs_amf0_parse(data + nparsed, size - nparsed, &nparsed);
if (*pdata == NULL || nparsed > size) {
trace("invalid amf0 value data");
srs_trace("invalid amf0 value data");
return -1;
}
... ... @@ -206,22 +205,22 @@ int build_keyframes(srs_flv_t ic, srs_amf0_t *pname, srs_amf0_t* pdata, srs_amf0
return ret;
}
trace("build keyframe infos from flv");
srs_trace("build keyframe infos from flv");
for (;;) {
offset = srs_flv_tellg(ic);
// tag header
if ((ret = srs_flv_read_tag_header(ic, &type, &size, &timestamp)) != 0) {
if (srs_flv_is_eof(ret)) {
trace("parse completed.");
srs_trace("parse completed.");
return 0;
}
trace("flv get packet failed. ret=%d", ret);
srs_trace("flv get packet failed. ret=%d", ret);
return ret;
}
if (size <= 0) {
trace("invalid size=%d", size);
srs_trace("invalid size=%d", size);
return ret;
}
... ... @@ -343,20 +342,20 @@ int do_inject_flv(srs_flv_t ic, srs_flv_t oc, srs_amf0_t amf0_name, srs_amf0_t a
free(data);
}
trace("build keyframe infos from flv");
srs_trace("build keyframe infos from flv");
for (;;) {
// tag header
if ((ret = srs_flv_read_tag_header(ic, &type, &size, &timestamp)) != 0) {
if (srs_flv_is_eof(ret)) {
trace("parse completed.");
srs_trace("parse completed.");
return 0;
}
trace("flv get packet failed. ret=%d", ret);
srs_trace("flv get packet failed. ret=%d", ret);
return ret;
}
if (size <= 0) {
trace("invalid size=%d", size);
srs_trace("invalid size=%d", size);
break;
}
... ...
... ... @@ -25,6 +25,7 @@ gcc srs_ingest_flv.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_ingest_
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
... ... @@ -33,7 +34,6 @@ gcc srs_ingest_flv.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_ingest_
#include <fcntl.h>
#include "../../objs/include/srs_librtmp.h"
#include "srs_research_public.h"
int parse_flv(srs_flv_t flv);
int main(int argc, char** argv)
... ... @@ -59,14 +59,14 @@ int main(int argc, char** argv)
in_flv_file = argv[1];
trace("parse and show flv file detail.");
trace("srs(simple-rtmp-server) client librtmp library.");
trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
trace("input: %s", in_flv_file);
srs_trace("parse and show flv file detail.");
srs_trace("srs(simple-rtmp-server) client librtmp library.");
srs_trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
srs_trace("input: %s", in_flv_file);
if ((flv = srs_flv_open_read(in_flv_file)) == NULL) {
ret = 2;
trace("open flv file failed. ret=%d", ret);
srs_trace("open flv file failed. ret=%d", ret);
return ret;
}
... ... @@ -148,12 +148,12 @@ int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset)
// amf0
amf0_name = srs_amf0_parse(data, size, &nparsed);
if (amf0_name == NULL || nparsed >= size) {
trace("invalid amf0 name data.");
srs_trace("invalid amf0 name data.");
return -1;
}
amf0_data = srs_amf0_parse(data + nparsed, size - nparsed, &nparsed);
trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
srs_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
"offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n%s%s",
srs_type2string(SRS_RTMP_TYPE_SCRIPT), timestamp, size + FLV_HEADER_SIZE, size,
(int)offset, hbuf, tbuf,
... ... @@ -179,7 +179,7 @@ int parse_audio_data(u_int32_t timestamp, char* data, int size, int64_t offset)
// bytes
parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16);
trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
srs_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
"offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n",
srs_type2string(SRS_RTMP_TYPE_AUDIO), timestamp, size + FLV_HEADER_SIZE, size,
(int)offset, hbuf, tbuf);
... ... @@ -197,7 +197,7 @@ int parse_video_data(u_int32_t timestamp, char* data, int size, int64_t offset)
// bytes
parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16);
trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
srs_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
"offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n",
srs_type2string(SRS_RTMP_TYPE_VIDEO), timestamp, size + FLV_HEADER_SIZE, size,
(int)offset, hbuf, tbuf);
... ... @@ -222,22 +222,22 @@ int parse_flv(srs_flv_t flv)
return ret;
}
trace("start parse flv");
srs_trace("start parse flv");
for (;;) {
offset = srs_flv_tellg(flv);
// tag header
if ((ret = srs_flv_read_tag_header(flv, &type, &size, &timestamp)) != 0) {
if (srs_flv_is_eof(ret)) {
trace("parse completed.");
srs_trace("parse completed.");
return 0;
}
trace("flv get packet failed. ret=%d", ret);
srs_trace("flv get packet failed. ret=%d", ret);
return ret;
}
if (size <= 0) {
trace("invalid size=%d", size);
srs_trace("invalid size=%d", size);
break;
}
... ...
... ... @@ -35,8 +35,6 @@ gcc srs_h264_raw_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_h
#include "../../objs/include/srs_librtmp.h"
#define srs_trace(msg, ...) printf(msg, ##__VA_ARGS__);printf("\n")
int read_h264_frame(char* data, int size, char** pp, int* pnb_start_code, int fps,
char** frame, int* frame_size, int* dts, int* pts)
{
... ... @@ -80,18 +78,18 @@ int read_h264_frame(char* data, int size, char** pp, int* pnb_start_code, int fp
int main(int argc, char** argv)
{
srs_trace("publish raw h.264 as rtmp stream to server like FMLE/FFMPEG/Encoder");
srs_trace("srs(simple-rtmp-server) client librtmp library.");
srs_trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
printf("publish raw h.264 as rtmp stream to server like FMLE/FFMPEG/Encoder\n");
printf("SRS(simple-rtmp-server) client librtmp library.\n");
printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
if (argc <= 2) {
srs_trace("Usage: %s <h264_raw_file> <rtmp_publish_url>", argv[0]);
srs_trace(" h264_raw_file: the h264 raw steam file.");
srs_trace(" rtmp_publish_url: the rtmp publish url.");
srs_trace("For example:");
srs_trace(" %s ./720p.h264.raw rtmp://127.0.0.1:1935/live/livestream", argv[0]);
srs_trace("Where the file: http://winlinvip.github.io/srs.release/3rdparty/720p.h264.raw");
srs_trace("See: https://github.com/winlinvip/simple-rtmp-server/issues/66");
printf("Usage: %s <h264_raw_file> <rtmp_publish_url>\n", argv[0]);
printf(" h264_raw_file: the h264 raw steam file.\n");
printf(" rtmp_publish_url: the rtmp publish url.\n");
printf("For example:\n");
printf(" %s ./720p.h264.raw rtmp://127.0.0.1:1935/live/livestream\n", argv[0]);
printf("Where the file: http://winlinvip.github.io/srs.release/3rdparty/720p.h264.raw\n");
printf("See: https://github.com/winlinvip/simple-rtmp-server/issues/66\n");
exit(-1);
}
... ...
... ... @@ -33,7 +33,6 @@ gcc srs_ingest_flv.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_ingest_
#include <fcntl.h>
#include "../../objs/include/srs_librtmp.h"
#include "srs_research_public.h"
int proxy(srs_flv_t flv, srs_rtmp_t ortmp);
int connect_oc(srs_rtmp_t ortmp);
... ... @@ -87,22 +86,22 @@ int main(int argc, char** argv)
}
}
trace("ingest flv file and publish to RTMP server like FFMPEG.");
trace("srs(simple-rtmp-server) client librtmp library.");
trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
trace("input: %s", in_flv_file);
trace("output: %s", out_rtmp_url);
srs_trace("ingest flv file and publish to RTMP server like FFMPEG.");
srs_trace("srs(simple-rtmp-server) client librtmp library.");
srs_trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
srs_trace("input: %s", in_flv_file);
srs_trace("output: %s", out_rtmp_url);
if ((flv = srs_flv_open_read(in_flv_file)) == NULL) {
ret = 2;
trace("open flv file failed. ret=%d", ret);
srs_trace("open flv file failed. ret=%d", ret);
return ret;
}
ortmp = srs_rtmp_create(out_rtmp_url);
ret = proxy(flv, ortmp);
trace("ingest flv to RTMP completed");
srs_trace("ingest flv to RTMP completed");
srs_rtmp_destroy(ortmp);
srs_flv_close(flv);
... ... @@ -119,20 +118,20 @@ int do_proxy(srs_flv_t flv, srs_rtmp_t ortmp, int64_t re, u_int32_t* ptimestamp)
int size;
char* data = NULL;
trace("start ingest flv to RTMP stream");
srs_trace("start ingest flv to RTMP stream");
for (;;) {
// tag header
if ((ret = srs_flv_read_tag_header(flv, &type, &size, ptimestamp)) != 0) {
if (srs_flv_is_eof(ret)) {
trace("parse completed.");
srs_trace("parse completed.");
return 0;
}
trace("flv get packet failed. ret=%d", ret);
srs_trace("flv get packet failed. ret=%d", ret);
return ret;
}
if (size <= 0) {
trace("invalid size=%d", size);
srs_trace("invalid size=%d", size);
break;
}
... ... @@ -143,10 +142,10 @@ int do_proxy(srs_flv_t flv, srs_rtmp_t ortmp, int64_t re, u_int32_t* ptimestamp)
}
if ((ret = srs_write_packet(ortmp, type, *ptimestamp, data, size)) != 0) {
trace("irtmp get packet failed. ret=%d", ret);
srs_trace("irtmp get packet failed. ret=%d", ret);
return ret;
}
verbose("ortmp sent packet: type=%s, time=%d, size=%d",
srs_verbose("ortmp sent packet: type=%s, time=%d, size=%d",
srs_type2string(type), *ptimestamp, size);
re_update(re, *ptimestamp);
... ... @@ -183,22 +182,22 @@ int connect_oc(srs_rtmp_t ortmp)
int ret = 0;
if ((ret = srs_simple_handshake(ortmp)) != 0) {
trace("ortmp simple handshake failed. ret=%d", ret);
srs_trace("ortmp simple handshake failed. ret=%d", ret);
return ret;
}
trace("ortmp simple handshake success");
srs_trace("ortmp simple handshake success");
if ((ret = srs_connect_app(ortmp)) != 0) {
trace("ortmp connect vhost/app failed. ret=%d", ret);
srs_trace("ortmp connect vhost/app failed. ret=%d", ret);
return ret;
}
trace("ortmp connect vhost/app success");
srs_trace("ortmp connect vhost/app success");
if ((ret = srs_publish_stream(ortmp)) != 0) {
trace("ortmp publish stream failed. ret=%d", ret);
srs_trace("ortmp publish stream failed. ret=%d", ret);
return ret;
}
trace("ortmp publish stream success");
srs_trace("ortmp publish stream success");
return ret;
}
... ... @@ -210,16 +209,16 @@ int64_t re_create()
// use the starttime to get the deviation
int64_t deviation = re - tools_main_entrance_startup_time;
trace("deviation is %d ms, pulse is %d ms", (int)(deviation), (int)(RE_PULSE_MS));
srs_trace("deviation is %d ms, pulse is %d ms", (int)(deviation), (int)(RE_PULSE_MS));
// so, we adjust time to max(0, deviation)
// because the last pulse, we already sleeped
int adjust = (int)(deviation);
if (adjust > 0) {
trace("adjust re time for %d ms", adjust);
srs_trace("adjust re time for %d ms", adjust);
re -= adjust;
} else {
trace("no need to adjust re time");
srs_trace("no need to adjust re time");
}
return re;
... ... @@ -240,7 +239,7 @@ void re_cleanup(int64_t re, u_int32_t time)
int64_t now = srs_get_time_ms();
int64_t diff = time - (now -re);
if (diff > 0) {
trace("re_cleanup sleep for the last pulse for %d ms", (int)diff);
srs_trace("re_cleanup sleep for the last pulse for %d ms", (int)diff);
usleep(diff * 1000);
}
}
... ...
... ... @@ -29,7 +29,6 @@ gcc srs_ingest_rtmp.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_ingest
#include <unistd.h>
#include "../../objs/include/srs_librtmp.h"
#include "srs_research_public.h"
int connect_ic(srs_rtmp_t irtmp);
int connect_oc(srs_rtmp_t ortmp);
... ... @@ -73,17 +72,17 @@ int main(int argc, char** argv)
}
}
trace("ingest RTMP and publish to RTMP server like edge.");
trace("srs(simple-rtmp-server) client librtmp library.");
trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
trace("input: %s", in_rtmp_url);
trace("output: %s", out_rtmp_url);
srs_trace("ingest RTMP and publish to RTMP server like edge.");
srs_trace("srs(simple-rtmp-server) client librtmp library.");
srs_trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision());
srs_trace("input: %s", in_rtmp_url);
srs_trace("output: %s", out_rtmp_url);
irtmp = srs_rtmp_create(in_rtmp_url);
ortmp = srs_rtmp_create(out_rtmp_url);
ret = proxy(irtmp, ortmp);
trace("proxy completed");
srs_trace("proxy completed");
srs_rtmp_destroy(irtmp);
srs_rtmp_destroy(ortmp);
... ... @@ -107,20 +106,20 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp)
return ret;
}
trace("start proxy RTMP stream");
srs_trace("start proxy RTMP stream");
for (;;) {
if ((ret = srs_read_packet(irtmp, &type, &timestamp, &data, &size)) != 0) {
trace("irtmp get packet failed. ret=%d", ret);
srs_trace("irtmp get packet failed. ret=%d", ret);
return ret;
}
verbose("irtmp got packet: type=%s, time=%d, size=%d",
srs_verbose("irtmp got packet: type=%s, time=%d, size=%d",
srs_type2string(type), timestamp, size);
if ((ret = srs_write_packet(ortmp, type, timestamp, data, size)) != 0) {
trace("irtmp get packet failed. ret=%d", ret);
srs_trace("irtmp get packet failed. ret=%d", ret);
return ret;
}
verbose("ortmp sent packet: type=%s, time=%d, size=%d",
srs_verbose("ortmp sent packet: type=%s, time=%d, size=%d",
srs_type2string(type), timestamp, size);
}
... ... @@ -132,22 +131,22 @@ int connect_ic(srs_rtmp_t irtmp)
int ret = 0;
if ((ret = srs_simple_handshake(irtmp)) != 0) {
trace("irtmp simple handshake failed. ret=%d", ret);
srs_trace("irtmp simple handshake failed. ret=%d", ret);
return ret;
}
trace("irtmp simple handshake success");
srs_trace("irtmp simple handshake success");
if ((ret = srs_connect_app(irtmp)) != 0) {
trace("irtmp connect vhost/app failed. ret=%d", ret);
srs_trace("irtmp connect vhost/app failed. ret=%d", ret);
return ret;
}
trace("irtmp connect vhost/app success");
srs_trace("irtmp connect vhost/app success");
if ((ret = srs_play_stream(irtmp)) != 0) {
trace("irtmp play stream failed. ret=%d", ret);
srs_trace("irtmp play stream failed. ret=%d", ret);
return ret;
}
trace("irtmp play stream success");
srs_trace("irtmp play stream success");
return ret;
}
... ... @@ -157,22 +156,22 @@ int connect_oc(srs_rtmp_t ortmp)
int ret = 0;
if ((ret = srs_simple_handshake(ortmp)) != 0) {
trace("ortmp simple handshake failed. ret=%d", ret);
srs_trace("ortmp simple handshake failed. ret=%d", ret);
return ret;
}
trace("ortmp simple handshake success");
srs_trace("ortmp simple handshake success");
if ((ret = srs_connect_app(ortmp)) != 0) {
trace("ortmp connect vhost/app failed. ret=%d", ret);
srs_trace("ortmp connect vhost/app failed. ret=%d", ret);
return ret;
}
trace("ortmp connect vhost/app success");
srs_trace("ortmp connect vhost/app success");
if ((ret = srs_publish_stream(ortmp)) != 0) {
trace("ortmp publish stream failed. ret=%d", ret);
srs_trace("ortmp publish stream failed. ret=%d", ret);
return ret;
}
trace("ortmp publish stream success");
srs_trace("ortmp publish stream success");
return ret;
}
... ...
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_RESEARH_PUBLIC_HPP
#define SRS_RESEARH_PUBLIC_HPP
/*
#include "srs_research_public.h"
*/
#include <string.h>
#include <time.h>
char* format_time()
{
struct timeval tv;
static char buf[23];
memset(buf, 0, sizeof(buf));
// clock time
if (gettimeofday(&tv, NULL) == -1) {
return buf;
}
// to calendar time
struct tm* tm;
if ((tm = localtime(&tv.tv_sec)) == NULL) {
return buf;
}
snprintf(buf, sizeof(buf),
"%d-%02d-%02d %02d:%02d:%02d.%03d",
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec,
(int)(tv.tv_usec / 1000));
return buf;
}
#define trace(msg, ...) printf("[%s]", format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define verbose(msg, ...) printf("[%s]", format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#if 1
#undef verbose
#define verbose(msg, ...) (void)0
#endif
#endif
... ... @@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_librtmp.hpp>
#include <stdlib.h>
#include <sys/time.h>
#include <string>
#include <sstream>
... ... @@ -32,7 +33,6 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_protocol_rtmp.hpp>
#include <srs_lib_simple_socket.hpp>
#include <srs_kernel_log.hpp>
#include <srs_protocol_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_protocol_stack.hpp>
... ... @@ -531,6 +531,33 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp)
return context->rtmp->get_recv_bytes();
}
const char* srs_format_time()
{
struct timeval tv;
static char buf[23];
memset(buf, 0, sizeof(buf));
// clock time
if (gettimeofday(&tv, NULL) == -1) {
return buf;
}
// to calendar time
struct tm* tm;
if ((tm = localtime(&tv.tv_sec)) == NULL) {
return buf;
}
snprintf(buf, sizeof(buf),
"%d-%02d-%02d %02d:%02d:%02d.%03d",
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec,
(int)(tv.tv_usec / 1000));
return buf;
}
struct FlvContext
{
SrsFileReader reader;
... ...
... ... @@ -209,6 +209,8 @@ extern const char* srs_type2string(int type);
*
* @remark: for read, user must free the data.
* @remark: for write, user should never free the data, even if error.
* @example /trunk/research/librtmp/srs_play.c
* @example /trunk/research/librtmp/srs_publish.c
*
* @return 0, success; otherswise, failed.
*/
... ... @@ -232,11 +234,22 @@ extern int srs_version_revision();
extern int64_t srs_get_time_ms();
extern int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp);
extern int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp);
// log to console.
extern const char* srs_format_time();
#ifndef srs_trace
#define srs_trace(msg, ...) printf("[%s]", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#endif
#ifndef srs_verbose
#define srs_verbose(msg, ...) printf("[%s]", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#endif
/*************************************************************
**************************************************************
* flv codec
* @example /trunk/research/librtmp/srs_flv_injecter.c
* @example /trunk/research/librtmp/srs_flv_parser.c
* @example /trunk/research/librtmp/srs_ingest_flv.c
* @example /trunk/research/librtmp/srs_ingest_rtmp.c
**************************************************************
*************************************************************/
typedef void* srs_flv_t;
... ... @@ -276,6 +289,8 @@ extern flv_bool srs_flv_is_keyframe(char* data, int32_t size);
/*************************************************************
**************************************************************
* amf0 codec
* @example /trunk/research/librtmp/srs_ingest_flv.c
* @example /trunk/research/librtmp/srs_ingest_rtmp.c
**************************************************************
*************************************************************/
/* the output handler. */
... ... @@ -351,6 +366,8 @@ extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize);
* @remark, user should free the frames.
* @remark, the tbn of dts/pts is 1/1000 for RTMP, that is, in ms.
* @remark, cts = pts - dts
* @remark, use srs_h264_startswith_annexb to check whether frame is annexb format.
* @example /trunk/research/librtmp/srs_h264_raw_publish.c
*
* @return 0, success; otherswise, failed.
*/
... ... @@ -394,6 +411,9 @@ extern int srs_write_h264_raw_frames(srs_rtmp_t rtmp,
* @param pnb_start_code output the size of start code, must >=3.
* NULL to ignore.
*
* @reamrk used to check whether current frame is in annexb format.
* @example /trunk/research/librtmp/srs_h264_raw_publish.c
*
* @return 0 false; otherwise, true.
*/
extern int srs_h264_startswith_annexb(
... ...
... ... @@ -137,7 +137,6 @@ file
..\..\research\librtmp\srs_ingest_rtmp.c,
..\..\research\librtmp\srs_play.c,
..\..\research\librtmp\srs_publish.c,
..\..\research\librtmp\srs_research_public.h,
..\..\research\hls\ts_info.cc;
mainconfig
... ...