parent
a68a8c47a4
commit
aa73d96c7c
@ -0,0 +1,182 @@ |
||||
#include "ffmpeg_context.h" |
||||
|
||||
FFmpegContext *saveFFmpegContext() { |
||||
FFmpegContext *context = (FFmpegContext *)av_mallocz(sizeof(FFmpegContext)); |
||||
|
||||
// cmdutils.c
|
||||
context->sws_dict = sws_dict; |
||||
context->swr_opts = swr_opts; |
||||
context->format_opts = format_opts; |
||||
context->codec_opts = codec_opts; |
||||
context->hide_banner = hide_banner; |
||||
#if HAVE_COMMANDLINETOARGVW && defined(_WIN32) |
||||
/* Will be leaked on exit */ |
||||
context->win32_argv_utf8 = win32_argv_utf8; |
||||
context->win32_argc = win32_argc; |
||||
#endif |
||||
|
||||
// ffmpeg.c
|
||||
context->vstats_file = vstats_file; |
||||
context->nb_output_dumped = nb_output_dumped; |
||||
context->current_time = current_time; |
||||
context->progress_avio = progress_avio; |
||||
context->input_files = input_files; |
||||
context->nb_input_files = nb_input_files; |
||||
context->output_files = output_files; |
||||
context->nb_output_files = nb_output_files; |
||||
context->filtergraphs = filtergraphs; |
||||
context->nb_filtergraphs = nb_filtergraphs; |
||||
#if HAVE_TERMIOS_H |
||||
/* init terminal so that we can grab keys */ |
||||
context->oldtty = oldtty; |
||||
context->restore_tty = restore_tty; |
||||
#endif |
||||
context->received_sigterm = received_sigterm; |
||||
context->received_nb_signals = received_nb_signals; |
||||
context->transcode_init_done = transcode_init_done; |
||||
context->ffmpeg_exited = ffmpeg_exited; |
||||
context->copy_ts_first_pts = copy_ts_first_pts; |
||||
|
||||
// ffmpeg_hw.c
|
||||
context->nb_hw_devices = nb_hw_devices; |
||||
context->hw_devices = hw_devices; |
||||
|
||||
// ffmpeg_mux.c
|
||||
context->want_sdp = want_sdp; |
||||
|
||||
// ffmpeg_mux_init.c
|
||||
context->enc_stats_files = enc_stats_files; |
||||
context->nb_enc_stats_files = nb_enc_stats_files; |
||||
|
||||
// ffmpeg_opt.c
|
||||
context->filter_hw_device = filter_hw_device; |
||||
context->vstats_filename = vstats_filename; |
||||
context->sdp_filename = sdp_filename; |
||||
context->audio_drift_threshold = audio_drift_threshold; |
||||
context->dts_delta_threshold = dts_delta_threshold; |
||||
context->dts_error_threshold = dts_error_threshold; |
||||
context->video_sync_method = video_sync_method; |
||||
context->frame_drop_threshold = frame_drop_threshold; |
||||
context->do_benchmark = do_benchmark; |
||||
context->do_benchmark_all = do_benchmark_all; |
||||
context->do_hex_dump = do_hex_dump; |
||||
context->do_pkt_dump = do_pkt_dump; |
||||
context->copy_ts = copy_ts; |
||||
context->start_at_zero = start_at_zero; |
||||
context->copy_tb = copy_tb; |
||||
context->debug_ts = debug_ts; |
||||
context->exit_on_error = exit_on_error; |
||||
context->abort_on_flags = abort_on_flags; |
||||
context->print_stats = print_stats; |
||||
context->stdin_interaction = stdin_interaction; |
||||
context->max_error_rate = max_error_rate; |
||||
context->filter_nbthreads = filter_nbthreads; |
||||
context->filter_complex_nbthreads = filter_complex_nbthreads; |
||||
context->vstats_version = vstats_version; |
||||
context->auto_conversion_filters = auto_conversion_filters; |
||||
context->stats_period = stats_period; |
||||
context->file_overwrite = file_overwrite; |
||||
context->no_file_overwrite = no_file_overwrite; |
||||
#if FFMPEG_OPT_PSNR |
||||
context->do_psnr = do_psnr; |
||||
#endif |
||||
context->ignore_unknown_streams = ignore_unknown_streams; |
||||
context->copy_unknown_streams = copy_unknown_streams; |
||||
context->recast_media = recast_media; |
||||
|
||||
// opt_common.c
|
||||
context->report_file = report_file; |
||||
context->report_file_level = report_file_level; |
||||
context->warned_cfg = warned_cfg; |
||||
|
||||
return context; |
||||
} |
||||
|
||||
void loadFFmpegContext(FFmpegContext *context) { |
||||
|
||||
// cmdutils.c
|
||||
sws_dict = context->sws_dict; |
||||
swr_opts = context->swr_opts; |
||||
format_opts = context->format_opts; |
||||
codec_opts = context->codec_opts; |
||||
hide_banner = context->hide_banner; |
||||
#if HAVE_COMMANDLINETOARGVW && defined(_WIN32) |
||||
/* Will be leaked on exit */ |
||||
win32_argv_utf8 = context->win32_argv_utf8; |
||||
win32_argc = context->win32_argc; |
||||
#endif |
||||
|
||||
// ffmpeg.c
|
||||
vstats_file = context->vstats_file; |
||||
nb_output_dumped = context->nb_output_dumped; |
||||
current_time = context->current_time; |
||||
progress_avio = context->progress_avio; |
||||
input_files = context->input_files; |
||||
nb_input_files = context->nb_input_files; |
||||
output_files = context->output_files; |
||||
nb_output_files = context->nb_output_files; |
||||
filtergraphs = context->filtergraphs; |
||||
nb_filtergraphs = context->nb_filtergraphs; |
||||
#if HAVE_TERMIOS_H |
||||
/* init terminal so that we can grab keys */ |
||||
oldtty = context->oldtty; |
||||
restore_tty = context->restore_tty; |
||||
#endif |
||||
received_sigterm = context->received_sigterm; |
||||
received_nb_signals = context->received_nb_signals; |
||||
transcode_init_done = context->transcode_init_done; |
||||
ffmpeg_exited = context->ffmpeg_exited; |
||||
copy_ts_first_pts = context->copy_ts_first_pts; |
||||
|
||||
// ffmpeg_hw.c
|
||||
nb_hw_devices = context->nb_hw_devices; |
||||
hw_devices = context->hw_devices; |
||||
|
||||
// ffmpeg_mux.c
|
||||
want_sdp = context->want_sdp; |
||||
|
||||
// ffmpeg_mux_init.c
|
||||
enc_stats_files = context->enc_stats_files; |
||||
nb_enc_stats_files = context->nb_enc_stats_files; |
||||
|
||||
// ffmpeg_opt.c
|
||||
filter_hw_device = context->filter_hw_device; |
||||
vstats_filename = context->vstats_filename; |
||||
sdp_filename = context->sdp_filename; |
||||
audio_drift_threshold = context->audio_drift_threshold; |
||||
dts_delta_threshold = context->dts_delta_threshold; |
||||
dts_error_threshold = context->dts_error_threshold; |
||||
video_sync_method = context->video_sync_method; |
||||
frame_drop_threshold = context->frame_drop_threshold; |
||||
do_benchmark = context->do_benchmark; |
||||
do_benchmark_all = context->do_benchmark_all; |
||||
do_hex_dump = context->do_hex_dump; |
||||
do_pkt_dump = context->do_pkt_dump; |
||||
copy_ts = context->copy_ts; |
||||
start_at_zero = context->start_at_zero; |
||||
copy_tb = context->copy_tb; |
||||
debug_ts = context->debug_ts; |
||||
exit_on_error = context->exit_on_error; |
||||
abort_on_flags = context->abort_on_flags; |
||||
print_stats = context->print_stats; |
||||
stdin_interaction = context->stdin_interaction; |
||||
max_error_rate = context->max_error_rate; |
||||
filter_nbthreads = context->filter_nbthreads; |
||||
filter_complex_nbthreads = context->filter_complex_nbthreads; |
||||
vstats_version = context->vstats_version; |
||||
auto_conversion_filters = context->auto_conversion_filters; |
||||
stats_period = context->stats_period; |
||||
file_overwrite = context->file_overwrite; |
||||
no_file_overwrite = context->no_file_overwrite; |
||||
#if FFMPEG_OPT_PSNR |
||||
do_psnr = context->do_psnr; |
||||
#endif |
||||
ignore_unknown_streams = context->ignore_unknown_streams; |
||||
copy_unknown_streams = context->copy_unknown_streams; |
||||
recast_media = context->recast_media; |
||||
|
||||
// opt_common.c
|
||||
report_file = context->report_file; |
||||
report_file_level = context->report_file_level; |
||||
warned_cfg = context->warned_cfg; |
||||
} |
||||
@ -0,0 +1,145 @@ |
||||
/*
|
||||
* Copyright (c) 2024 ARTHENICA LTD |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_CONTEXT_H |
||||
#define FFMPEG_CONTEXT_H |
||||
|
||||
#if HAVE_TERMIOS_H |
||||
#include <termios.h> |
||||
#endif |
||||
|
||||
#include "fftools_ffmpeg.h" |
||||
#include "libavformat/avio.h" |
||||
#include "libavutil/dict.h" |
||||
|
||||
extern __thread BenchmarkTimeStamps current_time; |
||||
extern __thread struct termios oldtty; |
||||
extern __thread int restore_tty; |
||||
extern __thread volatile int received_sigterm; |
||||
extern __thread volatile int received_nb_signals; |
||||
extern __thread atomic_int transcode_init_done; |
||||
extern __thread volatile int ffmpeg_exited; |
||||
extern __thread int64_t copy_ts_first_pts; |
||||
extern __thread int nb_hw_devices; |
||||
extern __thread HWDevice **hw_devices; |
||||
extern __thread int want_sdp; |
||||
extern __thread struct EncStatsFile *enc_stats_files; |
||||
extern __thread int nb_enc_stats_files; |
||||
extern __thread float audio_drift_threshold; |
||||
extern __thread int file_overwrite; |
||||
extern __thread int no_file_overwrite; |
||||
extern __thread FILE *report_file; |
||||
extern __thread int report_file_level; |
||||
extern __thread int warned_cfg; |
||||
|
||||
typedef struct FFmpegContext { |
||||
|
||||
// cmdutils.c
|
||||
AVDictionary *sws_dict; |
||||
AVDictionary *swr_opts; |
||||
AVDictionary *format_opts, *codec_opts; |
||||
int hide_banner; |
||||
#if HAVE_COMMANDLINETOARGVW && defined(_WIN32) |
||||
/* Will be leaked on exit */ |
||||
char **win32_argv_utf8; |
||||
int win32_argc; |
||||
#endif |
||||
|
||||
// ffmpeg.c
|
||||
FILE *vstats_file; |
||||
unsigned nb_output_dumped; |
||||
BenchmarkTimeStamps current_time; |
||||
AVIOContext *progress_avio; |
||||
InputFile **input_files; |
||||
int nb_input_files; |
||||
OutputFile **output_files; |
||||
int nb_output_files; |
||||
FilterGraph **filtergraphs; |
||||
int nb_filtergraphs; |
||||
#if HAVE_TERMIOS_H |
||||
/* init terminal so that we can grab keys */ |
||||
struct termios oldtty; |
||||
int restore_tty; |
||||
#endif |
||||
volatile int received_sigterm; |
||||
volatile int received_nb_signals; |
||||
atomic_int transcode_init_done; |
||||
volatile int ffmpeg_exited; |
||||
int64_t copy_ts_first_pts; |
||||
|
||||
// ffmpeg_hw.c
|
||||
int nb_hw_devices; |
||||
HWDevice **hw_devices; |
||||
|
||||
// ffmpeg_mux.c
|
||||
int want_sdp; |
||||
|
||||
// ffmpeg_mux_init.c
|
||||
EncStatsFile *enc_stats_files; |
||||
int nb_enc_stats_files; |
||||
|
||||
// ffmpeg_opt.c
|
||||
HWDevice *filter_hw_device; |
||||
char *vstats_filename; |
||||
char *sdp_filename; |
||||
float audio_drift_threshold; |
||||
float dts_delta_threshold; |
||||
float dts_error_threshold; |
||||
enum VideoSyncMethod video_sync_method; |
||||
float frame_drop_threshold; |
||||
int do_benchmark; |
||||
int do_benchmark_all; |
||||
int do_hex_dump; |
||||
int do_pkt_dump; |
||||
int copy_ts; |
||||
int start_at_zero; |
||||
int copy_tb; |
||||
int debug_ts; |
||||
int exit_on_error; |
||||
int abort_on_flags; |
||||
int print_stats; |
||||
int stdin_interaction; |
||||
float max_error_rate; |
||||
char *filter_nbthreads; |
||||
int filter_complex_nbthreads; |
||||
int vstats_version; |
||||
int auto_conversion_filters; |
||||
int64_t stats_period; |
||||
int file_overwrite; |
||||
int no_file_overwrite; |
||||
#if FFMPEG_OPT_PSNR |
||||
int do_psnr; |
||||
#endif |
||||
int ignore_unknown_streams; |
||||
int copy_unknown_streams; |
||||
int recast_media; |
||||
|
||||
// opt_common.c
|
||||
FILE *report_file; |
||||
int report_file_level; |
||||
int warned_cfg; |
||||
|
||||
void *arg; |
||||
|
||||
} FFmpegContext; |
||||
|
||||
FFmpegContext *saveFFmpegContext(); |
||||
void loadFFmpegContext(FFmpegContext *context); |
||||
|
||||
#endif // FFMPEG_CONTEXT_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,962 @@ |
||||
/*
|
||||
* 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 |
||||
*/ |
||||
|
||||
/*
|
||||
* This file is the modified version of ffmpeg_enc.c file living in ffmpeg |
||||
* source code under the fftools folder. We manually update it each time we |
||||
* depend on a new ffmpeg version. Below you can see the list of changes applied |
||||
* by us to ffmpeg-kit library. |
||||
* |
||||
* ffmpeg-kit changes by ARTHENICA LTD |
||||
* |
||||
* 11.2024 |
||||
* -------------------------------------------------------- |
||||
* - Migrated from FFmpeg 6.1 |
||||
*/ |
||||
|
||||
#include <math.h> |
||||
#include <stdint.h> |
||||
|
||||
#include "fftools_ffmpeg.h" |
||||
|
||||
#include "libavutil/avassert.h" |
||||
#include "libavutil/avstring.h" |
||||
#include "libavutil/avutil.h" |
||||
#include "libavutil/dict.h" |
||||
#include "libavutil/display.h" |
||||
#include "libavutil/eval.h" |
||||
#include "libavutil/frame.h" |
||||
#include "libavutil/intreadwrite.h" |
||||
#include "libavutil/log.h" |
||||
#include "libavutil/pixdesc.h" |
||||
#include "libavutil/rational.h" |
||||
#include "libavutil/timestamp.h" |
||||
|
||||
#include "libavcodec/avcodec.h" |
||||
|
||||
#include "libavformat/avformat.h" |
||||
|
||||
struct Encoder { |
||||
AVFrame *sq_frame; |
||||
|
||||
// packet for receiving encoded output
|
||||
AVPacket *pkt; |
||||
|
||||
// combined size of all the packets received from the encoder
|
||||
uint64_t data_size; |
||||
|
||||
// number of packets received from the encoder
|
||||
uint64_t packets_encoded; |
||||
|
||||
int opened; |
||||
}; |
||||
|
||||
void enc_free(Encoder **penc) { |
||||
Encoder *enc = *penc; |
||||
|
||||
if (!enc) |
||||
return; |
||||
|
||||
av_frame_free(&enc->sq_frame); |
||||
|
||||
av_packet_free(&enc->pkt); |
||||
|
||||
av_freep(penc); |
||||
} |
||||
|
||||
int enc_alloc(Encoder **penc, const AVCodec *codec) { |
||||
Encoder *enc; |
||||
|
||||
*penc = NULL; |
||||
|
||||
enc = av_mallocz(sizeof(*enc)); |
||||
if (!enc) |
||||
return AVERROR(ENOMEM); |
||||
|
||||
enc->pkt = av_packet_alloc(); |
||||
if (!enc->pkt) |
||||
goto fail; |
||||
|
||||
*penc = enc; |
||||
|
||||
return 0; |
||||
fail: |
||||
enc_free(&enc); |
||||
return AVERROR(ENOMEM); |
||||
} |
||||
|
||||
static int hw_device_setup_for_encode(OutputStream *ost, |
||||
AVBufferRef *frames_ref) { |
||||
const AVCodecHWConfig *config; |
||||
HWDevice *dev = NULL; |
||||
int i; |
||||
|
||||
if (frames_ref && ((AVHWFramesContext *)frames_ref->data)->format == |
||||
ost->enc_ctx->pix_fmt) { |
||||
// Matching format, will try to use hw_frames_ctx.
|
||||
} else { |
||||
frames_ref = NULL; |
||||
} |
||||
|
||||
for (i = 0;; i++) { |
||||
config = avcodec_get_hw_config(ost->enc_ctx->codec, i); |
||||
if (!config) |
||||
break; |
||||
|
||||
if (frames_ref && |
||||
config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX && |
||||
(config->pix_fmt == AV_PIX_FMT_NONE || |
||||
config->pix_fmt == ost->enc_ctx->pix_fmt)) { |
||||
av_log(ost->enc_ctx, AV_LOG_VERBOSE, |
||||
"Using input " |
||||
"frames context (format %s) with %s encoder.\n", |
||||
av_get_pix_fmt_name(ost->enc_ctx->pix_fmt), |
||||
ost->enc_ctx->codec->name); |
||||
ost->enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref); |
||||
if (!ost->enc_ctx->hw_frames_ctx) |
||||
return AVERROR(ENOMEM); |
||||
return 0; |
||||
} |
||||
|
||||
if (!dev && config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) |
||||
dev = hw_device_get_by_type(config->device_type); |
||||
} |
||||
|
||||
if (dev) { |
||||
av_log(ost->enc_ctx, AV_LOG_VERBOSE, |
||||
"Using device %s " |
||||
"(type %s) with %s encoder.\n", |
||||
dev->name, av_hwdevice_get_type_name(dev->type), |
||||
ost->enc_ctx->codec->name); |
||||
ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); |
||||
if (!ost->enc_ctx->hw_device_ctx) |
||||
return AVERROR(ENOMEM); |
||||
} else { |
||||
// No device required, or no device available.
|
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static int set_encoder_id(OutputFile *of, OutputStream *ost) { |
||||
const char *cname = ost->enc_ctx->codec->name; |
||||
uint8_t *encoder_string; |
||||
int encoder_string_len; |
||||
|
||||
if (av_dict_get(ost->st->metadata, "encoder", NULL, 0)) |
||||
return 0; |
||||
|
||||
encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(cname) + 2; |
||||
encoder_string = av_mallocz(encoder_string_len); |
||||
if (!encoder_string) |
||||
return AVERROR(ENOMEM); |
||||
|
||||
if (!of->bitexact && !ost->bitexact) |
||||
av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len); |
||||
else |
||||
av_strlcpy(encoder_string, "Lavc ", encoder_string_len); |
||||
av_strlcat(encoder_string, cname, encoder_string_len); |
||||
av_dict_set(&ost->st->metadata, "encoder", encoder_string, |
||||
AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int enc_open(OutputStream *ost, const AVFrame *frame) { |
||||
InputStream *ist = ost->ist; |
||||
Encoder *e = ost->enc; |
||||
AVCodecContext *enc_ctx = ost->enc_ctx; |
||||
AVCodecContext *dec_ctx = NULL; |
||||
const AVCodec *enc = enc_ctx->codec; |
||||
OutputFile *of = output_files[ost->file_index]; |
||||
FrameData *fd; |
||||
int ret; |
||||
|
||||
if (e->opened) |
||||
return 0; |
||||
|
||||
// frame is always non-NULL for audio and video
|
||||
av_assert0(frame || (enc->type != AVMEDIA_TYPE_VIDEO && |
||||
enc->type != AVMEDIA_TYPE_AUDIO)); |
||||
|
||||
if (frame) { |
||||
av_assert0(frame->opaque_ref); |
||||
fd = (FrameData *)frame->opaque_ref->data; |
||||
} |
||||
|
||||
ret = set_encoder_id(output_files[ost->file_index], ost); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
if (ist) { |
||||
dec_ctx = ist->dec_ctx; |
||||
} |
||||
|
||||
// the timebase is chosen by filtering code
|
||||
if (ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO) { |
||||
enc_ctx->time_base = frame->time_base; |
||||
enc_ctx->framerate = fd->frame_rate_filter; |
||||
ost->st->avg_frame_rate = fd->frame_rate_filter; |
||||
} |
||||
|
||||
switch (enc_ctx->codec_type) { |
||||
case AVMEDIA_TYPE_AUDIO: |
||||
enc_ctx->sample_fmt = frame->format; |
||||
enc_ctx->sample_rate = frame->sample_rate; |
||||
ret = av_channel_layout_copy(&enc_ctx->ch_layout, &frame->ch_layout); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
if (ost->bits_per_raw_sample) |
||||
enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; |
||||
else |
||||
enc_ctx->bits_per_raw_sample = |
||||
FFMIN(fd->bits_per_raw_sample, |
||||
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3); |
||||
break; |
||||
|
||||
case AVMEDIA_TYPE_VIDEO: { |
||||
enc_ctx->width = frame->width; |
||||
enc_ctx->height = frame->height; |
||||
enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio = |
||||
ost->frame_aspect_ratio.num |
||||
? // overridden by the -aspect cli option
|
||||
av_mul_q(ost->frame_aspect_ratio, |
||||
(AVRational){enc_ctx->height, enc_ctx->width}) |
||||
: frame->sample_aspect_ratio; |
||||
|
||||
enc_ctx->pix_fmt = frame->format; |
||||
|
||||
if (ost->bits_per_raw_sample) |
||||
enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; |
||||
else |
||||
enc_ctx->bits_per_raw_sample = |
||||
FFMIN(fd->bits_per_raw_sample, |
||||
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth); |
||||
|
||||
enc_ctx->color_range = frame->color_range; |
||||
enc_ctx->color_primaries = frame->color_primaries; |
||||
enc_ctx->color_trc = frame->color_trc; |
||||
enc_ctx->colorspace = frame->colorspace; |
||||
enc_ctx->chroma_sample_location = frame->chroma_location; |
||||
|
||||
if (enc_ctx->flags & |
||||
(AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) || |
||||
(frame->flags & AV_FRAME_FLAG_INTERLACED) |
||||
#if FFMPEG_OPT_TOP |
||||
|| ost->top_field_first >= 0 |
||||
#endif |
||||
) { |
||||
int top_field_first = |
||||
#if FFMPEG_OPT_TOP |
||||
ost->top_field_first >= 0 |
||||
? ost->top_field_first |
||||
: |
||||
#endif |
||||
!!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST); |
||||
|
||||
if (enc->id == AV_CODEC_ID_MJPEG) |
||||
enc_ctx->field_order = |
||||
top_field_first ? AV_FIELD_TT : AV_FIELD_BB; |
||||
else |
||||
enc_ctx->field_order = |
||||
top_field_first ? AV_FIELD_TB : AV_FIELD_BT; |
||||
} else |
||||
enc_ctx->field_order = AV_FIELD_PROGRESSIVE; |
||||
|
||||
break; |
||||
} |
||||
case AVMEDIA_TYPE_SUBTITLE: |
||||
if (ost->enc_timebase.num) |
||||
av_log(ost, AV_LOG_WARNING, |
||||
"-enc_time_base not supported for subtitles, ignoring\n"); |
||||
enc_ctx->time_base = AV_TIME_BASE_Q; |
||||
|
||||
if (!enc_ctx->width) { |
||||
enc_ctx->width = ost->ist->par->width; |
||||
enc_ctx->height = ost->ist->par->height; |
||||
} |
||||
if (dec_ctx && dec_ctx->subtitle_header) { |
||||
/* ASS code assumes this buffer is null terminated so add extra
|
||||
* byte. */ |
||||
enc_ctx->subtitle_header = |
||||
av_mallocz(dec_ctx->subtitle_header_size + 1); |
||||
if (!enc_ctx->subtitle_header) |
||||
return AVERROR(ENOMEM); |
||||
memcpy(enc_ctx->subtitle_header, dec_ctx->subtitle_header, |
||||
dec_ctx->subtitle_header_size); |
||||
enc_ctx->subtitle_header_size = dec_ctx->subtitle_header_size; |
||||
} |
||||
|
||||
break; |
||||
default: |
||||
av_assert0(0); |
||||
break; |
||||
} |
||||
|
||||
if (ost->bitexact) |
||||
enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT; |
||||
|
||||
if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0)) |
||||
av_dict_set(&ost->encoder_opts, "threads", "auto", 0); |
||||
|
||||
if (enc->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) { |
||||
ret = av_dict_set(&ost->encoder_opts, "flags", "+copy_opaque", |
||||
AV_DICT_MULTIKEY); |
||||
if (ret < 0) |
||||
return ret; |
||||
} |
||||
|
||||
av_dict_set(&ost->encoder_opts, "flags", "+frame_duration", |
||||
AV_DICT_MULTIKEY); |
||||
|
||||
ret = hw_device_setup_for_encode(ost, frame ? frame->hw_frames_ctx : NULL); |
||||
if (ret < 0) { |
||||
av_log(ost, AV_LOG_ERROR, "Encoding hardware device setup failed: %s\n", |
||||
av_err2str(ret)); |
||||
return ret; |
||||
} |
||||
|
||||
if ((ret = avcodec_open2(ost->enc_ctx, enc, &ost->encoder_opts)) < 0) { |
||||
if (ret != AVERROR_EXPERIMENTAL) |
||||
av_log(ost, AV_LOG_ERROR, |
||||
"Error while opening encoder - maybe " |
||||
"incorrect parameters such as bit_rate, rate, width or " |
||||
"height.\n"); |
||||
return ret; |
||||
} |
||||
|
||||
e->opened = 1; |
||||
|
||||
if (ost->sq_idx_encode >= 0) { |
||||
e->sq_frame = av_frame_alloc(); |
||||
if (!e->sq_frame) |
||||
return AVERROR(ENOMEM); |
||||
} |
||||
|
||||
if (ost->enc_ctx->frame_size) { |
||||
av_assert0(ost->sq_idx_encode >= 0); |
||||
sq_frame_samples(output_files[ost->file_index]->sq_encode, |
||||
ost->sq_idx_encode, ost->enc_ctx->frame_size); |
||||
} |
||||
|
||||
ret = check_avoptions(ost->encoder_opts); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000 && |
||||
ost->enc_ctx->codec_id != |
||||
AV_CODEC_ID_CODEC2 /* don't complain about 700 bit/s modes */) |
||||
av_log(ost, AV_LOG_WARNING, |
||||
"The bitrate parameter is set too low." |
||||
" It takes bits/s as argument, not kbits/s\n"); |
||||
|
||||
ret = avcodec_parameters_from_context(ost->par_in, ost->enc_ctx); |
||||
if (ret < 0) { |
||||
av_log(ost, AV_LOG_FATAL, |
||||
"Error initializing the output stream codec context.\n"); |
||||
return ret; |
||||
} |
||||
|
||||
/*
|
||||
* Add global input side data. For now this is naive, and copies it |
||||
* from the input stream's global side data. All side data should |
||||
* really be funneled over AVFrame and libavfilter, then added back to |
||||
* packet side data, and then potentially using the first packet for |
||||
* global side data. |
||||
*/ |
||||
if (ist) { |
||||
int i; |
||||
for (i = 0; i < ist->st->codecpar->nb_coded_side_data; i++) { |
||||
AVPacketSideData *sd_src = &ist->st->codecpar->coded_side_data[i]; |
||||
if (sd_src->type != AV_PKT_DATA_CPB_PROPERTIES) { |
||||
AVPacketSideData *sd_dst = |
||||
av_packet_side_data_new(&ost->par_in->coded_side_data, |
||||
&ost->par_in->nb_coded_side_data, |
||||
sd_src->type, sd_src->size, 0); |
||||
if (!sd_dst) |
||||
return AVERROR(ENOMEM); |
||||
memcpy(sd_dst->data, sd_src->data, sd_src->size); |
||||
if (ist->autorotate && |
||||
sd_src->type == AV_PKT_DATA_DISPLAYMATRIX) |
||||
av_display_rotation_set((int32_t *)sd_dst->data, 0); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// copy timebase while removing common factors
|
||||
if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) |
||||
ost->st->time_base = |
||||
av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1}); |
||||
|
||||
ret = of_stream_init(of, ost); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb) { |
||||
OutputFile *of = output_files[ost->file_index]; |
||||
|
||||
if (of->recording_time != INT64_MAX && |
||||
av_compare_ts(ts, tb, of->recording_time, AV_TIME_BASE_Q) >= 0) { |
||||
close_output_stream(ost); |
||||
return 0; |
||||
} |
||||
return 1; |
||||
} |
||||
|
||||
int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub) { |
||||
Encoder *e = ost->enc; |
||||
int subtitle_out_max_size = 1024 * 1024; |
||||
int subtitle_out_size, nb, i, ret; |
||||
AVCodecContext *enc; |
||||
AVPacket *pkt = e->pkt; |
||||
int64_t pts; |
||||
|
||||
if (sub->pts == AV_NOPTS_VALUE) { |
||||
av_log(ost, AV_LOG_ERROR, "Subtitle packets must have a pts\n"); |
||||
return exit_on_error ? AVERROR(EINVAL) : 0; |
||||
} |
||||
if (ost->finished || |
||||
(of->start_time != AV_NOPTS_VALUE && sub->pts < of->start_time)) |
||||
return 0; |
||||
|
||||
enc = ost->enc_ctx; |
||||
|
||||
/* Note: DVB subtitle need one packet to draw them and one other
|
||||
packet to clear them */ |
||||
/* XXX: signal it in the codec context ? */ |
||||
if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) |
||||
nb = 2; |
||||
else if (enc->codec_id == AV_CODEC_ID_ASS) |
||||
nb = FFMAX(sub->num_rects, 1); |
||||
else |
||||
nb = 1; |
||||
|
||||
/* shift timestamp to honor -ss and make check_recording_time() work with -t
|
||||
*/ |
||||
pts = sub->pts; |
||||
if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE) |
||||
pts -= output_files[ost->file_index]->start_time; |
||||
for (i = 0; i < nb; i++) { |
||||
AVSubtitle local_sub = *sub; |
||||
|
||||
if (!check_recording_time(ost, pts, AV_TIME_BASE_Q)) |
||||
return 0; |
||||
|
||||
ret = av_new_packet(pkt, subtitle_out_max_size); |
||||
if (ret < 0) |
||||
return AVERROR(ENOMEM); |
||||
|
||||
local_sub.pts = pts; |
||||
// start_display_time is required to be 0
|
||||
local_sub.pts += av_rescale_q(sub->start_display_time, |
||||
(AVRational){1, 1000}, AV_TIME_BASE_Q); |
||||
local_sub.end_display_time -= sub->start_display_time; |
||||
local_sub.start_display_time = 0; |
||||
|
||||
if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE && i == 1) |
||||
local_sub.num_rects = 0; |
||||
else if (enc->codec_id == AV_CODEC_ID_ASS && sub->num_rects > 0) { |
||||
local_sub.num_rects = 1; |
||||
local_sub.rects += i; |
||||
} |
||||
|
||||
ost->frames_encoded++; |
||||
|
||||
subtitle_out_size = |
||||
avcodec_encode_subtitle(enc, pkt->data, pkt->size, &local_sub); |
||||
if (subtitle_out_size < 0) { |
||||
av_log(ost, AV_LOG_FATAL, "Subtitle encoding failed\n"); |
||||
return subtitle_out_size; |
||||
} |
||||
|
||||
av_shrink_packet(pkt, subtitle_out_size); |
||||
pkt->time_base = AV_TIME_BASE_Q; |
||||
pkt->pts = sub->pts; |
||||
pkt->duration = av_rescale_q(sub->end_display_time, |
||||
(AVRational){1, 1000}, pkt->time_base); |
||||
if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { |
||||
/* XXX: the pts correction is handled here. Maybe handling
|
||||
it in the codec would be better */ |
||||
if (i == 0) |
||||
pkt->pts += av_rescale_q(sub->start_display_time, |
||||
(AVRational){1, 1000}, pkt->time_base); |
||||
else |
||||
pkt->pts += av_rescale_q(sub->end_display_time, |
||||
(AVRational){1, 1000}, pkt->time_base); |
||||
} |
||||
pkt->dts = pkt->pts; |
||||
|
||||
ret = of_output_packet(of, ost, pkt); |
||||
if (ret < 0) |
||||
return ret; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, |
||||
const AVPacket *pkt, uint64_t frame_num) { |
||||
Encoder *e = ost->enc; |
||||
AVIOContext *io = es->io; |
||||
AVRational tb = frame ? frame->time_base : pkt->time_base; |
||||
int64_t pts = frame ? frame->pts : pkt->pts; |
||||
|
||||
AVRational tbi = (AVRational){0, 1}; |
||||
int64_t ptsi = INT64_MAX; |
||||
|
||||
const FrameData *fd = NULL; |
||||
|
||||
if (frame ? frame->opaque_ref : pkt->opaque_ref) { |
||||
fd = (const FrameData *)(frame ? frame->opaque_ref->data |
||||
: pkt->opaque_ref->data); |
||||
tbi = fd->dec.tb; |
||||
ptsi = fd->dec.pts; |
||||
} |
||||
|
||||
for (size_t i = 0; i < es->nb_components; i++) { |
||||
const EncStatsComponent *c = &es->components[i]; |
||||
|
||||
switch (c->type) { |
||||
case ENC_STATS_LITERAL: |
||||
avio_write(io, c->str, c->str_len); |
||||
continue; |
||||
case ENC_STATS_FILE_IDX: |
||||
avio_printf(io, "%d", ost->file_index); |
||||
continue; |
||||
case ENC_STATS_STREAM_IDX: |
||||
avio_printf(io, "%d", ost->index); |
||||
continue; |
||||
case ENC_STATS_TIMEBASE: |
||||
avio_printf(io, "%d/%d", tb.num, tb.den); |
||||
continue; |
||||
case ENC_STATS_TIMEBASE_IN: |
||||
avio_printf(io, "%d/%d", tbi.num, tbi.den); |
||||
continue; |
||||
case ENC_STATS_PTS: |
||||
avio_printf(io, "%" PRId64, pts); |
||||
continue; |
||||
case ENC_STATS_PTS_IN: |
||||
avio_printf(io, "%" PRId64, ptsi); |
||||
continue; |
||||
case ENC_STATS_PTS_TIME: |
||||
avio_printf(io, "%g", pts * av_q2d(tb)); |
||||
continue; |
||||
case ENC_STATS_PTS_TIME_IN: |
||||
avio_printf(io, "%g", |
||||
ptsi == INT64_MAX ? INFINITY : ptsi * av_q2d(tbi)); |
||||
continue; |
||||
case ENC_STATS_FRAME_NUM: |
||||
avio_printf(io, "%" PRIu64, frame_num); |
||||
continue; |
||||
case ENC_STATS_FRAME_NUM_IN: |
||||
avio_printf(io, "%" PRIu64, fd ? fd->dec.frame_num : -1); |
||||
continue; |
||||
} |
||||
|
||||
if (frame) { |
||||
switch (c->type) { |
||||
case ENC_STATS_SAMPLE_NUM: |
||||
avio_printf(io, "%" PRIu64, ost->samples_encoded); |
||||
continue; |
||||
case ENC_STATS_NB_SAMPLES: |
||||
avio_printf(io, "%d", frame->nb_samples); |
||||
continue; |
||||
default: |
||||
av_assert0(0); |
||||
} |
||||
} else { |
||||
switch (c->type) { |
||||
case ENC_STATS_DTS: |
||||
avio_printf(io, "%" PRId64, pkt->dts); |
||||
continue; |
||||
case ENC_STATS_DTS_TIME: |
||||
avio_printf(io, "%g", pkt->dts * av_q2d(tb)); |
||||
continue; |
||||
case ENC_STATS_PKT_SIZE: |
||||
avio_printf(io, "%d", pkt->size); |
||||
continue; |
||||
case ENC_STATS_BITRATE: { |
||||
double duration = FFMAX(pkt->duration, 1) * av_q2d(tb); |
||||
avio_printf(io, "%g", 8.0 * pkt->size / duration); |
||||
continue; |
||||
} |
||||
case ENC_STATS_AVG_BITRATE: { |
||||
double duration = pkt->dts * av_q2d(tb); |
||||
avio_printf(io, "%g", |
||||
duration > 0 ? 8.0 * e->data_size / duration : -1.); |
||||
continue; |
||||
} |
||||
default: |
||||
av_assert0(0); |
||||
} |
||||
} |
||||
} |
||||
avio_w8(io, '\n'); |
||||
avio_flush(io); |
||||
} |
||||
|
||||
static inline double psnr(double d) { return -10.0 * log10(d); } |
||||
|
||||
static int update_video_stats(OutputStream *ost, const AVPacket *pkt, |
||||
int write_vstats) { |
||||
Encoder *e = ost->enc; |
||||
const uint8_t *sd = |
||||
av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, NULL); |
||||
AVCodecContext *enc = ost->enc_ctx; |
||||
enum AVPictureType pict_type; |
||||
int64_t frame_number; |
||||
double ti1, bitrate, avg_bitrate; |
||||
double psnr_val = -1; |
||||
|
||||
ost->quality = sd ? AV_RL32(sd) : -1; |
||||
pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; |
||||
|
||||
if ((enc->flags & AV_CODEC_FLAG_PSNR) && sd && sd[5]) { |
||||
// FIXME the scaling assumes 8bit
|
||||
double error = |
||||
AV_RL64(sd + 8) / (enc->width * enc->height * 255.0 * 255.0); |
||||
if (error >= 0 && error <= 1) |
||||
psnr_val = psnr(error); |
||||
} |
||||
|
||||
if (!write_vstats) |
||||
return 0; |
||||
|
||||
/* this is executed just the first time update_video_stats is called */ |
||||
if (!vstats_file) { |
||||
vstats_file = fopen(vstats_filename, "w"); |
||||
if (!vstats_file) { |
||||
perror("fopen"); |
||||
return AVERROR(errno); |
||||
} |
||||
} |
||||
|
||||
frame_number = e->packets_encoded; |
||||
if (vstats_version <= 1) { |
||||
fprintf(vstats_file, "frame= %5" PRId64 " q= %2.1f ", frame_number, |
||||
ost->quality / (float)FF_QP2LAMBDA); |
||||
} else { |
||||
fprintf(vstats_file, "out= %2d st= %2d frame= %5" PRId64 " q= %2.1f ", |
||||
ost->file_index, ost->index, frame_number, |
||||
ost->quality / (float)FF_QP2LAMBDA); |
||||
} |
||||
|
||||
if (psnr_val >= 0) |
||||
fprintf(vstats_file, "PSNR= %6.2f ", psnr_val); |
||||
|
||||
fprintf(vstats_file, "f_size= %6d ", pkt->size); |
||||
/* compute pts value */ |
||||
ti1 = pkt->dts * av_q2d(pkt->time_base); |
||||
if (ti1 < 0.01) |
||||
ti1 = 0.01; |
||||
|
||||
bitrate = (pkt->size * 8) / av_q2d(enc->time_base) / 1000.0; |
||||
avg_bitrate = (double)(e->data_size * 8) / ti1 / 1000.0; |
||||
fprintf( |
||||
vstats_file, |
||||
"s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", |
||||
(double)e->data_size / 1024, ti1, bitrate, avg_bitrate); |
||||
fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(pict_type)); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) { |
||||
Encoder *e = ost->enc; |
||||
AVCodecContext *enc = ost->enc_ctx; |
||||
AVPacket *pkt = e->pkt; |
||||
const char *type_desc = av_get_media_type_string(enc->codec_type); |
||||
const char *action = frame ? "encode" : "flush"; |
||||
int ret; |
||||
|
||||
if (frame) { |
||||
if (ost->enc_stats_pre.io) |
||||
enc_stats_write(ost, &ost->enc_stats_pre, frame, NULL, |
||||
ost->frames_encoded); |
||||
|
||||
ost->frames_encoded++; |
||||
ost->samples_encoded += frame->nb_samples; |
||||
|
||||
if (debug_ts) { |
||||
av_log(ost, AV_LOG_INFO, |
||||
"encoder <- type:%s " |
||||
"frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", |
||||
type_desc, av_ts2str(frame->pts), |
||||
av_ts2timestr(frame->pts, &enc->time_base), |
||||
enc->time_base.num, enc->time_base.den); |
||||
} |
||||
|
||||
if (frame->sample_aspect_ratio.num && !ost->frame_aspect_ratio.num) |
||||
enc->sample_aspect_ratio = frame->sample_aspect_ratio; |
||||
} |
||||
|
||||
update_benchmark(NULL); |
||||
|
||||
ret = avcodec_send_frame(enc, frame); |
||||
if (ret < 0 && !(ret == AVERROR_EOF && !frame)) { |
||||
av_log(ost, AV_LOG_ERROR, "Error submitting %s frame to the encoder\n", |
||||
type_desc); |
||||
return ret; |
||||
} |
||||
|
||||
while (1) { |
||||
av_packet_unref(pkt); |
||||
|
||||
ret = avcodec_receive_packet(enc, pkt); |
||||
update_benchmark("%s_%s %d.%d", action, type_desc, ost->file_index, |
||||
ost->index); |
||||
|
||||
pkt->time_base = enc->time_base; |
||||
|
||||
/* if two pass, output log on success and EOF */ |
||||
if ((ret >= 0 || ret == AVERROR_EOF) && ost->logfile && enc->stats_out) |
||||
fprintf(ost->logfile, "%s", enc->stats_out); |
||||
|
||||
if (ret == AVERROR(EAGAIN)) { |
||||
av_assert0(frame); // should never happen during flushing
|
||||
return 0; |
||||
} else if (ret == AVERROR_EOF) { |
||||
ret = of_output_packet(of, ost, NULL); |
||||
return ret < 0 ? ret : AVERROR_EOF; |
||||
} else if (ret < 0) { |
||||
av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc); |
||||
return ret; |
||||
} |
||||
|
||||
if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { |
||||
ret = update_video_stats(ost, pkt, !!vstats_filename); |
||||
if (ret < 0) |
||||
return ret; |
||||
} |
||||
|
||||
if (ost->enc_stats_post.io) |
||||
enc_stats_write(ost, &ost->enc_stats_post, NULL, pkt, |
||||
e->packets_encoded); |
||||
|
||||
if (debug_ts) { |
||||
av_log(ost, AV_LOG_INFO, |
||||
"encoder -> type:%s " |
||||
"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " |
||||
"duration:%s duration_time:%s\n", |
||||
type_desc, av_ts2str(pkt->pts), |
||||
av_ts2timestr(pkt->pts, &enc->time_base), |
||||
av_ts2str(pkt->dts), |
||||
av_ts2timestr(pkt->dts, &enc->time_base), |
||||
av_ts2str(pkt->duration), |
||||
av_ts2timestr(pkt->duration, &enc->time_base)); |
||||
} |
||||
|
||||
if ((ret = trigger_fix_sub_duration_heartbeat(ost, pkt)) < 0) { |
||||
av_log(NULL, AV_LOG_ERROR, |
||||
"Subtitle heartbeat logic failed in %s! (%s)\n", __func__, |
||||
av_err2str(ret)); |
||||
return ret; |
||||
} |
||||
|
||||
e->data_size += pkt->size; |
||||
|
||||
e->packets_encoded++; |
||||
|
||||
ret = of_output_packet(of, ost, pkt); |
||||
if (ret < 0) |
||||
return ret; |
||||
} |
||||
|
||||
av_assert0(0); |
||||
} |
||||
|
||||
static int submit_encode_frame(OutputFile *of, OutputStream *ost, |
||||
AVFrame *frame) { |
||||
Encoder *e = ost->enc; |
||||
int ret; |
||||
|
||||
if (ost->sq_idx_encode < 0) |
||||
return encode_frame(of, ost, frame); |
||||
|
||||
if (frame) { |
||||
ret = av_frame_ref(e->sq_frame, frame); |
||||
if (ret < 0) |
||||
return ret; |
||||
frame = e->sq_frame; |
||||
} |
||||
|
||||
ret = sq_send(of->sq_encode, ost->sq_idx_encode, SQFRAME(frame)); |
||||
if (ret < 0) { |
||||
if (frame) |
||||
av_frame_unref(frame); |
||||
if (ret != AVERROR_EOF) |
||||
return ret; |
||||
} |
||||
|
||||
while (1) { |
||||
AVFrame *enc_frame = e->sq_frame; |
||||
|
||||
ret = sq_receive(of->sq_encode, ost->sq_idx_encode, SQFRAME(enc_frame)); |
||||
if (ret == AVERROR_EOF) { |
||||
enc_frame = NULL; |
||||
} else if (ret < 0) { |
||||
return (ret == AVERROR(EAGAIN)) ? 0 : ret; |
||||
} |
||||
|
||||
ret = encode_frame(of, ost, enc_frame); |
||||
if (enc_frame) |
||||
av_frame_unref(enc_frame); |
||||
if (ret < 0) { |
||||
if (ret == AVERROR_EOF) |
||||
close_output_stream(ost); |
||||
return ret; |
||||
} |
||||
} |
||||
} |
||||
|
||||
static int do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame) { |
||||
AVCodecContext *enc = ost->enc_ctx; |
||||
int ret; |
||||
|
||||
if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && |
||||
enc->ch_layout.nb_channels != frame->ch_layout.nb_channels) { |
||||
av_log(ost, AV_LOG_ERROR, |
||||
"Audio channel count changed and encoder does not support " |
||||
"parameter " |
||||
"changes\n"); |
||||
return 0; |
||||
} |
||||
|
||||
if (!check_recording_time(ost, frame->pts, frame->time_base)) |
||||
return 0; |
||||
|
||||
ret = submit_encode_frame(of, ost, frame); |
||||
return (ret < 0 && ret != AVERROR_EOF) ? ret : 0; |
||||
} |
||||
|
||||
static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, |
||||
AVRational tb, |
||||
const AVFrame *in_picture) { |
||||
double pts_time; |
||||
|
||||
if (kf->ref_pts == AV_NOPTS_VALUE) |
||||
kf->ref_pts = in_picture->pts; |
||||
|
||||
pts_time = (in_picture->pts - kf->ref_pts) * av_q2d(tb); |
||||
if (kf->index < kf->nb_pts && |
||||
av_compare_ts(in_picture->pts, tb, kf->pts[kf->index], |
||||
AV_TIME_BASE_Q) >= 0) { |
||||
kf->index++; |
||||
goto force_keyframe; |
||||
} else if (kf->pexpr) { |
||||
double res; |
||||
kf->expr_const_values[FKF_T] = pts_time; |
||||
res = av_expr_eval(kf->pexpr, kf->expr_const_values, NULL); |
||||
av_log(logctx, AV_LOG_TRACE, |
||||
"force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f " |
||||
"prev_forced_t:%f -> res:%f\n", |
||||
kf->expr_const_values[FKF_N], |
||||
kf->expr_const_values[FKF_N_FORCED], |
||||
kf->expr_const_values[FKF_PREV_FORCED_N], |
||||
kf->expr_const_values[FKF_T], |
||||
kf->expr_const_values[FKF_PREV_FORCED_T], res); |
||||
|
||||
kf->expr_const_values[FKF_N] += 1; |
||||
|
||||
if (res) { |
||||
kf->expr_const_values[FKF_PREV_FORCED_N] = |
||||
kf->expr_const_values[FKF_N] - 1; |
||||
kf->expr_const_values[FKF_PREV_FORCED_T] = |
||||
kf->expr_const_values[FKF_T]; |
||||
kf->expr_const_values[FKF_N_FORCED] += 1; |
||||
goto force_keyframe; |
||||
} |
||||
} else if (kf->type == KF_FORCE_SOURCE && |
||||
(in_picture->flags & AV_FRAME_FLAG_KEY)) { |
||||
goto force_keyframe; |
||||
} |
||||
|
||||
return AV_PICTURE_TYPE_NONE; |
||||
|
||||
force_keyframe: |
||||
av_log(logctx, AV_LOG_DEBUG, "Forced keyframe at time %f\n", pts_time); |
||||
return AV_PICTURE_TYPE_I; |
||||
} |
||||
|
||||
/* May modify/reset frame */ |
||||
static int do_video_out(OutputFile *of, OutputStream *ost, |
||||
AVFrame *in_picture) { |
||||
int ret; |
||||
AVCodecContext *enc = ost->enc_ctx; |
||||
|
||||
if (!check_recording_time(ost, in_picture->pts, ost->enc_ctx->time_base)) |
||||
return 0; |
||||
|
||||
in_picture->quality = enc->global_quality; |
||||
in_picture->pict_type = |
||||
forced_kf_apply(ost, &ost->kf, enc->time_base, in_picture); |
||||
|
||||
#if FFMPEG_OPT_TOP |
||||
if (ost->top_field_first >= 0) { |
||||
in_picture->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; |
||||
in_picture->flags |= |
||||
AV_FRAME_FLAG_TOP_FIELD_FIRST * (!!ost->top_field_first); |
||||
} |
||||
#endif |
||||
|
||||
ret = submit_encode_frame(of, ost, in_picture); |
||||
return (ret == AVERROR_EOF) ? 0 : ret; |
||||
} |
||||
|
||||
int enc_frame(OutputStream *ost, AVFrame *frame) { |
||||
OutputFile *of = output_files[ost->file_index]; |
||||
int ret; |
||||
|
||||
ret = enc_open(ost, frame); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
return ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO |
||||
? do_video_out(of, ost, frame) |
||||
: do_audio_out(of, ost, frame); |
||||
} |
||||
|
||||
int enc_flush(void) { |
||||
int ret; |
||||
|
||||
for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { |
||||
OutputFile *of = output_files[ost->file_index]; |
||||
if (ost->sq_idx_encode >= 0) |
||||
sq_send(of->sq_encode, ost->sq_idx_encode, SQFRAME(NULL)); |
||||
} |
||||
|
||||
for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { |
||||
Encoder *e = ost->enc; |
||||
AVCodecContext *enc = ost->enc_ctx; |
||||
OutputFile *of = output_files[ost->file_index]; |
||||
|
||||
if (!enc || !e->opened || |
||||
(enc->codec_type != AVMEDIA_TYPE_VIDEO && |
||||
enc->codec_type != AVMEDIA_TYPE_AUDIO)) |
||||
continue; |
||||
|
||||
ret = submit_encode_frame(of, ost, NULL); |
||||
if (ret != AVERROR_EOF) |
||||
return ret; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,271 +0,0 @@ |
||||
#! /bin/sh |
||||
# Wrapper for Microsoft lib.exe |
||||
|
||||
me=ar-lib |
||||
scriptversion=2019-07-04.01; # UTC |
||||
|
||||
# Copyright (C) 2010-2021 Free Software Foundation, Inc. |
||||
# Written by Peter Rosin <peda@lysator.liu.se>. |
||||
# |
||||
# This program is free software; you can redistribute it and/or modify |
||||
# it under the terms of the GNU General Public License as published by |
||||
# the Free Software Foundation; either version 2, or (at your option) |
||||
# any later version. |
||||
# |
||||
# This program 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 General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
|
||||
# As a special exception to the GNU General Public License, if you |
||||
# distribute this file as part of a program that contains a |
||||
# configuration script generated by Autoconf, you may include it under |
||||
# the same distribution terms that you use for the rest of that program. |
||||
|
||||
# This file is maintained in Automake, please report |
||||
# bugs to <bug-automake@gnu.org> or send patches to |
||||
# <automake-patches@gnu.org>. |
||||
|
||||
|
||||
# func_error message |
||||
func_error () |
||||
{ |
||||
echo "$me: $1" 1>&2 |
||||
exit 1 |
||||
} |
||||
|
||||
file_conv= |
||||
|
||||
# func_file_conv build_file |
||||
# Convert a $build file to $host form and store it in $file |
||||
# Currently only supports Windows hosts. |
||||
func_file_conv () |
||||
{ |
||||
file=$1 |
||||
case $file in |
||||
/ | /[!/]*) # absolute file, and not a UNC file |
||||
if test -z "$file_conv"; then |
||||
# lazily determine how to convert abs files |
||||
case `uname -s` in |
||||
MINGW*) |
||||
file_conv=mingw |
||||
;; |
||||
CYGWIN* | MSYS*) |
||||
file_conv=cygwin |
||||
;; |
||||
*) |
||||
file_conv=wine |
||||
;; |
||||
esac |
||||
fi |
||||
case $file_conv in |
||||
mingw) |
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` |
||||
;; |
||||
cygwin | msys) |
||||
file=`cygpath -m "$file" || echo "$file"` |
||||
;; |
||||
wine) |
||||
file=`winepath -w "$file" || echo "$file"` |
||||
;; |
||||
esac |
||||
;; |
||||
esac |
||||
} |
||||
|
||||
# func_at_file at_file operation archive |
||||
# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE |
||||
# for each of them. |
||||
# When interpreting the content of the @FILE, do NOT use func_file_conv, |
||||
# since the user would need to supply preconverted file names to |
||||
# binutils ar, at least for MinGW. |
||||
func_at_file () |
||||
{ |
||||
operation=$2 |
||||
archive=$3 |
||||
at_file_contents=`cat "$1"` |
||||
eval set x "$at_file_contents" |
||||
shift |
||||
|
||||
for member |
||||
do |
||||
$AR -NOLOGO $operation:"$member" "$archive" || exit $? |
||||
done |
||||
} |
||||
|
||||
case $1 in |
||||
'') |
||||
func_error "no command. Try '$0 --help' for more information." |
||||
;; |
||||
-h | --h*) |
||||
cat <<EOF |
||||
Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...] |
||||
|
||||
Members may be specified in a file named with @FILE. |
||||
EOF |
||||
exit $? |
||||
;; |
||||
-v | --v*) |
||||
echo "$me, version $scriptversion" |
||||
exit $? |
||||
;; |
||||
esac |
||||
|
||||
if test $# -lt 3; then |
||||
func_error "you must specify a program, an action and an archive" |
||||
fi |
||||
|
||||
AR=$1 |
||||
shift |
||||
while : |
||||
do |
||||
if test $# -lt 2; then |
||||
func_error "you must specify a program, an action and an archive" |
||||
fi |
||||
case $1 in |
||||
-lib | -LIB \ |
||||
| -ltcg | -LTCG \ |
||||
| -machine* | -MACHINE* \ |
||||
| -subsystem* | -SUBSYSTEM* \ |
||||
| -verbose | -VERBOSE \ |
||||
| -wx* | -WX* ) |
||||
AR="$AR $1" |
||||
shift |
||||
;; |
||||
*) |
||||
action=$1 |
||||
shift |
||||
break |
||||
;; |
||||
esac |
||||
done |
||||
orig_archive=$1 |
||||
shift |
||||
func_file_conv "$orig_archive" |
||||
archive=$file |
||||
|
||||
# strip leading dash in $action |
||||
action=${action#-} |
||||
|
||||
delete= |
||||
extract= |
||||
list= |
||||
quick= |
||||
replace= |
||||
index= |
||||
create= |
||||
|
||||
while test -n "$action" |
||||
do |
||||
case $action in |
||||
d*) delete=yes ;; |
||||
x*) extract=yes ;; |
||||
t*) list=yes ;; |
||||
q*) quick=yes ;; |
||||
r*) replace=yes ;; |
||||
s*) index=yes ;; |
||||
S*) ;; # the index is always updated implicitly |
||||
c*) create=yes ;; |
||||
u*) ;; # TODO: don't ignore the update modifier |
||||
v*) ;; # TODO: don't ignore the verbose modifier |
||||
*) |
||||
func_error "unknown action specified" |
||||
;; |
||||
esac |
||||
action=${action#?} |
||||
done |
||||
|
||||
case $delete$extract$list$quick$replace,$index in |
||||
yes,* | ,yes) |
||||
;; |
||||
yesyes*) |
||||
func_error "more than one action specified" |
||||
;; |
||||
*) |
||||
func_error "no action specified" |
||||
;; |
||||
esac |
||||
|
||||
if test -n "$delete"; then |
||||
if test ! -f "$orig_archive"; then |
||||
func_error "archive not found" |
||||
fi |
||||
for member |
||||
do |
||||
case $1 in |
||||
@*) |
||||
func_at_file "${1#@}" -REMOVE "$archive" |
||||
;; |
||||
*) |
||||
func_file_conv "$1" |
||||
$AR -NOLOGO -REMOVE:"$file" "$archive" || exit $? |
||||
;; |
||||
esac |
||||
done |
||||
|
||||
elif test -n "$extract"; then |
||||
if test ! -f "$orig_archive"; then |
||||
func_error "archive not found" |
||||
fi |
||||
if test $# -gt 0; then |
||||
for member |
||||
do |
||||
case $1 in |
||||
@*) |
||||
func_at_file "${1#@}" -EXTRACT "$archive" |
||||
;; |
||||
*) |
||||
func_file_conv "$1" |
||||
$AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $? |
||||
;; |
||||
esac |
||||
done |
||||
else |
||||
$AR -NOLOGO -LIST "$archive" | tr -d '\r' | sed -e 's/\\/\\\\/g' \ |
||||
| while read member |
||||
do |
||||
$AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $? |
||||
done |
||||
fi |
||||
|
||||
elif test -n "$quick$replace"; then |
||||
if test ! -f "$orig_archive"; then |
||||
if test -z "$create"; then |
||||
echo "$me: creating $orig_archive" |
||||
fi |
||||
orig_archive= |
||||
else |
||||
orig_archive=$archive |
||||
fi |
||||
|
||||
for member |
||||
do |
||||
case $1 in |
||||
@*) |
||||
func_file_conv "${1#@}" |
||||
set x "$@" "@$file" |
||||
;; |
||||
*) |
||||
func_file_conv "$1" |
||||
set x "$@" "$file" |
||||
;; |
||||
esac |
||||
shift |
||||
shift |
||||
done |
||||
|
||||
if test -n "$orig_archive"; then |
||||
$AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $? |
||||
else |
||||
$AR -NOLOGO -OUT:"$archive" "$@" || exit $? |
||||
fi |
||||
|
||||
elif test -n "$list"; then |
||||
if test ! -f "$orig_archive"; then |
||||
func_error "archive not found" |
||||
fi |
||||
$AR -NOLOGO -LIST "$archive" || exit $? |
||||
fi |
||||
@ -1,348 +0,0 @@ |
||||
#! /bin/sh |
||||
# Wrapper for compilers which do not understand '-c -o'. |
||||
|
||||
scriptversion=2018-03-07.03; # UTC |
||||
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc. |
||||
# Written by Tom Tromey <tromey@cygnus.com>. |
||||
# |
||||
# This program is free software; you can redistribute it and/or modify |
||||
# it under the terms of the GNU General Public License as published by |
||||
# the Free Software Foundation; either version 2, or (at your option) |
||||
# any later version. |
||||
# |
||||
# This program 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 General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
|
||||
# As a special exception to the GNU General Public License, if you |
||||
# distribute this file as part of a program that contains a |
||||
# configuration script generated by Autoconf, you may include it under |
||||
# the same distribution terms that you use for the rest of that program. |
||||
|
||||
# This file is maintained in Automake, please report |
||||
# bugs to <bug-automake@gnu.org> or send patches to |
||||
# <automake-patches@gnu.org>. |
||||
|
||||
nl=' |
||||
' |
||||
|
||||
# We need space, tab and new line, in precisely that order. Quoting is |
||||
# there to prevent tools from complaining about whitespace usage. |
||||
IFS=" "" $nl" |
||||
|
||||
file_conv= |
||||
|
||||
# func_file_conv build_file lazy |
||||
# Convert a $build file to $host form and store it in $file |
||||
# Currently only supports Windows hosts. If the determined conversion |
||||
# type is listed in (the comma separated) LAZY, no conversion will |
||||
# take place. |
||||
func_file_conv () |
||||
{ |
||||
file=$1 |
||||
case $file in |
||||
/ | /[!/]*) # absolute file, and not a UNC file |
||||
if test -z "$file_conv"; then |
||||
# lazily determine how to convert abs files |
||||
case `uname -s` in |
||||
MINGW*) |
||||
file_conv=mingw |
||||
;; |
||||
CYGWIN* | MSYS*) |
||||
file_conv=cygwin |
||||
;; |
||||
*) |
||||
file_conv=wine |
||||
;; |
||||
esac |
||||
fi |
||||
case $file_conv/,$2, in |
||||
*,$file_conv,*) |
||||
;; |
||||
mingw/*) |
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` |
||||
;; |
||||
cygwin/* | msys/*) |
||||
file=`cygpath -m "$file" || echo "$file"` |
||||
;; |
||||
wine/*) |
||||
file=`winepath -w "$file" || echo "$file"` |
||||
;; |
||||
esac |
||||
;; |
||||
esac |
||||
} |
||||
|
||||
# func_cl_dashL linkdir |
||||
# Make cl look for libraries in LINKDIR |
||||
func_cl_dashL () |
||||
{ |
||||
func_file_conv "$1" |
||||
if test -z "$lib_path"; then |
||||
lib_path=$file |
||||
else |
||||
lib_path="$lib_path;$file" |
||||
fi |
||||
linker_opts="$linker_opts -LIBPATH:$file" |
||||
} |
||||
|
||||
# func_cl_dashl library |
||||
# Do a library search-path lookup for cl |
||||
func_cl_dashl () |
||||
{ |
||||
lib=$1 |
||||
found=no |
||||
save_IFS=$IFS |
||||
IFS=';' |
||||
for dir in $lib_path $LIB |
||||
do |
||||
IFS=$save_IFS |
||||
if $shared && test -f "$dir/$lib.dll.lib"; then |
||||
found=yes |
||||
lib=$dir/$lib.dll.lib |
||||
break |
||||
fi |
||||
if test -f "$dir/$lib.lib"; then |
||||
found=yes |
||||
lib=$dir/$lib.lib |
||||
break |
||||
fi |
||||
if test -f "$dir/lib$lib.a"; then |
||||
found=yes |
||||
lib=$dir/lib$lib.a |
||||
break |
||||
fi |
||||
done |
||||
IFS=$save_IFS |
||||
|
||||
if test "$found" != yes; then |
||||
lib=$lib.lib |
||||
fi |
||||
} |
||||
|
||||
# func_cl_wrapper cl arg... |
||||
# Adjust compile command to suit cl |
||||
func_cl_wrapper () |
||||
{ |
||||
# Assume a capable shell |
||||
lib_path= |
||||
shared=: |
||||
linker_opts= |
||||
for arg |
||||
do |
||||
if test -n "$eat"; then |
||||
eat= |
||||
else |
||||
case $1 in |
||||
-o) |
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'. |
||||
eat=1 |
||||
case $2 in |
||||
*.o | *.[oO][bB][jJ]) |
||||
func_file_conv "$2" |
||||
set x "$@" -Fo"$file" |
||||
shift |
||||
;; |
||||
*) |
||||
func_file_conv "$2" |
||||
set x "$@" -Fe"$file" |
||||
shift |
||||
;; |
||||
esac |
||||
;; |
||||
-I) |
||||
eat=1 |
||||
func_file_conv "$2" mingw |
||||
set x "$@" -I"$file" |
||||
shift |
||||
;; |
||||
-I*) |
||||
func_file_conv "${1#-I}" mingw |
||||
set x "$@" -I"$file" |
||||
shift |
||||
;; |
||||
-l) |
||||
eat=1 |
||||
func_cl_dashl "$2" |
||||
set x "$@" "$lib" |
||||
shift |
||||
;; |
||||
-l*) |
||||
func_cl_dashl "${1#-l}" |
||||
set x "$@" "$lib" |
||||
shift |
||||
;; |
||||
-L) |
||||
eat=1 |
||||
func_cl_dashL "$2" |
||||
;; |
||||
-L*) |
||||
func_cl_dashL "${1#-L}" |
||||
;; |
||||
-static) |
||||
shared=false |
||||
;; |
||||
-Wl,*) |
||||
arg=${1#-Wl,} |
||||
save_ifs="$IFS"; IFS=',' |
||||
for flag in $arg; do |
||||
IFS="$save_ifs" |
||||
linker_opts="$linker_opts $flag" |
||||
done |
||||
IFS="$save_ifs" |
||||
;; |
||||
-Xlinker) |
||||
eat=1 |
||||
linker_opts="$linker_opts $2" |
||||
;; |
||||
-*) |
||||
set x "$@" "$1" |
||||
shift |
||||
;; |
||||
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++) |
||||
func_file_conv "$1" |
||||
set x "$@" -Tp"$file" |
||||
shift |
||||
;; |
||||
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) |
||||
func_file_conv "$1" mingw |
||||
set x "$@" "$file" |
||||
shift |
||||
;; |
||||
*) |
||||
set x "$@" "$1" |
||||
shift |
||||
;; |
||||
esac |
||||
fi |
||||
shift |
||||
done |
||||
if test -n "$linker_opts"; then |
||||
linker_opts="-link$linker_opts" |
||||
fi |
||||
exec "$@" $linker_opts |
||||
exit 1 |
||||
} |
||||
|
||||
eat= |
||||
|
||||
case $1 in |
||||
'') |
||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2 |
||||
exit 1; |
||||
;; |
||||
-h | --h*) |
||||
cat <<\EOF |
||||
Usage: compile [--help] [--version] PROGRAM [ARGS] |
||||
|
||||
Wrapper for compilers which do not understand '-c -o'. |
||||
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining |
||||
arguments, and rename the output as expected. |
||||
|
||||
If you are trying to build a whole package this is not the |
||||
right script to run: please start by reading the file 'INSTALL'. |
||||
|
||||
Report bugs to <bug-automake@gnu.org>. |
||||
EOF |
||||
exit $? |
||||
;; |
||||
-v | --v*) |
||||
echo "compile $scriptversion" |
||||
exit $? |
||||
;; |
||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ |
||||
icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) |
||||
func_cl_wrapper "$@" # Doesn't return... |
||||
;; |
||||
esac |
||||
|
||||
ofile= |
||||
cfile= |
||||
|
||||
for arg |
||||
do |
||||
if test -n "$eat"; then |
||||
eat= |
||||
else |
||||
case $1 in |
||||
-o) |
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'. |
||||
# So we strip '-o arg' only if arg is an object. |
||||
eat=1 |
||||
case $2 in |
||||
*.o | *.obj) |
||||
ofile=$2 |
||||
;; |
||||
*) |
||||
set x "$@" -o "$2" |
||||
shift |
||||
;; |
||||
esac |
||||
;; |
||||
*.c) |
||||
cfile=$1 |
||||
set x "$@" "$1" |
||||
shift |
||||
;; |
||||
*) |
||||
set x "$@" "$1" |
||||
shift |
||||
;; |
||||
esac |
||||
fi |
||||
shift |
||||
done |
||||
|
||||
if test -z "$ofile" || test -z "$cfile"; then |
||||
# If no '-o' option was seen then we might have been invoked from a |
||||
# pattern rule where we don't need one. That is ok -- this is a |
||||
# normal compilation that the losing compiler can handle. If no |
||||
# '.c' file was seen then we are probably linking. That is also |
||||
# ok. |
||||
exec "$@" |
||||
fi |
||||
|
||||
# Name of file we expect compiler to create. |
||||
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` |
||||
|
||||
# Create the lock directory. |
||||
# Note: use '[/\\:.-]' here to ensure that we don't use the same name |
||||
# that we are using for the .o file. Also, base the name on the expected |
||||
# object file name, since that is what matters with a parallel build. |
||||
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d |
||||
while true; do |
||||
if mkdir "$lockdir" >/dev/null 2>&1; then |
||||
break |
||||
fi |
||||
sleep 1 |
||||
done |
||||
# FIXME: race condition here if user kills between mkdir and trap. |
||||
trap "rmdir '$lockdir'; exit 1" 1 2 15 |
||||
|
||||
# Run the compile. |
||||
"$@" |
||||
ret=$? |
||||
|
||||
if test -f "$cofile"; then |
||||
test "$cofile" = "$ofile" || mv "$cofile" "$ofile" |
||||
elif test -f "${cofile}bj"; then |
||||
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" |
||||
fi |
||||
|
||||
rmdir "$lockdir" |
||||
exit $ret |
||||
|
||||
# Local Variables: |
||||
# mode: shell-script |
||||
# sh-indentation: 2 |
||||
# eval: (add-hook 'before-save-hook 'time-stamp) |
||||
# time-stamp-start: "scriptversion=" |
||||
# time-stamp-format: "%:y-%02m-%02d.%02H" |
||||
# time-stamp-time-zone: "UTC0" |
||||
# time-stamp-end: "; # UTC" |
||||
# End: |
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,791 +0,0 @@ |
||||
#! /bin/sh |
||||
# depcomp - compile a program generating dependencies as side-effects |
||||
|
||||
scriptversion=2018-03-07.03; # UTC |
||||
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc. |
||||
|
||||
# This program is free software; you can redistribute it and/or modify |
||||
# it under the terms of the GNU General Public License as published by |
||||
# the Free Software Foundation; either version 2, or (at your option) |
||||
# any later version. |
||||
|
||||
# This program 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 General Public License for more details. |
||||
|
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
|
||||
# As a special exception to the GNU General Public License, if you |
||||
# distribute this file as part of a program that contains a |
||||
# configuration script generated by Autoconf, you may include it under |
||||
# the same distribution terms that you use for the rest of that program. |
||||
|
||||
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. |
||||
|
||||
case $1 in |
||||
'') |
||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2 |
||||
exit 1; |
||||
;; |
||||
-h | --h*) |
||||
cat <<\EOF |
||||
Usage: depcomp [--help] [--version] PROGRAM [ARGS] |
||||
|
||||
Run PROGRAMS ARGS to compile a file, generating dependencies |
||||
as side-effects. |
||||
|
||||
Environment variables: |
||||
depmode Dependency tracking mode. |
||||
source Source file read by 'PROGRAMS ARGS'. |
||||
object Object file output by 'PROGRAMS ARGS'. |
||||
DEPDIR directory where to store dependencies. |
||||
depfile Dependency file to output. |
||||
tmpdepfile Temporary file to use when outputting dependencies. |
||||
libtool Whether libtool is used (yes/no). |
||||
|
||||
Report bugs to <bug-automake@gnu.org>. |
||||
EOF |
||||
exit $? |
||||
;; |
||||
-v | --v*) |
||||
echo "depcomp $scriptversion" |
||||
exit $? |
||||
;; |
||||
esac |
||||
|
||||
# Get the directory component of the given path, and save it in the |
||||
# global variables '$dir'. Note that this directory component will |
||||
# be either empty or ending with a '/' character. This is deliberate. |
||||
set_dir_from () |
||||
{ |
||||
case $1 in |
||||
*/*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; |
||||
*) dir=;; |
||||
esac |
||||
} |
||||
|
||||
# Get the suffix-stripped basename of the given path, and save it the |
||||
# global variable '$base'. |
||||
set_base_from () |
||||
{ |
||||
base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` |
||||
} |
||||
|
||||
# If no dependency file was actually created by the compiler invocation, |
||||
# we still have to create a dummy depfile, to avoid errors with the |
||||
# Makefile "include basename.Plo" scheme. |
||||
make_dummy_depfile () |
||||
{ |
||||
echo "#dummy" > "$depfile" |
||||
} |
||||
|
||||
# Factor out some common post-processing of the generated depfile. |
||||
# Requires the auxiliary global variable '$tmpdepfile' to be set. |
||||
aix_post_process_depfile () |
||||
{ |
||||
# If the compiler actually managed to produce a dependency file, |
||||
# post-process it. |
||||
if test -f "$tmpdepfile"; then |
||||
# Each line is of the form 'foo.o: dependency.h'. |
||||
# Do two passes, one to just change these to |
||||
# $object: dependency.h |
||||
# and one to simply output |
||||
# dependency.h: |
||||
# which is needed to avoid the deleted-header problem. |
||||
{ sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" |
||||
sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" |
||||
} > "$depfile" |
||||
rm -f "$tmpdepfile" |
||||
else |
||||
make_dummy_depfile |
||||
fi |
||||
} |
||||
|
||||
# A tabulation character. |
||||
tab=' ' |
||||
# A newline character. |
||||
nl=' |
||||
' |
||||
# Character ranges might be problematic outside the C locale. |
||||
# These definitions help. |
||||
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ |
||||
lower=abcdefghijklmnopqrstuvwxyz |
||||
digits=0123456789 |
||||
alpha=${upper}${lower} |
||||
|
||||
if test -z "$depmode" || test -z "$source" || test -z "$object"; then |
||||
echo "depcomp: Variables source, object and depmode must be set" 1>&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. |
||||
depfile=${depfile-`echo "$object" | |
||||
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} |
||||
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} |
||||
|
||||
rm -f "$tmpdepfile" |
||||
|
||||
# Avoid interferences from the environment. |
||||
gccflag= dashmflag= |
||||
|
||||
# Some modes work just like other modes, but use different flags. We |
||||
# parameterize here, but still list the modes in the big case below, |
||||
# to make depend.m4 easier to write. Note that we *cannot* use a case |
||||
# here, because this file can only contain one case statement. |
||||
if test "$depmode" = hp; then |
||||
# HP compiler uses -M and no extra arg. |
||||
gccflag=-M |
||||
depmode=gcc |
||||
fi |
||||
|
||||
if test "$depmode" = dashXmstdout; then |
||||
# This is just like dashmstdout with a different argument. |
||||
dashmflag=-xM |
||||
depmode=dashmstdout |
||||
fi |
||||
|
||||
cygpath_u="cygpath -u -f -" |
||||
if test "$depmode" = msvcmsys; then |
||||
# This is just like msvisualcpp but w/o cygpath translation. |
||||
# Just convert the backslash-escaped backslashes to single forward |
||||
# slashes to satisfy depend.m4 |
||||
cygpath_u='sed s,\\\\,/,g' |
||||
depmode=msvisualcpp |
||||
fi |
||||
|
||||
if test "$depmode" = msvc7msys; then |
||||
# This is just like msvc7 but w/o cygpath translation. |
||||
# Just convert the backslash-escaped backslashes to single forward |
||||
# slashes to satisfy depend.m4 |
||||
cygpath_u='sed s,\\\\,/,g' |
||||
depmode=msvc7 |
||||
fi |
||||
|
||||
if test "$depmode" = xlc; then |
||||
# IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. |
||||
gccflag=-qmakedep=gcc,-MF |
||||
depmode=gcc |
||||
fi |
||||
|
||||
case "$depmode" in |
||||
gcc3) |
||||
## gcc 3 implements dependency tracking that does exactly what |
||||
## we want. Yay! Note: for some reason libtool 1.4 doesn't like |
||||
## it if -MD -MP comes after the -MF stuff. Hmm. |
||||
## Unfortunately, FreeBSD c89 acceptance of flags depends upon |
||||
## the command line argument order; so add the flags where they |
||||
## appear in depend2.am. Note that the slowdown incurred here |
||||
## affects only configure: in makefiles, %FASTDEP% shortcuts this. |
||||
for arg |
||||
do |
||||
case $arg in |
||||
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; |
||||
*) set fnord "$@" "$arg" ;; |
||||
esac |
||||
shift # fnord |
||||
shift # $arg |
||||
done |
||||
"$@" |
||||
stat=$? |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile" |
||||
exit $stat |
||||
fi |
||||
mv "$tmpdepfile" "$depfile" |
||||
;; |
||||
|
||||
gcc) |
||||
## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. |
||||
## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. |
||||
## (see the conditional assignment to $gccflag above). |
||||
## There are various ways to get dependency output from gcc. Here's |
||||
## why we pick this rather obscure method: |
||||
## - Don't want to use -MD because we'd like the dependencies to end |
||||
## up in a subdir. Having to rename by hand is ugly. |
||||
## (We might end up doing this anyway to support other compilers.) |
||||
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like |
||||
## -MM, not -M (despite what the docs say). Also, it might not be |
||||
## supported by the other compilers which use the 'gcc' depmode. |
||||
## - Using -M directly means running the compiler twice (even worse |
||||
## than renaming). |
||||
if test -z "$gccflag"; then |
||||
gccflag=-MD, |
||||
fi |
||||
"$@" -Wp,"$gccflag$tmpdepfile" |
||||
stat=$? |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile" |
||||
exit $stat |
||||
fi |
||||
rm -f "$depfile" |
||||
echo "$object : \\" > "$depfile" |
||||
# The second -e expression handles DOS-style file names with drive |
||||
# letters. |
||||
sed -e 's/^[^:]*: / /' \ |
||||
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" |
||||
## This next piece of magic avoids the "deleted header file" problem. |
||||
## The problem is that when a header file which appears in a .P file |
||||
## is deleted, the dependency causes make to die (because there is |
||||
## typically no way to rebuild the header). We avoid this by adding |
||||
## dummy dependencies for each header file. Too bad gcc doesn't do |
||||
## this for us directly. |
||||
## Some versions of gcc put a space before the ':'. On the theory |
||||
## that the space means something, we add a space to the output as |
||||
## well. hp depmode also adds that space, but also prefixes the VPATH |
||||
## to the object. Take care to not repeat it in the output. |
||||
## Some versions of the HPUX 10.20 sed can't process this invocation |
||||
## correctly. Breaking it into two sed invocations is a workaround. |
||||
tr ' ' "$nl" < "$tmpdepfile" \ |
||||
| sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ |
||||
| sed -e 's/$/ :/' >> "$depfile" |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
hp) |
||||
# This case exists only to let depend.m4 do its work. It works by |
||||
# looking at the text of this script. This case will never be run, |
||||
# since it is checked for above. |
||||
exit 1 |
||||
;; |
||||
|
||||
sgi) |
||||
if test "$libtool" = yes; then |
||||
"$@" "-Wp,-MDupdate,$tmpdepfile" |
||||
else |
||||
"$@" -MDupdate "$tmpdepfile" |
||||
fi |
||||
stat=$? |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile" |
||||
exit $stat |
||||
fi |
||||
rm -f "$depfile" |
||||
|
||||
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files |
||||
echo "$object : \\" > "$depfile" |
||||
# Clip off the initial element (the dependent). Don't try to be |
||||
# clever and replace this with sed code, as IRIX sed won't handle |
||||
# lines with more than a fixed number of characters (4096 in |
||||
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; |
||||
# the IRIX cc adds comments like '#:fec' to the end of the |
||||
# dependency line. |
||||
tr ' ' "$nl" < "$tmpdepfile" \ |
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ |
||||
| tr "$nl" ' ' >> "$depfile" |
||||
echo >> "$depfile" |
||||
# The second pass generates a dummy entry for each header file. |
||||
tr ' ' "$nl" < "$tmpdepfile" \ |
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ |
||||
>> "$depfile" |
||||
else |
||||
make_dummy_depfile |
||||
fi |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
xlc) |
||||
# This case exists only to let depend.m4 do its work. It works by |
||||
# looking at the text of this script. This case will never be run, |
||||
# since it is checked for above. |
||||
exit 1 |
||||
;; |
||||
|
||||
aix) |
||||
# The C for AIX Compiler uses -M and outputs the dependencies |
||||
# in a .u file. In older versions, this file always lives in the |
||||
# current directory. Also, the AIX compiler puts '$object:' at the |
||||
# start of each line; $object doesn't have directory information. |
||||
# Version 6 uses the directory in both cases. |
||||
set_dir_from "$object" |
||||
set_base_from "$object" |
||||
if test "$libtool" = yes; then |
||||
tmpdepfile1=$dir$base.u |
||||
tmpdepfile2=$base.u |
||||
tmpdepfile3=$dir.libs/$base.u |
||||
"$@" -Wc,-M |
||||
else |
||||
tmpdepfile1=$dir$base.u |
||||
tmpdepfile2=$dir$base.u |
||||
tmpdepfile3=$dir$base.u |
||||
"$@" -M |
||||
fi |
||||
stat=$? |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" |
||||
exit $stat |
||||
fi |
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" |
||||
do |
||||
test -f "$tmpdepfile" && break |
||||
done |
||||
aix_post_process_depfile |
||||
;; |
||||
|
||||
tcc) |
||||
# tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 |
||||
# FIXME: That version still under development at the moment of writing. |
||||
# Make that this statement remains true also for stable, released |
||||
# versions. |
||||
# It will wrap lines (doesn't matter whether long or short) with a |
||||
# trailing '\', as in: |
||||
# |
||||
# foo.o : \ |
||||
# foo.c \ |
||||
# foo.h \ |
||||
# |
||||
# It will put a trailing '\' even on the last line, and will use leading |
||||
# spaces rather than leading tabs (at least since its commit 0394caf7 |
||||
# "Emit spaces for -MD"). |
||||
"$@" -MD -MF "$tmpdepfile" |
||||
stat=$? |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile" |
||||
exit $stat |
||||
fi |
||||
rm -f "$depfile" |
||||
# Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. |
||||
# We have to change lines of the first kind to '$object: \'. |
||||
sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" |
||||
# And for each line of the second kind, we have to emit a 'dep.h:' |
||||
# dummy dependency, to avoid the deleted-header problem. |
||||
sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
## The order of this option in the case statement is important, since the |
||||
## shell code in configure will try each of these formats in the order |
||||
## listed in this file. A plain '-MD' option would be understood by many |
||||
## compilers, so we must ensure this comes after the gcc and icc options. |
||||
pgcc) |
||||
# Portland's C compiler understands '-MD'. |
||||
# Will always output deps to 'file.d' where file is the root name of the |
||||
# source file under compilation, even if file resides in a subdirectory. |
||||
# The object file name does not affect the name of the '.d' file. |
||||
# pgcc 10.2 will output |
||||
# foo.o: sub/foo.c sub/foo.h |
||||
# and will wrap long lines using '\' : |
||||
# foo.o: sub/foo.c ... \ |
||||
# sub/foo.h ... \ |
||||
# ... |
||||
set_dir_from "$object" |
||||
# Use the source, not the object, to determine the base name, since |
||||
# that's sadly what pgcc will do too. |
||||
set_base_from "$source" |
||||
tmpdepfile=$base.d |
||||
|
||||
# For projects that build the same source file twice into different object |
||||
# files, the pgcc approach of using the *source* file root name can cause |
||||
# problems in parallel builds. Use a locking strategy to avoid stomping on |
||||
# the same $tmpdepfile. |
||||
lockdir=$base.d-lock |
||||
trap " |
||||
echo '$0: caught signal, cleaning up...' >&2 |
||||
rmdir '$lockdir' |
||||
exit 1 |
||||
" 1 2 13 15 |
||||
numtries=100 |
||||
i=$numtries |
||||
while test $i -gt 0; do |
||||
# mkdir is a portable test-and-set. |
||||
if mkdir "$lockdir" 2>/dev/null; then |
||||
# This process acquired the lock. |
||||
"$@" -MD |
||||
stat=$? |
||||
# Release the lock. |
||||
rmdir "$lockdir" |
||||
break |
||||
else |
||||
# If the lock is being held by a different process, wait |
||||
# until the winning process is done or we timeout. |
||||
while test -d "$lockdir" && test $i -gt 0; do |
||||
sleep 1 |
||||
i=`expr $i - 1` |
||||
done |
||||
fi |
||||
i=`expr $i - 1` |
||||
done |
||||
trap - 1 2 13 15 |
||||
if test $i -le 0; then |
||||
echo "$0: failed to acquire lock after $numtries attempts" >&2 |
||||
echo "$0: check lockdir '$lockdir'" >&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile" |
||||
exit $stat |
||||
fi |
||||
rm -f "$depfile" |
||||
# Each line is of the form `foo.o: dependent.h', |
||||
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. |
||||
# Do two passes, one to just change these to |
||||
# `$object: dependent.h' and one to simply `dependent.h:'. |
||||
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" |
||||
# Some versions of the HPUX 10.20 sed can't process this invocation |
||||
# correctly. Breaking it into two sed invocations is a workaround. |
||||
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ |
||||
| sed -e 's/$/ :/' >> "$depfile" |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
hp2) |
||||
# The "hp" stanza above does not work with aCC (C++) and HP's ia64 |
||||
# compilers, which have integrated preprocessors. The correct option |
||||
# to use with these is +Maked; it writes dependencies to a file named |
||||
# 'foo.d', which lands next to the object file, wherever that |
||||
# happens to be. |
||||
# Much of this is similar to the tru64 case; see comments there. |
||||
set_dir_from "$object" |
||||
set_base_from "$object" |
||||
if test "$libtool" = yes; then |
||||
tmpdepfile1=$dir$base.d |
||||
tmpdepfile2=$dir.libs/$base.d |
||||
"$@" -Wc,+Maked |
||||
else |
||||
tmpdepfile1=$dir$base.d |
||||
tmpdepfile2=$dir$base.d |
||||
"$@" +Maked |
||||
fi |
||||
stat=$? |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" |
||||
exit $stat |
||||
fi |
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" |
||||
do |
||||
test -f "$tmpdepfile" && break |
||||
done |
||||
if test -f "$tmpdepfile"; then |
||||
sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" |
||||
# Add 'dependent.h:' lines. |
||||
sed -ne '2,${ |
||||
s/^ *// |
||||
s/ \\*$// |
||||
s/$/:/ |
||||
p |
||||
}' "$tmpdepfile" >> "$depfile" |
||||
else |
||||
make_dummy_depfile |
||||
fi |
||||
rm -f "$tmpdepfile" "$tmpdepfile2" |
||||
;; |
||||
|
||||
tru64) |
||||
# The Tru64 compiler uses -MD to generate dependencies as a side |
||||
# effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. |
||||
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put |
||||
# dependencies in 'foo.d' instead, so we check for that too. |
||||
# Subdirectories are respected. |
||||
set_dir_from "$object" |
||||
set_base_from "$object" |
||||
|
||||
if test "$libtool" = yes; then |
||||
# Libtool generates 2 separate objects for the 2 libraries. These |
||||
# two compilations output dependencies in $dir.libs/$base.o.d and |
||||
# in $dir$base.o.d. We have to check for both files, because |
||||
# one of the two compilations can be disabled. We should prefer |
||||
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is |
||||
# automatically cleaned when .libs/ is deleted, while ignoring |
||||
# the former would cause a distcleancheck panic. |
||||
tmpdepfile1=$dir$base.o.d # libtool 1.5 |
||||
tmpdepfile2=$dir.libs/$base.o.d # Likewise. |
||||
tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 |
||||
"$@" -Wc,-MD |
||||
else |
||||
tmpdepfile1=$dir$base.d |
||||
tmpdepfile2=$dir$base.d |
||||
tmpdepfile3=$dir$base.d |
||||
"$@" -MD |
||||
fi |
||||
|
||||
stat=$? |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" |
||||
exit $stat |
||||
fi |
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" |
||||
do |
||||
test -f "$tmpdepfile" && break |
||||
done |
||||
# Same post-processing that is required for AIX mode. |
||||
aix_post_process_depfile |
||||
;; |
||||
|
||||
msvc7) |
||||
if test "$libtool" = yes; then |
||||
showIncludes=-Wc,-showIncludes |
||||
else |
||||
showIncludes=-showIncludes |
||||
fi |
||||
"$@" $showIncludes > "$tmpdepfile" |
||||
stat=$? |
||||
grep -v '^Note: including file: ' "$tmpdepfile" |
||||
if test $stat -ne 0; then |
||||
rm -f "$tmpdepfile" |
||||
exit $stat |
||||
fi |
||||
rm -f "$depfile" |
||||
echo "$object : \\" > "$depfile" |
||||
# The first sed program below extracts the file names and escapes |
||||
# backslashes for cygpath. The second sed program outputs the file |
||||
# name when reading, but also accumulates all include files in the |
||||
# hold buffer in order to output them again at the end. This only |
||||
# works with sed implementations that can handle large buffers. |
||||
sed < "$tmpdepfile" -n ' |
||||
/^Note: including file: *\(.*\)/ { |
||||
s//\1/ |
||||
s/\\/\\\\/g |
||||
p |
||||
}' | $cygpath_u | sort -u | sed -n ' |
||||
s/ /\\ /g |
||||
s/\(.*\)/'"$tab"'\1 \\/p |
||||
s/.\(.*\) \\/\1:/ |
||||
H |
||||
$ { |
||||
s/.*/'"$tab"'/ |
||||
G |
||||
p |
||||
}' >> "$depfile" |
||||
echo >> "$depfile" # make sure the fragment doesn't end with a backslash |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
msvc7msys) |
||||
# This case exists only to let depend.m4 do its work. It works by |
||||
# looking at the text of this script. This case will never be run, |
||||
# since it is checked for above. |
||||
exit 1 |
||||
;; |
||||
|
||||
#nosideeffect) |
||||
# This comment above is used by automake to tell side-effect |
||||
# dependency tracking mechanisms from slower ones. |
||||
|
||||
dashmstdout) |
||||
# Important note: in order to support this mode, a compiler *must* |
||||
# always write the preprocessed file to stdout, regardless of -o. |
||||
"$@" || exit $? |
||||
|
||||
# Remove the call to Libtool. |
||||
if test "$libtool" = yes; then |
||||
while test "X$1" != 'X--mode=compile'; do |
||||
shift |
||||
done |
||||
shift |
||||
fi |
||||
|
||||
# Remove '-o $object'. |
||||
IFS=" " |
||||
for arg |
||||
do |
||||
case $arg in |
||||
-o) |
||||
shift |
||||
;; |
||||
$object) |
||||
shift |
||||
;; |
||||
*) |
||||
set fnord "$@" "$arg" |
||||
shift # fnord |
||||
shift # $arg |
||||
;; |
||||
esac |
||||
done |
||||
|
||||
test -z "$dashmflag" && dashmflag=-M |
||||
# Require at least two characters before searching for ':' |
||||
# in the target name. This is to cope with DOS-style filenames: |
||||
# a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. |
||||
"$@" $dashmflag | |
||||
sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" |
||||
rm -f "$depfile" |
||||
cat < "$tmpdepfile" > "$depfile" |
||||
# Some versions of the HPUX 10.20 sed can't process this sed invocation |
||||
# correctly. Breaking it into two sed invocations is a workaround. |
||||
tr ' ' "$nl" < "$tmpdepfile" \ |
||||
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ |
||||
| sed -e 's/$/ :/' >> "$depfile" |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
dashXmstdout) |
||||
# This case only exists to satisfy depend.m4. It is never actually |
||||
# run, as this mode is specially recognized in the preamble. |
||||
exit 1 |
||||
;; |
||||
|
||||
makedepend) |
||||
"$@" || exit $? |
||||
# Remove any Libtool call |
||||
if test "$libtool" = yes; then |
||||
while test "X$1" != 'X--mode=compile'; do |
||||
shift |
||||
done |
||||
shift |
||||
fi |
||||
# X makedepend |
||||
shift |
||||
cleared=no eat=no |
||||
for arg |
||||
do |
||||
case $cleared in |
||||
no) |
||||
set ""; shift |
||||
cleared=yes ;; |
||||
esac |
||||
if test $eat = yes; then |
||||
eat=no |
||||
continue |
||||
fi |
||||
case "$arg" in |
||||
-D*|-I*) |
||||
set fnord "$@" "$arg"; shift ;; |
||||
# Strip any option that makedepend may not understand. Remove |
||||
# the object too, otherwise makedepend will parse it as a source file. |
||||
-arch) |
||||
eat=yes ;; |
||||
-*|$object) |
||||
;; |
||||
*) |
||||
set fnord "$@" "$arg"; shift ;; |
||||
esac |
||||
done |
||||
obj_suffix=`echo "$object" | sed 's/^.*\././'` |
||||
touch "$tmpdepfile" |
||||
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" |
||||
rm -f "$depfile" |
||||
# makedepend may prepend the VPATH from the source file name to the object. |
||||
# No need to regex-escape $object, excess matching of '.' is harmless. |
||||
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" |
||||
# Some versions of the HPUX 10.20 sed can't process the last invocation |
||||
# correctly. Breaking it into two sed invocations is a workaround. |
||||
sed '1,2d' "$tmpdepfile" \ |
||||
| tr ' ' "$nl" \ |
||||
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ |
||||
| sed -e 's/$/ :/' >> "$depfile" |
||||
rm -f "$tmpdepfile" "$tmpdepfile".bak |
||||
;; |
||||
|
||||
cpp) |
||||
# Important note: in order to support this mode, a compiler *must* |
||||
# always write the preprocessed file to stdout. |
||||
"$@" || exit $? |
||||
|
||||
# Remove the call to Libtool. |
||||
if test "$libtool" = yes; then |
||||
while test "X$1" != 'X--mode=compile'; do |
||||
shift |
||||
done |
||||
shift |
||||
fi |
||||
|
||||
# Remove '-o $object'. |
||||
IFS=" " |
||||
for arg |
||||
do |
||||
case $arg in |
||||
-o) |
||||
shift |
||||
;; |
||||
$object) |
||||
shift |
||||
;; |
||||
*) |
||||
set fnord "$@" "$arg" |
||||
shift # fnord |
||||
shift # $arg |
||||
;; |
||||
esac |
||||
done |
||||
|
||||
"$@" -E \ |
||||
| sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ |
||||
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ |
||||
| sed '$ s: \\$::' > "$tmpdepfile" |
||||
rm -f "$depfile" |
||||
echo "$object : \\" > "$depfile" |
||||
cat < "$tmpdepfile" >> "$depfile" |
||||
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
msvisualcpp) |
||||
# Important note: in order to support this mode, a compiler *must* |
||||
# always write the preprocessed file to stdout. |
||||
"$@" || exit $? |
||||
|
||||
# Remove the call to Libtool. |
||||
if test "$libtool" = yes; then |
||||
while test "X$1" != 'X--mode=compile'; do |
||||
shift |
||||
done |
||||
shift |
||||
fi |
||||
|
||||
IFS=" " |
||||
for arg |
||||
do |
||||
case "$arg" in |
||||
-o) |
||||
shift |
||||
;; |
||||
$object) |
||||
shift |
||||
;; |
||||
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") |
||||
set fnord "$@" |
||||
shift |
||||
shift |
||||
;; |
||||
*) |
||||
set fnord "$@" "$arg" |
||||
shift |
||||
shift |
||||
;; |
||||
esac |
||||
done |
||||
"$@" -E 2>/dev/null | |
||||
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" |
||||
rm -f "$depfile" |
||||
echo "$object : \\" > "$depfile" |
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" |
||||
echo "$tab" >> "$depfile" |
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" |
||||
rm -f "$tmpdepfile" |
||||
;; |
||||
|
||||
msvcmsys) |
||||
# This case exists only to let depend.m4 do its work. It works by |
||||
# looking at the text of this script. This case will never be run, |
||||
# since it is checked for above. |
||||
exit 1 |
||||
;; |
||||
|
||||
none) |
||||
exec "$@" |
||||
;; |
||||
|
||||
*) |
||||
echo "Unknown depmode $depmode" 1>&2 |
||||
exit 1 |
||||
;; |
||||
esac |
||||
|
||||
exit 0 |
||||
|
||||
# Local Variables: |
||||
# mode: shell-script |
||||
# sh-indentation: 2 |
||||
# eval: (add-hook 'before-save-hook 'time-stamp) |
||||
# time-stamp-start: "scriptversion=" |
||||
# time-stamp-format: "%:y-%02m-%02d.%02H" |
||||
# time-stamp-time-zone: "UTC0" |
||||
# time-stamp-end: "; # UTC" |
||||
# End: |
||||
@ -1,541 +0,0 @@ |
||||
#!/bin/sh |
||||
# install - install a program, script, or datafile |
||||
|
||||
scriptversion=2020-11-14.01; # UTC |
||||
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was |
||||
# later released in X11R6 (xc/config/util/install.sh) with the |
||||
# following copyright and license. |
||||
# |
||||
# Copyright (C) 1994 X Consortium |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
# of this software and associated documentation files (the "Software"), to |
||||
# deal in the Software without restriction, including without limitation the |
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
||||
# sell copies of the Software, and to permit persons to whom the Software is |
||||
# furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included in |
||||
# all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||||
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- |
||||
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
# |
||||
# Except as contained in this notice, the name of the X Consortium shall not |
||||
# be used in advertising or otherwise to promote the sale, use or other deal- |
||||
# ings in this Software without prior written authorization from the X Consor- |
||||
# tium. |
||||
# |
||||
# |
||||
# FSF changes to this file are in the public domain. |
||||
# |
||||
# Calling this script install-sh is preferred over install.sh, to prevent |
||||
# 'make' implicit rules from creating a file called install from it |
||||
# when there is no Makefile. |
||||
# |
||||
# This script is compatible with the BSD install script, but was written |
||||
# from scratch. |
||||
|
||||
tab=' ' |
||||
nl=' |
||||
' |
||||
IFS=" $tab$nl" |
||||
|
||||
# Set DOITPROG to "echo" to test this script. |
||||
|
||||
doit=${DOITPROG-} |
||||
doit_exec=${doit:-exec} |
||||
|
||||
# Put in absolute file names if you don't have them in your path; |
||||
# or use environment vars. |
||||
|
||||
chgrpprog=${CHGRPPROG-chgrp} |
||||
chmodprog=${CHMODPROG-chmod} |
||||
chownprog=${CHOWNPROG-chown} |
||||
cmpprog=${CMPPROG-cmp} |
||||
cpprog=${CPPROG-cp} |
||||
mkdirprog=${MKDIRPROG-mkdir} |
||||
mvprog=${MVPROG-mv} |
||||
rmprog=${RMPROG-rm} |
||||
stripprog=${STRIPPROG-strip} |
||||
|
||||
posix_mkdir= |
||||
|
||||
# Desired mode of installed file. |
||||
mode=0755 |
||||
|
||||
# Create dirs (including intermediate dirs) using mode 755. |
||||
# This is like GNU 'install' as of coreutils 8.32 (2020). |
||||
mkdir_umask=22 |
||||
|
||||
backupsuffix= |
||||
chgrpcmd= |
||||
chmodcmd=$chmodprog |
||||
chowncmd= |
||||
mvcmd=$mvprog |
||||
rmcmd="$rmprog -f" |
||||
stripcmd= |
||||
|
||||
src= |
||||
dst= |
||||
dir_arg= |
||||
dst_arg= |
||||
|
||||
copy_on_change=false |
||||
is_target_a_directory=possibly |
||||
|
||||
usage="\ |
||||
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE |
||||
or: $0 [OPTION]... SRCFILES... DIRECTORY |
||||
or: $0 [OPTION]... -t DIRECTORY SRCFILES... |
||||
or: $0 [OPTION]... -d DIRECTORIES... |
||||
|
||||
In the 1st form, copy SRCFILE to DSTFILE. |
||||
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. |
||||
In the 4th, create DIRECTORIES. |
||||
|
||||
Options: |
||||
--help display this help and exit. |
||||
--version display version info and exit. |
||||
|
||||
-c (ignored) |
||||
-C install only if different (preserve data modification time) |
||||
-d create directories instead of installing files. |
||||
-g GROUP $chgrpprog installed files to GROUP. |
||||
-m MODE $chmodprog installed files to MODE. |
||||
-o USER $chownprog installed files to USER. |
||||
-p pass -p to $cpprog. |
||||
-s $stripprog installed files. |
||||
-S SUFFIX attempt to back up existing files, with suffix SUFFIX. |
||||
-t DIRECTORY install into DIRECTORY. |
||||
-T report an error if DSTFILE is a directory. |
||||
|
||||
Environment variables override the default commands: |
||||
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG |
||||
RMPROG STRIPPROG |
||||
|
||||
By default, rm is invoked with -f; when overridden with RMPROG, |
||||
it's up to you to specify -f if you want it. |
||||
|
||||
If -S is not specified, no backups are attempted. |
||||
|
||||
Email bug reports to bug-automake@gnu.org. |
||||
Automake home page: https://www.gnu.org/software/automake/ |
||||
" |
||||
|
||||
while test $# -ne 0; do |
||||
case $1 in |
||||
-c) ;; |
||||
|
||||
-C) copy_on_change=true;; |
||||
|
||||
-d) dir_arg=true;; |
||||
|
||||
-g) chgrpcmd="$chgrpprog $2" |
||||
shift;; |
||||
|
||||
--help) echo "$usage"; exit $?;; |
||||
|
||||
-m) mode=$2 |
||||
case $mode in |
||||
*' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) |
||||
echo "$0: invalid mode: $mode" >&2 |
||||
exit 1;; |
||||
esac |
||||
shift;; |
||||
|
||||
-o) chowncmd="$chownprog $2" |
||||
shift;; |
||||
|
||||
-p) cpprog="$cpprog -p";; |
||||
|
||||
-s) stripcmd=$stripprog;; |
||||
|
||||
-S) backupsuffix="$2" |
||||
shift;; |
||||
|
||||
-t) |
||||
is_target_a_directory=always |
||||
dst_arg=$2 |
||||
# Protect names problematic for 'test' and other utilities. |
||||
case $dst_arg in |
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;; |
||||
esac |
||||
shift;; |
||||
|
||||
-T) is_target_a_directory=never;; |
||||
|
||||
--version) echo "$0 $scriptversion"; exit $?;; |
||||
|
||||
--) shift |
||||
break;; |
||||
|
||||
-*) echo "$0: invalid option: $1" >&2 |
||||
exit 1;; |
||||
|
||||
*) break;; |
||||
esac |
||||
shift |
||||
done |
||||
|
||||
# We allow the use of options -d and -T together, by making -d |
||||
# take the precedence; this is for compatibility with GNU install. |
||||
|
||||
if test -n "$dir_arg"; then |
||||
if test -n "$dst_arg"; then |
||||
echo "$0: target directory not allowed when installing a directory." >&2 |
||||
exit 1 |
||||
fi |
||||
fi |
||||
|
||||
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then |
||||
# When -d is used, all remaining arguments are directories to create. |
||||
# When -t is used, the destination is already specified. |
||||
# Otherwise, the last argument is the destination. Remove it from $@. |
||||
for arg |
||||
do |
||||
if test -n "$dst_arg"; then |
||||
# $@ is not empty: it contains at least $arg. |
||||
set fnord "$@" "$dst_arg" |
||||
shift # fnord |
||||
fi |
||||
shift # arg |
||||
dst_arg=$arg |
||||
# Protect names problematic for 'test' and other utilities. |
||||
case $dst_arg in |
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;; |
||||
esac |
||||
done |
||||
fi |
||||
|
||||
if test $# -eq 0; then |
||||
if test -z "$dir_arg"; then |
||||
echo "$0: no input file specified." >&2 |
||||
exit 1 |
||||
fi |
||||
# It's OK to call 'install-sh -d' without argument. |
||||
# This can happen when creating conditional directories. |
||||
exit 0 |
||||
fi |
||||
|
||||
if test -z "$dir_arg"; then |
||||
if test $# -gt 1 || test "$is_target_a_directory" = always; then |
||||
if test ! -d "$dst_arg"; then |
||||
echo "$0: $dst_arg: Is not a directory." >&2 |
||||
exit 1 |
||||
fi |
||||
fi |
||||
fi |
||||
|
||||
if test -z "$dir_arg"; then |
||||
do_exit='(exit $ret); exit $ret' |
||||
trap "ret=129; $do_exit" 1 |
||||
trap "ret=130; $do_exit" 2 |
||||
trap "ret=141; $do_exit" 13 |
||||
trap "ret=143; $do_exit" 15 |
||||
|
||||
# Set umask so as not to create temps with too-generous modes. |
||||
# However, 'strip' requires both read and write access to temps. |
||||
case $mode in |
||||
# Optimize common cases. |
||||
*644) cp_umask=133;; |
||||
*755) cp_umask=22;; |
||||
|
||||
*[0-7]) |
||||
if test -z "$stripcmd"; then |
||||
u_plus_rw= |
||||
else |
||||
u_plus_rw='% 200' |
||||
fi |
||||
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; |
||||
*) |
||||
if test -z "$stripcmd"; then |
||||
u_plus_rw= |
||||
else |
||||
u_plus_rw=,u+rw |
||||
fi |
||||
cp_umask=$mode$u_plus_rw;; |
||||
esac |
||||
fi |
||||
|
||||
for src |
||||
do |
||||
# Protect names problematic for 'test' and other utilities. |
||||
case $src in |
||||
-* | [=\(\)!]) src=./$src;; |
||||
esac |
||||
|
||||
if test -n "$dir_arg"; then |
||||
dst=$src |
||||
dstdir=$dst |
||||
test -d "$dstdir" |
||||
dstdir_status=$? |
||||
# Don't chown directories that already exist. |
||||
if test $dstdir_status = 0; then |
||||
chowncmd="" |
||||
fi |
||||
else |
||||
|
||||
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command |
||||
# might cause directories to be created, which would be especially bad |
||||
# if $src (and thus $dsttmp) contains '*'. |
||||
if test ! -f "$src" && test ! -d "$src"; then |
||||
echo "$0: $src does not exist." >&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
if test -z "$dst_arg"; then |
||||
echo "$0: no destination specified." >&2 |
||||
exit 1 |
||||
fi |
||||
dst=$dst_arg |
||||
|
||||
# If destination is a directory, append the input filename. |
||||
if test -d "$dst"; then |
||||
if test "$is_target_a_directory" = never; then |
||||
echo "$0: $dst_arg: Is a directory" >&2 |
||||
exit 1 |
||||
fi |
||||
dstdir=$dst |
||||
dstbase=`basename "$src"` |
||||
case $dst in |
||||
*/) dst=$dst$dstbase;; |
||||
*) dst=$dst/$dstbase;; |
||||
esac |
||||
dstdir_status=0 |
||||
else |
||||
dstdir=`dirname "$dst"` |
||||
test -d "$dstdir" |
||||
dstdir_status=$? |
||||
fi |
||||
fi |
||||
|
||||
case $dstdir in |
||||
*/) dstdirslash=$dstdir;; |
||||
*) dstdirslash=$dstdir/;; |
||||
esac |
||||
|
||||
obsolete_mkdir_used=false |
||||
|
||||
if test $dstdir_status != 0; then |
||||
case $posix_mkdir in |
||||
'') |
||||
# With -d, create the new directory with the user-specified mode. |
||||
# Otherwise, rely on $mkdir_umask. |
||||
if test -n "$dir_arg"; then |
||||
mkdir_mode=-m$mode |
||||
else |
||||
mkdir_mode= |
||||
fi |
||||
|
||||
posix_mkdir=false |
||||
# The $RANDOM variable is not portable (e.g., dash). Use it |
||||
# here however when possible just to lower collision chance. |
||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ |
||||
|
||||
trap ' |
||||
ret=$? |
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null |
||||
exit $ret |
||||
' 0 |
||||
|
||||
# Because "mkdir -p" follows existing symlinks and we likely work |
||||
# directly in world-writeable /tmp, make sure that the '$tmpdir' |
||||
# directory is successfully created first before we actually test |
||||
# 'mkdir -p'. |
||||
if (umask $mkdir_umask && |
||||
$mkdirprog $mkdir_mode "$tmpdir" && |
||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 |
||||
then |
||||
if test -z "$dir_arg" || { |
||||
# Check for POSIX incompatibilities with -m. |
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or |
||||
# other-writable bit of parent directory when it shouldn't. |
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory. |
||||
test_tmpdir="$tmpdir/a" |
||||
ls_ld_tmpdir=`ls -ld "$test_tmpdir"` |
||||
case $ls_ld_tmpdir in |
||||
d????-?r-*) different_mode=700;; |
||||
d????-?--*) different_mode=755;; |
||||
*) false;; |
||||
esac && |
||||
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && { |
||||
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` |
||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" |
||||
} |
||||
} |
||||
then posix_mkdir=: |
||||
fi |
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" |
||||
else |
||||
# Remove any dirs left behind by ancient mkdir implementations. |
||||
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null |
||||
fi |
||||
trap '' 0;; |
||||
esac |
||||
|
||||
if |
||||
$posix_mkdir && ( |
||||
umask $mkdir_umask && |
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" |
||||
) |
||||
then : |
||||
else |
||||
|
||||
# mkdir does not conform to POSIX, |
||||
# or it failed possibly due to a race condition. Create the |
||||
# directory the slow way, step by step, checking for races as we go. |
||||
|
||||
case $dstdir in |
||||
/*) prefix='/';; |
||||
[-=\(\)!]*) prefix='./';; |
||||
*) prefix='';; |
||||
esac |
||||
|
||||
oIFS=$IFS |
||||
IFS=/ |
||||
set -f |
||||
set fnord $dstdir |
||||
shift |
||||
set +f |
||||
IFS=$oIFS |
||||
|
||||
prefixes= |
||||
|
||||
for d |
||||
do |
||||
test X"$d" = X && continue |
||||
|
||||
prefix=$prefix$d |
||||
if test -d "$prefix"; then |
||||
prefixes= |
||||
else |
||||
if $posix_mkdir; then |
||||
(umask $mkdir_umask && |
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break |
||||
# Don't fail if two instances are running concurrently. |
||||
test -d "$prefix" || exit 1 |
||||
else |
||||
case $prefix in |
||||
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; |
||||
*) qprefix=$prefix;; |
||||
esac |
||||
prefixes="$prefixes '$qprefix'" |
||||
fi |
||||
fi |
||||
prefix=$prefix/ |
||||
done |
||||
|
||||
if test -n "$prefixes"; then |
||||
# Don't fail if two instances are running concurrently. |
||||
(umask $mkdir_umask && |
||||
eval "\$doit_exec \$mkdirprog $prefixes") || |
||||
test -d "$dstdir" || exit 1 |
||||
obsolete_mkdir_used=true |
||||
fi |
||||
fi |
||||
fi |
||||
|
||||
if test -n "$dir_arg"; then |
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } && |
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && |
||||
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || |
||||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 |
||||
else |
||||
|
||||
# Make a couple of temp file names in the proper directory. |
||||
dsttmp=${dstdirslash}_inst.$$_ |
||||
rmtmp=${dstdirslash}_rm.$$_ |
||||
|
||||
# Trap to clean up those temp files at exit. |
||||
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 |
||||
|
||||
# Copy the file name to the temp name. |
||||
(umask $cp_umask && |
||||
{ test -z "$stripcmd" || { |
||||
# Create $dsttmp read-write so that cp doesn't create it read-only, |
||||
# which would cause strip to fail. |
||||
if test -z "$doit"; then |
||||
: >"$dsttmp" # No need to fork-exec 'touch'. |
||||
else |
||||
$doit touch "$dsttmp" |
||||
fi |
||||
} |
||||
} && |
||||
$doit_exec $cpprog "$src" "$dsttmp") && |
||||
|
||||
# and set any options; do chmod last to preserve setuid bits. |
||||
# |
||||
# If any of these fail, we abort the whole thing. If we want to |
||||
# ignore errors from any of these, just make sure not to ignore |
||||
# errors from the above "$doit $cpprog $src $dsttmp" command. |
||||
# |
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && |
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && |
||||
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && |
||||
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && |
||||
|
||||
# If -C, don't bother to copy if it wouldn't change the file. |
||||
if $copy_on_change && |
||||
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && |
||||
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && |
||||
set -f && |
||||
set X $old && old=:$2:$4:$5:$6 && |
||||
set X $new && new=:$2:$4:$5:$6 && |
||||
set +f && |
||||
test "$old" = "$new" && |
||||
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 |
||||
then |
||||
rm -f "$dsttmp" |
||||
else |
||||
# If $backupsuffix is set, and the file being installed |
||||
# already exists, attempt a backup. Don't worry if it fails, |
||||
# e.g., if mv doesn't support -f. |
||||
if test -n "$backupsuffix" && test -f "$dst"; then |
||||
$doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null |
||||
fi |
||||
|
||||
# Rename the file to the real destination. |
||||
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || |
||||
|
||||
# The rename failed, perhaps because mv can't rename something else |
||||
# to itself, or perhaps because mv is so ancient that it does not |
||||
# support -f. |
||||
{ |
||||
# Now remove or move aside any old file at destination location. |
||||
# We try this two ways since rm can't unlink itself on some |
||||
# systems and the destination file might be busy for other |
||||
# reasons. In this case, the final cleanup might fail but the new |
||||
# file should still install successfully. |
||||
{ |
||||
test ! -f "$dst" || |
||||
$doit $rmcmd "$dst" 2>/dev/null || |
||||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && |
||||
{ $doit $rmcmd "$rmtmp" 2>/dev/null; :; } |
||||
} || |
||||
{ echo "$0: cannot unlink or rename $dst" >&2 |
||||
(exit 1); exit 1 |
||||
} |
||||
} && |
||||
|
||||
# Now rename the file to the real destination. |
||||
$doit $mvcmd "$dsttmp" "$dst" |
||||
} |
||||
fi || exit 1 |
||||
|
||||
trap '' 0 |
||||
fi |
||||
done |
||||
|
||||
# Local variables: |
||||
# eval: (add-hook 'before-save-hook 'time-stamp) |
||||
# time-stamp-start: "scriptversion=" |
||||
# time-stamp-format: "%:y-%02m-%02d.%02H" |
||||
# time-stamp-time-zone: "UTC0" |
||||
# time-stamp-end: "; # UTC" |
||||
# End: |
||||
@ -1,215 +0,0 @@ |
||||
#! /bin/sh |
||||
# Common wrapper for a few potentially missing GNU programs. |
||||
|
||||
scriptversion=2018-03-07.03; # UTC |
||||
|
||||
# Copyright (C) 1996-2021 Free Software Foundation, Inc. |
||||
# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996. |
||||
|
||||
# This program is free software; you can redistribute it and/or modify |
||||
# it under the terms of the GNU General Public License as published by |
||||
# the Free Software Foundation; either version 2, or (at your option) |
||||
# any later version. |
||||
|
||||
# This program 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 General Public License for more details. |
||||
|
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
|
||||
# As a special exception to the GNU General Public License, if you |
||||
# distribute this file as part of a program that contains a |
||||
# configuration script generated by Autoconf, you may include it under |
||||
# the same distribution terms that you use for the rest of that program. |
||||
|
||||
if test $# -eq 0; then |
||||
echo 1>&2 "Try '$0 --help' for more information" |
||||
exit 1 |
||||
fi |
||||
|
||||
case $1 in |
||||
|
||||
--is-lightweight) |
||||
# Used by our autoconf macros to check whether the available missing |
||||
# script is modern enough. |
||||
exit 0 |
||||
;; |
||||
|
||||
--run) |
||||
# Back-compat with the calling convention used by older automake. |
||||
shift |
||||
;; |
||||
|
||||
-h|--h|--he|--hel|--help) |
||||
echo "\ |
||||
$0 [OPTION]... PROGRAM [ARGUMENT]... |
||||
|
||||
Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due |
||||
to PROGRAM being missing or too old. |
||||
|
||||
Options: |
||||
-h, --help display this help and exit |
||||
-v, --version output version information and exit |
||||
|
||||
Supported PROGRAM values: |
||||
aclocal autoconf autoheader autom4te automake makeinfo |
||||
bison yacc flex lex help2man |
||||
|
||||
Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and |
||||
'g' are ignored when checking the name. |
||||
|
||||
Send bug reports to <bug-automake@gnu.org>." |
||||
exit $? |
||||
;; |
||||
|
||||
-v|--v|--ve|--ver|--vers|--versi|--versio|--version) |
||||
echo "missing $scriptversion (GNU Automake)" |
||||
exit $? |
||||
;; |
||||
|
||||
-*) |
||||
echo 1>&2 "$0: unknown '$1' option" |
||||
echo 1>&2 "Try '$0 --help' for more information" |
||||
exit 1 |
||||
;; |
||||
|
||||
esac |
||||
|
||||
# Run the given program, remember its exit status. |
||||
"$@"; st=$? |
||||
|
||||
# If it succeeded, we are done. |
||||
test $st -eq 0 && exit 0 |
||||
|
||||
# Also exit now if we it failed (or wasn't found), and '--version' was |
||||
# passed; such an option is passed most likely to detect whether the |
||||
# program is present and works. |
||||
case $2 in --version|--help) exit $st;; esac |
||||
|
||||
# Exit code 63 means version mismatch. This often happens when the user |
||||
# tries to use an ancient version of a tool on a file that requires a |
||||
# minimum version. |
||||
if test $st -eq 63; then |
||||
msg="probably too old" |
||||
elif test $st -eq 127; then |
||||
# Program was missing. |
||||
msg="missing on your system" |
||||
else |
||||
# Program was found and executed, but failed. Give up. |
||||
exit $st |
||||
fi |
||||
|
||||
perl_URL=https://www.perl.org/ |
||||
flex_URL=https://github.com/westes/flex |
||||
gnu_software_URL=https://www.gnu.org/software |
||||
|
||||
program_details () |
||||
{ |
||||
case $1 in |
||||
aclocal|automake) |
||||
echo "The '$1' program is part of the GNU Automake package:" |
||||
echo "<$gnu_software_URL/automake>" |
||||
echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" |
||||
echo "<$gnu_software_URL/autoconf>" |
||||
echo "<$gnu_software_URL/m4/>" |
||||
echo "<$perl_URL>" |
||||
;; |
||||
autoconf|autom4te|autoheader) |
||||
echo "The '$1' program is part of the GNU Autoconf package:" |
||||
echo "<$gnu_software_URL/autoconf/>" |
||||
echo "It also requires GNU m4 and Perl in order to run:" |
||||
echo "<$gnu_software_URL/m4/>" |
||||
echo "<$perl_URL>" |
||||
;; |
||||
esac |
||||
} |
||||
|
||||
give_advice () |
||||
{ |
||||
# Normalize program name to check for. |
||||
normalized_program=`echo "$1" | sed ' |
||||
s/^gnu-//; t |
||||
s/^gnu//; t |
||||
s/^g//; t'` |
||||
|
||||
printf '%s\n' "'$1' is $msg." |
||||
|
||||
configure_deps="'configure.ac' or m4 files included by 'configure.ac'" |
||||
case $normalized_program in |
||||
autoconf*) |
||||
echo "You should only need it if you modified 'configure.ac'," |
||||
echo "or m4 files included by it." |
||||
program_details 'autoconf' |
||||
;; |
||||
autoheader*) |
||||
echo "You should only need it if you modified 'acconfig.h' or" |
||||
echo "$configure_deps." |
||||
program_details 'autoheader' |
||||
;; |
||||
automake*) |
||||
echo "You should only need it if you modified 'Makefile.am' or" |
||||
echo "$configure_deps." |
||||
program_details 'automake' |
||||
;; |
||||
aclocal*) |
||||
echo "You should only need it if you modified 'acinclude.m4' or" |
||||
echo "$configure_deps." |
||||
program_details 'aclocal' |
||||
;; |
||||
autom4te*) |
||||
echo "You might have modified some maintainer files that require" |
||||
echo "the 'autom4te' program to be rebuilt." |
||||
program_details 'autom4te' |
||||
;; |
||||
bison*|yacc*) |
||||
echo "You should only need it if you modified a '.y' file." |
||||
echo "You may want to install the GNU Bison package:" |
||||
echo "<$gnu_software_URL/bison/>" |
||||
;; |
||||
lex*|flex*) |
||||
echo "You should only need it if you modified a '.l' file." |
||||
echo "You may want to install the Fast Lexical Analyzer package:" |
||||
echo "<$flex_URL>" |
||||
;; |
||||
help2man*) |
||||
echo "You should only need it if you modified a dependency" \ |
||||
"of a man page." |
||||
echo "You may want to install the GNU Help2man package:" |
||||
echo "<$gnu_software_URL/help2man/>" |
||||
;; |
||||
makeinfo*) |
||||
echo "You should only need it if you modified a '.texi' file, or" |
||||
echo "any other file indirectly affecting the aspect of the manual." |
||||
echo "You might want to install the Texinfo package:" |
||||
echo "<$gnu_software_URL/texinfo/>" |
||||
echo "The spurious makeinfo call might also be the consequence of" |
||||
echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" |
||||
echo "want to install GNU make:" |
||||
echo "<$gnu_software_URL/make/>" |
||||
;; |
||||
*) |
||||
echo "You might have modified some files without having the proper" |
||||
echo "tools for further handling them. Check the 'README' file, it" |
||||
echo "often tells you about the needed prerequisites for installing" |
||||
echo "this package. You may also peek at any GNU archive site, in" |
||||
echo "case some other package contains this missing '$1' program." |
||||
;; |
||||
esac |
||||
} |
||||
|
||||
give_advice "$1" | sed -e '1s/^/WARNING: /' \ |
||||
-e '2,$s/^/ /' >&2 |
||||
|
||||
# Propagate the correct exit status (expected to be 127 for a program |
||||
# not found, 63 for a program that failed due to version mismatch). |
||||
exit $st |
||||
|
||||
# Local variables: |
||||
# eval: (add-hook 'before-save-hook 'time-stamp) |
||||
# time-stamp-start: "scriptversion=" |
||||
# time-stamp-format: "%:y-%02m-%02d.%02H" |
||||
# time-stamp-time-zone: "UTC0" |
||||
# time-stamp-end: "; # UTC" |
||||
# End: |
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,182 @@ |
||||
#include "ffmpeg_context.h" |
||||
|
||||
FFmpegContext *saveFFmpegContext() { |
||||
FFmpegContext *context = (FFmpegContext *)av_mallocz(sizeof(FFmpegContext)); |
||||
|
||||
// cmdutils.c
|
||||
context->sws_dict = sws_dict; |
||||
context->swr_opts = swr_opts; |
||||
context->format_opts = format_opts; |
||||
context->codec_opts = codec_opts; |
||||
context->hide_banner = hide_banner; |
||||
#if HAVE_COMMANDLINETOARGVW && defined(_WIN32) |
||||
/* Will be leaked on exit */ |
||||
context->win32_argv_utf8 = win32_argv_utf8; |
||||
context->win32_argc = win32_argc; |
||||
#endif |
||||
|
||||
// ffmpeg.c
|
||||
context->vstats_file = vstats_file; |
||||
context->nb_output_dumped = nb_output_dumped; |
||||
context->current_time = current_time; |
||||
context->progress_avio = progress_avio; |
||||
context->input_files = input_files; |
||||
context->nb_input_files = nb_input_files; |
||||
context->output_files = output_files; |
||||
context->nb_output_files = nb_output_files; |
||||
context->filtergraphs = filtergraphs; |
||||
context->nb_filtergraphs = nb_filtergraphs; |
||||
#if HAVE_TERMIOS_H |
||||
/* init terminal so that we can grab keys */ |
||||
context->oldtty = oldtty; |
||||
context->restore_tty = restore_tty; |
||||
#endif |
||||
context->received_sigterm = received_sigterm; |
||||
context->received_nb_signals = received_nb_signals; |
||||
context->transcode_init_done = transcode_init_done; |
||||
context->ffmpeg_exited = ffmpeg_exited; |
||||
context->copy_ts_first_pts = copy_ts_first_pts; |
||||
|
||||
// ffmpeg_hw.c
|
||||
context->nb_hw_devices = nb_hw_devices; |
||||
context->hw_devices = hw_devices; |
||||
|
||||
// ffmpeg_mux.c
|
||||
context->want_sdp = want_sdp; |
||||
|
||||
// ffmpeg_mux_init.c
|
||||
context->enc_stats_files = enc_stats_files; |
||||
context->nb_enc_stats_files = nb_enc_stats_files; |
||||
|
||||
// ffmpeg_opt.c
|
||||
context->filter_hw_device = filter_hw_device; |
||||
context->vstats_filename = vstats_filename; |
||||
context->sdp_filename = sdp_filename; |
||||
context->audio_drift_threshold = audio_drift_threshold; |
||||
context->dts_delta_threshold = dts_delta_threshold; |
||||
context->dts_error_threshold = dts_error_threshold; |
||||
context->video_sync_method = video_sync_method; |
||||
context->frame_drop_threshold = frame_drop_threshold; |
||||
context->do_benchmark = do_benchmark; |
||||
context->do_benchmark_all = do_benchmark_all; |
||||
context->do_hex_dump = do_hex_dump; |
||||
context->do_pkt_dump = do_pkt_dump; |
||||
context->copy_ts = copy_ts; |
||||
context->start_at_zero = start_at_zero; |
||||
context->copy_tb = copy_tb; |
||||
context->debug_ts = debug_ts; |
||||
context->exit_on_error = exit_on_error; |
||||
context->abort_on_flags = abort_on_flags; |
||||
context->print_stats = print_stats; |
||||
context->stdin_interaction = stdin_interaction; |
||||
context->max_error_rate = max_error_rate; |
||||
context->filter_nbthreads = filter_nbthreads; |
||||
context->filter_complex_nbthreads = filter_complex_nbthreads; |
||||
context->vstats_version = vstats_version; |
||||
context->auto_conversion_filters = auto_conversion_filters; |
||||
context->stats_period = stats_period; |
||||
context->file_overwrite = file_overwrite; |
||||
context->no_file_overwrite = no_file_overwrite; |
||||
#if FFMPEG_OPT_PSNR |
||||
context->do_psnr = do_psnr; |
||||
#endif |
||||
context->ignore_unknown_streams = ignore_unknown_streams; |
||||
context->copy_unknown_streams = copy_unknown_streams; |
||||
context->recast_media = recast_media; |
||||
|
||||
// opt_common.c
|
||||
context->report_file = report_file; |
||||
context->report_file_level = report_file_level; |
||||
context->warned_cfg = warned_cfg; |
||||
|
||||
return context; |
||||
} |
||||
|
||||
void loadFFmpegContext(FFmpegContext *context) { |
||||
|
||||
// cmdutils.c
|
||||
sws_dict = context->sws_dict; |
||||
swr_opts = context->swr_opts; |
||||
format_opts = context->format_opts; |
||||
codec_opts = context->codec_opts; |
||||
hide_banner = context->hide_banner; |
||||
#if HAVE_COMMANDLINETOARGVW && defined(_WIN32) |
||||
/* Will be leaked on exit */ |
||||
win32_argv_utf8 = context->win32_argv_utf8; |
||||
win32_argc = context->win32_argc; |
||||
#endif |
||||
|
||||
// ffmpeg.c
|
||||
vstats_file = context->vstats_file; |
||||
nb_output_dumped = context->nb_output_dumped; |
||||
current_time = context->current_time; |
||||
progress_avio = context->progress_avio; |
||||
input_files = context->input_files; |
||||
nb_input_files = context->nb_input_files; |
||||
output_files = context->output_files; |
||||
nb_output_files = context->nb_output_files; |
||||
filtergraphs = context->filtergraphs; |
||||
nb_filtergraphs = context->nb_filtergraphs; |
||||
#if HAVE_TERMIOS_H |
||||
/* init terminal so that we can grab keys */ |
||||
oldtty = context->oldtty; |
||||
restore_tty = context->restore_tty; |
||||
#endif |
||||
received_sigterm = context->received_sigterm; |
||||
received_nb_signals = context->received_nb_signals; |
||||
transcode_init_done = context->transcode_init_done; |
||||
ffmpeg_exited = context->ffmpeg_exited; |
||||
copy_ts_first_pts = context->copy_ts_first_pts; |
||||
|
||||
// ffmpeg_hw.c
|
||||
nb_hw_devices = context->nb_hw_devices; |
||||
hw_devices = context->hw_devices; |
||||
|
||||
// ffmpeg_mux.c
|
||||
want_sdp = context->want_sdp; |
||||
|
||||
// ffmpeg_mux_init.c
|
||||
enc_stats_files = context->enc_stats_files; |
||||
nb_enc_stats_files = context->nb_enc_stats_files; |
||||
|
||||
// ffmpeg_opt.c
|
||||
filter_hw_device = context->filter_hw_device; |
||||
vstats_filename = context->vstats_filename; |
||||
sdp_filename = context->sdp_filename; |
||||
audio_drift_threshold = context->audio_drift_threshold; |
||||
dts_delta_threshold = context->dts_delta_threshold; |
||||
dts_error_threshold = context->dts_error_threshold; |
||||
video_sync_method = context->video_sync_method; |
||||
frame_drop_threshold = context->frame_drop_threshold; |
||||
do_benchmark = context->do_benchmark; |
||||
do_benchmark_all = context->do_benchmark_all; |
||||
do_hex_dump = context->do_hex_dump; |
||||
do_pkt_dump = context->do_pkt_dump; |
||||
copy_ts = context->copy_ts; |
||||
start_at_zero = context->start_at_zero; |
||||
copy_tb = context->copy_tb; |
||||
debug_ts = context->debug_ts; |
||||
exit_on_error = context->exit_on_error; |
||||
abort_on_flags = context->abort_on_flags; |
||||
print_stats = context->print_stats; |
||||
stdin_interaction = context->stdin_interaction; |
||||
max_error_rate = context->max_error_rate; |
||||
filter_nbthreads = context->filter_nbthreads; |
||||
filter_complex_nbthreads = context->filter_complex_nbthreads; |
||||
vstats_version = context->vstats_version; |
||||
auto_conversion_filters = context->auto_conversion_filters; |
||||
stats_period = context->stats_period; |
||||
file_overwrite = context->file_overwrite; |
||||
no_file_overwrite = context->no_file_overwrite; |
||||
#if FFMPEG_OPT_PSNR |
||||
do_psnr = context->do_psnr; |
||||
#endif |
||||
ignore_unknown_streams = context->ignore_unknown_streams; |
||||
copy_unknown_streams = context->copy_unknown_streams; |
||||
recast_media = context->recast_media; |
||||
|
||||
// opt_common.c
|
||||
report_file = context->report_file; |
||||
report_file_level = context->report_file_level; |
||||
warned_cfg = context->warned_cfg; |
||||
} |
||||
@ -0,0 +1,145 @@ |
||||
/*
|
||||
* Copyright (c) 2024 ARTHENICA LTD |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_CONTEXT_H |
||||
#define FFMPEG_CONTEXT_H |
||||
|
||||
#if HAVE_TERMIOS_H |
||||
#include <termios.h> |
||||
#endif |
||||
|
||||
#include "fftools_ffmpeg.h" |
||||
#include "libavformat/avio.h" |
||||
#include "libavutil/dict.h" |
||||
|
||||
extern __thread BenchmarkTimeStamps current_time; |
||||
extern __thread struct termios oldtty; |
||||
extern __thread int restore_tty; |
||||
extern __thread volatile int received_sigterm; |
||||
extern __thread volatile int received_nb_signals; |
||||
extern __thread atomic_int transcode_init_done; |
||||
extern __thread volatile int ffmpeg_exited; |
||||
extern __thread int64_t copy_ts_first_pts; |
||||
extern __thread int nb_hw_devices; |
||||
extern __thread HWDevice **hw_devices; |
||||
extern __thread int want_sdp; |
||||
extern __thread struct EncStatsFile *enc_stats_files; |
||||
extern __thread int nb_enc_stats_files; |
||||
extern __thread float audio_drift_threshold; |
||||
extern __thread int file_overwrite; |
||||
extern __thread int no_file_overwrite; |
||||
extern __thread FILE *report_file; |
||||
extern __thread int report_file_level; |
||||
extern __thread int warned_cfg; |
||||
|
||||
typedef struct FFmpegContext { |
||||
|
||||
// cmdutils.c
|
||||
AVDictionary *sws_dict; |
||||
AVDictionary *swr_opts; |
||||
AVDictionary *format_opts, *codec_opts; |
||||
int hide_banner; |
||||
#if HAVE_COMMANDLINETOARGVW && defined(_WIN32) |
||||
/* Will be leaked on exit */ |
||||
char **win32_argv_utf8; |
||||
int win32_argc; |
||||
#endif |
||||
|
||||
// ffmpeg.c
|
||||
FILE *vstats_file; |
||||
unsigned nb_output_dumped; |
||||
BenchmarkTimeStamps current_time; |
||||
AVIOContext *progress_avio; |
||||
InputFile **input_files; |
||||
int nb_input_files; |
||||
OutputFile **output_files; |
||||
int nb_output_files; |
||||
FilterGraph **filtergraphs; |
||||
int nb_filtergraphs; |
||||
#if HAVE_TERMIOS_H |
||||
/* init terminal so that we can grab keys */ |
||||
struct termios oldtty; |
||||
int restore_tty; |
||||
#endif |
||||
volatile int received_sigterm; |
||||
volatile int received_nb_signals; |
||||
atomic_int transcode_init_done; |
||||
volatile int ffmpeg_exited; |
||||
int64_t copy_ts_first_pts; |
||||
|
||||
// ffmpeg_hw.c
|
||||
int nb_hw_devices; |
||||
HWDevice **hw_devices; |
||||
|
||||
// ffmpeg_mux.c
|
||||
int want_sdp; |
||||
|
||||
// ffmpeg_mux_init.c
|
||||
EncStatsFile *enc_stats_files; |
||||
int nb_enc_stats_files; |
||||
|
||||
// ffmpeg_opt.c
|
||||
HWDevice *filter_hw_device; |
||||
char *vstats_filename; |
||||
char *sdp_filename; |
||||
float audio_drift_threshold; |
||||
float dts_delta_threshold; |
||||
float dts_error_threshold; |
||||
enum VideoSyncMethod video_sync_method; |
||||
float frame_drop_threshold; |
||||
int do_benchmark; |
||||
int do_benchmark_all; |
||||
int do_hex_dump; |
||||
int do_pkt_dump; |
||||
int copy_ts; |
||||
int start_at_zero; |
||||
int copy_tb; |
||||
int debug_ts; |
||||
int exit_on_error; |
||||
int abort_on_flags; |
||||
int print_stats; |
||||
int stdin_interaction; |
||||
float max_error_rate; |
||||
char *filter_nbthreads; |
||||
int filter_complex_nbthreads; |
||||
int vstats_version; |
||||
int auto_conversion_filters; |
||||
int64_t stats_period; |
||||
int file_overwrite; |
||||
int no_file_overwrite; |
||||
#if FFMPEG_OPT_PSNR |
||||
int do_psnr; |
||||
#endif |
||||
int ignore_unknown_streams; |
||||
int copy_unknown_streams; |
||||
int recast_media; |
||||
|
||||
// opt_common.c
|
||||
FILE *report_file; |
||||
int report_file_level; |
||||
int warned_cfg; |
||||
|
||||
void *arg; |
||||
|
||||
} FFmpegContext; |
||||
|
||||
FFmpegContext *saveFFmpegContext(); |
||||
void loadFFmpegContext(FFmpegContext *context); |
||||
|
||||
#endif // FFMPEG_CONTEXT_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue