annotate libmpdemux/demux_avs.c @ 15020:3f80d5095f3e

usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
author rfelker
date Tue, 29 Mar 2005 18:14:24 +0000
parents 253b2c16c668
children 71a915145b2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14693
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
1 /*
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
2 * Demuxer for avisynth
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
3 * Copyright (c) 2005 Gianluigi Tiesi <sherpya@netfarm.it>
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
4 *
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
6 * modify it under the terms of the GNU Library General Public
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
9 *
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
13 * Library General Public License for more details.
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
14 *
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
15 * You should have received a copy of the GNU Library General Public
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
16 * License along with this library; if not, write to the
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
18 * Boston, MA 02111-1307, USA.
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
19 */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
20
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
21 #include <stdio.h>
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
22 #include <stdlib.h>
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
23 #include <unistd.h>
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
24
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
25 #include "config.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
26 #include "mp_msg.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
27 #include "help_mp.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
28
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
29 #include "stream.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
30 #include "demuxer.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
31 #include "stheader.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
32
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
33 #include "wine/windef.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
34
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
35 #ifdef WIN32_LOADER
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
36 #include "ldt_keeper.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
37 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
38
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
39 #include "demux_avs.h"
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
40
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
41 #define MAX_AVS_SIZE 16 * 1024 /* 16k should be enough */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
42 #undef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
43
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
44 HMODULE WINAPI LoadLibraryA(LPCSTR);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
45 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
46 int WINAPI FreeLibrary(HMODULE);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
47
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
48 typedef WINAPI AVS_ScriptEnvironment* (*imp_avs_create_script_environment)(int version);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
49 typedef WINAPI AVS_Value (*imp_avs_invoke)(AVS_ScriptEnvironment *, const char * name, AVS_Value args, const char** arg_names);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
50 typedef WINAPI const AVS_VideoInfo *(*imp_avs_get_video_info)(AVS_Clip *);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
51 typedef WINAPI AVS_Clip* (*imp_avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
52 typedef WINAPI AVS_VideoFrame* (*imp_avs_get_frame)(AVS_Clip *, int n);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
53 typedef WINAPI void (*imp_avs_release_video_frame)(AVS_VideoFrame *);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
54 #ifdef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
55 //typedef WINAPI int (*imp_avs_get_audio)(AVS_Clip *, void * buf, uint64_t start, uint64_t count);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
56 typedef WINAPI int (*imp_avs_get_audio)(AVS_ScriptEnvironment *, void * buf, uint64_t start, uint64_t count);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
57 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
58
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
59 #define Q(string) # string
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
60 #define IMPORT_FUNC(x) \
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
61 AVS->x = ( imp_##x ) GetProcAddress(AVS->dll, Q(x)); \
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
62 if (!AVS->x) { mp_msg(MSGT_DEMUX,MSGL_V,"AVS: failed to load "Q(x)"()\n"); return 0; }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
63
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
64 typedef struct tagAVS
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
65 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
66 AVS_ScriptEnvironment *avs_env;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
67 AVS_Value handler;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
68 AVS_Clip *clip;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
69 const AVS_VideoInfo *video_info;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
70 HMODULE dll;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
71 int frameno;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
72 int init;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
73
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
74 imp_avs_create_script_environment avs_create_script_environment;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
75 imp_avs_invoke avs_invoke;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
76 imp_avs_get_video_info avs_get_video_info;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
77 imp_avs_take_clip avs_take_clip;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
78 imp_avs_get_frame avs_get_frame;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
79 imp_avs_release_video_frame avs_release_video_frame;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
80 #ifdef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
81 imp_avs_get_audio avs_get_audio;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
82 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
83 } AVS_T;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
84
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
85 AVS_T *initAVS(const char *filename)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
86 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
87 AVS_T *AVS = (AVS_T *) malloc (sizeof(AVS_T));
14695
faust3
parents: 14693
diff changeset
88 AVS_Value arg0 = avs_new_value_string(filename);
faust3
parents: 14693
diff changeset
89 AVS_Value args = avs_new_value_array(&arg0, 1);
faust3
parents: 14693
diff changeset
90
14693
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
91 memset(AVS, 0, sizeof(AVS_T));
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
92
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
93 #ifdef WIN32_LOADER
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
94 Setup_LDT_Keeper();
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
95 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
96
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
97 AVS->dll = LoadLibraryA("avisynth.dll");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
98 if(!AVS->dll)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
99 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
100 mp_msg(MSGT_DEMUX ,MSGL_V, "AVS: failed to load avisynth.dll\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
101 return NULL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
102 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
103
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
104 /* Dynamic import of needed stuff from avisynth.dll */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
105 IMPORT_FUNC(avs_create_script_environment);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
106 IMPORT_FUNC(avs_create_script_environment);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
107 IMPORT_FUNC(avs_invoke);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
108 IMPORT_FUNC(avs_get_video_info);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
109 IMPORT_FUNC(avs_take_clip);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
110 IMPORT_FUNC(avs_get_frame);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
111 IMPORT_FUNC(avs_release_video_frame);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
112 #ifdef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
113 IMPORT_FUNC(avs_get_audio);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
114 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
115
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
116 AVS->avs_env = AVS->avs_create_script_environment(AVISYNTH_INTERFACE_VERSION);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
117 if (!AVS->avs_env)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
118 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
119 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_create_script_environment failed\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
120 return NULL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
121 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
122
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
123
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
124 AVS->handler = AVS->avs_invoke(AVS->avs_env, "Import", args, 0);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
125
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
126 if (avs_is_error(AVS->handler))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
127 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
128 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Avisynth error: %s\n", avs_as_string(AVS->handler));
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
129 return NULL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
130 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
131
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
132 if (!avs_is_clip(AVS->handler))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
133 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
134 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Avisynth doesn't return a clip\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
135 return NULL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
136 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
137
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
138 return AVS;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
139 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
140
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
141 /* Implement RGB MODES ?? */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
142 #if 0
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
143 static __inline int get_mmioFOURCC(const AVS_VideoInfo *v)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
144 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
145 if (avs_is_rgb(v)) return mmioFOURCC(8, 'R', 'G', 'B');
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
146 if (avs_is_rgb24(v)) return mmioFOURCC(24, 'R', 'G', 'B');
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
147 if (avs_is_rgb32(v)) return mmioFOURCC(32, 'R', 'G', 'B');
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
148 if (avs_is_yv12(v)) return mmioFOURCC('Y', 'V', '1', '2');
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
149 if (avs_is_yuy(v)) return mmioFOURCC('Y', 'U', 'Y', ' ');
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
150 if (avs_is_yuy2(v)) return mmioFOURCC('Y', 'U', 'Y', '2');
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
151 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
152 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
153 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
154
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
155 int demux_avs_fill_buffer(demuxer_t *demuxer)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
156 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
157 AVS_VideoFrame *curr_frame;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
158 demux_packet_t *dp = NULL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
159 AVS_T *AVS = (AVS_T *) demuxer->priv;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
160
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
161 demux_stream_t *d_video=demuxer->video;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
162 sh_video_t *sh_video=d_video->sh;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
163
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
164 #ifdef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
165 demux_stream_t *d_audio=demuxer->audio;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
166 sh_audio_t *sh_audio=d_audio->sh;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
167 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
168
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
169 if (AVS->video_info->num_frames < AVS->frameno) return 0; // EOF
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
170
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
171 curr_frame = AVS->avs_get_frame(AVS->clip, AVS->frameno);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
172 if (!curr_frame)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
173 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
174 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: error getting frame -- EOF??\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
175 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
176 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
177
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
178 if (avs_has_video(AVS->video_info))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
179 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
180 dp = new_demux_packet(curr_frame->vfb->data_size);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
181 sh_video->num_frames_decoded++;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
182 sh_video->num_frames++;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
183
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
184 d_video->pts=AVS->frameno / sh_video->fps; // OSD
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
185
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
186 memcpy(dp->buffer, curr_frame->vfb->data + curr_frame->offset, curr_frame->vfb->data_size);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
187 ds_add_packet(demuxer->video, dp);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
188
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
189 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
190
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
191 #ifdef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
192 /* Audio */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
193 if (avs_has_audio(AVS->video_info))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
194 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
195 int l = sh_audio->wf->nAvgBytesPerSec;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
196 dp = new_demux_packet(l);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
197
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
198 if (AVS->avs_get_audio(AVS->avs_env, dp->buffer, AVS->frameno*sh_video->fps*l, l))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
199 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
200 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_get_audio() failed\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
201 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
202 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
203 ds_add_packet(demuxer->audio, dp);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
204 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
205 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
206
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
207 AVS->frameno++;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
208 AVS->avs_release_video_frame(curr_frame);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
209 return 1;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
210 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
211
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
212 int demux_open_avs(demuxer_t* demuxer)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
213 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
214 sh_video_t *sh_video = NULL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
215 #ifdef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
216 sh_audio_t *sh_audio = NULL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
217 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
218 int found = 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
219 AVS_T *AVS = (AVS_T *) demuxer->priv;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
220 AVS->frameno = 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
221
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
222 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: demux_open_avs()\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
223 demuxer->seekable = 1;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
224
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
225 AVS->clip = AVS->avs_take_clip(AVS->handler, AVS->avs_env);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
226 if(!AVS->clip)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
227 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
228 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_take_clip() failed\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
229 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
230 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
231
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
232 AVS->video_info = AVS->avs_get_video_info(AVS->clip);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
233 if (!AVS->video_info)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
234 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
235 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_get_video_info() call failed\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
236 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
237 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
238
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
239 if (!avs_is_yv12(AVS->video_info))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
240 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
241 AVS->handler = AVS->avs_invoke(AVS->avs_env, "ConvertToYV12", avs_new_value_array(&AVS->handler, 1), 0);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
242 if (avs_is_error(AVS->handler))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
243 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
244 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Cannot convert input video to YV12: %s\n", avs_as_string(AVS->handler));
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
245 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
246 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
247
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
248 AVS->clip = AVS->avs_take_clip(AVS->handler, AVS->avs_env);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
249
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
250 if(!AVS->clip)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
251 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
252 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_take_clip() failed\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
253 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
254 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
255
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
256 AVS->video_info = AVS->avs_get_video_info(AVS->clip);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
257 if (!AVS->video_info)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
258 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
259 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_get_video_info() call failed\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
260 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
261 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
262 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
263
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
264 // TODO check field-based ??
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
265
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
266 /* Video */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
267 if (avs_has_video(AVS->video_info))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
268 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
269 found = 1;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
270 sh_video = new_sh_video(demuxer, 0);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
271
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
272 demuxer->video->sh = sh_video;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
273 sh_video->ds = demuxer->video;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
274
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
275 sh_video->disp_w = AVS->video_info->width;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
276 sh_video->disp_h = AVS->video_info->height;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
277
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
278 //sh_video->format = get_mmioFOURCC(AVS->video_info);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
279 sh_video->format = mmioFOURCC('Y', 'V', '1', '2');
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
280 sh_video->fps = (float) ((float) AVS->video_info->fps_numerator / (float) AVS->video_info->fps_denominator);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
281 sh_video->frametime = 1.0 / sh_video->fps;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
282
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
283 sh_video->bih = (BITMAPINFOHEADER*) malloc(sizeof(BITMAPINFOHEADER) + (256 * 4));
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
284 sh_video->bih->biCompression = sh_video->format;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
285 sh_video->bih->biBitCount = avs_bits_per_pixel(AVS->video_info);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
286 //sh_video->bih->biPlanes = 2;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
287
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
288 sh_video->bih->biWidth = AVS->video_info->width;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
289 sh_video->bih->biHeight = AVS->video_info->height;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
290 sh_video->num_frames = 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
291 sh_video->num_frames_decoded = 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
292 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
293
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
294 #ifdef ENABLE_AUDIO
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
295 /* Audio */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
296 if (avs_has_audio(AVS->video_info))
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
297 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
298 found = 1;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
299 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Clip has audio -> Channels = %d - Freq = %d\n", AVS->video_info->nchannels, AVS->video_info->audio_samples_per_second);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
300
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
301 sh_audio = new_sh_audio(demuxer, 0);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
302 demuxer->audio->sh = sh_audio;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
303 sh_audio->ds = demuxer->audio;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
304
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
305 sh_audio->wf = (WAVEFORMATEX*) malloc(sizeof(WAVEFORMATEX));
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
306 sh_audio->wf->wFormatTag = sh_audio->format = 0x1;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
307 sh_audio->wf->nChannels = sh_audio->channels = AVS->video_info->nchannels;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
308 sh_audio->wf->nSamplesPerSec = sh_audio->samplerate = AVS->video_info->audio_samples_per_second;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
309 sh_audio->wf->nAvgBytesPerSec = AVS->video_info->audio_samples_per_second * 4;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
310 sh_audio->wf->nBlockAlign = 4;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
311 sh_audio->wf->wBitsPerSample = sh_audio->samplesize = 16; // AVS->video_info->sample_type ??
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
312 sh_audio->wf->cbSize = 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
313 sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
314 sh_audio->o_bps = sh_audio->wf->nAvgBytesPerSec;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
315 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
316 #endif
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
317
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
318 AVS->init = 1;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
319 return found;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
320 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
321
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
322 int demux_avs_control(demuxer_t *demuxer, int cmd, void *arg)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
323 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
324 demux_stream_t *d_video=demuxer->video;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
325 sh_video_t *sh_video=d_video->sh;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
326 AVS_T *AVS = (AVS_T *) demuxer->priv;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
327
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
328 switch(cmd)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
329 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
330 case DEMUXER_CTRL_GET_TIME_LENGTH:
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
331 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
332 if (!AVS->video_info->num_frames) return DEMUXER_CTRL_DONTKNOW;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
333 *((unsigned long *)arg) = AVS->video_info->num_frames / sh_video->fps;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
334 return DEMUXER_CTRL_OK;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
335 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
336 case DEMUXER_CTRL_GET_PERCENT_POS:
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
337 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
338 if (!AVS->video_info->num_frames) return DEMUXER_CTRL_DONTKNOW;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
339 *((int *)arg) = (int) (AVS->frameno * 100 / AVS->video_info->num_frames);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
340 return DEMUXER_CTRL_OK;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
341 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
342 default:
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
343 return DEMUXER_CTRL_NOTIMPL;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
344 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
345 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
346
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
347 void demux_close_avs(demuxer_t* demuxer)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
348 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
349 AVS_T *AVS = (AVS_T *) demuxer->priv;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
350 // TODO release_clip?
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
351 if (AVS)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
352 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
353 if (AVS->dll)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
354 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
355 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Unloading avisynth.dll\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
356 FreeLibrary(AVS->dll);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
357 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
358 free(AVS);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
359 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
360 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
361
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
362 void demux_seek_avs(demuxer_t *demuxer, float rel_seek_secs,int flags)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
363 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
364 demux_stream_t *d_video=demuxer->video;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
365 sh_video_t *sh_video=d_video->sh;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
366 AVS_T *AVS = (AVS_T *) demuxer->priv;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
367 int video_pos=AVS->frameno;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
368
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
369 //mp_msg(MSGT_DEMUX, MSGL_V, "AVS: seek rel_seek_secs = %f - flags = %x\n", rel_seek_secs, flags);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
370
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
371 // seek absolute
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
372 if (flags&1) video_pos=0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
373
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
374 video_pos += (rel_seek_secs * sh_video->fps);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
375 if (video_pos < 0) video_pos = 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
376 if (video_pos > AVS->video_info->num_frames) video_pos = AVS->video_info->num_frames;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
377
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
378 AVS->frameno = video_pos;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
379 sh_video->num_frames_decoded = video_pos;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
380 sh_video->num_frames = video_pos;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
381 d_video->pts=AVS->frameno / sh_video->fps; // OSD
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
382 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
383
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
384 int avs_check_file(demuxer_t *demuxer, const char *filename)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
385 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
386 mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_check_file - attempting to open file %s\n", filename);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
387
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
388 if (!filename) return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
389
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
390 /* Avoid crazy memory eating when passing an mpg stream */
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
391 if (demuxer->movi_end > MAX_AVS_SIZE)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
392 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
393 mp_msg(MSGT_DEMUX,MSGL_V, "AVS: File is too big, aborting...\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
394 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
395 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
396
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
397 demuxer->priv = initAVS(filename);
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
398
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
399 if (demuxer->priv)
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
400 {
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
401 mp_msg(MSGT_DEMUX,MSGL_V, "AVS: Init Ok\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
402 return 1;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
403 }
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
404 mp_msg(MSGT_DEMUX,MSGL_V, "AVS: Init failed\n");
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
405 return 0;
37116118ab6a avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
diff changeset
406 }