Make AltiVec code write alpha as 255 instead of 0 when converting to RGBA
[mplayer/glamo.git] / libmpdemux / parse_es.c
blobd907d284225f5e1ea79f7f6e832399fec49eb515
1 //=================== MPEG-ES VIDEO PARSER =========================
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 #include "config.h"
8 #include "mp_msg.h"
9 #include "help_mp.h"
11 #include "stream/stream.h"
12 #include "demuxer.h"
13 #include "parse_es.h"
15 //static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
16 unsigned char* videobuffer=NULL;
17 int videobuf_len=0;
18 int next_nal = -1;
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) {
26 int skipped=0;
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");
30 goto eof_out;
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);
38 return 0x100|next_nal;
40 eof_out:
41 next_nal = -1;
42 videobuf_code_len = 0;
43 return 0;
46 // return: packet length
47 int read_video_packet(demux_stream_t *ds){
48 int packet_start;
49 int res, read;
51 if (VIDEOBUFFER_SIZE - videobuf_len < 5)
52 return 0;
53 // SYNC STREAM
54 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
56 // COPY STARTCODE:
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;
62 videobuf_len+=4;
64 // READ PACKET:
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;
71 videobuf_len-=3;
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);
77 if (next_nal < 0)
78 goto eof_out;
79 videobuf_code_len=4;
81 return videobuf_len-packet_start;
83 eof_out:
84 next_nal = -1;
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){
92 // SYNC STREAM
93 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
95 videobuf_code_len=0; // force resync
97 // SYNC AGAIN:
98 return sync_video_packet(ds);