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 {
36 kWaitingForInit,
37 kParsingHeaders,
38 kParsingClusters,
39 kError
40 };
41
42 void ChangeState(State new_state);
43
44 // Parses WebM Header, Info, Tracks elements. It also skips other level 1
45 // elements that are not used right now. Once the Info & Tracks elements have
46 // been parsed, this method will transition the parser from PARSING_HEADERS to
47 // PARSING_CLUSTERS.
48 //
49 // Returns < 0 if the parse fails.
50 // Returns 0 if more data is needed.
51 // Returning > 0 indicates success & the number of bytes parsed.
52 int ParseInfoAndTracks(const uint8_t* data, int size);
53
54 // Incrementally parses WebM cluster elements. This method also skips
55 // CUES elements if they are encountered since we currently don't use the
56 // data in these elements.
57 //
58 // Returns < 0 if the parse fails.
59 // Returns 0 if more data is needed.
60 // Returning > 0 indicates success & the number of bytes parsed.
61 int ParseCluster(const uint8_t* data, int size);
62
63 // Fetch keys for the input key ids. Returns true on success, false otherwise.
64 bool FetchKeysIfNecessary(const std::string& audio_encryption_key_id,
65 const std::string& video_encryption_key_id);
66
67 State state_;
68 InitCB init_cb_;
69 NewMediaSampleCB new_sample_cb_;
70 KeySource* decryption_key_source_;
71 bool ignore_text_tracks_;
72
73 bool unknown_segment_size_;
74
75 std::unique_ptr<WebMClusterParser> cluster_parser_;
76 ByteQueue byte_queue_;
77
78 DISALLOW_COPY_AND_ASSIGN(WebMMediaParser);
79};
80
81} // namespace media
82} // namespace shaka
83
84#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.