andreybl wrote:
IMHO, the GCWriter::AddSystemData is the right place to start with the encryption.
Actually, I was investigating the the mxfcrypt.cpp for the right entry point for the MPEG-Encryption. Then I saw the discussion about MPEG->EncryptedMXF here. The suggestion is to use the EssenceSource for the encryption. Well, I've got a couple of discrepancies with my previouse experience with MXFLib:
1) actual job for creation and writing of the KLV is done in GCWriter::AddSystemData. Shouldn't encryption be done somewhere in this method? Otherwise I'm expected to make setting of K and other thing somewhere in the EssenceSource. IMHO, the EssenceSouce should only know the source, and nothing extra from the MXF.
As I see, the CGWriter do not expect any KL from the EssenceSource. Neither can he recognize, whether the passed essence is encrypted or not.
2) Why is advice given to make encryption with EssenceSource, if the encryption is done with Encrypt_GCReadHandler? I would expect some kind of "reuse".
thank you for clarifications.
1) The EssenceSource is the entity that "knows" about the essence, as such it is the only object that knows what specific wrapping should be used for this essence. It can be queried for items such as the GCEssenceType and the GCElementType (for building a standard GC key) or for an override key if required. This allows an EssenceSource to supply encrypted data and have it correctly KLVWrapped by the GCWriter without the GCWriter having to be encryption-aware.
2) The current mxfrcrypt example application shows one way of producing an encrypted MXF file - it takes a plaintext file and encrypts each essence KLV. It writes these encrypted KLVs using the "raw" AddEssenceData method which adds an entire KLVObject to the output stream, rather than the other methods which each build a new KLV. This makes sense for this application as it is already reading a KLVObject.
The method that I am recommending is to write an "intermediate" EssenceSource (a sort of EssenceSource filter similar to a DirectShow filter). This would read plaintext data from an existing EssenceSource, encrypt it and then pass the encrypted data out as its output. About 99% of the work can be done by code re-use by having an internal KLVEObject. However, I notice now that a small modification would currently be required to the library code to enable the (currently commented out) WriteHandler code in KLVObject.
The small modification has been added to the short-term to-do list (but you could do this yourself quite easily) and the whole method has been added to the release 1.0 suggested features list.