You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avisynth: Cosmetics
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
committed by
Michael Niedermayer
parent
1549122d26
commit
2c18bfe6af
@@ -19,9 +19,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libavutil/internal.h"
|
#include "libavutil/internal.h"
|
||||||
|
#include "libavcodec/internal.h"
|
||||||
#include "avformat.h"
|
#include "avformat.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "libavcodec/internal.h"
|
|
||||||
|
|
||||||
/* Enable function pointer definitions for runtime loading. */
|
/* Enable function pointer definitions for runtime loading. */
|
||||||
#define AVSC_NO_DECLSPEC
|
#define AVSC_NO_DECLSPEC
|
||||||
@@ -104,7 +104,8 @@ typedef struct AviSynthContext AviSynthContext;
|
|||||||
|
|
||||||
static const int avs_planes_packed[1] = { 0 };
|
static const int avs_planes_packed[1] = { 0 };
|
||||||
static const int avs_planes_grey[1] = { AVS_PLANAR_Y };
|
static const int avs_planes_grey[1] = { AVS_PLANAR_Y };
|
||||||
static const int avs_planes_yuv[3] = {AVS_PLANAR_Y, AVS_PLANAR_U, AVS_PLANAR_V};
|
static const int avs_planes_yuv[3] = { AVS_PLANAR_Y, AVS_PLANAR_U,
|
||||||
|
AVS_PLANAR_V };
|
||||||
|
|
||||||
/* A conflict between C++ global objects, atexit, and dynamic loading requires
|
/* A conflict between C++ global objects, atexit, and dynamic loading requires
|
||||||
* us to register our own atexit handler to prevent double freeing. */
|
* us to register our own atexit handler to prevent double freeing. */
|
||||||
@@ -116,7 +117,8 @@ static AviSynthContext *avs_ctx_list = NULL;
|
|||||||
|
|
||||||
static av_cold void avisynth_atexit_handler(void);
|
static av_cold void avisynth_atexit_handler(void);
|
||||||
|
|
||||||
static av_cold int avisynth_load_library(void) {
|
static av_cold int avisynth_load_library(void)
|
||||||
|
{
|
||||||
avs_library = av_mallocz(sizeof(AviSynthLibrary));
|
avs_library = av_mallocz(sizeof(AviSynthLibrary));
|
||||||
if (!avs_library)
|
if (!avs_library)
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
@@ -126,11 +128,11 @@ static av_cold int avisynth_load_library(void) {
|
|||||||
goto init_fail;
|
goto init_fail;
|
||||||
|
|
||||||
#define LOAD_AVS_FUNC(name, continue_on_fail) \
|
#define LOAD_AVS_FUNC(name, continue_on_fail) \
|
||||||
{ \
|
avs_library->name = \
|
||||||
avs_library->name = (void*)GetProcAddress(avs_library->library, #name); \
|
(void *)GetProcAddress(avs_library->library, #name); \
|
||||||
if (!continue_on_fail && !avs_library->name) \
|
if (!continue_on_fail && !avs_library->name) \
|
||||||
goto fail; \
|
goto fail;
|
||||||
}
|
|
||||||
LOAD_AVS_FUNC(avs_bit_blt, 0);
|
LOAD_AVS_FUNC(avs_bit_blt, 0);
|
||||||
LOAD_AVS_FUNC(avs_clip_get_error, 0);
|
LOAD_AVS_FUNC(avs_clip_get_error, 0);
|
||||||
LOAD_AVS_FUNC(avs_create_script_environment, 0);
|
LOAD_AVS_FUNC(avs_create_script_environment, 0);
|
||||||
@@ -160,14 +162,14 @@ init_fail:
|
|||||||
/* Note that avisynth_context_create and avisynth_context_destroy
|
/* Note that avisynth_context_create and avisynth_context_destroy
|
||||||
* do not allocate or free the actual context! That is taken care of
|
* do not allocate or free the actual context! That is taken care of
|
||||||
* by libavformat. */
|
* by libavformat. */
|
||||||
static av_cold int avisynth_context_create(AVFormatContext *s) {
|
static av_cold int avisynth_context_create(AVFormatContext *s)
|
||||||
|
{
|
||||||
AviSynthContext *avs = (AviSynthContext *)s->priv_data;
|
AviSynthContext *avs = (AviSynthContext *)s->priv_data;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!avs_library) {
|
if (!avs_library)
|
||||||
if (ret = avisynth_load_library())
|
if (ret = avisynth_load_library())
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
avs->env = avs_library->avs_create_script_environment(3);
|
avs->env = avs_library->avs_create_script_environment(3);
|
||||||
if (avs_library->avs_get_error) {
|
if (avs_library->avs_get_error) {
|
||||||
@@ -188,7 +190,8 @@ static av_cold int avisynth_context_create(AVFormatContext *s) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void avisynth_context_destroy(AviSynthContext *avs) {
|
static av_cold void avisynth_context_destroy(AviSynthContext *avs)
|
||||||
|
{
|
||||||
if (avs_atexit_called)
|
if (avs_atexit_called)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -211,7 +214,8 @@ static av_cold void avisynth_context_destroy(AviSynthContext *avs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void avisynth_atexit_handler(void) {
|
static av_cold void avisynth_atexit_handler(void)
|
||||||
|
{
|
||||||
AviSynthContext *avs = avs_ctx_list;
|
AviSynthContext *avs = avs_ctx_list;
|
||||||
|
|
||||||
while (avs) {
|
while (avs) {
|
||||||
@@ -226,7 +230,8 @@ static av_cold void avisynth_atexit_handler(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create AVStream from audio and video data. */
|
/* Create AVStream from audio and video data. */
|
||||||
static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) {
|
static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
int planar = 0; // 0: packed, 1: YUV, 2: Y8
|
int planar = 0; // 0: packed, 1: YUV, 2: Y8
|
||||||
|
|
||||||
@@ -235,8 +240,10 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) {
|
|||||||
st->codec->width = avs->vi->width;
|
st->codec->width = avs->vi->width;
|
||||||
st->codec->height = avs->vi->height;
|
st->codec->height = avs->vi->height;
|
||||||
|
|
||||||
st->time_base = (AVRational) {avs->vi->fps_denominator, avs->vi->fps_numerator};
|
st->time_base = (AVRational) { avs->vi->fps_denominator,
|
||||||
st->avg_frame_rate = (AVRational) {avs->vi->fps_numerator, avs->vi->fps_denominator};
|
avs->vi->fps_numerator };
|
||||||
|
st->avg_frame_rate = (AVRational) { avs->vi->fps_numerator,
|
||||||
|
avs->vi->fps_denominator };
|
||||||
st->start_time = 0;
|
st->start_time = 0;
|
||||||
st->duration = avs->vi->num_frames;
|
st->duration = avs->vi->num_frames;
|
||||||
st->nb_frames = avs->vi->num_frames;
|
st->nb_frames = avs->vi->num_frames;
|
||||||
@@ -278,7 +285,8 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) {
|
|||||||
planar = 1;
|
planar = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
av_log(s, AV_LOG_ERROR, "unknown AviSynth colorspace %d\n", avs->vi->pixel_type);
|
av_log(s, AV_LOG_ERROR,
|
||||||
|
"unknown AviSynth colorspace %d\n", avs->vi->pixel_type);
|
||||||
avs->error = 1;
|
avs->error = 1;
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
@@ -299,13 +307,15 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st) {
|
static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
|
|
||||||
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
|
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
|
||||||
st->codec->sample_rate = avs->vi->audio_samples_per_second;
|
st->codec->sample_rate = avs->vi->audio_samples_per_second;
|
||||||
st->codec->channels = avs->vi->nchannels;
|
st->codec->channels = avs->vi->nchannels;
|
||||||
st->time_base = (AVRational) {1, avs->vi->audio_samples_per_second};
|
st->time_base = (AVRational) { 1,
|
||||||
|
avs->vi->audio_samples_per_second };
|
||||||
|
|
||||||
switch (avs->vi->sample_type) {
|
switch (avs->vi->sample_type) {
|
||||||
case AVS_SAMPLE_INT8:
|
case AVS_SAMPLE_INT8:
|
||||||
@@ -324,14 +334,16 @@ static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st) {
|
|||||||
st->codec->codec_id = CODEC_ID_PCM_F32LE;
|
st->codec->codec_id = CODEC_ID_PCM_F32LE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
av_log(s, AV_LOG_ERROR, "unknown AviSynth sample type %d\n", avs->vi->sample_type);
|
av_log(s, AV_LOG_ERROR,
|
||||||
|
"unknown AviSynth sample type %d\n", avs->vi->sample_type);
|
||||||
avs->error = 1;
|
avs->error = 1;
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int avisynth_create_stream(AVFormatContext *s) {
|
static int avisynth_create_stream(AVFormatContext *s)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -356,7 +368,8 @@ static int avisynth_create_stream(AVFormatContext *s) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int avisynth_open_file(AVFormatContext *s) {
|
static int avisynth_open_file(AVFormatContext *s)
|
||||||
|
{
|
||||||
AviSynthContext *avs = (AviSynthContext *)s->priv_data;
|
AviSynthContext *avs = (AviSynthContext *)s->priv_data;
|
||||||
AVS_Value arg, val;
|
AVS_Value arg, val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -371,7 +384,8 @@ static int avisynth_open_file(AVFormatContext *s) {
|
|||||||
#ifdef USING_AVISYNTH
|
#ifdef USING_AVISYNTH
|
||||||
/* Convert UTF-8 to ANSI code page */
|
/* Convert UTF-8 to ANSI code page */
|
||||||
MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wc, MAX_PATH * 4);
|
MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wc, MAX_PATH * 4);
|
||||||
WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi, MAX_PATH * 4, NULL, NULL);
|
WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
|
||||||
|
MAX_PATH * 4, NULL, NULL);
|
||||||
arg = avs_new_value_string(filename_ansi);
|
arg = avs_new_value_string(filename_ansi);
|
||||||
#else
|
#else
|
||||||
arg = avs_new_value_string(s->filename);
|
arg = avs_new_value_string(s->filename);
|
||||||
@@ -404,7 +418,9 @@ fail:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void avisynth_next_stream(AVFormatContext *s, AVStream **st, AVPacket *pkt, int *discard) {
|
static void avisynth_next_stream(AVFormatContext *s, AVStream **st,
|
||||||
|
AVPacket *pkt, int *discard)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
|
|
||||||
pkt->stream_index = avs->curr_stream++;
|
pkt->stream_index = avs->curr_stream++;
|
||||||
@@ -420,7 +436,9 @@ static void avisynth_next_stream(AVFormatContext *s, AVStream **st, AVPacket *pk
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Copy AviSynth clip data into an AVPacket. */
|
/* Copy AviSynth clip data into an AVPacket. */
|
||||||
static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int discard) {
|
static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
|
||||||
|
int discard)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
AVS_VideoFrame *frame;
|
AVS_VideoFrame *frame;
|
||||||
unsigned char *dst_p;
|
unsigned char *dst_p;
|
||||||
@@ -441,21 +459,21 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int dis
|
|||||||
pkt->duration = 1;
|
pkt->duration = 1;
|
||||||
|
|
||||||
// Define the bpp values for the new AviSynth 2.6 colorspaces
|
// Define the bpp values for the new AviSynth 2.6 colorspaces
|
||||||
if (avs_is_yv24(avs->vi)) {
|
if (avs_is_yv24(avs->vi))
|
||||||
bits = 24;
|
bits = 24;
|
||||||
} else if (avs_is_yv16(avs->vi)) {
|
else if (avs_is_yv16(avs->vi))
|
||||||
bits = 16;
|
bits = 16;
|
||||||
} else if (avs_is_yv411(avs->vi)) {
|
else if (avs_is_yv411(avs->vi))
|
||||||
bits = 12;
|
bits = 12;
|
||||||
} else if (avs_is_y8(avs->vi)) {
|
else if (avs_is_y8(avs->vi))
|
||||||
bits = 8;
|
bits = 8;
|
||||||
} else {
|
else
|
||||||
bits = avs_bits_per_pixel(avs->vi);
|
bits = avs_bits_per_pixel(avs->vi);
|
||||||
}
|
|
||||||
|
|
||||||
/* Without the cast to int64_t, calculation overflows at about 9k x 9k
|
/* Without the cast to int64_t, calculation overflows at about 9k x 9k
|
||||||
* resolution. */
|
* resolution. */
|
||||||
pkt->size = (((int64_t)avs->vi->width * (int64_t)avs->vi->height) * bits) / 8;
|
pkt->size = (((int64_t)avs->vi->width *
|
||||||
|
(int64_t)avs->vi->height) * bits) / 8;
|
||||||
if (!pkt->size)
|
if (!pkt->size)
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
pkt->data = av_malloc(pkt->size);
|
pkt->data = av_malloc(pkt->size);
|
||||||
@@ -496,7 +514,8 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int dis
|
|||||||
pitch = -pitch;
|
pitch = -pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
avs_library->avs_bit_blt(avs->env, dst_p, rowsize, src_p, pitch, rowsize, planeheight);
|
avs_library->avs_bit_blt(avs->env, dst_p, rowsize, src_p, pitch,
|
||||||
|
rowsize, planeheight);
|
||||||
dst_p += rowsize * planeheight;
|
dst_p += rowsize * planeheight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,7 +523,9 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int dis
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int discard) {
|
static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt,
|
||||||
|
int discard)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
AVRational fps, samplerate;
|
AVRational fps, samplerate;
|
||||||
int samples;
|
int samples;
|
||||||
@@ -521,7 +542,8 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int dis
|
|||||||
|
|
||||||
if (avs_has_video(avs->vi)) {
|
if (avs_has_video(avs->vi)) {
|
||||||
if (avs->curr_frame < avs->vi->num_frames)
|
if (avs->curr_frame < avs->vi->num_frames)
|
||||||
samples = av_rescale_q(avs->curr_frame, samplerate, fps) - avs->curr_sample;
|
samples = av_rescale_q(avs->curr_frame, samplerate, fps) -
|
||||||
|
avs->curr_sample;
|
||||||
else
|
else
|
||||||
samples = av_rescale_q(1, samplerate, fps);
|
samples = av_rescale_q(1, samplerate, fps);
|
||||||
} else {
|
} else {
|
||||||
@@ -548,7 +570,8 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int dis
|
|||||||
pkt->dts = n;
|
pkt->dts = n;
|
||||||
pkt->duration = samples;
|
pkt->duration = samples;
|
||||||
|
|
||||||
pkt->size = avs_bytes_per_channel_sample(avs->vi) * samples * avs->vi->nchannels;
|
pkt->size = avs_bytes_per_channel_sample(avs->vi) *
|
||||||
|
samples * avs->vi->nchannels;
|
||||||
if (!pkt->size)
|
if (!pkt->size)
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
pkt->data = av_malloc(pkt->size);
|
pkt->data = av_malloc(pkt->size);
|
||||||
@@ -566,7 +589,8 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int dis
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int avisynth_read_header(AVFormatContext *s) {
|
static av_cold int avisynth_read_header(AVFormatContext *s)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// Calling library must implement a lock for thread-safe opens.
|
// Calling library must implement a lock for thread-safe opens.
|
||||||
@@ -582,7 +606,8 @@ static av_cold int avisynth_read_header(AVFormatContext *s) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) {
|
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
int discard = 0;
|
int discard = 0;
|
||||||
@@ -613,7 +638,8 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int avisynth_read_close(AVFormatContext *s) {
|
static av_cold int avisynth_read_close(AVFormatContext *s)
|
||||||
|
{
|
||||||
if (avpriv_lock_avformat())
|
if (avpriv_lock_avformat())
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
|
|
||||||
@@ -622,7 +648,9 @@ static av_cold int avisynth_read_close(AVFormatContext *s) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {
|
static int avisynth_read_seek(AVFormatContext *s, int stream_index,
|
||||||
|
int64_t timestamp, int flags)
|
||||||
|
{
|
||||||
AviSynthContext *avs = s->priv_data;
|
AviSynthContext *avs = s->priv_data;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
AVRational fps, samplerate;
|
AVRational fps, samplerate;
|
||||||
@@ -630,13 +658,16 @@ static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t time
|
|||||||
if (avs->error)
|
if (avs->error)
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
|
|
||||||
fps = (AVRational) {avs->vi->fps_numerator, avs->vi->fps_denominator};
|
fps = (AVRational) { avs->vi->fps_numerator,
|
||||||
|
avs->vi->fps_denominator };
|
||||||
samplerate = (AVRational) { avs->vi->audio_samples_per_second, 1 };
|
samplerate = (AVRational) { avs->vi->audio_samples_per_second, 1 };
|
||||||
|
|
||||||
st = s->streams[stream_index];
|
st = s->streams[stream_index];
|
||||||
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
|
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||||
/* AviSynth frame counts are signed int. */
|
/* AviSynth frame counts are signed int. */
|
||||||
if ((timestamp >= avs->vi->num_frames) || (timestamp > INT_MAX) || (timestamp < 0))
|
if ((timestamp >= avs->vi->num_frames) ||
|
||||||
|
(timestamp > INT_MAX) ||
|
||||||
|
(timestamp < 0))
|
||||||
return AVERROR_EOF;
|
return AVERROR_EOF;
|
||||||
avs->curr_frame = timestamp;
|
avs->curr_frame = timestamp;
|
||||||
if (avs_has_audio(avs->vi))
|
if (avs_has_audio(avs->vi))
|
||||||
|
Reference in New Issue
Block a user