mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-10-28 10:04:37 +08:00
Until the codec signals INFO_OUTPUT_FORMAT_CHANGED, MediaCodec returns the output format set up at configure time. The decoder parsed that format right after start() and copied its crop rectangle, display size and color description into the codec context, although at that point the codec has not decoded anything and these fields hold its defaults. For a 1920x1080 HLG stream, c2.xring.hevc.decoder reports the crop rectangle Rect(0, 0, 175, 143) and BT.601 SDR color there, and MediaTek decoders report rectangles such as Rect(0, 0, 318, 238). Callers reading the codec context after avcodec_open2() got 176x144 or 319x239 and a wrong color description instead of the stream properties. Keep the values set by the caller until the codec signals a format change. The pixel format is still taken from the initial format, as it reflects the configuration. If the first output buffer arrives without a format change, the initial format describes the decoded frames and is applied at that point.
116 lines
3.1 KiB
C
116 lines
3.1 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 {
|
|
|
|
AVCodecContext *avctx;
|
|
atomic_int refcount;
|
|
atomic_int hw_buffer_count;
|
|
|
|
char *codec_name;
|
|
|
|
FFAMediaCodec *codec;
|
|
FFAMediaFormat *format;
|
|
/* Set once the codec has signalled an output format or produced output.
|
|
* Until then format is the one set up at configure time and its stream
|
|
* info is not applied.
|
|
*/
|
|
bool has_output_format;
|
|
|
|
void *surface;
|
|
|
|
int started;
|
|
int draining;
|
|
int flushing;
|
|
int eos;
|
|
|
|
int width;
|
|
int height;
|
|
int stride;
|
|
int slice_height;
|
|
int color_format;
|
|
int crop_top;
|
|
int crop_bottom;
|
|
int crop_left;
|
|
int crop_right;
|
|
int display_width;
|
|
int display_height;
|
|
|
|
uint64_t output_buffer_count;
|
|
ssize_t current_input_buffer;
|
|
|
|
bool delay_flush;
|
|
atomic_int serial;
|
|
|
|
bool use_ndk_codec;
|
|
} 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,
|
|
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);
|
|
|
|
typedef struct MediaCodecBuffer {
|
|
|
|
MediaCodecDecContext *ctx;
|
|
ssize_t index;
|
|
int64_t pts;
|
|
atomic_int released;
|
|
int serial;
|
|
|
|
} MediaCodecBuffer;
|
|
|
|
#endif /* AVCODEC_MEDIACODECDEC_COMMON_H */
|