Commit 2ef15b46 authored by Diego Biurrun's avatar Diego Biurrun

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

parent 992f71e9
......@@ -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);
......@@ -45,40 +46,41 @@ void av_destruct_packet(AVPacket *pkt)
void av_init_packet(AVPacket *pkt)
{
pkt->pts = AV_NOPTS_VALUE;
pkt->dts = AV_NOPTS_VALUE;
pkt->pos = -1;
pkt->duration = 0;
pkt->pts = AV_NOPTS_VALUE;
pkt->dts = AV_NOPTS_VALUE;
pkt->pos = -1;
pkt->duration = 0;
pkt->convergence_duration = 0;
pkt->flags = 0;
pkt->stream_index = 0;
pkt->destruct= NULL;
pkt->side_data = NULL;
pkt->side_data_elems = 0;
pkt->flags = 0;
pkt->stream_index = 0;
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->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,40 +91,45 @@ 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;
pkt->data = new_ptr;
pkt->size += grow_by;
memset(pkt->data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
return 0;
}
#define DUP_DATA(dst, src, size, padding) \
do { \
void *data; \
if (padding) { \
if ((unsigned)(size) > (unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \
goto failed_alloc; \
data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); \
} else { \
data = av_malloc(size); \
} \
if (!data) \
goto failed_alloc; \
memcpy(data, src, size); \
if (padding) \
memset((uint8_t*)data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); \
dst = data; \
} while(0)
#define DUP_DATA(dst, src, size, padding) \
do { \
void *data; \
if (padding) { \
if ((unsigned)(size) > \
(unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \
goto failed_alloc; \
data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); \
} else { \
data = av_malloc(size); \
} \
if (!data) \
goto failed_alloc; \
memcpy(data, src, size); \
if (padding) \
memset((uint8_t *)data + size, 0, \
FF_INPUT_BUFFER_PADDING_SIZE); \
dst = data; \
} 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;
......
......@@ -39,8 +39,8 @@ typedef struct BFIContext {
static av_cold int bfi_decode_init(AVCodecContext *avctx)
{
BFIContext *bfi = avctx->priv_data;
avctx->pix_fmt = PIX_FMT_PAL8;
bfi->dst = av_mallocz(avctx->width * avctx->height);
avctx->pix_fmt = PIX_FMT_PAL8;
bfi->dst = av_mallocz(avctx->width * avctx->height);
return 0;
}
......@@ -48,9 +48,9 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
int *data_size, AVPacket *avpkt)
{
GetByteContext g;
int buf_size = avpkt->size;
int buf_size = avpkt->size;
BFIContext *bfi = avctx->priv_data;
uint8_t *dst = bfi->dst;
uint8_t *dst = bfi->dst;
uint8_t *src, *dst_offset, colour1, colour2;
uint8_t *frame_end = bfi->dst + avctx->width * avctx->height;
uint32_t *pal;
......@@ -82,9 +82,8 @@ 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) |
(avctx->extradata[i * 3 + j] >> 4)) << shift;
*pal += ((avctx->extradata[i * 3 + j] << 2) |
(avctx->extradata[i * 3 + j] >> 4)) << shift;
pal++;
}
bfi->frame.palette_has_changed = 1;
......@@ -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;
}
}
......@@ -169,12 +163,12 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
src += avctx->width;
dst += bfi->frame.linesize[0];
}
*data_size = sizeof(AVFrame);
*data_size = sizeof(AVFrame);
*(AVFrame *)data = bfi->frame;
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])
......
This diff is collapsed.
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment