Skip to content
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

Merged
merged 3 commits into from
Jul 28, 2020

Conversation

sr1990
Copy link
Contributor

@sr1990 sr1990 commented Jul 21, 2020

No description provided.

@sr1990 sr1990 changed the title Writing to memory file before writing webm segments. Write to memory file before writing to file for WebM segments generation. Jul 21, 2020
Copy link
Contributor

@kqyang kqyang left a 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);
Copy link
Contributor

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.

Comment on lines 39 to 40
if (!writer_->WriteToFile(segment_name))
return Status(error::FILE_FAILURE, "Unable to write file.");
Copy link
Contributor

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()) {
...
}

Copy link
Contributor

@kqyang kqyang left a 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_ =
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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_?

Copy link
Contributor

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.

@kqyang kqyang merged commit 11d6989 into shaka-project:master Jul 28, 2020
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants