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_TRACKS_BUILDER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBM_TRACKS_BUILDER_H_
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <cstdint>
|
2015-10-08 21:48:07 +00:00
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/macros/classes.h>
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-10-08 21:48:07 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class TracksBuilder {
|
|
|
|
public:
|
|
|
|
// If |allow_invalid_values| is false, some AddTrack() parameters will be
|
|
|
|
// basically checked and will assert if out of valid range. |codec_id|,
|
|
|
|
// |name|, |language| and any device-specific constraints are not checked.
|
|
|
|
explicit TracksBuilder(bool allow_invalid_values);
|
|
|
|
TracksBuilder(); // Sets |allow_invalid_values| to false.
|
|
|
|
~TracksBuilder();
|
|
|
|
|
|
|
|
// Only a non-negative |default_duration| will result in a serialized
|
|
|
|
// kWebMIdDefaultDuration element. Note, 0 is allowed here for testing only
|
|
|
|
// if |allow_invalid_values_| is true, since it is an illegal value for
|
|
|
|
// DefaultDuration. Similar applies to |audio_channels|,
|
|
|
|
// |audio_sampling_frequency|, |video_pixel_width| and |video_pixel_height|.
|
|
|
|
void AddVideoTrack(int track_num,
|
2015-10-14 22:46:23 +00:00
|
|
|
uint64_t track_uid,
|
2015-10-08 21:48:07 +00:00
|
|
|
const std::string& codec_id,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& language,
|
|
|
|
int default_duration,
|
|
|
|
int video_pixel_width,
|
|
|
|
int video_pixel_height);
|
|
|
|
void AddAudioTrack(int track_num,
|
2015-10-14 22:46:23 +00:00
|
|
|
uint64_t track_uid,
|
2015-10-08 21:48:07 +00:00
|
|
|
const std::string& codec_id,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& language,
|
|
|
|
int default_duration,
|
|
|
|
int audio_channels,
|
|
|
|
double audio_sampling_frequency);
|
|
|
|
void AddTextTrack(int track_num,
|
2015-10-14 22:46:23 +00:00
|
|
|
uint64_t track_uid,
|
2015-10-08 21:48:07 +00:00
|
|
|
const std::string& codec_id,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& language);
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
std::vector<uint8_t> Finish();
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void AddTrackInternal(int track_num,
|
|
|
|
int track_type,
|
2015-10-14 22:46:23 +00:00
|
|
|
uint64_t track_uid,
|
2015-10-08 21:48:07 +00:00
|
|
|
const std::string& codec_id,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& language,
|
|
|
|
int default_duration,
|
|
|
|
int video_pixel_width,
|
|
|
|
int video_pixel_height,
|
|
|
|
int audio_channels,
|
|
|
|
double audio_sampling_frequency);
|
|
|
|
int GetTracksSize() const;
|
|
|
|
int GetTracksPayloadSize() const;
|
2015-10-14 22:46:23 +00:00
|
|
|
void WriteTracks(uint8_t* buffer, int buffer_size) const;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
class Track {
|
|
|
|
public:
|
|
|
|
Track(int track_num,
|
|
|
|
int track_type,
|
2015-10-14 22:46:23 +00:00
|
|
|
uint64_t track_uid,
|
2015-10-08 21:48:07 +00:00
|
|
|
const std::string& codec_id,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& language,
|
|
|
|
int default_duration,
|
|
|
|
int video_pixel_width,
|
|
|
|
int video_pixel_height,
|
|
|
|
int audio_channels,
|
|
|
|
double audio_sampling_frequency,
|
|
|
|
bool allow_invalid_values);
|
|
|
|
|
|
|
|
int GetSize() const;
|
2015-10-14 22:46:23 +00:00
|
|
|
void Write(uint8_t** buf, int* buf_size) const;
|
|
|
|
|
2015-10-08 21:48:07 +00:00
|
|
|
private:
|
|
|
|
int GetPayloadSize() const;
|
|
|
|
int GetVideoPayloadSize() const;
|
|
|
|
int GetAudioPayloadSize() const;
|
|
|
|
|
|
|
|
int track_num_;
|
|
|
|
int track_type_;
|
|
|
|
int track_uid_;
|
|
|
|
std::string codec_id_;
|
|
|
|
std::string name_;
|
|
|
|
std::string language_;
|
|
|
|
int default_duration_;
|
|
|
|
int video_pixel_width_;
|
|
|
|
int video_pixel_height_;
|
|
|
|
int audio_channels_;
|
|
|
|
double audio_sampling_frequency_;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::list<Track> TrackList;
|
|
|
|
TrackList tracks_;
|
|
|
|
bool allow_invalid_values_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TracksBuilder);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // 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_TRACKS_BUILDER_H_
|