summaryrefslogtreecommitdiff
path: root/src/multiplexer.cc
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 /src/multiplexer.cc
parent5298cdacd41efbf2ffd0282b14e401734b31d90a (diff)
*** empty log message ***R0_2_8
Diffstat (limited to 'src/multiplexer.cc')
-rw-r--r--src/multiplexer.cc115
1 files changed, 20 insertions, 95 deletions
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, ...