Tuesday, September 20, 2011

SoMagic EasyCap is no longer a (very small) boat anchor

Success in getting continuous video frames out of the capture device!

I can now stream 720x576 UYVY frames at 25 fps from the unit and pipe the output into mplayer, which can play them.
Obligatory screenshot follows (which doesn't do justice to the fact that it's motion video...but it would seem unfair of Carole Hersee to miss out, now she isn't cut in two!)
One full frame of test card F


I've posted the source code that you need to do this to a public github project easycap-somagic-linux . The code is incredibly rough yet, and there's plenty of to-dos on the list, but they will have to wait until I have more time. It's usable as far as I need it to be, for now.

I'm hoping that someone else will pick it up and turn it into a proper device and video4linux driver.


28 comments:

szu said...

great! your code works perfectly with my somagic easycap (purchased for use with a windows notebook, but it's nice to know that it is now also usable with linux).
interestingly, it failed when connected through the 2.0 hub, is this expected behavior?

Juanbe said...

Thanks, thanks, thanks!

Great job!! Will follow updates!

entereczek said...

Amazing, works awesomely on my Somagic easycap!

Keep up the good work.

calamari said...

Hi,

Thanks for this. I'd like to try to get this working for NTSC. I'm wondering if you can provide any hints where you are setting the capture resolution and refresh rate. I'm coming to the conclusion that you might not know (that it is contained in the raw USB dumps and you're just duplicating what happened on Windows), but I thought it might be worth asking anyways :)

Thanks,
calamari

Pedro said...

Hi,
In github, in the readme file, the paramenters:
./capture 1c88 003c | mplayer - -demuxer rawvideo -rawvideo "w=720:h=576:format=uyvy:fps=25"

What should be in the first hypen (right after mplayer)?

Thanks.
Pedro

PD: That is a great job!

bonybrown said...

calamari,

The resolution and refresh rate are fixed because all this device does (basically) is dump the output of the SAA7113 chip that decodes the video. So the refresh rate is fixed at the video rate, and the resolution fixed at 720 samples x the number of video lines.

There are registers that control whether the decoder chip is decoding NTSC or PAL.
If you look at the USB control transfers in capture.c where the 6th bytes seems to be increasing... They are the ones that look like this:
\x0b\x4a\xc0\x01\x01\x15\x00\xff\x06\x00\x00\x00\x00

I believe the 6th byte is the SAA7113 register address, and the 7th is the register value.
So it's a matter of looking at the SAA7113 datasheet and working out what values to put in. I'd start with subaddress 08h on page 41.

That said, I don't know what changes will need to be made to get the chip doing the USB transfers to send the data. It might just work, maybe not.

bonybrown said...

Pedro,

The hyphen on it's own means "read the input data from stdin"...which is where the "capture" program is outputting the raw UYVY frames to.

Thanks,
Tony.

Pedro said...

Hi,

Thanks for the clarification. Unfortunately I can't see video with my easycap yet. One doubt: Why is libusb_augmented disabled in init1/2.c?

regards,
Pedro

Jonarne said...

I had a good look at the packets that are sent during init1, and realized that it's actually programming the usb controller.

I'm able to change both the Name and ID that the device is reporting after init1, and it looks like I could be able to program this chip to say whatever I want in most of the fields listed by lsusb -vd 1c88:003c.

If I'm correct in my assumptions, I think I should be able to get this card to work with the driver for easycap with usbid 05e1:0408 found here, but I need to investigate some more.

Pedro said...

Hi,

I would like to note that somagic uses different chips, my easycap has Cirrus5340+SMI2021CBE+Silan SC8113.

regards,
Pedro

Jonarne said...

I would guess that the different video chips are pin/code compatible, but that's just a guess.

Mine is the GM7113C, but it's compatible with the saa7113.

I found a datasheet for the SC8113, but it was in Chinese.

Jonarne said...

Also, I've uploaded the results of my research to github:
https://github.com/jonjonarnearne/somagic_dc60

At the moment it's only loading the firmware, but I'm working on improving it.

Jonarne said...

@Pedro:
I would guess that if there are big differences between the 7113 and 8113, the firmware that is loaded during Init1 is different between the different versions of the Easycap.

