diff options
author | John Stebbins <[email protected]> | 2016-05-25 09:40:34 -0600 |
---|---|---|
committer | John Stebbins <[email protected]> | 2016-05-25 09:41:27 -0600 |
commit | 9dabe455a7b9f4917c1f36c3229c8fb9914a3fc4 (patch) | |
tree | e11bf8164e9db8a266a2c05c7e7a5fd4a408e929 | |
parent | a8aec0058298b75b59559c0bebd659852d7b32d9 (diff) |
encx265: simplify chapter mark handling
Use hb_chapter_enqueue/dequeue
-rw-r--r-- | libhb/common.c | 2 | ||||
-rw-r--r-- | libhb/encx265.c | 101 |
2 files changed, 24 insertions, 79 deletions
diff --git a/libhb/common.c b/libhb/common.c index 0310eeeac..32e0bc49a 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -5412,6 +5412,8 @@ void hb_chapter_enqueue(hb_chapter_queue_t *q, hb_buffer_t *buf) { item->start = buf->s.start; item->new_chap = buf->s.new_chap; + // Make sure work_loop doesn't also copy the chapter mark + buf->s.new_chap = 0; hb_list_add(q->list_chapter, item); } } diff --git a/libhb/encx265.c b/libhb/encx265.c index 7cda7b71b..aab791a9a 100644 --- a/libhb/encx265.c +++ b/libhb/encx265.c @@ -39,33 +39,24 @@ static const char * const hb_x265_encopt_synonyms[][2] = struct hb_work_private_s { - hb_job_t *job; - x265_encoder *x265; - x265_param *param; + hb_job_t * job; + x265_encoder * x265; + x265_param * param; - int64_t last_stop; - uint32_t frames_in; + int64_t last_stop; + uint32_t frames_in; - hb_list_t *delayed_chapters; - int64_t next_chapter_pts; + hb_chapter_queue_t * chapter_queue; struct { - int64_t duration; - } - frame_info[FRAME_INFO_SIZE]; + int64_t duration; + } frame_info[FRAME_INFO_SIZE]; - char csvfn[1024]; + char csvfn[1024]; // Multiple bit-depth - const x265_api *api; -}; - -// used in delayed_chapters list -struct chapter_s -{ - int index; - int64_t start; + const x265_api * api; }; static int param_parse(hb_work_private_t *pv, x265_param *param, @@ -101,9 +92,8 @@ int encx265Init(hb_work_object_t *w, hb_job_t *job) uint32_t nnal; const char * const *profile_names; - pv->next_chapter_pts = AV_NOPTS_VALUE; - pv->delayed_chapters = hb_list_init(); pv->job = job; + pv->chapter_queue = hb_chapter_queue_init(); w->private_data = pv; depth = hb_video_encoder_get_depth(job->vcodec); @@ -347,17 +337,11 @@ void encx265Close(hb_work_object_t *w) { hb_work_private_t *pv = w->private_data; - if (pv == NULL) return; - if (pv->delayed_chapters != NULL) + if (pv == NULL) { - struct chapter_s *item; - while ((item = hb_list_item(pv->delayed_chapters, 0)) != NULL) - { - hb_list_rem(pv->delayed_chapters, item); - free(item); - } - hb_list_close(&pv->delayed_chapters); + return; } + hb_chapter_queue_close(&pv->chapter_queue); pv->api->param_free(pv->param); pv->api->encoder_close(pv->x265); @@ -440,31 +424,9 @@ static hb_buffer_t* nal_encode(hb_work_object_t *w, break; } - if (pv->next_chapter_pts != AV_NOPTS_VALUE && - pv->next_chapter_pts <= pic_out->pts && - pic_out->sliceType == X265_TYPE_IDR) + if (pic_out->sliceType == X265_TYPE_IDR) { - // we're no longer looking for this chapter - pv->next_chapter_pts = AV_NOPTS_VALUE; - - // get the chapter index from the list - struct chapter_s *item = hb_list_item(pv->delayed_chapters, 0); - if (item != NULL) - { - // we're done with this chapter - hb_list_rem(pv->delayed_chapters, item); - buf->s.new_chap = item->index; - free(item); - - // we may still have another pending chapter - item = hb_list_item(pv->delayed_chapters, 0); - if (item != NULL) - { - // we're looking for this one now - // we still need it, don't remove it - pv->next_chapter_pts = item->start; - } - } + hb_chapter_dequeue(pv->chapter_queue, buf); } // discard empty buffers (no video) @@ -497,34 +459,15 @@ static hb_buffer_t* x265_encode(hb_work_object_t *w, hb_buffer_t *in) if (in->s.new_chap && job->chapter_markers) { - if (pv->next_chapter_pts == AV_NOPTS_VALUE) - { - pv->next_chapter_pts = in->s.start; - } - /* - * Chapter markers are sometimes so close we can get a new one before - * the previous marker has been through the encoding queue. - * - * Dropping markers can cause weird side-effects downstream, including - * but not limited to missing chapters in the output, so we need to save - * it somehow. - */ - struct chapter_s *item = malloc(sizeof(struct chapter_s)); - if (item != NULL) - { - item->start = in->s.start; - item->index = in->s.new_chap; - hb_list_add(pv->delayed_chapters, item); - } - /* don't let 'work_loop' put a chapter mark on the wrong buffer */ - in->s.new_chap = 0; /* - * Chapters have to start with an IDR frame so request that this frame be - * coded as IDR. Since there may be up to 16 frames currently buffered in - * the encoder, remember the timestamp so when this frame finally pops out - * of the encoder we'll mark its buffer as the start of a chapter. + * Chapters have to start with an IDR frame so request that this + * frame be coded as IDR. Since there may be up to 16 frames + * currently buffered in the encoder, remember the timestamp so + * when this frame finally pops out of the encoder we'll mark + * its buffer as the start of a chapter. */ pic_in.sliceType = X265_TYPE_IDR; + hb_chapter_enqueue(pv->chapter_queue, in); } else { |