1 //=================== MPEG-ES VIDEO PARSER =========================
11 #include "stream/stream.h"
15 //static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
16 unsigned char* videobuffer
=NULL
;
19 ///! legacy variable, 4 if stream is synced, 0 if not
20 int videobuf_code_len
=0;
22 #define MAX_SYNCLEN (10 * 1024 * 1024)
23 // sync video stream, and returns next packet code
24 int sync_video_packet(demux_stream_t
*ds
){
25 if (!videobuf_code_len
) {
27 if (!demux_pattern_3(ds
, NULL
, MAX_SYNCLEN
, &skipped
, 0x100)) {
28 if (skipped
== MAX_SYNCLEN
)
29 mp_msg(MSGT_DEMUXER
, MSGL_ERR
, "parse_es: could not sync video stream!\n");
32 next_nal
= demux_getc(ds
);
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
);
38 return 0x100|next_nal
;
42 videobuf_code_len
= 0;
46 // return: packet length
47 int read_video_packet(demux_stream_t
*ds
){
51 if (VIDEOBUFFER_SIZE
- videobuf_len
< 5)
54 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
57 packet_start
=videobuf_len
;
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
;
65 res
= demux_pattern_3(ds
, &videobuffer
[videobuf_len
],
66 VIDEOBUFFER_SIZE
- videobuf_len
, &read
, 0x100);
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
);
75 // Save next packet code:
76 next_nal
= demux_getc(ds
);
81 return videobuf_len
-packet_start
;
85 videobuf_code_len
= 0;
86 return videobuf_len
- packet_start
;
89 // return: next packet code
90 int skip_video_packet(demux_stream_t
*ds
){
93 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
95 videobuf_code_len
=0; // force resync
98 return sync_video_packet(ds
);