Shaka Packager SDK
ts_writer.h
1 // Copyright 2016 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_FORMATS_MP2T_TS_WRITER_H_
8 #define PACKAGER_MEDIA_FORMATS_MP2T_TS_WRITER_H_
9 
10 #include <list>
11 #include <map>
12 #include <memory>
13 #include <vector>
14 
15 #include "packager/base/optional.h"
16 #include "packager/file/file.h"
17 #include "packager/file/file_closer.h"
18 #include "packager/media/formats/mp2t/continuity_counter.h"
19 
20 namespace shaka {
21 namespace media {
22 namespace mp2t {
23 
24 class PesPacket;
25 class ProgramMapTableWriter;
26 
29 class TsWriter {
30  public:
31  explicit TsWriter(std::unique_ptr<ProgramMapTableWriter> pmt_writer);
32  virtual ~TsWriter();
33 
38  virtual bool NewSegment(const std::string& file_name);
39 
41  virtual void SignalEncrypted();
42 
46  virtual bool FinalizeSegment();
47 
52  virtual bool AddPesPacket(std::unique_ptr<PesPacket> pes_packet);
53 
55  base::Optional<uint64_t> GetFilePosition();
56 
57  private:
58  TsWriter(const TsWriter&) = delete;
59  TsWriter& operator=(const TsWriter&) = delete;
60 
61  // True if further segments generated by this instance should be encrypted.
62  bool encrypted_ = false;
63 
64  ContinuityCounter pat_continuity_counter_;
65  ContinuityCounter elementary_stream_continuity_counter_;
66 
67  std::unique_ptr<ProgramMapTableWriter> pmt_writer_;
68 
69  std::unique_ptr<File, FileCloser> current_file_;
70 };
71 
72 } // namespace mp2t
73 } // namespace media
74 } // namespace shaka
75 
76 #endif // PACKAGER_MEDIA_FORMATS_MP2T_TS_WRITER_H_
virtual bool NewSegment(const std::string &file_name)
Definition: ts_writer.cc:166
base::Optional< uint64_t > GetFilePosition()
Definition: ts_writer.cc:217
All the methods that are virtual are virtual for mocking.
virtual bool AddPesPacket(std::unique_ptr< PesPacket > pes_packet)
Definition: ts_writer.cc:205
virtual bool FinalizeSegment()
Definition: ts_writer.cc:201
virtual void SignalEncrypted()
Signals the writer that the rest of the segments are encrypted.
Definition: ts_writer.cc:197