OSDN Git Service

古いコンフィグを削除
[coroid/inqubus.git] / vhook / framehook.c
1 /*フレームフックの相手をするため専用*/
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <SDL/SDL.h>
7 #include "common/framehook_ext.h"
8 #include "framehook.h"
9 #include "main.h"
10 #include "mydef.h"
11 #include "nicodef.h"
12 #include "util.h"
13
14 #ifdef _WIN32
15  #define DLLEXPORT __declspec(dllexport)
16 #else
17  #define DLLEXPORT
18 #endif
19
20 typedef struct ContextInfo{
21         FILE* log;
22         DATA data;
23 } ContextInfo;
24
25 /*
26  * 必要な関数ひとつめ。最初に呼ばれるよ!
27  * 
28  */
29 int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]);
30
31 DLLEXPORT int ExtConfigure(void **ctxp,const toolbox *tbox, int argc, char *argv[]){
32         int i;
33         //ログ
34         FILE* log = fopen("[log]vhext.txt", "w");
35         if(log == NULL){
36                 puts("[framehook/init]failed to open logfile.\n");
37                 fflush(log);
38                 return -1;
39         }else{
40                 fputs("[framehook/init]initializing..\n",log);
41                 fflush(log);
42         }
43         //必要な設定があるかの確認
44         fprintf(log,"[framehook/init]called with argc = %d\n",argc);
45         fflush(log);
46         for(i=0;i<argc;i++){
47                 fprintf(log,"[framehook/init]arg[%2d] = %s\n",i,argv[i]);
48                 fflush(log);
49         }
50         //セッティング取得。
51         SETTING setting;
52         if(init_setting(log,tbox,&setting,argc,argv)){
53                 fputs("[framehook/init]initialized settings.\n",log);
54                 fflush(log);
55         }else{
56                 fputs("[framehook/init]failed to initialize settings.\n",log);
57                 fflush(log);
58                 return -2;
59         }
60         //ライブラリなどの初期化
61         if(init(log)){
62                 fputs("[framehook/init]initialized libs.\n",log);
63                 fflush(log);
64         }else{
65                 fputs("[framehook/init]failed to initialize libs.\n",log);
66                 fflush(log);
67                 return -3;
68         }
69         /*コンテキストの設定*/
70         *ctxp = malloc(sizeof(ContextInfo));
71         if(*ctxp == NULL){
72                 fputs("[framehook/init]initialized to malloc for context.\n",log);
73                 fflush(log);
74         }
75         ContextInfo* ci = (ContextInfo*)*ctxp;
76         ci->log = log;
77         fflush(log);
78         if(initData(&ci->data,log,&setting)){
79                 fputs("[framehook/init]initialized context.\n",log);
80                 fputs("[framehook/init]initialized.\n",log);
81                 fflush(log);
82                 return 0;
83         }else{
84                 fputs("[framehook/init]failed to initialize context.\n",log);
85                 fflush(log);
86                 return -4;
87         }
88 }
89 /*
90  * 内部でのみ呼ばれる。
91  */
92
93  /*
94         argv[0]:プログラム
95         argv[1]:vhook
96         argv[2]:フォント
97         argv[3]:フォントインデックス
98         argv[4]:一画面
99         argv[5]:影の種類
100         以降オプション
101         --enable-show-video:描画中に動画を見せる。
102         --enable-fontsize-fix:フォントサイズを自動で調整する。
103 */
104  
105 int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]){
106         /*videoの長さ*/
107         setting->video_length = (tbox->video_length * VPOS_FACTOR);
108         /*以降オプション*/
109         
110         //コメントを見せるか否か?
111         setting->enable_user_comment = FALSE;
112         setting->enable_owner_comment = FALSE;
113         setting->data_user_path = NULL;
114         setting->data_owner_path = NULL;
115         //一般的な設定
116         setting->font_path = NULL;
117         setting->font_index = 0;
118         setting->user_slot_max = 30;
119         setting->owner_slot_max = 30;
120         setting->shadow_kind = 1;//デフォルトはニコニコ動画風
121         setting->show_video = FALSE;
122         setting->fontsize_fix=FALSE;
123         setting->opaque_comment=FALSE;
124     setting->aspect_mode = 0;
125         int i;
126         char* arg;
127         for(i=0;i<argc;i++){
128                 arg = argv[i];
129                 if(!setting->data_user_path && strncmp(FRAMEHOOK_OPT_DATA_USER,arg,FRAMEHOOK_OPT_DATA_USER_LEN) == 0){
130                         char* data_user = arg+FRAMEHOOK_OPT_DATA_USER_LEN;
131                         setting->data_user_path = data_user;
132                         setting->enable_user_comment = TRUE;
133                         fprintf(log,"[framehook/init]User Comment data path:%s\n",setting->data_user_path);
134                         fflush(log);
135                 }else if(!setting->data_owner_path && strncmp(FRAMEHOOK_OPT_DATA_OWNER,arg,FRAMEHOOK_OPT_DATA_OWNER_LEN) == 0){
136                         char* data_owner = arg+FRAMEHOOK_OPT_DATA_OWNER_LEN;
137                         setting->data_owner_path = data_owner;
138                         setting->enable_owner_comment = TRUE;
139                         fprintf(log,"[framehook/init]Owner Comment data path:%s\n",setting->data_owner_path);
140                         fflush(log);
141                 }else if(!setting->font_path && strncmp(FRAMEHOOK_OPT_FONT,arg,FRAMEHOOK_OPT_FONT_LEN) == 0){
142                         char* font = arg+FRAMEHOOK_OPT_FONT_LEN;
143                         setting->font_path = font;
144                         fprintf(log,"[framehook/init]Font path:%s\n",setting->font_path);
145                         fflush(log);
146                 }else if(strncmp(FRAMEHOOK_OPT_FONTINDEX,arg,FRAMEHOOK_OPT_FONTINDEX_LEN) == 0){
147                         setting->font_index = MAX(0,atoi(arg+FRAMEHOOK_OPT_FONTINDEX_LEN));
148                         fprintf(log,"[framehook/init]font index:%d\n",setting->font_index);
149                         fflush(log);
150                 }else if(strncmp(FRAMEHOOK_OPT_SHADOW,arg,FRAMEHOOK_OPT_SHADOW_LEN) == 0){
151                         setting->shadow_kind = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHADOW_LEN));
152                         fprintf(log,"[framehook/init]shadow kind:%d\n",setting->shadow_kind);
153                         fflush(log);
154                 }else if(strncmp(FRAMEHOOK_OPT_SHOW_USER,arg,FRAMEHOOK_OPT_SHOW_USER_LEN) == 0){
155                         setting->user_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_USER_LEN));
156                         fprintf(log,"[framehook/init]User Comments on screen:%d\n",setting->user_slot_max);
157                         fflush(log);
158                 }else if(strncmp(FRAMEHOOK_OPT_SHOW_OWNER,arg,FRAMEHOOK_OPT_SHOW_OWNER_LEN) == 0){
159                         setting->owner_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_OWNER_LEN));
160                         fprintf(log,"[framehook/init]Owner Comments on screen:%d\n",setting->owner_slot_max);
161                         fflush(log);
162                 }else if(!setting->show_video && strcmp(arg,"--enable-show-video") == 0){
163                         fputs("[framehook/init]show video while converting.\n",log);
164                         fflush(log);
165                         setting->show_video=TRUE;
166                 }else if(!setting->fontsize_fix && strcmp(arg,"--enable-fix-font-size") == 0){
167                         fputs("[framehook/init]fix font size automatically.\n",log);
168                         fflush(log);
169                         setting->fontsize_fix=TRUE;
170                 }else if(!setting->opaque_comment && strcmp(arg,"--enable-opaque-comment") == 0){
171                         fputs("[framehook/init]enable opaque comment.\n",log);
172                         fflush(log);
173                         setting->opaque_comment=TRUE;
174         } else if (strncmp(FRAMEHOOK_OPT_ASPECT_MODE, arg, FRAMEHOOK_OPT_ASPECT_MODE_LEN) == 0) {
175             setting->aspect_mode = MAX(0, atoi(arg + FRAMEHOOK_OPT_ASPECT_MODE_LEN));
176             fprintf(log, "[framehook/init]aspect mode:%d\n", setting->aspect_mode);
177             fflush(log);
178         }
179     }
180         //引数を正しく入力したか否かのチェック
181         //ここでチェックしているの以外は、デフォルト設定で逃げる。
182         if(!setting->font_path){
183                 fputs("[framehook/init]please set FONT PATH.\n",log);
184                 fflush(log);
185                 return FALSE;
186         }
187         return TRUE;
188 }
189
190 /*
191  * 必要な関数二つめ。フレームごとに呼ばれるよ!
192  * 
193  */
194 DLLEXPORT void ExtProcess(void *ctx,const toolbox *tbox,vhext_frame *pict){
195     ContextInfo *ci = (ContextInfo *) ctx;
196     FILE* log = ci->log;
197
198         /* Note:
199          * Saccubus 1.22以降の拡張vhookフィルタでは、RGB24フォーマットでのみ
200          * 画像が提供されます。
201          */
202
203         //SDLのサーフェイスに変換
204     SDL_Surface* surf = SDL_CreateRGBSurfaceFrom(pict->data,
205                                                                                         pict->w,pict->h,24,pict->linesize,
206                                                                                                 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
207                                                                                                     0xff000000,
208                                                                                                     0x00ff0000,
209                                                                                                     0x0000ff00,
210                                                                                                 #else
211                                                                                                     0x000000ff,
212                                                                                                     0x0000ff00,
213                                                                                                     0x00ff0000,
214                                                                                                 #endif
215                                                                                                     0x00000000
216                                                                                                 );
217         //フィルタ
218         int now_vpos = (pict->pts * VPOS_FACTOR);
219         if(!main_process(&ci->data,surf,now_vpos)){
220                 fputs("[framehook/process]failed to process.\n",log);
221                 fflush(log);
222                 exit(1);
223         }
224         //サーフェイス開放
225         SDL_FreeSurface(surf);
226         fflush(log);
227 }
228
229 /*
230  * 必要な関数最後。終わったら呼ばれるよ!
231  * 
232  */
233
234 DLLEXPORT void ExtRelease(void *ctx,const toolbox *tbox){
235     ContextInfo *ci;
236     ci = (ContextInfo *) ctx;
237     FILE* log = ci->log;
238     fputs("[framehook/close]closing...\n",log);
239     if (ctx) {
240         closeData(&ci->data);
241             fputs("[framehook/close]closed.\n",log);
242         fclose(log);
243             //コンテキスト全体
244         free(ctx);
245     }
246     //ライブラリの終了
247     close();
248 }
249