DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
webvtt_sample_converter.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_WEBVTT_WEBVTT_SAMPLE_CONVERTER_H_
8 #define PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SAMPLE_CONVERTER_H_
9 
10 #include <stdint.h>
11 #include <list>
12 
13 #include "packager/media/base/status.h"
14 #include "packager/media/formats/mp4/box.h"
15 #include "packager/media/formats/mp4/box_definitions.h"
16 #include "packager/media/formats/webvtt/cue.h"
17 
18 namespace shaka {
19 namespace media {
20 
24 void AppendBoxToVector(mp4::Box* box, std::vector<uint8_t>* output_vector);
25 
56  public:
58  virtual ~WebVttSampleConverter();
59 
62  virtual void PushCue(const Cue& cue);
63 
67  virtual void Flush();
68 
70  virtual size_t ReadySamplesSize();
71 
76  virtual std::shared_ptr<MediaSample> PopSample();
77 
78  private:
79  // Handle |cues_| except the last item, and create samples from them.
80  // All cues that overlap with the latest cue are not processed.
81  // Usually the last cue (and cues that overlap with it) should not be
82  // processed right away because the following cues may overlap with the latest
83  // cue or the existing cues.
84  // If a cue has been proceessed, then this returns true.
85  bool HandleAllCuesButLatest();
86 
87  // Same as HandleAllCuesButLatest() but it also includes the latest cue.
88  // If a cue has been processed, then this returns true.
89  bool HandleAllCues();
90 
91  // Sweep line algorithm that handles the cues in |cues_|.
92  // This does not erase |cues_|.
93  // If a cue has been processed, this returns true.
94  // |sweep_line| is the start time and |sweep_stop_time| is when the sweep
95  // should stop.
96  bool SweepCues(uint64_t sweep_line, uint64_t sweep_stop_time);
97 
98  // This is going to be in 'mdat' box. Keep this around until a sample is
99  // ready.
100  std::list<Cue> cues_;
101 
102  // For comment samples.
103  std::list<mp4::VTTAdditionalTextBox> additional_texts_;
104 
105  // Samples that are ready to be processed.
106  std::list<std::shared_ptr<MediaSample>> ready_samples_;
107 
108  // This keeps track of the max end time of the processed cues which is the
109  // start time of the next cue. Used to check if cue_current_time has to be set
110  // or an empty cue (gap) has to be added.
111  uint64_t next_cue_start_time_;
112 
113  DISALLOW_COPY_AND_ASSIGN(WebVttSampleConverter);
114 };
115 
116 } // namespace media
117 } // namespace shaka
118 
119 #endif // PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SAMPLE_CONVERTER_H_
virtual std::shared_ptr< MediaSample > PopSample()