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

use second sample in webm and mp4 formats #835

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packager/media/formats/mp4/segmenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ Status Segmenter::AddSample(size_t stream_id, const MediaSample& sample) {
if (!status.ok())
return status;

if (sample_duration_ == 0)
sample_duration_ = sample.duration();
if (num_samples_ < 2) {
sample_durations_[num_samples_] = sample.duration();
num_samples_++;
}
stream_durations_[stream_id] += sample.duration();
return Status::OK;
}
Expand Down
5 changes: 3 additions & 2 deletions packager/media/formats/mp4/segmenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Segmenter {

/// @return The sample duration in the timescale of the media.
/// Returns 0 if no samples are added yet.
uint32_t sample_duration() const { return sample_duration_; }
uint32_t sample_duration() const { return sample_durations_[1]; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change uint32_t to int64_t? Same below.


protected:
/// Update segmentation progress using ProgressListener.
Expand Down Expand Up @@ -144,7 +144,8 @@ class Segmenter {
ProgressListener* progress_listener_ = nullptr;
uint64_t progress_target_ = 0u;
uint64_t accumulated_progress_ = 0u;
uint32_t sample_duration_ = 0u;
uint32_t sample_durations_[2] = {0, 0};
uint32_t num_samples_ = 0u;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/uint32_t/size_t/

std::vector<uint64_t> stream_durations_;
std::vector<KeyFrameInfo> key_frame_infos_;

Expand Down
12 changes: 7 additions & 5 deletions packager/media/formats/webm/segmenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ Status Segmenter::Finalize() {
Status Segmenter::AddSample(const MediaSample& source_sample) {
std::shared_ptr<MediaSample> sample(source_sample.Clone());

if (sample_duration_ == 0) {
first_timestamp_ = sample->pts();
sample_duration_ = sample->duration();
if (muxer_listener_)
muxer_listener_->OnSampleDurationReady(sample_duration_);
if (num_samples_ < 2) {
sample_durations_[num_samples_] = sample->duration();
if (num_samples_ == 0)
first_timestamp_ = sample->pts();
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if (muxer_listener_)

muxer_listener_->OnSampleDurationReady(sample_durations_[num_samples_]);
num_samples_++;
}

UpdateProgress(sample->duration());
Expand Down
3 changes: 2 additions & 1 deletion packager/media/formats/webm/segmenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class Segmenter {
uint64_t progress_target_ = 0;
uint64_t accumulated_progress_ = 0;
uint64_t first_timestamp_ = 0;
int64_t sample_duration_ = 0;
int64_t sample_durations_[2] = {0, 0};
int64_t num_samples_ = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/int64_t/size_t/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should num_samples be size_t? I'm assuming only sample_durations_[2] needs to be size_t

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_samples_ should be size type, so it should be size_t. sample_durations_ should still be int64_t.

// The position (in bytes) of the start of the Segment payload in the init
// file. This is also the size of the header before the SeekHead.
uint64_t segment_payload_pos_ = 0;
Expand Down