MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / mpegts_push_data

Function mpegts_push_data

libavformat/mpegts.c:641–828  ·  view source on GitHub ↗

return non zero if a packet could be constructed */

Source from the content-addressed store, hash-verified

639
640/* return non zero if a packet could be constructed */
641static int mpegts_push_data(MpegTSFilter *filter,
642 const uint8_t *buf, int buf_size, int is_start,
643 int64_t pos)
644{
645 PESContext *pes = filter->u.pes_filter.opaque;
646 MpegTSContext *ts = pes->ts;
647 const uint8_t *p;
648 int len, code;
649
650 if(!ts->pkt)
651 return 0;
652
653 if (is_start) {
654 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
655 new_pes_packet(pes, ts->pkt);
656 ts->stop_parse = 1;
657 }
658 pes->state = MPEGTS_HEADER;
659 pes->data_index = 0;
660 pes->ts_packet_pos = pos;
661 }
662 p = buf;
663 while (buf_size > 0) {
664 switch(pes->state) {
665 case MPEGTS_HEADER:
666 len = PES_START_SIZE - pes->data_index;
667 if (len > buf_size)
668 len = buf_size;
669 memcpy(pes->header + pes->data_index, p, len);
670 pes->data_index += len;
671 p += len;
672 buf_size -= len;
673 if (pes->data_index == PES_START_SIZE) {
674 /* we got all the PES or section header. We can now
675 decide */
676#if 0
677 av_hex_dump_log(pes->stream, AV_LOG_DEBUG, pes->header, pes->data_index);
678#endif
679 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
680 pes->header[2] == 0x01) {
681 /* it must be an mpeg2 PES stream */
682 code = pes->header[3] | 0x100;
683 dprintf(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, code);
684
685 if ((!pes->st && pes->stream->nb_streams == MAX_STREAMS) ||
686 (pes->st && pes->st->discard == AVDISCARD_ALL) ||
687 code == 0x1be) /* padding_stream */
688 goto skip;
689
690 /* stream not present in PMT */
691 if (!pes->st) {
692 pes->st = av_new_stream(ts->stream, pes->pid);
693 if (!pes->st)
694 return AVERROR(ENOMEM);
695 mpegts_set_stream_info(pes->st, pes, 0, 0);
696 }
697
698 pes->total_size = AV_RB16(pes->header + 4);

Callers

nothing calls this directly

Calls 7

new_pes_packetFunction · 0.85
av_hex_dump_logFunction · 0.85
av_new_streamFunction · 0.85
mpegts_set_stream_infoFunction · 0.85
av_mallocFunction · 0.85
get_ptsFunction · 0.70
AV_RB16Function · 0.50

Tested by

no test coverage detected