Skip to contentSkip to conversation

ivtv-utils/test/ps-analyzer.cpp: error in extracting SCR?

DISCUSSION Lars Hanisch 3 participants 6 messages Feb 4, 2010 – Feb 7, 2010 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

Hi,

I'm writing some code repacking the program stream that ivtv delivers
into a transport stream (BTW: is there existing code for this?). Since many players needs the PCR I would like to use the SCR of the PS and place it in the adaption field of the TS (if wikipedia [1] and my interpretation of it is correct it should be the same).

I stumbled upon the ps-analyzer.cpp in the test-directory of the
ivtv-utils (1.4.0). From line 190 to 198 the SCR and SCR extension are extracted from the PS-header. But referring to [2] the SCR extension has 9 bits, the highest 2 bits in the fifth byte after the sync bytes and the lower 7 bits in the sixth byte. The last bit is a marker bit (always 1).

So instead of

scr_ext = (hdr[4] & 0x1) << 8; scr_ext |= hdr[5];

I think it should be

scr_ext = (unsigned)(hdr[4] & 0x3) << 7; scr_ext |= (hdr[5] & 0xfe) >> 1;

And the bitrate is coded in the next 22 bits, so it should be

mux_rate = (unsigned)(hdr[6]) << 14; mux_rate |= (unsigned)(hdr[7]) << 6; mux_rate |= (unsigned)(hdr[8] & 0xfc) >> 2;

Am I correct?

Regards,
Lars.

[1] http://en.wikipedia.org/wiki/Presentation_time_stamp
[2] http://en.wikipedia.org/wiki/MPEG_program_stream

#1 lore raw
Quoted 4 lines · Lars Hanisch

Hi,

I'm writing some code repacking the program stream that ivtv delivers
into a transport stream (BTW: is there existing code for this?).

Buy a CX23418 based board. That chip's firmware can produce a TS.

I think Compro and LeadTek cards are available in Europe and are supported by the cx18 driver.

Quoted 13 lines

Since
many players needs the PCR I would like to use the SCR of the PS and place it in the adaption field of the TS (if wikipedia [1] and my interpretation of it is correct it should be the same).

I stumbled upon the ps-analyzer.cpp in the test-directory of the
ivtv-utils (1.4.0). From line 190 to 198 the SCR and SCR extension are extracted from the PS-header. But referring to [2] the SCR extension has 9 bits, the highest 2 bits in the fifth byte after the sync bytes and the lower 7 bits in the sixth byte. The last bit is a marker bit (always 1).

So instead of

Quoted 7 lines

scr_ext = (hdr[4] & 0x1) << 8;
scr_ext |= hdr[5];

I think it should be

scr_ext = (unsigned)(hdr[4] & 0x3) << 7;
scr_ext |= (hdr[5] & 0xfe) >> 1;

Given the non-authoritative MPEG-2 documents I have, yes, you appear to be correct on this.

Please keep in mind that ps-analyzer.cpp is simply a debug tool from an ivtv developer perspective. You base prodcution software off of it at your own risk. :)

Quoted 7 lines

And the bitrate is coded in the next 22 bits, so it should be

mux_rate = (unsigned)(hdr[6]) << 14;
mux_rate |= (unsigned)(hdr[7]) << 6;
mux_rate |= (unsigned)(hdr[8] & 0xfc) >> 2;

Am I correct?

I did not check this one, but I would not be surprised if ps-analyzer had this wrong too.

Regards,
Andy

Quoted 6 lines

Regards,
Lars.

[1] http://en.wikipedia.org/wiki/Presentation_time_stamp
[2] http://en.wikipedia.org/wiki/MPEG_program_stream
--

#2 lore raw
Quoted 33 lines · On Thursday 04 February 2010 04:16:03 Andy Walls wrote:
Quoted 4 lines · Lars Hanisch

Hi,

I'm writing some code repacking the program stream that ivtv delivers
into a transport stream (BTW: is there existing code for this?).

Buy a CX23418 based board. That chip's firmware can produce a TS.

I think Compro and LeadTek cards are available in Europe and are supported by the cx18 driver.

Quoted 13 lines

Since
many players needs the PCR I would like to use the SCR of the PS and place it in the adaption field of the TS (if wikipedia [1] and my interpretation of it is correct it should be the same).

I stumbled upon the ps-analyzer.cpp in the test-directory of the
ivtv-utils (1.4.0). From line 190 to 198 the SCR and SCR extension are extracted from the PS-header. But referring to [2] the SCR extension has 9 bits, the highest 2 bits in the fifth byte after the sync bytes and the lower 7 bits in the sixth byte. The last bit is a marker bit (always 1).

So instead of

Quoted 7 lines

scr_ext = (hdr[4] & 0x1) << 8;
scr_ext |= hdr[5];

I think it should be

scr_ext = (unsigned)(hdr[4] & 0x3) << 7;
scr_ext |= (hdr[5] & 0xfe) >> 1;

Quoted 14 lines

Given the non-authoritative MPEG-2 documents I have, yes, you appear to be correct on this.

