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#include <memory>
10#include <string>
11
12#include <packager/macros/classes.h>
13#include <packager/media/base/byte_queue.h>
14#include <packager/media/base/media_parser.h>
15
16namespace shaka {
17namespace media {
18
19class WebMClusterParser;
20
22 public:
24 ~WebMMediaParser() override;
25
28 void Init(const InitCB& init_cb,
29 const NewMediaSampleCB& new_media_sample_cb,
30 const NewTextSampleCB& new_text_sample_cb,
31 KeySource* decryption_key_source) override;
32 [[nodiscard]] bool Flush() override;
33 [[nodiscard]] bool Parse(const uint8_t* buf, int size) override;
35
36 private:
37 enum State { kWaitingForInit, kParsingHeaders, kParsingClusters, kError };
38
39 void ChangeState(State new_state);
40
41 // Parses WebM Header, Info, Tracks elements. It also skips other level 1
42 // elements that are not used right now. Once the Info & Tracks elements have
43 // been parsed, this method will transition the parser from PARSING_HEADERS to
44 // PARSING_CLUSTERS.
45 //
46 // Returns < 0 if the parse fails.
47 // Returns 0 if more data is needed.
48 // Returning > 0 indicates success & the number of bytes parsed.
49 int ParseInfoAndTracks(const uint8_t* data, int size);
50
51 // Incrementally parses WebM cluster elements. This method also skips
52 // CUES elements if they are encountered since we currently don't use the
53 // data in these elements.
54 //
55 // Returns < 0 if the parse fails.
56 // Returns 0 if more data is needed.
57 // Returning > 0 indicates success & the number of bytes parsed.
58 int ParseCluster(const uint8_t* data, int size);
59
60 // Fetch keys for the input key ids. Returns true on success, false otherwise.
61 bool FetchKeysIfNecessary(const std::string& audio_encryption_key_id,
62 const std::string& video_encryption_key_id);
63
64 State state_;
65 InitCB init_cb_;
66 NewMediaSampleCB new_sample_cb_;
67 KeySource* decryption_key_source_;
68 bool ignore_text_tracks_;
69
70 bool unknown_segment_size_;
71
72 std::unique_ptr<WebMClusterParser> cluster_parser_;
73 ByteQueue byte_queue_;
74
75 DISALLOW_COPY_AND_ASSIGN(WebMMediaParser);
76};
77
78} // namespace media
79} // namespace shaka
80
81#endif // PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
KeySource is responsible for encryption key acquisition.
Definition key_source.h:56
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.