Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
2ef15b46
Commit
2ef15b46
authored
Apr 01, 2012
by
Diego Biurrun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avpacket, bfi, bgmc, rawenc: K&R prettyprinting cosmetics
parent
992f71e9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
472 additions
and
479 deletions
+472
-479
avpacket.c
libavcodec/avpacket.c
+62
-51
bfi.c
libavcodec/bfi.c
+14
-20
bgmc.c
libavcodec/bgmc.c
+360
-372
rawenc.c
libavformat/rawenc.c
+36
-36
No files found.
libavcodec/avpacket.c
View file @
2ef15b46
...
...
@@ -19,13 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "libavutil/avassert.h"
#include "avcodec.h"
void
av_destruct_packet_nofree
(
AVPacket
*
pkt
)
{
pkt
->
data
=
NULL
;
pkt
->
size
=
0
;
pkt
->
data
=
NULL
;
pkt
->
size
=
0
;
pkt
->
side_data
=
NULL
;
pkt
->
side_data_elems
=
0
;
}
...
...
@@ -35,7 +35,8 @@ void av_destruct_packet(AVPacket *pkt)
int
i
;
av_free
(
pkt
->
data
);
pkt
->
data
=
NULL
;
pkt
->
size
=
0
;
pkt
->
data
=
NULL
;
pkt
->
size
=
0
;
for
(
i
=
0
;
i
<
pkt
->
side_data_elems
;
i
++
)
av_free
(
pkt
->
side_data
[
i
].
data
);
...
...
@@ -52,33 +53,34 @@ void av_init_packet(AVPacket *pkt)
pkt
->
convergence_duration
=
0
;
pkt
->
flags
=
0
;
pkt
->
stream_index
=
0
;
pkt
->
destruct
=
NULL
;
pkt
->
destruct
=
NULL
;
pkt
->
side_data
=
NULL
;
pkt
->
side_data_elems
=
0
;
}
int
av_new_packet
(
AVPacket
*
pkt
,
int
size
)
{
uint8_t
*
data
=
NULL
;
if
((
unsigned
)
size
<
(
unsigned
)
size
+
FF_INPUT_BUFFER_PADDING_SIZE
)
uint8_t
*
data
=
NULL
;
if
((
unsigned
)
size
<
(
unsigned
)
size
+
FF_INPUT_BUFFER_PADDING_SIZE
)
data
=
av_malloc
(
size
+
FF_INPUT_BUFFER_PADDING_SIZE
);
if
(
data
){
if
(
data
)
{
memset
(
data
+
size
,
0
,
FF_INPUT_BUFFER_PADDING_SIZE
);
}
else
size
=
0
;
}
else
size
=
0
;
av_init_packet
(
pkt
);
pkt
->
data
=
data
;
pkt
->
size
=
size
;
pkt
->
destruct
=
av_destruct_packet
;
if
(
!
data
)
if
(
!
data
)
return
AVERROR
(
ENOMEM
);
return
0
;
}
void
av_shrink_packet
(
AVPacket
*
pkt
,
int
size
)
{
if
(
pkt
->
size
<=
size
)
return
;
if
(
pkt
->
size
<=
size
)
return
;
pkt
->
size
=
size
;
memset
(
pkt
->
data
+
size
,
0
,
FF_INPUT_BUFFER_PADDING_SIZE
);
}
...
...
@@ -89,9 +91,11 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
av_assert0
((
unsigned
)
pkt
->
size
<=
INT_MAX
-
FF_INPUT_BUFFER_PADDING_SIZE
);
if
(
!
pkt
->
size
)
return
av_new_packet
(
pkt
,
grow_by
);
if
((
unsigned
)
grow_by
>
INT_MAX
-
(
pkt
->
size
+
FF_INPUT_BUFFER_PADDING_SIZE
))
if
((
unsigned
)
grow_by
>
INT_MAX
-
(
pkt
->
size
+
FF_INPUT_BUFFER_PADDING_SIZE
))
return
-
1
;
new_ptr
=
av_realloc
(
pkt
->
data
,
pkt
->
size
+
grow_by
+
FF_INPUT_BUFFER_PADDING_SIZE
);
new_ptr
=
av_realloc
(
pkt
->
data
,
pkt
->
size
+
grow_by
+
FF_INPUT_BUFFER_PADDING_SIZE
);
if
(
!
new_ptr
)
return
AVERROR
(
ENOMEM
);
pkt
->
data
=
new_ptr
;
...
...
@@ -104,7 +108,8 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
do { \
void *data; \
if (padding) { \
if ((unsigned)(size) > (unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \
if ((unsigned)(size) > \
(unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \
goto failed_alloc; \
data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); \
} else { \
...
...
@@ -114,15 +119,17 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
goto failed_alloc; \
memcpy(data, src, size); \
if (padding) \
memset((uint8_t*)data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); \
memset((uint8_t *)data + size, 0, \
FF_INPUT_BUFFER_PADDING_SIZE); \
dst = data; \
} while(0)
} while
(0)
int
av_dup_packet
(
AVPacket
*
pkt
)
{
AVPacket
tmp_pkt
;
if
(((
pkt
->
destruct
==
av_destruct_packet_nofree
)
||
(
pkt
->
destruct
==
NULL
))
&&
pkt
->
data
)
{
if
(((
pkt
->
destruct
==
av_destruct_packet_nofree
)
||
(
pkt
->
destruct
==
NULL
))
&&
pkt
->
data
)
{
tmp_pkt
=
*
pkt
;
pkt
->
data
=
NULL
;
...
...
@@ -135,14 +142,15 @@ int av_dup_packet(AVPacket *pkt)
DUP_DATA
(
pkt
->
side_data
,
tmp_pkt
.
side_data
,
pkt
->
side_data_elems
*
sizeof
(
*
pkt
->
side_data
),
0
);
memset
(
pkt
->
side_data
,
0
,
pkt
->
side_data_elems
*
sizeof
(
*
pkt
->
side_data
));
for
(
i
=
0
;
i
<
pkt
->
side_data_elems
;
i
++
)
{
memset
(
pkt
->
side_data
,
0
,
pkt
->
side_data_elems
*
sizeof
(
*
pkt
->
side_data
));
for
(
i
=
0
;
i
<
pkt
->
side_data_elems
;
i
++
)
DUP_DATA
(
pkt
->
side_data
[
i
].
data
,
tmp_pkt
.
side_data
[
i
].
data
,
pkt
->
side_data
[
i
].
size
,
1
);
}
}
}
return
0
;
failed_alloc:
av_destruct_packet
(
pkt
);
return
AVERROR
(
ENOMEM
);
...
...
@@ -151,14 +159,16 @@ failed_alloc:
void
av_free_packet
(
AVPacket
*
pkt
)
{
if
(
pkt
)
{
if
(
pkt
->
destruct
)
pkt
->
destruct
(
pkt
);
pkt
->
data
=
NULL
;
pkt
->
size
=
0
;
if
(
pkt
->
destruct
)
pkt
->
destruct
(
pkt
);
pkt
->
data
=
NULL
;
pkt
->
size
=
0
;
pkt
->
side_data
=
NULL
;
pkt
->
side_data_elems
=
0
;
}
}
uint8_t
*
av_packet_new_side_data
(
AVPacket
*
pkt
,
enum
AVPacketSideDataType
type
,
uint8_t
*
av_packet_new_side_data
(
AVPacket
*
pkt
,
enum
AVPacketSideDataType
type
,
int
size
)
{
int
elems
=
pkt
->
side_data_elems
;
...
...
@@ -168,7 +178,8 @@ uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
if
((
unsigned
)
size
>
INT_MAX
-
FF_INPUT_BUFFER_PADDING_SIZE
)
return
NULL
;
pkt
->
side_data
=
av_realloc
(
pkt
->
side_data
,
(
elems
+
1
)
*
sizeof
(
*
pkt
->
side_data
));
pkt
->
side_data
=
av_realloc
(
pkt
->
side_data
,
(
elems
+
1
)
*
sizeof
(
*
pkt
->
side_data
));
if
(
!
pkt
->
side_data
)
return
NULL
;
...
...
@@ -182,7 +193,7 @@ uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
return
pkt
->
side_data
[
elems
].
data
;
}
uint8_t
*
av_packet_get_side_data
(
AVPacket
*
pkt
,
enum
AVPacketSideDataType
type
,
uint8_t
*
av_packet_get_side_data
(
AVPacket
*
pkt
,
enum
AVPacketSideDataType
type
,
int
*
size
)
{
int
i
;
...
...
libavcodec/bfi.c
View file @
2ef15b46
...
...
@@ -82,8 +82,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
int
shift
=
16
;
*
pal
=
0
;
for
(
j
=
0
;
j
<
3
;
j
++
,
shift
-=
8
)
*
pal
+=
((
avctx
->
extradata
[
i
*
3
+
j
]
<<
2
)
|
*
pal
+=
((
avctx
->
extradata
[
i
*
3
+
j
]
<<
2
)
|
(
avctx
->
extradata
[
i
*
3
+
j
]
>>
4
))
<<
shift
;
pal
++
;
}
...
...
@@ -107,7 +106,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
return
-
1
;
}
/* Get length and offset(if required) */
/* Get length and offset
(if required) */
if
(
length
==
0
)
{
if
(
code
==
1
)
{
length
=
bytestream2_get_byte
(
&
g
);
...
...
@@ -127,8 +126,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
break
;
switch
(
code
)
{
case
0
:
//Normal Chain
case
0
:
// normal chain
if
(
length
>=
bytestream2_get_bytes_left
(
&
g
))
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Frame larger than buffer.
\n
"
);
return
-
1
;
...
...
@@ -136,21 +134,18 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
bytestream2_get_buffer
(
&
g
,
dst
,
length
);
dst
+=
length
;
break
;
case
1
:
//Back Chain
case
1
:
// back chain
dst_offset
=
dst
-
offset
;
length
*=
4
;
//
Convert dwords to bytes.
length
*=
4
;
//
Convert dwords to bytes.
if
(
dst_offset
<
bfi
->
dst
)
break
;
while
(
length
--
)
*
dst
++
=
*
dst_offset
++
;
break
;
case
2
:
//Skip Chain
case
2
:
// skip chain
dst
+=
length
;
break
;
case
3
:
//Fill Chain
case
3
:
// fill chain
colour1
=
bytestream2_get_byte
(
&
g
);
colour2
=
bytestream2_get_byte
(
&
g
);
while
(
length
--
)
{
...
...
@@ -158,7 +153,6 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
*
dst
++
=
colour2
;
}
break
;
}
}
...
...
@@ -174,7 +168,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
return
buf_size
;
}
static
av_cold
int
bfi_decode_close
(
AVCodecContext
*
avctx
)
static
av_cold
int
bfi_decode_close
(
AVCodecContext
*
avctx
)
{
BFIContext
*
bfi
=
avctx
->
priv_data
;
if
(
bfi
->
frame
.
data
[
0
])
...
...
libavcodec/bgmc.c
View file @
2ef15b46
...
...
@@ -25,10 +25,8 @@
* @author Thilo Borgmann <thilo.borgmann _at_ googlemail.com>
*/
#include "bgmc.h"
#define FREQ_BITS 14 // bits used by frequency counters
#define VALUE_BITS 18 // bits used to represent the values
#define TOP_VALUE ((1 << VALUE_BITS) - 1) // maximum value
...
...
@@ -41,8 +39,7 @@
#define LUT_BUFF 4 // number of buffered lookup tables
/** Cumulative frequency tables for block Gilbert-Moore coding.
*/
/** Cumulative frequency tables for block Gilbert-Moore coding. */
static
const
uint16_t
cf_tables_1
[
3
][
129
]
=
{
{
16384
,
16066
,
15748
,
15431
,
15114
,
14799
,
14485
,
14173
,
13861
,
13552
,
...
...
@@ -416,7 +413,7 @@ static const uint16_t cf_tables_3[5][257] = {
};
static
const
uint16_t
*
const
cf_table
[
16
]
=
{
static
const
uint16_t
*
const
cf_table
[
16
]
=
{
cf_tables_1
[
0
],
cf_tables_1
[
1
],
cf_tables_1
[
2
],
cf_tables_2
[
0
],
cf_tables_2
[
1
],
cf_tables_2
[
2
],
cf_tables_2
[
3
],
cf_tables_2
[
4
],
cf_tables_2
[
5
],
cf_tables_2
[
6
],
cf_tables_2
[
7
],
cf_tables_3
[
0
],
...
...
@@ -424,10 +421,8 @@ static const uint16_t * const cf_table[16] = {
};
/** Initialize a given lookup table using a given delta
*/
static
void
bgmc_lut_fillp
(
uint8_t
*
lut
,
int
*
lut_status
,
int
delta
)
/** Initialize a given lookup table using a given delta */
static
void
bgmc_lut_fillp
(
uint8_t
*
lut
,
int
*
lut_status
,
int
delta
)
{
unsigned
int
sx
,
i
;
...
...
@@ -446,10 +441,8 @@ static void bgmc_lut_fillp(uint8_t *lut, int *lut_status,
}
/** Retune the index of a suitable lookup table for a given delta
*/
static
uint8_t
*
bgmc_lut_getp
(
uint8_t
*
lut
,
int
*
lut_status
,
int
delta
)
/** Retune the index of a suitable lookup table for a given delta */
static
uint8_t
*
bgmc_lut_getp
(
uint8_t
*
lut
,
int
*
lut_status
,
int
delta
)
{
unsigned
int
i
=
av_clip
(
delta
,
0
,
LUT_BUFF
-
1
);
...
...
@@ -462,11 +455,10 @@ static uint8_t* bgmc_lut_getp(uint8_t *lut, int *lut_status,
}
/** Initialize the lookup table arrays
*/
/** Initialize the lookup table arrays */
int
ff_bgmc_init
(
AVCodecContext
*
avctx
,
uint8_t
**
cf_lut
,
int
**
cf_lut_status
)
{
*
cf_lut
=
av_malloc
(
sizeof
(
*
cf_lut
)
*
LUT_BUFF
*
16
*
LUT_SIZE
);
*
cf_lut
=
av_malloc
(
sizeof
(
*
cf_lut
)
*
LUT_BUFF
*
16
*
LUT_SIZE
);
*
cf_lut_status
=
av_malloc
(
sizeof
(
*
cf_lut_status
)
*
LUT_BUFF
);
if
(
!
cf_lut
||
!
cf_lut_status
)
{
...
...
@@ -474,8 +466,7 @@ int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status)
av_log
(
avctx
,
AV_LOG_ERROR
,
"Allocating buffer memory failed.
\n
"
);
return
AVERROR
(
ENOMEM
);
}
else
{
// initialize lut_status buffer to a value never used to compare
// against
// initialize lut_status buffer to a value never used to compare against
memset
(
*
cf_lut_status
,
-
1
,
sizeof
(
*
cf_lut_status
)
*
LUT_BUFF
);
}
...
...
@@ -483,8 +474,7 @@ int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status)
}
/** Release the lookup table arrays
*/
/** Release the lookup table arrays */
void
ff_bgmc_end
(
uint8_t
**
cf_lut
,
int
**
cf_lut_status
)
{
av_freep
(
cf_lut
);
...
...
@@ -492,10 +482,9 @@ void ff_bgmc_end(uint8_t **cf_lut, int **cf_lut_status)
}
/** Initialize decoding and reads the first value
*/
void
ff_bgmc_decode_init
(
GetBitContext
*
gb
,
unsigned
int
*
h
,
unsigned
int
*
l
,
unsigned
int
*
v
)
/** Initialize decoding and reads the first value */
void
ff_bgmc_decode_init
(
GetBitContext
*
gb
,
unsigned
int
*
h
,
unsigned
int
*
l
,
unsigned
int
*
v
)
{
*
h
=
TOP_VALUE
;
*
l
=
0
;
...
...
@@ -503,16 +492,14 @@ void ff_bgmc_decode_init(GetBitContext *gb,
}
/** Finish decoding
*/
/** Finish decoding */
void
ff_bgmc_decode_end
(
GetBitContext
*
gb
)
{
skip_bits_long
(
gb
,
-
(
VALUE_BITS
-
2
));
}
/** Read and decode a block Gilbert-Moore coded symbol
*/
/** Read and decode a block Gilbert-Moore coded symbol */
void
ff_bgmc_decode
(
GetBitContext
*
gb
,
unsigned
int
num
,
int32_t
*
dst
,
int
delta
,
unsigned
int
sx
,
unsigned
int
*
h
,
unsigned
int
*
l
,
unsigned
int
*
v
,
...
...
@@ -539,8 +526,8 @@ void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst,
symbol
=
(
symbol
>>
delta
)
-
1
;
high
=
low
+
((
range
*
cf_table
[
sx
][(
symbol
)
<<
delta
]
-
(
1
<<
FREQ_BITS
))
>>
FREQ_BITS
);
low
=
low
+
((
range
*
cf_table
[
sx
][(
symbol
+
1
)
<<
delta
]
)
>>
FREQ_BITS
);
high
=
low
+
((
range
*
cf_table
[
sx
][(
symbol
)
<<
delta
]
-
(
1
<<
FREQ_BITS
))
>>
FREQ_BITS
);
low
=
low
+
((
range
*
cf_table
[
sx
][(
symbol
+
1
)
<<
delta
]
)
>>
FREQ_BITS
);
while
(
1
)
{
if
(
high
>=
HALF
)
{
...
...
@@ -552,7 +539,8 @@ void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst,
value
-=
FIRST_QTR
;
low
-=
FIRST_QTR
;
high
-=
FIRST_QTR
;
}
else
break
;
}
else
break
;
}
low
*=
2
;
...
...
libavformat/rawenc.c
View file @
2ef15b46
...
...
@@ -57,6 +57,18 @@ AVOutputFormat ff_adx_muxer = {
};
#endif
#if CONFIG_CAVSVIDEO_MUXER
AVOutputFormat
ff_cavsvideo_muxer
=
{
.
name
=
"cavsvideo"
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"raw Chinese AVS video"
),
.
extensions
=
"cavs"
,
.
audio_codec
=
CODEC_ID_NONE
,
.
video_codec
=
CODEC_ID_CAVS
,
.
write_packet
=
ff_raw_write_packet
,
.
flags
=
AVFMT_NOTIMESTAMPS
,
};
#endif
#if CONFIG_DIRAC_MUXER
AVOutputFormat
ff_dirac_muxer
=
{
.
name
=
"dirac"
,
...
...
@@ -158,18 +170,6 @@ AVOutputFormat ff_h264_muxer = {
};
#endif
#if CONFIG_CAVSVIDEO_MUXER
AVOutputFormat
ff_cavsvideo_muxer
=
{
.
name
=
"cavsvideo"
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"raw Chinese AVS video"
),
.
extensions
=
"cavs"
,
.
audio_codec
=
CODEC_ID_NONE
,
.
video_codec
=
CODEC_ID_CAVS
,
.
write_packet
=
ff_raw_write_packet
,
.
flags
=
AVFMT_NOTIMESTAMPS
,
};
#endif
#if CONFIG_M4V_MUXER
AVOutputFormat
ff_m4v_muxer
=
{
.
name
=
"m4v"
,
...
...
@@ -207,30 +207,6 @@ AVOutputFormat ff_mlp_muxer = {
};
#endif
#if CONFIG_SRT_MUXER
AVOutputFormat
ff_srt_muxer
=
{
.
name
=
"srt"
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"SubRip subtitle format"
),
.
mime_type
=
"application/x-subrip"
,
.
extensions
=
"srt"
,
.
write_packet
=
ff_raw_write_packet
,
.
flags
=
AVFMT_NOTIMESTAMPS
,
.
subtitle_codec
=
CODEC_ID_SRT
,
};
#endif
#if CONFIG_TRUEHD_MUXER
AVOutputFormat
ff_truehd_muxer
=
{
.
name
=
"truehd"
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"raw TrueHD"
),
.
extensions
=
"thd"
,
.
audio_codec
=
CODEC_ID_TRUEHD
,
.
video_codec
=
CODEC_ID_NONE
,
.
write_packet
=
ff_raw_write_packet
,
.
flags
=
AVFMT_NOTIMESTAMPS
,
};
#endif
#if CONFIG_MPEG1VIDEO_MUXER
AVOutputFormat
ff_mpeg1video_muxer
=
{
.
name
=
"mpeg1video"
,
...
...
@@ -267,3 +243,27 @@ AVOutputFormat ff_rawvideo_muxer = {
.
flags
=
AVFMT_NOTIMESTAMPS
,
};
#endif
#if CONFIG_SRT_MUXER
AVOutputFormat
ff_srt_muxer
=
{
.
name
=
"srt"
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"SubRip subtitle format"
),
.
mime_type
=
"application/x-subrip"
,
.
extensions
=
"srt"
,
.
write_packet
=
ff_raw_write_packet
,
.
flags
=
AVFMT_NOTIMESTAMPS
,
.
subtitle_codec
=
CODEC_ID_SRT
,
};
#endif
#if CONFIG_TRUEHD_MUXER
AVOutputFormat
ff_truehd_muxer
=
{
.
name
=
"truehd"
,
.
long_name
=
NULL_IF_CONFIG_SMALL
(
"raw TrueHD"
),
.
extensions
=
"thd"
,
.
audio_codec
=
CODEC_ID_TRUEHD
,
.
video_codec
=
CODEC_ID_NONE
,
.
write_packet
=
ff_raw_write_packet
,
.
flags
=
AVFMT_NOTIMESTAMPS
,
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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