DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs 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 "packager/media/base/media_parser.h"
11 
12 #include <stdint.h>
13 #include <string>
14 #include <vector>
15 
16 namespace edash_packager {
17 namespace media {
18 
19 // If comment is not empty, then this is metadata and other fields must
20 // be empty.
21 // Data that can be multiline are vector of strings.
22 struct Cue {
23  Cue();
24  ~Cue();
25 
26  std::string identifier;
27  uint64_t start_time;
28  uint64_t duration;
29  std::string settings;
30  std::vector<std::string> payload;
31  std::vector<std::string> comment;
32 };
33 
34 // WebVTT parser.
35 // The input may not be encrypted so decryption_key_source is ignored.
37  public:
39  ~WebVttMediaParser() override;
40 
43  void Init(const InitCB& init_cb,
44  const NewSampleCB& new_sample_cb,
45  KeySource* decryption_key_source) override;
46  void Flush() override;
47  bool Parse(const uint8_t* buf, int size) override;
49 
50  private:
51  enum WebVttReadingState {
52  kHeader,
53  kMetadata,
54  kCueIdentifierOrTimingOrComment,
55  kCueTiming,
56  kCuePayload,
57  kComment,
58  kParseError,
59  };
60 
61  InitCB init_cb_;
62  NewSampleCB new_sample_cb_;
63 
64  // All the unprocessed data passed to this parser.
65  std::string data_;
66 
67  // The WEBVTT text + metadata header (global settings) for this webvtt.
68  // One element per line.
69  std::vector<std::string> header_;
70 
71  // This is set to what the parser is expecting. For example, if the parse is
72  // expecting a kCueTiming, then the next line that it parses should be a
73  // WebVTT timing line or an empty line.
74  WebVttReadingState state_;
75 
76  Cue current_cue_;
77 
78  DISALLOW_COPY_AND_ASSIGN(WebVttMediaParser);
79 };
80 
81 } // namespace media
82 } // namespace edash_packager
83 
84 #endif // MEDIA_FORMATS_WEBVTT_WEBVTT_MEDIA_PARSER_H_
bool Parse(const uint8_t *buf, int size) override
base::Callback< bool(uint32_t track_id, const scoped_refptr< MediaSample > &media_sample)> NewSampleCB
Definition: media_parser.h:43
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:29
base::Callback< void(const std::vector< scoped_refptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:34
void Init(const InitCB &init_cb, const NewSampleCB &new_sample_cb, KeySource *decryption_key_source) override