freeMXF.org
http://freemxf.org/forum/

problem with read an MXF file
http://freemxf.org/forum/viewtopic.php?f=2&t=203
Page 1 of 1

Author:  bernard [ Fri Mar 26, 2010 3:39 pm ]
Post subject:  problem with read an MXF file

Hello everyone,
I need a help. In fact, I beg you for helping me.
I spent all week trying to read data from file with bodyReaderPtr->ReadFromFile() function but it doesn't work.
I have to get JPEG2000 files from MXF file.
Could you help me, please?
I presented my code below. Maybe should I do it in another way?


I built mainProcess function:
Code:
int MXFManager ::mainProcess() {
   MyGCReadHandler* myGCReadHandlerPtr = new MyGCReadHandler();
   BodyReaderPtr bodyReaderPtr = new BodyReader(inFilePtr);
   
   for( ;  ; ) {      // till readResult breaks the loop
      UInt32 bodySID = bodyReaderPtr->GetBodySID();
      cout << "bodySID: " << bodySID << endl;
      cout << "MakeGCReader(bodySID): " << bodyReaderPtr->MakeGCReader(bodySID) << endl;
      GCReaderPtr gcReaderPtr = bodyReaderPtr->GetGCReader(bodySID);
      gcReaderPtr->SetDataHandler(bodySID);
      cout << "Tell(): " << bodyReaderPtr->Tell() << endl;
      inFilePtr->Seek(bodyReaderPtr->Tell());
      bool readResult= bodyReaderPtr->ReadFromFile();      // CRASH!!!
      cout << "readResult: " << readResult << endl;
      if (!readResult) {
         break;
      }
      bodyReaderPtr->ReSync();
   }
   return 0;
}


My HandleData is shown below.
Code:

// class MyGCReadHandler : GCReadHandler_Base

bool MyGCReadHandler ::HandleData(mxflib::GCReaderPtr Caller, mxflib::KLVObjectPtr Object){
   cout << "MyGCReadHandler ::HandleData" << endl ;
   return true;
}


Problems.

1. Program is crashed in line with:
bool readResult= gcReaderPtr->ReadFromFile();

2. I've read Ly's posts
http://www.freemxf.org/freemxf_board/vi ... 8420633da0

I tried to do it the same he does. I called:
gcReaderPtr->SetDataHandler(bodySID,myGCReadHandlerPtr);
but compiler returns: "error C2243: 'type cast' : conversion from 'MyGCReadHandler *' to 'mxflib::IRefCount<T> *' exists, but is inaccessible".
So I call

3. I've read Matt's chapter in the MXF Book. I don't understand something.
On page 328 there are two examples with two for_each loops.
Code:
BodyReaderPtr BodyParser = new BodyReader(InFile);
for_each(BodySID) {
   BodyParser->MakeGCReader(BodySID, DefaultHandler[BodySID]);
   GCReaderPtr ThisReader = BodyParser->GetGCReader(BodySID);
   for_each(TrackNumber in BodySID) {
      ThisReader->SetDataHandler(TrackNumber, Handler[BodySID][TrackNumber]);
   }
}

- "TrackNumber in BodySID" - I don't understand it. BodySID is UInt32 not table or list, isn't it? How to get BodySID and TrackNumber?
- How should I create DefaultHandler and Handler tables?


I don't know what it's wrong.
I'll be really grateful for explain me it.
Bernard

Author:  Matt Beard [ Tue Mar 30, 2010 8:50 am ]
Post subject: 

A few questions:

1) Why are you doing this?
Code:
inFilePtr->Seek(bodyReaderPtr->Tell());


2) The following line removes the data handler allocated to bodySID - is this what you intend?
Code:
gcReaderPtr->SetDataHandler(bodySID);


3) What do you mean by "CRASH!!!"

4) When you define class MyGCReadHandler, is it defined with a "public" base class of "GCReadHandler_Base", or private?

Author:  bernard [ Tue Mar 30, 2010 1:08 pm ]
Post subject: 

1) I tried to running my program, but I couldn't find where I made a mistake (or mistakes).
I added the line with seek() function, because I thought it's needed to start from beginning of an MXF file.

2) Removes? I thought I have to set the handler to get an access to the file. On page 328 of the MXF book there are loops with SetDataHandler() so I thought I have add this line.

3) By "CRASH!!!" I mean that the program breaks in this line. Debugger returns:
Debug Assertion Failed!
(path) \mxflib\smartptr.h
Line: 470

4) It's defind with private operator.

Author:  Matt Beard [ Thu Apr 01, 2010 8:13 am ]
Post subject: 

So, it seems that the "private" class derivation is the problem.

If you define it as "public" you should be able to add that then with a SetDataHandler() call.

Author:  bernard [ Tue Apr 06, 2010 12:03 pm ]
Post subject: 

