4
* Procedures concerned with reading data and parsing
5
* start codes from MPEG files.
10
* Copyright (c) 1995 The Regents of the University of California.
11
* All rights reserved.
13
* Permission to use, copy, modify, and distribute this software and its
14
* documentation for any purpose, without fee, and without written agreement is
15
* hereby granted, provided that the above copyright notice and the following
16
* two paragraphs appear in all copies of this software.
18
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
19
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
20
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
21
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
24
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
26
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
27
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
31
* Portions of this software Copyright (c) 1995 Brown University.
32
* All rights reserved.
34
* Permission to use, copy, modify, and distribute this software and its
35
* documentation for any purpose, without fee, and without written agreement
36
* is hereby granted, provided that the above copyright notice and the
37
* following two paragraphs appear in all copies of this software.
39
* IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR
40
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
41
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN
42
* UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
* BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
45
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
46
* PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
47
* BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
48
* SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
51
#include <sys/types.h>
59
#include "SDL_endian.h"
67
Changes to make the code reentrant:
68
deglobalized: totNumFrames, realTimeStart, stream id vars, Prase_done,
69
swap, seekValue, input, EOF_flag, ReadPacket statics, sys_layer,
70
bitOffset, bitLength, bitBuffer, curVidStream
71
removed: [aud,sys,vid]Bytes
73
get rid on ANSI C complaints about shifting
74
-lsh@cs.brown.edu (Loring Holden)
78
*--------------------------------------------------------------
82
* Called by get_more_data to read in more data from
83
* video MPG files (non-system-layer)
86
* Input buffer updated, buffer length updated.
87
* Returns 1 if data read, 0 if EOF, -1 if error.
92
*--------------------------------------------------------------
96
get_more_data( VidStream* vid_stream )
98
unsigned int *buf_start;
99
int length, num_read, i;
100
unsigned int request;
101
unsigned char *buffer, *mark;
103
Sint32 timestamp_offset;
106
if (vid_stream->EOF_flag) return 0;
108
buf_start = vid_stream->buf_start;
109
length = vid_stream->buf_length;
110
buffer = (unsigned char *) vid_stream->buffer;
113
memcpy((unsigned char *) buf_start, buffer, (unsigned int) (length*4));
114
mark = ((unsigned char *) (buf_start + length));
117
mark = (unsigned char *) buf_start;
121
request = (vid_stream->max_buf_length-length)*4;
123
data_pos = vid_stream->_smpeg->mpeg->pos;
124
num_read = vid_stream->_smpeg->mpeg->copy_data((Uint8 *)mark, request);
126
vid_stream->timestamp = vid_stream->_smpeg->mpeg->timestamp;
127
timestamp_offset = vid_stream->_smpeg->mpeg->timestamp_pos - data_pos;
128
vid_stream->timestamp_mark = (unsigned int *)(mark+timestamp_offset);
129
vid_stream->timestamp_used = false;
131
/* Paulo Villegas - 26/1/1993: Correction for 4-byte alignment */
133
int num_read_rounded;
134
unsigned char *index;
136
num_read_rounded = 4*(num_read/4);
138
/* this can happen only if num_read<request; i.e. end of file reached */
139
if ( num_read_rounded < num_read ) {
140
num_read_rounded = 4*( num_read/4+1 );
142
/* fill in with zeros */
143
for( index=mark+num_read; index<mark+num_read_rounded; *(index++)=0 );
145
/* advance to the next 4-byte boundary */
146
num_read = num_read_rounded;
154
vid_stream->buffer = buf_start;
156
/* Make 32 bits after end equal to 0 and 32
157
* bits after that equal to seq end code
158
* in order to prevent messy data from infinite
162
*(buf_start + length) = 0x0;
163
*(buf_start + length+1) = SEQ_END_CODE;
165
vid_stream->EOF_flag = 1;
169
lmark = (unsigned int *) mark;
171
num_read = num_read/4;
173
for (i = 0; i < num_read; i++) {
174
*lmark = SDL_SwapBE32(*lmark);
178
vid_stream->buffer = buf_start;
179
vid_stream->buf_length = length + num_read;