2014-04-01 01:34:59 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_MP2T_MP2T_MEDIA_PARSER_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_MP2T_MP2T_MEDIA_PARSER_H_
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2020-10-16 21:18:35 +00:00
|
|
|
#include <bitset>
|
2014-04-10 19:57:10 +00:00
|
|
|
#include <deque>
|
2014-04-01 01:34:59 +00:00
|
|
|
#include <map>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/byte_queue.h"
|
|
|
|
#include "packager/media/base/media_parser.h"
|
|
|
|
#include "packager/media/base/stream_info.h"
|
2021-01-25 20:16:32 +00:00
|
|
|
#include "packager/media/formats/mp2t/ts_stream_type.h"
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-04-01 01:34:59 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-04-10 19:57:10 +00:00
|
|
|
class MediaSample;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
namespace mp2t {
|
|
|
|
|
|
|
|
class PidState;
|
2014-04-10 19:57:10 +00:00
|
|
|
class TsPacket;
|
|
|
|
class TsSection;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2014-04-16 23:22:31 +00:00
|
|
|
class Mp2tMediaParser : public MediaParser {
|
2014-04-01 01:34:59 +00:00
|
|
|
public:
|
2014-07-02 19:21:56 +00:00
|
|
|
Mp2tMediaParser();
|
2015-07-22 23:40:45 +00:00
|
|
|
~Mp2tMediaParser() override;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2016-01-21 18:30:29 +00:00
|
|
|
/// @name MediaParser implementation overrides.
|
|
|
|
/// @{
|
2015-07-22 23:40:45 +00:00
|
|
|
void Init(const InitCB& init_cb,
|
2020-07-01 22:43:44 +00:00
|
|
|
const NewMediaSampleCB& new_media_sample_cb,
|
|
|
|
const NewTextSampleCB& new_text_sample_cb,
|
2015-07-22 23:40:45 +00:00
|
|
|
KeySource* decryption_key_source) override;
|
2016-01-21 18:30:29 +00:00
|
|
|
bool Flush() override WARN_UNUSED_RESULT;
|
|
|
|
bool Parse(const uint8_t* buf, int size) override WARN_UNUSED_RESULT;
|
|
|
|
/// @}
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Callback invoked to register a Program Map Table.
|
|
|
|
// Note: Does nothing if the PID is already registered.
|
|
|
|
void RegisterPmt(int program_number, int pmt_pid);
|
|
|
|
|
|
|
|
// Callback invoked to register a PES pid.
|
2014-04-10 19:57:10 +00:00
|
|
|
// Possible values for |media_type| are defined in:
|
|
|
|
// ISO-13818.1 / ITU H.222 Table 2.34 "Media type assignments".
|
2014-04-01 01:34:59 +00:00
|
|
|
// |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
|
2021-01-25 20:16:32 +00:00
|
|
|
void RegisterPes(int pmt_pid, int pes_pid, TsStreamType media_type);
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// Callback invoked each time the audio/video decoder configuration is
|
|
|
|
// changed.
|
2020-10-06 23:07:51 +00:00
|
|
|
void OnNewStreamInfo(uint32_t pes_pid,
|
2020-10-16 21:18:35 +00:00
|
|
|
std::shared_ptr<StreamInfo> new_stream_info);
|
2014-04-10 19:57:10 +00:00
|
|
|
|
|
|
|
// Callback invoked by the ES media parser
|
|
|
|
// to emit a new audio/video access unit.
|
2020-10-16 21:18:35 +00:00
|
|
|
void OnEmitMediaSample(uint32_t pes_pid,
|
|
|
|
std::shared_ptr<MediaSample> new_sample);
|
|
|
|
void OnEmitTextSample(uint32_t pes_pid,
|
|
|
|
std::shared_ptr<TextSample> new_sample);
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// Invoke the initialization callback if needed.
|
|
|
|
bool FinishInitializationIfNeeded();
|
|
|
|
|
2014-04-10 19:57:10 +00:00
|
|
|
bool EmitRemainingSamples();
|
|
|
|
|
|
|
|
/// Set the value of the "SBR in mime-type" flag which leads to sample rate
|
|
|
|
/// doubling. Default value is false.
|
|
|
|
void set_sbr_in_mime_type(bool sbr_in_mimetype) {
|
2020-10-16 21:18:35 +00:00
|
|
|
sbr_in_mimetype_ = sbr_in_mimetype;
|
|
|
|
}
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// List of callbacks.
|
|
|
|
InitCB init_cb_;
|
2020-10-16 21:18:35 +00:00
|
|
|
NewMediaSampleCB new_media_sample_cb_;
|
|
|
|
NewTextSampleCB new_text_sample_cb_;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
bool sbr_in_mimetype_;
|
|
|
|
|
2014-04-10 19:57:10 +00:00
|
|
|
// Bytes of the TS media.
|
2014-04-01 01:34:59 +00:00
|
|
|
ByteQueue ts_byte_queue_;
|
|
|
|
|
2020-10-16 21:18:35 +00:00
|
|
|
// Map of PIDs and their states. Use an ordered map so manifest generation
|
|
|
|
// has a deterministic order.
|
|
|
|
std::map<int, std::unique_ptr<PidState>> pids_;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// Whether |init_cb_| has been invoked.
|
|
|
|
bool is_initialized_;
|
|
|
|
|
2017-12-01 22:53:20 +00:00
|
|
|
// A map used to track unsupported stream types and make sure the error is
|
|
|
|
// only logged once.
|
2020-10-16 21:18:35 +00:00
|
|
|
std::bitset<256> stream_type_logged_once_;
|
2017-12-01 22:53:20 +00:00
|
|
|
|
2014-04-16 23:22:31 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Mp2tMediaParser);
|
2014-04-01 01:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
#endif
|