Please keep in mind that ps-analyzer.cpp is simply a debug tool from an ivtv developer perspective. You base prodcution software off of it at your own risk. :)

Quoted 7 lines

And the bitrate is coded in the next 22 bits, so it should be

mux_rate = (unsigned)(hdr[6]) << 14;
mux_rate |= (unsigned)(hdr[7]) << 6;
mux_rate |= (unsigned)(hdr[8] & 0xfc) >> 2;

Am I correct?

Yes, you are correct. I miscounted the bits when I wrote this originally. Thanks for reporting this!

Regards,

Hans

Quoted 21 lines

I did not check this one, but I would not be surprised if ps-analyzer had this wrong too.

Regards,
Andy

Quoted 6 lines

Regards,
Lars.

[1] http://en.wikipedia.org/wiki/Presentation_time_stamp
[2] http://en.wikipedia.org/wiki/MPEG_program_stream
--

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
#3 lore raw

Am 04.02.2010 08:25, schrieb Hans Verkuil:

Quoted 11 lines · On Thursday 04 February 2010 04:16:03 Andy Walls wrote:
Quoted 10 lines · Lars Hanisch
Quoted 4 lines

Hi,

I'm writing some code repacking the program stream that ivtv delivers
into a transport stream (BTW: is there existing code for this?).

Buy a CX23418 based board. That chip's firmware can produce a TS.

I think Compro and LeadTek cards are available in Europe and are supported by the cx18 driver.

My PVR150 and 350 are still ok and I hope I have DVB-S-access in one
or two years... But I will keep that in mind in case I need a new card.

Quoted 24 lines
Quoted 24 lines
Quoted 22 lines

Since
many players needs the PCR I would like to use the SCR of the PS and

place it in the adaption field of the TS (if wikipedia [1] and my interpretation of it is correct it should be the same).

I stumbled upon the ps-analyzer.cpp in the test-directory of the
ivtv-utils (1.4.0). From line 190 to 198 the SCR and SCR extension are extracted from the PS-header. But referring to [2] the SCR extension has 9 bits, the highest 2 bits in the fifth byte after the sync bytes and the lower 7 bits in the sixth byte. The last bit is a marker bit (always 1).

So instead of

scr_ext = (hdr[4]& 0x1)<< 8;
scr_ext |= hdr[5];

I think it should be

scr_ext = (unsigned)(hdr[4]& 0x3)<< 7;
scr_ext |= (hdr[5]& 0xfe)>> 1;

Quoted 6 lines
Quoted 6 lines

Given the non-authoritative MPEG-2 documents I have, yes, you appear to be correct on this.

Please keep in mind that ps-analyzer.cpp is simply a debug tool from an ivtv developer perspective. You base prodcution software off of it at your own risk. :)

Of course I will. :-) I already had coded my part and was looking for
references...

Quoted 11 lines
Quoted 8 lines
Quoted 8 lines

And the bitrate is coded in the next 22 bits, so it should be

mux_rate = (unsigned)(hdr[6])<< 14;
mux_rate |= (unsigned)(hdr[7])<< 6;
mux_rate |= (unsigned)(hdr[8]& 0xfc)>> 2;

Am I correct?

Yes, you are correct. I miscounted the bits when I wrote this originally. Thanks for reporting this!

You're welcome!

Regards,
Lars.

Quoted 27 lines

Regards,

Hans

Quoted 21 lines

I did not check this one, but I would not be surprised if ps-analyzer had this wrong too.

Regards,
Andy

Quoted 6 lines

Regards,
Lars.

[1] http://en.wikipedia.org/wiki/Presentation_time_stamp
[2] http://en.wikipedia.org/wiki/MPEG_program_stream
--

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Hans Verkuil

Hi,

Just for completeness, attached is the patch against the subversion
repository at ivtvdriver.org.

Regards,
Lars.

Am 04.02.2010 08:25, schrieb Hans Verkuil:

Quoted 47 lines · On Thursday 04 February 2010 04:16:03 Andy Walls wrote:
Quoted 46 lines · Lars Hanisch
Quoted 4 lines

Hi,

I'm writing some code repacking the program stream that ivtv delivers
into a transport stream (BTW: is there existing code for this?).

Buy a CX23418 based board. That chip's firmware can produce a TS.

I think Compro and LeadTek cards are available in Europe and are supported by the cx18 driver.

Quoted 13 lines

Since
many players needs the PCR I would like to use the SCR of the PS and place it in the adaption field of the TS (if wikipedia [1] and my interpretation of it is correct it should be the same).

I stumbled upon the ps-analyzer.cpp in the test-directory of the
ivtv-utils (1.4.0). From line 190 to 198 the SCR and SCR extension are extracted from the PS-header. But referring to [2] the SCR extension has 9 bits, the highest 2 bits in the fifth byte after the sync bytes and the lower 7 bits in the sixth byte. The last bit is a marker bit (always 1).

So instead of

Quoted 7 lines

scr_ext = (hdr[4]& 0x1)<< 8;
scr_ext |= hdr[5];

I think it should be

scr_ext = (unsigned)(hdr[4]& 0x3)<< 7;
scr_ext |= (hdr[5]& 0xfe)>> 1;

Given the non-authoritative MPEG-2 documents I have, yes, you appear to be correct on this.

Please keep in mind that ps-analyzer.cpp is simply a debug tool from an ivtv developer perspective. You base prodcution software off of it at your own risk. :)

Quoted 6 lines

And the bitrate is coded in the next 22 bits, so it should be

mux_rate = (unsigned)(hdr[6])<< 14;
mux_rate |= (unsigned)(hdr[7])<< 6;
mux_rate |= (unsigned)(hdr[8]& 0xfc)>> 2;

Quoted 31 lines
Quoted 1 line
Quoted 1 line

Am I correct?

Yes, you are correct. I miscounted the bits when I wrote this originally. Thanks for reporting this!

Regards,

Hans

Quoted 21 lines

I did not check this one, but I would not be surprised if ps-analyzer had this wrong too.

Regards,
Andy

Quoted 6 lines

Regards,
Lars.

[1] http://en.wikipedia.org/wiki/Presentation_time_stamp
[2] http://en.wikipedia.org/wiki/MPEG_program_stream
--

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

ps-analyzer.cpp +5 -5
Index: test/ps-analyzer.cpp
===================================================================
@@ -194,11 +194,11 @@
 	scr |= (u64)(hdr[2] & 3) << 13;
 	scr |= (u64)hdr[3] << 5;
 	scr |= (u64)(hdr[4] & 0xf8) >> 3;
-	scr_ext = (hdr[4] & 0x1) << 8;
-	scr_ext |= hdr[5];
-	mux_rate = (hdr[6] & 0x7f) << 15;
-	mux_rate |= hdr[7] << 7;
-	mux_rate |= (hdr[8] & 0xfe) >> 1;
+	scr_ext = (unsigned)(hdr[4] & 0x3) << 7;
+	scr_ext |= (hdr[5] & 0xfe) >> 1;
+	mux_rate = (unsigned)(hdr[6]) << 14;
+	mux_rate |= (unsigned)(hdr[7]) << 6;
+	mux_rate |= (unsigned)(hdr[8] & 0xfc) >> 2;
 	if (g_verbose)
 		printf("%lld: pack scr=%lld scr_ext=%3u scr=%lld ns mux_rate=%u\n", pos, scr, scr_ext, scr2ns(scr, scr_ext), mux_rate);
 
#5 lore raw
Quoted 4 lines · Lars Hanisch

Hi,

Just for completeness, attached is the patch against the subversion
repository at ivtvdriver.org.

Thanks!

Regards,
Andy

Quoted 83 lines

Regards,
Lars.

Am 04.02.2010 08:25, schrieb Hans Verkuil:

Quoted 78 lines · On Thursday 04 February 2010 04:16:03 Andy Walls wrote:
Quoted 33 lines · Lars Hanisch
Quoted 4 lines

Hi,

I'm writing some code repacking the program stream that ivtv delivers
into a transport stream (BTW: is there existing code for this?).

Buy a CX23418 based board. That chip's firmware can produce a TS.

I think Compro and LeadTek cards are available in Europe and are supported by the cx18 driver.

Quoted 13 lines

Since
many players needs the PCR I would like to use the SCR of the PS and place it in the adaption field of the TS (if wikipedia [1] and my interpretation of it is correct it should be the same).

I stumbled upon the ps-analyzer.cpp in the test-directory of the
ivtv-utils (1.4.0). From line 190 to 198 the SCR and SCR extension are extracted from the PS-header. But referring to [2] the SCR extension has 9 bits, the highest 2 bits in the fifth byte after the sync bytes and the lower 7 bits in the sixth byte. The last bit is a marker bit (always 1).

So instead of

Quoted 7 lines

scr_ext = (hdr[4]& 0x1)<< 8;
scr_ext |= hdr[5];

I think it should be

scr_ext = (unsigned)(hdr[4]& 0x3)<< 7;
scr_ext |= (hdr[5]& 0xfe)>> 1;

Quoted 14 lines

Given the non-authoritative MPEG-2 documents I have, yes, you appear to be correct on this.

Please keep in mind that ps-analyzer.cpp is simply a debug tool from an ivtv developer perspective. You base prodcution software off of it at your own risk. :)

Quoted 7 lines

And the bitrate is coded in the next 22 bits, so it should be

mux_rate = (unsigned)(hdr[6])<< 14;
mux_rate |= (unsigned)(hdr[7])<< 6;
mux_rate |= (unsigned)(hdr[8]& 0xfc)>> 2;

Am I correct?

Yes, you are correct. I miscounted the bits when I wrote this originally. Thanks for reporting this!

Regards,

Hans

Quoted 21 lines

I did not check this one, but I would not be surprised if ps-analyzer had this wrong too.

Regards,
Andy

Quoted 6 lines

Regards,
Lars.

[1] http://en.wikipedia.org/wiki/Presentation_time_stamp
[2] http://en.wikipedia.org/wiki/MPEG_program_stream
--

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html