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_TS_PACKET_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_MP2T_TS_PACKET_H_
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-08-31 23:59:46 +00:00
|
|
|
#include "packager/macros.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 {
|
|
|
|
|
|
|
|
class BitReader;
|
|
|
|
|
|
|
|
namespace mp2t {
|
|
|
|
|
|
|
|
class TsPacket {
|
|
|
|
public:
|
|
|
|
static const int kPacketSize = 188;
|
|
|
|
|
|
|
|
// Return the number of bytes to discard
|
|
|
|
// to be synchronized on a TS syncword.
|
2014-09-30 21:52:21 +00:00
|
|
|
static int Sync(const uint8_t* buf, int size);
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// Parse a TS packet.
|
|
|
|
// Return a TsPacket only when parsing was successful.
|
|
|
|
// Return NULL otherwise.
|
2014-09-30 21:52:21 +00:00
|
|
|
static TsPacket* Parse(const uint8_t* buf, int size);
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
~TsPacket();
|
|
|
|
|
|
|
|
// TS header accessors.
|
|
|
|
bool payload_unit_start_indicator() const {
|
|
|
|
return payload_unit_start_indicator_;
|
|
|
|
}
|
|
|
|
int pid() const { return pid_; }
|
|
|
|
int continuity_counter() const { return continuity_counter_; }
|
|
|
|
bool discontinuity_indicator() const { return discontinuity_indicator_; }
|
|
|
|
bool random_access_indicator() const { return random_access_indicator_; }
|
|
|
|
|
|
|
|
// Return the offset and the size of the payload.
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint8_t* payload() const { return payload_; }
|
2014-04-01 01:34:59 +00:00
|
|
|
int payload_size() const { return payload_size_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
TsPacket();
|
|
|
|
|
|
|
|
// Parse an Mpeg2 TS header.
|
|
|
|
// The buffer size should be at least |kPacketSize|
|
2014-09-30 21:52:21 +00:00
|
|
|
bool ParseHeader(const uint8_t* buf);
|
2014-04-01 01:34:59 +00:00
|
|
|
bool ParseAdaptationField(BitReader* bit_reader,
|
|
|
|
int adaptation_field_length);
|
|
|
|
|
|
|
|
// Size of the payload.
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint8_t* payload_;
|
2014-04-01 01:34:59 +00:00
|
|
|
int payload_size_;
|
|
|
|
|
|
|
|
// TS header.
|
|
|
|
bool payload_unit_start_indicator_;
|
|
|
|
int pid_;
|
|
|
|
int continuity_counter_;
|
|
|
|
|
|
|
|
// Params from the adaptation field.
|
|
|
|
bool discontinuity_indicator_;
|
|
|
|
bool random_access_indicator_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TsPacket);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|