public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Lars Hanisch <dvb@cinnamon-sage.de>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Andy Walls <awalls@radix.net>, linux-media@vger.kernel.org
Subject: Re: ivtv-utils/test/ps-analyzer.cpp: error in extracting SCR?
Date: Sun, 07 Feb 2010 21:36:37 +0100	[thread overview]
Message-ID: <4B6F2455.4040001@cinnamon-sage.de> (raw)
In-Reply-To: <201002040825.32062.hverkuil@xs4all.nl>

[-- Attachment #1: Type: text/plain, Size: 2562 bytes --]

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:
> On Thursday 04 February 2010 04:16:03 Andy Walls wrote:
>> On Thu, 2010-02-04 at 01:18 +0100, Lars Hanisch wrote:
>>> 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.
>>
>>>   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;
>>
>>
>> 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. :)
>>
>>>    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
>
>>
>> I did not check this one, but I would not be surprised if ps-analyzer
>> had this wrong too.
>>
>> Regards,
>> Andy
>>
>>> 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 majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>>
>


[-- Attachment #2: ps-analyzer-corrected_scr_muxrate.diff --]
[-- Type: text/plain, Size: 798 bytes --]

Index: test/ps-analyzer.cpp
===================================================================
--- test/ps-analyzer.cpp	(Revision 4152)
+++ test/ps-analyzer.cpp	(Arbeitskopie)
@@ -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);
 

  parent reply	other threads:[~2010-02-07 20:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-04  0:18 ivtv-utils/test/ps-analyzer.cpp: error in extracting SCR? Lars Hanisch
2010-02-04  3:16 ` Andy Walls
2010-02-04  7:25   ` Hans Verkuil
2010-02-04 18:50     ` Lars Hanisch
2010-02-07 20:36     ` Lars Hanisch [this message]
2010-02-07 20:53       ` Andy Walls

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B6F2455.4040001@cinnamon-sage.de \
    --to=dvb@cinnamon-sage.de \
    --cc=awalls@radix.net \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox