Shaka Packager SDK
mp4_muxer.cc
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/media/formats/mp4/mp4_muxer.h"
8 
9 #include <algorithm>
10 
11 #include "packager/base/time/clock.h"
12 #include "packager/base/time/time.h"
13 #include "packager/file/file.h"
14 #include "packager/media/base/aes_encryptor.h"
15 #include "packager/media/base/audio_stream_info.h"
16 #include "packager/media/base/fourccs.h"
17 #include "packager/media/base/key_source.h"
18 #include "packager/media/base/media_sample.h"
19 #include "packager/media/base/text_stream_info.h"
20 #include "packager/media/base/video_stream_info.h"
21 #include "packager/media/codecs/es_descriptor.h"
22 #include "packager/media/event/muxer_listener.h"
23 #include "packager/media/formats/mp4/box_definitions.h"
24 #include "packager/media/formats/mp4/multi_segment_segmenter.h"
25 #include "packager/media/formats/mp4/single_segment_segmenter.h"
26 #include "packager/status_macros.h"
27 
28 namespace shaka {
29 namespace media {
30 namespace mp4 {
31 
32 namespace {
33 
34 // Sets the range start and end value from offset and size.
35 // |start| and |end| are for byte-range-spec specified in RFC2616.
36 void SetStartAndEndFromOffsetAndSize(size_t offset,
37  size_t size,
38  Range* range) {
39  DCHECK(range);
40  range->start = static_cast<uint32_t>(offset);
41  // Note that ranges are inclusive. So we need - 1.
42  range->end = range->start + static_cast<uint32_t>(size) - 1;
43 }
44 
45 FourCC CodecToFourCC(Codec codec, H26xStreamFormat h26x_stream_format) {
46  switch (codec) {
47  case kCodecAV1:
48  return FOURCC_av01;
49  case kCodecH264:
50  return h26x_stream_format ==
51  H26xStreamFormat::kNalUnitStreamWithParameterSetNalus
52  ? FOURCC_avc3
53  : FOURCC_avc1;
54  case kCodecH265:
55  return h26x_stream_format ==
56  H26xStreamFormat::kNalUnitStreamWithParameterSetNalus
57  ? FOURCC_hev1
58  : FOURCC_hvc1;
59  case kCodecVP8:
60  return FOURCC_vp08;
61  case kCodecVP9:
62  return FOURCC_vp09;
63  case kCodecAAC:
64  return FOURCC_mp4a;
65  case kCodecAC3:
66  return FOURCC_ac_3;
67  case kCodecDTSC:
68  return FOURCC_dtsc;
69  case kCodecDTSH:
70  return FOURCC_dtsh;
71  case kCodecDTSL:
72  return FOURCC_dtsl;
73  case kCodecDTSE:
74  return FOURCC_dtse;
75  case kCodecDTSM:
76  return FOURCC_dtsm;
77  case kCodecEAC3:
78  return FOURCC_ec_3;
79  case kCodecFlac:
80  return FOURCC_fLaC;
81  case kCodecOpus:
82  return FOURCC_Opus;
83  default:
84  return FOURCC_NULL;
85  }
86 }
87 
88 void GenerateSinf(FourCC old_type,
89  const EncryptionConfig& encryption_config,
90  ProtectionSchemeInfo* sinf) {
91  sinf->format.format = old_type;
92 
93  DCHECK_NE(encryption_config.protection_scheme, FOURCC_NULL);
94  sinf->type.type = encryption_config.protection_scheme;
95 
96  // The version of cenc implemented here. CENC 4.
97  const int kCencSchemeVersion = 0x00010000;
98  sinf->type.version = kCencSchemeVersion;
99 
100  auto& track_encryption = sinf->info.track_encryption;
101  track_encryption.default_is_protected = 1;
102 
103  track_encryption.default_crypt_byte_block =
104  encryption_config.crypt_byte_block;
105  track_encryption.default_skip_byte_block = encryption_config.skip_byte_block;
106  switch (encryption_config.protection_scheme) {
107  case FOURCC_cenc:
108  case FOURCC_cbc1:
109  DCHECK_EQ(track_encryption.default_crypt_byte_block, 0u);
110  DCHECK_EQ(track_encryption.default_skip_byte_block, 0u);
111  // CENCv3 10.1 ‘cenc’ AES-CTR scheme and 10.2 ‘cbc1’ AES-CBC scheme:
112  // The version of the Track Encryption Box (‘tenc’) SHALL be 0.
113  track_encryption.version = 0;
114  break;
115  case FOURCC_cbcs:
116  case FOURCC_cens:
117  // CENCv3 10.3 ‘cens’ AES-CTR subsample pattern encryption scheme and
118  // 10.4 ‘cbcs’ AES-CBC subsample pattern encryption scheme:
119  // The version of the Track Encryption Box (‘tenc’) SHALL be 1.
120  track_encryption.version = 1;
121  break;
122  default:
123  NOTREACHED() << "Unexpected protection scheme "
124  << encryption_config.protection_scheme;
125  }
126 
127  track_encryption.default_per_sample_iv_size =
128  encryption_config.per_sample_iv_size;
129  track_encryption.default_constant_iv = encryption_config.constant_iv;
130  track_encryption.default_kid = encryption_config.key_id;
131 }
132 
133 // The roll distance is expressed in sample units and always takes negative
134 // values.
135 int16_t GetRollDistance(uint64_t seek_preroll_ns, uint32_t sampling_frequency) {
136  const double kNanosecondsPerSecond = 1000000000;
137  const double preroll_in_samples =
138  seek_preroll_ns / kNanosecondsPerSecond * sampling_frequency;
139  // Round to closest integer.
140  return -static_cast<int16_t>(preroll_in_samples + 0.5);
141 }
142 
143 } // namespace
144 
145 MP4Muxer::MP4Muxer(const MuxerOptions& options) : Muxer(options) {}
146 MP4Muxer::~MP4Muxer() {}
147 
148 Status MP4Muxer::InitializeMuxer() {
149  // Muxer will be delay-initialized after seeing the first sample.
150  to_be_initialized_ = true;
151  return Status::OK;
152 }
153 
154 Status MP4Muxer::Finalize() {
155  // This happens on streams that are not initialized, i.e. not going through
156  // DelayInitializeMuxer, which can only happen if there are no samples from
157  // the stream.
158  if (!segmenter_) {
159  DCHECK(to_be_initialized_);
160  LOG(INFO) << "Skip stream '" << options().output_file_name
161  << "' which does not contain any sample.";
162  return Status::OK;
163  }
164 
165  Status segmenter_finalized = segmenter_->Finalize();
166 
167  if (!segmenter_finalized.ok())
168  return segmenter_finalized;
169 
170  FireOnMediaEndEvent();
171  LOG(INFO) << "MP4 file '" << options().output_file_name << "' finalized.";
172  return Status::OK;
173 }
174 
175 Status MP4Muxer::AddSample(size_t stream_id, const MediaSample& sample) {
176  if (to_be_initialized_) {
177  RETURN_IF_ERROR(UpdateEditListOffsetFromSample(sample));
178  RETURN_IF_ERROR(DelayInitializeMuxer());
179  to_be_initialized_ = false;
180  }
181  DCHECK(segmenter_);
182  return segmenter_->AddSample(stream_id, sample);
183 }
184 
185 Status MP4Muxer::FinalizeSegment(size_t stream_id,
186  const SegmentInfo& segment_info) {
187  DCHECK(segmenter_);
188  VLOG(3) << "Finalizing " << (segment_info.is_subsegment ? "sub" : "")
189  << "segment " << segment_info.start_timestamp << " duration "
190  << segment_info.duration;
191  return segmenter_->FinalizeSegment(stream_id, segment_info);
192 }
193 
194 Status MP4Muxer::DelayInitializeMuxer() {
195  DCHECK(!streams().empty());
196 
197  std::unique_ptr<FileType> ftyp(new FileType);
198  std::unique_ptr<Movie> moov(new Movie);
199 
200  ftyp->major_brand = FOURCC_isom;
201  ftyp->compatible_brands.push_back(FOURCC_iso8);
202  ftyp->compatible_brands.push_back(FOURCC_mp41);
203  ftyp->compatible_brands.push_back(FOURCC_dash);
204 
205  if (streams().size() == 1) {
206  FourCC codec_fourcc = FOURCC_NULL;
207  if (streams()[0]->stream_type() == kStreamVideo) {
208  codec_fourcc =
209  CodecToFourCC(streams()[0]->codec(),
210  static_cast<const VideoStreamInfo*>(streams()[0].get())
211  ->h26x_stream_format());
212  if (codec_fourcc != FOURCC_NULL)
213  ftyp->compatible_brands.push_back(codec_fourcc);
214  }
215 
216  // CMAF allows only one track/stream per file.
217  // CMAF requires single initialization switching for AVC3/HEV1, which is not
218  // supported yet.
219  if (codec_fourcc != FOURCC_avc3 && codec_fourcc != FOURCC_hev1)
220  ftyp->compatible_brands.push_back(FOURCC_cmfc);
221  }
222 
223  moov->header.creation_time = IsoTimeNow();
224  moov->header.modification_time = IsoTimeNow();
225  moov->header.next_track_id = static_cast<uint32_t>(streams().size()) + 1;
226 
227  moov->tracks.resize(streams().size());
228  moov->extends.tracks.resize(streams().size());
229 
230  // Initialize tracks.
231  for (uint32_t i = 0; i < streams().size(); ++i) {
232  const StreamInfo* stream = streams()[i].get();
233  Track& trak = moov->tracks[i];
234  trak.header.track_id = i + 1;
235 
236  TrackExtends& trex = moov->extends.tracks[i];
237  trex.track_id = trak.header.track_id;
238  trex.default_sample_description_index = 1;
239 
240  bool generate_trak_result = false;
241  switch (stream->stream_type()) {
242  case kStreamVideo:
243  generate_trak_result = GenerateVideoTrak(
244  static_cast<const VideoStreamInfo*>(stream), &trak, i + 1);
245  break;
246  case kStreamAudio:
247  generate_trak_result = GenerateAudioTrak(
248  static_cast<const AudioStreamInfo*>(stream), &trak, i + 1);
249  break;
250  case kStreamText:
251  generate_trak_result = GenerateTextTrak(
252  static_cast<const TextStreamInfo*>(stream), &trak, i + 1);
253  break;
254  default:
255  NOTIMPLEMENTED() << "Not implemented for stream type: "
256  << stream->stream_type();
257  }
258  if (!generate_trak_result)
259  return Status(error::MUXER_FAILURE, "Failed to generate trak.");
260 
261  // Generate EditList if needed. See UpdateEditListOffsetFromSample() for
262  // more information.
263  if (edit_list_offset_.value() > 0) {
264  EditListEntry entry;
265  entry.media_time = edit_list_offset_.value();
266  entry.media_rate_integer = 1;
267  trak.edit.list.edits.push_back(entry);
268  }
269 
270  if (stream->is_encrypted() && options().mp4_params.include_pssh_in_stream) {
271  moov->pssh.clear();
272  const auto& key_system_info = stream->encryption_config().key_system_info;
273  for (const ProtectionSystemSpecificInfo& system : key_system_info) {
274  if (system.psshs.empty())
275  continue;
277  pssh.raw_box = system.psshs;
278  moov->pssh.push_back(pssh);
279  }
280  }
281  }
282 
283  if (options().segment_template.empty()) {
284  segmenter_.reset(new SingleSegmentSegmenter(options(), std::move(ftyp),
285  std::move(moov)));
286  } else {
287  segmenter_.reset(
288  new MultiSegmentSegmenter(options(), std::move(ftyp), std::move(moov)));
289  }
290 
291  const Status segmenter_initialized =
292  segmenter_->Initialize(streams(), muxer_listener(), progress_listener());
293  if (!segmenter_initialized.ok())
294  return segmenter_initialized;
295 
296  FireOnMediaStartEvent();
297  return Status::OK;
298 }
299 
300 Status MP4Muxer::UpdateEditListOffsetFromSample(const MediaSample& sample) {
301  if (edit_list_offset_)
302  return Status::OK;
303 
304  const int64_t pts = sample.pts();
305  const int64_t dts = sample.dts();
306  // An EditList entry is inserted if one of the below conditions occur [4]:
307  // (1) pts > dts for the first sample. Due to Chrome's dts bug [1], dts is
308  // used in buffered range API, while pts is used elsewhere (players,
309  // manifests, and Chrome's own appendWindow check etc.), this
310  // inconsistency creates various problems, including possible stalls
311  // during playback. Since Chrome adjusts pts only when seeing EditList
312  // [2], we can insert an EditList with the time equal to difference of pts
313  // and dts to make aligned buffered ranges using pts and dts. This
314  // effectively workarounds the dts bug. It is also recommended by ISO-BMFF
315  // specification [3].
316  // (2) pts == dts and with pts < 0. This happens for some audio codecs where a
317  // negative presentation timestamp signals that the sample is not supposed
318  // to be shown, i.e. for audio priming. EditList is needed to encode
319  // negative timestamps.
320  // [1] https://crbug.com/718641, fixed but behind MseBufferByPts, still not
321  // enabled as of M67.
322  // [2] This is actually a bug, see https://crbug.com/354518. It looks like
323  // Chrome is planning to enable the fix for [1] before addressing this
324  // bug, so we are safe.
325  // [3] ISO 14496-12:2015 8.6.6.1
326  // It is recommended that such an edit be used to establish a presentation
327  // time of 0 for the first presented sample, when composition offsets are
328  // used.
329  // [4] ISO 23009-19:2018 7.5.13
330  // In two cases, an EditBox containing a single EditListBox with the
331  // following constraints may be present in the CMAF header of a CMAF track
332  // to adjust the presentation time of all media samples in the CMAF track.
333  // a) The first case is a video CMAF track file using v0 TrackRunBoxes
334  // with positive composition offsets to reorder video media samples.
335  // b) The second case is an audio CMAF track where each media sample's
336  // presentation time does not equal its composition time.
337  const int64_t pts_dts_offset = pts - dts;
338  if (pts_dts_offset > 0) {
339  if (pts < 0) {
340  LOG(ERROR) << "Negative presentation timestamp (" << pts
341  << ") is not supported when there is an offset between "
342  "presentation timestamp and decoding timestamp ("
343  << dts << ").";
344  return Status(error::MUXER_FAILURE,
345  "Unsupported negative pts when there is an offset between "
346  "pts and dts.");
347  }
348  edit_list_offset_ = pts_dts_offset;
349  return Status::OK;
350  }
351  if (pts_dts_offset < 0) {
352  LOG(ERROR) << "presentation timestamp (" << pts
353  << ") is not supposed to be greater than decoding timestamp ("
354  << dts << ").";
355  return Status(error::MUXER_FAILURE, "Not expecting pts < dts.");
356  }
357  edit_list_offset_ = std::max(-sample.pts(), static_cast<int64_t>(0));
358  return Status::OK;
359 }
360 
361 void MP4Muxer::InitializeTrak(const StreamInfo* info, Track* trak) {
362  int64_t now = IsoTimeNow();
363  trak->header.creation_time = now;
364  trak->header.modification_time = now;
365  trak->header.duration = 0;
366  trak->media.header.creation_time = now;
367  trak->media.header.modification_time = now;
368  trak->media.header.timescale = info->time_scale();
369  trak->media.header.duration = 0;
370  if (!info->language().empty()) {
371  // Strip off the subtag, if any.
372  std::string main_language = info->language();
373  size_t dash = main_language.find('-');
374  if (dash != std::string::npos) {
375  main_language.erase(dash);
376  }
377 
378  // ISO-639-2/T main language code should be 3 characters.
379  if (main_language.size() != 3) {
380  LOG(WARNING) << "'" << main_language << "' is not a valid ISO-639-2 "
381  << "language code, ignoring.";
382  } else {
383  trak->media.header.language.code = main_language;
384  }
385  }
386 }
387 
388 bool MP4Muxer::GenerateVideoTrak(const VideoStreamInfo* video_info,
389  Track* trak,
390  uint32_t track_id) {
391  InitializeTrak(video_info, trak);
392 
393  // width and height specify the track's visual presentation size as
394  // fixed-point 16.16 values.
395  uint32_t pixel_width = video_info->pixel_width();
396  uint32_t pixel_height = video_info->pixel_height();
397  if (pixel_width == 0 || pixel_height == 0) {
398  LOG(WARNING) << "pixel width/height are not set. Assuming 1:1.";
399  pixel_width = 1;
400  pixel_height = 1;
401  }
402  const double sample_aspect_ratio =
403  static_cast<double>(pixel_width) / pixel_height;
404  trak->header.width = video_info->width() * sample_aspect_ratio * 0x10000;
405  trak->header.height = video_info->height() * 0x10000;
406 
407  VideoSampleEntry video;
408  video.format =
409  CodecToFourCC(video_info->codec(), video_info->h26x_stream_format());
410  video.width = video_info->width();
411  video.height = video_info->height();
412  video.codec_configuration.data = video_info->codec_config();
413  if (pixel_width != 1 || pixel_height != 1) {
414  video.pixel_aspect.h_spacing = pixel_width;
415  video.pixel_aspect.v_spacing = pixel_height;
416  }
417 
418  SampleDescription& sample_description =
419  trak->media.information.sample_table.description;
420  sample_description.type = kVideo;
421  sample_description.video_entries.push_back(video);
422 
423  if (video_info->is_encrypted()) {
424  if (video_info->has_clear_lead()) {
425  // Add a second entry for clear content.
426  sample_description.video_entries.push_back(video);
427  }
428  // Convert the first entry to an encrypted entry.
429  VideoSampleEntry& entry = sample_description.video_entries[0];
430  GenerateSinf(entry.format, video_info->encryption_config(), &entry.sinf);
431  entry.format = FOURCC_encv;
432  }
433  return true;
434 }
435 
436 bool MP4Muxer::GenerateAudioTrak(const AudioStreamInfo* audio_info,
437  Track* trak,
438  uint32_t track_id) {
439  InitializeTrak(audio_info, trak);
440 
441  trak->header.volume = 0x100;
442 
443  AudioSampleEntry audio;
444  audio.format =
445  CodecToFourCC(audio_info->codec(), H26xStreamFormat::kUnSpecified);
446  switch(audio_info->codec()){
447  case kCodecAAC:
448  audio.esds.es_descriptor.set_object_type(
449  ObjectType::kISO_14496_3); // MPEG4 AAC.
450  audio.esds.es_descriptor.set_esid(track_id);
451  audio.esds.es_descriptor.set_decoder_specific_info(
452  audio_info->codec_config());
453  audio.esds.es_descriptor.set_max_bitrate(audio_info->max_bitrate());
454  audio.esds.es_descriptor.set_avg_bitrate(audio_info->avg_bitrate());
455  break;
456  case kCodecDTSC:
457  case kCodecDTSH:
458  case kCodecDTSL:
459  case kCodecDTSE:
460  case kCodecDTSM:
461  audio.ddts.extra_data = audio_info->codec_config();
462  audio.ddts.max_bitrate = audio_info->max_bitrate();
463  audio.ddts.avg_bitrate = audio_info->avg_bitrate();
464  audio.ddts.sampling_frequency = audio_info->sampling_frequency();
465  audio.ddts.pcm_sample_depth = audio_info->sample_bits();
466  break;
467  case kCodecAC3:
468  audio.dac3.data = audio_info->codec_config();
469  break;
470  case kCodecEAC3:
471  audio.dec3.data = audio_info->codec_config();
472  break;
473  case kCodecFlac:
474  audio.dfla.data = audio_info->codec_config();
475  break;
476  case kCodecOpus:
477  audio.dops.opus_identification_header = audio_info->codec_config();
478  break;
479  default:
480  NOTIMPLEMENTED() << " Unsupported audio codec " << audio_info->codec();
481  return false;
482  }
483 
484  if (audio_info->codec() == kCodecAC3 || audio_info->codec() == kCodecEAC3) {
485  // AC3 and EC3 does not fill in actual channel count and sample size in
486  // sample description entry. Instead, two constants are used.
487  audio.channelcount = 2;
488  audio.samplesize = 16;
489  } else {
490  audio.channelcount = audio_info->num_channels();
491  audio.samplesize = audio_info->sample_bits();
492  }
493  audio.samplerate = audio_info->sampling_frequency();
494  SampleTable& sample_table = trak->media.information.sample_table;
495  SampleDescription& sample_description = sample_table.description;
496  sample_description.type = kAudio;
497  sample_description.audio_entries.push_back(audio);
498 
499  if (audio_info->is_encrypted()) {
500  if (audio_info->has_clear_lead()) {
501  // Add a second entry for clear content.
502  sample_description.audio_entries.push_back(audio);
503  }
504  // Convert the first entry to an encrypted entry.
505  AudioSampleEntry& entry = sample_description.audio_entries[0];
506  GenerateSinf(entry.format, audio_info->encryption_config(), &entry.sinf);
507  entry.format = FOURCC_enca;
508  }
509 
510  if (audio_info->seek_preroll_ns() > 0) {
511  sample_table.sample_group_descriptions.resize(1);
512  SampleGroupDescription& sample_group_description =
513  sample_table.sample_group_descriptions.back();
514  sample_group_description.grouping_type = FOURCC_roll;
515  sample_group_description.audio_roll_recovery_entries.resize(1);
516  sample_group_description.audio_roll_recovery_entries[0].roll_distance =
517  GetRollDistance(audio_info->seek_preroll_ns(), audio.samplerate);
518  // sample to group box is not allowed in the init segment per CMAF
519  // specification. It is put in the fragment instead.
520  }
521  return true;
522 }
523 
524 bool MP4Muxer::GenerateTextTrak(const TextStreamInfo* text_info,
525  Track* trak,
526  uint32_t track_id) {
527  InitializeTrak(text_info, trak);
528 
529  if (text_info->codec_string() == "wvtt") {
530  // Handle WebVTT.
531  TextSampleEntry webvtt;
532  webvtt.format = FOURCC_wvtt;
533 
534  // 14496-30:2014 7.5 Web Video Text Tracks Sample entry format.
535  // In the sample entry, a WebVTT configuration box must occur, carrying
536  // exactly the lines of the WebVTT file header, i.e. all text lines up to
537  // but excluding the 'two or more line terminators' that end the header.
538  webvtt.config.config = "WEBVTT";
539  // The spec does not define a way to carry STYLE and REGION information in
540  // the mp4 container.
541  if (!text_info->codec_config().empty()) {
542  LOG(INFO) << "Skipping possible style / region configuration as the spec "
543  "does not define a way to carry them inside ISO-BMFF files.";
544  }
545 
546  // TODO(rkuroiwa): This should be the source file URI(s). Putting bogus
547  // string for now so that the box will be there for samples with overlapping
548  // cues.
549  webvtt.label.source_label = "source_label";
550  SampleDescription& sample_description =
551  trak->media.information.sample_table.description;
552  sample_description.type = kText;
553  sample_description.text_entries.push_back(webvtt);
554  return true;
555  }
556  NOTIMPLEMENTED() << text_info->codec_string()
557  << " handling not implemented yet.";
558  return false;
559 }
560 
561 base::Optional<Range> MP4Muxer::GetInitRangeStartAndEnd() {
562  size_t range_offset = 0;
563  size_t range_size = 0;
564  const bool has_range = segmenter_->GetInitRange(&range_offset, &range_size);
565 
566  if (!has_range)
567  return base::nullopt;
568 
569  Range range;
570  SetStartAndEndFromOffsetAndSize(range_offset, range_size, &range);
571  return range;
572 }
573 
574 base::Optional<Range> MP4Muxer::GetIndexRangeStartAndEnd() {
575  size_t range_offset = 0;
576  size_t range_size = 0;
577  const bool has_range = segmenter_->GetIndexRange(&range_offset, &range_size);
578 
579  if (!has_range)
580  return base::nullopt;
581 
582  Range range;
583  SetStartAndEndFromOffsetAndSize(range_offset, range_size, &range);
584  return range;
585 }
586 
587 void MP4Muxer::FireOnMediaStartEvent() {
588  if (!muxer_listener())
589  return;
590 
591  if (streams().size() > 1) {
592  LOG(ERROR) << "MuxerListener cannot take more than 1 stream.";
593  return;
594  }
595  DCHECK(!streams().empty()) << "Media started without a stream.";
596 
597  const uint32_t timescale = segmenter_->GetReferenceTimeScale();
598  muxer_listener()->OnMediaStart(options(), *streams().front(), timescale,
599  MuxerListener::kContainerMp4);
600 }
601 
602 void MP4Muxer::FireOnMediaEndEvent() {
603  if (!muxer_listener())
604  return;
605 
606  MuxerListener::MediaRanges media_range;
607  media_range.init_range = GetInitRangeStartAndEnd();
608  media_range.index_range = GetIndexRangeStartAndEnd();
609  media_range.subsegment_ranges = segmenter_->GetSegmentRanges();
610 
611  const float duration_seconds = static_cast<float>(segmenter_->GetDuration());
612  muxer_listener()->OnMediaEnd(media_range, duration_seconds);
613 }
614 
615 uint64_t MP4Muxer::IsoTimeNow() {
616  // Time in seconds from Jan. 1, 1904 to epoch time, i.e. Jan. 1, 1970.
617  const uint64_t kIsomTimeOffset = 2082844800l;
618  return kIsomTimeOffset +
619  (clock() ? clock()->Now() : base::Time::Now()).ToDoubleT();
620 }
621 
622 } // namespace mp4
623 } // namespace media
624 } // namespace shaka
base::Optional< Range > init_range
Range of the initialization section of a segment.
Abstract class holds stream information.
Definition: stream_info.h:61
base::Optional< Range > index_range
Range of the index section of a segment.
MP4Muxer(const MuxerOptions &options)
Create a MP4Muxer object from MuxerOptions.
Definition: mp4_muxer.cc:145
All the methods that are virtual are virtual for mocking.
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:20
Mp4OutputParams mp4_params
MP4 (ISO-BMFF) specific parameters.
Definition: muxer_options.h:25
virtual void OnMediaEnd(const MediaRanges &media_ranges, float duration_seconds)=0
Class to hold a media sample.
Definition: media_sample.h:22
virtual void OnMediaStart(const MuxerOptions &muxer_options, const StreamInfo &stream_info, uint32_t time_scale, ContainerType container_type)=0
Holds video stream information.
Holds audio stream information.