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