mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
UniquePtr: Support SrsUniquePtr to replace SrsAutoFree. v6.0.136 (#4109)
To manage an object: ```cpp // Before MyClass* ptr = new MyClass(); SrsAutoFree(MyClass, ptr); ptr->do_something(); // Now SrsUniquePtr<MyClass> ptr(new MyClass()); ptr->do_something(); ``` To manage an array of objects: ```cpp // Before char* ptr = new char[10]; SrsAutoFreeA(char, ptr); ptr[0] = 0xf; // Now SrsUniquePtr<char[]> ptr(new char[10]); ptr[0] = 0xf; ``` In fact, SrsUniquePtr is a limited subset of SrsAutoFree, mainly managing pointers and arrays. SrsUniquePtr is better than SrsAutoFree because it has the same API to standard unique ptr. ```cpp SrsUniquePtr<MyClass> ptr(new MyClass()); ptr->do_something(); MyClass* p = ptr.get(); ``` SrsAutoFree actually uses a pointer to a pointer, so it can be set to NULL, allowing the pointer's value to be changed later (this usage is different from SrsUniquePtr). ```cpp // OK to free ptr correctly. MyClass* ptr; SrsAutoFree(MyClass, ptr); ptr = new MyClass(); // Crash because ptr is an invalid pointer. MyClass* ptr; SrsUniquePtr<MyClass> ptr(ptr); ptr = new MyClass(); ``` Additionally, SrsAutoFreeH can use specific release functions, which SrsUniquePtr does not support. --------- Co-authored-by: Jacob Su <suzp1984@gmail.com>
This commit is contained in:
parent
baf22d01c1
commit
23d2602c34
72 changed files with 1720 additions and 1669 deletions
1
trunk/3rdparty/st-srs/README.md
vendored
1
trunk/3rdparty/st-srs/README.md
vendored
|
@ -119,6 +119,7 @@ The branch [srs](https://github.com/ossrs/state-threads/tree/srs) was patched an
|
||||||
- [x] Check capability for backtrack.
|
- [x] Check capability for backtrack.
|
||||||
- [x] Support set specifics for any thread.
|
- [x] Support set specifics for any thread.
|
||||||
- [x] Support st_destroy to free resources for asan.
|
- [x] Support st_destroy to free resources for asan.
|
||||||
|
- [x] Support free the stack, [#38](https://github.com/ossrs/state-threads/issues/38).
|
||||||
- [ ] System: Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12).
|
- [ ] System: Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12).
|
||||||
|
|
||||||
## GDB Tools
|
## GDB Tools
|
||||||
|
|
6
trunk/3rdparty/st-srs/stk.c
vendored
6
trunk/3rdparty/st-srs/stk.c
vendored
|
@ -65,6 +65,7 @@ _st_stack_t *_st_stack_new(int stack_size)
|
||||||
_st_stack_t *ts;
|
_st_stack_t *ts;
|
||||||
int extra;
|
int extra;
|
||||||
|
|
||||||
|
/* If cache stack, we try to use stack from the cache list. */
|
||||||
#ifdef MD_CACHE_STACK
|
#ifdef MD_CACHE_STACK
|
||||||
for (qp = _st_free_stacks.next; qp != &_st_free_stacks; qp = qp->next) {
|
for (qp = _st_free_stacks.next; qp != &_st_free_stacks; qp = qp->next) {
|
||||||
ts = _ST_THREAD_STACK_PTR(qp);
|
ts = _ST_THREAD_STACK_PTR(qp);
|
||||||
|
@ -80,10 +81,13 @@ _st_stack_t *_st_stack_new(int stack_size)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0;
|
extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0;
|
||||||
|
/* If not cache stack, we will free all stack in the list, which contains the stack to be freed.
|
||||||
|
* Note that we should never directly free it at _st_stack_free, because it is still be used,
|
||||||
|
* and will cause crash. */
|
||||||
#ifndef MD_CACHE_STACK
|
#ifndef MD_CACHE_STACK
|
||||||
for (qp = _st_free_stacks.next; qp != &_st_free_stacks;) {
|
for (qp = _st_free_stacks.next; qp != &_st_free_stacks;) {
|
||||||
ts = _ST_THREAD_STACK_PTR(qp);
|
ts = _ST_THREAD_STACK_PTR(qp);
|
||||||
// Before qp is freed, move to next one, because the qp will be freed when free the ts.
|
/* Before qp is freed, move to next one, because the qp will be freed when free the ts. */
|
||||||
qp = qp->next;
|
qp = qp->next;
|
||||||
|
|
||||||
ST_REMOVE_LINK(&ts->links);
|
ST_REMOVE_LINK(&ts->links);
|
||||||
|
|
2
trunk/3rdparty/st-srs/utest/st_utest.hpp
vendored
2
trunk/3rdparty/st-srs/utest/st_utest.hpp
vendored
|
@ -44,7 +44,7 @@ struct ErrorObject {
|
||||||
};
|
};
|
||||||
extern std::ostream& operator<<(std::ostream& out, const ErrorObject* err);
|
extern std::ostream& operator<<(std::ostream& out, const ErrorObject* err);
|
||||||
#define ST_ASSERT_ERROR(error, r0, message) if (error) return new ErrorObject(r0, message)
|
#define ST_ASSERT_ERROR(error, r0, message) if (error) return new ErrorObject(r0, message)
|
||||||
#define ST_COROUTINE_JOIN(trd, r0) ErrorObject* r0 = NULL; SrsAutoFree(ErrorObject, r0); if (trd) st_thread_join(trd, (void**)&r0)
|
#define ST_COROUTINE_JOIN(trd, r0) ErrorObject* r0 = NULL; if (trd) st_thread_join(trd, (void**)&r0); SrsUniquePtr<ErrorObject> r0_uptr(r0)
|
||||||
#define ST_EXPECT_SUCCESS(r0) EXPECT_TRUE(!r0) << r0
|
#define ST_EXPECT_SUCCESS(r0) EXPECT_TRUE(!r0) << r0
|
||||||
#define ST_EXPECT_FAILED(r0) EXPECT_TRUE(r0) << r0
|
#define ST_EXPECT_FAILED(r0) EXPECT_TRUE(r0) << r0
|
||||||
|
|
||||||
|
|
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -269,7 +269,7 @@ MODULE_ID="CORE"
|
||||||
MODULE_DEPENDS=()
|
MODULE_DEPENDS=()
|
||||||
ModuleLibIncs=(${SRS_OBJS})
|
ModuleLibIncs=(${SRS_OBJS})
|
||||||
MODULE_FILES=("srs_core" "srs_core_version" "srs_core_version5" "srs_core_autofree" "srs_core_performance"
|
MODULE_FILES=("srs_core" "srs_core_version" "srs_core_version5" "srs_core_autofree" "srs_core_performance"
|
||||||
"srs_core_time" "srs_core_platform")
|
"srs_core_time" "srs_core_platform" "srs_core_deprecated")
|
||||||
CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . $SRS_WORKDIR/auto/modules.sh
|
CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . $SRS_WORKDIR/auto/modules.sh
|
||||||
CORE_OBJS="${MODULE_OBJS[@]}"
|
CORE_OBJS="${MODULE_OBJS[@]}"
|
||||||
#
|
#
|
||||||
|
|
|
@ -7,6 +7,7 @@ The changelog for SRS.
|
||||||
<a name="v6-changes"></a>
|
<a name="v6-changes"></a>
|
||||||
|
|
||||||
## SRS 6.0 Changelog
|
## SRS 6.0 Changelog
|
||||||
|
* v6.0, 2024-07-09, Merge [#4109](https://github.com/ossrs/srs/pull/4109): UniquePtr: Support SrsUniquePtr to replace SrsAutoFree. v6.0.136 (#4109)
|
||||||
* v6.0, 2024-07-08, Merge [#4042](https://github.com/ossrs/srs/pull/4042): Refine config directive token parsing. v6.0.135 (#4042)
|
* v6.0, 2024-07-08, Merge [#4042](https://github.com/ossrs/srs/pull/4042): Refine config directive token parsing. v6.0.135 (#4042)
|
||||||
* v6.0, 2024-07-04, Merge [#4106](https://github.com/ossrs/srs/pull/4106): SmartPtr: Fix SRT source memory leaking. v6.0.134 (#4106)
|
* v6.0, 2024-07-04, Merge [#4106](https://github.com/ossrs/srs/pull/4106): SmartPtr: Fix SRT source memory leaking. v6.0.134 (#4106)
|
||||||
* v6.0, 2024-06-29, Merge [#4077](https://github.com/ossrs/srs/pull/4077): Fix misspelling error in app config. v6.0.133 (#4077)
|
* v6.0, 2024-06-29, Merge [#4077](https://github.com/ossrs/srs/pull/4077): Fix misspelling error in app config. v6.0.133 (#4077)
|
||||||
|
|
|
@ -27,11 +27,11 @@ ProcessorCount(JOBS)
|
||||||
# We should always configure SRS for switching between branches.
|
# We should always configure SRS for switching between branches.
|
||||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
EXECUTE_PROCESS(
|
EXECUTE_PROCESS(
|
||||||
COMMAND ./configure --osx --srt=on --gb28181=on --apm=on --h265=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
|
COMMAND ./configure --osx --srt=on --gb28181=on --apm=on --h265=on --hds=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
|
||||||
WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
|
WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
|
||||||
ELSE ()
|
ELSE ()
|
||||||
EXECUTE_PROCESS(
|
EXECUTE_PROCESS(
|
||||||
COMMAND ./configure --srt=on --gb28181=on --apm=on --h265=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
|
COMMAND ./configure --srt=on --gb28181=on --apm=on --h265=on --hds=on --utest=on --ffmpeg-opus=off --jobs=${JOBS}
|
||||||
WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
|
WORKING_DIRECTORY ${SRS_DIR} RESULT_VARIABLE ret)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
if(NOT ret EQUAL 0)
|
if(NOT ret EQUAL 0)
|
||||||
|
|
|
@ -14,18 +14,26 @@ if [[ ! -f ~/git/srs-bench/go.mod ]]; then
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d ~/git/state-threads ]]; then
|
||||||
|
echo "no state-threads at ~/git"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Copy signaling"
|
echo "Copy signaling"
|
||||||
cp -R 3rdparty/signaling/* ~/git/signaling/ &&
|
cp -R 3rdparty/signaling/* ~/git/signaling/ &&
|
||||||
cp -R 3rdparty/signaling/.gitignore ~/git/signaling/ &&
|
cp -R 3rdparty/signaling/.gitignore ~/git/signaling/ &&
|
||||||
(cd ~/git/signaling && git st)
|
(cd ~/git/signaling && git status)
|
||||||
|
|
||||||
echo "Copy httpx-static"
|
echo "Copy httpx-static"
|
||||||
cp -R 3rdparty/httpx-static/* ~/git/go-oryx/httpx-static/ &&
|
cp -R 3rdparty/httpx-static/* ~/git/go-oryx/httpx-static/ &&
|
||||||
cp -R 3rdparty/httpx-static/.gitignore ~/git/go-oryx/httpx-static/ &&
|
cp -R 3rdparty/httpx-static/.gitignore ~/git/go-oryx/httpx-static/ &&
|
||||||
(cd ~/git/go-oryx && git st)
|
(cd ~/git/go-oryx && git status)
|
||||||
|
|
||||||
echo "Copy srs-bench"
|
echo "Copy srs-bench"
|
||||||
cp -R 3rdparty/srs-bench/* ~/git/srs-bench/ &&
|
cp -R 3rdparty/srs-bench/* ~/git/srs-bench/ &&
|
||||||
cp -R 3rdparty/srs-bench/.gitignore ~/git/srs-bench/ &&
|
cp -R 3rdparty/srs-bench/.gitignore ~/git/srs-bench/ &&
|
||||||
(cd ~/git/srs-bench && git st)
|
(cd ~/git/srs-bench && git status)
|
||||||
|
|
||||||
|
echo "Copy state-threads"
|
||||||
|
cp -R 3rdparty/st-srs/* ~/git/state-threads/ &&
|
||||||
|
(cd ~/git/state-threads && git st)
|
||||||
|
|
|
@ -216,9 +216,6 @@ srs_error_t SrsDynamicHttpConn::proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage
|
||||||
output = o;
|
output = o;
|
||||||
srs_trace("flv: proxy %s:%d %s to %s", ip.c_str(), port, r->uri().c_str(), output.c_str());
|
srs_trace("flv: proxy %s:%d %s to %s", ip.c_str(), port, r->uri().c_str(), output.c_str());
|
||||||
|
|
||||||
char* buffer = new char[SRS_HTTP_FLV_STREAM_BUFFER];
|
|
||||||
SrsAutoFreeA(char, buffer);
|
|
||||||
|
|
||||||
ISrsHttpResponseReader* rr = r->body_reader();
|
ISrsHttpResponseReader* rr = r->body_reader();
|
||||||
SrsHttpFileReader reader(rr);
|
SrsHttpFileReader reader(rr);
|
||||||
SrsFlvDecoder dec;
|
SrsFlvDecoder dec;
|
||||||
|
|
|
@ -1157,13 +1157,13 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveCo
|
||||||
srs_assert(!file.empty());
|
srs_assert(!file.empty());
|
||||||
srs_trace("config parse include %s", file.c_str());
|
srs_trace("config parse include %s", file.c_str());
|
||||||
|
|
||||||
SrsConfigBuffer* include_file_buffer = NULL;
|
SrsConfigBuffer* include_file_buffer_raw = NULL;
|
||||||
SrsAutoFree(SrsConfigBuffer, include_file_buffer);
|
if ((err = conf->build_buffer(file, &include_file_buffer_raw)) != srs_success) {
|
||||||
if ((err = conf->build_buffer(file, &include_file_buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "buffer fullfill %s", file.c_str());
|
return srs_error_wrap(err, "buffer fullfill %s", file.c_str());
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsConfigBuffer> include_file_buffer(include_file_buffer_raw);
|
||||||
|
|
||||||
if ((err = parse_conf(include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
|
if ((err = parse_conf(include_file_buffer.get(), SrsDirectiveContextFile, conf)) != srs_success) {
|
||||||
return srs_error_wrap(err, "parse include buffer %s", file.c_str());
|
return srs_error_wrap(err, "parse include buffer %s", file.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1629,9 +1629,7 @@ srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsConfDirective* old_root = root;
|
SrsUniquePtr<SrsConfDirective> old_root(root);
|
||||||
SrsAutoFree(SrsConfDirective, old_root);
|
|
||||||
|
|
||||||
root = conf->root;
|
root = conf->root;
|
||||||
conf->root = NULL;
|
conf->root = NULL;
|
||||||
|
|
||||||
|
@ -1665,14 +1663,14 @@ srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge config: rtc_server
|
// Merge config: rtc_server
|
||||||
if ((err = reload_rtc_server(old_root)) != srs_success) {
|
if ((err = reload_rtc_server(old_root.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "http steram");;
|
return srs_error_wrap(err, "http steram");;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: support reload stream_caster.
|
// TODO: FIXME: support reload stream_caster.
|
||||||
|
|
||||||
// merge config: vhost
|
// merge config: vhost
|
||||||
if ((err = reload_vhost(old_root)) != srs_success) {
|
if ((err = reload_vhost(old_root.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "vhost");;
|
return srs_error_wrap(err, "vhost");;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2260,13 +2258,13 @@ srs_error_t SrsConfig::parse_file(const char* filename)
|
||||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "empty config");
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "empty config");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsConfigBuffer* buffer = NULL;
|
SrsConfigBuffer* buffer_raw = NULL;
|
||||||
SrsAutoFree(SrsConfigBuffer, buffer);
|
if ((err = build_buffer(config_file, &buffer_raw)) != srs_success) {
|
||||||
if ((err = build_buffer(config_file, &buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "buffer fullfill %s", filename);
|
return srs_error_wrap(err, "buffer fullfill %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = parse_buffer(buffer)) != srs_success) {
|
SrsUniquePtr<SrsConfigBuffer> buffer(buffer_raw);
|
||||||
|
if ((err = parse_buffer(buffer.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "parse buffer %s", filename);
|
return srs_error_wrap(err, "parse buffer %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -902,19 +902,18 @@ srs_error_t SrsSslConnection::read(void* plaintext, size_t nn_plaintext, ssize_t
|
||||||
if (r0 == -1 && r1 == SSL_ERROR_WANT_READ) {
|
if (r0 == -1 && r1 == SSL_ERROR_WANT_READ) {
|
||||||
// TODO: Can we avoid copy?
|
// TODO: Can we avoid copy?
|
||||||
int nn_cipher = nn_plaintext;
|
int nn_cipher = nn_plaintext;
|
||||||
char* cipher = new char[nn_cipher];
|
SrsUniquePtr<char[]> cipher(new char[nn_cipher]);
|
||||||
SrsAutoFreeA(char, cipher);
|
|
||||||
|
|
||||||
// Read the cipher from SSL.
|
// Read the cipher from SSL.
|
||||||
ssize_t nn = 0;
|
ssize_t nn = 0;
|
||||||
if ((err = transport->read(cipher, nn_cipher, &nn)) != srs_success) {
|
if ((err = transport->read(cipher.get(), nn_cipher, &nn)) != srs_success) {
|
||||||
return srs_error_wrap(err, "https: read");
|
return srs_error_wrap(err, "https: read");
|
||||||
}
|
}
|
||||||
|
|
||||||
int r0 = BIO_write(bio_in, cipher, nn);
|
int r0 = BIO_write(bio_in, cipher.get(), nn);
|
||||||
if (r0 <= 0) {
|
if (r0 <= 0) {
|
||||||
// TODO: 0 or -1 maybe block, use BIO_should_retry to check.
|
// TODO: 0 or -1 maybe block, use BIO_should_retry to check.
|
||||||
return srs_error_new(ERROR_HTTPS_READ, "BIO_write r0=%d, cipher=%p, size=%d", r0, cipher, nn);
|
return srs_error_new(ERROR_HTTPS_READ, "BIO_write r0=%d, cipher=%p, size=%d", r0, cipher.get(), nn);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,8 +294,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format, SrsFragmentWindow* afragments
|
||||||
ss << " </Period>" << endl;
|
ss << " </Period>" << endl;
|
||||||
ss << "</MPD>" << endl;
|
ss << "</MPD>" << endl;
|
||||||
|
|
||||||
SrsFileWriter* fw = new SrsFileWriter();
|
SrsUniquePtr<SrsFileWriter> fw(new SrsFileWriter());
|
||||||
SrsAutoFree(SrsFileWriter, fw);
|
|
||||||
|
|
||||||
string full_path_tmp = full_path + ".tmp";
|
string full_path_tmp = full_path + ".tmp";
|
||||||
if ((err = fw->open(full_path_tmp)) != srs_success) {
|
if ((err = fw->open(full_path_tmp)) != srs_success) {
|
||||||
|
@ -652,8 +651,7 @@ srs_error_t SrsDashController::refresh_init_mp4(SrsSharedPtrMessage* msg, SrsFor
|
||||||
path += "/audio-init.mp4";
|
path += "/audio-init.mp4";
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsInitMp4* init_mp4 = new SrsInitMp4();
|
SrsUniquePtr<SrsInitMp4> init_mp4(new SrsInitMp4());
|
||||||
SrsAutoFree(SrsInitMp4, init_mp4);
|
|
||||||
|
|
||||||
init_mp4->set_path(path);
|
init_mp4->set_path(path);
|
||||||
|
|
||||||
|
|
|
@ -120,18 +120,18 @@ srs_error_t SrsDvrSegmenter::write_audio(SrsSharedPtrMessage* shared_audio, SrsF
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsSharedPtrMessage* audio = shared_audio->copy();
|
// TODO: FIXME: Use SrsSharedPtr instead.
|
||||||
SrsAutoFree(SrsSharedPtrMessage, audio);
|
SrsUniquePtr<SrsSharedPtrMessage> audio(shared_audio->copy());
|
||||||
|
|
||||||
if ((err = jitter->correct(audio, jitter_algorithm)) != srs_success) {
|
if ((err = jitter->correct(audio.get(), jitter_algorithm)) != srs_success) {
|
||||||
return srs_error_wrap(err, "jitter");
|
return srs_error_wrap(err, "jitter");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = on_update_duration(audio)) != srs_success) {
|
if ((err = on_update_duration(audio.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "update duration");
|
return srs_error_wrap(err, "update duration");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = encode_audio(audio, format)) != srs_success) {
|
if ((err = encode_audio(audio.get(), format)) != srs_success) {
|
||||||
return srs_error_wrap(err, "encode audio");
|
return srs_error_wrap(err, "encode audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,18 +142,18 @@ srs_error_t SrsDvrSegmenter::write_video(SrsSharedPtrMessage* shared_video, SrsF
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsSharedPtrMessage* video = shared_video->copy();
|
// TODO: FIXME: Use SrsSharedPtr instead.
|
||||||
SrsAutoFree(SrsSharedPtrMessage, video);
|
SrsUniquePtr<SrsSharedPtrMessage> video(shared_video->copy());
|
||||||
|
|
||||||
if ((err = jitter->correct(video, jitter_algorithm)) != srs_success) {
|
if ((err = jitter->correct(video.get(), jitter_algorithm)) != srs_success) {
|
||||||
return srs_error_wrap(err, "jitter");
|
return srs_error_wrap(err, "jitter");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = encode_video(video, format)) != srs_success) {
|
if ((err = encode_video(video.get(), format)) != srs_success) {
|
||||||
return srs_error_wrap(err, "encode video");
|
return srs_error_wrap(err, "encode video");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = on_update_duration(video)) != srs_success) {
|
if ((err = on_update_duration(video.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "update duration");
|
return srs_error_wrap(err, "update duration");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,14 +256,11 @@ srs_error_t SrsDvrFlvSegmenter::refresh_metadata()
|
||||||
int64_t cur = fs->tellg();
|
int64_t cur = fs->tellg();
|
||||||
|
|
||||||
// buffer to write the size.
|
// buffer to write the size.
|
||||||
char* buf = new char[SrsAmf0Size::number()];
|
SrsUniquePtr<char[]> buf(new char[SrsAmf0Size::number()]);
|
||||||
SrsAutoFreeA(char, buf);
|
SrsBuffer stream(buf.get(), SrsAmf0Size::number());
|
||||||
|
|
||||||
SrsBuffer stream(buf, SrsAmf0Size::number());
|
|
||||||
|
|
||||||
// filesize to buf.
|
// filesize to buf.
|
||||||
SrsAmf0Any* size = SrsAmf0Any::number((double)cur);
|
SrsUniquePtr<SrsAmf0Any> size(SrsAmf0Any::number((double)cur));
|
||||||
SrsAutoFree(SrsAmf0Any, size);
|
|
||||||
|
|
||||||
stream.skip(-1 * stream.pos());
|
stream.skip(-1 * stream.pos());
|
||||||
if ((err = size->write(&stream)) != srs_success) {
|
if ((err = size->write(&stream)) != srs_success) {
|
||||||
|
@ -272,13 +269,12 @@ srs_error_t SrsDvrFlvSegmenter::refresh_metadata()
|
||||||
|
|
||||||
// update the flesize.
|
// update the flesize.
|
||||||
fs->seek2(filesize_offset);
|
fs->seek2(filesize_offset);
|
||||||
if ((err = fs->write(buf, SrsAmf0Size::number(), NULL)) != srs_success) {
|
if ((err = fs->write(buf.get(), SrsAmf0Size::number(), NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "update filesize");
|
return srs_error_wrap(err, "update filesize");
|
||||||
}
|
}
|
||||||
|
|
||||||
// duration to buf
|
// duration to buf
|
||||||
SrsAmf0Any* dur = SrsAmf0Any::number((double)srsu2ms(fragment->duration()) / 1000.0);
|
SrsUniquePtr<SrsAmf0Any> dur(SrsAmf0Any::number((double)srsu2ms(fragment->duration()) / 1000.0));
|
||||||
SrsAutoFree(SrsAmf0Any, dur);
|
|
||||||
|
|
||||||
stream.skip(-1 * stream.pos());
|
stream.skip(-1 * stream.pos());
|
||||||
if ((err = dur->write(&stream)) != srs_success) {
|
if ((err = dur->write(&stream)) != srs_success) {
|
||||||
|
@ -287,7 +283,7 @@ srs_error_t SrsDvrFlvSegmenter::refresh_metadata()
|
||||||
|
|
||||||
// update the duration
|
// update the duration
|
||||||
fs->seek2(duration_offset);
|
fs->seek2(duration_offset);
|
||||||
if ((err = fs->write(buf, SrsAmf0Size::number(), NULL)) != srs_success) {
|
if ((err = fs->write(buf.get(), SrsAmf0Size::number(), NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "update duration");
|
return srs_error_wrap(err, "update duration");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,14 +329,12 @@ srs_error_t SrsDvrFlvSegmenter::encode_metadata(SrsSharedPtrMessage* metadata)
|
||||||
|
|
||||||
SrsBuffer stream(metadata->payload, metadata->size);
|
SrsBuffer stream(metadata->payload, metadata->size);
|
||||||
|
|
||||||
SrsAmf0Any* name = SrsAmf0Any::str();
|
SrsUniquePtr<SrsAmf0Any> name(SrsAmf0Any::str());
|
||||||
SrsAutoFree(SrsAmf0Any, name);
|
|
||||||
if ((err = name->read(&stream)) != srs_success) {
|
if ((err = name->read(&stream)) != srs_success) {
|
||||||
return srs_error_wrap(err, "read name");
|
return srs_error_wrap(err, "read name");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAmf0Object* obj = SrsAmf0Any::object();
|
SrsUniquePtr<SrsAmf0Object> obj(SrsAmf0Any::object());
|
||||||
SrsAutoFree(SrsAmf0Object, obj);
|
|
||||||
if ((err = obj->read(&stream)) != srs_success) {
|
if ((err = obj->read(&stream)) != srs_success) {
|
||||||
return srs_error_wrap(err, "read object");
|
return srs_error_wrap(err, "read object");
|
||||||
}
|
}
|
||||||
|
@ -355,8 +349,7 @@ srs_error_t SrsDvrFlvSegmenter::encode_metadata(SrsSharedPtrMessage* metadata)
|
||||||
obj->set("duration", SrsAmf0Any::number(0));
|
obj->set("duration", SrsAmf0Any::number(0));
|
||||||
|
|
||||||
int size = name->total_size() + obj->total_size();
|
int size = name->total_size() + obj->total_size();
|
||||||
char* payload = new char[size];
|
SrsUniquePtr<char[]> payload(new char[size]);
|
||||||
SrsAutoFreeA(char, payload);
|
|
||||||
|
|
||||||
// 11B flv header, 3B object EOF, 8B number value, 1B number flag.
|
// 11B flv header, 3B object EOF, 8B number value, 1B number flag.
|
||||||
duration_offset = fs->tellg() + size + 11 - SrsAmf0Size::object_eof() - SrsAmf0Size::number();
|
duration_offset = fs->tellg() + size + 11 - SrsAmf0Size::object_eof() - SrsAmf0Size::number();
|
||||||
|
@ -364,7 +357,7 @@ srs_error_t SrsDvrFlvSegmenter::encode_metadata(SrsSharedPtrMessage* metadata)
|
||||||
filesize_offset = duration_offset - SrsAmf0Size::utf8("duration") - SrsAmf0Size::number();
|
filesize_offset = duration_offset - SrsAmf0Size::utf8("duration") - SrsAmf0Size::number();
|
||||||
|
|
||||||
// convert metadata to bytes.
|
// convert metadata to bytes.
|
||||||
SrsBuffer buf(payload, size);
|
SrsBuffer buf(payload.get(), size);
|
||||||
|
|
||||||
if ((err = name->write(&buf)) != srs_success) {
|
if ((err = name->write(&buf)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write name");
|
return srs_error_wrap(err, "write name");
|
||||||
|
@ -374,7 +367,7 @@ srs_error_t SrsDvrFlvSegmenter::encode_metadata(SrsSharedPtrMessage* metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
// to flv file.
|
// to flv file.
|
||||||
if ((err = enc->write_metadata(18, payload, size)) != srs_success) {
|
if ((err = enc->write_metadata(18, payload.get(), size)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write metadata");
|
return srs_error_wrap(err, "write metadata");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,8 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
|
||||||
|
|
||||||
#ifdef SRS_APM
|
#ifdef SRS_APM
|
||||||
// Create a client span and store it to an AMF0 propagator.
|
// Create a client span and store it to an AMF0 propagator.
|
||||||
ISrsApmSpan* span_client = _srs_apm->inject(_srs_apm->span("edge-pull")->set_kind(SrsApmKindClient)->as_child(_srs_apm->load()), sdk->extra_args());
|
SrsUniquePtr<ISrsApmSpan> span_client(_srs_apm->inject(_srs_apm->span("edge-pull")->set_kind(SrsApmKindClient)
|
||||||
SrsAutoFree(ISrsApmSpan, span_client);
|
->as_child(_srs_apm->load()), sdk->extra_args()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((err = sdk->connect()) != srs_success) {
|
if ((err = sdk->connect()) != srs_success) {
|
||||||
|
@ -595,8 +595,7 @@ srs_error_t SrsEdgeIngester::ingest(string& redirect)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_edge();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_edge());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
// we only use the redict once.
|
// we only use the redict once.
|
||||||
// reset the redirect to empty, for maybe the origin changed.
|
// reset the redirect to empty, for maybe the origin changed.
|
||||||
|
@ -615,15 +614,15 @@ srs_error_t SrsEdgeIngester::ingest(string& redirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read from client.
|
// read from client.
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
if ((err = upstream->recv_message(&msg)) != srs_success) {
|
if ((err = upstream->recv_message(&msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "recv message");
|
return srs_error_wrap(err, "recv message");
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(msg);
|
srs_assert(msg_raw);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
if ((err = process_publish_message(msg, redirect)) != srs_success) {
|
if ((err = process_publish_message(msg.get(), redirect)) != srs_success) {
|
||||||
return srs_error_wrap(err, "process message");
|
return srs_error_wrap(err, "process message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -659,14 +658,14 @@ srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg, stri
|
||||||
|
|
||||||
// process onMetaData
|
// process onMetaData
|
||||||
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
|
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt_raw = NULL;
|
||||||
if ((err = upstream->decode_message(msg, &pkt)) != srs_success) {
|
if ((err = upstream->decode_message(msg, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "decode message");
|
return srs_error_wrap(err, "decode message");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
if (dynamic_cast<SrsOnMetaDataPacket*>(pkt)) {
|
if (dynamic_cast<SrsOnMetaDataPacket*>(pkt.get())) {
|
||||||
SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt);
|
SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt.get());
|
||||||
if ((err = source_->on_meta_data(msg, metadata)) != srs_success) {
|
if ((err = source_->on_meta_data(msg, metadata)) != srs_success) {
|
||||||
return srs_error_wrap(err, "source consume metadata");
|
return srs_error_wrap(err, "source consume metadata");
|
||||||
}
|
}
|
||||||
|
@ -678,15 +677,15 @@ srs_error_t SrsEdgeIngester::process_publish_message(SrsCommonMessage* msg, stri
|
||||||
|
|
||||||
// call messages, for example, reject, redirect.
|
// call messages, for example, reject, redirect.
|
||||||
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
|
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt_raw = NULL;
|
||||||
if ((err = upstream->decode_message(msg, &pkt)) != srs_success) {
|
if ((err = upstream->decode_message(msg, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "decode message");
|
return srs_error_wrap(err, "decode message");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
// RTMP 302 redirect
|
// RTMP 302 redirect
|
||||||
if (dynamic_cast<SrsCallPacket*>(pkt)) {
|
if (dynamic_cast<SrsCallPacket*>(pkt.get())) {
|
||||||
SrsCallPacket* call = dynamic_cast<SrsCallPacket*>(pkt);
|
SrsCallPacket* call = dynamic_cast<SrsCallPacket*>(pkt.get());
|
||||||
if (!call->arguments->is_object()) {
|
if (!call->arguments->is_object()) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -793,8 +792,8 @@ srs_error_t SrsEdgeForwarder::start()
|
||||||
#ifdef SRS_APM
|
#ifdef SRS_APM
|
||||||
// Create a client span and store it to an AMF0 propagator.
|
// Create a client span and store it to an AMF0 propagator.
|
||||||
// Note that we are able to load the span from coroutine context because in the same coroutine.
|
// Note that we are able to load the span from coroutine context because in the same coroutine.
|
||||||
ISrsApmSpan* span_client = _srs_apm->inject(_srs_apm->span("edge-push")->set_kind(SrsApmKindClient)->as_child(_srs_apm->load()), sdk->extra_args());
|
SrsUniquePtr<ISrsApmSpan> span_client(_srs_apm->inject(_srs_apm->span("edge-push")->set_kind(SrsApmKindClient)
|
||||||
SrsAutoFree(ISrsApmSpan, span_client);
|
->as_child(_srs_apm->load()), sdk->extra_args()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((err = sdk->connect()) != srs_success) {
|
if ((err = sdk->connect()) != srs_success) {
|
||||||
|
@ -859,9 +858,7 @@ srs_error_t SrsEdgeForwarder::do_cycle()
|
||||||
|
|
||||||
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE);
|
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE);
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_edge();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_edge());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
SrsMessageArray msgs(SYS_MAX_EDGE_SEND_MSGS);
|
SrsMessageArray msgs(SYS_MAX_EDGE_SEND_MSGS);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -247,8 +247,7 @@ srs_error_t SrsForwarder::forward()
|
||||||
|
|
||||||
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE);
|
sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE);
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_forwarder();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_forwarder());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
SrsMessageArray msgs(SYS_MAX_FORWARD_SEND_MSGS);
|
SrsMessageArray msgs(SYS_MAX_FORWARD_SEND_MSGS);
|
||||||
|
|
||||||
|
|
|
@ -164,8 +164,7 @@ void SrsGbSession::on_ps_pack(SrsPackContext* ctx, SrsPsPacket* ps, const std::v
|
||||||
media_reserved_ = ctx->media_reserved_;
|
media_reserved_ = ctx->media_reserved_;
|
||||||
|
|
||||||
// Group all video in pack to a video frame, because only allows one video for each PS pack.
|
// Group all video in pack to a video frame, because only allows one video for each PS pack.
|
||||||
SrsTsMessage* video = new SrsTsMessage();
|
SrsUniquePtr<SrsTsMessage> video(new SrsTsMessage());
|
||||||
SrsAutoFree(SrsTsMessage, video);
|
|
||||||
|
|
||||||
for (vector<SrsTsMessage*>::const_iterator it = msgs.begin(); it != msgs.end(); ++it) {
|
for (vector<SrsTsMessage*>::const_iterator it = msgs.begin(); it != msgs.end(); ++it) {
|
||||||
SrsTsMessage* msg = *it;
|
SrsTsMessage* msg = *it;
|
||||||
|
@ -190,7 +189,7 @@ void SrsGbSession::on_ps_pack(SrsPackContext* ctx, SrsPsPacket* ps, const std::v
|
||||||
|
|
||||||
// Send the generated video message.
|
// Send the generated video message.
|
||||||
if (video->payload->length() > 0) {
|
if (video->payload->length() > 0) {
|
||||||
srs_error_t err = muxer_->on_ts_message(video);
|
srs_error_t err = muxer_->on_ts_message(video.get());
|
||||||
if (err != srs_success) {
|
if (err != srs_success) {
|
||||||
srs_warn("Muxer: Ignore video err %s", srs_error_desc(err).c_str());
|
srs_warn("Muxer: Ignore video err %s", srs_error_desc(err).c_str());
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
|
@ -1051,8 +1050,7 @@ srs_error_t SrsGbSipTcpReceiver::do_cycle()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsHttpParser* parser = new SrsHttpParser();
|
SrsUniquePtr<SrsHttpParser> parser(new SrsHttpParser());
|
||||||
SrsAutoFree(SrsHttpParser, parser);
|
|
||||||
|
|
||||||
// We might get SIP request or response message.
|
// We might get SIP request or response message.
|
||||||
if ((err = parser->initialize(HTTP_BOTH)) != srs_success) {
|
if ((err = parser->initialize(HTTP_BOTH)) != srs_success) {
|
||||||
|
@ -1065,14 +1063,14 @@ srs_error_t SrsGbSipTcpReceiver::do_cycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use HTTP parser to parse SIP messages.
|
// Use HTTP parser to parse SIP messages.
|
||||||
ISrsHttpMessage* hmsg = NULL;
|
ISrsHttpMessage* hmsg_raw = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, hmsg);
|
if ((err = parser->parse_message(conn_, &hmsg_raw)) != srs_success) {
|
||||||
if ((err = parser->parse_message(conn_, &hmsg)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "parse message");
|
return srs_error_wrap(err, "parse message");
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> hmsg(hmsg_raw);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
if ((err = smsg.parse(hmsg)) != srs_success) {
|
if ((err = smsg.parse(hmsg.get())) != srs_success) {
|
||||||
srs_warn("SIP: Drop msg type=%d, method=%d, err is %s", hmsg->message_type(), hmsg->method(), srs_error_summary(err).c_str());
|
srs_warn("SIP: Drop msg type=%d, method=%d, err is %s", hmsg->message_type(), hmsg->method(), srs_error_summary(err).c_str());
|
||||||
srs_freep(err); continue;
|
srs_freep(err); continue;
|
||||||
}
|
}
|
||||||
|
@ -1156,9 +1154,8 @@ srs_error_t SrsGbSipTcpSender::do_cycle()
|
||||||
return srs_error_wrap(err, "pull");
|
return srs_error_wrap(err, "pull");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSipMessage* msg = msgs_.front();
|
SrsUniquePtr<SrsSipMessage> msg(msgs_.front());
|
||||||
msgs_.erase(msgs_.begin());
|
msgs_.erase(msgs_.begin());
|
||||||
SrsAutoFree(SrsSipMessage, msg);
|
|
||||||
|
|
||||||
if (msg->type_ == HTTP_RESPONSE) {
|
if (msg->type_ == HTTP_RESPONSE) {
|
||||||
SrsSipResponseWriter res(conn_);
|
SrsSipResponseWriter res(conn_);
|
||||||
|
|
|
@ -44,8 +44,7 @@ string serialFlv(SrsSharedPtrMessage *msg)
|
||||||
int size = 15 + msg->size;
|
int size = 15 + msg->size;
|
||||||
char *byte = new char[size];
|
char *byte = new char[size];
|
||||||
|
|
||||||
SrsBuffer *stream = new SrsBuffer(byte, size);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(byte, size));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// tag header
|
// tag header
|
||||||
long long dts = msg->timestamp;
|
long long dts = msg->timestamp;
|
||||||
|
@ -450,8 +449,7 @@ srs_error_t SrsHds::flush_bootstrap()
|
||||||
|
|
||||||
int size = 1024*100;
|
int size = 1024*100;
|
||||||
|
|
||||||
char *start_abst = new char[1024*100];
|
SrsUniquePtr<char[]> start_abst(new char[1024*100]);
|
||||||
SrsAutoFreeA(char, start_abst);
|
|
||||||
|
|
||||||
int size_abst = 0;
|
int size_abst = 0;
|
||||||
char *start_asrt = NULL;
|
char *start_asrt = NULL;
|
||||||
|
@ -459,7 +457,7 @@ srs_error_t SrsHds::flush_bootstrap()
|
||||||
char *start_afrt = NULL;
|
char *start_afrt = NULL;
|
||||||
int size_afrt = 0;
|
int size_afrt = 0;
|
||||||
|
|
||||||
SrsBuffer abst(start_abst, size);
|
SrsBuffer abst(start_abst.get(), size);
|
||||||
|
|
||||||
// @see video_file_format_spec_v10_1
|
// @see video_file_format_spec_v10_1
|
||||||
// page: 46
|
// page: 46
|
||||||
|
@ -554,7 +552,7 @@ srs_error_t SrsHds::flush_bootstrap()
|
||||||
abst.write_1bytes(1);
|
abst.write_1bytes(1);
|
||||||
size_abst += 1;
|
size_abst += 1;
|
||||||
|
|
||||||
start_asrt = start_abst + size_abst;
|
start_asrt = start_abst.get() + size_abst;
|
||||||
|
|
||||||
// follows by asrt
|
// follows by asrt
|
||||||
abst.write_4bytes(0);
|
abst.write_4bytes(0);
|
||||||
|
@ -622,7 +620,7 @@ srs_error_t SrsHds::flush_bootstrap()
|
||||||
size_abst += 1;
|
size_abst += 1;
|
||||||
|
|
||||||
// follows by afrt
|
// follows by afrt
|
||||||
start_afrt = start_abst + size_abst;
|
start_afrt = start_abst.get() + size_abst;
|
||||||
|
|
||||||
abst.write_4bytes(0);
|
abst.write_4bytes(0);
|
||||||
abst.write_string("afrt");
|
abst.write_string("afrt");
|
||||||
|
@ -672,7 +670,7 @@ srs_error_t SrsHds::flush_bootstrap()
|
||||||
|
|
||||||
update_box(start_afrt, size_afrt);
|
update_box(start_afrt, size_afrt);
|
||||||
size_abst += size_afrt;
|
size_abst += size_afrt;
|
||||||
update_box(start_abst, size_abst);
|
update_box(start_abst.get(), size_abst);
|
||||||
|
|
||||||
string path = _srs_config->get_hds_path(hds_req->vhost) + "/" + hds_req->app + "/" + hds_req->stream +".abst";
|
string path = _srs_config->get_hds_path(hds_req->vhost) + "/" + hds_req->app + "/" + hds_req->stream +".abst";
|
||||||
|
|
||||||
|
@ -681,7 +679,7 @@ srs_error_t SrsHds::flush_bootstrap()
|
||||||
return srs_error_new(ERROR_HDS_OPEN_BOOTSTRAP_FAILED, "open bootstrap file failed, path=%s", path.c_str());
|
return srs_error_new(ERROR_HDS_OPEN_BOOTSTRAP_FAILED, "open bootstrap file failed, path=%s", path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(fd, start_abst, size_abst) != size_abst) {
|
if (write(fd, start_abst.get(), size_abst) != size_abst) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return srs_error_new(ERROR_HDS_WRITE_BOOTSTRAP_FAILED, "write bootstrap file failed, path=", path.c_str());
|
return srs_error_new(ERROR_HDS_WRITE_BOOTSTRAP_FAILED, "write bootstrap file failed, path=", path.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,7 @@ srs_error_t SrsHttpHeartbeat::do_heartbeat()
|
||||||
ip = ips[_srs_config->get_stats_network() % (int)ips.size()];
|
ip = ips[_srs_config->get_stats_network() % (int)ips.size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("device_id", SrsJsonAny::str(device_id.c_str()));
|
obj->set("device_id", SrsJsonAny::str(device_id.c_str()));
|
||||||
obj->set("ip", SrsJsonAny::str(ip->ip.c_str()));
|
obj->set("ip", SrsJsonAny::str(ip->ip.c_str()));
|
||||||
|
@ -75,11 +74,12 @@ srs_error_t SrsHttpHeartbeat::do_heartbeat()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string req = obj->dumps();
|
std::string req = obj->dumps();
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = http.post(uri.get_path(), req, &msg)) != srs_success) {
|
if ((err = http.post(uri.get_path(), req, &msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "http post hartbeart uri failed. url=%s, request=%s", url.c_str(), req.c_str());
|
return srs_error_wrap(err, "http post hartbeart uri failed. url=%s, request=%s", url.c_str(), req.c_str());
|
||||||
}
|
}
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
std::string res;
|
std::string res;
|
||||||
if ((err = msg->body_read_all(res)) != srs_success) {
|
if ((err = msg->body_read_all(res)) != srs_success) {
|
||||||
|
|
|
@ -1374,8 +1374,7 @@ srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma
|
||||||
// update the hls time, for hls_dispose.
|
// update the hls time, for hls_dispose.
|
||||||
last_update_time = srs_get_system_time();
|
last_update_time = srs_get_system_time();
|
||||||
|
|
||||||
SrsSharedPtrMessage* audio = shared_audio->copy();
|
SrsUniquePtr<SrsSharedPtrMessage> audio(shared_audio->copy());
|
||||||
SrsAutoFree(SrsSharedPtrMessage, audio);
|
|
||||||
|
|
||||||
// ts support audio codec: aac/mp3
|
// ts support audio codec: aac/mp3
|
||||||
SrsAudioCodecId acodec = format->acodec->id;
|
SrsAudioCodecId acodec = format->acodec->id;
|
||||||
|
@ -1390,7 +1389,7 @@ srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: config the jitter of HLS.
|
// TODO: FIXME: config the jitter of HLS.
|
||||||
if ((err = jitter->correct(audio, SrsRtmpJitterAlgorithmOFF)) != srs_success) {
|
if ((err = jitter->correct(audio.get(), SrsRtmpJitterAlgorithmOFF)) != srs_success) {
|
||||||
return srs_error_wrap(err, "hls: jitter");
|
return srs_error_wrap(err, "hls: jitter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1456,8 +1455,7 @@ srs_error_t SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* forma
|
||||||
// update the hls time, for hls_dispose.
|
// update the hls time, for hls_dispose.
|
||||||
last_update_time = srs_get_system_time();
|
last_update_time = srs_get_system_time();
|
||||||
|
|
||||||
SrsSharedPtrMessage* video = shared_video->copy();
|
SrsUniquePtr<SrsSharedPtrMessage> video(shared_video->copy());
|
||||||
SrsAutoFree(SrsSharedPtrMessage, video);
|
|
||||||
|
|
||||||
// ignore info frame,
|
// ignore info frame,
|
||||||
// @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909
|
// @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909
|
||||||
|
@ -1477,7 +1475,7 @@ srs_error_t SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* forma
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: config the jitter of HLS.
|
// TODO: FIXME: config the jitter of HLS.
|
||||||
if ((err = jitter->correct(video, SrsRtmpJitterAlgorithmOFF)) != srs_success) {
|
if ((err = jitter->correct(video.get(), SrsRtmpJitterAlgorithmOFF)) != srs_success) {
|
||||||
return srs_error_wrap(err, "hls: jitter");
|
return srs_error_wrap(err, "hls: jitter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,7 @@ srs_error_t srs_api_response_jsonp(ISrsHttpResponseWriter* w, string callback, s
|
||||||
|
|
||||||
srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, int code)
|
srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, int code)
|
||||||
{
|
{
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(code));
|
obj->set("code", SrsJsonAny::integer(code));
|
||||||
|
|
||||||
|
@ -76,8 +75,7 @@ srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callba
|
||||||
|
|
||||||
srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, srs_error_t err)
|
srs_error_t srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, srs_error_t err)
|
||||||
{
|
{
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(srs_error_code(err)));
|
obj->set("code", SrsJsonAny::integer(srs_error_code(err)));
|
||||||
|
|
||||||
|
@ -104,8 +102,7 @@ srs_error_t srs_api_response_json(ISrsHttpResponseWriter* w, string data)
|
||||||
|
|
||||||
srs_error_t srs_api_response_json_code(ISrsHttpResponseWriter* w, int code)
|
srs_error_t srs_api_response_json_code(ISrsHttpResponseWriter* w, int code)
|
||||||
{
|
{
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(code));
|
obj->set("code", SrsJsonAny::integer(code));
|
||||||
|
|
||||||
|
@ -114,8 +111,7 @@ srs_error_t srs_api_response_json_code(ISrsHttpResponseWriter* w, int code)
|
||||||
|
|
||||||
srs_error_t srs_api_response_json_code(ISrsHttpResponseWriter* w, srs_error_t code)
|
srs_error_t srs_api_response_json_code(ISrsHttpResponseWriter* w, srs_error_t code)
|
||||||
{
|
{
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(srs_error_code(code)));
|
obj->set("code", SrsJsonAny::integer(srs_error_code(code)));
|
||||||
|
|
||||||
|
@ -179,8 +175,7 @@ srs_error_t SrsGoApiRoot::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -219,8 +214,7 @@ srs_error_t SrsGoApiApi::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -247,8 +241,7 @@ srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -298,8 +291,7 @@ srs_error_t SrsGoApiVersion::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -329,15 +321,14 @@ srs_error_t SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||||
|
|
||||||
srs_api_dump_summaries(obj);
|
srs_api_dump_summaries(obj.get());
|
||||||
|
|
||||||
return srs_api_response(w, r, obj->dumps());
|
return srs_api_response(w, r, obj->dumps());
|
||||||
}
|
}
|
||||||
|
@ -354,8 +345,7 @@ srs_error_t SrsGoApiRusages::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -401,8 +391,7 @@ srs_error_t SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsHtt
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -480,8 +469,7 @@ srs_error_t SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsH
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -521,8 +509,7 @@ srs_error_t SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -563,8 +550,7 @@ srs_error_t SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -592,8 +578,7 @@ srs_error_t SrsGoApiFeatures::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -662,8 +647,7 @@ srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
{
|
{
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -719,8 +703,7 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
|
||||||
return srs_api_response_code(w, r, ERROR_RTMP_VHOST_NOT_FOUND);
|
return srs_api_response_code(w, r, ERROR_RTMP_VHOST_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -777,8 +760,7 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
return srs_api_response_code(w, r, ERROR_RTMP_STREAM_NOT_FOUND);
|
return srs_api_response_code(w, r, ERROR_RTMP_STREAM_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -839,8 +821,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
|
return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -918,14 +899,13 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
|
||||||
std::string rpc = r->query_get("rpc");
|
std::string rpc = r->query_get("rpc");
|
||||||
|
|
||||||
// the object to return for request.
|
// the object to return for request.
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
|
|
||||||
// for rpc=raw, to query the raw api config for http api.
|
// for rpc=raw, to query the raw api config for http api.
|
||||||
if (rpc == "raw") {
|
if (rpc == "raw") {
|
||||||
// query global scope.
|
// query global scope.
|
||||||
if ((err = _srs_config->raw_to_json(obj)) != srs_success) {
|
if ((err = _srs_config->raw_to_json(obj.get())) != srs_success) {
|
||||||
int code = srs_error_code(err);
|
int code = srs_error_code(err);
|
||||||
srs_error_reset(err);
|
srs_error_reset(err);
|
||||||
return srs_api_response_code(w, r, code);
|
return srs_api_response_code(w, r, code);
|
||||||
|
@ -989,8 +969,7 @@ SrsGoApiClusters::~SrsGoApiClusters()
|
||||||
|
|
||||||
srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
SrsJsonObject* data = SrsJsonAny::object();
|
SrsJsonObject* data = SrsJsonAny::object();
|
||||||
|
@ -1057,8 +1036,7 @@ srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
}
|
}
|
||||||
|
|
||||||
// By default, response the json style response.
|
// By default, response the json style response.
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
SrsJsonObject* data = SrsJsonAny::object();
|
SrsJsonObject* data = SrsJsonAny::object();
|
||||||
|
|
|
@ -155,14 +155,13 @@ srs_error_t SrsHttpConn::do_cycle()
|
||||||
return srs_error_wrap(err, "start");
|
return srs_error_wrap(err, "start");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRequest* last_req = NULL;
|
|
||||||
SrsAutoFree(SrsRequest, last_req);
|
|
||||||
|
|
||||||
// process all http messages.
|
// process all http messages.
|
||||||
err = process_requests(&last_req);
|
SrsRequest* last_req_raw = NULL;
|
||||||
|
err = process_requests(&last_req_raw);
|
||||||
|
SrsUniquePtr<SrsRequest> last_req(last_req_raw);
|
||||||
|
|
||||||
srs_error_t r0 = srs_success;
|
srs_error_t r0 = srs_success;
|
||||||
if ((r0 = on_disconnect(last_req)) != srs_success) {
|
if ((r0 = on_disconnect(last_req.get())) != srs_success) {
|
||||||
err = srs_error_wrap(err, "on disconnect %s", srs_error_desc(r0).c_str());
|
err = srs_error_wrap(err, "on disconnect %s", srs_error_desc(r0).c_str());
|
||||||
srs_freep(r0);
|
srs_freep(r0);
|
||||||
}
|
}
|
||||||
|
@ -180,18 +179,18 @@ srs_error_t SrsHttpConn::process_requests(SrsRequest** preq)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a http message
|
// get a http message
|
||||||
ISrsHttpMessage* req = NULL;
|
ISrsHttpMessage* req_raw = NULL;
|
||||||
if ((err = parser->parse_message(skt, &req)) != srs_success) {
|
if ((err = parser->parse_message(skt, &req_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "parse message");
|
return srs_error_wrap(err, "parse message");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if SUCCESS, always NOT-NULL.
|
// if SUCCESS, always NOT-NULL.
|
||||||
// always free it in this scope.
|
// always free it in this scope.
|
||||||
srs_assert(req);
|
srs_assert(req_raw);
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
SrsUniquePtr<ISrsHttpMessage> req(req_raw);
|
||||||
|
|
||||||
// Attach owner connection to message.
|
// Attach owner connection to message.
|
||||||
SrsHttpMessage* hreq = (SrsHttpMessage*)req;
|
SrsHttpMessage* hreq = (SrsHttpMessage*)req.get();
|
||||||
hreq->set_connection(this);
|
hreq->set_connection(this);
|
||||||
|
|
||||||
// copy request to last request object.
|
// copy request to last request object.
|
||||||
|
@ -200,17 +199,17 @@ srs_error_t SrsHttpConn::process_requests(SrsRequest** preq)
|
||||||
|
|
||||||
// may should discard the body.
|
// may should discard the body.
|
||||||
SrsHttpResponseWriter writer(skt);
|
SrsHttpResponseWriter writer(skt);
|
||||||
if ((err = handler_->on_http_message(req, &writer)) != srs_success) {
|
if ((err = handler_->on_http_message(req.get(), &writer)) != srs_success) {
|
||||||
return srs_error_wrap(err, "on http message");
|
return srs_error_wrap(err, "on http message");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, handle http request.
|
// ok, handle http request.
|
||||||
if ((err = process_request(&writer, req, req_id)) != srs_success) {
|
if ((err = process_request(&writer, req.get(), req_id)) != srs_success) {
|
||||||
return srs_error_wrap(err, "process request=%d", req_id);
|
return srs_error_wrap(err, "process request=%d", req_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// After the request is processed.
|
// After the request is processed.
|
||||||
if ((err = handler_->on_message_done(req, &writer)) != srs_success) {
|
if ((err = handler_->on_message_done(req.get(), &writer)) != srs_success) {
|
||||||
return srs_error_wrap(err, "on message done");
|
return srs_error_wrap(err, "on message done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,11 +46,8 @@ srs_error_t SrsHttpHooks::on_connect(string url, SrsRequest* req)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -85,11 +82,8 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -125,11 +119,8 @@ srs_error_t SrsHttpHooks::on_publish(string url, SrsRequest* req)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -169,11 +160,8 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -216,11 +204,8 @@ srs_error_t SrsHttpHooks::on_play(string url, SrsRequest* req)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -261,11 +246,8 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -311,9 +293,7 @@ srs_error_t SrsHttpHooks::on_dvr(SrsContextId c, string url, SrsRequest* req, st
|
||||||
std::string cwd = _srs_config->cwd();
|
std::string cwd = _srs_config->cwd();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -364,9 +344,7 @@ srs_error_t SrsHttpHooks::on_hls(SrsContextId c, string url, SrsRequest* req, st
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
obj->set("service_id", SrsJsonAny::str(stat->service_id().c_str()));
|
||||||
|
@ -449,21 +427,20 @@ srs_error_t SrsHttpHooks::on_hls_notify(SrsContextId c, std::string url, SrsRequ
|
||||||
}
|
}
|
||||||
srs_info("GET %s", path.c_str());
|
srs_info("GET %s", path.c_str());
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = http.get(path.c_str(), "", &msg)) != srs_success) {
|
if ((err = http.get(path.c_str(), "", &msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "http: get %s", url.c_str());
|
return srs_error_wrap(err, "http: get %s", url.c_str());
|
||||||
}
|
}
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
int nb_buf = srs_min(nb_notify, SRS_HTTP_READ_BUFFER);
|
int nb_buf = srs_min(nb_notify, SRS_HTTP_READ_BUFFER);
|
||||||
char* buf = new char[nb_buf];
|
SrsUniquePtr<char[]> buf(new char[nb_buf]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
int nb_read = 0;
|
int nb_read = 0;
|
||||||
ISrsHttpResponseReader* br = msg->body_reader();
|
ISrsHttpResponseReader* br = msg->body_reader();
|
||||||
while (nb_read < nb_notify && !br->eof()) {
|
while (nb_read < nb_notify && !br->eof()) {
|
||||||
ssize_t nb_bytes = 0;
|
ssize_t nb_bytes = 0;
|
||||||
if ((err = br->read(buf, nb_buf, &nb_bytes)) != srs_success) {
|
if ((err = br->read(buf.get(), nb_buf, &nb_bytes)) != srs_success) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nb_read += (int)nb_bytes;
|
nb_read += (int)nb_bytes;
|
||||||
|
@ -490,9 +467,7 @@ srs_error_t SrsHttpHooks::discover_co_workers(string url, string& host, int& por
|
||||||
return srs_error_wrap(err, "http: post %s, status=%d, res=%s", url.c_str(), status_code, res.c_str());
|
return srs_error_wrap(err, "http: post %s, status=%d, res=%s", url.c_str(), status_code, res.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsJsonObject* robj = NULL;
|
SrsJsonObject* robj_raw = NULL;
|
||||||
SrsAutoFree(SrsJsonObject, robj);
|
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsJsonAny* jr = NULL;
|
SrsJsonAny* jr = NULL;
|
||||||
if ((jr = SrsJsonAny::loads(res)) == NULL) {
|
if ((jr = SrsJsonAny::loads(res)) == NULL) {
|
||||||
|
@ -504,8 +479,9 @@ srs_error_t SrsHttpHooks::discover_co_workers(string url, string& host, int& por
|
||||||
return srs_error_new(ERROR_OCLUSTER_DISCOVER, "response %s", res.c_str());
|
return srs_error_new(ERROR_OCLUSTER_DISCOVER, "response %s", res.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
robj = jr->to_object();
|
robj_raw = jr->to_object();
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsJsonObject> robj(robj_raw);
|
||||||
|
|
||||||
SrsJsonAny* prop = NULL;
|
SrsJsonAny* prop = NULL;
|
||||||
if ((prop = robj->ensure_property_object("data")) == NULL) {
|
if ((prop = robj->ensure_property_object("data")) == NULL) {
|
||||||
|
@ -540,9 +516,7 @@ srs_error_t SrsHttpHooks::on_forward_backend(string url, SrsRequest* req, std::v
|
||||||
SrsContextId cid = _srs_context->get_id();
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||||
SrsJsonObject* obj = SrsJsonAny::object();
|
|
||||||
SrsAutoFree(SrsJsonObject, obj);
|
|
||||||
|
|
||||||
obj->set("action", SrsJsonAny::str("on_forward"));
|
obj->set("action", SrsJsonAny::str("on_forward"));
|
||||||
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
obj->set("server_id", SrsJsonAny::str(stat->server_id().c_str()));
|
||||||
|
@ -566,11 +540,10 @@ srs_error_t SrsHttpHooks::on_forward_backend(string url, SrsRequest* req, std::v
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse string res to json.
|
// parse string res to json.
|
||||||
SrsJsonAny* info = SrsJsonAny::loads(res);
|
SrsUniquePtr<SrsJsonAny> info(SrsJsonAny::loads(res));
|
||||||
if (!info) {
|
if (!info.get()) {
|
||||||
return srs_error_new(ERROR_SYSTEM_FORWARD_LOOP, "load json from %s", res.c_str());
|
return srs_error_new(ERROR_SYSTEM_FORWARD_LOOP, "load json from %s", res.c_str());
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsJsonAny, info);
|
|
||||||
|
|
||||||
// response error code in string.
|
// response error code in string.
|
||||||
if (!info->is_object()) {
|
if (!info->is_object()) {
|
||||||
|
@ -622,11 +595,11 @@ srs_error_t SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::strin
|
||||||
path += "?" + uri.get_query();
|
path += "?" + uri.get_query();
|
||||||
}
|
}
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = hc->post(path, req, &msg)) != srs_success) {
|
if ((err = hc->post(path, req, &msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "http: client post");
|
return srs_error_wrap(err, "http: client post");
|
||||||
}
|
}
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
code = msg->status_code();
|
code = msg->status_code();
|
||||||
if ((err = msg->body_read_all(res)) != srs_success) {
|
if ((err = msg->body_read_all(res)) != srs_success) {
|
||||||
|
@ -644,11 +617,10 @@ srs_error_t SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::strin
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse string res to json.
|
// parse string res to json.
|
||||||
SrsJsonAny* info = SrsJsonAny::loads(res);
|
SrsUniquePtr<SrsJsonAny> info(SrsJsonAny::loads(res));
|
||||||
if (!info) {
|
if (!info.get()) {
|
||||||
return srs_error_new(ERROR_HTTP_DATA_INVALID, "http: not json %s", res.c_str());
|
return srs_error_new(ERROR_HTTP_DATA_INVALID, "http: not json %s", res.c_str());
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsJsonAny, info);
|
|
||||||
|
|
||||||
// response error code in string.
|
// response error code in string.
|
||||||
if (!info->is_object()) {
|
if (!info->is_object()) {
|
||||||
|
|
|
@ -209,15 +209,14 @@ srs_error_t SrsHlsStream::serve_exists_session(ISrsHttpResponseWriter* w, ISrsHt
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// Read m3u8 content.
|
// Read m3u8 content.
|
||||||
SrsFileReader* fs = factory->create_file_reader();
|
SrsUniquePtr<SrsFileReader> fs(factory->create_file_reader());
|
||||||
SrsAutoFree(SrsFileReader, fs);
|
|
||||||
|
|
||||||
if ((err = fs->open(fullpath)) != srs_success) {
|
if ((err = fs->open(fullpath)) != srs_success) {
|
||||||
return srs_error_wrap(err, "open %s", fullpath.c_str());
|
return srs_error_wrap(err, "open %s", fullpath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
string content;
|
string content;
|
||||||
if ((err = srs_ioutil_read_all(fs, content)) != srs_success) {
|
if ((err = srs_ioutil_read_all(fs.get(), content)) != srs_success) {
|
||||||
return srs_error_wrap(err, "read %s", fullpath.c_str());
|
return srs_error_wrap(err, "read %s", fullpath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,8 +399,7 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsFileReader* fs = fs_factory->create_file_reader();
|
SrsUniquePtr<SrsFileReader> fs(fs_factory->create_file_reader());
|
||||||
SrsAutoFree(SrsFileReader, fs);
|
|
||||||
|
|
||||||
// open flv file
|
// open flv file
|
||||||
if ((err = fs->open(fullpath)) != srs_success) {
|
if ((err = fs->open(fullpath)) != srs_success) {
|
||||||
|
@ -416,7 +414,7 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
SrsFlvVodStreamDecoder ffd;
|
SrsFlvVodStreamDecoder ffd;
|
||||||
|
|
||||||
// open fast decoder
|
// open fast decoder
|
||||||
if ((err = ffd.initialize(fs)) != srs_success) {
|
if ((err = ffd.initialize(fs.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "init ffd");
|
return srs_error_wrap(err, "init ffd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,9 +427,7 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
}
|
}
|
||||||
|
|
||||||
// save sequence header, send later
|
// save sequence header, send later
|
||||||
char* sh_data = NULL;
|
|
||||||
int sh_size = 0;
|
int sh_size = 0;
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
// send sequence header
|
// send sequence header
|
||||||
int64_t start = 0;
|
int64_t start = 0;
|
||||||
|
@ -442,9 +438,9 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
return srs_error_new(ERROR_HTTP_REMUX_SEQUENCE_HEADER, "no sequence, size=%d", sh_size);
|
return srs_error_new(ERROR_HTTP_REMUX_SEQUENCE_HEADER, "no sequence, size=%d", sh_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sh_data = new char[sh_size];
|
|
||||||
SrsAutoFreeA(char, sh_data);
|
SrsUniquePtr<char[]> sh_data(new char[sh_size]);
|
||||||
if ((err = fs->read(sh_data, sh_size, NULL)) != srs_success) {
|
if ((err = fs->read(sh_data.get(), sh_size, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "fs read");
|
return srs_error_wrap(err, "fs read");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,7 +456,7 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
if ((err = w->write(flv_header, sizeof(flv_header))) != srs_success) {
|
if ((err = w->write(flv_header, sizeof(flv_header))) != srs_success) {
|
||||||
return srs_error_wrap(err, "write flv header");
|
return srs_error_wrap(err, "write flv header");
|
||||||
}
|
}
|
||||||
if (sh_size > 0 && (err = w->write(sh_data, sh_size)) != srs_success) {
|
if (sh_size > 0 && (err = w->write(sh_data.get(), sh_size)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write sequence");
|
return srs_error_wrap(err, "write sequence");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +466,7 @@ srs_error_t SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
}
|
}
|
||||||
|
|
||||||
// send data
|
// send data
|
||||||
if ((err = copy(w, fs, r, left)) != srs_success) {
|
if ((err = copy(w, fs.get(), r, left)) != srs_success) {
|
||||||
return srs_error_wrap(err, "read flv=%s size=%" PRId64, fullpath.c_str(), left);
|
return srs_error_wrap(err, "read flv=%s size=%" PRId64, fullpath.c_str(), left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,8 +480,7 @@ srs_error_t SrsVodStream::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
srs_assert(start >= 0);
|
srs_assert(start >= 0);
|
||||||
srs_assert(end == -1 || end >= 0);
|
srs_assert(end == -1 || end >= 0);
|
||||||
|
|
||||||
SrsFileReader* fs = fs_factory->create_file_reader();
|
SrsUniquePtr<SrsFileReader> fs(fs_factory->create_file_reader());
|
||||||
SrsAutoFree(SrsFileReader, fs);
|
|
||||||
|
|
||||||
// open flv file
|
// open flv file
|
||||||
if ((err = fs->open(fullpath)) != srs_success) {
|
if ((err = fs->open(fullpath)) != srs_success) {
|
||||||
|
@ -520,7 +515,7 @@ srs_error_t SrsVodStream::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
fs->seek2(start);
|
fs->seek2(start);
|
||||||
|
|
||||||
// send data
|
// send data
|
||||||
if ((err = copy(w, fs, r, left)) != srs_success) {
|
if ((err = copy(w, fs.get(), r, left)) != srs_success) {
|
||||||
return srs_error_wrap(err, "read mp4=%s size=%" PRId64, fullpath.c_str(), left);
|
return srs_error_wrap(err, "read mp4=%s size=%" PRId64, fullpath.c_str(), left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,8 +529,7 @@ srs_error_t SrsVodStream::serve_m3u8_ctx(ISrsHttpResponseWriter * w, ISrsHttpMes
|
||||||
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
|
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
|
||||||
srs_assert(hr);
|
srs_assert(hr);
|
||||||
|
|
||||||
SrsRequest* req = hr->to_request(hr->host())->as_http();
|
SrsUniquePtr<SrsRequest> req(hr->to_request(hr->host())->as_http());
|
||||||
SrsAutoFree(SrsRequest, req);
|
|
||||||
|
|
||||||
// discovery vhost, resolve the vhost from config
|
// discovery vhost, resolve the vhost from config
|
||||||
SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);
|
SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);
|
||||||
|
@ -545,7 +539,7 @@ srs_error_t SrsVodStream::serve_m3u8_ctx(ISrsHttpResponseWriter * w, ISrsHttpMes
|
||||||
|
|
||||||
// Try to serve by HLS streaming.
|
// Try to serve by HLS streaming.
|
||||||
bool served = false;
|
bool served = false;
|
||||||
if ((err = hls_.serve_m3u8_ctx(w, r, fs_factory, fullpath, req, &served)) != srs_success) {
|
if ((err = hls_.serve_m3u8_ctx(w, r, fs_factory, fullpath, req.get(), &served)) != srs_success) {
|
||||||
return srs_error_wrap(err, "hls ctx");
|
return srs_error_wrap(err, "hls ctx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,17 +129,17 @@ srs_error_t SrsBufferCache::cycle()
|
||||||
|
|
||||||
// the stream cache will create consumer to cache stream,
|
// the stream cache will create consumer to cache stream,
|
||||||
// which will trigger to fetch stream from origin for edge.
|
// which will trigger to fetch stream from origin for edge.
|
||||||
SrsLiveConsumer* consumer = NULL;
|
SrsLiveConsumer* consumer_raw = NULL;
|
||||||
SrsAutoFree(SrsLiveConsumer, consumer);
|
if ((err = live_source->create_consumer(consumer_raw)) != srs_success) {
|
||||||
if ((err = live_source->create_consumer(consumer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "create consumer");
|
return srs_error_wrap(err, "create consumer");
|
||||||
}
|
}
|
||||||
if ((err = live_source->consumer_dumps(consumer, false, false, true)) != srs_success) {
|
SrsUniquePtr<SrsLiveConsumer> consumer(consumer_raw);
|
||||||
|
|
||||||
|
if ((err = live_source->consumer_dumps(consumer.get(), false, false, true)) != srs_success) {
|
||||||
return srs_error_wrap(err, "dumps consumer");
|
return srs_error_wrap(err, "dumps consumer");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_http_stream_cache();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_http_stream_cache());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
||||||
|
|
||||||
|
@ -647,7 +647,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
string enc_desc;
|
string enc_desc;
|
||||||
ISrsBufferEncoder* enc = NULL;
|
ISrsBufferEncoder* enc_raw = NULL;
|
||||||
|
|
||||||
srs_assert(entry);
|
srs_assert(entry);
|
||||||
bool drop_if_not_match = _srs_config->get_vhost_http_remux_drop_if_not_match(req->vhost);
|
bool drop_if_not_match = _srs_config->get_vhost_http_remux_drop_if_not_match(req->vhost);
|
||||||
|
@ -658,29 +658,29 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
if (srs_string_ends_with(entry->pattern, ".flv")) {
|
if (srs_string_ends_with(entry->pattern, ".flv")) {
|
||||||
w->header()->set_content_type("video/x-flv");
|
w->header()->set_content_type("video/x-flv");
|
||||||
enc_desc = "FLV";
|
enc_desc = "FLV";
|
||||||
enc = new SrsFlvStreamEncoder();
|
enc_raw = new SrsFlvStreamEncoder();
|
||||||
((SrsFlvStreamEncoder*)enc)->set_drop_if_not_match(drop_if_not_match);
|
((SrsFlvStreamEncoder*)enc_raw)->set_drop_if_not_match(drop_if_not_match);
|
||||||
((SrsFlvStreamEncoder*)enc)->set_has_audio(has_audio);
|
((SrsFlvStreamEncoder*)enc_raw)->set_has_audio(has_audio);
|
||||||
((SrsFlvStreamEncoder*)enc)->set_has_video(has_video);
|
((SrsFlvStreamEncoder*)enc_raw)->set_has_video(has_video);
|
||||||
((SrsFlvStreamEncoder*)enc)->set_guess_has_av(guess_has_av);
|
((SrsFlvStreamEncoder*)enc_raw)->set_guess_has_av(guess_has_av);
|
||||||
} else if (srs_string_ends_with(entry->pattern, ".aac")) {
|
} else if (srs_string_ends_with(entry->pattern, ".aac")) {
|
||||||
w->header()->set_content_type("audio/x-aac");
|
w->header()->set_content_type("audio/x-aac");
|
||||||
enc_desc = "AAC";
|
enc_desc = "AAC";
|
||||||
enc = new SrsAacStreamEncoder();
|
enc_raw = new SrsAacStreamEncoder();
|
||||||
} else if (srs_string_ends_with(entry->pattern, ".mp3")) {
|
} else if (srs_string_ends_with(entry->pattern, ".mp3")) {
|
||||||
w->header()->set_content_type("audio/mpeg");
|
w->header()->set_content_type("audio/mpeg");
|
||||||
enc_desc = "MP3";
|
enc_desc = "MP3";
|
||||||
enc = new SrsMp3StreamEncoder();
|
enc_raw = new SrsMp3StreamEncoder();
|
||||||
} else if (srs_string_ends_with(entry->pattern, ".ts")) {
|
} else if (srs_string_ends_with(entry->pattern, ".ts")) {
|
||||||
w->header()->set_content_type("video/MP2T");
|
w->header()->set_content_type("video/MP2T");
|
||||||
enc_desc = "TS";
|
enc_desc = "TS";
|
||||||
enc = new SrsTsStreamEncoder();
|
enc_raw = new SrsTsStreamEncoder();
|
||||||
((SrsTsStreamEncoder*)enc)->set_has_audio(has_audio);
|
((SrsTsStreamEncoder*)enc_raw)->set_has_audio(has_audio);
|
||||||
((SrsTsStreamEncoder*)enc)->set_has_video(has_video);
|
((SrsTsStreamEncoder*)enc_raw)->set_has_video(has_video);
|
||||||
} else {
|
} else {
|
||||||
return srs_error_new(ERROR_HTTP_LIVE_STREAM_EXT, "invalid pattern=%s", entry->pattern.c_str());
|
return srs_error_new(ERROR_HTTP_LIVE_STREAM_EXT, "invalid pattern=%s", entry->pattern.c_str());
|
||||||
}
|
}
|
||||||
SrsAutoFree(ISrsBufferEncoder, enc);
|
SrsUniquePtr<ISrsBufferEncoder> enc(enc_raw);
|
||||||
|
|
||||||
// Enter chunked mode, because we didn't set the content-length.
|
// Enter chunked mode, because we didn't set the content-length.
|
||||||
w->write_header(SRS_CONSTS_HTTP_OK);
|
w->write_header(SRS_CONSTS_HTTP_OK);
|
||||||
|
@ -691,17 +691,17 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
}
|
}
|
||||||
|
|
||||||
// create consumer of souce, ignore gop cache, use the audio gop cache.
|
// create consumer of souce, ignore gop cache, use the audio gop cache.
|
||||||
SrsLiveConsumer* consumer = NULL;
|
SrsLiveConsumer* consumer_raw = NULL;
|
||||||
SrsAutoFree(SrsLiveConsumer, consumer);
|
if ((err = live_source->create_consumer(consumer_raw)) != srs_success) {
|
||||||
if ((err = live_source->create_consumer(consumer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "create consumer");
|
return srs_error_wrap(err, "create consumer");
|
||||||
}
|
}
|
||||||
if ((err = live_source->consumer_dumps(consumer, true, true, !enc->has_cache())) != srs_success) {
|
SrsUniquePtr<SrsLiveConsumer> consumer(consumer_raw);
|
||||||
|
|
||||||
|
if ((err = live_source->consumer_dumps(consumer.get(), true, true, !enc->has_cache())) != srs_success) {
|
||||||
return srs_error_wrap(err, "dumps consumer");
|
return srs_error_wrap(err, "dumps consumer");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_http_stream();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_http_stream());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
||||||
|
|
||||||
|
@ -718,21 +718,20 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
|
|
||||||
// if gop cache enabled for encoder, dump to consumer.
|
// if gop cache enabled for encoder, dump to consumer.
|
||||||
if (enc->has_cache()) {
|
if (enc->has_cache()) {
|
||||||
if ((err = enc->dump_cache(consumer, live_source->jitter())) != srs_success) {
|
if ((err = enc->dump_cache(consumer.get(), live_source->jitter())) != srs_success) {
|
||||||
return srs_error_wrap(err, "encoder dump cache");
|
return srs_error_wrap(err, "encoder dump cache");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to use fast flv encoder, remember that it maybe NULL.
|
// Try to use fast flv encoder, remember that it maybe NULL.
|
||||||
SrsFlvStreamEncoder* ffe = dynamic_cast<SrsFlvStreamEncoder*>(enc);
|
SrsFlvStreamEncoder* ffe = dynamic_cast<SrsFlvStreamEncoder*>(enc.get());
|
||||||
|
|
||||||
// Note that the handler of hc now is hxc.
|
// Note that the handler of hc now is hxc.
|
||||||
SrsHttpxConn* hxc = dynamic_cast<SrsHttpxConn*>(hc->handler());
|
SrsHttpxConn* hxc = dynamic_cast<SrsHttpxConn*>(hc->handler());
|
||||||
srs_assert(hxc);
|
srs_assert(hxc);
|
||||||
|
|
||||||
// Start a thread to receive all messages from client, then drop them.
|
// Start a thread to receive all messages from client, then drop them.
|
||||||
SrsHttpRecvThread* trd = new SrsHttpRecvThread(hxc);
|
SrsUniquePtr<SrsHttpRecvThread> trd(new SrsHttpRecvThread(hxc));
|
||||||
SrsAutoFree(SrsHttpRecvThread, trd);
|
|
||||||
|
|
||||||
if ((err = trd->start()) != srs_success) {
|
if ((err = trd->start()) != srs_success) {
|
||||||
return srs_error_wrap(err, "start recv thread");
|
return srs_error_wrap(err, "start recv thread");
|
||||||
|
@ -777,7 +776,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
||||||
if (ffe) {
|
if (ffe) {
|
||||||
err = ffe->write_tags(msgs.msgs, count);
|
err = ffe->write_tags(msgs.msgs, count);
|
||||||
} else {
|
} else {
|
||||||
err = streaming_send_messages(enc, msgs.msgs, count);
|
err = streaming_send_messages(enc.get(), msgs.msgs, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: Update the stat.
|
// TODO: FIXME: Update the stat.
|
||||||
|
@ -809,8 +808,7 @@ srs_error_t SrsLiveStream::http_hooks_on_play(ISrsHttpMessage* r)
|
||||||
|
|
||||||
// Create request to report for the specified connection.
|
// Create request to report for the specified connection.
|
||||||
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
|
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
|
||||||
SrsRequest* nreq = hr->to_request(req->vhost);
|
SrsUniquePtr<SrsRequest> nreq(hr->to_request(req->vhost));
|
||||||
SrsAutoFree(SrsRequest, nreq);
|
|
||||||
|
|
||||||
// the http hooks will cause context switch,
|
// the http hooks will cause context switch,
|
||||||
// so we must copy all hooks for the on_connect may freed.
|
// so we must copy all hooks for the on_connect may freed.
|
||||||
|
@ -829,7 +827,7 @@ srs_error_t SrsLiveStream::http_hooks_on_play(ISrsHttpMessage* r)
|
||||||
|
|
||||||
for (int i = 0; i < (int)hooks.size(); i++) {
|
for (int i = 0; i < (int)hooks.size(); i++) {
|
||||||
std::string url = hooks.at(i);
|
std::string url = hooks.at(i);
|
||||||
if ((err = SrsHttpHooks::on_play(url, nreq)) != srs_success) {
|
if ((err = SrsHttpHooks::on_play(url, nreq.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "http on_play %s", url.c_str());
|
return srs_error_wrap(err, "http on_play %s", url.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -845,8 +843,7 @@ void SrsLiveStream::http_hooks_on_stop(ISrsHttpMessage* r)
|
||||||
|
|
||||||
// Create request to report for the specified connection.
|
// Create request to report for the specified connection.
|
||||||
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
|
SrsHttpMessage* hr = dynamic_cast<SrsHttpMessage*>(r);
|
||||||
SrsRequest* nreq = hr->to_request(req->vhost);
|
SrsUniquePtr<SrsRequest> nreq(hr->to_request(req->vhost));
|
||||||
SrsAutoFree(SrsRequest, nreq);
|
|
||||||
|
|
||||||
// the http hooks will cause context switch,
|
// the http hooks will cause context switch,
|
||||||
// so we must copy all hooks for the on_connect may freed.
|
// so we must copy all hooks for the on_connect may freed.
|
||||||
|
@ -866,7 +863,7 @@ void SrsLiveStream::http_hooks_on_stop(ISrsHttpMessage* r)
|
||||||
|
|
||||||
for (int i = 0; i < (int)hooks.size(); i++) {
|
for (int i = 0; i < (int)hooks.size(); i++) {
|
||||||
std::string url = hooks.at(i);
|
std::string url = hooks.at(i);
|
||||||
SrsHttpHooks::on_stop(url, nreq);
|
SrsHttpHooks::on_stop(url, nreq.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -1063,15 +1060,11 @@ void SrsHttpStreamServer::http_unmount(SrsRequest* r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free all HTTP resources.
|
// Free all HTTP resources.
|
||||||
SrsLiveEntry* entry = it->second;
|
SrsUniquePtr<SrsLiveEntry> entry(it->second);
|
||||||
SrsAutoFree(SrsLiveEntry, entry);
|
|
||||||
streamHandlers.erase(it);
|
streamHandlers.erase(it);
|
||||||
|
|
||||||
SrsLiveStream* stream = entry->stream;
|
SrsUniquePtr<SrsLiveStream> stream(entry->stream);
|
||||||
SrsAutoFree(SrsLiveStream, stream);
|
SrsUniquePtr<SrsBufferCache> cache(entry->cache);
|
||||||
|
|
||||||
SrsBufferCache* cache = entry->cache;
|
|
||||||
SrsAutoFree(SrsBufferCache, cache);
|
|
||||||
|
|
||||||
// Notify cache and stream to stop.
|
// Notify cache and stream to stop.
|
||||||
if (stream->entry) stream->entry->enabled = false;
|
if (stream->entry) stream->entry->enabled = false;
|
||||||
|
@ -1088,7 +1081,7 @@ void SrsHttpStreamServer::http_unmount(SrsRequest* r)
|
||||||
|
|
||||||
// Unmount the HTTP handler, which will free the entry. Note that we must free it after cache and
|
// Unmount the HTTP handler, which will free the entry. Note that we must free it after cache and
|
||||||
// stream stopped for it uses it.
|
// stream stopped for it uses it.
|
||||||
mux.unhandle(entry->mount, stream);
|
mux.unhandle(entry->mount, stream.get());
|
||||||
|
|
||||||
srs_trace("http: unmount flv stream for sid=%s, i=%d", sid.c_str(), i);
|
srs_trace("http: unmount flv stream for sid=%s, i=%d", sid.c_str(), i);
|
||||||
}
|
}
|
||||||
|
@ -1170,8 +1163,7 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle
|
||||||
srs_assert(hreq);
|
srs_assert(hreq);
|
||||||
|
|
||||||
// hijack for entry.
|
// hijack for entry.
|
||||||
SrsRequest* r = hreq->to_request(vhost->arg0());
|
SrsUniquePtr<SrsRequest> r(hreq->to_request(vhost->arg0()));
|
||||||
SrsAutoFree(SrsRequest, r);
|
|
||||||
|
|
||||||
std::string sid = r->get_stream_url();
|
std::string sid = r->get_stream_url();
|
||||||
// check whether the http remux is enabled,
|
// check whether the http remux is enabled,
|
||||||
|
@ -1189,7 +1181,7 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSharedPtr<SrsLiveSource> live_source;
|
SrsSharedPtr<SrsLiveSource> live_source;
|
||||||
if ((err = _srs_sources->fetch_or_create(r, server, live_source)) != srs_success) {
|
if ((err = _srs_sources->fetch_or_create(r.get(), server, live_source)) != srs_success) {
|
||||||
return srs_error_wrap(err, "source create");
|
return srs_error_wrap(err, "source create");
|
||||||
}
|
}
|
||||||
srs_assert(live_source.get() != NULL);
|
srs_assert(live_source.get() != NULL);
|
||||||
|
@ -1200,7 +1192,7 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle
|
||||||
live_source->set_gop_cache_max_frames(gcmf);
|
live_source->set_gop_cache_max_frames(gcmf);
|
||||||
|
|
||||||
// create http streaming handler.
|
// create http streaming handler.
|
||||||
if ((err = http_mount(r)) != srs_success) {
|
if ((err = http_mount(r.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "http mount");
|
return srs_error_wrap(err, "http mount");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,11 +266,12 @@ srs_error_t SrsLatestVersion::query_latest_version(string& url)
|
||||||
path += "?";
|
path += "?";
|
||||||
path += uri.get_query();
|
path += uri.get_query();
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = http.get(path, "", &msg)) != srs_success) {
|
if ((err = http.get(path, "", &msg_raw)) != srs_success) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
string res;
|
string res;
|
||||||
int code = msg->status_code();
|
int code = msg->status_code();
|
||||||
|
@ -288,11 +289,10 @@ srs_error_t SrsLatestVersion::query_latest_version(string& url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response in json object.
|
// Response in json object.
|
||||||
SrsJsonAny* jres = SrsJsonAny::loads((char*)res.c_str());
|
SrsUniquePtr<SrsJsonAny> jres(SrsJsonAny::loads((char*)res.c_str()));
|
||||||
if (!jres || !jres->is_object()) {
|
if (!jres.get() || !jres->is_object()) {
|
||||||
return srs_error_new(ERROR_HTTP_DATA_INVALID, "invalid response %s", res.c_str());
|
return srs_error_new(ERROR_HTTP_DATA_INVALID, "invalid response %s", res.c_str());
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsJsonAny, jres);
|
|
||||||
|
|
||||||
SrsJsonObject* obj = jres->to_object();
|
SrsJsonObject* obj = jres->to_object();
|
||||||
SrsJsonAny* prop = NULL;
|
SrsJsonAny* prop = NULL;
|
||||||
|
|
|
@ -688,8 +688,7 @@ srs_error_t SrsUdpMuxListener::cycle()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_recv(srs_netfd_fileno(lfd));
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_rtc_recv(srs_netfd_fileno(lfd)));
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
uint64_t nn_msgs = 0;
|
uint64_t nn_msgs = 0;
|
||||||
uint64_t nn_msgs_stage = 0;
|
uint64_t nn_msgs_stage = 0;
|
||||||
|
@ -697,8 +696,7 @@ srs_error_t SrsUdpMuxListener::cycle()
|
||||||
uint64_t nn_loop = 0;
|
uint64_t nn_loop = 0;
|
||||||
srs_utime_t time_last = srs_get_system_time();
|
srs_utime_t time_last = srs_get_system_time();
|
||||||
|
|
||||||
SrsErrorPithyPrint* pp_pkt_handler_err = new SrsErrorPithyPrint();
|
SrsUniquePtr<SrsErrorPithyPrint> pp_pkt_handler_err(new SrsErrorPithyPrint());
|
||||||
SrsAutoFree(SrsErrorPithyPrint, pp_pkt_handler_err);
|
|
||||||
|
|
||||||
set_socket_buffer();
|
set_socket_buffer();
|
||||||
|
|
||||||
|
|
|
@ -236,13 +236,12 @@ srs_error_t SrsMpegtsOverUdp::on_udp_bytes(string host, int port, char* buf, int
|
||||||
}
|
}
|
||||||
buffer->erase(buffer->length());
|
buffer->erase(buffer->length());
|
||||||
int nb_fbuf = fr.filesize();
|
int nb_fbuf = fr.filesize();
|
||||||
char* fbuf = new char[nb_fbuf];
|
SrsUniquePtr<char[]> fbuf(new char[nb_fbuf]);
|
||||||
SrsAutoFreeA(char, fbuf);
|
if ((err = fr.read(fbuf.get(), nb_fbuf, NULL)) != srs_success) {
|
||||||
if ((err = fr.read(fbuf, nb_fbuf, NULL)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "read data");
|
return srs_error_wrap(err, "read data");
|
||||||
}
|
}
|
||||||
fr.close();
|
fr.close();
|
||||||
buffer->append(fbuf, nb_fbuf);
|
buffer->append(fbuf.get(), nb_fbuf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// find the sync byte of mpegts.
|
// find the sync byte of mpegts.
|
||||||
|
@ -268,12 +267,10 @@ srs_error_t SrsMpegtsOverUdp::on_udp_bytes(string host, int port, char* buf, int
|
||||||
int nb_packet = buffer->length() / SRS_TS_PACKET_SIZE;
|
int nb_packet = buffer->length() / SRS_TS_PACKET_SIZE;
|
||||||
for (int i = 0; i < nb_packet; i++) {
|
for (int i = 0; i < nb_packet; i++) {
|
||||||
char* p = buffer->bytes() + (i * SRS_TS_PACKET_SIZE);
|
char* p = buffer->bytes() + (i * SRS_TS_PACKET_SIZE);
|
||||||
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(p, SRS_TS_PACKET_SIZE));
|
||||||
SrsBuffer* stream = new SrsBuffer(p, SRS_TS_PACKET_SIZE);
|
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// process each ts packet
|
// process each ts packet
|
||||||
if ((err = context->decode(stream, this)) != srs_success) {
|
if ((err = context->decode(stream.get(), this)) != srs_success) {
|
||||||
srs_info("parse ts packet err=%s", srs_error_desc(err).c_str());
|
srs_info("parse ts packet err=%s", srs_error_desc(err).c_str());
|
||||||
srs_error_reset(err);
|
srs_error_reset(err);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -94,8 +94,7 @@ public:
|
||||||
// if there is 1client, it will print every 3s.
|
// if there is 1client, it will print every 3s.
|
||||||
// if there is 10clients, random select one to print every 3s.
|
// if there is 10clients, random select one to print every 3s.
|
||||||
// Usage:
|
// Usage:
|
||||||
// SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_play();
|
// SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_rtmp_play());
|
||||||
// SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
// while (true) {
|
// while (true) {
|
||||||
// pprint->elapse();
|
// pprint->elapse();
|
||||||
// if (pprint->can_print()) {
|
// if (pprint->can_print()) {
|
||||||
|
|
|
@ -577,10 +577,8 @@ srs_error_t SrsHttpRecvThread::cycle()
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
while ((err = trd->pull()) == srs_success) {
|
while ((err = trd->pull()) == srs_success) {
|
||||||
ISrsHttpMessage* req = NULL;
|
// Ignore any received messages.
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
if ((err = conn->pop_message(NULL)) != srs_success) {
|
||||||
|
|
||||||
if ((err = conn->pop_message(&req)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "pop message");
|
return srs_error_wrap(err, "pop message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,9 @@ srs_error_t SrsGoApiRtcPlay::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsJsonObject* res = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> res(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, res);
|
|
||||||
|
|
||||||
if ((err = do_serve_http(w, r, res)) != srs_success) {
|
if ((err = do_serve_http(w, r, res.get())) != srs_success) {
|
||||||
srs_warn("RTC error %s", srs_error_desc(err).c_str()); srs_freep(err);
|
srs_warn("RTC error %s", srs_error_desc(err).c_str()); srs_freep(err);
|
||||||
return srs_api_response_code(w, r, SRS_CONSTS_HTTP_BadRequest);
|
return srs_api_response_code(w, r, SRS_CONSTS_HTTP_BadRequest);
|
||||||
}
|
}
|
||||||
|
@ -73,8 +72,7 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
hdr->set("Connection", "Close");
|
hdr->set("Connection", "Close");
|
||||||
|
|
||||||
// Parse req, the request json object, from body.
|
// Parse req, the request json object, from body.
|
||||||
SrsJsonObject* req = NULL;
|
SrsJsonObject* req_raw = NULL;
|
||||||
SrsAutoFree(SrsJsonObject, req);
|
|
||||||
if (true) {
|
if (true) {
|
||||||
string req_json;
|
string req_json;
|
||||||
if ((err = r->body_read_all(req_json)) != srs_success) {
|
if ((err = r->body_read_all(req_json)) != srs_success) {
|
||||||
|
@ -86,8 +84,9 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
return srs_error_new(ERROR_RTC_API_BODY, "invalid body %s", req_json.c_str());
|
return srs_error_new(ERROR_RTC_API_BODY, "invalid body %s", req_json.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
req = json->to_object();
|
req_raw = json->to_object();
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsJsonObject> req(req_raw);
|
||||||
|
|
||||||
// Fetch params from req object.
|
// Fetch params from req object.
|
||||||
SrsJsonAny* prop = NULL;
|
SrsJsonAny* prop = NULL;
|
||||||
|
@ -351,10 +350,9 @@ srs_error_t SrsGoApiRtcPublish::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsJsonObject* res = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> res(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, res);
|
|
||||||
|
|
||||||
if ((err = do_serve_http(w, r, res)) != srs_success) {
|
if ((err = do_serve_http(w, r, res.get())) != srs_success) {
|
||||||
srs_warn("RTC error %s", srs_error_desc(err).c_str()); srs_freep(err);
|
srs_warn("RTC error %s", srs_error_desc(err).c_str()); srs_freep(err);
|
||||||
return srs_api_response_code(w, r, SRS_CONSTS_HTTP_BadRequest);
|
return srs_api_response_code(w, r, SRS_CONSTS_HTTP_BadRequest);
|
||||||
}
|
}
|
||||||
|
@ -370,8 +368,7 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
|
||||||
w->header()->set("Connection", "Close");
|
w->header()->set("Connection", "Close");
|
||||||
|
|
||||||
// Parse req, the request json object, from body.
|
// Parse req, the request json object, from body.
|
||||||
SrsJsonObject* req = NULL;
|
SrsJsonObject* req_raw = NULL;
|
||||||
SrsAutoFree(SrsJsonObject, req);
|
|
||||||
if (true) {
|
if (true) {
|
||||||
string req_json;
|
string req_json;
|
||||||
if ((err = r->body_read_all(req_json)) != srs_success) {
|
if ((err = r->body_read_all(req_json)) != srs_success) {
|
||||||
|
@ -383,8 +380,9 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
|
||||||
return srs_error_new(ERROR_RTC_API_BODY, "invalid body %s", req_json.c_str());
|
return srs_error_new(ERROR_RTC_API_BODY, "invalid body %s", req_json.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
req = json->to_object();
|
req_raw = json->to_object();
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsJsonObject> req(req_raw);
|
||||||
|
|
||||||
// Fetch params from req object.
|
// Fetch params from req object.
|
||||||
SrsJsonAny* prop = NULL;
|
SrsJsonAny* prop = NULL;
|
||||||
|
@ -775,12 +773,11 @@ srs_error_t SrsGoApiRtcNACK::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsJsonObject* res = SrsJsonAny::object();
|
SrsUniquePtr<SrsJsonObject> res(SrsJsonAny::object());
|
||||||
SrsAutoFree(SrsJsonObject, res);
|
|
||||||
|
|
||||||
res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||||
|
|
||||||
if ((err = do_serve_http(w, r, res)) != srs_success) {
|
if ((err = do_serve_http(w, r, res.get())) != srs_success) {
|
||||||
srs_warn("RTC: NACK err %s", srs_error_desc(err).c_str());
|
srs_warn("RTC: NACK err %s", srs_error_desc(err).c_str());
|
||||||
res->set("code", SrsJsonAny::integer(srs_error_code(err)));
|
res->set("code", SrsJsonAny::integer(srs_error_code(err)));
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
|
|
|
@ -644,17 +644,18 @@ srs_error_t SrsRtcPlayStream::cycle()
|
||||||
SrsSharedPtr<SrsRtcSource>& source = source_;
|
SrsSharedPtr<SrsRtcSource>& source = source_;
|
||||||
srs_assert(source.get());
|
srs_assert(source.get());
|
||||||
|
|
||||||
SrsRtcConsumer* consumer = NULL;
|
SrsRtcConsumer* consumer_raw = NULL;
|
||||||
SrsAutoFree(SrsRtcConsumer, consumer);
|
if ((err = source->create_consumer(consumer_raw)) != srs_success) {
|
||||||
if ((err = source->create_consumer(consumer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "create consumer, source=%s", req_->get_stream_url().c_str());
|
return srs_error_wrap(err, "create consumer, source=%s", req_->get_stream_url().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(consumer);
|
srs_assert(consumer_raw);
|
||||||
|
SrsUniquePtr<SrsRtcConsumer> consumer(consumer_raw);
|
||||||
|
|
||||||
consumer->set_handler(this);
|
consumer->set_handler(this);
|
||||||
|
|
||||||
// TODO: FIXME: Dumps the SPS/PPS from gop cache, without other frames.
|
// TODO: FIXME: Dumps the SPS/PPS from gop cache, without other frames.
|
||||||
if ((err = source->consumer_dumps(consumer)) != srs_success) {
|
if ((err = source->consumer_dumps(consumer.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "dumps consumer, url=%s", req_->get_stream_url().c_str());
|
return srs_error_wrap(err, "dumps consumer, url=%s", req_->get_stream_url().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,8 +667,7 @@ srs_error_t SrsRtcPlayStream::cycle()
|
||||||
srs_trace("RTC: start play url=%s, source_id=%s/%s, realtime=%d, mw_msgs=%d", req_->get_stream_url().c_str(),
|
srs_trace("RTC: start play url=%s, source_id=%s/%s, realtime=%d, mw_msgs=%d", req_->get_stream_url().c_str(),
|
||||||
cid.c_str(), source->pre_source_id().c_str(), realtime, mw_msgs);
|
cid.c_str(), source->pre_source_id().c_str(), realtime, mw_msgs);
|
||||||
|
|
||||||
SrsErrorPithyPrint* epp = new SrsErrorPithyPrint();
|
SrsUniquePtr<SrsErrorPithyPrint> epp(new SrsErrorPithyPrint());
|
||||||
SrsAutoFree(SrsErrorPithyPrint, epp);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if ((err = trd_->pull()) != srs_success) {
|
if ((err = trd_->pull()) != srs_success) {
|
||||||
|
@ -1541,13 +1541,12 @@ srs_error_t SrsRtcPublishStream::send_periodic_twcc()
|
||||||
// limit the max count=1024 to avoid dead loop.
|
// limit the max count=1024 to avoid dead loop.
|
||||||
for (int i = 0; i < 1024 && rtcp_twcc_.need_feedback(); ++i) {
|
for (int i = 0; i < 1024 && rtcp_twcc_.need_feedback(); ++i) {
|
||||||
char pkt[kMaxUDPDataSize];
|
char pkt[kMaxUDPDataSize];
|
||||||
SrsBuffer *buffer = new SrsBuffer(pkt, sizeof(pkt));
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(pkt, sizeof(pkt)));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
|
||||||
|
|
||||||
rtcp_twcc_.set_feedback_count(twcc_fb_count_);
|
rtcp_twcc_.set_feedback_count(twcc_fb_count_);
|
||||||
twcc_fb_count_++;
|
twcc_fb_count_++;
|
||||||
|
|
||||||
if((err = rtcp_twcc_.encode(buffer)) != srs_success) {
|
if((err = rtcp_twcc_.encode(buffer.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "encode, count=%u", twcc_fb_count_);
|
return srs_error_wrap(err, "encode, count=%u", twcc_fb_count_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1937,15 +1936,14 @@ srs_error_t SrsRtcConnection::add_publisher(SrsRtcUserConfig* ruc, SrsSdp& local
|
||||||
|
|
||||||
SrsRequest* req = ruc->req_;
|
SrsRequest* req = ruc->req_;
|
||||||
|
|
||||||
SrsRtcSourceDescription* stream_desc = new SrsRtcSourceDescription();
|
SrsUniquePtr<SrsRtcSourceDescription> stream_desc(new SrsRtcSourceDescription());
|
||||||
SrsAutoFree(SrsRtcSourceDescription, stream_desc);
|
|
||||||
|
|
||||||
// TODO: FIXME: Change to api of stream desc.
|
// TODO: FIXME: Change to api of stream desc.
|
||||||
if ((err = negotiate_publish_capability(ruc, stream_desc)) != srs_success) {
|
if ((err = negotiate_publish_capability(ruc, stream_desc.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "publish negotiate, offer=%s", srs_string_replace(ruc->remote_sdp_str_.c_str(), "\r\n", "\\r\\n").c_str());
|
return srs_error_wrap(err, "publish negotiate, offer=%s", srs_string_replace(ruc->remote_sdp_str_.c_str(), "\r\n", "\\r\\n").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = generate_publish_local_sdp(req, local_sdp, stream_desc, ruc->remote_sdp_.is_unified(), ruc->audio_before_video_)) != srs_success) {
|
if ((err = generate_publish_local_sdp(req, local_sdp, stream_desc.get(), ruc->remote_sdp_.is_unified(), ruc->audio_before_video_)) != srs_success) {
|
||||||
return srs_error_wrap(err, "generate local sdp");
|
return srs_error_wrap(err, "generate local sdp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1962,10 +1960,10 @@ srs_error_t SrsRtcConnection::add_publisher(SrsRtcUserConfig* ruc, SrsSdp& local
|
||||||
source->set_stream_created();
|
source->set_stream_created();
|
||||||
|
|
||||||
// Apply the SDP to source.
|
// Apply the SDP to source.
|
||||||
source->set_stream_desc(stream_desc);
|
source->set_stream_desc(stream_desc.get());
|
||||||
|
|
||||||
// TODO: FIXME: What happends when error?
|
// TODO: FIXME: What happends when error?
|
||||||
if ((err = create_publisher(req, stream_desc)) != srs_success) {
|
if ((err = create_publisher(req, stream_desc.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "create publish");
|
return srs_error_wrap(err, "create publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1988,8 +1986,7 @@ srs_error_t SrsRtcConnection::add_player(SrsRtcUserConfig* ruc, SrsSdp& local_sd
|
||||||
return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "no play relations");
|
return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "no play relations");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSourceDescription* stream_desc = new SrsRtcSourceDescription();
|
SrsUniquePtr<SrsRtcSourceDescription> stream_desc(new SrsRtcSourceDescription());
|
||||||
SrsAutoFree(SrsRtcSourceDescription, stream_desc);
|
|
||||||
std::map<uint32_t, SrsRtcTrackDescription*>::iterator it = play_sub_relations.begin();
|
std::map<uint32_t, SrsRtcTrackDescription*>::iterator it = play_sub_relations.begin();
|
||||||
while (it != play_sub_relations.end()) {
|
while (it != play_sub_relations.end()) {
|
||||||
SrsRtcTrackDescription* track_desc = it->second;
|
SrsRtcTrackDescription* track_desc = it->second;
|
||||||
|
@ -2005,7 +2002,7 @@ srs_error_t SrsRtcConnection::add_player(SrsRtcUserConfig* ruc, SrsSdp& local_sd
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = generate_play_local_sdp(req, local_sdp, stream_desc, ruc->remote_sdp_.is_unified(), ruc->audio_before_video_)) != srs_success) {
|
if ((err = generate_play_local_sdp(req, local_sdp, stream_desc.get(), ruc->remote_sdp_.is_unified(), ruc->audio_before_video_)) != srs_success) {
|
||||||
return srs_error_wrap(err, "generate local sdp");
|
return srs_error_wrap(err, "generate local sdp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2046,20 +2043,19 @@ srs_error_t SrsRtcConnection::on_rtcp(char* unprotected_buf, int nb_unprotected_
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(unprotected_buf, nb_unprotected_buf);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(unprotected_buf, nb_unprotected_buf));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
|
||||||
|
|
||||||
SrsRtcpCompound rtcp_compound;
|
SrsRtcpCompound rtcp_compound;
|
||||||
if(srs_success != (err = rtcp_compound.decode(buffer))) {
|
if(srs_success != (err = rtcp_compound.decode(buffer.get()))) {
|
||||||
return srs_error_wrap(err, "decode rtcp plaintext=%u, bytes=[%s], at=%s", nb_unprotected_buf,
|
return srs_error_wrap(err, "decode rtcp plaintext=%u, bytes=[%s], at=%s", nb_unprotected_buf,
|
||||||
srs_string_dumps_hex(unprotected_buf, nb_unprotected_buf, 8).c_str(),
|
srs_string_dumps_hex(unprotected_buf, nb_unprotected_buf, 8).c_str(),
|
||||||
srs_string_dumps_hex(buffer->head(), buffer->left(), 8).c_str());
|
srs_string_dumps_hex(buffer->head(), buffer->left(), 8).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcpCommon* rtcp = NULL;
|
SrsRtcpCommon* rtcp_raw = NULL;
|
||||||
while(NULL != (rtcp = rtcp_compound.get_next_rtcp())) {
|
while(NULL != (rtcp_raw = rtcp_compound.get_next_rtcp())) {
|
||||||
err = dispatch_rtcp(rtcp);
|
err = dispatch_rtcp(rtcp_raw);
|
||||||
SrsAutoFree(SrsRtcpCommon, rtcp);
|
SrsUniquePtr<SrsRtcpCommon> rtcp(rtcp_raw);
|
||||||
|
|
||||||
if(srs_success != err) {
|
if(srs_success != err) {
|
||||||
return srs_error_wrap(err, "plaintext=%u, bytes=[%s], rtcp=(%u,%u,%u,%u)", nb_unprotected_buf,
|
return srs_error_wrap(err, "plaintext=%u, bytes=[%s], rtcp=(%u,%u,%u,%u)", nb_unprotected_buf,
|
||||||
|
@ -2626,8 +2622,7 @@ srs_error_t SrsRtcConnection::negotiate_publish_capability(SrsRtcUserConfig* ruc
|
||||||
|
|
||||||
if (remote_media_desc.is_video()) nn_any_video_parsed++;
|
if (remote_media_desc.is_video()) nn_any_video_parsed++;
|
||||||
|
|
||||||
SrsRtcTrackDescription* track_desc = new SrsRtcTrackDescription();
|
SrsUniquePtr<SrsRtcTrackDescription> track_desc(new SrsRtcTrackDescription());
|
||||||
SrsAutoFree(SrsRtcTrackDescription, track_desc);
|
|
||||||
|
|
||||||
track_desc->set_direction("recvonly");
|
track_desc->set_direction("recvonly");
|
||||||
track_desc->set_mid(remote_media_desc.mid_);
|
track_desc->set_mid(remote_media_desc.mid_);
|
||||||
|
|
|
@ -329,13 +329,12 @@ srs_error_t SrsDtlsCertificate::initialize()
|
||||||
// TODO: FIXME: Unused variable.
|
// TODO: FIXME: Unused variable.
|
||||||
/*int r = */X509_digest(dtls_cert, EVP_sha256(), md, &n);
|
/*int r = */X509_digest(dtls_cert, EVP_sha256(), md, &n);
|
||||||
|
|
||||||
char* fp = new char[3 * n];
|
SrsUniquePtr<char[]> fp(new char[3 * n]);
|
||||||
SrsAutoFreeA(char, fp);
|
char* p = fp.get();
|
||||||
char *p = fp;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < n; i++, ++p) {
|
for (unsigned int i = 0; i < n; i++, ++p) {
|
||||||
int nb = snprintf(p, 3, "%02X", md[i]);
|
int nb = snprintf(p, 3, "%02X", md[i]);
|
||||||
srs_assert(nb > 0 && nb < (3 * n - (p - fp)));
|
srs_assert(nb > 0 && nb < (3 * n - (p - fp.get())));
|
||||||
p += nb;
|
p += nb;
|
||||||
|
|
||||||
if(i < (n-1)) {
|
if(i < (n-1)) {
|
||||||
|
@ -345,7 +344,7 @@ srs_error_t SrsDtlsCertificate::initialize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fingerprint.assign(fp, strlen(fp));
|
fingerprint.assign(fp.get(), strlen(fp.get()));
|
||||||
srs_trace("fingerprint=%s", fingerprint.c_str());
|
srs_trace("fingerprint=%s", fingerprint.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -985,10 +984,9 @@ srs_error_t SrsSRTP::initialize(string recv_key, std::string send_key)
|
||||||
|
|
||||||
// init recv context
|
// init recv context
|
||||||
policy.ssrc.type = ssrc_any_inbound;
|
policy.ssrc.type = ssrc_any_inbound;
|
||||||
uint8_t *rkey = new uint8_t[recv_key.size()];
|
SrsUniquePtr<uint8_t[]> rkey(new uint8_t[recv_key.size()]);
|
||||||
SrsAutoFreeA(uint8_t, rkey);
|
memcpy(rkey.get(), recv_key.data(), recv_key.size());
|
||||||
memcpy(rkey, recv_key.data(), recv_key.size());
|
policy.key = rkey.get();
|
||||||
policy.key = rkey;
|
|
||||||
|
|
||||||
srtp_err_status_t r0 = srtp_err_status_ok;
|
srtp_err_status_t r0 = srtp_err_status_ok;
|
||||||
if ((r0 = srtp_create(&recv_ctx_, &policy)) != srtp_err_status_ok) {
|
if ((r0 = srtp_create(&recv_ctx_, &policy)) != srtp_err_status_ok) {
|
||||||
|
@ -996,10 +994,9 @@ srs_error_t SrsSRTP::initialize(string recv_key, std::string send_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
policy.ssrc.type = ssrc_any_outbound;
|
policy.ssrc.type = ssrc_any_outbound;
|
||||||
uint8_t *skey = new uint8_t[send_key.size()];
|
SrsUniquePtr<uint8_t[]> skey(new uint8_t[send_key.size()]);
|
||||||
SrsAutoFreeA(uint8_t, skey);
|
memcpy(skey.get(), send_key.data(), send_key.size());
|
||||||
memcpy(skey, send_key.data(), send_key.size());
|
policy.key = skey.get();
|
||||||
policy.key = skey;
|
|
||||||
|
|
||||||
if ((r0 = srtp_create(&send_ctx_, &policy)) != srtp_err_status_ok) {
|
if ((r0 = srtp_create(&send_ctx_, &policy)) != srtp_err_status_ok) {
|
||||||
return srs_error_new(ERROR_RTC_SRTP_INIT, "srtp create r0=%u", r0);
|
return srs_error_new(ERROR_RTC_SRTP_INIT, "srtp create r0=%u", r0);
|
||||||
|
|
|
@ -391,8 +391,7 @@ srs_error_t SrsRtcUdpNetwork::on_binding_request(SrsStunPacket* r, string ice_pw
|
||||||
|
|
||||||
SrsStunPacket stun_binding_response;
|
SrsStunPacket stun_binding_response;
|
||||||
char buf[kRtpPacketSize];
|
char buf[kRtpPacketSize];
|
||||||
SrsBuffer* stream = new SrsBuffer(buf, sizeof(buf));
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf)));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
stun_binding_response.set_message_type(BindingResponse);
|
stun_binding_response.set_message_type(BindingResponse);
|
||||||
stun_binding_response.set_local_ufrag(r->get_remote_ufrag());
|
stun_binding_response.set_local_ufrag(r->get_remote_ufrag());
|
||||||
|
@ -402,7 +401,7 @@ srs_error_t SrsRtcUdpNetwork::on_binding_request(SrsStunPacket* r, string ice_pw
|
||||||
stun_binding_response.set_mapped_address(be32toh(inet_addr(get_peer_ip().c_str())));
|
stun_binding_response.set_mapped_address(be32toh(inet_addr(get_peer_ip().c_str())));
|
||||||
stun_binding_response.set_mapped_port(get_peer_port());
|
stun_binding_response.set_mapped_port(get_peer_port());
|
||||||
|
|
||||||
if ((err = stun_binding_response.encode(ice_pwd, stream)) != srs_success) {
|
if ((err = stun_binding_response.encode(ice_pwd, stream.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "stun binding response encode failed");
|
return srs_error_wrap(err, "stun binding response encode failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,8 +519,7 @@ srs_error_t SrsRtcTcpNetwork::on_binding_request(SrsStunPacket* r, std::string i
|
||||||
|
|
||||||
SrsStunPacket stun_binding_response;
|
SrsStunPacket stun_binding_response;
|
||||||
char buf[kRtpPacketSize];
|
char buf[kRtpPacketSize];
|
||||||
SrsBuffer* stream = new SrsBuffer(buf, sizeof(buf));
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf)));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
stun_binding_response.set_message_type(BindingResponse);
|
stun_binding_response.set_message_type(BindingResponse);
|
||||||
stun_binding_response.set_local_ufrag(r->get_remote_ufrag());
|
stun_binding_response.set_local_ufrag(r->get_remote_ufrag());
|
||||||
|
@ -531,7 +529,7 @@ srs_error_t SrsRtcTcpNetwork::on_binding_request(SrsStunPacket* r, std::string i
|
||||||
stun_binding_response.set_mapped_address(be32toh(inet_addr(get_peer_ip().c_str())));
|
stun_binding_response.set_mapped_address(be32toh(inet_addr(get_peer_ip().c_str())));
|
||||||
stun_binding_response.set_mapped_port(get_peer_port());
|
stun_binding_response.set_mapped_port(get_peer_port());
|
||||||
|
|
||||||
if ((err = stun_binding_response.encode(ice_pwd, stream)) != srs_success) {
|
if ((err = stun_binding_response.encode(ice_pwd, stream.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "stun binding response encode failed");
|
return srs_error_wrap(err, "stun binding response encode failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <srs_app_log.hpp>
|
#include <srs_app_log.hpp>
|
||||||
#include <srs_app_threads.hpp>
|
#include <srs_app_threads.hpp>
|
||||||
#include <srs_app_statistic.hpp>
|
#include <srs_app_statistic.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
#ifdef SRS_FFMPEG_FIT
|
#ifdef SRS_FFMPEG_FIT
|
||||||
#include <srs_app_rtc_codec.hpp>
|
#include <srs_app_rtc_codec.hpp>
|
||||||
|
@ -449,8 +450,7 @@ void SrsRtcSource::init_for_play_before_publishing()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSourceDescription* stream_desc = new SrsRtcSourceDescription();
|
SrsUniquePtr<SrsRtcSourceDescription> stream_desc(new SrsRtcSourceDescription());
|
||||||
SrsAutoFree(SrsRtcSourceDescription, stream_desc);
|
|
||||||
|
|
||||||
// audio track description
|
// audio track description
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -485,7 +485,7 @@ void SrsRtcSource::init_for_play_before_publishing()
|
||||||
video_payload->set_h264_param_desc("level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f");
|
video_payload->set_h264_param_desc("level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f");
|
||||||
}
|
}
|
||||||
|
|
||||||
set_stream_desc(stream_desc);
|
set_stream_desc(stream_desc.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSource::update_auth(SrsRequest* r)
|
void SrsRtcSource::update_auth(SrsRequest* r)
|
||||||
|
@ -1006,16 +1006,14 @@ srs_error_t SrsRtcRtpBuilder::transcode(SrsAudioFrame* audio)
|
||||||
|
|
||||||
for (std::vector<SrsAudioFrame*>::iterator it = out_audios.begin(); it != out_audios.end(); ++it) {
|
for (std::vector<SrsAudioFrame*>::iterator it = out_audios.begin(); it != out_audios.end(); ++it) {
|
||||||
SrsAudioFrame* out_audio = *it;
|
SrsAudioFrame* out_audio = *it;
|
||||||
|
SrsUniquePtr<SrsRtpPacket> pkt(new SrsRtpPacket());
|
||||||
|
|
||||||
SrsRtpPacket* pkt = new SrsRtpPacket();
|
if ((err = package_opus(out_audio, pkt.get())) != srs_success) {
|
||||||
SrsAutoFree(SrsRtpPacket, pkt);
|
|
||||||
|
|
||||||
if ((err = package_opus(out_audio, pkt)) != srs_success) {
|
|
||||||
err = srs_error_wrap(err, "package opus");
|
err = srs_error_wrap(err, "package opus");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = bridge_->on_rtp(pkt)) != srs_success) {
|
if ((err = bridge_->on_rtp(pkt.get())) != srs_success) {
|
||||||
err = srs_error_wrap(err, "consume opus");
|
err = srs_error_wrap(err, "consume opus");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1083,14 +1081,13 @@ srs_error_t SrsRtcRtpBuilder::on_video(SrsSharedPtrMessage* msg)
|
||||||
|
|
||||||
// Well, for each IDR, we append a SPS/PPS before it, which is packaged in STAP-A.
|
// Well, for each IDR, we append a SPS/PPS before it, which is packaged in STAP-A.
|
||||||
if (has_idr) {
|
if (has_idr) {
|
||||||
SrsRtpPacket* pkt = new SrsRtpPacket();
|
SrsUniquePtr<SrsRtpPacket> pkt(new SrsRtpPacket());
|
||||||
SrsAutoFree(SrsRtpPacket, pkt);
|
|
||||||
|
|
||||||
if ((err = package_stap_a(msg, pkt)) != srs_success) {
|
if ((err = package_stap_a(msg, pkt.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "package stap-a");
|
return srs_error_wrap(err, "package stap-a");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = bridge_->on_rtp(pkt)) != srs_success) {
|
if ((err = bridge_->on_rtp(pkt.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "consume sps/pps");
|
return srs_error_wrap(err, "consume sps/pps");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1231,7 +1228,7 @@ srs_error_t SrsRtcRtpBuilder::package_nalus(SrsSharedPtrMessage* msg, const vect
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsRtpRawNALUs* raw = new SrsRtpRawNALUs();
|
SrsRtpRawNALUs* raw_raw = new SrsRtpRawNALUs();
|
||||||
SrsAvcNaluType first_nalu_type = SrsAvcNaluTypeReserved;
|
SrsAvcNaluType first_nalu_type = SrsAvcNaluTypeReserved;
|
||||||
|
|
||||||
for (int i = 0; i < (int)samples.size(); i++) {
|
for (int i = 0; i < (int)samples.size(); i++) {
|
||||||
|
@ -1245,13 +1242,13 @@ srs_error_t SrsRtcRtpBuilder::package_nalus(SrsSharedPtrMessage* msg, const vect
|
||||||
first_nalu_type = SrsAvcNaluType((uint8_t)(sample->bytes[0] & kNalTypeMask));
|
first_nalu_type = SrsAvcNaluType((uint8_t)(sample->bytes[0] & kNalTypeMask));
|
||||||
}
|
}
|
||||||
|
|
||||||
raw->push_back(sample->copy());
|
raw_raw->push_back(sample->copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore empty.
|
// Ignore empty.
|
||||||
int nn_bytes = raw->nb_bytes();
|
int nn_bytes = raw_raw->nb_bytes();
|
||||||
if (nn_bytes <= 0) {
|
if (nn_bytes <= 0) {
|
||||||
srs_freep(raw);
|
srs_freep(raw_raw);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1266,12 +1263,12 @@ srs_error_t SrsRtcRtpBuilder::package_nalus(SrsSharedPtrMessage* msg, const vect
|
||||||
pkt->nalu_type = (SrsAvcNaluType)first_nalu_type;
|
pkt->nalu_type = (SrsAvcNaluType)first_nalu_type;
|
||||||
pkt->header.set_sequence(video_sequence++);
|
pkt->header.set_sequence(video_sequence++);
|
||||||
pkt->header.set_timestamp(msg->timestamp * 90);
|
pkt->header.set_timestamp(msg->timestamp * 90);
|
||||||
pkt->set_payload(raw, SrsRtspPacketPayloadTypeNALU);
|
pkt->set_payload(raw_raw, SrsRtspPacketPayloadTypeNALU);
|
||||||
pkt->wrap(msg);
|
pkt->wrap(msg);
|
||||||
} else {
|
} else {
|
||||||
// We must free it, should never use RTP packets to free it,
|
// We must free it, should never use RTP packets to free it,
|
||||||
// because more than one RTP packet will refer to it.
|
// because more than one RTP packet will refer to it.
|
||||||
SrsAutoFree(SrsRtpRawNALUs, raw);
|
SrsUniquePtr<SrsRtpRawNALUs> raw(raw_raw);
|
||||||
|
|
||||||
// Package NALUs in FU-A RTP packets.
|
// Package NALUs in FU-A RTP packets.
|
||||||
int fu_payload_size = kRtpMaxPayloadSize;
|
int fu_payload_size = kRtpMaxPayloadSize;
|
||||||
|
@ -1642,13 +1639,13 @@ srs_error_t SrsRtcFrameBuilder::packet_video_key_frame(SrsRtpPacket* pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset SPS/PPS cache, ensuring that the next SPS/PPS will be handled when both are received.
|
// Reset SPS/PPS cache, ensuring that the next SPS/PPS will be handled when both are received.
|
||||||
|
// Note that we should use SrsAutoFree to set the ptr to NULL.
|
||||||
SrsAutoFree(SrsRtpPacket, obs_whip_sps_);
|
SrsAutoFree(SrsRtpPacket, obs_whip_sps_);
|
||||||
SrsAutoFree(SrsRtpPacket, obs_whip_pps_);
|
SrsAutoFree(SrsRtpPacket, obs_whip_pps_);
|
||||||
|
|
||||||
// h264 raw to h264 packet.
|
// h264 raw to h264 packet.
|
||||||
std::string sh;
|
std::string sh;
|
||||||
SrsRawH264Stream* avc = new SrsRawH264Stream();
|
SrsUniquePtr<SrsRawH264Stream> avc(new SrsRawH264Stream());
|
||||||
SrsAutoFree(SrsRawH264Stream, avc);
|
|
||||||
|
|
||||||
if ((err = avc->mux_sequence_header(string(sps->bytes, sps->size), string(pps->bytes, pps->size), sh)) != srs_success) {
|
if ((err = avc->mux_sequence_header(string(sps->bytes, sps->size), string(pps->bytes, pps->size), sh)) != srs_success) {
|
||||||
return srs_error_wrap(err, "mux sequence header");
|
return srs_error_wrap(err, "mux sequence header");
|
||||||
|
|
|
@ -755,25 +755,26 @@ srs_error_t SrsRtmpConn::playing(SrsSharedPtr<SrsLiveSource> source)
|
||||||
set_sock_options();
|
set_sock_options();
|
||||||
|
|
||||||
// Create a consumer of source.
|
// Create a consumer of source.
|
||||||
SrsLiveConsumer* consumer = NULL;
|
SrsLiveConsumer* consumer_raw = NULL;
|
||||||
SrsAutoFree(SrsLiveConsumer, consumer);
|
if ((err = source->create_consumer(consumer_raw)) != srs_success) {
|
||||||
if ((err = source->create_consumer(consumer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "rtmp: create consumer");
|
return srs_error_wrap(err, "rtmp: create consumer");
|
||||||
}
|
}
|
||||||
if ((err = source->consumer_dumps(consumer)) != srs_success) {
|
SrsUniquePtr<SrsLiveConsumer> consumer(consumer_raw);
|
||||||
|
|
||||||
|
if ((err = source->consumer_dumps(consumer.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: dumps consumer");
|
return srs_error_wrap(err, "rtmp: dumps consumer");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use receiving thread to receive packets from peer.
|
// Use receiving thread to receive packets from peer.
|
||||||
SrsQueueRecvThread trd(consumer, rtmp, SRS_PERF_MW_SLEEP, _srs_context->get_id());
|
SrsQueueRecvThread trd(consumer.get(), rtmp, SRS_PERF_MW_SLEEP, _srs_context->get_id());
|
||||||
|
|
||||||
if ((err = trd.start()) != srs_success) {
|
if ((err = trd.start()) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: start receive thread");
|
return srs_error_wrap(err, "rtmp: start receive thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deliver packets to peer.
|
// Deliver packets to peer.
|
||||||
wakable = consumer;
|
wakable = consumer.get();
|
||||||
err = do_playing(source, consumer, &trd);
|
err = do_playing(source, consumer.get(), &trd);
|
||||||
wakable = NULL;
|
wakable = NULL;
|
||||||
|
|
||||||
trd.stop();
|
trd.stop();
|
||||||
|
@ -795,8 +796,7 @@ srs_error_t SrsRtmpConn::do_playing(SrsSharedPtr<SrsLiveSource> source, SrsLiveC
|
||||||
srs_assert(consumer);
|
srs_assert(consumer);
|
||||||
|
|
||||||
// initialize other components
|
// initialize other components
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_play();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_rtmp_play());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
||||||
bool user_specified_duration_to_stop = (req->duration > 0);
|
bool user_specified_duration_to_stop = (req->duration > 0);
|
||||||
|
@ -816,9 +816,8 @@ srs_error_t SrsRtmpConn::do_playing(SrsSharedPtr<SrsLiveSource> source, SrsLiveC
|
||||||
srsu2msi(send_min_interval), srsu2msi(mw_sleep), mw_msgs, realtime, tcp_nodelay);
|
srsu2msi(send_min_interval), srsu2msi(mw_sleep), mw_msgs, realtime, tcp_nodelay);
|
||||||
|
|
||||||
#ifdef SRS_APM
|
#ifdef SRS_APM
|
||||||
ISrsApmSpan* span = _srs_apm->span("play-cycle")->set_kind(SrsApmKindProducer)->as_child(span_client_)
|
SrsUniquePtr<ISrsApmSpan> span(_srs_apm->span("play-cycle")->set_kind(SrsApmKindProducer)->as_child(span_client_)
|
||||||
->attr("realtime", srs_fmt("%d", realtime))->end();
|
->attr("realtime", srs_fmt("%d", realtime))->end());
|
||||||
SrsAutoFree(ISrsApmSpan, span);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -866,7 +865,7 @@ srs_error_t SrsRtmpConn::do_playing(SrsSharedPtr<SrsLiveSource> source, SrsLiveC
|
||||||
|
|
||||||
#ifdef SRS_APM
|
#ifdef SRS_APM
|
||||||
// TODO: Do not use pithy print for frame span.
|
// TODO: Do not use pithy print for frame span.
|
||||||
ISrsApmSpan* sample = _srs_apm->span("play-frame")->set_kind(SrsApmKindConsumer)->as_child(span)
|
ISrsApmSpan* sample = _srs_apm->span("play-frame")->set_kind(SrsApmKindConsumer)->as_child(span.get())
|
||||||
->attr("msgs", srs_fmt("%d", count))->attr("kbps", srs_fmt("%d", kbps->get_send_kbps_30s()));
|
->attr("msgs", srs_fmt("%d", count))->attr("kbps", srs_fmt("%d", kbps->get_send_kbps_30s()));
|
||||||
srs_freep(sample);
|
srs_freep(sample);
|
||||||
#endif
|
#endif
|
||||||
|
@ -974,8 +973,7 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPu
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsRequest* req = info->req;
|
SrsRequest* req = info->req;
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_rtmp_publish();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_rtmp_publish());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
// start isolate recv thread.
|
// start isolate recv thread.
|
||||||
// TODO: FIXME: Pass the callback here.
|
// TODO: FIXME: Pass the callback here.
|
||||||
|
@ -998,9 +996,8 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPu
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SRS_APM
|
#ifdef SRS_APM
|
||||||
ISrsApmSpan* span = _srs_apm->span("publish-cycle")->set_kind(SrsApmKindProducer)->as_child(span_client_)
|
SrsUniquePtr<ISrsApmSpan> span(_srs_apm->span("publish-cycle")->set_kind(SrsApmKindProducer)->as_child(span_client_)
|
||||||
->attr("timeout", srs_fmt("%d", srsu2msi(publish_normal_timeout)))->end();
|
->attr("timeout", srs_fmt("%d", srsu2msi(publish_normal_timeout)))->end());
|
||||||
SrsAutoFree(ISrsApmSpan, span);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Response the start publishing message, let client start to publish messages.
|
// Response the start publishing message, let client start to publish messages.
|
||||||
|
@ -1062,7 +1059,7 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSharedPtr<SrsLiveSource> source, SrsPu
|
||||||
|
|
||||||
#ifdef SRS_APM
|
#ifdef SRS_APM
|
||||||
// TODO: Do not use pithy print for frame span.
|
// TODO: Do not use pithy print for frame span.
|
||||||
ISrsApmSpan* sample = _srs_apm->span("publish-frame")->set_kind(SrsApmKindConsumer)->as_child(span)
|
ISrsApmSpan* sample = _srs_apm->span("publish-frame")->set_kind(SrsApmKindConsumer)->as_child(span.get())
|
||||||
->attr("msgs", srs_fmt("%" PRId64, nb_frames))->attr("kbps", srs_fmt("%d", kbps->get_recv_kbps_30s()));
|
->attr("msgs", srs_fmt("%" PRId64, nb_frames))->attr("kbps", srs_fmt("%d", kbps->get_recv_kbps_30s()));
|
||||||
srs_freep(sample);
|
srs_freep(sample);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1158,11 +1155,11 @@ srs_error_t SrsRtmpConn::handle_publish_message(SrsSharedPtr<SrsLiveSource>& sou
|
||||||
|
|
||||||
// process publish event.
|
// process publish event.
|
||||||
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
|
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt_raw = NULL;
|
||||||
if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) {
|
if ((err = rtmp->decode_message(msg, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: decode message");
|
return srs_error_wrap(err, "rtmp: decode message");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
// for flash, any packet is republish.
|
// for flash, any packet is republish.
|
||||||
if (info->type == SrsRtmpConnFlashPublish) {
|
if (info->type == SrsRtmpConnFlashPublish) {
|
||||||
|
@ -1173,8 +1170,8 @@ srs_error_t SrsRtmpConn::handle_publish_message(SrsSharedPtr<SrsLiveSource>& sou
|
||||||
}
|
}
|
||||||
|
|
||||||
// for fmle, drop others except the fmle start packet.
|
// for fmle, drop others except the fmle start packet.
|
||||||
if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
|
if (dynamic_cast<SrsFMLEStartPacket*>(pkt.get())) {
|
||||||
SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt);
|
SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt.get());
|
||||||
if ((err = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != srs_success) {
|
if ((err = rtmp->fmle_unpublish(info->res->stream_id, unpublish->transaction_id)) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: republish");
|
return srs_error_wrap(err, "rtmp: republish");
|
||||||
}
|
}
|
||||||
|
@ -1230,14 +1227,14 @@ srs_error_t SrsRtmpConn::process_publish_message(SrsSharedPtr<SrsLiveSource>& so
|
||||||
|
|
||||||
// process onMetaData
|
// process onMetaData
|
||||||
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
|
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt_raw = NULL;
|
||||||
if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) {
|
if ((err = rtmp->decode_message(msg, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: decode message");
|
return srs_error_wrap(err, "rtmp: decode message");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
if (dynamic_cast<SrsOnMetaDataPacket*>(pkt)) {
|
if (dynamic_cast<SrsOnMetaDataPacket*>(pkt.get())) {
|
||||||
SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt);
|
SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt.get());
|
||||||
if ((err = source->on_meta_data(msg, metadata)) != srs_success) {
|
if ((err = source->on_meta_data(msg, metadata)) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: consume metadata");
|
return srs_error_wrap(err, "rtmp: consume metadata");
|
||||||
}
|
}
|
||||||
|
@ -1249,27 +1246,27 @@ srs_error_t SrsRtmpConn::process_publish_message(SrsSharedPtr<SrsLiveSource>& so
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtmpConn::process_play_control_msg(SrsLiveConsumer* consumer, SrsCommonMessage* msg)
|
srs_error_t SrsRtmpConn::process_play_control_msg(SrsLiveConsumer* consumer, SrsCommonMessage* msg_raw)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
if (!msg) {
|
if (!msg_raw) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
if (!msg->header.is_amf0_command() && !msg->header.is_amf3_command()) {
|
if (!msg->header.is_amf0_command() && !msg->header.is_amf3_command()) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt_raw = NULL;
|
||||||
if ((err = rtmp->decode_message(msg, &pkt)) != srs_success) {
|
if ((err = rtmp->decode_message(msg.get(), &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: decode message");
|
return srs_error_wrap(err, "rtmp: decode message");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
// for jwplayer/flowplayer, which send close as pause message.
|
// for jwplayer/flowplayer, which send close as pause message.
|
||||||
SrsCloseStreamPacket* close = dynamic_cast<SrsCloseStreamPacket*>(pkt);
|
SrsCloseStreamPacket* close = dynamic_cast<SrsCloseStreamPacket*>(pkt.get());
|
||||||
if (close) {
|
if (close) {
|
||||||
return srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "rtmp: close stream");
|
return srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "rtmp: close stream");
|
||||||
}
|
}
|
||||||
|
@ -1277,7 +1274,7 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsLiveConsumer* consumer, Srs
|
||||||
// call msg,
|
// call msg,
|
||||||
// support response null first,
|
// support response null first,
|
||||||
// TODO: FIXME: response in right way, or forward in edge mode.
|
// TODO: FIXME: response in right way, or forward in edge mode.
|
||||||
SrsCallPacket* call = dynamic_cast<SrsCallPacket*>(pkt);
|
SrsCallPacket* call = dynamic_cast<SrsCallPacket*>(pkt.get());
|
||||||
if (call) {
|
if (call) {
|
||||||
// only response it when transaction id not zero,
|
// only response it when transaction id not zero,
|
||||||
// for the zero means donot need response.
|
// for the zero means donot need response.
|
||||||
|
@ -1293,7 +1290,7 @@ srs_error_t SrsRtmpConn::process_play_control_msg(SrsLiveConsumer* consumer, Srs
|
||||||
}
|
}
|
||||||
|
|
||||||
// pause
|
// pause
|
||||||
SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(pkt);
|
SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(pkt.get());
|
||||||
if (pause) {
|
if (pause) {
|
||||||
if ((err = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != srs_success) {
|
if ((err = rtmp->on_play_client_pause(info->res->stream_id, pause->is_pause)) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtmp: pause");
|
return srs_error_wrap(err, "rtmp: pause");
|
||||||
|
@ -1344,18 +1341,15 @@ srs_error_t SrsRtmpConn::check_edge_token_traverse_auth()
|
||||||
int port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
int port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
srs_parse_hostport(hostport, server, port);
|
srs_parse_hostport(hostport, server, port);
|
||||||
|
|
||||||
SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT);
|
SrsUniquePtr<SrsTcpClient> transport(new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT));
|
||||||
SrsAutoFree(SrsTcpClient, transport);
|
|
||||||
|
|
||||||
if ((err = transport->connect()) != srs_success) {
|
if ((err = transport->connect()) != srs_success) {
|
||||||
srs_warn("Illegal edge token, tcUrl=%s, %s", req->tcUrl.c_str(), srs_error_desc(err).c_str());
|
srs_warn("Illegal edge token, tcUrl=%s, %s", req->tcUrl.c_str(), srs_error_desc(err).c_str());
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtmpClient* client = new SrsRtmpClient(transport);
|
SrsUniquePtr<SrsRtmpClient> client(new SrsRtmpClient(transport.get()));
|
||||||
SrsAutoFree(SrsRtmpClient, client);
|
return do_token_traverse_auth(client.get());
|
||||||
return do_token_traverse_auth(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return srs_error_new(ERROR_EDGE_PORT_INVALID, "rtmp: Illegal edge token, server=%d", (int)args.size());
|
return srs_error_new(ERROR_EDGE_PORT_INVALID, "rtmp: Illegal edge token, server=%d", (int)args.size());
|
||||||
|
@ -1611,8 +1605,7 @@ srs_error_t SrsRtmpConn::cycle()
|
||||||
#ifdef SRS_APM
|
#ifdef SRS_APM
|
||||||
// Final APM span, parent is the last span, not the root span. Note that only client or server kind will be filtered
|
// Final APM span, parent is the last span, not the root span. Note that only client or server kind will be filtered
|
||||||
// for error or exception report.
|
// for error or exception report.
|
||||||
ISrsApmSpan* span_final = _srs_apm->span("final")->set_kind(SrsApmKindServer)->as_child(span_client_);
|
SrsUniquePtr<ISrsApmSpan> span_final(_srs_apm->span("final")->set_kind(SrsApmKindServer)->as_child(span_client_));
|
||||||
SrsAutoFree(ISrsApmSpan, span_final);
|
|
||||||
if (srs_error_code(err) != 0) {
|
if (srs_error_code(err) != 0) {
|
||||||
span_final->record_error(err)->set_status(SrsApmStatusError, srs_fmt("fail code=%d", srs_error_code(err)));
|
span_final->record_error(err)->set_status(SrsApmStatusError, srs_fmt("fail code=%d", srs_error_code(err)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1530,8 +1530,7 @@ srs_error_t SrsOriginHub::create_backend_forwarders(bool& applied)
|
||||||
std::string url = *it;
|
std::string url = *it;
|
||||||
|
|
||||||
// create temp Request by url
|
// create temp Request by url
|
||||||
SrsRequest* req = new SrsRequest();
|
SrsUniquePtr<SrsRequest> req(new SrsRequest());
|
||||||
SrsAutoFree(SrsRequest, req);
|
|
||||||
srs_parse_rtmp_url(url, req->tcUrl, req->stream);
|
srs_parse_rtmp_url(url, req->tcUrl, req->stream);
|
||||||
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);
|
srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);
|
||||||
|
|
||||||
|
@ -1543,7 +1542,7 @@ srs_error_t SrsOriginHub::create_backend_forwarders(bool& applied)
|
||||||
forward_server << req->host << ":" << req->port;
|
forward_server << req->host << ":" << req->port;
|
||||||
|
|
||||||
// initialize the forwarder with request.
|
// initialize the forwarder with request.
|
||||||
if ((err = forwarder->initialize(req, forward_server.str())) != srs_success) {
|
if ((err = forwarder->initialize(req.get(), forward_server.str())) != srs_success) {
|
||||||
return srs_error_wrap(err, "init backend forwarder failed, forward-to=%s", forward_server.str().c_str());
|
return srs_error_wrap(err, "init backend forwarder failed, forward-to=%s", forward_server.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2475,8 +2474,7 @@ srs_error_t SrsLiveSource::on_aggregate(SrsCommonMessage* msg)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsBuffer* stream = new SrsBuffer(msg->payload, msg->size);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(msg->payload, msg->size));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// the aggregate message always use abs time.
|
// the aggregate message always use abs time.
|
||||||
int delta = -1;
|
int delta = -1;
|
||||||
|
@ -2663,13 +2661,6 @@ srs_error_t SrsLiveSource::create_consumer(SrsLiveConsumer*& consumer)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
consumer = new SrsLiveConsumer(this);
|
|
||||||
consumers.push_back(consumer);
|
|
||||||
|
|
||||||
// There should be one consumer, so reset the timeout.
|
|
||||||
stream_die_at_ = 0;
|
|
||||||
publisher_idle_at_ = 0;
|
|
||||||
|
|
||||||
// for edge, when play edge stream, check the state
|
// for edge, when play edge stream, check the state
|
||||||
if (_srs_config->get_vhost_is_edge(req->vhost)) {
|
if (_srs_config->get_vhost_is_edge(req->vhost)) {
|
||||||
// notice edge to start for the first client.
|
// notice edge to start for the first client.
|
||||||
|
@ -2678,6 +2669,13 @@ srs_error_t SrsLiveSource::create_consumer(SrsLiveConsumer*& consumer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
consumer = new SrsLiveConsumer(this);
|
||||||
|
consumers.push_back(consumer);
|
||||||
|
|
||||||
|
// There are more than one consumer, so reset the timeout.
|
||||||
|
stream_die_at_ = 0;
|
||||||
|
publisher_idle_at_ = 0;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -439,8 +439,7 @@ srs_error_t SrsMpegtsSrtConn::do_publishing()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_srt_publish();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_srt_publish());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
int nb_packets = 0;
|
int nb_packets = 0;
|
||||||
|
|
||||||
|
@ -487,20 +486,20 @@ srs_error_t SrsMpegtsSrtConn::do_playing()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsSrtConsumer* consumer = NULL;
|
SrsSrtConsumer* consumer_raw = NULL;
|
||||||
SrsAutoFree(SrsSrtConsumer, consumer);
|
if ((err = srt_source_->create_consumer(consumer_raw)) != srs_success) {
|
||||||
if ((err = srt_source_->create_consumer(consumer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "create consumer, ts source=%s", req_->get_stream_url().c_str());
|
return srs_error_wrap(err, "create consumer, ts source=%s", req_->get_stream_url().c_str());
|
||||||
}
|
}
|
||||||
srs_assert(consumer);
|
|
||||||
|
srs_assert(consumer_raw);
|
||||||
|
SrsUniquePtr<SrsSrtConsumer> consumer(consumer_raw);
|
||||||
|
|
||||||
// TODO: FIXME: Dumps the SPS/PPS from gop cache, without other frames.
|
// TODO: FIXME: Dumps the SPS/PPS from gop cache, without other frames.
|
||||||
if ((err = srt_source_->consumer_dumps(consumer)) != srs_success) {
|
if ((err = srt_source_->consumer_dumps(consumer.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "dumps consumer, url=%s", req_->get_stream_url().c_str());
|
return srs_error_wrap(err, "dumps consumer, url=%s", req_->get_stream_url().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPithyPrint* pprint = SrsPithyPrint::create_srt_play();
|
SrsUniquePtr<SrsPithyPrint> pprint(SrsPithyPrint::create_srt_play());
|
||||||
SrsAutoFree(SrsPithyPrint, pprint);
|
|
||||||
|
|
||||||
SrsSrtRecvThread srt_recv_trd(srt_conn_);
|
SrsSrtRecvThread srt_recv_trd(srt_conn_);
|
||||||
if ((err = srt_recv_trd.start()) != srs_success) {
|
if ((err = srt_recv_trd.start()) != srs_success) {
|
||||||
|
@ -519,15 +518,16 @@ srs_error_t SrsMpegtsSrtConn::do_playing()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for amount of packets.
|
// Wait for amount of packets.
|
||||||
SrsSrtPacket* pkt = NULL;
|
SrsSrtPacket* pkt_raw = NULL;
|
||||||
SrsAutoFree(SrsSrtPacket, pkt);
|
consumer->dump_packet(&pkt_raw);
|
||||||
consumer->dump_packet(&pkt);
|
if (!pkt_raw) {
|
||||||
if (!pkt) {
|
|
||||||
// TODO: FIXME: We should check the quit event.
|
// TODO: FIXME: We should check the quit event.
|
||||||
consumer->wait(1, 1000 * SRS_UTIME_MILLISECONDS);
|
consumer->wait(1, 1000 * SRS_UTIME_MILLISECONDS);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SrsUniquePtr<SrsSrtPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
++nb_packets;
|
++nb_packets;
|
||||||
|
|
||||||
// reportable
|
// reportable
|
||||||
|
@ -580,11 +580,10 @@ srs_error_t SrsMpegtsSrtConn::on_srt_packet(char* buf, int nb_buf)
|
||||||
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet first=%#x", (uint8_t)buf[0]);
|
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet first=%#x", (uint8_t)buf[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSrtPacket* packet = new SrsSrtPacket();
|
SrsUniquePtr<SrsSrtPacket> packet(new SrsSrtPacket());
|
||||||
SrsAutoFree(SrsSrtPacket, packet);
|
|
||||||
packet->wrap(buf, nb_buf);
|
packet->wrap(buf, nb_buf);
|
||||||
|
|
||||||
if ((err = srt_source_->on_packet(packet)) != srs_success) {
|
if ((err = srt_source_->on_packet(packet.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "on srt packet");
|
return srs_error_wrap(err, "on srt packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -307,13 +307,11 @@ srs_error_t SrsSrtFrameBuilder::on_packet(SrsSrtPacket *pkt)
|
||||||
int nb_packet = nb_buf / SRS_TS_PACKET_SIZE;
|
int nb_packet = nb_buf / SRS_TS_PACKET_SIZE;
|
||||||
for (int i = 0; i < nb_packet; i++) {
|
for (int i = 0; i < nb_packet; i++) {
|
||||||
char* p = buf + (i * SRS_TS_PACKET_SIZE);
|
char* p = buf + (i * SRS_TS_PACKET_SIZE);
|
||||||
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(p, SRS_TS_PACKET_SIZE));
|
||||||
SrsBuffer* stream = new SrsBuffer(p, SRS_TS_PACKET_SIZE);
|
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// Process each ts packet. Note that the jitter of UDP may cause video glitch when packet loss or wrong seq. We
|
// Process each ts packet. Note that the jitter of UDP may cause video glitch when packet loss or wrong seq. We
|
||||||
// don't handle it because SRT will, see tlpktdrop at https://ossrs.net/lts/zh-cn/docs/v4/doc/srt-params
|
// don't handle it because SRT will, see tlpktdrop at https://ossrs.net/lts/zh-cn/docs/v4/doc/srt-params
|
||||||
if ((err = ts_ctx_->decode(stream, this)) != srs_success) {
|
if ((err = ts_ctx_->decode(stream.get(), this)) != srs_success) {
|
||||||
srs_warn("parse ts packet err=%s", srs_error_desc(err).c_str());
|
srs_warn("parse ts packet err=%s", srs_error_desc(err).c_str());
|
||||||
srs_error_reset(err);
|
srs_error_reset(err);
|
||||||
continue;
|
continue;
|
||||||
|
@ -391,8 +389,7 @@ srs_error_t SrsSrtFrameBuilder::on_ts_video_avc(SrsTsMessage* msg, SrsBuffer* av
|
||||||
|
|
||||||
vector<pair<char*, int> > ipb_frames;
|
vector<pair<char*, int> > ipb_frames;
|
||||||
|
|
||||||
SrsRawH264Stream* avc = new SrsRawH264Stream();
|
SrsUniquePtr<SrsRawH264Stream> avc(new SrsRawH264Stream());
|
||||||
SrsAutoFree(SrsRawH264Stream, avc);
|
|
||||||
|
|
||||||
// send each frame.
|
// send each frame.
|
||||||
while (!avs->empty()) {
|
while (!avs->empty()) {
|
||||||
|
@ -465,8 +462,7 @@ srs_error_t SrsSrtFrameBuilder::check_sps_pps_change(SrsTsMessage* msg)
|
||||||
uint32_t dts = (uint32_t)(msg->dts / 90);
|
uint32_t dts = (uint32_t)(msg->dts / 90);
|
||||||
|
|
||||||
std::string sh;
|
std::string sh;
|
||||||
SrsRawH264Stream* avc = new SrsRawH264Stream();
|
SrsUniquePtr<SrsRawH264Stream> avc(new SrsRawH264Stream());
|
||||||
SrsAutoFree(SrsRawH264Stream, avc);
|
|
||||||
|
|
||||||
if ((err = avc->mux_sequence_header(sps_, pps_, sh)) != srs_success) {
|
if ((err = avc->mux_sequence_header(sps_, pps_, sh)) != srs_success) {
|
||||||
return srs_error_wrap(err, "mux sequence header");
|
return srs_error_wrap(err, "mux sequence header");
|
||||||
|
@ -565,9 +561,7 @@ srs_error_t SrsSrtFrameBuilder::on_ts_video_hevc(SrsTsMessage *msg, SrsBuffer *a
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
vector<pair<char*, int> > ipb_frames;
|
vector<pair<char*, int> > ipb_frames;
|
||||||
|
SrsUniquePtr<SrsRawHEVCStream> hevc(new SrsRawHEVCStream());
|
||||||
SrsRawHEVCStream *hevc = new SrsRawHEVCStream();
|
|
||||||
SrsAutoFree(SrsRawHEVCStream, hevc);
|
|
||||||
|
|
||||||
std::vector<std::string> hevc_pps;
|
std::vector<std::string> hevc_pps;
|
||||||
// send each frame.
|
// send each frame.
|
||||||
|
@ -660,8 +654,7 @@ srs_error_t SrsSrtFrameBuilder::check_vps_sps_pps_change(SrsTsMessage* msg)
|
||||||
uint32_t dts = (uint32_t)(msg->dts / 90);
|
uint32_t dts = (uint32_t)(msg->dts / 90);
|
||||||
|
|
||||||
std::string sh;
|
std::string sh;
|
||||||
SrsRawHEVCStream* hevc = new SrsRawHEVCStream();
|
SrsUniquePtr<SrsRawHEVCStream> hevc(new SrsRawHEVCStream());
|
||||||
SrsAutoFree(SrsRawHEVCStream, hevc);
|
|
||||||
|
|
||||||
if ((err = hevc->mux_sequence_header(hevc_vps_, hevc_sps_, hevc_pps_, sh)) != srs_success) {
|
if ((err = hevc->mux_sequence_header(hevc_vps_, hevc_sps_, hevc_pps_, sh)) != srs_success) {
|
||||||
return srs_error_wrap(err, "mux sequence header");
|
return srs_error_wrap(err, "mux sequence header");
|
||||||
|
@ -766,8 +759,7 @@ srs_error_t SrsSrtFrameBuilder::on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsRawAacStream* aac = new SrsRawAacStream();
|
SrsUniquePtr<SrsRawAacStream> aac(new SrsRawAacStream());
|
||||||
SrsAutoFree(SrsRawAacStream, aac);
|
|
||||||
|
|
||||||
// ts tbn to flv tbn.
|
// ts tbn to flv tbn.
|
||||||
uint32_t pts = (uint32_t)(msg->pts / 90);
|
uint32_t pts = (uint32_t)(msg->pts / 90);
|
||||||
|
|
|
@ -706,11 +706,10 @@ srs_error_t SrsClsClient::report()
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsClsSugars* sugars = sugars_;
|
SrsUniquePtr<SrsClsSugars> sugars(sugars_);
|
||||||
SrsAutoFree(SrsClsSugars, sugars);
|
|
||||||
sugars_ = new SrsClsSugars();
|
sugars_ = new SrsClsSugars();
|
||||||
|
|
||||||
if ((err = send_logs(sugars)) != srs_success) {
|
if ((err = send_logs(sugars.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "cls");
|
return srs_error_wrap(err, "cls");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,16 +726,15 @@ srs_error_t SrsClsClient::do_send_logs(ISrsEncoder* sugar, int count, int total)
|
||||||
return srs_error_new(ERROR_CLS_EXCEED_SIZE, "exceed 5MB actual %d", size);
|
return srs_error_new(ERROR_CLS_EXCEED_SIZE, "exceed 5MB actual %d", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* buf = new char[size];
|
SrsUniquePtr<char[]> buf(new char[size]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
memset(buf, 0, size);
|
memset(buf.get(), 0, size);
|
||||||
SrsBuffer b(buf, size);
|
SrsBuffer b(buf.get(), size);
|
||||||
if ((err = sugar->encode(&b)) != srs_success) {
|
if ((err = sugar->encode(&b)) != srs_success) {
|
||||||
return srs_error_wrap(err, "encode log");
|
return srs_error_wrap(err, "encode log");
|
||||||
}
|
}
|
||||||
|
|
||||||
string body(buf, size);
|
string body(buf.get(), size);
|
||||||
|
|
||||||
// Write a CLS log to service specified by url.
|
// Write a CLS log to service specified by url.
|
||||||
string url = "http://" + endpoint_ + ":80/structuredlog?topic_id=" + topic_;
|
string url = "http://" + endpoint_ + ":80/structuredlog?topic_id=" + topic_;
|
||||||
|
@ -776,11 +774,11 @@ srs_error_t SrsClsClient::do_send_logs(ISrsEncoder* sugar, int count, int total)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start request and parse response.
|
// Start request and parse response.
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = http.post(path, body, &msg)) != srs_success) {
|
if ((err = http.post(path, body, &msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "http: client post");
|
return srs_error_wrap(err, "http: client post");
|
||||||
}
|
}
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
string res;
|
string res;
|
||||||
uint16_t code = msg->status_code();
|
uint16_t code = msg->status_code();
|
||||||
|
@ -819,10 +817,9 @@ srs_error_t SrsClsClient::send_logs(SrsClsSugars* sugars)
|
||||||
|
|
||||||
// Never do infinite loop, limit to a max loop and drop logs if exceed.
|
// Never do infinite loop, limit to a max loop and drop logs if exceed.
|
||||||
for (int i = 0; i < 128 && !sugars->empty(); ++i) {
|
for (int i = 0; i < 128 && !sugars->empty(); ++i) {
|
||||||
SrsClsSugars* v = sugars->slice(SRS_CLS_BATCH_MAX_LOG_SIZE);
|
SrsUniquePtr<SrsClsSugars> v(sugars->slice(SRS_CLS_BATCH_MAX_LOG_SIZE));
|
||||||
SrsAutoFree(SrsClsSugars, v);
|
|
||||||
|
|
||||||
if ((err = do_send_logs((ISrsEncoder*)v, v->size(), total)) != srs_success) {
|
if ((err = do_send_logs((ISrsEncoder*)v.get(), v->size(), total)) != srs_success) {
|
||||||
return srs_error_wrap(err, "send %d/%d/%d logs", v->size(), i, total);
|
return srs_error_wrap(err, "send %d/%d/%d logs", v->size(), i, total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2148,8 +2145,7 @@ srs_error_t SrsApmClient::do_report()
|
||||||
// Update statistaic for APM.
|
// Update statistaic for APM.
|
||||||
nn_spans_ += spans_.size();
|
nn_spans_ += spans_.size();
|
||||||
|
|
||||||
SrsOtelExportTraceServiceRequest* sugar = new SrsOtelExportTraceServiceRequest();
|
SrsUniquePtr<SrsOtelExportTraceServiceRequest> sugar(new SrsOtelExportTraceServiceRequest());
|
||||||
SrsAutoFree(SrsOtelExportTraceServiceRequest, sugar);
|
|
||||||
|
|
||||||
SrsOtelResourceSpans* rs = sugar->append();
|
SrsOtelResourceSpans* rs = sugar->append();
|
||||||
// See https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions
|
// See https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions
|
||||||
|
@ -2169,16 +2165,15 @@ srs_error_t SrsApmClient::do_report()
|
||||||
return srs_error_new(ERROR_APM_EXCEED_SIZE, "exceed 5MB actual %d", size);
|
return srs_error_new(ERROR_APM_EXCEED_SIZE, "exceed 5MB actual %d", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* buf = new char[size];
|
SrsUniquePtr<char[]> buf(new char[size]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
memset(buf, 0, size);
|
memset(buf.get(), 0, size);
|
||||||
SrsBuffer b(buf, size);
|
SrsBuffer b(buf.get(), size);
|
||||||
if ((err = sugar->encode(&b)) != srs_success) {
|
if ((err = sugar->encode(&b)) != srs_success) {
|
||||||
return srs_error_wrap(err, "encode log");
|
return srs_error_wrap(err, "encode log");
|
||||||
}
|
}
|
||||||
|
|
||||||
string body(buf, size);
|
string body(buf.get(), size);
|
||||||
|
|
||||||
// Write a CLS log to service specified by url.
|
// Write a CLS log to service specified by url.
|
||||||
string url = "http://" + endpoint_ + "/v1/traces";
|
string url = "http://" + endpoint_ + "/v1/traces";
|
||||||
|
@ -2204,11 +2199,11 @@ srs_error_t SrsApmClient::do_report()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start request and parse response.
|
// Start request and parse response.
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = http.post(path, body, &msg)) != srs_success) {
|
if ((err = http.post(path, body, &msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "http: client post");
|
return srs_error_wrap(err, "http: client post");
|
||||||
}
|
}
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
string res;
|
string res;
|
||||||
uint16_t code = msg->status_code();
|
uint16_t code = msg->status_code();
|
||||||
|
|
|
@ -9,79 +9,106 @@
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <stdlib.h>
|
// Unique ptr smart pointer, only support unique ptr, with limited APIs and features,
|
||||||
|
|
||||||
// The auto free helper, which is actually the unique ptr, without the move feature,
|
|
||||||
// see https://github.com/ossrs/srs/discussions/3667#discussioncomment-8969107
|
// see https://github.com/ossrs/srs/discussions/3667#discussioncomment-8969107
|
||||||
//
|
//
|
||||||
// To free the instance in the current scope, for instance, MyClass* ptr,
|
|
||||||
// which is a ptr and this class will:
|
|
||||||
// 1. free the ptr.
|
|
||||||
// 2. set ptr to NULL.
|
|
||||||
//
|
|
||||||
// Usage:
|
// Usage:
|
||||||
// MyClass* po = new MyClass();
|
// SrsUniquePtr<MyClass> ptr(new MyClass());
|
||||||
// // ...... use po
|
// ptr->do_something();
|
||||||
// SrsAutoFree(MyClass, po);
|
|
||||||
//
|
//
|
||||||
// Usage for array:
|
// Note that the ptr should be initialized before use it, or it will crash if not set, for example:
|
||||||
// MyClass** pa = new MyClass*[size];
|
// Myclass* p;
|
||||||
// // ....... use pa
|
// SrsUniquePtr<MyClass> ptr(p); // crash because p is an invalid pointer.
|
||||||
// SrsAutoFreeA(MyClass*, pa);
|
|
||||||
//
|
//
|
||||||
// @remark the MyClass can be basic type, for instance, SrsAutoFreeA(char, pstr),
|
// Note that do not support array or object created by malloc, because we only use delete to dispose
|
||||||
// where the char* pstr = new char[size].
|
// the resource.
|
||||||
// To delete object.
|
|
||||||
#define SrsAutoFree(className, instance) \
|
|
||||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, NULL)
|
|
||||||
// To delete array.
|
|
||||||
#define SrsAutoFreeA(className, instance) \
|
|
||||||
impl_SrsAutoFree<className> _auto_free_array_##instance(&instance, true, false, NULL)
|
|
||||||
// Use free instead of delete.
|
|
||||||
#define SrsAutoFreeF(className, instance) \
|
|
||||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, true, NULL)
|
|
||||||
// Use hook instead of delete.
|
|
||||||
#define SrsAutoFreeH(className, instance, hook) \
|
|
||||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, hook)
|
|
||||||
// The template implementation.
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class impl_SrsAutoFree
|
class SrsUniquePtr
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
T** ptr;
|
T* ptr_;
|
||||||
bool is_array;
|
|
||||||
bool _use_free;
|
|
||||||
void (*_hook)(T*);
|
|
||||||
public:
|
public:
|
||||||
// If use_free, use free(void*) to release the p.
|
SrsUniquePtr(T* ptr = NULL) {
|
||||||
// If specified hook, use hook(p) to release it.
|
ptr_ = ptr;
|
||||||
// Use delete to release p, or delete[] if p is an array.
|
|
||||||
impl_SrsAutoFree(T** p, bool array, bool use_free, void (*hook)(T*)) {
|
|
||||||
ptr = p;
|
|
||||||
is_array = array;
|
|
||||||
_use_free = use_free;
|
|
||||||
_hook = hook;
|
|
||||||
}
|
}
|
||||||
|
virtual ~SrsUniquePtr() {
|
||||||
virtual ~impl_SrsAutoFree() {
|
delete ptr_;
|
||||||
if (ptr == NULL || *ptr == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_use_free) {
|
|
||||||
free(*ptr);
|
|
||||||
} else if (_hook) {
|
|
||||||
_hook(*ptr);
|
|
||||||
} else {
|
|
||||||
if (is_array) {
|
|
||||||
delete[] *ptr;
|
|
||||||
} else {
|
|
||||||
delete *ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*ptr = NULL;
|
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
|
// Get the object.
|
||||||
|
T* get() {
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
// Overload the -> operator.
|
||||||
|
T* operator->() {
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
// Copy the unique ptr.
|
||||||
|
SrsUniquePtr(const SrsUniquePtr<T>&) = delete;
|
||||||
|
// The assign operator.
|
||||||
|
SrsUniquePtr<T>& operator=(const SrsUniquePtr<T>&) = delete;
|
||||||
|
private:
|
||||||
|
// Overload the * operator.
|
||||||
|
T& operator*() = delete;
|
||||||
|
// Overload the bool operator.
|
||||||
|
operator bool() const = delete;
|
||||||
|
#if __cplusplus >= 201103L // C++11
|
||||||
|
private:
|
||||||
|
// The move constructor.
|
||||||
|
SrsUniquePtr(SrsUniquePtr<T>&&) = delete;
|
||||||
|
// The move assign operator.
|
||||||
|
SrsUniquePtr<T>& operator=(SrsUniquePtr<T>&&) = delete;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
// The unique ptr for array objects, only support unique ptr, with limited APIs and features,
|
||||||
|
// see https://github.com/ossrs/srs/discussions/3667#discussioncomment-8969107
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// SrsUniquePtr<MyClass[]> ptr(new MyClass[10]);
|
||||||
|
// ptr[0]->do_something();
|
||||||
|
template<class T>
|
||||||
|
class SrsUniquePtr<T[]>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T* ptr_;
|
||||||
|
public:
|
||||||
|
SrsUniquePtr(T* ptr = NULL) {
|
||||||
|
ptr_ = ptr;
|
||||||
|
}
|
||||||
|
virtual ~SrsUniquePtr() {
|
||||||
|
delete[] ptr_;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
// Get the object.
|
||||||
|
T* get() {
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
// Overload the [] operator.
|
||||||
|
T& operator[](std::size_t index) {
|
||||||
|
return ptr_[index];
|
||||||
|
}
|
||||||
|
const T& operator[](std::size_t index) const {
|
||||||
|
return ptr_[index];
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
// Copy the unique ptr.
|
||||||
|
SrsUniquePtr(const SrsUniquePtr<T>&) = delete;
|
||||||
|
// The assign operator.
|
||||||
|
SrsUniquePtr<T>& operator=(const SrsUniquePtr<T>&) = delete;
|
||||||
|
private:
|
||||||
|
// Overload the * operator.
|
||||||
|
T& operator*() = delete;
|
||||||
|
// Overload the bool operator.
|
||||||
|
operator bool() const = delete;
|
||||||
|
#if __cplusplus >= 201103L // C++11
|
||||||
|
private:
|
||||||
|
// The move constructor.
|
||||||
|
SrsUniquePtr(SrsUniquePtr<T>&&) = delete;
|
||||||
|
// The move assign operator.
|
||||||
|
SrsUniquePtr<T>& operator=(SrsUniquePtr<T>&&) = delete;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// Shared ptr smart pointer, only support shared ptr, no weak ptr, no shared from this, no inheritance,
|
// Shared ptr smart pointer, only support shared ptr, no weak ptr, no shared from this, no inheritance,
|
||||||
|
|
8
trunk/src/core/srs_core_deprecated.cpp
Normal file
8
trunk/src/core/srs_core_deprecated.cpp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2013-2024 The SRS Authors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
95
trunk/src/core/srs_core_deprecated.hpp
Normal file
95
trunk/src/core/srs_core_deprecated.hpp
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2013-2024 The SRS Authors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SRS_CORE_DEPRECATED_HPP
|
||||||
|
#define SRS_CORE_DEPRECATED_HPP
|
||||||
|
|
||||||
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// Note that the SrsAutoFree is deprecated, please use SrsUniquePtr instead.
|
||||||
|
//
|
||||||
|
// Note: Please use SrsUniquePtr if possible. Please aware that there is a slight difference between SrsAutoFree
|
||||||
|
// and SrsUniquePtr. SrsAutoFree will track the address of pointer, while SrsUniquePtr will not.
|
||||||
|
// MyClass* p;
|
||||||
|
// SrsAutoFree(MyClass, p); // p will be freed even p is changed later.
|
||||||
|
// SrsUniquePtr ptr(p); // crash because p is an invalid pointer.
|
||||||
|
//
|
||||||
|
// The auto free helper, which is actually the unique ptr, without the move feature,
|
||||||
|
// see https://github.com/ossrs/srs/discussions/3667#discussioncomment-8969107
|
||||||
|
//
|
||||||
|
// To free the instance in the current scope, for instance, MyClass* ptr,
|
||||||
|
// which is a ptr and this class will:
|
||||||
|
// 1. free the ptr.
|
||||||
|
// 2. set ptr to NULL.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// MyClass* po = new MyClass();
|
||||||
|
// // ...... use po
|
||||||
|
// SrsAutoFree(MyClass, po);
|
||||||
|
//
|
||||||
|
// Usage for array:
|
||||||
|
// MyClass** pa = new MyClass*[size];
|
||||||
|
// // ....... use pa
|
||||||
|
// SrsAutoFreeA(MyClass*, pa);
|
||||||
|
//
|
||||||
|
// @remark the MyClass can be basic type, for instance, SrsAutoFreeA(char, pstr),
|
||||||
|
// where the char* pstr = new char[size].
|
||||||
|
// To delete object.
|
||||||
|
#define SrsAutoFree(className, instance) \
|
||||||
|
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, NULL)
|
||||||
|
// To delete array.
|
||||||
|
#define SrsAutoFreeA(className, instance) \
|
||||||
|
impl_SrsAutoFree<className> _auto_free_array_##instance(&instance, true, false, NULL)
|
||||||
|
// Use free instead of delete.
|
||||||
|
#define SrsAutoFreeF(className, instance) \
|
||||||
|
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, true, NULL)
|
||||||
|
// Use hook instead of delete.
|
||||||
|
#define SrsAutoFreeH(className, instance, hook) \
|
||||||
|
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, hook)
|
||||||
|
// The template implementation.
|
||||||
|
template<class T>
|
||||||
|
class impl_SrsAutoFree
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T** ptr;
|
||||||
|
bool is_array;
|
||||||
|
bool _use_free;
|
||||||
|
void (*_hook)(T*);
|
||||||
|
public:
|
||||||
|
// If use_free, use free(void*) to release the p.
|
||||||
|
// If specified hook, use hook(p) to release it.
|
||||||
|
// Use delete to release p, or delete[] if p is an array.
|
||||||
|
impl_SrsAutoFree(T** p, bool array, bool use_free, void (*hook)(T*)) {
|
||||||
|
ptr = p;
|
||||||
|
is_array = array;
|
||||||
|
_use_free = use_free;
|
||||||
|
_hook = hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~impl_SrsAutoFree() {
|
||||||
|
if (ptr == NULL || *ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_use_free) {
|
||||||
|
free(*ptr);
|
||||||
|
} else if (_hook) {
|
||||||
|
_hook(*ptr);
|
||||||
|
} else {
|
||||||
|
if (is_array) {
|
||||||
|
delete[] *ptr;
|
||||||
|
} else {
|
||||||
|
delete *ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*ptr = NULL;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 6
|
#define VERSION_MAJOR 6
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 135
|
#define VERSION_REVISION 136
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -54,8 +54,7 @@ srs_error_t SrsAacTransmuxer::write_audio(int64_t timestamp, char* data, int siz
|
||||||
|
|
||||||
timestamp &= 0x7fffffff;
|
timestamp &= 0x7fffffff;
|
||||||
|
|
||||||
SrsBuffer* stream = new SrsBuffer(data, size);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(data, size));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// audio decode
|
// audio decode
|
||||||
if (!stream->require(1)) {
|
if (!stream->require(1)) {
|
||||||
|
|
|
@ -730,13 +730,12 @@ srs_error_t SrsVideoFrame::parse_avc_b_frame(const SrsSample* sample, bool& is_b
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer* stream = new SrsBuffer(sample->bytes, sample->size);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(sample->bytes, sample->size));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// Skip nalu header.
|
// Skip nalu header.
|
||||||
stream->skip(1);
|
stream->skip(1);
|
||||||
|
|
||||||
SrsBitBuffer bitstream(stream);
|
SrsBitBuffer bitstream(stream.get());
|
||||||
int32_t first_mb_in_slice = 0;
|
int32_t first_mb_in_slice = 0;
|
||||||
if ((err = srs_avc_nalu_read_uev(&bitstream, first_mb_in_slice)) != srs_success) {
|
if ((err = srs_avc_nalu_read_uev(&bitstream, first_mb_in_slice)) != srs_success) {
|
||||||
return srs_error_wrap(err, "nalu read uev");
|
return srs_error_wrap(err, "nalu read uev");
|
||||||
|
@ -794,8 +793,7 @@ srs_error_t SrsFormat::on_audio(int64_t timestamp, char* data, int size)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(data, size);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(data, size));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
|
||||||
|
|
||||||
// We already checked the size is positive and data is not NULL.
|
// We already checked the size is positive and data is not NULL.
|
||||||
srs_assert(buffer->require(1));
|
srs_assert(buffer->require(1));
|
||||||
|
@ -824,10 +822,10 @@ srs_error_t SrsFormat::on_audio(int64_t timestamp, char* data, int size)
|
||||||
buffer->skip(-1 * buffer->pos());
|
buffer->skip(-1 * buffer->pos());
|
||||||
|
|
||||||
if (codec == SrsAudioCodecIdMP3) {
|
if (codec == SrsAudioCodecIdMP3) {
|
||||||
return audio_mp3_demux(buffer, timestamp, fresh);
|
return audio_mp3_demux(buffer.get(), timestamp, fresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
return audio_aac_demux(buffer, timestamp);
|
return audio_aac_demux(buffer.get(), timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsFormat::on_video(int64_t timestamp, char* data, int size)
|
srs_error_t SrsFormat::on_video(int64_t timestamp, char* data, int size)
|
||||||
|
@ -839,10 +837,8 @@ srs_error_t SrsFormat::on_video(int64_t timestamp, char* data, int size)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(data, size);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(data, size));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
return video_avc_demux(buffer.get(), timestamp);
|
||||||
|
|
||||||
return video_avc_demux(buffer, timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsFormat::on_aac_sequence_header(char* data, int size)
|
srs_error_t SrsFormat::on_aac_sequence_header(char* data, int size)
|
||||||
|
@ -2808,8 +2804,7 @@ srs_error_t SrsFormat::audio_aac_sequence_header_demux(char* data, int size)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(data, size);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(data, size));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
|
||||||
|
|
||||||
// only need to decode the first 2bytes:
|
// only need to decode the first 2bytes:
|
||||||
// audioObjectType, aac_profile, 5bits.
|
// audioObjectType, aac_profile, 5bits.
|
||||||
|
|
|
@ -585,8 +585,7 @@ void SrsFlvTransmuxer::cache_metadata(char type, char* data, int size, char* cac
|
||||||
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
SrsBuffer* tag_stream = new SrsBuffer(cache, 11);
|
SrsUniquePtr<SrsBuffer> tag_stream(new SrsBuffer(cache, 11));
|
||||||
SrsAutoFree(SrsBuffer, tag_stream);
|
|
||||||
|
|
||||||
// write data size.
|
// write data size.
|
||||||
tag_stream->write_1bytes(type);
|
tag_stream->write_1bytes(type);
|
||||||
|
@ -611,8 +610,7 @@ void SrsFlvTransmuxer::cache_audio(int64_t timestamp, char* data, int size, char
|
||||||
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
SrsBuffer* tag_stream = new SrsBuffer(cache, 11);
|
SrsUniquePtr<SrsBuffer> tag_stream(new SrsBuffer(cache, 11));
|
||||||
SrsAutoFree(SrsBuffer, tag_stream);
|
|
||||||
|
|
||||||
// write data size.
|
// write data size.
|
||||||
tag_stream->write_1bytes(SrsFrameTypeAudio);
|
tag_stream->write_1bytes(SrsFrameTypeAudio);
|
||||||
|
@ -638,8 +636,7 @@ void SrsFlvTransmuxer::cache_video(int64_t timestamp, char* data, int size, char
|
||||||
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
(char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0.
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
SrsBuffer* tag_stream = new SrsBuffer(cache, 11);
|
SrsUniquePtr<SrsBuffer> tag_stream(new SrsBuffer(cache, 11));
|
||||||
SrsAutoFree(SrsBuffer, tag_stream);
|
|
||||||
|
|
||||||
// write data size.
|
// write data size.
|
||||||
tag_stream->write_1bytes(SrsFrameTypeVideo);
|
tag_stream->write_1bytes(SrsFrameTypeVideo);
|
||||||
|
@ -652,8 +649,7 @@ void SrsFlvTransmuxer::cache_video(int64_t timestamp, char* data, int size, char
|
||||||
|
|
||||||
void SrsFlvTransmuxer::cache_pts(int size, char* cache)
|
void SrsFlvTransmuxer::cache_pts(int size, char* cache)
|
||||||
{
|
{
|
||||||
SrsBuffer* tag_stream = new SrsBuffer(cache, 11);
|
SrsUniquePtr<SrsBuffer> tag_stream(new SrsBuffer(cache, 11));
|
||||||
SrsAutoFree(SrsBuffer, tag_stream);
|
|
||||||
tag_stream->write_4bytes(size);
|
tag_stream->write_4bytes(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,8 +857,7 @@ srs_error_t SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart
|
||||||
return srs_error_wrap(err, "read tag header");
|
return srs_error_wrap(err, "read tag header");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer* tag_stream = new SrsBuffer(tag_header, SRS_FLV_TAG_HEADER_SIZE);
|
SrsUniquePtr<SrsBuffer> tag_stream(new SrsBuffer(tag_header, SRS_FLV_TAG_HEADER_SIZE));
|
||||||
SrsAutoFree(SrsBuffer, tag_stream);
|
|
||||||
|
|
||||||
int8_t tag_type = tag_stream->read_1bytes();
|
int8_t tag_type = tag_stream->read_1bytes();
|
||||||
int32_t data_size = tag_stream->read_3bytes();
|
int32_t data_size = tag_stream->read_3bytes();
|
||||||
|
|
|
@ -75,8 +75,7 @@ srs_error_t SrsMp3Transmuxer::write_audio(int64_t timestamp, char* data, int siz
|
||||||
|
|
||||||
timestamp &= 0x7fffffff;
|
timestamp &= 0x7fffffff;
|
||||||
|
|
||||||
SrsBuffer* stream = new SrsBuffer(data, size);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(data, size));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// audio decode
|
// audio decode
|
||||||
if (!stream->require(1)) {
|
if (!stream->require(1)) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <srs_kernel_io.hpp>
|
#include <srs_kernel_io.hpp>
|
||||||
#include <srs_kernel_utility.hpp>
|
#include <srs_kernel_utility.hpp>
|
||||||
#include <srs_kernel_buffer.hpp>
|
#include <srs_kernel_buffer.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -36,10 +37,8 @@ srs_error_t srs_mp4_write_box(ISrsWriter* writer, ISrsCodec* box)
|
||||||
int nb_data = box->nb_bytes();
|
int nb_data = box->nb_bytes();
|
||||||
std::vector<char> data(nb_data);
|
std::vector<char> data(nb_data);
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(&data[0], nb_data);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(&data[0], nb_data));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = box->encode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = box->encode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "encode box");
|
return srs_error_wrap(err, "encode box");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5316,6 +5315,7 @@ srs_error_t SrsMp4BoxReader::read(SrsSimpleStream* stream, SrsMp4Box** ppbox)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsMp4Box* box = NULL;
|
SrsMp4Box* box = NULL;
|
||||||
|
// Note that we should use SrsAutoFree to free the ptr which is set later.
|
||||||
SrsAutoFree(SrsMp4Box, box);
|
SrsAutoFree(SrsMp4Box, box);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -5339,11 +5339,10 @@ srs_error_t SrsMp4BoxReader::read(SrsSimpleStream* stream, SrsMp4Box** ppbox)
|
||||||
stream->append(buf, (int)nread);
|
stream->append(buf, (int)nread);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(stream->bytes(), stream->length());
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(stream->bytes(), stream->length()));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
|
||||||
|
|
||||||
// Discovery the box with basic header.
|
// Discovery the box with basic header.
|
||||||
if (!box && (err = SrsMp4Box::discovery(buffer, &box)) != srs_success) {
|
if (!box && (err = SrsMp4Box::discovery(buffer.get(), &box)) != srs_success) {
|
||||||
if (srs_error_code(err) == ERROR_MP4_BOX_REQUIRE_SPACE) {
|
if (srs_error_code(err) == ERROR_MP4_BOX_REQUIRE_SPACE) {
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
continue;
|
continue;
|
||||||
|
@ -5431,15 +5430,14 @@ srs_error_t SrsMp4Decoder::initialize(ISrsReadSeeker* rs)
|
||||||
off_t offset = -1;
|
off_t offset = -1;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SrsMp4Box* box = NULL;
|
SrsMp4Box* box_raw = NULL;
|
||||||
SrsAutoFree(SrsMp4Box, box);
|
if ((err = load_next_box(&box_raw, 0)) != srs_success) {
|
||||||
|
|
||||||
if ((err = load_next_box(&box, 0)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "load box");
|
return srs_error_wrap(err, "load box");
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsMp4Box> box(box_raw);
|
||||||
|
|
||||||
if (box->is_ftyp()) {
|
if (box->is_ftyp()) {
|
||||||
SrsMp4FileTypeBox* ftyp = dynamic_cast<SrsMp4FileTypeBox*>(box);
|
SrsMp4FileTypeBox* ftyp = dynamic_cast<SrsMp4FileTypeBox*>(box.get());
|
||||||
if ((err = parse_ftyp(ftyp)) != srs_success) {
|
if ((err = parse_ftyp(ftyp)) != srs_success) {
|
||||||
return srs_error_wrap(err, "parse ftyp");
|
return srs_error_wrap(err, "parse ftyp");
|
||||||
}
|
}
|
||||||
|
@ -5450,7 +5448,7 @@ srs_error_t SrsMp4Decoder::initialize(ISrsReadSeeker* rs)
|
||||||
}
|
}
|
||||||
offset = off_t(cur - box->sz());
|
offset = off_t(cur - box->sz());
|
||||||
} else if (box->is_moov()) {
|
} else if (box->is_moov()) {
|
||||||
SrsMp4MovieBox* moov = dynamic_cast<SrsMp4MovieBox*>(box);
|
SrsMp4MovieBox* moov = dynamic_cast<SrsMp4MovieBox*>(box.get());
|
||||||
if ((err = parse_moov(moov)) != srs_success) {
|
if ((err = parse_moov(moov)) != srs_success) {
|
||||||
return srs_error_wrap(err, "parse moov");
|
return srs_error_wrap(err, "parse moov");
|
||||||
}
|
}
|
||||||
|
@ -5653,6 +5651,7 @@ srs_error_t SrsMp4Decoder::load_next_box(SrsMp4Box** ppbox, uint32_t required_bo
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SrsMp4Box* box = NULL;
|
SrsMp4Box* box = NULL;
|
||||||
|
// Note that we should use SrsAutoFree to free the ptr which is set later.
|
||||||
SrsAutoFree(SrsMp4Box, box);
|
SrsAutoFree(SrsMp4Box, box);
|
||||||
|
|
||||||
if ((err = do_load_next_box(&box, required_box_type)) != srs_success) {
|
if ((err = do_load_next_box(&box, required_box_type)) != srs_success) {
|
||||||
|
@ -5680,15 +5679,14 @@ srs_error_t SrsMp4Decoder::do_load_next_box(SrsMp4Box** ppbox, uint32_t required
|
||||||
return srs_error_wrap(err, "read box");
|
return srs_error_wrap(err, "read box");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(stream->bytes(), stream->length());
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(stream->bytes(), stream->length()));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
|
||||||
|
|
||||||
// Decode the box:
|
// Decode the box:
|
||||||
// 1. Any box, when no box type is required.
|
// 1. Any box, when no box type is required.
|
||||||
// 2. Matched box, when box type match the required type.
|
// 2. Matched box, when box type match the required type.
|
||||||
// 3. Mdat box, always decode the mdat because we only decode the header of it.
|
// 3. Mdat box, always decode the mdat because we only decode the header of it.
|
||||||
if (!required_box_type || (uint32_t)box->type == required_box_type || box->is_mdat()) {
|
if (!required_box_type || (uint32_t)box->type == required_box_type || box->is_mdat()) {
|
||||||
err = box->decode(buffer);
|
err = box->decode(buffer.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip the box from stream, move stream to next box.
|
// Skip the box from stream, move stream to next box.
|
||||||
|
@ -5741,8 +5739,7 @@ srs_error_t SrsMp4Encoder::initialize(ISrsWriteSeeker* ws)
|
||||||
|
|
||||||
// Write ftyp box.
|
// Write ftyp box.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsMp4FileTypeBox* ftyp = new SrsMp4FileTypeBox();
|
SrsUniquePtr<SrsMp4FileTypeBox> ftyp(new SrsMp4FileTypeBox());
|
||||||
SrsAutoFree(SrsMp4FileTypeBox, ftyp);
|
|
||||||
|
|
||||||
ftyp->major_brand = SrsMp4BoxBrandISOM;
|
ftyp->major_brand = SrsMp4BoxBrandISOM;
|
||||||
ftyp->minor_version = 512;
|
ftyp->minor_version = 512;
|
||||||
|
@ -5751,10 +5748,8 @@ srs_error_t SrsMp4Encoder::initialize(ISrsWriteSeeker* ws)
|
||||||
int nb_data = ftyp->nb_bytes();
|
int nb_data = ftyp->nb_bytes();
|
||||||
std::vector<char> data(nb_data);
|
std::vector<char> data(nb_data);
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(&data[0], nb_data);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(&data[0], nb_data));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = ftyp->encode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = ftyp->encode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "encode ftyp");
|
return srs_error_wrap(err, "encode ftyp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5766,16 +5761,13 @@ srs_error_t SrsMp4Encoder::initialize(ISrsWriteSeeker* ws)
|
||||||
|
|
||||||
// 8B reserved free box.
|
// 8B reserved free box.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsMp4FreeSpaceBox* freeb = new SrsMp4FreeSpaceBox(SrsMp4BoxTypeFREE);
|
SrsUniquePtr<SrsMp4FreeSpaceBox> freeb(new SrsMp4FreeSpaceBox(SrsMp4BoxTypeFREE));
|
||||||
SrsAutoFree(SrsMp4FreeSpaceBox, freeb);
|
|
||||||
|
|
||||||
int nb_data = freeb->nb_bytes();
|
int nb_data = freeb->nb_bytes();
|
||||||
std::vector<char> data(nb_data);
|
std::vector<char> data(nb_data);
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(&data[0], nb_data);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(&data[0], nb_data));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = freeb->encode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = freeb->encode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "encode free box");
|
return srs_error_wrap(err, "encode free box");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5789,8 +5781,7 @@ srs_error_t SrsMp4Encoder::initialize(ISrsWriteSeeker* ws)
|
||||||
// Write empty mdat box,
|
// Write empty mdat box,
|
||||||
// its payload will be writen by samples,
|
// its payload will be writen by samples,
|
||||||
// and we will update its header(size) when flush.
|
// and we will update its header(size) when flush.
|
||||||
SrsMp4MediaDataBox* mdat = new SrsMp4MediaDataBox();
|
SrsUniquePtr<SrsMp4MediaDataBox> mdat(new SrsMp4MediaDataBox());
|
||||||
SrsAutoFree(SrsMp4MediaDataBox, mdat);
|
|
||||||
|
|
||||||
// Update the mdat box from this offset.
|
// Update the mdat box from this offset.
|
||||||
if ((err = wsio->lseek(0, SEEK_CUR, &mdat_offset)) != srs_success) {
|
if ((err = wsio->lseek(0, SEEK_CUR, &mdat_offset)) != srs_success) {
|
||||||
|
@ -5798,18 +5789,15 @@ srs_error_t SrsMp4Encoder::initialize(ISrsWriteSeeker* ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
int nb_data = mdat->sz_header();
|
int nb_data = mdat->sz_header();
|
||||||
uint8_t* data = new uint8_t[nb_data];
|
SrsUniquePtr<uint8_t[]> data(new uint8_t[nb_data]);
|
||||||
SrsAutoFreeA(uint8_t, data);
|
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer((char*)data, nb_data);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer((char*)data.get(), nb_data));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = mdat->encode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = mdat->encode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "encode mdat");
|
return srs_error_wrap(err, "encode mdat");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: Ensure all bytes are writen.
|
// TODO: FIXME: Ensure all bytes are writen.
|
||||||
if ((err = wsio->write(data, nb_data, NULL)) != srs_success) {
|
if ((err = wsio->write(data.get(), nb_data, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write mdat");
|
return srs_error_wrap(err, "write mdat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5874,8 +5862,7 @@ srs_error_t SrsMp4Encoder::flush()
|
||||||
|
|
||||||
// Write moov.
|
// Write moov.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsMp4MovieBox* moov = new SrsMp4MovieBox();
|
SrsUniquePtr<SrsMp4MovieBox> moov(new SrsMp4MovieBox());
|
||||||
SrsAutoFree(SrsMp4MovieBox, moov);
|
|
||||||
|
|
||||||
SrsMp4MovieHeaderBox* mvhd = new SrsMp4MovieHeaderBox();
|
SrsMp4MovieHeaderBox* mvhd = new SrsMp4MovieHeaderBox();
|
||||||
moov->set_mvhd(mvhd);
|
moov->set_mvhd(mvhd);
|
||||||
|
@ -6057,23 +6044,20 @@ srs_error_t SrsMp4Encoder::flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = samples->write(moov)) != srs_success) {
|
if ((err = samples->write(moov.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "write samples");
|
return srs_error_wrap(err, "write samples");
|
||||||
}
|
}
|
||||||
|
|
||||||
int nb_data = moov->nb_bytes();
|
int nb_data = moov->nb_bytes();
|
||||||
uint8_t* data = new uint8_t[nb_data];
|
SrsUniquePtr<uint8_t[]> data(new uint8_t[nb_data]);
|
||||||
SrsAutoFreeA(uint8_t, data);
|
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer((char*)data, nb_data);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer((char*)data.get(), nb_data));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = moov->encode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = moov->encode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "encode moov");
|
return srs_error_wrap(err, "encode moov");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: Ensure all bytes are writen.
|
// TODO: FIXME: Ensure all bytes are writen.
|
||||||
if ((err = wsio->write(data, nb_data, NULL)) != srs_success) {
|
if ((err = wsio->write(data.get(), nb_data, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write moov");
|
return srs_error_wrap(err, "write moov");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6083,21 +6067,17 @@ srs_error_t SrsMp4Encoder::flush()
|
||||||
// Write mdat box with size of data,
|
// Write mdat box with size of data,
|
||||||
// its payload already writen by samples,
|
// its payload already writen by samples,
|
||||||
// and we will update its header(size) when flush.
|
// and we will update its header(size) when flush.
|
||||||
SrsMp4MediaDataBox* mdat = new SrsMp4MediaDataBox();
|
SrsUniquePtr<SrsMp4MediaDataBox> mdat(new SrsMp4MediaDataBox());
|
||||||
SrsAutoFree(SrsMp4MediaDataBox, mdat);
|
|
||||||
|
|
||||||
// Update the size of mdat first, for over 2GB file.
|
// Update the size of mdat first, for over 2GB file.
|
||||||
mdat->nb_data = mdat_bytes;
|
mdat->nb_data = mdat_bytes;
|
||||||
mdat->update_size();
|
mdat->update_size();
|
||||||
|
|
||||||
int nb_data = mdat->sz_header();
|
int nb_data = mdat->sz_header();
|
||||||
uint8_t* data = new uint8_t[nb_data];
|
SrsUniquePtr<uint8_t[]> data(new uint8_t[nb_data]);
|
||||||
SrsAutoFreeA(uint8_t, data);
|
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer((char*)data, nb_data);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer((char*)data.get(), nb_data));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = mdat->encode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = mdat->encode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "encode mdat");
|
return srs_error_wrap(err, "encode mdat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6117,7 +6097,7 @@ srs_error_t SrsMp4Encoder::flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: Ensure all bytes are writen.
|
// TODO: FIXME: Ensure all bytes are writen.
|
||||||
if ((err = wsio->write(data, nb_data, NULL)) != srs_success) {
|
if ((err = wsio->write(data.get(), nb_data, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write mdat");
|
return srs_error_wrap(err, "write mdat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6231,22 +6211,20 @@ srs_error_t SrsMp4M2tsInitEncoder::write(SrsFormat* format, bool video, int tid)
|
||||||
|
|
||||||
// Write ftyp box.
|
// Write ftyp box.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsMp4FileTypeBox* ftyp = new SrsMp4FileTypeBox();
|
SrsUniquePtr<SrsMp4FileTypeBox> ftyp(new SrsMp4FileTypeBox());
|
||||||
SrsAutoFree(SrsMp4FileTypeBox, ftyp);
|
|
||||||
|
|
||||||
ftyp->major_brand = SrsMp4BoxBrandISO5;
|
ftyp->major_brand = SrsMp4BoxBrandISO5;
|
||||||
ftyp->minor_version = 512;
|
ftyp->minor_version = 512;
|
||||||
ftyp->set_compatible_brands(SrsMp4BoxBrandISO6, SrsMp4BoxBrandMP41);
|
ftyp->set_compatible_brands(SrsMp4BoxBrandISO6, SrsMp4BoxBrandMP41);
|
||||||
|
|
||||||
if ((err = srs_mp4_write_box(writer, ftyp)) != srs_success) {
|
if ((err = srs_mp4_write_box(writer, ftyp.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "write ftyp");
|
return srs_error_wrap(err, "write ftyp");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write moov.
|
// Write moov.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsMp4MovieBox* moov = new SrsMp4MovieBox();
|
SrsUniquePtr<SrsMp4MovieBox> moov(new SrsMp4MovieBox());
|
||||||
SrsAutoFree(SrsMp4MovieBox, moov);
|
|
||||||
|
|
||||||
SrsMp4MovieHeaderBox* mvhd = new SrsMp4MovieHeaderBox();
|
SrsMp4MovieHeaderBox* mvhd = new SrsMp4MovieHeaderBox();
|
||||||
moov->set_mvhd(mvhd);
|
moov->set_mvhd(mvhd);
|
||||||
|
@ -6456,7 +6434,7 @@ srs_error_t SrsMp4M2tsInitEncoder::write(SrsFormat* format, bool video, int tid)
|
||||||
trex->default_sample_description_index = 1;
|
trex->default_sample_description_index = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = srs_mp4_write_box(writer, moov)) != srs_success) {
|
if ((err = srs_mp4_write_box(writer, moov.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "write moov");
|
return srs_error_wrap(err, "write moov");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6492,8 +6470,7 @@ srs_error_t SrsMp4M2tsSegmentEncoder::initialize(ISrsWriter* w, uint32_t sequenc
|
||||||
|
|
||||||
// Write styp box.
|
// Write styp box.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsMp4SegmentTypeBox* styp = new SrsMp4SegmentTypeBox();
|
SrsUniquePtr<SrsMp4SegmentTypeBox> styp(new SrsMp4SegmentTypeBox());
|
||||||
SrsAutoFree(SrsMp4SegmentTypeBox, styp);
|
|
||||||
|
|
||||||
styp->major_brand = SrsMp4BoxBrandMSDH;
|
styp->major_brand = SrsMp4BoxBrandMSDH;
|
||||||
styp->minor_version = 0;
|
styp->minor_version = 0;
|
||||||
|
@ -6502,7 +6479,7 @@ srs_error_t SrsMp4M2tsSegmentEncoder::initialize(ISrsWriter* w, uint32_t sequenc
|
||||||
// Used for sidx to calcalute the referenced size.
|
// Used for sidx to calcalute the referenced size.
|
||||||
styp_bytes = styp->nb_bytes();
|
styp_bytes = styp->nb_bytes();
|
||||||
|
|
||||||
if ((err = srs_mp4_write_box(writer, styp)) != srs_success) {
|
if ((err = srs_mp4_write_box(writer, styp.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "write styp");
|
return srs_error_wrap(err, "write styp");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6556,8 +6533,7 @@ srs_error_t SrsMp4M2tsSegmentEncoder::flush(uint64_t& dts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Although the sidx is not required to start play DASH, but it's required for AV sync.
|
// Although the sidx is not required to start play DASH, but it's required for AV sync.
|
||||||
SrsMp4SegmentIndexBox* sidx = new SrsMp4SegmentIndexBox();
|
SrsUniquePtr<SrsMp4SegmentIndexBox> sidx(new SrsMp4SegmentIndexBox());
|
||||||
SrsAutoFree(SrsMp4SegmentIndexBox, sidx);
|
|
||||||
if (true) {
|
if (true) {
|
||||||
sidx->version = 1;
|
sidx->version = 1;
|
||||||
sidx->reference_id = 1;
|
sidx->reference_id = 1;
|
||||||
|
@ -6580,13 +6556,11 @@ srs_error_t SrsMp4M2tsSegmentEncoder::flush(uint64_t& dts)
|
||||||
// Create a mdat box.
|
// Create a mdat box.
|
||||||
// its payload will be writen by samples,
|
// its payload will be writen by samples,
|
||||||
// and we will update its header(size) when flush.
|
// and we will update its header(size) when flush.
|
||||||
SrsMp4MediaDataBox* mdat = new SrsMp4MediaDataBox();
|
SrsUniquePtr<SrsMp4MediaDataBox> mdat(new SrsMp4MediaDataBox());
|
||||||
SrsAutoFree(SrsMp4MediaDataBox, mdat);
|
|
||||||
|
|
||||||
// Write moof.
|
// Write moof.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsMp4MovieFragmentBox* moof = new SrsMp4MovieFragmentBox();
|
SrsUniquePtr<SrsMp4MovieFragmentBox> moof(new SrsMp4MovieFragmentBox());
|
||||||
SrsAutoFree(SrsMp4MovieFragmentBox, moof);
|
|
||||||
|
|
||||||
SrsMp4MovieFragmentHeaderBox* mfhd = new SrsMp4MovieFragmentHeaderBox();
|
SrsMp4MovieFragmentHeaderBox* mfhd = new SrsMp4MovieFragmentHeaderBox();
|
||||||
moof->set_mfhd(mfhd);
|
moof->set_mfhd(mfhd);
|
||||||
|
@ -6611,7 +6585,7 @@ srs_error_t SrsMp4M2tsSegmentEncoder::flush(uint64_t& dts)
|
||||||
SrsMp4TrackFragmentRunBox* trun = new SrsMp4TrackFragmentRunBox();
|
SrsMp4TrackFragmentRunBox* trun = new SrsMp4TrackFragmentRunBox();
|
||||||
traf->set_trun(trun);
|
traf->set_trun(trun);
|
||||||
|
|
||||||
if ((err = samples->write(moof, dts)) != srs_success) {
|
if ((err = samples->write(moof.get(), dts)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write samples");
|
return srs_error_wrap(err, "write samples");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6623,11 +6597,11 @@ srs_error_t SrsMp4M2tsSegmentEncoder::flush(uint64_t& dts)
|
||||||
// Update the size of sidx.
|
// Update the size of sidx.
|
||||||
SrsMp4SegmentIndexEntry* entry = &sidx->entries[0];
|
SrsMp4SegmentIndexEntry* entry = &sidx->entries[0];
|
||||||
entry->referenced_size = moof_bytes + mdat->nb_bytes();
|
entry->referenced_size = moof_bytes + mdat->nb_bytes();
|
||||||
if ((err = srs_mp4_write_box(writer, sidx)) != srs_success) {
|
if ((err = srs_mp4_write_box(writer, sidx.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "write sidx");
|
return srs_error_wrap(err, "write sidx");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = srs_mp4_write_box(writer, moof)) != srs_success) {
|
if ((err = srs_mp4_write_box(writer, moof.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "write moof");
|
return srs_error_wrap(err, "write moof");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6635,18 +6609,15 @@ srs_error_t SrsMp4M2tsSegmentEncoder::flush(uint64_t& dts)
|
||||||
// Write mdat.
|
// Write mdat.
|
||||||
if (true) {
|
if (true) {
|
||||||
int nb_data = mdat->sz_header();
|
int nb_data = mdat->sz_header();
|
||||||
uint8_t* data = new uint8_t[nb_data];
|
SrsUniquePtr<uint8_t[]> data(new uint8_t[nb_data]);
|
||||||
SrsAutoFreeA(uint8_t, data);
|
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer((char*)data, nb_data);
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer((char*)data.get(), nb_data));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = mdat->encode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = mdat->encode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "encode mdat");
|
return srs_error_wrap(err, "encode mdat");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: Ensure all bytes are writen.
|
// TODO: FIXME: Ensure all bytes are writen.
|
||||||
if ((err = writer->write(data, nb_data, NULL)) != srs_success) {
|
if ((err = writer->write(data.get(), nb_data, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write mdat");
|
return srs_error_wrap(err, "write mdat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,7 @@ srs_error_t SrsPsContext::decode(SrsBuffer* stream, ISrsPsMessageHandler* handle
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reap the last completed PS message.
|
// Reap the last completed PS message.
|
||||||
SrsTsMessage* msg = reap();
|
SrsUniquePtr<SrsTsMessage> msg(reap());
|
||||||
SrsAutoFree(SrsTsMessage, msg);
|
|
||||||
|
|
||||||
if (msg->sid == SrsTsPESStreamIdProgramStreamMap) {
|
if (msg->sid == SrsTsPESStreamIdProgramStreamMap) {
|
||||||
if (!msg->payload || !msg->payload->length()) {
|
if (!msg->payload || !msg->payload->length()) {
|
||||||
|
@ -136,7 +135,7 @@ srs_error_t SrsPsContext::decode(SrsBuffer* stream, ISrsPsMessageHandler* handle
|
||||||
helper_.pack_nn_msgs_++;
|
helper_.pack_nn_msgs_++;
|
||||||
|
|
||||||
//srs_error("PS: Got message %s, dts=%" PRId64 ", payload=%dB", msg->is_video() ? "Video" : "Audio", msg->dts/9000, msg->PES_packet_length);
|
//srs_error("PS: Got message %s, dts=%" PRId64 ", payload=%dB", msg->is_video() ? "Video" : "Audio", msg->dts/9000, msg->PES_packet_length);
|
||||||
if (handler && (err = handler->on_ts_message(msg)) != srs_success) {
|
if (handler && (err = handler->on_ts_message(msg.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "handle PS message");
|
return srs_error_wrap(err, "handle PS message");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -257,20 +257,20 @@ srs_error_t SrsTsContext::decode(SrsBuffer* stream, ISrsTsHandler* handler)
|
||||||
// parse util EOF of stream.
|
// parse util EOF of stream.
|
||||||
// for example, parse multiple times for the PES_packet_length(0) packet.
|
// for example, parse multiple times for the PES_packet_length(0) packet.
|
||||||
while (!stream->empty()) {
|
while (!stream->empty()) {
|
||||||
SrsTsPacket* packet = new SrsTsPacket(this);
|
SrsUniquePtr<SrsTsPacket> packet(new SrsTsPacket(this));
|
||||||
SrsAutoFree(SrsTsPacket, packet);
|
|
||||||
|
|
||||||
SrsTsMessage* msg = NULL;
|
SrsTsMessage* msg_raw = NULL;
|
||||||
if ((err = packet->decode(stream, &msg)) != srs_success) {
|
if ((err = packet->decode(stream, &msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: ts packet decode");
|
return srs_error_wrap(err, "ts: ts packet decode");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msg) {
|
if (!msg_raw) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsTsMessage, msg);
|
|
||||||
|
|
||||||
if ((err = handler->on_ts_message(msg)) != srs_success) {
|
SrsUniquePtr<SrsTsMessage> msg(msg_raw);
|
||||||
|
|
||||||
|
if ((err = handler->on_ts_message(msg.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: handle ts message");
|
return srs_error_wrap(err, "ts: handle ts message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,46 +381,42 @@ srs_error_t SrsTsContext::encode_pat_pmt(ISrsStreamWriter* writer, int16_t vpid,
|
||||||
int16_t pmt_number = TS_PMT_NUMBER;
|
int16_t pmt_number = TS_PMT_NUMBER;
|
||||||
int16_t pmt_pid = TS_PMT_PID;
|
int16_t pmt_pid = TS_PMT_PID;
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsTsPacket* pkt = SrsTsPacket::create_pat(this, pmt_number, pmt_pid);
|
SrsUniquePtr<SrsTsPacket> pkt(SrsTsPacket::create_pat(this, pmt_number, pmt_pid));
|
||||||
SrsAutoFree(SrsTsPacket, pkt);
|
|
||||||
|
|
||||||
pkt->sync_byte = sync_byte;
|
pkt->sync_byte = sync_byte;
|
||||||
|
|
||||||
char* buf = new char[SRS_TS_PACKET_SIZE];
|
SrsUniquePtr<char[]> buf(new char[SRS_TS_PACKET_SIZE]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
// set the left bytes with 0xFF.
|
// set the left bytes with 0xFF.
|
||||||
int nb_buf = pkt->size();
|
int nb_buf = pkt->size();
|
||||||
srs_assert(nb_buf < SRS_TS_PACKET_SIZE);
|
srs_assert(nb_buf < SRS_TS_PACKET_SIZE);
|
||||||
memset(buf + nb_buf, 0xFF, SRS_TS_PACKET_SIZE - nb_buf);
|
memset(buf.get() + nb_buf, 0xFF, SRS_TS_PACKET_SIZE - nb_buf);
|
||||||
|
|
||||||
SrsBuffer stream(buf, nb_buf);
|
SrsBuffer stream(buf.get(), nb_buf);
|
||||||
if ((err = pkt->encode(&stream)) != srs_success) {
|
if ((err = pkt->encode(&stream)) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: encode packet");
|
return srs_error_wrap(err, "ts: encode packet");
|
||||||
}
|
}
|
||||||
if ((err = writer->write(buf, SRS_TS_PACKET_SIZE, NULL)) != srs_success) {
|
if ((err = writer->write(buf.get(), SRS_TS_PACKET_SIZE, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: write packet");
|
return srs_error_wrap(err, "ts: write packet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsTsPacket* pkt = SrsTsPacket::create_pmt(this, pmt_number, pmt_pid, vpid, vs, apid, as);
|
SrsUniquePtr<SrsTsPacket> pkt(SrsTsPacket::create_pmt(this, pmt_number, pmt_pid, vpid, vs, apid, as));
|
||||||
SrsAutoFree(SrsTsPacket, pkt);
|
|
||||||
|
|
||||||
pkt->sync_byte = sync_byte;
|
pkt->sync_byte = sync_byte;
|
||||||
|
|
||||||
char* buf = new char[SRS_TS_PACKET_SIZE];
|
SrsUniquePtr<char[]> buf(new char[SRS_TS_PACKET_SIZE]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
// set the left bytes with 0xFF.
|
// set the left bytes with 0xFF.
|
||||||
int nb_buf = pkt->size();
|
int nb_buf = pkt->size();
|
||||||
srs_assert(nb_buf < SRS_TS_PACKET_SIZE);
|
srs_assert(nb_buf < SRS_TS_PACKET_SIZE);
|
||||||
memset(buf + nb_buf, 0xFF, SRS_TS_PACKET_SIZE - nb_buf);
|
memset(buf.get() + nb_buf, 0xFF, SRS_TS_PACKET_SIZE - nb_buf);
|
||||||
|
|
||||||
SrsBuffer stream(buf, nb_buf);
|
SrsBuffer stream(buf.get(), nb_buf);
|
||||||
if ((err = pkt->encode(&stream)) != srs_success) {
|
if ((err = pkt->encode(&stream)) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: encode packet");
|
return srs_error_wrap(err, "ts: encode packet");
|
||||||
}
|
}
|
||||||
if ((err = writer->write(buf, SRS_TS_PACKET_SIZE, NULL)) != srs_success) {
|
if ((err = writer->write(buf.get(), SRS_TS_PACKET_SIZE, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: write packet");
|
return srs_error_wrap(err, "ts: write packet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,7 +457,7 @@ srs_error_t SrsTsContext::encode_pes(ISrsStreamWriter* writer, SrsTsMessage* msg
|
||||||
char* p = start;
|
char* p = start;
|
||||||
|
|
||||||
while (p < end) {
|
while (p < end) {
|
||||||
SrsTsPacket* pkt = NULL;
|
SrsTsPacket* pkt_raw = NULL;
|
||||||
if (p == start) {
|
if (p == start) {
|
||||||
// write pcr according to message.
|
// write pcr according to message.
|
||||||
bool write_pcr = msg->write_pcr;
|
bool write_pcr = msg->write_pcr;
|
||||||
|
@ -485,19 +481,18 @@ srs_error_t SrsTsContext::encode_pes(ISrsStreamWriter* writer, SrsTsMessage* msg
|
||||||
int64_t pcr = write_pcr? msg->dts : -1;
|
int64_t pcr = write_pcr? msg->dts : -1;
|
||||||
|
|
||||||
// TODO: FIXME: finger it why use discontinuity of msg.
|
// TODO: FIXME: finger it why use discontinuity of msg.
|
||||||
pkt = SrsTsPacket::create_pes_first(this,
|
pkt_raw = SrsTsPacket::create_pes_first(this,
|
||||||
pid, msg->sid, channel->continuity_counter++, msg->is_discontinuity,
|
pid, msg->sid, channel->continuity_counter++, msg->is_discontinuity,
|
||||||
pcr, msg->dts, msg->pts, msg->payload->length()
|
pcr, msg->dts, msg->pts, msg->payload->length()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
pkt = SrsTsPacket::create_pes_continue(this, pid, msg->sid, channel->continuity_counter++);
|
pkt_raw = SrsTsPacket::create_pes_continue(this, pid, msg->sid, channel->continuity_counter++);
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsTsPacket, pkt);
|
SrsUniquePtr<SrsTsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
pkt->sync_byte = sync_byte;
|
pkt->sync_byte = sync_byte;
|
||||||
|
|
||||||
char* buf = new char[SRS_TS_PACKET_SIZE];
|
SrsUniquePtr<char[]> buf(new char[SRS_TS_PACKET_SIZE]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
// set the left bytes with 0xFF.
|
// set the left bytes with 0xFF.
|
||||||
int nb_buf = pkt->size();
|
int nb_buf = pkt->size();
|
||||||
|
@ -507,7 +502,7 @@ srs_error_t SrsTsContext::encode_pes(ISrsStreamWriter* writer, SrsTsMessage* msg
|
||||||
int nb_stuffings = SRS_TS_PACKET_SIZE - nb_buf - left;
|
int nb_stuffings = SRS_TS_PACKET_SIZE - nb_buf - left;
|
||||||
if (nb_stuffings > 0) {
|
if (nb_stuffings > 0) {
|
||||||
// set all bytes to stuffings.
|
// set all bytes to stuffings.
|
||||||
memset(buf, 0xFF, SRS_TS_PACKET_SIZE);
|
memset(buf.get(), 0xFF, SRS_TS_PACKET_SIZE);
|
||||||
|
|
||||||
// padding with stuffings.
|
// padding with stuffings.
|
||||||
pkt->padding(nb_stuffings);
|
pkt->padding(nb_stuffings);
|
||||||
|
@ -520,14 +515,14 @@ srs_error_t SrsTsContext::encode_pes(ISrsStreamWriter* writer, SrsTsMessage* msg
|
||||||
nb_stuffings = SRS_TS_PACKET_SIZE - nb_buf - left;
|
nb_stuffings = SRS_TS_PACKET_SIZE - nb_buf - left;
|
||||||
srs_assert(nb_stuffings == 0);
|
srs_assert(nb_stuffings == 0);
|
||||||
}
|
}
|
||||||
memcpy(buf + nb_buf, p, left);
|
memcpy(buf.get() + nb_buf, p, left);
|
||||||
p += left;
|
p += left;
|
||||||
|
|
||||||
SrsBuffer stream(buf, nb_buf);
|
SrsBuffer stream(buf.get(), nb_buf);
|
||||||
if ((err = pkt->encode(&stream)) != srs_success) {
|
if ((err = pkt->encode(&stream)) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: encode packet");
|
return srs_error_wrap(err, "ts: encode packet");
|
||||||
}
|
}
|
||||||
if ((err = writer->write(buf, SRS_TS_PACKET_SIZE, NULL)) != srs_success) {
|
if ((err = writer->write(buf.get(), SRS_TS_PACKET_SIZE, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "ts: write packet");
|
return srs_error_wrap(err, "ts: write packet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2774,13 +2769,12 @@ srs_error_t SrsEncFileWriter::write(void* data, size_t count, ssize_t* pnwrite)
|
||||||
if (nb_buf == HLS_AES_ENCRYPT_BLOCK_LENGTH) {
|
if (nb_buf == HLS_AES_ENCRYPT_BLOCK_LENGTH) {
|
||||||
nb_buf = 0;
|
nb_buf = 0;
|
||||||
|
|
||||||
char* cipher = new char[HLS_AES_ENCRYPT_BLOCK_LENGTH];
|
SrsUniquePtr<char[]> cipher(new char[HLS_AES_ENCRYPT_BLOCK_LENGTH]);
|
||||||
SrsAutoFreeA(char, cipher);
|
|
||||||
|
|
||||||
AES_KEY* k = (AES_KEY*)key;
|
AES_KEY* k = (AES_KEY*)key;
|
||||||
AES_cbc_encrypt((unsigned char *)buf, (unsigned char *)cipher, HLS_AES_ENCRYPT_BLOCK_LENGTH, k, iv, AES_ENCRYPT);
|
AES_cbc_encrypt((unsigned char *)buf, (unsigned char *)cipher.get(), HLS_AES_ENCRYPT_BLOCK_LENGTH, k, iv, AES_ENCRYPT);
|
||||||
|
|
||||||
if ((err = SrsFileWriter::write(cipher, HLS_AES_ENCRYPT_BLOCK_LENGTH, pnwrite)) != srs_success) {
|
if ((err = SrsFileWriter::write(cipher.get(), HLS_AES_ENCRYPT_BLOCK_LENGTH, pnwrite)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write cipher");
|
return srs_error_wrap(err, "write cipher");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2810,14 +2804,13 @@ void SrsEncFileWriter::close()
|
||||||
memset(buf + nb_buf, nb_padding, nb_padding);
|
memset(buf + nb_buf, nb_padding, nb_padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* cipher = new char[nb_buf + nb_padding];
|
SrsUniquePtr<char[]> cipher(new char[nb_buf + nb_padding]);
|
||||||
SrsAutoFreeA(char, cipher);
|
|
||||||
|
|
||||||
AES_KEY* k = (AES_KEY*)key;
|
AES_KEY* k = (AES_KEY*)key;
|
||||||
AES_cbc_encrypt((unsigned char *)buf, (unsigned char *)cipher, nb_buf + nb_padding, k, iv, AES_ENCRYPT);
|
AES_cbc_encrypt((unsigned char *)buf, (unsigned char *)cipher.get(), nb_buf + nb_padding, k, iv, AES_ENCRYPT);
|
||||||
|
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
if ((err = SrsFileWriter::write(cipher, nb_buf + nb_padding, NULL)) != srs_success) {
|
if ((err = SrsFileWriter::write(cipher.get(), nb_buf + nb_padding, NULL)) != srs_success) {
|
||||||
srs_warn("ignore err %s", srs_error_desc(err).c_str());
|
srs_warn("ignore err %s", srs_error_desc(err).c_str());
|
||||||
srs_error_reset(err);
|
srs_error_reset(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ using namespace std;
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
#include <srs_kernel_buffer.hpp>
|
#include <srs_kernel_buffer.hpp>
|
||||||
#include <srs_kernel_flv.hpp>
|
#include <srs_kernel_flv.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
// this value must:
|
// this value must:
|
||||||
// equals to (SRS_SYS_CYCLE_INTERVAL*SRS_SYS_TIME_RESOLUTION_MS_TIMES)*1000
|
// equals to (SRS_SYS_CYCLE_INTERVAL*SRS_SYS_TIME_RESOLUTION_MS_TIMES)*1000
|
||||||
|
|
|
@ -294,11 +294,10 @@ int SrsIngestHlsInput::parseTs(ISrsTsHandler* handler, char* body, int nb_body)
|
||||||
int nb_packet = (int)nb_body / SRS_TS_PACKET_SIZE;
|
int nb_packet = (int)nb_body / SRS_TS_PACKET_SIZE;
|
||||||
for (int i = 0; i < nb_packet; i++) {
|
for (int i = 0; i < nb_packet; i++) {
|
||||||
char* p = (char*)body + (i * SRS_TS_PACKET_SIZE);
|
char* p = (char*)body + (i * SRS_TS_PACKET_SIZE);
|
||||||
SrsBuffer* stream = new SrsBuffer(p, SRS_TS_PACKET_SIZE);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(p, SRS_TS_PACKET_SIZE));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// process each ts packet
|
// process each ts packet
|
||||||
if ((err = context->decode(stream, handler)) != srs_success) {
|
if ((err = context->decode(stream.get(), handler)) != srs_success) {
|
||||||
// TODO: FIXME: Use error
|
// TODO: FIXME: Use error
|
||||||
ret = srs_error_code(err);
|
ret = srs_error_code(err);
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
|
@ -316,8 +315,7 @@ int SrsIngestHlsInput::parseAac(ISrsAacHandler* handler, char* body, int nb_body
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
SrsBuffer* stream = new SrsBuffer(body, nb_body);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(body, nb_body));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
// atleast 2bytes.
|
// atleast 2bytes.
|
||||||
if (!stream->require(3)) {
|
if (!stream->require(3)) {
|
||||||
|
@ -384,8 +382,8 @@ int SrsIngestHlsInput::parseM3u8(SrsHttpUri* url, double& td, double& duration)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = client.get(url->get_path(), "", &msg)) != srs_success) {
|
if ((err = client.get(url->get_path(), "", &msg_raw)) != srs_success) {
|
||||||
// TODO: FIXME: Use error
|
// TODO: FIXME: Use error
|
||||||
ret = srs_error_code(err);
|
ret = srs_error_code(err);
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
|
@ -393,8 +391,8 @@ int SrsIngestHlsInput::parseM3u8(SrsHttpUri* url, double& td, double& duration)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(msg);
|
srs_assert(msg_raw);
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
std::string body;
|
std::string body;
|
||||||
if ((err = msg->body_read_all(body)) != srs_success) {
|
if ((err = msg->body_read_all(body)) != srs_success) {
|
||||||
|
@ -619,8 +617,8 @@ int SrsIngestHlsInput::SrsTsPiece::fetch(string m3u8)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg_raw = NULL;
|
||||||
if ((err = client.get(uri.get_path(), "", &msg)) != srs_success) {
|
if ((err = client.get(uri.get_path(), "", &msg_raw)) != srs_success) {
|
||||||
// TODO: FIXME: Use error
|
// TODO: FIXME: Use error
|
||||||
ret = srs_error_code(err);
|
ret = srs_error_code(err);
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
|
@ -628,8 +626,8 @@ int SrsIngestHlsInput::SrsTsPiece::fetch(string m3u8)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(msg);
|
srs_assert(msg_raw);
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
if ((err = msg->body_read_all(body)) != srs_success) {
|
if ((err = msg->body_read_all(body)) != srs_success) {
|
||||||
// TODO: FIXME: Use error
|
// TODO: FIXME: Use error
|
||||||
|
@ -912,8 +910,7 @@ int SrsIngestHlsOutput::parse_message_queue()
|
||||||
srs_assert(!queue.empty());
|
srs_assert(!queue.empty());
|
||||||
std::multimap<int64_t, SrsTsMessage*>::iterator it = queue.begin();
|
std::multimap<int64_t, SrsTsMessage*>::iterator it = queue.begin();
|
||||||
|
|
||||||
SrsTsMessage* msg = it->second;
|
SrsUniquePtr<SrsTsMessage> msg(it->second);
|
||||||
SrsAutoFree(SrsTsMessage, msg);
|
|
||||||
queue.erase(it);
|
queue.erase(it);
|
||||||
|
|
||||||
if (msg->channel->stream == SrsTsStreamVideoH264) {
|
if (msg->channel->stream == SrsTsStreamVideoH264) {
|
||||||
|
@ -925,12 +922,12 @@ int SrsIngestHlsOutput::parse_message_queue()
|
||||||
|
|
||||||
// publish audio or video.
|
// publish audio or video.
|
||||||
if (msg->channel->stream == SrsTsStreamVideoH264) {
|
if (msg->channel->stream == SrsTsStreamVideoH264) {
|
||||||
if ((ret = on_ts_video(msg, &avs)) != ERROR_SUCCESS) {
|
if ((ret = on_ts_video(msg.get(), &avs)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg->channel->stream == SrsTsStreamAudioAAC) {
|
if (msg->channel->stream == SrsTsStreamAudioAAC) {
|
||||||
if ((ret = on_ts_audio(msg, &avs)) != ERROR_SUCCESS) {
|
if ((ret = on_ts_audio(msg.get(), &avs)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -947,8 +944,7 @@ int SrsIngestHlsOutput::flush_message_queue()
|
||||||
while (!queue.empty()) {
|
while (!queue.empty()) {
|
||||||
std::multimap<int64_t, SrsTsMessage*>::iterator it = queue.begin();
|
std::multimap<int64_t, SrsTsMessage*>::iterator it = queue.begin();
|
||||||
|
|
||||||
SrsTsMessage* msg = it->second;
|
SrsUniquePtr<SrsTsMessage> msg(it->second);
|
||||||
SrsAutoFree(SrsTsMessage, msg);
|
|
||||||
queue.erase(it);
|
queue.erase(it);
|
||||||
|
|
||||||
// parse the stream.
|
// parse the stream.
|
||||||
|
@ -956,12 +952,12 @@ int SrsIngestHlsOutput::flush_message_queue()
|
||||||
|
|
||||||
// publish audio or video.
|
// publish audio or video.
|
||||||
if (msg->channel->stream == SrsTsStreamVideoH264) {
|
if (msg->channel->stream == SrsTsStreamVideoH264) {
|
||||||
if ((ret = on_ts_video(msg, &avs)) != ERROR_SUCCESS) {
|
if ((ret = on_ts_video(msg.get(), &avs)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg->channel->stream == SrsTsStreamAudioAAC) {
|
if (msg->channel->stream == SrsTsStreamAudioAAC) {
|
||||||
if ((ret = on_ts_audio(msg, &avs)) != ERROR_SUCCESS) {
|
if ((ret = on_ts_audio(msg.get(), &avs)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,29 +55,27 @@ srs_error_t parse(std::string mp4_file, bool verbose)
|
||||||
}
|
}
|
||||||
srs_trace("MP4 box reader open success");
|
srs_trace("MP4 box reader open success");
|
||||||
|
|
||||||
SrsSimpleStream* stream = new SrsSimpleStream();
|
SrsUniquePtr<SrsSimpleStream> stream(new SrsSimpleStream());
|
||||||
SrsAutoFree(SrsSimpleStream, stream);
|
|
||||||
|
|
||||||
fprintf(stderr, "\n%s\n", mp4_file.c_str());
|
fprintf(stderr, "\n%s\n", mp4_file.c_str());
|
||||||
while (true) {
|
while (true) {
|
||||||
SrsMp4Box* box = NULL;
|
SrsMp4Box* box = NULL;
|
||||||
|
// Note that we should use SrsAutoFree to free the ptr which is set later.
|
||||||
SrsAutoFree(SrsMp4Box, box);
|
SrsAutoFree(SrsMp4Box, box);
|
||||||
|
|
||||||
if ((err = br.read(stream, &box)) != srs_success) {
|
if ((err = br.read(stream.get(), &box)) != srs_success) {
|
||||||
if (srs_error_code(err) == ERROR_SYSTEM_FILE_EOF) {
|
if (srs_error_code(err) == ERROR_SYSTEM_FILE_EOF) {
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
return srs_error_wrap(err, "read box");
|
return srs_error_wrap(err, "read box");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(stream->bytes(), stream->length());
|
SrsUniquePtr<SrsBuffer> buffer(new SrsBuffer(stream->bytes(), stream->length()));
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
if ((err = box->decode(buffer.get())) != srs_success) {
|
||||||
|
|
||||||
if ((err = box->decode(buffer)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "decode box");
|
return srs_error_wrap(err, "decode box");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = br.skip(box, stream)) != srs_success) {
|
if ((err = br.skip(box, stream.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "skip box");
|
return srs_error_wrap(err, "skip box");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,19 +201,18 @@ srs_error_t SrsSslClient::read(void* plaintext, size_t nn_plaintext, ssize_t* nr
|
||||||
if (r0 == -1 && r1 == SSL_ERROR_WANT_READ) {
|
if (r0 == -1 && r1 == SSL_ERROR_WANT_READ) {
|
||||||
// TODO: Can we avoid copy?
|
// TODO: Can we avoid copy?
|
||||||
int nn_cipher = nn_plaintext;
|
int nn_cipher = nn_plaintext;
|
||||||
char* cipher = new char[nn_cipher];
|
SrsUniquePtr<char[]> cipher(new char[nn_cipher]);
|
||||||
SrsAutoFreeA(char, cipher);
|
|
||||||
|
|
||||||
// Read the cipher from SSL.
|
// Read the cipher from SSL.
|
||||||
ssize_t nn = 0;
|
ssize_t nn = 0;
|
||||||
if ((err = transport->read(cipher, nn_cipher, &nn)) != srs_success) {
|
if ((err = transport->read(cipher.get(), nn_cipher, &nn)) != srs_success) {
|
||||||
return srs_error_wrap(err, "https: read");
|
return srs_error_wrap(err, "https: read");
|
||||||
}
|
}
|
||||||
|
|
||||||
int r0 = BIO_write(bio_in, cipher, nn);
|
int r0 = BIO_write(bio_in, cipher.get(), nn);
|
||||||
if (r0 <= 0) {
|
if (r0 <= 0) {
|
||||||
// TODO: 0 or -1 maybe block, use BIO_should_retry to check.
|
// TODO: 0 or -1 maybe block, use BIO_should_retry to check.
|
||||||
return srs_error_new(ERROR_HTTPS_READ, "BIO_write r0=%d, cipher=%p, size=%d", r0, cipher, nn);
|
return srs_error_new(ERROR_HTTPS_READ, "BIO_write r0=%d, cipher=%p, size=%d", r0, cipher.get(), nn);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -421,8 +421,7 @@ srs_error_t SrsHttpFileServer::serve_file(ISrsHttpResponseWriter* w, ISrsHttpMes
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsFileReader* fs = fs_factory->create_file_reader();
|
SrsUniquePtr<SrsFileReader> fs(fs_factory->create_file_reader());
|
||||||
SrsAutoFree(SrsFileReader, fs);
|
|
||||||
|
|
||||||
if ((err = fs->open(fullpath)) != srs_success) {
|
if ((err = fs->open(fullpath)) != srs_success) {
|
||||||
return srs_error_wrap(err, "open file %s", fullpath.c_str());
|
return srs_error_wrap(err, "open file %s", fullpath.c_str());
|
||||||
|
@ -484,7 +483,7 @@ srs_error_t SrsHttpFileServer::serve_file(ISrsHttpResponseWriter* w, ISrsHttpMes
|
||||||
|
|
||||||
// write body.
|
// write body.
|
||||||
int64_t left = length;
|
int64_t left = length;
|
||||||
if ((err = copy(w, fs, r, left)) != srs_success) {
|
if ((err = copy(w, fs.get(), r, left)) != srs_success) {
|
||||||
return srs_error_wrap(err, "copy file=%s size=%" PRId64, fullpath.c_str(), left);
|
return srs_error_wrap(err, "copy file=%s size=%" PRId64, fullpath.c_str(), left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,18 +594,17 @@ srs_error_t SrsHttpFileServer::copy(ISrsHttpResponseWriter* w, SrsFileReader* fs
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
int64_t left = size;
|
int64_t left = size;
|
||||||
char* buf = new char[SRS_HTTP_TS_SEND_BUFFER_SIZE];
|
SrsUniquePtr<char[]> buf(new char[SRS_HTTP_TS_SEND_BUFFER_SIZE]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
ssize_t nread = -1;
|
ssize_t nread = -1;
|
||||||
int max_read = srs_min(left, SRS_HTTP_TS_SEND_BUFFER_SIZE);
|
int max_read = srs_min(left, SRS_HTTP_TS_SEND_BUFFER_SIZE);
|
||||||
if ((err = fs->read(buf, max_read, &nread)) != srs_success) {
|
if ((err = fs->read(buf.get(), max_read, &nread)) != srs_success) {
|
||||||
return srs_error_wrap(err, "read limit=%d, left=%" PRId64, max_read, left);
|
return srs_error_wrap(err, "read limit=%d, left=%" PRId64, max_read, left);
|
||||||
}
|
}
|
||||||
|
|
||||||
left -= nread;
|
left -= nread;
|
||||||
if ((err = w->write(buf, (int)nread)) != srs_success) {
|
if ((err = w->write(buf.get(), (int)nread)) != srs_success) {
|
||||||
return srs_error_wrap(err, "write limit=%d, bytes=%d, left=%" PRId64, max_read, (int)nread, left);
|
return srs_error_wrap(err, "write limit=%d, bytes=%d, left=%" PRId64, max_read, (int)nread, left);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,11 +125,10 @@ srs_error_t SrsRawH264Stream::mux_sequence_header(string sps, string pps, string
|
||||||
// Nbytes of pps:
|
// Nbytes of pps:
|
||||||
// pictureParameterSetNALUnit
|
// pictureParameterSetNALUnit
|
||||||
int nb_packet = 5 + (3 + (int)sps.length()) + (3 + (int)pps.length());
|
int nb_packet = 5 + (3 + (int)sps.length()) + (3 + (int)pps.length());
|
||||||
char* packet = new char[nb_packet];
|
SrsUniquePtr<char[]> packet(new char[nb_packet]);
|
||||||
SrsAutoFreeA(char, packet);
|
|
||||||
|
|
||||||
// use stream to generate the h264 packet.
|
// use stream to generate the h264 packet.
|
||||||
SrsBuffer stream(packet, nb_packet);
|
SrsBuffer stream(packet.get(), nb_packet);
|
||||||
|
|
||||||
// decode the SPS:
|
// decode the SPS:
|
||||||
// @see: 7.3.2.1.1, ISO_IEC_14496-10-AVC-2012.pdf, page 62
|
// @see: 7.3.2.1.1, ISO_IEC_14496-10-AVC-2012.pdf, page 62
|
||||||
|
@ -186,7 +185,7 @@ srs_error_t SrsRawH264Stream::mux_sequence_header(string sps, string pps, string
|
||||||
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
|
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
|
||||||
// profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 144
|
// profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 144
|
||||||
|
|
||||||
sh = string(packet, nb_packet);
|
sh = string(packet.get(), nb_packet);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -200,11 +199,10 @@ srs_error_t SrsRawH264Stream::mux_ipb_frame(char* frame, int nb_frame, string& i
|
||||||
// Nbytes of nalu.
|
// Nbytes of nalu.
|
||||||
// NALUnit
|
// NALUnit
|
||||||
int nb_packet = 4 + nb_frame;
|
int nb_packet = 4 + nb_frame;
|
||||||
char* packet = new char[nb_packet];
|
SrsUniquePtr<char[]> packet(new char[nb_packet]);
|
||||||
SrsAutoFreeA(char, packet);
|
|
||||||
|
|
||||||
// use stream to generate the h264 packet.
|
// use stream to generate the h264 packet.
|
||||||
SrsBuffer stream(packet, nb_packet);
|
SrsBuffer stream(packet.get(), nb_packet);
|
||||||
|
|
||||||
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
|
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
|
||||||
// lengthSizeMinusOne, or NAL_unit_length, always use 4bytes size
|
// lengthSizeMinusOne, or NAL_unit_length, always use 4bytes size
|
||||||
|
@ -217,7 +215,7 @@ srs_error_t SrsRawH264Stream::mux_ipb_frame(char* frame, int nb_frame, string& i
|
||||||
// NALUnit
|
// NALUnit
|
||||||
stream.write_bytes(frame, nb_frame);
|
stream.write_bytes(frame, nb_frame);
|
||||||
|
|
||||||
ibp = string(packet, nb_packet);
|
ibp = string(packet.get(), nb_packet);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -406,11 +404,10 @@ srs_error_t SrsRawHEVCStream::mux_sequence_header(std::string vps, std::string s
|
||||||
}
|
}
|
||||||
|
|
||||||
int nb_packet = 23 + 5 + (int)vps.length() + 5 + (int)sps.length() + 5 + pps_size - 2;
|
int nb_packet = 23 + 5 + (int)vps.length() + 5 + (int)sps.length() + 5 + pps_size - 2;
|
||||||
char* packet = new char[nb_packet];
|
SrsUniquePtr<char[]> packet(new char[nb_packet]);
|
||||||
SrsAutoFreeA(char, packet);
|
|
||||||
|
|
||||||
// use stream to generate the hevc packet.
|
// use stream to generate the hevc packet.
|
||||||
SrsBuffer stream(packet, nb_packet);
|
SrsBuffer stream(packet.get(), nb_packet);
|
||||||
|
|
||||||
SrsFormat format;
|
SrsFormat format;
|
||||||
if ((err = format.initialize()) != srs_success) {
|
if ((err = format.initialize()) != srs_success) {
|
||||||
|
@ -511,7 +508,7 @@ srs_error_t SrsRawHEVCStream::mux_sequence_header(std::string vps, std::string s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hvcC = string(packet, nb_packet);
|
hvcC = string(packet.get(), nb_packet);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -525,11 +522,10 @@ srs_error_t SrsRawHEVCStream::mux_ipb_frame(char *frame, int nb_frame, std::stri
|
||||||
// Nbytes of nalu.
|
// Nbytes of nalu.
|
||||||
// NALUnit
|
// NALUnit
|
||||||
int nb_packet = 4 + nb_frame;
|
int nb_packet = 4 + nb_frame;
|
||||||
char *packet = new char[nb_packet];
|
SrsUniquePtr<char[]> packet(new char[nb_packet]);
|
||||||
SrsAutoFreeA(char, packet);
|
|
||||||
|
|
||||||
// use stream to generate the h265 packet.
|
// use stream to generate the h265 packet.
|
||||||
SrsBuffer stream(packet, nb_packet);
|
SrsBuffer stream(packet.get(), nb_packet);
|
||||||
|
|
||||||
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
|
// 5.3.4.2.1 Syntax, ISO_IEC_14496-15-AVC-format-2012.pdf, page 16
|
||||||
// lengthSizeMinusOne, or NAL_unit_length, always use 4bytes size
|
// lengthSizeMinusOne, or NAL_unit_length, always use 4bytes size
|
||||||
|
@ -542,7 +538,7 @@ srs_error_t SrsRawHEVCStream::mux_ipb_frame(char *frame, int nb_frame, std::stri
|
||||||
// NALUnit
|
// NALUnit
|
||||||
stream.write_bytes(frame, nb_frame);
|
stream.write_bytes(frame, nb_frame);
|
||||||
|
|
||||||
ibp = string(packet, nb_packet);
|
ibp = string(packet.get(), nb_packet);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,8 +177,7 @@ srs_error_t SrsStunPacket::decode(const char* buf, const int nb_buf)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsBuffer* stream = new SrsBuffer(const_cast<char*>(buf), nb_buf);
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(const_cast<char*>(buf), nb_buf));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
if (stream->left() < 20) {
|
if (stream->left() < 20) {
|
||||||
return srs_error_new(ERROR_RTC_STUN, "invalid stun packet, size=%d", stream->size());
|
return srs_error_new(ERROR_RTC_STUN, "invalid stun packet, size=%d", stream->size());
|
||||||
|
@ -306,8 +305,7 @@ srs_error_t SrsStunPacket::encode_binding_response(const string& pwd, SrsBuffer*
|
||||||
string SrsStunPacket::encode_username()
|
string SrsStunPacket::encode_username()
|
||||||
{
|
{
|
||||||
char buf[1460];
|
char buf[1460];
|
||||||
SrsBuffer* stream = new SrsBuffer(buf, sizeof(buf));
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf)));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
string username = remote_ufrag + ":" + local_ufrag;
|
string username = remote_ufrag + ":" + local_ufrag;
|
||||||
|
|
||||||
|
@ -326,8 +324,7 @@ string SrsStunPacket::encode_username()
|
||||||
string SrsStunPacket::encode_mapped_address()
|
string SrsStunPacket::encode_mapped_address()
|
||||||
{
|
{
|
||||||
char buf[1460];
|
char buf[1460];
|
||||||
SrsBuffer* stream = new SrsBuffer(buf, sizeof(buf));
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf)));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
stream->write_2bytes(XorMappedAddress);
|
stream->write_2bytes(XorMappedAddress);
|
||||||
stream->write_2bytes(8);
|
stream->write_2bytes(8);
|
||||||
|
@ -342,8 +339,7 @@ string SrsStunPacket::encode_mapped_address()
|
||||||
string SrsStunPacket::encode_hmac(char* hmac_buf, const int hmac_buf_len)
|
string SrsStunPacket::encode_hmac(char* hmac_buf, const int hmac_buf_len)
|
||||||
{
|
{
|
||||||
char buf[1460];
|
char buf[1460];
|
||||||
SrsBuffer* stream = new SrsBuffer(buf, sizeof(buf));
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf)));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
stream->write_2bytes(MessageIntegrity);
|
stream->write_2bytes(MessageIntegrity);
|
||||||
stream->write_2bytes(hmac_buf_len);
|
stream->write_2bytes(hmac_buf_len);
|
||||||
|
@ -355,8 +351,7 @@ string SrsStunPacket::encode_hmac(char* hmac_buf, const int hmac_buf_len)
|
||||||
string SrsStunPacket::encode_fingerprint(uint32_t crc32)
|
string SrsStunPacket::encode_fingerprint(uint32_t crc32)
|
||||||
{
|
{
|
||||||
char buf[1460];
|
char buf[1460];
|
||||||
SrsBuffer* stream = new SrsBuffer(buf, sizeof(buf));
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(buf, sizeof(buf)));
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
stream->write_2bytes(Fingerprint);
|
stream->write_2bytes(Fingerprint);
|
||||||
stream->write_2bytes(4);
|
stream->write_2bytes(4);
|
||||||
|
|
|
@ -522,16 +522,16 @@ namespace srs_internal
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// generate digest
|
// generate digest
|
||||||
char* c1_digest = NULL;
|
char* c1_digest_raw = NULL;
|
||||||
|
|
||||||
if ((err = calc_c1_digest(owner, c1_digest)) != srs_success) {
|
if ((err = calc_c1_digest(owner, c1_digest_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "sign c1");
|
return srs_error_wrap(err, "sign c1");
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(c1_digest != NULL);
|
srs_assert(c1_digest_raw != NULL);
|
||||||
SrsAutoFreeA(char, c1_digest);
|
SrsUniquePtr<char[]> c1_digest(c1_digest_raw);
|
||||||
|
|
||||||
memcpy(digest.digest, c1_digest, 32);
|
memcpy(digest.digest, c1_digest.get(), 32);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -540,16 +540,16 @@ namespace srs_internal
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
char* c1_digest = NULL;
|
char* c1_digest_raw = NULL;
|
||||||
|
|
||||||
if ((err = calc_c1_digest(owner, c1_digest)) != srs_success) {
|
if ((err = calc_c1_digest(owner, c1_digest_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "validate c1");
|
return srs_error_wrap(err, "validate c1");
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(c1_digest != NULL);
|
srs_assert(c1_digest_raw != NULL);
|
||||||
SrsAutoFreeA(char, c1_digest);
|
SrsUniquePtr<char[]> c1_digest(c1_digest_raw);
|
||||||
|
|
||||||
is_valid = srs_bytes_equals(digest.digest, c1_digest, 32);
|
is_valid = srs_bytes_equals(digest.digest, c1_digest.get(), 32);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -576,15 +576,15 @@ namespace srs_internal
|
||||||
// TODO: FIXME: use the actual key size.
|
// TODO: FIXME: use the actual key size.
|
||||||
//srs_assert(pkey_size == 128);
|
//srs_assert(pkey_size == 128);
|
||||||
|
|
||||||
char* s1_digest = NULL;
|
char* s1_digest_raw = NULL;
|
||||||
if ((err = calc_s1_digest(owner, s1_digest)) != srs_success) {
|
if ((err = calc_s1_digest(owner, s1_digest_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "calc s1 digest");
|
return srs_error_wrap(err, "calc s1 digest");
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(s1_digest != NULL);
|
srs_assert(s1_digest_raw != NULL);
|
||||||
SrsAutoFreeA(char, s1_digest);
|
SrsUniquePtr<char[]> s1_digest(s1_digest_raw);
|
||||||
|
|
||||||
memcpy(digest.digest, s1_digest, 32);
|
memcpy(digest.digest, s1_digest.get(), 32);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -593,16 +593,16 @@ namespace srs_internal
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
char* s1_digest = NULL;
|
char* s1_digest_raw = NULL;
|
||||||
|
|
||||||
if ((err = calc_s1_digest(owner, s1_digest)) != srs_success) {
|
if ((err = calc_s1_digest(owner, s1_digest_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "validate s1");
|
return srs_error_wrap(err, "validate s1");
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(s1_digest != NULL);
|
srs_assert(s1_digest_raw != NULL);
|
||||||
SrsAutoFreeA(char, s1_digest);
|
SrsUniquePtr<char[]> s1_digest(s1_digest_raw);
|
||||||
|
|
||||||
is_valid = srs_bytes_equals(digest.digest, s1_digest, 32);
|
is_valid = srs_bytes_equals(digest.digest, s1_digest.get(), 32);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -611,21 +611,18 @@ namespace srs_internal
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
/**
|
// c1s1 is splited by digest:
|
||||||
* c1s1 is splited by digest:
|
// c1s1-part1: n bytes (time, version, key and digest-part1).
|
||||||
* c1s1-part1: n bytes (time, version, key and digest-part1).
|
// digest-data: 32bytes
|
||||||
* digest-data: 32bytes
|
// c1s1-part2: (1536-n-32)bytes (digest-part2)
|
||||||
* c1s1-part2: (1536-n-32)bytes (digest-part2)
|
// @return a new allocated bytes, user must free it.
|
||||||
* @return a new allocated bytes, user must free it.
|
SrsUniquePtr<char[]> c1s1_joined_bytes(new char[1536 -32]);
|
||||||
*/
|
if ((err = copy_to(owner, c1s1_joined_bytes.get(), 1536 - 32, false)) != srs_success) {
|
||||||
char* c1s1_joined_bytes = new char[1536 -32];
|
|
||||||
SrsAutoFreeA(char, c1s1_joined_bytes);
|
|
||||||
if ((err = copy_to(owner, c1s1_joined_bytes, 1536 - 32, false)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "copy bytes");
|
return srs_error_wrap(err, "copy bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
c1_digest = new char[SRS_OpensslHashSize];
|
c1_digest = new char[SRS_OpensslHashSize];
|
||||||
if ((err = openssl_HMACsha256(SrsGenuineFPKey, 30, c1s1_joined_bytes, 1536 - 32, c1_digest)) != srs_success) {
|
if ((err = openssl_HMACsha256(SrsGenuineFPKey, 30, c1s1_joined_bytes.get(), 1536 - 32, c1_digest)) != srs_success) {
|
||||||
srs_freepa(c1_digest);
|
srs_freepa(c1_digest);
|
||||||
return srs_error_wrap(err, "calc c1 digest");
|
return srs_error_wrap(err, "calc c1 digest");
|
||||||
}
|
}
|
||||||
|
@ -637,21 +634,18 @@ namespace srs_internal
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
/**
|
// c1s1 is splited by digest:
|
||||||
* c1s1 is splited by digest:
|
// c1s1-part1: n bytes (time, version, key and digest-part1).
|
||||||
* c1s1-part1: n bytes (time, version, key and digest-part1).
|
// digest-data: 32bytes
|
||||||
* digest-data: 32bytes
|
// c1s1-part2: (1536-n-32)bytes (digest-part2)
|
||||||
* c1s1-part2: (1536-n-32)bytes (digest-part2)
|
// @return a new allocated bytes, user must free it.
|
||||||
* @return a new allocated bytes, user must free it.
|
SrsUniquePtr<char[]> c1s1_joined_bytes(new char[1536 -32]);
|
||||||
*/
|
if ((err = copy_to(owner, c1s1_joined_bytes.get(), 1536 - 32, false)) != srs_success) {
|
||||||
char* c1s1_joined_bytes = new char[1536 -32];
|
|
||||||
SrsAutoFreeA(char, c1s1_joined_bytes);
|
|
||||||
if ((err = copy_to(owner, c1s1_joined_bytes, 1536 - 32, false)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "copy bytes");
|
return srs_error_wrap(err, "copy bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
s1_digest = new char[SRS_OpensslHashSize];
|
s1_digest = new char[SRS_OpensslHashSize];
|
||||||
if ((err = openssl_HMACsha256(SrsGenuineFMSKey, 36, c1s1_joined_bytes, 1536 - 32, s1_digest)) != srs_success) {
|
if ((err = openssl_HMACsha256(SrsGenuineFMSKey, 36, c1s1_joined_bytes.get(), 1536 - 32, s1_digest)) != srs_success) {
|
||||||
srs_freepa(s1_digest);
|
srs_freepa(s1_digest);
|
||||||
return srs_error_wrap(err, "calc s1 digest");
|
return srs_error_wrap(err, "calc s1 digest");
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,11 +128,9 @@ srs_error_t SrsPacket::encode(int& psize, char*& ppayload)
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
payload = new char[size];
|
payload = new char[size];
|
||||||
|
SrsUniquePtr<SrsBuffer> stream(new SrsBuffer(payload, size));
|
||||||
|
|
||||||
SrsBuffer* stream = new SrsBuffer(payload, size);
|
if ((err = encode_packet(stream.get())) != srs_success) {
|
||||||
SrsAutoFree(SrsBuffer, stream);
|
|
||||||
|
|
||||||
if ((err = encode_packet(stream)) != srs_success) {
|
|
||||||
srs_freepa(payload);
|
srs_freepa(payload);
|
||||||
return srs_error_wrap(err, "encode packet");
|
return srs_error_wrap(err, "encode packet");
|
||||||
}
|
}
|
||||||
|
@ -556,22 +554,20 @@ srs_error_t SrsProtocol::do_iovs_send(iovec* iovs, int size)
|
||||||
return srs_write_large_iovs(skt, iovs, size);
|
return srs_write_large_iovs(skt, iovs, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsProtocol::do_send_and_free_packet(SrsPacket* packet, int stream_id)
|
srs_error_t SrsProtocol::do_send_and_free_packet(SrsPacket* packet_raw, int stream_id)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
srs_assert(packet);
|
srs_assert(packet_raw);
|
||||||
SrsAutoFree(SrsPacket, packet);
|
SrsUniquePtr<SrsPacket> packet(packet_raw);
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg(new SrsCommonMessage());
|
||||||
|
|
||||||
SrsCommonMessage* msg = new SrsCommonMessage();
|
if ((err = packet->to_msg(msg.get(), stream_id)) != srs_success) {
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
|
||||||
|
|
||||||
if ((err = packet->to_msg(msg, stream_id)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "to message");
|
return srs_error_wrap(err, "to message");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSharedPtrMessage* shared_msg = new SrsSharedPtrMessage();
|
SrsSharedPtrMessage* shared_msg = new SrsSharedPtrMessage();
|
||||||
if ((err = shared_msg->create(msg)) != srs_success) {
|
if ((err = shared_msg->create(msg.get())) != srs_success) {
|
||||||
srs_freep(shared_msg);
|
srs_freep(shared_msg);
|
||||||
return srs_error_wrap(err, "create message");
|
return srs_error_wrap(err, "create message");
|
||||||
}
|
}
|
||||||
|
@ -580,7 +576,7 @@ srs_error_t SrsProtocol::do_send_and_free_packet(SrsPacket* packet, int stream_i
|
||||||
return srs_error_wrap(err, "send packet");
|
return srs_error_wrap(err, "send packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = on_send_packet(&msg->header, packet)) != srs_success) {
|
if ((err = on_send_packet(&msg->header, packet.get())) != srs_success) {
|
||||||
return srs_error_wrap(err, "on send packet");
|
return srs_error_wrap(err, "on send packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1237,12 +1233,12 @@ srs_error_t SrsProtocol::on_recv_message(SrsCommonMessage* msg)
|
||||||
return srs_error_wrap(err, "response ack");
|
return srs_error_wrap(err, "response ack");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPacket* packet = NULL;
|
SrsPacket* packet_raw = NULL;
|
||||||
switch (msg->header.message_type) {
|
switch (msg->header.message_type) {
|
||||||
case RTMP_MSG_SetChunkSize:
|
case RTMP_MSG_SetChunkSize:
|
||||||
case RTMP_MSG_UserControlMessage:
|
case RTMP_MSG_UserControlMessage:
|
||||||
case RTMP_MSG_WindowAcknowledgementSize:
|
case RTMP_MSG_WindowAcknowledgementSize:
|
||||||
if ((err = decode_message(msg, &packet)) != srs_success) {
|
if ((err = decode_message(msg, &packet_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "decode message");
|
return srs_error_wrap(err, "decode message");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1253,14 +1249,13 @@ srs_error_t SrsProtocol::on_recv_message(SrsCommonMessage* msg)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(packet);
|
|
||||||
|
|
||||||
// always free the packet.
|
// always free the packet.
|
||||||
SrsAutoFree(SrsPacket, packet);
|
srs_assert(packet_raw);
|
||||||
|
SrsUniquePtr<SrsPacket> packet(packet_raw);
|
||||||
|
|
||||||
switch (msg->header.message_type) {
|
switch (msg->header.message_type) {
|
||||||
case RTMP_MSG_WindowAcknowledgementSize: {
|
case RTMP_MSG_WindowAcknowledgementSize: {
|
||||||
SrsSetWindowAckSizePacket* pkt = dynamic_cast<SrsSetWindowAckSizePacket*>(packet);
|
SrsSetWindowAckSizePacket* pkt = dynamic_cast<SrsSetWindowAckSizePacket*>(packet.get());
|
||||||
srs_assert(pkt != NULL);
|
srs_assert(pkt != NULL);
|
||||||
|
|
||||||
if (pkt->ackowledgement_window_size > 0) {
|
if (pkt->ackowledgement_window_size > 0) {
|
||||||
|
@ -1272,7 +1267,7 @@ srs_error_t SrsProtocol::on_recv_message(SrsCommonMessage* msg)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RTMP_MSG_SetChunkSize: {
|
case RTMP_MSG_SetChunkSize: {
|
||||||
SrsSetChunkSizePacket* pkt = dynamic_cast<SrsSetChunkSizePacket*>(packet);
|
SrsSetChunkSizePacket* pkt = dynamic_cast<SrsSetChunkSizePacket*>(packet.get());
|
||||||
srs_assert(pkt != NULL);
|
srs_assert(pkt != NULL);
|
||||||
|
|
||||||
// for some server, the actual chunk size can greater than the max value(65536),
|
// for some server, the actual chunk size can greater than the max value(65536),
|
||||||
|
@ -1292,7 +1287,7 @@ srs_error_t SrsProtocol::on_recv_message(SrsCommonMessage* msg)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RTMP_MSG_UserControlMessage: {
|
case RTMP_MSG_UserControlMessage: {
|
||||||
SrsUserControlPacket* pkt = dynamic_cast<SrsUserControlPacket*>(packet);
|
SrsUserControlPacket* pkt = dynamic_cast<SrsUserControlPacket*>(packet.get());
|
||||||
srs_assert(pkt != NULL);
|
srs_assert(pkt != NULL);
|
||||||
|
|
||||||
if (pkt->event_type == SrcPCUCSetBufferLength) {
|
if (pkt->event_type == SrcPCUCSetBufferLength) {
|
||||||
|
@ -1822,8 +1817,7 @@ srs_error_t SrsRtmpClient::handshake()
|
||||||
|
|
||||||
// maybe st has problem when alloc object on stack, always alloc object at heap.
|
// maybe st has problem when alloc object on stack, always alloc object at heap.
|
||||||
// @see https://github.com/ossrs/srs/issues/509
|
// @see https://github.com/ossrs/srs/issues/509
|
||||||
SrsComplexHandshake* complex_hs = new SrsComplexHandshake();
|
SrsUniquePtr<SrsComplexHandshake> complex_hs(new SrsComplexHandshake());
|
||||||
SrsAutoFree(SrsComplexHandshake, complex_hs);
|
|
||||||
|
|
||||||
if ((err = complex_hs->handshake_with_server(hs_bytes, io)) != srs_success) {
|
if ((err = complex_hs->handshake_with_server(hs_bytes, io)) != srs_success) {
|
||||||
// As client, we never verify s0s1s2, because some server doesn't follow the RTMP spec.
|
// As client, we never verify s0s1s2, because some server doesn't follow the RTMP spec.
|
||||||
|
@ -1922,13 +1916,14 @@ srs_error_t SrsRtmpClient::connect_app(string app, string tcUrl, SrsRequest* r,
|
||||||
}
|
}
|
||||||
|
|
||||||
// expect connect _result
|
// expect connect _result
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsConnectAppResPacket* pkt = NULL;
|
SrsConnectAppResPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsConnectAppResPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsConnectAppResPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "expect connect app response");
|
return srs_error_wrap(err, "expect connect app response");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
|
||||||
SrsAutoFree(SrsConnectAppResPacket, pkt);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
SrsUniquePtr<SrsConnectAppResPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
// server info
|
// server info
|
||||||
SrsAmf0Any* data = pkt->info->get_property("data");
|
SrsAmf0Any* data = pkt->info->get_property("data");
|
||||||
|
@ -1989,13 +1984,14 @@ srs_error_t SrsRtmpClient::create_stream(int& stream_id)
|
||||||
|
|
||||||
// CreateStream _result.
|
// CreateStream _result.
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsCreateStreamResPacket* pkt = NULL;
|
SrsCreateStreamResPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsCreateStreamResPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsCreateStreamResPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "expect create stream response");
|
return srs_error_wrap(err, "expect create stream response");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
|
||||||
SrsAutoFree(SrsCreateStreamResPacket, pkt);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
SrsUniquePtr<SrsCreateStreamResPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
stream_id = (int)pkt->stream_id;
|
stream_id = (int)pkt->stream_id;
|
||||||
}
|
}
|
||||||
|
@ -2100,13 +2096,14 @@ srs_error_t SrsRtmpClient::fmle_publish(string stream, int& stream_id)
|
||||||
|
|
||||||
// expect result of CreateStream
|
// expect result of CreateStream
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsCreateStreamResPacket* pkt = NULL;
|
SrsCreateStreamResPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsCreateStreamResPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsCreateStreamResPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "expect create stream response message failed");
|
return srs_error_wrap(err, "expect create stream response message failed");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
|
||||||
SrsAutoFree(SrsCreateStreamResPacket, pkt);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
SrsUniquePtr<SrsCreateStreamResPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
stream_id = (int)pkt->stream_id;
|
stream_id = (int)pkt->stream_id;
|
||||||
}
|
}
|
||||||
|
@ -2242,13 +2239,14 @@ srs_error_t SrsRtmpServer::connect_app(SrsRequest* req)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsConnectAppPacket* pkt = NULL;
|
SrsConnectAppPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsConnectAppPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsConnectAppPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "expect connect app response");
|
return srs_error_wrap(err, "expect connect app response");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
|
||||||
SrsAutoFree(SrsConnectAppPacket, pkt);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
SrsUniquePtr<SrsConnectAppPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
SrsAmf0Any* prop = NULL;
|
SrsAmf0Any* prop = NULL;
|
||||||
|
|
||||||
|
@ -2383,15 +2381,16 @@ srs_error_t SrsRtmpServer::redirect(SrsRequest* r, string url, bool& accepted)
|
||||||
// or we never know whether the client is ok to redirect.
|
// or we never know whether the client is ok to redirect.
|
||||||
protocol->set_recv_timeout(SRS_RTMP_REDIRECT_TIMEOUT);
|
protocol->set_recv_timeout(SRS_RTMP_REDIRECT_TIMEOUT);
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsCallPacket* pkt = NULL;
|
SrsCallPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsCallPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsCallPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
// ignore any error of redirect response.
|
// ignore any error of redirect response.
|
||||||
return srs_success;
|
return srs_success;
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
|
||||||
SrsAutoFree(SrsCallPacket, pkt);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
SrsUniquePtr<SrsCallPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
string message;
|
string message;
|
||||||
if (pkt->arguments && pkt->arguments->is_string()) {
|
if (pkt->arguments && pkt->arguments->is_string()) {
|
||||||
|
@ -2438,12 +2437,12 @@ srs_error_t SrsRtmpServer::identify_client(int stream_id, SrsRtmpConnType& type,
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
if ((err = protocol->recv_message(&msg)) != srs_success) {
|
if ((err = protocol->recv_message(&msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "recv identify message");
|
return srs_error_wrap(err, "recv identify message");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
SrsMessageHeader& h = msg->header;
|
SrsMessageHeader& h = msg->header;
|
||||||
|
|
||||||
if (h.is_ackledgement() || h.is_set_chunk_size() || h.is_window_ackledgement_size() || h.is_user_control_message()) {
|
if (h.is_ackledgement() || h.is_set_chunk_size() || h.is_window_ackledgement_size() || h.is_user_control_message()) {
|
||||||
|
@ -2455,27 +2454,26 @@ srs_error_t SrsRtmpServer::identify_client(int stream_id, SrsRtmpConnType& type,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt_raw = NULL;
|
||||||
if ((err = protocol->decode_message(msg, &pkt)) != srs_success) {
|
if ((err = protocol->decode_message(msg.get(), &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "decode identify");
|
return srs_error_wrap(err, "decode identify");
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
if (dynamic_cast<SrsCreateStreamPacket*>(pkt.get())) {
|
||||||
|
return identify_create_stream_client(dynamic_cast<SrsCreateStreamPacket*>(pkt.get()), stream_id, 3, type, stream_name, duration);
|
||||||
if (dynamic_cast<SrsCreateStreamPacket*>(pkt)) {
|
|
||||||
return identify_create_stream_client(dynamic_cast<SrsCreateStreamPacket*>(pkt), stream_id, 3, type, stream_name, duration);
|
|
||||||
}
|
}
|
||||||
if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
|
if (dynamic_cast<SrsFMLEStartPacket*>(pkt.get())) {
|
||||||
return identify_fmle_publish_client(dynamic_cast<SrsFMLEStartPacket*>(pkt), type, stream_name);
|
return identify_fmle_publish_client(dynamic_cast<SrsFMLEStartPacket*>(pkt.get()), type, stream_name);
|
||||||
}
|
}
|
||||||
if (dynamic_cast<SrsPlayPacket*>(pkt)) {
|
if (dynamic_cast<SrsPlayPacket*>(pkt.get())) {
|
||||||
return identify_play_client(dynamic_cast<SrsPlayPacket*>(pkt), type, stream_name, duration);
|
return identify_play_client(dynamic_cast<SrsPlayPacket*>(pkt.get()), type, stream_name, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// call msg,
|
// call msg,
|
||||||
// support response null first,
|
// support response null first,
|
||||||
// TODO: FIXME: response in right way, or forward in edge mode.
|
// TODO: FIXME: response in right way, or forward in edge mode.
|
||||||
SrsCallPacket* call = dynamic_cast<SrsCallPacket*>(pkt);
|
SrsCallPacket* call = dynamic_cast<SrsCallPacket*>(pkt.get());
|
||||||
if (call) {
|
if (call) {
|
||||||
SrsCallResPacket* res = new SrsCallResPacket(call->transaction_id);
|
SrsCallResPacket* res = new SrsCallResPacket(call->transaction_id);
|
||||||
res->command_object = SrsAmf0Any::null();
|
res->command_object = SrsAmf0Any::null();
|
||||||
|
@ -2646,14 +2644,14 @@ srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
|
||||||
// FCPublish
|
// FCPublish
|
||||||
double fc_publish_tid = 0;
|
double fc_publish_tid = 0;
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsFMLEStartPacket* pkt = NULL;
|
SrsFMLEStartPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsFMLEStartPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsFMLEStartPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "recv FCPublish");
|
return srs_error_wrap(err, "recv FCPublish");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
SrsAutoFree(SrsFMLEStartPacket, pkt);
|
SrsUniquePtr<SrsFMLEStartPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
fc_publish_tid = pkt->transaction_id;
|
fc_publish_tid = pkt->transaction_id;
|
||||||
}
|
}
|
||||||
|
@ -2668,14 +2666,14 @@ srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
|
||||||
// createStream
|
// createStream
|
||||||
double create_stream_tid = 0;
|
double create_stream_tid = 0;
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsCreateStreamPacket* pkt = NULL;
|
SrsCreateStreamPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsCreateStreamPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsCreateStreamPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "recv createStream");
|
return srs_error_wrap(err, "recv createStream");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
SrsAutoFree(SrsCreateStreamPacket, pkt);
|
SrsUniquePtr<SrsCreateStreamPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
create_stream_tid = pkt->transaction_id;
|
create_stream_tid = pkt->transaction_id;
|
||||||
}
|
}
|
||||||
|
@ -2689,14 +2687,14 @@ srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
|
||||||
|
|
||||||
// publish
|
// publish
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsPublishPacket* pkt = NULL;
|
SrsPublishPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsPublishPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsPublishPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "recv publish");
|
return srs_error_wrap(err, "recv publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
SrsAutoFree(SrsPublishPacket, pkt);
|
SrsUniquePtr<SrsPublishPacket> pkt(pkt_raw);
|
||||||
}
|
}
|
||||||
// publish response onFCPublish(NetStream.Publish.Start)
|
// publish response onFCPublish(NetStream.Publish.Start)
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -2720,14 +2718,14 @@ srs_error_t SrsRtmpServer::start_haivision_publish(int stream_id)
|
||||||
|
|
||||||
// publish
|
// publish
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
SrsPublishPacket* pkt = NULL;
|
SrsPublishPacket* pkt_raw = NULL;
|
||||||
if ((err = expect_message<SrsPublishPacket>(&msg, &pkt)) != srs_success) {
|
if ((err = expect_message<SrsPublishPacket>(&msg_raw, &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "recv publish");
|
return srs_error_wrap(err, "recv publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
SrsAutoFree(SrsPublishPacket, pkt);
|
SrsUniquePtr<SrsPublishPacket> pkt(pkt_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish response onFCPublish(NetStream.Publish.Start)
|
// publish response onFCPublish(NetStream.Publish.Start)
|
||||||
|
@ -2829,12 +2827,12 @@ srs_error_t SrsRtmpServer::identify_create_stream_client(SrsCreateStreamPacket*
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
if ((err = protocol->recv_message(&msg)) != srs_success) {
|
if ((err = protocol->recv_message(&msg_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "recv identify");
|
return srs_error_wrap(err, "recv identify");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
SrsMessageHeader& h = msg->header;
|
SrsMessageHeader& h = msg->header;
|
||||||
|
|
||||||
if (h.is_ackledgement() || h.is_set_chunk_size() || h.is_window_ackledgement_size() || h.is_user_control_message()) {
|
if (h.is_ackledgement() || h.is_set_chunk_size() || h.is_window_ackledgement_size() || h.is_user_control_message()) {
|
||||||
|
@ -2846,24 +2844,23 @@ srs_error_t SrsRtmpServer::identify_create_stream_client(SrsCreateStreamPacket*
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt_raw = NULL;
|
||||||
if ((err = protocol->decode_message(msg, &pkt)) != srs_success) {
|
if ((err = protocol->decode_message(msg.get(), &pkt_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "decode identify");
|
return srs_error_wrap(err, "decode identify");
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsPacket> pkt(pkt_raw);
|
||||||
|
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
if (dynamic_cast<SrsPlayPacket*>(pkt.get())) {
|
||||||
|
return identify_play_client(dynamic_cast<SrsPlayPacket*>(pkt.get()), type, stream_name, duration);
|
||||||
if (dynamic_cast<SrsPlayPacket*>(pkt)) {
|
|
||||||
return identify_play_client(dynamic_cast<SrsPlayPacket*>(pkt), type, stream_name, duration);
|
|
||||||
}
|
}
|
||||||
if (dynamic_cast<SrsPublishPacket*>(pkt)) {
|
if (dynamic_cast<SrsPublishPacket*>(pkt.get())) {
|
||||||
return identify_flash_publish_client(dynamic_cast<SrsPublishPacket*>(pkt), type, stream_name);
|
return identify_flash_publish_client(dynamic_cast<SrsPublishPacket*>(pkt.get()), type, stream_name);
|
||||||
}
|
}
|
||||||
if (dynamic_cast<SrsCreateStreamPacket*>(pkt)) {
|
if (dynamic_cast<SrsCreateStreamPacket*>(pkt.get())) {
|
||||||
return identify_create_stream_client(dynamic_cast<SrsCreateStreamPacket*>(pkt), stream_id, depth-1, type, stream_name, duration);
|
return identify_create_stream_client(dynamic_cast<SrsCreateStreamPacket*>(pkt.get()), stream_id, depth-1, type, stream_name, duration);
|
||||||
}
|
}
|
||||||
if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
|
if (dynamic_cast<SrsFMLEStartPacket*>(pkt.get())) {
|
||||||
return identify_haivision_publish_client(dynamic_cast<SrsFMLEStartPacket*>(pkt), type, stream_name);
|
return identify_haivision_publish_client(dynamic_cast<SrsFMLEStartPacket*>(pkt.get()), type, stream_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_trace("ignore AMF0/AMF3 command message.");
|
srs_trace("ignore AMF0/AMF3 command message.");
|
||||||
|
@ -3873,13 +3870,13 @@ srs_error_t SrsPlayPacket::decode(SrsBuffer* stream)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAmf0Any* reset_value = NULL;
|
SrsAmf0Any* reset_value_raw = NULL;
|
||||||
if ((err = srs_amf0_read_any(stream, &reset_value)) != srs_success) {
|
if ((err = srs_amf0_read_any(stream, &reset_value_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "reset");
|
return srs_error_wrap(err, "reset");
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsAmf0Any, reset_value);
|
SrsUniquePtr<SrsAmf0Any> reset_value(reset_value_raw);
|
||||||
|
|
||||||
if (reset_value) {
|
if (reset_value.get()) {
|
||||||
// check if the value is bool or number
|
// check if the value is bool or number
|
||||||
// An optional Boolean value or number that specifies whether
|
// An optional Boolean value or number that specifies whether
|
||||||
// to flush any previous playlist
|
// to flush any previous playlist
|
||||||
|
@ -4274,20 +4271,19 @@ srs_error_t SrsOnMetaDataPacket::decode(SrsBuffer* stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the metadata maybe object or ecma array
|
// the metadata maybe object or ecma array
|
||||||
SrsAmf0Any* any = NULL;
|
SrsAmf0Any* any_raw = NULL;
|
||||||
if ((err = srs_amf0_read_any(stream, &any)) != srs_success) {
|
if ((err = srs_amf0_read_any(stream, &any_raw)) != srs_success) {
|
||||||
return srs_error_wrap(err, "metadata");
|
return srs_error_wrap(err, "metadata");
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(any);
|
srs_assert(any_raw);
|
||||||
if (any->is_object()) {
|
if (any_raw->is_object()) {
|
||||||
srs_freep(metadata);
|
srs_freep(metadata);
|
||||||
metadata = any->to_object();
|
metadata = any_raw->to_object();
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsAmf0Any, any);
|
SrsUniquePtr<SrsAmf0Any> any(any_raw);
|
||||||
|
|
||||||
if (any->is_ecma_array()) {
|
if (any->is_ecma_array()) {
|
||||||
SrsAmf0EcmaArray* arr = any->to_ecma_array();
|
SrsAmf0EcmaArray* arr = any->to_ecma_array();
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ using namespace std;
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
#include <srs_kernel_log.hpp>
|
#include <srs_kernel_log.hpp>
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
#include <srt/srt.h>
|
#include <srt/srt.h>
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ using namespace std;
|
||||||
#include <srs_kernel_log.hpp>
|
#include <srs_kernel_log.hpp>
|
||||||
#include <srs_protocol_utility.hpp>
|
#include <srs_protocol_utility.hpp>
|
||||||
#include <srs_kernel_utility.hpp>
|
#include <srs_kernel_utility.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
// nginx also set to 512
|
// nginx also set to 512
|
||||||
#define SERVER_LISTEN_BACKLOG 512
|
#define SERVER_LISTEN_BACKLOG 512
|
||||||
|
|
|
@ -920,13 +920,12 @@ srs_error_t srs_ioutil_read_all(ISrsReader* in, std::string& content)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// Cache to read, it might cause coroutine switch, so we use local cache here.
|
// Cache to read, it might cause coroutine switch, so we use local cache here.
|
||||||
char* buf = new char[SRS_HTTP_READ_CACHE_BYTES];
|
SrsUniquePtr<char[]> buf(new char[SRS_HTTP_READ_CACHE_BYTES]);
|
||||||
SrsAutoFreeA(char, buf);
|
|
||||||
|
|
||||||
// Whatever, read util EOF.
|
// Whatever, read util EOF.
|
||||||
while (true) {
|
while (true) {
|
||||||
ssize_t nb_read = 0;
|
ssize_t nb_read = 0;
|
||||||
if ((err = in->read(buf, SRS_HTTP_READ_CACHE_BYTES, &nb_read)) != srs_success) {
|
if ((err = in->read(buf.get(), SRS_HTTP_READ_CACHE_BYTES, &nb_read)) != srs_success) {
|
||||||
int code = srs_error_code(err);
|
int code = srs_error_code(err);
|
||||||
if (code == ERROR_SYSTEM_FILE_EOF || code == ERROR_HTTP_RESPONSE_EOF || code == ERROR_HTTP_REQUEST_EOF
|
if (code == ERROR_SYSTEM_FILE_EOF || code == ERROR_HTTP_RESPONSE_EOF || code == ERROR_HTTP_REQUEST_EOF
|
||||||
|| code == ERROR_HTTP_STREAM_EOF
|
|| code == ERROR_HTTP_STREAM_EOF
|
||||||
|
@ -938,7 +937,7 @@ srs_error_t srs_ioutil_read_all(ISrsReader* in, std::string& content)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nb_read > 0) {
|
if (nb_read > 0) {
|
||||||
content.append(buf, nb_read);
|
content.append(buf.get(), nb_read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,6 +10,7 @@ using namespace std;
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
#include <srs_protocol_conn.hpp>
|
#include <srs_protocol_conn.hpp>
|
||||||
#include <srs_app_conn.hpp>
|
#include <srs_app_conn.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
VOID TEST(CoreAutoFreeTest, Free)
|
VOID TEST(CoreAutoFreeTest, Free)
|
||||||
{
|
{
|
||||||
|
@ -88,7 +89,7 @@ VOID TEST(CoreLogger, CheckVsnprintf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrTypical)
|
VOID TEST(CoreSmartPtr, SharedPtrTypical)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedPtr<int> p(new int(100));
|
SrsSharedPtr<int> p(new int(100));
|
||||||
|
@ -118,7 +119,7 @@ VOID TEST(CoreLogger, SharedPtrTypical)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrReset)
|
VOID TEST(CoreSmartPtr, SharedPtrReset)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedPtr<int> p(new int(100));
|
SrsSharedPtr<int> p(new int(100));
|
||||||
|
@ -143,21 +144,21 @@ SrsSharedPtr<int> mock_create_from_ptr(SrsSharedPtr<int> p) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrContructor)
|
VOID TEST(CoreSmartPtr, SharedPtrContructor)
|
||||||
{
|
{
|
||||||
int* p = new int(100);
|
int* p = new int(100);
|
||||||
SrsSharedPtr<int> q = mock_create_from_ptr(p);
|
SrsSharedPtr<int> q = mock_create_from_ptr(p);
|
||||||
EXPECT_EQ(100, *q);
|
EXPECT_EQ(100, *q);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrObject)
|
VOID TEST(CoreSmartPtr, SharedPtrObject)
|
||||||
{
|
{
|
||||||
SrsSharedPtr<MyNormalObject> p(new MyNormalObject(100));
|
SrsSharedPtr<MyNormalObject> p(new MyNormalObject(100));
|
||||||
EXPECT_TRUE(p);
|
EXPECT_TRUE(p);
|
||||||
EXPECT_EQ(100, p->id());
|
EXPECT_EQ(100, p->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrNullptr)
|
VOID TEST(CoreSmartPtr, SharedPtrNullptr)
|
||||||
{
|
{
|
||||||
SrsSharedPtr<int> p(NULL);
|
SrsSharedPtr<int> p(NULL);
|
||||||
EXPECT_FALSE(p);
|
EXPECT_FALSE(p);
|
||||||
|
@ -176,17 +177,17 @@ public:
|
||||||
public:
|
public:
|
||||||
MockWrapper(int* p) {
|
MockWrapper(int* p) {
|
||||||
ptr = p;
|
ptr = p;
|
||||||
*ptr = *ptr + 1;
|
if (ptr) *ptr = *ptr + 1;
|
||||||
}
|
}
|
||||||
~MockWrapper() {
|
~MockWrapper() {
|
||||||
*ptr = *ptr - 1;
|
if (ptr) *ptr = *ptr - 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrWrapper)
|
VOID TEST(CoreSmartPtr, SharedPtrWrapper)
|
||||||
{
|
{
|
||||||
int* ptr = new int(100);
|
int* ptr = new int(100);
|
||||||
SrsAutoFree(int, ptr);
|
SrsUniquePtr<int> ptr_uptr(ptr);
|
||||||
EXPECT_EQ(100, *ptr);
|
EXPECT_EQ(100, *ptr);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -222,7 +223,7 @@ VOID TEST(CoreLogger, SharedPtrWrapper)
|
||||||
EXPECT_EQ(100, *ptr);
|
EXPECT_EQ(100, *ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrAssign)
|
VOID TEST(CoreSmartPtr, SharedPtrAssign)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedPtr<int> p(new int(100));
|
SrsSharedPtr<int> p(new int(100));
|
||||||
|
@ -242,11 +243,11 @@ VOID TEST(CoreLogger, SharedPtrAssign)
|
||||||
}
|
}
|
||||||
|
|
||||||
int* ptr0 = new int(100);
|
int* ptr0 = new int(100);
|
||||||
SrsAutoFree(int, ptr0);
|
SrsUniquePtr<int> ptr0_uptr(ptr0);
|
||||||
EXPECT_EQ(100, *ptr0);
|
EXPECT_EQ(100, *ptr0);
|
||||||
|
|
||||||
int* ptr1 = new int(200);
|
int* ptr1 = new int(200);
|
||||||
SrsAutoFree(int, ptr1);
|
SrsUniquePtr<int> ptr1_uptr(ptr1);
|
||||||
EXPECT_EQ(200, *ptr1);
|
EXPECT_EQ(200, *ptr1);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -280,7 +281,7 @@ SrsSharedPtr<T> mock_shared_ptr_move_ctr(SrsSharedPtr<T> p) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedPtrMove)
|
VOID TEST(CoreSmartPtr, SharedPtrMove)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedPtr<int> p(new int(100));
|
SrsSharedPtr<int> p(new int(100));
|
||||||
|
@ -297,7 +298,7 @@ VOID TEST(CoreLogger, SharedPtrMove)
|
||||||
}
|
}
|
||||||
|
|
||||||
int* ptr = new int(100);
|
int* ptr = new int(100);
|
||||||
SrsAutoFree(int, ptr);
|
SrsUniquePtr<int> ptr_uptr(ptr);
|
||||||
EXPECT_EQ(100, *ptr);
|
EXPECT_EQ(100, *ptr);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -358,7 +359,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedResourceTypical)
|
VOID TEST(CoreSmartPtr, SharedResourceTypical)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedResource<MockIntResource>* p = new SrsSharedResource<MockIntResource>(new MockIntResource(100));
|
SrsSharedResource<MockIntResource>* p = new SrsSharedResource<MockIntResource>(new MockIntResource(100));
|
||||||
|
@ -420,7 +421,7 @@ SrsSharedResource<T> mock_shared_resource_move_ctr(SrsSharedResource<T> p) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(CoreLogger, SharedResourceMove)
|
VOID TEST(CoreSmartPtr, SharedResourceMove)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedResource<MockIntResource> p(new MockIntResource(100));
|
SrsSharedResource<MockIntResource> p(new MockIntResource(100));
|
||||||
|
@ -439,3 +440,52 @@ VOID TEST(CoreLogger, SharedResourceMove)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID TEST(CoreSmartPtr, UniquePtrNormal)
|
||||||
|
{
|
||||||
|
if (true) {
|
||||||
|
SrsUniquePtr<int> p(new int(100));
|
||||||
|
EXPECT_EQ(100, *p.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
int* ptr = new int(100);
|
||||||
|
SrsUniquePtr<int> ptr_uptr(ptr);
|
||||||
|
EXPECT_EQ(100, *ptr);
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsUniquePtr<MockWrapper> p(new MockWrapper(ptr));
|
||||||
|
EXPECT_EQ(101, *ptr);
|
||||||
|
EXPECT_EQ(101, *p->ptr);
|
||||||
|
|
||||||
|
SrsUniquePtr<MockWrapper> p0(new MockWrapper(ptr));
|
||||||
|
EXPECT_EQ(102, *ptr);
|
||||||
|
EXPECT_EQ(102, *p0->ptr);
|
||||||
|
}
|
||||||
|
EXPECT_EQ(100, *ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TEST(CoreSmartPtr, UniquePtrArray)
|
||||||
|
{
|
||||||
|
if (true) {
|
||||||
|
int* ptr = new int[100];
|
||||||
|
ptr[0] = 100;
|
||||||
|
|
||||||
|
SrsUniquePtr<int[]> p(ptr);
|
||||||
|
EXPECT_EQ(100, *p.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
int* ptr = new int(100);
|
||||||
|
SrsUniquePtr<int> ptr_uptr(ptr);
|
||||||
|
EXPECT_EQ(100, *ptr);
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsUniquePtr<MockWrapper[]> p(new MockWrapper[1]{MockWrapper(ptr)});
|
||||||
|
EXPECT_EQ(101, *ptr);
|
||||||
|
EXPECT_EQ(101, *(p[0].ptr));
|
||||||
|
|
||||||
|
SrsUniquePtr<MockWrapper[]> p0(new MockWrapper[1]{MockWrapper(ptr)});
|
||||||
|
EXPECT_EQ(102, *ptr);
|
||||||
|
EXPECT_EQ(102, *(p0[0].ptr));
|
||||||
|
}
|
||||||
|
EXPECT_EQ(100, *ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,8 @@ VOID TEST(ProtocolGbSipTest, SipViaBranchMagic)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_FAILED(smsg.parse(msg));
|
HELPER_ASSERT_FAILED(smsg.parse(msg));
|
||||||
|
@ -127,8 +127,9 @@ VOID TEST(ProtocolGbSipTest, SipRegisterRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
||||||
EXPECT_STREQ("/sip:registrar.biloxi.com", msg->path().c_str());
|
EXPECT_STREQ("/sip:registrar.biloxi.com", msg->path().c_str());
|
||||||
EXPECT_STREQ("SIP/2.0/UDP bobspc.biloxi.com:5060;branch=z9hG4bKnashds7", msg->header()->get("Via").c_str());
|
EXPECT_STREQ("SIP/2.0/UDP bobspc.biloxi.com:5060;branch=z9hG4bKnashds7", msg->header()->get("Via").c_str());
|
||||||
|
@ -178,8 +179,9 @@ VOID TEST(ProtocolGbSipTest, SipRegisterRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_REQUEST, (http_parser_type)msg->message_type());
|
EXPECT_EQ(HTTP_REQUEST, (http_parser_type)msg->message_type());
|
||||||
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
||||||
EXPECT_STREQ("/sip:registrar.biloxi.com", msg->path().c_str());
|
EXPECT_STREQ("/sip:registrar.biloxi.com", msg->path().c_str());
|
||||||
|
@ -193,8 +195,9 @@ VOID TEST(ProtocolGbSipTest, SipRegisterRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_REQUEST, (http_parser_type)msg->message_type());
|
EXPECT_EQ(HTTP_REQUEST, (http_parser_type)msg->message_type());
|
||||||
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
||||||
EXPECT_STREQ("/sip:registrar.biloxi.com", msg->path().c_str());
|
EXPECT_STREQ("/sip:registrar.biloxi.com", msg->path().c_str());
|
||||||
|
@ -225,8 +228,9 @@ VOID TEST(ProtocolGbSipTest, SipRegisterResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
||||||
EXPECT_EQ(200, msg->status_code());
|
EXPECT_EQ(200, msg->status_code());
|
||||||
EXPECT_STREQ("SIP/2.0/UDP bobspc.biloxi.com:5060;branch=z9hG4bKnashds7;received=192.0.2.4",
|
EXPECT_STREQ("SIP/2.0/UDP bobspc.biloxi.com:5060;branch=z9hG4bKnashds7;received=192.0.2.4",
|
||||||
|
@ -273,8 +277,9 @@ VOID TEST(ProtocolGbSipTest, SipRegisterResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type)msg->message_type());
|
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type)msg->message_type());
|
||||||
EXPECT_EQ(200, msg->status_code());
|
EXPECT_EQ(200, msg->status_code());
|
||||||
}
|
}
|
||||||
|
@ -287,8 +292,9 @@ VOID TEST(ProtocolGbSipTest, SipRegisterResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type)msg->message_type());
|
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type)msg->message_type());
|
||||||
EXPECT_EQ(200, msg->status_code());
|
EXPECT_EQ(200, msg->status_code());
|
||||||
}
|
}
|
||||||
|
@ -317,8 +323,9 @@ VOID TEST(ProtocolGbSipTest, SipSessionUacInviteRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_INVITE, msg->method());
|
EXPECT_EQ(HTTP_INVITE, msg->method());
|
||||||
EXPECT_STREQ("/sip:bob@biloxi.com", msg->path().c_str());
|
EXPECT_STREQ("/sip:bob@biloxi.com", msg->path().c_str());
|
||||||
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8", msg->header()->get("Via").c_str());
|
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8", msg->header()->get("Via").c_str());
|
||||||
|
@ -378,8 +385,9 @@ VOID TEST(ProtocolGbSipTest, SipSessionUasTryingResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
||||||
EXPECT_EQ(100, msg->status_code());
|
EXPECT_EQ(100, msg->status_code());
|
||||||
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8;received=192.0.2.1", msg->header()->get("Via").c_str());
|
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8;received=192.0.2.1", msg->header()->get("Via").c_str());
|
||||||
|
@ -434,8 +442,9 @@ VOID TEST(ProtocolGbSipTest, SipSessionUas200OkResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
||||||
EXPECT_EQ(200, msg->status_code());
|
EXPECT_EQ(200, msg->status_code());
|
||||||
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8;received=192.0.2.1", msg->header()->get("Via").c_str());
|
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8;received=192.0.2.1", msg->header()->get("Via").c_str());
|
||||||
|
@ -493,8 +502,9 @@ VOID TEST(ProtocolGbSipTest, SipSessionUacAckRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_ACK, msg->method());
|
EXPECT_EQ(HTTP_ACK, msg->method());
|
||||||
EXPECT_STREQ("/sip:bob@192.0.2.4", msg->path().c_str());
|
EXPECT_STREQ("/sip:bob@192.0.2.4", msg->path().c_str());
|
||||||
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds9", msg->header()->get("Via").c_str());
|
EXPECT_STREQ("SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds9", msg->header()->get("Via").c_str());
|
||||||
|
@ -548,8 +558,9 @@ VOID TEST(ProtocolGbSipTest, SipSessionUacByeRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_BYE, msg->method());
|
EXPECT_EQ(HTTP_BYE, msg->method());
|
||||||
EXPECT_STREQ("/sip:alice@pc33.atlanta.com", msg->path().c_str());
|
EXPECT_STREQ("/sip:alice@pc33.atlanta.com", msg->path().c_str());
|
||||||
EXPECT_STREQ("SIP/2.0/UDP 192.0.2.4;branch=z9hG4bKnashds10", msg->header()->get("Via").c_str());
|
EXPECT_STREQ("SIP/2.0/UDP 192.0.2.4;branch=z9hG4bKnashds10", msg->header()->get("Via").c_str());
|
||||||
|
@ -603,8 +614,8 @@ VOID TEST(ProtocolGbSipTest, SipRegisterExpires)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -629,8 +640,8 @@ VOID TEST(ProtocolGbSipTest, SipRegisterExpires)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -670,8 +681,8 @@ VOID TEST(ProtocolGbSipTest, SipSmallMessagesInOneBuffer)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -681,8 +692,8 @@ VOID TEST(ProtocolGbSipTest, SipSmallMessagesInOneBuffer)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -723,8 +734,8 @@ VOID TEST(ProtocolGbSipTest, SipSmallMessagesWithBody)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -735,8 +746,8 @@ VOID TEST(ProtocolGbSipTest, SipSmallMessagesWithBody)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -999,8 +1010,9 @@ VOID TEST(ProtocolGbSipTest, GbRegisterRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
EXPECT_EQ(HTTP_REGISTER, msg->method());
|
||||||
EXPECT_EQ(0, msg->content_length());
|
EXPECT_EQ(0, msg->content_length());
|
||||||
|
|
||||||
|
@ -1061,8 +1073,9 @@ VOID TEST(ProtocolGbSipTest, GbRegisterResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
EXPECT_EQ(HTTP_RESPONSE, (http_parser_type) msg->message_type());
|
||||||
EXPECT_EQ(200, msg->status_code());
|
EXPECT_EQ(200, msg->status_code());
|
||||||
EXPECT_EQ(0, msg->content_length());
|
EXPECT_EQ(0, msg->content_length());
|
||||||
|
@ -1133,8 +1146,8 @@ VOID TEST(ProtocolGbSipTest, GbInviteRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -1190,8 +1203,8 @@ VOID TEST(ProtocolGbSipTest, GbTringResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -1255,8 +1268,8 @@ VOID TEST(ProtocolGbSipTest, Gb200OkResponse)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_RESPONSE));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
@ -1309,8 +1322,8 @@ VOID TEST(ProtocolGbSipTest, GbAckRequest)
|
||||||
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
HELPER_ASSERT_SUCCESS(p.initialize(HTTP_BOTH));
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL;
|
ISrsHttpMessage* msg = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
|
||||||
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSipMessage smsg;
|
SrsSipMessage smsg;
|
||||||
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
HELPER_ASSERT_SUCCESS(smsg.parse(msg));
|
||||||
|
|
|
@ -620,7 +620,7 @@ VOID TEST(ProtocolHTTPTest, HTTPHeaderOrder)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsJsonObject* o = SrsJsonObject::object();
|
SrsJsonObject* o = SrsJsonObject::object();
|
||||||
SrsAutoFree(SrsJsonObject, o);
|
SrsUniquePtr<SrsJsonObject> o_uptr(o);
|
||||||
h.dumps(o);
|
h.dumps(o);
|
||||||
|
|
||||||
ASSERT_EQ(3, o->count());
|
ASSERT_EQ(3, o->count());
|
||||||
|
@ -633,7 +633,7 @@ VOID TEST(ProtocolHTTPTest, HTTPHeaderOrder)
|
||||||
h.del("User-Agent");
|
h.del("User-Agent");
|
||||||
|
|
||||||
SrsJsonObject* o = SrsJsonObject::object();
|
SrsJsonObject* o = SrsJsonObject::object();
|
||||||
SrsAutoFree(SrsJsonObject, o);
|
SrsUniquePtr<SrsJsonObject> o_uptr(o);
|
||||||
h.dumps(o);
|
h.dumps(o);
|
||||||
|
|
||||||
ASSERT_EQ(2, o->count());
|
ASSERT_EQ(2, o->count());
|
||||||
|
@ -645,7 +645,7 @@ VOID TEST(ProtocolHTTPTest, HTTPHeaderOrder)
|
||||||
h.del("Server");
|
h.del("Server");
|
||||||
|
|
||||||
SrsJsonObject* o = SrsJsonObject::object();
|
SrsJsonObject* o = SrsJsonObject::object();
|
||||||
SrsAutoFree(SrsJsonObject, o);
|
SrsUniquePtr<SrsJsonObject> o_uptr(o);
|
||||||
h.dumps(o);
|
h.dumps(o);
|
||||||
|
|
||||||
ASSERT_EQ(1, o->count());
|
ASSERT_EQ(1, o->count());
|
||||||
|
@ -656,7 +656,7 @@ VOID TEST(ProtocolHTTPTest, HTTPHeaderOrder)
|
||||||
h.del("Connection");
|
h.del("Connection");
|
||||||
|
|
||||||
SrsJsonObject* o = SrsJsonObject::object();
|
SrsJsonObject* o = SrsJsonObject::object();
|
||||||
SrsAutoFree(SrsJsonObject, o);
|
SrsUniquePtr<SrsJsonObject> o_uptr(o);
|
||||||
h.dumps(o);
|
h.dumps(o);
|
||||||
|
|
||||||
ASSERT_EQ(0, o->count());
|
ASSERT_EQ(0, o->count());
|
||||||
|
@ -748,7 +748,7 @@ VOID TEST(ProtocolHTTPTest, HTTPServerMuxerImplicitHandler)
|
||||||
HELPER_ASSERT_SUCCESS(s.handle("/api/", h0));
|
HELPER_ASSERT_SUCCESS(s.handle("/api/", h0));
|
||||||
|
|
||||||
MockHttpHandler* h1 = new MockHttpHandler("Done");
|
MockHttpHandler* h1 = new MockHttpHandler("Done");
|
||||||
SrsAutoFree(MockHttpHandler, h1);
|
SrsUniquePtr<MockHttpHandler> o_uptr(h1);
|
||||||
HELPER_EXPECT_FAILED(s.handle("/api/", h1));
|
HELPER_EXPECT_FAILED(s.handle("/api/", h1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,7 +893,7 @@ VOID TEST(ProtocolHTTPTest, HTTPServerMuxerBasic)
|
||||||
HELPER_ASSERT_SUCCESS(s.initialize());
|
HELPER_ASSERT_SUCCESS(s.initialize());
|
||||||
|
|
||||||
MockHttpHandler* h0 = new MockHttpHandler("Hello, world!");
|
MockHttpHandler* h0 = new MockHttpHandler("Hello, world!");
|
||||||
SrsAutoFree(MockHttpHandler, h0);
|
SrsUniquePtr<MockHttpHandler> o_uptr(h0);
|
||||||
HELPER_EXPECT_FAILED(s.handle("", h0));
|
HELPER_EXPECT_FAILED(s.handle("", h0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2154,7 +2154,7 @@ VOID TEST(ProtocolHTTPTest, ParsingLargeMessages)
|
||||||
if (true) {
|
if (true) {
|
||||||
// First message, 144 header + 315 body.
|
// First message, 144 header + 315 body.
|
||||||
io.append(p, 144 + 315); p += 144 + 315;
|
io.append(p, 144 + 315); p += 144 + 315;
|
||||||
ISrsHttpMessage* msg = NULL; SrsAutoFree(ISrsHttpMessage, msg); HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(315, msg->content_length());
|
EXPECT_EQ(315, msg->content_length());
|
||||||
|
|
||||||
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
||||||
|
@ -2164,7 +2164,7 @@ VOID TEST(ProtocolHTTPTest, ParsingLargeMessages)
|
||||||
if (true) {
|
if (true) {
|
||||||
// Second message, 164 header + 683 body.
|
// Second message, 164 header + 683 body.
|
||||||
io.append(p, 164 + 683); p += 164 + 683;
|
io.append(p, 164 + 683); p += 164 + 683;
|
||||||
ISrsHttpMessage* msg = NULL; SrsAutoFree(ISrsHttpMessage, msg); HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(683, msg->content_length());
|
EXPECT_EQ(683, msg->content_length());
|
||||||
|
|
||||||
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
||||||
|
@ -2174,7 +2174,7 @@ VOID TEST(ProtocolHTTPTest, ParsingLargeMessages)
|
||||||
if (true) {
|
if (true) {
|
||||||
// Thrid message, 144 header + 315 body.
|
// Thrid message, 144 header + 315 body.
|
||||||
io.append(p, 144 + 315); p += 144 + 315;
|
io.append(p, 144 + 315); p += 144 + 315;
|
||||||
ISrsHttpMessage* msg = NULL; SrsAutoFree(ISrsHttpMessage, msg); HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(315, msg->content_length());
|
EXPECT_EQ(315, msg->content_length());
|
||||||
|
|
||||||
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
||||||
|
@ -2184,7 +2184,7 @@ VOID TEST(ProtocolHTTPTest, ParsingLargeMessages)
|
||||||
if (true) {
|
if (true) {
|
||||||
// Forth message, 164 header + 255 body.
|
// Forth message, 164 header + 255 body.
|
||||||
io.append(p, 164 + 255); p += 164 + 255;
|
io.append(p, 164 + 255); p += 164 + 255;
|
||||||
ISrsHttpMessage* msg = NULL; SrsAutoFree(ISrsHttpMessage, msg); HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(255, msg->content_length());
|
EXPECT_EQ(255, msg->content_length());
|
||||||
|
|
||||||
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
||||||
|
@ -2197,7 +2197,7 @@ VOID TEST(ProtocolHTTPTest, ParsingLargeMessages)
|
||||||
// First, we got 4k bytes, then got the left bytes, to simulate the network read.
|
// First, we got 4k bytes, then got the left bytes, to simulate the network read.
|
||||||
r.in_bytes.push_back(string((char*)p, 4096)); p += 4096;
|
r.in_bytes.push_back(string((char*)p, 4096)); p += 4096;
|
||||||
r.in_bytes.push_back(string((char*)p, 165 + 6317 - 4096)); p += 165 + 6317 - 4096;
|
r.in_bytes.push_back(string((char*)p, 165 + 6317 - 4096)); p += 165 + 6317 - 4096;
|
||||||
ISrsHttpMessage* msg = NULL; SrsAutoFree(ISrsHttpMessage, msg); HELPER_ASSERT_SUCCESS(hp.parse_message(&r, &msg));
|
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&r, &msg)); SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(6317, msg->content_length());
|
EXPECT_EQ(6317, msg->content_length());
|
||||||
|
|
||||||
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
||||||
|
@ -2209,7 +2209,7 @@ VOID TEST(ProtocolHTTPTest, ParsingLargeMessages)
|
||||||
io.append(p, 164 + 354); p += 164 + 354;
|
io.append(p, 164 + 354); p += 164 + 354;
|
||||||
EXPECT_EQ((int)sizeof(data), p - data);
|
EXPECT_EQ((int)sizeof(data), p - data);
|
||||||
|
|
||||||
ISrsHttpMessage* msg = NULL; SrsAutoFree(ISrsHttpMessage, msg); HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); SrsUniquePtr<ISrsHttpMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(354, msg->content_length());
|
EXPECT_EQ(354, msg->content_length());
|
||||||
|
|
||||||
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
string body; HELPER_ASSERT_SUCCESS(msg->body_read_all(body));
|
||||||
|
|
|
@ -439,29 +439,27 @@ void mock_print_mp4(string data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSimpleStream* stream = new SrsSimpleStream();
|
SrsUniquePtr<SrsSimpleStream> stream(new SrsSimpleStream());
|
||||||
SrsAutoFree(SrsSimpleStream, stream);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SrsMp4Box* box = NULL;
|
SrsMp4Box* box = NULL;
|
||||||
SrsAutoFree(SrsMp4Box, box);
|
if ((err = br.read(stream.get(), &box)) != srs_success) {
|
||||||
|
|
||||||
if ((err = br.read(stream, &box)) != srs_success) {
|
|
||||||
if (srs_error_code(err) != ERROR_SYSTEM_FILE_EOF) {
|
if (srs_error_code(err) != ERROR_SYSTEM_FILE_EOF) {
|
||||||
mock_print_err(srs_error_wrap(err, "read"));
|
mock_print_err(srs_error_wrap(err, "read"));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
SrsUniquePtr<SrsMp4Box> box_uptr(box);
|
||||||
|
|
||||||
SrsBuffer* buffer = new SrsBuffer(stream->bytes(), stream->length());
|
SrsBuffer* buffer = new SrsBuffer(stream->bytes(), stream->length());
|
||||||
SrsAutoFree(SrsBuffer, buffer);
|
SrsUniquePtr<SrsBuffer> buffer_uptr(buffer);
|
||||||
|
|
||||||
if ((err = box->decode(buffer)) != srs_success) {
|
if ((err = box->decode(buffer)) != srs_success) {
|
||||||
mock_print_err(srs_error_wrap(err, "decode"));
|
mock_print_err(srs_error_wrap(err, "decode"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = br.skip(box, stream)) != srs_success) {
|
if ((err = br.skip(box, stream.get())) != srs_success) {
|
||||||
mock_print_err(srs_error_wrap(err, "skip"));
|
mock_print_err(srs_error_wrap(err, "skip"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3458,7 +3456,7 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsAudioFrame f;
|
SrsAudioFrame f;
|
||||||
SrsAudioCodecConfig* cc = new SrsAudioCodecConfig();
|
SrsAudioCodecConfig* cc = new SrsAudioCodecConfig();
|
||||||
SrsAutoFree(SrsAudioCodecConfig, cc);
|
SrsUniquePtr<SrsAudioCodecConfig> cc_uptr(cc);
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.acodec() != NULL);
|
EXPECT_TRUE(f.acodec() != NULL);
|
||||||
|
|
||||||
|
@ -3497,7 +3495,7 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
SrsAutoFree(SrsVideoCodecConfig, cc);
|
SrsUniquePtr<SrsVideoCodecConfig> cc_uptr(cc);
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
|
@ -3509,7 +3507,7 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
SrsAutoFree(SrsVideoCodecConfig, cc);
|
SrsUniquePtr<SrsVideoCodecConfig> cc_uptr(cc);
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
|
@ -3520,7 +3518,7 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
SrsAutoFree(SrsVideoCodecConfig, cc);
|
SrsUniquePtr<SrsVideoCodecConfig> cc_uptr(cc);
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
|
@ -3531,7 +3529,7 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
SrsAutoFree(SrsVideoCodecConfig, cc);
|
SrsUniquePtr<SrsVideoCodecConfig> cc_uptr(cc);
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
|
@ -3542,7 +3540,7 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
SrsAutoFree(SrsVideoCodecConfig, cc);
|
SrsUniquePtr<SrsVideoCodecConfig> cc_uptr(cc);
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
|
@ -6295,7 +6293,7 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
|
||||||
HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw)));
|
HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw)));
|
||||||
|
|
||||||
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
||||||
SrsAutoFreeA(uint8_t, cp);
|
SrsUniquePtr<uint8_t[]> cp_uptr(cp);
|
||||||
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
||||||
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, cp, fmt.nb_raw
|
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, cp, fmt.nb_raw
|
||||||
));
|
));
|
||||||
|
@ -6308,7 +6306,7 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
|
||||||
HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw)));
|
HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw)));
|
||||||
|
|
||||||
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
||||||
SrsAutoFreeA(uint8_t, cp);
|
SrsUniquePtr<uint8_t[]> cp_uptr(cp);
|
||||||
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
||||||
SrsMp4HandlerTypeSOUN, 0x00, 0, 0, cp, fmt.nb_raw
|
SrsMp4HandlerTypeSOUN, 0x00, 0, 0, cp, fmt.nb_raw
|
||||||
));
|
));
|
||||||
|
@ -6327,7 +6325,7 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
|
||||||
HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw)));
|
HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw)));
|
||||||
|
|
||||||
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
||||||
SrsAutoFreeA(uint8_t, cp);
|
SrsUniquePtr<uint8_t[]> cp_uptr(cp);
|
||||||
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
||||||
SrsMp4HandlerTypeSOUN, 0x00, 34, 34, cp, fmt.nb_raw
|
SrsMp4HandlerTypeSOUN, 0x00, 34, 34, cp, fmt.nb_raw
|
||||||
));
|
));
|
||||||
|
@ -6349,7 +6347,7 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
|
||||||
HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw)));
|
HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw)));
|
||||||
|
|
||||||
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
|
||||||
SrsAutoFreeA(uint8_t, cp);
|
SrsUniquePtr<uint8_t[]> cp_uptr(cp);
|
||||||
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
HELPER_EXPECT_SUCCESS(enc.write_sample(
|
||||||
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, cp, fmt.nb_raw
|
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, cp, fmt.nb_raw
|
||||||
));
|
));
|
||||||
|
|
|
@ -19,6 +19,7 @@ using namespace std;
|
||||||
#include <srs_protocol_http_conn.hpp>
|
#include <srs_protocol_http_conn.hpp>
|
||||||
#include <srs_protocol_protobuf.hpp>
|
#include <srs_protocol_protobuf.hpp>
|
||||||
#include <srs_kernel_buffer.hpp>
|
#include <srs_kernel_buffer.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
MockEmptyIO::MockEmptyIO()
|
MockEmptyIO::MockEmptyIO()
|
||||||
{
|
{
|
||||||
|
@ -399,7 +400,7 @@ VOID TEST(ProtocolHandshakeTest, VerifyFPC0C1)
|
||||||
// manually validate the c1
|
// manually validate the c1
|
||||||
// @see: calc_c1_digest
|
// @see: calc_c1_digest
|
||||||
char* c1s1_joined_bytes = new char[1536 -32];
|
char* c1s1_joined_bytes = new char[1536 -32];
|
||||||
SrsAutoFreeA(char, c1s1_joined_bytes);
|
SrsUniquePtr<char[]> cp_uptr(c1s1_joined_bytes);
|
||||||
HELPER_ASSERT_SUCCESS( c1.payload->copy_to(&c1, c1s1_joined_bytes, 1536 - 32, false));
|
HELPER_ASSERT_SUCCESS( c1.payload->copy_to(&c1, c1s1_joined_bytes, 1536 - 32, false));
|
||||||
|
|
||||||
bool is_valid;
|
bool is_valid;
|
||||||
|
@ -739,11 +740,11 @@ VOID TEST(ProtocolStackTest, ProtocolRecvMessage)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(proto.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(proto.decode_message(msg, &pkt));
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
|
|
||||||
SrsConnectAppPacket* spkt = dynamic_cast<SrsConnectAppPacket*>(pkt);
|
SrsConnectAppPacket* spkt = dynamic_cast<SrsConnectAppPacket*>(pkt);
|
||||||
ASSERT_TRUE(NULL != spkt);
|
ASSERT_TRUE(NULL != spkt);
|
||||||
|
@ -776,11 +777,11 @@ VOID TEST(ProtocolStackTest, ProtocolRecvMessageBug98)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(proto.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(proto.decode_message(msg, &pkt));
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
|
|
||||||
SrsUserControlPacket* spkt = dynamic_cast<SrsUserControlPacket*>(pkt);
|
SrsUserControlPacket* spkt = dynamic_cast<SrsUserControlPacket*>(pkt);
|
||||||
ASSERT_TRUE(NULL != spkt);
|
ASSERT_TRUE(NULL != spkt);
|
||||||
|
@ -813,11 +814,11 @@ VOID TEST(ProtocolStackTest, ProtocolRecvAckSizeMessage)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt = NULL;
|
SrsPacket* pkt = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(proto.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(proto.decode_message(msg, &pkt));
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
|
|
||||||
SrsSetWindowAckSizePacket* spkt = dynamic_cast<SrsSetWindowAckSizePacket*>(pkt);
|
SrsSetWindowAckSizePacket* spkt = dynamic_cast<SrsSetWindowAckSizePacket*>(pkt);
|
||||||
ASSERT_TRUE(NULL != spkt);
|
ASSERT_TRUE(NULL != spkt);
|
||||||
|
@ -849,7 +850,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVMessage)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,7 +879,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvAMessage)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -926,7 +927,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVMessage2Trunk)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1019,13 +1020,13 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAMessage)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1139,13 +1140,13 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAFmt1)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1257,13 +1258,13 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAFmt2)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1374,13 +1375,13 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAFmt3)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1519,7 +1520,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVMessage)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1527,7 +1528,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVMessage)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1535,7 +1536,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVMessage)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1689,7 +1690,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt1)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1697,7 +1698,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt1)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1705,7 +1706,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt1)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x22, msg->header.timestamp);
|
EXPECT_EQ(0x22, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1857,7 +1858,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt2)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1865,7 +1866,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt2)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -1873,7 +1874,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt2)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x22, msg->header.timestamp);
|
EXPECT_EQ(0x22, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -2024,7 +2025,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt3)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -2032,7 +2033,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt3)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -2040,7 +2041,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVFmt3)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -2094,7 +2095,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid1BNormal)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 1B cid(6bits), cid in 2-63
|
// 1B cid(6bits), cid in 2-63
|
||||||
EXPECT_EQ(0x09, msg->header.prefer_cid);
|
EXPECT_EQ(0x09, msg->header.prefer_cid);
|
||||||
|
@ -2147,7 +2148,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid1BMax)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 1B cid(6bits), max is 63
|
// 1B cid(6bits), max is 63
|
||||||
EXPECT_EQ(0x3F, msg->header.prefer_cid);
|
EXPECT_EQ(0x3F, msg->header.prefer_cid);
|
||||||
|
@ -2200,7 +2201,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid2BMin)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 2B cid(8bits), min is 64
|
// 2B cid(8bits), min is 64
|
||||||
EXPECT_EQ(64, msg->header.prefer_cid);
|
EXPECT_EQ(64, msg->header.prefer_cid);
|
||||||
|
@ -2253,7 +2254,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid2BNormal)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 2B cid(8bits), cid in 64-319
|
// 2B cid(8bits), cid in 64-319
|
||||||
EXPECT_EQ(0x10+64, msg->header.prefer_cid);
|
EXPECT_EQ(0x10+64, msg->header.prefer_cid);
|
||||||
|
@ -2306,7 +2307,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid2BNormal2)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 2B cid(8bits), cid in 64-319
|
// 2B cid(8bits), cid in 64-319
|
||||||
EXPECT_EQ(0x11+64, msg->header.prefer_cid);
|
EXPECT_EQ(0x11+64, msg->header.prefer_cid);
|
||||||
|
@ -2359,7 +2360,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid2BMax)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 2B cid(68bits), max is 319
|
// 2B cid(68bits), max is 319
|
||||||
EXPECT_EQ(319, msg->header.prefer_cid);
|
EXPECT_EQ(319, msg->header.prefer_cid);
|
||||||
|
@ -2412,7 +2413,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid3BMin)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 3B cid(16bits), min is 64
|
// 3B cid(16bits), min is 64
|
||||||
EXPECT_EQ(64, msg->header.prefer_cid);
|
EXPECT_EQ(64, msg->header.prefer_cid);
|
||||||
|
@ -2465,7 +2466,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid3BNormal)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 3B cid(16bits), cid in 64-65599
|
// 3B cid(16bits), cid in 64-65599
|
||||||
EXPECT_EQ(0x10*256+64, msg->header.prefer_cid);
|
EXPECT_EQ(0x10*256+64, msg->header.prefer_cid);
|
||||||
|
@ -2518,7 +2519,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid3BNormal2)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 3B cid(16bits), cid in 64-65599
|
// 3B cid(16bits), cid in 64-65599
|
||||||
EXPECT_EQ(0x01 + (0x10*256) + 64, msg->header.prefer_cid);
|
EXPECT_EQ(0x01 + (0x10*256) + 64, msg->header.prefer_cid);
|
||||||
|
@ -2571,7 +2572,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid3BNormal3)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 3B cid(16bits), cid in 64-65599
|
// 3B cid(16bits), cid in 64-65599
|
||||||
EXPECT_EQ(0xFF + (0x10*256) + 64, msg->header.prefer_cid);
|
EXPECT_EQ(0xFF + (0x10*256) + 64, msg->header.prefer_cid);
|
||||||
|
@ -2624,7 +2625,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid3BNormal4)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 3B cid(16bits), cid in 64-65599
|
// 3B cid(16bits), cid in 64-65599
|
||||||
EXPECT_EQ(0x02 + (0x10*256) + 64, msg->header.prefer_cid);
|
EXPECT_EQ(0x02 + (0x10*256) + 64, msg->header.prefer_cid);
|
||||||
|
@ -2677,7 +2678,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid3BMax)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 2B cid(16bits), max is 65599
|
// 2B cid(16bits), max is 65599
|
||||||
EXPECT_EQ(65599, msg->header.prefer_cid);
|
EXPECT_EQ(65599, msg->header.prefer_cid);
|
||||||
|
@ -2717,7 +2718,7 @@ VOID TEST(ProtocolStackTest, ProtocolRecvV0LenMessage)
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// protocol stack will ignore the empty video message.
|
// protocol stack will ignore the empty video message.
|
||||||
EXPECT_EQ(4, msg->header.payload_length);
|
EXPECT_EQ(4, msg->header.payload_length);
|
||||||
|
@ -2735,7 +2736,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendVMessage)
|
||||||
|
|
||||||
uint8_t data[] = {0x01, 0x02, 0x03, 0x04};
|
uint8_t data[] = {0x01, 0x02, 0x03, 0x04};
|
||||||
|
|
||||||
SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = new SrsCommonMessage(); SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->size = sizeof(data);
|
msg->size = sizeof(data);
|
||||||
msg->payload = new char[msg->size];
|
msg->payload = new char[msg->size];
|
||||||
memcpy(msg->payload, data, msg->size);
|
memcpy(msg->payload, data, msg->size);
|
||||||
|
@ -3314,7 +3315,7 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = new SrsCommonMessage(); SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.payload_length = msg->size = 4096;
|
msg->header.payload_length = msg->size = 4096;
|
||||||
msg->payload = new char[msg->size];
|
msg->payload = new char[msg->size];
|
||||||
|
|
||||||
|
@ -3337,14 +3338,14 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
ASSERT_TRUE(msg->header.is_window_ackledgement_size());
|
ASSERT_TRUE(msg->header.is_window_ackledgement_size());
|
||||||
}
|
}
|
||||||
// recv video
|
// recv video
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
ASSERT_TRUE(msg->header.is_video());
|
ASSERT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3355,14 +3356,16 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
|
||||||
}
|
}
|
||||||
// recv auto send acked size. #1
|
// recv auto send acked size. #1
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
ASSERT_TRUE(msg->header.is_ackledgement());
|
ASSERT_TRUE(msg->header.is_ackledgement());
|
||||||
}
|
}
|
||||||
|
|
||||||
// send again
|
// send again
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = new SrsCommonMessage();
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.payload_length = msg->size = 4096;
|
msg->header.payload_length = msg->size = 4096;
|
||||||
msg->payload = new char[msg->size];
|
msg->payload = new char[msg->size];
|
||||||
|
|
||||||
|
@ -3383,7 +3386,7 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
ASSERT_TRUE(msg->header.is_video());
|
ASSERT_TRUE(msg->header.is_video());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3396,7 +3399,7 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
ASSERT_TRUE(msg->header.is_ackledgement());
|
ASSERT_TRUE(msg->header.is_ackledgement());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3427,7 +3430,7 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_TRUE(msg->header.is_user_control_message());
|
EXPECT_TRUE(msg->header.is_user_control_message());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3439,12 +3442,15 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow)
|
||||||
}
|
}
|
||||||
// recv ping
|
// recv ping
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
ASSERT_TRUE(msg->header.is_user_control_message());
|
ASSERT_TRUE(msg->header.is_user_control_message());
|
||||||
|
|
||||||
SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt);
|
SrsPacket* pkt = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.decode_message(msg, &pkt));
|
HELPER_ASSERT_SUCCESS(proto.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
|
|
||||||
SrsUserControlPacket* spkt = dynamic_cast<SrsUserControlPacket*>(pkt);
|
SrsUserControlPacket* spkt = dynamic_cast<SrsUserControlPacket*>(pkt);
|
||||||
ASSERT_TRUE(spkt != NULL);
|
ASSERT_TRUE(spkt != NULL);
|
||||||
|
|
||||||
|
@ -3504,8 +3510,8 @@ VOID TEST(ProtocolStackTest, ProtocolExcpectMessage)
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
SrsConnectAppPacket* pkt = NULL;
|
SrsConnectAppPacket* pkt = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.expect_message<SrsConnectAppPacket>(&msg, &pkt));
|
HELPER_ASSERT_SUCCESS(proto.expect_message<SrsConnectAppPacket>(&msg, &pkt));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
SrsAutoFree(SrsConnectAppPacket, pkt);
|
SrsUniquePtr<SrsConnectAppPacket> pkt_uptr(pkt);
|
||||||
ASSERT_TRUE(NULL != pkt);
|
ASSERT_TRUE(NULL != pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,33 +209,37 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVFmt11)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x40, msg->header.timestamp);
|
EXPECT_EQ(0x40, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -433,33 +437,37 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVFmt11Length)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x40, msg->header.timestamp);
|
EXPECT_EQ(0x40, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -653,33 +661,37 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVFmt12)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x40, msg->header.timestamp);
|
EXPECT_EQ(0x40, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -876,35 +888,39 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVFmt12Length)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
EXPECT_EQ(0x110, msg->header.payload_length);
|
EXPECT_EQ(0x110, msg->header.payload_length);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
EXPECT_EQ(0x120, msg->header.payload_length);
|
EXPECT_EQ(0x120, msg->header.payload_length);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x40, msg->header.timestamp);
|
EXPECT_EQ(0x40, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -949,9 +965,10 @@ VOID TEST(ProtocolStackTest, ProtocolRecvExtTimeMessage)
|
||||||
};
|
};
|
||||||
bio.in_buffer.append((char*)data, sizeof(data));
|
bio.in_buffer.append((char*)data, sizeof(data));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
}
|
}
|
||||||
|
@ -993,9 +1010,10 @@ VOID TEST(ProtocolStackTest, ProtocolRecvExtTimeMessage2)
|
||||||
};
|
};
|
||||||
bio.in_buffer.append((char*)data, sizeof(data));
|
bio.in_buffer.append((char*)data, sizeof(data));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x7f010203, msg->header.timestamp);
|
EXPECT_EQ(0x7f010203, msg->header.timestamp);
|
||||||
}
|
}
|
||||||
|
@ -1038,9 +1056,10 @@ VOID TEST(ProtocolStackTest, ProtocolRecvExtTimeMessage3)
|
||||||
};
|
};
|
||||||
bio.in_buffer.append((char*)data, sizeof(data));
|
bio.in_buffer.append((char*)data, sizeof(data));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// always use 31bits timestamp
|
// always use 31bits timestamp
|
||||||
EXPECT_EQ(0x7f010203, msg->header.timestamp);
|
EXPECT_EQ(0x7f010203, msg->header.timestamp);
|
||||||
|
@ -1113,9 +1132,10 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVExtTime2Trunk)
|
||||||
};
|
};
|
||||||
bio.in_buffer.append((char*)data, sizeof(data));
|
bio.in_buffer.append((char*)data, sizeof(data));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 0xCX with extended timestamp.
|
// 0xCX with extended timestamp.
|
||||||
EXPECT_EQ(0x00010203, msg->header.timestamp);
|
EXPECT_EQ(0x00010203, msg->header.timestamp);
|
||||||
|
@ -1170,9 +1190,10 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVExtTime2Trunk2)
|
||||||
};
|
};
|
||||||
bio.in_buffer.append((char*)data, sizeof(data));
|
bio.in_buffer.append((char*)data, sizeof(data));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 0xCX without extended timestamp.
|
// 0xCX without extended timestamp.
|
||||||
EXPECT_EQ(0x00010203, msg->header.timestamp);
|
EXPECT_EQ(0x00010203, msg->header.timestamp);
|
||||||
|
@ -1223,9 +1244,10 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid1BMin)
|
||||||
};
|
};
|
||||||
bio.in_buffer.append((char*)data, sizeof(data));
|
bio.in_buffer.append((char*)data, sizeof(data));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
// 1B cid(6bits), min is 2
|
// 1B cid(6bits), min is 2
|
||||||
EXPECT_EQ(0x02, msg->header.prefer_cid);
|
EXPECT_EQ(0x02, msg->header.prefer_cid);
|
||||||
|
@ -1235,15 +1257,15 @@ VOID TEST(ProtocolKbpsTest, Connections)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsKbps, kbps);
|
SrsUniquePtr<SrsKbps> kbps_uptr(kbps);
|
||||||
|
|
||||||
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
||||||
SrsAutoFree(SrsNetworkDelta, delta);
|
SrsUniquePtr<SrsNetworkDelta> delta_uptr(delta);
|
||||||
delta->set_io(io, io);
|
delta->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1289,15 +1311,15 @@ VOID TEST(ProtocolKbpsTest, Connections)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsKbps, kbps);
|
SrsUniquePtr<SrsKbps> kbps_uptr(kbps);
|
||||||
|
|
||||||
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
||||||
SrsAutoFree(SrsNetworkDelta, delta);
|
SrsUniquePtr<SrsNetworkDelta> delta_uptr(delta);
|
||||||
delta->set_io(io, io);
|
delta->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1343,15 +1365,15 @@ VOID TEST(ProtocolKbpsTest, Connections)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsKbps, kbps);
|
SrsUniquePtr<SrsKbps> kbps_uptr(kbps);
|
||||||
|
|
||||||
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
||||||
SrsAutoFree(SrsNetworkDelta, delta);
|
SrsUniquePtr<SrsNetworkDelta> delta_uptr(delta);
|
||||||
delta->set_io(io, io);
|
delta->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1400,12 +1422,12 @@ VOID TEST(ProtocolKbpsTest, Delta)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
||||||
SrsAutoFree(SrsNetworkDelta, delta);
|
SrsUniquePtr<SrsNetworkDelta> delta_uptr(delta);
|
||||||
delta->set_io(io, io);
|
delta->set_io(io, io);
|
||||||
|
|
||||||
// No data.
|
// No data.
|
||||||
|
@ -1428,12 +1450,12 @@ VOID TEST(ProtocolKbpsTest, Delta)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
||||||
SrsAutoFree(SrsNetworkDelta, delta);
|
SrsUniquePtr<SrsNetworkDelta> delta_uptr(delta);
|
||||||
delta->set_io(io, io);
|
delta->set_io(io, io);
|
||||||
|
|
||||||
// No data.
|
// No data.
|
||||||
|
@ -1450,7 +1472,7 @@ VOID TEST(ProtocolKbpsTest, Delta)
|
||||||
|
|
||||||
// Kbps without io, gather delta.
|
// Kbps without io, gather delta.
|
||||||
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsKbps, kbps);
|
SrsUniquePtr<SrsKbps> kbps_uptr(kbps);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
kbps->sample();
|
kbps->sample();
|
||||||
|
@ -1482,16 +1504,16 @@ VOID TEST(ProtocolKbpsTest, RAWStatistic)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
||||||
SrsAutoFree(SrsNetworkDelta, delta);
|
SrsUniquePtr<SrsNetworkDelta> delta_uptr(delta);
|
||||||
delta->set_io(io, io);
|
delta->set_io(io, io);
|
||||||
|
|
||||||
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsKbps, kbps);
|
SrsUniquePtr<SrsKbps> kbps_uptr(kbps);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
kbps->add_delta(delta);
|
kbps->add_delta(delta);
|
||||||
|
@ -1522,10 +1544,10 @@ VOID TEST(ProtocolKbpsTest, RAWStatistic)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
|
|
||||||
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
SrsKbps* kbps = new SrsKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsKbps, kbps);
|
SrsUniquePtr<SrsKbps> kbps_uptr(kbps);
|
||||||
|
|
||||||
// No io, no data.
|
// No io, no data.
|
||||||
EXPECT_EQ(0, kbps->get_recv_bytes());
|
EXPECT_EQ(0, kbps->get_recv_bytes());
|
||||||
|
@ -1533,10 +1555,10 @@ VOID TEST(ProtocolKbpsTest, RAWStatistic)
|
||||||
|
|
||||||
// With io, zero data.
|
// With io, zero data.
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
SrsNetworkDelta* delta = new SrsNetworkDelta();
|
||||||
SrsAutoFree(SrsNetworkDelta, delta);
|
SrsUniquePtr<SrsNetworkDelta> delta_uptr(delta);
|
||||||
delta->set_io(io, io);
|
delta->set_io(io, io);
|
||||||
|
|
||||||
kbps->add_delta(delta);
|
kbps->add_delta(delta);
|
||||||
|
@ -1646,12 +1668,12 @@ VOID TEST(ProtocolKbpsTest, ConnectionsSugar)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsNetworkKbps, kbps);
|
SrsUniquePtr<SrsNetworkKbps> kbps_uptr(kbps);
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1694,12 +1716,12 @@ VOID TEST(ProtocolKbpsTest, ConnectionsSugar)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsNetworkKbps, kbps);
|
SrsUniquePtr<SrsNetworkKbps> kbps_uptr(kbps);
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1742,12 +1764,12 @@ VOID TEST(ProtocolKbpsTest, ConnectionsSugar)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsNetworkKbps, kbps);
|
SrsUniquePtr<SrsNetworkKbps> kbps_uptr(kbps);
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1793,13 +1815,13 @@ VOID TEST(ProtocolKbpsTest, DeltaSugar)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
// Kbps without io, gather delta.
|
// Kbps without io, gather delta.
|
||||||
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsNetworkKbps, kbps);
|
SrsUniquePtr<SrsNetworkKbps> kbps_uptr(kbps);
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1832,12 +1854,12 @@ VOID TEST(ProtocolKbpsTest, RAWStatisticSugar)
|
||||||
{
|
{
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
|
|
||||||
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsNetworkKbps, kbps);
|
SrsUniquePtr<SrsNetworkKbps> kbps_uptr(kbps);
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
// No data, 0kbps.
|
// No data, 0kbps.
|
||||||
|
@ -1867,10 +1889,10 @@ VOID TEST(ProtocolKbpsTest, RAWStatisticSugar)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockWallClock* clock = new MockWallClock();
|
MockWallClock* clock = new MockWallClock();
|
||||||
SrsAutoFree(MockWallClock, clock);
|
SrsUniquePtr<MockWallClock> clock_uptr(clock);
|
||||||
|
|
||||||
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
SrsNetworkKbps* kbps = new SrsNetworkKbps(clock->set_clock(0));
|
||||||
SrsAutoFree(SrsNetworkKbps, kbps);
|
SrsUniquePtr<SrsNetworkKbps> kbps_uptr(kbps);
|
||||||
|
|
||||||
// No io, no data.
|
// No io, no data.
|
||||||
EXPECT_EQ(0, kbps->get_recv_bytes());
|
EXPECT_EQ(0, kbps->get_recv_bytes());
|
||||||
|
@ -1878,7 +1900,7 @@ VOID TEST(ProtocolKbpsTest, RAWStatisticSugar)
|
||||||
|
|
||||||
// With io, zero data.
|
// With io, zero data.
|
||||||
MockStatistic* io = new MockStatistic();
|
MockStatistic* io = new MockStatistic();
|
||||||
SrsAutoFree(MockStatistic, io);
|
SrsUniquePtr<MockStatistic> io_uptr(io);
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
kbps->sample();
|
kbps->sample();
|
||||||
|
@ -1977,8 +1999,8 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
||||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* req = NULL;
|
ISrsHttpMessage* req = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
|
||||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> req_uptr(req);
|
||||||
|
|
||||||
char v[64] = {0};
|
char v[64] = {0};
|
||||||
HELPER_ASSERT_SUCCESS(req->body_reader()->read(v, sizeof(v), NULL));
|
HELPER_ASSERT_SUCCESS(req->body_reader()->read(v, sizeof(v), NULL));
|
||||||
|
@ -1995,8 +2017,8 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
||||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* req = NULL;
|
ISrsHttpMessage* req = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
|
||||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> req_uptr(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -2007,8 +2029,8 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
||||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* req = NULL;
|
ISrsHttpMessage* req = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
|
||||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> req_uptr(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -2019,8 +2041,8 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
||||||
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
||||||
|
|
||||||
ISrsHttpMessage* req = NULL;
|
ISrsHttpMessage* req = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
|
||||||
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> req_uptr(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2497,33 +2519,37 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x30, msg->header.timestamp);
|
EXPECT_EQ(0x30, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -2719,33 +2745,37 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVFmt1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x30, msg->header.timestamp);
|
EXPECT_EQ(0x30, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -2937,33 +2967,37 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVFmt2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x30, msg->header.timestamp);
|
EXPECT_EQ(0x30, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
@ -3153,33 +3187,37 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVAVVFmt3)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x10, msg->header.timestamp);
|
EXPECT_EQ(0x10, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_audio());
|
EXPECT_TRUE(msg->header.is_audio());
|
||||||
EXPECT_EQ(0x15, msg->header.timestamp);
|
EXPECT_EQ(0x15, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x20, msg->header.timestamp);
|
EXPECT_EQ(0x20, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg_raw = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg_raw));
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg(msg_raw);
|
||||||
|
|
||||||
EXPECT_TRUE(msg->header.is_video());
|
EXPECT_TRUE(msg->header.is_video());
|
||||||
EXPECT_EQ(0x30, msg->header.timestamp);
|
EXPECT_EQ(0x30, msg->header.timestamp);
|
||||||
EXPECT_EQ(0x01, msg->header.stream_id);
|
EXPECT_EQ(0x01, msg->header.stream_id);
|
||||||
|
|
|
@ -711,7 +711,7 @@ VOID TEST(KernelRTCTest, NACKFetchRTPPacket)
|
||||||
|
|
||||||
SrsRtcTrackDescription ds;
|
SrsRtcTrackDescription ds;
|
||||||
SrsRtcVideoSendTrack* track = new SrsRtcVideoSendTrack(&s, &ds);
|
SrsRtcVideoSendTrack* track = new SrsRtcVideoSendTrack(&s, &ds);
|
||||||
SrsAutoFree(SrsRtcVideoSendTrack, track);
|
SrsUniquePtr<SrsRtcVideoSendTrack> track_uptr(track);
|
||||||
|
|
||||||
// The RTP queue will free the packet.
|
// The RTP queue will free the packet.
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -975,7 +975,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportNormal)
|
||||||
if (true)
|
if (true)
|
||||||
{
|
{
|
||||||
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
||||||
SrsAutoFree(SrsRtpPacket, video_rtp_pkt);
|
SrsUniquePtr<SrsRtpPacket> video_rtp_pkt_uptr(video_rtp_pkt);
|
||||||
|
|
||||||
uint32_t video_absolute_ts = srs_get_system_time();
|
uint32_t video_absolute_ts = srs_get_system_time();
|
||||||
uint32_t video_rtp_ts = random();
|
uint32_t video_rtp_ts = random();
|
||||||
|
@ -988,7 +988,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportNormal)
|
||||||
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
||||||
|
|
||||||
SrsRtcpSR* video_sr = new SrsRtcpSR();
|
SrsRtcpSR* video_sr = new SrsRtcpSR();
|
||||||
SrsAutoFree(SrsRtcpSR, video_sr);
|
SrsUniquePtr<SrsRtcpSR> video_sr_uptr(video_sr);
|
||||||
video_sr->set_ssrc(200);
|
video_sr->set_ssrc(200);
|
||||||
|
|
||||||
video_sr->set_ntp(ntp.ntp_);
|
video_sr->set_ntp(ntp.ntp_);
|
||||||
|
@ -1042,7 +1042,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportOutOfOrder)
|
||||||
if (true)
|
if (true)
|
||||||
{
|
{
|
||||||
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
||||||
SrsAutoFree(SrsRtpPacket, video_rtp_pkt);
|
SrsUniquePtr<SrsRtpPacket> video_rtp_pkt_uptr(video_rtp_pkt);
|
||||||
|
|
||||||
uint32_t video_absolute_ts = srs_get_system_time();
|
uint32_t video_absolute_ts = srs_get_system_time();
|
||||||
uint32_t video_rtp_ts = random();
|
uint32_t video_rtp_ts = random();
|
||||||
|
@ -1055,7 +1055,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportOutOfOrder)
|
||||||
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
||||||
|
|
||||||
SrsRtcpSR* video_sr1 = new SrsRtcpSR();
|
SrsRtcpSR* video_sr1 = new SrsRtcpSR();
|
||||||
SrsAutoFree(SrsRtcpSR, video_sr1);
|
SrsUniquePtr<SrsRtcpSR> video_sr1_uptr(video_sr1);
|
||||||
video_sr1->set_ssrc(200);
|
video_sr1->set_ssrc(200);
|
||||||
|
|
||||||
video_sr1->set_ntp(ntp.ntp_);
|
video_sr1->set_ntp(ntp.ntp_);
|
||||||
|
@ -1072,7 +1072,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportOutOfOrder)
|
||||||
|
|
||||||
ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
||||||
SrsRtcpSR* video_sr2 = new SrsRtcpSR();
|
SrsRtcpSR* video_sr2 = new SrsRtcpSR();
|
||||||
SrsAutoFree(SrsRtcpSR, video_sr2);
|
SrsUniquePtr<SrsRtcpSR> video_sr2_uptr(video_sr2);
|
||||||
video_sr2->set_ssrc(200);
|
video_sr2->set_ssrc(200);
|
||||||
video_sr2->set_ntp(ntp.ntp_);
|
video_sr2->set_ntp(ntp.ntp_);
|
||||||
video_sr2->set_rtp_ts(video_rtp_ts);
|
video_sr2->set_rtp_ts(video_rtp_ts);
|
||||||
|
@ -1114,7 +1114,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportConsecutive)
|
||||||
if (true)
|
if (true)
|
||||||
{
|
{
|
||||||
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
||||||
SrsAutoFree(SrsRtpPacket, video_rtp_pkt);
|
SrsUniquePtr<SrsRtpPacket> video_rtp_pkt_uptr(video_rtp_pkt);
|
||||||
|
|
||||||
uint32_t video_absolute_ts = srs_get_system_time();
|
uint32_t video_absolute_ts = srs_get_system_time();
|
||||||
uint32_t video_rtp_ts = random();
|
uint32_t video_rtp_ts = random();
|
||||||
|
@ -1127,7 +1127,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportConsecutive)
|
||||||
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
||||||
|
|
||||||
SrsRtcpSR* video_sr = new SrsRtcpSR();
|
SrsRtcpSR* video_sr = new SrsRtcpSR();
|
||||||
SrsAutoFree(SrsRtcpSR, video_sr);
|
SrsUniquePtr<SrsRtcpSR> video_sr_uptr(video_sr);
|
||||||
video_sr->set_ssrc(200);
|
video_sr->set_ssrc(200);
|
||||||
|
|
||||||
video_sr->set_ntp(ntp.ntp_);
|
video_sr->set_ntp(ntp.ntp_);
|
||||||
|
@ -1219,7 +1219,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportDuplicated)
|
||||||
if (true)
|
if (true)
|
||||||
{
|
{
|
||||||
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
SrsRtpPacket* video_rtp_pkt = new SrsRtpPacket();
|
||||||
SrsAutoFree(SrsRtpPacket, video_rtp_pkt);
|
SrsUniquePtr<SrsRtpPacket> video_rtp_pkt_uptr(video_rtp_pkt);
|
||||||
|
|
||||||
uint32_t video_absolute_ts = srs_get_system_time();
|
uint32_t video_absolute_ts = srs_get_system_time();
|
||||||
uint32_t video_rtp_ts = random();
|
uint32_t video_rtp_ts = random();
|
||||||
|
@ -1232,7 +1232,7 @@ VOID TEST(KernelRTCTest, SyncTimestampBySenderReportDuplicated)
|
||||||
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
SrsNtp ntp = SrsNtp::from_time_ms(video_absolute_ts);
|
||||||
|
|
||||||
SrsRtcpSR* video_sr = new SrsRtcpSR();
|
SrsRtcpSR* video_sr = new SrsRtcpSR();
|
||||||
SrsAutoFree(SrsRtcpSR, video_sr);
|
SrsUniquePtr<SrsRtcpSR> video_sr_uptr(video_sr);
|
||||||
video_sr->set_ssrc(200);
|
video_sr->set_ssrc(200);
|
||||||
|
|
||||||
video_sr->set_ntp(ntp.ntp_);
|
video_sr->set_ntp(ntp.ntp_);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <srs_kernel_buffer.hpp>
|
#include <srs_kernel_buffer.hpp>
|
||||||
#include <srs_kernel_codec.hpp>
|
#include <srs_kernel_codec.hpp>
|
||||||
#include <srs_protocol_utility.hpp>
|
#include <srs_protocol_utility.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
#define SRS_DEFAULT_RECV_BUFFER_SIZE 131072
|
#define SRS_DEFAULT_RECV_BUFFER_SIZE 131072
|
||||||
|
|
||||||
|
@ -246,7 +247,7 @@ VOID TEST(ProtocolRTMPTest, SendPacketsError)
|
||||||
|
|
||||||
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
||||||
msg->create(&pkt);
|
msg->create(&pkt);
|
||||||
SrsAutoFree(SrsSharedPtrMessage, msg);
|
SrsUniquePtr<SrsSharedPtrMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSharedPtrMessage* msgs[10240];
|
SrsSharedPtrMessage* msgs[10240];
|
||||||
for (int i = 0; i < 10240; i++) {
|
for (int i = 0; i < 10240; i++) {
|
||||||
|
@ -358,7 +359,7 @@ VOID TEST(ProtocolRTMPTest, HugeMessages)
|
||||||
|
|
||||||
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
||||||
msg->create(&pkt);
|
msg->create(&pkt);
|
||||||
SrsAutoFree(SrsSharedPtrMessage, msg);
|
SrsUniquePtr<SrsSharedPtrMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSharedPtrMessage* msgs[1024];
|
SrsSharedPtrMessage* msgs[1024];
|
||||||
for (int i = 0; i < 1024; i++) {
|
for (int i = 0; i < 1024; i++) {
|
||||||
|
@ -380,7 +381,7 @@ VOID TEST(ProtocolRTMPTest, HugeMessages)
|
||||||
|
|
||||||
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
||||||
msg->create(&pkt);
|
msg->create(&pkt);
|
||||||
SrsAutoFree(SrsSharedPtrMessage, msg);
|
SrsUniquePtr<SrsSharedPtrMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsSharedPtrMessage* msgs[10240];
|
SrsSharedPtrMessage* msgs[10240];
|
||||||
for (int i = 0; i < 10240; i++) {
|
for (int i = 0; i < 10240; i++) {
|
||||||
|
@ -435,9 +436,10 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages)
|
||||||
// Always response ACK message.
|
// Always response ACK message.
|
||||||
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
|
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
io.in_buffer.append(&bytes);
|
io.in_buffer.append(&bytes);
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,12 +463,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages2)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x01, 's', 0x00, 0,0,0,0,0,0,0,0, 0x03,0,0,9};
|
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x01, 's', 0x00, 0,0,0,0,0,0,0,0, 0x03,0,0,9};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
|
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
|
|
||||||
SrsCallPacket* call = (SrsCallPacket*)pkt;
|
SrsCallPacket* call = (SrsCallPacket*)pkt;
|
||||||
EXPECT_STREQ("s", call->command_name.c_str());
|
EXPECT_STREQ("s", call->command_name.c_str());
|
||||||
|
@ -478,13 +480,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages2)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x01, 's'};
|
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x01, 's'};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
|
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -493,13 +494,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages2)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x00};
|
uint8_t bytes[] = {0x00};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.message_type = 0xff;
|
msg->header.message_type = 0xff;
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -508,13 +508,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages2)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x01, 's'};
|
uint8_t bytes[] = {0x02, 0x00, 0x01, 's'};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.message_type = RTMP_MSG_AMF0DataMessage;
|
msg->header.message_type = RTMP_MSG_AMF0DataMessage;
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,14 +527,13 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t'};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t'};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.message_type = RTMP_MSG_AMF0DataMessage;
|
msg->header.message_type = RTMP_MSG_AMF0DataMessage;
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Decode the response failed, no transaction ID was set by request.
|
// Decode the response failed, no transaction ID was set by request.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -544,14 +542,13 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x07, '_','r','e','s','u','l','t'};
|
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x07, '_','r','e','s','u','l','t'};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.message_type = RTMP_MSG_AMF3DataMessage;
|
msg->header.message_type = RTMP_MSG_AMF3DataMessage;
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Decode the response failed, no transaction ID was set by request.
|
// Decode the response failed, no transaction ID was set by request.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -560,14 +557,13 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x17, 0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
|
msg->header.message_type = RTMP_MSG_AMF3CommandMessage;
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Decode the response failed, no transaction ID was set by request.
|
// Decode the response failed, no transaction ID was set by request.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -580,13 +576,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the response packet.
|
// Without enough data, it fail when decoding the response packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -599,13 +594,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the response packet.
|
// Without enough data, it fail when decoding the response packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -618,13 +612,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the response packet.
|
// Without enough data, it fail when decoding the response packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -637,13 +630,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the response packet.
|
// Without enough data, it fail when decoding the response packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -657,13 +649,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the response packet.
|
// Without enough data, it fail when decoding the response packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -677,13 +668,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages3)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, '_','r','e','s','u','l','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the response packet.
|
// Without enough data, it fail when decoding the response packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,13 +687,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 0x07, 'c','o','n','n','e','c','t', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 0x07, 'c','o','n','n','e','c','t', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -712,13 +701,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 12, 'c','r','e','a','t','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 12, 'c','r','e','a','t','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -727,13 +715,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 4, 'p','l','a','y', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 4, 'p','l','a','y', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -742,13 +729,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 5, 'p','a','u','s','e', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 5, 'p','a','u','s','e', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -757,13 +743,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 13, 'r','e','l','e','a','s','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 13, 'r','e','l','e','a','s','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -772,13 +757,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 9, 'F','C','P','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 9, 'F','C','P','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -787,13 +771,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 7, 'p','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 7, 'p','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -802,13 +785,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 11, 'F','C','U','n','p','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 11, 'F','C','U','n','p','u','b','l','i','s','h', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -817,13 +799,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 13, '@','s','e','t','D','a','t','a','F','r','a','m','e', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 13, '@','s','e','t','D','a','t','a','F','r','a','m','e', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -832,12 +813,11 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 10, 'o','n','M','e','t','a','D','a','t','a', 03,0,0,9};
|
uint8_t bytes[] = {0x02, 0x00, 10, 'o','n','M','e','t','a','D','a','t','a', 03,0,0,9};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -846,13 +826,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
|
|
||||||
uint8_t bytes[] = {0x02, 0x00, 11, 'c','l','o','s','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 11, 'c','l','o','s','e','S','t','r','e','a','m', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -862,13 +841,12 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages4)
|
||||||
uint8_t bytes[] = {0x02, 0x00, 3, 's','r','s', 0x00,0,0,0,0,0,0,0,0};
|
uint8_t bytes[] = {0x02, 0x00, 3, 's','r','s', 0x00,0,0,0,0,0,0,0,0};
|
||||||
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
SrsCommonMessage* msg = _create_amf0((char*)bytes, sizeof(bytes), 1);
|
||||||
msg->header.message_type = RTMP_MSG_AMF0CommandMessage;
|
msg->header.message_type = RTMP_MSG_AMF0CommandMessage;
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt;
|
SrsPacket* pkt;
|
||||||
SrsAutoFree(SrsPacket, pkt);
|
|
||||||
|
|
||||||
// Without enough data, it fail when decoding the request packet.
|
// Without enough data, it fail when decoding the request packet.
|
||||||
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_FAILED(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -883,8 +861,9 @@ VOID TEST(ProtocolRTMPTest, RecvMessage)
|
||||||
uint8_t bytes[] = {0x01, 0x00, 0x00};
|
uint8_t bytes[] = {0x01, 0x00, 0x00};
|
||||||
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -894,8 +873,9 @@ VOID TEST(ProtocolRTMPTest, RecvMessage)
|
||||||
uint8_t bytes[] = {0x00, 0x00};
|
uint8_t bytes[] = {0x00, 0x00};
|
||||||
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -905,16 +885,18 @@ VOID TEST(ProtocolRTMPTest, RecvMessage)
|
||||||
uint8_t bytes[] = {0x00};
|
uint8_t bytes[] = {0x00};
|
||||||
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
MockBufferIO io;
|
MockBufferIO io;
|
||||||
SrsProtocol p(&io);
|
SrsProtocol p(&io);
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -929,8 +911,9 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
|
||||||
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
|
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
|
||||||
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -943,14 +926,16 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
|
||||||
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
uint8_t bytes2[] = {0x43, 0,0,0, 0,0,5, 0, 0,0,0,0, 1,2,3};
|
uint8_t bytes2[] = {0x43, 0,0,0, 0,0,5, 0, 0,0,0,0, 1,2,3};
|
||||||
io.in_buffer.append((char*)bytes2, sizeof(bytes2));
|
io.in_buffer.append((char*)bytes2, sizeof(bytes2));
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -960,8 +945,9 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
|
||||||
uint8_t bytes[] = {0x03};
|
uint8_t bytes[] = {0x03};
|
||||||
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -971,8 +957,9 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
|
||||||
uint8_t bytes[] = {0x43, 0,0,0, 0,0,0, 0};
|
uint8_t bytes[] = {0x43, 0,0,0, 0,0,0, 0};
|
||||||
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
io.in_buffer.append((char*)bytes, sizeof(bytes));
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
HELPER_EXPECT_FAILED(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,8 +1041,9 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
|
||||||
|
|
||||||
io.in_buffer.append(&io.out_buffer);
|
io.in_buffer.append(&io.out_buffer);
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(256, p.out_chunk_size);
|
EXPECT_EQ(256, p.out_chunk_size);
|
||||||
}
|
}
|
||||||
|
@ -1071,8 +1059,9 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
|
||||||
|
|
||||||
io.in_buffer.append(&io.out_buffer);
|
io.in_buffer.append(&io.out_buffer);
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(256, p.in_buffer_length);
|
EXPECT_EQ(256, p.in_buffer_length);
|
||||||
}
|
}
|
||||||
|
@ -1526,8 +1515,9 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
|
||||||
|
|
||||||
SrsProtocol p(&tio);
|
SrsProtocol p(&tio);
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
EXPECT_EQ(1024, p.in_chunk_size);
|
EXPECT_EQ(1024, p.in_chunk_size);
|
||||||
}
|
}
|
||||||
|
@ -2247,8 +2237,9 @@ VOID TEST(ProtocolRTMPTest, CoverAll)
|
||||||
EXPECT_EQ(0, r.get_recv_bytes());
|
EXPECT_EQ(0, r.get_recv_bytes());
|
||||||
EXPECT_EQ(0, r.get_send_bytes());
|
EXPECT_EQ(0, r.get_send_bytes());
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(r.recv_message(&msg));
|
HELPER_EXPECT_FAILED(r.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsCallPacket* pkt = new SrsCallPacket();
|
SrsCallPacket* pkt = new SrsCallPacket();
|
||||||
HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0));
|
HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0));
|
||||||
|
@ -2270,8 +2261,9 @@ VOID TEST(ProtocolRTMPTest, CoverAll)
|
||||||
EXPECT_EQ(0, r.get_recv_bytes());
|
EXPECT_EQ(0, r.get_recv_bytes());
|
||||||
EXPECT_EQ(0, r.get_send_bytes());
|
EXPECT_EQ(0, r.get_send_bytes());
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_FAILED(r.recv_message(&msg));
|
HELPER_EXPECT_FAILED(r.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsCallPacket* pkt = new SrsCallPacket();
|
SrsCallPacket* pkt = new SrsCallPacket();
|
||||||
HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0));
|
HELPER_EXPECT_SUCCESS(r.send_and_free_packet(pkt, 0));
|
||||||
|
@ -2328,7 +2320,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
|
|
||||||
int nn = name->total_size() + arr->total_size();
|
int nn = name->total_size() + arr->total_size();
|
||||||
char* b = new char[nn];
|
char* b = new char[nn];
|
||||||
SrsAutoFreeA(char, b);
|
SrsUniquePtr<char[]> cp_uptr(b);
|
||||||
|
|
||||||
SrsBuffer buf(b, nn);
|
SrsBuffer buf(b, nn);
|
||||||
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
||||||
|
@ -2336,7 +2328,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
srs_freep(name); srs_freep(arr);
|
srs_freep(name); srs_freep(arr);
|
||||||
|
|
||||||
SrsOnMetaDataPacket* p = new SrsOnMetaDataPacket();
|
SrsOnMetaDataPacket* p = new SrsOnMetaDataPacket();
|
||||||
SrsAutoFree(SrsOnMetaDataPacket, p);
|
SrsUniquePtr<SrsOnMetaDataPacket> p_uptr(p);
|
||||||
|
|
||||||
buf.skip(-1 * buf.pos());
|
buf.skip(-1 * buf.pos());
|
||||||
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
||||||
|
@ -2405,7 +2397,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
|
|
||||||
int nn = name->total_size() + tid->total_size() + null->total_size() + is_pause->total_size() + ts->total_size();
|
int nn = name->total_size() + tid->total_size() + null->total_size() + is_pause->total_size() + ts->total_size();
|
||||||
char* b = new char[nn];
|
char* b = new char[nn];
|
||||||
SrsAutoFreeA(char, b);
|
SrsUniquePtr<char[]> cp_uptr(b);
|
||||||
|
|
||||||
SrsBuffer buf(b, nn);
|
SrsBuffer buf(b, nn);
|
||||||
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
||||||
|
@ -2416,7 +2408,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(is_pause); srs_freep(ts);
|
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(is_pause); srs_freep(ts);
|
||||||
|
|
||||||
SrsPausePacket* p = new SrsPausePacket();
|
SrsPausePacket* p = new SrsPausePacket();
|
||||||
SrsAutoFree(SrsPausePacket, p);
|
SrsUniquePtr<SrsPausePacket> p_uptr(p);
|
||||||
|
|
||||||
buf.skip(-1 * buf.pos());
|
buf.skip(-1 * buf.pos());
|
||||||
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
||||||
|
@ -2435,7 +2427,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
|
|
||||||
int nn = name->total_size() + tid->total_size() + null->total_size() + stream_name->total_size() + start->total_size() + duration->total_size() + reset->total_size();
|
int nn = name->total_size() + tid->total_size() + null->total_size() + stream_name->total_size() + start->total_size() + duration->total_size() + reset->total_size();
|
||||||
char* b = new char[nn];
|
char* b = new char[nn];
|
||||||
SrsAutoFreeA(char, b);
|
SrsUniquePtr<char[]> cp_uptr(b);
|
||||||
|
|
||||||
SrsBuffer buf(b, nn);
|
SrsBuffer buf(b, nn);
|
||||||
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
||||||
|
@ -2448,7 +2440,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(stream_name); srs_freep(start); srs_freep(duration); srs_freep(reset);
|
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(stream_name); srs_freep(start); srs_freep(duration); srs_freep(reset);
|
||||||
|
|
||||||
SrsPlayPacket* p = new SrsPlayPacket();
|
SrsPlayPacket* p = new SrsPlayPacket();
|
||||||
SrsAutoFree(SrsPlayPacket, p);
|
SrsUniquePtr<SrsPlayPacket> p_uptr(p);
|
||||||
|
|
||||||
buf.skip(-1 * buf.pos());
|
buf.skip(-1 * buf.pos());
|
||||||
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
||||||
|
@ -2469,7 +2461,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
|
|
||||||
int nn = name->total_size() + tid->total_size() + null->total_size() + stream_name->total_size() + start->total_size() + duration->total_size() + reset->total_size();
|
int nn = name->total_size() + tid->total_size() + null->total_size() + stream_name->total_size() + start->total_size() + duration->total_size() + reset->total_size();
|
||||||
char* b = new char[nn];
|
char* b = new char[nn];
|
||||||
SrsAutoFreeA(char, b);
|
SrsUniquePtr<char[]> cp_uptr(b);
|
||||||
|
|
||||||
SrsBuffer buf(b, nn);
|
SrsBuffer buf(b, nn);
|
||||||
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
||||||
|
@ -2482,7 +2474,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(stream_name); srs_freep(start); srs_freep(duration); srs_freep(reset);
|
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(stream_name); srs_freep(start); srs_freep(duration); srs_freep(reset);
|
||||||
|
|
||||||
SrsPlayPacket* p = new SrsPlayPacket();
|
SrsPlayPacket* p = new SrsPlayPacket();
|
||||||
SrsAutoFree(SrsPlayPacket, p);
|
SrsUniquePtr<SrsPlayPacket> p_uptr(p);
|
||||||
|
|
||||||
buf.skip(-1 * buf.pos());
|
buf.skip(-1 * buf.pos());
|
||||||
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
HELPER_ASSERT_SUCCESS(p->decode(&buf));
|
||||||
|
@ -2503,7 +2495,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
|
|
||||||
int nn = name->total_size() + tid->total_size() + null->total_size() + stream_name->total_size() + start->total_size() + duration->total_size() + reset->total_size();
|
int nn = name->total_size() + tid->total_size() + null->total_size() + stream_name->total_size() + start->total_size() + duration->total_size() + reset->total_size();
|
||||||
char* b = new char[nn];
|
char* b = new char[nn];
|
||||||
SrsAutoFreeA(char, b);
|
SrsUniquePtr<char[]> cp_uptr(b);
|
||||||
|
|
||||||
SrsBuffer buf(b, nn);
|
SrsBuffer buf(b, nn);
|
||||||
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
HELPER_ASSERT_SUCCESS(name->write(&buf));
|
||||||
|
@ -2516,7 +2508,7 @@ VOID TEST(ProtocolRTMPTest, CoverAllUnmarshal)
|
||||||
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(stream_name); srs_freep(start); srs_freep(duration); srs_freep(reset);
|
srs_freep(name); srs_freep(tid); srs_freep(null); srs_freep(stream_name); srs_freep(start); srs_freep(duration); srs_freep(reset);
|
||||||
|
|
||||||
SrsPlayPacket* p = new SrsPlayPacket();
|
SrsPlayPacket* p = new SrsPlayPacket();
|
||||||
SrsAutoFree(SrsPlayPacket, p);
|
SrsUniquePtr<SrsPlayPacket> p_uptr(p);
|
||||||
|
|
||||||
buf.skip(-1 * buf.pos());
|
buf.skip(-1 * buf.pos());
|
||||||
HELPER_EXPECT_FAILED(p->decode(&buf));
|
HELPER_EXPECT_FAILED(p->decode(&buf));
|
||||||
|
@ -2593,9 +2585,11 @@ VOID TEST(ProtocolRTMPTest, ConnectAppWithArgs)
|
||||||
if (true) {
|
if (true) {
|
||||||
tio.in_buffer.append(&io.out_buffer);
|
tio.in_buffer.append(&io.out_buffer);
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
SrsConnectAppPacket* pkt = NULL; SrsAutoFree(SrsConnectAppPacket, pkt);
|
SrsConnectAppPacket* pkt = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
|
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
SrsUniquePtr<SrsConnectAppPacket> pkt_uptr(pkt);
|
||||||
|
|
||||||
SrsAmf0Any* prop = pkt->command_object->get_property("tcUrl");
|
SrsAmf0Any* prop = pkt->command_object->get_property("tcUrl");
|
||||||
ASSERT_TRUE(prop && prop->is_string());
|
ASSERT_TRUE(prop && prop->is_string());
|
||||||
|
@ -2624,8 +2618,9 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2640,11 +2635,13 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(p.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt);
|
SrsPacket* pkt = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2659,8 +2656,9 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2675,11 +2673,13 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_ASSERT_SUCCESS(p.recv_message(&msg));
|
HELPER_ASSERT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt);
|
SrsPacket* pkt = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
|
||||||
|
SrsUniquePtr<SrsPacket> pkt_uptr(pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2689,7 +2689,7 @@ srs_error_t _mock_packet_to_shared_msg(SrsPacket* packet, int stream_id, SrsShar
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsCommonMessage* msg = new SrsCommonMessage();
|
SrsCommonMessage* msg = new SrsCommonMessage();
|
||||||
SrsAutoFree(SrsCommonMessage, msg);
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
|
|
||||||
if ((err = packet->to_msg(msg, stream_id)) != srs_success) {
|
if ((err = packet->to_msg(msg, stream_id)) != srs_success) {
|
||||||
srs_freep(msg);
|
srs_freep(msg);
|
||||||
|
@ -2714,7 +2714,7 @@ VOID TEST(ProtocolRTMPTest, CheckStreamID)
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedPtrMessage* shared_msgs[2];
|
SrsSharedPtrMessage* shared_msgs[2];
|
||||||
SrsConnectAppPacket* res = new SrsConnectAppPacket();
|
SrsConnectAppPacket* res = new SrsConnectAppPacket();
|
||||||
SrsAutoFree(SrsConnectAppPacket, res);
|
SrsUniquePtr<SrsConnectAppPacket> res_uptr(res);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsSharedPtrMessage* shared_msg = new SrsSharedPtrMessage();
|
SrsSharedPtrMessage* shared_msg = new SrsSharedPtrMessage();
|
||||||
|
@ -2733,14 +2733,16 @@ VOID TEST(ProtocolRTMPTest, CheckStreamID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(1, msg->header.stream_id);
|
EXPECT_EQ(1, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
EXPECT_EQ(2, msg->header.stream_id);
|
EXPECT_EQ(2, msg->header.stream_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2765,8 +2767,9 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2785,8 +2788,9 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2805,8 +2809,9 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2825,8 +2830,9 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2859,8 +2865,9 @@ VOID TEST(ProtocolRTMPTest, MergeReadHandler)
|
||||||
r.set_merge_read(true, &h);
|
r.set_merge_read(true, &h);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
|
SrsCommonMessage* msg = NULL;
|
||||||
HELPER_EXPECT_SUCCESS(r.recv_message(&msg));
|
HELPER_EXPECT_SUCCESS(r.recv_message(&msg));
|
||||||
|
SrsUniquePtr<SrsCommonMessage> msg_uptr(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_TRUE(h.nn > 0);
|
EXPECT_TRUE(h.nn > 0);
|
||||||
|
|
|
@ -11,6 +11,7 @@ using namespace std;
|
||||||
#include <srs_app_listener.hpp>
|
#include <srs_app_listener.hpp>
|
||||||
#include <srs_protocol_st.hpp>
|
#include <srs_protocol_st.hpp>
|
||||||
#include <srs_protocol_utility.hpp>
|
#include <srs_protocol_utility.hpp>
|
||||||
|
#include <srs_core_deprecated.hpp>
|
||||||
|
|
||||||
#include <srs_protocol_st.hpp>
|
#include <srs_protocol_st.hpp>
|
||||||
#include <srs_protocol_http_conn.hpp>
|
#include <srs_protocol_http_conn.hpp>
|
||||||
|
@ -635,8 +636,8 @@ VOID TEST(HTTPServerTest, ContentLength)
|
||||||
io.append("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n");
|
io.append("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
||||||
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
char buf[32]; ssize_t nread = 0;
|
char buf[32]; ssize_t nread = 0;
|
||||||
ISrsHttpResponseReader* r = msg->body_reader();
|
ISrsHttpResponseReader* r = msg->body_reader();
|
||||||
|
@ -664,8 +665,8 @@ VOID TEST(HTTPServerTest, HTTPChunked)
|
||||||
io.append("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
|
io.append("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
||||||
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
char buf[32]; ssize_t nread = 0;
|
char buf[32]; ssize_t nread = 0;
|
||||||
ISrsHttpResponseReader* r = msg->body_reader();
|
ISrsHttpResponseReader* r = msg->body_reader();
|
||||||
|
@ -694,8 +695,8 @@ VOID TEST(HTTPServerTest, InfiniteChunked)
|
||||||
io.append("HTTP/1.1 200 OK\r\n\r\n");
|
io.append("HTTP/1.1 200 OK\r\n\r\n");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
||||||
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
char buf[32]; ssize_t nread = 0;
|
char buf[32]; ssize_t nread = 0;
|
||||||
ISrsHttpResponseReader* r = msg->body_reader();
|
ISrsHttpResponseReader* r = msg->body_reader();
|
||||||
|
@ -721,8 +722,8 @@ VOID TEST(HTTPServerTest, InfiniteChunked)
|
||||||
io.append("HTTP/1.1 200 OK\r\n\r\n");
|
io.append("HTTP/1.1 200 OK\r\n\r\n");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
||||||
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
|
ISrsHttpMessage* msg_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, msg);
|
SrsUniquePtr<ISrsHttpMessage> msg(msg_raw);
|
||||||
|
|
||||||
char buf[32]; ssize_t nread = 0;
|
char buf[32]; ssize_t nread = 0;
|
||||||
ISrsHttpResponseReader* r = msg->body_reader();
|
ISrsHttpResponseReader* r = msg->body_reader();
|
||||||
|
@ -750,8 +751,8 @@ VOID TEST(HTTPServerTest, OPTIONSRead)
|
||||||
io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\n\r\n");
|
io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\n\r\n");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
||||||
ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req));
|
ISrsHttpMessage* req_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
SrsUniquePtr<ISrsHttpMessage> req(req_raw);
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = req->body_reader();
|
ISrsHttpResponseReader* br = req->body_reader();
|
||||||
EXPECT_TRUE(br->eof());
|
EXPECT_TRUE(br->eof());
|
||||||
|
@ -763,8 +764,8 @@ VOID TEST(HTTPServerTest, OPTIONSRead)
|
||||||
io.append("HTTP/1.1 200 OK\r\n\r\n");
|
io.append("HTTP/1.1 200 OK\r\n\r\n");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
|
||||||
ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req));
|
ISrsHttpMessage* req_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
SrsUniquePtr<ISrsHttpMessage> req(req_raw);
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = req->body_reader();
|
ISrsHttpResponseReader* br = req->body_reader();
|
||||||
EXPECT_FALSE(br->eof());
|
EXPECT_FALSE(br->eof());
|
||||||
|
@ -776,8 +777,8 @@ VOID TEST(HTTPServerTest, OPTIONSRead)
|
||||||
io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello");
|
io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
||||||
ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req));
|
ISrsHttpMessage* req_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
SrsUniquePtr<ISrsHttpMessage> req(req_raw);
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = req->body_reader();
|
ISrsHttpResponseReader* br = req->body_reader();
|
||||||
EXPECT_FALSE(br->eof());
|
EXPECT_FALSE(br->eof());
|
||||||
|
@ -787,8 +788,8 @@ VOID TEST(HTTPServerTest, OPTIONSRead)
|
||||||
|
|
||||||
// The body will use as next HTTP request message.
|
// The body will use as next HTTP request message.
|
||||||
io.append("GET /rtc/v1/play HTTP/1.1\r\n\r\n");
|
io.append("GET /rtc/v1/play HTTP/1.1\r\n\r\n");
|
||||||
ISrsHttpMessage* req2 = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req2));
|
ISrsHttpMessage* req2_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req2_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, req2);
|
SrsUniquePtr<ISrsHttpMessage> req2(req2_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
// So if OPTIONS has body, but not specified the size, we think it has no body,
|
// So if OPTIONS has body, but not specified the size, we think it has no body,
|
||||||
|
@ -798,16 +799,16 @@ VOID TEST(HTTPServerTest, OPTIONSRead)
|
||||||
io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\n\r\n");
|
io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\n\r\n");
|
||||||
|
|
||||||
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST));
|
||||||
ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req));
|
ISrsHttpMessage* req_raw = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, req);
|
SrsUniquePtr<ISrsHttpMessage> req(req_raw);
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = req->body_reader();
|
ISrsHttpResponseReader* br = req->body_reader();
|
||||||
EXPECT_TRUE(br->eof());
|
EXPECT_TRUE(br->eof());
|
||||||
|
|
||||||
// The body will use as next HTTP request message.
|
// The body will use as next HTTP request message.
|
||||||
io.append("Hello");
|
io.append("Hello");
|
||||||
ISrsHttpMessage* req2 = NULL; HELPER_ASSERT_FAILED(hp.parse_message(&io, &req2));
|
ISrsHttpMessage* req2_raw = NULL; HELPER_ASSERT_FAILED(hp.parse_message(&io, &req2_raw));
|
||||||
SrsAutoFree(ISrsHttpMessage, req2);
|
SrsUniquePtr<ISrsHttpMessage> req2(req2_raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1320,8 +1321,8 @@ VOID TEST(HTTPClientTest, HTTPClientUtility)
|
||||||
HELPER_ASSERT_SUCCESS(client.initialize("http", "127.0.0.1", 8080, 1*SRS_UTIME_SECONDS));
|
HELPER_ASSERT_SUCCESS(client.initialize("http", "127.0.0.1", 8080, 1*SRS_UTIME_SECONDS));
|
||||||
|
|
||||||
ISrsHttpMessage* res = NULL;
|
ISrsHttpMessage* res = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, res);
|
|
||||||
HELPER_ASSERT_SUCCESS(client.post("/api/v1", "", &res));
|
HELPER_ASSERT_SUCCESS(client.post("/api/v1", "", &res));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> res_uptr(res);
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = res->body_reader();
|
ISrsHttpResponseReader* br = res->body_reader();
|
||||||
ASSERT_FALSE(br->eof());
|
ASSERT_FALSE(br->eof());
|
||||||
|
@ -1342,8 +1343,8 @@ VOID TEST(HTTPClientTest, HTTPClientUtility)
|
||||||
HELPER_ASSERT_SUCCESS(client.initialize("http", "127.0.0.1", 8080, 1*SRS_UTIME_SECONDS));
|
HELPER_ASSERT_SUCCESS(client.initialize("http", "127.0.0.1", 8080, 1*SRS_UTIME_SECONDS));
|
||||||
|
|
||||||
ISrsHttpMessage* res = NULL;
|
ISrsHttpMessage* res = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, res);
|
|
||||||
HELPER_ASSERT_SUCCESS(client.get("/api/v1", "", &res));
|
HELPER_ASSERT_SUCCESS(client.get("/api/v1", "", &res));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> res_uptr(res);
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = res->body_reader();
|
ISrsHttpResponseReader* br = res->body_reader();
|
||||||
ASSERT_FALSE(br->eof());
|
ASSERT_FALSE(br->eof());
|
||||||
|
@ -1366,8 +1367,8 @@ VOID TEST(HTTPClientTest, HTTPClientUtility)
|
||||||
client.set_header("agent", "srs");
|
client.set_header("agent", "srs");
|
||||||
|
|
||||||
ISrsHttpMessage* res = NULL;
|
ISrsHttpMessage* res = NULL;
|
||||||
SrsAutoFree(ISrsHttpMessage, res);
|
|
||||||
HELPER_ASSERT_SUCCESS(client.get("/api/v1", "", &res));
|
HELPER_ASSERT_SUCCESS(client.get("/api/v1", "", &res));
|
||||||
|
SrsUniquePtr<ISrsHttpMessage> res_uptr(res);
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = res->body_reader();
|
ISrsHttpResponseReader* br = res->body_reader();
|
||||||
ASSERT_FALSE(br->eof());
|
ASSERT_FALSE(br->eof());
|
||||||
|
|
|
@ -195,8 +195,7 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept)
|
||||||
srs_srt_t srt_client_fd = srs_srt_socket_invalid();
|
srs_srt_t srt_client_fd = srs_srt_socket_invalid();
|
||||||
HELPER_EXPECT_SUCCESS(srs_srt_socket(&srt_client_fd));
|
HELPER_EXPECT_SUCCESS(srs_srt_socket(&srt_client_fd));
|
||||||
|
|
||||||
SrsSrtSocket* srt_client_socket = new SrsSrtSocket(_srt_eventloop->poller(), srt_client_fd);
|
SrsUniquePtr<SrsSrtSocket> srt_client_socket(new SrsSrtSocket(_srt_eventloop->poller(), srt_client_fd));
|
||||||
SrsAutoFree(SrsSrtSocket, srt_client_socket);
|
|
||||||
|
|
||||||
// No client connected, accept will timeout.
|
// No client connected, accept will timeout.
|
||||||
srs_srt_t srt_fd = srs_srt_socket_invalid();
|
srs_srt_t srt_fd = srs_srt_socket_invalid();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue