1 /*
2  * Demuxer for avisynth
3  * Copyright (c) 2005 Gianluigi Tiesi <sherpya@netfarm.it>
4  *
5  * Avisynth C Interface Version 0.20
6  * Copyright 2003 Kevin Atkinson
7  *
8  * This file is part of MPlayer.
9  *
10  * MPlayer is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * MPlayer is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with MPlayer; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef MPLAYER_DEMUX_AVS_H
26 #define MPLAYER_DEMUX_AVS_H
27 
28 #include <stdint.h>
29 #include "loader/wine/windef.h"
30 
31 enum { AVISYNTH_INTERFACE_VERSION = 2 };
32 
33 enum
34 {
35   AVS_SAMPLE_INT8  = 1<<0,
36   AVS_SAMPLE_INT16 = 1<<1,
37   AVS_SAMPLE_INT24 = 1<<2,
38   AVS_SAMPLE_INT32 = 1<<3,
39   AVS_SAMPLE_FLOAT = 1<<4
40 };
41 
42 enum
43 {
44   AVS_PLANAR_Y=1<<0,
45   AVS_PLANAR_U=1<<1,
46   AVS_PLANAR_V=1<<2,
47   AVS_PLANAR_ALIGNED=1<<3,
48   AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
49   AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
50   AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED
51 };
52 
53 // Colorspace properties.
54 enum
55 {
56   AVS_CS_BGR = 1<<28,
57   AVS_CS_YUV = 1<<29,
58   AVS_CS_INTERLEAVED = 1<<30,
59   AVS_CS_PLANAR = 1<<31
60 };
61 
62 // Specific colorformats
63 enum
64 {
65   AVS_CS_UNKNOWN = 0,
66   AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
67   AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
68   AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
69   AVS_CS_YV12 = 1<<3 | AVS_CS_YUV | AVS_CS_PLANAR,  // y-v-u, planar
70   AVS_CS_I420 = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR,  // y-u-v, planar
71   AVS_CS_IYUV = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR  // same as above
72 };
73 
74 typedef struct AVS_Clip AVS_Clip;
75 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
76 
77 typedef struct AVS_Value AVS_Value;
78 struct AVS_Value {
79   short type;  // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
80                // for some function e'rror
81   short array_size;
82   union {
83     void * clip; // do not use directly, use avs_take_clip
84     char boolean;
85     int integer;
86     float floating_pt;
87     const char * string;
88     const AVS_Value * array;
89   } d;
90 };
91 
92 // AVS_VideoInfo is layed out identicly to VideoInfo
93 typedef struct AVS_VideoInfo {
94   int width, height;    // width=0 means no video
95   unsigned fps_numerator, fps_denominator;
96   int num_frames;
97 
98   int pixel_type;
99 
100   int audio_samples_per_second;   // 0 means no audio
101   int sample_type;
102   uint64_t num_audio_samples;
103   int nchannels;
104 
105   // Imagetype properties
106 
107   int image_type;
108 } AVS_VideoInfo;
109 
110 typedef struct AVS_VideoFrameBuffer {
111   BYTE * data;
112   int data_size;
113   // sequence_number is incremented every time the buffer is changed, so
114   // that stale views can tell they're no longer valid.
115   long sequence_number;
116 
117   long refcount;
118 } AVS_VideoFrameBuffer;
119 
120 typedef struct AVS_VideoFrame {
121   int refcount;
122   AVS_VideoFrameBuffer * vfb;
123   int offset, pitch, row_size, height, offsetU, offsetV, pitchUV;  // U&V offsets are from top of picture.
124 } AVS_VideoFrame;
125 
avs_new_value_string(const char * v0)126 static inline AVS_Value avs_new_value_string(const char * v0)
127 { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
128 
avs_new_value_array(AVS_Value * v0,int size)129 static inline AVS_Value avs_new_value_array(AVS_Value * v0, int size)
130 { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
131 
132 
avs_is_error(AVS_Value v)133 static inline int avs_is_error(AVS_Value v) { return v.type == 'e'; }
avs_is_clip(AVS_Value v)134 static inline int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
avs_is_string(AVS_Value v)135 static inline int avs_is_string(AVS_Value v) { return v.type == 's'; }
avs_has_video(const AVS_VideoInfo * p)136 static inline int avs_has_video(const AVS_VideoInfo * p) { return p->width != 0; }
avs_has_audio(const AVS_VideoInfo * p)137 static inline int avs_has_audio(const AVS_VideoInfo * p) { return p->audio_samples_per_second != 0; }
138 
avs_as_string(AVS_Value v)139 static inline const char * avs_as_string(AVS_Value v)
140 { return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
141 
142 /* Color spaces */
avs_is_rgb(const AVS_VideoInfo * p)143 static inline int avs_is_rgb(const AVS_VideoInfo * p)
144 { return p->pixel_type & AVS_CS_BGR; }
145 
avs_is_rgb24(const AVS_VideoInfo * p)146 static inline int avs_is_rgb24(const AVS_VideoInfo * p)
147 { return (p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24; } // Clear out additional properties
148 
avs_is_rgb32(const AVS_VideoInfo * p)149 static inline int avs_is_rgb32(const AVS_VideoInfo * p)
150 { return (p->pixel_type & AVS_CS_BGR32) == AVS_CS_BGR32 ; }
151 
avs_is_yuy(const AVS_VideoInfo * p)152 static inline int avs_is_yuy(const AVS_VideoInfo * p)
153 { return p->pixel_type & AVS_CS_YUV; }
154 
avs_is_yuy2(const AVS_VideoInfo * p)155 static inline int avs_is_yuy2(const AVS_VideoInfo * p)
156 { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
157 
avs_is_yv12(const AVS_VideoInfo * p)158 static inline int avs_is_yv12(const AVS_VideoInfo * p)
159 { return ((p->pixel_type & AVS_CS_YV12) == AVS_CS_YV12)||((p->pixel_type & AVS_CS_I420) == AVS_CS_I420); }
160 
avs_bits_per_pixel(const AVS_VideoInfo * p)161 static inline int avs_bits_per_pixel(const AVS_VideoInfo * p)
162 {
163   switch (p->pixel_type) {
164       case AVS_CS_BGR24: return 24;
165       case AVS_CS_BGR32: return 32;
166       case AVS_CS_YUY2:  return 16;
167       case AVS_CS_YV12:
168       case AVS_CS_I420:  return 12;
169       default:           return 0;
170     }
171 }
172 
173 #endif /* MPLAYER_DEMUX_AVS_H */
174