FFmpeg/libavcodec/mediacodecdec_common.h
Aman Gupta f611fef37c avcodec/mediacodecdec: refactor to take advantage of new decoding api
This refactor splits up the main mediacodec decode loop into two
send/receive helpers, which are then used to rewrite the receive_frame
callback and take full advantage of the new decoding api. Since we
can now request packets on demand with ff_decode_get_packet(), the
fifo buffer is no longer necessary and has been removed.

This change was motivated by behavior observed on certain Android TV
devices, featuring hardware mpeg2/h264 decoders which also deinterlace
content (to produce multiple frames per field). Previously, this code
caused buffering issues because queueInputBuffer() was always invoked
before each dequeueOutputBuffer(), even though twice as many output
buffers were being generated.

With this patch, the decoder will always attempt to drain new frames
first before sending more data into the underlying codec.

Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2018-02-19 15:27:34 +01:00

101 lines
2.7 KiB
C

/*
* Android MediaCodec decoder
*
* Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
*
* This file is part of FFmpeg.
*
* FFmpeg 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; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_MEDIACODECDEC_COMMON_H
#define AVCODEC_MEDIACODECDEC_COMMON_H
#include <stdint.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <sys/types.h>
#include "libavutil/frame.h"
#include "libavutil/pixfmt.h"
#include "avcodec.h"
#include "mediacodec_wrapper.h"
typedef struct MediaCodecDecContext {
atomic_int refcount;
char *codec_name;
FFAMediaCodec *codec;
FFAMediaFormat *format;
void *surface;
int started;
int draining;
int flushing;
int eos;
int width;
int height;
int stride;
int slice_height;
int color_format;
enum AVPixelFormat pix_fmt;
int crop_top;
int crop_bottom;
int crop_left;
int crop_right;
uint64_t output_buffer_count;
} MediaCodecDecContext;
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);
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);
typedef struct MediaCodecBuffer {
MediaCodecDecContext *ctx;
ssize_t index;
int64_t pts;
atomic_int released;
} MediaCodecBuffer;
#endif /* AVCODEC_MEDIACODECDEC_COMMON_H */