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 
55  public:
58 
61  void PushSample(std::shared_ptr<MediaSample> sample);
62 
66  void Flush();
67 
69  size_t ReadySamplesSize();
70 
75  std::shared_ptr<MediaSample> PopSample();
76 
77  private:
78  // Handle |cues_| except the last item, and create samples from them.
79  // All cues that overlap with the latest cue are not processed.
80  // Usually the last cue (and cues that overlap with it) should not be
81  // processed right away because the following cues may overlap with the latest
82  // cue or the existing cues.
83  // If a cue has been proceessed, then this returns true.
84  bool HandleAllCuesButLatest();
85 
86  // Same as HandleAllCuesButLatest() but it also includes the latest cue.
87  // If a cue has been processed, then this returns true.
88  bool HandleAllCues();
89 
90  // Sweep line algorithm that handles the cues in |cues_|.
91  // This does not erase |cues_|.
92  // If a cue has been processed, this returns true.
93  // |sweep_line| is the start time and |sweep_stop_time| is when the sweep
94  // should stop.
95  bool SweepCues(uint64_t sweep_line, uint64_t sweep_stop_time);
96 
97  // This is going to be in 'mdat' box. Keep this around until a sample is
98  // ready.
99  std::list<Cue> cues_;
100 
101  // For comment samples.
102  std::list<mp4::VTTAdditionalTextBox> additional_texts_;
103 
104  // Samples that are ready to be processed.
105  std::list<std::shared_ptr<MediaSample>> ready_samples_;
106 
107  // This keeps track of the max end time of the processed cues which is the
108  // start time of the next cue. Used to check if cue_current_time has to be set
109  // or an empty cue (gap) has to be added.
110  uint64_t next_cue_start_time_;
111 
112  DISALLOW_COPY_AND_ASSIGN(WebVttSampleConverter);
113 };
114 
115 } // namespace media
116 } // namespace shaka
117 
118 #endif // PACKAGER_MEDIA_FORMATS_WEBVTT_WEBVTT_SAMPLE_CONVERTER_H_
void PushSample(std::shared_ptr< MediaSample > sample)
std::shared_ptr< MediaSample > PopSample()