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

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

parent 992f71e9
...@@ -19,13 +19,13 @@ ...@@ -19,13 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "avcodec.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "avcodec.h"
void av_destruct_packet_nofree(AVPacket *pkt) 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 = NULL;
pkt->side_data_elems = 0; pkt->side_data_elems = 0;
} }
...@@ -35,7 +35,8 @@ void av_destruct_packet(AVPacket *pkt) ...@@ -35,7 +35,8 @@ void av_destruct_packet(AVPacket *pkt)
int i; int i;
av_free(pkt->data); 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++) for (i = 0; i < pkt->side_data_elems; i++)
av_free(pkt->side_data[i].data); av_free(pkt->side_data[i].data);
...@@ -45,40 +46,41 @@ void av_destruct_packet(AVPacket *pkt) ...@@ -45,40 +46,41 @@ void av_destruct_packet(AVPacket *pkt)
void av_init_packet(AVPacket *pkt) void av_init_packet(AVPacket *pkt)
{ {
pkt->pts = AV_NOPTS_VALUE; pkt->pts = AV_NOPTS_VALUE;
pkt->dts = AV_NOPTS_VALUE; pkt->dts = AV_NOPTS_VALUE;
pkt->pos = -1; pkt->pos = -1;
pkt->duration = 0; pkt->duration = 0;
pkt->convergence_duration = 0; pkt->convergence_duration = 0;
pkt->flags = 0; pkt->flags = 0;
pkt->stream_index = 0; pkt->stream_index = 0;
pkt->destruct= NULL; pkt->destruct = NULL;
pkt->side_data = NULL; pkt->side_data = NULL;
pkt->side_data_elems = 0; pkt->side_data_elems = 0;
} }
int av_new_packet(AVPacket *pkt, int size) int av_new_packet(AVPacket *pkt, int size)
{ {
uint8_t *data= NULL; uint8_t *data = NULL;
if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE) if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)
data = av_malloc(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); memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
}else } else
size=0; size = 0;
av_init_packet(pkt); av_init_packet(pkt);
pkt->data = data; pkt->data = data;
pkt->size = size; pkt->size = size;
pkt->destruct = av_destruct_packet; pkt->destruct = av_destruct_packet;
if(!data) if (!data)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
return 0; return 0;
} }
void av_shrink_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; pkt->size = size;
memset(pkt->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); memset(pkt->data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
} }
...@@ -89,40 +91,45 @@ int av_grow_packet(AVPacket *pkt, int grow_by) ...@@ -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); av_assert0((unsigned)pkt->size <= INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE);
if (!pkt->size) if (!pkt->size)
return av_new_packet(pkt, grow_by); 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; 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) if (!new_ptr)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
pkt->data = new_ptr; pkt->data = new_ptr;
pkt->size += grow_by; pkt->size += grow_by;
memset(pkt->data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); memset(pkt->data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
return 0; return 0;
} }
#define DUP_DATA(dst, src, size, padding) \ #define DUP_DATA(dst, src, size, padding) \
do { \ do { \
void *data; \ void *data; \
if (padding) { \ if (padding) { \
if ((unsigned)(size) > (unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \ if ((unsigned)(size) > \
goto failed_alloc; \ (unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \
data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); \ goto failed_alloc; \
} else { \ data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); \
data = av_malloc(size); \ } else { \
} \ data = av_malloc(size); \
if (!data) \ } \
goto failed_alloc; \ if (!data) \
memcpy(data, src, size); \ goto failed_alloc; \
if (padding) \ memcpy(data, src, size); \
memset((uint8_t*)data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); \ if (padding) \
dst = data; \ memset((uint8_t *)data + size, 0, \
} while(0) FF_INPUT_BUFFER_PADDING_SIZE); \
dst = data; \
} while (0)
int av_dup_packet(AVPacket *pkt) int av_dup_packet(AVPacket *pkt)
{ {
AVPacket tmp_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; tmp_pkt = *pkt;
pkt->data = NULL; pkt->data = NULL;
...@@ -135,14 +142,15 @@ int av_dup_packet(AVPacket *pkt) ...@@ -135,14 +142,15 @@ int av_dup_packet(AVPacket *pkt)
DUP_DATA(pkt->side_data, tmp_pkt.side_data, DUP_DATA(pkt->side_data, tmp_pkt.side_data,
pkt->side_data_elems * sizeof(*pkt->side_data), 0); pkt->side_data_elems * sizeof(*pkt->side_data), 0);
memset(pkt->side_data, 0, pkt->side_data_elems * sizeof(*pkt->side_data)); memset(pkt->side_data, 0,
for (i = 0; i < pkt->side_data_elems; i++) { 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, DUP_DATA(pkt->side_data[i].data, tmp_pkt.side_data[i].data,
pkt->side_data[i].size, 1); pkt->side_data[i].size, 1);
}
} }
} }
return 0; return 0;
failed_alloc: failed_alloc:
av_destruct_packet(pkt); av_destruct_packet(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
...@@ -151,14 +159,16 @@ failed_alloc: ...@@ -151,14 +159,16 @@ failed_alloc:
void av_free_packet(AVPacket *pkt) void av_free_packet(AVPacket *pkt)
{ {
if (pkt) { if (pkt) {
if (pkt->destruct) pkt->destruct(pkt); if (pkt->destruct)
pkt->data = NULL; pkt->size = 0; pkt->destruct(pkt);
pkt->data = NULL;
pkt->size = 0;
pkt->side_data = NULL; pkt->side_data = NULL;
pkt->side_data_elems = 0; 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 size)
{ {
int elems = pkt->side_data_elems; int elems = pkt->side_data_elems;
...@@ -168,7 +178,8 @@ uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, ...@@ -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) if ((unsigned)size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
return NULL; 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) if (!pkt->side_data)
return NULL; return NULL;
...@@ -182,7 +193,7 @@ uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, ...@@ -182,7 +193,7 @@ uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
return pkt->side_data[elems].data; 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 *size)
{ {
int i; int i;
......
...@@ -39,8 +39,8 @@ typedef struct BFIContext { ...@@ -39,8 +39,8 @@ typedef struct BFIContext {
static av_cold int bfi_decode_init(AVCodecContext *avctx) static av_cold int bfi_decode_init(AVCodecContext *avctx)
{ {
BFIContext *bfi = avctx->priv_data; BFIContext *bfi = avctx->priv_data;
avctx->pix_fmt = PIX_FMT_PAL8; avctx->pix_fmt = PIX_FMT_PAL8;
bfi->dst = av_mallocz(avctx->width * avctx->height); bfi->dst = av_mallocz(avctx->width * avctx->height);
return 0; return 0;
} }
...@@ -48,9 +48,9 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, ...@@ -48,9 +48,9 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
int *data_size, AVPacket *avpkt) int *data_size, AVPacket *avpkt)
{ {
GetByteContext g; GetByteContext g;
int buf_size = avpkt->size; int buf_size = avpkt->size;
BFIContext *bfi = avctx->priv_data; BFIContext *bfi = avctx->priv_data;
uint8_t *dst = bfi->dst; uint8_t *dst = bfi->dst;
uint8_t *src, *dst_offset, colour1, colour2; uint8_t *src, *dst_offset, colour1, colour2;
uint8_t *frame_end = bfi->dst + avctx->width * avctx->height; uint8_t *frame_end = bfi->dst + avctx->width * avctx->height;
uint32_t *pal; uint32_t *pal;
...@@ -82,9 +82,8 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, ...@@ -82,9 +82,8 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
int shift = 16; int shift = 16;
*pal = 0; *pal = 0;
for (j = 0; j < 3; j++, shift -= 8) for (j = 0; j < 3; j++, shift -= 8)
*pal += *pal += ((avctx->extradata[i * 3 + j] << 2) |
((avctx->extradata[i * 3 + j] << 2) | (avctx->extradata[i * 3 + j] >> 4)) << shift;
(avctx->extradata[i * 3 + j] >> 4)) << shift;
pal++; pal++;
} }
bfi->frame.palette_has_changed = 1; bfi->frame.palette_has_changed = 1;
...@@ -107,7 +106,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, ...@@ -107,7 +106,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
return -1; return -1;
} }
/* Get length and offset(if required) */ /* Get length and offset (if required) */
if (length == 0) { if (length == 0) {
if (code == 1) { if (code == 1) {
length = bytestream2_get_byte(&g); length = bytestream2_get_byte(&g);
...@@ -127,8 +126,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, ...@@ -127,8 +126,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
break; break;
switch (code) { switch (code) {
case 0: // normal chain
case 0: //Normal Chain
if (length >= bytestream2_get_bytes_left(&g)) { if (length >= bytestream2_get_bytes_left(&g)) {
av_log(avctx, AV_LOG_ERROR, "Frame larger than buffer.\n"); av_log(avctx, AV_LOG_ERROR, "Frame larger than buffer.\n");
return -1; return -1;
...@@ -136,21 +134,18 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, ...@@ -136,21 +134,18 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
bytestream2_get_buffer(&g, dst, length); bytestream2_get_buffer(&g, dst, length);
dst += length; dst += length;
break; break;
case 1: // back chain
case 1: //Back Chain
dst_offset = dst - offset; dst_offset = dst - offset;
length *= 4; //Convert dwords to bytes. length *= 4; // Convert dwords to bytes.
if (dst_offset < bfi->dst) if (dst_offset < bfi->dst)
break; break;
while (length--) while (length--)
*dst++ = *dst_offset++; *dst++ = *dst_offset++;
break; break;
case 2: // skip chain
case 2: //Skip Chain
dst += length; dst += length;
break; break;
case 3: // fill chain
case 3: //Fill Chain
colour1 = bytestream2_get_byte(&g); colour1 = bytestream2_get_byte(&g);
colour2 = bytestream2_get_byte(&g); colour2 = bytestream2_get_byte(&g);
while (length--) { while (length--) {
...@@ -158,7 +153,6 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, ...@@ -158,7 +153,6 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
*dst++ = colour2; *dst++ = colour2;
} }
break; break;
} }
} }
...@@ -169,12 +163,12 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data, ...@@ -169,12 +163,12 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
src += avctx->width; src += avctx->width;
dst += bfi->frame.linesize[0]; dst += bfi->frame.linesize[0];
} }
*data_size = sizeof(AVFrame); *data_size = sizeof(AVFrame);
*(AVFrame *)data = bfi->frame; *(AVFrame *)data = bfi->frame;
return buf_size; 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; BFIContext *bfi = avctx->priv_data;
if (bfi->frame.data[0]) if (bfi->frame.data[0])
......
This diff is collapsed.
...@@ -57,6 +57,18 @@ AVOutputFormat ff_adx_muxer = { ...@@ -57,6 +57,18 @@ AVOutputFormat ff_adx_muxer = {
}; };
#endif #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 #if CONFIG_DIRAC_MUXER
AVOutputFormat ff_dirac_muxer = { AVOutputFormat ff_dirac_muxer = {
.name = "dirac", .name = "dirac",
...@@ -158,18 +170,6 @@ AVOutputFormat ff_h264_muxer = { ...@@ -158,18 +170,6 @@ AVOutputFormat ff_h264_muxer = {
}; };
#endif #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 #if CONFIG_M4V_MUXER
AVOutputFormat ff_m4v_muxer = { AVOutputFormat ff_m4v_muxer = {
.name = "m4v", .name = "m4v",
...@@ -207,30 +207,6 @@ AVOutputFormat ff_mlp_muxer = { ...@@ -207,30 +207,6 @@ AVOutputFormat ff_mlp_muxer = {
}; };
#endif #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 #if CONFIG_MPEG1VIDEO_MUXER
AVOutputFormat ff_mpeg1video_muxer = { AVOutputFormat ff_mpeg1video_muxer = {
.name = "mpeg1video", .name = "mpeg1video",
...@@ -267,3 +243,27 @@ AVOutputFormat ff_rawvideo_muxer = { ...@@ -267,3 +243,27 @@ AVOutputFormat ff_rawvideo_muxer = {
.flags = AVFMT_NOTIMESTAMPS, .flags = AVFMT_NOTIMESTAMPS,
}; };
#endif #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