avpacket, bfi, bgmc, rawenc: K&R prettyprinting cosmetics

pull/5/head
Diego Biurrun 13 years ago
parent 992f71e95d
commit 2ef15b46e4
  1. 43
      libavcodec/avpacket.c
  2. 16
      libavcodec/bfi.c
  3. 42
      libavcodec/bgmc.c
  4. 72
      libavformat/rawenc.c

@ -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);
@ -78,7 +79,8 @@ int av_new_packet(AVPacket *pkt, int size)
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,7 +119,8 @@ 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)
@ -122,7 +128,8 @@ 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,8 +159,10 @@ 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;
}
@ -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;

@ -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++;
}
@ -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,8 +134,7 @@ 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.
if (dst_offset < bfi->dst)
@ -145,12 +142,10 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
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;
}
}

@ -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,
@ -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,8 +455,7 @@ 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);
@ -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,
@ -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;

@ -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

Loading…
Cancel
Save