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
15#include <packager/macros/classes.h>
16#include <packager/media/base/byte_queue.h>
17#include <packager/media/base/media_parser.h>
18#include <packager/media/base/stream_info.h>
19#include <packager/media/formats/mp2t/ts_audio_type.h>
20#include <packager/media/formats/mp2t/ts_stream_type.h>
21
22namespace shaka {
23namespace media {
24
25class MediaSample;
26
27namespace mp2t {
28
29class PidState;
30class TsPacket;
31class TsSection;
32
34 uint32_t max_bitrate;
35 std::string language;
36 TsAudioType audio_type;
37};
38
40 public:
42 ~Mp2tMediaParser() override;
43
46 void Init(const InitCB& init_cb,
47 const NewMediaSampleCB& new_media_sample_cb,
48 const NewTextSampleCB& new_text_sample_cb,
49 KeySource* decryption_key_source) override;
50 [[nodiscard]] bool Flush() override;
51 [[nodiscard]] bool Parse(const uint8_t* buf, int size) override;
53
54 private:
55 // Callback invoked to register a Program Map Table.
56 // Note: Does nothing if the PID is already registered.
57 void RegisterPmt(int program_number, int pmt_pid);
58
59 // Callback invoked to register a PES pid.
60 // Possible values for |media_type| are defined in:
61 // ISO-13818.1 / ITU H.222 Table 2.34 "Media type assignments".
62 // Possible values for |audio_type| are defined in:
63 // ISO-13818.1 / ITU H.222 Table 2-60 "Audio type values".
64 // |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
65 void RegisterPes(int pmt_pid,
66 int pes_pid,
67 TsStreamType media_type,
68 uint32_t max_bitrate,
69 const std::string& lang,
70 TsAudioType audio_type,
71 const uint8_t* descriptor,
72 size_t descriptor_length);
73
74 // Callback invoked each time the audio/video decoder configuration is
75 // changed.
76 void OnNewStreamInfo(uint32_t pes_pid,
77 std::shared_ptr<StreamInfo> new_stream_info);
78
79 // Callback invoked by the ES media parser
80 // to emit a new audio/video access unit.
81 void OnEmitMediaSample(uint32_t pes_pid,
82 std::shared_ptr<MediaSample> new_sample);
83 void OnEmitTextSample(uint32_t pes_pid,
84 std::shared_ptr<TextSample> new_sample);
85
86 // Invoke the initialization callback if needed.
87 bool FinishInitializationIfNeeded();
88
89 bool EmitRemainingSamples();
90
93 void set_sbr_in_mime_type(bool sbr_in_mimetype) {
94 sbr_in_mimetype_ = sbr_in_mimetype;
95 }
96
97 // List of callbacks.
98 InitCB init_cb_;
99 NewMediaSampleCB new_media_sample_cb_;
100 NewTextSampleCB new_text_sample_cb_;
101
102 bool sbr_in_mimetype_;
103
104 // Bytes of the TS media.
105 ByteQueue ts_byte_queue_;
106
107 // Map of PIDs and their states. Use an ordered map so manifest generation
108 // has a deterministic order.
109 std::map<int, std::unique_ptr<PidState>> pids_;
110
111 // Map of PIDs and their metadata.
112 std::map<int, PesMetadata> pes_metadata_;
113
114 // Whether |init_cb_| has been invoked.
115 bool is_initialized_;
116
117 // A map used to track unsupported stream types and make sure the error is
118 // only logged once.
119 std::bitset<256> stream_type_logged_once_;
120
121 DISALLOW_COPY_AND_ASSIGN(Mp2tMediaParser);
122};
123
124} // namespace mp2t
125} // namespace media
126} // namespace shaka
127
128#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.