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