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_TRACKS_PARSER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBM_WEBM_TRACKS_PARSER_H_
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
#include <map>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2015-10-08 21:48:07 +00:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
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/audio_stream_info.h>
|
|
|
|
#include <packager/media/base/text_track_config.h>
|
|
|
|
#include <packager/media/base/video_stream_info.h>
|
|
|
|
#include <packager/media/formats/webm/webm_audio_client.h>
|
|
|
|
#include <packager/media/formats/webm/webm_content_encodings_client.h>
|
|
|
|
#include <packager/media/formats/webm/webm_parser.h>
|
|
|
|
#include <packager/media/formats/webm/webm_video_client.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 {
|
|
|
|
|
2015-10-15 22:39:16 +00:00
|
|
|
/// Parser for WebM Tracks element.
|
2015-10-14 22:46:23 +00:00
|
|
|
class WebMTracksParser : public WebMParserClient {
|
2015-10-08 21:48:07 +00:00
|
|
|
public:
|
2015-10-14 22:46:23 +00:00
|
|
|
explicit WebMTracksParser(bool ignore_text_tracks);
|
2015-10-08 21:48:07 +00:00
|
|
|
~WebMTracksParser() override;
|
|
|
|
|
2015-10-15 22:39:16 +00:00
|
|
|
/// Parses a WebM Tracks element in |buf|.
|
|
|
|
/// @return -1 if the parse fails.
|
|
|
|
/// @return 0 if more data is needed.
|
|
|
|
/// @return The number of bytes parsed on success.
|
2015-10-14 22:46:23 +00:00
|
|
|
int Parse(const uint8_t* buf, int size);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
int64_t audio_track_num() const { return audio_track_num_; }
|
|
|
|
int64_t video_track_num() const { return video_track_num_; }
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-15 22:39:16 +00:00
|
|
|
/// If TrackEntry DefaultDuration field existed for the associated audio or
|
|
|
|
/// video track, returns that value converted from ns to base::TimeDelta with
|
|
|
|
/// precision not greater than |timecode_scale_in_us|. Defaults to
|
|
|
|
/// kNoTimestamp.
|
2015-10-14 23:12:10 +00:00
|
|
|
int64_t GetAudioDefaultDuration(const double timecode_scale_in_us) const;
|
|
|
|
int64_t GetVideoDefaultDuration(const double timecode_scale_in_us) const;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
const std::set<int64_t>& ignored_tracks() const { return ignored_tracks_; }
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
const std::string& audio_encryption_key_id() const {
|
|
|
|
return audio_encryption_key_id_;
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<AudioStreamInfo> audio_stream_info() {
|
2015-10-14 23:12:10 +00:00
|
|
|
return audio_stream_info_;
|
2015-10-08 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& video_encryption_key_id() const {
|
|
|
|
return video_encryption_key_id_;
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<VideoStreamInfo> video_stream_info() {
|
2015-10-14 23:12:10 +00:00
|
|
|
return video_stream_info_;
|
2015-10-08 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::map<int, TextTrackConfig> TextTracks;
|
|
|
|
|
|
|
|
const TextTracks& text_tracks() const {
|
|
|
|
return text_tracks_;
|
|
|
|
}
|
|
|
|
|
2017-04-25 19:02:08 +00:00
|
|
|
const VPCodecConfigurationRecord& vp_config() const { return vp_config_; }
|
|
|
|
|
2015-10-08 21:48:07 +00:00
|
|
|
private:
|
|
|
|
// WebMParserClient implementation.
|
|
|
|
WebMParserClient* OnListStart(int id) override;
|
|
|
|
bool OnListEnd(int id) override;
|
2015-10-14 22:46:23 +00:00
|
|
|
bool OnUInt(int id, int64_t val) override;
|
2015-10-08 21:48:07 +00:00
|
|
|
bool OnFloat(int id, double val) override;
|
2015-10-14 22:46:23 +00:00
|
|
|
bool OnBinary(int id, const uint8_t* data, int size) override;
|
2015-10-08 21:48:07 +00:00
|
|
|
bool OnString(int id, const std::string& str) override;
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
int64_t track_type_;
|
|
|
|
int64_t track_num_;
|
2015-10-08 21:48:07 +00:00
|
|
|
std::string track_name_;
|
|
|
|
std::string track_language_;
|
|
|
|
std::string codec_id_;
|
2015-10-14 22:46:23 +00:00
|
|
|
std::vector<uint8_t> codec_private_;
|
|
|
|
int64_t seek_preroll_;
|
|
|
|
int64_t codec_delay_;
|
|
|
|
int64_t default_duration_;
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<WebMContentEncodingsClient> track_content_encodings_client_;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
int64_t audio_track_num_;
|
|
|
|
int64_t audio_default_duration_;
|
|
|
|
int64_t video_track_num_;
|
|
|
|
int64_t video_default_duration_;
|
2015-10-08 21:48:07 +00:00
|
|
|
bool ignore_text_tracks_;
|
|
|
|
TextTracks text_tracks_;
|
2015-10-14 22:46:23 +00:00
|
|
|
std::set<int64_t> ignored_tracks_;
|
2015-10-08 21:48:07 +00:00
|
|
|
std::string audio_encryption_key_id_;
|
|
|
|
std::string video_encryption_key_id_;
|
|
|
|
|
|
|
|
WebMAudioClient audio_client_;
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<AudioStreamInfo> audio_stream_info_;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
WebMVideoClient video_client_;
|
2017-04-25 19:02:08 +00:00
|
|
|
VPCodecConfigurationRecord vp_config_;
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<VideoStreamInfo> video_stream_info_;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebMTracksParser);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // 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_TRACKS_PARSER_H_
|