mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
obs-ffmpeg: Respect AVFormatContext and AVOutputFormat constness
AVFormatContext::oformat was made const on April 27, 2021 [1]. If we
respect the constness of AVOutputFormat and do not cast results from
FFmpeg functions to non-const, we cannot modify the results after the
fact. Our choices are either to cast them to non-const (and presumably
have them implicitly casted back to const on later function calls), or
only try to modify the results in versions of FFmpeg where these are not
expected to be const.
Instead of relying on casts, we can set the encoder values in the
ffmpeg_cfg struct, which are later passed to new_stream.
Also modifies deps/media-playback. Removes compiler warnings.
Some avformat functions return const AV(In/Out)putFormat per [1], so
ifdef as needed.
[1]: 56450a0ee4
lavf 59.0.100 avformat.h
avformat: Constify the API wrt AV(In|Out)putFormat
Also constify AVProbeData.
This commit is contained in:
parent
abf1d609d2
commit
ce734366bc
4
deps/media-playback/media-playback/media.c
vendored
4
deps/media-playback/media-playback/media.c
vendored
|
@ -608,7 +608,11 @@ static int interrupt_callback(void *data)
|
|||
|
||||
static bool init_avformat(mp_media_t *m)
|
||||
{
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
|
||||
AVInputFormat *format = NULL;
|
||||
#else
|
||||
const AVInputFormat *format = NULL;
|
||||
#endif
|
||||
|
||||
if (m->format_name && *m->format_name) {
|
||||
format = av_find_input_format(m->format_name);
|
||||
|
|
|
@ -565,7 +565,11 @@ static inline bool ffmpeg_mux_get_extra_data(struct ffmpeg_mux *ffm)
|
|||
|
||||
static inline int open_output_file(struct ffmpeg_mux *ffm)
|
||||
{
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
|
||||
AVOutputFormat *format = ffm->output->oformat;
|
||||
#else
|
||||
const AVOutputFormat *format = ffm->output->oformat;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
if ((format->flags & AVFMT_NOFILE) == 0) {
|
||||
|
@ -631,7 +635,11 @@ static bool ffmpeg_mux_is_network(struct ffmpeg_mux *ffm)
|
|||
|
||||
static int ffmpeg_mux_init_context(struct ffmpeg_mux *ffm)
|
||||
{
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
|
||||
AVOutputFormat *output_format;
|
||||
#else
|
||||
const AVOutputFormat *output_format;
|
||||
#endif
|
||||
int ret;
|
||||
bool is_http = false;
|
||||
is_http = (strncmp(ffm->params.file, HTTP_PROTO,
|
||||
|
@ -665,8 +673,10 @@ static int ffmpeg_mux_init_context(struct ffmpeg_mux *ffm)
|
|||
return FFM_ERROR;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
|
||||
ffm->output->oformat->video_codec = AV_CODEC_ID_NONE;
|
||||
ffm->output->oformat->audio_codec = AV_CODEC_ID_NONE;
|
||||
#endif
|
||||
|
||||
if (!init_streams(ffm)) {
|
||||
free_avformat(ffm);
|
||||
|
|
|
@ -543,6 +543,7 @@ static enum AVCodecID get_codec_id(const char *name, int id)
|
|||
return codec->id;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
|
||||
static void set_encoder_ids(struct ffmpeg_data *data)
|
||||
{
|
||||
data->output->oformat->video_codec = get_codec_id(
|
||||
|
@ -551,6 +552,7 @@ static void set_encoder_ids(struct ffmpeg_data *data)
|
|||
data->output->oformat->audio_codec = get_codec_id(
|
||||
data->config.audio_encoder, data->config.audio_encoder_id);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
|
||||
{
|
||||
|
@ -570,7 +572,13 @@ bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
|
|||
|
||||
is_rtmp = (astrcmpi_n(config->url, "rtmp://", 7) == 0);
|
||||
|
||||
AVOutputFormat *output_format = av_guess_format(
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
|
||||
AVOutputFormat *output_format;
|
||||
#else
|
||||
const AVOutputFormat *output_format;
|
||||
#endif
|
||||
|
||||
output_format = av_guess_format(
|
||||
is_rtmp ? "flv" : data->config.format_name, data->config.url,
|
||||
is_rtmp ? NULL : data->config.format_mime_type);
|
||||
|
||||
|
@ -596,6 +604,7 @@ bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
|
||||
if (is_rtmp) {
|
||||
data->output->oformat->video_codec = AV_CODEC_ID_H264;
|
||||
data->output->oformat->audio_codec = AV_CODEC_ID_AAC;
|
||||
|
@ -603,6 +612,14 @@ bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
|
|||
if (data->config.format_name)
|
||||
set_encoder_ids(data);
|
||||
}
|
||||
#else
|
||||
if (is_rtmp) {
|
||||
data->config.audio_encoder = "aac";
|
||||
data->config.audio_encoder_id = AV_CODEC_ID_AAC;
|
||||
data->config.video_encoder = "libx264";
|
||||
data->config.video_encoder_id = AV_CODEC_ID_H264;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!init_streams(data))
|
||||
goto fail;
|
||||
|
|
Loading…
Reference in a new issue