| 641 | } |
| 642 | |
| 643 | static av_cold int omx_encode_init(AVCodecContext *avctx) |
| 644 | { |
| 645 | OMXCodecContext *s = avctx->priv_data; |
| 646 | int ret = AVERROR_ENCODER_NOT_FOUND; |
| 647 | const char *role; |
| 648 | OMX_BUFFERHEADERTYPE *buffer; |
| 649 | OMX_ERRORTYPE err; |
| 650 | |
| 651 | av_log(avctx, AV_LOG_WARNING, |
| 652 | "The %s encoder is deprecated and will be removed in future versions\n", |
| 653 | avctx->codec->name); |
| 654 | |
| 655 | /* cleanup relies on the mutexes/conditions being initialized first. */ |
| 656 | ret = ff_pthread_init(s, omx_codec_context_offsets); |
| 657 | if (ret < 0) |
| 658 | return ret; |
| 659 | s->omx_context = omx_init(avctx, s->libname, s->libprefix); |
| 660 | if (!s->omx_context) |
| 661 | return AVERROR_ENCODER_NOT_FOUND; |
| 662 | |
| 663 | s->avctx = avctx; |
| 664 | s->state = OMX_StateLoaded; |
| 665 | s->error = OMX_ErrorNone; |
| 666 | |
| 667 | switch (avctx->codec->id) { |
| 668 | case AV_CODEC_ID_MPEG4: |
| 669 | role = "video_encoder.mpeg4"; |
| 670 | break; |
| 671 | case AV_CODEC_ID_H264: |
| 672 | role = "video_encoder.avc"; |
| 673 | break; |
| 674 | default: |
| 675 | return AVERROR(ENOSYS); |
| 676 | } |
| 677 | |
| 678 | if ((ret = find_component(s->omx_context, avctx, role, s->component_name, sizeof(s->component_name))) < 0) |
| 679 | goto fail; |
| 680 | |
| 681 | av_log(avctx, AV_LOG_INFO, "Using %s\n", s->component_name); |
| 682 | |
| 683 | if ((ret = omx_component_init(avctx, role)) < 0) |
| 684 | goto fail; |
| 685 | |
| 686 | if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { |
| 687 | while (1) { |
| 688 | buffer = get_buffer(&s->output_mutex, &s->output_cond, |
| 689 | &s->num_done_out_buffers, s->done_out_buffers, 1); |
| 690 | if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { |
| 691 | if (buffer->nFilledLen > INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE - avctx->extradata_size) { |
| 692 | ret = AVERROR(ENOMEM); |
| 693 | goto fail; |
| 694 | } |
| 695 | |
| 696 | if ((ret = av_reallocp(&avctx->extradata, avctx->extradata_size + buffer->nFilledLen + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) { |
| 697 | avctx->extradata_size = 0; |
| 698 | goto fail; |
| 699 | } |
| 700 | memcpy(avctx->extradata + avctx->extradata_size, buffer->pBuffer + buffer->nOffset, buffer->nFilledLen); |
nothing calls this directly
no test coverage detected