If you could do a UsbSnoop/Wirshark usb-capture with your driver running windows. I might be able to check if your firmware is different.

calamari said...

@bonybrown Thank you so much for that info! I actually broke down and tried the device in Windows and found out there is a large delay between the video signal input and it being displayed (I'd say around a second or so). Is there that delay for you as well?

bonybrown said...

@Pedro - what driver disc did you get with your device. Mine says...
Model No: DC60-2021
Version 3.1C Win7-64
...which actually doesn't match @Jonarne's github project (says it's 2.1C ). I'm yet to check whether the init1 firmware is the same or not.

I looked at the datasheet for the SL8113, the chip pinouts are identical...I'm pretty convinced it's a direct replacement.

Libusb_augmented is commented out of the init code because that include declares the usb isochronous transfer functions. The init processes do not use them.

@Jonarne, great work on starting a driver. I didn't know where to begin with that.

@calamari, I can't really say because the Ulead studio software that came with the device always crashed on me. It worked only enough for me to grab the usb-snoop logs, I never actually saw video.

calamari said...

Here's a quick and dirty Makefile:

http://pastebin.com/raw.php?i=9T4GvaGa

calamari said...

@bonybrown Sorry I wasn't very clear. I'm wondering if there is a delay with your capture program.

bonybrown said...

@calamari, I can't say for certain, but I don't think so. I'm certain that capture.c doesn't buffer anything but one frame of video, so if there is any delay, it's either in the usb device, or in mplayer's processing of the data.

The best way of testing it would be to connect the AV out of a TV to the device and compare the delay between what's on the TV and what's captured.

And thanks for the makefile, I'll include it in the next commit.

calamari said...

I've made some progress with NTSC, but I just had to drop a note and say I was watching (on the capture card) some PBS show where the family is stuck in the 70s. They got a new color TV in fake-"1976" and your test image showed on their TV briefly. LOL, just had to post about it.

Where I am with NTSC: The image will go for seconds perfectly, then it'll go into glitching (a random colored dot and the rest of the line goes black). Trying to figure out why.

calamari said...

Well, I've torn this sync code apart and not solved my problem. I've noticed when it first starts, artifacts are abundant (and even a bit of rolling), but it gradually settles down to nearly perfect "sync". Once it finally gets settled, I can watch nearly glitch free (watched that way for nearly an hour).

I'm wondering if the "timing reference code" (FF 00 00 xx) might be contained in the data read by a write_buffer() call. If so, that might explain my glitches.

But it seems very strange that it should self-heal.

calamari said...

Here is the current NTSC code.. not really ready for prime time due to the glitches, but thought I'd put it out there:

http://pastebin.com/raw.php?i=7dL25SRh

Pedro said...

Hi,

I see that we have a common interest to develop a working piece of software to use our somagic easycaps on linux, Shouldn't be better to start a project in sourceforge or similar? github doesn't have a mailing list and posts in the blog is not the best way to share our experiences and data/code. What do you think?

best regards,
Pedro

Jonarne said...

@Pedro, I agree. If someone will set it up, I'll join, but i don't have time to set it up :)

calamari said...

I've created a project on Google Code:

http://code.google.com/p/easycap-somagic-linux/

Please let me know your Google Account id's and I'll add everyone. (Pedro: I was able to find your email address and added you in advance :)

calamari said...
This comment has been removed by the author.
Jonarne said...

Ok, maybe I'm a bit slow, but i could not find any mailing list on the google-code page, so I'm posting here again :)

I just ripped all the firmware code from BonyBrown's UsbSnoop log: first_init_0007.log

BonyBrown's firmware is identical to the firmware i ripped from my own driver, with version 2.1C, so the version numbers seems to have no relation with the firmware.

Also, I'm wondering if Pedro's Silan SC8113 chip has different inputs than the 7113 chip tha is in my easycap.
From what i understood of the datasheet, the 8113 chip has 3 CVBS inputs, while the 7114 has one CVBS and one S-Video? Or am I wrong here?

calamari said...

@Jonarne Pedro created a group for us. Access it here: http://groups.google.com/group/easycap-somagic-linux

There is also a link from the project main page (bottom of the left column)

calamari said...
This comment has been removed by the author.