annotate libmpdemux/muxer_mpeg.c @ 18192:0b77e66a7d32

introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
author nicodvb
date Sat, 22 Apr 2006 15:41:16 +0000
parents 7d83cd632b6b
children f7f6984638f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
1
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2 #include <stdio.h>
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
3 #include <stdlib.h>
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
4 #include <string.h>
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
5 #include <sys/types.h>
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
6
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
7 #include "config.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16750
diff changeset
8 #include "version.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16750
diff changeset
9 #include "mp_msg.h"
17065
cf6bfdf41143 Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents: 17023
diff changeset
10 #include "help_mp.h"
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
11
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
12 #include "bswap.h"
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
13
12341
0db4a3a5b01d removed loader/ dependancy, imported some files from g2, also used patches from Dominik Mierzejewski
alex
parents: 11223
diff changeset
14 #include "aviheader.h"
0db4a3a5b01d removed loader/ dependancy, imported some files from g2, also used patches from Dominik Mierzejewski
alex
parents: 11223
diff changeset
15 #include "ms_hdr.h"
0db4a3a5b01d removed loader/ dependancy, imported some files from g2, also used patches from Dominik Mierzejewski
alex
parents: 11223
diff changeset
16
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
17 #include "muxer.h"
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
18 #include "stream.h"
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
19 #include "demuxer.h"
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
20 #include "stheader.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16750
diff changeset
21 #include "m_option.h"
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
22 #include "mpeg_hdr.h"
17091
rathann
parents: 17066
diff changeset
23 #include "mp3_hdr.h"
rathann
parents: 17066
diff changeset
24 #include "liba52/a52.h"
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
25
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
26 #define PACK_HEADER_START_CODE 0x01ba
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
27 #define SYSTEM_HEADER_START_CODE 0x01bb
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
28 #define PSM_START_CODE 0x01bc
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
29
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
30 #define PES_PRIVATE1 0x01bd
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
31 #define PES_PRIVATE2 0x01bf
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
32
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
33 #define MUX_MPEG1 1
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
34 #define MUX_MPEG2 2
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
35
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
36 #define VIDEO_MPEG1 0x10000001
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
37 #define VIDEO_MPEG2 0x10000002
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
38 #define AUDIO_MP2 0x50
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
39 #define AUDIO_MP3 0x55
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
40 #define AUDIO_A52 0x2000
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
41 #define AUDIO_LPCM 0x10001 /* only a placeholder at the moment */
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
42 #define AUDIO_AAC1 0x706D
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
43 //#define AUDIO_AAC2 (short) mmioFOURCC('m','p','4','a')
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
44 #define AUDIO_AAC2 0x504D
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
45
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
46 #define ASPECT_1_1 1
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
47 #define ASPECT_4_3 2
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
48 #define ASPECT_16_9 3
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
49 #define ASPECT_2_21_1 4
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
50
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
51 #define FRAMERATE_23976 1
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
52 #define FRAMERATE_24 2
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
53 #define FRAMERATE_25 3
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
54 #define FRAMERATE_2997 4
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
55 #define FRAMERATE_30 5
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
56 #define FRAMERATE_50 6
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
57 #define FRAMERATE_5994 7
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
58 #define FRAMERATE_60 8
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
59
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
60 static char ftypes[] = {'?', 'I', 'P', 'B'};
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
61 #define FTYPE(x) (ftypes[(x)])
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
62
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
63
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
64 static const char *framerates[] = {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
65 "unchanged", "23.976", "24", "25", "29.97", "30", "50", "59.94", "60"
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
66 };
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
67
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
68 static const char *aspect_ratios[] = {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
69 "unchanged", "1/1", "4/3", "16/9", "2.21/1"
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
70 };
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
71
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
72 static char *conf_mux = "mpeg2";
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
73 static uint16_t conf_packet_size = 0; //dvd
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
74 static uint32_t conf_muxrate = 0; //kb/s
15083
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
75 static float conf_vaspect = 0;
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
76 static float conf_vframerate = 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
77 static uint32_t conf_vwidth = 0, conf_vheight = 0, conf_panscan_width = 0, conf_panscan_height = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
78 static uint32_t conf_vbitrate = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
79 static int conf_init_vpts = 200, conf_init_apts = 200;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
80 static int conf_ts_allframes = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
81 static int conf_init_adelay = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
82 static int conf_drop = 0;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
83 static int conf_telecine = 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
84
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
85 enum FRAME_TYPE {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
86 I_FRAME = 1,
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
87 P_FRAME = 2,
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
88 B_FRAME = 3
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
89 };
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
90
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
91 typedef struct {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
92 uint8_t *buffer;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
93 size_t size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
94 size_t alloc_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
95 uint8_t type;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
96 uint64_t pts, dts, idur;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
97 uint32_t pos; //start offset for the frame
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
98 } mpeg_frame_t;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
99
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
100 typedef struct {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
101 uint8_t cnt; // how many entries we use
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
102 struct {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
103 uint8_t id, type;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
104 uint32_t bufsize;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
105 uint32_t format;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
106 } streams[50]; //16 video + 16 audio mpa + 16 audio private + bd/bf for dvd
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
107 } sys_info_t;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
108
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
109 typedef struct {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
110 uint8_t cnt; // how many entries we use
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
111 struct {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
112 uint8_t id;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
113 uint8_t type;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
114 uint32_t format;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
115 } streams[50]; //16 video + 16 audio mpa + 16 audio private + bd/bf for dvd
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
116 } psm_info_t;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
117
18183
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
118 typedef struct {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
119 int size;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
120 uint64_t dts;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
121 } buffer_track_t;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
122
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
123 typedef struct {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
124 int mux;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
125 sys_info_t sys_info;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
126 psm_info_t psm_info;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
127 uint16_t packet_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
128 int is_dvd, is_xvcd, is_xsvcd, is_genmpeg1, is_genmpeg2, ts_allframes, has_video, has_audio;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
129 int update_system_header, use_psm;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
130 off_t headers_size, data_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
131 uint64_t scr, vbytes, abytes, init_delay_pts;
18183
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
132 uint64_t delta_scr;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
133 uint32_t muxrate;
17271
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
134 uint8_t *buff, *tmp, *abuf;
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
135 uint32_t headers_cnt;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
136 double init_adelay;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
137 int drop;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
138
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
139 //video patching parameters
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
140 uint8_t vaspect, vframerate;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
141 uint16_t vwidth, vheight, panscan_width, panscan_height;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
142 uint32_t vbitrate;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
143 int patch_seq, patch_sde;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
144 int psm_streams_cnt;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
145 } muxer_priv_t;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
146
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
147
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
148 typedef struct {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
149 int has_pts, has_dts, pes_is_aligned, type, is_late, min_pes_hlen, psm_fixed;
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
150 int real_framerate, delay_rff;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
151 uint64_t pts, last_pts, last_dts, dts, size, frame_duration, delta_pts, nom_delta_pts, frame_size, last_saved_pts;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
152 uint32_t buffer_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
153 uint8_t pes_priv_headers[4], has_pes_priv_headers; //for A52 and LPCM
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
154 uint32_t bitrate, rest;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
155 int32_t compensate;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
156 double delta_clock, timer, aframe_delta_pts, last_dpts;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
157 int drop_delayed_frames;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
158 mpeg_frame_t *framebuf;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
159 uint16_t framebuf_cnt;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
160 uint16_t framebuf_used;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
161 uint16_t max_pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
162 int32_t last_tr;
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
163 int max_tr;
17301
bbf5438d646a removed previously forgotten reording options/flags
nicodvb
parents: 17298
diff changeset
164 uint8_t id, is_mpeg12, telecine;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
165 uint64_t vframes;
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
166 uint8_t trf;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
167 mp_mpeg_header_t picture;
18183
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
168 int max_buffer_size;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
169 buffer_track_t *buffer_track;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
170 int track_pos, track_len, track_bufsize; //pos and len control the array, bufsize is the size of the buffer
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
171 unsigned char *pack;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
172 int pack_offset, pes_offset, pes_set, payload_offset;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
173 int frames;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
174 int last_frame_rest; //the rest of the previous frame
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
175 int is_ready;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
176 } muxer_headers_t;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
177
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
178 #define PULLDOWN32 1
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
179 #define TELECINE_FILM2PAL 2
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
180
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
181 m_option_t mpegopts_conf[] = {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
182 {"format", &(conf_mux), CONF_TYPE_STRING, 0, 0 ,0, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
183 {"size", &(conf_packet_size), CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
184 {"muxrate", &(conf_muxrate), CONF_TYPE_INT, CONF_RANGE, 0, 12000000, NULL}, //12 Mb/s
15083
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
185 {"vaspect", &(conf_vaspect), CONF_TYPE_FLOAT, 0, 0, 0, NULL},
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
186 {"vframerate", &(conf_vframerate), CONF_TYPE_FLOAT, 0, 0, 0, NULL},
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
187 {"vwidth", &(conf_vwidth), CONF_TYPE_INT, CONF_RANGE, 1, 4095, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
188 {"vheight", &(conf_vheight), CONF_TYPE_INT, CONF_RANGE, 1, 4095, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
189 {"vpswidth", &(conf_panscan_width), CONF_TYPE_INT, CONF_RANGE, 1, 16383, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
190 {"vpsheight", &(conf_panscan_height), CONF_TYPE_INT, CONF_RANGE, 1, 16383, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
191 {"vbitrate", &(conf_vbitrate), CONF_TYPE_INT, CONF_RANGE, 1, 104857599, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
192 {"init_vpts", &(conf_init_vpts), CONF_TYPE_INT, CONF_RANGE, 100, 700, NULL}, //2*frametime at 60fps
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
193 {"init_apts", &(conf_init_apts), CONF_TYPE_INT, CONF_RANGE, 100, 700, NULL},
14772
70f0de24b30a renamed init_adelay to vdelay with opposite range
nicodvb
parents: 14753
diff changeset
194 {"vdelay", &conf_init_adelay, CONF_TYPE_INT, CONF_RANGE, 1, 32760, NULL},
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
195 {"drop", &conf_drop, CONF_TYPE_FLAG, 0, 0, 1, NULL},
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
196 {"tsaf", &conf_ts_allframes, CONF_TYPE_FLAG, 0, 0, 1, NULL},
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
197 {"telecine", &conf_telecine, CONF_TYPE_FLAG, 0, 0, PULLDOWN32, NULL},
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
198 {"film2pal", &conf_telecine, CONF_TYPE_FLAG, 0, 0, TELECINE_FILM2PAL, NULL},
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
199 {NULL, NULL, 0, 0, 0, 0, NULL}
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
200 };
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
201
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
202 static void fix_audio_sys_header(muxer_priv_t *priv, uint8_t id, uint8_t newid, uint32_t size)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
203 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
204 uint8_t i;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
205
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
206 for(i = 0; i < priv->sys_info.cnt; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
207 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
208 if(priv->sys_info.streams[i].id == id)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
209 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
210 priv->sys_info.streams[i].id = newid;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
211 priv->sys_info.streams[i].type = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
212 priv->sys_info.streams[i].bufsize = size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
213 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
214 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
215 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
216
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
217 static inline int is_mpeg1(uint32_t x)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
218 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
219 return (
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
220 (x == 0x10000001) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
221 (x == mmioFOURCC('m','p','g','1')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
222 (x == mmioFOURCC('M','P','G','1'))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
223 );
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
224 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
225
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
226 static inline int is_mpeg2(uint32_t x)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
227 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
228 return (
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
229 (x == 0x10000002) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
230 (x == mmioFOURCC('m','p','g','2')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
231 (x == mmioFOURCC('M','P','G','2')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
232 (x == mmioFOURCC('m','p','e','g')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
233 (x == mmioFOURCC('M','P','E','G'))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
234 );
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
235 }
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
236
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
237 static inline int is_mpeg4(uint32_t x)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
238 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
239 return (
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
240 (x == 0x10000004) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
241 (x == mmioFOURCC('d','i','v','x')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
242 (x == mmioFOURCC('D','I','V','X')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
243 (x == mmioFOURCC('x','v','i','d')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
244 (x == mmioFOURCC('X','V','I','D')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
245 (x == mmioFOURCC('X','v','i','D')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
246 (x == mmioFOURCC('x','v','i','x')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
247 (x == mmioFOURCC('X','V','I','X')) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
248 (x == mmioFOURCC('m','p','4','v')) ||
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
249 (x == mmioFOURCC('M','P','4','V')) ||
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
250 (x == mmioFOURCC('F', 'M','P','4')) ||
18164
c692440493c8 added support for DX50 and dx50 4CCs
nicodvb
parents: 18163
diff changeset
251 (x == mmioFOURCC('f', 'm','p','4')) ||
c692440493c8 added support for DX50 and dx50 4CCs
nicodvb
parents: 18163
diff changeset
252 (x == mmioFOURCC('D', 'X','5','0')) ||
c692440493c8 added support for DX50 and dx50 4CCs
nicodvb
parents: 18163
diff changeset
253 (x == mmioFOURCC('d', 'x','5','0'))
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
254 );
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
255 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
256
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
257 //from unrarlib.c
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
258 static uint32_t CalcCRC32(uint8_t *buff, uint32_t size)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
259 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
260 uint32_t i, j, CRCTab[256], crc;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
261
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
262 for(i = 0;i < 256; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
263 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
264 for(crc = i, j = 0; j < 8; j++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
265 crc= (crc & 1) ? (crc >> 1)^0xEDB88320L : (crc >> 1);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
266 CRCTab[i] = crc;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
267 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
268
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
269
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
270 crc = 0xffffffff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
271 for(i = 0; i < size; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
272 crc = (crc << 8) ^ CRCTab[((crc >> 24) ^ buff[i]) & 0xff];
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
273
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
274 return crc;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
275 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
276
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
277
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
278 static void add_to_psm(muxer_priv_t *priv, uint8_t id, uint32_t format)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
279 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
280 uint8_t i;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
281
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
282 i = priv->psm_info.cnt;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
283 priv->psm_info.streams[i].id = id;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
284 priv->psm_info.streams[i].format = format;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
285
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
286 if(is_mpeg1(format))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
287 priv->psm_info.streams[i].type = 0x01;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
288 else if(is_mpeg2(format))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
289 priv->psm_info.streams[i].type = 0x02;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
290 else if(is_mpeg4(format))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
291 priv->psm_info.streams[i].type = 0x10;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
292 else if(format == AUDIO_MP2 || format == AUDIO_MP3)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
293 priv->psm_info.streams[i].type = 0x03;
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
294 else if(format == AUDIO_AAC1 || format == AUDIO_AAC2)
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
295 priv->psm_info.streams[i].type = 0x0f;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
296 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
297 priv->psm_info.streams[i].type = 0x81;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
298
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
299 if(format == AUDIO_A52)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
300 memcpy((char*) &(priv->psm_info.streams[i].format), "AC-3", 4);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
301
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
302 priv->psm_info.cnt++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
303 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
304
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
305
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
306 static mpeg_frame_t *init_frames(uint16_t num, size_t size)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
307 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
308 mpeg_frame_t *tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
309 uint16_t i;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
310
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
311 tmp = (mpeg_frame_t *) calloc(num, sizeof(mpeg_frame_t));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
312 if(tmp == NULL)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
313 return NULL;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
314
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
315 for(i=0; i < num; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
316 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
317 tmp[i].buffer = (uint8_t *) calloc(1, size);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
318 if(tmp[i].buffer == NULL)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
319 return NULL;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
320 tmp[i].size = 0;
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
321 tmp[i].pos = 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
322 tmp[i].alloc_size = size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
323 tmp[i].pts = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
324 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
325
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
326 return tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
327 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
328
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
329 static uint32_t calc_pack_hlen(muxer_priv_t *priv, muxer_headers_t *h);
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
330 static int add_frame(muxer_headers_t *spriv, uint64_t idur, uint8_t *ptr, int len, uint8_t pt, uint64_t dts, uint64_t pts);
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
331
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
332 static muxer_stream_t* mpegfile_new_stream(muxer_t *muxer,int type){
17818
e2f06b46dac0 dereference muxer->priv only after having checked muxer!=NULL in write_chunk(); closes cid 206
nicodvb
parents: 17815
diff changeset
333 muxer_priv_t *priv;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
334 muxer_stream_t *s;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
335 muxer_headers_t *spriv;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
336
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8585
diff changeset
337 if (!muxer) return NULL;
17818
e2f06b46dac0 dereference muxer->priv only after having checked muxer!=NULL in write_chunk(); closes cid 206
nicodvb
parents: 17815
diff changeset
338 priv = (muxer_priv_t*) muxer->priv;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
339 if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
340 mp_msg(MSGT_MUXER, MSGL_ERR, "Too many streams! increase MUXER_MAX_STREAMS !\n");
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
341 return NULL;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
342 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
343 switch (type) {
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
344 case MUXER_TYPE_VIDEO:
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
345 if (muxer->num_videos >= 16) {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
346 mp_msg(MSGT_MUXER, MSGL_ERR, "MPEG files can't contain more than 16 video streams!\n");
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
347 return NULL;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
348 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
349 break;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
350 case MUXER_TYPE_AUDIO:
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
351 if (muxer->num_audios >= 16) {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
352 mp_msg(MSGT_MUXER, MSGL_ERR, "MPEG files can't contain more than 16 audio streams!\n");
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
353 return NULL;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
354 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
355 break;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
356 default:
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
357 mp_msg(MSGT_MUXER, MSGL_ERR, "Unknown stream type!\n");
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
358 return NULL;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
359 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
360 s = (muxer_stream_t*) calloc(1, sizeof(muxer_stream_t));
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
361 if(!s) return NULL; // no mem!?
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
362 if (!(s->b_buffer = malloc(priv->packet_size))) {
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
363 free (s);
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
364 return NULL; // no mem?!
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
365 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
366 s->b_buffer_size = priv->packet_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
367 s->b_buffer_ptr = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
368 s->b_buffer_len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
369 s->priv = (muxer_headers_t*) calloc(1, sizeof(muxer_headers_t));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
370 if(s->priv == NULL) {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
371 free(s);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
372 return NULL;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
373 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
374 spriv = (muxer_headers_t *) s->priv;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
375 muxer->streams[muxer->avih.dwStreams]=s;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
376 s->type=type;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
377 s->id=muxer->avih.dwStreams;
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8585
diff changeset
378 s->muxer=muxer;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
379
11223
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
380 if (type == MUXER_TYPE_VIDEO) {
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
381 spriv->type = 1;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
382 spriv->last_pts = conf_init_vpts * 90 * 300;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
383 spriv->id = 0xe0 + muxer->num_videos;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
384 s->ckid = be2me_32 (0x100 + spriv->id);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
385 if(priv->is_genmpeg1 || priv->is_genmpeg2) {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
386 int n = priv->sys_info.cnt;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
387
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
388 priv->sys_info.streams[n].id = spriv->id;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
389 priv->sys_info.streams[n].type = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
390 priv->sys_info.streams[n].bufsize = (s->h.dwSuggestedBufferSize > 0 ? s->h.dwSuggestedBufferSize : 46*1024);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
391 priv->sys_info.cnt++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
392 }
11223
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
393 muxer->num_videos++;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
394 priv->has_video++;
11223
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
395 s->h.fccType=streamtypeVIDEO;
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
396 if(!muxer->def_v) muxer->def_v=s;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
397 spriv->framebuf_cnt = 30;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
398 spriv->framebuf_used = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
399 spriv->framebuf = init_frames(spriv->framebuf_cnt, (size_t) 5000);
14779
5c82935cb6f0 replace bzero() with memset()
nicodvb
parents: 14772
diff changeset
400 memset(&(spriv->picture), 0, sizeof(spriv->picture));
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
401 if(spriv->framebuf == NULL) {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
402 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't allocate initial frames structure, abort!\n");
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
403 return NULL;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
404 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
405 if(priv->is_xvcd)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
406 spriv->min_pes_hlen = 18;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
407 else if(priv->is_xsvcd)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
408 spriv->min_pes_hlen = 22;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
409 spriv->telecine = conf_telecine;
11223
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
410 mp_msg (MSGT_MUXER, MSGL_DBG2, "Added video stream %d, ckid=%X\n", muxer->num_videos, s->ckid);
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
411 } else { // MUXER_TYPE_AUDIO
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
412 spriv->type = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
413 spriv->pts = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
414 spriv->max_pl_size = priv->packet_size - calc_pack_hlen(priv, spriv);
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
415 spriv->drop_delayed_frames = conf_drop;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
416 spriv->last_pts = conf_init_apts * 90 * 300;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
417 if(conf_init_adelay < 0 && ! spriv->drop_delayed_frames)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
418 spriv->last_pts += (-conf_init_adelay) * 90 * 300;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
419 spriv->pts = spriv->last_pts;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
420 spriv->id = 0xc0 + muxer->num_audios;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
421 s->ckid = be2me_32 (0x100 + spriv->id);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
422 if(priv->is_genmpeg1 || priv->is_genmpeg2) {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
423 int n = priv->sys_info.cnt;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
424
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
425 priv->sys_info.streams[n].id = spriv->id;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
426 priv->sys_info.streams[n].type = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
427 priv->sys_info.streams[n].bufsize = (s->h.dwSuggestedBufferSize > 0 ? s->h.dwSuggestedBufferSize : 4*1024);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
428 priv->sys_info.cnt++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
429 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
430 if(priv->is_xvcd)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
431 spriv->min_pes_hlen = 13;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
432 else if(priv->is_xsvcd)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
433 spriv->min_pes_hlen = 17;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
434
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
435 muxer->num_audios++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
436 priv->has_audio++;
11223
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
437 s->h.fccType=streamtypeAUDIO;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
438
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
439 spriv->framebuf_cnt = 30;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
440 spriv->framebuf_used = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
441 spriv->framebuf = init_frames(spriv->framebuf_cnt, (size_t) 2048);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
442 if(spriv->framebuf == NULL) {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
443 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't allocate initial frames structure, abort!\n");
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
444 return NULL;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
445 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
446
11223
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
447 mp_msg (MSGT_MUXER, MSGL_DBG2, "Added audio stream %d, ckid=%X\n", s->id - muxer->num_videos + 1, s->ckid);
b677b25a898d update by Andriy N. Gritsenko <andrej@lucky.net>
alex
parents: 9007
diff changeset
448 }
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
449 muxer->avih.dwStreams++;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
450 return s;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
451 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
452
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
453 static void write_mpeg_ts(unsigned char *b, uint64_t ts, uint8_t mod) {
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
454 ts /= 300;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
455 b[0] = mod | ((ts >> 29) & 0xf) | 1;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
456 b[1] = (ts >> 22) & 0xff;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
457 b[2] = ((ts >> 14) & 0xff) | 1;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
458 b[3] = (ts >> 7) & 0xff;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
459 b[4] = ((ts << 1) & 0xff) | 1;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
460 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
461
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
462
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
463 static void write_mpeg_rate(int type, unsigned char *b, unsigned int rate)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
464 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
465 rate = (rate+49) / 50;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
466
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
467 if(type == MUX_MPEG1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
468 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
469 b[0] = ((rate >> 15) & 0x7f) | 0x80;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
470 b[1] = (rate >> 7) & 0xff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
471 b[2] = ((rate << 1) & 0xff) | 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
472 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
473 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
474 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
475 b[0] = (rate >> 14);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
476 b[1] = (rate >> 6) & 0xff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
477 b[2] = ((rate & 0x3f) << 2) | 0x03;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
478 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
479 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
480
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
481
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
482 static void write_mpeg_std(unsigned char *b, unsigned int size, unsigned int type, uint8_t mod)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
483 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
484 //type = 0:mpeg audio/128, 1:video and pes private streams (including ac3/dts/lpcm)/1024
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
485 if(type == 0) //audio
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
486 size = (size + 127) / 128;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
487 else //video or other
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
488 size = ((size + 1023) / 1024);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
489
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
490 if(! size)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
491 size++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
492
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
493 b[0] = ((size >> 8) & 0x3f) | (type==1 ? 0x60 : 0x40) | mod;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
494 b[1] = size & 0xff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
495 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
496
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
497 static void write_mpeg2_scr(unsigned char *b, uint64_t ts)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
498 {
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
499 uint16_t t1, t2, t3, scr_ext;
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
500 scr_ext = ts % 300ULL;
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
501 ts /= 300ULL;
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
502 ts &= 0x1FFFFFFFFULL; //33 bits
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
503 t1 = (ts >> 30) & 0x7;;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
504 t2 = (ts >> 15) & 0x7fff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
505 t3 = ts & 0x7fff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
506
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
507 b[0] = (t1 << 3 ) | 0x44 | ((t2 >> 13) & 0x3);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
508 b[1] = (t2 >> 5);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
509 b[2] = (t2 & 0x1f) << 3 | 0x4 | ((t3 >> 13) & 0x3);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
510 b[3] = (t3 >> 5);
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
511 b[4] = (t3 & 0x1f) << 3 | ((scr_ext >> 7) & 0x03) | 0x4;
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
512 b[5] = ((scr_ext << 1) & 0xFF) | 1;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
513 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
514
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
515
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
516 static int write_mpeg_pack_header(muxer_t *muxer, char *buff)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
517 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
518 int len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
519 muxer_priv_t *priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
520
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
521 priv = (muxer_priv_t *) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
522 *(uint32_t *)buff = be2me_32(PACK_HEADER_START_CODE);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
523 if(priv->mux==MUX_MPEG1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
524 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
525 write_mpeg_ts(&buff[4], priv->scr, 0x20); // 0010 and SCR
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
526 write_mpeg_rate(priv->mux, &buff[9], muxer->sysrate);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
527 len = 12;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
528 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
529 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
530 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
531 write_mpeg2_scr(&buff[4], priv->scr); // 0010 and SCR
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
532 write_mpeg_rate(priv->mux, &buff[10], muxer->sysrate);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
533 buff[13] = 0xf8; //5 bits reserved + 3 set to 0 to indicate 0 stuffing bytes
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
534 len = 14;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
535 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
536
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
537 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
538 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
539
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
540
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
541 static int write_mpeg_system_header(muxer_t *muxer, char *buff)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
542 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
543 int len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
544 uint8_t i;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
545 muxer_priv_t *priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
546 priv = (muxer_priv_t *) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
547
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
548 len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
549 *(uint32_t *)(&buff[len]) = be2me_32(SYSTEM_HEADER_START_CODE);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
550 len += 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
551 *(uint16_t *)(&buff[len]) = 0; //fake length, we'll fix it later
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
552 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
553 write_mpeg_rate(MUX_MPEG1, &buff[len], muxer->sysrate);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
554 len += 3;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
555
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
556 buff[len++] = 0x4 | (priv->is_xvcd ? 1 : 0); //1 audio stream bound, no fixed, CSPS only for xvcd
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
557 buff[len++] = 0xe1; //system_audio_lock, system_video_lock, marker, 1 video stream bound
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
558
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
559 buff[len++] = ((priv->mux == MUX_MPEG1) ? 0xff : 0x7f); //in mpeg2 there's the packet rate restriction
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
560
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
561 for(i = 0; i < priv->sys_info.cnt; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
562 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
563 buff[len++] = priv->sys_info.streams[i].id;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
564 write_mpeg_std(&buff[len], priv->sys_info.streams[i].bufsize, priv->sys_info.streams[i].type,
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
565 (priv->sys_info.streams[i].type == 1 ? 0xe0: 0xc0));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
566 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
567 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
568
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
569 *(uint16_t *)(&buff[4]) = be2me_16(len - 6); // length field fixed
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
570
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
571 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
572 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
573
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
574 static int write_mpeg_psm(muxer_t *muxer, char *buff)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
575 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
576 int len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
577 uint8_t i;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
578 uint16_t dlen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
579 muxer_priv_t *priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
580 priv = (muxer_priv_t *) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
581
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
582 len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
583 *(uint32_t *)(&buff[len]) = be2me_32(PSM_START_CODE);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
584 len += 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
585 *(uint16_t *)(&buff[len]) = 0; //fake length, we'll fix it later
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
586 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
587 buff[len++] = 0xe0; //1 current, 2 bits reserved, 5 version 0
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
588 buff[len++] = 0xff; //7 reserved, 1 marker
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
589 buff[len] = buff[len+1] = 0; //length of the program descriptors (unused)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
590 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
591 *(uint16_t *)(&buff[len]) = 0; //length of the es descriptors
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
592 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
593
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
594 dlen = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
595 for(i = 0; i < priv->psm_info.cnt; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
596 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
597 if(
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
598 (priv->psm_info.streams[i].id == 0xbd) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
599 (priv->psm_info.streams[i].id >= 0xe0 && priv->psm_info.streams[i].id <= 0xef) ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
600 (priv->psm_info.streams[i].id >= 0xc0 && priv->psm_info.streams[i].id <= 0xcf)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
601 )
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
602 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
603 buff[len++] = priv->psm_info.streams[i].type;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
604 buff[len++] = priv->psm_info.streams[i].id;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
605 buff[len++] = 0; //len of descriptor upper ...
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
606 buff[len++] = 6; //... lower
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
607
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
608 //registration descriptor
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
609 buff[len++] = 0x5; //tag
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
610 buff[len++] = 4; //length: 4 bytes
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
611 memcpy(&(buff[len]), (char*) &(priv->psm_info.streams[i].format), 4);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
612 len += 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
613 dlen += 10;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
614 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
615 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
616 *(uint16_t *)(&buff[10]) = be2me_16(dlen); //length of the es descriptors
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
617
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
618 *(uint16_t *)(&buff[4]) = be2me_16(len - 6 + 4); // length field fixed, including size of CRC32
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
619
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
620 *(uint32_t *)(&buff[len]) = CalcCRC32(buff, len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
621
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
622 len += 4; //for crc
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
623
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
624 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
625 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
626
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
627 static int write_mpeg_pes_header(muxer_headers_t *h, uint8_t *pes_id, uint8_t *buff, uint16_t plen, int stuffing_len, int mux_type)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
628 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
629 int len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
630
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
631 len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
632 memcpy(&buff[len], pes_id, 4);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
633 len += 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
634
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
635 buff[len] = buff[len+1] = 0; //fake len
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
636 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
637
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
638 if(mux_type == MUX_MPEG1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
639 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
640 if(stuffing_len > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
641 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
642 memset(&buff[len], 0xff, stuffing_len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
643 len += stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
644 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
645
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
646 if(h->buffer_size > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
647 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
648 write_mpeg_std(&buff[len], h->buffer_size, h->type, 0x40); // 01 is pes1 format
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
649 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
650 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
651 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
652 else //MPEG2
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
653 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
654 buff[len] = (h->pes_is_aligned ? 0x84 : 0x80); //0x10...
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
655 len++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
656 buff[len] = ((h->buffer_size > 0) ? 1 : 0) | (h->pts ? (h->dts ? 0xC0 : 0x80) : 0); //pes extension + pts/dts flags
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
657 len++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
658 buff[len] = (h->pts ? (h->dts ? 10 : 5) : 0) + ((h->buffer_size > 0) ? 3 : 0) + stuffing_len;//pts + std + stuffing
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
659 len++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
660 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
661
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
662
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
663 if(h->pts)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
664 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
665 write_mpeg_ts(&buff[len], h->pts, (h->dts ? 0x30 : 0x20)); // 001x and both PTS/DTS
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
666 len += 5;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
667
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
668 if(h->dts)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
669 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
670 write_mpeg_ts(&buff[len], h->dts, 0x10); // 0001 before DTS
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
671 len += 5;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
672 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
673 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
674 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
675 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
676 if(mux_type == MUX_MPEG1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
677 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
678 buff[len] = 0x0f;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
679 len += 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
680 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
681 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
682
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
683
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
684 if(mux_type == MUX_MPEG2)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
685 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
686 if(h->buffer_size > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
687 {
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
688 buff[len] = 0x1e; //std flag
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
689 len++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
690
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
691 write_mpeg_std(&buff[len], h->buffer_size, h->type, 0x40);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
692 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
693 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
694
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
695 if(stuffing_len > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
696 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
697 memset(&buff[len], 0xff, stuffing_len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
698 len += stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
699 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
700 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
701
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
702 if(h->has_pes_priv_headers > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
703 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
704 memcpy(&buff[len], h->pes_priv_headers, h->has_pes_priv_headers);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
705 len += h->has_pes_priv_headers;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
706 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
707
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
708 *((uint16_t*) &buff[4]) = be2me_16(len + plen - 6); //fix pes packet size
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
709 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
710 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
711
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
712
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
713 static void write_pes_padding(uint8_t *buff, uint16_t len)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
714 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
715 //6 header bytes + len-6 0xff chars
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
716 buff[0] = buff[1] = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
717 buff[2] = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
718 buff[3] = 0xbe;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
719 *((uint16_t*) &buff[4]) = be2me_16(len - 6);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
720 memset(&buff[6], 0xff, len - 6);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
721 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
722
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
723 static void write_psm_block(muxer_t *muxer, FILE *f)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
724 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
725 uint16_t offset, stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
726 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
727 uint8_t *buff = priv->buff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
728
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
729 offset = write_mpeg_pack_header(muxer, buff);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
730 offset += write_mpeg_psm(muxer, &buff[offset]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
731 stuffing_len = priv->packet_size - offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
732 if(stuffing_len > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
733 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
734 //insert a PES padding packet
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
735 write_pes_padding(&buff[offset], stuffing_len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
736 offset += stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
737 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
738 fwrite(buff, offset, 1, f);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
739 priv->headers_size += offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
740 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
741
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
742
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
743 static int write_nav_pack(uint8_t *buff)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
744 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
745 // concatenation of pes_private2 + 03d4 x 0 and pes_private2 + 03fa x 0
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
746 int len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
747
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
748 mp_msg(MSGT_MUXER, MSGL_DBG3, "NAV\n");
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
749 len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
750 *(uint32_t *)(&buff[len]) = be2me_32(PES_PRIVATE2);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
751 len += 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
752 buff[len++] = 0x3;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
753 buff[len++] = 0xd4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
754 memset(&buff[len], 0, 0x03d4);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
755 len += 0x03d4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
756
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
757 *(uint32_t *)(&buff[len]) = be2me_32(PES_PRIVATE2);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
758 len += 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
759 buff[len++] = 0x3;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
760 buff[len++] = 0xfa;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
761 memset(&buff[len], 0, 0x03fa);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
762 len += 0x03fa;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
763
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
764 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
765 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
766
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
767 static uint32_t calc_pes_hlen(int format, muxer_headers_t *h, muxer_priv_t *priv)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
768 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
769 uint32_t len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
770
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
771 if(format == MUX_MPEG1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
772 len = 6;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
773 else
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
774 len = 9;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
775
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
776 if(h->pts)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
777 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
778 len += 5;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
779 if(h->dts)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
780 len += 5;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
781 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
782 else if(format == MUX_MPEG1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
783 len += 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
784
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
785 if(h->buffer_size > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
786 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
787 if(format == MUX_MPEG2)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
788 len += 3;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
789 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
790 len += 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
791 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
792
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
793 len += h->has_pes_priv_headers;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
794
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
795 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
796 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
797
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
798 static uint32_t calc_pack_hlen(muxer_priv_t *priv, muxer_headers_t *h)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
799 {
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
800 uint32_t len, x;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
801
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
802 if(priv->mux == MUX_MPEG1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
803 len = 12;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
804 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
805 len = 14;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
806
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
807 /*if((priv->is_genmpeg1 || priv->is_genmpeg2) && priv->update_system_header)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
808 len += (6 + (3*priv->sys_info.cnt));*/
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
809
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
810 x = calc_pes_hlen(priv->mux, h, priv);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
811 if(h->min_pes_hlen > x)
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
812 len += h->min_pes_hlen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
813 else
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
814 len += x;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
815
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
816 return len;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
817 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
818
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
819
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
820 static int write_mpeg_pack(muxer_t *muxer, muxer_stream_t *s, FILE *f, char *bl, uint32_t len, int isoend)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
821 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
822 size_t tot, offset, pes_hlen, pack_hlen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
823 muxer_priv_t *priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
824 uint8_t *buff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
825 int stuffing_len = 0, stflen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
826 muxer_headers_t *spriv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
827
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
828 priv = (muxer_priv_t *) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
829 buff = priv->buff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
830
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
831 if(isoend)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
832 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
833 buff[0] = buff[1] = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
834 buff[2] = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
835 buff[3] = 0xb9;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
836 fwrite(buff, 4, 1, f);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
837 return 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
838 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
839
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
840 if((len == 0) || (bl == NULL)) //PACK headers only
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
841 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
842 offset = write_mpeg_pack_header(muxer, buff);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
843 offset += write_mpeg_system_header(muxer, &buff[offset]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
844
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
845 //priv->update_system_header = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
846
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
847 if(priv->is_dvd)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
848 offset += write_nav_pack(&buff[offset]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
849
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
850 stuffing_len = priv->packet_size - offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
851 if(stuffing_len > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
852 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
853 //insert a PES padding packet
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
854 write_pes_padding(&buff[offset], stuffing_len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
855 offset += stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
856 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
857
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
858 fwrite(buff, offset, 1, f);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
859 priv->headers_size += offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
860 tot = offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
861 muxer->movi_end += tot;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
862
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
863 return tot;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
864 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
865 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
866 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
867 spriv = (muxer_headers_t *) s->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
868
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
869 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nwrite_mpeg_pack(MUX=%d, len=%u, rate=%u, id=%X, pts: %"PRIu64", dts: %"PRIu64", scr: %"PRIu64", PACK_size:%u\n",
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
870 priv->mux, len, muxer->sysrate, s->ckid, spriv->pts, spriv->dts, priv->scr, priv->packet_size);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
871
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
872 //stflen is the count of stuffing bytes in the pes header itself,
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
873 //stuffing_len is the size of the stuffing pes stream (must be at least 7 bytes long)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
874 stflen = stuffing_len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
875 offset = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
876 offset = pack_hlen = write_mpeg_pack_header(muxer, &buff[offset]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
877
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
878 if(priv->update_system_header && (priv->is_genmpeg1 || priv->is_genmpeg2))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
879 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
880 pack_hlen += write_mpeg_system_header(muxer, &buff[offset]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
881 priv->update_system_header = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
882 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
883
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
884 offset = pack_hlen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
885
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
886 pes_hlen = calc_pes_hlen(priv->mux, spriv, priv);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
887 if(spriv->min_pes_hlen > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
888 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
889 if(spriv->min_pes_hlen > pes_hlen)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
890 stflen = spriv->min_pes_hlen - pes_hlen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
891 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
892
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
893 if((len >= priv->packet_size - pack_hlen - max(pes_hlen, spriv->min_pes_hlen)))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
894 stuffing_len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
895 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
896 stuffing_len = priv->packet_size - pack_hlen - max(pes_hlen, spriv->min_pes_hlen) - len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
897
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
898 if(stuffing_len > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
899 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
900 if(stuffing_len < 7)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
901 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
902 if(stflen + stuffing_len > 16)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
903 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
904 int x = 7 - stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
905 stflen -= x;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
906 stuffing_len += x;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
907 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
908 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
909 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
910 stflen += stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
911 stuffing_len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
912 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
913 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
914 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
915
18165
471ccd7705d6 removed skip_padding (never used and totally useless)
nicodvb
parents: 18164
diff changeset
916 len = priv->packet_size - pack_hlen - pes_hlen - stflen - stuffing_len;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
917
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
918 mp_msg(MSGT_MUXER, MSGL_DBG2, "LEN=%d, pack: %d, pes: %d, stf: %d, stf2: %d\n", len, pack_hlen, pes_hlen, stflen, stuffing_len);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
919
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
920 pes_hlen = write_mpeg_pes_header(spriv, (uint8_t *) &s->ckid, &buff[offset], len, stflen, priv->mux);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
921
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
922 offset += pes_hlen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
923
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
924 fwrite(buff, offset, 1, f);
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
925 mp_msg(MSGT_MUXER, MSGL_DBG2, "pack_len = %u, pes_hlen = %u, stuffing_len: %d+%d, SCRIVO: %d bytes di payload\n",
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
926 pack_hlen, pes_hlen, stuffing_len, stflen, len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
927 fwrite(bl, len, 1, f);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
928
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
929 offset += len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
930
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
931 if(stuffing_len > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
932 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
933 //insert a PES padding packet
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
934 mp_msg(MSGT_MUXER, MSGL_DBG2, "STUFFING: %d\n", stuffing_len);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
935 write_pes_padding(buff, stuffing_len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
936 fwrite(buff, stuffing_len, 1, f);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
937 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
938 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
939 stuffing_len = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
940
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
941 offset += stuffing_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
942
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
943 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nwritten len=%d, spriv: pack(%d), pes(%d), stuffing(%d) tot(%d), offset: %d\n",
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
944 len, pack_hlen, pes_hlen, stuffing_len, pack_hlen + pes_hlen + stuffing_len, offset);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
945
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
946 priv->headers_size += pack_hlen + pes_hlen + stuffing_len + stflen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
947 priv->data_size += len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
948 muxer->movi_end += offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
949
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
950 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
951 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
952 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
953
18183
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
954 static int update_demux_bufsize(muxer_headers_t *spriv, uint64_t dts, int framelen, int type)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
955 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
956 int dim = (spriv->track_len+16)*sizeof(buffer_track_t);
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
957
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
958 if(spriv->track_pos+1 >= spriv->track_len)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
959 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
960 buffer_track_t *tmp = realloc(spriv->buffer_track, dim);
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
961 if(!tmp)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
962 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
963 mp_msg(MSGT_MUXER, MSGL_ERR, "\r\nERROR, couldn't realloc %d bytes for tracking buffer\r\n", dim);
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
964 return 0;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
965 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
966 spriv->buffer_track = tmp;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
967 memset(&(spriv->buffer_track[spriv->track_pos+1]), 0, 16*sizeof(buffer_track_t));
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
968 spriv->track_len += 16;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
969 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
970
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
971 spriv->buffer_track[spriv->track_pos].size = framelen;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
972 spriv->buffer_track[spriv->track_pos].dts = dts; //must be dts
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
973
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
974 spriv->track_pos++;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
975 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
976
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
977 static void inline remove_frames(muxer_headers_t *spriv, int n)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
978 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
979 mpeg_frame_t tmp;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
980 int i;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
981
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
982 for(i = n; i < spriv->framebuf_used; i++)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
983 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
984 tmp = spriv->framebuf[i - n];
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
985 spriv->framebuf[i - n] = spriv->framebuf[i];
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
986 spriv->framebuf[i] = tmp;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
987 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
988 spriv->framebuf_used -= n;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
989 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
990
18192
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
991 static int calc_packet_len(muxer_stream_t *s, int psize, int finalize)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
992 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
993 muxer_headers_t *spriv = s->priv;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
994 int n, len, frpos, m;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
995
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
996 n = len = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
997 frpos = spriv->framebuf[0].pos;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
998 while(len < psize && n < spriv->framebuf_used)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
999 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1000 if(!frpos && len>0 && s->type == MUXER_TYPE_VIDEO && spriv->framebuf[n].type==I_FRAME)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1001 return len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1002 m = min(spriv->framebuf[n].size - frpos, psize - len);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1003 len += m;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1004 frpos += m;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1005 if(frpos == spriv->framebuf[n].size)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1006 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1007 frpos = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1008 n++;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1009 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1010 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1011
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1012 if(len < psize && !finalize)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1013 return 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1014 return len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1015 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1016
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1017 static int find_packet_timestamps(muxer_priv_t *priv, muxer_stream_t *s, uint64_t *dts, uint64_t *pts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1018 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1019 muxer_headers_t *spriv = s->priv;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1020 int i, m, pes_hlen, ret, threshold;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1021 uint64_t spts, sdts, dpts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1022
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1023 if(!spriv->framebuf_used)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1024 return 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1025
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1026 spts = spriv->pts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1027 sdts = spriv->dts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1028 spriv->dts = spriv->pts = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1029 ret = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1030 if(spriv->framebuf[0].pos == 0) // start of frame
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1031 i = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1032 else
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1033 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1034 pes_hlen = calc_pes_hlen(priv->mux, spriv, priv);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1035
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1036 if(pes_hlen < spriv->min_pes_hlen)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1037 pes_hlen = spriv->min_pes_hlen;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1038
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1039 m = spriv->framebuf[0].size - spriv->framebuf[0].pos;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1040
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1041 if(spriv->pack_offset + pes_hlen + m >= priv->packet_size)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1042 i = -1; //this pack won't have a pts: no space available
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1043 else
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1044 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1045 if(spriv->framebuf_used < 2)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1046 goto fail;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1047
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1048 if(spriv->framebuf[1].pts == spriv->framebuf[1].dts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1049 threshold = 5;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1050 else
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1051 threshold = 10;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1052
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1053 //headers+frame 0 < space available including timestamps
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1054 if(spriv->pack_offset + pes_hlen + m < priv->packet_size - threshold)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1055 i = 1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1056 else
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1057 i = -1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1058 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1059 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1060
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1061 if(i > -1)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1062 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1063 dpts = max(spriv->last_saved_pts, spriv->framebuf[i].pts) -
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1064 min(spriv->last_saved_pts, spriv->framebuf[i].pts) +
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1065 spriv->framebuf[0].idur;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1066
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1067 if(s->type != MUXER_TYPE_VIDEO)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1068 ret = 1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1069 else if((spriv->framebuf[i].type == I_FRAME || priv->ts_allframes || dpts >= 45000*300)) //0.5 seconds
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1070 ret = 1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1071
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1072 if(ret)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1073 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1074 *pts = spriv->framebuf[i].pts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1075 *dts = spriv->framebuf[i].dts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1076 if(*dts == *pts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1077 *dts = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1078 //spriv->last_saved_pts = spriv->pts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1079 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1080 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1081
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1082 fail:
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1083 spriv->pts = spts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1084 spriv->dts = sdts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1085 return ret;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1086 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1087
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1088
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1089 static int fill_packet(muxer_t *muxer, muxer_stream_t *s, int finalize)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1090 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1091 //try to fill a packet as much as possible
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1092 //spriv->pack_offset is the start position inited to 0
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1093 //data is taken from spriv->framebuf
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1094 //if audio and a52 insert the headers
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1095 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1096 muxer_headers_t *spriv = (muxer_headers_t *) s->priv;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1097 int pes_hlen = 0, len, stflen, stuffing_len, i, m, n, testlen, frpos, dvd_pack = 0, len2, target, hlen;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1098 uint64_t spts, sdts, pts=0, dts=0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1099 mpeg_frame_t *frm;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1100
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1101 spts = spriv->pts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1102 sdts = spriv->dts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1103
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1104 if(! spriv->framebuf_used)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1105 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1106 spriv->pack_offset = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1107 return 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1108 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1109
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1110 if(!spriv->pack_offset)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1111 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1112 spriv->pack_offset = write_mpeg_pack_header(muxer, spriv->pack);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1113 if(priv->update_system_header && (priv->is_genmpeg1 || priv->is_genmpeg2))
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1114 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1115 spriv->pack_offset += write_mpeg_system_header(muxer, &spriv->pack[spriv->pack_offset]);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1116 priv->update_system_header = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1117 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1118 spriv->pes_set = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1119 spriv->pes_offset = spriv->pack_offset;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1120 spriv->payload_offset = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1121 spriv->frames = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1122 spriv->last_frame_rest = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1123 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1124
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1125 if(!spriv->pes_set)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1126 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1127 //search the pts. yes if either it's video && (I-frame or priv->ts_allframes) && framebuf[i].pos == 0
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1128 //or it's audio && framebuf[i].pos == 0
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1129 //NB pts and dts can only be relative to the first frame beginning in this pack
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1130 if((priv->is_xsvcd || priv->is_xvcd) && spriv->size == 0)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1131 spriv->buffer_size = 4*1024;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1132
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1133 if(priv->is_dvd && s->type == MUXER_TYPE_VIDEO
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1134 && spriv->framebuf[0].type==I_FRAME && spriv->framebuf[0].pos==0)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1135 dvd_pack = 1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1136
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1137 spriv->dts = spriv->pts = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1138 if(find_packet_timestamps(priv, s, &dts, &pts))
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1139 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1140 spriv->pts = pts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1141 spriv->dts = dts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1142 spriv->last_saved_pts = pts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1143 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1144
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1145 pes_hlen = calc_pes_hlen(priv->mux, spriv, priv);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1146 stflen = (spriv->min_pes_hlen > pes_hlen ? spriv->min_pes_hlen - pes_hlen : 0);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1147
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1148 target = len = priv->packet_size - spriv->pack_offset - pes_hlen - stflen; //max space available
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1149 if(s->type == MUXER_TYPE_AUDIO && s->wf->wFormatTag == AUDIO_A52)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1150 hlen = 4;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1151 else
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1152 hlen = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1153
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1154 len -= hlen;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1155 target -= hlen;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1156
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1157 len2 = calc_packet_len(s, target, finalize);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1158 if(!len2)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1159 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1160 spriv->pack_offset = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1161 return 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1162 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1163 if(len2 < target)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1164 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1165 if(s->type == MUXER_TYPE_AUDIO && !finalize)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1166 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1167 spriv->pack_offset = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1168 spriv->pts = spts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1169 spriv->dts = sdts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1170 return 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1171 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1172 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1173 len = len2;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1174 stuffing_len = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1175 if(len < target)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1176 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1177 if(s->type == MUXER_TYPE_VIDEO) //FIXME: check i_frame
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1178 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1179 if(spriv->pts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1180 target += 5;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1181 if(spriv->dts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1182 target += 5;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1183 spriv->pts = spriv->dts = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1184 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1185
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1186 stuffing_len = target - len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1187 if(stuffing_len > 0 && stuffing_len < 7)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1188 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1189 if(stflen + stuffing_len > 16)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1190 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1191 int x = 7 - stuffing_len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1192 stflen -= x;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1193 stuffing_len += x;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1194
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1195 /*int x = stflen + stuffing_len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1196 stflen = 16;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1197 stuffing_len = x - stflen;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1198 */
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1199 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1200 else
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1201 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1202 stflen += stuffing_len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1203 stuffing_len = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1204 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1205 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1206 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1207
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1208 len += hlen;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1209 spriv->pack_offset += write_mpeg_pes_header(spriv, (uint8_t *) &s->ckid, &(spriv->pack[spriv->pack_offset]),
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1210 len, stflen, priv->mux);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1211
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1212 if(s->type == MUXER_TYPE_AUDIO && s->wf->wFormatTag == AUDIO_A52)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1213 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1214 spriv->payload_offset = spriv->pack_offset;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1215 spriv->pack_offset += 4; //for the 4 bytes of header
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1216 if(!spriv->framebuf[0].pos)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1217 spriv->last_frame_rest = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1218 else
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1219 spriv->last_frame_rest = spriv->framebuf[0].size - spriv->framebuf[0].pos;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1220 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1221
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1222 spriv->pes_set = 1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1223 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1224
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1225
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1226 if(spriv->dts || spriv->pts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1227 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1228 if((spriv->dts && priv->scr >= spriv->dts) || priv->scr >= spriv->pts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1229 mp_msg(MSGT_MUXER, MSGL_ERR, "\r\nERROR: scr %.3lf, dts %.3lf, pts %.3lf\r\n", (double) priv->scr/27000000.0, (double) spriv->dts/27000000.0, (double) spriv->pts/27000000.0);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1230 else if(priv->scr + 63000*300 < spriv->dts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1231 mp_msg(MSGT_MUXER, MSGL_INFO, "\r\nWARNING>: scr %.3lf, dts %.3lf, pts %.3lf, diff %.3lf, piff %.3lf\r\n", (double) priv->scr/27000000.0, (double) spriv->dts/27000000.0, (double) spriv->pts/27000000.0, (double)(spriv->dts - priv->scr)/27000000.0, (double)(spriv->pts - priv->scr)/27000000.0);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1232 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1233
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1234 n = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1235 len = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1236 testlen = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1237
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1238 frm = spriv->framebuf;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1239 while(spriv->pack_offset < priv->packet_size && n < spriv->framebuf_used)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1240 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1241 if(!frm->pos)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1242 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1243 //since iframes must always be aligned at block boundaries exit when we find the
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1244 //beginning of one in the middle of the flush
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1245 if(len > 0 && s->type == MUXER_TYPE_VIDEO && frm->type == I_FRAME)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1246 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1247 testlen = len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1248 break;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1249 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1250 spriv->frames++;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1251 update_demux_bufsize(spriv, frm->dts, frm->size, s->type);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1252 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1253
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1254 m = min(frm->size - frm->pos, priv->packet_size - spriv->pack_offset);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1255 memcpy(&(spriv->pack[spriv->pack_offset]), &(frm->buffer[frm->pos]), m);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1256
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1257 len += m;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1258 spriv->pack_offset += m;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1259 frm->pos += m;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1260
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1261 if(frm->pos == frm->size) //end of frame
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1262 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1263 frm->pos = frm->size = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1264 frm->pts = frm->dts = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1265 n++;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1266 frm++;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1267 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1268 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1269
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1270 if((priv->is_xsvcd || priv->is_xvcd) && spriv->size == 0)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1271 spriv->buffer_size = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1272
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1273 spriv->size += len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1274
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1275 if(dvd_pack && (spriv->pack_offset == priv->packet_size))
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1276 write_mpeg_pack(muxer, s, muxer->file, NULL, 0, 0); //insert fake Nav Packet
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1277
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1278 if(n > 0)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1279 remove_frames(spriv, n);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1280
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1281 spriv->track_bufsize += len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1282 if(spriv->track_bufsize > spriv->max_buffer_size)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1283 mp_msg(MSGT_MUXER, MSGL_ERR, "\r\nBUFFER OVERFLOW: %d > %d\r\n", spriv->track_bufsize, spriv->max_buffer_size);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1284
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1285 if(s->type == MUXER_TYPE_AUDIO && s->wf->wFormatTag == AUDIO_A52)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1286 fix_a52_headers(s);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1287
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1288 if(spriv->pack_offset < priv->packet_size) //here finalize is set
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1289 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1290 int diff = priv->packet_size - spriv->pack_offset;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1291 write_pes_padding(&(spriv->pack[spriv->pack_offset]), diff);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1292 spriv->pack_offset += diff;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1293 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1294
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1295 fwrite(spriv->pack, spriv->pack_offset, 1, muxer->file);
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1296
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1297 priv->headers_size += spriv->pack_offset - len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1298 priv->data_size += len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1299 muxer->movi_end += spriv->pack_offset;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1300
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1301 spriv->pack_offset = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1302 spriv->pes_set = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1303 spriv->frames = 0;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1304
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1305 spriv->pts = spts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1306 spriv->dts = sdts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1307
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1308 return len;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1309 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1310
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1311 static inline int find_best_stream(muxer_t *muxer)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1312 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1313 int i, ndts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1314 uint64_t dts = -1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1315 muxer_priv_t *priv = muxer->priv;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1316 muxer_headers_t *spriv;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1317
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1318 ndts = -1;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1319
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1320 //MUST ALWAYS apply: [pd]ts < SCR + 0.7 seconds
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1321 //FIXME: find pack_dts and pack_len instead, for the time being the code below is still reasonable
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1322 for(i = 0; i < muxer->avih.dwStreams; i++)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1323 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1324 spriv = muxer->streams[i]->priv;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1325
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1326 if(! spriv->framebuf_used || spriv->track_bufsize + priv->packet_size - 20 > spriv->max_buffer_size)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1327 continue;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1328 //59000 ~= 0.7 seconds - max(frame_duration) (<42 ms at 23.976 fps)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1329 if(spriv->framebuf[0].pts > priv->scr + 59000*300)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1330 continue;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1331
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1332 if(spriv->framebuf[0].dts <= dts)
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1333 {
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1334 dts = spriv->framebuf[0].dts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1335 ndts = i;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1336 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1337 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1338
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1339 return ndts;
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1340 }
0b77e66a7d32 introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents: 18187
diff changeset
1341
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1342 static void patch_seq(muxer_priv_t *priv, unsigned char *buf)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1343 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1344 if(priv->vwidth > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1345 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1346 buf[4] = (priv->vwidth >> 4) & 0xff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1347 buf[5] &= 0x0f;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1348 buf[5] |= (priv->vwidth & 0x0f) << 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1349 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1350
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1351 if(priv->vheight > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1352 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1353 buf[5] &= 0xf0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1354 buf[5] |= (priv->vheight >> 8) & 0x0f;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1355 buf[6] = priv->vheight & 0xff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1356 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1357
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1358 if(priv->vaspect > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1359 buf[7] = (buf[7] & 0x0f) | (priv->vaspect << 4);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1360
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1361 if(priv->vframerate > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1362 buf[7] = (buf[7] & 0xf0) | priv->vframerate;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1363
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1364 if(priv->vbitrate > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1365 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1366 buf[8] = (priv->vbitrate >> 10);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1367 buf[9] = (priv->vbitrate >> 2);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1368 buf[10] = (buf[10] & 0x3f) | (unsigned char) ((priv->vbitrate & 0x4) << 2);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1369 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1370 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1371
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1372 static void patch_panscan(muxer_priv_t *priv, unsigned char *buf)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1373 { //patches sequence display extension (display_horizontal_size and display_vertical_size)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1374 //1:
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1375 int offset = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1376
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1377 if(buf[0] & 0x01)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1378 offset += 3;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1379
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1380 if(priv->panscan_width > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1381 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1382 buf[offset] = (priv->panscan_width >> 6);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1383 buf[offset+1] = ((priv->panscan_width & 0x3F) << 2) | (buf[offset + 1] & 0x03);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1384 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1385
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1386 offset++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1387
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1388 if(priv->panscan_height > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1389 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1390 buf[offset] = (priv->panscan_height >> 13) << 7;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1391 buf[offset+1] = (priv->panscan_height >> 5) & 0xFF;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1392 buf[offset+2] = ((priv->panscan_height & 0x1F) << 3) | (buf[offset+2] & 0x07);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1393 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1394 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1395
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1396
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1397 #define max(a, b) ((a) >= (b) ? (a) : (b))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1398 #define min(a, b) ((a) <= (b) ? (a) : (b))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1399
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1400
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1401 static uint32_t dump_audio(muxer_t *muxer, muxer_stream_t *as, uint32_t abytes, int force)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1402 {
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1403 uint32_t len = 0, tlen, sz;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1404 uint64_t num_frames = 0, next_pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1405 uint16_t rest;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1406 int64_t tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1407 double delta_pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1408 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1409 muxer_headers_t *apriv = (muxer_headers_t*) as->priv;
17540
a04406156eab removed unused variables
nicodvb
parents: 17539
diff changeset
1410 uint32_t j, k, l, n;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1411 mpeg_frame_t *frm , frm2;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1412
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1413 tlen = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1414 for(j = 0; j < apriv->framebuf_used; j++)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1415 tlen += apriv->framebuf[j].size - apriv->framebuf[j].pos;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1416
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1417 abytes = min(abytes, tlen); //available bytes
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1418 if(! abytes)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1419 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1420
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1421 if(as->ckid == be2me_32(0x1bd))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1422 apriv->has_pes_priv_headers = 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1423 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1424 apriv->has_pes_priv_headers = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1425
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1426 rest = apriv->framebuf[0].pos;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1427 sz = priv->packet_size - calc_pack_hlen(priv, apriv); //how many payload bytes we are about to write
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1428 if(abytes < sz && !force)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1429 return 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1430 sz = min(sz, abytes);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1431 num_frames = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1432 tlen = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1433 next_pts = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1434 for(j = 0; j < apriv->framebuf_used; j++)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1435 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1436 frm = &(apriv->framebuf[j]);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1437 k = min(frm->size - frm->pos, sz - tlen);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1438 tlen += k;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1439 if(!frm->pos)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1440 num_frames++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1441 if(!frm->pos && !next_pts)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1442 next_pts = frm->pts;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1443 if(tlen == sz)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1444 break;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1445 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1446
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1447 if(tlen < sz && !force)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1448 return 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1449
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1450 if(!next_pts && force)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1451 next_pts = apriv->last_pts;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1452 apriv->last_dts = apriv->pts;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1453 apriv->pts = next_pts;
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
1454 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nAUDIO: tot=%"PRIu64", sz=%u bytes, FRAMES: %"PRIu64" * %u, REST: %u, DELTA_PTS: %u\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1455 apriv->size, sz, num_frames, (uint32_t) apriv->frame_size, (uint32_t) rest, (uint32_t) ((num_frames * apriv->delta_pts) / 300));
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1456
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1457 if(((priv->scr + (63000*300)) < next_pts) && (priv->scr < apriv->pts) && (! force))
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1458 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1459 apriv->is_late = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1460 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1461 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1462
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1463 n = 0; //number of complete frames
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1464 tlen = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1465 for(j = 0; j < apriv->framebuf_used; j++)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1466 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1467 int frame_size;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1468
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1469 frm = &(apriv->framebuf[j]);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1470 frame_size = frm->size - frm->pos;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1471 l = min(sz - tlen, frame_size);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1472
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1473 memcpy(&(priv->abuf[tlen]), &(frm->buffer[frm->pos]), l);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1474 tlen += l;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1475 if(l < frame_size) //there are few bytes still to write
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1476 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1477 frm->pos += l;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1478 break;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1479 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1480 else
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1481 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1482 frm->pos = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1483 frm->size = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1484 n++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1485 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1486 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1487
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1488 if(num_frames)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1489 apriv->frame_size = tlen/num_frames;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1490 else
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1491 apriv->frame_size = tlen;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1492
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1493 if(n)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1494 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1495 for(j = n; j < apriv->framebuf_used; j++)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1496 {
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
1497 apriv->framebuf[j - n].size = apriv->framebuf[j - n].pos = 0;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1498 frm2 = apriv->framebuf[j - n];
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1499 apriv->framebuf[j - n] = apriv->framebuf[j];
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1500 apriv->framebuf[j] = frm2;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1501 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1502 apriv->framebuf_used -= n;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1503 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1504
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1505
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1506 if(as->ckid == be2me_32(0x1bd))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1507 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1508 apriv->pes_priv_headers[0] = 0x80;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1509 apriv->pes_priv_headers[1] = num_frames;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1510 apriv->pes_priv_headers[2] = ((rest+1) >> 8) & 0xff; //256 * 0 ...
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1511 apriv->pes_priv_headers[3] = (rest+1) & 0xff; // + 1 byte(s) to skip
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1512 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1513
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1514 if((priv->is_xsvcd || priv->is_xvcd) && apriv->size == 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1515 apriv->buffer_size = 4*1024;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1516
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1517 len = write_mpeg_pack(muxer, as, muxer->file, priv->abuf, tlen, 0);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1518
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1519 if((priv->is_xsvcd || priv->is_xvcd) && apriv->size == 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1520 apriv->buffer_size = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1521
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1522 apriv->size += len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1523
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1524 tmp = apriv->pts - priv->scr;
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1525 if((abs(tmp) > (63000*300)) || (apriv->pts <= priv->scr))
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1526 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1527 double d;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1528
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1529 if(tmp > 0)
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1530 tmp = tmp - (63000*300);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1531
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1532 d = -tmp / 27000000.0;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1533 d *= apriv->bitrate;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1534 apriv->compensate = (int32_t) d;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1535
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1536 if((tmp) > 27000000) //usually up to 1 second it still acceptable
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1537 mp_msg(MSGT_MUXER, MSGL_ERR, "\nWARNING: SCR: << APTS, DELTA=%.3lf secs, COMPENSATE=%d, BR: %d\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1538 (((double) tmp)/27000000.0), apriv->compensate, apriv->bitrate);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1539 else if(apriv->pts < priv->scr)
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
1540 mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR: SCR: %"PRIu64", APTS: %"PRIu64", DELTA=-%.3lf secs, COMPENSATE=%d, BR: %d, lens: %d/%d, frames: %d\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1541 priv->scr, apriv->pts, (double) ((priv->scr - apriv->pts)/27000000.0), apriv->compensate, apriv->bitrate, tlen, len, n);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1542 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1543
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
1544 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nWRITTEN AUDIO: %u bytes, TIMER: %.3lf, FRAMES: %"PRIu64" * %u, DELTA_PTS: %.3lf\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1545 len, (double) (apriv->pts/27000000), num_frames, (uint32_t) apriv->frame_size, delta_pts);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1546
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1547 return len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1548 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1549
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1550 static inline void update_scr(muxer_priv_t *priv, uint32_t len, uint32_t totlen, double mult)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1551 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1552 uint64_t delta_scr;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1553 double perc;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1554
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1555 perc = (double) len / (double) totlen;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1556
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1557 delta_scr = (uint64_t) (mult * perc);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1558 priv->scr += delta_scr;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1559
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
1560 mp_msg(MSGT_MUXER, MSGL_DBG2, "UPDATE SCR TO %"PRIu64" (%.3lf): mult is %.3lf, perc: %.3lf, %u/%u, delta: %"PRIu64"\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1561 priv->scr, (double) (priv->scr/27000000.0), mult, perc, len, totlen, delta_scr);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1562 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1563
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1564
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1565 static int calc_frames_to_flush(muxer_headers_t *vpriv)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1566 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1567 int n, found = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1568
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1569 if(vpriv->framebuf_used > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1570 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1571 n = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1572 //let's count how many frames we'll store in the next pack sequence
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
1573 mp_msg(MSGT_MUXER, MSGL_DBG2, "\n");
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1574 while(n < vpriv->framebuf_used)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1575 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
1576 mp_msg(MSGT_MUXER, MSGL_DBG2, "n=%d, type=%c\n", n, FTYPE(vpriv->framebuf[n].type));
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1577 if(n+1 < vpriv->framebuf_used)
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
1578 mp_msg(MSGT_MUXER, MSGL_DBG2, "n+1=%d, type=%c\n", n+1, FTYPE(vpriv->framebuf[n+1].type));
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1579
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1580 if(vpriv->framebuf[n].type == I_FRAME)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1581 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1582 if(n > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1583 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1584 found = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1585 break;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1586 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1587 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1588
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1589 n++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1590 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1591 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1592
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1593 if(found && (n < vpriv->framebuf_used+1))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1594 return n;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1595 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1596 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1597 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1598
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1599
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
1600
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1601 static void check_pts(muxer_priv_t *priv, muxer_headers_t *vpriv, int i)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1602 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1603 uint64_t dpts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1604
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1605 dpts = max(vpriv->last_saved_pts, vpriv->pts) - min(vpriv->last_saved_pts, vpriv->pts);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1606 dpts += vpriv->framebuf[i].idur;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1607
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1608 if((!priv->ts_allframes) && (
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1609 (priv->is_dvd && (vpriv->framebuf[i].type != I_FRAME)) ||
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1610 ((priv->is_genmpeg1 || priv->is_genmpeg2) && (vpriv->framebuf[i].type != I_FRAME) && (dpts < 63000*300))) //0.7 seconds
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1611 )
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1612 vpriv->pts = vpriv->dts = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1613
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1614 if(vpriv->dts && ((vpriv->dts < priv->scr) || (vpriv->pts <= vpriv->dts)))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1615 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1616 mp_msg(MSGT_MUXER, MSGL_V, "\nWARNING, SCR: %.3lf, DTS: %.3lf, PTS: %.3lf\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1617 (double) priv->scr/27000000.0,(double) vpriv->dts/27000000.0, (double) vpriv->pts/27000000.0);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1618 vpriv->dts = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1619 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1620
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1621 if(vpriv->pts && (vpriv->pts <= priv->scr))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1622 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1623 mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: SCR: %.3lf, VPTS: %.3lf, DELTA=-%.3lf secs\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1624 (double) (priv->scr/27000000.0), (double)(vpriv->pts/27000000.0), (double) ((priv->scr - vpriv->pts)/27000000.0));
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1625 vpriv->pts = vpriv->dts = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1626 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1627
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1628 if(vpriv->pts)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1629 vpriv->last_saved_pts = vpriv->pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1630 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1631
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1632 static uint32_t calc_audio_chunk_size(muxer_stream_t *as, double duration, int finalize)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1633 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1634 muxer_headers_t *apriv;
17540
a04406156eab removed unused variables
nicodvb
parents: 17539
diff changeset
1635 uint32_t div, rest, abytes, available;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1636 double adur;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1637 uint64_t iaduration;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1638 int i;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1639
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1640 apriv = (muxer_headers_t*) as->priv;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1641
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1642 iaduration = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1643 adur = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1644 available = abytes = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1645 for(i = 0; i < apriv->framebuf_used; i++)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1646 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1647 if(adur < duration)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1648 abytes += apriv->framebuf[i].size - apriv->framebuf[i].pos;
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1649 adur += (double)(apriv->framebuf[i].idur/27000000.0);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1650 available += apriv->framebuf[i].size - apriv->framebuf[i].pos;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1651 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1652
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1653
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1654 if(adur < duration && !finalize)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1655 return 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1656
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1657 if(abytes > apriv->compensate)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1658 abytes -= apriv->compensate;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1659 div = abytes / apriv->max_pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1660 rest = abytes % apriv->max_pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1661 if(apriv->compensate > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1662 abytes = apriv->max_pl_size * (div - 1);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1663 else if(apriv->compensate < 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1664 abytes = apriv->max_pl_size * (div + 1);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1665 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1666 abytes = apriv->max_pl_size * (rest ? div + 1 : div);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1667 apriv->compensate = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1668
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1669 while(abytes > available)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1670 abytes -= apriv->max_pl_size;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1671
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1672 if(finalize)
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1673 abytes = available;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1674
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1675 return abytes;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
1676 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
1677
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1678 static int flush_buffers(muxer_t *muxer, int finalize)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1679 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1680 int i, n, pl_size, found;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1681 size_t saved;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1682 uint32_t abytes, vbytes, bytes = 0, frame_bytes = 0, audio_rest = 0, tot = 0, muxrate;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1683 uint32_t offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1684 uint64_t idur, init_delay = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1685 muxer_stream_t *s, *vs, *as;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1686 muxer_headers_t *vpriv = NULL, *apriv = NULL;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1687 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1688 uint8_t *tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1689 double mult, duration;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1690 uint64_t iduration;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1691 mpeg_frame_t temp_frame;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1692
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1693 /*
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1694 analyzes all streams and decides what to flush
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1695 trying to respect an interleaving distribution
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1696 equal to the v_bitrate/a_bitrate proportion
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1697 */
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1698 init:
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1699 n = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1700 vs = as = NULL;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1701 abytes = vbytes = found = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1702 for(i = 0; i < muxer->avih.dwStreams; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1703 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1704 s = muxer->streams[i];
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1705 if(s->type == MUXER_TYPE_VIDEO)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1706 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1707 vs = muxer->streams[i];
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1708 vpriv = (muxer_headers_t*) vs->priv;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
1709 if(!vpriv->is_ready)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
1710 return 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1711 n = found = calc_frames_to_flush(vpriv);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1712 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1713 else if(s->type == MUXER_TYPE_AUDIO)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1714 as = s;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1715 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1716
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1717 if((! found) && finalize)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1718 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1719 if(vpriv != NULL)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1720 found = n = vpriv->framebuf_used;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1721 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1722
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1723 if(found)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1724 {
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
1725 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nVIDEO, FLUSH %d frames (of %d), 0 to %d\n", n, vpriv->framebuf_used, n-1);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1726
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1727 tmp = priv->tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1728 vbytes = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1729 vpriv = (muxer_headers_t*) vs->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1730
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1731 duration = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1732 iduration = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1733 for(i = 0; i < n; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1734 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1735 vbytes += vpriv->framebuf[i].size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1736 iduration += vpriv->framebuf[i].idur;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1737 }
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1738 duration = (double) (iduration / 27000000.0);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1739
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
1740 init_delay = 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1741
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1742 if(as != NULL)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1743 {
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1744 uint32_t available, i;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1745
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1746 apriv = (muxer_headers_t*) as->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1747 abytes = calc_audio_chunk_size(as, duration, finalize);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1748 if(! abytes)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1749 return 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1750 for(i = 0; i < apriv->framebuf_used; i++)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1751 available += apriv->framebuf[i].size - apriv->framebuf[i].pos;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1752
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1753 if((abytes / apriv->max_pl_size) > n)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1754 audio_rest = (abytes - (apriv->max_pl_size * n)) / n;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1755 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1756 audio_rest = 0;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1757
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1758 if(available < abytes && !finalize)
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1759 {
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
1760 mp_msg(MSGT_MUXER, MSGL_DBG2, "Not enough audio data (%u < %u), exit\n", available, abytes);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1761 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1762 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1763 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1764
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1765 if((as != NULL) && (init_delay > 0))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1766 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1767 if(apriv->size == 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1768 apriv->pts += init_delay;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1769 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1770
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1771 saved = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1772 bytes = vbytes + abytes;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1773 muxrate = (uint32_t) ((double) bytes/duration);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1774 if(muxrate > muxer->sysrate && (priv->is_genmpeg1 || priv->is_genmpeg2))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1775 {
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
1776 mp_msg(MSGT_MUXER, MSGL_DBG3, "NEW MUXRATE: %u -> %u\n", muxrate, muxer->sysrate);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1777 muxer->sysrate = muxrate;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1778 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1779
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1780 idur = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1781 offset = 0;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
1782 priv->scr = vpriv->framebuf[0].dts - vpriv->framebuf[0].idur;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1783
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1784 if((priv->is_xvcd || priv->is_xsvcd) && (vpriv->size == 0))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1785 vpriv->buffer_size = (priv->is_xvcd ? 46 : 230)*1024;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1786
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1787 i = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1788 while(i < n)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1789 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1790 int frame_begin = 1, update;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1791 uint32_t pl_size = 0, target_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1792 uint8_t *buf;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1793
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1794 vpriv->pts = vpriv->framebuf[i].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1795 vpriv->dts = vpriv->framebuf[i].dts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1796 check_pts(priv, vpriv, i);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1797
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1798 if(priv->is_dvd && (vpriv->framebuf[i].type == I_FRAME) && (offset == 0))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1799 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1800 write_mpeg_pack(muxer, NULL, muxer->file, NULL, 0, 0); //insert fake Nav Packet
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1801 vpriv->pes_is_aligned = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1802 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1803
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1804 offset = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1805 vbytes = vpriv->framebuf[i].size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1806 while(vbytes > 0 && (i < n))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1807 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1808 target_size = priv->packet_size - calc_pack_hlen(priv, vpriv);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1809 if((vbytes >= target_size) || ((vbytes < target_size) && (i == n-1)))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1810 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1811 buf = &(vpriv->framebuf[i].buffer[offset]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1812 pl_size = vbytes;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1813 update = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1814 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1815 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1816 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1817 uint32_t tmp_offset = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1818
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1819 if(offset == 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1820 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1821 vpriv->pts = vpriv->framebuf[i].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1822 vpriv->dts = vpriv->framebuf[i].dts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1823 check_pts(priv, vpriv, i);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1824 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1825 else if(i < n-1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1826 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1827 vpriv->pts = vpriv->framebuf[i+1].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1828 vpriv->dts = vpriv->framebuf[i+1].dts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1829 check_pts(priv, vpriv, i+1);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1830 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1831 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1832 vpriv->pts = vpriv->dts = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1833
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1834 target_size = priv->packet_size - calc_pack_hlen(priv, vpriv); //it was only priv->packet_size
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1835 update = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1836
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1837 while((tmp_offset < target_size) && (i < n))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1838 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1839 pl_size = min(target_size - tmp_offset, vbytes);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1840 memcpy(&(tmp[tmp_offset]), &(vpriv->framebuf[i].buffer[offset]), pl_size);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1841 tmp_offset += pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1842 offset += pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1843 vbytes -= pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1844
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1845 if(vbytes == 0) //current frame is saved, pass to the next
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1846 {
17271
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1847 if(i+1 >= n) //the current one is the last frame in GOP
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1848 break;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1849 i++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1850 vbytes = vpriv->framebuf[i].size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1851 offset = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1852 frame_begin = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1853 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1854 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1855 buf = tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1856 pl_size = tmp_offset;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1857 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1858
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1859
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1860 if((pl_size < priv->packet_size - calc_pack_hlen(priv, vpriv)) && !finalize && (i >= n - 1))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1861 {
17271
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1862 if(vpriv->framebuf[n].alloc_size < pl_size + vpriv->framebuf[n].size)
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1863 {
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1864 vpriv->framebuf[n].buffer = realloc(vpriv->framebuf[n].buffer, pl_size + vpriv->framebuf[n].size);
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1865 vpriv->framebuf[n].alloc_size = pl_size + vpriv->framebuf[n].size;
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1866 }
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1867 memmove(&(vpriv->framebuf[n].buffer[pl_size]), vpriv->framebuf[n].buffer, vpriv->framebuf[n].size);
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1868 memcpy(vpriv->framebuf[n].buffer, buf, pl_size);
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
1869 vpriv->framebuf[n].size += pl_size;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1870 pl_size = update = vbytes = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1871 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1872 if(pl_size)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1873 pl_size = write_mpeg_pack(muxer, vs, muxer->file, buf, pl_size, 0);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1874 vpriv->pes_is_aligned = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1875 vpriv->pts = vpriv->dts = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1876 vpriv->buffer_size = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1877 vpriv->size += pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1878 if(update)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1879 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1880 vbytes -= pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1881 offset += pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1882 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1883
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1884 /* this is needed to calculate SCR */
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1885 frame_bytes = max(vpriv->framebuf[i].size, priv->packet_size) + priv->packet_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1886 if(abytes > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1887 //frame_bytes += min(apriv->max_pl_size, priv->packet_size) + audio_rest;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1888 frame_bytes += min(apriv->max_pl_size, abytes) + audio_rest;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1889
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1890 if(priv->ts_allframes)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1891 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1892 tot = frame_bytes;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1893 mult = (double) vpriv->framebuf[min(i, n-1)].idur;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1894 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1895 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1896 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1897 tot = bytes;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1898 //mult = (double) (max(iduration, iaduration));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1899 mult = (double) (iduration);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1900 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1901 update_scr(priv, pl_size, tot, mult);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1902
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1903
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1904 if(abytes > 0 && frame_begin) //it's time to save audio
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1905 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1906 pl_size = dump_audio(muxer, as, abytes, finalize);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1907 if(pl_size > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1908 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1909 abytes -= pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1910 update_scr(priv, pl_size, tot, mult);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1911 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1912 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1913
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1914 frame_begin = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1915 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1916
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1917 i++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1918 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1919
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1920
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1921 if(vpriv->is_mpeg12)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1922 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1923 for(i = 0; i < n; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1924 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1925 vpriv->last_dts = vpriv->framebuf[i].dts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1926 if(vpriv->framebuf[i].pts >= vpriv->last_pts)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1927 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1928 vpriv->last_pts = vpriv->framebuf[i].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1929 idur = vpriv->framebuf[i].idur;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1930 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1931 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1932
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1933 vpriv->last_dts += vpriv->framebuf[n-1].idur;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1934 vpriv->last_pts += idur;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1935 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1936
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
1937 for(i=0; i<n; i++)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
1938 vpriv->framebuf[i].pos = vpriv->framebuf[i].size = 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1939 for(i = n; i < vpriv->framebuf_used; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1940 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1941 temp_frame = vpriv->framebuf[i - n];
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1942 vpriv->framebuf[i - n] = vpriv->framebuf[i];
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1943 vpriv->framebuf[i] = temp_frame;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1944 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1945 vpriv->framebuf_used -= n;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1946
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1947 if((as != NULL) && priv->has_audio)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1948 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1949 while(abytes > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1950 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1951 mult = iduration;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1952 pl_size = dump_audio(muxer, as, abytes, finalize);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1953 if(pl_size > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1954 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1955 update_scr(priv, pl_size, bytes, mult);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1956 abytes -= pl_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1957 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1958 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1959 break;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1960 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1961 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1962
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1963 //goto init;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1964 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1965
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1966 muxer->file_end = priv->scr;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1967 return found;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1968 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1969
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1970
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1971 static inline uint64_t parse_fps(float fps)
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1972 {
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1973 // 90000 * 300 * 1001 / d , there's no rounding error with any of the admitted framerates
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1974 int d = (int)(fps*1001+0.5);
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1975
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
1976 return 27027000000ULL / d;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1977 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
1978
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
1979
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
1980 static int soft_telecine(muxer_headers_t *vpriv, uint8_t *fps_ptr, uint8_t *se_ptr, uint8_t *pce_ptr, int n)
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1981 {
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
1982 uint8_t fps, tff, rff;
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
1983 int period;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1984
17814
8f2e94a4a4c1 check pce_ptr before using it; fixes cid 207
nicodvb
parents: 17603
diff changeset
1985 if(! pce_ptr)
8f2e94a4a4c1 check pce_ptr before using it; fixes cid 207
nicodvb
parents: 17603
diff changeset
1986 return 0;
8f2e94a4a4c1 check pce_ptr before using it; fixes cid 207
nicodvb
parents: 17603
diff changeset
1987
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
1988 period = (vpriv->telecine == TELECINE_FILM2PAL) ? 12 : 4;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1989 if(fps_ptr != NULL)
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1990 {
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1991 fps = *fps_ptr & 0x0f;
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
1992 if((!fps) || (fps > FRAMERATE_24))
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1993 {
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1994 mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR! FRAMERATE IS INVALID: %d, disabling telecining\n", (int) fps);
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1995 vpriv->telecine = 0;
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1996 return 0;
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
1997 }
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
1998 if(vpriv->telecine == TELECINE_FILM2PAL)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
1999 {
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2000 *fps_ptr = (*fps_ptr & 0xf0) | FRAMERATE_25;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2001 vpriv->nom_delta_pts = parse_fps(25.0);
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2002 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2003 else
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2004 {
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2005 *fps_ptr = (*fps_ptr & 0xf0) | (fps + 3);
16192
c29fc3d0bf4a reconcile with earlier fps fix in mpeg header parser
rfelker
parents: 16162
diff changeset
2006 vpriv->nom_delta_pts = parse_fps((fps + 3) == FRAMERATE_2997 ? 30000.0/1001.0 : 30.0);
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2007 }
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2008 }
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2009
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2010 //in pce_ptr starting from bit 0 bit 24 is tff, bit 30 is rff,
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2011 if(pce_ptr[3] & 0x2)
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2012 {
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2013 mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR! RFF bit is already set, disabling telecining\n");
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2014 vpriv->telecine = 0;
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2015 return 0;
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2016 }
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2017
14894
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2018 vpriv->picture.progressive_sequence = 0;
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2019 vpriv->picture.progressive_frame = 1;
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2020 if(se_ptr)
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2021 se_ptr[1] &= 0xf7;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2022
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2023
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2024 if(! vpriv->vframes) //initial value of tff
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2025 vpriv->trf = (pce_ptr[3] >> 6) & 0x2;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2026
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2027 while(n < 0) n+=period;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2028 vpriv->trf = (vpriv->trf + n) % period;
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2029
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2030 //sets curent tff/rff bits
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2031 if(vpriv->telecine == TELECINE_FILM2PAL)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2032 {
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2033 //repeat 1 field every 12 frames
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2034 int rest1 = (vpriv->trf % period) == 11;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2035 int rest2 = vpriv->vframes % 999;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2036
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2037 rff = 0;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2038 if(rest1)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2039 rff = 2;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2040
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2041 if(vpriv->real_framerate == FRAMERATE_23976)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2042 {
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2043 //we have to inverse the 1/1000 framedrop, repeating two fields in a sequence of 999 frames
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2044 //486 and 978 are ideal because they are halfway in the sequence
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2045 //additionally x % 12 == 6 (halfway between two frames with rff set)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2046 //and enough in advance to check if rest1 is valid too,
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2047 //so we can delay the setting of rff to current_frame+3 with no risk to leave the
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2048 //current sequence unpatched
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2049 if(rest2 == 486 || rest2 == 978)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2050 {
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2051 if(rest1)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2052 {
17603
22ced3e0a4aa delay rff by 6, not 3 frames, so the rff will be in the middle of the 12 frames sequence
nicodvb
parents: 17600
diff changeset
2053 //delay the setting by 6 frames, so we don't have 2 consecutive rff
22ced3e0a4aa delay rff by 6, not 3 frames, so the rff will be in the middle of the 12 frames sequence
nicodvb
parents: 17600
diff changeset
2054 //and the transition will be smoother (halfway in the 12-frames sequence)
22ced3e0a4aa delay rff by 6, not 3 frames, so the rff will be in the middle of the 12 frames sequence
nicodvb
parents: 17600
diff changeset
2055 vpriv->delay_rff = 7;
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2056 mp_msg(MSGT_MUXER, MSGL_V, "\r\nDELAYED: %d\r\n", rest2);
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2057 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2058 else
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2059 rff = 2;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2060 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2061
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2062 if(!rest1 && vpriv->delay_rff)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2063 {
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2064 vpriv->delay_rff--;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2065 if(vpriv->delay_rff == 1)
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2066 {
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2067 rff = 2;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2068 vpriv->delay_rff = 0;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2069 mp_msg(MSGT_MUXER, MSGL_V, "\r\nRECOVERED: %d\r\n", rest2);
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2070 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2071 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2072 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2073
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2074 pce_ptr[3] = (pce_ptr[3] & 0xfd) | rff;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2075 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2076 else
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2077 {
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2078 tff = (vpriv->trf & 0x2) ? 0x80 : 0;
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2079 rff = (vpriv->trf & 0x1) ? 0x2 : 0;
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2080 pce_ptr[3] = (pce_ptr[3] & 0x7d) | tff | rff;
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2081 }
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2082 pce_ptr[4] |= 0x80; //sets progressive frame
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2083 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nTRF: %d, TFF: %d, RFF: %d, n: %d\n", vpriv->trf, tff >> 7, rff >> 1, n);
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2084
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2085
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2086 if(! vpriv->vframes)
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2087 mp_msg(MSGT_MUXER, MSGL_INFO, "\nENABLED SOFT TELECINING, FPS=%s, INITIAL PATTERN IS TFF:%d, RFF:%d\n",
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2088 framerates[(vpriv->telecine == TELECINE_FILM2PAL) ? FRAMERATE_25 : fps+3], tff >> 7, rff >> 1);
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2089
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2090 return 1;
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2091 }
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2092
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2093 static size_t parse_mpeg12_video(muxer_stream_t *s, muxer_priv_t *priv, muxer_headers_t *spriv, float fps, size_t len)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2094 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2095 size_t ptr = 0, sz = 0, tmp = 0;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2096 uint8_t *fps_ptr = NULL; //pointer to the fps byte in the sequence header
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2097 uint8_t *se_ptr = NULL; //pointer to sequence extension
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2098 uint8_t *pce_ptr = NULL; //pointer to picture coding extension
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2099 int frames_diff, d1, gop_reset = 0; //how any frames we advanced respect to the last one
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2100 int ret;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2101
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2102 mp_msg(MSGT_MUXER, MSGL_DBG2,"parse_mpeg12_video, len=%u\n", (uint32_t) len);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2103 if(s->buffer[0] != 0 || s->buffer[1] != 0 || s->buffer[2] != 1 || len<6)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2104 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2105 mp_msg(MSGT_MUXER, MSGL_ERR,"Unknown video format, possibly non-MPEG1/2 stream, len=%d!\n", len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2106 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2107 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2108
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2109 if(s->buffer[3] == 0 || s->buffer[3] == 0xb3 || s->buffer[3] == 0xb8)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2110 { // Video (0) Sequence header (b3) or GOP (b8)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2111 uint32_t temp_ref;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2112 int pt;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2113
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2114 if(s->buffer[3] == 0xb3) //sequence
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2115 {
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2116 fps_ptr = &(s->buffer[7]);
17600
6fa1149d8c80 experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents: 17591
diff changeset
2117 spriv->real_framerate = *fps_ptr & 0x0f;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2118 mp_header_process_sequence_header(&(spriv->picture), &(s->buffer[4]));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2119 spriv->delta_pts = spriv->nom_delta_pts = parse_fps(spriv->picture.fps);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2120
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2121 spriv->delta_clock = (double) 1/fps;
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2122 //the 2 lines below are needed to handle non-standard frame rates (such as 18)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2123 if(! spriv->delta_pts)
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2124 spriv->delta_pts = spriv->nom_delta_pts = (uint64_t) ((double)27000000.0 * spriv->delta_clock );
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2125 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nFPS: %.3f, FRAMETIME: %.3lf\n", fps, (double)1/fps);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2126 if(priv->patch_seq)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2127 patch_seq(priv, s->buffer);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2128
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2129 tmp = 12;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2130 if(s->buffer[tmp-1] & 2)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2131 tmp += 64;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2132
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2133 if(s->buffer[tmp-1] & 1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2134 tmp += 64;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2135
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2136 if(s->buffer[tmp] == 0 && s->buffer[tmp+1] == 0 && s->buffer[tmp+2] == 1 && s->buffer[tmp+3] == 0xb5)
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2137 {
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2138 se_ptr = &(s->buffer[tmp+4]);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2139 mp_header_process_extension(&(spriv->picture), &(s->buffer[tmp+4]));
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2140 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2141 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2142
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2143
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2144 if(spriv->picture.mpeg1 == 0 && priv->patch_sde)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2145 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2146 while((s->buffer[tmp] != 0 || s->buffer[tmp+1] != 0 || s->buffer[tmp+2] != 1 || s->buffer[tmp+3] != 0xb5 ||
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2147 ((s->buffer[tmp+4] & 0xf0) != 0x20)) &&
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2148 (tmp < len-5))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2149 tmp++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2150
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2151 if(tmp < len-5) //found
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2152 patch_panscan(priv, &(s->buffer[tmp+4]));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2153 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2154
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2155
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2156 if(s->buffer[3])
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2157 { // Sequence or GOP -- scan for Picture
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2158 /*while (ptr < len-5 &&
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2159 (s->buffer[ptr] != 0 || s->buffer[ptr+1] != 0 || s->buffer[ptr+2] != 1 || s->buffer[ptr+3] != 0))
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2160 ptr++;*/
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2161
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2162 do_loop: while (ptr < len-5 &&
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2163 (s->buffer[ptr] != 0 || s->buffer[ptr+1] != 0 || s->buffer[ptr+2] != 1))
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2164 ptr++;
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2165
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2166 if(s->buffer[ptr+3] == 0xb8)
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2167 gop_reset = 1;
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2168
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2169 if(s->buffer[ptr+3]) //not frame
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2170 {
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2171 ptr++;
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2172 goto do_loop;
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2173 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2174 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2175
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2176 if (ptr >= len-5)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2177 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2178 pt = 0; // Picture not found?!
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2179 temp_ref = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2180 mp_msg(MSGT_MUXER, MSGL_ERR,"Warning: picture not found in GOP!\n");
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2181 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2182 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2183 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2184 //following 2 lines are workaround: lavf doesn't sync to sequence headers before passing demux_packets
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2185 if(!spriv->nom_delta_pts)
17591
455d1aef7d97 init frame duration to 1/fps when we have a frame but not the enclosing sequence header: it's workaround against lavf's demuxer that doesn't sync to seq_hdr unlike mplayer's native demuxers
nicodvb
parents: 17583
diff changeset
2186 spriv->delta_pts = spriv->nom_delta_pts = parse_fps(fps);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2187 pt = (s->buffer[ptr+5] & 0x1c) >> 3;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2188 temp_ref = (s->buffer[ptr+4]<<2)+(s->buffer[ptr+5]>>6);
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2189 if(!spriv->vframes)
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2190 spriv->last_tr = spriv->max_tr = temp_ref;
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2191 d1 = temp_ref - spriv->last_tr;
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2192 if(gop_reset)
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2193 {
17539
c692a99ea1bd fixed wrong delta_frame calculation that would affect soft-telecine
nicodvb
parents: 17518
diff changeset
2194 frames_diff = spriv->max_tr + 1 + temp_ref - spriv->last_tr;
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2195 }
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2196 else
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2197 {
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2198 if(d1 < -6) //there's a wraparound
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2199 frames_diff = spriv->max_tr + 1 + temp_ref - spriv->last_tr;
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2200 else if(d1 > 6) //there's a wraparound
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2201 frames_diff = spriv->max_tr + 1 + spriv->last_tr - temp_ref;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2202 else if(!d1) //pre-emptive fix against broken sequences
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2203 frames_diff = 1;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2204 else
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2205 frames_diff = d1;
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2206 }
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2207 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nLAST: %d, TR: %d, GOP: %d, DIFF: %d, MAX: %d, d1: %d\n",
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2208 spriv->last_tr, temp_ref, gop_reset, frames_diff, spriv->max_tr, d1);
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2209
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2210 if(temp_ref > spriv->max_tr || gop_reset)
14880
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2211 spriv->max_tr = temp_ref;
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2212
991f5a7b1b7d telecine now works in display order (rather than decoding), as far as there are no more than 4 consecutive b-frames; added support for FMP4
nicodvb
parents: 14840
diff changeset
2213 spriv->last_tr = temp_ref;
14894
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2214 if(spriv->picture.mpeg1 == 0)
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2215 {
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2216 size_t tmp = ptr;
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2217
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2218 while (ptr < len-5 &&
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2219 (s->buffer[ptr] != 0 || s->buffer[ptr+1] != 0 || s->buffer[ptr+2] != 1 || s->buffer[ptr+3] != 0xb5))
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2220 ptr++;
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2221 if(ptr < len-5)
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2222 {
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2223 pce_ptr = &(s->buffer[ptr+4]);
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2224 if(spriv->telecine)
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2225 soft_telecine(spriv, fps_ptr, se_ptr, pce_ptr, frames_diff);
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2226 spriv->picture.display_time = 100;
14894
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2227 mp_header_process_extension(&(spriv->picture), &(s->buffer[ptr+4]));
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2228 if(spriv->picture.display_time >= 50 && spriv->picture.display_time <= 300)
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2229 spriv->delta_pts = (spriv->nom_delta_pts * spriv->picture.display_time) / 100;
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2230 }
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2231 else
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2232 spriv->delta_pts = spriv->nom_delta_pts;
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2233
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2234 ptr = tmp;
bd6d709d13fb recalculate frame duration after soft telecine
nicodvb
parents: 14881
diff changeset
2235 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2236 }
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2237
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2238 if(! spriv->vframes)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2239 frames_diff = 1;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2240
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2241 spriv->last_dts += spriv->delta_pts;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2242 spriv->last_pts += spriv->nom_delta_pts*(frames_diff-1) + spriv->delta_pts;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2243
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2244 ret = add_frame(spriv, spriv->delta_pts, s->buffer, len, pt, spriv->last_dts, spriv->last_pts);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2245 if(ret < 0)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2246 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2247 mp_msg(MSGT_MUXER, MSGL_FATAL, "\r\nPARSE_MPEG12: add_frames(%d) failed, exit\r\n", len);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2248 return 0;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2249 }
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2250 mp_msg(MSGT_MUXER, MSGL_DBG2, "\r\nVIDEO FRAME, PT: %C, tr: %d, diff: %d, dts: %.3lf, pts: %.3lf, pdt: %u, gop_reset: %d\r\n",
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2251 ftypes[pt], temp_ref, frames_diff, ((double) spriv->last_dts/27000000.0f),
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2252 ((double) spriv->last_pts/27000000.0f), spriv->picture.display_time, gop_reset);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2253
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2254 if(pt == B_FRAME)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2255 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2256 int j, n, adj = 0;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2257 int64_t diff = spriv->last_dts - spriv->last_pts;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2258
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2259 if(diff != 0)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2260 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2261 n = spriv->framebuf_used - 1;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2262
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2263 for(j = n; j >= 0; j--)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2264 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2265 if(spriv->framebuf[j].pts >= spriv->last_pts)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2266 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2267 spriv->framebuf[j].pts += diff;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2268 adj++;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2269 }
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2270 }
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2271 mp_msg(MSGT_MUXER, MSGL_V, "\r\nResynced B-frame by %d units, DIFF: %lld (%.3lf),[pd]ts=%.3lf\r\n",
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2272 n, diff, (double) diff/27000000.0f, (double) spriv->last_pts/27000000.0f);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2273 spriv->last_pts = spriv->last_dts;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2274 }
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2275 }
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2276 spriv->vframes++;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2277 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2278
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2279 mp_msg(MSGT_MUXER, MSGL_DBG2,"parse_mpeg12_video, return %u\n", (uint32_t) len);
18166
e952e8cdf98e removed useless (and broken as hell) buffering code from muxer1; buffering constraints will be fully respected when one of the forthcoming patches is applied
nicodvb
parents: 18165
diff changeset
2280 return len;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2281 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2282
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2283
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2284 static uint64_t fix_mp4_frame_duration(muxer_headers_t *vpriv)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2285 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2286 uint64_t mn, md, mx, diff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2287 uint32_t i;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2288
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2289 mn = mx = vpriv->framebuf[0].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2290 for(i = 0; i < 3; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2291 {
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
2292 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "PTS: %"PRIu64"\n", vpriv->framebuf[i].pts);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2293 if(vpriv->framebuf[i].pts < mn)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2294 mn = vpriv->framebuf[i].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2295 if(vpriv->framebuf[i].pts > mx)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2296 mx = vpriv->framebuf[i].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2297 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2298 md = mn;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2299 for(i=0; i<3; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2300 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2301 if((vpriv->framebuf[i].pts > mn) && (vpriv->framebuf[i].pts < mx))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2302 md = vpriv->framebuf[i].pts;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2303 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2304
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2305 if(mx - md > md - mn)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2306 diff = md - mn;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2307 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2308 diff = mx - md;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2309
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2310 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "MIN: %"PRIu64", mid: %"PRIu64", max: %"PRIu64", diff: %"PRIu64"\n", mn, md, mx, diff);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2311 if(diff > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2312 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2313 for(i=0; i<3; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2314 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2315 vpriv->framebuf[i].pts += diff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2316 vpriv->framebuf[i].dts += i * diff;
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2317 mp_msg(MSGT_MUXER, MSGL_DBG2, "FIXED_PTS: %.3lf, FIXED_DTS: %.3lf\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2318 (double) (vpriv->framebuf[i].pts/27000000.0), (double) (vpriv->framebuf[i].dts/27000000.0));
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2319 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2320 return diff;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2321 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2322 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2323 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2324 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2325
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2326
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2327 static size_t parse_mpeg4_video(muxer_stream_t *s, muxer_priv_t *priv, muxer_headers_t *vpriv, float fps, size_t len)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2328 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2329 size_t ptr = 0;
17815
36a155ee4d27 init delta_pts before using it; fixes cid 239
nicodvb
parents: 17814
diff changeset
2330 int64_t delta_pts=0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2331 uint8_t pt;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2332 int ret;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2333
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2334 mp_msg(MSGT_MUXER, MSGL_DBG2,"parse_mpeg4_video, len=%u\n", (uint32_t) len);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2335 if(len<6)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2336 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2337 mp_msg(MSGT_MUXER, MSGL_ERR,"Frame too short: %d, exit!\n", len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2338 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2339 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2340
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2341 pt = 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2342 while(ptr < len - 5)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2343 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2344 if(s->buffer[ptr] != 0 || s->buffer[ptr+1] != 0 || s->buffer[ptr+2] != 1)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2345 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2346 ptr++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2347 continue;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2348 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2349
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2350 if(s->buffer[ptr+3] >= 0x20 && s->buffer[ptr+3] <= 0x2f) //VOL
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2351 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2352 mp4_header_process_vol(&(vpriv->picture), &(s->buffer[ptr+4]));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2353 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2354 else if(s->buffer[ptr+3] == 0xb3) //gov
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2355 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2356 //fprintf(stderr, "\nGOV\n");
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2357 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2358 else if(s->buffer[ptr+3] == 0xb6) //vop
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2359 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2360 int32_t delta;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2361 mp4_header_process_vop(&(vpriv->picture), &(s->buffer[ptr+4]));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2362
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2363 delta = vpriv->picture.timeinc_unit - vpriv->last_tr;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2364 if((delta > 0) && (delta > (vpriv->picture.timeinc_resolution/2)))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2365 delta -= vpriv->picture.timeinc_resolution;
18163
1e4caa08161d fixed wrong operator precedence in parse_mpeg4_video()
nicodvb
parents: 18162
diff changeset
2366 else if((delta < 0) && (delta < (-(vpriv->picture.timeinc_resolution/2))))
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2367 delta += vpriv->picture.timeinc_resolution;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2368
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2369 delta_pts = (27000000 * (int64_t) delta) / vpriv->picture.timeinc_resolution;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2370 //warning, it seems that packed bops can lead to delta == 0
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2371
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2372 pt = vpriv->picture.picture_type + 1;
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
2373 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nTYPE: %c, RESOLUTION: %d, TEMP: %d, delta: %d, delta_pts: %"PRId64" = %.3lf, delta2: %.3lf\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2374 FTYPE(pt), vpriv->picture.timeinc_resolution, vpriv->picture.timeinc_unit, delta, delta_pts, (double) (delta_pts/27000000.0),
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2375 (double) delta / (double) vpriv->picture.timeinc_resolution);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2376
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2377 vpriv->last_tr = vpriv->picture.timeinc_unit;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2378
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2379 break;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2380 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2381
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2382 ptr++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2383 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2384
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2385 if(vpriv->vframes)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2386 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2387 vpriv->last_dts += vpriv->frame_duration;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2388 vpriv->last_pts += delta_pts;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2389 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2390
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2391 ret = add_frame(vpriv, delta_pts, s->buffer, len, pt, vpriv->last_dts, vpriv->last_pts);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2392 if(ret < 0)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2393 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2394 mp_msg(MSGT_MUXER, MSGL_FATAL, "\r\nPARSE_MPEG12: add_frames(%d) failed, exit\r\n", len);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2395 return 0;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2396 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2397
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2398 if(!vpriv->frame_duration && vpriv->framebuf_used == 3)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2399 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2400 vpriv->frame_duration = fix_mp4_frame_duration(vpriv);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2401 if(vpriv->frame_duration)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2402 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2403 vpriv->last_pts += vpriv->frame_duration;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2404 vpriv->last_dts = vpriv->framebuf[vpriv->framebuf_used-1].dts;
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2405 vpriv->delta_clock = ((double) vpriv->frame_duration)/27000000.0;
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
2406 mp_msg(MSGT_MUXER, MSGL_INFO, "FRAME DURATION: %"PRIu64" %.3lf\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2407 vpriv->frame_duration, (double) (vpriv->frame_duration/27000000.0));
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2408 vpriv->is_ready = 1;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2409 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2410 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2411
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2412 mp_msg(MSGT_MUXER, MSGL_DBG2, "LAST_PTS: %.3lf, LAST_DTS: %.3lf\n",
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2413 (double) (vpriv->last_pts/27000000.0), (double) (vpriv->last_dts/27000000.0));
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2414
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2415 vpriv->vframes++;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2416
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2417 return len;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2418 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2419
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2420
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2421 static int fill_last_frame(muxer_headers_t *spriv, uint8_t *ptr, int len)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2422 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2423 int idx;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2424
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2425 if(!len)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2426 return 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2427
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2428 if(spriv->framebuf_used == 0)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2429 idx = spriv->framebuf_used;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2430 else
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2431 idx = spriv->framebuf_used - 1;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2432
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2433 if(spriv->framebuf[idx].alloc_size < spriv->framebuf[idx].size + len)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2434 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2435 spriv->framebuf[idx].buffer = (uint8_t*) realloc(spriv->framebuf[idx].buffer, spriv->framebuf[idx].size + len);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2436 if(! spriv->framebuf[idx].buffer)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2437 return 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2438 spriv->framebuf[idx].alloc_size = spriv->framebuf[idx].size + len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2439 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2440
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2441 memcpy(&(spriv->framebuf[idx].buffer[spriv->framebuf[idx].size]), ptr, len);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2442 spriv->framebuf[idx].size += len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2443
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2444 return len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2445 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2446
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2447 static int add_frame(muxer_headers_t *spriv, uint64_t idur, uint8_t *ptr, int len, uint8_t pt, uint64_t dts, uint64_t pts)
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2448 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2449 int idx;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2450
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2451 idx = spriv->framebuf_used;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2452 if(idx >= spriv->framebuf_cnt)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2453 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2454 spriv->framebuf = (mpeg_frame_t*) realloc(spriv->framebuf, (spriv->framebuf_cnt+1)*sizeof(mpeg_frame_t));
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2455 if(spriv->framebuf == NULL)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2456 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2457 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't realloc frame buffer(idx), abort\n");
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2458 return -1;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2459 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2460
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2461 spriv->framebuf[spriv->framebuf_cnt].size = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2462 spriv->framebuf[spriv->framebuf_cnt].alloc_size = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2463 spriv->framebuf[spriv->framebuf_cnt].pos = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2464
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2465 spriv->framebuf[spriv->framebuf_cnt].buffer = (uint8_t*) malloc(len);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2466 if(spriv->framebuf[spriv->framebuf_cnt].buffer == NULL)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2467 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2468 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't realloc frame buffer(frame), abort\n");
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2469 return -1;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2470 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2471 spriv->framebuf[spriv->framebuf_cnt].alloc_size = len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2472 spriv->framebuf_cnt++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2473 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2474
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2475 if(spriv->framebuf[idx].alloc_size < spriv->framebuf[idx].size + len)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2476 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2477 spriv->framebuf[idx].buffer = realloc(spriv->framebuf[idx].buffer, spriv->framebuf[idx].size + len);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2478 if(spriv->framebuf[idx].buffer == NULL)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2479 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2480 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't realloc frame buffer(frame), abort\n");
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2481 return -1;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2482 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2483 spriv->framebuf[idx].alloc_size = spriv->framebuf[idx].size + len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2484 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2485
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2486 memcpy(&(spriv->framebuf[idx].buffer[spriv->framebuf[idx].size]), ptr, len);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2487 spriv->framebuf[idx].size += len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2488 spriv->framebuf[idx].pos = 0;
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2489 spriv->framebuf[idx].type = pt;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2490
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2491 spriv->framebuf[idx].idur = idur;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2492 spriv->framebuf[idx].dts = dts;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2493 spriv->framebuf[idx].pts = pts;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2494 spriv->framebuf_used++;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2495 mp_msg(MSGT_MUXER, MSGL_DBG2, "\r\nAdded frame, size: %u, idur: %llu, dts: %llu, pts: %llu, used: %u\r\n", len, idur, dts, pts, spriv->framebuf_used);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2496
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2497 return idx;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2498 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2499
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2500
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2501 extern int aac_parse_frame(uint8_t *buf, int *srate, int *num);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2502
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2503 static int parse_audio(muxer_stream_t *s, int finalize, unsigned int *nf, double *timer, double delay, int drop)
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2504 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2505 int i, j, len, chans, srate, spf, layer, dummy, tot, num, frm_idx;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2506 unsigned int frames;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2507 uint64_t idur;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2508 double dur;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2509 muxer_headers_t *spriv = (muxer_headers_t *) s->priv;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2510
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2511 i = tot = frames = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2512 switch(s->wf->wFormatTag)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2513 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2514 case AUDIO_MP2:
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2515 case AUDIO_MP3:
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2516 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2517 while(i + 3 < s->b_buffer_len)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2518 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2519 if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xE0) == 0xE0))
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2520 {
16162
b5c2254d13f8 set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents: 15947
diff changeset
2521 len = mp_get_mp3_header(&(s->b_buffer[i]), &chans, &srate, &spf, &layer, NULL);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2522 if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2523 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2524 dur = (double) spf / (double) srate;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2525 spriv->timer += dur;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2526 if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2527 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2528 i += len;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2529 tot = i;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2530 continue;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2531 }
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2532 frames++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2533 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2534
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2535 idur = (27000000ULL * spf) / srate;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2536 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2537 if(frm_idx < 0)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2538 continue;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2539 for(j = frm_idx; j < spriv->framebuf_cnt; j++)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2540 spriv->framebuf[j].pts = spriv->last_pts;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2541 spriv->last_pts += idur;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2542
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2543 i += len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2544 tot = i;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2545 continue;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2546 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2547 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2548 i++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2549 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2550 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2551 break;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2552
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2553 case AUDIO_A52:
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2554 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2555 while(i + 6 < s->b_buffer_len)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2556 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2557 if(s->b_buffer[i] == 0x0B && s->b_buffer[i+1] == 0x77)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2558 {
17493
f71e678e6216 use mp_a52_framesize() when liba52 is not available
nicodvb
parents: 17487
diff changeset
2559 srate = 0;
f71e678e6216 use mp_a52_framesize() when liba52 is not available
nicodvb
parents: 17487
diff changeset
2560 #ifdef USE_LIBA52
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2561 len = a52_syncinfo(&(s->b_buffer[i]), &dummy, &srate, &dummy);
17493
f71e678e6216 use mp_a52_framesize() when liba52 is not available
nicodvb
parents: 17487
diff changeset
2562 #else
f71e678e6216 use mp_a52_framesize() when liba52 is not available
nicodvb
parents: 17487
diff changeset
2563 len = mp_a52_framesize(&(s->b_buffer[i]), &srate);
f71e678e6216 use mp_a52_framesize() when liba52 is not available
nicodvb
parents: 17487
diff changeset
2564 #endif
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2565 if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2566 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2567 dur = (double) 1536 / (double) srate;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2568 spriv->timer += dur;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2569 if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2570 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2571 i += len;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2572 tot = i;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2573 continue;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2574 }
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2575 frames++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2576 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2577
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2578 idur = (27000000ULL * 1536) / srate;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2579 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2580 if(frm_idx < 0)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2581 continue;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2582 for(j = frm_idx; j < spriv->framebuf_cnt; j++)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2583 spriv->framebuf[j].pts = spriv->last_pts;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2584 spriv->last_pts += idur;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2585
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2586 i += len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2587 tot = i;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2588 continue;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2589 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2590 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2591 i++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2592 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2593 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2594 break;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2595
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2596 case AUDIO_AAC1:
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2597 case AUDIO_AAC2:
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2598 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2599 while(i + 7 < s->b_buffer_len)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2600 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2601 if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xF6) == 0xF0))
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2602 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2603 len = aac_parse_frame(&(s->b_buffer[i]), &srate, &num);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2604 if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2605 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2606 dur = (double) 1024 / (double) srate;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2607 spriv->timer += dur;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2608 if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2609 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2610 i += len;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2611 tot = i;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2612 continue;
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2613 }
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2614 frames++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2615 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2616
18161
516d7874450b changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
nicodvb
parents: 18044
diff changeset
2617 idur = (27000000ULL * 1024 * num) / srate;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2618 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2619 if(frm_idx < 0)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2620 continue;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2621 for(j = frm_idx; j < spriv->framebuf_cnt; j++)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2622 spriv->framebuf[j].pts = spriv->last_pts;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2623 spriv->last_pts += idur;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2624
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2625 i += len;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2626 tot = i;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2627 continue;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2628 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2629 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2630 i++;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2631 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2632 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2633 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2634
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2635 if(tot)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2636 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2637 memmove(s->b_buffer, &(s->b_buffer[tot]), s->b_buffer_len - tot);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2638 s->b_buffer_len -= tot;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2639 s->b_buffer_ptr += tot;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2640 if(s->b_buffer_len > 0)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2641 memmove(s->b_buffer, &(s->b_buffer[s->b_buffer_ptr]), s->b_buffer_len);
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2642 s->b_buffer_ptr = 0;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2643 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2644
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2645 if(finalize)
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2646 {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2647 frm_idx = add_frame(spriv, 0, s->b_buffer, s->b_buffer_len, 0, spriv->last_pts, spriv->last_pts);
17298
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2648 if(frm_idx >= 0)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2649 {
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2650 for(j = frm_idx; j < spriv->framebuf_cnt; j++)
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2651 spriv->framebuf[j].pts = spriv->last_pts;
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2652 }
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2653 }
104b09de82b9 removed broken frame reording code; unified audio and video frame storing code (in memory, not in the packets); simple workaround to handle non-standard framerate mpeg1/2 video
nicodvb
parents: 17271
diff changeset
2654
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2655 *nf = frames;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2656 *timer = spriv->timer;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2657
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2658 return tot;
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2659 }
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2660
18183
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2661 static void fix_parameters(muxer_stream_t *stream)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2662 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2663 muxer_headers_t *spriv = stream->priv;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2664 muxer_t *muxer = stream->muxer;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2665 muxer_priv_t *priv = muxer->priv;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2666
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2667 if(stream->type == MUXER_TYPE_AUDIO)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2668 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2669 spriv->max_buffer_size = 4*1024;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2670 if(stream->wf->wFormatTag == AUDIO_A52)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2671 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2672 stream->ckid = be2me_32 (0x1bd);
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2673 if(priv->is_genmpeg1 || priv->is_genmpeg2)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2674 fix_audio_sys_header(priv, spriv->id, 0xbd, 58*1024); //only one audio at the moment
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2675 spriv->id = 0xbd;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2676 spriv->max_buffer_size = 16*1024;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2677 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2678 else if(stream->wf->wFormatTag == AUDIO_AAC1 || stream->wf->wFormatTag == AUDIO_AAC2)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2679 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2680 priv->use_psm = 1;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2681 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2682 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2683 else //video
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2684 {
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2685 if(priv->is_dvd)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2686 spriv->max_buffer_size = 232*1024;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2687 else if(priv->is_xsvcd)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2688 spriv->max_buffer_size = 230*1024;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2689 else if(priv->is_xvcd)
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2690 spriv->max_buffer_size = 46*1024;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2691 else
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2692 spriv->max_buffer_size = 232*1024; //no profile => unconstrained :) FIXME!!!
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2693
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2694 if(is_mpeg4(stream->bih->biCompression))
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2695 spriv->is_ready = 0;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2696 else
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2697 spriv->is_ready = 1;
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2698 }
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
2699 }
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2700
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2701
17487
fa17424b4c7b change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents: 17366
diff changeset
2702 static void mpegfile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts_arg, double pts_arg){
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2703 size_t ptr=0, sz = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2704 uint64_t pts, tmp;
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8585
diff changeset
2705 muxer_t *muxer = s->muxer;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2706 muxer_priv_t *priv = (muxer_priv_t *)muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2707 muxer_headers_t *spriv = (muxer_headers_t*) s->priv;
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8585
diff changeset
2708 FILE *f;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2709 float fps;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2710 uint32_t stream_format, nf;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2711
9007
12fc55eb3373 Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents: 8585
diff changeset
2712 f = muxer->file;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2713
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2714 if(s->buffer == NULL)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2715 return;
18044
b693d92e6210 workaround to prevent segfault: when using -ve lavc with b-frames write_chunk(1st video frame) gets called with len=-1UL; -1ULl to whomever calls me that way
nicodvb
parents: 17818
diff changeset
2716 if(len == -1)
b693d92e6210 workaround to prevent segfault: when using -ve lavc with b-frames write_chunk(1st video frame) gets called with len=-1UL; -1ULl to whomever calls me that way
nicodvb
parents: 17818
diff changeset
2717 return;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2718
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2719 pts = 0;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2720 if (s->type == MUXER_TYPE_VIDEO) { // try to recognize frame type...
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2721 fps = (float) s->h.dwRate/ (float) s->h.dwScale;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2722 spriv->type = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2723 spriv->has_pes_priv_headers = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2724 stream_format = s->bih->biCompression;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2725 if(! spriv->vframes)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2726 {
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2727 spriv->last_dts = spriv->last_pts - (uint64_t)(27000000.0f/fps);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2728 mp_msg(MSGT_MUXER, MSGL_INFO,"INITV: %.3lf, %.3lf, fps: %.3f\r\n", (double) spriv->last_pts/27000000.0f, (double) spriv->last_dts/27000000.0f, fps);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2729 }
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2730
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2731 if(is_mpeg1(stream_format) || is_mpeg2(stream_format))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2732 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2733 spriv->is_mpeg12 = 1;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2734 spriv->is_ready = 1;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2735 if(len)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2736 sz = parse_mpeg12_video(s, priv, spriv, fps, len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2737 else {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2738 tmp = (uint64_t) (27000000.0f / fps);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2739 spriv->last_pts += tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2740 spriv->last_dts += tmp;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2741 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2742 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2743 else if(is_mpeg4(stream_format))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2744 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2745 spriv->is_mpeg12 = 0;
14840
d49482c5d8ac soft telecine support! :)) patch by nico
rfelker
parents: 14809
diff changeset
2746 spriv->telecine = 0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2747 if(spriv->size == 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2748 priv->use_psm = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2749 if(len)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2750 sz = parse_mpeg4_video(s, priv, spriv, fps, len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2751 else {
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2752 tmp = (uint64_t) (27000000.0f / fps);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2753 spriv->last_pts += tmp;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2754 spriv->last_dts += tmp;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2755 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2756 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2757
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2758 mp_msg(MSGT_MUXER, MSGL_DBG2,"mpegfile_write_chunk, Video codec=%x, len=%u, mpeg12 returned %u\n", stream_format, (uint32_t) len, (uint32_t) sz);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2759
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2760 ptr = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2761 priv->vbytes += len;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2762 } else { // MUXER_TYPE_AUDIO
17023
dd5be8f8d16d buffering in the muxer layer; patch by Corey Hickey (bugfood-ml ad fatooh punctum org) plus small fixes by me
nicodvb
parents: 17012
diff changeset
2763 double fake_timer;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2764 spriv->type = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2765 stream_format = s->wf->wFormatTag;
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2766
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2767 if(! spriv->vframes)
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2768 mp_msg(MSGT_MUXER, MSGL_INFO, "AINIT: %.3lf\r\n", (double) spriv->last_pts/27000000.0f);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2769 if(s->b_buffer_size - s->b_buffer_len < len)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2770 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2771 s->b_buffer = realloc(s->b_buffer, len + s->b_buffer_len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2772 if(s->b_buffer == NULL)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2773 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2774 mp_msg(MSGT_MUXER, MSGL_FATAL, "\nFATAL! couldn't realloc %d bytes\n", len + s->b_buffer_len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2775 return;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2776 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2777
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2778 s->b_buffer_size = len + s->b_buffer_len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2779 mp_msg(MSGT_MUXER, MSGL_DBG2, "REALLOC(%d) bytes to AUDIO backbuffer\n", s->b_buffer_size);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2780 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2781 memcpy(&(s->b_buffer[s->b_buffer_ptr + s->b_buffer_len]), s->buffer, len);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2782 s->b_buffer_len += len;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2783
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2784 parse_audio(s, 0, &nf, &fake_timer, priv->init_adelay, priv->drop);
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2785 spriv->vframes += nf;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2786 sz = max(len, 2 * priv->packet_size);
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2787 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2788
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2789
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2790 if(spriv->psm_fixed == 0) {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2791 add_to_psm(priv, spriv->id, stream_format);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2792 spriv->psm_fixed = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2793 priv->psm_streams_cnt++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2794 if((priv->psm_streams_cnt == muxer->num_videos + muxer->num_audios) && priv->use_psm)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2795 write_psm_block(muxer, muxer->file);
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2796 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2797
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2798
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2799 if(priv->init_adelay != 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2800 return;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2801
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2802 flush_buffers(muxer, 0);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2803 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2804
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2805
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2806 static void mpegfile_write_index(muxer_t *muxer)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2807 {
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2808 int i, nf;
17023
dd5be8f8d16d buffering in the muxer layer; patch by Corey Hickey (bugfood-ml ad fatooh punctum org) plus small fixes by me
nicodvb
parents: 17012
diff changeset
2809 double fake_timer;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2810 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2811
17065
cf6bfdf41143 Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents: 17023
diff changeset
2812 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingTrailer);
cf6bfdf41143 Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents: 17023
diff changeset
2813
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2814 for(i = 0; i < muxer->avih.dwStreams; i++)
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2815 {
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2816 if(muxer->streams[i]->type == MUXER_TYPE_AUDIO)
18181
afaa492536f6 new code to simplify assignment of timestamps; removed temp_ref from mpeg_frame_t and modified add_frame() accordingly; removed no more used drop_delayed_audio() and save_delayed_audio()
nicodvb
parents: 18166
diff changeset
2817 parse_audio(muxer->streams[i], 1, &nf, &fake_timer, priv->init_adelay, priv->drop);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
2818 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2819 while(flush_buffers(muxer, 0) > 0);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2820 flush_buffers(muxer, 1);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2821 if(priv->is_genmpeg1 || priv->is_genmpeg2)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2822 write_mpeg_pack(muxer, NULL, muxer->file, NULL, 0, 1); //insert fake Nav Packet
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2823
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16192
diff changeset
2824 mp_msg(MSGT_MUXER, MSGL_INFO, "\nOverhead: %.3lf%% (%"PRIu64" / %"PRIu64")\n", 100.0 * (double)priv->headers_size / (double)priv->data_size, priv->headers_size, priv->data_size);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2825 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2826
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2827 static void mpegfile_write_header(muxer_t *muxer)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2828 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2829 muxer_priv_t *priv = (muxer_priv_t*) muxer->priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2830
17065
cf6bfdf41143 Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents: 17023
diff changeset
2831 mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingHeader);
cf6bfdf41143 Clean up some muxer messages, patch by Corey Hickey bugfood-ml AT -fatooh/org- , small fixes by me
reynaldo
parents: 17023
diff changeset
2832
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2833 priv->headers_cnt++;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2834
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2835 if((priv->is_genmpeg1 || priv->is_genmpeg2) && (priv->headers_cnt == muxer->avih.dwStreams))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2836 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2837 int i;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2838 for(i = 0; i < muxer->avih.dwStreams; i++)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2839 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2840 priv->sys_info.streams[i].bufsize = muxer->streams[i]->h.dwSuggestedBufferSize;
15278
a45c7e1b998f added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents: 15083
diff changeset
2841 mp_msg(MSGT_MUXER, MSGL_DBG2, "IDX: %d, BUFSIZE: %u\n", i, priv->sys_info.streams[i].bufsize);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2842 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2843 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2844
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2845 //write the first system header only for generic mpeg1/2 muxes, and only when we have collected all necessary infos
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2846 if(priv->is_genmpeg1 || priv->is_genmpeg2 || ((priv->is_xvcd || priv->is_xsvcd) && (priv->headers_cnt == 1)))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2847 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2848 write_mpeg_pack(muxer, NULL, muxer->file, NULL, 0, 0);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2849 priv->update_system_header = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2850 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2851
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2852 return;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2853 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2854
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2855 static void setup_sys_params(muxer_priv_t *priv)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2856 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2857 if(priv->is_dvd)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2858 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2859 priv->sys_info.cnt = 4;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2860
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2861 priv->sys_info.streams[0].id = 0xb9;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2862 priv->sys_info.streams[0].type = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2863 priv->sys_info.streams[0].bufsize = 232*1024;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2864
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2865 priv->sys_info.streams[1].id = 0xb8;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2866 priv->sys_info.streams[1].type = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2867 priv->sys_info.streams[1].bufsize = 4*1024;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2868
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2869 priv->sys_info.streams[2].id = 0xbd;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2870 priv->sys_info.streams[2].type = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2871 priv->sys_info.streams[2].bufsize = 58*1024;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2872
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2873 priv->sys_info.streams[3].id = 0xbf;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2874 priv->sys_info.streams[3].type = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2875 priv->sys_info.streams[3].bufsize = 2*1024;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2876 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2877 else if(priv->is_xvcd || priv->is_xsvcd)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2878 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2879 priv->sys_info.cnt = 2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2880
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2881 priv->sys_info.streams[0].id = 0xe0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2882 priv->sys_info.streams[0].type = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2883 priv->sys_info.streams[0].bufsize = (priv->is_xvcd ? 46: 230)*1024;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2884
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2885 priv->sys_info.streams[1].id = 0xc0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2886 priv->sys_info.streams[1].type = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2887 priv->sys_info.streams[1].bufsize = 4*1024;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2888 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2889 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2890 priv->sys_info.cnt = 0;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2891 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2892
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2893
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2894 int muxer_init_muxer_mpeg(muxer_t *muxer){
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2895 muxer_priv_t *priv;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2896 priv = (muxer_priv_t *) calloc(1, sizeof(muxer_priv_t));
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2897 if(priv == NULL)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2898 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2899 priv->update_system_header = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2900
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2901 //calloc() already zero-ed all flags, so we assign only the ones we need
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2902
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2903 if(conf_mux != NULL) {
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2904 if(! strcasecmp(conf_mux, "mpeg1"))
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2905 {
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2906 priv->mux = MUX_MPEG1;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2907 priv->packet_size = 2048;
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2908 priv->is_genmpeg1 = 1;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2909 priv->muxrate = 1800 * 125; //Constrained parameters
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2910 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2911 else if(! strcasecmp(conf_mux, "dvd"))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2912 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2913 priv->mux = MUX_MPEG2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2914 priv->is_dvd = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2915 priv->packet_size = 2048;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2916 priv->muxrate = 10080 * 125;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2917 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2918 else if(! strcasecmp(conf_mux, "xsvcd"))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2919 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2920 priv->mux = MUX_MPEG2;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2921 priv->is_xsvcd = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2922 priv->packet_size = 2324;
18187
7d83cd632b6b fixed muxrates for xvcd and xsvcd
nicodvb
parents: 18186
diff changeset
2923 priv->muxrate = 150*2324;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2924 priv->ts_allframes = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2925 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2926 else if(! strcasecmp(conf_mux, "xvcd"))
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2927 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2928 priv->mux = MUX_MPEG1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2929 priv->is_xvcd = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2930 priv->packet_size = 2324;
18187
7d83cd632b6b fixed muxrates for xvcd and xsvcd
nicodvb
parents: 18186
diff changeset
2931 priv->muxrate = 75*2352;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2932 priv->ts_allframes = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2933 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2934 else
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2935 {
17066
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2936 if(strcasecmp(conf_mux, "mpeg2"))
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2937 mp_msg(MSGT_MUXER, MSGL_ERR, "Unknown format %s, default to mpeg2\n", conf_mux);
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2938 priv->mux = MUX_MPEG2;
e84e5e9e9ef4 fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents: 17065
diff changeset
2939 priv->is_genmpeg2 = 1;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2940 priv->packet_size = 2048;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2941 priv->muxrate = 1800 * 125; //Constrained parameters
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2942 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2943 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2944
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2945 if(conf_ts_allframes)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2946 priv->ts_allframes = 1;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2947 if(conf_muxrate > 0)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2948 priv->muxrate = conf_muxrate * 125; // * 1000 / 8
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2949 if(conf_packet_size)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2950 priv->packet_size = conf_packet_size;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2951 mp_msg(MSGT_MUXER, MSGL_INFO, "PACKET SIZE: %u bytes\n", priv->packet_size);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2952 setup_sys_params(priv);
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
2953
15083
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2954 if(conf_vaspect > 0)
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2955 {
15083
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2956 int asp = (int) (conf_vaspect * 1000.0f);
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2957 if(asp >= 1332 && asp <= 1334)
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2958 priv->vaspect = ASPECT_4_3;
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2959 else if(asp >= 1776 && asp <= 1778)
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2960 priv->vaspect = ASPECT_16_9;
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2961 else if(asp >= 2209 && asp <= 2211)
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2962 priv->vaspect = ASPECT_2_21_1;
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2963 else if(asp == 1000)
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2964 priv->vaspect = ASPECT_1_1;
15083
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2965 else
c73c1ea04d9c changed :vaspect option to CONF_TYPE_FLOAT
nicodvb
parents: 14927
diff changeset
2966 mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: unrecognized aspect %.3f\n", conf_vaspect);
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2967 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2968
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2969 priv->vframerate = 0; // no change
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2970 if(conf_telecine && conf_vframerate > 0)
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2971 {
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2972 mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: options 'telecine' and 'vframerate' are mutually exclusive, vframerate disabled\n");
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2973 conf_vframerate = 0;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2974 }
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2975
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2976 if(conf_vframerate)
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
2977 {
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2978 int fps;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2979
18162
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2980 fps = (int) (conf_vframerate * 1001 + 0.5);
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2981 switch(fps)
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2982 {
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2983 case 24000:
18162
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2984 priv->vframerate = FRAMERATE_23976;
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2985 break;
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2986 case 24024:
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2987 priv->vframerate = FRAMERATE_24;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2988 break;
18162
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2989 case 25025:
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2990 priv->vframerate = FRAMERATE_25;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2991 break;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2992 case 30000:
18162
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2993 priv->vframerate = FRAMERATE_2997;
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2994 break;
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2995 case 30030:
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2996 priv->vframerate = FRAMERATE_30;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2997 break;
18162
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
2998 case 50050:
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
2999 priv->vframerate = FRAMERATE_50;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
3000 break;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
3001 case 60000:
18162
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
3002 priv->vframerate = FRAMERATE_5994;
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
3003 break;
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
3004 case 60060:
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
3005 priv->vframerate = FRAMERATE_60;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
3006 break;
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
3007 default:
18162
1b4bf0c9ecb3 simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents: 18161
diff changeset
3008 mp_msg(MSGT_MUXER, MSGL_ERR, "WRONG FPS: %d/1000, ignoring\n", fps);
14914
8511347a0475 converted vframerate to CONF_TYPE_FLOAT
nicodvb
parents: 14894
diff changeset
3009 }
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3010 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3011
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3012 priv->vwidth = (uint16_t) conf_vwidth;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3013 priv->vheight = (uint16_t) conf_vheight;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3014 priv->panscan_width = (uint16_t) conf_panscan_width;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3015 priv->panscan_height = (uint16_t) conf_panscan_height;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3016 priv->vbitrate = ((conf_vbitrate) * 10) >> 2; //*1000 / 400
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3017
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3018 if(priv->vaspect || priv->vframerate || priv->vwidth || priv->vheight || priv->vbitrate || priv->panscan_width || priv->panscan_height)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3019 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3020 priv->patch_seq = priv->vaspect || priv->vframerate || priv->vwidth || priv->vheight || priv->vbitrate;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3021 priv->patch_sde = priv->panscan_width || priv->panscan_height;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3022 mp_msg(MSGT_MUXER, MSGL_INFO, "MPEG MUXER, patching");
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3023 if(priv->vwidth || priv->vheight)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3024 mp_msg(MSGT_MUXER, MSGL_INFO, " resolution to %dx%d", priv->vwidth, priv->vheight);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3025 if(priv->panscan_width || priv->panscan_height)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3026 mp_msg(MSGT_MUXER, MSGL_INFO, " panscan to to %dx%d", priv->panscan_width, priv->panscan_height);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3027 if(priv->vframerate)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3028 mp_msg(MSGT_MUXER, MSGL_INFO, " framerate to %s fps", framerates[priv->vframerate]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3029 if(priv->vaspect)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3030 mp_msg(MSGT_MUXER, MSGL_INFO, " aspect ratio to %s", aspect_ratios[priv->vaspect]);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3031 if(priv->vbitrate)
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3032 mp_msg(MSGT_MUXER, MSGL_INFO, " bitrate to %u", conf_vbitrate);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3033 mp_msg(MSGT_MUXER, MSGL_INFO, "\n");
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3034 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3035
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3036 priv->has_video = priv->has_audio = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3037
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3038
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3039 muxer->sysrate = priv->muxrate; // initial muxrate = constrained stream parameter
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3040 priv->scr = muxer->file_end = 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3041
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3042 if(conf_init_adelay)
14772
70f0de24b30a renamed init_adelay to vdelay with opposite range
nicodvb
parents: 14753
diff changeset
3043 priv->init_adelay = - (double) conf_init_adelay / (double) 1000.0;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3044
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3045 priv->drop = conf_drop;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3046
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3047 priv->buff = (uint8_t *) malloc(priv->packet_size);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3048 priv->tmp = (uint8_t *) malloc(priv->packet_size);
15947
e3d7f52776ff added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents: 15278
diff changeset
3049 priv->abuf = (uint8_t *) malloc(priv->packet_size);
17271
9e20b0073d9b simplification: don't use residual_buffer, but prepend remainder of current frame to next one (needed for future work; init frame->pos to 0 in reorder_frame(); fix: don't go beyond last frame in flush_buffer()
nicodvb
parents: 17091
diff changeset
3050 if((priv->buff == NULL) || (priv->tmp == NULL) || (priv->abuf == NULL))
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3051 {
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3052 mp_msg(MSGT_MUXER, MSGL_ERR, "\nCouldn't allocate %d bytes, exit\n", priv->packet_size);
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3053 return 0;
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3054 }
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3055
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3056 muxer->priv = (void *) priv;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
3057 muxer->cont_new_stream = &mpegfile_new_stream;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
3058 muxer->cont_write_chunk = &mpegfile_write_chunk;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
3059 muxer->cont_write_header = &mpegfile_write_header;
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
3060 muxer->cont_write_index = &mpegfile_write_index;
18183
ac03acb92d24 introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents: 18181
diff changeset
3061 muxer->fix_stream_parameters = &fix_parameters;
14753
70c446099f40 new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents: 12341
diff changeset
3062 return 1;
8585
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
3063 }
27da710563c2 the long-waited MUXER layer, and new MPEG-PS muxer
arpi
parents:
diff changeset
3064