Commit 2c18bfe6 authored by Stephen Hutchinson's avatar Stephen Hutchinson Committed by Michael Niedermayer

avisynth: Cosmetics

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 1549122d
......@@ -19,9 +19,9 @@
*/
#include "libavutil/internal.h"
#include "libavcodec/internal.h"
#include "avformat.h"
#include "internal.h"
#include "libavcodec/internal.h"
/* Enable function pointer definitions for runtime loading. */
#define AVSC_NO_DECLSPEC
......@@ -64,7 +64,7 @@
typedef struct {
void *library;
#define AVSC_DECLARE_FUNC(name) name##_func name
#define AVSC_DECLARE_FUNC(name) name ## _func name
AVSC_DECLARE_FUNC(avs_bit_blt);
AVSC_DECLARE_FUNC(avs_clip_get_error);
AVSC_DECLARE_FUNC(avs_create_script_environment);
......@@ -102,9 +102,10 @@ struct AviSynthContext {
};
typedef struct AviSynthContext AviSynthContext;
static const int avs_planes_packed[1] = {0};
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_packed[1] = { 0 };
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 };
/* A conflict between C++ global objects, atexit, and dynamic loading requires
* 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 int avisynth_load_library(void) {
static av_cold int avisynth_load_library(void)
{
avs_library = av_mallocz(sizeof(AviSynthLibrary));
if (!avs_library)
return AVERROR_UNKNOWN;
......@@ -126,11 +128,11 @@ static av_cold int avisynth_load_library(void) {
goto init_fail;
#define LOAD_AVS_FUNC(name, continue_on_fail) \
{ \
avs_library->name = (void*)GetProcAddress(avs_library->library, #name); \
if(!continue_on_fail && !avs_library->name) \
goto fail; \
}
avs_library->name = \
(void *)GetProcAddress(avs_library->library, #name); \
if (!continue_on_fail && !avs_library->name) \
goto fail;
LOAD_AVS_FUNC(avs_bit_blt, 0);
LOAD_AVS_FUNC(avs_clip_get_error, 0);
LOAD_AVS_FUNC(avs_create_script_environment, 0);
......@@ -160,14 +162,14 @@ init_fail:
/* Note that avisynth_context_create and avisynth_context_destroy
* do not allocate or free the actual context! That is taken care of
* 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;
int ret;
if (!avs_library) {
if (!avs_library)
if (ret = avisynth_load_library())
return ret;
}
avs->env = avs_library->avs_create_script_environment(3);
if (avs_library->avs_get_error) {
......@@ -188,7 +190,8 @@ static av_cold int avisynth_context_create(AVFormatContext *s) {
return 0;
}
static av_cold void avisynth_context_destroy(AviSynthContext *avs) {
static av_cold void avisynth_context_destroy(AviSynthContext *avs)
{
if (avs_atexit_called)
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;
while (avs) {
......@@ -226,7 +230,8 @@ static av_cold void avisynth_atexit_handler(void) {
}
/* 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;
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->height = avs->vi->height;
st->time_base = (AVRational) {avs->vi->fps_denominator, avs->vi->fps_numerator};
st->avg_frame_rate = (AVRational) {avs->vi->fps_numerator, avs->vi->fps_denominator};
st->time_base = (AVRational) { 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->duration = 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;
break;
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;
return AVERROR_UNKNOWN;
}
......@@ -299,13 +307,15 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) {
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;
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->sample_rate = avs->vi->audio_samples_per_second;
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) {
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;
break;
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;
return AVERROR_UNKNOWN;
}
return 0;
}
static int avisynth_create_stream(AVFormatContext *s) {
static int avisynth_create_stream(AVFormatContext *s)
{
AviSynthContext *avs = s->priv_data;
AVStream *st;
int ret;
......@@ -356,7 +368,8 @@ static int avisynth_create_stream(AVFormatContext *s) {
return 0;
}
static int avisynth_open_file(AVFormatContext *s) {
static int avisynth_open_file(AVFormatContext *s)
{
AviSynthContext *avs = (AviSynthContext *)s->priv_data;
AVS_Value arg, val;
int ret;
......@@ -371,7 +384,8 @@ static int avisynth_open_file(AVFormatContext *s) {
#ifdef USING_AVISYNTH
/* Convert UTF-8 to ANSI code page */
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);
#else
arg = avs_new_value_string(s->filename);
......@@ -404,7 +418,9 @@ fail:
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;
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. */
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;
AVS_VideoFrame *frame;
unsigned char *dst_p;
......@@ -441,21 +459,21 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int dis
pkt->duration = 1;
// 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;
} else if (avs_is_yv16(avs->vi)) {
else if (avs_is_yv16(avs->vi))
bits = 16;
} else if (avs_is_yv411(avs->vi)) {
else if (avs_is_yv411(avs->vi))
bits = 12;
} else if (avs_is_y8(avs->vi)) {
else if (avs_is_y8(avs->vi))
bits = 8;
} else {
else
bits = avs_bits_per_pixel(avs->vi);
}
/* Without the cast to int64_t, calculation overflows at about 9k x 9k
* 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)
return AVERROR_UNKNOWN;
pkt->data = av_malloc(pkt->size);
......@@ -496,7 +514,8 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int dis
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;
}
......@@ -504,7 +523,9 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, int dis
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;
AVRational fps, samplerate;
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->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
samples = av_rescale_q(1, samplerate, fps);
} else {
......@@ -548,7 +570,8 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int dis
pkt->dts = n;
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)
return AVERROR_UNKNOWN;
pkt->data = av_malloc(pkt->size);
......@@ -566,7 +589,8 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, int dis
return 0;
}
static av_cold int avisynth_read_header(AVFormatContext *s) {
static av_cold int avisynth_read_header(AVFormatContext *s)
{
int ret;
// 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;
}
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) {
static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt)
{
AviSynthContext *avs = s->priv_data;
AVStream *st;
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())
return AVERROR_UNKNOWN;
......@@ -622,7 +648,9 @@ static av_cold int avisynth_read_close(AVFormatContext *s) {
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;
AVStream *st;
AVRational fps, samplerate;
......@@ -630,13 +658,16 @@ static int avisynth_read_seek(AVFormatContext *s, int stream_index, int64_t time
if (avs->error)
return AVERROR_UNKNOWN;
fps = (AVRational) {avs->vi->fps_numerator, avs->vi->fps_denominator};
samplerate = (AVRational) {avs->vi->audio_samples_per_second, 1};
fps = (AVRational) { avs->vi->fps_numerator,
avs->vi->fps_denominator };
samplerate = (AVRational) { avs->vi->audio_samples_per_second, 1 };
st = s->streams[stream_index];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
/* 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;
avs->curr_frame = timestamp;
if (avs_has_audio(avs->vi))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment