2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2016 Google LLC. All rights reserved.
|
2016-03-21 00:04:54 +00:00
|
|
|
//
|
|
|
|
// 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 PACKAGER_MEDIA_FORMATS_MP2T_TS_WRITER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_MP2T_TS_WRITER_H_
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2016-03-21 00:04:54 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/file/file.h>
|
|
|
|
#include <packager/file/file_closer.h>
|
|
|
|
#include <packager/media/base/buffer_writer.h>
|
|
|
|
#include <packager/media/formats/mp2t/continuity_counter.h>
|
2023-08-31 23:59:46 +00:00
|
|
|
#include <optional>
|
2016-03-21 00:04:54 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-21 00:04:54 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp2t {
|
|
|
|
|
2017-10-23 22:59:30 +00:00
|
|
|
class PesPacket;
|
|
|
|
class ProgramMapTableWriter;
|
|
|
|
|
2016-03-21 00:04:54 +00:00
|
|
|
/// This class takes PesPackets, encapsulates them into TS packets, and write
|
|
|
|
/// the data to file. This also creates PSI from StreamInfo.
|
|
|
|
class TsWriter {
|
|
|
|
public:
|
2017-10-23 22:59:30 +00:00
|
|
|
explicit TsWriter(std::unique_ptr<ProgramMapTableWriter> pmt_writer);
|
2016-03-21 19:16:58 +00:00
|
|
|
virtual ~TsWriter();
|
2016-03-21 00:04:54 +00:00
|
|
|
|
|
|
|
/// This will fail if the current segment is not finalized.
|
2020-07-04 22:18:30 +00:00
|
|
|
/// @param buffer to write segment data.
|
2016-03-21 00:04:54 +00:00
|
|
|
/// @return true on success, false otherwise.
|
2020-07-04 22:18:30 +00:00
|
|
|
virtual bool NewSegment(BufferWriter* buffer);
|
2016-03-21 00:04:54 +00:00
|
|
|
|
2016-04-14 05:40:24 +00:00
|
|
|
/// Signals the writer that the rest of the segments are encrypted.
|
2016-07-01 21:49:46 +00:00
|
|
|
virtual void SignalEncrypted();
|
2016-04-14 05:40:24 +00:00
|
|
|
|
2020-07-04 22:18:30 +00:00
|
|
|
/// Add PesPacket to the instance. PesPacket might not be added to the buffer
|
2016-03-21 00:04:54 +00:00
|
|
|
/// immediately.
|
|
|
|
/// @param pes_packet gets added to the writer.
|
2020-07-04 22:18:30 +00:00
|
|
|
/// @param buffer to write pes packet.
|
2016-03-21 00:04:54 +00:00
|
|
|
/// @return true on success, false otherwise.
|
2020-07-04 22:18:30 +00:00
|
|
|
virtual bool AddPesPacket(std::unique_ptr<PesPacket> pes_packet, BufferWriter* buffer);
|
2018-02-01 20:25:07 +00:00
|
|
|
|
2016-04-14 05:40:24 +00:00
|
|
|
private:
|
2017-10-23 22:59:30 +00:00
|
|
|
TsWriter(const TsWriter&) = delete;
|
|
|
|
TsWriter& operator=(const TsWriter&) = delete;
|
|
|
|
|
2016-04-14 05:40:24 +00:00
|
|
|
// True if further segments generated by this instance should be encrypted.
|
|
|
|
bool encrypted_ = false;
|
2016-03-21 00:04:54 +00:00
|
|
|
|
|
|
|
ContinuityCounter pat_continuity_counter_;
|
|
|
|
ContinuityCounter elementary_stream_continuity_counter_;
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<ProgramMapTableWriter> pmt_writer_;
|
2016-03-21 00:04:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2016-03-21 00:04:54 +00:00
|
|
|
|
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_MP2T_TS_WRITER_H_
|