~ft/aacdec

ref: 1b71a6ba963d131375f5e489b3b25e36f19f3f24 aacdec/aacDECdrop/decthread.c -rw-r--r-- 3.2 KiB
1b71a6ba — Fabian Greffrath fix heap-buffer-overflow in mp4read.c 1 year, 23 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * function: Decoding thread for aacDECdrop
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright (C) 2002 John Edwards
 *
 * last mod: aacDecdrop decoder last updated 2002-03-14
 */

#include <windows.h>
#include <time.h>
#include <string.h>

#include "wave_out.h"
#include "decode.h"
#include "misc.h"

extern int decoding_done;
extern int animate;
extern double file_complete;
extern int totalfiles;
extern int numfiles;
int dec_mode;
int outputFormat;
int fileType;
int object_type;
extern char* fileName;
int stop_decoding;

typedef struct enclist_tag {
	char *filename;
	struct enclist_tag *next;
} enclist_t;

enclist_t *head = NULL;

CRITICAL_SECTION mutex;

DWORD WINAPI decode_thread(LPVOID arg);

void decthread_init(void)
{
	int thread_id;
	HANDLE thand;

	numfiles = 0;
	totalfiles = 0;
	file_complete = 0.0;

	InitializeCriticalSection(&mutex);

	thand = CreateThread(NULL, 0, decode_thread, NULL, 0, &thread_id);
	if (thand == NULL) {
		// something bad happened, might want to deal with that, maybe...
	}
}

void decthread_addfile(char *file)
{
	char *filename;
	enclist_t *entry, *node;

	if (file == NULL) return;

	// create entry
	filename = strdup(file);
	entry = (enclist_t *)malloc(sizeof(enclist_t));

	entry->filename = filename;
	entry->next = NULL;

	EnterCriticalSection(&mutex);

	// insert entry
	if (head == NULL) {
		head = entry;
	} else {
		node = head;
		while (node->next != NULL)
			node = node->next;

		node->next = entry;
	}
	numfiles++;
	totalfiles++;

	LeaveCriticalSection(&mutex);
}

/*
 * the caller is responsible for deleting the pointer
 */

char *_getfile()
{
	char *filename;
	enclist_t *entry;

	EnterCriticalSection(&mutex);

	if (head == NULL) {
		LeaveCriticalSection(&mutex);
		return NULL;
	}

	// pop entry
	entry = head;
	head = head->next;

	filename = entry->filename;
	free(entry);

	LeaveCriticalSection(&mutex);

	return filename;
}

void decthread_set_decode_mode(int decode_mode)
{
	dec_mode = decode_mode;
}

void decthread_set_outputFormat(int output_format)
{
	outputFormat = output_format;
}

void decthread_set_fileType(int file_type)
{
	fileType = file_type;
}

void decthread_set_object_type(int object_type)
{
	object_type = object_type;
}

void _error(char *errormessage)
{
	// do nothing
}

void _update(long total, long done)
{
	file_complete = (double)done / (double)total;
}

DWORD WINAPI decode_thread(LPVOID arg)
{
	char *in_file;

	while (!decoding_done)
	{
		while (in_file = _getfile())
		{
			aac_dec_opt      dec_opts;
			animate = 1;

			if(stop_decoding){
				numfiles--;
				break;
			}
			set_filename(in_file);

			dec_opts.progress_update = _update;
			dec_opts.filename = in_file;
			dec_opts.decode_mode = dec_mode;
			dec_opts.output_format = outputFormat;
			dec_opts.file_type = fileType;
			dec_opts.object_type = object_type;
			fileName = in_file;

			aac_decode(&dec_opts);

			numfiles--;
		} /* Finished this file, loop around to next... */

		file_complete = 0.0;
		animate = 0;
		totalfiles = 0;
		numfiles = 0;

		Sleep(500);
	} 

	DeleteCriticalSection(&mutex);

	return 0;
}

/******************************** end of decthread.c ********************************/