annotate mpegtsenc.c @ 1067:3d7fae1dfda4 libavformat

skip null fourcc, fix ep2_mystery_m640_dummy.mov
author bcoudurier
date Mon, 01 May 2006 15:52:57 +0000
parents 2177aea28f4f
children d3aff2c607f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 /*
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
2 * MPEG2 transport stream (aka DVB) mux
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 *
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
6 * 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
7 * License as published by the Free Software Foundation; either
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
9 *
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 *
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
15 * You should have received a copy 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
16 * License along with this library; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
17 * 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
18 */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
19 #include "avformat.h"
996
2177aea28f4f generic crc calculation code
michael
parents: 902
diff changeset
20 #include "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
21 #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
22
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
23 /* 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
24
902
5d1bcf01ce28 Properly #ifdef muxer-specific parts.
diego
parents: 896
diff changeset
25 #ifdef CONFIG_MUXERS
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
26 /*********************************************/
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
27 /* 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
28
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
29 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
30 int pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
31 int cc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
32 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
33 void *opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
34 } MpegTSSection;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
35
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
36 /* NOTE: 4 bytes must be left at the end for the crc32 */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
37 void mpegts_write_section(MpegTSSection *s, 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
38 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
39 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
40 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
41 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
42 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
43 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
44
996
2177aea28f4f generic crc calculation code
michael
parents: 902
diff changeset
45 crc = bswap_32(av_crc(av_crc04C11DB7, -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
46 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
47 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
48 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
49 buf[len - 1] = (crc) & 0xff;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
50
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
51 /* 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
52 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
53 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
54 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
55 q = packet;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
56 *q++ = 0x47;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
57 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
58 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
59 b |= 0x40;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
60 *q++ = b;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
61 *q++ = s->pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
62 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
63 *q++ = 0x10 | s->cc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
64 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
65 *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
66 len1 = TS_PACKET_SIZE - (q - packet);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
67 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
68 len1 = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
69 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
70 q += len1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
71 /* 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
72 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
73 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
74 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
75
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
76 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
77
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
78 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
79 len -= len1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
80 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
81 }
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 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
84 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
85 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
86 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
87 *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
88 *q++ = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
89 *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
90 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
91
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
92 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
93 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
94 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
95 {
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 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
97 unsigned int tot_len;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
98
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
99 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
100 /* 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
101 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
102 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
103
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
104 q = section;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
105 *q++ = tid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
106 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
107 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
108 *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
109 *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
110 *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
111 memcpy(q, buf, len);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
112
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
113 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
114 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
115 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
116
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 /* mpegts writer */
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 #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
121 #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
122 #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
123 #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
124
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
125 /* 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
126 #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
127 #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
128 #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
129
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
130 /* 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
131 #define DEFAULT_PES_HEADER_FREQ 16
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
132 #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
133
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
134 /* 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
135 #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
136 #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
137 #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
138
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
139 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
140 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
141 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
142 int cc;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
143 int payload_index;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
144 int64_t payload_pts;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
145 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
146 } MpegTSWriteStream;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
147
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
148 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
149 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
150 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
151 char *name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
152 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
153 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
154 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
155 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
156 } MpegTSService;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
157
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
158 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
159 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
160 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
161 MpegTSService **services;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
162 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
163 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
164 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
165 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
166 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
167 int onid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
168 int tsid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
169 } MpegTSWrite;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
170
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
171 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
172 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
173 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
174 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
175 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
176 int i;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
177
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
178 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
179 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
180 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
181 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
182 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
183 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
184 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
185 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
186 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
187
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
188 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
189 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
190 // 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
191 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
192 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
193
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
194 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
195 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
196
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
197 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
198 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
199
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
200 /* 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
201
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
202 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
203 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
204 program_info_length_ptr[1] = val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
205
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 break;
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_MPEG4:
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_MPEG4;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
216 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
217 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
218 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
219 break;
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_MP2:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
221 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
222 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
223 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
224 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
225 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
226 break;
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_AC3:
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_AC3;
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;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
230 default:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
231 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
232 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
233 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
234 *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
235 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
236 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
237 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
238
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
239 /* 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
240 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
241 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
242 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
243 *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
244 *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
245 *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
246 *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
247 *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
248 *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
249 }
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 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
251 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
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 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
254 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
255 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
256 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
257 *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
258 *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
259 *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
260 *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
261 *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
262 *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
263 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
264 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
265 }
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 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
267 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
268
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
269 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
270 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
271 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
272 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
273 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
274 data, q - data);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
275 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
276
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
277 /* 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
278 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
279 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
280 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
281 int len;
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 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
284 if (!str)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
285 len = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
286 else
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
287 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
288 *q++ = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
289 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
290 q += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
291 *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
292 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
293
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
294 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
295 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
296 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
297 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
298 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
299 int i, running_status, free_ca_mode, val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
300
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
301 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
302 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
303 *q++ = 0xff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
304 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
305 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
306 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
307 *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
308 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
309 q += 2;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
310 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
311 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
312
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
313 /* 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
314 *q++ = 0x48;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
315 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
316 q++;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
317 *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
318 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
319 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
320 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
321
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
322 /* fill descriptor length */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
323 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
324 (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
325 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
326 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
327 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
328 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
329 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
330 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
331
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
332 static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
333 int sid,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
334 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
335 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
336 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
337 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
338
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
339 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
340 if (!service)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
341 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
342 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
343 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
344 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
345 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
346 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
347 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
348 return service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
349 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
350
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
351 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
352 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
353 AVFormatContext *ctx = s->opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
354 put_buffer(&ctx->pb, 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
355 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
356
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
357 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
358 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
359 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
360 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
361 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
362 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
363 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
364 const char *service_name;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
365
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
366 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
367 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
368 /* 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
369 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
370 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
371 service_name = DEFAULT_SERVICE_NAME;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
372 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
373 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
374 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
375 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
376
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
377 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
378 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
379 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
380 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
381
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
382 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
383 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
384 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
385 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
386
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
387 /* 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
388 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
389 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
390 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
391 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
392 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
393 goto fail;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
394 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
395 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
396 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
397 ts_st->payload_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
398 /* update PCR pid by using the first video stream */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
399 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
400 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
401 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
402 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
403 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
404
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
405 /* 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
406 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
407 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
408 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
409 }
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
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
411 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
412 total_bit_rate = 8 * 1024;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
413 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
414 (TS_PACKET_SIZE * 8 * 1000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
415 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
416 (TS_PACKET_SIZE * 8 * 1000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
417 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
418 (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
419 #if 0
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
420 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
421 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
422 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
423
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
424 /* 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
425 find them */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
426 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
427 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
428 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
429 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
430 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
431 put_flush_packet(&s->pb);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
432
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
433 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
434
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
435 fail:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
436 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
437 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
438 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
439 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
440 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
441 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
442
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
443 /* 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
444 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
445 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
446 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
447 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
448
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
449 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
450 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
451 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
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->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
454 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
455 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
456 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
457 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
458 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
459 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
460 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
461
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
462 /* 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
463 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
464 const uint8_t *payload, int payload_size,
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
465 int64_t pts)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
466 {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
467 MpegTSWriteStream *ts_st = st->priv_data;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
468 uint8_t buf[TS_PACKET_SIZE];
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
469 uint8_t *q;
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
470 int val, is_start, len, header_len, write_pcr, private_code;
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
471 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
472 int64_t pcr = -1; /* avoid warning */
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
473
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
474 is_start = 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
475 while (payload_size > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
476 retransmit_si_info(s);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
477
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
478 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
479 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
480 ts_st->service->pcr_packet_count++;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
481 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
482 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
483 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
484 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
485 /* 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
486 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
487 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
488 }
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 }
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
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
491 /* prepare packet header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
492 q = buf;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
493 *q++ = 0x47;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
494 val = (ts_st->pid >> 8);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
495 if (is_start)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
496 val |= 0x40;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
497 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
498 *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
499 *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
500 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
501 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
502 *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
503 *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
504 *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
505 *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
506 *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
507 *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
508 *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
509 *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
510 }
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
511 if (is_start) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
512 /* write PES header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
513 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
514 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
515 *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
516 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
517 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
518 *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
519 } 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
520 (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
521 st->codec->codec_id == CODEC_ID_MP3)) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
522 *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
523 } 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
524 *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
525 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
526 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
527 }
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 (pts != AV_NOPTS_VALUE)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
530 header_len = 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
531 else
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
532 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
533 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
534 header_len++;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
535 len = payload_size + header_len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
536 *q++ = len >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
537 *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
538 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
539 /* 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
540 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
541 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
542 *q++ = val;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
543 if (pts != AV_NOPTS_VALUE) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
544 *q++ = 0x80; /* PTS only */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
545 *q++ = 0x05; /* header len */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
546 val = (0x02 << 4) |
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
547 (((pts >> 30) & 0x07) << 1) | 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
548 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
549 val = (((pts >> 15) & 0x7fff) << 1) | 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
550 *q++ = val >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
551 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
552 val = (((pts) & 0x7fff) << 1) | 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
553 *q++ = val >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
554 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
555 } else {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
556 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
557 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
558 }
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
559 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
560 *q++ = private_code;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
561 is_start = 0;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
562 }
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
563 /* 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
564 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
565 /* 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
566 len = TS_PACKET_SIZE - header_len;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
567 if (len > payload_size)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
568 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
569 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
570 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
571 /* 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
572 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
573 /* 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
574 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
575 memmove(buf + 4 + afc_len + stuffing_len,
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
576 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
577 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
578 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
579 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
580 } 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
581 /* 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
582 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
583 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
584 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
585 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
586 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
587 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
588 }
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 }
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 }
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 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
592 payload += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
593 payload_size -= 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
594 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
595 }
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
596 put_flush_packet(&s->pb);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
597 }
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
598
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
599 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
600 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
601 AVStream *st = s->streams[pkt->stream_index];
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
602 int size= pkt->size;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
603 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
604 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
605 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
606
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
607 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
608 /* for subtitle, a single PES packet must be generated */
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 mpegts_write_pes(s, st, buf, size, pkt->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
610 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
611 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
612
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
613 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
614 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
615 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
616 if (len > size)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
617 len = size;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
618 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
619 buf += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
620 size -= len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
621 ts_st->payload_index += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
622 if (ts_st->payload_pts == AV_NOPTS_VALUE)
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
623 ts_st->payload_pts = pkt->pts;
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
624 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
625 mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
626 ts_st->payload_pts);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
627 ts_st->payload_pts = AV_NOPTS_VALUE;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
628 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
629 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
630 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
631 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
632 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
633
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
634 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
635 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
636 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
637 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
638 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
639 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
640 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
641
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
642 /* 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
643 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
644 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
645 ts_st = st->priv_data;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
646 if (ts_st->payload_index > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
647 mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
648 ts_st->payload_pts);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
649 }
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 put_flush_packet(&s->pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
652
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
653 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
654 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
655 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
656 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
657 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
658 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
659 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
660
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
661 return 0;
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
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
664 AVOutputFormat mpegts_mux = {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
665 "mpegts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
666 "MPEG2 transport stream format",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
667 "video/x-mpegts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
668 "ts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
669 sizeof(MpegTSWrite),
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
670 CODEC_ID_MP2,
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
671 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
672 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
673 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
674 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
675 };
902
5d1bcf01ce28 Properly #ifdef muxer-specific parts.
diego
parents: 896
diff changeset
676 #endif // CONFIG_MUXERS