2016-03-21 00:04:54 +00:00
|
|
|
// Copyright 2016 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 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>
|
|
|
|
|
2017-07-10 18:26:22 +00:00
|
|
|
#include "packager/file/file.h"
|
|
|
|
#include "packager/file/file_closer.h"
|
2016-04-14 05:40:24 +00:00
|
|
|
#include "packager/media/formats/mp2t/continuity_counter.h"
|
2016-03-21 00:04:54 +00:00
|
|
|
#include "packager/media/formats/mp2t/pes_packet.h"
|
2016-04-14 05:40:24 +00:00
|
|
|
#include "packager/media/formats/mp2t/program_map_table_writer.h"
|
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 {
|
2017-02-21 18:36:50 +00:00
|
|
|
|
|
|
|
class StreamInfo;
|
|
|
|
|
2016-03-21 00:04:54 +00:00
|
|
|
namespace mp2t {
|
|
|
|
|
|
|
|
/// This class takes PesPackets, encapsulates them into TS packets, and write
|
|
|
|
/// the data to file. This also creates PSI from StreamInfo.
|
|
|
|
class TsWriter {
|
|
|
|
public:
|
|
|
|
TsWriter();
|
2016-03-21 19:16:58 +00:00
|
|
|
virtual ~TsWriter();
|
2016-03-21 00:04:54 +00:00
|
|
|
|
|
|
|
/// This must be called before calling other methods.
|
2016-04-14 05:40:24 +00:00
|
|
|
/// @param stream_info is the information about this stream.
|
2016-03-21 00:04:54 +00:00
|
|
|
/// @return true on success, false otherwise.
|
2016-06-29 21:24:40 +00:00
|
|
|
virtual bool Initialize(const StreamInfo& stream_info);
|
2016-03-21 00:04:54 +00:00
|
|
|
|
|
|
|
/// This will fail if the current segment is not finalized.
|
|
|
|
/// @param file_name is the output file name.
|
2016-04-14 05:40:24 +00:00
|
|
|
/// @param encrypted must be true if the new segment is encrypted.
|
2016-03-21 00:04:54 +00:00
|
|
|
/// @return true on success, false otherwise.
|
2016-03-21 19:16:58 +00:00
|
|
|
virtual bool NewSegment(const std::string& file_name);
|
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
|
|
|
|
2016-03-21 00:04:54 +00:00
|
|
|
/// Flush all the pending PesPackets that have not been written to file and
|
|
|
|
/// close the file.
|
|
|
|
/// @return true on success, false otherwise.
|
2016-03-21 19:16:58 +00:00
|
|
|
virtual bool FinalizeSegment();
|
2016-03-21 00:04:54 +00:00
|
|
|
|
|
|
|
/// Add PesPacket to the instance. PesPacket might not get written to file
|
|
|
|
/// immediately.
|
|
|
|
/// @param pes_packet gets added to the writer.
|
|
|
|
/// @return true on success, false otherwise.
|
2016-08-17 17:41:40 +00:00
|
|
|
virtual bool AddPesPacket(std::unique_ptr<PesPacket> pes_packet);
|
2016-03-21 00:04:54 +00:00
|
|
|
|
2016-04-14 05:40:24 +00:00
|
|
|
/// Only for testing.
|
|
|
|
void SetProgramMapTableWriterForTesting(
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<ProgramMapTableWriter> table_writer);
|
2016-03-21 00:04:54 +00:00
|
|
|
|
2016-04-14 05:40:24 +00:00
|
|
|
private:
|
|
|
|
// 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-04-14 05:40:24 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<File, FileCloser> current_file_;
|
2016-03-21 00:04:54 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TsWriter);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // 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_
|