summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2005-09-20 19:39:49 +0000
committerdeva <deva>2005-09-20 19:39:49 +0000
commit48b768db44cb9e00adfead71b973074685cec417 (patch)
treee606f6f93b5fee42335b6f4f3cfaf7b3dc487cae
parent5298cdacd41efbf2ffd0282b14e401734b31d90a (diff)
*** empty log message ***R0_2_8
-rw-r--r--src/Makefile.am2
-rw-r--r--src/audio_encoder.cc127
-rw-r--r--src/audio_encoder.h69
-rw-r--r--src/dvfile.cc9
-rw-r--r--src/file.cc116
-rw-r--r--src/file.h10
-rw-r--r--src/info_simple.cc94
-rw-r--r--src/info_simple.h45
-rw-r--r--src/iso11172-1.h12
-rw-r--r--src/liblame_wrapper.cc19
-rw-r--r--src/liblame_wrapper.h2
-rw-r--r--src/mov_encoder.cc7
-rw-r--r--src/mov_encoder_thread.cc65
-rw-r--r--src/multiplexer.cc115
-rw-r--r--src/server.cc4
-rw-r--r--src/util.cc11
-rw-r--r--src/util.h2
17 files changed, 542 insertions, 167 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 38bc2d5..c7e6a7d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,6 +22,7 @@ miav_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \
info.cc \
info_console.cc \
info_gui.cc \
+ info_simple.cc \
jpeg_mem_dest.cc \
libfame_wrapper.cc \
liblame_wrapper.cc \
@@ -63,6 +64,7 @@ EXTRA_DIST = \
info.h \
info_console.h \
info_gui.h \
+ info_simple.h \
iso11172-1.h \
iso11172-2.h \
iso11172-3.h \
diff --git a/src/audio_encoder.cc b/src/audio_encoder.cc
new file mode 100644
index 0000000..6bebe0c
--- /dev/null
+++ b/src/audio_encoder.cc
@@ -0,0 +1,127 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * audio_encoder.cc
+ *
+ * Sat Sep 17 18:38:45 CEST 2005
+ * Copyright 2005 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MIaV is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+#include "audio_encoder.h"
+#include "util.h"
+
+AudioEncoder::AudioEncoder(FramePriorityQueue *in, pthread_mutex_t *in_mutex, sem_t *in_sem,
+ FramePriorityQueue *out, pthread_mutex_t *out_mutex, sem_t *out_sem,
+ Info *i)
+{
+ info = i;
+ info->info("AudioEncoder");
+
+ running = true;
+
+ // Queues
+ inputqueue = in;
+ outputqueue = out;
+
+ // Queue mutexes
+ input_mutex = in_mutex;
+ output_mutex = out_mutex;
+
+ input_sem = in_sem;
+ output_sem = out_sem;
+
+ frame_number = 0;
+}
+
+AudioEncoder::~AudioEncoder()
+{
+}
+
+void AudioEncoder::thread_main()
+{
+ info->info("AudioEncoder::run");
+
+ unsigned int queuesize = 0;
+
+ // Run with slightly lower priority than MovEncoderWriter
+ nice(2);
+
+ Frame *in_frame = NULL;
+ Frame *out_frame = NULL;
+ Frame *tmpframe;
+
+ LibLAMEWrapper lame(info);
+
+ while(running) {
+ sem_wait(input_sem);
+
+ // If no frame is in the buffer, get one from the queue
+ while( in_frame == NULL ) {
+
+ // sem_wait(input_sem);
+
+ // Lock output mutex
+ pthread_mutex_lock( input_mutex );
+ tmpframe = inputqueue->top();
+
+ if(tmpframe && tmpframe->number == frame_number) {
+ inputqueue->pop();
+ queuesize = inputqueue->size();
+ in_frame = tmpframe;
+ frame_number++;
+ }
+
+ pthread_mutex_unlock( input_mutex );
+ // Unlock output mutex
+
+ sleep_1_frame();
+ }
+
+ // Check for end of stream
+ if(in_frame->endOfFrameStream == true) {
+ info->info("endOfFrameStream in AudioEncoder");
+ running = false;
+ out_frame = lame.close();
+ } else {
+ // Encode audio
+ out_frame = lame.encode(in_frame);
+ }
+ out_frame->number = in_frame->number;
+ out_frame->endOfFrameStream = in_frame->endOfFrameStream;
+
+ delete in_frame;
+ in_frame = NULL;
+
+ // Lock output mutex
+ pthread_mutex_lock(output_mutex);
+ outputqueue->push(out_frame);
+ pthread_mutex_unlock(output_mutex);
+ // Unlock output mutex
+
+ // Kick multiplexer (audio)
+ sem_post(output_sem);
+ }
+
+ // Kick multiplexer (audio)
+ sem_post(output_sem);
+
+ info->info("AudioEncoder::stop");
+}
diff --git a/src/audio_encoder.h b/src/audio_encoder.h
new file mode 100644
index 0000000..b15ce45
--- /dev/null
+++ b/src/audio_encoder.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * audio_encoder.h
+ *
+ * Sat Sep 17 18:38:45 CEST 2005
+ * Copyright 2005 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MIaV is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+#ifndef __MIAV_AUDIO_ENCODER_H__
+#define __MIAV_AUDIO_ENCODER_H__
+
+#include "frame.h"
+#include "util.h"
+
+#include "thread.h"
+#include <pthread.h>
+
+#include "info.h"
+
+#include "liblame_wrapper.h"
+
+class AudioEncoder : public Thread {
+public:
+ AudioEncoder(FramePriorityQueue *in, pthread_mutex_t *in_mutex, sem_t *in_sem,
+ FramePriorityQueue *out, pthread_mutex_t *out_mutex, sem_t *out_sem,
+ Info *info);
+ ~AudioEncoder();
+
+ void thread_main();
+
+ volatile bool running;
+
+private:
+ unsigned int frame_number;
+
+ Info *info;
+
+ // Input/Output queues
+ FramePriorityQueue *inputqueue;
+ FramePriorityQueue *outputqueue;
+ pthread_mutex_t *input_mutex;
+ pthread_mutex_t *output_mutex;
+
+ //thread stuff
+ sem_t *input_sem;
+ sem_t *output_sem;
+};
+
+
+#endif/*__MIAV_AUDIO_ENCODER_H__*/
diff --git a/src/dvfile.cc b/src/dvfile.cc
index a0dccf3..7eab867 100644
--- a/src/dvfile.cc
+++ b/src/dvfile.cc
@@ -35,6 +35,7 @@ dvfile::dvfile(Info* i)
{
info = i;
fp = fopen(TEST_MOVIE, "r");
+ if(!fp) info->error("Couldn't open %s for reading.", TEST_MOVIE);
}
dvfile::~dvfile()
@@ -51,8 +52,12 @@ unsigned char *dvfile::readFrame()
ts.tv_nsec = 1000000000L / 25L; // 1/25s
nanosleep(&ts, NULL);
- while(fread(frame, DVPACKAGE_SIZE, 1, fp) == 0) {
- fseek(fp, 0L, SEEK_SET);
+ if(fp) {
+ while(fread(frame, DVPACKAGE_SIZE, 1, fp) == 0) {
+ fseek(fp, 0L, SEEK_SET);
+ }
+ } else {
+ memset(frame, 0, sizeof(frame));
}
return frame;
diff --git a/src/file.cc b/src/file.cc
index 50ed3f9..9188e6e 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -33,6 +33,9 @@
#include <string.h>
#include <unistd.h>
+// For ntoh*
+#include <netinet/in.h>
+
#include <stdlib.h>
File::File(char *fn, char* ext, Info *i)
@@ -124,6 +127,99 @@ int File::Write(void* data, int size)
return w;
}
+int File::Write(char* data, int size)
+{
+ return Write((void*)data, size);
+}
+
+int File::Write(unsigned long long int val)
+{
+ int res;
+ int written = 0;
+ unsigned long int *h_u = (unsigned long int *)&val;
+ unsigned long int *h_l = (unsigned long int *)(((char*)&val) + sizeof(unsigned long int));
+
+ *h_u = htonl(*h_u);
+ *h_l = htonl(*h_l);
+
+ if((res = Write((void*)h_l, sizeof(*h_l))) < 0) {
+ return res;
+ }
+ written += res;
+
+ if((res = Write((void*)h_u, sizeof(*h_u))) < 0) {
+ return res;
+ }
+ written += res;
+
+ return written;
+}
+
+int File::Write(long long int val)
+{
+ int res;
+ int written = 0;
+ unsigned long int *h_u = (unsigned long int *)&val;
+ unsigned long int *h_l = (unsigned long int *)(((char*)&val) + sizeof(unsigned long int));
+
+ *h_u = htonl(*h_u);
+ *h_l = htonl(*h_l);
+
+ if((res = Write((void*)h_l, sizeof(*h_l))) < 0) {
+ return res;
+ }
+ written += res;
+
+ if((res = Write((void*)h_u, sizeof(*h_u))) < 0) {
+ return res;
+ }
+ written += res;
+
+ return written;
+}
+
+int File::Write(long int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int File::Write(unsigned long int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int File::Write(int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int File::Write(unsigned int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int File::Write(short int val)
+{
+ val = htons(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int File::Write(unsigned short int val)
+{
+ val = htons(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
int File::createPath(char* path)
{
// struct stat stats;
@@ -148,3 +244,23 @@ int File::createPath(char* path)
return 0;
}
+
+#ifdef __TEST_FILE
+#include "info_simple.h"
+
+int main(int argc, char *argv[]) {
+ if(argc < 3) {
+ fprintf(stderr, "usage:\n\ttest_file [filename] [extension]\n");
+ return 1;
+ }
+
+
+ InfoSimple info;
+ File file(argv[1], argv[2], &info);
+
+ unsigned int val = 0x01234567;
+ file.Write(val);
+
+}
+
+#endif/* __TEST_FILE*/
diff --git a/src/file.h b/src/file.h
index c7f01c0..561a39f 100644
--- a/src/file.h
+++ b/src/file.h
@@ -40,6 +40,16 @@ public:
~File();
int Write(void* data, int size);
+ int Write(char* data, int size);
+
+ int Write(unsigned long long int val);
+ int Write(long long int val);
+ int Write(long int val);
+ int Write(unsigned long int val);
+ int Write(int val);
+ int Write(unsigned int val);
+ int Write(short int val);
+ int Write(unsigned short int val);
private:
Info* info;
diff --git a/src/info_simple.cc b/src/info_simple.cc
new file mode 100644
index 0000000..a3db393
--- /dev/null
+++ b/src/info_simple.cc
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * info_simple.cc
+ *
+ * Tue Sep 20 17:00:25 CEST 2005
+ * Copyright 2005 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MIaV is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+#include "info_simple.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+
+InfoSimple::InfoSimple(): Info()
+{
+}
+
+InfoSimple::~InfoSimple()
+{
+ pthread_mutex_destroy(&mutex);
+}
+
+void InfoSimple::error(char *fmt, ...)
+{
+ char buf[1024];
+
+ pthread_mutex_lock(&mutex);
+ // Beginning of safezone
+
+ va_list argp;
+ va_start(argp, fmt);
+ vsprintf(buf, fmt, argp);
+ va_end(argp);
+
+ // End of safezone
+ pthread_mutex_unlock(&mutex);
+
+ fprintf(stderr, "Error: %s\n", buf);
+}
+
+void InfoSimple::warn(char *fmt, ...)
+{
+ char buf[1024];
+
+ pthread_mutex_lock(&mutex);
+ // Beginning of safezone
+
+ va_list argp;
+ va_start(argp, fmt);
+ vsprintf(buf, fmt, argp);
+ va_end(argp);
+
+ // End of safezone
+ pthread_mutex_unlock(&mutex);
+
+ fprintf(stderr, "Warning: %s\n", buf);
+}
+
+void InfoSimple::info(char *fmt, ...)
+{
+ char buf[1024];
+
+ pthread_mutex_lock(&mutex);
+ // Beginning of safezone
+
+ va_list argp;
+ va_start(argp, fmt);
+ vsprintf(buf, fmt, argp);
+ va_end(argp);
+
+ // End of safezone
+ pthread_mutex_unlock(&mutex);
+
+ fprintf(stderr, "Info: %s\n", buf);
+}
diff --git a/src/info_simple.h b/src/info_simple.h
new file mode 100644
index 0000000..302a371
--- /dev/null
+++ b/src/info_simple.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * info_simple.h
+ *
+ * Tue Sep 20 17:00:25 CEST 2005
+ * Copyright 2005 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MIaV is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+#ifndef __MIAV_INFO_SIMPLE_H__
+#define __MIAV_INFO_SIMPLE_H__
+
+#include "info.h"
+
+class InfoSimple: public Info {
+public:
+ InfoSimple();
+ ~InfoSimple();
+
+ void error(char* fmt, ...);
+ void warn(char* fmt, ...);
+ void info(char* fmt, ...);
+
+private:
+};
+
+#endif/*__MIAV_INFO_SIMPLE_H__*/
diff --git a/src/iso11172-1.h b/src/iso11172-1.h
index 6dda687..ee8f408 100644
--- a/src/iso11172-1.h
+++ b/src/iso11172-1.h
@@ -42,6 +42,18 @@ namespace ISO11172_1 {
////////////////////////////////////////////////////
// 64 bits (8 bytes)
typedef struct {
+ unsigned long long int marker_bit3:1;
+ unsigned long long int system_clock_reference3:15;
+ unsigned long long int marker_bit2:1;
+ unsigned long long int system_clock_reference2:15;
+ unsigned long long int marker_bit1:1;
+ unsigned long long int system_clock_reference1:3;
+ unsigned long long int padding:4;
+ unsigned long long int stuffing_byte:8;
+ unsigned long long int packet_length:16;
+ } packet_header;
+
+ typedef struct {
unsigned long long int marker_bit5:1;
unsigned long long int mux_rate:22;
unsigned long long int marker_bit4:1;
diff --git a/src/liblame_wrapper.cc b/src/liblame_wrapper.cc
index c72c2dc..b29acf9 100644
--- a/src/liblame_wrapper.cc
+++ b/src/liblame_wrapper.cc
@@ -94,22 +94,27 @@ LibLAMEWrapper::~LibLAMEWrapper()
Frame *LibLAMEWrapper::close(Frame *oldframe)
{
- Frame *frame = new Frame(NULL, oldframe->size + 7200);
- frame->number = oldframe->number;
+ Frame *frame;
+ unsigned int offset = 0;
- memcpy(frame->data, oldframe->data, oldframe->size);
+ frame = new Frame(NULL, (int)(1.25 * SAMPLES + 7200) * 2); // Big enough to hold two frames
+
+ if(oldframe) {
+ offset = oldframe->size;
+ frame->number = oldframe->number;
+ memcpy(frame->data, oldframe->data, oldframe->size);
+ delete oldframe;
+ }
int flush;
- flush = lame_encode_finish(gfp, frame->data + oldframe->size, 7200);
+ flush = lame_encode_finish(gfp, frame->data + offset, 7200);
- frame->size = oldframe->size + flush;
+ frame->size = offset + flush;
calc_bitrate += flush;
frame->bitrate = (unsigned int)((double)calc_bitrate / (double)(frame_number)) * 25;
- delete oldframe;
-
return frame;
}
diff --git a/src/liblame_wrapper.h b/src/liblame_wrapper.h
index cf8e688..43518c8 100644
--- a/src/liblame_wrapper.h
+++ b/src/liblame_wrapper.h
@@ -52,7 +52,7 @@ public:
Frame *encode(Frame *dvframe);
- Frame *close(Frame *dvframe);
+ Frame *close(Frame *dvframe = NULL);
private:
unsigned long long calc_bitrate;
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc
index 3d30bbb..209362b 100644
--- a/src/mov_encoder.cc
+++ b/src/mov_encoder.cc
@@ -154,12 +154,7 @@ void MovEncoder::thread_main()
delete item;
item = NULL;
- /*
- test++;
- if(test % (25 * 24) == 0)
- info->info("Input pool size: %d, video output pool size: %d, audio output pool size: %d",
- insize, v_outsize, a_outsize);
- */
+
// Kick reader
sem_post(read_sem);
}
diff --git a/src/mov_encoder_thread.cc b/src/mov_encoder_thread.cc
index 59e3c84..dab308d 100644
--- a/src/mov_encoder_thread.cc
+++ b/src/mov_encoder_thread.cc
@@ -93,7 +93,7 @@ MovEncoderThread::MovEncoderThread(const char *cpr, Info *i)
frame_number = 0;
}
-#include <unistd.h>
+//#include <unistd.h>
MovEncoderThread::~MovEncoderThread()
{
info->info("~MovEncoderThread");
@@ -123,56 +123,6 @@ MovEncoderThread::~MovEncoderThread()
info->info("Deleted the writer");
- /*
- // These should not be deleted here... its done elsewhere.
- // inputqueue = NULL;
-
- // sem_post(&video_out_sem);
- // sem_post(&audio_out_sem);
-
- // Tell the encoding threads to stop.
- for(int cnt = 0; cnt < threads; cnt++) {
- encs[cnt]->running = false;
- }
-
- // Kick them to initiate the exit.
- for(int cnt = 0; cnt < threads; cnt++) {
- sem_post(&in_sem);
- }
-
- // They should be exited now, so we can delete them.
- for(int cnt = 0; cnt < threads; cnt++) {
- // Wait for it to stop
- encs[cnt]->wait_stop();
- // Delete it
- delete encs[cnt];
- }
-
- // Tell the audio encoder to stop
- audioenc->running = false;
-
- // Kick it to make it stop.
- sem_post(&audio_in_sem);
-
- // Wait for it to stop.
- audioenc->wait_stop();
-
- // delete the audio encoder
- delete audioenc;
-
- // Tell the writer to stop
- writer->running = false;
-
- // Kick it to make it stop.
- sem_post(&video_out_sem);
- sem_post(&audio_out_sem);
-
- // Wait for it to stop.
- writer->wait_stop();
-
- // delete the writer (end thereby close the file)
- delete writer;
- */
// Destroy the semaphores.
sem_destroy(&in_sem);
sem_destroy(&video_out_sem);
@@ -180,12 +130,21 @@ MovEncoderThread::~MovEncoderThread()
sem_destroy(&audio_out_sem);
sem_destroy(&read_sem);
-
- info->info("MovEncoderThread done deinitializing.");
+ info->info("~MovEncoderThread::done");
}
+static int output = 0;
void MovEncoderThread::encode(Frame* frame)
{
+ if(output % 250 == 0) // 25 * 24
+ info->info("inputqueue: %d\tvideo_outputqueue: %d\taudio_inputqueue: %d\taudio_outputqueue: %d.",
+ inputqueue->size(),
+ video_outputqueue->size(),
+ audio_inputqueue->size(),
+ audio_outputqueue->size());
+ output++;
+
+
if(frame == NULL) {
info->info("MovEncoderThread::encode - NULL frame detected.");
// Terminate
diff --git a/src/multiplexer.cc b/src/multiplexer.cc
index 7f80345..d2aecfc 100644
--- a/src/multiplexer.cc
+++ b/src/multiplexer.cc
@@ -35,6 +35,12 @@
#define SIZEOF(x) (sizeof(x)-1)
+#define MASK3 0x7
+#define MASK15 0x7FFF
+#define TIMECODE32_30(x) ((x >> 30) & MASK3 )
+#define TIMECODE29_15(x) ((x >> 15) & MASK15)
+#define TIMECODE14_0(x) ((x >> 0) & MASK15)
+
// Audio index lists
/*
static unsigned int frequency_index[4] = {44100, 48000, 32000, 0};
@@ -109,7 +115,6 @@ Frame *Multiplexer::getFrame(StreamType type)
Frame *frame = NULL;
sem_wait(sem[type]);
- //if(*running) sem_wait(sem[type]);
while( frame == NULL ) {
// Lock output mutex
@@ -126,7 +131,7 @@ Frame *Multiplexer::getFrame(StreamType type)
pthread_mutex_unlock( mutex[type] );
// Unlock output mutex
- sleep_1_frame();
+ sleep_0_2_frame();
}
return frame;
}
@@ -188,12 +193,15 @@ bool Multiplexer::packet(StreamType type)
break;
}
- unsigned short int hton_framesize = framesize + 1; // Need space for dims too!
- hton_framesize = htons(hton_framesize);
- file->Write((char*)&hton_framesize, sizeof(hton_framesize));
-
- char dims[] = "\x0F";
- file->Write(dims, 1);
+ ISO11172_1::packet_header header;
+ header.marker_bit1 = header.marker_bit2 = header.marker_bit3 = 1;
+ header.padding = 0x2; // Must be 2
+ header.stuffing_byte = 0xFF;
+ header.packet_length = framesize + sizeof(ISO11172_1::packet_header) - sizeof(short);
+ header.system_clock_reference1 = TIMECODE32_30(SCR);
+ header.system_clock_reference2 = TIMECODE29_15(SCR);
+ header.system_clock_reference3 = TIMECODE14_0(SCR);
+ file->Write(*((unsigned long long int*)&header));
file->Write(buf, framesize);
@@ -252,8 +260,6 @@ void Multiplexer::system_header()
file->Write((void*)ISO11172_1::system_header_start_code, SIZEOF(ISO11172_1::system_header_start_code));
ISO11172_1::system_header header;
- unsigned long int *h_u = (unsigned long int *)&header;
- unsigned long int *h_l = (unsigned long int *)(((char*)&header) + sizeof(unsigned int));
header.marker_bit1 = header.marker_bit2 = header.marker_bit3 = 1;
@@ -268,97 +274,23 @@ void Multiplexer::system_header()
header.system_video_clock_flag = 1; // FIXME: What excactly is this??
header.video_bound = 1; // Only 1 video stream
header.reserved_byte = 0xFF; // Must be 0xFF
-
- *h_u = htonl(*h_u);
- *h_l = htonl(*h_l);
-
- file->Write((char*)h_l, sizeof(*h_l));
- file->Write((char*)h_u, sizeof(*h_u));
+ file->Write(*((unsigned long long int*)&header));
- unsigned int *d;
-
ISO11172_1::stream_description audio_stream_description;
audio_stream_description.stream_id = 0xC0;
audio_stream_description.market_bits = 0x3;
audio_stream_description.STD_buffer_bound_scale = 0; // Must be 0 for audio streams
audio_stream_description.STD_buffer_size_bound = 32; // Buffer must be 32 * 128 bytes
-
- d = (unsigned int*)&audio_stream_description;
- *d = htonl(*d);
- file->Write((char*)d, sizeof(*d));
+ file->Write(*((unsigned long int*)&audio_stream_description));
ISO11172_1::stream_description video_stream_description;
video_stream_description.stream_id = 0xE3;
video_stream_description.market_bits = 0x3;
video_stream_description.STD_buffer_bound_scale = 1; // Must be 1 for video streams
video_stream_description.STD_buffer_size_bound = 46; // Buffer must be 32 * 1024 bytes
-
- d = (unsigned int*)&video_stream_description;
- *d = htonl(*d);
- file->Write((char*)d, sizeof(*d));
-
- /* // old code!
- // header_length (16 bits)
- char system_header_length[] = "\x00\x0C";
- file->Write(system_header_length, SIZEOF(system_header_length));
-
- // marker_bit (1 bit) \.
- // rate_bound (22 bits) ) (24 bits)
- // marker_bit (1 bit) /
- char rate_bound[] = "\x80\x1B\x83";
- file->Write(rate_bound, SIZEOF(rate_bound));
-
- // audio_bound (6 bits) \.
- // fixed_flag (1 bit) ) (8 bits)
- // CSPS_flag (1 bit) /
- char audio_bound[] = "\x06"; // One audio stream, fixed bitrate and not iso costraint compliant
- file->Write(audio_bound, SIZEOF(audio_bound));
-
- // system_audio_lock_flag (1 bit) \.
- // system_video_lock_flag (1 bit) \.
- // marker_bit (1 bit) ) (8 bits)
- // video_bound (5 bits) _/
- char video_bound[] = "\x21"; // Audio and Video are not locked and there are only one video stream
- file->Write(video_bound, SIZEOF(video_bound));
-
- // reserved_byte (8 bit)
- char reserved_byte[] = "\xFF";
- file->Write(reserved_byte, SIZEOF(reserved_byte));
- */
-
- /*
- { // Audio
- // stream_id (8 bit)
- char stream_id[] = "\xC0";
- file->Write(stream_id, SIZEOF(stream_id));
-
- // '11' (2 bits) \.
- // STD_buffer_bound_scale (1 bit) ) (24 bits)
- // STD_buffer_size_bound (13 bits) /
- char reserved_byte[] = "\xC0\x20";
- file->Write(reserved_byte, SIZEOF(reserved_byte));
- }
-
- { // Video
- // stream_id (8 bit)
- char stream_id[] = "\xE3";
- file->Write(stream_id, SIZEOF(stream_id));
-
- // '11' (2 bits) \.
- // STD_buffer_bound_scale (1 bit) ) (24 bits)
- // STD_buffer_size_bound (13 bits) /
- char reserved_byte[] = "\xE0\x2E";
- file->Write(reserved_byte, SIZEOF(reserved_byte));
- }
- */
+ file->Write(*((unsigned long int*)&video_stream_description));
}
-#define MASK3 0x7
-#define MASK15 0x7FFF
-#define TIMECODE32_30(x) ((x >> 30) & MASK3 )
-#define TIMECODE29_15(x) ((x >> 15) & MASK15)
-#define TIMECODE14_0(x) ((x >> 0) & MASK15)
-
/**
* Create and write a pack
*/
@@ -416,14 +348,7 @@ bool Multiplexer::pack()
(unsigned long long int)header.system_clock_reference3
);
*/
- unsigned int *hton_header_u = (unsigned int *)&header;
- unsigned int *hton_header_l = (unsigned int *)(((char*)&header) + sizeof(unsigned int));
-
- *hton_header_l = htonl(*hton_header_l);
- *hton_header_u = htonl(*hton_header_u);
-
- file->Write((char*)hton_header_u, sizeof(*hton_header_u));
- file->Write((char*)hton_header_l, sizeof(*hton_header_l));
+ file->Write(*((unsigned long long int*)&header));
if(write_system_header % SYSTEM_HEADER_FREQUENCY == 0) system_header();
// Count this up here, we want a system header in pack 0, 5, ... NOT 4, 9, ...
diff --git a/src/server.cc b/src/server.cc
index 6d4d26b..4d556fc 100644
--- a/src/server.cc
+++ b/src/server.cc
@@ -68,6 +68,7 @@ void newConnection(Socket *socket, Info *info)
frame = new Frame(NULL, DVPACKAGE_SIZE);
+ info->info("CONNECTION OPENED");
info->info("New connection (%s)", inet_ntoa(socket->socketaddr.sin_addr));
Network network = Network(socket, info);
@@ -125,6 +126,5 @@ void newConnection(Socket *socket, Info *info)
if(enc) delete enc;
- info->info("Connection closed");
-
+ info->info("CONNECTION CLOSED");
}
diff --git a/src/util.cc b/src/util.cc
index b9d57ad..11f1402 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -82,3 +82,14 @@ void sleep_1_frame()
ts.tv_nsec = 1000000000L / 25L; // 1000ms / 25
nanosleep(&ts, NULL);
}
+
+void sleep_0_2_frame()
+{
+ // Sleep 1/25th of a second
+
+ struct timespec ts;
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 8000000L;//1000000000L / 25L * 0.2; // 1000ms / 25
+ nanosleep(&ts, NULL);
+}
diff --git a/src/util.h b/src/util.h
index 39ded7f..ef21e06 100644
--- a/src/util.h
+++ b/src/util.h
@@ -46,7 +46,7 @@ void *xmalloc(size_t s);
void *xrealloc(void *b, size_t s);
void sleep_1_frame();
-
+void sleep_0_2_frame();
//#ifdef __cplusplus
//}
//#endif