Thursday, December 31, 2009

PH61153 video selector switch disassembly

Disassembly Instructions
  1. Remove the silver front. It is only held by clips. Push inwards on the black part near the silver while pulling the silver part away. Start where it's easiest and go from there. You can put folded up paper in the gap to keep it open. The front will remain attached by cables.
  2. Separate the black parts of the case. Once the front is off, these clips are obvious.
  3. Unplug the cables going to the front from the main circuit board.
  4. Unscrew the small circuit board for the front input, and unplug its cable from the main board.
  5. Unscrew the screws holding the main board and the screws holding RCA connectors to the back. Remove the main board


The top of the main board shows the through-hole components and the back of the RCA jack circuit board. The socketed chip is a EM78P156EL microcontroller.

The bottom shows the surface mount components. The chips are 4000-series CMOS. The three along the bottom are 4052L. Each contains two four-channel analog multiplexers. The chip above them is an HEF4053B. It contains three two-channel analog multiplexers.

Here is the rest of the device. Note how except for the RF modulator, there's no shielding. Even the video signal from the front panel connects via ordinary wires. Nevertheless, the switch does not seem to degrade video quality.

The Story

I just got a PH61153 video selector switch. It has four inputs, supports composite and S-video and stereo audio and has an RF modulator. The best part is that it can automatically switch to the highest priority input which has a video signal, and so I can basically hide it and forget about it.

I got it from XSCargo. They were the only local store that had it in stock, and they certainly had what seemed like a good price ($19.95). Unfortunately, the low price only reflected the low quality. First I noticed that that Philips wasn't mentioned anywhere. Then I noticed that most of the them were badly scratched and scuffed, and one had something rattling around inside. Finally, when I bought one and brought it home, I found that one of the inputs didn't work. The switch never auto-switched to the first input, and if I manually switched to it I got no composite video or audio.

I didn't like the idea of going back to XSCargo. It was a long drive, and the replacement could again have some issue. At this point, I didn't want to open up the switch and so I first measured resistance at the inputs. Unlike the other inputs, the broken input had an open circuit on all three RCA jacks. Based on this, I concluded that the problem was probably a bad connection, and not a burned out part. So, I decided to open up the device.

The problem turned out to be a crack on the back circuit board. The RCA connectors on the back are all mounted the back circuit board, and the S-video connectors are mounted on the main board. The back circuit board has large square holes for the S-video connectors. As a result, it is only connected to the main board via four fingers. One of these fingers had cracked. That's not surprising when you consider how some RCA connectors can be very tight and hard to fully seat or unplug. It was an easy fix.

Saturday, December 26, 2009

Old Avant Browser user agent causes sites to redirect to mobile versions in IE

Avant Browser (an Internet Explorer shell) can come back to haunt you. When uninstalling, it leaves behind its addition to the Internet Explorer User-agent (in this case "Avant Browser []"). That addition causes some sites to redirect to the mobile versions in Internet Explorer 8. In some cases, it is impossible to view the normal version of the websites because even deep links redirect to the mobile homepage. To fix the problem, remove the User-agent addition. You can search for "Avant" in regedit.

Thursday, December 24, 2009

Cygwin 1.7 upgrade breaks Perl due to missing libssp0 dependency

After upgrading Cygwin to version 1.7, Perl failed with the following error message:

/usr/bin/perl.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

Then I ran "cygcheck /usr/bin/perl" and saw a bunch of these errors:

cygcheck: track_down: could not find cygssp-0.dll

I then installed libssp0 (current version 4.3.4-3), and Perl worked properly.

Wednesday, December 23, 2009

I saw the Torch today

I used to think that the Olympics are a part of human cultural heritage and that they're meant to be an expression of certain ideals. Starting with the 2008 Beijing Olympics I learned more about the business aspects of the Olympics. What I learned looked bad. I saw that the Olympics were being run like a corporation. Ideals, individuals or even athletes seemed to be less important than sponsors and branding. Basically, free speech and other freedoms are restricted to please the sponsors and control what people see. This is not acceptable, and it's especially disappointing to see this happening in Canada.

At first, I was planning to not see the Torch this year. What changed my mind was the thought that very many things are seriously messed up, and that I should focus more on recognizing the good parts and less on rejecting things because of bad parts.

At first I contemplated seeing the Torch at Point Pelee National Park, but I scheduled something else and I couldn't make it to Pt. Pelee on time. So I ended up seeing the 2008 Vancouver Torch in Kingsville, Ontario, and that turned out quite well. Plenty of people lined the streets in Kingsville, but it wasn't too crowded and everyone could get a close view of the Torch. Before and afterwards, the entertainment was children singing Christmas songs, which was quite nice.

This was the third Olympic Torch Relay I saw. The other two were the 1984 Sarajevo and 1988 Calgary Relays. It's interesting how they keep getting bigger. In late 1983, there was just the torchbearer and one or two cars, the 1988 Relay involved more vehicles, and finally in 2010 there was a whole mini-parade of vehicles for officials, sponsor displays and security. Maybe that's another illustration of how the Olympics have strayed from what is really important, or maybe not. I can't really complain about what I saw today.

Sunday, December 20, 2009

Enabling UAC Virtualization so old plugins can save settings

Originally, Windows had no filesystem security, and applications could write data wherever they wanted. Because of that old software often stores settings in the Windows directory or the application directory. For example, old Winamp plugins store their settings into the plugin directory (typically C:\Program Files\Winamp\Plugins). Starting with Vista, writing to those directories requires administrative privileges. To allow old software to function correctly, Windows can redirect such accesses to a place within the user's profile folder (%userprofile%\AppData\Local\VirtualStore). The same issues can exist with registry writes, and Windows can also redirect those. When an application is specifically designed for Vista or Windows 7, this redirection (called UAC Virtualization) is not needed and so it is disabled.

This normally works so well that one doesn't need to know about it. However, it fails when an application designed for Vista or Windows 7 loads old plugins. For example, some old Winamp plugins cannot save settings. Here are some solutions:
  • Grant write access to the directory.
  • Delete the manifest resource from the executable using a registry editor. However, some executables such as winamp.exe require the manifest resource.
  • Edit the manifest resource in the executable and remove the trustInfo section from the manifest. This means removing text from "<trustinfo" to "</trustinfo>". It's best to use a resource editor, but you can overwrite the text with spaces in a hex editor.
Task Manager can tell you if UAC Virtualization is enabled: right click on the executable and look for the check mark by "UAC Virtualization". This method can be used to change the setting, but I do not recommend it because it would have to be repeated every time the application is run.

Thursday, December 17, 2009

Changing Windows Live Messenger status via Windows messages from HoeKey

I use HoeKey for hotkeys. I love how it's tiny and unobtrusive. It's only using 128K of RAM now. I change instant messaging status via HoeKey so statuses in multiple applications stay synchronized. Here are the lines I use for Windows Live (formerly MSN) Messenger:

=Msg|MSBLWindowClass|273|40166 ; WLM Available
=Msg|MSBLWindowClass|273|40169 ; WLM Away
=Msg|MSBLWindowClass|273|40168 ; WLM Busy
=Msg|MSBLWindowClass|273|40210 ; WLM Sign out

To use those lines, either put a hotkey identifier before the equals sign or append them to other hotkeys. MSBLWindowClass is the window class of the Windows Live Messenger window. 273 means the message is WM_COMMAND. The 5 digit numbers correspond to wParam of the message and identifiers of entries on the File menu. Text after the semicolon is an explanatory comment.

Disclaimer: I don't like Windows Live Messenger. I just use it because it fully supports all the features of the protocol.

YouTube FLV files contain unique identifiers which could be used to find who downloaded a particular file

FLV files which have been downloaded from YouTube have a unique identifier. In several files I examined, the string "sourcedata" occurs at offset 0x10E and a unique alphanumeric ID is at offsets 0x11B through 0x125. Presumably, these unique identifiers can be matched with information in YouTube logs in order to find the IP or user who downloaded the file.

Sunday, December 13, 2009

Links in Windows are annoying

I just created a directory of photos for use with the Windows 7 desktop background slide show feature. It consists of photos which I uploaded to Panoramio or printed. I used links so I didn't end up with multiple copies of photos. Here are a few reasons why links in Windows are annoying:
  • To create links, one needs administrative privileges (eg. run command prompt as administrator). This is stupid, especially for symbolic links.
  • When deleting a symbolic link from the command prompt or explorer, the link is deleted, as expected. When deleting a photo while it is viewed via a symbolic link, the original photo is deleted and the link remains.
  • Hard links work in a more reasonable way. However, when deleting a link, file permissions are changed.

