Lines Matching defs:pes
467 MpegTSPESFilter *pes;
472 pes = &filter->u.pes_filter;
473 pes->pes_cb = pes_cb;
474 pes->opaque = opaque;
491 PESContext *pes = filter->u.pes_filter.opaque;
492 av_buffer_unref(&pes->buffer);
735 static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
742 av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, codec is open\n");
747 st->priv_data = pes;
751 pes->st = st;
752 pes->stream_type = stream_type;
754 av_log(pes->stream, AV_LOG_DEBUG,
756 st->index, pes->stream_type, pes->pid, (char *)&prog_reg_desc);
758 st->codec->codec_tag = pes->stream_type;
760 mpegts_find_stream_type(st, pes->stream_type, ISO_types);
764 mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
765 if (pes->stream_type == 0x83) {
773 memcpy(sub_pes, pes, sizeof(*sub_pes));
775 sub_st = avformat_new_stream(pes->stream, NULL);
781 sub_st->id = pes->pid;
787 sub_pes->sub_st = pes->sub_st = sub_st;
791 mpegts_find_stream_type(st, pes->stream_type, MISC_types);
800 static void reset_pes_packet_state(PESContext *pes)
802 pes->pts = AV_NOPTS_VALUE;
803 pes->dts = AV_NOPTS_VALUE;
804 pes->data_index = 0;
805 pes->flags = 0;
806 av_buffer_unref(&pes->buffer);
809 static void new_pes_packet(PESContext *pes, AVPacket *pkt)
813 pkt->buf = pes->buffer;
814 pkt->data = pes->buffer->data;
815 pkt->size = pes->data_index;
817 if (pes->total_size != MAX_PES_PAYLOAD &&
818 pes->pes_header_size + pes->data_index != pes->total_size +
820 av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n");
821 pes->flags |= AV_PKT_FLAG_CORRUPT;
826 if (pes->sub_st && pes->stream_type == 0x83 && pes->extended_stream_id == 0x76)
827 pkt->stream_index = pes->sub_st->index;
829 pkt->stream_index = pes->st->index;
830 pkt->pts = pes->pts;
831 pkt->dts = pes->dts;
833 pkt->pos = pes->ts_packet_pos;
834 pkt->flags = pes->flags;
836 pes->buffer = NULL;
837 reset_pes_packet_state(pes);
847 static int read_sl_header(PESContext *pes, SLConfigDescr *sl,
904 pes->dts = dts;
906 pes->pts = cts;
909 avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);
919 PESContext *pes = filter->u.pes_filter.opaque;
920 MpegTSContext *ts = pes->ts;
928 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
929 new_pes_packet(pes, ts->pkt);
932 reset_pes_packet_state(pes);
934 pes->state = MPEGTS_HEADER;
935 pes->ts_packet_pos = pos;
939 switch (pes->state) {
941 len = PES_START_SIZE - pes->data_index;
944 memcpy(pes->header + pes->data_index, p, len);
945 pes->data_index += len;
948 if (pes->data_index == PES_START_SIZE) {
951 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
952 pes->header[2] == 0x01) {
954 code = pes->header[3] | 0x100;
955 av_dlog(pes->stream, "pid=%x pes_code=%#x\n", pes->pid,
958 if ((pes->st && pes->st->discard == AVDISCARD_ALL &&
959 (!pes->sub_st ||
960 pes->sub_st->discard == AVDISCARD_ALL)) ||
965 if (!pes->st) {
969 pes->st = avformat_new_stream(ts->stream, NULL);
970 if (!pes->st)
972 pes->st->id = pes->pid;
973 mpegts_set_stream_info(pes->st, pes, 0, 0);
976 pes->total_size = AV_RB16(pes->header + 4);
979 if (!pes->total_size)
980 pes->total_size = MAX_PES_PAYLOAD;
982 /* allocate pes buffer */
983 pes->buffer = av_buffer_alloc(pes->total_size +
985 if (!pes->buffer)
992 pes->state = MPEGTS_PESHEADER;
993 if (pes->st->codec->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) {
994 av_dlog(pes->stream,
996 pes->pid,
997 pes->stream_type);
998 pes->st->request_probe = 1;
1001 pes->state = MPEGTS_PAYLOAD;
1002 pes->data_index = 0;
1008 pes->state = MPEGTS_SKIP;
1016 len = PES_HEADER_SIZE - pes->data_index;
1021 memcpy(pes->header + pes->data_index, p, len);
1022 pes->data_index += len;
1025 if (pes->data_index == PES_HEADER_SIZE) {
1026 pes->pes_header_size = pes->header[8] + 9;
1027 pes->state = MPEGTS_PESHEADER_FILL;
1031 len = pes->pes_header_size - pes->data_index;
1036 memcpy(pes->header + pes->data_index, p, len);
1037 pes->data_index += len;
1040 if (pes->data_index == pes->pes_header_size) {
1044 flags = pes->header[7];
1045 r = pes->header + 9;
1046 pes->pts = AV_NOPTS_VALUE;
1047 pes->dts = AV_NOPTS_VALUE;
1049 pes->dts = pes->pts = ff_parse_pes_pts(r);
1052 pes->pts = ff_parse_pes_pts(r);
1054 pes->dts = ff_parse_pes_pts(r);
1057 pes->extended_stream_id = -1;
1065 (r + 2) <= (pes->header + pes->pes_header_size)) {
1068 pes->extended_stream_id = r[1];
1073 pes->state = MPEGTS_PAYLOAD;
1074 pes->data_index = 0;
1075 if (pes->stream_type == 0x12 && buf_size > 0) {
1076 int sl_header_bytes = read_sl_header(pes, &pes->sl, p,
1078 pes->pes_header_size += sl_header_bytes;
1082 if (pes->stream_type == 0x15 && buf_size >= 5) {
1084 pes->pes_header_size += 5;
1088 if (pes->ts->fix_teletext_pts && pes->st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) {
1090 while ((p = av_find_program_from_stream(pes->stream, p, pes->st->index))) {
1092 MpegTSFilter *f = pes->ts->pids[p->pcr_pid];
1102 AVStream *pst = pes->stream->streams[p->stream_index[i]];
1113 pes->st->pts_wrap_reference = st->pts_wrap_reference;
1114 pes->st->pts_wrap_behavior = st->pts_wrap_behavior;
1115 if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) {
1116 pes->pts = pes->dts = pcr;
1117 } else if (pes->dts > pcr + 3654 + 9000) {
1118 pes->pts = pes->dts = pcr + 3654 + 9000;
1129 if (pes->buffer) {
1130 if (pes->data_index > 0 &&
1131 pes->data_index + buf_size > pes->total_size) {
1132 new_pes_packet(pes, ts->pkt);
1133 pes->total_size = MAX_PES_PAYLOAD;
1134 pes->buffer = av_buffer_alloc(pes->total_size +
1136 if (!pes->buffer)
1139 } else if (pes->data_index == 0 &&
1140 buf_size > pes->total_size) {
1141 // pes packet size is < ts size packet and pes data is padded with 0xff
1143 buf_size = pes->total_size;
1145 memcpy(pes->buffer->data + pes->data_index, p, buf_size);
1146 pes->data_index += buf_size;
1151 * in the pes header, i.e. not counting the first PES_START_SIZE bytes */
1152 if (!ts->stop_parse && pes->total_size < MAX_PES_PAYLOAD &&
1153 pes->pes_header_size + pes->data_index == pes->total_size + PES_START_SIZE) {
1155 new_pes_packet(pes, ts->pkt);
1172 PESContext *pes;
1175 pes = av_mallocz(sizeof(PESContext));
1176 if (!pes)
1178 pes->ts = ts;
1179 pes->stream = ts->stream;
1180 pes->pid = pid;
1181 pes->pcr_pid = pcr_pid;
1182 pes->state = MPEGTS_SKIP;
1183 pes->pts = AV_NOPTS_VALUE;
1184 pes->dts = AV_NOPTS_VALUE;
1185 tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes);
1187 av_free(pes);
1190 return pes;
1452 PESContext *pes;
1460 pes = ts->pids[pid]->u.pes_filter.opaque;
1461 st = pes->st;
1465 pes->sl = mp4_descr[i].sl;
1714 PESContext *pes;
1791 pes = NULL;
1804 pes = ts->pids[pid]->u.pes_filter.opaque;
1805 if (!pes->st) {
1806 pes->st = avformat_new_stream(pes->stream, NULL);
1807 if (!pes->st)
1809 pes->st->id = pes->pid;
1811 st = pes->st;
1815 pes = add_pes_stream(ts, pid, pcr_pid);
1816 if (pes) {
1817 st = avformat_new_stream(pes->stream, NULL);
1820 st->id = pes->pid;
1838 if (pes && !pes->stream_type)
1839 mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc);
1858 if (pes && prog_reg_desc == AV_RL32("HDMV") &&
1859 stream_type == 0x83 && pes->sub_st) {
1861 pes->sub_st->index);
1862 pes->sub_st->codec->codec_tag = st->codec->codec_tag;
2258 /* seek detected, flush pes buffer */
2262 PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
2263 av_buffer_unref(&pes->buffer);
2264 pes->data_index = 0;
2265 pes->state = MPEGTS_SKIP; /* skip until pes header */
2524 /* flush pes data left */
2527 PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
2528 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
2529 new_pes_packet(pes, pkt);
2530 pes->state = MPEGTS_SKIP;