FFmpeg
Loading...
Searching...
No Matches
mediacodecdec_common.c File Reference
#include <string.h>
#include <sys/types.h>
#include "libavutil/avassert.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 "libavutil/channel_layout.h"
#include "avcodec.h"
#include "decode.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.
 
#define OUTPUT_DEQUEUE_TIMEOUT_US   8000
 
#define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US   1000000
 
#define AMEDIAFORMAT_GET_INT32(name, key, mandatory)
 

Enumerations

enum  {
  ENCODING_PCM_16BIT = 0x00000002 , ENCODING_PCM_8BIT = 0x00000003 , ENCODING_PCM_FLOAT = 0x00000004 , ENCODING_PCM_24BIT_PACKED = 0x00000015 ,
  ENCODING_PCM_32BIT = 0x00000016
}
 
enum  {
  CHANNEL_OUT_FRONT_LEFT = 0x4 , CHANNEL_OUT_FRONT_RIGHT = 0x8 , CHANNEL_OUT_FRONT_CENTER = 0x10 , CHANNEL_OUT_LOW_FREQUENCY = 0x20 ,
  CHANNEL_OUT_BACK_LEFT = 0x40 , CHANNEL_OUT_BACK_RIGHT = 0x80 , CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100 , CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200 ,
  CHANNEL_OUT_BACK_CENTER = 0x400 , CHANNEL_OUT_SIDE_LEFT = 0x800 , CHANNEL_OUT_SIDE_RIGHT = 0x1000 , CHANNEL_OUT_TOP_CENTER = 0x2000 ,
  CHANNEL_OUT_TOP_FRONT_LEFT = 0x4000 , CHANNEL_OUT_TOP_FRONT_CENTER = 0x8000 , CHANNEL_OUT_TOP_FRONT_RIGHT = 0x10000 , CHANNEL_OUT_TOP_BACK_LEFT = 0x20000 ,
  CHANNEL_OUT_TOP_BACK_CENTER = 0x40000 , CHANNEL_OUT_TOP_BACK_RIGHT = 0x80000
}
 
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 AVSampleFormat mcdec_map_pcm_format (AVCodecContext *avctx, MediaCodecDecContext *s, int pcm_format)
 
static uint64_t mcdec_map_channel_mask (AVCodecContext *avctx, int channel_mask)
 
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_audio_buffer (AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, ssize_t index, FFAMediaCodecBufferInfo *info, AVFrame *frame)
 
