Log in

View Full Version : How to detect dual vs. single layer?


MEJHarrison
30th December 2004, 02:37
HI,

I'm working on an application where I need to read a handful of information off a DVD (runtime, CC, regions, audio attributes, etc). Things are going well except for the layer information. Where would I look for that information? I've been looking for the past week with no luck.

Lord_KiRon
30th December 2004, 15:19
It's a booktype I think but I do not know where to read it. :)

Joe Fenton
31st December 2004, 00:39
You want the Control Data Area at physical block number 0x2f200. The first section of the control data area is the Physical Format Information. At byte offset 0, bits 7-4 tell you the book type (DVD, DVD-R, DVD+RW, etc). At byte offset 2, bits 6-5 tell you the number of layers. There's other info in there. You should get something like the MMC3 specifications which documents all that.

MEJHarrison
31st December 2004, 00:55
Thanks for the information. Not content to sit on my butt waiting for someone to hand me the answer, I ran across this today Google search (http://groups-beta.google.com/group/alt.media.dvd.cracked/browse_thread/thread/67004e491e431c54/dae4522d3847ca08?q=DeviceIOControl+DVD+layers&_done=%2Fgroups%3Fhl%3Den%26c2coff%3D1%26q%3DDeviceIOControl+DVD+layers%26&_doneTitle=Back+to+Search&&d#dae4522d3847ca08). So I now have working code.

Still, thanks for the pointer to the MMC3 specs. I'll have to track that down. I'd like a better description than some C code.

MEJHarrison
31st December 2004, 23:53
I'm using that code I found to read the DVD_LAYER_DESCRIPTOR. Everything is working just great and matches data other programs are reading (like DVD Decryptor and DVDInfoPro). The only problem is the layers. No matter the disc, it always says there's one layer.

I looked at some other code online (all linux code) and they seem to try reading the layer descriptor for each layer (although all the code I found seems to loop through 4 times if possible).

So, since I'm not having much luck getting that field in the structure to populate, could I determine the number of layers by seeing how many layers I'm able to retrieve data for? Does that make sense? If I can read the DVD_LAYER_DESCRIPTOR for layer 0 & 1, it's dual layered. If I can only read it for layer 0 it's single layered? Would that work?

Is there any other reason that structure would be filling up with all correct data except for the layer information?

Joe Fenton
1st January 2005, 04:51
Here's a discussion on a linux forum about dvdinfo and what you get on different DVDs.

http://www.ussg.iu.edu/hypermail/linux/kernel/0103.0/1239.html

It seems DVDs return 0 or 1 for 1 or 2 layers in those bits I was telling you about. Maybe the code you were using for windows is buggy. I noticed it uses bitfields - compilers often change how they arrange bitfields from version to version, so maybe that code is old enough that the bitfield definitions are wrong, or your compiler does bitfields differently than the compiler used for that code. I'd just get the byte at offset 2 and use logical operations to get the two bits ((x>>5)&3).

MEJHarrison
3rd January 2005, 00:51
I've seen that link already. Thanks.

As for the code I'm using, it may very well be buggy. But if it is, I'm not sure where the bug is. Two weeks ago, I didn't know an IFO from a VOB. I'm a web developer, not a Windows developer, but I'm trying to expand my knowledge.

Anyway, I have a heavily stripped down version of that code here (http://home.comcast.net/~mejharrison/Dvd-Auth.c). If you can find any errors with it, I'd love to know what they are. Also, I have my DVD drive hard coded if you decide to compile it. So you'd have to change that.

As for the bitfields, I don't believe that's the problem. I've examined the entire byte and Layer Type seems to be the only bits getting values. I've also converted the code to c# and since c# doesn't support bitfields, I'm reading the data into bytes and using bit operations to extract the data. I get the exact same results.

Anyway, thanks for all the help. I really appreciate it. I'd love to get this figured out, but I'm about out of ideas at this point. I'd rather not have to get into ASPI or SPTI. I'm able to grab all the data I'm interested in at this point from the IFO files except for number of layers. That seems like a lot of work to go through just to find out how many layers the disc has.

If I do ever get this figured out, I'll happily post the c# code for anyone else interested.

Joe Fenton
3rd January 2005, 02:52
I'll look at the code, but in the meantime, how about the idiot's method of determining the number of layers... just read a block beyond what one layer can hold. If it reads at all, the disc is obviously dual-layer. :D

MEJHarrison
3rd January 2005, 20:39
That's and idiot method I'd not thought of. I read elsewhere to check the size of the disc.

Personally, I'm trying my own idiot method. I'm still requesting the DVD_LAYER_DESCRIPTOR structure. But instead of reading the number of layers from the structure, I'm asking for that structure twice and changing the layer number in the IOCTL_DVD_READ_STRUCTURE structure. I should always be able to read the structure for layer 0 and only get a result on layer 1 if it's a double layered disc. I'll have to do some testing of course, but it worked on the one disc I tried.

Speaking of which, why do all the code samples I see seem to loop through layers 0 though 3?

Joe Fenton
4th January 2005, 06:45
Originally posted by MEJHarrison
Speaking of which, why do all the code samples I see seem to loop through layers 0 though 3?

Probably because the original sample code people worked from did that. Remember that the # of layers is two bits, so that gives 0 to 3. If I had to guess, Windows internally removes the # of layers from the structure so you HAVE to try all 3 possible layers to figure out the number of layers and their properties.

MEJHarrison
4th January 2005, 18:05
That makes sense I guess about the two bits. But it's not really necessary to check all four is it? Since a DVD can only have two layers, it seems pointless to loop through all four. Or is there a valid reason to do so?

Joe Fenton
5th January 2005, 02:41
Knowing MS, they probably keep four instances because that is the theoretical maximum and won't return correct data unless you go through all four. For example, if you read just two, then try to read them again later, you get the next two instead. That would certainly explain why EVERYONE always reads all four.