2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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_STREAM_INFO_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_STREAM_INFO_H_
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2017-09-12 17:24:24 +00:00
|
|
|
#include <memory>
|
2013-09-24 04:17:12 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-03-11 02:48:04 +00:00
|
|
|
#include "packager/media/base/encryption_config.h"
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 04:17:12 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
enum StreamType {
|
2014-06-27 23:07:36 +00:00
|
|
|
kStreamUnknown = 0,
|
2013-09-24 04:17:12 +00:00
|
|
|
kStreamAudio,
|
|
|
|
kStreamVideo,
|
2015-10-14 23:12:10 +00:00
|
|
|
kStreamText,
|
2013-09-24 04:17:12 +00:00
|
|
|
};
|
|
|
|
|
2018-06-19 16:52:54 +00:00
|
|
|
std::string StreamTypeToString(StreamType type);
|
|
|
|
|
2016-07-27 00:51:08 +00:00
|
|
|
enum Codec {
|
|
|
|
kUnknownCodec = 0,
|
Implement ChunkingHandler
This handler is a multi-in multi-out handler. If more than one input is
provided, there should be one and only one video stream; also, all inputs
should come from the same thread and are synchronized.
There can be multiple chunking handler running in different threads or even
different processes, we use the "consistent chunking algorithm" to make sure
the chunks in different streams are aligned without explicit communcating
with each other - which is not efficient and often difficult.
Consistent Chunking Algorithm:
1. Find the consistent chunkable boundary
Let the timestamps for video frames be (t1, t2, t3, ...). Then a
consistent chunkable boundary is simply the first chunkable boundary after
(tk / N) != (tk-1 / N), where '/' denotes integer division, and N is the
intended chunk duration.
2. Chunk only at the consistent chunkable boundary
This algorithm will make sure the chunks from different video streams are
aligned if they have aligned GoPs. However, this algorithm will only work
for video streams. To be able to chunk non video streams at similar
positions as video streams, ChunkingHandler is designed to accept one video
input and multiple non video inputs, the non video inputs are chunked when
the video input is chunked. If the inputs are synchronized - which is true
if the inputs come from the same demuxer, the video and non video chunks
are aligned.
Change-Id: Id3bad51ab14f311efdb8713b6cd36d36cf9e4639
2017-02-07 18:58:47 +00:00
|
|
|
|
|
|
|
kCodecVideo = 100,
|
2018-08-25 02:04:00 +00:00
|
|
|
kCodecAV1 = kCodecVideo,
|
|
|
|
kCodecH264,
|
2017-03-23 18:34:20 +00:00
|
|
|
kCodecH265,
|
2019-09-21 01:02:13 +00:00
|
|
|
kCodecH265DolbyVision,
|
2016-07-27 00:51:08 +00:00
|
|
|
kCodecVP8,
|
|
|
|
kCodecVP9,
|
Implement ChunkingHandler
This handler is a multi-in multi-out handler. If more than one input is
provided, there should be one and only one video stream; also, all inputs
should come from the same thread and are synchronized.
There can be multiple chunking handler running in different threads or even
different processes, we use the "consistent chunking algorithm" to make sure
the chunks in different streams are aligned without explicit communcating
with each other - which is not efficient and often difficult.
Consistent Chunking Algorithm:
1. Find the consistent chunkable boundary
Let the timestamps for video frames be (t1, t2, t3, ...). Then a
consistent chunkable boundary is simply the first chunkable boundary after
(tk / N) != (tk-1 / N), where '/' denotes integer division, and N is the
intended chunk duration.
2. Chunk only at the consistent chunkable boundary
This algorithm will make sure the chunks from different video streams are
aligned if they have aligned GoPs. However, this algorithm will only work
for video streams. To be able to chunk non video streams at similar
positions as video streams, ChunkingHandler is designed to accept one video
input and multiple non video inputs, the non video inputs are chunked when
the video input is chunked. If the inputs are synchronized - which is true
if the inputs come from the same demuxer, the video and non video chunks
are aligned.
Change-Id: Id3bad51ab14f311efdb8713b6cd36d36cf9e4639
2017-02-07 18:58:47 +00:00
|
|
|
kCodecVideoMaxPlusOne,
|
|
|
|
|
|
|
|
kCodecAudio = 200,
|
|
|
|
kCodecAAC = kCodecAudio,
|
2016-07-27 00:51:08 +00:00
|
|
|
kCodecAC3,
|
2020-07-04 21:55:28 +00:00
|
|
|
kCodecAC4,
|
2017-03-23 18:34:20 +00:00
|
|
|
// TODO(kqyang): Use kCodecDTS and a kDtsStreamFormat for the various DTS
|
|
|
|
// streams.
|
2016-07-27 00:51:08 +00:00
|
|
|
kCodecDTSC,
|
|
|
|
kCodecDTSE,
|
|
|
|
kCodecDTSH,
|
|
|
|
kCodecDTSL,
|
|
|
|
kCodecDTSM,
|
|
|
|
kCodecDTSP,
|
|
|
|
kCodecEAC3,
|
2018-04-25 18:27:53 +00:00
|
|
|
kCodecFlac,
|
2016-07-27 00:51:08 +00:00
|
|
|
kCodecOpus,
|
|
|
|
kCodecVorbis,
|
2020-06-03 00:32:19 +00:00
|
|
|
kCodecMP3,
|
Implement ChunkingHandler
This handler is a multi-in multi-out handler. If more than one input is
provided, there should be one and only one video stream; also, all inputs
should come from the same thread and are synchronized.
There can be multiple chunking handler running in different threads or even
different processes, we use the "consistent chunking algorithm" to make sure
the chunks in different streams are aligned without explicit communcating
with each other - which is not efficient and often difficult.
Consistent Chunking Algorithm:
1. Find the consistent chunkable boundary
Let the timestamps for video frames be (t1, t2, t3, ...). Then a
consistent chunkable boundary is simply the first chunkable boundary after
(tk / N) != (tk-1 / N), where '/' denotes integer division, and N is the
intended chunk duration.
2. Chunk only at the consistent chunkable boundary
This algorithm will make sure the chunks from different video streams are
aligned if they have aligned GoPs. However, this algorithm will only work
for video streams. To be able to chunk non video streams at similar
positions as video streams, ChunkingHandler is designed to accept one video
input and multiple non video inputs, the non video inputs are chunked when
the video input is chunked. If the inputs are synchronized - which is true
if the inputs come from the same demuxer, the video and non video chunks
are aligned.
Change-Id: Id3bad51ab14f311efdb8713b6cd36d36cf9e4639
2017-02-07 18:58:47 +00:00
|
|
|
kCodecAudioMaxPlusOne,
|
|
|
|
|
|
|
|
kCodecText = 300,
|
2017-02-14 21:40:09 +00:00
|
|
|
kCodecWebVtt = kCodecText,
|
2020-10-08 21:46:37 +00:00
|
|
|
kCodecTtml,
|
2016-07-27 00:51:08 +00:00
|
|
|
};
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Abstract class holds stream information.
|
2017-01-24 00:55:02 +00:00
|
|
|
class StreamInfo {
|
2013-09-24 04:17:12 +00:00
|
|
|
public:
|
2017-02-27 17:22:25 +00:00
|
|
|
StreamInfo() = default;
|
|
|
|
|
2018-06-19 16:58:29 +00:00
|
|
|
StreamInfo(StreamType stream_type,
|
|
|
|
int track_id,
|
|
|
|
uint32_t time_scale,
|
|
|
|
uint64_t duration,
|
|
|
|
Codec codec,
|
|
|
|
const std::string& codec_string,
|
|
|
|
const uint8_t* codec_config,
|
|
|
|
size_t codec_config_size,
|
|
|
|
const std::string& language,
|
|
|
|
bool is_encrypted);
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2017-01-24 00:55:02 +00:00
|
|
|
virtual ~StreamInfo();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @return true if this object has appropriate configuration values, false
|
|
|
|
/// otherwise.
|
2013-09-24 04:17:12 +00:00
|
|
|
virtual bool IsValidConfig() const = 0;
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @return A human-readable string describing the stream info.
|
2013-10-14 20:55:48 +00:00
|
|
|
virtual std::string ToString() const;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2017-09-12 17:24:24 +00:00
|
|
|
/// @return A new copy of this stream info. The copy will be of the same
|
|
|
|
/// type as the original. This should be used when a copy is needed
|
|
|
|
/// without explicitly knowing the stream info type.
|
|
|
|
virtual std::unique_ptr<StreamInfo> Clone() const = 0;
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
StreamType stream_type() const { return stream_type_; }
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t track_id() const { return track_id_; }
|
|
|
|
uint32_t time_scale() const { return time_scale_; }
|
|
|
|
uint64_t duration() const { return duration_; }
|
2016-07-27 00:51:08 +00:00
|
|
|
Codec codec() const { return codec_; }
|
2013-10-14 20:55:48 +00:00
|
|
|
const std::string& codec_string() const { return codec_string_; }
|
2016-07-27 00:51:08 +00:00
|
|
|
const std::vector<uint8_t>& codec_config() const { return codec_config_; }
|
2013-10-14 20:55:48 +00:00
|
|
|
const std::string& language() const { return language_; }
|
2013-09-24 04:17:12 +00:00
|
|
|
bool is_encrypted() const { return is_encrypted_; }
|
2017-05-09 22:49:01 +00:00
|
|
|
bool has_clear_lead() const { return has_clear_lead_; }
|
2017-03-11 02:48:04 +00:00
|
|
|
const EncryptionConfig& encryption_config() const {
|
|
|
|
return encryption_config_;
|
|
|
|
}
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2017-03-23 16:38:51 +00:00
|
|
|
void set_duration(uint64_t duration) { duration_ = duration; }
|
2016-07-27 00:51:08 +00:00
|
|
|
void set_codec(Codec codec) { codec_ = codec; }
|
2018-06-19 16:58:29 +00:00
|
|
|
void set_codec_config(const std::vector<uint8_t>& data) {
|
|
|
|
codec_config_ = data;
|
|
|
|
}
|
2014-07-14 21:35:57 +00:00
|
|
|
void set_codec_string(const std::string& codec_string) {
|
|
|
|
codec_string_ = codec_string;
|
|
|
|
}
|
2015-02-02 19:27:32 +00:00
|
|
|
void set_language(const std::string& language) { language_ = language; }
|
2017-02-02 18:28:29 +00:00
|
|
|
void set_is_encrypted(bool is_encrypted) { is_encrypted_ = is_encrypted; }
|
2017-05-09 22:49:01 +00:00
|
|
|
void set_has_clear_lead(bool has_clear_lead) {
|
|
|
|
has_clear_lead_ = has_clear_lead;
|
|
|
|
}
|
2017-03-11 02:48:04 +00:00
|
|
|
void set_encryption_config(const EncryptionConfig& encryption_config) {
|
|
|
|
encryption_config_ = encryption_config;
|
|
|
|
}
|
2015-02-02 19:27:32 +00:00
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
private:
|
|
|
|
// Whether the stream is Audio or Video.
|
|
|
|
StreamType stream_type_;
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t track_id_;
|
2013-10-14 20:55:48 +00:00
|
|
|
// The actual time is calculated as time / time_scale_ in seconds.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t time_scale_;
|
2013-10-14 20:55:48 +00:00
|
|
|
// Duration base on time_scale.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint64_t duration_;
|
2016-07-27 00:51:08 +00:00
|
|
|
Codec codec_;
|
2013-10-14 20:55:48 +00:00
|
|
|
std::string codec_string_;
|
|
|
|
std::string language_;
|
2013-09-24 04:17:12 +00:00
|
|
|
// Whether the stream is potentially encrypted.
|
|
|
|
// Note that in a potentially encrypted stream, individual buffers
|
|
|
|
// can be encrypted or not encrypted.
|
|
|
|
bool is_encrypted_;
|
2017-05-09 22:49:01 +00:00
|
|
|
// Whether the stream has clear lead.
|
|
|
|
bool has_clear_lead_ = false;
|
2017-03-11 02:48:04 +00:00
|
|
|
EncryptionConfig encryption_config_;
|
2013-09-24 04:17:12 +00:00
|
|
|
// Optional byte data required for some audio/video decoders such as Vorbis
|
|
|
|
// codebooks.
|
2016-06-27 19:30:32 +00:00
|
|
|
std::vector<uint8_t> codec_config_;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
// Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
|
|
|
|
// generated copy constructor and assignment operator. Since the extra data is
|
|
|
|
// typically small, the performance impact is minimal.
|
|
|
|
};
|
|
|
|
|
|
|
|
} // 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_STREAM_INFO_H_
|