26 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
* |
* |
29 |
* $Id: encoder.c,v 1.95.2.4 2003-03-13 11:07:20 suxen_drol Exp $ |
* $Id: encoder.c,v 1.95.2.7 2003-03-15 17:03:17 suxen_drol Exp $ |
30 |
* |
* |
31 |
****************************************************************************/ |
****************************************************************************/ |
32 |
|
|
47 |
#include "utils/mbfunctions.h" |
#include "utils/mbfunctions.h" |
48 |
#include "bitstream/bitstream.h" |
#include "bitstream/bitstream.h" |
49 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
|
#include "utils/ratecontrol.h" |
|
50 |
#include "utils/emms.h" |
#include "utils/emms.h" |
51 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
52 |
#include "quant/adapt_quant.h" |
#include "quant/adapt_quant.h" |
166 |
/* framerate */ |
/* framerate */ |
167 |
pEnc->mbParam.fincr = MAX(create->fincr, 0); |
pEnc->mbParam.fincr = MAX(create->fincr, 0); |
168 |
pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase; |
pEnc->mbParam.fbase = create->fincr <= 0 ? 25 : create->fbase; |
169 |
|
if (pEnc->mbParam.fincr>0) |
170 |
simplify_time(&pEnc->mbParam.fincr, &pEnc->mbParam.fbase); |
simplify_time(&pEnc->mbParam.fincr, &pEnc->mbParam.fbase); |
171 |
|
|
172 |
/* plugin */ |
/* plugin */ |
182 |
memset(&pinfo, 0, sizeof(xvid_plg_info_t)); |
memset(&pinfo, 0, sizeof(xvid_plg_info_t)); |
183 |
pinfo.version = XVID_VERSION; |
pinfo.version = XVID_VERSION; |
184 |
if (create->plugins[n].func(0, XVID_PLG_INFO, &pinfo, 0) >= 0) { |
if (create->plugins[n].func(0, XVID_PLG_INFO, &pinfo, 0) >= 0) { |
185 |
pEnc->plugin_flags |= pinfo.flags; |
pEnc->mbParam.plugin_flags |= pinfo.flags; |
186 |
} |
} |
187 |
|
|
188 |
memset(&pcreate, 0, sizeof(xvid_plg_create_t)); |
memset(&pcreate, 0, sizeof(xvid_plg_create_t)); |
197 |
if (create->plugins[n].func(0, XVID_PLG_CREATE, &pcreate, &pEnc->plugins[n].param) >= 0) { |
if (create->plugins[n].func(0, XVID_PLG_CREATE, &pcreate, &pEnc->plugins[n].param) >= 0) { |
198 |
pEnc->plugins[n].func = create->plugins[n].func; |
pEnc->plugins[n].func = create->plugins[n].func; |
199 |
} |
} |
200 |
|
} |
201 |
|
|
202 |
|
if ((pEnc->mbParam.global_flags & XVID_EXTRASTATS_ENABLE) || |
203 |
|
(pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { |
204 |
|
pEnc->mbParam.plugin_flags |= XVID_REQORIGINAL; /* psnr calculation requires the original */ |
205 |
} |
} |
206 |
|
|
207 |
/* temp dquants */ |
/* temp dquants */ |
223 |
|
|
224 |
/* Bitrate allocator defaults |
/* Bitrate allocator defaults |
225 |
|
|
|
if (create->rc_bitrate <= 0) |
|
|
create->rc_bitrate = 900000; |
|
|
|
|
|
if (create->rc_reaction_delay_factor <= 0) |
|
|
create->rc_reaction_delay_factor = 16; |
|
|
|
|
|
if (create->rc_averaging_period <= 0) |
|
|
create->rc_averaging_period = 100; |
|
|
|
|
|
if (create->rc_buffer <= 0) |
|
|
create->rc_buffer = 100; |
|
|
|
|
|
|
|
|
|
|
226 |
if ((create->min_quantizer <= 0) || (create->min_quantizer > 31)) |
if ((create->min_quantizer <= 0) || (create->min_quantizer > 31)) |
227 |
create->min_quantizer = 1; |
create->min_quantizer = 1; |
228 |
|
|
230 |
create->max_quantizer = 31; |
create->max_quantizer = 31; |
231 |
|
|
232 |
if (create->max_quantizer < create->min_quantizer) |
if (create->max_quantizer < create->min_quantizer) |
233 |
create->max_quantizer = create->min_quantizer; |
create->max_quantizer = create->min_quantizer; */ |
|
|
|
|
pEnc->bitrate = create->rc_bitrate; */ |
|
234 |
|
|
235 |
|
|
236 |
/* allocate working frame-image memory */ |
/* allocate working frame-image memory */ |
255 |
|
|
256 |
/* allocate interpolation image memory */ |
/* allocate interpolation image memory */ |
257 |
|
|
258 |
if (create->global & XVID_EXTRASTATS_ENABLE) |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
259 |
image_null(&pEnc->sOriginal); |
image_null(&pEnc->sOriginal); |
260 |
|
image_null(&pEnc->sOriginal2); |
261 |
|
} |
262 |
|
|
263 |
image_null(&pEnc->f_refh); |
image_null(&pEnc->f_refh); |
264 |
image_null(&pEnc->f_refv); |
image_null(&pEnc->f_refv); |
272 |
image_null(&pEnc->vInterHV); |
image_null(&pEnc->vInterHV); |
273 |
image_null(&pEnc->vInterHVf); |
image_null(&pEnc->vInterHVf); |
274 |
|
|
275 |
if (create->global & XVID_EXTRASTATS_ENABLE) |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
276 |
{ if (image_create |
if (image_create |
277 |
(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
278 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
279 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
280 |
|
|
281 |
|
if (image_create |
282 |
|
(&pEnc->sOriginal2, pEnc->mbParam.edged_width, |
283 |
|
pEnc->mbParam.edged_height) < 0) |
284 |
|
goto xvid_err_memory3; |
285 |
} |
} |
286 |
|
|
287 |
if (image_create |
if (image_create |
416 |
pEnc->iFrameNum = 0; |
pEnc->iFrameNum = 0; |
417 |
pEnc->fMvPrevSigma = -1; |
pEnc->fMvPrevSigma = -1; |
418 |
|
|
|
/* XXX: cleanup ratecontol when new code is ready */ |
|
|
/* if (create->rc_bitrate) { |
|
|
RateControlInit(&pEnc->rate_control, create->rc_bitrate, |
|
|
create->rc_reaction_delay_factor, |
|
|
create->rc_averaging_period, create->rc_buffer, |
|
|
create->fbase * 1000 / create->fincr, |
|
|
create->max_quantizer, create->min_quantizer); |
|
|
} */ |
|
|
|
|
419 |
create->handle = (void *) pEnc; |
create->handle = (void *) pEnc; |
420 |
|
|
421 |
init_timer(); |
init_timer(); |
462 |
|
|
463 |
xvid_err_memory3: |
xvid_err_memory3: |
464 |
|
|
465 |
if (pEnc->mbParam.global_flags & XVID_EXTRASTATS_ENABLE) |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
466 |
{ image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
467 |
|
pEnc->mbParam.edged_height); |
468 |
|
image_destroy(&pEnc->sOriginal2, pEnc->mbParam.edged_width, |
469 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
470 |
} |
} |
471 |
|
|
592 |
image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width, |
593 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
594 |
|
|
595 |
if (pEnc->mbParam.global_flags & XVID_EXTRASTATS_ENABLE) |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
596 |
{ image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
597 |
|
pEnc->mbParam.edged_height); |
598 |
|
image_destroy(&pEnc->sOriginal2, pEnc->mbParam.edged_width, |
599 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
600 |
} |
} |
601 |
|
|
626 |
call the plugins |
call the plugins |
627 |
*/ |
*/ |
628 |
|
|
629 |
static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, int opt, int * type, int * quant) |
static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, IMAGE * original, |
630 |
|
int opt, int * type, int * quant, xvid_enc_stats_t * stats) |
631 |
{ |
{ |
632 |
int i; |
int i; |
633 |
xvid_plg_data_t data; |
xvid_plg_data_t data; |
635 |
memset(&data, 0, sizeof(xvid_plg_data_t)); |
memset(&data, 0, sizeof(xvid_plg_data_t)); |
636 |
data.version = XVID_VERSION; |
data.version = XVID_VERSION; |
637 |
|
|
638 |
|
data.width = pEnc->mbParam.width; |
639 |
|
data.height = pEnc->mbParam.height; |
640 |
|
data.fincr = frame->fincr; |
641 |
|
data.fbase = pEnc->mbParam.fbase; |
642 |
|
|
643 |
data.reference.csp = XVID_CSP_USER; |
data.reference.csp = XVID_CSP_USER; |
644 |
data.reference.plane[0] = pEnc->reference->image.y; |
data.reference.plane[0] = pEnc->reference->image.y; |
645 |
data.reference.plane[1] = pEnc->reference->image.u; |
data.reference.plane[1] = pEnc->reference->image.u; |
656 |
data.current.stride[1] = pEnc->mbParam.edged_width/2; |
data.current.stride[1] = pEnc->mbParam.edged_width/2; |
657 |
data.current.stride[2] = pEnc->mbParam.edged_width/2; |
data.current.stride[2] = pEnc->mbParam.edged_width/2; |
658 |
|
|
659 |
data.original.csp = XVID_CSP_NULL; |
data.frame_num = frame->frame_num; |
|
/* todo: data.original */ |
|
660 |
|
|
661 |
if (opt == XVID_PLG_BEFORE) { |
if (opt == XVID_PLG_BEFORE) { |
662 |
data.type = XVID_TYPE_AUTO; |
data.type = XVID_TYPE_AUTO; |
667 |
/* todo: vol,vop,motion flags */ |
/* todo: vol,vop,motion flags */ |
668 |
|
|
669 |
} else { // XVID_PLG_AFTER |
} else { // XVID_PLG_AFTER |
670 |
|
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
671 |
|
data.original.csp = XVID_CSP_USER; |
672 |
|
data.original.plane[0] = original->y; |
673 |
|
data.original.plane[1] = original->u; |
674 |
|
data.original.plane[2] = original->v; |
675 |
|
data.original.stride[0] = pEnc->mbParam.edged_width; |
676 |
|
data.original.stride[1] = pEnc->mbParam.edged_width/2; |
677 |
|
data.original.stride[2] = pEnc->mbParam.edged_width/2; |
678 |
|
} |
679 |
|
|
680 |
|
if ((frame->vol_flags & XVID_EXTRASTATS) || |
681 |
|
(pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { |
682 |
|
|
683 |
|
data.sse_y = |
684 |
|
plane_sse( original->y, frame->image.y, |
685 |
|
pEnc->mbParam.edged_width, pEnc->mbParam.width, |
686 |
|
pEnc->mbParam.height); |
687 |
|
|
688 |
|
data.sse_u = |
689 |
|
plane_sse( original->u, frame->image.u, |
690 |
|
pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2, |
691 |
|
pEnc->mbParam.height/2); |
692 |
|
|
693 |
|
data.sse_v = |
694 |
|
plane_sse( original->v, frame->image.v, |
695 |
|
pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2, |
696 |
|
pEnc->mbParam.height/2); |
697 |
|
} |
698 |
|
|
699 |
data.type = coding2type(frame->coding_type); |
data.type = coding2type(frame->coding_type); |
700 |
data.quant = frame->quant; |
data.quant = frame->quant; |
707 |
data.kblks = frame->sStat.kblks; |
data.kblks = frame->sStat.kblks; |
708 |
data.mblks = frame->sStat.mblks; |
data.mblks = frame->sStat.mblks; |
709 |
data.ublks = frame->sStat.ublks; |
data.ublks = frame->sStat.ublks; |
710 |
|
|
711 |
|
if (stats) |
712 |
|
{ |
713 |
|
stats->type = coding2type(frame->coding_type); |
714 |
|
stats->quant = frame->quant; |
715 |
|
stats->vol_flags = frame->vol_flags; |
716 |
|
stats->vop_flags = frame->vop_flags; |
717 |
|
stats->length = frame->length; |
718 |
|
stats->hlength = frame->length - (frame->sStat.iTextBits / 8); |
719 |
|
stats->kblks = frame->sStat.kblks; |
720 |
|
stats->mblks = frame->sStat.mblks; |
721 |
|
stats->ublks = frame->sStat.ublks; |
722 |
|
stats->sse_y = data.sse_y; |
723 |
|
stats->sse_u = data.sse_u; |
724 |
|
stats->sse_v = data.sse_v; |
725 |
|
} |
726 |
} |
} |
727 |
|
|
728 |
|
emms(); |
729 |
for (i=0; i<pEnc->num_plugins;i++) { |
for (i=0; i<pEnc->num_plugins;i++) { |
730 |
if (pEnc->plugins[i].func) { |
if (pEnc->plugins[i].func) { |
731 |
if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, 0) < 0) { |
if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, 0) < 0) { |
733 |
} |
} |
734 |
} |
} |
735 |
} |
} |
736 |
|
emms(); |
737 |
|
|
738 |
if (opt == XVID_PLG_BEFORE) { |
if (opt == XVID_PLG_BEFORE) { |
739 |
*type = data.type; |
*type = data.type; |
748 |
|
|
749 |
static __inline void inc_frame_num(Encoder * pEnc) |
static __inline void inc_frame_num(Encoder * pEnc) |
750 |
{ |
{ |
751 |
|
pEnc->current->frame_num = pEnc->m_framenum; |
752 |
pEnc->current->stamp = pEnc->mbParam.m_stamp; /* first frame is zero */ |
pEnc->current->stamp = pEnc->mbParam.m_stamp; /* first frame is zero */ |
|
pEnc->mbParam.m_stamp += pEnc->mbParam.fincr; |
|
753 |
|
|
754 |
|
pEnc->mbParam.m_stamp += pEnc->current->fincr; |
755 |
pEnc->m_framenum++; /* debug ticker */ |
pEnc->m_framenum++; /* debug ticker */ |
756 |
} |
} |
757 |
|
|
758 |
|
static __inline void dec_frame_num(Encoder * pEnc) |
759 |
|
{ |
760 |
|
pEnc->mbParam.m_stamp -= pEnc->mbParam.fincr; |
761 |
|
pEnc->m_framenum--; /* debug ticker */ |
762 |
|
} |
763 |
|
|
764 |
|
|
765 |
|
|
766 |
static __inline void |
static __inline void |
783 |
} |
} |
784 |
|
|
785 |
|
|
|
static void |
|
|
set_stats(xvid_enc_stats_t * stats, RateControl * rc, |
|
|
const MBParam * pParam, const FRAMEINFO * frame) |
|
|
{ |
|
|
if (stats) |
|
|
{ |
|
|
stats->type = coding2type(frame->coding_type); |
|
|
stats->quant = frame->quant; |
|
|
stats->vol_flags = frame->vol_flags; |
|
|
stats->vop_flags = frame->vop_flags; |
|
|
stats->length = frame->length; |
|
|
stats->hlength = frame->length - (frame->sStat.iTextBits / 8); |
|
|
stats->kblks = frame->sStat.kblks; |
|
|
stats->mblks = frame->sStat.mblks; |
|
|
stats->ublks = frame->sStat.ublks; |
|
|
} |
|
|
|
|
|
RateControlUpdate(rc, frame->quant, frame->length, frame->coding_type==I_VOP ); |
|
|
} |
|
|
|
|
|
|
|
786 |
|
|
787 |
/***************************************************************************** |
/***************************************************************************** |
788 |
* IPB frame encoder entry point |
* IPB frame encoder entry point |
797 |
****************************************************************************/ |
****************************************************************************/ |
798 |
|
|
799 |
|
|
|
/* XXX: dx50bvop broken! something todo with queue */ |
|
|
|
|
800 |
int |
int |
801 |
enc_encode(Encoder * pEnc, |
enc_encode(Encoder * pEnc, |
802 |
xvid_enc_frame_t * xFrame, |
xvid_enc_frame_t * xFrame, |
804 |
{ |
{ |
805 |
xvid_enc_frame_t * frame; |
xvid_enc_frame_t * frame; |
806 |
int type; |
int type; |
|
uint16_t x, y; |
|
807 |
Bitstream bs; |
Bitstream bs; |
808 |
|
|
809 |
if (XVID_MAJOR(xFrame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ |
if (XVID_MAJOR(xFrame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ |
866 |
|
|
867 |
if (pEnc->flush_bframes) |
if (pEnc->flush_bframes) |
868 |
{ |
{ |
869 |
if (pEnc->bframenum_head < pEnc->bframenum_tail) |
if (pEnc->bframenum_head < pEnc->bframenum_tail) { |
|
{ |
|
870 |
|
|
871 |
DPRINTF(DPRINTF_DEBUG,"*** BFRAME (flush) bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF(DPRINTF_DEBUG,"*** BFRAME (flush) bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
872 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
873 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
874 |
|
|
875 |
if (pEnc->bframes[pEnc->bframenum_head]->vop_flags & XVID_EXTRASTATS) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
876 |
image_copy(&pEnc->sOriginal, &pEnc->bframes[pEnc->bframenum_head]->image, |
image_copy(&pEnc->sOriginal2, &pEnc->bframes[pEnc->bframenum_head]->image, |
877 |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
878 |
} |
} |
879 |
|
|
880 |
FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs); |
FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs); |
881 |
|
call_plugins(pEnc, pEnc->bframes[pEnc->bframenum_head], &pEnc->sOriginal2, XVID_PLG_AFTER, 0, 0, stats); |
|
if (pEnc->bframes[pEnc->bframenum_head]->vop_flags & XVID_EXTRASTATS) { |
|
|
stats->sse_y = |
|
|
plane_sse( pEnc->sOriginal.y, pEnc->bframes[pEnc->bframenum_head]->image.y, |
|
|
pEnc->mbParam.edged_width, pEnc->mbParam.width, |
|
|
pEnc->mbParam.height); |
|
|
|
|
|
stats->sse_u = |
|
|
plane_sse( pEnc->sOriginal.u, pEnc->bframes[pEnc->bframenum_head]->image.u, |
|
|
pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2, |
|
|
pEnc->mbParam.height/2); |
|
|
|
|
|
stats->sse_v = |
|
|
plane_sse( pEnc->sOriginal.v, pEnc->bframes[pEnc->bframenum_head]->image.v, |
|
|
pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2, |
|
|
pEnc->mbParam.height/2); |
|
|
} |
|
|
|
|
|
set_stats(stats, &pEnc->rate_control, &pEnc->mbParam, pEnc->bframes[pEnc->bframenum_head]); |
|
|
emms(); |
|
|
call_plugins(pEnc, pEnc->current, XVID_PLG_AFTER, 0, 0); |
|
|
emms(); |
|
|
|
|
882 |
pEnc->bframenum_head++; |
pEnc->bframenum_head++; |
883 |
|
|
|
|
|
884 |
goto done; |
goto done; |
885 |
} |
} |
886 |
|
|
|
/* flush complete: reset counters */ |
|
|
|
|
|
pEnc->flush_bframes = 0; |
|
|
pEnc->bframenum_head = pEnc->bframenum_tail = 0; |
|
|
|
|
887 |
/* write an empty marker to the bitstream. |
/* write an empty marker to the bitstream. |
888 |
|
|
889 |
for divx5 decoder compatibility, this marker must consist |
for divx5 decoder compatibility, this marker must consist |
891 |
indentical to the future-referece frame. |
indentical to the future-referece frame. |
892 |
*/ |
*/ |
893 |
|
|
894 |
if ((pEnc->mbParam.global_flags & XVID_PACKED)) { |
if ((pEnc->mbParam.global_flags & XVID_PACKED && pEnc->bframenum_tail > 0)) { |
895 |
int tmp; |
int tmp; |
896 |
int bits; |
int bits; |
897 |
|
|
910 |
|
|
911 |
/* add the not-coded length to the reference frame size */ |
/* add the not-coded length to the reference frame size */ |
912 |
pEnc->current->length += (BitstreamPos(&bs) - bits) / 8; |
pEnc->current->length += (BitstreamPos(&bs) - bits) / 8; |
913 |
set_stats(stats, &pEnc->rate_control, &pEnc->mbParam, pEnc->current); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
|
emms(); |
|
|
call_plugins(pEnc, pEnc->current, XVID_PLG_AFTER, 0, 0); |
|
|
emms(); |
|
|
|
|
|
// xFrame->out_flags |= XVID_PACKED_FIXUP?; |
|
914 |
|
|
915 |
|
/* flush complete: reset counters */ |
916 |
|
pEnc->flush_bframes = 0; |
917 |
|
pEnc->bframenum_head = pEnc->bframenum_tail = 0; |
918 |
goto done; |
goto done; |
919 |
|
|
920 |
} |
} |
|
} |
|
921 |
|
|
922 |
|
/* flush complete: reset counters */ |
923 |
|
pEnc->flush_bframes = 0; |
924 |
|
pEnc->bframenum_head = pEnc->bframenum_tail = 0; |
925 |
|
} |
926 |
|
|
927 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
928 |
* dequeue frame from the encoding queue |
* dequeue frame from the encoding queue |
932 |
{ |
{ |
933 |
if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */ |
if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */ |
934 |
{ |
{ |
935 |
if (pEnc->bframenum_tail > 0) /* are bframes */ |
|
936 |
|
if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->mbParam.max_bframes > 0) { |
937 |
|
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
938 |
|
} |
939 |
|
|
940 |
|
/* if the very last frame is to be b-vop, we must change it to a p-vop */ |
941 |
|
if (pEnc->bframenum_tail > 0) |
942 |
{ |
{ |
943 |
|
|
944 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
945 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
946 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
947 |
|
|
948 |
/* XXX: convert B-VOP to P-VOP */ |
/* convert B-VOP to P-VOP */ |
949 |
pEnc->current->quant *= 2; |
pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; |
950 |
|
|
951 |
|
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
952 |
|
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
953 |
|
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
954 |
|
} |
955 |
|
|
956 |
FrameCodeP(pEnc, &bs, 1, 0); |
FrameCodeP(pEnc, &bs, 1, 0); |
957 |
|
|
958 |
goto done_flush; |
goto done_flush; |
959 |
} |
} |
960 |
|
|
975 |
|
|
976 |
|
|
977 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
978 |
* init pEnc->current field |
* init pEnc->current fields |
979 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
980 |
|
|
|
emms(); /* float-point region */ |
|
981 |
|
|
982 |
|
pEnc->current->fincr = pEnc->mbParam.fincr>0 ? pEnc->mbParam.fincr : frame->fincr; |
983 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags; |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags; |
984 |
pEnc->current->vop_flags = frame->vop_flags; |
pEnc->current->vop_flags = frame->vop_flags; |
985 |
pEnc->current->motion_flags = frame->motion; |
pEnc->current->motion_flags = frame->motion; |
991 |
pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); |
pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); |
992 |
} |
} |
993 |
|
|
994 |
if (xFrame->vop_flags & XVID_EXTRASTATS) { |
emms(); /* float-point region */ |
|
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
|
|
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
|
|
} |
|
|
|
|
995 |
if ((pEnc->current->vop_flags & XVID_LUMIMASKING)) { |
if ((pEnc->current->vop_flags & XVID_LUMIMASKING)) { |
996 |
|
unsigned int x, y; |
997 |
|
|
998 |
pEnc->current->quant = |
pEnc->current->quant = |
999 |
adaptive_quantization(pEnc->current->image.y, |
adaptive_quantization(pEnc->current->image.y, |
1017 |
} |
} |
1018 |
|
|
1019 |
} |
} |
|
|
|
1020 |
emms(); /* END floating-point region */ |
emms(); /* END floating-point region */ |
1021 |
call_plugins(pEnc, pEnc->current, XVID_PLG_BEFORE, &type, &pEnc->current->quant); |
|
1022 |
emms(); |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1023 |
|
* frame type & quant selection |
1024 |
|
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1025 |
|
|
1026 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, &pEnc->current->quant, stats); |
1027 |
|
|
1028 |
if (frame->type > 0) |
if (frame->type > 0) |
1029 |
type = frame->type; |
type = frame->type; |
1031 |
if (frame->quant > 0) |
if (frame->quant > 0) |
1032 |
pEnc->current->quant = frame->quant; |
pEnc->current->quant = frame->quant; |
1033 |
|
|
1034 |
if (type > 0) /* XVID_TYPE_?VOP */ |
if (type > 0){ /* XVID_TYPE_?VOP */ |
|
{ |
|
1035 |
type = type2coding(type); /* convert XVID_TYPE_?VOP to bitstream coding type */ |
type = type2coding(type); /* convert XVID_TYPE_?VOP to bitstream coding type */ |
1036 |
} |
} else{ /* XVID_TYPE_AUTO */ |
1037 |
else /* XVID_TYPE_AUTO */ |
if (pEnc->iFrameNum == 0 || (pEnc->mbParam.iMaxKeyInterval > 0 && pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval)){ |
|
{ |
|
|
if (pEnc->iFrameNum == 0 || |
|
|
(pEnc->mbParam.iMaxKeyInterval > 0 && pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval)) |
|
|
{ |
|
1038 |
pEnc->iFrameNum = 0; |
pEnc->iFrameNum = 0; |
1039 |
type = I_VOP; |
type = I_VOP; |
1040 |
}else{ |
}else{ |
1041 |
type = MEanalysis(&pEnc->reference->image, pEnc->current, |
type = MEanalysis(&pEnc->reference->image, pEnc->current, |
1042 |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
1043 |
pEnc->iFrameNum, pEnc->bframenum_tail); |
pEnc->iFrameNum, pEnc->bframenum_tail); |
1044 |
|
|
1045 |
|
if (type == B_VOP && !(pEnc->current->vop_flags & XVID_DYNAMIC_BFRAMES)) { |
1046 |
|
type = P_VOP; /* disable dynamic bframes */ |
1047 |
|
} |
1048 |
} |
} |
1049 |
} |
} |
1050 |
|
|
1051 |
|
/* bframes buffer overflow check */ |
1052 |
|
if (type != I_VOP) { |
1053 |
|
if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { |
1054 |
|
type = P_VOP; |
1055 |
|
}else{ |
1056 |
|
type = B_VOP; |
1057 |
|
} |
1058 |
|
} |
1059 |
|
|
1060 |
inc_frame_num(pEnc); |
inc_frame_num(pEnc); |
1061 |
pEnc->iFrameNum++; |
pEnc->iFrameNum++; |
1062 |
|
|
|
|
|
1063 |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
1064 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, |
1065 |
"%i st:%i if:%i", pEnc->m_framenum, pEnc->current->stamp, pEnc->iFrameNum); |
"%i st:%i if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); |
1066 |
} |
} |
1067 |
|
|
1068 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1069 |
* ivop/pvop/bvop selection |
* encode this frame as a b-vop |
1070 |
|
* (we dont encode here, rather we store the frame in the bframes queue, to be encoded later) |
1071 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1072 |
|
if (type == B_VOP) { |
1073 |
|
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
1074 |
|
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP"); |
1075 |
|
} |
1076 |
|
|
1077 |
if (type == I_VOP) { |
if (frame->bquant < 1) { |
1078 |
|
pEnc->current->quant = ((((pEnc->reference->quant + pEnc->current->quant) * |
1079 |
|
pEnc->mbParam.bquant_ratio) / 2) + pEnc->mbParam.bquant_offset)/100; |
1080 |
|
|
1081 |
DPRINTF(DPRINTF_DEBUG,"*** IFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
} else { |
1082 |
|
pEnc->current->quant = frame->bquant; |
1083 |
|
} |
1084 |
|
|
1085 |
|
if (pEnc->current->quant < 1) |
1086 |
|
pEnc->current->quant = 1; |
1087 |
|
else if (pEnc->current->quant > 31) |
1088 |
|
pEnc->current->quant = 31; |
1089 |
|
|
1090 |
|
DPRINTF(DPRINTF_DEBUG,"*** BFRAME (store) bf: head=%i tail=%i queue: head=%i tail=%i size=%i quant=%i", |
1091 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1092 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant); |
1093 |
|
|
1094 |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
/* store frame into bframe buffer & swap ref back to current */ |
1095 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP"); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1096 |
|
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
1097 |
|
|
1098 |
|
pEnc->bframenum_tail++; |
1099 |
|
|
1100 |
|
goto repeat; |
1101 |
} |
} |
1102 |
|
|
1103 |
// when we reach an iframe in CLOSED_GOP mode, encode the last bframe as a xFrame |
/* for unpacked bframes, output the stats for the last encoded frame */ |
1104 |
if ((pEnc->mbParam.global_flags & XVID_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) |
1105 |
|
{ |
1106 |
|
if (pEnc->current->stamp > 0) { |
1107 |
|
call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1108 |
|
} |
1109 |
|
else |
1110 |
|
stats->type = XVID_TYPE_NOTHING; |
1111 |
|
} |
1112 |
|
|
1113 |
|
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1114 |
|
* closed-gop |
1115 |
|
* if the frame prior to an iframe is scheduled as a bframe, we must change it to a pframe |
1116 |
|
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1117 |
|
|
1118 |
|
if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
1119 |
|
|
1120 |
// place this frame back on the encoding-queue (head) |
// place this frame back on the encoding-queue (head) |
1121 |
// we will deal with it next time |
// we will deal with it next time |
1122 |
pEnc->queue_head = (pEnc->queue_head + (pEnc->mbParam.max_bframes+1) - 1) % (pEnc->mbParam.max_bframes+1); |
pEnc->queue_head = (pEnc->queue_head + (pEnc->mbParam.max_bframes+1) - 1) % (pEnc->mbParam.max_bframes+1); |
1123 |
|
pEnc->queue_size++; |
1124 |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
1125 |
|
|
1126 |
|
dec_frame_num(pEnc); |
1127 |
|
pEnc->iFrameNum--; |
1128 |
|
|
1129 |
// grab the last frame from the bframe-queue |
// grab the last frame from the bframe-queue |
1130 |
|
|
1131 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
1135 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP"); |
1136 |
} |
} |
1137 |
|
|
1138 |
/* XXX: convert B-VOP to P-VOP */ |
/* convert B-VOP quant to P-VOP */ |
1139 |
pEnc->current->quant *= 2; |
pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; |
1140 |
|
type = P_VOP; |
1141 |
|
} |
1142 |
|
|
|
FrameCodeP(pEnc, &bs, 1, 0); |
|
1143 |
|
|
1144 |
} else { |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1145 |
|
* encode this frame as an i-vop |
1146 |
|
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1147 |
|
|
1148 |
|
if (type == I_VOP) { |
1149 |
|
|
1150 |
|
DPRINTF(DPRINTF_DEBUG,"*** IFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
1151 |
|
pEnc->bframenum_head, pEnc->bframenum_tail, |
1152 |
|
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1153 |
|
|
1154 |
|
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
1155 |
|
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP"); |
1156 |
|
} |
1157 |
|
|
1158 |
|
|
1159 |
/* ---- update vol flags at IVOP ----------- */ |
/* ---- update vol flags at IVOP ----------- */ |
1160 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
1176 |
|
|
1177 |
/* ^^^------------------------ */ |
/* ^^^------------------------ */ |
1178 |
|
|
1179 |
|
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
1180 |
|
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
1181 |
|
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1182 |
|
} |
1183 |
|
|
1184 |
FrameCodeI(pEnc, &bs); |
FrameCodeI(pEnc, &bs); |
1185 |
xFrame->out_flags |= XVID_KEYFRAME; |
xFrame->out_flags |= XVID_KEYFRAME; |
|
} |
|
1186 |
|
|
1187 |
} else if (((pEnc->current->vop_flags & XVID_DYNAMIC_BFRAMES) && type == P_VOP) || |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1188 |
pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { |
* encode this frame as an p-vop |
1189 |
/* |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
|
* This will be coded as a Predicted Frame |
|
|
*/ |
|
1190 |
|
|
1191 |
DPRINTF(DPRINTF_DEBUG,"*** xFrame bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
} else { // (type == P_VOP || type == S_VOP) |
1192 |
|
|
1193 |
|
DPRINTF(DPRINTF_DEBUG,"*** PFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
1194 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1195 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1196 |
|
|
1198 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP"); |
1199 |
} |
} |
1200 |
|
|
1201 |
FrameCodeP(pEnc, &bs, 1, 0); |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
1202 |
|
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
1203 |
} else { /* type == B_VOP */ |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
|
|
|
|
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
|
|
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP"); |
|
|
} |
|
|
|
|
|
if (frame->bquant < 1) { |
|
|
pEnc->current->quant = ((((pEnc->reference->quant + pEnc->current->quant) * |
|
|
pEnc->mbParam.bquant_ratio) / 2) + pEnc->mbParam.bquant_offset)/100; |
|
|
|
|
|
} else { |
|
|
pEnc->current->quant = frame->bquant; |
|
1204 |
} |
} |
1205 |
|
|
1206 |
if (pEnc->current->quant < 1) |
FrameCodeP(pEnc, &bs, 1, 0); |
|
pEnc->current->quant = 1; |
|
|
else if (pEnc->current->quant > 31) |
|
|
pEnc->current->quant = 31; |
|
|
|
|
|
DPRINTF(DPRINTF_DEBUG,"*** BFRAME (store) bf: head=%i tail=%i queue: head=%i tail=%i size=%i quant=%i\n", |
|
|
pEnc->bframenum_head, pEnc->bframenum_tail, |
|
|
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant); |
|
|
|
|
|
/* store frame into bframe buffer & swap ref back to current */ |
|
|
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
|
|
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
|
|
|
|
|
pEnc->bframenum_tail++; |
|
|
|
|
|
goto repeat; |
|
|
|
|
1207 |
} |
} |
1208 |
|
|
|
if (xFrame->vop_flags & XVID_EXTRASTATS) { |
|
|
stats->sse_y = |
|
|
plane_sse( pEnc->sOriginal.y, pEnc->current->image.y, |
|
|
pEnc->mbParam.edged_width, pEnc->mbParam.width, |
|
|
pEnc->mbParam.height); |
|
|
|
|
|
stats->sse_u = |
|
|
plane_sse( pEnc->sOriginal.u, pEnc->current->image.u, |
|
|
pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2, |
|
|
pEnc->mbParam.height/2); |
|
|
|
|
|
stats->sse_v = |
|
|
plane_sse( pEnc->sOriginal.v, pEnc->current->image.v, |
|
|
pEnc->mbParam.edged_width/2, pEnc->mbParam.width/2, |
|
|
pEnc->mbParam.height/2); |
|
|
} |
|
1209 |
|
|
1210 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1211 |
* okay, on next enc_encode call we must flush bframes |
* on next enc_encode call we must flush bframes |
1212 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1213 |
|
|
1214 |
done_flush: |
done_flush: |
1215 |
|
|
|
#if 0 |
|
|
{ |
|
|
char tmp[100]; |
|
|
wsprintf(tmp,"\\frame%03i.pgm", pEnc->m_framenum); |
|
|
image_dump_yuvpgm(&pEnc->current->image, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.width, pEnc->mbParam.height, tmp); |
|
|
} |
|
|
#endif |
|
|
|
|
|
/* packed_mode: repeat */ |
|
1216 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1217 |
|
|
1218 |
|
/* packed & queued_bframes: dont bother outputting stats, we do so after the flush */ |
1219 |
if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) { |
if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) { |
1220 |
goto repeat; |
goto repeat; |
1221 |
} |
} |
1222 |
|
|
1223 |
if ((pEnc->mbParam.global_flags & XVID_PACKED) || pEnc->mbParam.max_bframes == 0) |
/* packed or no-bframes: output stats */ |
1224 |
{ |
if ((pEnc->mbParam.global_flags & XVID_PACKED) || pEnc->mbParam.max_bframes == 0) { |
1225 |
/* packed(and low_delay) encoding gives us graceful reorded-stats output */ |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
|
set_stats(stats, &pEnc->rate_control, &pEnc->mbParam, pEnc->current); |
|
|
emms(); |
|
|
call_plugins(pEnc, pEnc->current, XVID_PLG_AFTER, 0, 0); |
|
|
emms(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
/* outherwise, output the previous frame */ |
|
|
/* XXX: for this to work, refernce must be valid for IVOPs too */ |
|
|
if (pEnc->current->stamp > 0) { |
|
|
set_stats(stats, &pEnc->rate_control, &pEnc->mbParam, pEnc->reference); |
|
|
emms(); |
|
|
call_plugins(pEnc, pEnc->current, XVID_PLG_AFTER, 0, 0); |
|
|
emms(); |
|
|
} |
|
|
else |
|
|
stats->type = XVID_TYPE_NOTHING; |
|
1226 |
} |
} |
1227 |
|
|
1228 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1296 |
stop_edges_timer(); |
stop_edges_timer(); |
1297 |
} |
} |
1298 |
|
|
|
//pEnc->iFrameNum = 0; |
|
1299 |
pEnc->mbParam.m_rounding_type = 1; |
pEnc->mbParam.m_rounding_type = 1; |
1300 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
|
//pEnc->current->quarterpel = pEnc->mbParam.m_quarterpel; |
|
1301 |
pEnc->current->coding_type = I_VOP; |
pEnc->current->coding_type = I_VOP; |
1302 |
|
|
1303 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |