-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UniquePtr: Support SrsUniquePtr to replace SrsAutoFree. v6.0.136 #4109
Conversation
#ifndef SRS_CORE_DEPRECATED_HPP | ||
#define SRS_CORE_DEPRECATED_HPP | ||
|
||
#include <srs_core.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this include header,srs_core.hpp
, is useless, can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make sure the first included file is this one.
Won't fix.
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
#include <srs_core_deprecated.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know whether it's a code conventions or not, but an empty cpp, seems useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will cause the utest fail. Please file another PR if you want to remove it.
Won't fix.
ba2a4c6
to
96ad539
Compare
// process all http messages. | ||
err = process_requests(&last_req); | ||
SrsRequest* last_req_raw = NULL; | ||
err = process_requests(&last_req_raw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err
need to freed and processed if it's not srs_success
, otherwise err != srs_success
would be a memory leak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The err is returned:
err = process_requests(&last_req_raw);
if ((r0 = on_disconnect(last_req.get())) != srs_success) {
err = srs_error_wrap(err, "on disconnect %s", srs_error_desc(r0).c_str());
srs_freep(r0);
}
return err;
Won't fix.
return srs_error_wrap(err, "create consumer, source=%s", req_->get_stream_url().c_str()); | ||
} | ||
|
||
srs_assert(consumer); | ||
srs_assert(consumer_raw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consumer_raw
will alway has value, no need to check with assert?
srs/trunk/src/app/srs_app_rtc_source.cpp
Lines 550 to 562 in baf22d0
srs_error_t SrsRtcSource::create_consumer(SrsRtcConsumer*& consumer) | |
{ | |
srs_error_t err = srs_success; | |
consumer = new SrsRtcConsumer(this); | |
consumers.push_back(consumer); | |
stream_die_at_ = 0; | |
// TODO: FIXME: Implements edge cluster. | |
return err; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bug or logic error.
Won't fix.
pkt->wrap(msg); | ||
} else { | ||
// We must free it, should never use RTP packets to free it, | ||
// because more than one RTP packet will refer to it. | ||
SrsAutoFree(SrsRtpRawNALUs, raw); | ||
SrsUniquePtr<SrsRtpRawNALUs> raw(raw_raw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather use a srs_freep(raw_raw)
manually in this else
scope to simple the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nop, it's used later:
SrsUniquePtr<SrsRtpRawNALUs> raw(raw_raw);
uint8_t header = raw->skip_first_byte();
Won't fix.
return srs_error_wrap(err, "create consumer, ts source=%s", req_->get_stream_url().c_str()); | ||
} | ||
srs_assert(consumer); | ||
|
||
srs_assert(consumer_raw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consumer_raw
always true
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bug or an error.
Won't fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all done
To manage an object:
To manage an array of objects:
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.
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).
Additionally, SrsAutoFreeH can use specific release functions, which SrsUniquePtr does not support.
Co-authored-by: Jacob Su [email protected]