1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

Merge commit '0a024268261d05ccdcf7e03c85fb78d22037a464'

* commit '0a024268261d05ccdcf7e03c85fb78d22037a464':
  libxvid: K&R formatting cosmetics

Conflicts:
	libavcodec/libxvid.c
	libavcodec/libxvid_rc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2014-08-26 21:45:39 +02:00
4 changed files with 326 additions and 304 deletions

View File

@@ -26,12 +26,14 @@
*/
#include <xvid.h>
#include "avcodec.h"
#include "internal.h"
#include "libavutil/file.h"
#include "libavutil/cpu.h"
#include "libavutil/file.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "avcodec.h"
#include "internal.h"
#include "libxvid.h"
#include "mpegvideo.h"
@@ -104,8 +106,8 @@ static int xvid_encode_close(AVCodecContext *avctx);
* @param handle Private context handle
* @return Returns XVID_ERR_xxxx on failure, or 0 on success.
*/
static int xvid_ff_2pass_create(xvid_plg_create_t * param,
void ** handle) {
static int xvid_ff_2pass_create(xvid_plg_create_t *param, void **handle)
{
struct xvid_ff_pass1 *x = (struct xvid_ff_pass1 *) param->param;
char *log = x->context->twopassbuffer;
@@ -136,7 +138,8 @@ static int xvid_ff_2pass_create(xvid_plg_create_t * param,
* @return Returns 0, success guaranteed
*/
static int xvid_ff_2pass_destroy(struct xvid_context *ref,
xvid_plg_destroy_t *param) {
xvid_plg_destroy_t *param)
{
/* Currently cannot think of anything to do on destruction */
/* Still, the framework should be here for reference/use */
if (ref->twopassbuffer)
@@ -152,7 +155,8 @@ static int xvid_ff_2pass_destroy(struct xvid_context *ref,
* @return Returns 0, success guaranteed
*/
static int xvid_ff_2pass_before(struct xvid_context *ref,
xvid_plg_data_t *param) {
xvid_plg_data_t *param)
{
int motion_remove;
int motion_replacements;
int vop_remove;
@@ -195,7 +199,8 @@ static int xvid_ff_2pass_before(struct xvid_context *ref,
* @return Returns XVID_ERR_xxxx on failure, or 0 on success
*/
static int xvid_ff_2pass_after(struct xvid_context *ref,
xvid_plg_data_t *param) {
xvid_plg_data_t *param)
{
char *log = ref->twopassbuffer;
const char *frame_types = " ipbs";
char frame_type;
@@ -205,16 +210,16 @@ static int xvid_ff_2pass_after(struct xvid_context *ref,
return XVID_ERR_FAIL;
/* Convert the type given to us into a character */
if( param->type < 5 && param->type > 0 ) {
if (param->type < 5 && param->type > 0)
frame_type = frame_types[param->type];
} else {
else
return XVID_ERR_FAIL;
}
snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
"%c %d %d %d %d %d %d\n",
frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks,
param->stats.ublks, param->stats.length, param->stats.hlength);
frame_type, param->stats.quant, param->stats.kblks,
param->stats.mblks, param->stats.ublks,
param->stats.length, param->stats.hlength);
return 0;
}
@@ -236,19 +241,14 @@ static int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2)
case XVID_PLG_INFO:
case XVID_PLG_FRAME:
return 0;
case XVID_PLG_BEFORE:
return xvid_ff_2pass_before(ref, p1);
case XVID_PLG_CREATE:
return xvid_ff_2pass_create(p1, p2);
case XVID_PLG_AFTER:
return xvid_ff_2pass_after(ref, p1);
case XVID_PLG_DESTROY:
return xvid_ff_2pass_destroy(ref, p1);
default:
return XVID_ERR_FAIL;
}
@@ -267,10 +267,10 @@ static int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2)
* @param frame_len Length of encoded frame data
* @return Returns new length of frame data
*/
static int xvid_strip_vol_header(AVCodecContext *avctx,
AVPacket *pkt,
static int xvid_strip_vol_header(AVCodecContext *avctx, AVPacket *pkt,
unsigned int header_len,
unsigned int frame_len) {
unsigned int frame_len)
{
int vo_len = 0, i;
for (i = 0; i < header_len - 3; i++) {
@@ -291,7 +291,7 @@ static int xvid_strip_vol_header(AVCodecContext *avctx,
avctx->extradata_size = vo_len;
}
/* Less dangerous now, memmove properly copies the two
chunks of overlapping data */
* chunks of overlapping data */
memmove(pkt->data, &pkt->data[vo_len], frame_len - vo_len);
pkt->size = frame_len - vo_len;
}
@@ -357,7 +357,8 @@ static void xvid_correct_framerate(AVCodecContext *avctx)
}
}
static av_cold int xvid_encode_init(AVCodecContext *avctx) {
static av_cold int xvid_encode_init(AVCodecContext *avctx)
{
int xerr, i;
int xvid_flags = avctx->flags;
struct xvid_context *x = avctx->priv_data;
@@ -391,20 +392,20 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
x->me_flags = 0;
switch (avctx->me_method) {
case ME_FULL: /* Quality 6 */
x->me_flags |= XVID_ME_EXTSEARCH16
| XVID_ME_EXTSEARCH8;
x->me_flags |= XVID_ME_EXTSEARCH16 |
XVID_ME_EXTSEARCH8;
case ME_EPZS: /* Quality 4 */
x->me_flags |= XVID_ME_ADVANCEDDIAMOND8
| XVID_ME_HALFPELREFINE8
| XVID_ME_CHROMA_PVOP
| XVID_ME_CHROMA_BVOP;
x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 |
XVID_ME_HALFPELREFINE8 |
XVID_ME_CHROMA_PVOP |
XVID_ME_CHROMA_BVOP;
case ME_LOG: /* Quality 2 */
case ME_PHODS:
case ME_X1:
x->me_flags |= XVID_ME_ADVANCEDDIAMOND16
| XVID_ME_HALFPELREFINE16;
x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 |
XVID_ME_HALFPELREFINE16;
case ME_ZERO: /* Quality 0 */
default:
@@ -415,16 +416,15 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
switch (avctx->mb_decision) {
case 2:
x->vop_flags |= XVID_VOP_MODEDECISION_RD;
x->me_flags |= XVID_ME_HALFPELREFINE8_RD
| XVID_ME_QUARTERPELREFINE8_RD
| XVID_ME_EXTSEARCH_RD
| XVID_ME_CHECKPREDICTION_RD;
x->me_flags |= XVID_ME_HALFPELREFINE8_RD |
XVID_ME_QUARTERPELREFINE8_RD |
XVID_ME_EXTSEARCH_RD |
XVID_ME_CHECKPREDICTION_RD;
case 1:
if (!(x->vop_flags & XVID_VOP_MODEDECISION_RD))
x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
x->me_flags |= XVID_ME_HALFPELREFINE16_RD
| XVID_ME_QUARTERPELREFINE16_RD;
x->me_flags |= XVID_ME_HALFPELREFINE16_RD |
XVID_ME_QUARTERPELREFINE16_RD;
default:
break;
}
@@ -458,8 +458,10 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_enc_create.version = XVID_VERSION;
/* Store the desired frame size */
xvid_enc_create.width = x->xsize = avctx->width;
xvid_enc_create.height = x->ysize = avctx->height;
xvid_enc_create.width =
x->xsize = avctx->width;
xvid_enc_create.height =
x->ysize = avctx->height;
/* Xvid can determine the proper profile to use */
/* xvid_enc_create.profile = XVID_PROFILE_S_L3; */
@@ -488,7 +490,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
"Xvid: Cannot allocate 2-pass log buffers\n");
goto fail;
}
x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0;
x->twopassbuffer[0] =
x->old_twopassbuffer[0] = 0;
plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass;
plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
@@ -499,8 +502,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
fd = av_tempfile("xvidff.", &x->twopassfile, 0, avctx);
if (fd == -1) {
av_log(avctx, AV_LOG_ERROR,
"Xvid: Cannot write 2-pass pipe\n");
av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write 2-pass pipe\n");
goto fail;
}
x->twopassfd = fd;
@@ -513,8 +515,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
if (strlen(avctx->stats_in) >
write(fd, avctx->stats_in, strlen(avctx->stats_in))) {
av_log(avctx, AV_LOG_ERROR,
"Xvid: Cannot write to 2-pass pipe\n");
av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write to 2-pass pipe\n");
goto fail;
}
@@ -542,8 +543,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
/* The old behavior is that when avctx->lumi_masking is specified,
* plugins[...].param = NULL. Trying to keep the old behavior here. */
plugins[xvid_enc_create.num_plugins].param = avctx->lumi_masking ? NULL
: &masking_l;
plugins[xvid_enc_create.num_plugins].param =
avctx->lumi_masking ? NULL : &masking_l;
xvid_enc_create.num_plugins++;
}
@@ -581,8 +582,10 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_enc_create.max_key_interval = 240; /* Xvid's best default */
/* Quants */
if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1;
else x->qscale = 0;
if (xvid_flags & CODEC_FLAG_QSCALE)
x->qscale = 1;
else
x->qscale = 0;
xvid_enc_create.min_quant[0] = avctx->qmin;
xvid_enc_create.min_quant[1] = avctx->qmin;
@@ -592,7 +595,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_enc_create.max_quant[2] = avctx->qmax;
/* Quant Matrices */
x->intra_matrix = x->inter_matrix = NULL;
x->intra_matrix =
x->inter_matrix = NULL;
if (avctx->mpeg_quant)
x->vol_flags |= XVID_VOL_MPEGQUANT;
if ((avctx->intra_matrix || avctx->inter_matrix)) {
@@ -641,7 +645,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_enc_create.max_bframes = avctx->max_b_frames;
xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset;
xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor;
if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED;
if (avctx->max_b_frames > 0 && !x->quicktime_format)
xvid_enc_create.global |= XVID_GLOBAL_PACKED;
av_assert0(xvid_enc_create.num_plugins + (!!x->ssim) + (!!x->variance_aq) + (!!x->lumi_aq) <= FF_ARRAY_ELEMS(plugins));
@@ -667,11 +672,11 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *picture, int *got_packet)
{
int xerr, i, ret, user_packet = !!pkt->data;
char *tmp;
struct xvid_context *x = avctx->priv_data;
AVFrame *p = avctx->coded_frame;
int mb_width = (avctx->width + 15) / 16;
int mb_height = (avctx->height + 15) / 16;
char *tmp;
xvid_enc_frame_t xvid_enc_frame = { 0 };
xvid_enc_stats_t xvid_enc_stats = { 0 };
@@ -689,7 +694,8 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
/* Initialize input image fields */
if (avctx->pix_fmt != AV_PIX_FMT_YUV420P) {
av_log(avctx, AV_LOG_ERROR, "Xvid: Color spaces other than 420p not supported\n");
av_log(avctx, AV_LOG_ERROR,
"Xvid: Color spaces other than 420P not supported\n");
return AVERROR(EINVAL);
}
@@ -724,8 +730,10 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den;
/* Quant Setting */
if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
else xvid_enc_frame.quant = 0;
if (x->qscale)
xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
else
xvid_enc_frame.quant = 0;
/* Matrices */
xvid_enc_frame.quant_intra_matrix = x->intra_matrix;
@@ -776,12 +784,14 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
av_free_packet(pkt);
if (!xerr)
return 0;
av_log(avctx, AV_LOG_ERROR, "Xvid: Encoding Error Occurred: %i\n", xerr);
av_log(avctx, AV_LOG_ERROR,
"Xvid: Encoding Error Occurred: %i\n", xerr);
return AVERROR_EXTERNAL;
}
}
static av_cold int xvid_encode_close(AVCodecContext *avctx) {
static av_cold int xvid_encode_close(AVCodecContext *avctx)
{
struct xvid_context *x = avctx->priv_data;
if(x->encoder_handle)

View File

@@ -26,7 +26,6 @@
* common functions for use with the Xvid wrappers
*/
int ff_tempfile(const char *prefix, char **filename);
#endif /* AVCODEC_LIBXVID_H */

View File

@@ -21,23 +21,23 @@
*/
#include "config.h"
#include <xvid.h>
#include "libavutil/attributes.h"
#include "libavutil/file.h"
#include "avcodec.h"
#include "libxvid.h"
#include "mpegvideo.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_IO_H
#include <io.h>
#endif
#undef NDEBUG
#include <assert.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <xvid.h>
#include "libavutil/attributes.h"
#include "libavutil/file.h"
#include "avcodec.h"
#include "libxvid.h"
#include "mpegvideo.h"
av_cold int ff_xvid_rate_control_init(MpegEncContext *s)
{
@@ -60,8 +60,12 @@ av_cold int ff_xvid_rate_control_init(MpegEncContext *s)
rce = &s->rc_context.entry[i];
snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n",
frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count,
rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8);
frame_types[rce->pict_type],
(int) lrintf(rce->qscale / FF_QP2LAMBDA),
rce->i_count, s->mb_num - rce->i_count - rce->skip_count,
rce->skip_count,
(rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits + 7) / 8,
(rce->header_bits + rce->mv_bits + 7) / 8);
if (write(fd, tmp, strlen(tmp)) < 0) {
av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno));
@@ -85,14 +89,16 @@ av_cold int ff_xvid_rate_control_init(MpegEncContext *s)
xvid_plg_create.fincr = s->avctx->time_base.num;
xvid_plg_create.param = &xvid_2pass2;
if(xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque)<0){
if (xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create,
&s->rc_context.non_lavc_opaque) < 0) {
av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n");
return -1;
}
return 0;
}
float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){
float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run)
{
xvid_plg_data_t xvid_plg_data = { 0 };
xvid_plg_data.version = XVID_MAKE_VERSION(1, 1, 0);
@@ -117,18 +123,21 @@ float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){
xvid_plg_data.stats.length = (s->frame_bits + 7) / 8;
xvid_plg_data.frame_num = s->rc_context.last_picture_number;
xvid_plg_data.quant = s->qscale;
xvid_plg_data.type = s->last_pict_type;
if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_AFTER, &xvid_plg_data, NULL)){
av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n");
if (xvid_plugin_2pass2(s->rc_context.non_lavc_opaque,
XVID_PLG_AFTER, &xvid_plg_data, NULL)) {
av_log(s->avctx, AV_LOG_ERROR,
"xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n");
return -1;
}
}
s->rc_context.last_picture_number =
xvid_plg_data.frame_num = s->picture_number;
xvid_plg_data.quant = 0;
if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_BEFORE, &xvid_plg_data, NULL)){
av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n");
if (xvid_plugin_2pass2(s->rc_context.non_lavc_opaque,
XVID_PLG_BEFORE, &xvid_plg_data, NULL)) {
av_log(s->avctx, AV_LOG_ERROR,
"xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n");
return -1;
}
s->rc_context.dry_run_qscale = xvid_plg_data.quant;
@@ -137,8 +146,10 @@ float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){
if (!dry_run)
s->rc_context.dry_run_qscale = 0;
if(s->pict_type == AV_PICTURE_TYPE_B) //FIXME this is not exactly identical to xvid
return xvid_plg_data.quant * FF_QP2LAMBDA * s->avctx->b_quant_factor + s->avctx->b_quant_offset;
// FIXME this is not exactly identical to Xvid
if (s->pict_type == AV_PICTURE_TYPE_B)
return xvid_plg_data.quant * FF_QP2LAMBDA * s->avctx->b_quant_factor +
s->avctx->b_quant_offset;
else
return xvid_plg_data.quant * FF_QP2LAMBDA;
}
@@ -147,5 +158,6 @@ av_cold void ff_xvid_rate_control_uninit(MpegEncContext *s)
{
xvid_plg_destroy_t xvid_plg_destroy;
xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_DESTROY, &xvid_plg_destroy, NULL);
xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_DESTROY,
&xvid_plg_destroy, NULL);
}

View File

@@ -137,7 +137,8 @@ void av_file_unmap(uint8_t *bufptr, size_t size)
#endif
}
int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx) {
int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx)
{
FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
int fd = -1;
#if !HAVE_MKSTEMP