Skip to content

Commit

Permalink
Adding support for the PNG codec.
Browse files Browse the repository at this point in the history
I am just copying what we did for tsc2.  If the codec is "png ", return an MP4PNGAtom, which is just a copy of the other atom classes.  This seems to work for our purposes.
  • Loading branch information
stephenkwagner committed Jan 20, 2017
1 parent 4f16d4d commit cfacbc9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
52 changes: 52 additions & 0 deletions src/atom_mp4v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,57 @@ void MP4Tsc2Atom::Generate()

///////////////////////////////////////////////////////////////////////////////

MP4PNGAtom::MP4PNGAtom(MP4File &file)
: MP4Atom(file, "png ")
{
AddReserved(*this, "reserved1", 6);
AddProperty(new MP4Integer16Property(*this, "dataReferenceIndex"));
AddReserved(*this, "reserved2", 16);
AddProperty(new MP4Integer16Property(*this, "width"));
AddProperty(new MP4Integer16Property(*this, "height"));
AddReserved(*this, "reserved3", 14);

MP4StringProperty* pProp = new MP4StringProperty(*this, "compressorName");
pProp->SetFixedLength(32);
pProp->SetCountedFormat(true);
// pProp->SetValue("TSC2 Codec");
AddProperty(pProp);
AddReserved(*this, "reserved4", 4); /* 7 */

ExpectChildAtom("colr", Optional, OnlyOne);
ExpectChildAtom("esds", Required, OnlyOne);
ExpectChildAtom("pasp", Optional, OnlyOne);
}

void MP4PNGAtom::Generate()
{
MP4Atom::Generate();

((MP4Integer16Property*)m_pProperties[1])->SetValue(1);

// property reserved3 has non-zero fixed values
static uint8_t reserved3[14] = {
0x00, 0x48, 0x00, 0x00,
0x00, 0x48, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x01,
};
m_pProperties[5]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[5])->
SetValue(reserved3, sizeof(reserved3));
m_pProperties[5]->SetReadOnly(true);

// property reserved4 has non-zero fixed values
static uint8_t reserved4[4] = {
0x00, 0x18, 0xFF, 0xFF,
};
m_pProperties[7]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[7])->
SetValue(reserved4, sizeof(reserved4));
m_pProperties[7]->SetReadOnly(true);
}

///////////////////////////////////////////////////////////////////////////////

}
} // namespace mp4v2::impl
13 changes: 11 additions & 2 deletions src/atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,25 @@ class MP4Mp4vAtom : public MP4Atom {
MP4Mp4vAtom &operator= ( const MP4Mp4vAtom &src );
};

class MP4Tsc2Atom : public MP4Atom {
class MP4Tsc2Atom : public MP4Atom {
public:
MP4Tsc2Atom(MP4File &file);
void Generate();
private:
MP4Tsc2Atom();
MP4Tsc2Atom( const MP4Tsc2Atom &src );
MP4Tsc2Atom &operator= ( const MP4Tsc2Atom &src );
};
};

class MP4PNGAtom : public MP4Atom {
public:
MP4PNGAtom(MP4File &file);
void Generate();
private:
MP4PNGAtom();
MP4PNGAtom( const MP4PNGAtom &src );
MP4PNGAtom &operator= ( const MP4PNGAtom &src );
};

class MP4S263Atom : public MP4Atom {
public:
Expand Down
4 changes: 3 additions & 1 deletion src/mp4atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ MP4Atom::factory( MP4File &file, MP4Atom* parent, const char* type )
case 'p':
if( ATOMID(type) == ATOMID("pasp") )
return new MP4PaspAtom(file);
if( ATOMID(type) == ATOMID("png ") )
return new MP4PNGAtom(file);

break;

case 'r':
Expand Down Expand Up @@ -983,7 +986,6 @@ MP4Atom::factory( MP4File &file, MP4Atom* parent, const char* type )
if( ATOMID(type) == ATOMID("tsc2") )
return new MP4Tsc2Atom(file);


if( ATOMID(type) == ATOMID("twos") )
return new MP4SoundAtom( file, type );
break;
Expand Down

0 comments on commit cfacbc9

Please sign in to comment.