FFmpeg
Macros | Enumerations | Functions | Variables
mediacodecdec_common.c File Reference
#include <string.h>
#include <sys/types.h>
#include "libavutil/common.h"
#include "libavutil/hwcontext_mediacodec.h"
#include "libavutil/mem.h"
#include "libavutil/log.h"
#include "libavutil/pixfmt.h"
#include "libavutil/time.h"
#include "libavutil/timestamp.h"
#include "avcodec.h"
#include "internal.h"
#include "mediacodec.h"
#include "mediacodec_surface.h"
#include "mediacodec_sw_buffer.h"
#include "mediacodec_wrapper.h"
#include "mediacodecdec_common.h"

Go to the source code of this file.

Macros

#define INPUT_DEQUEUE_TIMEOUT_US   8000
 OMX.k3.video.decoder.avc, OMX.NVIDIA. More...
 
#define OUTPUT_DEQUEUE_TIMEOUT_US   8000
 
#define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US   1000000
 
#define AMEDIAFORMAT_GET_INT32(name, key, mandatory)
 

Enumerations

enum  { COLOR_RANGE_FULL = 0x1, COLOR_RANGE_LIMITED = 0x2 }
 
enum  { COLOR_STANDARD_BT709 = 0x1, COLOR_STANDARD_BT601_PAL = 0x2, COLOR_STANDARD_BT601_NTSC = 0x4, COLOR_STANDARD_BT2020 = 0x6 }
 
enum  { COLOR_TRANSFER_LINEAR = 0x1, COLOR_TRANSFER_SDR_VIDEO = 0x3, COLOR_TRANSFER_ST2084 = 0x6, COLOR_TRANSFER_HLG = 0x7 }
 
enum  {
  COLOR_FormatYUV420Planar = 0x13, COLOR_FormatYUV420SemiPlanar = 0x15, COLOR_FormatYCbYCr = 0x19, COLOR_FormatAndroidOpaque = 0x7F000789,
  COLOR_QCOM_FormatYUV420SemiPlanar = 0x7fa30c00, COLOR_QCOM_FormatYUV420SemiPlanar32m = 0x7fa30c04, COLOR_QCOM_FormatYUV420PackedSemiPlanar64x32Tile2m8ka = 0x7fa30c03, COLOR_TI_FormatYUV420PackedSemiPlanar = 0x7f000100,
  COLOR_TI_FormatYUV420PackedSemiPlanarInterlaced = 0x7f000001
}
 

Functions

static enum AVColorRange mcdec_get_color_range (int color_range)
 
static enum AVColorSpace mcdec_get_color_space (int color_standard)
 
static enum AVColorPrimaries mcdec_get_color_pri (int color_standard)
 
static enum AVColorTransferCharacteristic mcdec_get_color_trc (int color_transfer)
 
static enum AVPixelFormat mcdec_map_color_format (AVCodecContext *avctx, MediaCodecDecContext *s, int color_format)
 
static void ff_mediacodec_dec_ref (MediaCodecDecContext *s)
 
static void ff_mediacodec_dec_unref (MediaCodecDecContext *s)
 
static void mediacodec_buffer_release (void *opaque, uint8_t *data)
 
static int mediacodec_wrap_hw_buffer (AVCodecContext *avctx, MediaCodecDecContext *s, ssize_t index, FFAMediaCodecBufferInfo *info, AVFrame *frame)
 
static int mediacodec_wrap_sw_buffer (AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, ssize_t index, FFAMediaCodecBufferInfo *info, AVFrame *frame)
 
static int mediacodec_dec_parse_format (AVCodecContext *avctx, MediaCodecDecContext *s)
 
static int mediacodec_dec_flush_codec (AVCodecContext *avctx, MediaCodecDecContext *s)
 
