shaka-packager/packager/media/base/video_stream_info.h

125 lines
4.6 KiB
C
Raw Normal View History

// 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
#ifndef MEDIA_BASE_VIDEO_STREAM_INFO_H_
#define MEDIA_BASE_VIDEO_STREAM_INFO_H_
#include "packager/media/base/stream_info.h"
namespace shaka {
namespace media {
enum class H26xStreamFormat {
kUnSpecified,
kAnnexbByteStream,
kNalUnitStreamWithParameterSetNalus,
kNalUnitStreamWithoutParameterSetNalus,
};
/// Holds video stream information.
class VideoStreamInfo : public StreamInfo {
public:
VideoStreamInfo() = default;
/// Construct an initialized video stream info object.
/// @param pixel_width is the width of the pixel. 0 if unknown.
/// @param pixel_height is the height of the pixels. 0 if unknown.
VideoStreamInfo(int track_id,
uint32_t time_scale,
uint64_t duration,
Codec codec,
H26xStreamFormat h26x_stream_format,
const std::string& codec_string,
const uint8_t* codec_config,
size_t codec_config_size,
uint16_t width,
uint16_t height,
uint32_t pixel_width,
uint32_t pixel_height,
uint32_t trick_play_rate,
uint8_t nalu_length_size,
const std::string& language,
bool is_encrypted);
~VideoStreamInfo() override;
/// @name StreamInfo implementation overrides.
/// @{
bool IsValidConfig() const override;
std::string ToString() const override;
/// @}
H26xStreamFormat h26x_stream_format() const { return h26x_stream_format_; }
uint16_t width() const { return width_; }
uint16_t height() const { return height_; }
/// Returns the pixel width.
/// @return 0 if unknown.
uint32_t pixel_width() const { return pixel_width_; }
/// Returns the pixel height.
/// @return 0 if unknown.
uint32_t pixel_height() const { return pixel_height_; }
uint8_t nalu_length_size() const { return nalu_length_size_; }
uint32_t trick_play_rate() const { return trick_play_rate_; }
uint32_t playback_rate() const { return playback_rate_; }
const std::vector<uint8_t>& eme_init_data() const { return eme_init_data_; }
void set_width(uint32_t width) { width_ = width; }
void set_height(uint32_t height) { height_ = height; }
void set_pixel_width(uint32_t pixel_width) { pixel_width_ = pixel_width; }
void set_pixel_height(uint32_t pixel_height) { pixel_height_ = pixel_height; }
void set_trick_play_rate(uint32_t trick_play_rate) {
trick_play_rate_ = trick_play_rate;
}
void set_playback_rate(uint32_t playback_rate) {
playback_rate_ = playback_rate;
}
void set_eme_init_data(const uint8_t* eme_init_data,
size_t eme_init_data_size) {
eme_init_data_.assign(eme_init_data, eme_init_data + eme_init_data_size);
}
private:
H26xStreamFormat h26x_stream_format_;
uint16_t width_;
uint16_t height_;
// pixel_width_:pixel_height_ is the sample aspect ratio.
// 0 means unknown.
uint32_t pixel_width_;
uint32_t pixel_height_;
uint32_t trick_play_rate_ = 0; // Non-zero for trick-play streams.
// Playback rate is the attribute for trick play stream, which signals the
// playout capabilities
// (http://dashif.org/wp-content/uploads/2016/12/DASH-IF-IOP-v4.0-clean.pdf,
// page 18, line 1). It is the ratio of main frame rate to the trick play
// frame rate. If the time scale and frame duration are not modified after
// trick play handler processing, the playback_rate equals to the number of
// frames between consecutive key frames selected for trick play stream. For
// example, if the video stream has GOP size of 10 and the trick play rate is
// 3, the key frames are in this trick play stream are [frame_0, frame_30,
// frame_60, ...]. Then the playback_rate is 30.
uint32_t playback_rate_;
// Specifies the size of the NAL unit length field. Can be 1, 2 or 4 bytes, or
// 0 if the stream is not a NAL structured video stream or if it is an AnnexB
// byte stream.
uint8_t nalu_length_size_;
// Container-specific data used by CDM to generate a license request:
// https://w3c.github.io/encrypted-media/#initialization-data.
std::vector<uint8_t> eme_init_data_;
// 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
} // namespace shaka
#endif // MEDIA_BASE_VIDEO_STREAM_INFO_H_