Shaka Packager SDK
Loading...
Searching...
No Matches
mp2t_media_parser.h
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PACKAGER_MEDIA_FORMATS_MP2T_MP2T_MEDIA_PARSER_H_
6#define PACKAGER_MEDIA_FORMATS_MP2T_MP2T_MEDIA_PARSER_H_
7
8#include <bitset>
9#include <cstdint>
10#include <deque>
11#include <map>
12#include <memory>
13#include <string>
14#include <unordered_set>
15
16#include <packager/macros/classes.h>
17#include <packager/media/base/byte_queue.h>
18#include <packager/media/base/media_parser.h>
19#include <packager/media/base/stream_info.h>
20#include <packager/media/formats/mp2t/ts_audio_type.h>
21#include <packager/media/formats/mp2t/ts_stream_type.h>
22
23namespace shaka {
24namespace media {
25
26class MediaSample;
27
28namespace mp2t {
29
30class PidState;
31class TsPacket;
32class TsSection;
33
35 uint32_t max_bitrate;
36 std::string language;
37 TsAudioType audio_type;
38};
39
41 public:
43 ~Mp2tMediaParser() override;
44
47 void Init(const InitCB& init_cb,
48 const NewMediaSampleCB& new_media_sample_cb,
49 const NewTextSampleCB& new_text_sample_cb,
50 KeySource* decryption_key_source) override;
51 [[nodiscard]] bool Flush() override;
52 [[nodiscard]] bool Parse(const uint8_t* buf, int size) override;
54
55 private:
56 // Callback invoked to register a Program Map Table.
57 // Note: Does nothing if the PID is already registered.
58 void RegisterPmt(int program_number, int pmt_pid);
59
60 // Callback invoked to register a PES pid.
61 // Possible values for |media_type| are defined in:
62 // ISO-13818.1 / ITU H.222 Table 2.34 "Media type assignments".
63 // Possible values for |audio_type| are defined in:
64 // ISO-13818.1 / ITU H.222 Table 2-60 "Audio type values".
65 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
66 void RegisterPes(int pmt_pid,
67 int pes_pid,
68 TsStreamType media_type,
69 uint32_t max_bitrate,
70 const std::string& lang,
71 TsAudioType audio_type,
72 const uint8_t* descriptor,
73 size_t descriptor_length);
74
75 // Callback invoked each time the audio/video decoder configuration is
76 // changed.
77 void OnNewStreamInfo(uint32_t pes_pid,
78 std::shared_ptr<StreamInfo> new_stream_info);
79
80 // Callback invoked by the ES media parser
81 // to emit a new audio/video access unit.
82 void OnEmitMediaSample(uint32_t pes_pid,
83 std::shared_ptr<MediaSample> new_sample);
84 void OnEmitTextSample(uint32_t pes_pid,
85 std::shared_ptr<TextSample> new_sample);
86
87 // Invoke the initialization callback if needed.
88 bool FinishInitializationIfNeeded();
89
90 bool EmitRemainingSamples();
91
94 void set_sbr_in_mime_type(bool sbr_in_mimetype) {
95 sbr_in_mimetype_ = sbr_in_mimetype;
96 }
97
98 void update_biggest_pts(int64_t pts);
99 std::unordered_set<int> text_pids_;
100
101 // List of callbacks.
102 InitCB init_cb_;
103 NewMediaSampleCB new_media_sample_cb_;
104 NewTextSampleCB new_text_sample_cb_;
105
106 bool sbr_in_mimetype_;
107
108 // Bytes of the TS media.
109 ByteQueue ts_byte_queue_;
110
111 // Map of PIDs and their states. Use an ordered map so manifest generation
112 // has a deterministic order.
113 std::map<int, std::unique_ptr<PidState>> pids_;
114
115 // Map of PIDs and their metadata.
116 std::map<int, PesMetadata> pes_metadata_;
117
118 // Whether |init_cb_| has been invoked.
119 bool is_initialized_;
120
121 // A map used to track unsupported stream types and make sure the error is
122 // only logged once.
123 std::bitset<256> stream_type_logged_once_;
124
125 // PTS used to update text generation if needed
126 int64_t biggest_pts_ = 0;
127
128 DISALLOW_COPY_AND_ASSIGN(Mp2tMediaParser);
129};
130
131} // namespace mp2t
132} // namespace media
133} // namespace shaka
134
135#endif
KeySource is responsible for encryption key acquisition.
Definition key_source.h:53
std::function< bool(uint32_t track_id, std::shared_ptr< MediaSample > media_sample)> NewMediaSampleCB
std::function< bool(uint32_t track_id, std::shared_ptr< TextSample > text_sample)> NewTextSampleCB
std::function< void(const std::vector< std::shared_ptr< StreamInfo > > &stream_info)> InitCB
void Init(const InitCB &init_cb, const NewMediaSampleCB &new_media_sample_cb, const NewTextSampleCB &new_text_sample_cb, KeySource *decryption_key_source) override
bool Parse(const uint8_t *buf, int size) override
All the methods that are virtual are virtual for mocking.