6 #ifndef PACKAGER_MEDIA_FORMATS_WVM_WVM_MEDIA_PARSER_H_
7 #define PACKAGER_MEDIA_FORMATS_WVM_WVM_MEDIA_PARSER_H_
15 #include <absl/base/internal/endian.h>
17 #include <packager/macros/classes.h>
18 #include <packager/media/base/media_parser.h>
19 #include <packager/media/codecs/h264_byte_to_unit_stream_converter.h>
24 class AesCbcDecryptor;
34 uint32_t demux_stream_id;
35 uint32_t parsed_audio_or_video_stream_id;
36 std::shared_ptr<MediaSample> media_sample;
44 std::shared_ptr<MediaSample> audio_sample;
45 std::shared_ptr<MediaSample> video_sample;
46 uint32_t audio_stream_id;
47 uint32_t video_stream_id;
48 int64_t audio_sample_duration;
49 int64_t video_sample_duration;
62 KeySource* decryption_key_source)
override;
63 [[nodiscard]]
bool Flush()
override;
64 [[nodiscard]]
bool Parse(
const uint8_t* buf,
int size)
override;
74 TrackTrickPlayFactor = 5,
75 TrackAdaptationInterval = 6,
82 VideoTicksPerFrame = 13,
86 AudioNumChannels = 17,
87 AudioSampleFrequency = 18,
100 VideoPixelWidth = 31,
101 VideoPixelHeight = 32,
103 SparseDownloadUrl = 34,
104 SparseDownloadRangeTranslations = 35,
105 SparseDownloadMap = 36,
106 AudioSampleSize = 37,
107 Audio_EsDescriptor = 38,
108 Video_AVCDecoderConfigurationRecord = 39,
109 Audio_EC3SpecificData = 40,
110 AudioIdentifier = 41,
112 VideoStreamType = 43,
114 AudioStreamType = 45,
115 Audio_DtsSpecificData = 46,
116 Audio_AC3SpecificData = 47,
135 PackHeaderStuffingSkip,
168 bool ParseIndexEntry();
170 bool DemuxNextPes(
bool is_program_end);
172 void StartMediaSampleDemux();
174 template <
typename T>
175 Tag GetTag(
const uint8_t& tag,
176 const uint32_t& length,
177 const uint8_t* start_index,
179 if (length ==
sizeof(uint8_t)) {
180 *value = *start_index;
181 }
else if (length ==
sizeof(int8_t)) {
182 *value = (int8_t)(*start_index);
183 }
else if (length ==
sizeof(uint16_t)) {
184 *value = absl::big_endian::Load16(start_index);
185 }
else if (length ==
sizeof(int16_t)) {
186 *value = (int16_t)(absl::big_endian::Load16(start_index));
187 }
else if (length ==
sizeof(uint32_t)) {
188 *value = absl::big_endian::Load32(start_index);
189 }
else if (length ==
sizeof(int32_t)) {
190 *value = (int32_t)(absl::big_endian::Load32(start_index));
191 }
else if (length ==
sizeof(uint64_t)) {
192 *value = absl::big_endian::Load64(start_index);
193 }
else if (length ==
sizeof(int64_t)) {
194 *value = (int64_t)(absl::big_endian::Load64(start_index));
203 bool Output(
bool must_process_encrypted);
205 bool GetAssetKey(
const uint8_t* asset_id,
EncryptionKey* encryption_key);
209 bool EmitSample(uint32_t parsed_audio_or_video_stream_id,
211 const std::shared_ptr<MediaSample>& new_sample,
214 bool EmitPendingSamples();
216 bool EmitLastSample(uint32_t stream_id,
217 const std::shared_ptr<MediaSample>& new_sample);
224 bool is_initialized_;
228 uint32_t skip_bytes_;
229 bool metadata_is_complete_;
230 uint8_t current_program_id_;
231 uint32_t pes_stream_id_;
232 uint32_t prev_pes_stream_id_;
233 size_t pes_packet_bytes_;
234 uint8_t pes_flags_1_;
235 uint8_t pes_flags_2_;
236 uint8_t prev_pes_flags_1_;
237 size_t pes_header_data_bytes_;
241 uint8_t index_program_id_;
242 std::shared_ptr<MediaSample> media_sample_;
243 size_t crypto_unit_start_pos_;
247 std::vector<uint8_t, std::allocator<uint8_t>> ecm_;
248 std::vector<uint8_t> psm_data_;
249 std::vector<uint8_t> index_data_;
250 std::map<std::string, uint32_t> program_demux_stream_map_;
251 int stream_id_count_;
252 std::vector<std::shared_ptr<StreamInfo>> stream_infos_;
253 std::deque<DemuxStreamIdMediaSample> media_sample_queue_;
254 std::vector<uint8_t> sample_data_;
256 std::unique_ptr<AesCbcDecryptor> content_decryptor_;
All the methods that are virtual are virtual for mocking.