Downloading photos, coordinates, titles and tags from Panoramio

I really like Panoramio. It's the main place where I publicly share my photos. Whenever I really like a photo and feel that it fits criteria for inclusion in Google Earth (via the Panoramio layer), I upload that photo to Panoramio.

My main complaint about Panoramio is that I cannot export any information about my photos. I've spent a significant amount of time and effort geotagging and tagging photos in Panoramio, and I cannot obtain any of that information. Yesterday I decided to do something about this.

I chose to do this from the command prompt using common GNU tools: bash, wget, grep, sed and more. There was an obvious simple first step: downloading the photo index pages. I noted that I had 27 pages, and then I used this bash command to get them all:

for (( i = 1 ; i < 28 ; i++ )) ; do wget "--user-agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko/20091102 Firefox/3.5.5" "$i" ; sleep 10 ; done

Looking at the HTML source, I noticed lines containing photo ID numbers and titles. Such information can be extracted by a simple regular expression:

for (( i = 1 ; i < 28 ; i++ )) ; do sed -n "sX^.*h2><a href=\"/photo/\([0-9]*\)\">\([^<]*\)<.*\$X\1:\2Xp" 5539\?comment_page\=1\&photo_page\=$i ; done > photo2title.txt

The tags were more tricky, because they were on multiple lines. This required a simple sed program which joined the lines:

for (( i = 1 ; i < 28 ; i++ )) ; do sed -n 's/^ *"\([0-9]*\)":\[/\1:/; t next; b ignore; :next; N; s/\]$//; t end; N; s/,$/,/; t next; :end; s/\
//g; s/   *//g; s/"//g; p; :ignore;' 5539\?comment_page\=1\&photo_page\=$i ; done > photo2tags.txt

The coordinates were not in the photo index pages however, and so I had to look for another source of information. Obviously, I could just download all the web pages of all the specific photos, but I didn't really like that solution. I went to view all of my photos in the map and then I opened the AdBlock Plus blockable items list. The link from where the map gets its information was very obvious:

After downloading that I noticed that I was getting the type of information I wanted, but I was getting only 24 entries. I assumed it was due to the "to=24" part of the URL, so I changed that to the number of photos I had. The number I got was three less than the number of photos. Sure enough, three of my photos failed to appear in the map on Panoramio. I reported this bug in the Panoramio forum, and went on with my project. Extracting the coordinates wasn't hard. I based the regular expression on the data for one photo which I pasted from get_panoramas.

sed 's/"photo_id": \([0-9]*\), "longitude": \(-\?[0-9.]*\), "height": [0-9]*, "width": [0-9]*, "photo_title": "[^"]*", "latitude": \(-\?[0-9.]*\),/~\1:\3,\2~/g; y/~/\
/;' get_panoramas | grep "^[0-9]*:" > photo2coords.txt

If I didn't care about tags I could have avoided getting the photo index pages and started with get_panoramas output. It would have been simpler, but I would have missed three photos and failed to notice a bug in Panoramio. Since I knew about the three missing photos, I went to their photo pages, looked at the HTML source, and manually added the coordinates to photo2coords.txt.

The only remaining data was the correspondence between photos on my hard drive and photos on Panoramio. The data collected so far was not helpful. I decided to get the original photos and match them up with local photos based on MD5 hashes. I already had several files which listed all of my photo ID numbers, and it was trivial to download all the photos with wget. I placed delays between the downloads to reduce the load on Panoramio. At the end, I noticed one error in the wget output, and I manually downloaded that photo.

Once I had the photos, MD5 hashes successfully found local locations of most of the photos. The EXIF date and time of when the photo was taken found local locations of most of the rest. Out of 646 photos, I only had to manually match up 12, which wasn't bad. I'm not documenting the detailed matching procedure here. One hint: the join command is helpful.

Thursday, December 10, 2009

Fixing resolution of C-770 MPEG4 videos

My Olympus C-770 Ultra Zoom camera is supposed to record 640x480 MPEG4 videos. However, some applications instead play the videos at 320x240. For example, QuickTime 6.x and Xvid play the video at 640x480, while QuickTime 7.x and ffdshow play it at 320x240.

My solution up to now was to play the videos using Haali Media Splitter for the .MP4 container and Xvid for decoding. That resolved all the problems for me, but if I sent a file to someone else, they could still end up viewing the video at 320x240. Now I've finally figured out what is wrong with the files themselves.

I started out by compiling mp4v2 in Cygwin. This resulted in some errors, but just re-running make was enough to get the executables compiled. Then I used "mp4file --dump" to examine the contents of the MP4 container. It showed a 320x240 size in two places: the tkhd header for the video track and the stsd atom. QuickTime 7.6.5 uses the tkhd size, and Mplayer 1.0rc1-3.4.2 uses the stsd size. Changing both sizes to 640x480 should make the video always play at 640x480.

After seeing 320x240 at two places in the file and not seeing 640x480, I was left wondering what was the actual resolution of the video. It seems to be 640x480 based on several pieces of supporting evidence:
  • The videos are clearer when decoded at 640x480 than when decoded at 320x240 and scaled up.
  • Even when decoding at 320x240, Mplayer allocates a 640 wide YUV buffer with 320x240 chroma (which should be at half resolution).
  • If I extract the video stream using mp4creator, Mplayer plays the resulting MPEG4 ES stream at 640x480. This is even true if extracting from an unaltered .MP4 file which plays at 320x240.
At this point, I was wondering how to change the tkhd and stsd resolution values. The tkhd values may be changed via mp4track (from mp4v2), but I don't know what program can change the stsd values. After finding that the values aren't protected by any sort of checksum and they occur at the same place in all of my videos, I decided to directly alter all the values without using a tool specifically designed for MP4 container files. The changes which need to be made are:
000000F0: 01 02
000000F1: 40 80
000000F4: 00 01
000000F5: F0 E0
000001B9: 01 02
000001BA: 40 80
000001BB: 00 01
000001BC: F0 E0
This is the output of "fc /b". The first four are lines are tkhd and last four are stsd. Note that the patch is simply changing obvious big endian values.

Now the only problem was how to automatically change these values. I thought I would be able to find a utility which takes "fc /b" or "cmp -l" output, verifies the original bytes and applies the changes. However, I didn't find any simple utilities so I decided to create my own. For fun, I created a sed script which transforms "fc /b" output into a C program which performs the patch. You can download it and the resulting Windows executable.

Sunday, December 06, 2009

Windows 7 can't always automatically update root certificates?

Today Secunia PSI refused to run with the message: "an error occurred while verifying the security certificate". Then I found that IE refused to show because the certificate was "not issued by a trusted certificate authority". Firefox did not have a problem with that webpage. For some reason, IE did not recognize the "Thawte Server CA" certificate. IE also refused to recognize StartSSL.

This was really weird, because as far as I know, Windows 7 is supposed to automatically update root certificates. Microsoft even explains how the process works in Vista. My first thought was that my firewall was blocking the update, but that was not it. Event log showed event 4100 from CAPI2, which is "Successful auto update retrieval of third-party root certificate". The problem was event 4110: "Failed to add certificate to Third-Party Root Certification Authorities store with error: A certificate chain could not be built to a trusted root authority."

I manually downloaded and installed the latest root certificate update from Windows Update. After that, everything works. I'm just left wondering why I had to deal with this in the first place.

Saturday, December 05, 2009

256 colour mode palette handling is broken in Windows 7?

A while ago I ported AcidWarp to Windows using SDL. At the time I was running Vista, and I had to use a workaround for full screen mode. I described the issues and my workaround in a post here.

Now I find that the workaround does not work in Windows 7. AcidWarp fails to get all 256 palette entries even when I use the directx SDL video driver. The program's 256 colours are then remapped onto a smaller number of colours. This results in visible errors in many AcidWarp patterns.

There is an even more serious palette issue. When using the directx SDL driver in the normal way (without workarounds, just using the "set SDL_VIDEODRIVER=directx" command), a substantial number of palette entries remain unchanged in full screen mode. These colours are not remapped, resulting in very ugly static parts of the pattern. This can be avoided by using the windib SDL driver or the workaround I developed in Vista.

One workaround for everything is killing explorer.exe. Then both directx and windib drivers are able to grab all 256 colours. Explorer can easily be restarted from Task Manager, and even the tray icons are preserved. Still, it's not a very nice workaround.