2001-07-22 14:18:56 +00:00
|
|
|
/*
|
2008-01-16 22:14:26 +00:00
|
|
|
* various utility functions for use within FFmpeg
|
2002-05-25 22:34:32 +00:00
|
|
|
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
2001-07-22 14:18:56 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
|
*
|
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-05-25 22:34:32 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-07-22 14:18:56 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2001-07-22 14:18:56 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2002-05-25 22:34:32 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-07-22 14:18:56 +00:00
|
|
|
*
|
2002-05-25 22:34:32 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-07-22 14:18:56 +00:00
|
|
|
*/
|
2011-03-15 13:11:57 +01:00
|
|
|
|
2013-11-23 21:32:55 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2012-01-05 10:14:07 +01:00
|
|
|
#include "libavutil/avassert.h"
|
2008-05-09 11:56:36 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2021-07-23 04:01:44 +02:00
|
|
|
#include "libavutil/bprint.h"
|
2014-01-16 01:53:03 +01:00
|
|
|
#include "libavutil/internal.h"
|
2017-12-21 22:54:06 +01:00
|
|
|
#include "libavutil/thread.h"
|
2012-07-27 16:28:36 +02:00
|
|
|
#include "libavutil/time.h"
|
2014-01-16 01:53:03 +01:00
|
|
|
|
|
|
|
|
#include "libavcodec/internal.h"
|
|
|
|
|
|
|
|
|
|
#include "avformat.h"
|
|
|
|
|
#include "avio_internal.h"
|
|
|
|
|
#include "internal.h"
|
2010-03-05 22:31:45 +00:00
|
|
|
#if CONFIG_NETWORK
|
|
|
|
|
#include "network.h"
|
|
|
|
|
#endif
|
2014-12-19 18:04:40 +01:00
|
|
|
|
2017-12-21 22:54:06 +01:00
|
|
|
static AVMutex avformat_mutex = AV_MUTEX_INITIALIZER;
|
|
|
|
|
|
2005-06-28 12:55:08 +00:00
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2008-01-16 22:14:26 +00:00
|
|
|
* various utility functions for use within FFmpeg
|
2005-06-28 12:55:08 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-12-21 22:54:06 +01:00
|
|
|
int ff_lock_avformat(void)
|
|
|
|
|
{
|
|
|
|
|
return ff_mutex_lock(&avformat_mutex) ? -1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ff_unlock_avformat(void)
|
|
|
|
|
{
|
|
|
|
|
return ff_mutex_unlock(&avformat_mutex) ? -1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 11:25:23 +02:00
|
|
|
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
|
2014-10-24 19:23:23 +02:00
|
|
|
{
|
2016-01-30 02:17:50 +01:00
|
|
|
av_assert0(!dst->codec_whitelist &&
|
|
|
|
|
!dst->format_whitelist &&
|
2016-03-03 17:14:26 +00:00
|
|
|
!dst->protocol_whitelist &&
|
|
|
|
|
!dst->protocol_blacklist);
|
2014-10-24 19:23:23 +02:00
|
|
|
dst-> codec_whitelist = av_strdup(src->codec_whitelist);
|
|
|
|
|
dst->format_whitelist = av_strdup(src->format_whitelist);
|
2016-01-30 02:17:50 +01:00
|
|
|
dst->protocol_whitelist = av_strdup(src->protocol_whitelist);
|
2016-03-03 17:14:26 +00:00
|
|
|
dst->protocol_blacklist = av_strdup(src->protocol_blacklist);
|
2014-10-24 19:23:23 +02:00
|
|
|
if ( (src-> codec_whitelist && !dst-> codec_whitelist)
|
2016-01-30 02:17:50 +01:00
|
|
|
|| (src-> format_whitelist && !dst-> format_whitelist)
|
2016-03-03 17:14:26 +00:00
|
|
|
|| (src->protocol_whitelist && !dst->protocol_whitelist)
|
|
|
|
|
|| (src->protocol_blacklist && !dst->protocol_blacklist)) {
|
|
|
|
|
av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
|
2014-10-24 19:23:23 +02:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 09:24:10 +02:00
|
|
|
const AVCodec *ff_find_decoder(AVFormatContext *s, const AVStream *st,
|
|
|
|
|
enum AVCodecID codec_id)
|
2013-09-28 17:07:47 +02:00
|
|
|
{
|
2016-04-10 20:58:15 +01:00
|
|
|
switch (st->codecpar->codec_type) {
|
2013-09-28 17:52:45 +02:00
|
|
|
case AVMEDIA_TYPE_VIDEO:
|
2014-01-26 23:35:38 +01:00
|
|
|
if (s->video_codec) return s->video_codec;
|
2013-09-28 17:52:45 +02:00
|
|
|
break;
|
|
|
|
|
case AVMEDIA_TYPE_AUDIO:
|
2014-01-26 23:35:38 +01:00
|
|
|
if (s->audio_codec) return s->audio_codec;
|
2013-09-28 17:52:45 +02:00
|
|
|
break;
|
|
|
|
|
case AVMEDIA_TYPE_SUBTITLE:
|
2014-01-26 23:35:38 +01:00
|
|
|
if (s->subtitle_codec) return s->subtitle_codec;
|
2013-09-28 17:52:45 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-28 17:07:47 +02:00
|
|
|
return avcodec_find_decoder(codec_id);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-19 17:20:35 +01:00
|
|
|
/* an arbitrarily chosen "sane" max packet size -- 50M */
|
|
|
|
|
#define SANE_CHUNK_SIZE (50000000)
|
2001-07-22 14:18:56 +00:00
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
/* Read the data in sane-sized chunks and append to pkt.
|
|
|
|
|
* Return the number of bytes read or an error. */
|
2013-02-19 17:20:35 +01:00
|
|
|
static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
|
2011-12-19 11:46:34 +01:00
|
|
|
{
|
2013-02-19 17:20:35 +01:00
|
|
|
int orig_size = pkt->size;
|
2013-03-16 17:03:41 +01:00
|
|
|
int ret;
|
2013-02-19 17:20:35 +01:00
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
int prev_size = pkt->size;
|
|
|
|
|
int read_size;
|
|
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
/* When the caller requests a lot of data, limit it to the amount
|
|
|
|
|
* left in file or SANE_CHUNK_SIZE when it is not known. */
|
2013-03-16 15:12:21 +01:00
|
|
|
read_size = size;
|
|
|
|
|
if (read_size > SANE_CHUNK_SIZE/10) {
|
|
|
|
|
read_size = ffio_limit(s, read_size);
|
|
|
|
|
// If filesize/maxsize is unknown, limit to SANE_CHUNK_SIZE
|
2021-08-04 16:52:07 +02:00
|
|
|
if (ffiocontext(s)->maxsize < 0)
|
2013-03-16 15:12:21 +01:00
|
|
|
read_size = FFMIN(read_size, SANE_CHUNK_SIZE);
|
|
|
|
|
}
|
2011-12-16 05:54:03 +01:00
|
|
|
|
2013-02-19 17:20:35 +01:00
|
|
|
ret = av_grow_packet(pkt, read_size);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
break;
|
2005-05-26 20:17:12 +00:00
|
|
|
|
2013-02-19 17:20:35 +01:00
|
|
|
ret = avio_read(s, pkt->data + prev_size, read_size);
|
|
|
|
|
if (ret != read_size) {
|
|
|
|
|
av_shrink_packet(pkt, prev_size + FFMAX(ret, 0));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-05-26 20:17:12 +00:00
|
|
|
|
2013-02-19 17:20:35 +01:00
|
|
|
size -= read_size;
|
|
|
|
|
} while (size > 0);
|
2013-03-16 15:12:21 +01:00
|
|
|
if (size > 0)
|
|
|
|
|
pkt->flags |= AV_PKT_FLAG_CORRUPT;
|
2005-05-26 20:17:12 +00:00
|
|
|
|
2013-02-19 17:20:35 +01:00
|
|
|
if (!pkt->size)
|
2015-10-23 11:11:31 +02:00
|
|
|
av_packet_unref(pkt);
|
2013-02-19 17:20:35 +01:00
|
|
|
return pkt->size > orig_size ? pkt->size - orig_size : ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
|
|
|
|
|
{
|
2021-01-31 13:05:49 -03:00
|
|
|
#if FF_API_INIT_PACKET
|
|
|
|
|
FF_DISABLE_DEPRECATION_WARNINGS
|
2013-02-19 17:20:35 +01:00
|
|
|
av_init_packet(pkt);
|
|
|
|
|
pkt->data = NULL;
|
|
|
|
|
pkt->size = 0;
|
2021-01-31 13:05:49 -03:00
|
|
|
FF_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
|
#else
|
|
|
|
|
av_packet_unref(pkt);
|
|
|
|
|
#endif
|
2013-02-19 17:20:35 +01:00
|
|
|
pkt->pos = avio_tell(s);
|
2005-05-26 20:17:12 +00:00
|
|
|
|
2013-02-19 17:20:35 +01:00
|
|
|
return append_packet_chunked(s, pkt, size);
|
2005-05-26 20:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-20 11:04:12 +01:00
|
|
|
int av_append_packet(AVIOContext *s, AVPacket *pkt, int size)
|
2010-11-21 10:24:48 +00:00
|
|
|
{
|
|
|
|
|
if (!pkt->size)
|
|
|
|
|
return av_get_packet(s, pkt, size);
|
2013-02-19 17:20:35 +01:00
|
|
|
return append_packet_chunked(s, pkt, size);
|
2010-11-21 10:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
2006-09-04 09:57:47 +00:00
|
|
|
int av_filename_number_test(const char *filename)
|
2002-05-20 16:28:47 +00:00
|
|
|
{
|
|
|
|
|
char buf[1024];
|
2014-01-16 01:53:03 +01:00
|
|
|
return filename &&
|
|
|
|
|
(av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0);
|
2002-05-20 16:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-10 18:37:55 +00:00
|
|
|
/**********************************************************/
|
|
|
|
|
|
2020-04-21 23:35:23 +08:00
|
|
|
int ff_is_intra_only(enum AVCodecID id)
|
2012-08-09 18:39:56 +02:00
|
|
|
{
|
|
|
|
|
const AVCodecDescriptor *d = avcodec_descriptor_get(id);
|
|
|
|
|
if (!d)
|
|
|
|
|
return 0;
|
2019-12-12 23:02:01 +09:00
|
|
|
if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
|
|
|
|
|
!(d->props & AV_CODEC_PROP_INTRA_ONLY))
|
2012-08-09 18:39:56 +02:00
|
|
|
return 0;
|
|
|
|
|
return 1;
|
2004-10-22 01:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-27 09:24:10 +02:00
|
|
|
/*******************************************************/
|
|
|
|
|
|
2012-08-05 11:11:04 +02:00
|
|
|
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
|
2007-07-11 12:45:14 +00:00
|
|
|
{
|
2012-08-05 11:11:04 +02:00
|
|
|
while (tags->id != AV_CODEC_ID_NONE) {
|
2007-07-11 12:45:14 +00:00
|
|
|
if (tags->id == id)
|
|
|
|
|
return tags->tag;
|
|
|
|
|
tags++;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-05 11:11:04 +02:00
|
|
|
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
|
2007-07-11 12:45:14 +00:00
|
|
|
{
|
2021-08-24 17:47:04 +02:00
|
|
|
for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
|
2014-01-16 01:53:03 +01:00
|
|
|
if (tag == tags[i].tag)
|
2007-07-27 11:36:17 +00:00
|
|
|
return tags[i].id;
|
2021-08-24 17:47:04 +02:00
|
|
|
for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
|
2021-12-13 19:55:39 +01:00
|
|
|
if (ff_toupper4(tag) == ff_toupper4(tags[i].tag))
|
2007-07-27 11:36:17 +00:00
|
|
|
return tags[i].id;
|
2012-08-05 11:11:04 +02:00
|
|
|
return AV_CODEC_ID_NONE;
|
2007-07-11 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-27 14:52:38 -05:00
|
|
|
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
|
|
|
|
|
{
|
2016-05-17 11:28:32 -07:00
|
|
|
if (bps <= 0 || bps > 64)
|
2016-05-11 00:00:52 +02:00
|
|
|
return AV_CODEC_ID_NONE;
|
|
|
|
|
|
2012-11-27 14:52:38 -05:00
|
|
|
if (flt) {
|
|
|
|
|
switch (bps) {
|
2014-01-16 01:53:03 +01:00
|
|
|
case 32:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_F32BE : AV_CODEC_ID_PCM_F32LE;
|
|
|
|
|
case 64:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_F64BE : AV_CODEC_ID_PCM_F64LE;
|
|
|
|
|
default:
|
|
|
|
|
return AV_CODEC_ID_NONE;
|
2012-11-27 14:52:38 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
2012-11-29 13:58:57 +01:00
|
|
|
bps += 7;
|
2012-11-27 14:52:38 -05:00
|
|
|
bps >>= 3;
|
|
|
|
|
if (sflags & (1 << (bps - 1))) {
|
|
|
|
|
switch (bps) {
|
2014-01-16 01:53:03 +01:00
|
|
|
case 1:
|
|
|
|
|
return AV_CODEC_ID_PCM_S8;
|
|
|
|
|
case 2:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_S16BE : AV_CODEC_ID_PCM_S16LE;
|
|
|
|
|
case 3:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE;
|
|
|
|
|
case 4:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_S32BE : AV_CODEC_ID_PCM_S32LE;
|
2016-08-17 19:46:21 +02:00
|
|
|
case 8:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_S64BE : AV_CODEC_ID_PCM_S64LE;
|
2014-01-16 01:53:03 +01:00
|
|
|
default:
|
|
|
|
|
return AV_CODEC_ID_NONE;
|
2012-11-27 14:52:38 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch (bps) {
|
2014-01-16 01:53:03 +01:00
|
|
|
case 1:
|
|
|
|
|
return AV_CODEC_ID_PCM_U8;
|
|
|
|
|
case 2:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_U16BE : AV_CODEC_ID_PCM_U16LE;
|
|
|
|
|
case 3:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_U24BE : AV_CODEC_ID_PCM_U24LE;
|
|
|
|
|
case 4:
|
|
|
|
|
return be ? AV_CODEC_ID_PCM_U32BE : AV_CODEC_ID_PCM_U32LE;
|
|
|
|
|
default:
|
|
|
|
|
return AV_CODEC_ID_NONE;
|
2012-11-27 14:52:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id)
|
2013-01-17 20:44:33 +01:00
|
|
|
{
|
|
|
|
|
unsigned int tag;
|
|
|
|
|
if (!av_codec_get_tag2(tags, id, &tag))
|
|
|
|
|
return 0;
|
|
|
|
|
return tag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id,
|
|
|
|
|
unsigned int *tag)
|
2007-07-11 12:45:14 +00:00
|
|
|
{
|
2021-08-24 17:47:04 +02:00
|
|
|
for (int i = 0; tags && tags[i]; i++) {
|
2013-01-17 20:44:33 +01:00
|
|
|
const AVCodecTag *codec_tags = tags[i];
|
|
|
|
|
while (codec_tags->id != AV_CODEC_ID_NONE) {
|
|
|
|
|
if (codec_tags->id == id) {
|
|
|
|
|
*tag = codec_tags->tag;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
codec_tags++;
|
|
|
|
|
}
|
2007-07-11 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag)
|
2007-07-11 12:45:14 +00:00
|
|
|
{
|
2021-08-24 17:47:04 +02:00
|
|
|
for (int i = 0; tags && tags[i]; i++) {
|
2014-01-16 01:53:03 +01:00
|
|
|
enum AVCodecID id = ff_codec_get_id(tags[i], tag);
|
|
|
|
|
if (id != AV_CODEC_ID_NONE)
|
|
|
|
|
return id;
|
2007-07-11 12:45:14 +00:00
|
|
|
}
|
2012-08-05 11:11:04 +02:00
|
|
|
return AV_CODEC_ID_NONE;
|
2007-07-11 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-10 20:58:15 +01:00
|
|
|
int ff_alloc_extradata(AVCodecParameters *par, int size)
|
2013-10-13 10:19:09 +00:00
|
|
|
{
|
2018-03-06 01:19:13 -03:00
|
|
|
av_freep(&par->extradata);
|
2018-03-06 01:37:21 -03:00
|
|
|
par->extradata_size = 0;
|
|
|
|
|
|
|
|
|
|
if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
|
2013-10-13 10:19:09 +00:00
|
|
|
return AVERROR(EINVAL);
|
2018-03-06 01:37:21 -03:00
|
|
|
|
2016-04-10 20:58:15 +01:00
|
|
|
par->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2018-03-06 01:37:21 -03:00
|
|
|
if (!par->extradata)
|
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
|
|
memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
|
par->extradata_size = size;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2013-10-13 10:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
|
|
|
|
|
int wanted_stream_nb, int related_stream,
|
2021-02-25 01:53:40 +01:00
|
|
|
const AVCodec **decoder_ret, int flags)
|
2010-12-27 09:08:20 +00:00
|
|
|
{
|
2021-08-24 17:47:04 +02:00
|
|
|
int nb_streams = ic->nb_streams;
|
2017-06-02 21:52:13 +02:00
|
|
|
int ret = AVERROR_STREAM_NOT_FOUND;
|
2017-06-02 22:45:02 +02:00
|
|
|
int best_count = -1, best_multiframe = -1, best_disposition = -1;
|
|
|
|
|
int count, multiframe, disposition;
|
|
|
|
|
int64_t best_bitrate = -1;
|
|
|
|
|
int64_t bitrate;
|
2010-12-27 09:08:20 +00:00
|
|
|
unsigned *program = NULL;
|
2014-05-07 05:52:58 +02:00
|
|
|
const AVCodec *decoder = NULL, *best_decoder = NULL;
|
2010-12-27 09:08:20 +00:00
|
|
|
|
|
|
|
|
if (related_stream >= 0 && wanted_stream_nb < 0) {
|
2011-08-22 23:42:19 +02:00
|
|
|
AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
|
2010-12-27 09:08:20 +00:00
|
|
|
if (p) {
|
2014-01-16 01:53:03 +01:00
|
|
|
program = p->stream_index;
|
2010-12-27 09:08:20 +00:00
|
|
|
nb_streams = p->nb_stream_indexes;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-24 17:47:04 +02:00
|
|
|
for (unsigned i = 0; i < nb_streams; i++) {
|
2011-02-20 01:18:30 +01:00
|
|
|
int real_stream_index = program ? program[i] : i;
|
2014-01-16 01:53:03 +01:00
|
|
|
AVStream *st = ic->streams[real_stream_index];
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 20:42:52 +02:00
|
|
|
AVCodecParameters *par = st->codecpar;
|
|
|
|
|
if (par->codec_type != type)
|
2010-12-27 09:08:20 +00:00
|
|
|
continue;
|
2011-02-20 01:18:30 +01:00
|
|
|
if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
|
2010-12-27 09:08:20 +00:00
|
|
|
continue;
|
2019-05-15 09:36:26 +02:00
|
|
|
if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
|
2014-01-16 00:36:27 +01:00
|
|
|
continue;
|
2010-12-27 09:08:20 +00:00
|
|
|
if (decoder_ret) {
|
2021-08-27 09:24:10 +02:00
|
|
|
decoder = ff_find_decoder(ic, st, par->codec_id);
|
2010-12-27 09:08:20 +00:00
|
|
|
if (!decoder) {
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
ret = AVERROR_DECODER_NOT_FOUND;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-20 12:26:27 +08:00
|
|
|
disposition = !(st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED | AV_DISPOSITION_VISUAL_IMPAIRED))
|
|
|
|
|
+ !! (st->disposition & AV_DISPOSITION_DEFAULT);
|
2021-08-24 19:41:16 +02:00
|
|
|
count = ffstream(st)->codec_info_nb_frames;
|
2016-04-10 20:58:15 +01:00
|
|
|
bitrate = par->bit_rate;
|
2012-11-18 13:19:14 +01:00
|
|
|
multiframe = FFMIN(5, count);
|
2017-06-02 21:52:13 +02:00
|
|
|
if ((best_disposition > disposition) ||
|
|
|
|
|
(best_disposition == disposition && best_multiframe > multiframe) ||
|
|
|
|
|
(best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
|
|
|
|
|
(best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
|
2010-12-27 09:08:20 +00:00
|
|
|
continue;
|
2017-06-02 21:52:13 +02:00
|
|
|
best_disposition = disposition;
|
2014-01-26 23:35:38 +01:00
|
|
|
best_count = count;
|
2012-11-18 13:19:14 +01:00
|
|
|
best_bitrate = bitrate;
|
|
|
|
|
best_multiframe = multiframe;
|
2014-01-16 01:53:03 +01:00
|
|
|
ret = real_stream_index;
|
2010-12-27 09:08:20 +00:00
|
|
|
best_decoder = decoder;
|
|
|
|
|
if (program && i == nb_streams - 1 && ret < 0) {
|
2014-01-16 01:53:03 +01:00
|
|
|
program = NULL;
|
2010-12-27 09:08:20 +00:00
|
|
|
nb_streams = ic->nb_streams;
|
2014-01-16 01:53:03 +01:00
|
|
|
/* no related stream found, try again with everything */
|
|
|
|
|
i = 0;
|
2010-12-27 09:08:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (decoder_ret)
|
2021-02-25 01:53:40 +01:00
|
|
|
*decoder_ret = best_decoder;
|
2010-12-27 09:08:20 +00:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 18:37:55 +00:00
|
|
|
/*******************************************************/
|
|
|
|
|
|
2021-12-15 20:00:31 +01:00
|
|
|
int ff_stream_side_data_copy(AVStream *dst, const AVStream *src)
|
|
|
|
|
{
|
2016-07-13 17:00:11 +02:00
|
|
|
/* Free existing side data*/
|
2021-08-24 17:47:04 +02:00
|
|
|
for (int i = 0; i < dst->nb_side_data; i++)
|
2016-07-13 17:00:11 +02:00
|
|
|
av_free(dst->side_data[i].data);
|
|
|
|
|
av_freep(&dst->side_data);
|
|
|
|
|
dst->nb_side_data = 0;
|
|
|
|
|
|
|
|
|
|
/* Copy side data if present */
|
|
|
|
|
if (src->nb_side_data) {
|
2021-09-14 21:31:53 +02:00
|
|
|
dst->side_data = av_calloc(src->nb_side_data,
|
|
|
|
|
sizeof(*dst->side_data));
|
2016-07-13 17:00:11 +02:00
|
|
|
if (!dst->side_data)
|
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
dst->nb_side_data = src->nb_side_data;
|
|
|
|
|
|
2021-08-24 17:47:04 +02:00
|
|
|
for (int i = 0; i < src->nb_side_data; i++) {
|
2016-07-13 17:00:11 +02:00
|
|
|
uint8_t *data = av_memdup(src->side_data[i].data,
|
|
|
|
|
src->side_data[i].size);
|
|
|
|
|
if (!data)
|
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
dst->side_data[i].type = src->side_data[i].type;
|
|
|
|
|
dst->side_data[i].size = src->side_data[i].size;
|
|
|
|
|
dst->side_data[i].data = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-16 16:25:26 -03:00
|
|
|
uint64_t ff_ntp_time(void)
|
2010-03-10 22:21:39 +00:00
|
|
|
{
|
2020-01-16 16:25:26 -03:00
|
|
|
return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
|
2010-03-10 22:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-07 15:27:36 +05:30
|
|
|
uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
|
|
|
|
|
{
|
|
|
|
|
uint64_t ntp_ts, frac_part, sec;
|
|
|
|
|
uint32_t usec;
|
|
|
|
|
|
|
|
|
|
//current ntp time in seconds and micro seconds
|
|
|
|
|
sec = ntp_time_us / 1000000;
|
|
|
|
|
usec = ntp_time_us % 1000000;
|
|
|
|
|
|
|
|
|
|
//encoding in ntp timestamp format
|
|
|
|
|
frac_part = usec * 0xFFFFFFFFULL;
|
|
|
|
|
frac_part /= 1000000;
|
|
|
|
|
|
|
|
|
|
if (sec > 0xFFFFFFFFULL)
|
|
|
|
|
av_log(NULL, AV_LOG_WARNING, "NTP time format roll over detected\n");
|
|
|
|
|
|
|
|
|
|
ntp_ts = sec << 32;
|
|
|
|
|
ntp_ts |= frac_part;
|
|
|
|
|
|
|
|
|
|
return ntp_ts;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 14:29:48 -07:00
|
|
|
uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
|
|
|
|
|
{
|
|
|
|
|
uint64_t sec = ntp_ts >> 32;
|
|
|
|
|
uint64_t frac_part = ntp_ts & 0xFFFFFFFFULL;
|
|
|
|
|
uint64_t usec = (frac_part * 1000000) / 0xFFFFFFFFULL;
|
|
|
|
|
|
|
|
|
|
return (sec * 1000000) + usec;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 22:58:01 +01:00
|
|
|
int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
|
2001-09-16 21:50:48 +00:00
|
|
|
{
|
|
|
|
|
const char *p;
|
2003-10-26 10:49:49 +00:00
|
|
|
char *q, buf1[20], c;
|
2016-11-01 22:58:01 +01:00
|
|
|
int nd, len, percentd_found;
|
2001-09-16 21:50:48 +00:00
|
|
|
|
|
|
|
|
q = buf;
|
|
|
|
|
p = path;
|
|
|
|
|
percentd_found = 0;
|
2014-01-16 01:53:03 +01:00
|
|
|
for (;;) {
|
2001-09-16 21:50:48 +00:00
|
|
|
c = *p++;
|
|
|
|
|
if (c == '\0')
|
|
|
|
|
break;
|
|
|
|
|
if (c == '%') {
|
2002-12-11 03:20:05 +00:00
|
|
|
do {
|
|
|
|
|
nd = 0;
|
2020-08-15 22:52:42 +02:00
|
|
|
while (av_isdigit(*p)) {
|
|
|
|
|
if (nd >= INT_MAX / 10 - 255)
|
|
|
|
|
goto fail;
|
2002-12-11 03:20:05 +00:00
|
|
|
nd = nd * 10 + *p++ - '0';
|
2020-08-15 22:52:42 +02:00
|
|
|
}
|
2002-12-11 03:20:05 +00:00
|
|
|
c = *p++;
|
2013-03-03 11:17:50 +01:00
|
|
|
} while (av_isdigit(c));
|
2002-12-11 03:20:05 +00:00
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
switch (c) {
|
2001-09-16 21:50:48 +00:00
|
|
|
case '%':
|
|
|
|
|
goto addchar;
|
|
|
|
|
case 'd':
|
2016-08-03 20:34:20 +02:00
|
|
|
if (!(flags & AV_FRAME_FILENAME_FLAGS_MULTIPLE) && percentd_found)
|
2001-09-16 21:50:48 +00:00
|
|
|
goto fail;
|
|
|
|
|
percentd_found = 1;
|
2015-02-04 13:01:25 +01:00
|
|
|
if (number < 0)
|
2015-02-03 09:01:29 -08:00
|
|
|
nd += 1;
|
2001-09-16 21:50:48 +00:00
|
|
|
snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
|
|
|
|
|
len = strlen(buf1);
|
|
|
|
|
if ((q - buf + len) > buf_size - 1)
|
|
|
|
|
goto fail;
|
|
|
|
|
memcpy(q, buf1, len);
|
|
|
|
|
q += len;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-01-16 01:53:03 +01:00
|
|
|
addchar:
|
2001-09-16 21:50:48 +00:00
|
|
|
if ((q - buf) < buf_size - 1)
|
|
|
|
|
*q++ = c;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-01 22:58:01 +01:00
|
|
|
if (!percentd_found)
|
2001-09-16 21:50:48 +00:00
|
|
|
goto fail;
|
|
|
|
|
*q = '\0';
|
|
|
|
|
return 0;
|
2014-01-16 01:53:03 +01:00
|
|
|
fail:
|
2001-09-16 21:50:48 +00:00
|
|
|
*q = '\0';
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 20:34:20 +02:00
|
|
|
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
|
|
|
|
|
{
|
2016-11-01 22:58:01 +01:00
|
|
|
return av_get_frame_filename2(buf, buf_size, path, number, 0);
|
2016-08-03 20:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-27 14:16:46 +00:00
|
|
|
void av_url_split(char *proto, int proto_size,
|
|
|
|
|
char *authorization, int authorization_size,
|
|
|
|
|
char *hostname, int hostname_size,
|
2014-01-16 01:53:03 +01:00
|
|
|
int *port_ptr, char *path, int path_size, const char *url)
|
2002-07-24 18:04:50 +00:00
|
|
|
{
|
2020-02-03 01:32:00 +01:00
|
|
|
const char *p, *ls, *at, *at2, *col, *brk;
|
2007-09-27 19:18:07 +00:00
|
|
|
|
2014-01-16 01:53:03 +01:00
|
|
|
if (port_ptr)
|
|
|
|
|
*port_ptr = -1;
|
|
|
|
|
if (proto_size > 0)
|
|
|
|
|
proto[0] = 0;
|
|
|
|
|
if (authorization_size > 0)
|
|
|
|
|
authorization[0] = 0;
|
|
|
|
|
if (hostname_size > 0)
|
|
|
|
|
hostname[0] = 0;
|
|
|
|
|
if (path_size > 0)
|
|
|
|
|
path[0] = 0;
|
2007-09-27 19:18:07 +00:00
|
|
|
|
|
|
|
|
/* parse protocol */
|
|
|
|
|
if ((p = strchr(url, ':'))) {
|
|
|
|
|
av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url));
|
|
|
|
|
p++; /* skip ':' */
|
2014-01-16 01:53:03 +01:00
|
|
|
if (*p == '/')
|
|
|
|
|
p++;
|
|
|
|
|
if (*p == '/')
|
|
|
|
|
p++;
|
2002-07-24 18:04:50 +00:00
|
|
|
} else {
|
2007-09-27 19:18:07 +00:00
|
|
|
/* no protocol means plain filename */
|
|
|
|
|
av_strlcpy(path, url, path_size);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-08-12 00:09:32 +00:00
|
|
|
|
2007-09-27 19:18:07 +00:00
|
|
|
/* separate path from hostname */
|
2020-02-03 01:32:00 +01:00
|
|
|
ls = p + strcspn(p, "/?#");
|
|
|
|
|
av_strlcpy(path, ls, path_size);
|
2007-09-27 19:18:07 +00:00
|
|
|
|
|
|
|
|
/* the rest is hostname, use that to parse auth/port */
|
|
|
|
|
if (ls != p) {
|
|
|
|
|
/* authorization (user[:pass]@hostname) */
|
2012-11-15 10:56:47 +00:00
|
|
|
at2 = p;
|
|
|
|
|
while ((at = strchr(p, '@')) && at < ls) {
|
|
|
|
|
av_strlcpy(authorization, at2,
|
|
|
|
|
FFMIN(authorization_size, at + 1 - at2));
|
2007-09-27 19:18:07 +00:00
|
|
|
p = at + 1; /* skip '@' */
|
2002-07-24 18:04:50 +00:00
|
|
|
}
|
2007-09-27 19:18:07 +00:00
|
|
|
|
2007-09-29 14:35:52 +00:00
|
|
|
if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) {
|
|
|
|
|
/* [host]:port */
|
|
|
|
|
av_strlcpy(hostname, p + 1,
|
|
|
|
|
FFMIN(hostname_size, brk - p));
|
|
|
|
|
if (brk[1] == ':' && port_ptr)
|
|
|
|
|
*port_ptr = atoi(brk + 2);
|
|
|
|
|
} else if ((col = strchr(p, ':')) && col < ls) {
|
|
|
|
|
av_strlcpy(hostname, p,
|
|
|
|
|
FFMIN(col + 1 - p, hostname_size));
|
2014-01-16 01:53:03 +01:00
|
|
|
if (port_ptr)
|
|
|
|
|
*port_ptr = atoi(col + 1);
|
2007-09-29 14:35:52 +00:00
|
|
|
} else
|
|
|
|
|
av_strlcpy(hostname, p,
|
|
|
|
|
FFMIN(ls + 1 - p, hostname_size));
|
2002-07-24 18:04:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 22:10:09 +08:00
|
|
|
int ff_mkdir_p(const char *path)
|
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
|
|
|
|
char *temp = av_strdup(path);
|
|
|
|
|
char *pos = temp;
|
|
|
|
|
char tmp_ch = '\0';
|
|
|
|
|
|
|
|
|
|
if (!path || !temp) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!av_strncasecmp(temp, "/", 1) || !av_strncasecmp(temp, "\\", 1)) {
|
|
|
|
|
pos++;
|
|
|
|
|
} else if (!av_strncasecmp(temp, "./", 2) || !av_strncasecmp(temp, ".\\", 2)) {
|
|
|
|
|
pos += 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( ; *pos != '\0'; ++pos) {
|
|
|
|
|
if (*pos == '/' || *pos == '\\') {
|
|
|
|
|
tmp_ch = *pos;
|
|
|
|
|
*pos = '\0';
|
|
|
|
|
ret = mkdir(temp, 0755);
|
|
|
|
|
*pos = tmp_ch;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 18:28:32 +11:00
|
|
|
if ((*(pos - 1) != '/') && (*(pos - 1) != '\\')) {
|
2018-09-22 22:10:09 +08:00
|
|
|
ret = mkdir(temp, 0755);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
av_free(temp);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-25 07:13:20 +00:00
|
|
|
char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
|
2008-08-27 23:43:28 +00:00
|
|
|
{
|
2010-03-25 07:13:20 +00:00
|
|
|
static const char hex_table_uc[16] = { '0', '1', '2', '3',
|
2010-03-25 07:14:41 +00:00
|
|
|
'4', '5', '6', '7',
|
|
|
|
|
'8', '9', 'A', 'B',
|
|
|
|
|
'C', 'D', 'E', 'F' };
|
2010-03-25 07:13:20 +00:00
|
|
|
static const char hex_table_lc[16] = { '0', '1', '2', '3',
|
|
|
|
|
'4', '5', '6', '7',
|
|
|
|
|
'8', '9', 'a', 'b',
|
|
|
|
|
'c', 'd', 'e', 'f' };
|
|
|
|
|
const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
|
2008-08-27 23:43:28 +00:00
|
|
|
|
2021-08-24 17:47:04 +02:00
|
|
|
for (int i = 0; i < s; i++) {
|
2008-08-28 12:00:58 +00:00
|
|
|
buff[i * 2] = hex_table[src[i] >> 4];
|
|
|
|
|
buff[i * 2 + 1] = hex_table[src[i] & 0xF];
|
2008-08-27 23:43:28 +00:00
|
|
|
}
|
2021-12-05 18:52:29 +01:00
|
|
|
buff[2 * s] = '\0';
|
2008-08-27 23:43:28 +00:00
|
|
|
|
|
|
|
|
return buff;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 10:05:33 +00:00
|
|
|
int ff_hex_to_data(uint8_t *data, const char *p)
|
|
|
|
|
{
|
|
|
|
|
int c, len, v;
|
|
|
|
|
|
|
|
|
|
len = 0;
|
2014-01-16 01:53:03 +01:00
|
|
|
v = 1;
|
2010-08-09 10:05:33 +00:00
|
|
|
for (;;) {
|
|
|
|
|
p += strspn(p, SPACE_CHARS);
|
|
|
|
|
if (*p == '\0')
|
|
|
|
|
break;
|
2013-03-03 11:17:50 +01:00
|
|
|
c = av_toupper((unsigned char) *p++);
|
2010-08-09 10:05:33 +00:00
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
|
c = c - '0';
|
|
|
|
|
else if (c >= 'A' && c <= 'F')
|
|
|
|
|
c = c - 'A' + 10;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
v = (v << 4) | c;
|
|
|
|
|
if (v & 0x100) {
|
|
|
|
|
if (data)
|
|
|
|
|
data[len] = v;
|
|
|
|
|
len++;
|
|
|
|
|
v = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 17:08:49 +02:00
|
|
|
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
|
2011-11-29 19:28:15 +01:00
|
|
|
unsigned int pts_num, unsigned int pts_den)
|
2002-10-21 15:54:49 +00:00
|
|
|
{
|
2021-09-09 17:08:49 +02:00
|
|
|
FFStream *const sti = ffstream(st);
|
2011-02-06 15:27:30 +01:00
|
|
|
AVRational new_tb;
|
2014-01-16 01:53:03 +01:00
|
|
|
if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
|
|
|
|
|
if (new_tb.num != pts_num)
|
|
|
|
|
av_log(NULL, AV_LOG_DEBUG,
|
|
|
|
|
"st:%d removing common factor %d from timebase\n",
|
2021-09-09 17:08:49 +02:00
|
|
|
st->index, pts_num / new_tb.num);
|
2014-01-16 01:53:03 +01:00
|
|
|
} else
|
|
|
|
|
av_log(NULL, AV_LOG_WARNING,
|
2021-09-09 17:08:49 +02:00
|
|
|
"st:%d has too large timebase, reducing\n", st->index);
|
2014-01-16 01:53:03 +01:00
|
|
|
|
|
|
|
|
if (new_tb.num <= 0 || new_tb.den <= 0) {
|
|
|
|
|
av_log(NULL, AV_LOG_ERROR,
|
2014-01-26 23:35:38 +01:00
|
|
|
"Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
|
|
|
|
|
new_tb.num, new_tb.den,
|
2021-09-09 17:08:49 +02:00
|
|
|
st->index);
|
2011-02-06 15:27:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-09-09 17:08:49 +02:00
|
|
|
st->time_base = new_tb;
|
2021-08-24 19:41:16 +02:00
|
|
|
sti->avctx->pkt_timebase = new_tb;
|
2021-09-09 17:08:49 +02:00
|
|
|
st->pts_wrap_bits = pts_wrap_bits;
|
2002-10-21 15:54:49 +00:00
|
|
|
}
|
2010-03-05 22:31:45 +00:00
|
|
|
|
2010-08-19 14:49:53 +00:00
|
|
|
void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
|
|
|
|
|
void *context)
|
|
|
|
|
{
|
|
|
|
|
const char *ptr = str;
|
|
|
|
|
|
|
|
|
|
/* Parse key=value pairs. */
|
|
|
|
|
for (;;) {
|
|
|
|
|
const char *key;
|
|
|
|
|
char *dest = NULL, *dest_end;
|
|
|
|
|
int key_len, dest_len = 0;
|
|
|
|
|
|
|
|
|
|
/* Skip whitespace and potential commas. */
|
2013-03-03 11:17:50 +01:00
|
|
|
while (*ptr && (av_isspace(*ptr) || *ptr == ','))
|
2010-08-19 14:49:53 +00:00
|
|
|
ptr++;
|
|
|
|
|
if (!*ptr)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
key = ptr;
|
|
|
|
|
|
|
|
|
|
if (!(ptr = strchr(key, '=')))
|
|
|
|
|
break;
|
|
|
|
|
ptr++;
|
|
|
|
|
key_len = ptr - key;
|
|
|
|
|
|
|
|
|
|
callback_get_buf(context, key, key_len, &dest, &dest_len);
|
2022-02-04 00:44:32 +01:00
|
|
|
dest_end = dest ? dest + dest_len - 1 : NULL;
|
2010-08-19 14:49:53 +00:00
|
|
|
|
|
|
|
|
if (*ptr == '\"') {
|
|
|
|
|
ptr++;
|
|
|
|
|
while (*ptr && *ptr != '\"') {
|
|
|
|
|
if (*ptr == '\\') {
|
|
|
|
|
if (!ptr[1])
|
|
|
|
|
break;
|
|
|
|
|
if (dest && dest < dest_end)
|
|
|
|
|
*dest++ = ptr[1];
|
|
|
|
|
ptr += 2;
|
|
|
|
|
} else {
|
|
|
|
|
if (dest && dest < dest_end)
|
|
|
|
|
*dest++ = *ptr;
|
|
|
|
|
ptr++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (*ptr == '\"')
|
|
|
|
|
ptr++;
|
|
|
|
|
} else {
|
2013-03-03 11:17:50 +01:00
|
|
|
for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++)
|
2010-08-19 14:49:53 +00:00
|
|
|
if (dest && dest < dest_end)
|
|
|
|
|
*dest++ = *ptr;
|
|
|
|
|
}
|
|
|
|
|
if (dest)
|
|
|
|
|
*dest = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-07 10:54:33 +01:00
|
|
|
int ff_find_stream_index(const AVFormatContext *s, int id)
|
2010-12-26 01:24:51 +00:00
|
|
|
{
|
2021-08-24 17:47:04 +02:00
|
|
|
for (unsigned i = 0; i < s->nb_streams; i++)
|
2010-12-26 01:24:51 +00:00
|
|
|
if (s->streams[i]->id == id)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2011-03-17 12:24:23 +02:00
|
|
|
|
2011-11-01 13:40:04 +02:00
|
|
|
int avformat_network_init(void)
|
|
|
|
|
{
|
|
|
|
|
#if CONFIG_NETWORK
|
|
|
|
|
int ret;
|
|
|
|
|
if ((ret = ff_network_init()) < 0)
|
|
|
|
|
return ret;
|
2015-01-22 15:50:48 +01:00
|
|
|
if ((ret = ff_tls_init()) < 0)
|
|
|
|
|
return ret;
|
2011-11-01 13:40:04 +02:00
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int avformat_network_deinit(void)
|
|
|
|
|
{
|
|
|
|
|
#if CONFIG_NETWORK
|
|
|
|
|
ff_network_close();
|
|
|
|
|
ff_tls_deinit();
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-12-16 12:48:09 +02:00
|
|
|
|
2021-11-30 00:38:30 +01:00
|
|
|
void ff_format_io_close_default(AVFormatContext *s, AVIOContext *pb)
|
2016-01-16 17:53:43 +01:00
|
|
|
{
|
2021-11-30 00:38:30 +01:00
|
|
|
avio_close(pb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
|
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
|
|
|
|
if (*pb) {
|
|
|
|
|
if (s->io_close == ff_format_io_close_default || s->io_close == NULL)
|
|
|
|
|
ret = s->io_close2(s, *pb);
|
|
|
|
|
else
|
|
|
|
|
s->io_close(s, *pb);
|
|
|
|
|
}
|
2016-01-16 17:53:43 +01:00
|
|
|
*pb = NULL;
|
2021-11-30 00:38:30 +01:00
|
|
|
return ret;
|
2016-01-16 17:53:43 +01:00
|
|
|
}
|
2016-02-04 03:28:19 +01:00
|
|
|
|
2021-08-20 19:31:13 +08:00
|
|
|
int ff_is_http_proto(const char *filename) {
|
2017-12-29 18:11:09 +08:00
|
|
|
const char *proto = avio_find_protocol_name(filename);
|
|
|
|
|
return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-31 21:49:02 +01:00
|
|
|
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
ret = av_bprint_finalize(buf, &str);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
return ret;
|
|
|
|
|
if (!av_bprint_is_complete(buf)) {
|
|
|
|
|
av_free(str);
|
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
par->extradata = str;
|
|
|
|
|
/* Note: the string is NUL terminated (so extradata can be read as a
|
|
|
|
|
* string), but the ending character is not accounted in the size (in
|
|
|
|
|
* binary formats you are likely not supposed to mux that character). When
|
|
|
|
|
* extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
|
|
|
|
|
* zeros. */
|
|
|
|
|
par->extradata_size = buf->len;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-09-09 16:38:21 +02:00
|
|
|
|
2017-12-29 01:01:37 +01:00
|
|
|
void ff_format_set_url(AVFormatContext *s, char *url)
|
|
|
|
|
{
|
|
|
|
|
av_assert0(url);
|
|
|
|
|
av_freep(&s->url);
|
|
|
|
|
s->url = url;
|
|
|
|
|
}
|