summaryrefslogtreecommitdiff
path: root/src/multiplexer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/multiplexer.cc')
-rw-r--r--src/multiplexer.cc106
1 files changed, 54 insertions, 52 deletions
diff --git a/src/multiplexer.cc b/src/multiplexer.cc
index 7a8b095..de6180f 100644
--- a/src/multiplexer.cc
+++ b/src/multiplexer.cc
@@ -118,18 +118,18 @@ 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));
+ unsigned long int h_u = val & 0xffffffff;
+ unsigned long int h_l = (val << 32) & 0xffffffff;
- *h_u = htonl(*h_u);
- *h_l = htonl(*h_l);
+ h_u = htonl(h_u);
+ h_l = htonl(h_l);
- if((res = Write((void*)h_l, sizeof(*h_l))) < 0) {
+ if((res = Write(&h_l, sizeof(h_l))) < 0) {
return res;
}
written += res;
- if((res = Write((void*)h_u, sizeof(*h_u))) < 0) {
+ if((res = Write(&h_u, sizeof(h_u))) < 0) {
return res;
}
written += res;
@@ -141,18 +141,18 @@ 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));
+ unsigned long int h_u = val & 0xffffffff;
+ unsigned long int h_l = (val << 32) & 0xffffffff;
- *h_u = htonl(*h_u);
- *h_l = htonl(*h_l);
+ h_u = htonl(h_u);
+ h_l = htonl(h_l);
- if((res = Write((void*)h_l, sizeof(*h_l))) < 0) {
+ if((res = Write(&h_l, sizeof(h_l))) < 0) {
return res;
}
written += res;
- if((res = Write((void*)h_u, sizeof(*h_u))) < 0) {
+ if((res = Write(&h_u, sizeof(h_u))) < 0) {
return res;
}
written += res;
@@ -275,14 +275,15 @@ bool Multiplexer::packet(StreamType type)
}
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);
- Write(*((unsigned long long int*)&header));
+ header.bits.marker_bit1 = header.bits.marker_bit2 =
+ header.bits.marker_bit3 = 1;
+ header.bits.padding = 0x2; // Must be 2
+ header.bits.stuffing_byte = 0xFF;
+ header.bits.packet_length = framesize + sizeof(ISO11172_1::packet_header) - sizeof(short);
+ header.bits.system_clock_reference1 = TIMECODE32_30(SCR);
+ header.bits.system_clock_reference2 = TIMECODE29_15(SCR);
+ header.bits.system_clock_reference3 = TIMECODE14_0(SCR);
+ Write(header.ulli);
Write(buf, framesize);
@@ -351,34 +352,35 @@ void Multiplexer::system_header()
ISO11172_1::system_header header;
- header.marker_bit1 = header.marker_bit2 = header.marker_bit3 = 1;
+ header.bits.marker_bit1 = header.bits.marker_bit2 =
+ header.bits.marker_bit3 = 1;
- header.header_length = 8 - 2 + (NUM_TYPES * 3);
+ header.bits.header_length = 8 - 2 + (NUM_TYPES * 3);
// (sizeof(header) - sizeof(header.header_length)) +
// NUM_TYPES * sizeof(ISO11172_1::stream_description);
- header.rate_bound = 3521; // FIXME: Taken from the example!
- header.audio_bound = 1; // Only 1 audio stream
- header.fixed_flag = 1; // Fixed bitrate (0 indicates vbr)
- header.CSPS_flag = 1; // Standarts compliant? (yes: see lame_set_strict_ISO in liblame_wrapper.cc)
- header.system_audio_clock_flag = 1; // FIXME: What excactly is this??
- 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
- Write(*((unsigned long long int*)&header));
+ header.bits.rate_bound = 3521; // FIXME: Taken from the example!
+ header.bits.audio_bound = 1; // Only 1 audio stream
+ header.bits.fixed_flag = 1; // Fixed bitrate (0 indicates vbr)
+ header.bits.CSPS_flag = 1; // Standarts compliant? (yes: see lame_set_strict_ISO in liblame_wrapper.cc)
+ header.bits.system_audio_clock_flag = 1; // FIXME: What excactly is this??
+ header.bits.system_video_clock_flag = 1; // FIXME: What excactly is this??
+ header.bits.video_bound = 1; // Only 1 video stream
+ header.bits.reserved_byte = 0xFF; // Must be 0xFF
+ Write(header.ulli);
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
- Write(*((unsigned long int*)&audio_stream_description));
+ audio_stream_description.bits.stream_id = 0xC0;
+ audio_stream_description.bits.market_bits = 0x3;
+ audio_stream_description.bits.STD_buffer_bound_scale = 0; // Must be 0 for audio streams
+ audio_stream_description.bits.STD_buffer_size_bound = 32; // Buffer must be 32 * 128 bytes
+ Write(audio_stream_description.uli);
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
- Write(*((unsigned long int*)&video_stream_description));
+ video_stream_description.bits.stream_id = 0xE3;
+ video_stream_description.bits.market_bits = 0x3;
+ video_stream_description.bits.STD_buffer_bound_scale = 1; // Must be 1 for video streams
+ video_stream_description.bits.STD_buffer_size_bound = 46; // Buffer must be 32 * 1024 bytes
+ Write(video_stream_description.uli);
}
/**
@@ -392,13 +394,13 @@ bool Multiplexer::pack()
ISO11172_1::pack_header header;
// Set marker bits to 1
- header.marker_bit1 =
- header.marker_bit2 =
- header.marker_bit3 =
- header.marker_bit4 =
- header.marker_bit5 = 1;
+ header.bits.marker_bit1 =
+ header.bits.marker_bit2 =
+ header.bits.marker_bit3 =
+ header.bits.marker_bit4 =
+ header.bits.marker_bit5 = 1;
- header.padding = 0x2;
+ header.bits.padding = 0x2;
unsigned int video_data_rate;
unsigned int audio_data_rate;
@@ -416,7 +418,7 @@ bool Multiplexer::pack()
PACKETS_PER_PACK, // packets_per_pack,
PACKET_SIZE);// packet_data_size)
- header.mux_rate = Rmux;
+ header.bits.mux_rate = Rmux;
//0x1B82;
SCR = ISO11172_1::SCR(SCR,
@@ -427,9 +429,9 @@ bool Multiplexer::pack()
// SCR = 0x40010003LL;
- header.system_clock_reference1 = TIMECODE32_30(SCR);
- header.system_clock_reference2 = TIMECODE29_15(SCR);
- header.system_clock_reference3 = TIMECODE14_0(SCR);
+ header.bits.system_clock_reference1 = TIMECODE32_30(SCR);
+ header.bits.system_clock_reference2 = TIMECODE29_15(SCR);
+ header.bits.system_clock_reference3 = TIMECODE14_0(SCR);
/*
info->info("timecode All: %lld, 1: %lld, 2: %lld, 3: %lld",
SCR,
@@ -438,7 +440,7 @@ bool Multiplexer::pack()
(unsigned long long int)header.system_clock_reference3
);
*/
- Write(*((unsigned long long int*)&header));
+ Write(header.ulli);
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, ...