summaryrefslogtreecommitdiff
path: root/src/multiplexer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/multiplexer.cc')
-rw-r--r--src/multiplexer.cc135
1 files changed, 119 insertions, 16 deletions
diff --git a/src/multiplexer.cc b/src/multiplexer.cc
index 0b54bf8..096ff86 100644
--- a/src/multiplexer.cc
+++ b/src/multiplexer.cc
@@ -68,12 +68,13 @@ static double picture_rate_index[16] = {
RESERVED, RESERVED, RESERVED, RESERVED, RESERVED, RESERVED, RESERVED
};
*/
-Multiplexer::Multiplexer(File *f, Info *i, volatile bool *r,
+Multiplexer::Multiplexer(File *f, Multicast *m, Info *i, volatile bool *r,
ThreadSafeQueuePriority *video_q,
ThreadSafeQueuePriority *audio_q)
{
running = r;
file = f;
+ multicast = m;
info = i;
frame[TYPE_VIDEO] = NULL;
@@ -98,10 +99,112 @@ Multiplexer::~Multiplexer()
{
}
+int Multiplexer::Write(void* data, int size)
+{
+ int ret;
+
+ multicast->Write(data, size);
+ ret = file->Write(data, size);
+
+ return ret;
+}
+
+int Multiplexer::Write(char* data, int size)
+{
+ return Write((void*)data, size);
+}
+
+int Multiplexer::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 Multiplexer::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 Multiplexer::Write(long int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int Multiplexer::Write(unsigned long int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int Multiplexer::Write(int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int Multiplexer::Write(unsigned int val)
+{
+ val = htonl(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int Multiplexer::Write(short int val)
+{
+ val = htons(val);
+
+ return Write((char*)&val, sizeof(val));
+}
+
+int Multiplexer::Write(unsigned short int val)
+{
+ val = htons(val);
+
+ return Write((char*)&val, sizeof(val));
+}
Frame *Multiplexer::getFrame(StreamType type)
{
- info->info("Get %s Frame", type==TYPE_AUDIO?"Audio\0":"Video\0");
+ // info->info("Get %s Frame", type==TYPE_AUDIO?"Audio\0":"Video\0");
read[type] = 0;
@@ -155,13 +258,13 @@ bool Multiplexer::packet(StreamType type)
unsigned short int framesize = read_stream(buf, PACKET_SIZE, type);
- file->Write((void*)ISO11172_1::packet_start_code_prefix, SIZEOF(ISO11172_1::packet_start_code_prefix));
+ Write((void*)ISO11172_1::packet_start_code_prefix, SIZEOF(ISO11172_1::packet_start_code_prefix));
switch(type) {
case TYPE_VIDEO:
- file->Write((void*)ISO11172_1::stream_id_video1, SIZEOF(ISO11172_1::stream_id_video1));
+ Write((void*)ISO11172_1::stream_id_video1, SIZEOF(ISO11172_1::stream_id_video1));
break;
case TYPE_AUDIO:
- file->Write((void*)ISO11172_1::stream_id_audio1, SIZEOF(ISO11172_1::stream_id_audio1));
+ Write((void*)ISO11172_1::stream_id_audio1, SIZEOF(ISO11172_1::stream_id_audio1));
break;
}
@@ -173,9 +276,9 @@ bool Multiplexer::packet(StreamType type)
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));
+ Write(*((unsigned long long int*)&header));
- file->Write(buf, framesize);
+ Write(buf, framesize);
if(framesize != PACKET_SIZE) return false;
@@ -229,7 +332,7 @@ void Multiplexer::system_header()
// info->info("\t\t[System Header]");
// system_header_start_code (32 bits)
- file->Write((void*)ISO11172_1::system_header_start_code, SIZEOF(ISO11172_1::system_header_start_code));
+ Write((void*)ISO11172_1::system_header_start_code, SIZEOF(ISO11172_1::system_header_start_code));
ISO11172_1::system_header header;
@@ -246,21 +349,21 @@ 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
- file->Write(*((unsigned long long int*)&header));
+ Write(*((unsigned long long int*)&header));
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
- file->Write(*((unsigned long int*)&audio_stream_description));
+ 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
- file->Write(*((unsigned long int*)&video_stream_description));
+ Write(*((unsigned long int*)&video_stream_description));
}
/**
@@ -270,7 +373,7 @@ bool Multiplexer::pack()
{
// info->info("\t[Pack");
- file->Write((void*)ISO11172_1::pack_start_code, SIZEOF(ISO11172_1::pack_start_code));
+ Write((void*)ISO11172_1::pack_start_code, SIZEOF(ISO11172_1::pack_start_code));
ISO11172_1::pack_header header;
// Set marker bits to 1
@@ -320,7 +423,7 @@ bool Multiplexer::pack()
(unsigned long long int)header.system_clock_reference3
);
*/
- file->Write(*((unsigned long long int*)&header));
+ 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, ...
@@ -345,7 +448,7 @@ void Multiplexer::iso11172_stream()
// info->info("]");
// info->info("[iso11172_end_code]");
- file->Write((void*)ISO11172_1::end_code, SIZEOF(ISO11172_1::end_code));
+ Write((void*)ISO11172_1::end_code, SIZEOF(ISO11172_1::end_code));
/*
info->info("false && false = %d", false && false);
@@ -354,7 +457,7 @@ void Multiplexer::iso11172_stream()
*/
}
-//#define BYPASS TYPE_VIDEO
+#define BYPASS TYPE_VIDEO
//#define BYPASS TYPE_AUDIO
void Multiplexer::multiplex()
{
@@ -365,7 +468,7 @@ void Multiplexer::multiplex()
do {
frmsz = read_stream(buf, sizeof(buf), BYPASS);
info->info("Wrote %d bytes", frmsz);
- file->Write(buf, frmsz);
+ Write(buf, frmsz);
} while(frmsz == sizeof(buf));
return;