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.
|
|
|
|
|
|
|
|
#ifndef MEDIA_FORMATS_WEBM_WEBM_STREAM_PARSER_H_
|
|
|
|
#define MEDIA_FORMATS_WEBM_WEBM_STREAM_PARSER_H_
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
#include "packager/base/callback_forward.h"
|
|
|
|
#include "packager/base/memory/ref_counted.h"
|
|
|
|
#include "packager/media/base/byte_queue.h"
|
2015-10-14 23:12:10 +00:00
|
|
|
#include "packager/media/base/media_parser.h"
|
2015-10-14 22:46:23 +00:00
|
|
|
|
|
|
|
namespace edash_packager {
|
2015-10-08 21:48:07 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class WebMClusterParser;
|
|
|
|
|
2015-10-14 23:12:10 +00:00
|
|
|
class WebMStreamParser : public MediaParser {
|
2015-10-08 21:48:07 +00:00
|
|
|
public:
|
|
|
|
WebMStreamParser();
|
|
|
|
~WebMStreamParser() override;
|
|
|
|
|
|
|
|
// StreamParser implementation.
|
|
|
|
void Init(const InitCB& init_cb,
|
2015-10-14 23:12:10 +00:00
|
|
|
const NewSampleCB& new_sample_cb,
|
|
|
|
KeySource* decryption_key_source) override;
|
2015-10-08 21:48:07 +00:00
|
|
|
void Flush() override;
|
2015-10-14 22:46:23 +00:00
|
|
|
bool Parse(const uint8_t* buf, int size) override;
|
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
|
|
|
|
|
|
|
// Fire needkey event through the |encrypted_media_init_data_cb_|.
|
|
|
|
void OnEncryptedMediaInitData(const std::string& key_id);
|
|
|
|
|
|
|
|
State state_;
|
|
|
|
InitCB init_cb_;
|
2015-10-14 23:12:10 +00:00
|
|
|
NewSampleCB new_sample_cb_;
|
|
|
|
KeySource* decryption_key_source_;
|
2015-10-08 21:48:07 +00:00
|
|
|
bool ignore_text_tracks_;
|
|
|
|
|
|
|
|
bool unknown_segment_size_;
|
|
|
|
|
|
|
|
scoped_ptr<WebMClusterParser> cluster_parser_;
|
|
|
|
ByteQueue byte_queue_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebMStreamParser);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2015-10-14 22:46:23 +00:00
|
|
|
} // namespace edash_packager
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_FORMATS_WEBM_WEBM_STREAM_PARSER_H_
|