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
|
|
|
|
|
|
|
#ifndef MEDIA_BASE_STREAM_INFO_H_
|
|
|
|
#define MEDIA_BASE_STREAM_INFO_H_
|
|
|
|
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
kCodecH264 = kCodecVideo,
|
2017-03-23 18:34:20 +00:00
|
|
|
kCodecH265,
|
2016-07-27 00:51:08 +00:00
|
|
|
kCodecVP8,
|
|
|
|
kCodecVP9,
|
|
|
|
kCodecVP10,
|
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,
|
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,
|
|
|
|
kCodecOpus,
|
|
|
|
kCodecVorbis,
|
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,
|
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:
|
2016-07-27 00:51:08 +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
|
|
|
|
|
|
|
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-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; }
|
2016-06-27 19:30:32 +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-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-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
|
|
|
|
|
|
|
#endif // MEDIA_BASE_STREAM_INFO_H_
|