DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
webvtt_fragmenter.h
1 // Copyright 2015 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 #ifndef PACKAGER_MEDIA_FORMATS_MP4_FRAGMENTER_H_
8 #define PACKAGER_MEDIA_FORMATS_MP4_FRAGMENTER_H_
9 
10 #include <stdint.h>
11 #include <list>
12 
13 #include "packager/media/base/status.h"
14 #include "packager/media/formats/mp4/box_definitions.h"
15 #include "packager/media/formats/webvtt/webvtt_media_parser.h"
16 
17 namespace shaka {
18 namespace media {
19 namespace mp4 {
20 
24 void AppendBoxToVector(Box* box, std::vector<uint8_t>* output_vector);
25 
54 // TODO(rkuroiwa): Rename this to WebVttSampleConverter, and put this in
55 // webvtt parser.
56 // For now, the output (from PopSample()) should still be in ISO-BMFF box form;
57 // and also to signal that, should have different types for TextStreamInfo. e.g.
58 // TextStreamInfo::type() returns kIsoBmffStreamText.
60  public:
63 
66  void PushSample(std::shared_ptr<MediaSample> sample);
67 
71  void Flush();
72 
74  size_t ReadySamplesSize();
75 
80  std::shared_ptr<MediaSample> PopSample();
81 
82  private:
83  // Handle |cues_| except the last item, and create samples from them.
84  // All cues that overlap with the latest cue are not processed.
85  // Usually the last cue (and cues that overlap with it) should not be
86  // processed right away because the following cues may overlap with the latest
87  // cue or the existing cues.
88  // If a cue has been proceessed, then this returns true.
89  bool HandleAllCuesButLatest();
90 
91  // Same as HandleAllCuesButLatest() but it also includes the latest cue.
92  // If a cue has been processed, then this returns true.
93  bool HandleAllCues();
94 
95  // Sweep line algorithm that handles the cues in |cues_|.
96  // This does not erase |cues_|.
97  // If a cue has been processed, this returns true.
98  // |sweep_line| is the start time and |sweep_stop_time| is when the sweep
99  // should stop.
100  bool SweepCues(uint64_t sweep_line, uint64_t sweep_stop_time);
101 
102  // This is going to be in 'mdat' box. Keep this around until a sample is
103  // ready.
104  std::list<Cue> cues_;
105 
106  // For comment samples.
107  std::list<VTTAdditionalTextBox> additional_texts_;
108 
109  // Samples that are ready to be processed.
110  std::list<std::shared_ptr<MediaSample>> ready_samples_;
111 
112  // This keeps track of the max end time of the processed cues which is the
113  // start time of the next cue. Used to check if cue_current_time has to be set
114  // or an empty cue (gap) has to be added.
115  uint64_t next_cue_start_time_;
116 
117  DISALLOW_COPY_AND_ASSIGN(WebVttFragmenter);
118 };
119 
120 } // namespace shaka
121 } // namespace media
122 } // namespace edash_packager
123 
124 #endif // PACKAGER_MEDIA_FORMATS_MP4_FRAGMENTER_H_
void PushSample(std::shared_ptr< MediaSample > sample)
std::shared_ptr< MediaSample > PopSample()