Mercurial > libavformat.hg
annotate mpegtsenc.c @ 3546:45c3d2b2b2fb libavformat
Alphabetically order AVInputFormat/AVOutputFormat declarations.
author | diego |
---|---|
date | Mon, 07 Jul 2008 11:11:08 +0000 |
parents | 7a0230981402 |
children | 2ca19db359bd |
rev | line source |
---|---|
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
1 /* |
1415
3b00fb8ef8e4
replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents:
1358
diff
changeset
|
2 * MPEG2 transport stream (aka DVB) muxer |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
3 * Copyright (c) 2003 Fabrice Bellard. |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
16 * |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
20 */ |
3286 | 21 |
22 #include "libavutil/crc.h" | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
23 #include "avformat.h" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
24 #include "mpegts.h" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
25 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
26 /* write DVB SI sections */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
27 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
28 /*********************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
29 /* mpegts section writer */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
30 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
31 typedef struct MpegTSSection { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
32 int pid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
33 int cc; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
34 void (*write_packet)(struct MpegTSSection *s, const uint8_t *packet); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
35 void *opaque; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
36 } MpegTSSection; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
37 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
38 /* NOTE: 4 bytes must be left at the end for the crc32 */ |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
996
diff
changeset
|
39 static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
40 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
41 unsigned int crc; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
42 unsigned char packet[TS_PACKET_SIZE]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
43 const unsigned char *buf_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
44 unsigned char *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
45 int first, b, len1, left; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
46 |
2893 | 47 crc = bswap_32(av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, buf, len - 4)); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
48 buf[len - 4] = (crc >> 24) & 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
49 buf[len - 3] = (crc >> 16) & 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
50 buf[len - 2] = (crc >> 8) & 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
51 buf[len - 1] = (crc) & 0xff; |
885 | 52 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
53 /* send each packet */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
54 buf_ptr = buf; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
55 while (len > 0) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
56 first = (buf == buf_ptr); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
57 q = packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
58 *q++ = 0x47; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
59 b = (s->pid >> 8); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
60 if (first) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
61 b |= 0x40; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
62 *q++ = b; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
63 *q++ = s->pid; |
3419 | 64 *q++ = 0x10 | s->cc; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
65 s->cc = (s->cc + 1) & 0xf; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
66 if (first) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
67 *q++ = 0; /* 0 offset */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
68 len1 = TS_PACKET_SIZE - (q - packet); |
885 | 69 if (len1 > len) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
70 len1 = len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
71 memcpy(q, buf_ptr, len1); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
72 q += len1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
73 /* add known padding data */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
74 left = TS_PACKET_SIZE - (q - packet); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
75 if (left > 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
76 memset(q, 0xff, left); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
77 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
78 s->write_packet(s, packet); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
79 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
80 buf_ptr += len1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
81 len -= len1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
82 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
83 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
84 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
85 static inline void put16(uint8_t **q_ptr, int val) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
86 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
87 uint8_t *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
88 q = *q_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
89 *q++ = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
90 *q++ = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
91 *q_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
92 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
93 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
996
diff
changeset
|
94 static int mpegts_write_section1(MpegTSSection *s, int tid, int id, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
95 int version, int sec_num, int last_sec_num, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
96 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:
diff
changeset
|
97 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
98 uint8_t section[1024], *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
99 unsigned int tot_len; |
885 | 100 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
101 tot_len = 3 + 5 + len + 4; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
102 /* check if not too big */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
103 if (tot_len > 1024) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
104 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
105 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
106 q = section; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
107 *q++ = tid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
108 put16(&q, 0xb000 | (len + 5 + 4)); /* 5 byte header + 4 byte CRC */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
109 put16(&q, id); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
110 *q++ = 0xc1 | (version << 1); /* current_next_indicator = 1 */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
111 *q++ = sec_num; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
112 *q++ = last_sec_num; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
113 memcpy(q, buf, len); |
885 | 114 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
115 mpegts_write_section(s, section, tot_len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
116 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
117 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
118 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
119 /*********************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
120 /* mpegts writer */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
121 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
122 #define DEFAULT_PMT_START_PID 0x1000 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
123 #define DEFAULT_START_PID 0x0100 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
124 #define DEFAULT_PROVIDER_NAME "FFmpeg" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
125 #define DEFAULT_SERVICE_NAME "Service01" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
126 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
127 /* default network id, transport stream and service identifiers */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
128 #define DEFAULT_ONID 0x0001 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
129 #define DEFAULT_TSID 0x0001 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
130 #define DEFAULT_SID 0x0001 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
131 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
132 /* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
133 #define DEFAULT_PES_HEADER_FREQ 16 |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
134 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
135 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
136 /* we retransmit the SI info at this rate */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
137 #define SDT_RETRANS_TIME 500 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
138 #define PAT_RETRANS_TIME 100 |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
139 #define PCR_RETRANS_TIME 20 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
140 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
141 typedef struct MpegTSWriteStream { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
142 struct MpegTSService *service; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
143 int pid; /* stream associated pid */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
144 int cc; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
145 int payload_index; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
146 int64_t payload_pts; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
147 int64_t payload_dts; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
148 uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE]; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
149 } MpegTSWriteStream; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
150 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
151 typedef struct MpegTSService { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
152 MpegTSSection pmt; /* MPEG2 pmt table context */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
153 int sid; /* service ID */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
154 char *name; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
155 char *provider_name; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
156 int pcr_pid; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
157 int pcr_packet_count; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
158 int pcr_packet_freq; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
159 } MpegTSService; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
160 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
161 typedef struct MpegTSWrite { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
162 MpegTSSection pat; /* MPEG2 pat table */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
163 MpegTSSection sdt; /* MPEG2 sdt table context */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
164 MpegTSService **services; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
165 int sdt_packet_count; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
166 int sdt_packet_freq; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
167 int pat_packet_count; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
168 int pat_packet_freq; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
169 int nb_services; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
170 int onid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
171 int tsid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
172 } MpegTSWrite; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
173 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
174 static void mpegts_write_pat(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
175 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
176 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
177 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
178 uint8_t data[1012], *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
179 int i; |
885 | 180 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
181 q = data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
182 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
183 service = ts->services[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
184 put16(&q, service->sid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
185 put16(&q, 0xe000 | service->pmt.pid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
186 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
187 mpegts_write_section1(&ts->pat, PAT_TID, ts->tsid, 0, 0, 0, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
188 data, q - data); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
189 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
190 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
191 static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
192 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
193 // MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
194 uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
195 int val, stream_type, i; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
196 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
197 q = data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
198 put16(&q, 0xe000 | service->pcr_pid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
199 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
200 program_info_length_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
201 q += 2; /* patched after */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
202 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
203 /* put program info here */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
204 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
205 val = 0xf000 | (q - program_info_length_ptr - 2); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
206 program_info_length_ptr[0] = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
207 program_info_length_ptr[1] = val; |
885 | 208 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
209 for(i = 0; i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
210 AVStream *st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
211 MpegTSWriteStream *ts_st = st->priv_data; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
212 switch(st->codec->codec_id) { |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
213 case CODEC_ID_MPEG1VIDEO: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
214 case CODEC_ID_MPEG2VIDEO: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
215 stream_type = STREAM_TYPE_VIDEO_MPEG2; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
216 break; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
217 case CODEC_ID_MPEG4: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
218 stream_type = STREAM_TYPE_VIDEO_MPEG4; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
219 break; |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
220 case CODEC_ID_H264: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
221 stream_type = STREAM_TYPE_VIDEO_H264; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
222 break; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
223 case CODEC_ID_MP2: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
224 case CODEC_ID_MP3: |
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
|
225 stream_type = STREAM_TYPE_AUDIO_MPEG1; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
226 break; |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
227 case CODEC_ID_AAC: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
228 stream_type = STREAM_TYPE_AUDIO_AAC; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
229 break; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
230 case CODEC_ID_AC3: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
231 stream_type = STREAM_TYPE_AUDIO_AC3; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
232 break; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
233 default: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
234 stream_type = STREAM_TYPE_PRIVATE_DATA; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
235 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
236 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
237 *q++ = stream_type; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
238 put16(&q, 0xe000 | ts_st->pid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
239 desc_length_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
240 q += 2; /* patched after */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
241 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
242 /* write optional descriptors here */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
243 switch(st->codec->codec_type) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
244 case CODEC_TYPE_AUDIO: |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
245 if (strlen(st->language) == 3) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
246 *q++ = 0x0a; /* ISO 639 language descriptor */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
247 *q++ = 4; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
248 *q++ = st->language[0]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
249 *q++ = st->language[1]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
250 *q++ = st->language[2]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
251 *q++ = 0; /* undefined type */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
252 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
253 break; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
254 case CODEC_TYPE_SUBTITLE: |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
255 { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
256 const char *language; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
257 language = st->language; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
258 if (strlen(language) != 3) |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
259 language = "eng"; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
260 *q++ = 0x59; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
261 *q++ = 8; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
262 *q++ = language[0]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
263 *q++ = language[1]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
264 *q++ = language[2]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
265 *q++ = 0x10; /* normal subtitles (0x20 = if hearing pb) */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
266 put16(&q, 1); /* page id */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
267 put16(&q, 1); /* ancillary page id */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
268 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
269 break; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
270 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
271 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
272 val = 0xf000 | (q - desc_length_ptr - 2); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
273 desc_length_ptr[0] = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
274 desc_length_ptr[1] = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
275 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
276 mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
277 data, q - data); |
885 | 278 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
279 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
280 /* NOTE: str == NULL is accepted for an empty string */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
281 static void putstr8(uint8_t **q_ptr, const char *str) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
282 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
283 uint8_t *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
284 int len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
285 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
286 q = *q_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
287 if (!str) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
288 len = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
289 else |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
290 len = strlen(str); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
291 *q++ = len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
292 memcpy(q, str, len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
293 q += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
294 *q_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
295 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
296 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
297 static void mpegts_write_sdt(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
298 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
299 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
300 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
301 uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
302 int i, running_status, free_ca_mode, val; |
885 | 303 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
304 q = data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
305 put16(&q, ts->onid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
306 *q++ = 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
307 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
308 service = ts->services[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
309 put16(&q, service->sid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
310 *q++ = 0xfc | 0x00; /* currently no EIT info */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
311 desc_list_len_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
312 q += 2; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
313 running_status = 4; /* running */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
314 free_ca_mode = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
315 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
316 /* write only one descriptor for the service name and provider */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
317 *q++ = 0x48; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
318 desc_len_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
319 q++; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
320 *q++ = 0x01; /* digital television service */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
321 putstr8(&q, service->provider_name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
322 putstr8(&q, service->name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
323 desc_len_ptr[0] = q - desc_len_ptr - 1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
324 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
325 /* fill descriptor length */ |
885 | 326 val = (running_status << 13) | (free_ca_mode << 12) | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
327 (q - desc_list_len_ptr - 2); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
328 desc_list_len_ptr[0] = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
329 desc_list_len_ptr[1] = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
330 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
331 mpegts_write_section1(&ts->sdt, SDT_TID, ts->tsid, 0, 0, 0, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
332 data, q - data); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
333 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
334 |
885 | 335 static MpegTSService *mpegts_add_service(MpegTSWrite *ts, |
336 int sid, | |
337 const char *provider_name, | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
338 const char *name) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
339 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
340 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
341 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
342 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:
diff
changeset
|
343 if (!service) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
344 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
345 service->pmt.pid = DEFAULT_PMT_START_PID + ts->nb_services - 1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
346 service->sid = sid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
347 service->provider_name = av_strdup(provider_name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
348 service->name = av_strdup(name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
349 service->pcr_pid = 0x1fff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
350 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:
diff
changeset
|
351 return service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
352 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
353 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
354 static void section_write_packet(MpegTSSection *s, const uint8_t *packet) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
355 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
356 AVFormatContext *ctx = s->opaque; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
357 put_buffer(ctx->pb, packet, TS_PACKET_SIZE); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
358 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
359 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
360 static int mpegts_write_header(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
361 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
362 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
363 MpegTSWriteStream *ts_st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
364 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
365 AVStream *st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
366 int i, total_bit_rate; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
367 const char *service_name; |
885 | 368 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
369 ts->tsid = DEFAULT_TSID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
370 ts->onid = DEFAULT_ONID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
371 /* allocate a single DVB service */ |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
372 service_name = s->title; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
373 if (service_name[0] == '\0') |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
374 service_name = DEFAULT_SERVICE_NAME; |
885 | 375 service = mpegts_add_service(ts, DEFAULT_SID, |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
376 DEFAULT_PROVIDER_NAME, service_name); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
377 service->pmt.write_packet = section_write_packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
378 service->pmt.opaque = s; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
379 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
380 ts->pat.pid = PAT_PID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
381 ts->pat.cc = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
382 ts->pat.write_packet = section_write_packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
383 ts->pat.opaque = s; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
384 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
385 ts->sdt.pid = SDT_PID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
386 ts->sdt.cc = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
387 ts->sdt.write_packet = section_write_packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
388 ts->sdt.opaque = s; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
389 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
390 /* assign pids to each stream */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
391 total_bit_rate = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
392 for(i = 0;i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
393 st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
394 ts_st = av_mallocz(sizeof(MpegTSWriteStream)); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
395 if (!ts_st) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
396 goto fail; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
397 st->priv_data = ts_st; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
398 ts_st->service = service; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
399 ts_st->pid = DEFAULT_START_PID + i; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
400 ts_st->payload_pts = AV_NOPTS_VALUE; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
401 ts_st->payload_dts = AV_NOPTS_VALUE; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
402 /* update PCR pid by using the first video stream */ |
885 | 403 if (st->codec->codec_type == CODEC_TYPE_VIDEO && |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
404 service->pcr_pid == 0x1fff) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
405 service->pcr_pid = ts_st->pid; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
406 total_bit_rate += st->codec->bit_rate; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
407 } |
885 | 408 |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
409 /* if no video stream, use the first stream as PCR */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
410 if (service->pcr_pid == 0x1fff && s->nb_streams > 0) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
411 ts_st = s->streams[0]->priv_data; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
412 service->pcr_pid = ts_st->pid; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
413 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
414 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
415 if (total_bit_rate <= 8 * 1024) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
416 total_bit_rate = 8 * 1024; |
885 | 417 service->pcr_packet_freq = (total_bit_rate * PCR_RETRANS_TIME) / |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
418 (TS_PACKET_SIZE * 8 * 1000); |
885 | 419 ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) / |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
420 (TS_PACKET_SIZE * 8 * 1000); |
885 | 421 ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) / |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
422 (TS_PACKET_SIZE * 8 * 1000); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
423 #if 0 |
885 | 424 printf("%d %d %d\n", |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
425 total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
426 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
427 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
428 /* write info at the start of the file, so that it will be fast to |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
429 find them */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
430 mpegts_write_sdt(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
431 mpegts_write_pat(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
432 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
433 mpegts_write_pmt(s, ts->services[i]); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
434 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
435 put_flush_packet(s->pb); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
436 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
437 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
438 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
439 fail: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
440 for(i = 0;i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
441 st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
442 av_free(st->priv_data); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
443 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
444 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
445 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
446 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
447 /* send SDT, PAT and PMT tables regulary */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
448 static void retransmit_si_info(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
449 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
450 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
451 int i; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
452 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
453 if (++ts->sdt_packet_count == ts->sdt_packet_freq) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
454 ts->sdt_packet_count = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
455 mpegts_write_sdt(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
456 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
457 if (++ts->pat_packet_count == ts->pat_packet_freq) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
458 ts->pat_packet_count = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
459 mpegts_write_pat(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
460 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
461 mpegts_write_pmt(s, ts->services[i]); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
462 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
463 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
464 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
465 |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
466 static void write_pts(uint8_t *q, int fourbits, int64_t pts) |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
467 { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
468 int val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
469 |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
470 val = fourbits << 4 | (((pts >> 30) & 0x07) << 1) | 1; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
471 *q++ = val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
472 val = (((pts >> 15) & 0x7fff) << 1) | 1; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
473 *q++ = val >> 8; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
474 *q++ = val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
475 val = (((pts) & 0x7fff) << 1) | 1; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
476 *q++ = val >> 8; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
477 *q++ = val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
478 } |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
479 |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
480 /* NOTE: pes_data contains all the PES packet */ |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
481 static void mpegts_write_pes(AVFormatContext *s, AVStream *st, |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
482 const uint8_t *payload, int payload_size, |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
483 int64_t pts, int64_t dts) |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
484 { |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
485 MpegTSWriteStream *ts_st = st->priv_data; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
486 uint8_t buf[TS_PACKET_SIZE]; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
487 uint8_t *q; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
488 int val, is_start, len, header_len, write_pcr, private_code, flags; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
489 int afc_len, stuffing_len; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
490 int64_t pcr = -1; /* avoid warning */ |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
491 |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
492 is_start = 1; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
493 while (payload_size > 0) { |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
494 retransmit_si_info(s); |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
495 |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
496 write_pcr = 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
497 if (ts_st->pid == ts_st->service->pcr_pid) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
498 ts_st->service->pcr_packet_count++; |
885 | 499 if (ts_st->service->pcr_packet_count >= |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
500 ts_st->service->pcr_packet_freq) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
501 ts_st->service->pcr_packet_count = 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
502 write_pcr = 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
503 /* XXX: this is incorrect, but at least we have a PCR |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
504 value */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
505 pcr = pts; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
506 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
507 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
508 |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
509 /* prepare packet header */ |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
510 q = buf; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
511 *q++ = 0x47; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
512 val = (ts_st->pid >> 8); |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
513 if (is_start) |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
514 val |= 0x40; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
515 *q++ = val; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
516 *q++ = ts_st->pid; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
517 *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
518 ts_st->cc = (ts_st->cc + 1) & 0xf; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
519 if (write_pcr) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
520 *q++ = 7; /* AFC length */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
521 *q++ = 0x10; /* flags: PCR present */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
522 *q++ = pcr >> 25; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
523 *q++ = pcr >> 17; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
524 *q++ = pcr >> 9; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
525 *q++ = pcr >> 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
526 *q++ = (pcr & 1) << 7; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
527 *q++ = 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
528 } |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
529 if (is_start) { |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
530 /* write PES header */ |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
531 *q++ = 0x00; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
532 *q++ = 0x00; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
533 *q++ = 0x01; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
534 private_code = 0; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
535 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
536 *q++ = 0xe0; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
537 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO && |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
538 (st->codec->codec_id == CODEC_ID_MP2 || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
539 st->codec->codec_id == CODEC_ID_MP3)) { |
885 | 540 *q++ = 0xc0; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
541 } else { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
542 *q++ = 0xbd; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
543 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
544 private_code = 0x20; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
545 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
546 } |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
547 header_len = 0; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
548 flags = 0; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
549 if (pts != AV_NOPTS_VALUE) { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
550 header_len += 5; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
551 flags |= 0x80; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
552 } |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
553 if (dts != AV_NOPTS_VALUE) { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
554 header_len += 5; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
555 flags |= 0x40; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
556 } |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
557 len = payload_size + header_len + 3; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
558 if (private_code != 0) |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
559 len++; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
560 *q++ = len >> 8; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
561 *q++ = len; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
562 val = 0x80; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
563 /* data alignment indicator is required for subtitle data */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
564 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
565 val |= 0x04; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
566 *q++ = val; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
567 *q++ = flags; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
568 *q++ = header_len; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
569 if (pts != AV_NOPTS_VALUE) { |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
570 write_pts(q, flags >> 6, pts); |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
571 q += 5; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
572 } |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
573 if (dts != AV_NOPTS_VALUE) { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
574 write_pts(q, 1, dts); |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
575 q += 5; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
576 } |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
577 if (private_code != 0) |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
578 *q++ = private_code; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
579 is_start = 0; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
580 } |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
581 /* header size */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
582 header_len = q - buf; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
583 /* data len */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
584 len = TS_PACKET_SIZE - header_len; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
585 if (len > payload_size) |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
586 len = payload_size; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
587 stuffing_len = TS_PACKET_SIZE - header_len - len; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
588 if (stuffing_len > 0) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
589 /* add stuffing with AFC */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
590 if (buf[3] & 0x20) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
591 /* stuffing already present: increase its size */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
592 afc_len = buf[4] + 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
593 memmove(buf + 4 + afc_len + stuffing_len, |
885 | 594 buf + 4 + afc_len, |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
595 header_len - (4 + afc_len)); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
596 buf[4] += stuffing_len; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
597 memset(buf + 4 + afc_len, 0xff, stuffing_len); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
598 } else { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
599 /* add stuffing */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
600 memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
601 buf[3] |= 0x20; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
602 buf[4] = stuffing_len - 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
603 if (stuffing_len >= 2) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
604 buf[5] = 0x00; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
605 memset(buf + 6, 0xff, stuffing_len - 2); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
606 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
607 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
608 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
609 memcpy(buf + TS_PACKET_SIZE - len, payload, len); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
610 payload += len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
611 payload_size -= len; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
612 put_buffer(s->pb, buf, TS_PACKET_SIZE); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
613 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
614 put_flush_packet(s->pb); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
615 } |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
616 |
468 | 617 static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
618 { |
468 | 619 AVStream *st = s->streams[pkt->stream_index]; |
620 int size= pkt->size; | |
621 uint8_t *buf= pkt->data; | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
622 MpegTSWriteStream *ts_st = st->priv_data; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
623 int len, max_payload_size; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
624 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
625 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
626 /* for subtitle, a single PES packet must be generated */ |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
627 mpegts_write_pes(s, st, buf, size, pkt->pts, AV_NOPTS_VALUE); |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
628 return 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
629 } |
885 | 630 |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
631 max_payload_size = DEFAULT_PES_PAYLOAD_SIZE; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
632 while (size > 0) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
633 len = max_payload_size - ts_st->payload_index; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
634 if (len > size) |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
635 len = size; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
636 memcpy(ts_st->payload + ts_st->payload_index, buf, len); |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
637 buf += len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
638 size -= len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
639 ts_st->payload_index += len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
640 if (ts_st->payload_pts == AV_NOPTS_VALUE) |
468 | 641 ts_st->payload_pts = pkt->pts; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
642 if (ts_st->payload_dts == AV_NOPTS_VALUE) |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
643 ts_st->payload_dts = pkt->dts; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
644 if (ts_st->payload_index >= max_payload_size) { |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
645 mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index, |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
646 ts_st->payload_pts, ts_st->payload_dts); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
647 ts_st->payload_pts = AV_NOPTS_VALUE; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
648 ts_st->payload_dts = AV_NOPTS_VALUE; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
649 ts_st->payload_index = 0; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
650 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
651 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
652 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
653 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
654 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
655 static int mpegts_write_end(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
656 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
657 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
658 MpegTSWriteStream *ts_st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
659 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
660 AVStream *st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
661 int i; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
662 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
663 /* flush current packets */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
664 for(i = 0; i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
665 st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
666 ts_st = st->priv_data; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
667 if (ts_st->payload_index > 0) { |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
668 mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index, |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
669 ts_st->payload_pts, ts_st->payload_dts); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
670 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
671 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
672 put_flush_packet(s->pb); |
885 | 673 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
674 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
675 service = ts->services[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
676 av_freep(&service->provider_name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
677 av_freep(&service->name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
678 av_free(service); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
679 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
680 av_free(ts->services); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
681 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
682 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
683 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
684 |
1167 | 685 AVOutputFormat mpegts_muxer = { |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
686 "mpegts", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3420
diff
changeset
|
687 NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
688 "video/x-mpegts", |
3420 | 689 "ts,m2t", |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
690 sizeof(MpegTSWrite), |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
691 CODEC_ID_MP2, |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
692 CODEC_ID_MPEG2VIDEO, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
693 mpegts_write_header, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
694 mpegts_write_packet, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
695 mpegts_write_end, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
696 }; |