2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_MEDIA_PARSER_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_MEDIA_PARSER_H_
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2022-12-17 05:40:00 +00:00
|
|
|
#include <functional>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2013-09-24 04:17:12 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2022-12-17 05:40:00 +00:00
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/macros.h>
|
|
|
|
#include <packager/media/base/container_names.h>
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 04:17:12 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-08-25 22:51:19 +00:00
|
|
|
class KeySource;
|
2013-09-24 04:17:12 +00:00
|
|
|
class MediaSample;
|
|
|
|
class StreamInfo;
|
2020-07-01 22:43:44 +00:00
|
|
|
class TextSample;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
class MediaParser {
|
|
|
|
public:
|
|
|
|
MediaParser() {}
|
|
|
|
virtual ~MediaParser() {}
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Called upon completion of parser initialization.
|
|
|
|
/// @param stream_info contains the stream info of all the elementary streams
|
|
|
|
/// within this file.
|
2022-12-17 05:40:00 +00:00
|
|
|
typedef std::function<void(
|
2017-01-24 00:55:02 +00:00
|
|
|
const std::vector<std::shared_ptr<StreamInfo> >& stream_info)>
|
|
|
|
InitCB;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Called when a new media sample has been parsed.
|
|
|
|
/// @param track_id is the track id of the new sample.
|
|
|
|
/// @param media_sample is the new media sample.
|
|
|
|
/// @return true if the sample is accepted, false if something was wrong
|
|
|
|
/// with the sample and a parsing error should be signaled.
|
2022-12-17 05:40:00 +00:00
|
|
|
typedef std::function<bool(uint32_t track_id,
|
|
|
|
std::shared_ptr<MediaSample> media_sample)>
|
2020-07-01 22:43:44 +00:00
|
|
|
NewMediaSampleCB;
|
|
|
|
|
|
|
|
/// Called when a new text sample has been parsed.
|
|
|
|
/// @param track_id is the track id of the new sample.
|
|
|
|
/// @param text_sample is the new text sample.
|
|
|
|
/// @return true if the sample is accepted, false if something was wrong
|
|
|
|
/// with the sample and a parsing error should be signaled.
|
2022-12-17 05:40:00 +00:00
|
|
|
typedef std::function<bool(uint32_t track_id,
|
|
|
|
std::shared_ptr<TextSample> text_sample)>
|
2020-07-01 22:43:44 +00:00
|
|
|
NewTextSampleCB;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Initialize the parser with necessary callbacks. Must be called before any
|
|
|
|
/// data is passed to Parse().
|
|
|
|
/// @param init_cb will be called once enough data has been parsed to
|
|
|
|
/// determine the initial stream configurations.
|
2020-07-01 22:43:44 +00:00
|
|
|
/// @param new_media_sample_cb will be called each time a new media sample is
|
|
|
|
/// available from the parser.
|
|
|
|
/// @param new_text_sample_cb will be called each time a new text sample is
|
|
|
|
/// available from the parser.
|
|
|
|
/// @param decryption_key_source the key source to decrypt the frames. May be
|
|
|
|
/// NULL, and caller retains ownership.
|
2013-09-24 04:17:12 +00:00
|
|
|
virtual 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,
|
2014-08-25 22:51:19 +00:00
|
|
|
KeySource* decryption_key_source) = 0;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2014-04-24 18:37:33 +00:00
|
|
|
/// Flush data currently in the parser and put the parser in a state where it
|
|
|
|
/// can receive data for a new seek point.
|
2016-01-21 18:30:29 +00:00
|
|
|
/// @return true if successful, false otherwise.
|
2022-12-17 05:40:00 +00:00
|
|
|
[[nodiscard]] virtual bool Flush() = 0;
|
2014-04-24 18:37:33 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Should be called when there is new data to parse.
|
|
|
|
/// @return true if successful.
|
2022-12-17 05:40:00 +00:00
|
|
|
[[nodiscard]] virtual bool Parse(const uint8_t* buf, int size) = 0;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MediaParser);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_MEDIA_PARSER_H_
|