Shaka Packager SDK
packed_audio_segmenter.h
1 // Copyright 2018 Google LLC. 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_PACKED_AUDIO_PACKED_AUDIO_SEGMENTER_H_
8 #define PACKAGER_MEDIA_FORMATS_PACKED_AUDIO_PACKED_AUDIO_SEGMENTER_H_
9 
10 #include <memory>
11 
12 #include "packager/media/base/buffer_writer.h"
13 #include "packager/media/base/stream_info.h"
14 #include "packager/status.h"
15 
16 namespace shaka {
17 namespace media {
18 
19 class AACAudioSpecificConfig;
20 class Id3Tag;
21 class MediaSample;
22 
24 constexpr double kPackedAudioTimescale = 90000;
25 
28 constexpr char kTimestampOwnerIdentifier[] =
29  "com.apple.streaming.transportStreamTimestamp";
30 
33 constexpr char kAudioDescriptionOwnerIdentifier[] =
34  "com.apple.streaming.audioDescription";
35 
41  public:
45  explicit PackedAudioSegmenter(uint32_t transport_stream_timestamp_offset);
46  virtual ~PackedAudioSegmenter();
47 
51  // This function is made virtual for testing.
52  virtual Status Initialize(const StreamInfo& stream_info);
53 
56  // This function is made virtual for testing.
57  virtual Status AddSample(const MediaSample& sample);
58 
62  // This function is made virtual for testing.
63  virtual Status FinalizeSegment();
64 
67  // This function is made virtual for testing.
68  virtual double TimescaleScale() const;
69 
71  BufferWriter* segment_buffer() { return &segment_buffer_; }
72 
73  private:
75  PackedAudioSegmenter& operator=(const PackedAudioSegmenter&) = delete;
76 
77  // These functions is made virtual for testing.
78  virtual std::unique_ptr<AACAudioSpecificConfig> CreateAdtsConverter();
79  virtual std::unique_ptr<Id3Tag> CreateId3Tag();
80 
81  Status EncryptionAudioSetup(const MediaSample& sample);
82  Status StartNewSegment(const MediaSample& first_sample);
83 
84  const uint32_t transport_stream_timestamp_offset_ = 0;
85  // Codec for the stream.
86  Codec codec_ = kUnknownCodec;
87  std::vector<uint8_t> audio_codec_config_;
88  // Calculated by output stream's timescale / input stream's timescale. This is
89  // used to scale the timestamps.
90  double timescale_scale_ = 0.0;
91  // Whether it is the start of a new segment.
92  bool start_of_new_segment_ = true;
93 
94  // Audio setup information for encrypted segment.
95  std::string audio_setup_information_;
96  // AAC is carried in ADTS.
97  std::unique_ptr<AACAudioSpecificConfig> adts_converter_;
98 
99  BufferWriter segment_buffer_;
100 };
101 
102 } // namespace media
103 } // namespace shaka
104 
105 #endif // PACKAGER_MEDIA_FORMATS_PACKED_AUDIO_PACKED_AUDIO_SEGMENTER_H_
Abstract class holds stream information.
Definition: stream_info.h:61
All the methods that are virtual are virtual for mocking.
virtual Status Initialize(const StreamInfo &stream_info)
Class to hold a media sample.
Definition: media_sample.h:22
PackedAudioSegmenter(uint32_t transport_stream_timestamp_offset)
virtual Status AddSample(const MediaSample &sample)