Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
aom-rav1e
Commits
17d2394c
Commit
17d2394c
authored
Mar 14, 2014
by
James Zern
Committed by
Gerrit Code Review
Mar 14, 2014
Browse files
Merge "y4minput: add some tolerance for read short counts"
parents
5aa56f7c
df0829fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
y4minput.c
View file @
17d2394c
...
...
@@ -10,10 +10,37 @@
* Based on code from the OggTheora software codec source code,
* Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors.
*/
#include
<errno.h>
#include
<stdlib.h>
#include
<string.h>
#include
"vpx/vpx_integer.h"
#include
"y4minput.h"
// Reads 'size' bytes from 'file' into 'buf' with some fault tolerance.
// Returns true on success.
static
int
file_read
(
void
*
buf
,
size_t
size
,
FILE
*
file
)
{
const
int
kMaxRetries
=
5
;
int
retry_count
=
0
;
size_t
len
=
0
;
do
{
const
size_t
n
=
fread
((
uint8_t
*
)
buf
+
len
,
1
,
size
-
len
,
file
);
len
+=
n
;
if
(
ferror
(
file
))
{
if
(
errno
==
EINTR
||
errno
==
EAGAIN
)
{
++
retry_count
;
clearerr
(
file
);
continue
;
}
else
{
fprintf
(
stderr
,
"Error reading file: %u of %u bytes read, %d: %s
\n
"
,
(
uint32_t
)
len
,
(
uint32_t
)
size
,
errno
,
strerror
(
errno
));
return
0
;
}
}
}
while
(
!
feof
(
file
)
&&
len
<
size
&&
retry_count
<
kMaxRetries
);
return
len
==
size
;
}
static
int
y4m_parse_tags
(
y4m_input
*
_y4m
,
char
*
_tags
)
{
int
got_w
;
int
got_h
;
...
...
@@ -670,8 +697,7 @@ int y4m_input_open(y4m_input *_y4m, FILE *_fin, char *_skip, int _nskip,
buffer
[
i
]
=
*
_skip
++
;
_nskip
--
;
}
else
{
ret
=
(
int
)
fread
(
buffer
+
i
,
1
,
1
,
_fin
);
if
(
ret
<
1
)
return
-
1
;
if
(
!
file_read
(
buffer
+
i
,
1
,
_fin
))
return
-
1
;
}
if
(
buffer
[
i
]
==
'\n'
)
break
;
}
...
...
@@ -853,10 +879,8 @@ int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) {
int
c_w
;
int
c_h
;
int
c_sz
;
int
ret
;
/*Read and skip the frame header.*/
ret
=
(
int
)
fread
(
frame
,
1
,
6
,
_fin
);
if
(
ret
<
6
)
return
0
;
if
(
!
file_read
(
frame
,
6
,
_fin
))
return
0
;
if
(
memcmp
(
frame
,
"FRAME"
,
5
))
{
fprintf
(
stderr
,
"Loss of framing in Y4M input data
\n
"
);
return
-
1
;
...
...
@@ -864,19 +888,19 @@ int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) {
if
(
frame
[
5
]
!=
'\n'
)
{
char
c
;
int
j
;
for
(
j
=
0
;
j
<
79
&&
fread
(
&
c
,
1
,
1
,
_fin
)
&&
c
!=
'\n'
;
j
++
)
;
for
(
j
=
0
;
j
<
79
&&
f
ile_
read
(
&
c
,
1
,
_fin
)
&&
c
!=
'\n'
;
j
++
)
{}
if
(
j
==
79
)
{
fprintf
(
stderr
,
"Error parsing Y4M frame header
\n
"
);
return
-
1
;
}
}
/*Read the frame data that needs no conversion.*/
if
(
f
read
(
_y4m
->
dst_buf
,
1
,
_y4m
->
dst_buf_read_sz
,
_fin
)
!=
_y4m
->
dst_buf_read_sz
)
{
if
(
!
file_
read
(
_y4m
->
dst_buf
,
_y4m
->
dst_buf_read_sz
,
_fin
))
{
fprintf
(
stderr
,
"Error reading Y4M frame data.
\n
"
);
return
-
1
;
}
/*Read the frame data that does need conversion.*/
if
(
f
read
(
_y4m
->
aux_buf
,
1
,
_y4m
->
aux_buf_read_sz
,
_fin
)
!=
_y4m
->
aux_buf_read_sz
)
{
if
(
!
file_
read
(
_y4m
->
aux_buf
,
_y4m
->
aux_buf_read_sz
,
_fin
))
{
fprintf
(
stderr
,
"Error reading Y4M frame data.
\n
"
);
return
-
1
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment