| 539 | } |
| 540 | |
| 541 | static int receive(hb_work_object_t *w, hb_buffer_t **out, int done) |
| 542 | { |
| 543 | hb_work_private_t *pv = w->private_data; |
| 544 | EbBufferHeaderType *headerPtr; |
| 545 | EbErrorType svt_ret; |
| 546 | hb_buffer_t *buf; |
| 547 | |
| 548 | svt_ret = svt_av1_enc_get_packet(pv->svt_handle, &headerPtr, done); |
| 549 | if (svt_ret == EB_NoErrorEmptyQueue) |
| 550 | { |
| 551 | *out = NULL; |
| 552 | return 1; |
| 553 | } |
| 554 | |
| 555 | if (headerPtr->flags & EB_BUFFERFLAG_EOS) |
| 556 | { |
| 557 | svt_av1_enc_release_out_buffer(&headerPtr); |
| 558 | *out = NULL; |
| 559 | return 2; |
| 560 | } |
| 561 | |
| 562 | buf = hb_buffer_init(headerPtr->n_filled_len); |
| 563 | if (buf == NULL) |
| 564 | { |
| 565 | hb_error("encsvtav1: failed to allocate output packet"); |
| 566 | svt_av1_enc_release_out_buffer(&headerPtr); |
| 567 | *out = NULL; |
| 568 | return 2; |
| 569 | } |
| 570 | |
| 571 | memcpy(buf->data, headerPtr->p_buffer, headerPtr->n_filled_len); |
| 572 | |
| 573 | buf->size = headerPtr->n_filled_len; |
| 574 | buf->s.start = headerPtr->pts; |
| 575 | buf->s.duration = get_frame_duration(pv); |
| 576 | buf->s.stop = buf->s.start + buf->s.duration; |
| 577 | buf->s.renderOffset = headerPtr->dts; |
| 578 | |
| 579 | // SVT-AV1 doesn't always respect forced keyframes, |
| 580 | // so always check for chapters |
| 581 | hb_chapter_dequeue(pv->chapter_queue, buf); |
| 582 | |
| 583 | switch (headerPtr->pic_type) |
| 584 | { |
| 585 | case EB_AV1_KEY_PICTURE: |
| 586 | buf->s.flags |= HB_FLAG_FRAMETYPE_KEY; |
| 587 | // fall-through |
| 588 | case EB_AV1_INTRA_ONLY_PICTURE: |
| 589 | buf->s.frametype = HB_FRAME_IDR; |
| 590 | break; |
| 591 | default: |
| 592 | buf->s.frametype = HB_FRAME_P; |
| 593 | break; |
| 594 | } |
| 595 | |
| 596 | buf->s.flags |= HB_FLAG_FRAMETYPE_REF; |
| 597 | |
| 598 | svt_av1_enc_release_out_buffer(&headerPtr); |
no test coverage detected