I changed from private to public:
Code:
class MyGCReadHandler : public GCReadHandler_Base {
public:
   MyGCReadHandler();
   bool HandleData(GCReaderPtr Caller, KLVObjectPtr Object);
};


but it still doesn't work.
The same error appears:

Debug Assertion Failed!
(path) \mxflib\smartptr.h
Line: 470

Author:  Matt Beard [ Wed Apr 07, 2010 11:01 am ]
Post subject: 

Have you now set the correct data handler?

What is the point in you code that triggers the assert?

Author:  bernard [ Wed Apr 07, 2010 12:55 pm ]
Post subject: 

Yes, I set data handler:

Code:
MyGCReadHandler* myGCReadHandlerPtr = new MyGCReadHandler();
gcReaderPtr->SetDataHandler(bodySID, myGCReadHandlerPtr);


I'd like to read an mxf file and then get jpeg2000 files from it.

Maybe I should do it in another way?

Author:  Matt Beard [ Thu Apr 08, 2010 9:07 am ]
Post subject: 

Not sure what is causing your problem. When I run the following code:
Code:
class MyGCReadHandler : public GCReadHandler_Base
{
    bool HandleData(mxflib::GCReaderPtr Caller, mxflib::KLVObjectPtr Object){
        cout << "MyGCReadHandler ::HandleData" << endl ;
        return true;
    };
};

int main(int argc, char *argv[])
{
   LoadDictionary("dict.xml");

   MXFFilePtr inFilePtr = new MXFFile();
   inFilePtr->Open("test.mxf");

   MyGCReadHandler* myGCReadHandlerPtr = new MyGCReadHandler();
   BodyReaderPtr bodyReaderPtr = new BodyReader(inFilePtr);
   
   for( ;  ; ) {      // till readResult breaks the loop
      UInt32 bodySID = bodyReaderPtr->GetBodySID();
      cout << "bodySID: " << bodySID << endl;
      cout << "MakeGCReader(bodySID): " << bodyReaderPtr->MakeGCReader(bodySID) << endl;
      GCReaderPtr gcReaderPtr = bodyReaderPtr->GetGCReader(bodySID);
      gcReaderPtr->SetDataHandler(bodySID);
      cout << "Tell(): " << bodyReaderPtr->Tell() << endl;
      inFilePtr->Seek(bodyReaderPtr->Tell());
      bool readResult= bodyReaderPtr->ReadFromFile();
      cout << "readResult: " << readResult << endl;
      if (!readResult) {
         break;
      }
      bodyReaderPtr->ReSync();
   }
   return 0;
}

It runs fine and gives the following output:
Code:
bodySID: 0
MakeGCReader(bodySID): 1
Tell(): 0
readResult: 1
bodySID: 0
MakeGCReader(bodySID): 0
Tell(): 188
readResult: 1
bodySID: 0
MakeGCReader(bodySID): 0
Tell(): 229655000
readResult: 1
bodySID: 0
MakeGCReader(bodySID): 0
Tell(): 229711096
readResult: 1
bodySID: 0
MakeGCReader(bodySID): 0
Tell(): 412787485
readResult: 1
bodySID: 0
MakeGCReader(bodySID): 0
Tell(): 412832483
readResult: 1
bodySID: 0
MakeGCReader(bodySID): 0
Tell(): 412832671
...

Author:  bernard [ Thu Apr 08, 2010 10:35 am ]
Post subject: 

Matt, I'm sorry I took your time.
When I read your post I analyzed my code again and I realized that I hadn't set inFilePtr.
Now it seems to work well.
I am so stupid or blind...

I'm really sorry.

Now I'll try to get JPEG2000 files.

Author:  Matt Beard [ Fri Apr 09, 2010 8:39 am ]
Post subject: 

No problem - glad that I helped to solve it in the end!

Author:  bernard [ Tue Apr 27, 2010 3:02 pm ]
Post subject: 

Hi Matt, it's me again.

Now I've got another problem.
I can't create an EssenceParser object.
I've done exactly what you wrote in the MXF book.
Code:
EssenceParserPtr mainParser = new EssenceParser;

First I couldn't compile it, because I got an error:
error C2248: 'mxflib::EssenceParser::EssenceParser' : cannot access private member declared in class 'mxflib::EssenceParser'

When I changed it in the essence.h file to a public member it's fine.

The second error which I received:
error C2440: 'initializing' : cannot convert from 'mxflib::EssenceParser *' to 'mxflib::SmartPtr<T>'

I declared EssenceParserPtr in my header file:
Code:
typedef SmartPtr<EssenceParser> EssenceParserPtr;

Have you got any idea how I can fix it?

Regards,
Bernard

PS.
I found a small mistake in the MXF book, on page 330. There is an example code. In the last if statement is:
Code:
if(BodyParser()->Eof()) break;


and should be (IMHO)
Code:
if(BodyParser->Eof()) break;

because BodyParser is not a function but an object.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/