Shaka Packager SDK
Loading...
Searching...
No Matches
webm_media_parser.h
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
6#define PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
7
8#include <cstdint>
9
10#include <packager/macros/classes.h>
11#include <packager/media/base/byte_queue.h>
12#include <packager/media/base/media_parser.h>
13
14namespace shaka {
15namespace media {
16
17class WebMClusterParser;
18
20 public:
22 ~WebMMediaParser() override;
23
26 void Init(const InitCB& init_cb,
27 const NewMediaSampleCB& new_media_sample_cb,
28 const NewTextSampleCB& new_text_sample_cb,
29 KeySource* decryption_key_source) override;
30 [[nodiscard]] bool Flush() override;
31 [[nodiscard]] bool Parse(const uint8_t* buf, int size) override;
33
34 private:
35 enum State { kWaitingForInit, kParsingHeaders, kParsingClusters, kError };
36
37 void ChangeState(State new_state);
38
39 // Parses WebM Header, Info, Tracks elements. It also skips other level 1
40 // elements that are not used right now. Once the Info & Tracks elements have
41 // been parsed, this method will transition the parser from PARSING_HEADERS to
42 // PARSING_CLUSTERS.
43 //
44 // Returns < 0 if the parse fails.
45 // Returns 0 if more data is needed.
46 // Returning > 0 indicates success & the number of bytes parsed.
47 int ParseInfoAndTracks(const uint8_t* data, int size);
48
49 // Incrementally parses WebM cluster elements. This method also skips
50 // CUES elements if they are encountered since we currently don't use the
51 // data in these elements.
52 //
53 // Returns < 0 if the parse fails.
54 // Returns 0 if more data is needed.
55 // Returning > 0 indicates success & the number of bytes parsed.
56 int ParseCluster(const uint8_t* data, int size);
57
58 // Fetch keys for the input key ids. Returns true on success, false otherwise.
59 bool FetchKeysIfNecessary(const std::string& audio_encryption_key_id,
60 const std::string& video_encryption_key_id);
61
62 State state_;
63 InitCB init_cb_;
64 NewMediaSampleCB new_sample_cb_;
65 KeySource* decryption_key_source_;
66 bool ignore_text_tracks_;
67
68 bool unknown_segment_size_;
69
70 std::unique_ptr<WebMClusterParser> cluster_parser_;
71 ByteQueue byte_queue_;
72
73 DISALLOW_COPY_AND_ASSIGN(WebMMediaParser);
74};
75
76} // namespace media
77} // namespace shaka
78
79#endif // PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
KeySource is responsible for encryption key acquisition.
Definition key_source.h:53
std::function< bool(uint32_t track_id, std::shared_ptr< MediaSample > media_sample)> NewMediaSampleCB
std::function< bool(uint32_t track_id, std::shared_ptr< TextSample > text_sample)> NewTextSampleCB
std::function< void(const std::vector< std::shared_ptr< StreamInfo > > &stream_info)> InitCB
bool Parse(const uint8_t *buf, int size) override
void Init(const InitCB &init_cb, const NewMediaSampleCB &new_media_sample_cb, const NewTextSampleCB &new_text_sample_cb, KeySource *decryption_key_source) override
All the methods that are virtual are virtual for mocking.