Permalink
Browse files

Use the new seom API, added support for ipv4:// output.

  • Loading branch information...
wereHamster committed Sep 24, 2007
1 parent 1536bbd commit c1aa02791e91bb86bcfbd4f7e6e07a329d7cbdc2
Showing with 174 additions and 192 deletions.
  1. +4 −4 Makefile
  2. +1 −1 convert-to-avi.sh
  3. +6 −13 include/stream.h
  4. +1 −0 include/yukon.h
  5. +7 −7 src/core/audio.c
  6. +4 −4 src/core/engine.c
  7. +44 −21 src/filter/main.c
  8. +5 −5 src/filter/wav.c
  9. +5 −5 src/filter/y4m.c
  10. +4 −5 src/stream/buffer.c
  11. +0 −89 src/stream/packet.c
  12. +59 −29 src/stream/stream.c
  13. +34 −9 src/tools/stat.c
View
@@ -11,7 +11,7 @@ ASM = yasm
CFLAGS = -Iinclude -Wall -std=c99 -O3
OBJS = src/core/conf.o src/core/log.o src/stream/stream.o src/core/engine.o \
- src/core/opengl.o src/stream/packet.o src/stream/buffer.o \
+ src/core/opengl.o src/stream/buffer.o \
src/glue/glue.o src/core/audio.o src/stream/arch/$(ARCH)/frame.o
LIBS = libX11.so libGL.so
@@ -32,13 +32,13 @@ $(LIBS):
rm -f $@.native
yukon-core-lib: $(OBJS)
- $(CC) -shared -o $@ $(OBJS) -lasound
+ $(CC) -shared -o $@ $(OBJS) -lasound -lseom
filter: src/filter/main.c src/filter/wav.c src/filter/y4m.c
- $(CC) $(CFLAGS) -o $@ src/filter/main.c src/filter/wav.c src/filter/y4m.c -lasound
+ $(CC) $(CFLAGS) -o $@ src/filter/main.c src/filter/wav.c src/filter/y4m.c -lasound -lseom
stat: src/tools/stat.c
- $(CC) $(CFLAGS) -o $@ $<
+ $(CC) $(CFLAGS) -o $@ $< -lseom
sysconf:
echo 'LDPATH="$(PREFIX)/$(LIBDIR)/yukon"' > $@
View
@@ -1,4 +1,4 @@
#!/bin/sh
./filter --audio "$1" | lame - audio.mp3
-./filter --video "$1" | mencoder -vf scale=400:300 -ovc xvid -xvidencopts bitrate=1200 -oac copy -audiofile audio.mp3 -o video.avi -
+./filter --video "$1" | mencoder -vf scale=1280:720 -ovc xvid -xvidencopts bitrate=1800 -oac copy -audiofile audio.mp3 -o video.avi -
View
@@ -14,39 +14,32 @@
#include <fcntl.h>
#include <unistd.h>
-struct yukonPacket {
- uint8_t type;
- uint64_t time;
- uint64_t size;
-};
+#include <seom/stream.h>
struct yukonBuffer {
pthread_mutex_t mutex;
pthread_cond_t cond;
unsigned long size, head, tail;
- struct yukonPacket *array[0];
+ struct seomPacket *array[0];
};
struct yukonStream {
int fileDescriptor;
+ seomStream *stream;
pthread_t multiplexerThread;
struct yukonBuffer *buffer;
};
-struct yukonPacket *yukonPacketCreate(unsigned char type, unsigned long size);
-void *yukonPacketPayload(struct yukonPacket *packet);
-void yukonPacketDestroy(struct yukonPacket *packet);
-
struct yukonBuffer *yukonBufferCreate(unsigned long size);
-void yukonBufferPut(struct yukonBuffer *buffer, struct yukonPacket *packet);
-struct yukonPacket *yukonBufferGet(struct yukonBuffer *buffer);
+void yukonBufferPut(struct yukonBuffer *buffer, struct seomPacket *packet);
+struct seomPacket *yukonBufferGet(struct yukonBuffer *buffer);
unsigned long yukonBufferCount(struct yukonBuffer *buffer);
void yukonBufferDestroy(struct yukonBuffer *buffer);
struct yukonStream *yukonStreamCreate(const char *spec, unsigned long size);
unsigned long yukonStreamStatus(struct yukonStream *stream);
-void yukonStreamPut(struct yukonStream *stream, struct yukonPacket *packet);
+void yukonStreamPut(struct yukonStream *stream, struct seomPacket *packet);
void yukonStreamDestroy(struct yukonStream *stream);
#endif /* __YUKON_STREAM__ */
View
@@ -25,6 +25,7 @@
#include <X11/Xlib.h>
#include <X11/keysym.h>
+#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glx.h>
View
@@ -126,16 +126,16 @@ void *audioThreadCallback(void *data)
return NULL;
}
- logMessage(4, "period: %u\n", period);
+ logMessage(4, "Audio capturing device is set up (period: %u)\n", period);
int count = snd_pcm_poll_descriptors_count(pcm);
struct pollfd ufds[count];
snd_pcm_poll_descriptors(pcm, ufds, count);
uint32_t header[1] = { snd_pcm_frames_to_bytes(pcm, 1) / 2 };
- struct yukonPacket *pkt = yukonPacketCreate(0x02, sizeof(header));
- memcpy(yukonPacketPayload(pkt), &header, sizeof(header));
+ struct seomPacket *pkt = seomPacketCreate(0x02, sizeof(header));
+ memcpy(seomPacketPayload(pkt), &header, sizeof(header));
yukonStreamPut(engine->stream, pkt);
for (;;) {
@@ -151,15 +151,15 @@ void *audioThreadCallback(void *data)
if (err < 0)
continue;
- struct yukonPacket *packet = yukonPacketCreate(0x03, snd_pcm_frames_to_bytes(pcm, period));
+ struct seomPacket *packet = seomPacketCreate(0x03, snd_pcm_frames_to_bytes(pcm, period));
if (packet == NULL)
continue;
snd_pcm_sframes_t delay;
snd_pcm_delay(pcm, &delay);
packet->time -= 1000000 / 48000 * delay;
- snd_pcm_sframes_t ret = snd_pcm_readi(pcm, yukonPacketPayload(packet), period);
+ snd_pcm_sframes_t ret = snd_pcm_readi(pcm, seomPacketPayload(packet), period);
if (ret < 0) {
logMessage(2, "overrun!\n");
ret = xrun(pcm, ret);
@@ -173,13 +173,13 @@ void *audioThreadCallback(void *data)
snd_pcm_drain(pcm);
snd_pcm_uframes_t left = snd_pcm_avail_update(pcm);
if (left > 0) {
- struct yukonPacket *packet = yukonPacketCreate(0x03, snd_pcm_frames_to_bytes(pcm, left));
+ struct seomPacket *packet = seomPacketCreate(0x03, snd_pcm_frames_to_bytes(pcm, left));
if (packet) {
snd_pcm_sframes_t delay;
snd_pcm_delay(pcm, &delay);
packet->time -= 1000000 / 48000 * delay;
- snd_pcm_sframes_t ret = snd_pcm_readi(pcm, yukonPacketPayload(packet), left);
+ snd_pcm_sframes_t ret = snd_pcm_readi(pcm, seomPacketPayload(packet), left);
if (ret < 0) {
logMessage(2, "overrun (%d)!\n", ret);
ret = xrun(pcm, ret);
View
@@ -26,8 +26,8 @@ struct yukonEngine *yukonEngineCreate(const char *spec, unsigned long scale, uns
pthread_create(&engine->audioThread, NULL, audioThreadCallback, engine);
uint32_t header[4] = { scale, engine->size[0] >> scale, engine->size[1] >> scale, yukonGlobal.fps };
- struct yukonPacket *packet = yukonPacketCreate(0x00, sizeof(header));
- memcpy(yukonPacketPayload(packet), &header, sizeof(header));
+ struct seomPacket *packet = seomPacketCreate(0x00, sizeof(header));
+ memcpy(seomPacketPayload(packet), &header, sizeof(header));
yukonStreamPut(engine->stream, packet);
logMessage(4, "Header %u:%u:%u:%u\n", header[0], header[1], header[2], header[3]);
@@ -61,11 +61,11 @@ void yukonEngineCapture(struct yukonEngine *engine)
lastCapture = now;
- struct yukonPacket *packet = yukonPacketCreate(0x01, engine->size[0] * engine->size[1] * 4);
+ struct seomPacket *packet = seomPacketCreate(0x01, engine->size[0] * engine->size[1] * 4);
if (packet == NULL)
return;
- glReadPixels(0, 0, engine->size[0], engine->size[1], GL_BGRA, GL_UNSIGNED_BYTE, yukonPacketPayload(packet));
+ glReadPixels(0, 0, engine->size[0], engine->size[1], GL_BGRA, GL_UNSIGNED_BYTE, seomPacketPayload(packet));
yukonStreamPut(engine->stream, packet);
}
View
@@ -1,25 +1,42 @@
#include <yukon.h>
-static struct yukonPacket packet;
-static char buffer[2500 * 2500* 4];
+void y4mWriteHeader(int fd, struct seomPacket *packet);
+void y4mWriteData(int fd, struct seomPacket *packet);
-void y4mWriteHeader(int fd, struct yukonPacket *packet, void *data, unsigned int size);
-void y4mWriteData(int fd, struct yukonPacket *packet, void *data, unsigned int size);
+void wavWriteHeader(int fd, struct seomPacket *packet);
+void wavWriteData(int fd, struct seomPacket *packet);
-void wavWriteHeader(int fd, struct yukonPacket *packet, void *data, unsigned int size);
-void wavWriteData(int fd, struct yukonPacket *packet, void *data, unsigned int size);
+struct filterStream {
+ int fileDescriptor;
+};
-uint64_t getPacket(int fd, uint8_t type)
+static unsigned long put(void *private, const struct iovec vec[], unsigned long num)
{
- if (read(fd, &packet, sizeof(struct yukonPacket)) == 0)
- return 0;
+ struct filterStream *stream = private;
+ return writev(stream->fileDescriptor, vec, num);
+}
+
+static unsigned long get(void *private, const struct iovec vec[], unsigned long num)
+{
+ struct filterStream *stream = private;
+ return readv(stream->fileDescriptor, vec, num);
+}
+
+static struct seomStreamOps ops = { put, get };
- if (packet.type == type || packet.type == type + 1)
- return read(fd, buffer, packet.size);
+struct seomPacket *getPacket(seomStream *stream, uint8_t type)
+{
+ for (;;) {
+ struct seomPacket *packet = seomStreamGet(stream);
+ if (packet == NULL)
+ return NULL;
+
+ if (packet->type == type || packet->type == type + 1)
+ return packet;
- lseek(fd, packet.size, SEEK_CUR);
- return getPacket(fd, type);
+ seomPacketDestroy(packet);
+ }
}
static int usage(char *self)
@@ -45,22 +62,28 @@ int main(int argc, char *argv[])
if (fd < 0)
return 0;
+ static struct filterStream private;
+ private.fileDescriptor = fd;
+ seomStream *stream = seomStreamCreate(&ops, &private);
+ if (stream == NULL)
+ return 0;
+
for (;;) {
- uint64_t size = getPacket(fd, type);
- if (size == 0)
+ struct seomPacket *packet = getPacket(stream, type);
+ if (packet == NULL)
break;
if (type == 0x00) {
- if (packet.type == 0x00) {
- y4mWriteHeader(1, &packet, buffer, size);
+ if (packet->type == 0x00) {
+ y4mWriteHeader(1, packet);
} else {
- y4mWriteData(1, &packet, buffer, size);
+ y4mWriteData(1, packet);
}
} else if (type == 0x02) {
- if (packet.type == 0x02) {
- wavWriteHeader(1, &packet, buffer, size);
+ if (packet->type == 0x02) {
+ wavWriteHeader(1, packet);
} else {
- wavWriteData(1, &packet, buffer, size);
+ wavWriteData(1, packet);
}
}
}
View
@@ -28,9 +28,9 @@ struct wavData {
static unsigned int bps;
static char silence[48000 * 4 * 2 * 8];
-void wavWriteHeader(int fd, struct yukonPacket *packet, void *data, unsigned int size)
+void wavWriteHeader(int fd, struct seomPacket *packet)
{
- uint32_t *sh = data;
+ uint32_t *sh = seomPacketPayload(packet);
unsigned int format = sh[0];
struct wavHeader header = { htonl(0x52494646), 0xffffffff, htonl(0x57415645) };
@@ -48,7 +48,7 @@ void wavWriteHeader(int fd, struct yukonPacket *packet, void *data, unsigned int
static uint64_t streamStart;
static uint64_t dataSize;
-void wavWriteData(int fd, struct yukonPacket *packet, void *data, unsigned int size)
+void wavWriteData(int fd, struct seomPacket *packet)
{
if (streamStart == 0)
streamStart = packet->time;
@@ -61,6 +61,6 @@ void wavWriteData(int fd, struct yukonPacket *packet, void *data, unsigned int s
dataSize += insert;
}
- write(fd, data, size);
- dataSize += size;
+ write(fd, seomPacketPayload(packet), packet->size);
+ dataSize += packet->size;
}
View
@@ -5,12 +5,12 @@ static unsigned int w, h;
static uint64_t timeStep;
static uint64_t timeNext;
-static struct yukonPacket pkt;
+static struct seomPacket pkt;
static char buffer[2500 * 2500* 4];
-void y4mWriteHeader(int fd, struct yukonPacket *packet, void *data, unsigned int size)
+void y4mWriteHeader(int fd, struct seomPacket *packet)
{
- uint32_t *sh = data;
+ uint32_t *sh = seomPacketPayload(packet);
unsigned int scale = sh[0], width = sh[1], height = sh[2], fps = sh[3];
char header[4096];
@@ -48,7 +48,7 @@ static uint64_t diff(uint64_t t1, uint64_t t2)
return t1 < t2 ? t2 - t1 : t1 - t2;
}
-void y4mWriteData(int fd, struct yukonPacket *packet, void *data, unsigned int size)
+void y4mWriteData(int fd, struct seomPacket *packet, void *data, unsigned int size)
{
if (pkt.time == 0) {
timeNext = packet->time;
@@ -60,5 +60,5 @@ void y4mWriteData(int fd, struct yukonPacket *packet, void *data, unsigned int s
}
pkt = *packet;
- memcpy(buffer, data, size);
+ memcpy(buffer, seomPacketPayload(packet), packet->size);
}
View
@@ -8,7 +8,7 @@ static unsigned long num(struct yukonBuffer *buffer)
struct yukonBuffer *yukonBufferCreate(unsigned long size)
{
- struct yukonBuffer *buffer = malloc(sizeof(struct yukonBuffer) + size * sizeof(struct yukonPacket *));
+ struct yukonBuffer *buffer = malloc(sizeof(struct yukonBuffer) + size * sizeof(struct seomPacket *));
if (buffer == NULL)
return NULL;
@@ -21,9 +21,8 @@ struct yukonBuffer *yukonBufferCreate(unsigned long size)
return buffer;
}
-void yukonBufferPut(struct yukonBuffer *buffer, struct yukonPacket *packet)
+void yukonBufferPut(struct yukonBuffer *buffer, struct seomPacket *packet)
{
-
pthread_mutex_lock(&buffer->mutex);
while (num(buffer) == buffer->size)
pthread_cond_wait(&buffer->cond, &buffer->mutex);
@@ -35,9 +34,9 @@ void yukonBufferPut(struct yukonBuffer *buffer, struct yukonPacket *packet)
pthread_cond_broadcast(&buffer->cond);
}
-struct yukonPacket *yukonBufferGet(struct yukonBuffer *buffer)
+struct seomPacket *yukonBufferGet(struct yukonBuffer *buffer)
{
- struct yukonPacket *packet = NULL;
+ struct seomPacket *packet = NULL;
pthread_mutex_lock(&buffer->mutex);
while (num(buffer) == 0)
Oops, something went wrong.

0 comments on commit c1aa027

Please sign in to comment.