-
Notifications
You must be signed in to change notification settings - Fork 518
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
Write to memory file before writing to file for WebM segments generation. #803
Write to memory file before writing to file for WebM segments generation. #803
Conversation
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.
Thanks for the extra work. Left a few comments.
writer_.reset(new MkvWriter); | ||
Status status = writer_->Open(segment_name); | ||
Status status = writer_->Open("memory://" + segment_name); |
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.
We need to save the file name so we can delete it later. We may call it temp_file_name_.
The file name can be created from segment_name
as in your code or from TempFilePath
function.
if (!writer_->WriteToFile(segment_name)) | ||
return Status(error::FILE_FAILURE, "Unable to write file."); |
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.
A simpler approach without the need to modify MkvWriter is to use File::Copy
. Also, the file needs to be deleted otherwise the memory will not be de-allocated, which could result in memory leak.
// Close the file, which also does flushing, to make sure the file is
// written before manifest is updated.
RETURN_IF_ERROR(writer_->Close());
if (!File::Copy(temp_file_name_.c_str(), segment_name.c_str())) {
...
}
if (!File::Delete(temp_file_name_.c_str()) {
...
}
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.
Thanks. Just one more comment.
@@ -77,15 +88,16 @@ Status MultiSegmentSegmenter::DoFinalize() { | |||
Status MultiSegmentSegmenter::NewSegment(uint64_t start_timestamp, | |||
bool is_subsegment) { | |||
if (!is_subsegment) { | |||
// Create a new file for the new segment. | |||
std::string segment_name = | |||
temp_file_name_ = |
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 should be either a memory file (prefix with "memory://") or an actual temporary file:
if (!TempFilePath(options().temp_dir, &temp_file_name_))
return Status(error::FILE_FAILURE, "Unable to create temporary file.");
This is because options().segment_template
could be a remote file, e.g. HttpFile. We don't want to create a temporary file there.
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.
Sorry about that. I have made the change.
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.
@kqyang Do you want to change temp_file_name_ to memory_file_name_?
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.
No. It is fine with me. Thanks.
No description provided.