static int mediacodec_wrap_sw_video_buffer (AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, 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_video_format (AVCodecContext *avctx, MediaCodecDecContext *s)
 
static int mediacodec_dec_parse_audio_format (AVCodecContext *avctx, MediaCodecDecContext *s)
 
static int mediacodec_dec_parse_format (AVCodecContext *avctx, MediaCodecDecContext *s)
 
static int mediacodec_dec_flush_codec (AVCodecContext *avctx, MediaCodecDecContext *s)
 
static int mediacodec_dec_get_video_codec (AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
 
static int mediacodec_dec_get_audio_codec (AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
 
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   pcm_format 
 
   enum AVSampleFormat   sample_format 
 
sample_formats [] 
 
struct { 
 
   int   mask 
 
   uint64_t   layout 
 
channel_masks [] 
 
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 86 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_send(), and mediacodec_get_input_index().

◆ OUTPUT_DEQUEUE_TIMEOUT_US

#define OUTPUT_DEQUEUE_TIMEOUT_US   8000

◆ OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US

#define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US   1000000

Definition at line 88 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_receive().

◆ 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; \
} else { \
(name) = 0; \
} \
} while (0) \
static const char *const format[]
Definition af_aiir.c:444
int32_t
#define s(width, name)
Definition cbs_vp9.c:198
double value
Definition eval.c:102
const char * key
#define fail
Definition test.h:479
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static int ff_AMediaFormat_getInt32(FFAMediaFormat *format, const char *name, int32_t *out)
const char * name
Definition qsvenc.c:142

Definition at line 538 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_audio_format(), and mediacodec_dec_parse_video_format().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ENCODING_PCM_16BIT 
ENCODING_PCM_8BIT 
ENCODING_PCM_FLOAT 
ENCODING_PCM_24BIT_PACKED 
ENCODING_PCM_32BIT 

Definition at line 90 of file mediacodecdec_common.c.

◆ anonymous enum

anonymous enum
Enumerator
CHANNEL_OUT_FRONT_LEFT 
CHANNEL_OUT_FRONT_RIGHT 
CHANNEL_OUT_FRONT_CENTER 
CHANNEL_OUT_LOW_FREQUENCY 
CHANNEL_OUT_BACK_LEFT 
CHANNEL_OUT_BACK_RIGHT 
CHANNEL_OUT_FRONT_LEFT_OF_CENTER 
CHANNEL_OUT_FRONT_RIGHT_OF_CENTER 
CHANNEL_OUT_BACK_CENTER 
CHANNEL_OUT_SIDE_LEFT 
CHANNEL_OUT_SIDE_RIGHT 
CHANNEL_OUT_TOP_CENTER 
CHANNEL_OUT_TOP_FRONT_LEFT 
CHANNEL_OUT_TOP_FRONT_CENTER 
CHANNEL_OUT_TOP_FRONT_RIGHT 
CHANNEL_OUT_TOP_BACK_LEFT 
CHANNEL_OUT_TOP_BACK_CENTER 
CHANNEL_OUT_TOP_BACK_RIGHT 

Definition at line 130 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 191 of file mediacodecdec_common.c.

Function Documentation

◆ mcdec_map_pcm_format()

static enum AVSampleFormat mcdec_map_pcm_format ( AVCodecContext * avctx,
MediaCodecDecContext * s,
int pcm_format )
static

Definition at line 112 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_audio_format().

◆ mcdec_map_channel_mask()

static uint64_t mcdec_map_channel_mask ( AVCodecContext * avctx,
int channel_mask )
static

Definition at line 178 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_audio_format().

◆ mcdec_map_color_format()

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

Definition at line 220 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_video_format().

◆ ff_mediacodec_dec_ref()

static void ff_mediacodec_dec_ref ( MediaCodecDecContext * s)
static

Definition at line 247 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 252 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 278 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 296 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_receive().

◆ mediacodec_wrap_sw_audio_buffer()

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

Definition at line 371 of file mediacodecdec_common.c.

Referenced by mediacodec_wrap_sw_buffer().

◆ mediacodec_wrap_sw_video_buffer()

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

Definition at line 444 of file mediacodecdec_common.c.

Referenced by mediacodec_wrap_sw_buffer().

◆ 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 522 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_receive().

◆ mediacodec_dec_parse_video_format()

static int mediacodec_dec_parse_video_format ( AVCodecContext * avctx,
MediaCodecDecContext * s )
static

Definition at line 551 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_format().

◆ mediacodec_dec_parse_audio_format()

static int mediacodec_dec_parse_audio_format ( AVCodecContext * avctx,
MediaCodecDecContext * s )
static

Definition at line 663 of file mediacodecdec_common.c.

Referenced by mediacodec_dec_parse_format().

◆ mediacodec_dec_parse_format()

static int mediacodec_dec_parse_format ( AVCodecContext * avctx,
MediaCodecDecContext * s )
static

Definition at line 710 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 720 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_flush().

◆ mediacodec_dec_get_video_codec()

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

Definition at line 743 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_init().

◆ mediacodec_dec_get_audio_codec()

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

Definition at line 814 of file mediacodecdec_common.c.

Referenced by ff_mediacodec_dec_init().

◆ ff_mediacodec_dec_init()

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

Definition at line 833 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 898 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 992 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 1117 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 1135 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 1154 of file mediacodecdec_common.c.

Referenced by mediacodec_receive_frame().

Variable Documentation

◆ pcm_format

int pcm_format

Definition at line 100 of file mediacodecdec_common.c.

Referenced by mcdec_map_pcm_format().

◆ sample_format

enum AVSampleFormat sample_format

Definition at line 101 of file mediacodecdec_common.c.

Referenced by ipcm_decoder_config().

◆ [struct]

const struct { ... } sample_formats[]
Initial value:
= {
{ 0 }
}
@ AV_SAMPLE_FMT_FLT
float
Definition samplefmt.h:60
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition samplefmt.h:59
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
Definition samplefmt.h:57
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
@ ENCODING_PCM_8BIT
@ ENCODING_PCM_32BIT
@ ENCODING_PCM_FLOAT
@ ENCODING_PCM_16BIT

Referenced by init_audio(), mcdec_map_pcm_format(), and read_header().

◆ mask

int mask

Definition at line 154 of file mediacodecdec_common.c.

◆ layout

◆ [struct]

const struct { ... } channel_masks[]
Initial value:
= {
}
#define AV_CH_SIDE_LEFT
#define AV_CH_TOP_FRONT_LEFT
#define AV_CH_FRONT_RIGHT
#define AV_CH_TOP_BACK_CENTER
#define AV_CH_FRONT_RIGHT_OF_CENTER
#define AV_CH_BACK_CENTER
#define AV_CH_TOP_FRONT_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CH_BACK_RIGHT
#define AV_CH_FRONT_CENTER
#define AV_CH_TOP_BACK_RIGHT
#define AV_CH_TOP_CENTER
#define AV_CH_SIDE_RIGHT
#define AV_CH_BACK_LEFT
#define AV_CH_TOP_BACK_LEFT
#define AV_CH_LOW_FREQUENCY
#define AV_CH_TOP_FRONT_RIGHT
#define AV_CH_FRONT_LEFT
@ CHANNEL_OUT_LOW_FREQUENCY
@ CHANNEL_OUT_TOP_BACK_LEFT
@ CHANNEL_OUT_TOP_FRONT_LEFT
@ CHANNEL_OUT_TOP_FRONT_RIGHT
@ CHANNEL_OUT_TOP_FRONT_CENTER
@ CHANNEL_OUT_FRONT_CENTER
@ CHANNEL_OUT_TOP_BACK_CENTER
@ CHANNEL_OUT_FRONT_RIGHT_OF_CENTER
@ CHANNEL_OUT_SIDE_RIGHT
@ CHANNEL_OUT_FRONT_RIGHT
@ CHANNEL_OUT_FRONT_LEFT
@ CHANNEL_OUT_SIDE_LEFT
@ CHANNEL_OUT_TOP_BACK_RIGHT
@ CHANNEL_OUT_BACK_CENTER
@ CHANNEL_OUT_TOP_CENTER
@ CHANNEL_OUT_BACK_LEFT
@ CHANNEL_OUT_BACK_RIGHT
@ CHANNEL_OUT_FRONT_LEFT_OF_CENTER

Referenced by mcdec_map_channel_mask().

◆ color_format

int color_format

Definition at line 205 of file mediacodecdec_common.c.

Referenced by mcdec_map_color_format(), and mediacodec_init().

◆ pix_fmt

enum AVPixelFormat pix_fmt

Definition at line 206 of file mediacodecdec_common.c.

◆ [struct]

const struct { ... } color_formats[]
Initial value:
= {
{ 0 }
}
@ COLOR_TI_FormatYUV420PackedSemiPlanar
@ COLOR_QCOM_FormatYUV420SemiPlanar32m
@ COLOR_TI_FormatYUV420PackedSemiPlanarInterlaced
@ COLOR_FormatYUV420Planar
@ COLOR_QCOM_FormatYUV420PackedSemiPlanar64x32Tile2m8ka
@ COLOR_QCOM_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
@ 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:96
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73

Referenced by mcdec_map_color_format(), and mediacodec_init().