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     memset(setting->comment, 0x00, sizeof(setting->comment));
112         //一般的な設定
113         setting->font_path = NULL;
114         setting->font_index = 0;
115         setting->user_slot_max = 30;
116         setting->owner_slot_max = 30;
117         setting->shadow_kind = 1;//デフォルトはニコニコ動画風
118         setting->show_video = FALSE;
119         setting->fontsize_fix=FALSE;
120         setting->opaque_comment=FALSE;
121     setting->aspect_mode = 0;
122         int i;
123         char* arg;
124         for(i=0;i<argc;i++) {
125         arg = argv[i];
126         if (!setting->comment[0].path && strncmp(FRAMEHOOK_OPT_DATA_USER, arg, FRAMEHOOK_OPT_DATA_USER_LEN) == 0) {
127             char* data = arg + FRAMEHOOK_OPT_DATA_USER_LEN;
128             setting->comment[0].path = data;
129             setting->comment[0].enable = TRUE;
130             fprintf(log, "[framehook/init]User Comment data path:%s\n", setting->comment[0].path);
131             fflush(log);
132         } else if (!setting->comment[1].path && strncmp(FRAMEHOOK_OPT_DATA_OWNER, arg, FRAMEHOOK_OPT_DATA_OWNER_LEN) == 0) {
133             char* data = arg + FRAMEHOOK_OPT_DATA_OWNER_LEN;
134             setting->comment[1].path = data;
135             setting->comment[1].enable = TRUE;
136             fprintf(log, "[framehook/init]Owner Comment data path:%s\n", setting->comment[1].path);
137             fflush(log);
138                 }else if(!setting->font_path && strncmp(FRAMEHOOK_OPT_FONT,arg,FRAMEHOOK_OPT_FONT_LEN) == 0){
139                         char* font = arg+FRAMEHOOK_OPT_FONT_LEN;
140                         setting->font_path = font;
141                         fprintf(log,"[framehook/init]Font path:%s\n",setting->font_path);
142                         fflush(log);
143                 }else if(strncmp(FRAMEHOOK_OPT_FONTINDEX,arg,FRAMEHOOK_OPT_FONTINDEX_LEN) == 0){
144                         setting->font_index = MAX(0,atoi(arg+FRAMEHOOK_OPT_FONTINDEX_LEN));
145                         fprintf(log,"[framehook/init]font index:%d\n",setting->font_index);
146                         fflush(log);
147                 }else if(strncmp(FRAMEHOOK_OPT_SHADOW,arg,FRAMEHOOK_OPT_SHADOW_LEN) == 0){
148                         setting->shadow_kind = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHADOW_LEN));
149                         fprintf(log,"[framehook/init]shadow kind:%d\n",setting->shadow_kind);
150                         fflush(log);
151                 }else if(strncmp(FRAMEHOOK_OPT_SHOW_USER,arg,FRAMEHOOK_OPT_SHOW_USER_LEN) == 0){
152                         setting->user_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_USER_LEN));
153                         fprintf(log,"[framehook/init]User Comments on screen:%d\n",setting->user_slot_max);
154                         fflush(log);
155                 }else if(strncmp(FRAMEHOOK_OPT_SHOW_OWNER,arg,FRAMEHOOK_OPT_SHOW_OWNER_LEN) == 0){
156                         setting->owner_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_OWNER_LEN));
157                         fprintf(log,"[framehook/init]Owner Comments on screen:%d\n",setting->owner_slot_max);
158                         fflush(log);
159                 }else if(!setting->show_video && strcmp(arg,"--enable-show-video") == 0){
160                         fputs("[framehook/init]show video while converting.\n",log);
161                         fflush(log);
162                         setting->show_video=TRUE;
163                 }else if(!setting->fontsize_fix && strcmp(arg,"--enable-fix-font-size") == 0){
164                         fputs("[framehook/init]fix font size automatically.\n",log);
165                         fflush(log);
166                         setting->fontsize_fix=TRUE;
167                 }else if(!setting->opaque_comment && strcmp(arg,"--enable-opaque-comment") == 0){
168                         fputs("[framehook/init]enable opaque comment.\n",log);
169                         fflush(log);
170                         setting->opaque_comment=TRUE;
171         } else if (strncmp(FRAMEHOOK_OPT_ASPECT_MODE, arg, FRAMEHOOK_OPT_ASPECT_MODE_LEN) == 0) {
172             setting->aspect_mode = MAX(0, atoi(arg + FRAMEHOOK_OPT_ASPECT_MODE_LEN));
173             fprintf(log, "[framehook/init]aspect mode:%d\n", setting->aspect_mode);
174             fflush(log);
175         }
176     }
177         //引数を正しく入力したか否かのチェック
178         //ここでチェックしているの以外は、デフォルト設定で逃げる。
179         if(!setting->font_path){
180                 fputs("[framehook/init]please set FONT PATH.\n",log);
181                 fflush(log);
182                 return FALSE;
183         }
184         return TRUE;
185 }
186
187 /*
188  * 必要な関数二つめ。フレームごとに呼ばれるよ!
189  * 
190  */
191 DLLEXPORT void ExtProcess(void *ctx,const toolbox *tbox,vhext_frame *pict){
192     ContextInfo *ci = (ContextInfo *) ctx;
193     FILE* log = ci->log;
194
195         /* Note:
196          * Saccubus 1.22以降の拡張vhookフィルタでは、RGB24フォーマットでのみ
197          * 画像が提供されます。
198          */
199
200         //SDLのサーフェイスに変換
201     SDL_Surface* surf = SDL_CreateRGBSurfaceFrom(pict->data,
202                                                                                         pict->w,pict->h,24,pict->linesize,
203                                                                                                 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
204                                                                                                     0xff000000,
205                                                                                                     0x00ff0000,
206                                                                                                     0x0000ff00,
207                                                                                                 #else
208                                                                                                     0x000000ff,
209                                                                                                     0x0000ff00,
210                                                                                                     0x00ff0000,
211                                                                                                 #endif
212                                                                                                     0x00000000
213                                                                                                 );
214         //フィルタ
215         int now_vpos = (pict->pts * VPOS_FACTOR);
216         if(!main_process(&ci->data,surf,now_vpos)){
217                 fputs("[framehook/process]failed to process.\n",log);
218                 fflush(log);
219                 exit(1);
220         }
221         //サーフェイス開放
222         SDL_FreeSurface(surf);
223         fflush(log);
224 }
225
226 /*
227  * 必要な関数最後。終わったら呼ばれるよ!
228  * 
229  */
230
231 DLLEXPORT void ExtRelease(void *ctx,const toolbox *tbox){
232     ContextInfo *ci;
233     ci = (ContextInfo *) ctx;
234     FILE* log = ci->log;
235     fputs("[framehook/close]closing...\n",log);
236     if (ctx) {
237         closeData(&ci->data);
238             fputs("[framehook/close]closed.\n",log);
239         fclose(log);
240             //コンテキスト全体
241         free(ctx);
242     }
243     //ライブラリの終了
244     close();
245 }
246