DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
webvtt_media_parser.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 MEDIA_FORMATS_WEBVTT_WEBVTT_MEDIA_PARSER_H_
8 #define MEDIA_FORMATS_WEBVTT_WEBVTT_MEDIA_PARSER_H_
9 
10 #include <stdint.h>
11 #include <string>
12 #include <vector>
13 
14 #include "packager/base/compiler_specific.h"
15 #include "packager/media/base/media_parser.h"
16 #include "packager/media/formats/webvtt/cue.h"
17 
18 namespace shaka {
19 namespace media {
20 
21 // WebVTT parser.
22 // The input may not be encrypted so decryption_key_source is ignored.
24  public:
26  ~WebVttMediaParser() override;
27 
30  void Init(const InitCB& init_cb,
31  const NewSampleCB& new_sample_cb,
32  KeySource* decryption_key_source) override;
33  bool Flush() override WARN_UNUSED_RESULT;
34  bool Parse(const uint8_t* buf, int size) override WARN_UNUSED_RESULT;
36 
37  private:
38  enum WebVttReadingState {
39  kHeader,
40  kMetadata,
41  kCueIdentifierOrTimingOrComment,
42  kCueTiming,
43  kCuePayload,
44  kComment,
45  kParseError,
46  };
47 
48  InitCB init_cb_;
49  NewSampleCB new_sample_cb_;
50 
51  // All the unprocessed data passed to this parser.
52  std::string data_;
53 
54  // The WEBVTT text + metadata header (global settings) for this webvtt.
55  // One element per line.
56  std::vector<std::string> header_;
57 
58  // This is set to what the parser is expecting. For example, if the parse is
59  // expecting a kCueTiming, then the next line that it parses should be a
60  // WebVTT timing line or an empty line.
61  WebVttReadingState state_;
62 
63  Cue current_cue_;
64 
65  DISALLOW_COPY_AND_ASSIGN(WebVttMediaParser);
66 };
67 
68 } // namespace media
69 } // namespace shaka
70 
71 #endif // MEDIA_FORMATS_WEBVTT_WEBVTT_MEDIA_PARSER_H_
void Init(const InitCB &init_cb, const NewSampleCB &new_sample_cb, KeySource *decryption_key_source) override
base::Callback< void(const std::vector< std::shared_ptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:34
base::Callback< bool(uint32_t track_id, const std::shared_ptr< MediaSample > &media_sample)> NewSampleCB
Definition: media_parser.h:43
bool Parse(const uint8_t *buf, int size) override WARN_UNUSED_RESULT
bool Flush() override WARN_UNUSED_RESULT
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:30