diff options
Diffstat (limited to 'libhb/encavcodec.c')
-rw-r--r-- | libhb/encavcodec.c | 96 |
1 files changed, 26 insertions, 70 deletions
diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index 5063e43f1..134dbcc6b 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -32,8 +32,7 @@ struct hb_work_private_s int frameno_in; int frameno_out; - hb_buffer_t * delay_head; - hb_buffer_t * delay_tail; + hb_buffer_list_t delay_list; int64_t dts_delay; @@ -66,6 +65,8 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) w->private_data = pv; pv->job = job; + hb_buffer_list_clear(&pv->delay_list); + int clock_min, clock_max, clock; hb_video_framerate_get_limits(&clock_min, &clock_max, &clock); @@ -435,27 +436,20 @@ static uint8_t convert_pict_type( int pict_type, char pkt_flag_key, uint16_t* sf // This is similar to how x264 generates DTS static hb_buffer_t * process_delay_list( hb_work_private_t * pv, hb_buffer_t * buf ) { - if ( pv->job->areBframes ) + if (pv->job->areBframes) { // Has dts_delay been set yet? - if ( pv->frameno_in <= pv->job->areBframes ) + hb_buffer_list_append(&pv->delay_list, buf); + if (pv->frameno_in <= pv->job->areBframes) { // dts_delay not yet set. queue up buffers till it is set. - if ( pv->delay_tail == NULL ) - { - pv->delay_head = pv->delay_tail = buf; - } - else - { - pv->delay_tail->next = buf; - pv->delay_tail = buf; - } return NULL; } // We have dts_delay. Apply it to any queued buffers renderOffset // and return all queued buffers. - if ( pv->delay_tail == NULL && buf != NULL ) + buf = hb_buffer_list_head(&pv->delay_list); + while (buf != NULL) { // Use the cached frame info to get the start time of Nth frame // Note that start Nth frame != start time this buffer since the @@ -467,40 +461,16 @@ static hb_buffer_t * process_delay_list( hb_work_private_t * pv, hb_buffer_t * b } else { - buf->s.renderOffset = - get_frame_start(pv, pv->frameno_out - pv->job->areBframes); - } - pv->frameno_out++; - return buf; - } - else - { - pv->delay_tail->next = buf; - buf = pv->delay_head; - while ( buf ) - { - // Use the cached frame info to get the start time of Nth frame - // Note that start Nth frame != start time this buffer since the - // output buffers have rearranged start times. - if (pv->frameno_out < pv->job->areBframes) - { - int64_t start = get_frame_start( pv, pv->frameno_out ); - buf->s.renderOffset = start - pv->dts_delay; - } - else - { - buf->s.renderOffset = get_frame_start(pv, + buf->s.renderOffset = get_frame_start(pv, pv->frameno_out - pv->job->areBframes); - } - buf = buf->next; - pv->frameno_out++; } - buf = pv->delay_head; - pv->delay_head = pv->delay_tail = NULL; - return buf; + buf = buf->next; + pv->frameno_out++; } + buf = hb_buffer_list_clear(&pv->delay_list); + return buf; } - else if ( buf ) + else if (buf != NULL) { buf->s.renderOffset = buf->s.start; return buf; @@ -520,12 +490,15 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_job_t * job = pv->job; AVFrame * frame; hb_buffer_t * in = *buf_in, * buf; + hb_buffer_list_t list; char final_flushing_call = !!(in->s.flags & HB_BUF_FLAG_EOF); - if ( final_flushing_call ) + + hb_buffer_list_clear(&list); + if (final_flushing_call) { - //make a flushing call to encode for codecs that can encode out of order /* EOF on input - send it downstream & say we're done */ - *buf_in = NULL; + // make a flushing call to encode for codecs that can encode + // out of order frame = NULL; } else @@ -560,9 +533,6 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in, AVPacket pkt; int got_packet; char still_flushing = final_flushing_call; - hb_buffer_t* buf_head = NULL; - hb_buffer_t* buf_last = NULL; - do { av_init_packet(&pkt); @@ -588,15 +558,7 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in, buf->s.frametype = convert_pict_type( pv->context->coded_frame->pict_type, pkt.flags & AV_PKT_FLAG_KEY, &buf->s.flags ); buf = process_delay_list( pv, buf ); - if (buf_head == NULL) - { - buf_head = buf; - } - else - { - buf_last->next = buf; - } - buf_last = buf; + hb_buffer_list_append(&list, buf); } /* Write stats */ if (job->pass_id == HB_PASS_ENCODE_1ST && @@ -605,27 +567,21 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in, fprintf( pv->file, "%s", pv->context->stats_out ); } } while (still_flushing); - if (buf_last != NULL && final_flushing_call) - { - buf_last->next = in; - buf = buf_head; - } - else if (final_flushing_call) + + if (final_flushing_call) { - buf = in; + *buf_in = NULL; + hb_buffer_list_append(&list, in); } } else { - buf = NULL; - hb_error( "encavcodec: codec context has uninitialized codec; skipping frame" ); } av_frame_free( &frame ); - *buf_out = buf; - + *buf_out = hb_buffer_list_clear(&list); return final_flushing_call? HB_WORK_DONE : HB_WORK_OK; } |