MCPcopy Create free account
hub / github.com/apache/brpc / Encode

Method Encode

src/brpc/ts.cpp:308–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308int TsPacket::Encode(void* data) const {
309 char* p = (char*)data;
310
311 policy::Write1Byte(&p, TS_SYNC_BYTE);
312
313 int16_t pidv = _pid & 0x1FFF;
314 pidv |= (_transport_priority << 13) & 0x2000;
315 pidv |= (_transport_error_indicator << 15) & 0x8000;
316 pidv |= (_payload_unit_start_indicator << 14) & 0x4000;
317 policy::WriteBigEndian2Bytes(&p, pidv);
318
319 int8_t ccv = _continuity_counter & 0x0F;
320 ccv |= (_transport_scrambling_control << 6) & 0xC0;
321 TsAdaptationFieldType af_control = _adaptation_field_control;
322 if (af_control == TS_AF_RESERVED) {
323 // In the case of a null packet, af_control shall be set to '01'.
324 af_control = TS_AF_PAYLOAD_ONLY;
325 }
326 ccv |= (af_control << 4) & 0x30;
327 policy::Write1Byte(&p, ccv);
328
329 if (_adaptation_field) {
330 if (_adaptation_field->Encode(p, af_control) != 0) {
331 LOG(ERROR) << "Fail to encode _adaptation_field";
332 return -1;
333 }
334 p += _adaptation_field->ByteSize();
335 }
336
337 if (_payload) {
338 if (_payload->Encode(p) != 0) {
339 LOG(ERROR) << "Fail to encode _payload";
340 return -1;
341 }
342 p += _payload->ByteSize();
343 }
344 return 0;
345}
346
347void TsPacket::AddPadding(size_t num_stuffings) {
348 const bool no_af_before = (_adaptation_field == NULL);

Callers 5

TEST_FFunction · 0.45
TEST_FFunction · 0.45
PsiEncodeMethod · 0.45
EncodePATPMTMethod · 0.45
EncodePESMethod · 0.45

Calls 11

Write1ByteFunction · 0.85
WriteBigEndian2BytesFunction · 0.85
WriteBigEndian3BytesFunction · 0.85
crc32_tsFunction · 0.85
WriteBigEndian4BytesFunction · 0.85
is_audioFunction · 0.85
is_videoFunction · 0.85
okMethod · 0.80
StatusEnum · 0.70
ByteSizeMethod · 0.45

Tested by 2

TEST_FFunction · 0.36
TEST_FFunction · 0.36