annotate mpegtsenc.c @ 1175:8b53c0f3e7ad libavformat

add loop_input to AVFormatContext, getting rid of old hack patch by Vctor Paesa <wzrlpy at arsystel com>
author mru
date Thu, 13 Jul 2006 21:13:49 +0000
parents d18cc9a1fd02
children 0899bfe4105c
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
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
25 /*********************************************/
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
26 /* 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
27
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
28 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
29 int pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
30 int cc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
31 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
32 void *opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
33 } MpegTSSection;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
34
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
35 /* NOTE: 4 bytes must be left at the end for the crc32 */
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 996
diff changeset
36 static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
37 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
38 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
39 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
40 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
41 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
42 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
43
996
2177aea28f4f generic crc calculation code
michael
parents: 902
diff changeset
44 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
45 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
46 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
47 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
48 buf[len - 1] = (crc) & 0xff;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
49
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
50 /* 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
51 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
52 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
53 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
54 q = packet;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
55 *q++ = 0x47;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
56 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
57 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
58 b |= 0x40;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
59 *q++ = b;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
60 *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
61 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
62 *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
63 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
64 *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
65 len1 = TS_PACKET_SIZE - (q - packet);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
66 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
67 len1 = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
68 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
69 q += len1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
70 /* 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
71 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
72 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
73 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
74
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
75 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
76
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
77 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
78 len -= len1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
79 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
80 }
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 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
83 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
84 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
85 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
86 *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
87 *q++ = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
88 *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
89 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
90
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 996
diff changeset
91 static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
92 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
93 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
94 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
95 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
96 unsigned int tot_len;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
97
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
98 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
99 /* 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
100 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
101 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
102
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
103 q = section;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
104 *q++ = tid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
105 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
106 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
107 *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
108 *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
109 *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
110 memcpy(q, buf, len);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
111
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
112 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
113 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
114 }
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 /* mpegts writer */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
118
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
119 #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
120 #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
121 #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
122 #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
123
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
124 /* 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
125 #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
126 #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
127 #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
128
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
129 /* 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
130 #define DEFAULT_PES_HEADER_FREQ 16
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
131 #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
132
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
133 /* 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
134 #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
135 #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
136 #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
137
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
138 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
139 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
140 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
141 int cc;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
142 int payload_index;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
143 int64_t payload_pts;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
144 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
145 } MpegTSWriteStream;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
146
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
147 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
148 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
149 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
150 char *name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
151 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
152 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
153 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
154 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
155 } MpegTSService;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
156
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
157 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
158 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
159 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
160 MpegTSService **services;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
161 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
162 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
163 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
164 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
165 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
166 int onid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
167 int tsid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
168 } MpegTSWrite;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
169
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
170 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
171 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
172 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
173 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
174 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
175 int i;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
176
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
177 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
178 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
179 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
180 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
181 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
182 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
183 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
184 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
185 }
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 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
188 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
189 // 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
190 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
191 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
192
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
193 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
194 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
195
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
196 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
197 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
198
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
199 /* 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
200
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
201 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
202 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
203 program_info_length_ptr[1] = val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
204
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
205 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
206 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
207 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
208 switch(st->codec->codec_id) {
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
209 case CODEC_ID_MPEG1VIDEO:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
210 case CODEC_ID_MPEG2VIDEO:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
211 stream_type = STREAM_TYPE_VIDEO_MPEG2;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
212 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
213 case CODEC_ID_MPEG4:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
214 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
215 break;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
216 case CODEC_ID_H264:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
217 stream_type = STREAM_TYPE_VIDEO_H264;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
218 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
219 case CODEC_ID_MP2:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
220 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
221 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
222 break;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
223 case CODEC_ID_AAC:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
224 stream_type = STREAM_TYPE_AUDIO_AAC;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
225 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
226 case CODEC_ID_AC3:
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
227 stream_type = STREAM_TYPE_AUDIO_AC3;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (Mns Rullgrd))
michael
parents: 250
diff changeset
228 break;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
229 default:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
230 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
231 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
232 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
233 *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
234 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
235 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
236 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
237
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
238 /* 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
239 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
240 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
241 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
242 *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
243 *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
244 *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
245 *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
246 *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
247 *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
248 }
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 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
250 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
251 {
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 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
253 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
254 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
255 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
256 *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
257 *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
258 *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
259 *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
260 *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
261 *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
262 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
263 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
264 }
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 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
266 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
267
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
268 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
269 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
270 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
271 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
272 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
273 data, q - data);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
274 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
275
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
276 /* 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
277 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
278 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
279 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
280 int len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
281
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
282 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
283 if (!str)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
284 len = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
285 else
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
286 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
287 *q++ = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
288 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
289 q += 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_ptr = q;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
291 }
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 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
294 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
295 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
296 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
297 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
298 int i, running_status, free_ca_mode, val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
299
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
300 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
301 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
302 *q++ = 0xff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
303 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
304 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
305 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
306 *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
307 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
308 q += 2;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
309 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
310 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
311
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
312 /* 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
313 *q++ = 0x48;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
314 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
315 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++ = 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
317 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
318 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
319 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
320
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
321 /* fill descriptor length */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
322 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
323 (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
324 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
325 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
326 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
327 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
328 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
329 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
330
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
331 static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
332 int sid,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
333 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
334 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
335 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
336 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
337
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
338 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
339 if (!service)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
340 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
341 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
342 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
343 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
344 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
345 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
346 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
347 return service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
348 }
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 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
351 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
352 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
353 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
354 }
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 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
357 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
358 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
359 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
360 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
361 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
362 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
363 const char *service_name;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
364
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
365 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
366 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
367 /* 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
368 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
369 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
370 service_name = DEFAULT_SERVICE_NAME;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
371 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
372 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
373 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
374 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
375
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
376 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
377 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
378 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
379 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
380
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
381 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
382 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
383 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
384 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
385
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
386 /* 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
387 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
388 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
389 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
390 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
391 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
392 goto fail;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
393 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
394 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
395 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
396 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
397 /* update PCR pid by using the first video stream */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
398 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
399 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
400 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
401 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
402 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
403
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
404 /* 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
405 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
406 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
407 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
408 }
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
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
410 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
411 total_bit_rate = 8 * 1024;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
412 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
413 (TS_PACKET_SIZE * 8 * 1000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
414 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
415 (TS_PACKET_SIZE * 8 * 1000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
416 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
417 (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
418 #if 0
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
419 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
420 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
421 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
422
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
423 /* 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
424 find them */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
425 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
426 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
427 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
428 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
429 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
430 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
431
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
432 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
433
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
434 fail:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
435 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
436 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
437 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
438 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
439 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
440 }
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 /* 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
443 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
444 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
445 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
446 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
447
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
448 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
449 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
450 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
451 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
452 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
453 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
454 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
455 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
456 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
457 }
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
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
461 /* 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
462 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
463 const uint8_t *payload, int payload_size,
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
464 int64_t pts)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
465 {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
466 MpegTSWriteStream *ts_st = st->priv_data;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
467 uint8_t buf[TS_PACKET_SIZE];
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
468 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
469 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
470 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
471 int64_t pcr = -1; /* avoid warning */
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
472
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
473 is_start = 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
474 while (payload_size > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
475 retransmit_si_info(s);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
476
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
477 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
478 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
479 ts_st->service->pcr_packet_count++;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
480 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
481 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
482 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
483 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
484 /* 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
485 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
486 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
487 }
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
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
490 /* prepare packet header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
491 q = buf;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
492 *q++ = 0x47;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
493 val = (ts_st->pid >> 8);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
494 if (is_start)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
495 val |= 0x40;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
496 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
497 *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
498 *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
499 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
500 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
501 *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
502 *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
503 *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
504 *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
505 *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
506 *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
507 *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
508 *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
509 }
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
510 if (is_start) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
511 /* write PES header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
512 *q++ = 0x00;
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++ = 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
515 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
516 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
517 *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
518 } 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
519 (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
520 st->codec->codec_id == CODEC_ID_MP3)) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
521 *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
522 } 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
523 *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
524 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
525 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
526 }
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 }
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
528 if (pts != AV_NOPTS_VALUE)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
529 header_len = 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
530 else
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
531 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
532 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
533 header_len++;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
534 len = payload_size + header_len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
535 *q++ = len >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
536 *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
537 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
538 /* 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
539 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
540 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
541 *q++ = val;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
542 if (pts != AV_NOPTS_VALUE) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
543 *q++ = 0x80; /* PTS only */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
544 *q++ = 0x05; /* header len */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
545 val = (0x02 << 4) |
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
546 (((pts >> 30) & 0x07) << 1) | 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
547 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
548 val = (((pts >> 15) & 0x7fff) << 1) | 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
549 *q++ = val >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
550 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
551 val = (((pts) & 0x7fff) << 1) | 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
552 *q++ = val >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
553 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
554 } else {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
555 *q++ = 0x00;
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 }
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
558 if (private_code != 0)
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 *q++ = private_code;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
560 is_start = 0;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
561 }
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
562 /* 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
563 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
564 /* 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
565 len = TS_PACKET_SIZE - header_len;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
566 if (len > payload_size)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
567 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
568 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
569 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
570 /* 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
571 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
572 /* 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
573 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
574 memmove(buf + 4 + afc_len + stuffing_len,
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
575 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
576 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
577 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
578 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
579 } 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
580 /* 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
581 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
582 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
583 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
584 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
585 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
586 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
587 }
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 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
591 payload += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
592 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
593 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
594 }
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
595 put_flush_packet(&s->pb);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
596 }
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
597
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
598 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
599 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
600 AVStream *st = s->streams[pkt->stream_index];
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
601 int size= pkt->size;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
602 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
603 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
604 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
605
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
606 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
607 /* 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
608 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
609 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
610 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
611
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
612 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
613 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
614 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
615 if (len > size)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
616 len = size;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
617 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
618 buf += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
619 size -= len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
620 ts_st->payload_index += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
621 if (ts_st->payload_pts == AV_NOPTS_VALUE)
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
622 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
623 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
624 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
625 ts_st->payload_pts);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
626 ts_st->payload_pts = AV_NOPTS_VALUE;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
627 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
628 }
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 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
631 }
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 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
634 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
635 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
636 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
637 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
638 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
639 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
640
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
641 /* 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
642 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
643 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
644 ts_st = st->priv_data;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
645 if (ts_st->payload_index > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
646 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
647 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
648 }
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 put_flush_packet(&s->pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
651
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
652 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
653 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
654 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
655 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
656 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
657 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
658 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
659
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
660 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
661 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
662
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1124
diff changeset
663 AVOutputFormat mpegts_muxer = {
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
664 "mpegts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
665 "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
666 "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
667 "ts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
668 sizeof(MpegTSWrite),
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
669 CODEC_ID_MP2,
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
670 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
671 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
672 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
673 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
674 };