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
Raphael Zumer
aom-rav1e
Commits
99e28b8b
Commit
99e28b8b
authored
Jan 27, 2016
by
clang-format
Committed by
James Zern
Jan 28, 2016
Browse files
apply clang-format
Change-Id: Ib8c9eb6263d6eba6b9d7b2e402b7e83a78c86be9
parent
0c29e46e
Changes
411
Expand all
Hide whitespace changes
Inline
Side-by-side
args.c
View file @
99e28b8b
...
...
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include
<stdlib.h>
#include
<string.h>
#include
<limits.h>
...
...
@@ -22,42 +21,36 @@ extern void die(const char *fmt, ...) __attribute__((noreturn));
extern
void
die
(
const
char
*
fmt
,
...);
#endif
struct
arg
arg_init
(
char
**
argv
)
{
struct
arg
a
;
a
.
argv
=
argv
;
a
.
argv
=
argv
;
a
.
argv_step
=
1
;
a
.
name
=
NULL
;
a
.
val
=
NULL
;
a
.
def
=
NULL
;
a
.
name
=
NULL
;
a
.
val
=
NULL
;
a
.
def
=
NULL
;
return
a
;
}
int
arg_match
(
struct
arg
*
arg_
,
const
struct
arg_def
*
def
,
char
**
argv
)
{
struct
arg
arg
;
if
(
!
argv
[
0
]
||
argv
[
0
][
0
]
!=
'-'
)
return
0
;
if
(
!
argv
[
0
]
||
argv
[
0
][
0
]
!=
'-'
)
return
0
;
arg
=
arg_init
(
argv
);
if
(
def
->
short_name
&&
strlen
(
arg
.
argv
[
0
])
==
strlen
(
def
->
short_name
)
+
1
&&
!
strcmp
(
arg
.
argv
[
0
]
+
1
,
def
->
short_name
))
{
if
(
def
->
short_name
&&
strlen
(
arg
.
argv
[
0
])
==
strlen
(
def
->
short_name
)
+
1
&&
!
strcmp
(
arg
.
argv
[
0
]
+
1
,
def
->
short_name
))
{
arg
.
name
=
arg
.
argv
[
0
]
+
1
;
arg
.
val
=
def
->
has_val
?
arg
.
argv
[
1
]
:
NULL
;
arg
.
argv_step
=
def
->
has_val
?
2
:
1
;
}
else
if
(
def
->
long_name
)
{
const
size_t
name_len
=
strlen
(
def
->
long_name
);
if
(
strlen
(
arg
.
argv
[
0
])
>=
name_len
+
2
&&
arg
.
argv
[
0
][
1
]
==
'-'
&&
!
strncmp
(
arg
.
argv
[
0
]
+
2
,
def
->
long_name
,
name_len
)
&&
(
arg
.
argv
[
0
][
name_len
+
2
]
==
'='
||
arg
.
argv
[
0
][
name_len
+
2
]
==
'\0'
))
{
if
(
strlen
(
arg
.
argv
[
0
])
>=
name_len
+
2
&&
arg
.
argv
[
0
][
1
]
==
'-'
&&
!
strncmp
(
arg
.
argv
[
0
]
+
2
,
def
->
long_name
,
name_len
)
&&
(
arg
.
argv
[
0
][
name_len
+
2
]
==
'='
||
arg
.
argv
[
0
][
name_len
+
2
]
==
'\0'
))
{
arg
.
name
=
arg
.
argv
[
0
]
+
2
;
arg
.
val
=
arg
.
name
[
name_len
]
==
'='
?
arg
.
name
+
name_len
+
1
:
NULL
;
arg
.
argv_step
=
1
;
...
...
@@ -70,8 +63,7 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) {
if
(
arg
.
name
&&
arg
.
val
&&
!
def
->
has_val
)
die
(
"Error: option %s requires no argument.
\n
"
,
arg
.
name
);
if
(
arg
.
name
&&
(
arg
.
val
||
!
def
->
has_val
))
{
if
(
arg
.
name
&&
(
arg
.
val
||
!
def
->
has_val
))
{
arg
.
def
=
def
;
*
arg_
=
arg
;
return
1
;
...
...
@@ -80,15 +72,12 @@ int arg_match(struct arg *arg_, const struct arg_def *def, char **argv) {
return
0
;
}
const
char
*
arg_next
(
struct
arg
*
arg
)
{
if
(
arg
->
argv
[
0
])
arg
->
argv
+=
arg
->
argv_step
;
if
(
arg
->
argv
[
0
])
arg
->
argv
+=
arg
->
argv_step
;
return
*
arg
->
argv
;
}
char
**
argv_dup
(
int
argc
,
const
char
**
argv
)
{
char
**
new_argv
=
malloc
((
argc
+
1
)
*
sizeof
(
*
argv
));
...
...
@@ -97,9 +86,8 @@ char **argv_dup(int argc, const char **argv) {
return
new_argv
;
}
void
arg_show_usage
(
FILE
*
fp
,
const
struct
arg_def
*
const
*
defs
)
{
char
option_text
[
40
]
=
{
0
};
char
option_text
[
40
]
=
{
0
};
for
(;
*
defs
;
defs
++
)
{
const
struct
arg_def
*
def
=
*
defs
;
...
...
@@ -109,15 +97,12 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) {
if
(
def
->
short_name
&&
def
->
long_name
)
{
char
*
comma
=
def
->
has_val
?
","
:
", "
;
snprintf
(
option_text
,
37
,
"-%s%s%s --%s%6s"
,
def
->
short_name
,
short_val
,
comma
,
def
->
long_name
,
long_val
);
snprintf
(
option_text
,
37
,
"-%s%s%s --%s%6s"
,
def
->
short_name
,
short_val
,
comma
,
def
->
long_name
,
long_val
);
}
else
if
(
def
->
short_name
)
snprintf
(
option_text
,
37
,
"-%s%s"
,
def
->
short_name
,
short_val
);
snprintf
(
option_text
,
37
,
"-%s%s"
,
def
->
short_name
,
short_val
);
else
if
(
def
->
long_name
)
snprintf
(
option_text
,
37
,
" --%s%s"
,
def
->
long_name
,
long_val
);
snprintf
(
option_text
,
37
,
" --%s%s"
,
def
->
long_name
,
long_val
);
fprintf
(
fp
,
" %-37s
\t
%s
\n
"
,
option_text
,
def
->
desc
);
...
...
@@ -127,59 +112,53 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) {
fprintf
(
fp
,
" %-37s
\t
"
,
""
);
for
(
listptr
=
def
->
enums
;
listptr
->
name
;
listptr
++
)
fprintf
(
fp
,
"%s%s"
,
listptr
->
name
,
listptr
[
1
].
name
?
", "
:
"
\n
"
);
fprintf
(
fp
,
"%s%s"
,
listptr
->
name
,
listptr
[
1
].
name
?
", "
:
"
\n
"
);
}
}
}
unsigned
int
arg_parse_uint
(
const
struct
arg
*
arg
)
{
long
int
rawval
;
char
*
endptr
;
long
int
rawval
;
char
*
endptr
;
rawval
=
strtol
(
arg
->
val
,
&
endptr
,
10
);
if
(
arg
->
val
[
0
]
!=
'\0'
&&
endptr
[
0
]
==
'\0'
)
{
if
(
rawval
>=
0
&&
rawval
<=
UINT_MAX
)
return
rawval
;
if
(
rawval
>=
0
&&
rawval
<=
UINT_MAX
)
return
rawval
;
die
(
"Option %s: Value %ld out of range for unsigned int
\n
"
,
arg
->
name
,
rawval
);
die
(
"Option %s: Value %ld out of range for unsigned int
\n
"
,
arg
->
name
,
rawval
);
}
die
(
"Option %s: Invalid character '%c'
\n
"
,
arg
->
name
,
*
endptr
);
return
0
;
}
int
arg_parse_int
(
const
struct
arg
*
arg
)
{
long
int
rawval
;
char
*
endptr
;
long
int
rawval
;
char
*
endptr
;
rawval
=
strtol
(
arg
->
val
,
&
endptr
,
10
);
if
(
arg
->
val
[
0
]
!=
'\0'
&&
endptr
[
0
]
==
'\0'
)
{
if
(
rawval
>=
INT_MIN
&&
rawval
<=
INT_MAX
)
return
rawval
;
if
(
rawval
>=
INT_MIN
&&
rawval
<=
INT_MAX
)
return
rawval
;
die
(
"Option %s: Value %ld out of range for signed int
\n
"
,
arg
->
name
,
rawval
);
die
(
"Option %s: Value %ld out of range for signed int
\n
"
,
arg
->
name
,
rawval
);
}
die
(
"Option %s: Invalid character '%c'
\n
"
,
arg
->
name
,
*
endptr
);
return
0
;
}
struct
vpx_rational
{
int
num
;
/**< fraction numerator */
int
den
;
/**< fraction denominator */
};
struct
vpx_rational
arg_parse_rational
(
const
struct
arg
*
arg
)
{
long
int
rawval
;
char
*
endptr
;
struct
vpx_rational
rat
;
long
int
rawval
;
char
*
endptr
;
struct
vpx_rational
rat
;
/* parse numerator */
rawval
=
strtol
(
arg
->
val
,
&
endptr
,
10
);
...
...
@@ -187,9 +166,11 @@ struct vpx_rational arg_parse_rational(const struct arg *arg) {
if
(
arg
->
val
[
0
]
!=
'\0'
&&
endptr
[
0
]
==
'/'
)
{
if
(
rawval
>=
INT_MIN
&&
rawval
<=
INT_MAX
)
rat
.
num
=
rawval
;
else
die
(
"Option %s: Value %ld out of range for signed int
\n
"
,
arg
->
name
,
rawval
);
}
else
die
(
"Option %s: Expected / at '%c'
\n
"
,
arg
->
name
,
*
endptr
);
else
die
(
"Option %s: Value %ld out of range for signed int
\n
"
,
arg
->
name
,
rawval
);
}
else
die
(
"Option %s: Expected / at '%c'
\n
"
,
arg
->
name
,
*
endptr
);
/* parse denominator */
rawval
=
strtol
(
endptr
+
1
,
&
endptr
,
10
);
...
...
@@ -197,40 +178,37 @@ struct vpx_rational arg_parse_rational(const struct arg *arg) {
if
(
arg
->
val
[
0
]
!=
'\0'
&&
endptr
[
0
]
==
'\0'
)
{
if
(
rawval
>=
INT_MIN
&&
rawval
<=
INT_MAX
)
rat
.
den
=
rawval
;
else
die
(
"Option %s: Value %ld out of range for signed int
\n
"
,
arg
->
name
,
rawval
);
}
else
die
(
"Option %s: Invalid character '%c'
\n
"
,
arg
->
name
,
*
endptr
);
else
die
(
"Option %s: Value %ld out of range for signed int
\n
"
,
arg
->
name
,
rawval
);
}
else
die
(
"Option %s: Invalid character '%c'
\n
"
,
arg
->
name
,
*
endptr
);
return
rat
;
}
int
arg_parse_enum
(
const
struct
arg
*
arg
)
{
const
struct
arg_enum_list
*
listptr
;
long
int
rawval
;
char
*
endptr
;
long
int
rawval
;
char
*
endptr
;
/* First see if the value can be parsed as a raw value */
rawval
=
strtol
(
arg
->
val
,
&
endptr
,
10
);
if
(
arg
->
val
[
0
]
!=
'\0'
&&
endptr
[
0
]
==
'\0'
)
{
/* Got a raw value, make sure it's valid */
for
(
listptr
=
arg
->
def
->
enums
;
listptr
->
name
;
listptr
++
)
if
(
listptr
->
val
==
rawval
)
return
rawval
;
if
(
listptr
->
val
==
rawval
)
return
rawval
;
}
/* Next see if it can be parsed as a string */
for
(
listptr
=
arg
->
def
->
enums
;
listptr
->
name
;
listptr
++
)
if
(
!
strcmp
(
arg
->
val
,
listptr
->
name
))
return
listptr
->
val
;
if
(
!
strcmp
(
arg
->
val
,
listptr
->
name
))
return
listptr
->
val
;
die
(
"Option %s: Invalid value '%s'
\n
"
,
arg
->
name
,
arg
->
val
);
return
0
;
}
int
arg_parse_enum_or_int
(
const
struct
arg
*
arg
)
{
if
(
arg
->
def
->
enums
)
return
arg_parse_enum
(
arg
);
if
(
arg
->
def
->
enums
)
return
arg_parse_enum
(
arg
);
return
arg_parse_int
(
arg
);
}
args.h
View file @
99e28b8b
...
...
@@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef ARGS_H_
#define ARGS_H_
#include
<stdio.h>
...
...
@@ -18,29 +17,33 @@ extern "C" {
#endif
struct
arg
{
char
**
argv
;
const
char
*
name
;
const
char
*
val
;
unsigned
int
argv_step
;
const
struct
arg_def
*
def
;
char
**
argv
;
const
char
*
name
;
const
char
*
val
;
unsigned
int
argv_step
;
const
struct
arg_def
*
def
;
};
struct
arg_enum_list
{
const
char
*
name
;
int
val
;
int
val
;
};
#define ARG_ENUM_LIST_END {0}
#define ARG_ENUM_LIST_END \
{ 0 }
typedef
struct
arg_def
{
const
char
*
short_name
;
const
char
*
long_name
;
int
has_val
;
int
has_val
;
const
char
*
desc
;
const
struct
arg_enum_list
*
enums
;
}
arg_def_t
;
#define ARG_DEF(s,l,v,d) {s,l,v,d, NULL}
#define ARG_DEF_ENUM(s,l,v,d,e) {s,l,v,d,e}
#define ARG_DEF_LIST_END {0}
#define ARG_DEF(s, l, v, d) \
{ s, l, v, d, NULL }
#define ARG_DEF_ENUM(s, l, v, d, e) \
{ s, l, v, d, e }
#define ARG_DEF_LIST_END \
{ 0 }
struct
arg
arg_init
(
char
**
argv
);
int
arg_match
(
struct
arg
*
arg_
,
const
struct
arg_def
*
def
,
char
**
argv
);
...
...
ivfdec.c
View file @
99e28b8b
...
...
@@ -46,7 +46,8 @@ int file_is_ivf(struct VpxInputContext *input_ctx) {
is_ivf
=
1
;
if
(
mem_get_le16
(
raw_hdr
+
4
)
!=
0
)
{
fprintf
(
stderr
,
"Error: Unrecognized IVF version! This file may not"
fprintf
(
stderr
,
"Error: Unrecognized IVF version! This file may not"
" decode properly."
);
}
...
...
@@ -69,14 +70,13 @@ int file_is_ivf(struct VpxInputContext *input_ctx) {
return
is_ivf
;
}
int
ivf_read_frame
(
FILE
*
infile
,
uint8_t
**
buffer
,
size_t
*
bytes_read
,
size_t
*
buffer_size
)
{
char
raw_header
[
IVF_FRAME_HDR_SZ
]
=
{
0
};
int
ivf_read_frame
(
FILE
*
infile
,
uint8_t
**
buffer
,
size_t
*
bytes_read
,
size_t
*
buffer_size
)
{
char
raw_header
[
IVF_FRAME_HDR_SZ
]
=
{
0
};
size_t
frame_size
=
0
;
if
(
fread
(
raw_header
,
IVF_FRAME_HDR_SZ
,
1
,
infile
)
!=
1
)
{
if
(
!
feof
(
infile
))
warn
(
"Failed to read frame size
\n
"
);
if
(
!
feof
(
infile
))
warn
(
"Failed to read frame size
\n
"
);
}
else
{
frame_size
=
mem_get_le32
(
raw_header
);
...
...
ivfdec.h
View file @
99e28b8b
...
...
@@ -18,11 +18,11 @@ extern "C" {
int
file_is_ivf
(
struct
VpxInputContext
*
input
);
int
ivf_read_frame
(
FILE
*
infile
,
uint8_t
**
buffer
,
size_t
*
bytes_read
,
size_t
*
buffer_size
);
int
ivf_read_frame
(
FILE
*
infile
,
uint8_t
**
buffer
,
size_t
*
bytes_read
,
size_t
*
buffer_size
);
#ifdef __cplusplus
}
/* extern "C" */
}
/* extern "C" */
#endif
#endif // IVFDEC_H_
ivfenc.c
View file @
99e28b8b
...
...
@@ -13,10 +13,8 @@
#include
"vpx/vpx_encoder.h"
#include
"vpx_ports/mem_ops.h"
void
ivf_write_file_header
(
FILE
*
outfile
,
const
struct
vpx_codec_enc_cfg
*
cfg
,
unsigned
int
fourcc
,
int
frame_cnt
)
{
void
ivf_write_file_header
(
FILE
*
outfile
,
const
struct
vpx_codec_enc_cfg
*
cfg
,
unsigned
int
fourcc
,
int
frame_cnt
)
{
char
header
[
32
];
header
[
0
]
=
'D'
;
...
...
ivfenc.h
View file @
99e28b8b
...
...
@@ -19,17 +19,15 @@ struct vpx_codec_cx_pkt;
extern
"C"
{
#endif
void
ivf_write_file_header
(
FILE
*
outfile
,
const
struct
vpx_codec_enc_cfg
*
cfg
,
uint32_t
fourcc
,
int
frame_cnt
);
void
ivf_write_file_header
(
FILE
*
outfile
,
const
struct
vpx_codec_enc_cfg
*
cfg
,
uint32_t
fourcc
,
int
frame_cnt
);
void
ivf_write_frame_header
(
FILE
*
outfile
,
int64_t
pts
,
size_t
frame_size
);
void
ivf_write_frame_size
(
FILE
*
outfile
,
size_t
frame_size
);
#ifdef __cplusplus
}
/* extern "C" */
}
/* extern "C" */
#endif
#endif // IVFENC_H_
md5_utils.c
View file @
99e28b8b
...
...
@@ -20,19 +20,17 @@
* Still in the public domain.
*/
#include
<string.h>
/* for memcpy() */
#include
<string.h>
/* for memcpy() */
#include
"md5_utils.h"
static
void
byteSwap
(
UWORD32
*
buf
,
unsigned
words
)
{
static
void
byteSwap
(
UWORD32
*
buf
,
unsigned
words
)
{
md5byte
*
p
;
/* Only swap bytes for big endian machines */
int
i
=
1
;
if
(
*
(
char
*
)
&
i
==
1
)
return
;
if
(
*
(
char
*
)
&
i
==
1
)
return
;
p
=
(
md5byte
*
)
buf
;
...
...
@@ -47,8 +45,7 @@ byteSwap(UWORD32 *buf, unsigned words) {
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
void
MD5Init
(
struct
MD5Context
*
ctx
)
{
void
MD5Init
(
struct
MD5Context
*
ctx
)
{
ctx
->
buf
[
0
]
=
0x67452301
;
ctx
->
buf
[
1
]
=
0xefcdab89
;
ctx
->
buf
[
2
]
=
0x98badcfe
;
...
...
@@ -62,8 +59,7 @@ MD5Init(struct MD5Context *ctx) {
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
MD5Update
(
struct
MD5Context
*
ctx
,
md5byte
const
*
buf
,
unsigned
len
)
{
void
MD5Update
(
struct
MD5Context
*
ctx
,
md5byte
const
*
buf
,
unsigned
len
)
{
UWORD32
t
;
/* Update byte count */
...
...
@@ -71,9 +67,9 @@ MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) {
t
=
ctx
->
bytes
[
0
];
if
((
ctx
->
bytes
[
0
]
=
t
+
len
)
<
t
)
ctx
->
bytes
[
1
]
++
;
/* Carry from low to high */
ctx
->
bytes
[
1
]
++
;
/* Carry from low to high */
t
=
64
-
(
t
&
0x3f
);
/* Space available in ctx->in (at least 1) */
t
=
64
-
(
t
&
0x3f
);
/* Space available in ctx->in (at least 1) */
if
(
t
>
len
)
{
memcpy
((
md5byte
*
)
ctx
->
in
+
64
-
t
,
buf
,
len
);
...
...
@@ -104,8 +100,7 @@ MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) {
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void
MD5Final
(
md5byte
digest
[
16
],
struct
MD5Context
*
ctx
)
{
void
MD5Final
(
md5byte
digest
[
16
],
struct
MD5Context
*
ctx
)
{
int
count
=
ctx
->
bytes
[
0
]
&
0x3f
;
/* Number of bytes in ctx->in */
md5byte
*
p
=
(
md5byte
*
)
ctx
->
in
+
count
;
...
...
@@ -115,7 +110,7 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx) {
/* Bytes of padding needed to make 56 bytes (-8..55) */
count
=
56
-
1
-
count
;
if
(
count
<
0
)
{
/* Padding forces an extra block */
if
(
count
<
0
)
{
/* Padding forces an extra block */
memset
(
p
,
0
,
count
+
8
);
byteSwap
(
ctx
->
in
,
16
);
MD5Transform
(
ctx
->
buf
,
ctx
->
in
);
...
...
@@ -147,16 +142,15 @@ MD5Final(md5byte digest[16], struct MD5Context *ctx) {
#define F4(x, y, z) (y ^ (x | ~z))
/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f,w,x,y,z,in,s) \
(w += f(x,y,z) + in, w = (w<<s | w>>(32
-
s)) + x)
#define MD5STEP(f,
w,
x,
y,
z,
in,
s) \
(w += f(x,
y,
z) + in, w = (w
<<
s | w
>>
(32
-
s)) + x)
/*
* The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
void
MD5Transform
(
UWORD32
buf
[
4
],
UWORD32
const
in
[
16
])
{
void
MD5Transform
(
UWORD32
buf
[
4
],
UWORD32
const
in
[
16
])
{
register
UWORD32
a
,
b
,
c
,
d
;
a
=
buf
[
0
];
...
...
rate_hist.c
View file @
99e28b8b
...
...
@@ -45,8 +45,7 @@ struct rate_hist *init_rate_histogram(const vpx_codec_enc_cfg_t *cfg,
hist
->
samples
=
cfg
->
rc_buf_sz
*
5
/
4
*
fps
->
num
/
fps
->
den
/
1000
;
// prevent division by zero
if
(
hist
->
samples
==
0
)
hist
->
samples
=
1
;
if
(
hist
->
samples
==
0
)
hist
->
samples
=
1
;
hist
->
frames
=
0
;
hist
->
total
=
0
;
...
...
@@ -78,18 +77,16 @@ void update_rate_histogram(struct rate_hist *hist,
int64_t
avg_bitrate
=
0
;
int64_t
sum_sz
=
0
;
const
int64_t
now
=
pkt
->
data
.
frame
.
pts
*
1000
*
(
uint64_t
)
cfg
->
g_timebase
.
num
/
(
uint64_t
)
cfg
->
g_timebase
.
den
;
(
uint64_t
)
cfg
->
g_timebase
.
num
/
(
uint64_t
)
cfg
->
g_timebase
.
den
;
int
idx
=
hist
->
frames
++
%
hist
->
samples
;
hist
->
pts
[
idx
]
=
now
;
hist
->
sz
[
idx
]
=
(
int
)
pkt
->
data
.
frame
.
sz
;
if
(
now
<
cfg
->
rc_buf_initial_sz
)
return
;
if
(
now
<
cfg
->
rc_buf_initial_sz
)
return
;
if
(
!
cfg
->
rc_target_bitrate
)
return
;
if
(
!
cfg
->
rc_target_bitrate
)
return
;
then
=
now
;
...
...
@@ -98,20 +95,16 @@ void update_rate_histogram(struct rate_hist *hist,
const
int
i_idx
=
(
i
-
1
)
%
hist
->
samples
;
then
=
hist
->
pts
[
i_idx
];
if
(
now
-
then
>
cfg
->
rc_buf_sz
)
break
;
if
(
now
-
then
>
cfg
->
rc_buf_sz
)
break
;
sum_sz
+=
hist
->
sz
[
i_idx
];
}
if
(
now
==
then
)
return
;
if
(
now
==
then
)
return
;
avg_bitrate
=
sum_sz
*
8
*
1000
/
(
now
-
then
);
idx
=
(
int
)(
avg_bitrate
*
(
RATE_BINS
/
2
)
/
(
cfg
->
rc_target_bitrate
*
1000
));
if
(
idx
<
0
)
idx
=
0
;
if
(
idx
>
RATE_BINS
-
1
)
idx
=
RATE_BINS
-
1
;
if
(
idx
<
0
)
idx
=
0
;
if
(
idx
>
RATE_BINS
-
1
)
idx
=
RATE_BINS
-
1
;
if
(
hist
->
bucket
[
idx
].
low
>
avg_bitrate
)
hist
->
bucket
[
idx
].
low
=
(
int
)
avg_bitrate
;
if
(
hist
->
bucket
[
idx
].
high
<
avg_bitrate
)
...
...
@@ -120,8 +113,8 @@ void update_rate_histogram(struct rate_hist *hist,
hist
->
total
++
;
}
static
int
merge_hist_buckets
(
struct
hist_bucket
*
bucket
,
int
max_buckets
,
int
*
num_buckets
)
{
static
int
merge_hist_buckets
(
struct
hist_bucket
*
bucket
,
int
max_buckets
,
int
*
num_buckets
)
{
int
small_bucket
=
0
,
merge_bucket
=
INT_MAX
,
big_bucket
=
0
;
int
buckets
=
*
num_buckets
;
int
i
;
...
...
@@ -129,10 +122,8 @@ static int merge_hist_buckets(struct hist_bucket *bucket,
/* Find the extrema for this list of buckets */
big_bucket
=
small_bucket
=
0
;
for
(
i
=
0
;
i
<
buckets
;
i
++
)
{
if
(
bucket
[
i
].
count
<
bucket
[
small_bucket
].
count
)
small_bucket
=
i
;
if
(
bucket
[
i
].
count
>
bucket
[
big_bucket
].
count
)
big_bucket
=
i
;
if
(
bucket
[
i
].
count
<
bucket
[
small_bucket
].
count
)
small_bucket
=
i
;
if
(
bucket
[
i
].
count
>
bucket
[
big_bucket
].
count
)
big_bucket
=
i
;
}
/* If we have too many buckets, merge the smallest with an adjacent
...
...
@@ -174,13 +165,10 @@ static int merge_hist_buckets(struct hist_bucket *bucket,
*/
big_bucket
=
small_bucket
=
0
;
for
(
i
=
0
;
i
<
buckets
;
i
++
)
{
if
(
i
>
merge_bucket
)
bucket
[
i
]
=
bucket
[
i
+
1
];
if
(
i
>
merge_bucket
)
bucket
[
i
]
=
bucket
[
i
+
1
];
if
(
bucket
[
i
].
count
<
bucket
[
small_bucket
].
count
)
small_bucket
=
i
;
if
(
bucket
[
i
].
count
>
bucket
[
big_bucket
].
count
)
big_bucket
=
i
;
if
(
bucket
[
i
].
count
<
bucket
[
small_bucket
].
count
)
small_bucket
=
i
;
if
(
bucket
[
i
].
count
>
bucket
[
big_bucket
].
count
)
big_bucket
=
i
;
}
}
...
...
@@ -188,8 +176,8 @@ static int merge_hist_buckets(struct hist_bucket *bucket,
return
bucket
[
big_bucket
].
count
;
}
static
void
show_histogram
(
const
struct
hist_bucket
*
bucket
,
int
buckets
,
int
total
,
int
scale
)
{
static
void
show_histogram
(
const
struct
hist_bucket
*
bucket
,
int
buckets
,
int
total
,
int
scale
)
{
const
char
*
pat1
,
*
pat2
;
int
i
;
...
...
@@ -232,8 +220,7 @@ static void show_histogram(const struct hist_bucket *bucket,
pct
=
(
float
)(
100
.
0
*
bucket
[
i
].
count
/
total
);
len
=
HIST_BAR_MAX
*
bucket
[
i
].
count
/
scale
;
if
(
len
<
1
)
len
=
1
;
if
(
len
<
1
)
len
=
1
;
assert
(
len
<=
HIST_BAR_MAX
);
if
(
bucket
[
i
].
low
==
bucket
[
i
].
high
)
...
...
@@ -241,8 +228,7 @@ static void show_histogram(const struct hist_bucket *bucket,
else
fprintf
(
stderr
,
pat2
,
bucket
[
i
].
low
,
bucket
[
i
].
high
);
for
(
j
=
0
;
j
<
HIST_BAR_MAX
;
j
++
)
fprintf
(
stderr
,
j
<
len
?
"="
:
" "
);
for
(
j
=
0
;
j
<
HIST_BAR_MAX
;
j
++
)
fprintf
(
stderr
,
j
<
len
?
"="
:
" "
);
fprintf
(
stderr
,
"
\t
%5d (%6.2f%%)
\n
"
,
bucket
[
i
].
count
,
pct
);
}
}
...
...
@@ -268,14 +254,13 @@ void show_q_histogram(const int counts[64], int max_buckets) {
show_histogram
(
bucket
,
buckets
,
total
,
scale
);
}
void
show_rate_histogram
(
struct
rate_hist
*
hist
,
const
vpx_codec_enc_cfg_t
*
cfg
,
int
max_buckets
)
{
void
show_rate_histogram
(
struct
rate_hist
*
hist
,
const
vpx_codec_enc_cfg_t
*
cfg
,
int
max_buckets
)
{
int
i
,
scale
;
int
buckets
=
0
;
for
(
i
=
0
;
i
<
RATE_BINS
;
i
++
)
{
if
(
hist
->
bucket
[
i
].
low
==
INT_MAX
)