| 473 | } |
| 474 | |
| 475 | static void Encode(hb_work_object_t *w, hb_buffer_list_t *list) |
| 476 | { |
| 477 | hb_work_private_t * pv = w->private_data; |
| 478 | hb_audio_t * audio = w->audio; |
| 479 | uint64_t pts, pos; |
| 480 | |
| 481 | while (hb_list_bytes(pv->list) >= pv->input_samples * sizeof(float)) |
| 482 | { |
| 483 | int ret; |
| 484 | |
| 485 | hb_list_getbytes(pv->list, (uint8_t *)pv->input_buf, |
| 486 | pv->input_samples * sizeof(float), &pts, &pos); |
| 487 | |
| 488 | // Prepare input frame |
| 489 | int out_size; |
| 490 | AVFrame frame = { .nb_samples = pv->samples_per_frame, |
| 491 | .format = pv->context->sample_fmt, |
| 492 | .ch_layout = pv->context->ch_layout |
| 493 | }; |
| 494 | |
| 495 | out_size = av_samples_get_buffer_size(NULL, |
| 496 | pv->context->ch_layout.nb_channels, |
| 497 | pv->samples_per_frame, |
| 498 | pv->context->sample_fmt, 1); |
| 499 | avcodec_fill_audio_frame(&frame, |
| 500 | pv->context->ch_layout.nb_channels, pv->context->sample_fmt, |
| 501 | (uint8_t *)pv->output_buf, out_size, 1); |
| 502 | if (pv->swresample != NULL) |
| 503 | { |
| 504 | int out_samples; |
| 505 | |
| 506 | out_samples = swr_convert(pv->swresample, |
| 507 | frame.extended_data, frame.nb_samples, |
| 508 | (const uint8_t **)&pv->input_buf, frame.nb_samples); |
| 509 | if (out_samples != pv->samples_per_frame) |
| 510 | { |
| 511 | // we're not doing sample rate conversion, |
| 512 | // so this shouldn't happen |
| 513 | hb_log("encavcodecaWork: swr_convert() failed"); |
| 514 | continue; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | frame.pts = pts + (90000LL * pos / (sizeof(float) * |
| 519 | pv->out_discrete_channels * |
| 520 | audio->config.out.samplerate)); |
| 521 | |
| 522 | frame.pts = av_rescale_q(frame.pts, (AVRational){1, 90000}, |
| 523 | pv->context->time_base); |
| 524 | |
| 525 | // Encode |
| 526 | ret = avcodec_send_frame(pv->context, &frame); |
| 527 | if (ret < 0) |
| 528 | { |
| 529 | hb_log("encavcodecaudio: avcodec_send_frame failed"); |
| 530 | return; |
| 531 | } |
| 532 | get_packets(w, list); |
no test coverage detected