2009-04-16 09:00:46 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2009> Edward Hervey <bilboed@bilboed.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:22:16 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-04-16 09:00:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GST_FFMPEG_UTILS_H__
|
|
|
|
#define __GST_FFMPEG_UTILS_H__
|
|
|
|
|
2011-10-17 14:26:52 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-04-16 09:00:46 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
2012-09-10 15:08:00 +00:00
|
|
|
#include <libavutil/mathematics.h>
|
2011-10-17 14:26:52 +00:00
|
|
|
|
2009-04-16 09:00:46 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2020-10-05 18:47:42 +00:00
|
|
|
/* Introduced since ffmpeg version 4.3
|
|
|
|
*
|
|
|
|
* Note: Not all ffmpeg encoders seem to be reusable after flushing/draining.
|
|
|
|
* So if ffmpeg encoder doesn't support it, we should reopen encoding session.
|
|
|
|
*
|
|
|
|
* Before ffmpeg 4.3, avcodec_flush_buffers() was implemented in
|
|
|
|
* libavcodec/decodec.c but it was moved to libavcodec/utils.c and it would be
|
|
|
|
* accepted if encoder supports AV_CODEC_CAP_ENCODER_FLUSH flag.
|
|
|
|
* That implies that avcodec_flush_buffers() wasn't intended to be working
|
|
|
|
* properly for encoders.
|
|
|
|
*/
|
|
|
|
#ifndef AV_CODEC_CAP_ENCODER_FLUSH
|
|
|
|
/*
|
|
|
|
* This encoder can be flushed using avcodec_flush_buffers(). If this flag is
|
|
|
|
* not set, the encoder must be closed and reopened to ensure that no frames
|
|
|
|
* remain pending.
|
|
|
|
*/
|
|
|
|
#define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21)
|
|
|
|
#endif
|
|
|
|
|
2009-04-16 09:00:46 +00:00
|
|
|
/*
|
|
|
|
*Get the size of an picture
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gst_ffmpeg_avpicture_get_size (int pix_fmt, int width, int height);
|
|
|
|
|
|
|
|
/*
|
2018-06-29 02:52:02 +00:00
|
|
|
* Fill in pointers in an AVFrame, aligned by 4 (required by X).
|
2009-04-16 09:00:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2018-06-29 02:52:02 +00:00
|
|
|
gst_ffmpeg_avpicture_fill (AVFrame * picture,
|
2009-04-16 09:00:46 +00:00
|
|
|
uint8_t * ptr,
|
2015-11-04 20:18:56 +00:00
|
|
|
enum AVPixelFormat pix_fmt,
|
2009-04-16 09:00:46 +00:00
|
|
|
int width,
|
|
|
|
int height);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert from/to a GStreamer <-> FFMpeg timestamp.
|
|
|
|
*/
|
|
|
|
static inline guint64
|
|
|
|
gst_ffmpeg_time_ff_to_gst (gint64 pts, AVRational base)
|
|
|
|
{
|
|
|
|
guint64 out;
|
|
|
|
|
|
|
|
if (pts == AV_NOPTS_VALUE){
|
|
|
|
out = GST_CLOCK_TIME_NONE;
|
|
|
|
} else {
|
|
|
|
AVRational bq = { 1, GST_SECOND };
|
|
|
|
out = av_rescale_q (pts, base, bq);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gint64
|
|
|
|
gst_ffmpeg_time_gst_to_ff (guint64 time, AVRational base)
|
|
|
|
{
|
|
|
|
gint64 out;
|
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (time) || base.num == 0) {
|
|
|
|
out = AV_NOPTS_VALUE;
|
|
|
|
} else {
|
|
|
|
AVRational bq = { 1, GST_SECOND };
|
|
|
|
out = av_rescale_q (time, bq, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2020-10-05 18:47:42 +00:00
|
|
|
void
|
2010-03-24 11:07:28 +00:00
|
|
|
gst_ffmpeg_init_pix_fmt_info(void);
|
2009-04-16 09:00:46 +00:00
|
|
|
|
2011-06-21 04:33:29 +00:00
|
|
|
int
|
|
|
|
gst_ffmpeg_auto_max_threads(void);
|
2009-04-16 09:00:46 +00:00
|
|
|
|
2015-10-02 20:02:01 +00:00
|
|
|
const gchar *
|
2014-01-03 15:28:44 +00:00
|
|
|
gst_ffmpeg_get_codecid_longname (enum AVCodecID codec_id);
|
2009-04-16 09:00:46 +00:00
|
|
|
|
|
|
|
gint
|
2012-09-12 13:30:05 +00:00
|
|
|
av_smp_format_depth(enum AVSampleFormat smp_fmt);
|
2009-04-16 09:00:46 +00:00
|
|
|
|
2009-03-08 10:31:35 +00:00
|
|
|
GstBuffer *
|
2011-06-02 14:23:19 +00:00
|
|
|
new_aligned_buffer (gint size);
|
2009-03-08 10:31:35 +00:00
|
|
|
|
2009-04-16 09:00:46 +00:00
|
|
|
#endif /* __GST_FFMPEG_UTILS_H__ */
|