libxvid: K&R formatting cosmetics
Signed-off-by: Diego Biurrun <diego@biurrun.de>
This commit is contained in:
committed by
Diego Biurrun
parent
56a721f020
commit
0a02426826
@@ -25,12 +25,14 @@
|
|||||||
* @author Adam Thayer (krevnik@comcast.net)
|
* @author Adam Thayer (krevnik@comcast.net)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xvid.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "avcodec.h"
|
#include <xvid.h>
|
||||||
|
|
||||||
#include "libavutil/cpu.h"
|
#include "libavutil/cpu.h"
|
||||||
#include "libavutil/intreadwrite.h"
|
#include "libavutil/intreadwrite.h"
|
||||||
#include "libavutil/mathematics.h"
|
#include "libavutil/mathematics.h"
|
||||||
|
|
||||||
|
#include "avcodec.h"
|
||||||
#include "libxvid.h"
|
#include "libxvid.h"
|
||||||
#include "mpegvideo.h"
|
#include "mpegvideo.h"
|
||||||
|
|
||||||
@@ -92,8 +94,8 @@ struct xvid_ff_pass1 {
|
|||||||
* @param handle Private context handle
|
* @param handle Private context handle
|
||||||
* @return Returns XVID_ERR_xxxx on failure, or 0 on success.
|
* @return Returns XVID_ERR_xxxx on failure, or 0 on success.
|
||||||
*/
|
*/
|
||||||
static int xvid_ff_2pass_create(xvid_plg_create_t * param,
|
static int xvid_ff_2pass_create(xvid_plg_create_t *param, void **handle)
|
||||||
void ** handle) {
|
{
|
||||||
struct xvid_ff_pass1 *x = (struct xvid_ff_pass1 *) param->param;
|
struct xvid_ff_pass1 *x = (struct xvid_ff_pass1 *) param->param;
|
||||||
char *log = x->context->twopassbuffer;
|
char *log = x->context->twopassbuffer;
|
||||||
|
|
||||||
@@ -124,7 +126,8 @@ static int xvid_ff_2pass_create(xvid_plg_create_t * param,
|
|||||||
* @return Returns 0, success guaranteed
|
* @return Returns 0, success guaranteed
|
||||||
*/
|
*/
|
||||||
static int xvid_ff_2pass_destroy(struct xvid_context *ref,
|
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 */
|
/* Currently cannot think of anything to do on destruction */
|
||||||
/* Still, the framework should be here for reference/use */
|
/* Still, the framework should be here for reference/use */
|
||||||
if (ref->twopassbuffer)
|
if (ref->twopassbuffer)
|
||||||
@@ -140,7 +143,8 @@ static int xvid_ff_2pass_destroy(struct xvid_context *ref,
|
|||||||
* @return Returns 0, success guaranteed
|
* @return Returns 0, success guaranteed
|
||||||
*/
|
*/
|
||||||
static int xvid_ff_2pass_before(struct xvid_context *ref,
|
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_remove;
|
||||||
int motion_replacements;
|
int motion_replacements;
|
||||||
int vop_remove;
|
int vop_remove;
|
||||||
@@ -183,7 +187,8 @@ static int xvid_ff_2pass_before(struct xvid_context *ref,
|
|||||||
* @return Returns XVID_ERR_xxxx on failure, or 0 on success
|
* @return Returns XVID_ERR_xxxx on failure, or 0 on success
|
||||||
*/
|
*/
|
||||||
static int xvid_ff_2pass_after(struct xvid_context *ref,
|
static int xvid_ff_2pass_after(struct xvid_context *ref,
|
||||||
xvid_plg_data_t *param) {
|
xvid_plg_data_t *param)
|
||||||
|
{
|
||||||
char *log = ref->twopassbuffer;
|
char *log = ref->twopassbuffer;
|
||||||
const char *frame_types = " ipbs";
|
const char *frame_types = " ipbs";
|
||||||
char frame_type;
|
char frame_type;
|
||||||
@@ -193,16 +198,16 @@ static int xvid_ff_2pass_after(struct xvid_context *ref,
|
|||||||
return XVID_ERR_FAIL;
|
return XVID_ERR_FAIL;
|
||||||
|
|
||||||
/* Convert the type given to us into a character */
|
/* 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];
|
frame_type = frame_types[param->type];
|
||||||
} else {
|
else
|
||||||
return XVID_ERR_FAIL;
|
return XVID_ERR_FAIL;
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
|
snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
|
||||||
"%c %d %d %d %d %d %d\n",
|
"%c %d %d %d %d %d %d\n",
|
||||||
frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks,
|
frame_type, param->stats.quant, param->stats.kblks,
|
||||||
param->stats.ublks, param->stats.length, param->stats.hlength);
|
param->stats.mblks, param->stats.ublks,
|
||||||
|
param->stats.length, param->stats.hlength);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -224,19 +229,14 @@ static int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2)
|
|||||||
case XVID_PLG_INFO:
|
case XVID_PLG_INFO:
|
||||||
case XVID_PLG_FRAME:
|
case XVID_PLG_FRAME:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case XVID_PLG_BEFORE:
|
case XVID_PLG_BEFORE:
|
||||||
return xvid_ff_2pass_before(ref, p1);
|
return xvid_ff_2pass_before(ref, p1);
|
||||||
|
|
||||||
case XVID_PLG_CREATE:
|
case XVID_PLG_CREATE:
|
||||||
return xvid_ff_2pass_create(p1, p2);
|
return xvid_ff_2pass_create(p1, p2);
|
||||||
|
|
||||||
case XVID_PLG_AFTER:
|
case XVID_PLG_AFTER:
|
||||||
return xvid_ff_2pass_after(ref, p1);
|
return xvid_ff_2pass_after(ref, p1);
|
||||||
|
|
||||||
case XVID_PLG_DESTROY:
|
case XVID_PLG_DESTROY:
|
||||||
return xvid_ff_2pass_destroy(ref, p1);
|
return xvid_ff_2pass_destroy(ref, p1);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return XVID_ERR_FAIL;
|
return XVID_ERR_FAIL;
|
||||||
}
|
}
|
||||||
@@ -255,10 +255,10 @@ static int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2)
|
|||||||
* @param frame_len Length of encoded frame data
|
* @param frame_len Length of encoded frame data
|
||||||
* @return Returns new length of frame data
|
* @return Returns new length of frame data
|
||||||
*/
|
*/
|
||||||
static int xvid_strip_vol_header(AVCodecContext *avctx,
|
static int xvid_strip_vol_header(AVCodecContext *avctx, AVPacket *pkt,
|
||||||
AVPacket *pkt,
|
|
||||||
unsigned int header_len,
|
unsigned int header_len,
|
||||||
unsigned int frame_len) {
|
unsigned int frame_len)
|
||||||
|
{
|
||||||
int vo_len = 0, i;
|
int vo_len = 0, i;
|
||||||
|
|
||||||
for (i = 0; i < header_len - 3; i++) {
|
for (i = 0; i < header_len - 3; i++) {
|
||||||
@@ -279,7 +279,7 @@ static int xvid_strip_vol_header(AVCodecContext *avctx,
|
|||||||
avctx->extradata_size = vo_len;
|
avctx->extradata_size = vo_len;
|
||||||
}
|
}
|
||||||
/* Less dangerous now, memmove properly copies the two
|
/* 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);
|
memmove(pkt->data, &pkt->data[vo_len], frame_len - vo_len);
|
||||||
pkt->size = frame_len - vo_len;
|
pkt->size = frame_len - vo_len;
|
||||||
}
|
}
|
||||||
@@ -345,7 +345,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 xerr, i;
|
||||||
int xvid_flags = avctx->flags;
|
int xvid_flags = avctx->flags;
|
||||||
struct xvid_context *x = avctx->priv_data;
|
struct xvid_context *x = avctx->priv_data;
|
||||||
@@ -366,8 +367,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */
|
x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */
|
||||||
if (xvid_flags & CODEC_FLAG_4MV)
|
if (xvid_flags & CODEC_FLAG_4MV)
|
||||||
x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */
|
x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */
|
||||||
if( avctx->trellis
|
if (avctx->trellis)
|
||||||
)
|
|
||||||
x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */
|
x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */
|
||||||
if (xvid_flags & CODEC_FLAG_AC_PRED)
|
if (xvid_flags & CODEC_FLAG_AC_PRED)
|
||||||
x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */
|
x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */
|
||||||
@@ -378,20 +378,20 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
x->me_flags = 0;
|
x->me_flags = 0;
|
||||||
switch (avctx->me_method) {
|
switch (avctx->me_method) {
|
||||||
case ME_FULL: /* Quality 6 */
|
case ME_FULL: /* Quality 6 */
|
||||||
x->me_flags |= XVID_ME_EXTSEARCH16
|
x->me_flags |= XVID_ME_EXTSEARCH16 |
|
||||||
| XVID_ME_EXTSEARCH8;
|
XVID_ME_EXTSEARCH8;
|
||||||
|
|
||||||
case ME_EPZS: /* Quality 4 */
|
case ME_EPZS: /* Quality 4 */
|
||||||
x->me_flags |= XVID_ME_ADVANCEDDIAMOND8
|
x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 |
|
||||||
| XVID_ME_HALFPELREFINE8
|
XVID_ME_HALFPELREFINE8 |
|
||||||
| XVID_ME_CHROMA_PVOP
|
XVID_ME_CHROMA_PVOP |
|
||||||
| XVID_ME_CHROMA_BVOP;
|
XVID_ME_CHROMA_BVOP;
|
||||||
|
|
||||||
case ME_LOG: /* Quality 2 */
|
case ME_LOG: /* Quality 2 */
|
||||||
case ME_PHODS:
|
case ME_PHODS:
|
||||||
case ME_X1:
|
case ME_X1:
|
||||||
x->me_flags |= XVID_ME_ADVANCEDDIAMOND16
|
x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 |
|
||||||
| XVID_ME_HALFPELREFINE16;
|
XVID_ME_HALFPELREFINE16;
|
||||||
|
|
||||||
case ME_ZERO: /* Quality 0 */
|
case ME_ZERO: /* Quality 0 */
|
||||||
default:
|
default:
|
||||||
@@ -402,16 +402,15 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
switch (avctx->mb_decision) {
|
switch (avctx->mb_decision) {
|
||||||
case 2:
|
case 2:
|
||||||
x->vop_flags |= XVID_VOP_MODEDECISION_RD;
|
x->vop_flags |= XVID_VOP_MODEDECISION_RD;
|
||||||
x->me_flags |= XVID_ME_HALFPELREFINE8_RD
|
x->me_flags |= XVID_ME_HALFPELREFINE8_RD |
|
||||||
| XVID_ME_QUARTERPELREFINE8_RD
|
XVID_ME_QUARTERPELREFINE8_RD |
|
||||||
| XVID_ME_EXTSEARCH_RD
|
XVID_ME_EXTSEARCH_RD |
|
||||||
| XVID_ME_CHECKPREDICTION_RD;
|
XVID_ME_CHECKPREDICTION_RD;
|
||||||
case 1:
|
case 1:
|
||||||
if (!(x->vop_flags & XVID_VOP_MODEDECISION_RD))
|
if (!(x->vop_flags & XVID_VOP_MODEDECISION_RD))
|
||||||
x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
|
x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
|
||||||
x->me_flags |= XVID_ME_HALFPELREFINE16_RD
|
x->me_flags |= XVID_ME_HALFPELREFINE16_RD |
|
||||||
| XVID_ME_QUARTERPELREFINE16_RD;
|
XVID_ME_QUARTERPELREFINE16_RD;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -445,8 +444,10 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
xvid_enc_create.version = XVID_VERSION;
|
xvid_enc_create.version = XVID_VERSION;
|
||||||
|
|
||||||
/* Store the desired frame size */
|
/* Store the desired frame size */
|
||||||
xvid_enc_create.width = x->xsize = avctx->width;
|
xvid_enc_create.width =
|
||||||
xvid_enc_create.height = x->ysize = avctx->height;
|
x->xsize = avctx->width;
|
||||||
|
xvid_enc_create.height =
|
||||||
|
x->ysize = avctx->height;
|
||||||
|
|
||||||
/* Xvid can determine the proper profile to use */
|
/* Xvid can determine the proper profile to use */
|
||||||
/* xvid_enc_create.profile = XVID_PROFILE_S_L3; */
|
/* xvid_enc_create.profile = XVID_PROFILE_S_L3; */
|
||||||
@@ -475,7 +476,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
"Xvid: Cannot allocate 2-pass log buffers\n");
|
"Xvid: Cannot allocate 2-pass log buffers\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
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].func = xvid_ff_2pass;
|
||||||
plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
|
plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
|
||||||
@@ -486,8 +488,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
|
|
||||||
fd = ff_tempfile("xvidff.", &x->twopassfile);
|
fd = ff_tempfile("xvidff.", &x->twopassfile);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
av_log(avctx, AV_LOG_ERROR,
|
av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write 2-pass pipe\n");
|
||||||
"Xvid: Cannot write 2-pass pipe\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,8 +501,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
if (strlen(avctx->stats_in) >
|
if (strlen(avctx->stats_in) >
|
||||||
write(fd, avctx->stats_in, strlen(avctx->stats_in))) {
|
write(fd, avctx->stats_in, strlen(avctx->stats_in))) {
|
||||||
close(fd);
|
close(fd);
|
||||||
av_log(avctx, AV_LOG_ERROR,
|
av_log(avctx, AV_LOG_ERROR, "Xvid: Cannot write to 2-pass pipe\n");
|
||||||
"Xvid: Cannot write to 2-pass pipe\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,8 +536,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
|
|
||||||
/* The old behavior is that when avctx->lumi_masking is specified,
|
/* The old behavior is that when avctx->lumi_masking is specified,
|
||||||
* plugins[...].param = NULL. Trying to keep the old behavior here. */
|
* plugins[...].param = NULL. Trying to keep the old behavior here. */
|
||||||
plugins[xvid_enc_create.num_plugins].param = avctx->lumi_masking ? NULL
|
plugins[xvid_enc_create.num_plugins].param =
|
||||||
: &masking_l;
|
avctx->lumi_masking ? NULL : &masking_l;
|
||||||
xvid_enc_create.num_plugins++;
|
xvid_enc_create.num_plugins++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,8 +570,10 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
xvid_enc_create.max_key_interval = 240; /* Xvid's best default */
|
xvid_enc_create.max_key_interval = 240; /* Xvid's best default */
|
||||||
|
|
||||||
/* Quants */
|
/* Quants */
|
||||||
if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1;
|
if (xvid_flags & CODEC_FLAG_QSCALE)
|
||||||
else x->qscale = 0;
|
x->qscale = 1;
|
||||||
|
else
|
||||||
|
x->qscale = 0;
|
||||||
|
|
||||||
xvid_enc_create.min_quant[0] = avctx->qmin;
|
xvid_enc_create.min_quant[0] = avctx->qmin;
|
||||||
xvid_enc_create.min_quant[1] = avctx->qmin;
|
xvid_enc_create.min_quant[1] = avctx->qmin;
|
||||||
@@ -581,7 +583,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
xvid_enc_create.max_quant[2] = avctx->qmax;
|
xvid_enc_create.max_quant[2] = avctx->qmax;
|
||||||
|
|
||||||
/* Quant Matrices */
|
/* Quant Matrices */
|
||||||
x->intra_matrix = x->inter_matrix = NULL;
|
x->intra_matrix =
|
||||||
|
x->inter_matrix = NULL;
|
||||||
if (avctx->mpeg_quant)
|
if (avctx->mpeg_quant)
|
||||||
x->vol_flags |= XVID_VOL_MPEGQUANT;
|
x->vol_flags |= XVID_VOL_MPEGQUANT;
|
||||||
if ((avctx->intra_matrix || avctx->inter_matrix)) {
|
if ((avctx->intra_matrix || avctx->inter_matrix)) {
|
||||||
@@ -630,7 +633,8 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
|
|||||||
xvid_enc_create.max_bframes = avctx->max_b_frames;
|
xvid_enc_create.max_bframes = avctx->max_b_frames;
|
||||||
xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset;
|
xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset;
|
||||||
xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor;
|
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;
|
||||||
|
|
||||||
/* Create encoder context */
|
/* Create encoder context */
|
||||||
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
|
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
|
||||||
@@ -651,11 +655,11 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
const AVFrame *picture, int *got_packet)
|
const AVFrame *picture, int *got_packet)
|
||||||
{
|
{
|
||||||
int xerr, i, ret, user_packet = !!pkt->data;
|
int xerr, i, ret, user_packet = !!pkt->data;
|
||||||
char *tmp;
|
|
||||||
struct xvid_context *x = avctx->priv_data;
|
struct xvid_context *x = avctx->priv_data;
|
||||||
AVFrame *p = avctx->coded_frame;
|
AVFrame *p = avctx->coded_frame;
|
||||||
int mb_width = (avctx->width + 15) / 16;
|
int mb_width = (avctx->width + 15) / 16;
|
||||||
int mb_height = (avctx->height + 15) / 16;
|
int mb_height = (avctx->height + 15) / 16;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
xvid_enc_frame_t xvid_enc_frame = { 0 };
|
xvid_enc_frame_t xvid_enc_frame = { 0 };
|
||||||
xvid_enc_stats_t xvid_enc_stats = { 0 };
|
xvid_enc_stats_t xvid_enc_stats = { 0 };
|
||||||
@@ -676,7 +680,8 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
|
|
||||||
/* Initialize input image fields */
|
/* Initialize input image fields */
|
||||||
if (avctx->pix_fmt != AV_PIX_FMT_YUV420P) {
|
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 -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,8 +714,10 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den;
|
xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den;
|
||||||
|
|
||||||
/* Quant Setting */
|
/* Quant Setting */
|
||||||
if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
|
if (x->qscale)
|
||||||
else xvid_enc_frame.quant = 0;
|
xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
|
||||||
|
else
|
||||||
|
xvid_enc_frame.quant = 0;
|
||||||
|
|
||||||
/* Matrices */
|
/* Matrices */
|
||||||
xvid_enc_frame.quant_intra_matrix = x->intra_matrix;
|
xvid_enc_frame.quant_intra_matrix = x->intra_matrix;
|
||||||
@@ -761,12 +768,14 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
av_free_packet(pkt);
|
av_free_packet(pkt);
|
||||||
if (!xerr)
|
if (!xerr)
|
||||||
return 0;
|
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 -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
struct xvid_context *x = avctx->priv_data;
|
||||||
|
|
||||||
xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
|
xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
* common functions for use with the Xvid wrappers
|
* common functions for use with the Xvid wrappers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
int ff_tempfile(const char *prefix, char **filename);
|
int ff_tempfile(const char *prefix, char **filename);
|
||||||
|
|
||||||
#endif /* AVCODEC_LIBXVID_H */
|
#endif /* AVCODEC_LIBXVID_H */
|
||||||
|
@@ -21,27 +21,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <xvid.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#if !HAVE_MKSTEMP
|
#if !HAVE_MKSTEMP
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <xvid.h>
|
||||||
|
|
||||||
#include "libavutil/attributes.h"
|
#include "libavutil/attributes.h"
|
||||||
#include "libavutil/internal.h"
|
#include "libavutil/internal.h"
|
||||||
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "libxvid.h"
|
#include "libxvid.h"
|
||||||
#include "mpegvideo.h"
|
#include "mpegvideo.h"
|
||||||
|
|
||||||
#undef NDEBUG
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
/* Wrapper to work around the lack of mkstemp() on mingw.
|
/* Wrapper to work around the lack of mkstemp() on mingw.
|
||||||
* Also, tries to create file in /tmp first, if possible.
|
* Also, tries to create file in /tmp first, if possible.
|
||||||
* *prefix can be a character constant; *filename will be allocated internally.
|
* *prefix can be a character constant; *filename will be allocated internally.
|
||||||
* @return file descriptor of opened file (or -1 on error)
|
* @return file descriptor of opened file (or -1 on error)
|
||||||
* and opened file name in **filename. */
|
* and opened file name in **filename. */
|
||||||
int ff_tempfile(const char *prefix, char **filename) {
|
int ff_tempfile(const char *prefix, char **filename)
|
||||||
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
#if !HAVE_MKSTEMP
|
#if !HAVE_MKSTEMP
|
||||||
*filename = tempnam(".", prefix);
|
*filename = tempnam(".", prefix);
|
||||||
@@ -93,8 +93,12 @@ av_cold int ff_xvid_rate_control_init(MpegEncContext *s)
|
|||||||
rce = &s->rc_context.entry[i];
|
rce = &s->rc_context.entry[i];
|
||||||
|
|
||||||
snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n",
|
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,
|
frame_types[rce->pict_type],
|
||||||
rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8);
|
(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);
|
||||||
|
|
||||||
write(fd, tmp, strlen(tmp));
|
write(fd, tmp, strlen(tmp));
|
||||||
}
|
}
|
||||||
@@ -113,14 +117,16 @@ av_cold int ff_xvid_rate_control_init(MpegEncContext *s)
|
|||||||
xvid_plg_create.fincr = s->avctx->time_base.num;
|
xvid_plg_create.fincr = s->avctx->time_base.num;
|
||||||
xvid_plg_create.param = &xvid_2pass2;
|
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");
|
av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
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_t xvid_plg_data = { 0 };
|
||||||
|
|
||||||
xvid_plg_data.version = XVID_MAKE_VERSION(1, 1, 0);
|
xvid_plg_data.version = XVID_MAKE_VERSION(1, 1, 0);
|
||||||
@@ -145,18 +151,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.stats.length = (s->frame_bits + 7) / 8;
|
||||||
xvid_plg_data.frame_num = s->rc_context.last_picture_number;
|
xvid_plg_data.frame_num = s->rc_context.last_picture_number;
|
||||||
xvid_plg_data.quant = s->qscale;
|
xvid_plg_data.quant = s->qscale;
|
||||||
|
|
||||||
xvid_plg_data.type = s->last_pict_type;
|
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)){
|
if (xvid_plugin_2pass2(s->rc_context.non_lavc_opaque,
|
||||||
av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n");
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s->rc_context.last_picture_number =
|
s->rc_context.last_picture_number =
|
||||||
xvid_plg_data.frame_num = s->picture_number;
|
xvid_plg_data.frame_num = s->picture_number;
|
||||||
xvid_plg_data.quant = 0;
|
xvid_plg_data.quant = 0;
|
||||||
if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_BEFORE, &xvid_plg_data, NULL)){
|
if (xvid_plugin_2pass2(s->rc_context.non_lavc_opaque,
|
||||||
av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n");
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
s->rc_context.dry_run_qscale = xvid_plg_data.quant;
|
s->rc_context.dry_run_qscale = xvid_plg_data.quant;
|
||||||
@@ -165,8 +174,10 @@ float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){
|
|||||||
if (!dry_run)
|
if (!dry_run)
|
||||||
s->rc_context.dry_run_qscale = 0;
|
s->rc_context.dry_run_qscale = 0;
|
||||||
|
|
||||||
if(s->pict_type == AV_PICTURE_TYPE_B) //FIXME this is not exactly identical to xvid
|
// 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;
|
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
|
else
|
||||||
return xvid_plg_data.quant * FF_QP2LAMBDA;
|
return xvid_plg_data.quant * FF_QP2LAMBDA;
|
||||||
}
|
}
|
||||||
@@ -175,5 +186,6 @@ av_cold void ff_xvid_rate_control_uninit(MpegEncContext *s)
|
|||||||
{
|
{
|
||||||
xvid_plg_destroy_t xvid_plg_destroy;
|
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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user