1 /*
2 * function: Decoding thread for aacDECdrop
3 *
4 * This program is distributed under the GNU General Public License, version 2.
5 * A copy of this license is included with this source.
6 *
7 * Copyright (C) 2002 John Edwards
8 *
9 * last mod: aacDecdrop decoder last updated 2002-03-14
10 */
11
12 #include <windows.h>
13 #include <time.h>
14 #include <string.h>
15
16 #include "wave_out.h"
17 #include "decode.h"
18 #include "misc.h"
19
20 extern int decoding_done;
21 extern int animate;
22 extern double file_complete;
23 extern int totalfiles;
24 extern int numfiles;
25 int dec_mode;
26 int outputFormat;
27 int fileType;
28 int object_type;
29 extern char* fileName;
30 int stop_decoding;
31
32 typedef struct enclist_tag {
33 char *filename;
34 struct enclist_tag *next;
35 } enclist_t;
36
37 enclist_t *head = NULL;
38
39 CRITICAL_SECTION mutex;
40
41 DWORD WINAPI decode_thread(LPVOID arg);
42
decthread_init(void)43 void decthread_init(void)
44 {
45 int thread_id;
46 HANDLE thand;
47
48 numfiles = 0;
49 totalfiles = 0;
50 file_complete = 0.0;
51
52 InitializeCriticalSection(&mutex);
53
54 thand = CreateThread(NULL, 0, decode_thread, NULL, 0, &thread_id);
55 if (thand == NULL) {
56 // something bad happened, might want to deal with that, maybe...
57 }
58 }
59
decthread_addfile(char * file)60 void decthread_addfile(char *file)
61 {
62 char *filename;
63 enclist_t *entry, *node;
64
65 if (file == NULL) return;
66
67 // create entry
68 filename = strdup(file);
69 entry = (enclist_t *)malloc(sizeof(enclist_t));
70
71 entry->filename = filename;
72 entry->next = NULL;
73
74 EnterCriticalSection(&mutex);
75
76 // insert entry
77 if (head == NULL) {
78 head = entry;
79 } else {
80 node = head;
81 while (node->next != NULL)
82 node = node->next;
83
84 node->next = entry;
85 }
86 numfiles++;
87 totalfiles++;
88
89 LeaveCriticalSection(&mutex);
90 }
91
92 /*
93 * the caller is responsible for deleting the pointer
94 */
95
_getfile()96 char *_getfile()
97 {
98 char *filename;
99 enclist_t *entry;
100
101 EnterCriticalSection(&mutex);
102
103 if (head == NULL) {
104 LeaveCriticalSection(&mutex);
105 return NULL;
106 }
107
108 // pop entry
109 entry = head;
110 head = head->next;
111
112 filename = entry->filename;
113 free(entry);
114
115 LeaveCriticalSection(&mutex);
116
117 return filename;
118 }
119
decthread_set_decode_mode(int decode_mode)120 void decthread_set_decode_mode(int decode_mode)
121 {
122 dec_mode = decode_mode;
123 }
124
decthread_set_outputFormat(int output_format)125 void decthread_set_outputFormat(int output_format)
126 {
127 outputFormat = output_format;
128 }
129
decthread_set_fileType(int file_type)130 void decthread_set_fileType(int file_type)
131 {
132 fileType = file_type;
133 }
134
decthread_set_object_type(int object_type)135 void decthread_set_object_type(int object_type)
136 {
137 object_type = object_type;
138 }
139
_error(char * errormessage)140 void _error(char *errormessage)
141 {
142 // do nothing
143 }
144
_update(long total,long done)145 void _update(long total, long done)
146 {
147 file_complete = (double)done / (double)total;
148 }
149
decode_thread(LPVOID arg)150 DWORD WINAPI decode_thread(LPVOID arg)
151 {
152 char *in_file;
153
154 while (!decoding_done)
155 {
156 while (in_file = _getfile())
157 {
158 aac_dec_opt dec_opts;
159 animate = 1;
160
161 if(stop_decoding){
162 numfiles--;
163 break;
164 }
165 set_filename(in_file);
166
167 dec_opts.progress_update = _update;
168 dec_opts.filename = in_file;
169 dec_opts.decode_mode = dec_mode;
170 dec_opts.output_format = outputFormat;
171 dec_opts.file_type = fileType;
172 dec_opts.object_type = object_type;
173 fileName = in_file;
174
175 aac_decode(&dec_opts);
176
177 numfiles--;
178 } /* Finished this file, loop around to next... */
179
180 file_complete = 0.0;
181 animate = 0;
182 totalfiles = 0;
183 numfiles = 0;
184
185 Sleep(500);
186 }
187
188 DeleteCriticalSection(&mutex);
189
190 return 0;
191 }
192
193 /******************************** end of decthread.c ********************************/
194
195