[vorbis-dev] Some new code for Ogg Drop
Lars Brubaker
LarsBB at reflexive.net
Tue Dec 26 17:25:09 PST 2000
> Hi Lars,
>
> Can you please send your patches in "diff -u" or "diff -c" format?
> I like -u best, some others like -c; both are much better than
> plain diff. It's easier to apply such a patch to a different
> source tree than you generated it from, and (most important) it's
> human readable. With CVS, you can do "cvs diff -u ...".
>
> Cheers && happy hacking,
>
> Segher
>
Here you are -u as requested. If you need anything else just let me know.
Index: encthread.c
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/encthread.c,v
retrieving revision 1.2
diff -u -r1.2 encthread.c
--- encthread.c 2000/11/07 17:54:35 1.2
+++ encthread.c 2000/12/27 01:23:27
@@ -1,14 +1,17 @@
+//*************************************************************************
********************************************
#include <windows.h>
#include <time.h>
#include "audio.h"
#include "encode.h"
+//*************************************************************************
********************************************
extern int encoding_done;
extern int animate;
extern double file_complete;
extern int totalfiles;
extern int numfiles;
+//*************************************************************************
********************************************
typedef struct enclist_tag {
char *filename;
struct enclist_tag *next;
@@ -27,11 +30,13 @@
CRITICAL_SECTION mutex;
+//*************************************************************************
********************************************
DWORD WINAPI encode_thread(LPVOID arg);
+//*************************************************************************
********************************************
void encthread_init(void)
{
- int thread_id;
+ unsigned long thread_id;
HANDLE thand;
numfiles = 0;
@@ -46,13 +51,42 @@
}
}
+//*************************************************************************
********************************************
+static char* pCurrentDecopressingFileName = NULL;
+
+//*************************************************************************
********************************************
void encthread_addfile(char *file)
{
char *filename;
enclist_t *entry, *node;
+ enclist_t *pNext;
+
+ if(file == NULL)
+ {
+ return;
+ }
- if (file == NULL) return;
+ // let's see if the file is already being decompressed. If it
+ // is let's not put it in the list again.
+ if(pCurrentDecopressingFileName && strcmp(pCurrentDecopressingFileName,
file) == 0)
+ {
+ // we are adding a file that is in the list (and is the one being
decompressed).
+ return;
+ }
+
+ pNext = head;
+ while(pNext)
+ {
+ if(strcmp(pNext->filename, file) == 0)
+ {
+ // don't add the file it's already in the list.
+ return;
+ }
+ // move on to the next file in the list.
+ pNext = pNext->next;
+ }
+
EnterCriticalSection(&mutex);
// create entry
@@ -80,6 +114,7 @@
LeaveCriticalSection(&mutex);
}
+//*************************************************************************
********************************************
// the caller is responsible for deleting the pointer
char *_getfile()
{
@@ -105,34 +140,39 @@
return filename;
}
+//*************************************************************************
********************************************
void encthread_setbitrate(int kbps)
{
opt.kbps = kbps;
}
+//*************************************************************************
********************************************
void _nothing_prog(char *fn, long total, long done, double time)
{
// do nothing
}
+//*************************************************************************
********************************************
void _nothing_end(char *fn, double time, int rate, long samples, long
bytes)
{
// do nothing
}
+//*************************************************************************
********************************************
void _error(char *errormessage)
{
// do nothing
}
+//*************************************************************************
********************************************
void _update(char *fn, long total, long done, double time)
{
file_complete = (double)done / (double)total;
}
+//*************************************************************************
********************************************
DWORD WINAPI encode_thread(LPVOID arg)
{
- char *in_file;
long nextserial;
char buf[1024];
@@ -142,8 +182,10 @@
srand(time(NULL));
nextserial = rand();
- while (!encoding_done) {
- while (in_file = _getfile()) {
+ while (!encoding_done)
+ {
+ while(pCurrentDecopressingFileName = _getfile())
+ {
oe_enc_opt enc_opts;
char *out_fn = NULL;
FILE *in, *out = NULL;
@@ -162,21 +204,23 @@
enc_opts.error = _error;
- in = fopen(in_file, "rb");
+ in = fopen(pCurrentDecopressingFileName, "rb");
- if (in == NULL) {
+ if (in == NULL)
+ {
MessageBox(NULL, "blah", "error opening inputfile", 0);
numfiles--;
continue;
}
- if (out == NULL) {
+ if (out == NULL)
+ {
/* Create a filename from existing filename, replacing extension with
.ogg */
char *start, *end;
- start = in_file;
- end = rindex(in_file, '.');
- end = end?end:(start + strlen(in_file)+1);
+ start = pCurrentDecopressingFileName;
+ end = rindex(pCurrentDecopressingFileName, '.');
+ end = end?end:(start + strlen(pCurrentDecopressingFileName)+1);
out_fn = (char *)malloc(end - start + 5);
strncpy(out_fn, start, end-start);
@@ -195,7 +239,7 @@
if (!foundformat) {
free(out_fn);
- _snprintf(buf, 1024, "Format not supported! Skipping file %s...",
in_file);
+ _snprintf(buf, 1024, "Format not supported! Skipping file %s...",
pCurrentDecopressingFileName);
MessageBox(NULL, buf, "error", 0);
numfiles--;
continue;
@@ -213,11 +257,22 @@
enc_opts.out = out;
enc_opts.comments = &vc;
enc_opts.filename = out_fn;
- enc_opts.bitrate = opt.kbps; /* defaulted at the start, so this is ok */
+ if(enc_opts.channels > 1)
+ {
+ /* defaulted at the start, so this is ok */
+ enc_opts.bitrate = opt.kbps;
+ }
+ else
+ {
+ // it's only one chanel 1/2 the output bit rate
+ enc_opts.bitrate = opt.kbps/2;
+ }
if (!enc_opts.total_samples_per_channel)
+ {
enc_opts.progress_update = _nothing_prog;
+ }
oe_encode(&enc_opts); /* Should we care about return val? */
@@ -227,6 +282,7 @@
fclose(out);
numfiles--;
+ pCurrentDecopressingFileName = NULL;
} /* Finished this file, loop around to next... */
file_complete = 0.0;
@@ -245,3 +301,5 @@
return 0;
}
+
+//*************************************************************************
********************************************
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Vorbis-dev
mailing list