Lines Matching refs:pes
1135 MpegTSPESFilter *pes;
1140 pes = &filter->u.pes_filter;
1141 pes->pes_cb = pes_cb;
1142 pes->opaque = opaque;
1159 PESContext *pes = filter->u.pes_filter.opaque;
1160 av_buffer_unref(&pes->buffer);
1162 * avformat_close_input (pes->st->priv_data == pes) */
1163 if (!pes->st || pes->merged_st) {
1504 static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
1513 av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, internal codec is open\n");
1518 st->priv_data = pes;
1522 pes->st = st;
1523 pes->stream_type = stream_type;
1525 av_log(pes->stream, AV_LOG_DEBUG,
1527 st->index, pes->stream_type, pes->pid, (char *)&prog_reg_desc);
1529 st->codecpar->codec_tag = pes->stream_type;
1531 mpegts_find_stream_type(st, pes->stream_type, ISO_types);
1532 if (pes->stream_type == 4 || pes->stream_type == 0x0f)
1537 mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
1538 if (pes->stream_type == 0x83) {
1543 PESContext *sub_pes = av_memdup(pes, sizeof(*sub_pes));
1547 sub_st = avformat_new_stream(pes->stream, NULL);
1553 sub_st->id = pes->pid;
1559 sub_pes->sub_st = pes->sub_st = sub_st;
1563 mpegts_find_stream_type(st, pes->stream_type, MISC_types);
1565 mpegts_find_stream_type(st, pes->stream_type, HLS_SAMPLE_ENC_types);
1588 static void reset_pes_packet_state(PESContext *pes)
1590 pes->pts = AV_NOPTS_VALUE;
1591 pes->dts = AV_NOPTS_VALUE;
1592 pes->data_index = 0;
1593 pes->flags = 0;
1594 av_buffer_unref(&pes->buffer);
1604 static int new_pes_packet(PESContext *pes, AVPacket *pkt)
1610 pkt->buf = pes->buffer;
1611 pkt->data = pes->buffer->data;
1612 pkt->size = pes->data_index;
1614 if (pes->PES_packet_length &&
1615 pes->pes_header_size + pes->data_index != pes->PES_packet_length +
1617 av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n");
1618 pes->flags |= AV_PKT_FLAG_CORRUPT;
1623 if (pes->sub_st && pes->stream_type == 0x83 && pes->extended_stream_id == 0x76)
1624 pkt->stream_index = pes->sub_st->index;
1626 pkt->stream_index = pes->st->index;
1627 pkt->pts = pes->pts;
1628 pkt->dts = pes->dts;
1630 pkt->pos = pes->ts_packet_pos;
1631 pkt->flags = pes->flags;
1633 pes->buffer = NULL;
1634 reset_pes_packet_state(pes);
1639 *sd = pes->stream_id;
1651 static int read_sl_header(PESContext *pes, SLConfigDescr *sl,
1712 pes->dts = dts;
1714 pes->pts = cts;
1717 avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);
1739 PESContext *pes = filter->u.pes_filter.opaque;
1740 MpegTSContext *ts = pes->ts;
1748 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
1749 ret = new_pes_packet(pes, ts->pkt);
1754 reset_pes_packet_state(pes);
1756 pes->state = MPEGTS_HEADER;
1757 pes->ts_packet_pos = pos;
1761 switch (pes->state) {
1763 len = PES_START_SIZE - pes->data_index;
1766 memcpy(pes->header + pes->data_index, p, len);
1767 pes->data_index += len;
1770 if (pes->data_index == PES_START_SIZE) {
1773 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
1774 pes->header[2] == 0x01) {
1776 pes->stream_id = pes->header[3];
1777 av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_id=%#x\n", pes->pid, pes->stream_id);
1779 if ((pes->st && pes->st->discard == AVDISCARD_ALL &&
1780 (!pes->sub_st ||
1781 pes->sub_st->discard == AVDISCARD_ALL)) ||
1782 pes->stream_id == STREAM_ID_PADDING_STREAM)
1786 if (!pes->st) {
1792 pes->st = avformat_new_stream(ts->stream, NULL);
1793 if (!pes->st)
1795 pes->st->id = pes->pid;
1796 mpegts_set_stream_info(pes->st, pes, 0, 0);
1799 pes->PES_packet_length = AV_RB16(pes->header + 4);
1802 if (pes->stream_id != STREAM_ID_PROGRAM_STREAM_MAP &&
1803 pes->stream_id != STREAM_ID_PRIVATE_STREAM_2 &&
1804 pes->stream_id != STREAM_ID_ECM_STREAM &&
1805 pes->stream_id != STREAM_ID_EMM_STREAM &&
1806 pes->stream_id != STREAM_ID_PROGRAM_STREAM_DIRECTORY &&
1807 pes->stream_id != STREAM_ID_DSMCC_STREAM &&
1808 pes->stream_id != STREAM_ID_TYPE_E_STREAM) {
1809 FFStream *const pes_sti = ffstream(pes->st);
1810 pes->state = MPEGTS_PESHEADER;
1811 if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes_sti->request_probe) {
1812 av_log(pes->stream, AV_LOG_TRACE,
1814 pes->pid,
1815 pes->stream_type);
1819 pes->pes_header_size = 6;
1820 pes->state = MPEGTS_PAYLOAD;
1821 pes->data_index = 0;
1827 pes->state = MPEGTS_SKIP;
1835 len = PES_HEADER_SIZE - pes->data_index;
1840 memcpy(pes->header + pes->data_index, p, len);
1841 pes->data_index += len;
1844 if (pes->data_index == PES_HEADER_SIZE) {
1845 pes->pes_header_size = pes->header[8] + 9;
1846 pes->state = MPEGTS_PESHEADER_FILL;
1850 len = pes->pes_header_size - pes->data_index;
1855 memcpy(pes->header + pes->data_index, p, len);
1856 pes->data_index += len;
1859 if (pes->data_index == pes->pes_header_size) {
1863 flags = pes->header[7];
1864 r = pes->header + 9;
1865 pes->pts = AV_NOPTS_VALUE;
1866 pes->dts = AV_NOPTS_VALUE;
1868 pes->dts = pes->pts = ff_parse_pes_pts(r);
1871 pes->pts = ff_parse_pes_pts(r);
1873 pes->dts = ff_parse_pes_pts(r);
1876 pes->extended_stream_id = -1;
1884 (r + 2) <= (pes->header + pes->pes_header_size)) {
1887 pes->extended_stream_id = r[1];
1892 pes->state = MPEGTS_PAYLOAD;
1893 pes->data_index = 0;
1894 if (pes->stream_type == 0x12 && buf_size > 0) {
1895 int sl_header_bytes = read_sl_header(pes, &pes->sl, p,
1897 pes->pes_header_size += sl_header_bytes;
1901 if (pes->stream_type == 0x15 && buf_size >= 5) {
1903 pes->pes_header_size += 5;
1907 if ( pes->ts->fix_teletext_pts
1908 && ( pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT
1909 || pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE)
1913 while ((p = av_find_program_from_stream(pes->stream, p, pes->st->index))) {
1915 MpegTSFilter *f = pes->ts->pids[p->pcr_pid];
1925 AVStream *pst = pes->stream->streams[p->stream_index[i]];
1939 FFStream *const pes_sti = ffstream(pes->st);
1944 if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) {
1945 pes->pts = pes->dts = pcr;
1946 } else if (pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT &&
1947 pes->dts > pcr + 3654 + 9000) {
1948 pes->pts = pes->dts = pcr + 3654 + 9000;
1949 } else if (pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE &&
1950 pes->dts > pcr + 10*90000) { //10sec
1951 pes->pts = pes->dts = pcr + 3654 + 9000;
1959 if (pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT &&
1961 av_log(pes->stream, AV_LOG_VERBOSE,
1965 pes->pid);
1966 pes->dts = pes->pts = AV_NOPTS_VALUE;
1974 if (pes->PES_packet_length && pes->PES_packet_length + PES_START_SIZE > pes->pes_header_size)
1975 max_packet_size = pes->PES_packet_length + PES_START_SIZE - pes->pes_header_size;
1977 if (pes->data_index > 0 &&
1978 pes->data_index + buf_size > max_packet_size) {
1979 ret = new_pes_packet(pes, ts->pkt);
1982 pes->PES_packet_length = 0;
1985 } else if (pes->data_index == 0 &&
1987 // pes packet size is < ts size packet and pes data is padded with 0xff
1992 if (!pes->buffer) {
1993 pes->buffer = buffer_pool_get(ts, max_packet_size);
1994 if (!pes->buffer)
1998 memcpy(pes->buffer->data + pes->data_index, p, buf_size);
1999 pes->data_index += buf_size;
2003 if (!ts->stop_parse && pes->PES_packet_length &&
2004 pes->pes_header_size + pes->data_index == pes->PES_packet_length + PES_START_SIZE) {
2006 ret = new_pes_packet(pes, ts->pkt);
2007 pes->state = MPEGTS_SKIP;
2026 PESContext *pes;
2029 pes = av_mallocz(sizeof(PESContext));
2030 if (!pes)
2032 pes->ts = ts;
2033 pes->stream = ts->stream;
2034 pes->pid = pid;
2035 pes->pcr_pid = pcr_pid;
2036 pes->state = MPEGTS_SKIP;
2037 pes->pts = AV_NOPTS_VALUE;
2038 pes->dts = AV_NOPTS_VALUE;
2039 tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes);
2041 av_free(pes);
2044 return pes;
2320 PESContext *pes;
2330 pes = ts->pids[pid]->u.pes_filter.opaque;
2331 st = pes->st;
2336 pes->sl = mp4_descr[i].sl;
2927 PESContext *pes;
3045 pes = NULL;
3060 pes = ts->pids[pid]->u.pes_filter.opaque;
3061 if (ts->merge_pmt_versions && !pes->st) {
3064 pes->st = st;
3065 pes->stream_type = stream_type;
3066 pes->merged_st = 1;
3069 if (!pes->st) {
3070 pes->st = avformat_new_stream(pes->stream, NULL);
3071 if (!pes->st)
3073 pes->st->id = pes->pid;
3075 st = pes->st;
3079 pes = add_pes_stream(ts, pid, pcr_pid);
3080 if (ts->merge_pmt_versions && pes && !pes->st) {
3083 pes->st = st;
3084 pes->stream_type = stream_type;
3085 pes->merged_st = 1;
3088 if (pes && !pes->st) {
3089 st = avformat_new_stream(pes->stream, NULL);
3092 st->id = pes->pid;
3125 if (pes && !pes->stream_type)
3126 mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc);
3150 if (pes && prog_reg_desc == AV_RL32("HDMV") &&
3151 stream_type == 0x83 && pes->sub_st) {
3153 pes->sub_st->index);
3154 pes->sub_st->codecpar->codec_tag = st->codecpar->codec_tag;
3617 /* seek detected, flush pes buffer */
3621 PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
3622 av_buffer_unref(&pes->buffer);
3623 pes->data_index = 0;
3624 pes->state = MPEGTS_SKIP; /* skip until pes header */
3897 /* flush pes data left */
3900 PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
3901 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
3902 ret = new_pes_packet(pes, pkt);
3905 pes->state = MPEGTS_SKIP;