|
|
|
@ -41,62 +41,63 @@ void pic_pacer_Init(struct pic_pacer *pic_pacer) |
|
|
|
{ |
|
|
|
vlc_mutex_init(&pic_pacer->lock); |
|
|
|
vlc_cond_init(&pic_pacer->wait); |
|
|
|
pic_pacer->nb_out = 0; |
|
|
|
pic_pacer->allocated_max = 6; |
|
|
|
pic_pacer->allocated_next = pic_pacer->allocated_max; |
|
|
|
pic_pacer->queued_for_decode = 0; |
|
|
|
pic_pacer->nb_fields_out = 0; |
|
|
|
pic_pacer->allocated_fields_max = 6 /* pics */ * 2; |
|
|
|
pic_pacer->allocated_fields_next = pic_pacer->allocated_fields_max; |
|
|
|
pic_pacer->queued_fields_for_decode = 0; |
|
|
|
} |
|
|
|
|
|
|
|
void pic_pacer_AccountAllocation(struct pic_pacer *pic_pacer) |
|
|
|
void pic_pacer_AccountAllocation(struct pic_pacer *pic_pacer, bool b_field) |
|
|
|
{ |
|
|
|
vlc_mutex_lock(&pic_pacer->lock); |
|
|
|
pic_pacer->nb_out += 1; |
|
|
|
pic_pacer->nb_fields_out += b_field ? 1 : 2; |
|
|
|
vlc_mutex_unlock(&pic_pacer->lock); |
|
|
|
} |
|
|
|
|
|
|
|
void pic_pacer_AccountScheduledDecode(struct pic_pacer *pic_pacer) |
|
|
|
void pic_pacer_AccountScheduledDecode(struct pic_pacer *pic_pacer, bool b_field) |
|
|
|
{ |
|
|
|
vlc_mutex_lock(&pic_pacer->lock); |
|
|
|
pic_pacer->queued_for_decode += 1; |
|
|
|
pic_pacer->queued_fields_for_decode += b_field ? 1 : 2; |
|
|
|
vlc_mutex_unlock(&pic_pacer->lock); |
|
|
|
} |
|
|
|
|
|
|
|
void pic_pacer_AccountFinishedDecode(struct pic_pacer *pic_pacer) |
|
|
|
void pic_pacer_AccountFinishedDecode(struct pic_pacer *pic_pacer, bool b_field) |
|
|
|
{ |
|
|
|
vlc_mutex_lock(&pic_pacer->lock); |
|
|
|
pic_pacer->queued_for_decode -= 1; |
|
|
|
pic_pacer->queued_fields_for_decode -= b_field ? 1 : 2; |
|
|
|
vlc_cond_signal(&pic_pacer->wait); |
|
|
|
vlc_mutex_unlock(&pic_pacer->lock); |
|
|
|
} |
|
|
|
|
|
|
|
void pic_pacer_WaitAllocatableSlot(struct pic_pacer *pic_pacer) |
|
|
|
void pic_pacer_WaitAllocatableSlot(struct pic_pacer *pic_pacer, bool b_field) |
|
|
|
{ |
|
|
|
vlc_mutex_lock(&pic_pacer->lock); |
|
|
|
uint8_t allocatable_total = pic_pacer->allocated_max + PIC_PACER_DECODE_QUEUE; |
|
|
|
uint8_t allocatable_fields_total = pic_pacer->allocated_fields_max + PIC_PACER_DECODE_QUEUE; |
|
|
|
|
|
|
|
while( pic_pacer->queued_for_decode + pic_pacer->nb_out >= allocatable_total ) |
|
|
|
while( pic_pacer->queued_fields_for_decode + |
|
|
|
pic_pacer->nb_fields_out + (1 - !!b_field) >= allocatable_fields_total ) |
|
|
|
{ |
|
|
|
#ifdef PIC_PACER_DEBUG |
|
|
|
fprintf(stderr, "input pacing %d+%d >= %d\n", |
|
|
|
pic_pacer->queued_for_decode, pic_pacer->nb_out, allocatable_total); |
|
|
|
pic_pacer->queued_fields_for_decode, pic_pacer->nb_fields_out, allocatable_fields_total); |
|
|
|
#endif |
|
|
|
vlc_cond_wait(&pic_pacer->wait, &pic_pacer->lock); |
|
|
|
/*update*/ |
|
|
|
allocatable_total = pic_pacer->allocated_max + PIC_PACER_DECODE_QUEUE; |
|
|
|
allocatable_fields_total = pic_pacer->allocated_fields_max + PIC_PACER_DECODE_QUEUE; |
|
|
|
} |
|
|
|
vlc_mutex_unlock(&pic_pacer->lock); |
|
|
|
} |
|
|
|
|
|
|
|
void pic_pacer_AccountDeallocation(struct pic_pacer *pic_pacer) |
|
|
|
void pic_pacer_AccountDeallocation(struct pic_pacer *pic_pacer, bool b_field) |
|
|
|
{ |
|
|
|
vlc_mutex_lock(&pic_pacer->lock); |
|
|
|
assert(pic_pacer->nb_out > 0); |
|
|
|
pic_pacer->nb_out -= 1; |
|
|
|
assert(pic_pacer->nb_fields_out > 0); |
|
|
|
pic_pacer->nb_fields_out -= (b_field ? 1 : 2); |
|
|
|
|
|
|
|
/* our shrink condition */ |
|
|
|
if(pic_pacer->allocated_next < pic_pacer->allocated_max && |
|
|
|
pic_pacer->nb_out <= pic_pacer->allocated_next) |
|
|
|
pic_pacer->allocated_max = pic_pacer->allocated_next; |
|
|
|
if(pic_pacer->allocated_fields_next < pic_pacer->allocated_fields_max && |
|
|
|
pic_pacer->nb_fields_out <= pic_pacer->allocated_fields_next) |
|
|
|
pic_pacer->allocated_fields_max = pic_pacer->allocated_fields_next; |
|
|
|
|
|
|
|
vlc_cond_signal(&pic_pacer->wait); |
|
|
|
|
|
|
|
@ -107,21 +108,21 @@ void pic_pacer_UpdateMaxBuffering(struct pic_pacer *pic_pacer, uint8_t pic_max) |
|
|
|
{ |
|
|
|
vlc_mutex_lock(&pic_pacer->lock); |
|
|
|
|
|
|
|
pic_max += PIC_PACER_ALLOCATABLE_MAX; |
|
|
|
bool b_growing = pic_max > pic_pacer->allocated_max; |
|
|
|
const uint8_t fields_max = (pic_max + PIC_PACER_ALLOCATABLE_MAX) * 2; |
|
|
|
bool b_growing = fields_max > pic_pacer->allocated_fields_max; |
|
|
|
#ifdef PIC_PACER_DEBUG |
|
|
|
fprintf(stderr, "updating pacer max %d/%d to %d\n", |
|
|
|
pic_pacer->nb_out, pic_pacer->allocated_max, pic_reorder_max); |
|
|
|
pic_pacer->nb_fields_out, pic_pacer->allocated_fields_max / 2, pic_max); |
|
|
|
#endif |
|
|
|
if(b_growing) |
|
|
|
{ |
|
|
|
pic_pacer->allocated_max = pic_max; |
|
|
|
pic_pacer->allocated_next = pic_max; |
|
|
|
pic_pacer->allocated_fields_max = fields_max; |
|
|
|
pic_pacer->allocated_fields_next = fields_max; |
|
|
|
vlc_cond_signal(&pic_pacer->wait); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
pic_pacer->allocated_next = pic_max; |
|
|
|
pic_pacer->allocated_fields_next = fields_max; |
|
|
|
} |
|
|
|
|
|
|
|
vlc_mutex_unlock(&pic_pacer->lock); |
|
|
|
|