Mercurial > mplayer.hg
annotate libmpdemux/muxer_mpeg.c @ 21449:77088392a591
[cosmetics] Reindent XML source
author | torinthiel |
---|---|
date | Sun, 03 Dec 2006 12:12:29 +0000 |
parents | 24775c741a9a |
children | dd765bcd83aa |
rev | line source |
---|---|
8585 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
5 #include <sys/types.h> | |
6 | |
7 #include "config.h" | |
17012 | 8 #include "version.h" |
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 | 11 |
12341
0db4a3a5b01d
removed loader/ dependancy, imported some files from g2, also used patches from Dominik Mierzejewski
alex
parents:
11223
diff
changeset
|
12 #include "aviheader.h" |
0db4a3a5b01d
removed loader/ dependancy, imported some files from g2, also used patches from Dominik Mierzejewski
alex
parents:
11223
diff
changeset
|
13 #include "ms_hdr.h" |
0db4a3a5b01d
removed loader/ dependancy, imported some files from g2, also used patches from Dominik Mierzejewski
alex
parents:
11223
diff
changeset
|
14 |
8585 | 15 #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
|
16 #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
|
17 #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
|
18 #include "stheader.h" |
17012 | 19 #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
|
20 #include "mpeg_hdr.h" |
17091 | 21 #include "mp3_hdr.h" |
22 #include "liba52/a52.h" | |
8585 | 23 |
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
|
24 #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
|
25 #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
|
26 #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
|
27 |
70c446099f40
new mpeg 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 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
|
29 #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
|
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
|
31 #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
|
32 #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
|
33 |
70c446099f40
new mpeg 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 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
|
35 #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
|
36 #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
|
37 #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
|
38 #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
|
39 #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
|
40 #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
|
41 //#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
|
42 #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
|
43 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
44 #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
|
45 #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
|
46 #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
|
47 #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
|
48 |
70c446099f40
new mpeg 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 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
|
50 #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
|
51 #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
|
52 #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
|
53 #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
|
54 #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
|
55 #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
|
56 #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
|
57 |
70c446099f40
new mpeg 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 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
|
59 #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
|
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
|
61 |
70c446099f40
new mpeg 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 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
|
63 "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
|
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
|
65 |
70c446099f40
new mpeg 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 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
|
67 "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
|
68 }; |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
71 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
|
72 static uint32_t conf_muxrate = 0; //kb/s |
15083 | 73 static float conf_vaspect = 0; |
14914 | 74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 static int conf_init_adelay = 0; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
80 static int conf_abuf_size = 0; |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
81 static int conf_vbuf_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
|
82 static int conf_drop = 0; |
14840 | 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 | 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 { |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
124 uint64_t dts, pts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
125 uint64_t frame_dts, frame_pts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
126 int len, stflen; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
127 } pack_stats_t; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
128 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
129 typedef struct { |
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
|
130 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
|
131 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
|
132 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
|
133 uint16_t packet_size; |
21141 | 134 int is_dvd, is_xvcd, is_xsvcd, is_genmpeg1, is_genmpeg2, rawpes, ts_allframes, has_video, has_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
|
135 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
|
136 off_t headers_size, data_size; |
18200 | 137 uint64_t scr; |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
138 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
|
139 uint32_t muxrate; |
18200 | 140 uint8_t *buff; |
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
|
141 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
|
142 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
|
143 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
|
144 |
70c446099f40
new mpeg 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 //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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 } 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
|
152 |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 typedef struct { |
18200 | 155 int has_pts, has_dts, pes_is_aligned, type, min_pes_hlen, psm_fixed; |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
156 int real_framerate, delay_rff; |
18200 | 157 uint64_t pts, last_pts, last_dts, dts, size, frame_duration, delta_pts, nom_delta_pts, 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
|
158 uint32_t buffer_size; |
18200 | 159 double delta_clock, timer; |
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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 int max_tr; |
17301
bbf5438d646a
removed previously forgotten reording options/flags
nicodvb
parents:
17298
diff
changeset
|
166 uint8_t id, is_mpeg12, telecine; |
14840 | 167 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
|
168 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
|
169 mp_mpeg_header_t picture; |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
170 int max_buffer_size; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
171 buffer_track_t *buffer_track; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
172 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
|
173 unsigned char *pack; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
174 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
|
175 int frames; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
176 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
|
177 int is_ready; |
18248
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
178 int mpa_layer; |
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
|
179 } 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
|
180 |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
181 #define PULLDOWN32 1 |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
182 #define TELECINE_FILM2PAL 2 |
8585 | 183 |
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
|
184 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
|
185 {"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
|
186 {"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
|
187 {"muxrate", &(conf_muxrate), CONF_TYPE_INT, CONF_RANGE, 0, 12000000, NULL}, //12 Mb/s |
15083 | 188 {"vaspect", &(conf_vaspect), CONF_TYPE_FLOAT, 0, 0, 0, NULL}, |
14914 | 189 {"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
|
190 {"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
|
191 {"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
|
192 {"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
|
193 {"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
|
194 {"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
|
195 {"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
|
196 {"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
|
197 {"vdelay", &conf_init_adelay, CONF_TYPE_INT, CONF_RANGE, 1, 32760, NULL}, |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
198 {"vbuf_size", &conf_vbuf_size, CONF_TYPE_INT, CONF_RANGE, 40, 1024, NULL}, |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
199 {"abuf_size", &conf_abuf_size, CONF_TYPE_INT, CONF_RANGE, 4, 64, 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
|
200 {"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
|
201 {"tsaf", &conf_ts_allframes, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
202 {"telecine", &conf_telecine, CONF_TYPE_FLAG, 0, 0, PULLDOWN32, NULL}, |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
203 {"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
|
204 {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
|
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 |
70c446099f40
new mpeg 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 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
|
208 { |
70c446099f40
new mpeg 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 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
|
210 |
70c446099f40
new mpeg 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 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
|
212 { |
70c446099f40
new mpeg 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 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
|
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 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
|
216 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
|
217 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
|
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 } |
70c446099f40
new mpeg 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 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
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 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
|
225 (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
|
226 (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
|
227 (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
|
228 ); |
70c446099f40
new mpeg 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 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
232 { |
70c446099f40
new mpeg 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 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
|
234 (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
|
235 (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
|
236 (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
|
237 (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
|
238 (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
|
239 ); |
70c446099f40
new mpeg 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 } |
8585 | 241 |
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
|
242 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
|
243 { |
70c446099f40
new mpeg 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 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
|
245 (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
|
246 (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
|
247 (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
|
248 (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
|
249 (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
|
250 (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
|
251 (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
|
252 (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
|
253 (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
|
254 (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
|
255 (x == mmioFOURCC('F', 'M','P','4')) || |
18164 | 256 (x == mmioFOURCC('f', 'm','p','4')) || |
257 (x == mmioFOURCC('D', 'X','5','0')) || | |
258 (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
|
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 } |
70c446099f40
new mpeg 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 //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
|
263 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
|
264 { |
70c446099f40
new mpeg 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 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
|
266 |
70c446099f40
new mpeg 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 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
|
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 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
|
270 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
|
271 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
|
272 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
276 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
|
277 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
|
278 |
70c446099f40
new mpeg 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 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
|
280 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
284 { |
70c446099f40
new mpeg 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 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
|
286 |
70c446099f40
new mpeg 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 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
|
288 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
|
289 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
|
290 |
70c446099f40
new mpeg 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 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
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 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
|
305 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
|
306 |
70c446099f40
new mpeg 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 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
|
308 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
312 { |
70c446099f40
new mpeg 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 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
|
314 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
|
315 |
70c446099f40
new mpeg 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 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
|
317 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
|
318 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
|
319 |
70c446099f40
new mpeg 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 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
|
321 { |
70c446099f40
new mpeg 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].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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
330 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
331 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
|
332 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
333 |
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
|
334 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 | 335 |
336 static muxer_stream_t* mpegfile_new_stream(muxer_t *muxer,int type){ | |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
337 muxer_priv_t *priv = (muxer_priv_t*) muxer->priv; |
8585 | 338 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
|
339 muxer_headers_t *spriv; |
8585 | 340 |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
341 if (!muxer) return NULL; |
8585 | 342 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
|
343 mp_msg(MSGT_MUXER, MSGL_ERR, "Too many streams! increase MUXER_MAX_STREAMS !\n"); |
8585 | 344 return NULL; |
345 } | |
346 switch (type) { | |
347 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
|
348 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
|
349 mp_msg(MSGT_MUXER, MSGL_ERR, "MPEG files can't contain more than 16 video streams!\n"); |
8585 | 350 return NULL; |
351 } | |
352 break; | |
353 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
|
354 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
|
355 mp_msg(MSGT_MUXER, MSGL_ERR, "MPEG files can't contain more than 16 audio streams!\n"); |
8585 | 356 return NULL; |
357 } | |
358 break; | |
359 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
|
360 mp_msg(MSGT_MUXER, MSGL_ERR, "Unknown stream type!\n"); |
8585 | 361 return NULL; |
362 } | |
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
|
363 s = (muxer_stream_t*) calloc(1, sizeof(muxer_stream_t)); |
8585 | 364 if(!s) return NULL; // no mem!? |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
365 if (!(s->b_buffer = malloc(priv->packet_size))) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
366 goto init_fail; |
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
|
367 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
|
368 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
|
369 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
|
370 s->priv = (muxer_headers_t*) calloc(1, sizeof(muxer_headers_t)); |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
371 if(s->priv == NULL) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
372 goto init_fail; |
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
|
373 spriv = (muxer_headers_t *) s->priv; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
374 spriv->pack = malloc(priv->packet_size); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
375 if(! spriv->pack) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
376 goto init_fail; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
377 spriv->buffer_track = calloc(1, 4096*sizeof(buffer_track_t)); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
378 if(!spriv->buffer_track) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
379 goto init_fail; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
380 spriv->track_pos = 0; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
381 spriv->track_len = 4096; |
8585 | 382 muxer->streams[muxer->avih.dwStreams]=s; |
383 s->type=type; | |
384 s->id=muxer->avih.dwStreams; | |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
385 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
|
386 |
11223 | 387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 if(priv->is_genmpeg1 || priv->is_genmpeg2) { |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
393 int v = (conf_vbuf_size ? conf_vbuf_size*1024 : |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
394 (s->h.dwSuggestedBufferSize ? s->h.dwSuggestedBufferSize : 46*1024)); |
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
|
395 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
|
396 |
70c446099f40
new mpeg 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 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
|
398 priv->sys_info.streams[n].type = 1; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
399 priv->sys_info.streams[n].bufsize = v; |
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
|
400 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
|
401 } |
11223 | 402 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
|
403 priv->has_video++; |
11223 | 404 s->h.fccType=streamtypeVIDEO; |
405 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
|
406 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
|
407 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
|
408 spriv->framebuf = init_frames(spriv->framebuf_cnt, (size_t) 5000); |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
409 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
|
410 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't allocate initial frames structure, abort!\n"); |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
411 goto init_fail; |
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 } |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 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
|
417 spriv->min_pes_hlen = 22; |
14840 | 418 spriv->telecine = conf_telecine; |
11223 | 419 mp_msg (MSGT_MUXER, MSGL_DBG2, "Added video stream %d, ckid=%X\n", muxer->num_videos, s->ckid); |
420 } 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
|
421 spriv->type = 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 if(priv->is_genmpeg1 || priv->is_genmpeg2) { |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
430 int a1 = (conf_abuf_size ? conf_abuf_size*1024 : |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
431 (s->h.dwSuggestedBufferSize ? s->h.dwSuggestedBufferSize : 4*1024)); |
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
|
432 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
|
433 |
70c446099f40
new mpeg 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 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
|
435 priv->sys_info.streams[n].type = 0; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
436 priv->sys_info.streams[n].bufsize = a1; |
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
|
437 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
|
438 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 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
|
443 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
444 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
|
445 priv->has_audio++; |
11223 | 446 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
|
447 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 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
|
452 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't allocate initial frames structure, abort!\n"); |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
453 goto init_fail; |
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
|
454 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
455 |
11223 | 456 mp_msg (MSGT_MUXER, MSGL_DBG2, "Added audio stream %d, ckid=%X\n", s->id - muxer->num_videos + 1, s->ckid); |
457 } | |
8585 | 458 muxer->avih.dwStreams++; |
459 return s; | |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
460 |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
461 init_fail: |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
462 if(s) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
463 { |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
464 if(s->priv) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
465 { |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
466 spriv = s->priv; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
467 if(spriv->pack) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
468 free(spriv->pack); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
469 if(spriv->buffer_track) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
470 free(spriv->buffer_track); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
471 free(s->priv); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
472 } |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
473 if(s->b_buffer) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
474 free(s->b_buffer); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
475 free(s); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
476 } |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
477 return NULL; |
8585 | 478 } |
479 | |
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
|
480 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
|
481 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
|
482 b[0] = mod | ((ts >> 29) & 0xf) | 1; |
8585 | 483 b[1] = (ts >> 22) & 0xff; |
484 b[2] = ((ts >> 14) & 0xff) | 1; | |
485 b[3] = (ts >> 7) & 0xff; | |
486 b[4] = ((ts << 1) & 0xff) | 1; | |
487 } | |
488 | |
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
|
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 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
|
491 { |
70c446099f40
new mpeg 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 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
|
493 |
70c446099f40
new mpeg 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 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
|
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 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
|
497 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
|
498 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
|
499 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
500 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
|
501 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
502 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
|
503 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
|
504 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
|
505 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
510 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
511 //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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 |
70c446099f40
new mpeg 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 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
|
518 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
|
519 |
70c446099f40
new mpeg 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 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
|
521 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
|
522 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
525 { |
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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 |
70c446099f40
new mpeg 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 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
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 |
70c446099f40
new mpeg 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 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
|
544 { |
70c446099f40
new mpeg 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 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
|
546 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
|
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 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
|
549 *(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
|
550 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
|
551 { |
70c446099f40
new mpeg 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 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
|
553 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
|
554 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
|
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 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
|
557 { |
70c446099f40
new mpeg 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 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
|
559 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
|
560 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
|
561 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
|
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 |
70c446099f40
new mpeg 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 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
|
565 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
569 { |
70c446099f40
new mpeg 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 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
|
571 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
|
572 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
|
573 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
|
574 |
70c446099f40
new mpeg 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 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
|
576 *(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
|
577 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
|
578 *(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
|
579 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
|
580 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
|
581 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
|
582 |
70c446099f40
new mpeg 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 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
|
584 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
|
585 |
70c446099f40
new mpeg 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 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
|
587 |
70c446099f40
new mpeg 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 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
|
589 { |
70c446099f40
new mpeg 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 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
|
591 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
|
592 (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
|
593 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
|
594 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 *(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
|
597 |
70c446099f40
new mpeg 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 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
|
599 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
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 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 |
70c446099f40
new mpeg 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 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
|
610 *(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
|
611 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
|
612 *(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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 *(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
|
619 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
|
620 |
70c446099f40
new mpeg 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 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
|
622 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
|
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 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
|
625 (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
|
626 (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
|
627 (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
|
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 { |
70c446099f40
new mpeg 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 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
|
631 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
|
632 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
|
633 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
|
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 //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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
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 } |
70c446099f40
new mpeg 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 *(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
|
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 *(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
|
646 |
19637 | 647 *(uint32_t *)(&buff[len]) = be2me_32(CalcCRC32(buff, 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
|
648 |
70c446099f40
new mpeg 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 += 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
|
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 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
|
652 } |
70c446099f40
new mpeg 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 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
|
655 { |
70c446099f40
new mpeg 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 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
|
657 |
70c446099f40
new mpeg 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 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
|
659 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
|
660 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
|
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 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
|
663 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
|
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 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
|
666 { |
70c446099f40
new mpeg 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 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
|
668 { |
70c446099f40
new mpeg 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 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
|
670 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
|
671 } |
70c446099f40
new mpeg 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 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
|
674 { |
70c446099f40
new mpeg 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 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
|
676 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
|
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 } |
70c446099f40
new mpeg 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 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
|
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 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 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
|
687 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
688 |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
691 { |
70c446099f40
new mpeg 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 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
|
693 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
|
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(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
|
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 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
|
698 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
|
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 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
|
702 { |
70c446099f40
new mpeg 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 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
|
704 { |
70c446099f40
new mpeg 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 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
|
706 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
|
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 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
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 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
|
714 { |
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
|
715 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
|
716 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
|
717 |
70c446099f40
new mpeg 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 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
|
719 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
|
720 } |
70c446099f40
new mpeg 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 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
|
723 { |
70c446099f40
new mpeg 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 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
|
725 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
|
726 } |
70c446099f40
new mpeg 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 } |
70c446099f40
new mpeg 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 *((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
|
730 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
|
731 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
735 { |
70c446099f40
new mpeg 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 //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
|
737 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
|
738 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
|
739 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
|
740 *((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
|
741 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
|
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 |
70c446099f40
new mpeg 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 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
|
745 { |
70c446099f40
new mpeg 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 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
|
747 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
|
748 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
|
749 |
70c446099f40
new mpeg 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 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
|
751 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
|
752 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
|
753 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
|
754 { |
70c446099f40
new mpeg 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 //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
|
756 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
|
757 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
|
758 } |
70c446099f40
new mpeg 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 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
|
760 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
|
761 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
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 // 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
|
767 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
|
768 |
15278
a45c7e1b998f
added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents:
15083
diff
changeset
|
769 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
|
770 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
|
771 *(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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
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 *(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
|
779 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
|
780 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
|
781 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
|
782 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
|
783 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
|
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 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
|
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 |
70c446099f40
new mpeg 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 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
|
789 { |
70c446099f40
new mpeg 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 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
|
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 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
|
793 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
|
794 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
|
795 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
|
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 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
|
798 { |
70c446099f40
new mpeg 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 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
|
800 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
|
801 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
|
802 } |
70c446099f40
new mpeg 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 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
|
804 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
|
805 |
70c446099f40
new mpeg 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 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
|
807 { |
70c446099f40
new mpeg 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 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
|
809 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
|
810 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
|
811 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
|
812 } |
70c446099f40
new mpeg 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 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
814 //len = max(h->min_pes_hlen, 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
|
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; |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
817 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
818 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
819 |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
820 static int write_mpeg_pack(muxer_t *muxer, muxer_stream_t *s, FILE *f, int isoend) |
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
|
821 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
822 size_t tot, offset; |
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
|
823 muxer_priv_t *priv; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
824 unsigned char *buff; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
825 int 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
|
826 |
70c446099f40
new mpeg 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 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
|
828 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
|
829 |
70c446099f40
new mpeg 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 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
|
831 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
832 offset = priv->packet_size - 4; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
833 write_pes_padding(buff, offset); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
834 buff[offset + 0] = buff[offset + 1] = 0; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
835 buff[offset + 2] = 1; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
836 buff[offset + 3] = 0xb9; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
837 |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
838 fwrite(buff, priv->packet_size, 1, 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
|
839 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
|
840 } |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
841 else //FAKE DVD NAV PACK |
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
|
842 { |
70c446099f40
new mpeg 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_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
|
844 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
|
845 |
70c446099f40
new mpeg 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 //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
|
847 |
70c446099f40
new mpeg 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 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
|
849 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
|
850 |
70c446099f40
new mpeg 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 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
|
852 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
|
853 { |
70c446099f40
new mpeg 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 //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
|
855 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
|
856 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
|
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 |
70c446099f40
new mpeg 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 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
|
860 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
|
861 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
|
862 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
|
863 |
70c446099f40
new mpeg 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 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
|
865 } |
70c446099f40
new mpeg 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 |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
868 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
|
869 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
870 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
|
871 |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
872 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
|
873 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
874 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
|
875 if(!tmp) |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
876 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
877 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
|
878 return 0; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
879 } |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
880 spriv->buffer_track = tmp; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
881 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
|
882 spriv->track_len += 16; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
883 } |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
884 |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
885 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
|
886 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
|
887 |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
888 spriv->track_pos++; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
889 } |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
890 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
891 static void fix_a52_headers(muxer_stream_t *s) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
892 { |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
893 muxer_headers_t *spriv = s->priv; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
894 int x = spriv->payload_offset; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
895 |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
896 spriv->pack[x+0] = 0x80; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
897 spriv->pack[x+1] = spriv->frames; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
898 if(spriv->frames) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
899 { |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
900 spriv->pack[x+2] = ((spriv->last_frame_rest+1) >> 8) & 0xff; //256 * 0 ... |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
901 spriv->pack[x+3] = (spriv->last_frame_rest+1) & 0xff; // + 1 byte(s) to skip |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
902 } |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
903 else |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
904 spriv->pack[x+2] = spriv->pack[x+3] = 0; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
905 } |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
906 |
18197 | 907 static inline void remove_frames(muxer_headers_t *spriv, int n) |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
908 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
909 mpeg_frame_t tmp; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
910 int i; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
911 |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
912 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
|
913 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
914 tmp = spriv->framebuf[i - n]; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
915 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
|
916 spriv->framebuf[i] = tmp; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
917 } |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
918 spriv->framebuf_used -= n; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
919 } |
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
|
920 |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
921 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
|
922 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
923 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
|
924 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
|
925 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
926 n = len = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
927 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
|
928 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
|
929 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
930 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
|
931 return len; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
932 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
|
933 len += m; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
934 frpos += m; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
935 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
|
936 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
937 frpos = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
938 n++; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
939 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
940 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
941 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
942 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
|
943 return 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
944 return len; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
945 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
946 |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
947 static int find_packet_timestamps(muxer_priv_t *priv, muxer_stream_t *s, unsigned int start, uint64_t *dts, uint64_t *pts) |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
948 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
949 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
|
950 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
|
951 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
|
952 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
953 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
|
954 return 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
955 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
956 spts = spriv->pts; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
957 sdts = spriv->dts; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
958 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
|
959 ret = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
960 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
|
961 i = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
962 else |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
963 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
964 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
|
965 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
966 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
|
967 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
|
968 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
969 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
|
970 |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
971 if(start + pes_hlen + m >= priv->packet_size) //spriv->pack_offset |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
972 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
|
973 else |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
974 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
975 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
|
976 goto fail; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
977 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
978 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
|
979 threshold = 5; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
980 else |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
981 threshold = 10; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
982 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
983 //headers+frame 0 < space available including timestamps |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
984 if(start + pes_hlen + m < priv->packet_size - threshold) |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
985 i = 1; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
986 else |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
987 i = -1; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
988 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
989 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
990 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
991 if(i > -1) |
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 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
|
994 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
|
995 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
|
996 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
997 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
|
998 ret = 1; |
18751
6dd7e4c77e3d
try to reduce the distance between consecutive frames with pts to no more than 0.4 seconds (required by dvds)
nicodvb
parents:
18745
diff
changeset
|
999 else if((spriv->framebuf[i].type == I_FRAME || priv->ts_allframes || dpts >= 36000*300)) //0.4 seconds |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1000 ret = 1; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1001 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1002 if(ret) |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1003 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1004 *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
|
1005 *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
|
1006 if(*dts == *pts) |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1007 *dts = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1008 } |
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 fail: |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1012 spriv->pts = spts; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1013 spriv->dts = sdts; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1014 return ret; |
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 |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1017 static int get_packet_stats(muxer_priv_t *priv, muxer_stream_t *s, pack_stats_t *p, int finalize) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1018 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1019 muxer_headers_t *spriv = s->priv; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1020 int len, len2, pack_hlen, pes_hlen, hlen, target, stflen, stuffing_len; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1021 uint64_t pts, dts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1022 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1023 spriv->pts = spriv->dts = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1024 p->dts = p->pts = p->frame_pts = p->frame_dts = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1025 p->len = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1026 |
21141 | 1027 if(priv->rawpes) |
1028 pack_hlen = 0; | |
1029 else if(priv->mux == MUX_MPEG1) | |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1030 pack_hlen = 12; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1031 else |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1032 pack_hlen = 14; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1033 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1034 if(find_packet_timestamps(priv, s, pack_hlen, &dts, &pts)) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1035 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1036 p->pts = p->frame_pts = pts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1037 p->dts = p->frame_dts = dts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1038 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1039 spriv->pts = pts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1040 spriv->dts = dts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1041 } |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1042 pes_hlen = calc_pes_hlen(priv->mux, spriv, priv); |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1043 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1044 p->stflen = stflen = (spriv->min_pes_hlen > pes_hlen ? spriv->min_pes_hlen - pes_hlen : 0); |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1045 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1046 target = len = priv->packet_size - pack_hlen - pes_hlen - stflen; //max space available |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1047 if(s->type == MUXER_TYPE_AUDIO && s->wf->wFormatTag == AUDIO_A52) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1048 hlen = 4; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1049 else |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1050 hlen = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1051 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1052 len -= hlen; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1053 target -= hlen; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1054 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1055 len2 = calc_packet_len(s, target, finalize); |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1056 if(!len2 || (len2 < target && s->type == MUXER_TYPE_AUDIO && !finalize)) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1057 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1058 //p->len = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1059 //p->dts = p->pts = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1060 spriv->pts = spriv->dts = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1061 //fprintf(stderr, "\r\nLEN2: %d, target: %d, type: %d\r\n", len2, target, s->type); |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1062 return 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1063 } |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1064 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1065 len = len2; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1066 stuffing_len = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1067 if(len < target) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1068 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1069 if(s->type == MUXER_TYPE_VIDEO) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1070 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1071 if(spriv->pts) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1072 target += 5; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1073 if(spriv->dts) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1074 target += 5; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1075 spriv->pts = spriv->dts = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1076 p->pts = p->dts = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1077 } |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1078 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1079 stuffing_len = target - len; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1080 if(stuffing_len > 0 && stuffing_len < 7) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1081 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1082 if(stflen + stuffing_len > 16) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1083 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1084 int x = 7 - stuffing_len; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1085 stflen -= x; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1086 stuffing_len += x; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1087 } |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1088 else |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1089 { |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1090 stflen += stuffing_len; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1091 stuffing_len = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1092 } |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1093 } |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1094 } |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1095 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1096 len += hlen; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1097 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1098 p->len = len; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1099 p->stflen = stflen; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1100 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1101 return p->len; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1102 } |
18192
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 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
|
1105 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1106 //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
|
1107 //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
|
1108 //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
|
1109 //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
|
1110 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
|
1111 muxer_headers_t *spriv = (muxer_headers_t *) s->priv; |
18958
a8e681ad7c90
Remove unused variables, patch by Stefan Huehner stefan at huehner org.
diego
parents:
18751
diff
changeset
|
1112 int len, m, n, dvd_pack = 0; |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1113 mpeg_frame_t *frm; |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1114 pack_stats_t p; |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1115 |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1116 spriv->dts = spriv->pts = 0; |
18192
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 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
|
1119 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1120 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
|
1121 return 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1122 } |
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 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
|
1125 { |
21141 | 1126 if(priv->rawpes) |
1127 spriv->pack_offset = 0; | |
1128 else | |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1129 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
|
1130 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
|
1131 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1132 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
|
1133 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
|
1134 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1135 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
|
1136 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
|
1137 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
|
1138 spriv->frames = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1139 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
|
1140 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1141 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1142 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
|
1143 { |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1144 int bufsize = 0; |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1145 //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
|
1146 //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
|
1147 //NB pts and dts can only be relative to the first frame beginning in this pack |
21141 | 1148 if((priv->is_xsvcd || priv->is_xvcd || priv->rawpes) && spriv->size == 0) |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1149 { |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1150 if(s->type == MUXER_TYPE_VIDEO) |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1151 bufsize = (conf_vbuf_size ? conf_vbuf_size : (priv->is_xvcd ? 46 : 232)); |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1152 else |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1153 bufsize = (conf_abuf_size ? conf_abuf_size : 4); |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1154 spriv->buffer_size = bufsize*1024; |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1155 } |
18192
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 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
|
1158 && 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
|
1159 dvd_pack = 1; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1160 |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1161 if(! get_packet_stats(priv, s, &p, finalize)) |
18192
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 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
|
1164 return 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1165 } |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1166 spriv->dts = p.dts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1167 spriv->pts = p.pts; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1168 if(spriv->pts) |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1169 spriv->last_saved_pts = p.pts; |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1170 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1171 spriv->pack_offset += write_mpeg_pes_header(spriv, (uint8_t *) &s->ckid, &(spriv->pack[spriv->pack_offset]), |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1172 p.len, p.stflen, priv->mux); |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1173 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1174 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
|
1175 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1176 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
|
1177 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
|
1178 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
|
1179 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
|
1180 else |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1181 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
|
1182 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1183 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1184 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
|
1185 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1186 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1187 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1188 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
|
1189 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1190 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
|
1191 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
|
1192 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
|
1193 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
|
1194 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1195 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1196 n = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1197 len = 0; |
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 frm = spriv->framebuf; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1200 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
|
1201 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1202 if(!frm->pos) |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1203 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1204 //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
|
1205 //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
|
1206 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
|
1207 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1208 break; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1209 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1210 spriv->frames++; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1211 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
|
1212 } |
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 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
|
1215 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
|
1216 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1217 len += m; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1218 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
|
1219 frm->pos += m; |
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 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
|
1222 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1223 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
|
1224 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
|
1225 n++; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1226 frm++; |
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 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1229 |
21141 | 1230 if((priv->is_xsvcd || priv->is_xvcd || priv->rawpes) && spriv->size == 0) |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1231 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
|
1232 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1233 spriv->size += len; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1234 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1235 if(dvd_pack && (spriv->pack_offset == priv->packet_size)) |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1236 write_mpeg_pack(muxer, NULL, muxer->file, 0); //insert fake Nav Packet |
18192
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 if(n > 0) |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1239 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
|
1240 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1241 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
|
1242 if(spriv->track_bufsize > spriv->max_buffer_size) |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1243 mp_msg(MSGT_MUXER, MSGL_ERR, "\r\nBUFFER OVERFLOW: %d > %d, pts: %llu\r\n", spriv->track_bufsize, spriv->max_buffer_size, spriv->pts); |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1244 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1245 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
|
1246 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
|
1247 |
21141 | 1248 if(spriv->pack_offset < priv->packet_size && !priv->rawpes) //here finalize is set |
18192
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 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
|
1251 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
|
1252 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
|
1253 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1254 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1255 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
|
1256 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1257 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
|
1258 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
|
1259 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
|
1260 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1261 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
|
1262 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
|
1263 spriv->frames = 0; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1264 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1265 return len; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1266 } |
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 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
|
1269 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1270 int i, ndts; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1271 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
|
1272 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
|
1273 muxer_headers_t *spriv; |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1274 pack_stats_t p; |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1275 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1276 ndts = -1; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1277 |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1278 //THIS RULE MUST ALWAYS apply: dts <= SCR + 0.7 seconds |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1279 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
|
1280 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1281 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
|
1282 |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1283 p.len = 0; |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1284 get_packet_stats(priv, muxer->streams[i], &p, 0); |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1285 |
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1286 if(spriv->track_bufsize + p.len > spriv->max_buffer_size) |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1287 continue; |
18745
19cd9e0f8ac4
prevent buffer overflow in the STD; simplified fill_packet() (moving part of the code to get_packet_stats())
nicodvb
parents:
18558
diff
changeset
|
1288 if(p.frame_pts && p.frame_dts > priv->scr + 63000*300) |
18192
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1289 continue; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1290 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1291 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
|
1292 { |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1293 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
|
1294 ndts = i; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1295 } |
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 |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1298 return ndts; |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1299 } |
0b77e66a7d32
introduced new functions to handle pack writing and interleaving strategy (will soon replace current ones)
nicodvb
parents:
18187
diff
changeset
|
1300 |
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
|
1301 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
|
1302 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1303 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
|
1304 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1305 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
|
1306 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
|
1307 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
|
1308 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1309 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1310 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
|
1311 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1312 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
|
1313 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
|
1314 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
|
1315 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1316 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1317 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
|
1318 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
|
1319 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1320 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
|
1321 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
|
1322 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1323 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
|
1324 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1325 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
|
1326 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
|
1327 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
|
1328 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1329 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1330 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1331 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
|
1332 { //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
|
1333 //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
|
1334 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
|
1335 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1336 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
|
1337 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
|
1338 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1339 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
|
1340 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1341 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
|
1342 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
|
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 |
70c446099f40
new mpeg 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 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
|
1346 |
70c446099f40
new mpeg 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 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
|
1348 { |
70c446099f40
new mpeg 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 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
|
1350 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
|
1351 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
|
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 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1356 static void update_scr(muxer_t *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
|
1357 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1358 muxer_priv_t *priv = muxer->priv; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1359 muxer_stream_t *stream; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1360 muxer_headers_t *spriv; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1361 int i, j; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1362 uint64_t mindts = (uint64_t) -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
|
1363 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1364 priv->scr += priv->delta_scr; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1365 |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1366 for(i = 0; i < muxer->avih.dwStreams; i++) |
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
|
1367 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1368 stream = muxer->streams[i]; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1369 spriv = stream->priv; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1370 if(spriv->framebuf_used && spriv->framebuf[0].dts < mindts) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1371 mindts = spriv->framebuf[0].dts; |
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
|
1372 } |
70c446099f40
new mpeg 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 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1374 mp_msg(MSGT_MUXER, MSGL_DBG2, "UPDATE SCR TO %"PRIu64" (%.3lf)\n", priv->scr, (double) (priv->scr/27000000.0)); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1375 |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1376 for(i = 0; i < muxer->avih.dwStreams; i++) |
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
|
1377 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1378 stream = muxer->streams[i]; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1379 spriv = stream->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
|
1380 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1381 j = 0; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1382 while(j < spriv->track_pos && priv->scr >= spriv->buffer_track[j].dts) |
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
|
1383 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1384 spriv->track_bufsize -= spriv->buffer_track[j].size; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1385 j++; |
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
|
1386 } |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1387 if(spriv->track_bufsize < 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
|
1388 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1389 double d; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1390 muxer->sysrate = (muxer->sysrate * 11) / 10; //raise by 10% |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1391 d = (double) priv->packet_size / (double)muxer->sysrate; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1392 priv->delta_scr = (uint64_t) (d * 27000000.0f); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1393 mp_msg(MSGT_MUXER, MSGL_INFO, "\r\nBUFFER UNDEFLOW at stream %d, raising muxrate to %d kb/s, delta_scr: %llu\r\n", i, muxer->sysrate/125, priv->delta_scr); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1394 spriv->track_bufsize = 0; |
21448 | 1395 } |
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
|
1396 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1397 if(j > 0) |
21448 | 1398 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1399 memmove(spriv->buffer_track, &(spriv->buffer_track[j]), (spriv->track_len - j) * sizeof(buffer_track_t)); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1400 spriv->track_pos -= j; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1401 for(j = spriv->track_pos; j < spriv->track_len; j++) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1402 spriv->buffer_track[j].size = 0; |
21448 | 1403 } |
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 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1405 if(spriv->framebuf_used && spriv->framebuf[0].dts < mindts) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1406 mindts = spriv->framebuf[0].dts; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1407 } |
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
|
1408 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1410 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1411 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
|
1412 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1413 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
|
1414 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1415 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
|
1416 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1417 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
|
1418 //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
|
1419 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
|
1420 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
|
1421 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1422 mp_msg(MSGT_MUXER, MSGL_DBG2, "CALC_FRAMES, n=%d, type=%c, pts=%.3lf\n", n, FTYPE(vpriv->framebuf[n].type), (double)vpriv->framebuf[n].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
|
1423 if(n+1 < vpriv->framebuf_used) |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1424 mp_msg(MSGT_MUXER, MSGL_DBG2, "n+1=%d, type=%c, pts=%.3lf\n", n+1, FTYPE(vpriv->framebuf[n+1].type), (double)vpriv->framebuf[n+1].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
|
1425 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1426 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
|
1427 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1428 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
|
1429 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1430 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
|
1431 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
|
1432 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1433 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1434 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1435 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
|
1436 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1437 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1438 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1439 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
|
1440 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
|
1441 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
|
1442 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
|
1443 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1444 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1445 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
|
1446 { |
18199 | 1447 int i, n, found; |
1448 int skip_cnt; | |
1449 uint64_t 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
|
1450 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
|
1451 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
|
1452 muxer_priv_t *priv = (muxer_priv_t *) muxer->priv; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1453 double duration; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1454 uint64_t iduration, iaduration; |
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
|
1455 |
70c446099f40
new mpeg 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 /* |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1457 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
|
1458 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
|
1459 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
|
1460 */ |
70c446099f40
new mpeg 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 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
|
1462 vs = as = NULL; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1463 found = 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
|
1464 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
|
1465 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1466 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
|
1467 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
|
1468 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1469 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
|
1470 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
|
1471 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
|
1472 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
|
1473 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
|
1474 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1475 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
|
1476 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
|
1477 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1478 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1479 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
|
1480 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1481 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
|
1482 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
|
1483 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1484 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1485 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
|
1486 { |
15278
a45c7e1b998f
added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents:
15083
diff
changeset
|
1487 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
|
1488 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1489 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
|
1490 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1491 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
|
1492 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
|
1493 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
|
1494 iduration += vpriv->framebuf[i].idur; |
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
|
1495 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
|
1496 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1497 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
|
1498 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1499 apriv = (muxer_headers_t*) as->priv; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1500 iaduration = 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
|
1501 for(i = 0; i < apriv->framebuf_used; 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
|
1502 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1503 iaduration += apriv->framebuf[i].idur; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1504 } |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1505 if(iaduration < iduration) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1506 { |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1507 mp_msg(MSGT_MUXER, MSGL_DBG2, "Not enough audio data exit\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
|
1508 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
|
1509 } |
70c446099f40
new mpeg 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 } |
70c446099f40
new mpeg 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 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1512 if(as != NULL && (apriv->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
|
1513 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1514 init_delay = vpriv->framebuf[0].pts - vpriv->framebuf[0].dts; |
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
|
1515 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1516 for(i = 0; i < apriv->framebuf_cnt; i++) |
21448 | 1517 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1518 apriv->framebuf[i].pts += init_delay; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1519 apriv->framebuf[i].dts += init_delay; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1520 } |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1521 apriv->last_pts += init_delay; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1522 mp_msg(MSGT_MUXER, MSGL_DBG2, "\r\nINITIAL VIDEO DELAY: %.3lf, currAPTS: %.3lf\r\n", (double) init_delay/27000000.0f, (double) apriv->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
|
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 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1525 if((priv->is_xvcd || priv->is_xsvcd) && (vpriv->size == 0)) |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
1526 vpriv->buffer_size = (conf_vbuf_size ? conf_vbuf_size : (priv->is_xvcd ? 46 : 230))*1024; |
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
|
1527 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1528 i = 0; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1529 skip_cnt = 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
|
1530 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1531 while(1) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1532 { |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1533 update_scr(muxer); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1534 i = find_best_stream(muxer); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1535 if(i < 0) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1536 continue; |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1537 if(!fill_packet(muxer, muxer->streams[i], finalize)) |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1538 skip_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
|
1539 |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1540 if(skip_cnt == muxer->avih.dwStreams) |
20344
5ccb2b837b1c
if no stream could be muxed flush_buffers() returns 0: prevents while(1) stall at the end
nicodvb
parents:
20153
diff
changeset
|
1541 { |
5ccb2b837b1c
if no stream could be muxed flush_buffers() returns 0: prevents while(1) stall at the end
nicodvb
parents:
20153
diff
changeset
|
1542 found = 0; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1543 break; |
20344
5ccb2b837b1c
if no stream could be muxed flush_buffers() returns 0: prevents while(1) stall at the end
nicodvb
parents:
20153
diff
changeset
|
1544 } |
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
|
1545 } |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1546 } |
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
|
1547 |
70c446099f40
new mpeg 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 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
|
1549 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
|
1550 } |
70c446099f40
new mpeg 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 |
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
|
1553 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
|
1554 { |
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
|
1555 // 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
|
1556 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
|
1557 |
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
|
1558 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
|
1559 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1560 |
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
|
1561 |
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
|
1562 static int soft_telecine(muxer_headers_t *vpriv, uint8_t *fps_ptr, uint8_t *se_ptr, uint8_t *pce_ptr, int n) |
14840 | 1563 { |
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
|
1564 uint8_t fps, tff, rff; |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1565 int period; |
14840 | 1566 |
17814 | 1567 if(! pce_ptr) |
1568 return 0; | |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1569 fps = 0; |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1570 period = (vpriv->telecine == TELECINE_FILM2PAL) ? 12 : 4; |
14840 | 1571 if(fps_ptr != NULL) |
1572 { | |
1573 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
|
1574 if((!fps) || (fps > FRAMERATE_24)) |
14840 | 1575 { |
1576 mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR! FRAMERATE IS INVALID: %d, disabling telecining\n", (int) fps); | |
1577 vpriv->telecine = 0; | |
1578 return 0; | |
1579 } | |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1580 if(vpriv->telecine == TELECINE_FILM2PAL) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1581 { |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1582 *fps_ptr = (*fps_ptr & 0xf0) | FRAMERATE_25; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1583 vpriv->nom_delta_pts = parse_fps(25.0); |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1584 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1585 else |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1586 { |
21448 | 1587 *fps_ptr = (*fps_ptr & 0xf0) | (fps + 3); |
1588 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
|
1589 } |
14840 | 1590 } |
1591 | |
1592 //in pce_ptr starting from bit 0 bit 24 is tff, bit 30 is rff, | |
1593 if(pce_ptr[3] & 0x2) | |
1594 { | |
1595 mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR! RFF bit is already set, disabling telecining\n"); | |
1596 vpriv->telecine = 0; | |
1597 return 0; | |
1598 } | |
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
|
1599 |
14894 | 1600 vpriv->picture.progressive_sequence = 0; |
1601 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
|
1602 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
|
1603 se_ptr[1] &= 0xf7; |
14840 | 1604 |
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
|
1605 |
14840 | 1606 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
|
1607 vpriv->trf = (pce_ptr[3] >> 6) & 0x2; |
14840 | 1608 |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1609 while(n < 0) n+=period; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1610 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
|
1611 |
14840 | 1612 //sets curent tff/rff bits |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1613 if(vpriv->telecine == TELECINE_FILM2PAL) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1614 { |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1615 //repeat 1 field every 12 frames |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1616 int rest1 = (vpriv->trf % period) == 11; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1617 int rest2 = vpriv->vframes % 999; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1618 |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1619 rff = 0; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1620 if(rest1) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1621 rff = 2; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1622 |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1623 if(vpriv->real_framerate == FRAMERATE_23976) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1624 { |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1625 //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
|
1626 //486 and 978 are ideal because they are halfway in the sequence |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1627 //additionally x % 12 == 6 (halfway between two frames with rff set) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1628 //and enough in advance to check if rest1 is valid too, |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1629 //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
|
1630 //current sequence unpatched |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1631 if(rest2 == 486 || rest2 == 978) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1632 { |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1633 if(rest1) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1634 { |
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
|
1635 //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
|
1636 //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
|
1637 vpriv->delay_rff = 7; |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1638 mp_msg(MSGT_MUXER, MSGL_V, "\r\nDELAYED: %d\r\n", rest2); |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1639 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1640 else |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1641 rff = 2; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1642 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1643 |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1644 if(!rest1 && vpriv->delay_rff) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1645 { |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1646 vpriv->delay_rff--; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1647 if(vpriv->delay_rff == 1) |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1648 { |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1649 rff = 2; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1650 vpriv->delay_rff = 0; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1651 mp_msg(MSGT_MUXER, MSGL_V, "\r\nRECOVERED: %d\r\n", rest2); |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1652 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1653 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1654 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1655 |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1656 pce_ptr[3] = (pce_ptr[3] & 0xfd) | rff; |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1657 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1658 else |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1659 { |
21448 | 1660 tff = (vpriv->trf & 0x2) ? 0x80 : 0; |
1661 rff = (vpriv->trf & 0x1) ? 0x2 : 0; | |
1662 pce_ptr[3] = (pce_ptr[3] & 0x7d) | tff | rff; | |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1663 } |
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1664 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
|
1665 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
|
1666 |
14840 | 1667 |
1668 if(! vpriv->vframes) | |
1669 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
|
1670 framerates[(vpriv->telecine == TELECINE_FILM2PAL) ? FRAMERATE_25 : fps+3], tff >> 7, rff >> 1); |
14840 | 1671 |
1672 return 1; | |
1673 } | |
1674 | |
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
|
1675 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
|
1676 { |
18199 | 1677 size_t ptr = 0, tmp = 0; |
14840 | 1678 uint8_t *fps_ptr = NULL; //pointer to the fps byte in the sequence header |
1679 uint8_t *se_ptr = NULL; //pointer to sequence extension | |
1680 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
|
1681 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
|
1682 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
|
1683 |
15278
a45c7e1b998f
added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents:
15083
diff
changeset
|
1684 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
|
1685 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
|
1686 { |
70c446099f40
new mpeg 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 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
|
1688 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
|
1689 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
1692 { // 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
|
1693 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
|
1694 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
|
1695 |
70c446099f40
new mpeg 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 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
|
1697 { |
14840 | 1698 fps_ptr = &(s->buffer[7]); |
17600
6fa1149d8c80
experimental film2pal and ntsc2pal soft teleciner
nicodvb
parents:
17591
diff
changeset
|
1699 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
|
1700 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
|
1701 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
|
1702 |
70c446099f40
new mpeg 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 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
|
1704 //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
|
1705 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
|
1706 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
|
1707 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
|
1708 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
|
1709 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
|
1710 |
70c446099f40
new mpeg 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 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
|
1712 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
|
1713 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
|
1714 |
70c446099f40
new mpeg 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 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
|
1716 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
|
1717 |
14840 | 1718 if(s->buffer[tmp] == 0 && s->buffer[tmp+1] == 0 && s->buffer[tmp+2] == 1 && s->buffer[tmp+3] == 0xb5) |
1719 { | |
1720 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
|
1721 mp_header_process_extension(&(spriv->picture), &(s->buffer[tmp+4])); |
14840 | 1722 } |
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
|
1723 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1725 |
70c446099f40
new mpeg 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 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
|
1727 { |
70c446099f40
new mpeg 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 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
|
1729 ((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
|
1730 (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
|
1731 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
|
1732 |
70c446099f40
new mpeg 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 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
|
1734 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
|
1735 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1738 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
|
1739 { // 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
|
1740 /*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
|
1741 (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
|
1742 ptr++;*/ |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1743 |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1744 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
|
1745 (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
|
1746 ptr++; |
17066
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1747 |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1748 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
|
1749 gop_reset = 1; |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1750 |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1751 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
|
1752 { |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1753 ptr++; |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1754 goto do_loop; |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1755 } |
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
|
1756 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1757 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1758 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
|
1759 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1760 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
|
1761 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
|
1762 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
|
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 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
|
1765 { |
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
|
1766 //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
|
1767 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
|
1768 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
|
1769 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
|
1770 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
|
1771 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
|
1772 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
|
1773 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
|
1774 if(gop_reset) |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1775 { |
17539
c692a99ea1bd
fixed wrong delta_frame calculation that would affect soft-telecine
nicodvb
parents:
17518
diff
changeset
|
1776 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
|
1777 } |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1778 else |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1779 { |
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
|
1780 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
|
1781 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
|
1782 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
|
1783 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
|
1784 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
|
1785 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
|
1786 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
|
1787 frames_diff = d1; |
17066
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1788 } |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
1789 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
|
1790 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
|
1791 |
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
|
1792 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
|
1793 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
|
1794 |
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
|
1795 spriv->last_tr = temp_ref; |
14894 | 1796 if(spriv->picture.mpeg1 == 0) |
1797 { | |
1798 size_t tmp = ptr; | |
1799 | |
1800 while (ptr < len-5 && | |
1801 (s->buffer[ptr] != 0 || s->buffer[ptr+1] != 0 || s->buffer[ptr+2] != 1 || s->buffer[ptr+3] != 0xb5)) | |
1802 ptr++; | |
1803 if(ptr < len-5) | |
1804 { | |
1805 pce_ptr = &(s->buffer[ptr+4]); | |
1806 if(spriv->telecine) | |
1807 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
|
1808 spriv->picture.display_time = 100; |
14894 | 1809 mp_header_process_extension(&(spriv->picture), &(s->buffer[ptr+4])); |
1810 if(spriv->picture.display_time >= 50 && spriv->picture.display_time <= 300) | |
1811 spriv->delta_pts = (spriv->nom_delta_pts * spriv->picture.display_time) / 100; | |
1812 } | |
1813 else | |
1814 spriv->delta_pts = spriv->nom_delta_pts; | |
1815 | |
1816 ptr = tmp; | |
1817 } | |
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
|
1818 } |
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
|
1819 |
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
|
1820 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
|
1821 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
|
1822 |
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
|
1823 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
|
1824 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
|
1825 |
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
|
1826 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
|
1827 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
|
1828 { |
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
|
1829 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
|
1830 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
|
1831 } |
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
|
1832 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
|
1833 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
|
1834 ((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
|
1835 |
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
|
1836 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
|
1837 { |
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
|
1838 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
|
1839 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
|
1840 |
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
|
1841 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
|
1842 { |
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
|
1843 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
|
1844 |
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
|
1845 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
|
1846 { |
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
|
1847 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
|
1848 { |
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
|
1849 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
|
1850 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
|
1851 } |
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
|
1852 } |
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
|
1853 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
|
1854 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
|
1855 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
|
1856 } |
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
|
1857 } |
14840 | 1858 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
|
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 |
15278
a45c7e1b998f
added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents:
15083
diff
changeset
|
1861 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
|
1862 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
|
1863 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1864 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1865 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1866 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
|
1867 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1868 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
|
1869 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
|
1870 |
70c446099f40
new mpeg 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 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
|
1872 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
|
1873 { |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16192
diff
changeset
|
1874 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
|
1875 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
|
1876 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
|
1877 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
|
1878 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
|
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 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
|
1881 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
|
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 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
|
1884 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
|
1885 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
1888 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
|
1889 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
|
1890 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
|
1891 |
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
|
1892 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
|
1893 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
|
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 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
|
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 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
|
1898 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
|
1899 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
|
1900 (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
|
1901 } |
70c446099f40
new mpeg 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 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
|
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 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
|
1905 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
|
1906 } |
70c446099f40
new mpeg 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 |
70c446099f40
new mpeg 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 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
|
1910 { |
70c446099f40
new mpeg 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 size_t ptr = 0; |
17815 | 1912 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
|
1913 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
|
1914 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
|
1915 |
15278
a45c7e1b998f
added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents:
15083
diff
changeset
|
1916 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
|
1917 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
|
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 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
|
1920 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
|
1921 } |
70c446099f40
new mpeg 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 |
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
|
1923 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
|
1924 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
|
1925 { |
70c446099f40
new mpeg 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(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
|
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 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
|
1929 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
|
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 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
|
1933 { |
70c446099f40
new mpeg 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 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
|
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 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
|
1937 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1938 //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
|
1939 } |
70c446099f40
new mpeg 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 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
|
1941 { |
70c446099f40
new mpeg 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 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
|
1943 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
|
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 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
|
1946 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
|
1947 delta -= vpriv->picture.timeinc_resolution; |
18163
1e4caa08161d
fixed wrong operator precedence in parse_mpeg4_video()
nicodvb
parents:
18162
diff
changeset
|
1948 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
|
1949 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
|
1950 |
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
|
1951 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
|
1952 //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
|
1953 |
70c446099f40
new mpeg 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 pt = vpriv->picture.picture_type + 1; |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16192
diff
changeset
|
1955 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
|
1956 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
|
1957 (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
|
1958 |
70c446099f40
new mpeg 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 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
|
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 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
|
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 |
70c446099f40
new mpeg 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 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
|
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 |
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
|
1967 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
|
1968 { |
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
|
1969 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
|
1970 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
|
1971 } |
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 |
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
|
1973 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
|
1974 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
|
1975 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
1976 mp_msg(MSGT_MUXER, MSGL_FATAL, "\r\nPARSE_MPEG4: add_frames(%d) failed, exit\r\n", len); |
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
|
1977 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
|
1978 } |
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
|
1979 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1980 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
|
1981 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1982 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
|
1983 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
|
1984 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1985 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
|
1986 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
|
1987 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
|
1988 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
|
1989 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
|
1990 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
|
1991 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1992 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1993 |
15278
a45c7e1b998f
added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents:
15083
diff
changeset
|
1994 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
|
1995 (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
|
1996 |
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
|
1997 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
|
1998 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
1999 return len; |
8585 | 2000 } |
2001 | |
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
|
2002 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2003 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
|
2004 { |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2005 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
|
2006 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2007 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
|
2008 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
|
2009 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2010 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
|
2011 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
|
2012 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
|
2013 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
|
2014 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2015 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
|
2016 { |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2017 if(spriv->framebuf[idx].size > SIZE_MAX - (size_t)len) |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2018 return 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
|
2019 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
|
2020 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
|
2021 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
|
2022 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
|
2023 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2024 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2025 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
|
2026 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
|
2027 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2028 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
|
2029 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2030 |
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
|
2031 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
|
2032 { |
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
|
2033 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
|
2034 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2035 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
|
2036 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
|
2037 { |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2038 spriv->framebuf = (mpeg_frame_t*) realloc_struct(spriv->framebuf, (spriv->framebuf_cnt+1), sizeof(mpeg_frame_t)); |
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
|
2039 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
|
2040 { |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2041 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
|
2042 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
|
2043 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2044 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2045 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
|
2046 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
|
2047 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
|
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
|
2049 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
|
2050 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
|
2051 { |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2052 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
|
2053 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
|
2054 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2055 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
|
2056 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
|
2057 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2058 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2059 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
|
2060 { |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2061 if(spriv->framebuf[idx].size > SIZE_MAX - (size_t)len) |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2062 { |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2063 mp_msg(MSGT_MUXER, MSGL_FATAL, "Size overflow, couldn't realloc frame buffer(frame), abort\n"); |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2064 return -1; |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2065 } |
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
|
2066 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
|
2067 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
|
2068 { |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2069 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
|
2070 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
|
2071 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2072 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
|
2073 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2074 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2075 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
|
2076 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
|
2077 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
|
2078 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
|
2079 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2080 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
|
2081 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
|
2082 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
|
2083 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
|
2084 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
|
2085 |
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
|
2086 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
|
2087 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2088 |
18248
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2089 static int analyze_mpa(muxer_stream_t *s) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2090 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2091 int i = 0, len, max, chans, srate, spf, layer; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2092 int score[4] = {0, 0, 0, 0}; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2093 |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2094 while(i < s->b_buffer_len + 3) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2095 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2096 if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xE0) == 0xE0)) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2097 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2098 len = mp_get_mp3_header(&(s->b_buffer[i]), &chans, &srate, &spf, &layer, NULL); |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2099 if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len)) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2100 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2101 score[layer]++; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2102 i += len; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2103 } |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2104 } |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2105 i++; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2106 } |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2107 |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2108 max = 0; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2109 layer = 2; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2110 for(i = 1; i <= 3; i++) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2111 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2112 if(score[i] >= max) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2113 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2114 max = score[i]; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2115 layer = i; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2116 } |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2117 } |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2118 |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2119 return layer; //actual layer with the highest score |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2120 } |
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
|
2121 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2122 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
|
2123 |
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
|
2124 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
|
2125 { |
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
|
2126 int i, j, len, chans, srate, spf, layer, dummy, tot, num, frm_idx; |
18238 | 2127 int finished; |
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
|
2128 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
|
2129 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
|
2130 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
|
2131 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
|
2132 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2133 i = tot = frames = 0; |
18238 | 2134 finished = 0; |
2135 while(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
|
2136 { |
18238 | 2137 len = 0; |
2138 switch(s->wf->wFormatTag) | |
2139 { | |
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
|
2140 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
|
2141 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
|
2142 { |
18238 | 2143 if(i + 3 >= s->b_buffer_len) |
2144 { | |
2145 finished = 1; | |
2146 break; | |
2147 } | |
2148 | |
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
|
2149 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
|
2150 { |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15947
diff
changeset
|
2151 len = mp_get_mp3_header(&(s->b_buffer[i]), &chans, &srate, &spf, &layer, NULL); |
18248
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2152 if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2153 && layer == spriv->mpa_layer) |
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
|
2154 { |
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
|
2155 dur = (double) spf / (double) srate; |
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
|
2156 idur = (27000000ULL * spf) / srate; |
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
|
2157 } |
18238 | 2158 else |
2159 len = 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
|
2160 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2161 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2162 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
|
2163 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2164 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
|
2165 { |
18238 | 2166 if(i + 6 >= s->b_buffer_len) |
2167 { | |
2168 finished = 1; | |
2169 break; | |
2170 } | |
2171 | |
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
|
2172 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
|
2173 { |
17493
f71e678e6216
use mp_a52_framesize() when liba52 is not available
nicodvb
parents:
17487
diff
changeset
|
2174 srate = 0; |
f71e678e6216
use mp_a52_framesize() when liba52 is not available
nicodvb
parents:
17487
diff
changeset
|
2175 #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
|
2176 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
|
2177 #else |
f71e678e6216
use mp_a52_framesize() when liba52 is not available
nicodvb
parents:
17487
diff
changeset
|
2178 len = mp_a52_framesize(&(s->b_buffer[i]), &srate); |
f71e678e6216
use mp_a52_framesize() when liba52 is not available
nicodvb
parents:
17487
diff
changeset
|
2179 #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
|
2180 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
|
2181 { |
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
|
2182 dur = (double) 1536 / (double) srate; |
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
|
2183 idur = (27000000ULL * 1536) / srate; |
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
|
2184 } |
18238 | 2185 else |
2186 len = 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
|
2187 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2188 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2189 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
|
2190 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2191 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
|
2192 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
|
2193 { |
18238 | 2194 if(i + 7 >= s->b_buffer_len) |
2195 { | |
2196 finished = 1; | |
2197 break; | |
2198 } | |
2199 | |
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
|
2200 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
|
2201 { |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2202 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
|
2203 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
|
2204 { |
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
|
2205 dur = (double) 1024 / (double) srate; |
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
|
2206 idur = (27000000ULL * 1024 * num) / srate; |
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
|
2207 } |
18238 | 2208 else |
2209 len = 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
|
2210 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2211 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2212 } |
18238 | 2213 |
2214 if(finished) | |
2215 break; | |
2216 | |
2217 if(!len) | |
2218 { | |
2219 i++; | |
2220 continue; | |
2221 } | |
2222 | |
2223 spriv->timer += dur; | |
2224 if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay) | |
2225 { | |
2226 i += len; | |
2227 tot = i; | |
2228 continue; | |
2229 } | |
2230 | |
2231 frames++; | |
2232 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot); | |
2233 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts); | |
2234 if(frm_idx < 0) | |
2235 { | |
2236 mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't add audio frame buffer(frame), abort\n"); | |
2237 goto audio_exit; | |
2238 } | |
2239 for(j = frm_idx; j < spriv->framebuf_cnt; j++) | |
2240 spriv->framebuf[j].pts = spriv->last_pts; | |
2241 spriv->last_pts += idur; | |
2242 | |
2243 i += len; | |
2244 tot = i; | |
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
|
2245 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2246 |
18238 | 2247 audio_exit: |
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
|
2248 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
|
2249 { |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2250 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
|
2251 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
|
2252 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
|
2253 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
|
2254 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
|
2255 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
|
2256 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2257 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2258 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
|
2259 { |
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
|
2260 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
|
2261 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
|
2262 { |
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
|
2263 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
|
2264 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
|
2265 } |
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
|
2266 } |
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
|
2267 |
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
|
2268 *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
|
2269 *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
|
2270 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2271 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
|
2272 } |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2273 |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2274 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
|
2275 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2276 muxer_headers_t *spriv = stream->priv; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2277 muxer_t *muxer = stream->muxer; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2278 muxer_priv_t *priv = muxer->priv; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2279 |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2280 if(stream->type == MUXER_TYPE_AUDIO) |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2281 { |
18248
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2282 spriv->is_ready = 1; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2283 if(conf_abuf_size) |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2284 spriv->max_buffer_size = conf_abuf_size*1024; |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2285 else |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2286 spriv->max_buffer_size = 4*1024; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2287 if(stream->wf->wFormatTag == AUDIO_A52) |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2288 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2289 stream->ckid = be2me_32 (0x1bd); |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2290 if(priv->is_genmpeg1 || priv->is_genmpeg2) |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2291 fix_audio_sys_header(priv, spriv->id, 0xbd, max(conf_abuf_size, 58)*1024); //only one audio at the moment |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2292 spriv->id = 0xbd; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2293 if(!conf_abuf_size) |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2294 spriv->max_buffer_size = 16*1024; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2295 } |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2296 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
|
2297 { |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2298 priv->use_psm = 1; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2299 } |
18248
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2300 else if(stream->wf->wFormatTag == AUDIO_MP2 || stream->wf->wFormatTag == AUDIO_MP3) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2301 spriv->is_ready = 0; |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2302 } |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2303 else //video |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2304 { |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2305 if(conf_vbuf_size) |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2306 spriv->max_buffer_size = conf_vbuf_size*1024; |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2307 else |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2308 { |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2309 if(priv->is_dvd) |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2310 spriv->max_buffer_size = 232*1024; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2311 else if(priv->is_xsvcd) |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2312 spriv->max_buffer_size = 230*1024; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2313 else if(priv->is_xvcd) |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2314 spriv->max_buffer_size = 46*1024; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2315 else |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2316 spriv->max_buffer_size = 232*1024; //no profile => unconstrained :) FIXME!!! |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2317 } |
18183
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2318 |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2319 if(is_mpeg4(stream->bih->biCompression)) |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2320 spriv->is_ready = 0; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2321 else |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2322 spriv->is_ready = 1; |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2323 } |
ac03acb92d24
introduced structures and code to keep track of decoder's buffers sizes
nicodvb
parents:
18181
diff
changeset
|
2324 } |
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
|
2325 |
e3d7f52776ff
added support for vbr audio (frames are parsed individually); fixed small bugs in the management of pes_extension
nicodvb
parents:
15278
diff
changeset
|
2326 |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
17366
diff
changeset
|
2327 static void mpegfile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts_arg, double pts_arg){ |
18249 | 2328 size_t sz = 0; |
2329 uint64_t tmp; | |
9007
12fc55eb3373
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
2330 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
|
2331 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
|
2332 muxer_headers_t *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
|
2333 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
|
2334 uint32_t stream_format, nf; |
21448 | 2335 |
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
|
2336 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
|
2337 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
|
2338 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
|
2339 return; |
21448 | 2340 |
8585 | 2341 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
|
2342 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
|
2343 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
|
2344 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
|
2345 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
|
2346 { |
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
|
2347 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
|
2348 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
|
2349 } |
8585 | 2350 |
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
|
2351 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
|
2352 { |
70c446099f40
new mpeg 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 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
|
2354 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
|
2355 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
|
2356 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
|
2357 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
|
2358 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
|
2359 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
|
2360 spriv->last_dts += tmp; |
8585 | 2361 } |
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
|
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 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
|
2364 { |
70c446099f40
new mpeg 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 spriv->is_mpeg12 = 0; |
14840 | 2366 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
|
2367 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
|
2368 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
|
2369 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
|
2370 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
|
2371 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
|
2372 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
|
2373 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
|
2374 spriv->last_dts += tmp; |
8585 | 2375 } |
2376 } | |
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
|
2377 |
15278
a45c7e1b998f
added support for AAC; moved most of MSGL_V to MSGL_DBG2 to reduce verbosity
nicodvb
parents:
15083
diff
changeset
|
2378 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); |
8585 | 2379 } 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
|
2380 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
|
2381 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
|
2382 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
|
2383 |
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
|
2384 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
|
2385 { |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2386 if(s->b_buffer_len > SIZE_MAX - len) |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2387 { |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2388 mp_msg(MSGT_MUXER, MSGL_FATAL, "\nFATAL! couldn't realloc, integer overflow\n"); |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2389 return; |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18249
diff
changeset
|
2390 } |
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
|
2391 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
|
2392 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
|
2393 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2394 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
|
2395 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
|
2396 } |
70c446099f40
new mpeg 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 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
|
2399 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
|
2400 } |
70c446099f40
new mpeg 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 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
|
2402 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
|
2403 |
18248
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2404 if(!spriv->is_ready) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2405 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2406 if(s->b_buffer_len >= 32*1024) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2407 { |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2408 spriv->mpa_layer = analyze_mpa(s); |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2409 spriv->is_ready = 1; |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2410 } |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2411 } |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2412 else |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2413 { |
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 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
|
2415 spriv->vframes += nf; |
18248
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2416 if(! spriv->vframes) |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2417 mp_msg(MSGT_MUXER, MSGL_INFO, "AINIT: %.3lf\r\n", (double) spriv->last_pts/27000000.0f); |
595d94213ad0
when muxing mpeg audio streams analyze the first 32 KB of data to obtain the most likely correct layer, otherwise every misdetection during parse_audio() will lead to wrong timestamps and loss of synchrony
nicodvb
parents:
18238
diff
changeset
|
2418 } |
8585 | 2419 } |
21448 | 2420 |
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
|
2421 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2422 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
|
2423 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
|
2424 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
|
2425 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
|
2426 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
|
2427 write_psm_block(muxer, muxer->file); |
8585 | 2428 } |
21448 | 2429 |
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
|
2430 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
|
2431 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2432 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2433 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2434 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
|
2435 { |
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
|
2436 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
|
2437 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
|
2438 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
|
2439 |
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
|
2440 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
|
2441 |
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
|
2442 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
|
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 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
|
2445 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
|
2446 } |
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
|
2447 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
|
2448 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
|
2449 if(priv->is_genmpeg1 || priv->is_genmpeg2) |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
2450 write_mpeg_pack(muxer, NULL, muxer->file, 1); //insert fake Nav Packet |
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
|
2451 |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16192
diff
changeset
|
2452 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
|
2453 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2454 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2455 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
|
2456 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2457 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
|
2458 |
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
|
2459 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
|
2460 |
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
|
2461 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
|
2462 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2463 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
|
2464 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2465 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
|
2466 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
|
2467 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2468 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
|
2469 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
|
2470 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2471 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2472 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2473 //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
|
2474 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
|
2475 { |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
2476 write_mpeg_pack(muxer, NULL, muxer->file, 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
|
2477 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
|
2478 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2479 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2480 return; |
8585 | 2481 } |
2482 | |
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
|
2483 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
|
2484 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2485 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
|
2486 { |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2487 int v = (conf_vbuf_size ? conf_vbuf_size : 232); |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2488 int a1 = (conf_abuf_size ? conf_abuf_size : 4); |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2489 int a2 = (conf_abuf_size>58 ? conf_abuf_size : 58); |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2490 |
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
|
2491 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
|
2492 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2493 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
|
2494 priv->sys_info.streams[0].type = 1; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2495 priv->sys_info.streams[0].bufsize = v*1024; |
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
|
2496 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2497 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
|
2498 priv->sys_info.streams[1].type = 0; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2499 priv->sys_info.streams[1].bufsize = a1*1024; |
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
|
2500 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2501 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
|
2502 priv->sys_info.streams[2].type = 1; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2503 priv->sys_info.streams[2].bufsize = a2*1024; |
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
|
2504 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2505 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
|
2506 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
|
2507 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
|
2508 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2509 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
|
2510 { |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2511 int v = (conf_vbuf_size ? conf_vbuf_size : (priv->is_xvcd ? 46: 230)); |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2512 int a1 = (conf_abuf_size ? conf_abuf_size : 4); |
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2513 |
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
|
2514 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
|
2515 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2516 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
|
2517 priv->sys_info.streams[0].type = 1; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2518 priv->sys_info.streams[0].bufsize = v*1024; |
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
|
2519 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2520 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
|
2521 priv->sys_info.streams[1].type = 0; |
21413
06d63614eeaa
permit to specify the sizes of the decoders' buffers
nicodvb
parents:
21372
diff
changeset
|
2522 priv->sys_info.streams[1].bufsize = a1*1024; |
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
|
2523 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2524 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
|
2525 priv->sys_info.cnt = 0; |
8585 | 2526 } |
2527 | |
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
|
2528 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2529 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
|
2530 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
|
2531 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
|
2532 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
|
2533 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
|
2534 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
|
2535 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2536 //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
|
2537 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2538 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
|
2539 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
|
2540 { |
17066
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
2541 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
|
2542 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
|
2543 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
|
2544 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
|
2545 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2546 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
|
2547 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2548 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
|
2549 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
|
2550 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
|
2551 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
|
2552 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2553 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
|
2554 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2555 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
|
2556 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
|
2557 priv->packet_size = 2324; |
18187 | 2558 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
|
2559 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
|
2560 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2561 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
|
2562 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2563 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
|
2564 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
|
2565 priv->packet_size = 2324; |
18187 | 2566 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
|
2567 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
|
2568 } |
21141 | 2569 else if(! strcasecmp(conf_mux, "pes1")) |
2570 { | |
2571 priv->mux = MUX_MPEG1; | |
2572 priv->rawpes = 1; | |
2573 priv->packet_size = 2048; | |
2574 priv->muxrate = 10080 * 125; | |
2575 priv->ts_allframes = 1; | |
2576 } | |
2577 else if(! strcasecmp(conf_mux, "pes2")) | |
2578 { | |
2579 priv->mux = MUX_MPEG2; | |
2580 priv->rawpes = 1; | |
2581 priv->packet_size = 2048; | |
2582 priv->muxrate = 10080 * 125; | |
2583 priv->ts_allframes = 1; | |
2584 } | |
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
|
2585 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
|
2586 { |
17066
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
2587 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
|
2588 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
|
2589 priv->mux = MUX_MPEG2; |
e84e5e9e9ef4
fixed wrong telecine trf pattern; fall back to mpeg2 when user specifies unknown format
nicodvb
parents:
17065
diff
changeset
|
2590 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
|
2591 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
|
2592 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
|
2593 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2594 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2595 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2596 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
|
2597 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
|
2598 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
|
2599 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
|
2600 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
|
2601 priv->packet_size = conf_packet_size; |
18196
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
2602 priv->delta_scr = (uint64_t) (90000.0f*300.0f*(double)priv->packet_size/(double)priv->muxrate); |
f7f6984638f8
finally replaced the old interleaving with the new one that respects buffering and [pd]ts<->scr constraints; don't check spriv->framebuf_used in find_best_stream()
nicodvb
parents:
18192
diff
changeset
|
2603 mp_msg(MSGT_MUXER, MSGL_INFO, "PACKET SIZE: %u bytes, deltascr: %llu\n", priv->packet_size, priv->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
|
2604 setup_sys_params(priv); |
8585 | 2605 |
15083 | 2606 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
|
2607 { |
15083 | 2608 int asp = (int) (conf_vaspect * 1000.0f); |
2609 if(asp >= 1332 && asp <= 1334) | |
2610 priv->vaspect = ASPECT_4_3; | |
2611 else if(asp >= 1776 && asp <= 1778) | |
2612 priv->vaspect = ASPECT_16_9; | |
2613 else if(asp >= 2209 && asp <= 2211) | |
2614 priv->vaspect = ASPECT_2_21_1; | |
2615 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
|
2616 priv->vaspect = ASPECT_1_1; |
15083 | 2617 else |
2618 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
|
2619 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2620 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2621 priv->vframerate = 0; // no change |
14914 | 2622 if(conf_telecine && conf_vframerate > 0) |
2623 { | |
2624 mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: options 'telecine' and 'vframerate' are mutually exclusive, vframerate disabled\n"); | |
2625 conf_vframerate = 0; | |
2626 } | |
2627 | |
2628 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
|
2629 { |
14914 | 2630 int fps; |
2631 | |
18162
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2632 fps = (int) (conf_vframerate * 1001 + 0.5); |
14914 | 2633 switch(fps) |
2634 { | |
2635 case 24000: | |
18162
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2636 priv->vframerate = FRAMERATE_23976; |
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2637 break; |
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2638 case 24024: |
14914 | 2639 priv->vframerate = FRAMERATE_24; |
2640 break; | |
18162
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2641 case 25025: |
14914 | 2642 priv->vframerate = FRAMERATE_25; |
2643 break; | |
2644 case 30000: | |
18162
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2645 priv->vframerate = FRAMERATE_2997; |
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2646 break; |
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2647 case 30030: |
14914 | 2648 priv->vframerate = FRAMERATE_30; |
2649 break; | |
18162
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2650 case 50050: |
14914 | 2651 priv->vframerate = FRAMERATE_50; |
2652 break; | |
2653 case 60000: | |
18162
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2654 priv->vframerate = FRAMERATE_5994; |
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2655 break; |
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2656 case 60060: |
14914 | 2657 priv->vframerate = FRAMERATE_60; |
2658 break; | |
2659 default: | |
18162
1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
nicodvb
parents:
18161
diff
changeset
|
2660 mp_msg(MSGT_MUXER, MSGL_ERR, "WRONG FPS: %d/1000, ignoring\n", fps); |
14914 | 2661 } |
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
|
2662 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2663 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2664 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
|
2665 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
|
2666 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
|
2667 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
|
2668 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
|
2669 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2670 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
|
2671 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2672 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
|
2673 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
|
2674 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
|
2675 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
|
2676 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
|
2677 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
|
2678 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
|
2679 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
|
2680 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
|
2681 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
|
2682 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
|
2683 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
|
2684 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
|
2685 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
|
2686 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2687 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2688 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
|
2689 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2690 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2691 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
|
2692 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
|
2693 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2694 if(conf_init_adelay) |
14772
70f0de24b30a
renamed init_adelay to vdelay with opposite range
nicodvb
parents:
14753
diff
changeset
|
2695 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
|
2696 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2697 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
|
2698 |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2699 priv->buff = (uint8_t *) malloc(priv->packet_size); |
18200 | 2700 if((priv->buff == 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
|
2701 { |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2702 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
|
2703 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
|
2704 } |
70c446099f40
new mpeg muxer compatible with dvd/[s]vcd; small changes in the muxer layer (sanity checks in the muxer_init functions)
nicodvb
parents:
12341
diff
changeset
|
2705 |
70c446099f40
new mpeg 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 = (void *) priv; |
8585 | 2707 muxer->cont_new_stream = &mpegfile_new_stream; |
2708 muxer->cont_write_chunk = &mpegfile_write_chunk; | |
2709 muxer->cont_write_header = &mpegfile_write_header; | |
2710 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
|
2711 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
|
2712 return 1; |
8585 | 2713 } |
2714 |