MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / omx_encode_frame

Function omx_encode_frame

libavcodec/omx.c:741–916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

739
740
741static int omx_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
742 const AVFrame *frame, int *got_packet)
743{
744 OMXCodecContext *s = avctx->priv_data;
745 int ret = 0;
746 OMX_BUFFERHEADERTYPE* buffer;
747 OMX_ERRORTYPE err;
748 int had_partial = 0;
749
750 if (frame) {
751 uint8_t *dst[4];
752 int linesize[4];
753 int need_copy;
754 buffer = get_buffer(&s->input_mutex, &s->input_cond,
755 &s->num_free_in_buffers, s->free_in_buffers, 1);
756
757 buffer->nFilledLen = av_image_fill_arrays(dst, linesize, buffer->pBuffer, avctx->pix_fmt, s->stride, s->plane_size, 1);
758
759 if (s->input_zerocopy) {
760 uint8_t *src[4] = { NULL };
761 int src_linesize[4];
762 av_image_fill_arrays(src, src_linesize, frame->data[0], avctx->pix_fmt, s->stride, s->plane_size, 1);
763 if (frame->linesize[0] == src_linesize[0] &&
764 frame->linesize[1] == src_linesize[1] &&
765 frame->linesize[2] == src_linesize[2] &&
766 frame->data[1] == src[1] &&
767 frame->data[2] == src[2]) {
768 // If the input frame happens to have all planes stored contiguously,
769 // with the right strides, just clone the frame and set the OMX
770 // buffer header to point to it
771 AVFrame *local = av_frame_clone(frame);
772 if (!local) {
773 // Return the buffer to the queue so it's not lost
774 append_buffer(&s->input_mutex, &s->input_cond, &s->num_free_in_buffers, s->free_in_buffers, buffer);
775 return AVERROR(ENOMEM);
776 } else {
777 buffer->pAppPrivate = local;
778 buffer->pOutputPortPrivate = NULL;
779 buffer->pBuffer = local->data[0];
780 need_copy = 0;
781 }
782 } else {
783 // If not, we need to allocate a new buffer with the right
784 // size and copy the input frame into it.
785 uint8_t *buf = NULL;
786 int image_buffer_size = av_image_get_buffer_size(avctx->pix_fmt, s->stride, s->plane_size, 1);
787 if (image_buffer_size >= 0)
788 buf = av_malloc(image_buffer_size);
789 if (!buf) {
790 // Return the buffer to the queue so it's not lost
791 append_buffer(&s->input_mutex, &s->input_cond, &s->num_free_in_buffers, s->free_in_buffers, buffer);
792 return AVERROR(ENOMEM);
793 } else {
794 buffer->pAppPrivate = buf;
795 // Mark that pAppPrivate is an av_malloc'ed buffer, not an AVFrame
796 buffer->pOutputPortPrivate = (void*) 1;
797 buffer->pBuffer = buf;
798 need_copy = 1;

Callers

nothing calls this directly

Calls 14

av_image_fill_arraysFunction · 0.85
av_frame_cloneFunction · 0.85
append_bufferFunction · 0.85
av_image_get_buffer_sizeFunction · 0.85
av_image_copy2Function · 0.85
to_omx_ticksFunction · 0.85
av_rescale_qFunction · 0.85
av_logFunction · 0.85
av_reallocpFunction · 0.85
av_packet_from_dataFunction · 0.85
av_freepFunction · 0.85
from_omx_ticksFunction · 0.85

Tested by

no test coverage detected