2015-10-08 21:48:07 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2023-10-14 16:36:01 +00:00
|
|
|
#include <packager/macros/classes.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/byte_queue.h>
|
|
|
|
#include <packager/media/base/media_parser.h>
|
2015-10-14 22:46:23 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-10-08 21:48:07 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class WebMClusterParser;
|
|
|
|
|
2015-10-15 22:39:16 +00:00
|
|
|
class WebMMediaParser : public MediaParser {
|
2015-10-08 21:48:07 +00:00
|
|
|
public:
|
2015-10-15 22:39:16 +00:00
|
|
|
WebMMediaParser();
|
|
|
|
~WebMMediaParser() override;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2016-01-21 18:30:29 +00:00
|
|
|
/// @name MediaParser implementation overrides.
|
|
|
|
/// @{
|
2015-10-08 21:48:07 +00:00
|
|
|
void Init(const InitCB& init_cb,
|
2020-07-01 22:43:44 +00:00
|
|
|
const NewMediaSampleCB& new_media_sample_cb,
|
|
|
|
const NewTextSampleCB& new_text_sample_cb,
|
2015-10-14 23:12:10 +00:00
|
|
|
KeySource* decryption_key_source) override;
|
2022-12-17 05:40:00 +00:00
|
|
|
[[nodiscard]] bool Flush() override;
|
|
|
|
[[nodiscard]] bool Parse(const uint8_t* buf, int size) override;
|
2016-01-21 18:30:29 +00:00
|
|
|
/// @}
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum State {
|
|
|
|
kWaitingForInit,
|
|
|
|
kParsingHeaders,
|
|
|
|
kParsingClusters,
|
|
|
|
kError
|
|
|
|
};
|
|
|
|
|
|
|
|
void ChangeState(State new_state);
|
|
|
|
|
|
|
|
// Parses WebM Header, Info, Tracks elements. It also skips other level 1
|
|
|
|
// elements that are not used right now. Once the Info & Tracks elements have
|
|
|
|
// been parsed, this method will transition the parser from PARSING_HEADERS to
|
|
|
|
// PARSING_CLUSTERS.
|
|
|
|
//
|
|
|
|
// Returns < 0 if the parse fails.
|
|
|
|
// Returns 0 if more data is needed.
|
|
|
|
// Returning > 0 indicates success & the number of bytes parsed.
|
2015-10-14 22:46:23 +00:00
|
|
|
int ParseInfoAndTracks(const uint8_t* data, int size);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
// Incrementally parses WebM cluster elements. This method also skips
|
|
|
|
// CUES elements if they are encountered since we currently don't use the
|
|
|
|
// data in these elements.
|
|
|
|
//
|
|
|
|
// Returns < 0 if the parse fails.
|
|
|
|
// Returns 0 if more data is needed.
|
|
|
|
// Returning > 0 indicates success & the number of bytes parsed.
|
2015-10-14 22:46:23 +00:00
|
|
|
int ParseCluster(const uint8_t* data, int size);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2016-01-13 01:32:48 +00:00
|
|
|
// Fetch keys for the input key ids. Returns true on success, false otherwise.
|
|
|
|
bool FetchKeysIfNecessary(const std::string& audio_encryption_key_id,
|
|
|
|
const std::string& video_encryption_key_id);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
State state_;
|
|
|
|
InitCB init_cb_;
|
2020-07-01 22:43:44 +00:00
|
|
|
NewMediaSampleCB new_sample_cb_;
|
2015-10-14 23:12:10 +00:00
|
|
|
KeySource* decryption_key_source_;
|
2015-10-08 21:48:07 +00:00
|
|
|
bool ignore_text_tracks_;
|
|
|
|
|
|
|
|
bool unknown_segment_size_;
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<WebMClusterParser> cluster_parser_;
|
2015-10-08 21:48:07 +00:00
|
|
|
ByteQueue byte_queue_;
|
|
|
|
|
2015-10-15 22:39:16 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebMMediaParser);
|
2015-10-08 21:48:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
|