annotate mpegts.c @ 678:9b2cda2905cc libavformat

removing --disable-risky patch by (Josh Varner <jlvarner gmail com>)
author michael
date Mon, 21 Feb 2005 17:50:48 +0000
parents 29a19aec26b2
children af4e24d6310c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * MPEG2 transport stream (aka DVB) demux
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
3 * Copyright (c) 2002-2003 Fabrice Bellard.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
21 #include "mpegts.h"
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
22
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
23 //#define DEBUG_SI
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
24 //#define DEBUG_SEEK
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
26 /* 1.0 second at 24Mbit/s */
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
27 #define MAX_SCAN_PACKETS 32000
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
28
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
29 /* maximum size in which we look for synchronisation if
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
30 synchronisation is lost */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
31 #define MAX_RESYNC_SIZE 4096
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
32
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
33 static int add_pes_stream(MpegTSContext *ts, int pid, int stream_type);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
34
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
35 enum MpegTSFilterType {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
36 MPEGTS_PES,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
37 MPEGTS_SECTION,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
40 typedef void PESCallback(void *opaque, const uint8_t *buf, int len, int is_start);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
41
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
42 typedef struct MpegTSPESFilter {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
43 PESCallback *pes_cb;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
44 void *opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
45 } MpegTSPESFilter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
46
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
47 typedef void SectionCallback(void *opaque, const uint8_t *buf, int len);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
48
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
49 typedef void SetServiceCallback(void *opaque, int ret);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
51 typedef struct MpegTSSectionFilter {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
52 int section_index;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
53 int section_h_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
54 uint8_t *section_buf;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
55 int check_crc:1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
56 int end_of_section_reached:1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
57 SectionCallback *section_cb;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
58 void *opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
59 } MpegTSSectionFilter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
60
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
61 typedef struct MpegTSFilter {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 int pid;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 int last_cc; /* last cc code (-1 if first packet) */
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
64 enum MpegTSFilterType type;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
65 union {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
66 MpegTSPESFilter pes_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
67 MpegTSSectionFilter section_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
68 } u;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
69 } MpegTSFilter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
70
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
71 typedef struct MpegTSService {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
72 int running:1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
73 int sid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
74 char *provider_name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
75 char *name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
76 } MpegTSService;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
78 struct MpegTSContext {
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
79 /* user data */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
80 AVFormatContext *stream;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 int raw_packet_size; /* raw packet size, including FEC if present */
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
82 int auto_guess; /* if true, all pids are analized to find streams */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
83 int set_service_ret;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
84
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
85 int mpeg2ts_raw; /* force raw MPEG2 transport stream output, if possible */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
86 int mpeg2ts_compute_pcr; /* compute exact PCR for each transport stream packet */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
87
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
88 /* used to estimate the exact PCR */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
89 int64_t cur_pcr;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
90 int pcr_incr;
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
91 int pcr_pid;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
92
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
93 /* data needed to handle file based ts */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
94 int stop_parse; /* stop parsing loop */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
95 AVPacket *pkt; /* packet containing av data */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
96
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
97 /******************************************/
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
98 /* private mpegts data */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
99 /* scan context */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
100 MpegTSFilter *sdt_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
101 int nb_services;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
102 MpegTSService **services;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
103
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
104 /* set service context (XXX: allocated it ?) */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
105 SetServiceCallback *set_service_cb;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
106 void *set_service_opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
107 MpegTSFilter *pat_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
108 MpegTSFilter *pmt_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
109 int req_sid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
110
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
111 MpegTSFilter *pids[NB_PID_MAX];
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
112 };
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
114 static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
115 const uint8_t *buf, int buf_size, int is_start)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
116 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
117 MpegTSSectionFilter *tss = &tss1->u.section_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
118 int len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
119
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
120 if (is_start) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
121 memcpy(tss->section_buf, buf, buf_size);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
122 tss->section_index = buf_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
123 tss->section_h_size = -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
124 tss->end_of_section_reached = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
125 } else {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
126 if (tss->end_of_section_reached)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
127 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
128 len = 4096 - tss->section_index;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
129 if (buf_size < len)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
130 len = buf_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
131 memcpy(tss->section_buf + tss->section_index, buf, len);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
132 tss->section_index += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
133 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
134
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
135 /* compute section length if possible */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
136 if (tss->section_h_size == -1 && tss->section_index >= 3) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
137 len = (((tss->section_buf[1] & 0xf) << 8) | tss->section_buf[2]) + 3;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
138 if (len > 4096)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
139 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
140 tss->section_h_size = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
141 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
142
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
143 if (tss->section_h_size != -1 && tss->section_index >= tss->section_h_size) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
144 tss->end_of_section_reached = 1;
675
29a19aec26b2 Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents: 555
diff changeset
145 if (!tss->check_crc ||
29a19aec26b2 Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents: 555
diff changeset
146 mpegts_crc32(tss->section_buf, tss->section_h_size) == 0)
29a19aec26b2 Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents: 555
diff changeset
147 tss->section_cb(tss->opaque, tss->section_buf, tss->section_h_size);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
148 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
149 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
150
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
151 MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
152 SectionCallback *section_cb, void *opaque,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
153 int check_crc)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
154
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
155 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
156 MpegTSFilter *filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
157 MpegTSSectionFilter *sec;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
158
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
159 #ifdef DEBUG_SI
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
160 printf("Filter: pid=0x%x\n", pid);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
161 #endif
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
162 if (pid >= NB_PID_MAX || ts->pids[pid])
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
163 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
164 filter = av_mallocz(sizeof(MpegTSFilter));
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
165 if (!filter)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
166 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
167 ts->pids[pid] = filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
168 filter->type = MPEGTS_SECTION;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
169 filter->pid = pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
170 filter->last_cc = -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
171 sec = &filter->u.section_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
172 sec->section_cb = section_cb;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
173 sec->opaque = opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
174 sec->section_buf = av_malloc(MAX_SECTION_SIZE);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
175 sec->check_crc = check_crc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
176 if (!sec->section_buf) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
177 av_free(filter);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
178 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
179 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
180 return filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
181 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
182
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
183 MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
184 PESCallback *pes_cb,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
185 void *opaque)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
186 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
187 MpegTSFilter *filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
188 MpegTSPESFilter *pes;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
189
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
190 if (pid >= NB_PID_MAX || ts->pids[pid])
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
191 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
192 filter = av_mallocz(sizeof(MpegTSFilter));
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
193 if (!filter)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
194 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
195 ts->pids[pid] = filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
196 filter->type = MPEGTS_PES;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
197 filter->pid = pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
198 filter->last_cc = -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
199 pes = &filter->u.pes_filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
200 pes->pes_cb = pes_cb;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
201 pes->opaque = opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
202 return filter;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
203 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
204
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
205 void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
206 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
207 int pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
208
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
209 pid = filter->pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
210 if (filter->type == MPEGTS_SECTION)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
211 av_freep(&filter->u.section_filter.section_buf);
342
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 329
diff changeset
212 else if (filter->type == MPEGTS_PES)
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 329
diff changeset
213 av_freep(&filter->u.pes_filter.opaque);
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 329
diff changeset
214
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
215 av_free(filter);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
216 ts->pids[pid] = NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
217 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
218
329
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
219 static int analyze(const uint8_t *buf, int size, int packet_size, int *index){
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
220 int stat[packet_size];
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
221 int i;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
222 int x=0;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
223 int best_score=0;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
224
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
225 memset(stat, 0, packet_size*sizeof(int));
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
226
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
227 for(x=i=0; i<size; i++){
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
228 if(buf[i] == 0x47){
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
229 stat[x]++;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
230 if(stat[x] > best_score){
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
231 best_score= stat[x];
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
232 if(index) *index= x;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
233 }
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
234 }
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
235
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
236 x++;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
237 if(x == packet_size) x= 0;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
238 }
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
239
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
240 return best_score;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
241 }
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
242
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 /* autodetect fec presence. Must have at least 1024 bytes */
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
244 static int get_packet_size(const uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 {
329
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
246 int score, fec_score;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 return -1;
329
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
250
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
251 score = analyze(buf, size, TS_PACKET_SIZE, NULL);
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
252 fec_score= analyze(buf, size, TS_FEC_PACKET_SIZE, NULL);
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
253 // av_log(NULL, AV_LOG_DEBUG, "score: %d, fec_score: %d \n", score, fec_score);
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
254
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
255 if (score > fec_score) return TS_PACKET_SIZE;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
256 else if(score < fec_score) return TS_FEC_PACKET_SIZE;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
257 else return -1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
260 typedef struct SectionHeader {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
261 uint8_t tid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
262 uint16_t id;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
263 uint8_t version;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
264 uint8_t sec_num;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
265 uint8_t last_sec_num;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
266 } SectionHeader;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
267
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
268 static inline int get8(const uint8_t **pp, const uint8_t *p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
269 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
270 const uint8_t *p;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
271 int c;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
272
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
273 p = *pp;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
274 if (p >= p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
275 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
276 c = *p++;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
277 *pp = p;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
278 return c;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
279 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
280
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
281 static inline int get16(const uint8_t **pp, const uint8_t *p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
282 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
283 const uint8_t *p;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
284 int c;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
285
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
286 p = *pp;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
287 if ((p + 1) >= p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
288 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
289 c = (p[0] << 8) | p[1];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
290 p += 2;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
291 *pp = p;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
292 return c;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
293 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
294
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
295 /* read and allocate a DVB string preceeded by its length */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
296 static char *getstr8(const uint8_t **pp, const uint8_t *p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
297 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
298 int len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
299 const uint8_t *p;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
300 char *str;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
301
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
302 p = *pp;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
303 len = get8(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
304 if (len < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
305 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
306 if ((p + len) > p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
307 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
308 str = av_malloc(len + 1);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
309 if (!str)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
310 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
311 memcpy(str, p, len);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
312 str[len] = '\0';
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
313 p += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
314 *pp = p;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
315 return str;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
316 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
317
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
318 static int parse_section_header(SectionHeader *h,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
319 const uint8_t **pp, const uint8_t *p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
320 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
321 int val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
322
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
323 val = get8(pp, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
324 if (val < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
325 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
326 h->tid = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
327 *pp += 2;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
328 val = get16(pp, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
329 if (val < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
330 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
331 h->id = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
332 val = get8(pp, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
333 if (val < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
334 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
335 h->version = (val >> 1) & 0x1f;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
336 val = get8(pp, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
337 if (val < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
338 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
339 h->sec_num = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
340 val = get8(pp, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
341 if (val < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
342 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
343 h->last_sec_num = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
344 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
345 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
346
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
347 static MpegTSService *new_service(MpegTSContext *ts, int sid,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
348 char *provider_name, char *name)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
349 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
350 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
351
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
352 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
353 printf("new_service: sid=0x%04x provider='%s' name='%s'\n",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
354 sid, provider_name, name);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
355 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
356
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
357 service = av_mallocz(sizeof(MpegTSService));
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
358 if (!service)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
359 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
360 service->sid = sid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
361 service->provider_name = provider_name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
362 service->name = name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
363 dynarray_add(&ts->services, &ts->nb_services, service);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
364 return service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
365 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
366
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
367 static void pmt_cb(void *opaque, const uint8_t *section, int section_len)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
368 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
369 MpegTSContext *ts = opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
370 SectionHeader h1, *h = &h1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
371 const uint8_t *p, *p_end;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
372 int program_info_length, pcr_pid, pid, stream_type, desc_length;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
373
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
374 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
375 printf("PMT:\n");
398
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
376 av_hex_dump(stdout, (uint8_t *)section, section_len);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
377 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
378 p_end = section + section_len - 4;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
379 p = section;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
380 if (parse_section_header(h, &p, p_end) < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
381 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
382 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
383 printf("sid=0x%x sec_num=%d/%d\n", h->id, h->sec_num, h->last_sec_num);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
384 #endif
160
9bde37b1a5ce try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents: 152
diff changeset
385 if (h->tid != PMT_TID || (ts->req_sid >= 0 && h->id != ts->req_sid) )
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
386 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
387
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
388 pcr_pid = get16(&p, p_end) & 0x1fff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
389 if (pcr_pid < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
390 return;
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
391 ts->pcr_pid = pcr_pid;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
392 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
393 printf("pcr_pid=0x%x\n", pcr_pid);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
394 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
395 program_info_length = get16(&p, p_end) & 0xfff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
396 if (program_info_length < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
397 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
398 p += program_info_length;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
399 if (p >= p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
400 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
401 for(;;) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
402 stream_type = get8(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
403 if (stream_type < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
404 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
405 pid = get16(&p, p_end) & 0x1fff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
406 if (pid < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
407 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
408 desc_length = get16(&p, p_end) & 0xfff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
409 if (desc_length < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
410 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
411 p += desc_length;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
412 if (p > p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
413 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
414
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
415 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
416 printf("stream_type=%d pid=0x%x\n", stream_type, pid);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
417 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
418
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
419 /* now create ffmpeg stream */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
420 switch(stream_type) {
160
9bde37b1a5ce try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents: 152
diff changeset
421 case STREAM_TYPE_AUDIO_MPEG1:
9bde37b1a5ce try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents: 152
diff changeset
422 case STREAM_TYPE_AUDIO_MPEG2:
9bde37b1a5ce try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents: 152
diff changeset
423 case STREAM_TYPE_VIDEO_MPEG1:
9bde37b1a5ce try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents: 152
diff changeset
424 case STREAM_TYPE_VIDEO_MPEG2:
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
425 case STREAM_TYPE_VIDEO_MPEG4:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
426 case STREAM_TYPE_VIDEO_H264:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
427 case STREAM_TYPE_AUDIO_AAC:
165
e4d2f704bf80 - Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
michaelni
parents: 160
diff changeset
428 case STREAM_TYPE_AUDIO_AC3:
496
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 474
diff changeset
429 case STREAM_TYPE_AUDIO_DTS:
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
430 add_pes_stream(ts, pid, stream_type);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
431 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
432 default:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
433 /* we ignore the other streams */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
434 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
435 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
436 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
437 /* all parameters are there */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
438 ts->set_service_cb(ts->set_service_opaque, 0);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
439 mpegts_close_filter(ts, ts->pmt_filter);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
440 ts->pmt_filter = NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
441 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
442
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
443 static void pat_cb(void *opaque, const uint8_t *section, int section_len)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
444 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
445 MpegTSContext *ts = opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
446 SectionHeader h1, *h = &h1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
447 const uint8_t *p, *p_end;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
448 int sid, pmt_pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
449
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
450 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
451 printf("PAT:\n");
398
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
452 av_hex_dump(stdout, (uint8_t *)section, section_len);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
453 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
454 p_end = section + section_len - 4;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
455 p = section;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
456 if (parse_section_header(h, &p, p_end) < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
457 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
458 if (h->tid != PAT_TID)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
459 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
460
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
461 for(;;) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
462 sid = get16(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
463 if (sid < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
464 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
465 pmt_pid = get16(&p, p_end) & 0x1fff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
466 if (pmt_pid < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
467 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
468 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
469 printf("sid=0x%x pid=0x%x\n", sid, pmt_pid);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
470 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
471 if (sid == 0x0000) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
472 /* NIT info */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
473 } else {
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
474 if (ts->req_sid == sid) {
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
475 ts->pmt_filter = mpegts_open_section_filter(ts, pmt_pid,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
476 pmt_cb, ts, 1);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
477 goto found;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
478 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
479 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
480 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
481 /* not found */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
482 ts->set_service_cb(ts->set_service_opaque, -1);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
483
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
484 found:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
485 mpegts_close_filter(ts, ts->pat_filter);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
486 ts->pat_filter = NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
487 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
488
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
489 /* add all services found in the PAT */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
490 static void pat_scan_cb(void *opaque, const uint8_t *section, int section_len)
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
491 {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
492 MpegTSContext *ts = opaque;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
493 SectionHeader h1, *h = &h1;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
494 const uint8_t *p, *p_end;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
495 int sid, pmt_pid;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
496 char *provider_name, *name;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
497 char buf[256];
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
498
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
499 #ifdef DEBUG_SI
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
500 printf("PAT:\n");
398
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
501 av_hex_dump(stdout, (uint8_t *)section, section_len);
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
502 #endif
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
503 p_end = section + section_len - 4;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
504 p = section;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
505 if (parse_section_header(h, &p, p_end) < 0)
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
506 return;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
507 if (h->tid != PAT_TID)
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
508 return;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
509
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
510 for(;;) {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
511 sid = get16(&p, p_end);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
512 if (sid < 0)
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
513 break;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
514 pmt_pid = get16(&p, p_end) & 0x1fff;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
515 if (pmt_pid < 0)
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
516 break;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
517 #ifdef DEBUG_SI
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
518 printf("sid=0x%x pid=0x%x\n", sid, pmt_pid);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
519 #endif
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
520 if (sid == 0x0000) {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
521 /* NIT info */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
522 } else {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
523 /* add the service with a dummy name */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
524 snprintf(buf, sizeof(buf), "Service %x\n", sid);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
525 name = av_strdup(buf);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
526 provider_name = av_strdup("");
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
527 if (name && provider_name) {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
528 new_service(ts, sid, provider_name, name);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
529 } else {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
530 av_freep(&name);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
531 av_freep(&provider_name);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
532 }
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
533 }
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
534 }
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
535 ts->stop_parse = 1;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
536
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
537 /* remove filter */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
538 mpegts_close_filter(ts, ts->pat_filter);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
539 ts->pat_filter = NULL;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
540 }
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
541
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
542 void mpegts_set_service(MpegTSContext *ts, int sid,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
543 SetServiceCallback *set_service_cb, void *opaque)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
544 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
545 ts->set_service_cb = set_service_cb;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
546 ts->set_service_opaque = opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
547 ts->req_sid = sid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
548 ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
549 pat_cb, ts, 1);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
550 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
551
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
552 static void sdt_cb(void *opaque, const uint8_t *section, int section_len)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
553 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
554 MpegTSContext *ts = opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
555 SectionHeader h1, *h = &h1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
556 const uint8_t *p, *p_end, *desc_list_end, *desc_end;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
557 int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
558 char *name, *provider_name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
559
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
560 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
561 printf("SDT:\n");
398
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
562 av_hex_dump(stdout, (uint8_t *)section, section_len);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
563 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
564
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
565 p_end = section + section_len - 4;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
566 p = section;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
567 if (parse_section_header(h, &p, p_end) < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
568 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
569 if (h->tid != SDT_TID)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
570 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
571 onid = get16(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
572 if (onid < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
573 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
574 val = get8(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
575 if (val < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
576 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
577 for(;;) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
578 sid = get16(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
579 if (sid < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
580 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
581 val = get8(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
582 if (val < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
583 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
584 desc_list_len = get16(&p, p_end) & 0xfff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
585 if (desc_list_len < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
586 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
587 desc_list_end = p + desc_list_len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
588 if (desc_list_end > p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
589 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
590 for(;;) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
591 desc_tag = get8(&p, desc_list_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
592 if (desc_tag < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
593 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
594 desc_len = get8(&p, desc_list_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
595 desc_end = p + desc_len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
596 if (desc_end > desc_list_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
597 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
598 #ifdef DEBUG_SI
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
599 printf("tag: 0x%02x len=%d\n", desc_tag, desc_len);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
600 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
601 switch(desc_tag) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
602 case 0x48:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
603 service_type = get8(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
604 if (service_type < 0)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
605 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
606 provider_name = getstr8(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
607 if (!provider_name)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
608 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
609 name = getstr8(&p, p_end);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
610 if (!name)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
611 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
612 new_service(ts, sid, provider_name, name);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
613 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
614 default:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
615 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
616 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
617 p = desc_end;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
618 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
619 p = desc_list_end;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
620 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
621 ts->stop_parse = 1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
622
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
623 /* remove filter */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
624 mpegts_close_filter(ts, ts->sdt_filter);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
625 ts->sdt_filter = NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
626 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
627
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
628 /* scan services in a transport stream by looking at the SDT */
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
629 void mpegts_scan_sdt(MpegTSContext *ts)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
630 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
631 ts->sdt_filter = mpegts_open_section_filter(ts, SDT_PID,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
632 sdt_cb, ts, 1);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
633 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
634
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
635 /* scan services in a transport stream by looking at the PAT (better
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
636 than nothing !) */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
637 void mpegts_scan_pat(MpegTSContext *ts)
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
638 {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
639 ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID,
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
640 pat_scan_cb, ts, 1);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
641 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
642
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
643 /* TS stream handling */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
644
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
645 enum MpegTSState {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
646 MPEGTS_HEADER = 0,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
647 MPEGTS_PESHEADER_FILL,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
648 MPEGTS_PAYLOAD,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
649 MPEGTS_SKIP,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
650 };
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
651
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
652 /* enough for PES header + length */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
653 #define PES_START_SIZE 9
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
654 #define MAX_PES_HEADER_SIZE (9 + 255)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
655
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
656 typedef struct PESContext {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
657 int pid;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
658 int stream_type;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
659 MpegTSContext *ts;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
660 AVFormatContext *stream;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
661 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
662 enum MpegTSState state;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
663 /* used to get the format */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
664 int data_index;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
665 int total_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
666 int pes_header_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
667 int64_t pts, dts;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
668 uint8_t header[MAX_PES_HEADER_SIZE];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
669 } PESContext;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
670
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
671 static int64_t get_pts(const uint8_t *p)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
672 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
673 int64_t pts;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
674 int val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
675
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
676 pts = (int64_t)((p[0] >> 1) & 0x07) << 30;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
677 val = (p[1] << 8) | p[2];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
678 pts |= (int64_t)(val >> 1) << 15;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
679 val = (p[3] << 8) | p[4];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
680 pts |= (int64_t)(val >> 1);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
681 return pts;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
682 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
683
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
684 /* return non zero if a packet could be constructed */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
685 static void mpegts_push_data(void *opaque,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
686 const uint8_t *buf, int buf_size, int is_start)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
687 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
688 PESContext *pes = opaque;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
689 MpegTSContext *ts = pes->ts;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
690 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
691 const uint8_t *p;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
692 int len, code, codec_type, codec_id;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
693
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
694 if (is_start) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
695 pes->state = MPEGTS_HEADER;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
696 pes->data_index = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
697 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
698 p = buf;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
699 while (buf_size > 0) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
700 switch(pes->state) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
701 case MPEGTS_HEADER:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
702 len = PES_START_SIZE - pes->data_index;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
703 if (len > buf_size)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
704 len = buf_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
705 memcpy(pes->header + pes->data_index, p, len);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
706 pes->data_index += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
707 p += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
708 buf_size -= len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
709 if (pes->data_index == PES_START_SIZE) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
710 /* we got all the PES or section header. We can now
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
711 decide */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
712 #if 0
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
713 av_hex_dump(pes->header, pes->data_index);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
714 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
715 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
716 pes->header[2] == 0x01) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
717 /* it must be an mpeg2 PES stream */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
718 code = pes->header[3] | 0x100;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
719 if (!((code >= 0x1c0 && code <= 0x1df) ||
165
e4d2f704bf80 - Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
michaelni
parents: 160
diff changeset
720 (code >= 0x1e0 && code <= 0x1ef) ||
e4d2f704bf80 - Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
michaelni
parents: 160
diff changeset
721 (code == 0x1bd)))
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
722 goto skip;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
723 if (!pes->st) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
724 /* allocate stream */
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
725 switch(pes->stream_type){
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
726 case STREAM_TYPE_AUDIO_MPEG1:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
727 case STREAM_TYPE_AUDIO_MPEG2:
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
728 codec_type = CODEC_TYPE_AUDIO;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
729 codec_id = CODEC_ID_MP3;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
730 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
731 case STREAM_TYPE_VIDEO_MPEG1:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
732 case STREAM_TYPE_VIDEO_MPEG2:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
733 codec_type = CODEC_TYPE_VIDEO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
734 codec_id = CODEC_ID_MPEG2VIDEO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
735 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
736 case STREAM_TYPE_VIDEO_MPEG4:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
737 codec_type = CODEC_TYPE_VIDEO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
738 codec_id = CODEC_ID_MPEG4;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
739 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
740 case STREAM_TYPE_VIDEO_H264:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
741 codec_type = CODEC_TYPE_VIDEO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
742 codec_id = CODEC_ID_H264;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
743 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
744 case STREAM_TYPE_AUDIO_AAC:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
745 codec_type = CODEC_TYPE_AUDIO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
746 codec_id = CODEC_ID_AAC;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
747 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
748 case STREAM_TYPE_AUDIO_AC3:
165
e4d2f704bf80 - Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
michaelni
parents: 160
diff changeset
749 codec_type = CODEC_TYPE_AUDIO;
e4d2f704bf80 - Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
michaelni
parents: 160
diff changeset
750 codec_id = CODEC_ID_AC3;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
751 break;
496
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 474
diff changeset
752 case STREAM_TYPE_AUDIO_DTS:
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 474
diff changeset
753 codec_type = CODEC_TYPE_AUDIO;
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 474
diff changeset
754 codec_id = CODEC_ID_DTS;
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 474
diff changeset
755 break;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
756 default:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
757 if (code >= 0x1c0 && code <= 0x1df) {
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
758 codec_type = CODEC_TYPE_AUDIO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
759 codec_id = CODEC_ID_MP2;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
760 } else if (code == 0x1bd) {
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
761 codec_type = CODEC_TYPE_AUDIO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
762 codec_id = CODEC_ID_AC3;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
763 } else {
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
764 codec_type = CODEC_TYPE_VIDEO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
765 codec_id = CODEC_ID_MPEG1VIDEO;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
766 }
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
767 break;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
768 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
769 st = av_new_stream(pes->stream, pes->pid);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
770 if (st) {
463
696f41bc8784 store index for seeking in the native timebase of each stream
michael
parents: 462
diff changeset
771 av_set_pts_info(st, 60, 1, 90000);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
772 st->priv_data = pes;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
773 st->codec.codec_type = codec_type;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
774 st->codec.codec_id = codec_id;
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
775 st->need_parsing = 1;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
776 pes->st = st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
777 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
778 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
779 pes->state = MPEGTS_PESHEADER_FILL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
780 pes->total_size = (pes->header[4] << 8) | pes->header[5];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
781 /* NOTE: a zero total size means the PES size is
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
782 unbounded */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
783 if (pes->total_size)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
784 pes->total_size += 6;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
785 pes->pes_header_size = pes->header[8] + 9;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
786 } else {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
787 /* otherwise, it should be a table */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
788 /* skip packet */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
789 skip:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
790 pes->state = MPEGTS_SKIP;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
791 continue;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
792 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
793 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
794 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
795 /**********************************************/
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
796 /* PES packing parsing */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
797 case MPEGTS_PESHEADER_FILL:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
798 len = pes->pes_header_size - pes->data_index;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
799 if (len > buf_size)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
800 len = buf_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
801 memcpy(pes->header + pes->data_index, p, len);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
802 pes->data_index += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
803 p += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
804 buf_size -= len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
805 if (pes->data_index == pes->pes_header_size) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
806 const uint8_t *r;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
807 unsigned int flags;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
808
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
809 flags = pes->header[7];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
810 r = pes->header + 9;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
811 pes->pts = AV_NOPTS_VALUE;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
812 pes->dts = AV_NOPTS_VALUE;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
813 if ((flags & 0xc0) == 0x80) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
814 pes->pts = get_pts(r);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
815 r += 5;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
816 } else if ((flags & 0xc0) == 0xc0) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
817 pes->pts = get_pts(r);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
818 r += 5;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
819 pes->dts = get_pts(r);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
820 r += 5;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
821 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
822 /* we got the full header. We parse it and get the payload */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
823 pes->state = MPEGTS_PAYLOAD;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
824 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
825 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
826 case MPEGTS_PAYLOAD:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
827 if (pes->total_size) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
828 len = pes->total_size - pes->data_index;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
829 if (len > buf_size)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
830 len = buf_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
831 } else {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
832 len = buf_size;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
833 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
834 if (len > 0) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
835 AVPacket *pkt = ts->pkt;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
836 if (pes->st && av_new_packet(pkt, len) == 0) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
837 memcpy(pkt->data, p, len);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
838 pkt->stream_index = pes->st->index;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
839 pkt->pts = pes->pts;
367
3fca8e9142a4 avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 342
diff changeset
840 pkt->dts = pes->dts;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
841 /* reset pts values */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
842 pes->pts = AV_NOPTS_VALUE;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
843 pes->dts = AV_NOPTS_VALUE;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
844 ts->stop_parse = 1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
845 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
846 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
847 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
848 buf_size = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
849 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
850 case MPEGTS_SKIP:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
851 buf_size = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
852 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
853 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
854 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
855 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
856
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
857 static int add_pes_stream(MpegTSContext *ts, int pid, int stream_type)
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
858 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
859 MpegTSFilter *tss;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
860 PESContext *pes;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
861
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
862 /* if no pid found, then add a pid context */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
863 pes = av_mallocz(sizeof(PESContext));
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
864 if (!pes)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
865 return -1;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
866 pes->ts = ts;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
867 pes->stream = ts->stream;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
868 pes->pid = pid;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
869 pes->stream_type = stream_type;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
870 tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
871 if (!tss) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
872 av_free(pes);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
873 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
874 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
875 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
876 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
877
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
878 /* handle one TS packet */
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
879 static void handle_packet(MpegTSContext *ts, const uint8_t *packet)
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
880 {
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
881 AVFormatContext *s = ts->stream;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
882 MpegTSFilter *tss;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
883 int len, pid, cc, cc_ok, afc, is_start;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
884 const uint8_t *p, *p_end;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
885
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
886 pid = ((packet[1] & 0x1f) << 8) | packet[2];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
887 is_start = packet[1] & 0x40;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
888 tss = ts->pids[pid];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
889 if (ts->auto_guess && tss == NULL && is_start) {
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 310
diff changeset
890 add_pes_stream(ts, pid, 0);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
891 tss = ts->pids[pid];
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
892 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
893 if (!tss)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
894 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
895
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
896 /* continuity check (currently not used) */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
897 cc = (packet[3] & 0xf);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
898 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc));
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
899 tss->last_cc = cc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
900
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
901 /* skip adaptation field */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
902 afc = (packet[3] >> 4) & 3;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
903 p = packet + 4;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
904 if (afc == 0) /* reserved value */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
905 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
906 if (afc == 2) /* adaptation field only */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
907 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
908 if (afc == 3) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
909 /* skip adapation field */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
910 p += p[0] + 1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
911 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
912 /* if past the end of packet, ignore */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
913 p_end = packet + TS_PACKET_SIZE;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
914 if (p >= p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
915 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
916
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
917 if (tss->type == MPEGTS_SECTION) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
918 if (is_start) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
919 /* pointer field present */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
920 len = *p++;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
921 if (p + len > p_end)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
922 return;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
923 if (len && cc_ok) {
675
29a19aec26b2 Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents: 555
diff changeset
924 /* write remaining section bytes */
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
925 write_section_data(s, tss,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
926 p, len, 0);
675
29a19aec26b2 Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents: 555
diff changeset
927 /* check whether filter has been closed */
29a19aec26b2 Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents: 555
diff changeset
928 if (!ts->pids[pid])
29a19aec26b2 Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents: 555
diff changeset
929 return;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
930 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
931 p += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
932 if (p < p_end) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
933 write_section_data(s, tss,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
934 p, p_end - p, 1);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
935 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
936 } else {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
937 if (cc_ok) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
938 write_section_data(s, tss,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
939 p, p_end - p, 0);
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
940 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
941 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
942 } else {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
943 tss->u.pes_filter.pes_cb(tss->u.pes_filter.opaque,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
944 p, p_end - p, is_start);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
945 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
946 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
947
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
948 /* XXX: try to find a better synchro over several packets (use
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
949 get_packet_size() ?) */
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
950 static int mpegts_resync(ByteIOContext *pb)
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
951 {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
952 int c, i;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
953
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
954 for(i = 0;i < MAX_RESYNC_SIZE; i++) {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
955 c = url_fgetc(pb);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
956 if (c < 0)
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
957 return -1;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
958 if (c == 0x47) {
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
959 url_fseek(pb, -1, SEEK_CUR);
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
960 return 0;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
961 }
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
962 }
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
963 /* no sync found */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
964 return -1;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
965 }
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
966
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
967 /* return -1 if error or EOF. Return 0 if OK. */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
968 static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size)
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
969 {
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
970 int skip, len;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
971
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
972 for(;;) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
973 len = get_buffer(pb, buf, TS_PACKET_SIZE);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
974 if (len != TS_PACKET_SIZE)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
975 return AVERROR_IO;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
976 /* check paquet sync byte */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
977 if (buf[0] != 0x47) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
978 /* find a new packet start */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
979 url_fseek(pb, -TS_PACKET_SIZE, SEEK_CUR);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
980 if (mpegts_resync(pb) < 0)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
981 return AVERROR_INVALIDDATA;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
982 else
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
983 continue;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
984 } else {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
985 skip = raw_packet_size - TS_PACKET_SIZE;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
986 if (skip > 0)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
987 url_fskip(pb, skip);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
988 break;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
989 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
990 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
991 return 0;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
992 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
993
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
994 static int handle_packets(MpegTSContext *ts, int nb_packets)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
995 {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
996 AVFormatContext *s = ts->stream;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
997 ByteIOContext *pb = &s->pb;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
998 uint8_t packet[TS_PACKET_SIZE];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
999 int packet_num, ret;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1000
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1001 ts->stop_parse = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1002 packet_num = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1003 for(;;) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1004 if (ts->stop_parse)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1005 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1006 packet_num++;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1007 if (nb_packets != 0 && packet_num >= nb_packets)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1008 break;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1009 ret = read_packet(pb, packet, ts->raw_packet_size);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1010 if (ret != 0)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1011 return ret;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1012 handle_packet(ts, packet);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1013 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1014 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1015 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1016
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1017 static int mpegts_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 {
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1019 #if 1
329
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1020 const int size= p->buf_size;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1021 int score, fec_score;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1022 #define CHECK_COUNT 10
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1023
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1024 if (size < (TS_FEC_PACKET_SIZE * CHECK_COUNT))
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1025 return -1;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1026
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1027 score = analyze(p->buf, TS_PACKET_SIZE *CHECK_COUNT, TS_PACKET_SIZE, NULL);
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1028 fec_score= analyze(p->buf, TS_FEC_PACKET_SIZE*CHECK_COUNT, TS_FEC_PACKET_SIZE, NULL);
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1029 // av_log(NULL, AV_LOG_DEBUG, "score: %d, fec_score: %d \n", score, fec_score);
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1030
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1031 // we need a clear definition for the returned score otherwise things will become messy sooner or later
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1032 if (score > fec_score && score > 6) return AVPROBE_SCORE_MAX + score - CHECK_COUNT;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1033 else if( fec_score > 6) return AVPROBE_SCORE_MAX + fec_score - CHECK_COUNT;
d20a3caaef29 better get_packet_size and probe
michael
parents: 313
diff changeset
1034 else return -1;
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1035 #else
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1036 /* only use the extension for safer guess */
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1037 if (match_ext(p->filename, "ts"))
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1038 return AVPROBE_SCORE_MAX;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1039 else
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1040 return 0;
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1041 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1043
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1044 void set_service_cb(void *opaque, int ret)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1045 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1046 MpegTSContext *ts = opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1047 ts->set_service_ret = ret;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1048 ts->stop_parse = 1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1049 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1050
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1051 /* return the 90 kHz PCR and the extension for the 27 MHz PCR. return
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1052 (-1) if not available */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1053 static int parse_pcr(int64_t *ppcr_high, int *ppcr_low,
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1054 const uint8_t *packet)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1055 {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1056 int afc, len, flags;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1057 const uint8_t *p;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1058 unsigned int v;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1059
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1060 afc = (packet[3] >> 4) & 3;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1061 if (afc <= 1)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1062 return -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1063 p = packet + 4;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1064 len = p[0];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1065 p++;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1066 if (len == 0)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1067 return -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1068 flags = *p++;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1069 len--;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1070 if (!(flags & 0x10))
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1071 return -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1072 if (len < 6)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1073 return -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1074 v = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1075 *ppcr_high = ((int64_t)v << 1) | (p[4] >> 7);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1076 *ppcr_low = ((p[4] & 1) << 8) | p[5];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1077 return 0;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1078 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1079
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080 static int mpegts_read_header(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1081 AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1082 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1083 MpegTSContext *ts = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1084 ByteIOContext *pb = &s->pb;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1085 uint8_t buf[1024];
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1086 int len, sid, i;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
1087 int64_t pos;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1088 MpegTSService *service;
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1089
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1090 if (ap) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1091 ts->mpeg2ts_raw = ap->mpeg2ts_raw;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1092 ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1093 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1094
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 /* read the first 1024 bytes to get packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 len = get_buffer(pb, buf, sizeof(buf));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098 if (len != sizeof(buf))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100 ts->raw_packet_size = get_packet_size(buf, sizeof(buf));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101 if (ts->raw_packet_size <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 goto fail;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1103 ts->stream = s;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1104 ts->auto_guess = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1105
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1106 if (!ts->mpeg2ts_raw) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1107 /* normal demux */
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1108
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1109 if (!ts->auto_guess) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1110 ts->set_service_ret = -1;
160
9bde37b1a5ce try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents: 152
diff changeset
1111
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1112 /* first do a scaning to get all the services */
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1113 url_fseek(pb, pos, SEEK_SET);
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1114 mpegts_scan_sdt(ts);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1115
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1116 handle_packets(ts, MAX_SCAN_PACKETS);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1117
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1118 if (ts->nb_services <= 0) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1119 /* no SDT found, we try to look at the PAT */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1120
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1121 /* First remove the SDT filters from each PID */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1122 int i;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1123 for (i=0; i < NB_PID_MAX; i++) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1124 if (ts->pids[i])
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1125 mpegts_close_filter(ts, ts->pids[i]);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1126 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1127 url_fseek(pb, pos, SEEK_SET);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1128 mpegts_scan_pat(ts);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1129
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1130 handle_packets(ts, MAX_SCAN_PACKETS);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1131 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1132
398
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
1133 if (ts->nb_services <= 0) {
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
1134 /* raw transport stream */
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
1135 ts->auto_guess = 1;
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
1136 s->ctx_flags |= AVFMTCTX_NOHEADER;
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
1137 goto do_pcr;
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
1138 }
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1139
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1140 /* tune to first service found */
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1141 for(i=0; i<ts->nb_services && ts->set_service_ret; i++){
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1142 service = ts->services[i];
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1143 sid = service->sid;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1144 #ifdef DEBUG_SI
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1145 printf("tuning to '%s'\n", service->name);
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1146 #endif
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1147
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1148 /* now find the info for the first service if we found any,
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1149 otherwise try to filter all PATs */
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1150
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1151 url_fseek(pb, pos, SEEK_SET);
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1152 mpegts_set_service(ts, sid, set_service_cb, ts);
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1153
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1154 handle_packets(ts, MAX_SCAN_PACKETS);
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1155 }
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1156 /* if could not find service, exit */
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1157
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1158 if (ts->set_service_ret != 0)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1159 return -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1160
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1161 #ifdef DEBUG_SI
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1162 printf("tuning done\n");
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1163 #endif
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1164 }
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1165 s->ctx_flags |= AVFMTCTX_NOHEADER;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1166 } else {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1167 AVStream *st;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1168 int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1169 int64_t pcrs[2], pcr_h;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1170 int packet_count[2];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1171 uint8_t packet[TS_PACKET_SIZE];
170
0543d27721c1 cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents: 165
diff changeset
1172
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1173 /* only read packets */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1174
398
0d92246d3644 Support raw mpegts streams from dvr patch by (wmglo at dent dot med dot uni-muenchen dot de)
michael
parents: 367
diff changeset
1175 do_pcr:
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1176 st = av_new_stream(s, 0);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1177 if (!st)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1178 goto fail;
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 444
diff changeset
1179 av_set_pts_info(st, 60, 1, 27000000);
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1180 st->codec.codec_type = CODEC_TYPE_DATA;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1181 st->codec.codec_id = CODEC_ID_MPEG2TS;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1182
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1183 /* we iterate until we find two PCRs to estimate the bitrate */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1184 pcr_pid = -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1185 nb_pcrs = 0;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1186 nb_packets = 0;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1187 for(;;) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1188 ret = read_packet(&s->pb, packet, ts->raw_packet_size);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1189 if (ret < 0)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1190 return -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1191 pid = ((packet[1] & 0x1f) << 8) | packet[2];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1192 if ((pcr_pid == -1 || pcr_pid == pid) &&
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1193 parse_pcr(&pcr_h, &pcr_l, packet) == 0) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1194 pcr_pid = pid;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1195 packet_count[nb_pcrs] = nb_packets;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1196 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1197 nb_pcrs++;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1198 if (nb_pcrs >= 2)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1199 break;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1200 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1201 nb_packets++;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1202 }
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1203 ts->pcr_pid = pcr_pid;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1204
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1205 /* NOTE1: the bitrate is computed without the FEC */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1206 /* NOTE2: it is only the bitrate of the start of the stream */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1207 ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1208 ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1209 s->bit_rate = (TS_PACKET_SIZE * 8) * 27e6 / ts->pcr_incr;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1210 st->codec.bit_rate = s->bit_rate;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1211 st->start_time = ts->cur_pcr * 1000000.0 / 27.0e6;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1212 #if 0
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1213 printf("start=%0.3f pcr=%0.3f incr=%d\n",
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1214 st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1215 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1216 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1217
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218 url_fseek(pb, pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1224 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1225
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1226 static int mpegts_raw_read_packet(AVFormatContext *s,
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1227 AVPacket *pkt)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1228 {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1229 MpegTSContext *ts = s->priv_data;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1230 int ret, i;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1231 int64_t pcr_h, next_pcr_h, pos;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1232 int pcr_l, next_pcr_l;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1233 uint8_t pcr_buf[12];
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1234
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1235 if (av_new_packet(pkt, TS_PACKET_SIZE) < 0)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1236 return -ENOMEM;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1237 ret = read_packet(&s->pb, pkt->data, ts->raw_packet_size);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1238 if (ret < 0) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1239 av_free_packet(pkt);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1240 return ret;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1241 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1242 if (ts->mpeg2ts_compute_pcr) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1243 /* compute exact PCR for each packet */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1244 if (parse_pcr(&pcr_h, &pcr_l, pkt->data) == 0) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1245 /* we read the next PCR (XXX: optimize it by using a bigger buffer */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1246 pos = url_ftell(&s->pb);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1247 for(i = 0; i < MAX_PACKET_READAHEAD; i++) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1248 url_fseek(&s->pb, pos + i * ts->raw_packet_size, SEEK_SET);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1249 get_buffer(&s->pb, pcr_buf, 12);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1250 if (parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1251 /* XXX: not precise enough */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1252 ts->pcr_incr = ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) /
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1253 (i + 1);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1254 break;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1255 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1256 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1257 url_fseek(&s->pb, pos, SEEK_SET);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1258 /* no next PCR found: we use previous increment */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1259 ts->cur_pcr = pcr_h * 300 + pcr_l;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1260 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1261 pkt->pts = ts->cur_pcr;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1262 pkt->duration = ts->pcr_incr;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1263 ts->cur_pcr += ts->pcr_incr;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1264 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1265 pkt->stream_index = 0;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1266 return 0;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1267 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1268
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 static int mpegts_read_packet(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1272 MpegTSContext *ts = s->priv_data;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1273
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1274 if (!ts->mpeg2ts_raw) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1275 ts->pkt = pkt;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1276 return handle_packets(ts, 0);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1277 } else {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1278 return mpegts_raw_read_packet(s, pkt);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1279 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1280 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1281
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1282 static int mpegts_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1283 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1284 MpegTSContext *ts = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1285 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1286 for(i=0;i<NB_PID_MAX;i++)
342
0c1b489c96bf memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 329
diff changeset
1287 if (ts->pids[i]) mpegts_close_filter(ts, ts->pids[i]);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1288 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1289 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1290
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1291 static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
463
696f41bc8784 store index for seeking in the native timebase of each stream
michael
parents: 462
diff changeset
1292 int64_t *ppos, int64_t pos_limit)
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1293 {
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1294 MpegTSContext *ts = s->priv_data;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1295 int64_t pos, timestamp;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1296 uint8_t buf[TS_PACKET_SIZE];
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1297 int pcr_l, pid;
463
696f41bc8784 store index for seeking in the native timebase of each stream
michael
parents: 462
diff changeset
1298 const int find_next= 1;
696f41bc8784 store index for seeking in the native timebase of each stream
michael
parents: 462
diff changeset
1299 pos = ((*ppos + ts->raw_packet_size - 1) / ts->raw_packet_size) * ts->raw_packet_size;
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1300 if (find_next) {
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1301 for(;;) {
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1302 url_fseek(&s->pb, pos, SEEK_SET);
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1303 if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1304 return AV_NOPTS_VALUE;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1305 pid = ((buf[1] & 0x1f) << 8) | buf[2];
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1306 if (pid == ts->pcr_pid &&
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1307 parse_pcr(&timestamp, &pcr_l, buf) == 0) {
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1308 break;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1309 }
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1310 pos += ts->raw_packet_size;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1311 }
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1312 } else {
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1313 for(;;) {
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1314 pos -= ts->raw_packet_size;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1315 if (pos < 0)
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1316 return AV_NOPTS_VALUE;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1317 url_fseek(&s->pb, pos, SEEK_SET);
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1318 if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1319 return AV_NOPTS_VALUE;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1320 pid = ((buf[1] & 0x1f) << 8) | buf[2];
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1321 if (pid == ts->pcr_pid &&
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1322 parse_pcr(&timestamp, &pcr_l, buf) == 0) {
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1323 break;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1324 }
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1325 }
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1326 }
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1327 *ppos = pos;
463
696f41bc8784 store index for seeking in the native timebase of each stream
michael
parents: 462
diff changeset
1328
310
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1329 return timestamp;
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1330 }
944c8edaf609 seek support
bellard
parents: 292
diff changeset
1331
555
0a997108f384 use native timebase for seeking
michael
parents: 496
diff changeset
1332 static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1333 MpegTSContext *ts = s->priv_data;
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1334 uint8_t buf[TS_PACKET_SIZE];
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1335 int64_t pos;
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1336
555
0a997108f384 use native timebase for seeking
michael
parents: 496
diff changeset
1337 if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1338 return -1;
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1339
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1340 pos= url_ftell(&s->pb);
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1341
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1342 for(;;) {
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1343 url_fseek(&s->pb, pos, SEEK_SET);
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1344 if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE)
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1345 return -1;
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1346 // pid = ((buf[1] & 0x1f) << 8) | buf[2];
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1347 if(buf[1] & 0x40) break;
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1348 pos += ts->raw_packet_size;
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1349 }
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1350 url_fseek(&s->pb, pos, SEEK_SET);
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1351
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1352 return 0;
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1353 }
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1354
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1355 /**************************************************************/
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1356 /* parsing functions - called from other demuxers such as RTP */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1357
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1358 MpegTSContext *mpegts_parse_open(AVFormatContext *s)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1359 {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1360 MpegTSContext *ts;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1361
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1362 ts = av_mallocz(sizeof(MpegTSContext));
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1363 if (!ts)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1364 return NULL;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1365 /* no stream case, currently used by RTP */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1366 ts->raw_packet_size = TS_PACKET_SIZE;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1367 ts->stream = s;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1368 ts->auto_guess = 1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1369 return ts;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1370 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1371
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1372 /* return the consumed length if a packet was output, or -1 if no
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1373 packet is output */
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1374 int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1375 const uint8_t *buf, int len)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1376 {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1377 int len1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1378
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1379 len1 = len;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1380 ts->pkt = pkt;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1381 ts->stop_parse = 0;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1382 for(;;) {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1383 if (ts->stop_parse)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1384 break;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1385 if (len < TS_PACKET_SIZE)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1386 return -1;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1387 if (buf[0] != 0x47) {
444
d42038d418a0 Off-by-two in mpegts.c patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents: 398
diff changeset
1388 buf++;
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1389 len--;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1390 } else {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1391 handle_packet(ts, buf);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1392 buf += TS_PACKET_SIZE;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1393 len -= TS_PACKET_SIZE;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1394 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1395 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1396 return len1 - len;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1397 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1398
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1399 void mpegts_parse_close(MpegTSContext *ts)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1400 {
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1401 int i;
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1402
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1403 for(i=0;i<NB_PID_MAX;i++)
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1404 av_free(ts->pids[i]);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1405 av_free(ts);
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1406 }
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1407
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1408 AVInputFormat mpegts_demux = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1409 "mpegts",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1410 "MPEG2 transport stream format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1411 sizeof(MpegTSContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1412 mpegts_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1413 mpegts_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1414 mpegts_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1415 mpegts_read_close,
474
2846bb67dd8f fix playback of http://www.zonque.org/test-long.ps
michael
parents: 463
diff changeset
1416 read_seek,
463
696f41bc8784 store index for seeking in the native timebase of each stream
michael
parents: 462
diff changeset
1417 mpegts_get_pcr,
292
155ce13f1033 mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents: 283
diff changeset
1418 .flags = AVFMT_SHOW_IDS,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1419 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1420
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1421 int mpegts_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1422 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1423 av_register_input_format(&mpegts_demux);
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 170
diff changeset
1424 #ifdef CONFIG_ENCODERS
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents: 107
diff changeset
1425 av_register_output_format(&mpegts_mux);
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 170
diff changeset
1426 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1427 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1428 }