int ff_mediacodec_dec_init (AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
 
int ff_mediacodec_dec_send (AVCodecContext *avctx, MediaCodecDecContext *s, AVPacket *pkt, bool wait)
 
int ff_mediacodec_dec_receive (AVCodecContext *avctx, MediaCodecDecContext *s, AVFrame *frame, bool wait)
 
int ff_mediacodec_dec_flush (AVCodecContext *avctx, MediaCodecDecContext *s)
 
int ff_mediacodec_dec_close (AVCodecContext *avctx, MediaCodecDecContext *s)
 
int ff_mediacodec_dec_is_flushing (AVCodecContext *avctx, MediaCodecDecContext *s)
 

Variables

struct {
   int   color_format
 
   enum AVPixelFormat   pix_fmt
 
color_formats []
 

Macro Definition Documentation

◆ INPUT_DEQUEUE_TIMEOUT_US

#define INPUT_DEQUEUE_TIMEOUT_US   8000

OMX.k3.video.decoder.avc, OMX.NVIDIA.

  • OMX.SEC.avc.dec and OMX.google codec workarounds used in various place are taken from the Gstreamer project.

Gstreamer references: https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/sys/androidmedia/

Gstreamer copyright notice:

Copyright (C) 2012, Collabora Ltd. Author: Sebastian Dröge sebas.nosp@m.tian.nosp@m..droe.nosp@m.ge@c.nosp@m.ollab.nosp@m.ora..nosp@m.co.uk

Copyright (C) 2012, Rafaël Carré <funman@videolanorg>

Copyright (C) 2015, Sebastian Dröge sebas.nosp@m.tian.nosp@m.@cent.nosp@m.ricu.nosp@m.lar.c.nosp@m.om

Copyright (C) 2014-2015, Collabora Ltd. Author: Matthieu Bouron matth.nosp@m.ieu..nosp@m.bouro.nosp@m.n@gc.nosp@m.ollab.nosp@m.ora..nosp@m.com

Copyright (C) 2015, Edward Hervey Author: Edward Hervey bilbo.nosp@m.ed@g.nosp@m.mail..nosp@m.com

Copyright (C) 2015, Matthew Waters matth.nosp@m.ew@c.nosp@m.entri.nosp@m.cula.nosp@m.r.com

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Definition at line 84 of file mediacodecdec_common.c.

◆ OUTPUT_DEQUEUE_TIMEOUT_US

#define OUTPUT_DEQUEUE_TIMEOUT_US   8000

Definition at line 85 of file mediacodecdec_common.c.

◆ OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US

#define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US   1000000

Definition at line 86 of file mediacodecdec_common.c.

◆ AMEDIAFORMAT_GET_INT32

#define AMEDIAFORMAT_GET_INT32 (   name,
  key,
  mandatory 
)
Value:
do { \
int32_t value = 0; \
if (ff_AMediaFormat_getInt32(s->format, key, &value)) { \
(name) = value; \
} else if (mandatory) { \
av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", key, format); \
goto fail; \
} \
} while (0) \

Definition at line 428 of file mediacodecdec_common.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
COLOR_RANGE_FULL 
COLOR_RANGE_LIMITED 

Definition at line 88 of file mediacodecdec_common.c.

◆ anonymous enum

anonymous enum
Enumerator
COLOR_STANDARD_BT709 
COLOR_STANDARD_BT601_PAL 
COLOR_STANDARD_BT601_NTSC 
COLOR_STANDARD_BT2020 

Definition at line 105 of file mediacodecdec_common.c.

◆ anonymous enum

anonymous enum
Enumerator
COLOR_TRANSFER_LINEAR 
COLOR_TRANSFER_SDR_VIDEO 
COLOR_TRANSFER_ST2084 
COLOR_TRANSFER_HLG 

Definition at line 144 of file mediacodecdec_common.c.

◆ anonymous enum

anonymous enum
Enumerator
COLOR_FormatYUV420Planar 
COLOR_FormatYUV420SemiPlanar 
COLOR_FormatYCbYCr 
COLOR_FormatAndroidOpaque 
COLOR_QCOM_FormatYUV420SemiPlanar 
COLOR_QCOM_FormatYUV420SemiPlanar32m 
COLOR_QCOM_FormatYUV420PackedSemiPlanar64x32Tile2m8ka 
COLOR_TI_FormatYUV420PackedSemiPlanar 
COLOR_TI_FormatYUV420PackedSemiPlanarInterlaced 

Definition at line 167 of file mediacodecdec_common.c.

Function Documentation

◆ mcdec_get_color_range()

static enum AVColorRange mcdec_get_color_range ( int  color_range)
static

Definition at line 93 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_format().

◆ mcdec_get_color_space()

static enum AVColorSpace mcdec_get_color_space ( int  color_standard)
static

Definition at line 112 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_format().

◆ mcdec_get_color_pri()

static enum AVColorPrimaries mcdec_get_color_pri ( int  color_standard)
static

Definition at line 128 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_format().

◆ mcdec_get_color_trc()

static enum AVColorTransferCharacteristic mcdec_get_color_trc ( int  color_transfer)
static

Definition at line 151 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_format().

◆ mcdec_map_color_format()

static enum AVPixelFormat mcdec_map_color_format ( AVCodecContext avctx,
MediaCodecDecContext s,
int  color_format 
)
static

Definition at line 196 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_format().

◆ ff_mediacodec_dec_ref()

static void ff_mediacodec_dec_ref ( MediaCodecDecContext s)
static

Definition at line 223 of file mediacodecdec_common.c.

Referenced by mediacodec_wrap_hw_buffer().

◆ ff_mediacodec_dec_unref()

static void ff_mediacodec_dec_unref ( MediaCodecDecContext s)
static

Definition at line 228 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_close(), and mediacodec_buffer_release().

◆ mediacodec_buffer_release()

static void mediacodec_buffer_release ( void *  opaque,
uint8_t *  data 
)
static

Definition at line 254 of file mediacodecdec_common.c.

Referenced by mediacodec_wrap_hw_buffer().

◆ mediacodec_wrap_hw_buffer()

static int mediacodec_wrap_hw_buffer ( AVCodecContext avctx,
MediaCodecDecContext s,
ssize_t  index,
FFAMediaCodecBufferInfo info,
AVFrame frame 
)
static

Definition at line 273 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_receive().

◆ mediacodec_wrap_sw_buffer()

static int mediacodec_wrap_sw_buffer ( AVCodecContext avctx,
MediaCodecDecContext s,
uint8_t *  data,
size_t  size,
ssize_t  index,
FFAMediaCodecBufferInfo info,
AVFrame frame 
)
static

Definition at line 350 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_receive().

◆ mediacodec_dec_parse_format()

static int mediacodec_dec_parse_format ( AVCodecContext avctx,
MediaCodecDecContext s 
)
static

Definition at line 439 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_init(), and ff_mediacodec_dec_receive().

◆ mediacodec_dec_flush_codec()

static int mediacodec_dec_flush_codec ( AVCodecContext avctx,
MediaCodecDecContext s 
)
static

Definition at line 532 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_flush().

◆ ff_mediacodec_dec_init()

int ff_mediacodec_dec_init ( AVCodecContext avctx,
MediaCodecDecContext s,
const char *  mime,
FFAMediaFormat format 
)

Definition at line 555 of file mediacodecdec_common.c.

Referenced by mediacodec_decode_init().

◆ ff_mediacodec_dec_send()

int ff_mediacodec_dec_send ( AVCodecContext avctx,
MediaCodecDecContext s,
AVPacket pkt,
bool  wait 
)

Definition at line 656 of file mediacodecdec_common.c.

Referenced by mediacodec_receive_frame().

◆ ff_mediacodec_dec_receive()

int ff_mediacodec_dec_receive ( AVCodecContext avctx,
MediaCodecDecContext s,
AVFrame frame,
bool  wait 
)

Definition at line 750 of file mediacodecdec_common.c.

Referenced by mediacodec_receive_frame().

◆ ff_mediacodec_dec_flush()

int ff_mediacodec_dec_flush ( AVCodecContext avctx,
MediaCodecDecContext s 
)

Definition at line 873 of file mediacodecdec_common.c.

Referenced by mediacodec_decode_flush(), and mediacodec_receive_frame().

◆ ff_mediacodec_dec_close()

int ff_mediacodec_dec_close ( AVCodecContext avctx,
MediaCodecDecContext s 
)

Definition at line 891 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_init(), and mediacodec_decode_close().

◆ ff_mediacodec_dec_is_flushing()

int ff_mediacodec_dec_is_flushing ( AVCodecContext avctx,
MediaCodecDecContext s 
)

Definition at line 898 of file mediacodecdec_common.c.

Referenced by mediacodec_receive_frame().

Variable Documentation

◆ color_format

int color_format

Definition at line 181 of file mediacodecdec_common.c.

Referenced by mcdec_map_color_format().

◆ pix_fmt

enum AVPixelFormat pix_fmt

Definition at line 182 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_init().

◆ color_formats

const { ... } color_formats[]
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
COLOR_QCOM_FormatYUV420SemiPlanar
@ COLOR_QCOM_FormatYUV420SemiPlanar
Definition: mediacodecdec_common.c:172
COLOR_QCOM_FormatYUV420SemiPlanar32m
@ COLOR_QCOM_FormatYUV420SemiPlanar32m
Definition: mediacodecdec_common.c:173
fail
#define fail()
Definition: checkasm.h:131
COLOR_TI_FormatYUV420PackedSemiPlanarInterlaced
@ COLOR_TI_FormatYUV420PackedSemiPlanarInterlaced
Definition: mediacodecdec_common.c:176
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
s
#define s(width, name)
Definition: cbs_vp9.c:256
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
key
const char * key
Definition: hwcontext_opencl.c:174
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecdec_common.c:169
COLOR_TI_FormatYUV420PackedSemiPlanar
@ COLOR_TI_FormatYUV420PackedSemiPlanar
Definition: mediacodecdec_common.c:175
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecdec_common.c:168
COLOR_QCOM_FormatYUV420PackedSemiPlanar64x32Tile2m8ka
@ COLOR_QCOM_FormatYUV420PackedSemiPlanar64x32Tile2m8ka
Definition: mediacodecdec_common.c:174
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
ff_AMediaFormat_getInt32
int ff_AMediaFormat_getInt32(FFAMediaFormat *format, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:752
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89