Mercurial > mplayer.hg
annotate libmpdemux/parse_es.c @ 20139:1ef90de62efa
Fix problems on live streams with huge timestamps, causing overflows and
negative pts values. It also changes pts to double, since there is no
enough precision in float to represent 32bit uint timestamps.
author | rtogni |
---|---|
date | Mon, 09 Oct 2006 20:00:02 +0000 |
parents | a9e2922e91fd |
children | 4d81dbdf46b9 |
rev | line source |
---|---|
1376
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
1 //=================== MPEG-ES VIDEO PARSER ========================= |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
2 |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
3 #include <stdio.h> |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
4 #include <stdlib.h> |
1430 | 5 #include <unistd.h> |
1376
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
6 |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
7 #include "config.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
8 #include "mp_msg.h" |
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
9 #include "help_mp.h" |
1376
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
10 |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
11 #include "stream.h" |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
12 #include "demuxer.h" |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
13 #include "parse_es.h" |
1 | 14 |
15 //static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE]; | |
1376
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
16 unsigned char* videobuffer=NULL; |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
17 int videobuf_len=0; |
17418 | 18 int next_nal = -1; |
19 ///! legacy variable, 4 if stream is synced, 0 if not | |
1376
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
20 int videobuf_code_len=0; |
1 | 21 |
17418 | 22 #define MAX_SYNCLEN (10 * 1024 * 1024) |
1 | 23 // sync video stream, and returns next packet code |
24 int sync_video_packet(demux_stream_t *ds){ | |
17418 | 25 if (!videobuf_code_len) { |
1 | 26 int skipped=0; |
17418 | 27 if (!demux_pattern_3(ds, NULL, MAX_SYNCLEN, &skipped, 0x100)) { |
17420 | 28 if (skipped == MAX_SYNCLEN) |
17418 | 29 mp_msg(MSGT_DEMUXER, MSGL_ERR, "parse_es: could not sync video stream!\n", skipped); |
30 goto eof_out; | |
31 } | |
32 next_nal = demux_getc(ds); | |
33 if (next_nal < 0) | |
34 goto eof_out; | |
35 videobuf_code_len = 4; | |
36 if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,next_nal); | |
1 | 37 } |
17418 | 38 return 0x100|next_nal; |
39 | |
40 eof_out: | |
41 next_nal = -1; | |
42 videobuf_code_len = 0; | |
43 return 0; | |
1 | 44 } |
45 | |
46 // return: packet length | |
47 int read_video_packet(demux_stream_t *ds){ | |
48 int packet_start; | |
17418 | 49 int res, read; |
1 | 50 |
16369 | 51 if (VIDEOBUFFER_SIZE - videobuf_len < 5) |
52 return 0; | |
1 | 53 // SYNC STREAM |
54 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
55 | |
56 // COPY STARTCODE: | |
57 packet_start=videobuf_len; | |
17418 | 58 videobuffer[videobuf_len+0]=0; |
59 videobuffer[videobuf_len+1]=0; | |
60 videobuffer[videobuf_len+2]=1; | |
61 videobuffer[videobuf_len+3]=next_nal; | |
1 | 62 videobuf_len+=4; |
63 | |
64 // READ PACKET: | |
17418 | 65 res = demux_pattern_3(ds, &videobuffer[videobuf_len], |
66 VIDEOBUFFER_SIZE - videobuf_len, &read, 0x100); | |
67 videobuf_len += read; | |
68 if (!res) | |
69 goto eof_out; | |
70 | |
71 videobuf_len-=3; | |
1 | 72 |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
73 mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: packet 0x1%02X len=%d (total=%d)\n",videobuffer[packet_start+3],videobuf_len-packet_start,videobuf_len); |
1 | 74 |
75 // Save next packet code: | |
17418 | 76 next_nal = demux_getc(ds); |
77 if (next_nal < 0) | |
78 goto eof_out; | |
1 | 79 videobuf_code_len=4; |
80 | |
81 return videobuf_len-packet_start; | |
17418 | 82 |
83 eof_out: | |
84 next_nal = -1; | |
85 videobuf_code_len = 0; | |
86 return videobuf_len - packet_start; | |
1 | 87 } |
88 | |
89 // return: next packet code | |
90 int skip_video_packet(demux_stream_t *ds){ | |
91 | |
92 // SYNC STREAM | |
93 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
94 | |
95 videobuf_code_len=0; // force resync | |
96 | |
97 // SYNC AGAIN: | |
98 return sync_video_packet(ds); | |
99 } |