"Fossies" - the Fresh Open Source Software Archive

Member "MediaInfo_CLI_GNU_FromSource/MediaInfoLib/Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp" (10 Sep 2019, 381084 Bytes) of package /linux/misc/MediaInfo_CLI_19.09_GNU_FromSource.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "File_Mpeg4_Elements.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 19.07_vs_19.09.

    1 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
    2  *
    3  *  Use of this source code is governed by a BSD-style license that can
    4  *  be found in the License.html file in the root of the source tree.
    5  */
    6 
    7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    8 //
    9 // Contributor: Lionel Duchateau, kurtnoise@free.fr
   10 //
   11 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   12 
   13 //---------------------------------------------------------------------------
   14 // Pre-compilation
   15 #include "MediaInfo/PreComp.h"
   16 #ifdef __BORLANDC__
   17     #pragma hdrstop
   18 #endif
   19 //---------------------------------------------------------------------------
   20 
   21 //---------------------------------------------------------------------------
   22 #include "MediaInfo/Setup.h"
   23 //---------------------------------------------------------------------------
   24 
   25 //---------------------------------------------------------------------------
   26 #ifdef MEDIAINFO_MPEG4_YES
   27 //---------------------------------------------------------------------------
   28 
   29 //---------------------------------------------------------------------------
   30 #include "MediaInfo/Multiple/File_Mpeg4.h"
   31 #if defined(MEDIAINFO_DVDIF_YES)
   32     #include "MediaInfo/Multiple/File_DvDif.h"
   33 #endif
   34 #if defined(MEDIAINFO_MXF_YES)
   35     #include "MediaInfo/Multiple/File_Mxf.h"
   36 #endif
   37 #if defined(MEDIAINFO_AIC_YES)
   38     #include "MediaInfo/Video/File_Aic.h"
   39 #endif
   40 #if defined(MEDIAINFO_AV1_YES)
   41     #include "MediaInfo/Video/File_Av1.h"
   42 #endif
   43 #if defined(MEDIAINFO_AVC_YES)
   44     #include "MediaInfo/Video/File_Avc.h"
   45 #endif
   46 #if defined(MEDIAINFO_FFV1_YES)
   47     #include "MediaInfo/Video/File_Ffv1.h"
   48 #endif
   49 #if defined(MEDIAINFO_H263_YES)
   50     #include "MediaInfo/Video/File_H263.h"
   51 #endif
   52 #if defined(MEDIAINFO_HEVC_YES)
   53     #include "MediaInfo/Video/File_Hevc.h"
   54 #endif
   55 #if defined(MEDIAINFO_MPEGV_YES)
   56     #include "MediaInfo/Video/File_Mpegv.h"
   57 #endif
   58 #if defined(MEDIAINFO_PRORES_YES)
   59     #include "MediaInfo/Video/File_ProRes.h"
   60 #endif
   61 #if defined(MEDIAINFO_VC1_YES)
   62     #include "MediaInfo/Video/File_Vc1.h"
   63 #endif
   64 #if defined(MEDIAINFO_VC3_YES)
   65     #include "MediaInfo/Video/File_Vc3.h"
   66 #endif
   67 #if defined(MEDIAINFO_AAC_YES)
   68     #include "MediaInfo/Audio/File_Aac.h"
   69 #endif
   70 #if defined(MEDIAINFO_AC3_YES)
   71     #include "MediaInfo/Audio/File_Ac3.h"
   72 #endif
   73 #if defined(MEDIAINFO_AC4_YES)
   74     #include "MediaInfo/Audio/File_Ac4.h"
   75 #endif
   76 #if defined(MEDIAINFO_SMPTEST0337_YES)
   77     #include "MediaInfo/Audio/File_ChannelGrouping.h"
   78 #endif
   79 #if defined(MEDIAINFO_AMR_YES)
   80     #include "MediaInfo/Audio/File_Amr.h"
   81 #endif
   82 #if defined(MEDIAINFO_ADPCM_YES)
   83     #include "MediaInfo/Audio/File_Adpcm.h"
   84 #endif
   85 #if defined(MEDIAINFO_MPEGA_YES)
   86     #include "MediaInfo/Audio/File_Mpega.h"
   87 #endif
   88 #if defined(MEDIAINFO_PCM_YES)
   89     #include "MediaInfo/Audio/File_Pcm.h"
   90 #endif
   91 #if defined(MEDIAINFO_SMPTEST0337_YES)
   92     #include "MediaInfo/Audio/File_SmpteSt0337.h"
   93 #endif
   94 #if defined(MEDIAINFO_CDP_YES)
   95     #include "MediaInfo/Text/File_Cdp.h"
   96 #endif
   97 #if defined(MEDIAINFO_CDP_YES)
   98     #include "MediaInfo/Text/File_Cdp.h"
   99 #endif
  100 #if defined(MEDIAINFO_PROPERTYLIST_YES)
  101     #include "MediaInfo/Tag/File_PropertyList.h"
  102 #endif
  103 #if defined(MEDIAINFO_TIMEDTEXT_YES)
  104     #include "MediaInfo/Text/File_TimedText.h"
  105 #endif
  106 #if defined(MEDIAINFO_TTML_YES)
  107     #include "MediaInfo/Text/File_Ttml.h"
  108 #endif
  109 #if defined(MEDIAINFO_JPEG_YES)
  110     #include "MediaInfo/Image/File_Jpeg.h"
  111 #endif
  112 #include "MediaInfo/Multiple/File_Mpeg4_TimeCode.h"
  113 #include "ZenLib/FileName.h"
  114 #include "ThirdParty/base64/base64.h"
  115 #include <zlib.h>
  116 #include <algorithm>
  117 #include <cmath>
  118 #include <cfloat>
  119 //---------------------------------------------------------------------------
  120 
  121 namespace MediaInfoLib
  122 {
  123 
  124 //***************************************************************************
  125 // Infos
  126 //***************************************************************************
  127 
  128 //---------------------------------------------------------------------------
  129 static const char* Mpeg4_Meta_Kind(int32u Kind)
  130 {
  131     switch (Kind)
  132     {
  133         case 0x00 : return "Binary";
  134         case 0x01 : return "UTF8";
  135         case 0x02 : return "UTF16";
  136         case 0x03 : return "Mac String";
  137         case 0x0E : return "Jpeg";
  138         case 0x15 : return "Signed Integer"; //the size of the integer is derived from the container size
  139         case 0x16 : return "Float 32";
  140         case 0x17 : return "Float 64";
  141         default   : return "";
  142     }
  143 }
  144 
  145 //---------------------------------------------------------------------------
  146 static const char* Mpeg4_TypeModifierName(int32u TypeModifierName)
  147 {
  148     switch (TypeModifierName)
  149     {
  150         case 0x01 : return "Matrix";
  151         case 0x02 : return "Clip";
  152         case 0x03 : return "Volume";
  153         case 0x04 : return "Audio balance";
  154         case 0x05 : return "Graphic mode";
  155         case 0x06 : return "Matrix object";
  156         case 0x07 : return "Graphics mode object";
  157         case 0x76696465 : return "Image type";
  158         default   : return "";
  159     }
  160 }
  161 
  162 //---------------------------------------------------------------------------
  163 static const char* Mpeg4_sample_depends_on[]=
  164 {
  165     "",
  166     "this sample does depend on others (not an I picture)",
  167     "this sample does not depend on others (I picture)",
  168     "reserved",
  169 };
  170 
  171 //---------------------------------------------------------------------------
  172 static const char* Mpeg4_sample_is_depended_on[]=
  173 {
  174     "",
  175     "other samples depend on this one (not disposable)",
  176     "no other sample depends on this one (disposable)",
  177     "reserved",
  178 };
  179 
  180 //---------------------------------------------------------------------------
  181 static const char* Mpeg4_sample_has_redundancy[]=
  182 {
  183     "",
  184     "there is redundant coding in this sample",
  185     "there is no redundant coding in this sample",
  186     "reserved",
  187 };
  188 
  189 //---------------------------------------------------------------------------
  190 static Ztring Mpeg4_Vendor(int32u Vendor)
  191 {
  192     switch (Vendor)
  193     {
  194         case 0x46464D50 : return __T("FFMpeg");
  195         case 0x4D4F544F : return __T("Motorola");
  196         case 0x50484C50 : return __T("Philips");
  197         case 0x6170706C : return __T("Apple");
  198         case 0x6E6F6B69 : return __T("Nokia");
  199         case 0x6D6F746F : return __T("Motorola");
  200         default         : return Ztring().From_CC4(Vendor);
  201     }
  202 }
  203 
  204 //---------------------------------------------------------------------------
  205 const char* Mpeg4_chan(int16u Ordering)
  206 {
  207     //Source: http://developer.apple.com/library/mac/#documentation/MusicAudio/Reference/CACoreAudioReference/CoreAudioTypes/CompositePage.html
  208     //Arbitrary decision (0° = Front):
  209     //Front = 0°-80°
  210     //Side = 80°-120°
  211     //Rear = 120°-180°
  212     switch(Ordering)
  213     {
  214         case 100 : return "Front: C";
  215         case 101 : return "Front: L R";
  216         case 102 : return "Front: L R (Headphones)"; //With headphones
  217         case 103 : return "Front: L R (Matrix)"; //With matrix
  218         case 104 : return "Front: C S";
  219         case 105 : return "Front: X Y";
  220         case 106 : return "Front: L R (Binaural)";
  221         case 107 : return "Front: W X Y Z";
  222         case 108 : return "Front: L R, Side: L R";
  223         case 109 : return "Front: L C R, Rear: L R";
  224         case 110 : return "Front: L C R, Rear: L C R";
  225         case 111 : return "Front: L C R, Side: L R, Rear: L C R";
  226         case 112 : return "Front: L R, TopFront: L R, Rear: L R, TopRear: L R";
  227         case 113 : return "Front: L C R";
  228         case 114 : return "Front: L C R";
  229         case 115 : return "Front: L C R, Rear: C";
  230         case 116 : return "Front: L C R, Rear: C";
  231         case 117 : return "Front: L C R, Side: L R";
  232         case 118 : return "Front: L C R, Side: L R";
  233         case 119 : return "Front: L C R, Side: L R";
  234         case 120 : return "Front: L C R, Side: L R";
  235         case 121 : return "Front: L C R, Side: L R, LFE";
  236         case 122 : return "Front: L C R, Side: L R, LFE";
  237         case 123 : return "Front: L C R, Side: L R, LFE";
  238         case 124 : return "Front: L C R, Side: L R, LFE";
  239         case 125 : return "Front: L C R, Side: L C R";
  240         case 126 : return "Front: L Lc C Rc R, Side: L R";
  241         case 127 : return "Front: L Lc Rc R, Side: L R, LFE";
  242         case 128 : return "Front: L C R, Side: L R, Rear: L R, LFE";
  243         case 129 : return "Front: L C R, Side: L R, Rear: L R, LFE";
  244         case 130 : return "Front: L C R, Side: L R, LF, Front: L R (Matrix)";
  245         case 131 : return "Front: L R, Rear: C";
  246         case 132 : return "Front: L R, Side: L R";
  247         case 133 : return "Front: L R, LFE";
  248         case 134 : return "Front: L R, Rear: C, LFE";
  249         case 135 : return "Front: L C R, Side: L R, LFE";
  250         case 136 : return "Front: L C R, LFE";
  251         case 137 : return "Front: L C R, Rear: C, LFE";
  252         case 138 : return "Front: L R, Rear: L R, LFE";
  253         case 139 : return "Front: L C R, Rear: L R, LFE";
  254         case 140 : return "Front: L C R, Side: L R, Rear: L R";
  255         case 141 : return "Front: L C R, Side: L R, Rear: C";
  256         case 142 : return "Front: L C R, Side: L R, Rear: C, LFE";
  257         case 143 : return "Front: L C R, Side: L R, Rear: L R";
  258         case 144 : return "Front: L C R, Side: L R, Rear: L C R";
  259         case 145 : return "Front: Lw L C R Rw, TopFront: L C R, Side: L R, Rear: L C Cd R, LFE: L R"; //d=direct, all must be confirmed
  260         case 146 : return "Front: Lw L Lc C Rc R Rw, TopFront: L C R, Side: L R, Rear: L C Cd R, LFE: L R, HI, VI, Haptic"; //d=direct, all must be confirmed
  261         default  : return "";
  262     }
  263 }
  264 
  265 //---------------------------------------------------------------------------
  266 const char* Mpeg4_chan_Layout(int16u Ordering)
  267 {
  268     //Source: http://developer.apple.com/library/mac/#documentation/MusicAudio/Reference/CACoreAudioReference/CoreAudioTypes/CompositePage.html
  269     // L - left
  270     // R - right
  271     // C - center
  272     // Ls - left surround
  273     // Rs - right surround
  274     // Cs - center surround
  275     // Rls - rear left surround
  276     // Rrs - rear right surround
  277     // Lw - left wide
  278     // Rw - right wide
  279     // Lsd - left surround direct
  280     // Rsd - right surround direct
  281     // Lc - left center
  282     // Rc - right center
  283     // Ts - top surround
  284     // Vhl - vertical height left
  285     // Vhc - vertical height center
  286     // Vhr - vertical height right
  287     // Lt - left matrix total. for matrix encoded stereo.
  288     // Rt - right matrix total. for matrix encoded stereo.
  289     switch(Ordering)
  290     {
  291         case 100 : return "C";
  292         case 101 : return "L R";
  293         case 102 : return "L R"; //With headphones
  294         case 103 : return "Lt Rt"; //L R with matrix
  295         case 104 : return "M S";
  296         case 105 : return "X Y";
  297         case 106 : return "L R";
  298         case 107 : return "W X Y Z";
  299         case 108 : return "L R Ls Rs";
  300         case 109 : return "L R Lrs Rrs C";
  301         case 110 : return "L R Lrs Rrs C Cs";
  302         case 111 : return "L R Lrs Rrs C Crs, Ls, Rs";
  303         case 112 : return "L R Lrs Rrs Vhl Vhr, Vhlrs, Vhrrs";
  304         case 113 : return "L R C";
  305         case 114 : return "C L R";
  306         case 115 : return "L R C Cs";
  307         case 116 : return "C L R Cs";
  308         case 117 : return "L R C Ls Rs";
  309         case 118 : return "L R Ls Rs C";
  310         case 119 : return "L C R Ls Rs";
  311         case 120 : return "C L R Ls Rs";
  312         case 121 : return "L R C LFE Ls Rs";
  313         case 122 : return "L R Ls Rs C LFE";
  314         case 123 : return "L C R Ls Rs LFE";
  315         case 124 : return "C L R Ls Rs LFE";
  316         case 125 : return "L R C LFE Ls Rs Cs";
  317         case 126 : return "L R C LFE Ls Rs Lc Rc";
  318         case 127 : return "C Lc Rc L R Ls Rs LFE";
  319         case 128 : return "L R C LFE Ls R Rls Rrs";
  320         case 129 : return "L R Ls Rs C LFE Lc Rc";
  321         case 130 : return "L R C LFE Ls Rs Lt Rt";
  322         case 131 : return "L R Cs";
  323         case 132 : return "L R Ls Rs";
  324         case 133 : return "L R LFE";
  325         case 134 : return "L R LFE Cs";
  326         case 135 : return "L R LFE Ls Rs";
  327         case 136 : return "L R C LFE";
  328         case 137 : return "L R C LFE Cs";
  329         case 138 : return "L R Ls Rs LFE";
  330         case 139 : return "L R Ls Rs C Cs";
  331         case 140 : return "L R Ls Rs C Rls Rrs";
  332         case 141 : return "C L R Ls Rs Cs ";
  333         case 142 : return "C L R Ls Rs Cs LFE";
  334         case 143 : return "C L R Ls Rs Rls Rrs";
  335         case 144 : return "C L R Ls Rs Rls Rrs Cs";
  336         case 145 : return "L R C Vhc Lsd Rsd Ls Rs Vhl Vhr Lw Rw Csd Cs LFE1 LFE2";
  337         case 146 : return "L R C Vhc Lsd Rsd Ls Rs Vhl Vhr Lw Rw Csd Cs LFE1 LFE2 Lc Rc HI VI Haptic";
  338         case 147 : return "";
  339         default  : return "";
  340     }
  341 }
  342 
  343 //---------------------------------------------------------------------------
  344 static std::string Mpeg4_chan_ChannelDescription (int64u ChannelLabels)
  345 {
  346     std::string Text;
  347     if ((ChannelLabels&0x000E)!=0x0000)
  348         Text+="Front:";
  349     if (ChannelLabels&0x0002)
  350         Text+=" L";
  351     if (ChannelLabels&0x0008)
  352         Text+=" C";
  353     if (ChannelLabels&0x0004)
  354         Text+=" R";
  355 
  356     if ((ChannelLabels&0x0C00)!=0x0000)
  357     {
  358         if (!Text.empty())
  359             Text+=", ";
  360         Text+="Side:";
  361     }
  362     if (ChannelLabels&0x0400)
  363         Text+=" L";
  364     if (ChannelLabels&0x0800)
  365         Text+=" R";
  366 
  367     if ((ChannelLabels&0x0260)!=0x0000)
  368     {
  369         if (!Text.empty())
  370             Text+=", ";
  371         Text+="Back:";
  372     }
  373     if (ChannelLabels&0x0020)
  374         Text+=" L";
  375     if (ChannelLabels&0x0200)
  376         Text+=" C";
  377     if (ChannelLabels&0x0040)
  378         Text+=" R";
  379 
  380     if ((ChannelLabels&0x0010)!=0x0000)
  381     {
  382         if (!Text.empty())
  383             Text+=", ";
  384         Text+="LFE";
  385     }
  386 
  387     if (ChannelLabels&0x000000C000000000LL)
  388     {
  389         if (!Text.empty())
  390             Text+=", ";
  391         Text+="Front:";
  392     }
  393     if (ChannelLabels&0x0000004000000000LL)
  394         Text+=" L";
  395     if (ChannelLabels&0x0000008000000000LL)
  396         Text+=" R";
  397     if (ChannelLabels&0x000000C000000000LL)
  398         Text+=" (Matrix)";
  399 
  400     return Text;
  401 }
  402 
  403 //---------------------------------------------------------------------------
  404 static const char* Mpeg4_chan_ChannelDescription_Layout (int32u ChannelLabel)
  405 {
  406     switch(ChannelLabel)
  407     {
  408         case   1 : return "L";
  409         case   2 : return "R";
  410         case   3 : return "C";
  411         case   4 : return "LFE";
  412         case   5 : return "Ls";
  413         case   6 : return "Rs";
  414         case   7 : return "Lc";
  415         case   8 : return "Rc";
  416         case   9 : return "Cs";
  417         case  10 : return "Lsd";
  418         case  11 : return "Rsd";
  419         case  12 : return "Tcs";
  420         case  13 : return "Vhl";
  421         case  14 : return "Vhc";
  422         case  15 : return "Vhr";
  423         case  16 : return "Trs";
  424         case  17 : return "Trs";
  425         case  18 : return "Trs";
  426         case  33 : return "Lrs";
  427         case  34 : return "Rrs";
  428         case  35 : return "Lw";
  429         case  36 : return "Rw";
  430         case  37 : return "LFE2";
  431         case  38 : return "Lt";
  432         case  39 : return "Rt";
  433         case 200 : return "W";
  434         case 201 : return "X";
  435         case 202 : return "Y";
  436         case 203 : return "Z";
  437         case 204 : return "M";
  438         case 205 : return "S";
  439         case 206 : return "X";
  440         case 207 : return "Y";
  441         case 0x10000 : return "Discrete-0";
  442         case 0x10001 : return "Discrete-1";
  443         case 0x10002 : return "Discrete-2";
  444         case 0x10003 : return "Discrete-3";
  445         case 0x10004 : return "Discrete-4";
  446         case 0x10005 : return "Discrete-5";
  447         case 0x10006 : return "Discrete-6";
  448         case 0x10007 : return "Discrete-7";
  449         case 0x10008 : return "Discrete-8";
  450         case 0x10009 : return "Discrete-9";
  451         case 0x1000A : return "Discrete-10";
  452         case 0x1000B : return "Discrete-11";
  453         case 0x1000C : return "Discrete-12";
  454         case 0x1000D : return "Discrete-13";
  455         case 0x1000E : return "Discrete-14";
  456         case 0x1000F : return "Discrete-15";
  457         default  : return "?";
  458     }
  459 }
  460 
  461 //---------------------------------------------------------------------------
  462 static std::string Mpeg4_chan_ChannelBitmap (int32u ChannelBitmap)
  463 {
  464     std::string Text;
  465     if ((ChannelBitmap&0x0007)!=0x0000)
  466         Text+="Front:";
  467     if (ChannelBitmap&0x0001)
  468         Text+=" L";
  469     if (ChannelBitmap&0x0004)
  470         Text+=" C";
  471     if (ChannelBitmap&0x0002)
  472         Text+=" R";
  473 
  474     if ((ChannelBitmap&0x0600)!=0x0000)
  475         Text+=", Side:";
  476     if (ChannelBitmap&0x0200)
  477         Text+=" L";
  478     if (ChannelBitmap&0x0400)
  479         Text+=" R";
  480 
  481     if ((ChannelBitmap&0x0130)!=0x0000)
  482         Text+=", Back:";
  483     if (ChannelBitmap&0x0010)
  484         Text+=" L";
  485     if (ChannelBitmap&0x0100)
  486         Text+=" C";
  487     if (ChannelBitmap&0x0020)
  488         Text+=" R";
  489 
  490     if ((ChannelBitmap&0x0008)!=0x0000)
  491         Text+=", LFE";
  492 
  493     return Text;
  494 }
  495 
  496 //---------------------------------------------------------------------------
  497 static const char* Mpeg4_chan_ChannelBitmap_Layout (int32u ChannelBitmap)
  498 {
  499     switch(ChannelBitmap)
  500     {
  501         case   0 : return "L";      // Left
  502         case   1 : return "R";      // Right
  503         case   2 : return "C";      // Center
  504         case   3 : return "LFE";    // LFEScreen
  505         case   4 : return "Ls";     // LeftSurround / Back Left
  506         case   5 : return "Rs";     // RightSurround / Back Right
  507         case   6 : return "?";      // LeftCenter
  508         case   7 : return "?";      // RightCenter
  509         case   8 : return "Cs";     // CenterSurround / Back Center
  510         case   9 : return "Lsd";    // LeftSurroundDirect / Side Left
  511         case  10 : return "Rsd";    // RightSurroundDirect / Side Right
  512         case  11 : return "?";      // TopCenterSurround
  513         case  12 : return "?";      // VerticalHeightLeft / Top Front Left
  514         case  13 : return "?";      // VerticalHeightCenter / Top Front Center
  515         case  14 : return "?";      // VerticalHeightRight / Top Front Right"
  516         case  15 : return "?";      // TopBackLeft
  517         case  16 : return "?";      // TopBackCenter
  518         case  17 : return "?";      // TopBackRight
  519         default  : return "?";
  520     }
  521 }
  522 
  523 //---------------------------------------------------------------------------
  524 static const char* Mpeg4_jp2h_METH(int8u METH)
  525 {
  526     switch (METH)
  527     {
  528         case 0x01 : return "Enumerated colourspace";
  529         case 0x02 : return "Restricted ICC profile";
  530         default   : return "";
  531     }
  532 }
  533 
  534 //---------------------------------------------------------------------------
  535 static const char* Mpeg4_jp2h_EnumCS(int32u EnumCS)
  536 {
  537     switch (EnumCS)
  538     {
  539         case 0x10 : return "RGB"; //sRGB
  540         case 0x11 : return "Y";
  541         case 0x12 : return "YUV"; //sYUV
  542         default   : return "";
  543     }
  544 }
  545 
  546 //---------------------------------------------------------------------------
  547 const char* Mpegv_colour_primaries(int8u colour_primaries);
  548 const char* Mpegv_transfer_characteristics(int8u transfer_characteristics);
  549 const char* Mpegv_matrix_coefficients(int8u matrix_coefficients);
  550 const char* Mpegv_matrix_coefficients_ColorSpace(int8u matrix_coefficients);
  551 
  552 //---------------------------------------------------------------------------
  553 // DTS
  554 #if defined(MEDIAINFO_DTS_YES)
  555     extern const char*  DTS_ChannelPositions[16];
  556     extern const char*  DTS_ChannelPositions2[16];
  557     extern std::string DTS_HD_SpeakerActivityMask (int16u SpeakerActivityMask, bool AddCs=false, bool AddLrsRrs=false);
  558     extern std::string DTS_HD_SpeakerActivityMask2 (int16u SpeakerActivityMask, bool AddCs=false, bool AddLrsRrs=false);
  559 #endif //defined(MEDIAINFO_DTS_YES)
  560 
  561 //---------------------------------------------------------------------------
  562 int8u File_Mpeg4_PcmSampleSizeFromCodecID(int32u CodecID)
  563 {
  564     switch (CodecID)
  565     {
  566         case 0x72617720:
  567             return 8;
  568         case 0x00000000:
  569         case 0x4E4F4E45:
  570         case 0x74776F73:
  571         case 0x736F7774:
  572             return 16;
  573         case 0x696E3234:
  574             return 24;
  575         case 0x666C3332:
  576         case 0x696E3332:
  577             return 32;
  578         case 0x666C3634:
  579         case 0x696E3634:
  580             return 64;
  581         default:
  582             return 0;
  583     }
  584 }
  585 
  586 //***************************************************************************
  587 // Constants
  588 //***************************************************************************
  589 
  590 //---------------------------------------------------------------------------
  591 namespace Elements
  592 {
  593     const int64u bloc=0x626C6F63;
  594     const int64u cdat=0x63646174;
  595     const int64u cdt2=0x63647432;
  596     const int64u free=0x66726565;
  597     const int64u ftyp=0x66747970;
  598     const int64u ftyp_qt=0x71742020;
  599     const int64u ftyp_dash=0x64617368;
  600     const int64u ftyp_isom=0x69736F6D;
  601     const int64u ftyp_caqv=0x63617176;
  602     const int64u idat=0x69646174;
  603     const int64u idsc=0x69647363;
  604     const int64u jp2c=0x6A703263;
  605     const int64u jp2h=0x6A703268;
  606     const int64u jp2h_ihdr=0x69686472;
  607     const int64u jp2h_colr=0x636F6C72;
  608     const int64u mdat=0x6D646174;
  609     const int64u meta=0x6D657461;
  610     const int64u meta_grpl=0x6772706C;
  611     const int64u meta_hdlr=0x68646C72;
  612     const int64u meta_idat=0x69646174;
  613     const int64u meta_iinf=0x69696E66;
  614     const int64u meta_iinf_infe=0x696E6665;
  615     const int64u meta_iloc=0x696C6F63;
  616     const int64u meta_iprp=0x69707270;
  617     const int64u meta_iprp_ipco=0x6970636F;
  618     const int64u meta_iprp_ipco_av1C=0x61763143;
  619     const int64u meta_iprp_ipco_auxC=0x61757843;
  620     const int64u meta_iprp_ipco_avcC=0x61766343;
  621     const int64u meta_iprp_ipco_clap=0x636C6170;
  622     const int64u meta_iprp_ipco_clli=0x636C6C69;
  623     const int64u meta_iprp_ipco_colr=0x636F6C72;
  624     const int64u meta_iprp_ipco_hvcC=0x68766343;
  625     const int64u meta_iprp_ipco_imir=0x696D6972;
  626     const int64u meta_iprp_ipco_irot=0x69726F74;
  627     const int64u meta_iprp_ipco_ispe=0x69737065;
  628     const int64u meta_iprp_ipco_mdcv=0x6D646376;
  629     const int64u meta_iprp_ipco_pasp=0x70617370;
  630     const int64u meta_iprp_ipco_pixi=0x70697869;
  631     const int64u meta_iprp_ipco_rloc=0x726C6F63;
  632     const int64u meta_iprp_ipma=0x69706D61;
  633     const int64u meta_iref=0x69726566;
  634     const int64u meta_pitm=0x7069746D;
  635     const int64u mfra=0x6D667261;
  636     const int64u mfra_mfro=0x6D66726F;
  637     const int64u mfra_tfra=0x74667261;
  638     const int64u moof=0x6D6F6F66;
  639     const int64u moof_mfhd=0x6D666864;
  640     const int64u moof_traf=0x74726166;
  641     const int64u moof_traf_sdtp=0x73647470;
  642     const int64u moof_traf_tfhd=0x74666864;
  643     const int64u moof_traf_trun=0x7472756E;
  644     const int64u moov=0x6D6F6F76;
  645     const int64u moov_ainf=0x61696E66;
  646     const int64u moov_cmov=0x636D6F76;
  647     const int64u moov_cmov_cmvd=0x636D7664;
  648     const int64u moov_cmov_dcom=0x64636F6D;
  649     const int64u moov_cmov_dcom_zlib=0x7A6C6962;
  650     const int64u moov_ctab=0x63746162;
  651     const int64u moov_iods=0x696F6473;
  652     const int64u moov_meta=0x6D657461;
  653     const int64u moov_meta______=0x2D2D2D2D;
  654     const int64u moov_meta___day=0xA9646179;
  655     const int64u moov_meta__disk=0x6469736B;
  656     const int64u moov_meta__trkn=0x74726B6E;
  657     const int64u moov_meta__trng=0x74726E67;
  658     const int64u moov_meta__covr=0x636F7672;
  659     const int64u moov_meta__gnre=0x676E7265;
  660     const int64u moov_meta_bxml=0x62786D6C;
  661     const int64u moov_meta_hdlr=0x68646C72;
  662     const int64u moov_meta_hdlr_mdir=0x6D646972;
  663     const int64u moov_meta_hdlr_mdta=0x6D647461;
  664     const int64u moov_meta_hdlr_mp7b=0x6D703762;
  665     const int64u moov_meta_hdlr_mp7t=0x6D703774;
  666     const int64u moov_meta_keys=0x6B657973;
  667     const int64u moov_meta_keys_mdta=0x6D647461;
  668     const int64u moov_meta_ilst=0x696C7374;
  669     const int64u moov_meta_ilst_xxxx_data=0x64617461;
  670     const int64u moov_meta_ilst_xxxx_mean=0x6D65616E;
  671     const int64u moov_meta_ilst_xxxx_name=0x6E616D65;
  672     const int64u moov_meta_xml=0x786D6C20;
  673     const int64u moov_mvex=0x6D766578;
  674     const int64u moov_mvex_mehd=0x6D656864;
  675     const int64u moov_mvex_trex=0x74726578;
  676     const int64u moov_mvhd=0x6D766864;
  677     const int64u moov_trak=0x7472616B;
  678     const int64u moov_trak_edts=0x65647473;
  679     const int64u moov_trak_edts_elst=0x656C7374;
  680     const int64u moov_trak_load=0x6C6F6164;
  681     const int64u moov_trak_mdia=0x6D646961;
  682     const int64u moov_trak_mdia_hdlr=0x68646C72;
  683     const int64u moov_trak_mdia_hdlr_alis=0x616C6973;
  684     const int64u moov_trak_mdia_hdlr_clcp=0x636C6370;
  685     const int64u moov_trak_mdia_hdlr_data=0x64617461;
  686     const int64u moov_trak_mdia_hdlr_hint=0x68696E74;
  687     const int64u moov_trak_mdia_hdlr_MPEG=0x4D504547;
  688     const int64u moov_trak_mdia_hdlr_ocsm=0x6F63736D;
  689     const int64u moov_trak_mdia_hdlr_odsm=0x6F64736D;
  690     const int64u moov_trak_mdia_hdlr_sbtl=0x7362746C;
  691     const int64u moov_trak_mdia_hdlr_sdsm=0x7364736D;
  692     const int64u moov_trak_mdia_hdlr_soun=0x736F756E;
  693     const int64u moov_trak_mdia_hdlr_subt=0x73756274;
  694     const int64u moov_trak_mdia_hdlr_subp=0x73756270;
  695     const int64u moov_trak_mdia_hdlr_text=0x74657874;
  696     const int64u moov_trak_mdia_hdlr_twen=0x7477656E;
  697     const int64u moov_trak_mdia_hdlr_tmcd=0x746D6364;
  698     const int64u moov_trak_mdia_hdlr_vide=0x76696465;
  699     const int64u moov_trak_mdia_imap=0x696D6170;
  700     const int64u moov_trak_mdia_imap_sean=0x7365616E;
  701     const int64u moov_trak_mdia_imap_sean___in=0x0000696E;
  702     const int64u moov_trak_mdia_imap_sean___in___ty=0x00007479;
  703     const int64u moov_trak_mdia_imap_sean___in_dtst=0x64747374;
  704     const int64u moov_trak_mdia_imap_sean___in_obid=0x6F626964;
  705     const int64u moov_trak_mdia_mdhd=0x6D646864;
  706     const int64u moov_trak_mdia_minf=0x6D696E66;
  707     const int64u moov_trak_mdia_minf_code=0x636F6465;
  708     const int64u moov_trak_mdia_minf_code_sean=0x7365616E;
  709     const int64u moov_trak_mdia_minf_code_sean_RU_A=0x52552A41;
  710     const int64u moov_trak_mdia_minf_dinf=0x64696E66;
  711     const int64u moov_trak_mdia_minf_dinf_url_=0x75726C20;
  712     const int64u moov_trak_mdia_minf_dinf_urn_=0x75726E20;
  713     const int64u moov_trak_mdia_minf_dinf_dref=0x64726566;
  714     const int64u moov_trak_mdia_minf_dinf_dref_alis=0x616C6973;
  715     const int64u moov_trak_mdia_minf_dinf_dref_rsrc=0x72737263;
  716     const int64u moov_trak_mdia_minf_dinf_dref_url_=0x75726C20;
  717     const int64u moov_trak_mdia_minf_dinf_derf_urn_=0x75726E20;
  718     const int64u moov_trak_mdia_minf_gmhd=0x676D6864;
  719     const int64u moov_trak_mdia_minf_gmhd_gmin=0x676D696E;
  720     const int64u moov_trak_mdia_minf_gmhd_tmcd=0x746D6364;
  721     const int64u moov_trak_mdia_minf_gmhd_tmcd_tcmi=0x74636D69;
  722     const int64u moov_trak_mdia_minf_gmhd_tcmi=0x74636D69;
  723     const int64u moov_trak_mdia_minf_hint=0x68696E74;
  724     const int64u moov_trak_mdia_minf_hdlr=0x68646C72;
  725     const int64u moov_trak_mdia_minf_hmhd=0x686D6864;
  726     const int64u moov_trak_mdia_minf_nmhd=0x6E6D6864;
  727     const int64u moov_trak_mdia_minf_smhd=0x736D6864;
  728     const int64u moov_trak_mdia_minf_stbl=0x7374626C;
  729     const int64u moov_trak_mdia_minf_stbl_co64=0x636F3634;
  730     const int64u moov_trak_mdia_minf_stbl_cslg=0x63736C67;
  731     const int64u moov_trak_mdia_minf_stbl_ctts=0x63747473;
  732     const int64u moov_trak_mdia_minf_stbl_sdtp=0x73647470;
  733     const int64u moov_trak_mdia_minf_stbl_stco=0x7374636F;
  734     const int64u moov_trak_mdia_minf_stbl_stdp=0x73746470;
  735     const int64u moov_trak_mdia_minf_stbl_stps=0x73747073;
  736     const int64u moov_trak_mdia_minf_stbl_stsc=0x73747363;
  737     const int64u moov_trak_mdia_minf_stbl_stsd=0x73747364;
  738     const int64u moov_trak_mdia_minf_stbl_stsd_alac=0x616C6163;
  739     const int64u moov_trak_mdia_minf_stbl_stsd_mp4a=0x6D703461;
  740     const int64u moov_trak_mdia_minf_stbl_stsd_mp4s=0x6D703473;
  741     const int64u moov_trak_mdia_minf_stbl_stsd_mp4v=0x6D703476;
  742     const int64u moov_trak_mdia_minf_stbl_stsd_stpp=0x73747070;
  743     const int64u moov_trak_mdia_minf_stbl_stsd_stpp_btrt=0x62747274;
  744     const int64u moov_trak_mdia_minf_stbl_stsd_text=0x74657874;
  745     const int64u moov_trak_mdia_minf_stbl_stsd_tmcd=0x746D6364;
  746     const int64u moov_trak_mdia_minf_stbl_stsd_tmcd_name=0x6E616D65;
  747     const int64u moov_trak_mdia_minf_stbl_stsd_tx3g=0x74783367;
  748     const int64u moov_trak_mdia_minf_stbl_stsd_tx3g_ftab=0x66746162;
  749     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_alac=0x616C6163;
  750     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_AALP=0x41414C50;
  751     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_ACLR=0x41434C52;
  752     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_APRG=0x41505247;
  753     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_ARES=0x41524553;
  754     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_AORD=0x414F5244;
  755     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_av1C=0x61763143;
  756     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_avcC=0x61766343;
  757     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_avcE=0x61766345;
  758     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_bitr=0x62697472;
  759     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_btrt=0x62747274;
  760     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_ccst=0x63637374;
  761     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_clap=0x636C6170;
  762     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_chan=0x6368616E;
  763     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_clli=0x636C6C69;
  764     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_colr=0x636F6C72;
  765     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_colr_clcn=0x636C636E;
  766     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_colr_nclc=0x6E636C63;
  767     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_colr_prof=0x70726F66;
  768     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_d263=0x64323633;
  769     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_dac3=0x64616333;
  770     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_dac4=0x64616334;
  771     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_damr=0x64616D72;
  772     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_dec3=0x64656333;
  773     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_ddts=0x64647473;
  774     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_dvc1=0x64766331;
  775     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_dvcC=0x64766343;
  776     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_dvvC=0x64767643;
  777     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_esds=0x65736473;
  778     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_fiel=0x6669656C;
  779     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_glbl=0x676C626C;
  780     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_hvcC=0x68766343;
  781     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_hvcE=0x68766345;
  782     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_idfm=0x6964666D;
  783     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_atom=0x61746F6D;
  784     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_qtat=0x71746174;
  785     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_fxat=0x66786174;
  786     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_priv=0x70726976;
  787     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_subs=0x73756273;
  788     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_cspc=0x63737063;
  789     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_jp2h=0x6A703268;
  790     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_jp2h_colr=0x636F6C72;
  791     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_jp2h_ihdr=0x69686472;
  792     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_mdcv=0x6D646376;
  793     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_pasp=0x70617370;
  794     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_SA3D=0x53413344;
  795     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_sinf=0x73696E66;
  796     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_frma=0x66726D61;
  797     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_imif=0x696D6966;
  798     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_schi=0x73636869;
  799     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_schm=0x7363686D;
  800     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_wave=0x77617665;
  801     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_wave_acbf=0x61636266;
  802     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_wave_enda=0x656E6461;
  803     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_wave_frma=0x66726D61;
  804     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_wave_samr=0x73616D72;
  805     const int64u moov_trak_mdia_minf_stbl_stsd_xxxx_wave_srcq=0x73726371;
  806     const int64u moov_trak_mdia_minf_stbl_stsh=0x73747368;
  807     const int64u moov_trak_mdia_minf_stbl_stss=0x73747373;
  808     const int64u moov_trak_mdia_minf_stbl_stsz=0x7374737A;
  809     const int64u moov_trak_mdia_minf_stbl_stts=0x73747473;
  810     const int64u moov_trak_mdia_minf_stbl_stz2=0x73747A32;
  811     const int64u moov_trak_mdia_minf_sthd=0x73746864;
  812     const int64u moov_trak_mdia_minf_vmhd=0x766D6864;
  813     const int64u moov_trak_meta=0x6D657461;
  814     const int64u moov_trak_meta______=0x2D2D2D2D;
  815     const int64u moov_trak_meta___day=0xA9646179;
  816     const int64u moov_trak_meta__disk=0x6469736B;
  817     const int64u moov_trak_meta__trkn=0x74726B6E;
  818     const int64u moov_trak_meta__trng=0x74726E67;
  819     const int64u moov_trak_meta__covr=0x636F7672;
  820     const int64u moov_trak_meta__gnre=0x676E7265;
  821     const int64u moov_trak_meta_bxml=0x62786D6C;
  822     const int64u moov_trak_meta_hdlr=0x68646C72;
  823     const int64u moov_trak_meta_hdlr_mdir=0x6D646972;
  824     const int64u moov_trak_meta_hdlr_mdta=0x6D647461;
  825     const int64u moov_trak_meta_hdlr_mp7b=0x6D703762;
  826     const int64u moov_trak_meta_hdlr_mp7t=0x6D703774;
  827     const int64u moov_trak_meta_keys=0x6B657973;
  828     const int64u moov_trak_meta_keys_mdta=0x6D647461;
  829     const int64u moov_trak_meta_ilst=0x696C7374;
  830     const int64u moov_trak_meta_ilst_xxxx_data=0x64617461;
  831     const int64u moov_trak_meta_ilst_xxxx_mean=0x6D65616E;
  832     const int64u moov_trak_meta_ilst_xxxx_name=0x6E616D65;
  833     const int64u moov_trak_meta_xml=0x786D6C20;
  834     const int64u moov_trak_tapt=0x74617074;
  835     const int64u moov_trak_tapt_clef=0x636C6566;
  836     const int64u moov_trak_tapt_enof=0x656E6F66;
  837     const int64u moov_trak_tapt_prof=0x70726F66;
  838     const int64u moov_trak_tkhd=0x746B6864;
  839     const int64u moov_trak_txas=0x74786173;
  840     const int64u moov_trak_tref=0x74726566;
  841     const int64u moov_trak_tref_dpnd=0x64706E64;
  842     const int64u moov_trak_tref_chap=0x63686170;
  843     const int64u moov_trak_tref_clcp=0x636C6370;
  844     const int64u moov_trak_tref_fall=0x66616C6C;
  845     const int64u moov_trak_tref_folw=0x666F6C77;
  846     const int64u moov_trak_tref_forc=0x666F7263;
  847     const int64u moov_trak_tref_hint=0x68696E74;
  848     const int64u moov_trak_tref_ipir=0x69706972;
  849     const int64u moov_trak_tref_mpod=0x6D706F64;
  850     const int64u moov_trak_tref_scpt=0x73637074;
  851     const int64u moov_trak_tref_ssrc=0x73737263;
  852     const int64u moov_trak_tref_sync=0x73796E63;
  853     const int64u moov_trak_tref_thmb=0x74686D62;
  854     const int64u moov_trak_tref_tmcd=0x746D6364;
  855     const int64u moov_trak_tref_vdep=0x76646570;
  856     const int64u moov_trak_udta=0x75647461;
  857     const int64u moov_udta=0x75647461;
  858     const int64u moov_udta_AllF=0x416C6C46;
  859     const int64u moov_udta_chpl=0x6368706C;
  860     const int64u moov_udta_clsf=0x636C7366;
  861     const int64u moov_udta_DcMD=0x44634D44;
  862     const int64u moov_udta_DcMD_Cmbo=0x436D626F;
  863     const int64u moov_udta_DcMD_DcME=0x44634D45;
  864     const int64u moov_udta_DcMD_DcME_Keyw=0x4B657977;
  865     const int64u moov_udta_DcMD_DcME_Mtmd=0x4D746D64;
  866     const int64u moov_udta_DcMD_DcME_Rate=0x52617465;
  867     const int64u moov_udta_FIEL=0x4649454C;
  868     const int64u moov_udta_FXTC=0x46585443;
  869     const int64u moov_udta_hinf=0x68696E66;
  870     const int64u moov_udta_hinv=0x68696E76;
  871     const int64u moov_udta_hnti=0x686E7469;
  872     const int64u moov_udta_hnti_rtp=0x72747020;
  873     const int64u moov_udta_ID32=0x49443332;
  874     const int64u moov_udta_kywd=0x6B797764;
  875     const int64u moov_udta_loci=0x6C6F6369;
  876     const int64u moov_udta_LOOP=0x4C4F4F50;
  877     const int64u moov_udta_MCPS=0x4D435053;
  878     const int64u moov_udta_meta=0x6D657461;
  879     const int64u moov_udta_meta_hdlr=0x68646C72;
  880     const int64u moov_udta_meta_ilst=0x696C7374;
  881     const int64u moov_udta_meta_ilst_xxxx_data=0x64617461;
  882     const int64u moov_udta_meta_ilst_xxxx_mean=0x6D65616E;
  883     const int64u moov_udta_meta_ilst_xxxx_name=0x6E616D65;
  884     const int64u moov_udta_meta_uuid=0x75756964;
  885     const int64u moov_udta_ndrm=0x6E64726D;
  886     const int64u moov_udta_nsav=0x6E736176;
  887     const int64u moov_udta_ptv =0x70747620;
  888     const int64u moov_udta_rtng=0x72746E67;
  889     const int64u moov_udta_Sel0=0x53656C30;
  890     const int64u moov_udta_tags=0x74616773;
  891     const int64u moov_udta_tags_meta=0x6D657461;
  892     const int64u moov_udta_tags_tseg=0x74736567;
  893     const int64u moov_udta_tags_tseg_tshd=0x74736864;
  894     const int64u moov_udta_WLOC=0x574C4F43;
  895     const int64u moov_udta_XMP_=0x584D505F;
  896     const int64u moov_udta_yrrc=0x79727263;
  897     const int64u pdin=0x7064696E;
  898     const int64u PICT=0x50494354;
  899     const int64u pckg=0x70636B67;
  900     const int64u pnot=0x706E6F74;
  901     const int64u RDAO=0x5244414F;
  902     const int64u RDAS=0x52444153;
  903     const int64u RDVO=0x5244564F;
  904     const int64u RDVS=0x52445653;
  905     const int64u RED1=0x52454431;
  906     const int64u REDA=0x52454441;
  907     const int64u REDV=0x52454456;
  908     const int64u REOB=0x52454F42;
  909     const int64u skip=0x736B6970;
  910     const int64u wide=0x77696465;
  911 }
  912 
  913 //---------------------------------------------------------------------------
  914 static const char* Mpeg4_Description(int32u Description)
  915 {
  916     switch (Description)
  917     {
  918         case Elements::moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_atom : return "Classic atom structure";
  919         case Elements::moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_qtat : return "QT atom structure";
  920         case Elements::moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_fxat : return "Effect";
  921         case Elements::moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_priv : return "Private";
  922         case Elements::moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_subs : return "Substitute if main codec not available";
  923         case Elements::moov_trak_mdia_minf_stbl_stsd_xxxx_idfm_cspc : return "Native pixel format";
  924         default                                                     : return "";
  925     }
  926 }
  927 
  928 //***************************************************************************
  929 // Format
  930 //***************************************************************************
  931 
  932 //---------------------------------------------------------------------------
  933 void File_Mpeg4::Data_Parse()
  934 {
  935     //mdat
  936     if (IsParsing_mdat)
  937     {
  938         mdat_xxxx();
  939         return;
  940     }
  941 
  942     //Padding
  943     if (!Element_Code && !Element_Size)
  944         return;
  945 
  946     //Parsing
  947     DATA_BEGIN
  948     ATOM(bloc)
  949     ATOM(cdat)
  950     ATOM(cdt2)
  951     LIST_SKIP(free)
  952     ATOM(ftyp)
  953     ATOM(idat)
  954     ATOM(idsc)
  955     ATOM(jp2c)
  956     LIST(jp2h)
  957         ATOM_BEGIN
  958         ATOM(jp2h_colr)
  959         ATOM(jp2h_ihdr)
  960         ATOM_END
  961     LIST(mdat)
  962         ATOM_DEFAULT_ALONE(mdat_xxxx)
  963     LIST(meta)
  964         ATOM_BEGIN
  965         LIST(meta_grpl)
  966             ATOM_DEFAULT_ALONE (meta_grpl_xxxx)
  967         ATOM(meta_hdlr)
  968         ATOM(meta_idat)
  969         LIST(meta_iinf)
  970             ATOM_BEGIN
  971             ATOM(meta_iinf_infe)
  972             ATOM_END
  973         ATOM(meta_iloc)
  974         LIST(meta_iprp)
  975             ATOM_BEGIN
  976             LIST(meta_iprp_ipco)
  977                 ATOM_BEGIN
  978                 ATOM(meta_iprp_ipco_av1C)
  979                 ATOM(meta_iprp_ipco_auxC)
  980                 ATOM(meta_iprp_ipco_avcC)
  981                 ATOM(meta_iprp_ipco_clap)
  982                 ATOM(meta_iprp_ipco_clli)
  983                 ATOM(meta_iprp_ipco_colr)
  984                 ATOM(meta_iprp_ipco_hvcC)
  985                 ATOM(meta_iprp_ipco_ispe)
  986                 ATOM(meta_iprp_ipco_imir)
  987                 ATOM(meta_iprp_ipco_irot)
  988                 ATOM(meta_iprp_ipco_mdcv)
  989                 ATOM(meta_iprp_ipco_pasp)
  990                 ATOM(meta_iprp_ipco_pixi)
  991                 ATOM(meta_iprp_ipco_rloc)
  992                 ATOM_END
  993             ATOM(meta_iprp_ipma)
  994             ATOM_END
  995         LIST(meta_iref)
  996             ATOM_DEFAULT_ALONE (meta_iref_xxxx)
  997         ATOM(meta_pitm)
  998         ATOM_END
  999     LIST(mfra)
 1000         ATOM_BEGIN
 1001         ATOM(mfra_mfro)
 1002         ATOM(mfra_tfra)
 1003         ATOM_END
 1004     LIST(moof)
 1005         ATOM_BEGIN
 1006         ATOM(moof_mfhd)
 1007         LIST(moof_traf)
 1008             ATOM_BEGIN
 1009             ATOM(moof_traf_sdtp)
 1010             ATOM(moof_traf_tfhd)
 1011             ATOM(moof_traf_trun)
 1012             ATOM_END
 1013         ATOM_END
 1014     LIST(moov)
 1015         ATOM_BEGIN
 1016         ATOM(moov_ainf)
 1017         LIST(moov_cmov)
 1018             ATOM_BEGIN
 1019             ATOM(moov_cmov_dcom)
 1020             ATOM(moov_cmov_cmvd)
 1021             ATOM_END
 1022         ATOM(moov_ctab)
 1023         ATOM(moov_iods)
 1024         LIST(moov_meta)
 1025             ATOM_BEGIN
 1026             ATOM(moov_meta_bxml)
 1027             LIST(moov_meta_keys)
 1028                 ATOM_BEGIN
 1029                 ATOM(moov_meta_keys_mdta)
 1030                 ATOM_END
 1031             ATOM(moov_meta_hdlr)
 1032             LIST(moov_meta_ilst)
 1033                 LIST_DEFAULT_ALONE_BEGIN (moov_meta_ilst_xxxx)
 1034                     ATOM_BEGIN
 1035                     ATOM (moov_meta_ilst_xxxx_data)
 1036                     ATOM (moov_meta_ilst_xxxx_mean)
 1037                     ATOM (moov_meta_ilst_xxxx_name)
 1038                     ATOM_END
 1039                 LIST_DEFAULT_ALONE_END
 1040             ATOM(moov_meta_xml)
 1041             ATOM_END
 1042         LIST(moov_mvex)
 1043             ATOM_BEGIN
 1044             ATOM(moov_mvex_mehd)
 1045             ATOM(moov_mvex_trex)
 1046             ATOM_END
 1047         ATOM(moov_mvhd)
 1048         LIST(moov_trak)
 1049             ATOM_BEGIN
 1050             LIST(moov_trak_edts)
 1051                 ATOM_BEGIN
 1052                 ATOM(moov_trak_edts_elst)
 1053                 ATOM_END
 1054             ATOM(moov_trak_load)
 1055             LIST(moov_trak_mdia)
 1056                 ATOM_BEGIN
 1057                 ATOM(moov_trak_mdia_hdlr)
 1058                 LIST(moov_trak_mdia_imap)
 1059                     ATOM_BEGIN
 1060                     LIST(moov_trak_mdia_imap_sean)
 1061                         ATOM_BEGIN
 1062                         LIST(moov_trak_mdia_imap_sean___in)
 1063                             ATOM_BEGIN
 1064                             ATOM(moov_trak_mdia_imap_sean___in___ty)
 1065                             ATOM(moov_trak_mdia_imap_sean___in_dtst)
 1066                             ATOM(moov_trak_mdia_imap_sean___in_obid)
 1067                             ATOM_END
 1068                         ATOM_END
 1069                     ATOM_END
 1070                 ATOM(moov_trak_mdia_mdhd)
 1071                 LIST(moov_trak_mdia_minf)
 1072                     ATOM_BEGIN
 1073                     LIST(moov_trak_mdia_minf_code)
 1074                         ATOM_BEGIN
 1075                         LIST(moov_trak_mdia_minf_code_sean)
 1076                             ATOM_BEGIN
 1077                             ATOM(moov_trak_mdia_minf_code_sean_RU_A)
 1078                             ATOM_END
 1079                         ATOM_END
 1080                     LIST(moov_trak_mdia_minf_dinf)
 1081                         ATOM_BEGIN
 1082                         ATOM(moov_trak_mdia_minf_dinf_url_)
 1083                         ATOM(moov_trak_mdia_minf_dinf_urn_)
 1084                         LIST(moov_trak_mdia_minf_dinf_dref)
 1085                             ATOM_BEGIN
 1086                             ATOM(moov_trak_mdia_minf_dinf_dref_alis)
 1087                             ATOM(moov_trak_mdia_minf_dinf_dref_rsrc)
 1088                             ATOM(moov_trak_mdia_minf_dinf_url_)
 1089                             ATOM(moov_trak_mdia_minf_dinf_urn_)
 1090                             ATOM_END
 1091                         ATOM_END
 1092                     ATOM(moov_trak_mdia_minf_hdlr)
 1093                     LIST(moov_trak_mdia_minf_gmhd)
 1094                         ATOM_BEGIN
 1095                         ATOM(moov_trak_mdia_minf_gmhd_gmin)
 1096                         LIST(moov_trak_mdia_minf_gmhd_tmcd)
 1097                             ATOM_BEGIN
 1098                             ATOM(moov_trak_mdia_minf_gmhd_tmcd_tcmi)
 1099                             ATOM_END
 1100                         ATOM(moov_trak_mdia_minf_gmhd_tcmi)
 1101                         ATOM_END
 1102                     ATOM(moov_trak_mdia_minf_hint)
 1103                     ATOM(moov_trak_mdia_minf_hmhd)
 1104                     ATOM(moov_trak_mdia_minf_nmhd)
 1105                     ATOM(moov_trak_mdia_minf_smhd)
 1106                     LIST(moov_trak_mdia_minf_stbl)
 1107                         ATOM_BEGIN
 1108                         ATOM(moov_trak_mdia_minf_stbl_co64)
 1109                         ATOM(moov_trak_mdia_minf_stbl_cslg)
 1110                         ATOM(moov_trak_mdia_minf_stbl_ctts)
 1111                         ATOM(moov_trak_mdia_minf_stbl_sdtp)
 1112                         ATOM(moov_trak_mdia_minf_stbl_stco)
 1113                         ATOM(moov_trak_mdia_minf_stbl_stdp)
 1114                         ATOM(moov_trak_mdia_minf_stbl_stps)
 1115                         ATOM(moov_trak_mdia_minf_stbl_stsc)
 1116                         LIST(moov_trak_mdia_minf_stbl_stsd)
 1117                             ATOM_BEGIN
 1118                             LIST(moov_trak_mdia_minf_stbl_stsd_stpp)
 1119                                 ATOM_BEGIN
 1120                                 ATOM(moov_trak_mdia_minf_stbl_stsd_stpp_btrt)
 1121                                 ATOM_END
 1122                             ATOM(moov_trak_mdia_minf_stbl_stsd_text)
 1123                             LIST(moov_trak_mdia_minf_stbl_stsd_tmcd)
 1124                                 ATOM_BEGIN
 1125                                 ATOM(moov_trak_mdia_minf_stbl_stsd_tmcd_name)
 1126                                 ATOM_END
 1127                             LIST(moov_trak_mdia_minf_stbl_stsd_tx3g)
 1128                                 ATOM_BEGIN
 1129                                 ATOM(moov_trak_mdia_minf_stbl_stsd_tx3g_ftab)
 1130                                 ATOM_END
 1131                             LIST_DEFAULT(moov_trak_mdia_minf_stbl_stsd_xxxx)
 1132                                 ATOM_BEGIN
 1133                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_alac)
 1134                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_AALP)
 1135                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_ACLR)
 1136                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_APRG)
 1137                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_ARES)
 1138                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_AORD)
 1139                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_av1C)
 1140                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_avcC)
 1141                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_avcE)
 1142                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_bitr)
 1143                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_btrt)
 1144                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_ccst)
 1145                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_chan)
 1146                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_clap)
 1147                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_clli)
 1148                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_mdcv)
 1149                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_colr)
 1150                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_d263)
 1151                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_dac3)
 1152                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_dac4)
 1153                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_damr)
 1154                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_dec3)
 1155                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_ddts)
 1156                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_dvc1)
 1157                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_dvcC)
 1158                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_dvvC)
 1159                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_esds)
 1160                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_fiel)
 1161                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_glbl)
 1162                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_hvcC)
 1163                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_hvcE)
 1164                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_idfm)
 1165                                 LIST(moov_trak_mdia_minf_stbl_stsd_xxxx_jp2h)
 1166                                     ATOM_BEGIN
 1167                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_jp2h_colr)
 1168                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_jp2h_ihdr)
 1169                                     ATOM_END
 1170                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_pasp)
 1171                                 ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_SA3D)
 1172                                 LIST(moov_trak_mdia_minf_stbl_stsd_xxxx_sinf)
 1173                                     ATOM_BEGIN
 1174                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_frma)
 1175                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_imif)
 1176                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_schi)
 1177                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_sinf_schm)
 1178                                     ATOM_END
 1179                                 LIST(moov_trak_mdia_minf_stbl_stsd_xxxx_wave)
 1180                                     ATOM_BEGIN
 1181                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_esds)
 1182                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_wave_acbf)
 1183                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_wave_enda)
 1184                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_wave_frma)
 1185                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_wave_samr)
 1186                                     ATOM(moov_trak_mdia_minf_stbl_stsd_xxxx_wave_srcq)
 1187                                     ATOM_DEFAULT(moov_trak_mdia_minf_stbl_stsd_xxxx_wave_xxxx)
 1188                                     ATOM_END_DEFAULT
 1189                                 ATOM_END
 1190                             ATOM_END_DEFAULT
 1191                         ATOM(moov_trak_mdia_minf_stbl_stsh)
 1192                         ATOM(moov_trak_mdia_minf_stbl_stss)
 1193                         ATOM(moov_trak_mdia_minf_stbl_stsz)
 1194                         ATOM(moov_trak_mdia_minf_stbl_stts)
 1195                         ATOM(moov_trak_mdia_minf_stbl_stz2)
 1196                         ATOM_END
 1197                     ATOM(moov_trak_mdia_minf_sthd)
 1198                     ATOM(moov_trak_mdia_minf_vmhd)
 1199                     ATOM_END
 1200                 ATOM_END
 1201             /* Need additional tests
 1202             LIST(moov_trak_meta)
 1203                 ATOM_BEGIN
 1204                 ATOM(moov_trak_meta_bxml)
 1205                 LIST(moov_trak_meta_keys)
 1206                     ATOM_BEGIN
 1207                     ATOM(moov_trak_meta_keys_mdta)
 1208                     ATOM_END
 1209                 ATOM(moov_trak_meta_hdlr)
 1210                 LIST(moov_trak_meta_ilst)
 1211                     ATOM_BEGIN
 1212                     LIST_DEFAULT (moov_trak_meta_ilst_xxxx)
 1213                         ATOM_BEGIN
 1214                         ATOM (moov_trak_meta_ilst_xxxx_data)
 1215                         ATOM (moov_trak_meta_ilst_xxxx_mean)
 1216                         ATOM (moov_trak_meta_ilst_xxxx_name)
 1217                         ATOM_END
 1218                     ATOM_END_DEFAULT
 1219                 ATOM(moov_trak_meta_xml)
 1220                 ATOM_END
 1221             */
 1222             LIST(moov_trak_tapt)
 1223                 ATOM_BEGIN
 1224                 ATOM(moov_trak_tapt_clef)
 1225                 ATOM(moov_trak_tapt_prof)
 1226                 ATOM(moov_trak_tapt_enof)
 1227                 ATOM_END
 1228             ATOM(moov_trak_tkhd)
 1229             ATOM(moov_trak_txas)
 1230             LIST(moov_trak_tref)
 1231                 ATOM_BEGIN
 1232                 ATOM(moov_trak_tref_chap)
 1233                 ATOM(moov_trak_tref_clcp)
 1234                 ATOM(moov_trak_tref_dpnd)
 1235                 ATOM(moov_trak_tref_fall)
 1236                 ATOM(moov_trak_tref_folw)
 1237                 ATOM(moov_trak_tref_forc)
 1238                 ATOM(moov_trak_tref_ipir)
 1239                 ATOM(moov_trak_tref_hint)
 1240                 ATOM(moov_trak_tref_mpod)
 1241                 ATOM(moov_trak_tref_scpt)
 1242                 ATOM(moov_trak_tref_ssrc)
 1243                 ATOM(moov_trak_tref_sync)
 1244                 ATOM(moov_trak_tref_thmb)
 1245                 ATOM(moov_trak_tref_tmcd)
 1246                 ATOM(moov_trak_tref_vdep)
 1247                 ATOM_END
 1248             LIST(moov_trak_udta)
 1249                 ATOM_DEFAULT_ALONE (moov_trak_udta_xxxx);
 1250             ATOM_END
 1251         LIST(moov_udta)
 1252             ATOM_BEGIN
 1253             ATOM(moov_udta_AllF)
 1254             ATOM(moov_udta_chpl)
 1255             ATOM(moov_udta_clsf)
 1256             LIST(moov_udta_DcMD)
 1257                 ATOM_BEGIN
 1258                 ATOM(moov_udta_DcMD_Cmbo)
 1259                 LIST(moov_udta_DcMD_DcME)
 1260                     ATOM_BEGIN
 1261                     ATOM(moov_udta_DcMD_DcME_Keyw)
 1262                     ATOM(moov_udta_DcMD_DcME_Mtmd)
 1263                     ATOM(moov_udta_DcMD_DcME_Rate)
 1264                     ATOM_END
 1265                 ATOM_END
 1266             ATOM(moov_udta_FIEL)
 1267             ATOM(moov_udta_FXTC)
 1268             ATOM(moov_udta_hinf)
 1269             ATOM(moov_udta_hinv)
 1270             LIST(moov_udta_hnti)
 1271                 ATOM_BEGIN
 1272                 ATOM(moov_udta_hnti_rtp)
 1273                 ATOM_END
 1274             ATOM(moov_udta_ID32)
 1275             ATOM(moov_udta_kywd)
 1276             ATOM(moov_udta_loci)
 1277             ATOM(moov_udta_LOOP)
 1278             ATOM(moov_udta_MCPS)
 1279             LIST(moov_udta_meta)
 1280                 ATOM_BEGIN
 1281                 ATOM(moov_udta_meta_hdlr)
 1282                 LIST(moov_udta_meta_ilst)
 1283                     LIST_DEFAULT_ALONE_BEGIN (moov_udta_meta_ilst_xxxx)
 1284                         ATOM_BEGIN
 1285                         ATOM (moov_udta_meta_ilst_xxxx_data);
 1286                         ATOM (moov_udta_meta_ilst_xxxx_mean);
 1287                         ATOM (moov_udta_meta_ilst_xxxx_name);
 1288                         ATOM_END
 1289                     LIST_DEFAULT_ALONE_END
 1290                 ATOM(moov_udta_meta_uuid)
 1291                 ATOM_END
 1292             ATOM(moov_udta_ndrm)
 1293             ATOM(moov_udta_nsav)
 1294             ATOM(moov_udta_ptv )
 1295             ATOM(moov_udta_rtng)
 1296             ATOM(moov_udta_Sel0)
 1297             LIST(moov_udta_tags)
 1298                 ATOM_BEGIN
 1299                 ATOM(moov_udta_tags_meta)
 1300                 LIST(moov_udta_tags_tseg)
 1301                     ATOM_BEGIN
 1302                     ATOM(moov_udta_tags_tseg_tshd);
 1303                     ATOM_END
 1304                 ATOM_END
 1305             ATOM(moov_udta_WLOC)
 1306             ATOM(moov_udta_XMP_)
 1307             ATOM(moov_udta_yrrc)
 1308             ATOM_DEFAULT (moov_udta_xxxx); //User data
 1309             ATOM_END_DEFAULT
 1310         ATOM_END
 1311     ATOM(pdin)
 1312     ATOM(PICT)
 1313     ATOM(RDAO)
 1314     ATOM(RDAS)
 1315     ATOM(RDVO)
 1316     ATOM(RDVS)
 1317     ATOM(RED1)
 1318     ATOM(REDA)
 1319     ATOM(REDV)
 1320     ATOM(REOB)
 1321     ATOM(pckg)
 1322     ATOM(pnot)
 1323     LIST_SKIP(skip)
 1324     LIST_SKIP(wide)
 1325     DATA_END
 1326 }
 1327 
 1328 //***************************************************************************
 1329 // Elements
 1330 //***************************************************************************
 1331 
 1332 #define VERSION_FLAG() \
 1333     int32u Flags; \
 1334     int8u Version; \
 1335     { \
 1336         Get_B1(Version,                                         "Version"); \
 1337         Get_B3(Flags,                                           "Flags"); \
 1338     } \
 1339 
 1340 #define NAME_VERSION_FLAG(ELEMENT_NAME) \
 1341     Element_Name(ELEMENT_NAME); \
 1342     VERSION_FLAG(); \
 1343 
 1344 #define INTEGRITY_VERSION(_VERSION) \
 1345     if (Version>_VERSION) \
 1346     { \
 1347         Skip_XX(Element_Size-Element_Offset,                    "Unknown data"); \
 1348         return; \
 1349     } \
 1350 
 1351 #define INTEGRITY(TOVALIDATE, ERRORTEXT) \
 1352     if (!(TOVALIDATE)) \
 1353     { \
 1354         Trusted_IsNot(ERRORTEXT); \
 1355         return; \
 1356     } \
 1357 
 1358 #define INTEGRITY_SIZE1(ELEMENT_SIZE0) \
 1359     INTEGRITY_VERSION(0); \
 1360     if (Element_Size!=ELEMENT_SIZE0+4) \
 1361     { \
 1362         Trusted_IsNot("Size is wrong"); \
 1363         return; \
 1364     } \
 1365 
 1366 #define INTEGRITY_SIZE2(ELEMENT_SIZE0, ELEMENT_SIZE1) \
 1367     INTEGRITY_VERSION(1); \
 1368     if (Version==0 && Element_Size!=ELEMENT_SIZE0 \
 1369      || Version==1 && Element_Size!=ELEMENT_SIZE1) \
 1370     { \
 1371         Trusted_IsNot("Size is wrong"); \
 1372         return; \
 1373     } \
 1374 
 1375 #define INTEGRITY_SIZE_ATLEAST1(ELEMENT_SIZE0) \
 1376     INTEGRITY_VERSION(0); \
 1377     if (Version==0 && Element_Size<ELEMENT_SIZE0) \
 1378     { \
 1379         Trusted_IsNot("Size is wrong"); \
 1380         return; \
 1381     } \
 1382 
 1383 #define INTEGRITY_SIZE_ATLEAST2(ELEMENT_SIZE0, ELEMENT_SIZE1) \
 1384     INTEGRITY_VERSION(1); \
 1385     if (Version==0 && Element_Size<ELEMENT_SIZE0 \
 1386      || Version==1 && Element_Size<ELEMENT_SIZE1) \
 1387     { \
 1388         Trusted_IsNot("Size is wrong"); \
 1389         return; \
 1390     } \
 1391 
 1392 #define Get_B4_DEPENDOFVERSION( _VERSION, _INFO, _NAME) \
 1393     { \
 1394         if (Version!=_VERSION) \
 1395         { \
 1396             int16u Info; \
 1397             Get_B2(Info,                                        _NAME); \
 1398             _INFO=Info; \
 1399         } \
 1400         else \
 1401             Get_B4(_INFO,                                       _NAME); \
 1402     } \
 1403 
 1404 #define Get_B_DEPENDOFVERSION(_INFO, _NAME) \
 1405     { \
 1406         if (Version==0) \
 1407         { \
 1408             int32u Info; \
 1409             Get_B4(Info,                                        _NAME); \
 1410             _INFO=Info; \
 1411         } \
 1412         else \
 1413             Get_B8(_INFO,                                       _NAME); \
 1414     } \
 1415 
 1416 #define Get_DATE1904_DEPENDOFVERSION(_INFO, _NAME) \
 1417     { \
 1418         if (Version==0) \
 1419         { \
 1420             int32u Temp; \
 1421             Get_B4(Temp,                                        _NAME); \
 1422             if (Temp) \
 1423                 _INFO.Date_From_Seconds_1904(Temp); \
 1424         } \
 1425         else \
 1426         { \
 1427             int64u Temp; \
 1428             Get_B8(Temp,                                        _NAME); \
 1429             if (Temp) \
 1430                 _INFO.Date_From_Seconds_1904(Temp); \
 1431         } \
 1432         Param_Info1(_INFO); \
 1433     } \
 1434 
 1435 //-------------------------------------------------------------------------
 1436 void File_Mpeg4::bloc()
 1437 {
 1438     NAME_VERSION_FLAG("Base Location");
 1439 
 1440     //Parsing
 1441     Skip_XX(256,                                                "baseLocation");
 1442     Skip_XX(256,                                                "purchaseLocation");
 1443     Skip_XX(512,                                                "Reserved");
 1444 }
 1445 
 1446 //---------------------------------------------------------------------------
 1447 void File_Mpeg4::cdat()
 1448 {
 1449     Element_Code=Element_Code==Elements::cdat?1:2;
 1450 
 1451     if (!Status[IsAccepted])
 1452     {
 1453         Accept("EIA-608");
 1454         Fill(Stream_General, 0, General_Format, "Final Cut EIA-608", Unlimited, true, true);
 1455     }
 1456     #ifdef MEDIAINFO_EIA608_YES
 1457         if (Streams[(int32u)Element_Code].Parsers.empty())
 1458         {
 1459             File_Eia608* Parser=new File_Eia608();
 1460             Open_Buffer_Init(Parser);
 1461             Streams[(int32u)Element_Code].Parsers.push_back(Parser);
 1462         }
 1463     #endif //MEDIAINFO_EIA608_YES
 1464 
 1465     Element_Name(Element_Code==1?"EIA-608-1":"EIA-608-2");
 1466 
 1467     #if MEDIAINFO_DEMUX
 1468         Demux(Buffer+Buffer_Offset, (size_t)Element_Size, ContentType_MainStream);
 1469         for (size_t Pos=0; Pos<Streams[(int32u)Element_Code].Parsers.size(); Pos++)
 1470         {
 1471             Streams[(int32u)Element_Code].Parsers[Pos]->FrameInfo.DTS=FrameInfo.DTS;
 1472             if (Element_Size>1)
 1473                 Streams[(int32u)Element_Code].Parsers[Pos]->FrameInfo.DUR=FrameInfo.DUR/(Element_Size/2);
 1474         }
 1475     #endif //MEDIAINFO_DEMUX
 1476     while (Element_Offset+2<=Element_Size)
 1477     {
 1478         for (size_t Pos=0; Pos<Streams[(int32u)Element_Code].Parsers.size(); Pos++)
 1479             Open_Buffer_Continue(Streams[(int32u)Element_Code].Parsers[Pos], Buffer+Buffer_Offset+(size_t)Element_Offset, 2);
 1480         Element_Offset+=2;
 1481     }
 1482 }
 1483 
 1484 //---------------------------------------------------------------------------
 1485 void File_Mpeg4::free()
 1486 {
 1487     Element_Name("Free space");
 1488 
 1489     //Parsing
 1490     Skip_XX(Element_TotalSize_Get(),                            "Data");
 1491     #if MEDIAINFO_HASH
 1492         if (Hash && !IsSecondPass)
 1493             GoTo(File_Offset+Buffer_Offset+Element_TotalSize_Get()); //Hash will be done during second pass
 1494     #endif //MEDIAINFO_HASH
 1495 
 1496     //ISM
 1497     if (moof_traf_base_data_offset==(int64u)-1 && !data_offset_present)
 1498         Stream->second.stco.push_back(File_Offset+Buffer_Offset);
 1499 }
 1500 
 1501 //---------------------------------------------------------------------------
 1502 void File_Mpeg4::ftyp()
 1503 {
 1504     Element_Name("File Type");
 1505 
 1506     if (Count_Get(Stream_General))
 1507     {
 1508         Skip_XX(Element_Size,                                   "Duplicate ftyp");
 1509         return;
 1510     }
 1511 
 1512     //Parsing
 1513     std::vector<int32u> ftyps;
 1514     int32u MajorBrandVersion;
 1515     Get_C4 (MajorBrand,                                         "MajorBrand");
 1516     ftyps.push_back(MajorBrand);
 1517     Get_B4 (MajorBrandVersion,                                  "MajorBrandVersion");
 1518     while (Element_Offset<Element_Size)
 1519     {
 1520         int32u CompatibleBrand;
 1521         Get_C4 (CompatibleBrand,                                "CompatibleBrand");
 1522         ftyps.push_back(CompatibleBrand);
 1523     }
 1524 
 1525     FILLING_BEGIN();
 1526         Accept("MPEG-4");
 1527 
 1528         for (size_t Pos=0; Pos<ftyps.size(); Pos++)
 1529             switch (ftyps[Pos])
 1530             {
 1531                 case Elements::ftyp_dash : if (Config->File_Names.size()==1)TestContinuousFileNames(1, __T("m4s")); break;
 1532                 case Elements::ftyp_caqv : Fill(StreamKind_Last, StreamPos_Last, "Encoded_Application", "Casio Digital Camera"); break;
 1533                 default : ;
 1534             }
 1535         CodecID_Fill(Ztring().From_CC4(MajorBrand), Stream_General, 0, InfoCodecID_Format_Mpeg4);
 1536         if (Retrieve_Const(Stream_General, 0, General_Format).empty())
 1537             Fill(Stream_General, 0, General_Format, Ztring().From_CC4(MajorBrand));
 1538         Ztring CodecID_String=Ztring().From_CC4(MajorBrand);
 1539         if (MajorBrand==Elements::ftyp_qt)
 1540         {
 1541             ZtringList Version;
 1542             Version.Separator_Set(0, __T("."));
 1543             Version.push_back(Ztring().From_CC2(MajorBrandVersion>>16));
 1544             Version.push_back(Ztring().From_CC1((int8u)(MajorBrandVersion>>8)));
 1545             if (MajorBrandVersion&0xFF)
 1546                 Version.push_back(Ztring().From_CC1((int8u)MajorBrandVersion));
 1547             Fill(Stream_General, 0, General_CodecID_Version, Version.Read());
 1548             CodecID_String += __T(' ');
 1549             CodecID_String += Version.Read();
 1550         }
 1551         if (ftyps.size()>1)
 1552         {
 1553             ZtringList Compat;
 1554             Compat.Separator_Set(0, __T("/"));
 1555             for (size_t i=1; i<ftyps.size(); i++)
 1556                 if (ftyps[i])
 1557                     Compat.push_back(Ztring().From_CC4(ftyps[i]));
 1558             Fill(Stream_General, 0, General_CodecID_Compatible, Compat.Read());
 1559             CodecID_String += __T(" (");
 1560             CodecID_String += Compat.Read();
 1561             CodecID_String += __T(')');
 1562         }
 1563         Fill(Stream_General, 0, General_CodecID_String, CodecID_String, true);
 1564     FILLING_END();
 1565 }
 1566 
 1567 //---------------------------------------------------------------------------
 1568 void File_Mpeg4::idat()
 1569 {
 1570     Element_Name("QTI");
 1571 
 1572     //Parsing
 1573     Skip_XX(Element_Size,                                       "Data");
 1574 
 1575     FILLING_BEGIN();
 1576         Accept("QTI");
 1577 
 1578         Fill(Stream_General, 0, General_Format, "MPEG-4");
 1579         CodecID_Fill(__T("QTI"), Stream_General, 0, InfoCodecID_Format_Mpeg4);
 1580     FILLING_END();
 1581 }
 1582 
 1583 //---------------------------------------------------------------------------
 1584 void File_Mpeg4::idsc()
 1585 {
 1586     Element_Name("QTI");
 1587 
 1588     //Parsing
 1589     Skip_XX(Element_Size,                                       "Data");
 1590 
 1591     FILLING_BEGIN();
 1592         Accept("QTI");
 1593 
 1594         Fill(Stream_General, 0, General_Format, "MPEG-4");
 1595         CodecID_Fill(__T("QTI"), Stream_General, 0, InfoCodecID_Format_Mpeg4);
 1596     FILLING_END();
 1597 }
 1598 
 1599 //---------------------------------------------------------------------------
 1600 void File_Mpeg4::jp2c()
 1601 {
 1602     Element_Name("JPEG 2000 content");
 1603 
 1604     #if defined(MEDIAINFO_JPEG_YES)
 1605         //Creating the parser
 1606         File_Jpeg MI;
 1607         if (IsSub || Config->File_Names.size()>1) //If contained in another container or several files, this is a video stream
 1608             MI.StreamKind=Stream_Video;
 1609         Open_Buffer_Init(&MI);
 1610 
 1611         //Demux
 1612         #if MEDIAINFO_DEMUX
 1613             #if MEDIAINFO_EVENTS
 1614                 StreamIDs_Width[0]=0;
 1615             #endif //MEDIAINFO_EVENTS
 1616             if (Frame_Count_NotParsedIncluded==(int64u)-1)
 1617                 Frame_Count_NotParsedIncluded=0;
 1618             if (Config->Demux_Rate_Get())
 1619             {
 1620                 FrameInfo.DTS=float64_int64s(Frame_Count_NotParsedIncluded*1000000000/Config->Demux_Rate_Get());
 1621                 FrameInfo.PTS=FrameInfo.DTS;
 1622                 FrameInfo.DUR=float64_int64s(1000000000/Config->Demux_Rate_Get());
 1623             }
 1624             Demux(Buffer+Buffer_Offset, (size_t)Element_Size, ContentType_MainStream);
 1625         #endif //MEDIAINFO_DEMUX
 1626 
 1627         //Parsing
 1628         Open_Buffer_Continue(&MI);
 1629 
 1630         //Filling
 1631         if (Frame_Count==0)
 1632         {
 1633             Accept("MPEG-4");
 1634 
 1635             Fill(Stream_General, 0, General_Format, "JPEG 2000", Unlimited, true, true);
 1636             Fill(Stream_General, 0, General_Format_Profile, "MPEG-4");
 1637 
 1638             Finish(&MI);
 1639             Merge(MI, MI.StreamKind, 0, 0);
 1640 
 1641             Fill("MPEG-4");
 1642             if (Config->File_Names.size()>1 && File_Size!=(int64u)-1)
 1643             {
 1644                 int64u OverHead=Config->File_Sizes[0]-Element_Size;
 1645                 Fill(Stream_Video, 0, Video_StreamSize, File_Size-Config->File_Names.size()*OverHead, 10, true);
 1646             }
 1647             if (Config->ParseSpeed<1.0)
 1648                 Finish("MPEG-4");
 1649         }
 1650         Frame_Count++;
 1651         if (Frame_Count_NotParsedIncluded!=(int64u)-1)
 1652             Frame_Count_NotParsedIncluded++;
 1653     #endif
 1654 
 1655 }
 1656 
 1657 //---------------------------------------------------------------------------
 1658 void File_Mpeg4::jp2h()
 1659 {
 1660     Element_Name("JPEG-2000 header");
 1661 }
 1662 
 1663 //---------------------------------------------------------------------------
 1664 void File_Mpeg4::jp2h_colr()
 1665 {
 1666     Element_Name("Color");
 1667 
 1668     //Parsing
 1669     int8u METH;
 1670     Get_B1 (METH,                                               "METH - Specification method"); Param_Info1(Mpeg4_jp2h_METH(METH));
 1671     Skip_B1(                                                    "PREC - Precedence");
 1672     Skip_B1(                                                    "APPROX - Colourspace approximation");
 1673     switch (METH)
 1674     {
 1675         case 0x01 : {
 1676                     int32u EnumCS;
 1677                     Get_B4 (EnumCS,                             "EnumCS - Enumerated colourspace"); Param_Info1(Mpeg4_jp2h_EnumCS(EnumCS));
 1678                     Fill(StreamKind_Last, 0, "ColorSpace", Mpeg4_jp2h_EnumCS(EnumCS));
 1679                     }
 1680                     break;
 1681         case 0x02 : Skip_XX(Element_Size-Element_Offset,        "PROFILE");
 1682                     break;
 1683         default   : Skip_XX(Element_Size-Element_Offset,        "Unknown");
 1684                     return;
 1685     }
 1686 }
 1687 
 1688 //---------------------------------------------------------------------------
 1689 void File_Mpeg4::jp2h_ihdr()
 1690 {
 1691     Element_Name("Header");
 1692 
 1693     //Parsing
 1694     Skip_B4(                                                    "Height");
 1695     Skip_B4(                                                    "Width");
 1696     Skip_B2(                                                    "NC - Number of components");
 1697     BS_Begin();
 1698     Skip_SB(                                                    "BPC - Bits per component (Sign)");
 1699     Skip_S1(7,                                                  "BPC - Bits per component (Value)");
 1700     BS_End();
 1701     Skip_B1(                                                    "C - Compression type");
 1702     Skip_B1(                                                    "UnkC - Colourspace Unknown");
 1703     Skip_B1(                                                    "IPR - Intellectual Property");
 1704 }
 1705 
 1706 //---------------------------------------------------------------------------
 1707 void File_Mpeg4::mdat()
 1708 {
 1709     #if MEDIAINFO_TRACE
 1710         Trace_Layers_Update(8); //Streams
 1711     #endif //MEDIAINFO_TRACE
 1712 
 1713     if (!Status[IsAccepted])
 1714     {
 1715         Data_Accept("MPEG-4");
 1716 
 1717         Fill(Stream_General, 0, General_Format, "QuickTime");
 1718     }
 1719     Element_Name("Data");
 1720 
 1721     //Sizes
 1722     if (Retrieve(Stream_General, 0, General_HeaderSize).empty())
 1723     {
 1724         Fill(Stream_General, 0, General_HeaderSize, File_Offset+Buffer_Offset-Header_Size);
 1725         Fill(Stream_General, 0, General_DataSize, Element_TotalSize_Get()+Header_Size);
 1726         if (File_Size!=(int64u)-1 && File_Offset+Buffer_Offset+Element_TotalSize_Get()<=File_Size)
 1727             Fill(Stream_General, 0, General_FooterSize, File_Size-(File_Offset+Buffer_Offset+Element_TotalSize_Get()));
 1728         Fill(Stream_General, 0, General_IsStreamable, FirstMoovPos==(int64u)-1?"No":"Yes");
 1729     }
 1730 
 1731     //Trace
 1732     #if MEDIAINFO_TRACE
 1733         Trace_Layers_Update(0); //Container1
 1734     #endif //MEDIAINFO_TRACE
 1735 
 1736     if (IsSecondPass && !mdat_Pos.empty() && mdat_Pos.begin()->Offset<File_Offset+Buffer_Offset+Element_TotalSize_Get())
 1737     {
 1738         //Next piece of data
 1739         mdat_Pos_Temp=&mdat_Pos[0];
 1740         IsParsing_mdat_Set();
 1741         mdat_StreamJump();
 1742 
 1743         return; //Only if have something in this mdat
 1744     }
 1745 
 1746     //In case of mdat is before moov
 1747     if (FirstMdatPos==(int64u)-1)
 1748     {
 1749         Buffer_Offset-=(size_t)Header_Size;
 1750         Element_Level--;
 1751         BookMark_Set(); //Remembering this place, for stream parsing in phase 2
 1752         Element_Level++;
 1753         Buffer_Offset+=(size_t)Header_Size;
 1754 
 1755         FirstMdatPos=File_Offset+Buffer_Offset-Header_Size;
 1756     }
 1757     if (File_Offset+Buffer_Offset>LastMdatPos)
 1758         LastMdatPos=File_Offset+Buffer_Offset+Element_TotalSize_Get();
 1759 
 1760     //Parsing
 1761     Skip_XX(Element_TotalSize_Get(),                            "Data");
 1762     #if MEDIAINFO_HASH
 1763         if (Hash && !IsSecondPass)
 1764             GoTo(File_Offset+Buffer_Offset+Element_TotalSize_Get()); //Hash will be done during second pass
 1765     #endif //MEDIAINFO_HASH
 1766 
 1767     //ISM
 1768     if (moof_traf_base_data_offset==(int64u)-1 && !data_offset_present)
 1769         Stream->second.stco.push_back(File_Offset+Buffer_Offset);
 1770 }
 1771 
 1772 //---------------------------------------------------------------------------
 1773 void File_Mpeg4::mdat_xxxx()
 1774 {
 1775     if (!Element_IsComplete_Get())
 1776     {
 1777         Element_WaitForMoreData();
 1778         return;
 1779     }
 1780 
 1781     if (!IsSub)
 1782     {
 1783         if (Config->ParseSpeed>=1.0)
 1784             Config->State_Set(((float)Buffer_TotalBytes)/File_Size);
 1785     }
 1786 
 1787     stream &Stream_Temp=Streams[(int32u)Element_Code];
 1788     if (Stream_Temp.Parsers.empty())
 1789     {
 1790         Skip_XX(Element_Size,                                   "Unknown");
 1791         mdat_StreamJump();
 1792         return;
 1793     }
 1794     #if MEDIAINFO_DEMUX
 1795         if (Stream_Temp.StreamKind!=Stream_Other && Stream_Temp.StreamKind!=Stream_Max)
 1796         {
 1797             //DTS
 1798             Frame_Count_NotParsedIncluded=Stream_Temp.stts_FramePos;
 1799             if (Stream_Temp.stts_Durations_Pos<Stream_Temp.stts_Durations.size())
 1800             {
 1801                 stream::stts_durations::iterator stts_Duration=Stream_Temp.stts_Durations.begin()+Stream_Temp.stts_Durations_Pos;
 1802                 int64u stts_Offset=stts_Duration->DTS_Begin+(((int64u)stts_Duration->SampleDuration)*(Frame_Count_NotParsedIncluded-stts_Duration->Pos_Begin));
 1803                 FrameInfo.DTS=Stream_Temp.mdhd_TimeScale?(TimeCode_DtsOffset+stts_Offset*1000000000/Stream_Temp.mdhd_TimeScale):((int64u)-1);
 1804                 if (!Stream_Temp.edts.empty())
 1805                 {
 1806                     int64s Delay=0;
 1807                     switch (Stream_Temp.edts.size())
 1808                     {
 1809                         case 0 :
 1810                                 break;
 1811                         case 1 :
 1812                                 if (Stream_Temp.edts[0].Duration==Stream_Temp.tkhd_Duration && Stream_Temp.edts[0].Rate==0x00010000 && moov_mvhd_TimeScale)
 1813                                 {
 1814                                     Delay=-((int64s)Stream_Temp.edts[0].Delay);
 1815                                 }
 1816                                 break;
 1817                         case 2 :
 1818                                 if (Stream_Temp.edts[0].Delay==(int32u)-1 && Stream_Temp.edts[0].Duration+Stream_Temp.edts[1].Duration==Stream_Temp.tkhd_Duration && Stream_Temp.edts[0].Rate==0x00010000 && Stream_Temp.edts[1].Rate==0x00010000 && moov_mvhd_TimeScale)
 1819                                 {
 1820                                     Delay=((int64s)Stream_Temp.edts[0].Duration)-Stream_Temp.edts[1].Delay;
 1821                                 }
 1822                                 break;
 1823                         default:
 1824                                 break; //TODO: handle more complex Edit Lists
 1825                     }
 1826 
 1827                     if (FrameInfo.DTS!=(int64u)-1 && -Delay<(int64s)stts_Offset) //TODO: check potential incoherency between movie timescale and track timescale
 1828                         FrameInfo.DTS+=Delay*1000000000/moov_mvhd_TimeScale;
 1829                     else
 1830                         FrameInfo.DTS=TimeCode_DtsOffset;
 1831                 }
 1832                 FrameInfo.PTS=Stream_Temp.PtsDtsAreSame?FrameInfo.DTS:(int64u)-1;
 1833                 FrameInfo.DUR=Stream_Temp.mdhd_TimeScale?(((int64u)stts_Duration->SampleDuration)*1000000000/Stream_Temp.mdhd_TimeScale):((int64u)-1);
 1834                 Stream_Temp.stts_FramePos++;
 1835                 if (Stream_Temp.stts_FramePos>=stts_Duration->Pos_End)
 1836                     Stream_Temp.stts_Durations_Pos++;
 1837                 if (!Stream_Temp.stss.empty())
 1838                 {
 1839                     Demux_random_access=false;
 1840                     for (size_t Pos=0; Pos<Stream_Temp.stss.size(); Pos++)
 1841                         if (Stream_Temp.stss[Pos]==Frame_Count_NotParsedIncluded)
 1842                         {
 1843                             Demux_random_access=true;
 1844                             break;
 1845                         }
 1846                 }
 1847                 else
 1848                     Demux_random_access=true;
 1849             }
 1850             else
 1851             {
 1852                 FrameInfo.DTS=(int64u)-1;
 1853                 FrameInfo.DUR=(int64u)-1;
 1854                 Stream_Temp.stts_FramePos++;
 1855             }
 1856 
 1857             bool ShouldDemux=true;
 1858             if (Stream_Temp.Demux_Level&(1<<7) && Element_Size-Stream_Temp.Demux_Offset)
 1859             {
 1860                 if (Stream_Temp.Parsers[0]->Status[IsAccepted])
 1861                     ShouldDemux=false;
 1862                 else
 1863                 {
 1864                     //Checking if we need to add SPS/PPS
 1865                     size_t CheckMax=Stream_Temp.Demux_Offset+0x10; //SPS uses to be in the first bytes only
 1866                     if (CheckMax>Element_Size-4)
 1867                         CheckMax=Element_Size-4;
 1868                     ShouldDemux=false;
 1869                     for (size_t i=Stream_Temp.Demux_Offset; i<CheckMax; i++)
 1870                         if (Buffer[i]==0x00 && Buffer[i+1]==0x00 && Buffer[i+2]==0x01 && Buffer[i+3]==0x67)
 1871                         {
 1872                             Stream_Temp.Demux_Level&=~((1<<7)|(1<<6)); //Remove the flag, SPS/PPS detected
 1873                             ShouldDemux=true;
 1874                             break;
 1875                         }
 1876                 }
 1877 
 1878                 if (!ShouldDemux)
 1879                 {
 1880                     if (Stream_Temp.CodecID==0x4156696E) //AVin
 1881                     {
 1882                         int32u Height=Retrieve(Stream_Video, Stream_Temp.StreamPos, Video_Height).To_int32u();
 1883                         int32u Fields;
 1884                         if (Retrieve(Stream_Video, Stream_Temp.StreamPos, Video_ScanType)==__T("Progressive"))
 1885                             Fields=1;
 1886                         else if (Retrieve(Stream_Video, Stream_Temp.StreamPos, Video_ScanType)==__T("Interlaced"))
 1887                             Fields=2;
 1888                         else
 1889                             Fields=0;
 1890                         int32u SampleDuration;
 1891                         if (Stream_Temp.stts.size()==1)
 1892                             SampleDuration=Stream_Temp.stts[0].SampleDuration;
 1893                         else
 1894                             SampleDuration=0;
 1895                         Stream_Temp.CodecID=File_Avc::AVC_Intra_CodecID_FromMeta(Height, Fields, SampleDuration, Stream_Temp.mdhd_TimeScale, Stream_Temp.stsz_Sample_Size);
 1896                     }
 1897 
 1898                     //Stream_Temp.Demux_Level|= (1<<6); //In case of seek, we need to send again SPS/PPS //Deactivated because Hydra does not decode after a seek + 1 SPS/PPS only.
 1899                     //Stream_Temp.Demux_Level&=~(1<<7); //Remove the flag, SPS/PPS sent
 1900                     Demux_Level=Stream_Temp.Demux_Level;
 1901                     File_Avc::avcintra_header AvcIntraHeader=File_Avc::AVC_Intra_Headers_Data(Stream_Temp.CodecID);
 1902                     size_t Buffer_Temp_Size=AvcIntraHeader.Size+(size_t)(Element_Size-Stream_Temp.Demux_Offset);
 1903                     int8u* Buffer_Temp_Data=new int8u[Buffer_Temp_Size];
 1904                     if (AvcIntraHeader.Data)
 1905                         memcpy(Buffer_Temp_Data, AvcIntraHeader.Data, AvcIntraHeader.Size);
 1906                     memcpy(Buffer_Temp_Data+AvcIntraHeader.Size, Buffer+Buffer_Offset+Stream_Temp.Demux_Offset, (size_t)(Element_Size-Stream_Temp.Demux_Offset));
 1907                     Demux(Buffer_Temp_Data, Buffer_Temp_Size, ContentType_MainStream);
 1908                     Open_Buffer_Continue(Stream_Temp.Parsers[0], AvcIntraHeader.Data, AvcIntraHeader.Size);
 1909                     ShouldDemux = false;
 1910                 }
 1911             }
 1912             if (ShouldDemux)
 1913             {
 1914                 Demux_Level=Stream_Temp.Demux_Level;
 1915                 Demux(Buffer+Buffer_Offset+Stream_Temp.Demux_Offset, (size_t)(Element_Size-Stream_Temp.Demux_Offset), ContentType_MainStream);
 1916             }
 1917         }
 1918     #endif //MEDIAINFO_DEMUX
 1919 
 1920     for (size_t Pos=0; Pos<Stream_Temp.Parsers.size(); Pos++)
 1921     {
 1922         #if MEDIAINFO_DEMUX
 1923         Stream_Temp.Parsers[Pos]->FrameInfo=FrameInfo;
 1924         #endif //MEDIAINFO_DEMUX
 1925 
 1926         Open_Buffer_Continue(Stream_Temp.Parsers[Pos], Buffer+Buffer_Offset, (size_t)Element_Size);
 1927         #if MEDIAINFO_DEMUX
 1928             if (Config->Demux_EventWasSent && Config->Demux_Unpacketize_Get())
 1929                 Stream_Temp.Demux_EventWasSent=true;
 1930         #endif //MEDIAINFO_DEMUX
 1931         Element_Show();
 1932 
 1933         #if MEDIAINFO_DEMUX
 1934             if (!Stream_Temp.IsFilled && Stream_Temp.Parsers[Pos]->Status[IsFilled])
 1935             {
 1936                 if (Stream_Temp.StreamKind==Stream_Other) //If this is a TimeCode track
 1937                 {
 1938                     if (((File_Mpeg4_TimeCode*)Stream_Temp.Parsers[Pos])->Pos!=(int32u)-1)
 1939                     {
 1940                         for (std::map<int32u, stream>::iterator StreamTemp=Streams.begin(); StreamTemp!=Streams.end(); ++StreamTemp)
 1941                             if (StreamTemp->second.TimeCode_TrackID==(int32u)Element_Code)
 1942                             {
 1943                                 TimeCode_FrameOffset=((File_Mpeg4_TimeCode*)Stream_Temp.Parsers[Pos])->Pos;
 1944                                 TimeCode_DtsOffset=float64_int64s(((float64)TimeCode_FrameOffset)*1000000000*Stream_Temp.TimeCode->FrameDuration/Stream_Temp.TimeCode->TimeScale);
 1945                             }
 1946                     }
 1947                 }
 1948 
 1949                 Stream_Temp.IsFilled=true;
 1950 
 1951                 if (Config->ParseSpeed<1 && !mdat_Pos.empty())
 1952                 {
 1953                     bool File_Offset_Next_IsValid;
 1954                     int64u File_Offset_Next;
 1955                     if (mdat_Pos_Temp!=mdat_Pos_Max)
 1956                     {
 1957                         File_Offset_Next=mdat_Pos_Temp->Offset;
 1958                         File_Offset_Next_IsValid=true;
 1959                     }
 1960                     else
 1961                     {
 1962                         File_Offset_Next=(int64u)-1;
 1963                         File_Offset_Next_IsValid=false;
 1964                     }
 1965                     mdat_pos mdat_Pos_New;
 1966                     mdat_Pos_Max=mdat_Pos.empty()?NULL:(&mdat_Pos[0]+mdat_Pos.size());
 1967                     if (!mdat_Pos.empty())
 1968                     {
 1969                         for (mdat_Pos_Type* mdat_Pos_Item=&mdat_Pos[0]; mdat_Pos_Item<mdat_Pos_Max; ++mdat_Pos_Item)
 1970                             if (mdat_Pos_Item->StreamID!=(int32u)Element_Code)
 1971                                 mdat_Pos_New.push_back(*mdat_Pos_Item);
 1972                     }
 1973                     mdat_Pos=mdat_Pos_New;
 1974                     std::sort(mdat_Pos.begin(), mdat_Pos.end(), &mdat_pos_sort);
 1975                     mdat_Pos_Temp=mdat_Pos.empty()?NULL:&mdat_Pos[0];
 1976                     mdat_Pos_Max=mdat_Pos_Temp+mdat_Pos.size();
 1977                     if (File_Offset_Next_IsValid)
 1978                         for (; mdat_Pos_Temp<mdat_Pos_Max; ++mdat_Pos_Temp)
 1979                         {
 1980                             if (mdat_Pos_Temp->Offset>=File_Offset_Next)
 1981                                 break;
 1982                         }
 1983                     else
 1984                         mdat_Pos_Temp=mdat_Pos_Max;
 1985                 }
 1986             }
 1987         #endif //MEDIAINFO_DEMUX
 1988 
 1989         //Multiple parsers
 1990         if (Stream_Temp.Parsers.size()>1)
 1991         {
 1992             if (!Stream_Temp.Parsers[Pos]->Status[IsAccepted] && Stream_Temp.Parsers[Pos]->Status[IsFinished])
 1993             {
 1994                 delete *(Stream_Temp.Parsers.begin()+Pos);
 1995                 Stream_Temp.Parsers.erase(Stream_Temp.Parsers.begin()+Pos);
 1996                 Pos--;
 1997             }
 1998             else if (Stream_Temp.Parsers.size()>1 && Stream_Temp.Parsers[Pos]->Status[IsAccepted])
 1999             {
 2000                 File__Analyze* Parser=Stream_Temp.Parsers[Pos];
 2001                 for (size_t Pos2=0; Pos2<Stream_Temp.Parsers.size(); Pos2++)
 2002                 {
 2003                     if (Pos2!=Pos)
 2004                         delete *(Stream_Temp.Parsers.begin()+Pos2);
 2005                 }
 2006                 Stream_Temp.Parsers_Clear();
 2007                 Stream_Temp.Parsers.push_back(Parser);
 2008             }
 2009         }
 2010     }
 2011 
 2012     //Next piece of data
 2013     Element_Offset=Element_Size;
 2014     Element_Show();
 2015     mdat_StreamJump();
 2016 }
 2017 
 2018 //---------------------------------------------------------------------------
 2019 void File_Mpeg4::mdat_StreamJump()
 2020 {
 2021     #if MEDIAINFO_DEMUX
 2022         if (Config->ParseSpeed>=1 && !mdat_Pos.empty() && !StreamOffset_Jump.empty())
 2023         {
 2024             std::map<int64u, int64u>::iterator StreamOffset_Jump_Temp=StreamOffset_Jump.find(File_Offset+Buffer_Offset+Element_Size);
 2025             if (StreamOffset_Jump_Temp!=StreamOffset_Jump.end())
 2026             {
 2027                 if (!mdat_Pos.empty())
 2028                 {
 2029                     mdat_Pos_Temp=&mdat_Pos[0];
 2030                     while (mdat_Pos_Temp<mdat_Pos_Max && mdat_Pos_Temp->Offset!=StreamOffset_Jump_Temp->second)
 2031                         mdat_Pos_Temp++;
 2032                 }
 2033                 else
 2034                     mdat_Pos_Temp=NULL;
 2035             }
 2036         }
 2037     #endif // MEDIAINFO_DEMUX
 2038 
 2039     //Finding right file offset
 2040     int64u ToJump=File_Size;
 2041     if (!mdat_Pos.empty() && mdat_Pos_Temp!=mdat_Pos_Max)
 2042         ToJump=mdat_Pos_Temp->Offset;
 2043     if (ToJump>File_Size)
 2044         ToJump=File_Size;
 2045     if (ToJump!=File_Offset+Buffer_Offset+Element_Size)
 2046     {
 2047         if (!Status[IsAccepted])
 2048             Data_Accept("MPEG-4");
 2049         #if MEDIAINFO_HASH
 2050             if (ToJump==File_Size && Config->File_Hash_Get().to_ulong() && (IsSecondPass && mdat_Pos_NormalParsing))
 2051             {
 2052                 //This is the end of the parsing, jump to the hash position, for hash only up to the end of the file)
 2053                 Hash_ParseUpTo=File_Size;
 2054                 Data_GoTo(Hash_Offset, "MPEG-4"); 
 2055             }
 2056             else
 2057         #endif //MEDIAINFO_HASH
 2058                 Data_GoTo(ToJump, "MPEG-4"); //Not just after
 2059     }
 2060 }
 2061 
 2062 //---------------------------------------------------------------------------
 2063 void File_Mpeg4::meta()
 2064 {
 2065     NAME_VERSION_FLAG("Metadata");
 2066 }
 2067 
 2068 //---------------------------------------------------------------------------
 2069 void File_Mpeg4::meta_idat()
 2070 {
 2071     Element_Name("Item data");
 2072 }
 2073 
 2074 //---------------------------------------------------------------------------
 2075 void File_Mpeg4::meta_grpl()
 2076 {
 2077     Element_Name("Groups List");
 2078 }
 2079 
 2080 //---------------------------------------------------------------------------
 2081 void File_Mpeg4::meta_grpl_xxxx()
 2082 {
 2083     switch (Element_Code)
 2084     {
 2085         case 0x616C7472: Element_Name("Alternative To Each Other"); break; //altr
 2086         case 0x73746572: Element_Name("Stereo Pair"); break; //ster
 2087     }
 2088     VERSION_FLAG();
 2089 
 2090     //Parsing
 2091     int32u num_entities_in_group;
 2092     Skip_B4(                                                    "group_id");
 2093     Get_B4 (num_entities_in_group,                              "num_entities_in_group");
 2094     for (int16u i=0; i<num_entities_in_group; i++)
 2095         Skip_B4(                                                "entity_id");
 2096 }
 2097 
 2098 //---------------------------------------------------------------------------
 2099 void File_Mpeg4::meta_iinf()
 2100 {
 2101     NAME_VERSION_FLAG("Item Information");
 2102 
 2103     //Parsing
 2104     Skip_B2(                                                    "entry-count");
 2105 }
 2106 
 2107 //---------------------------------------------------------------------------
 2108 #define META_CREATESTREAM() \
 2109     stream& Current=Streams[moov_trak_tkhd_TrackID]; \
 2110     if (Current.StreamKind==Stream_Max) \
 2111     { \
 2112         Stream_Prepare(Stream_Video); \
 2113         Current.StreamKind=Stream_Video; \
 2114         Current.StreamPos=StreamPos_Last; \
 2115         Current.IsEnabled=(meta_pitm_item_ID==(int32u)-1 || meta_pitm_item_ID==moov_trak_tkhd_TrackID)?true:false; \
 2116         Current.IsImage=true; \
 2117         Fill(StreamKind_Last, StreamPos_Last, General_ID, moov_trak_tkhd_TrackID, 10, true); \
 2118     } \
 2119 
 2120 //---------------------------------------------------------------------------
 2121 void File_Mpeg4::meta_iinf_infe()
 2122 {
 2123     NAME_VERSION_FLAG("Item Information Entry");
 2124 
 2125     //Parsing
 2126     if (Version<2 || Version>3)
 2127         return;
 2128     int32u item_ID, item_type;
 2129     int16u protection_index;
 2130     Get_B4_DEPENDOFVERSION(3, item_ID,                          "item_ID");
 2131     Get_B2 (protection_index,                                   "protection_index");
 2132     Get_C4 (item_type,                                          "item_type");
 2133     Skip_NulString(                                             "item_name");
 2134     switch (item_type)
 2135     {
 2136         case 0x6D696D65:    // mime
 2137                             Skip_NulString(                     "content_type");
 2138                             if (Element_Offset<Element_Size)
 2139                                 Skip_NulString(                 "content_encoding");
 2140                             break;
 2141         case 0x75726900:    // uri
 2142                             Skip_NulString(                     "item_uri_type");
 2143                             break;
 2144     }
 2145     
 2146     FILLING_BEGIN();
 2147         moov_trak_tkhd_TrackID=item_ID;
 2148         const char* Format=NULL;
 2149         bool Skip=false;
 2150         switch (item_type)
 2151         {
 2152             case 0x45786966:    // Exif
 2153             //case 0x68767431:    // hvt1 --> image tile TODO
 2154             case 0x6D696D65:    // mime
 2155             case 0x75726900:    // uri
 2156                                 Skip=true; // Currently not supported
 2157                                 break;
 2158             case 0x64696D67:    // dimg
 2159                                 Format="Derived Image";
 2160                                 break;
 2161             case 0x67726964:    // grid
 2162                                 Format="Grid";
 2163                                 break;
 2164             case 0x6964656E:    // iden
 2165                                 Format="Identity";
 2166                                 break;
 2167             case 0x696F766C:    // iovl
 2168                                 Format="Image Overlay";
 2169                                 break;
 2170         }
 2171         if (!Skip)
 2172         {
 2173             META_CREATESTREAM();
 2174             if (Format)
 2175                 Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Format), Format);
 2176             else
 2177                 CodecID_Fill(Ztring().From_CC4(item_type), StreamKind_Last, StreamPos_Last, InfoCodecID_Format_Mpeg4);
 2178         }
 2179         if (protection_index)
 2180             Fill(StreamKind_Last, StreamPos_Last, "Encrypted", "Yes");
 2181     FILLING_END();
 2182 }
 2183 
 2184 //---------------------------------------------------------------------------
 2185 void File_Mpeg4::meta_iloc()
 2186 {
 2187     NAME_VERSION_FLAG("Item Location");
 2188 
 2189     //Parsing
 2190     if (Version>1)
 2191         return;
 2192     int16u item_count;
 2193     int8u  offset_size, length_size, base_offset_size, index_size;
 2194     BS_Begin();
 2195     Get_S1 (4, offset_size,                                     "offset_size");
 2196     Get_S1 (4, length_size,                                     "length_size");
 2197     Get_S1 (4, base_offset_size,                                "base_offset_size");
 2198     if (Version)
 2199         Get_S1 (4, index_size,                                  "index_size");
 2200     else
 2201     {
 2202         Skip_S1(4,                                              "reserved");
 2203         index_size=0;
 2204     }
 2205     Get_S2 (16, item_count,                                     "item_count");
 2206     offset_size*=8;
 2207     length_size*=8;
 2208     base_offset_size*=8;
 2209     index_size*=8;
 2210     for (int16u i=0; i<item_count; i++)
 2211     {
 2212         Element_Begin1("item");
 2213         int16u item_ID, extent_count;
 2214         Get_S2 (16, item_ID,                                    "item_ID");
 2215         if (Version)
 2216         {
 2217             Skip_S2(12,                                         "reserved");
 2218             Skip_S1( 4,                                         "construction_method");
 2219         }
 2220         Skip_S2(16,                                             "data_reference_index");
 2221         if (base_offset_size)
 2222             Skip_BS(base_offset_size,                           "base_offset");
 2223         Get_S2 (16, extent_count,                               "extent_count");
 2224         for (int16u j=0; j< extent_count; j++)
 2225         {
 2226             Element_Begin1("extent");
 2227             if (index_size)
 2228                 Skip_BS(index_size,                             "extent_index");
 2229             if (offset_size)
 2230                 Skip_BS(offset_size,                            "extent_offset");
 2231             if (length_size)
 2232             {
 2233                 int32u extent_length;
 2234                 Get_BS (length_size, extent_length,             "extent_length");
 2235 
 2236                 FILLING_BEGIN();
 2237                     Streams[item_ID].stsz_StreamSize+=extent_length;
 2238                 FILLING_END();
 2239             }
 2240             Element_End0();
 2241         }
 2242         Element_End0();
 2243     }
 2244     BS_End();
 2245 }
 2246 
 2247 //---------------------------------------------------------------------------
 2248 void File_Mpeg4::meta_iprp()
 2249 {
 2250     Element_Name("Item Property");
 2251 
 2252     meta_iprp_ipma_Entries.clear();
 2253     delete[] meta_iprp_ipco_Buffer;
 2254     meta_iprp_ipco_Buffer=NULL;
 2255 }
 2256 
 2257 //---------------------------------------------------------------------------
 2258 void File_Mpeg4::meta_iprp_ipco()
 2259 {
 2260     Element_Name("Item Property Container");
 2261 
 2262     if (meta_iprp_ipma_Entries.empty())
 2263     {
 2264         meta_iprp_ipco_Buffer_Size=(size_t)Element_Size;
 2265         meta_iprp_ipco_Buffer=new int8u[meta_iprp_ipco_Buffer_Size];
 2266         memcpy(meta_iprp_ipco_Buffer, Buffer+Buffer_Offset, meta_iprp_ipco_Buffer_Size);
 2267 
 2268         Skip_XX(Element_Size,                                   "(Waiting, need ipma atom)");
 2269     }
 2270 }
 2271 
 2272 //---------------------------------------------------------------------------
 2273 #define FILLING_BEGIN_IPCO() \
 2274     { \
 2275         FILLING_BEGIN(); \
 2276             std::vector<int32u>& Entry=meta_iprp_ipma_Entries[meta_iprp_ipco_Buffer_Size]; \
 2277             size_t Entry_Size=Entry.size(); \
 2278             int64u Element_Offset_Save=Element_Offset; \
 2279             for (size_t i=0; i<Entry_Size; i++) \
 2280             { \
 2281                 moov_trak_tkhd_TrackID=Entry[i]; \
 2282                 META_CREATESTREAM(); \
 2283                 Element_Offset=Element_Offset_Save; \
 2284 
 2285 #define FILLING_END_IPCO() \
 2286             } \
 2287         FILLING_END(); \
 2288         meta_iprp_ipco_Buffer_Size++; \
 2289     } \
 2290 
 2291 //---------------------------------------------------------------------------
 2292 void File_Mpeg4::meta_iprp_ipco_av1C()
 2293 {
 2294     FILLING_BEGIN_IPCO();
 2295         moov_trak_mdia_minf_stbl_stsd_xxxx_av1C();
 2296     FILLING_END_IPCO();
 2297 }
 2298 
 2299 //---------------------------------------------------------------------------
 2300 void File_Mpeg4::meta_iprp_ipco_auxC()
 2301 {
 2302     NAME_VERSION_FLAG("Image Properties for Auxiliary Images");
 2303 
 2304     //Parsing
 2305     if (Version)
 2306         return;
 2307     Skip_NulString(                                             "name");
 2308 }
 2309 
 2310 //---------------------------------------------------------------------------
 2311 void File_Mpeg4::meta_iprp_ipco_avcC()
 2312 {
 2313     FILLING_BEGIN_IPCO();
 2314         moov_trak_mdia_minf_stbl_stsd_xxxx_avcC();
 2315     FILLING_END_IPCO();
 2316 }
 2317 
 2318 //---------------------------------------------------------------------------
 2319 void File_Mpeg4::meta_iprp_ipco_clap()
 2320 {
 2321     FILLING_BEGIN_IPCO();
 2322         moov_trak_mdia_minf_stbl_stsd_xxxx_clap();
 2323     FILLING_END_IPCO();
 2324 }
 2325 
 2326 //---------------------------------------------------------------------------
 2327 void File_Mpeg4::meta_iprp_ipco_clli()
 2328 {
 2329     FILLING_BEGIN_IPCO();
 2330         moov_trak_mdia_minf_stbl_stsd_xxxx_clli();
 2331     FILLING_END_IPCO();
 2332 }
 2333 
 2334 //---------------------------------------------------------------------------
 2335 void File_Mpeg4::meta_iprp_ipco_colr()
 2336 {
 2337     FILLING_BEGIN_IPCO();
 2338         moov_trak_mdia_minf_stbl_stsd_xxxx_colr();
 2339     FILLING_END_IPCO();
 2340 }
 2341 
 2342 //---------------------------------------------------------------------------
 2343 void File_Mpeg4::meta_iprp_ipco_hvcC()
 2344 {
 2345     int64u Element_Code_Save=Element_Code;
 2346     FILLING_BEGIN_IPCO();
 2347         Element_Code=Element_Code_Save;
 2348         moov_trak_mdia_minf_stbl_stsd_Pos=0;
 2349         moov_trak_mdia_minf_stbl_stsd_xxxx_hvcC();
 2350     FILLING_END_IPCO();
 2351 }
 2352 
 2353 //---------------------------------------------------------------------------
 2354 void File_Mpeg4::meta_iprp_ipco_imir()
 2355 {
 2356     Element_Name("ImageMirror");
 2357 
 2358     //Parsing
 2359     bool axis;
 2360     BS_Begin();
 2361     Skip_S1(6,                                                  "reserved");
 2362     Get_SB (axis,                                               "axis");
 2363     BS_End();
 2364 
 2365     FILLING_BEGIN_IPCO();
 2366         Fill(Stream_Video, StreamPos_Last, "Mirror", axis?"Horizontal":"Vertical");
 2367     FILLING_END_IPCO();
 2368 }
 2369 
 2370 //---------------------------------------------------------------------------
 2371 void File_Mpeg4::meta_iprp_ipco_irot()
 2372 {
 2373     Element_Name("Image Rotation");
 2374 
 2375     //Parsing
 2376     int8u angle;
 2377     BS_Begin();
 2378     Skip_S1(6,                                                  "reserved");
 2379     Get_S1 (2, angle,                                           "angle");
 2380     BS_End();
 2381 
 2382     FILLING_BEGIN_IPCO();
 2383         int32s Value=angle;
 2384         Value*=-90;
 2385         Fill(Stream_Video, StreamPos_Last, Video_Rotation, Value, 0);
 2386         if (Value)
 2387             Fill(Stream_Video, StreamPos_Last, Video_Rotation_String, Ztring::ToZtring(Value, 0)+__T("\xB0")); //degree sign
 2388     FILLING_END_IPCO();
 2389 }
 2390 
 2391 //---------------------------------------------------------------------------
 2392 void File_Mpeg4::meta_iprp_ipco_ispe()
 2393 {
 2394     NAME_VERSION_FLAG("Image Spatial Extents");
 2395 
 2396     //Parsing
 2397     if (Version)
 2398         return;
 2399     int32u image_width, image_height;
 2400     Get_B4 (image_width,                                        "image_width");
 2401     Get_B4 (image_height,                                       "image_height");
 2402 
 2403     FILLING_BEGIN_IPCO();
 2404         if (image_width)
 2405             Fill(Stream_Video, StreamPos_Last, Video_Width, image_width, 10, true);
 2406         if (image_height)
 2407             Fill(Stream_Video, StreamPos_Last, Video_Height, image_height, 10, true);
 2408     FILLING_END_IPCO();
 2409 }
 2410 
 2411 //---------------------------------------------------------------------------
 2412 void File_Mpeg4::meta_iprp_ipco_lsel()
 2413 {
 2414     Element_Name("Layer Selector");
 2415 
 2416     //Parsing
 2417     Skip_B2(                                                    "layer_id");
 2418 }
 2419 
 2420 //---------------------------------------------------------------------------
 2421 void File_Mpeg4::meta_iprp_ipco_mdcv()
 2422 {
 2423     FILLING_BEGIN_IPCO();
 2424         moov_trak_mdia_minf_stbl_stsd_xxxx_mdcv();
 2425     FILLING_END_IPCO();
 2426 }
 2427 
 2428 //---------------------------------------------------------------------------
 2429 void File_Mpeg4::meta_iprp_ipco_pasp()
 2430 {
 2431     FILLING_BEGIN_IPCO();
 2432         moov_trak_mdia_minf_stbl_stsd_xxxx_pasp();
 2433     FILLING_END_IPCO();
 2434 }
 2435 
 2436 //---------------------------------------------------------------------------
 2437 void File_Mpeg4::meta_iprp_ipco_pixi()
 2438 {
 2439     NAME_VERSION_FLAG("Pixel Information");
 2440 
 2441     //Parsing
 2442     int8u num_channels;
 2443     Get_B1 (num_channels,                                       "num_channels");
 2444 
 2445     set<int8u> bits_per_channel_List;
 2446     for (int8u Pos=0; Pos<num_channels; Pos++)
 2447     {
 2448         int8u bits_per_channel;
 2449         Get_B1 (bits_per_channel,                               "bits_per_channel");
 2450         bits_per_channel_List.insert(bits_per_channel);
 2451     }
 2452 
 2453     FILLING_BEGIN_IPCO();
 2454         if (bits_per_channel_List.size()==1)
 2455             Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_BitDepth), *bits_per_channel_List.begin());
 2456     FILLING_END_IPCO();
 2457 }
 2458 
 2459 //---------------------------------------------------------------------------
 2460 void File_Mpeg4::meta_iprp_ipco_rloc()
 2461 {
 2462     NAME_VERSION_FLAG("Relative Location");
 2463 
 2464     //Parsing
 2465     if (Version)
 2466         return;
 2467     Skip_B4(                                                    "horizontal_offset");
 2468     Skip_B4(                                                    "vertical_offset");
 2469 }
 2470 
 2471 //---------------------------------------------------------------------------
 2472 void File_Mpeg4::meta_iprp_ipma()
 2473 {
 2474     NAME_VERSION_FLAG("Item Property Association");
 2475 
 2476     //Parsing
 2477     int32u entry_count;
 2478     Get_B4 (entry_count,                                        "entry-count");
 2479 
 2480     for (int32u Pos=0; Pos<entry_count; Pos++)
 2481     {
 2482         Element_Begin1("entry");
 2483         int32u item_ID;
 2484         int8u association_count;
 2485         if (Version<1)
 2486         {
 2487             int16u item_ID2;
 2488             Get_B2 (item_ID2,                                  "item_ID");
 2489             item_ID=item_ID2;
 2490         }
 2491         else
 2492             Get_B4 (item_ID,                                    "item_ID");
 2493         Get_B1 (association_count,                              "association_count");
 2494         for (int8u j=0; j<association_count; j++)
 2495         {
 2496             Element_Begin1("association");
 2497             int16u property_index;
 2498             BS_Begin();
 2499             bool essential;
 2500             Get_SB(essential,                                   "essential");
 2501             Get_S2 ((Flags&1)?15:7, property_index,             "property_index");
 2502             BS_End();
 2503             Element_End0();
 2504             if (property_index)
 2505             {
 2506                 if (property_index-1>=meta_iprp_ipma_Entries.size())
 2507                     meta_iprp_ipma_Entries.resize(property_index);
 2508                 std::vector<int32u>& Entry=meta_iprp_ipma_Entries[property_index-1];
 2509                 if (find(Entry.begin(), Entry.end(), item_ID)==Entry.end())
 2510                     Entry.push_back(item_ID);
 2511             }
 2512         }
 2513         Element_End0();
 2514     }
 2515 
 2516     if (meta_iprp_ipco_Buffer)
 2517     {
 2518         Element_End0();
 2519         const int8u* Buffer_Save=Buffer;
 2520         size_t Buffer_Offset_Save=Buffer_Offset;
 2521         size_t Buffer_Size_Save=Buffer_Size;
 2522         int64u File_Offset_Save=File_Offset;
 2523         int64u Element_Size_Save=Element_Size;
 2524         Buffer=meta_iprp_ipco_Buffer;
 2525         Buffer_Offset=0;
 2526         Buffer_Size=meta_iprp_ipco_Buffer_Size;
 2527         File_Offset=0;
 2528         Element_Offset=0;
 2529         Element_Size=Buffer_Size;
 2530         Element_Begin1("Item Property Container (parsing)");
 2531         Element[Element_Level].Code=Elements::meta_iprp_ipco;
 2532         meta_iprp_ipco_Buffer_Size=0;
 2533         Open_Buffer_Continue(Buffer, Buffer_Size);
 2534         Element_End0();
 2535         Buffer=Buffer_Save;
 2536         Buffer_Offset=Buffer_Offset_Save;
 2537         Buffer_Size=Buffer_Size_Save;
 2538         File_Offset=File_Offset_Save;
 2539         Element_Offset=Element_Size_Save;
 2540         Element_Size=Element_Size_Save;
 2541         delete[] meta_iprp_ipco_Buffer; meta_iprp_ipco_Buffer=NULL;
 2542         Element_Begin0();
 2543         Element[Element_Level].Code=Elements::meta_iprp_ipma;
 2544     }
 2545 }
 2546 
 2547 //---------------------------------------------------------------------------
 2548 void File_Mpeg4::meta_iref()
 2549 {
 2550     NAME_VERSION_FLAG("Item Reference");
 2551     if (Version>1)
 2552     {
 2553         Element_Offset=Element_TotalSize_Get();
 2554         return;
 2555     }
 2556     Version_Temp=Version;
 2557 }
 2558 
 2559 //---------------------------------------------------------------------------
 2560 void File_Mpeg4::meta_iref_xxxx()
 2561 {
 2562     const char* From;
 2563     const char* To;
 2564     switch (Element_Code)
 2565     {
 2566         case 0x6175786C: Element_Name("Auxilary"); From="Auxilary"; To="Auxilary for"; break; //auxl
 2567         case 0x63647363: Element_Name("Content Describes"); From="Describes"; To="Describes for"; break; //cdsc
 2568         case 0x64696D67: Element_Name("Derived Image"); From="Derived"; To="Derived for"; break; //dimg
 2569         case 0x696C6F63: Element_Name("Item Location"); From="Location"; To="Location for"; break; //iloc
 2570         case 0x74686D62: Element_Name("Thumbnails"); From="Thumbnail"; To="Thumbnail for"; break; //thmb
 2571         default: From="Reference"; To="Reference for"; 
 2572     }
 2573 
 2574     //Parsing
 2575     int32u Version=Version_Temp;
 2576     int32u from_item_ID;
 2577     int16u ref_count;
 2578     Get_B4_DEPENDOFVERSION(1, from_item_ID,                     "from_item_ID");
 2579     Get_B2 (ref_count,                                          "ref_count");
 2580     for (int16u i=0; i<ref_count; i++)
 2581     {
 2582         int32u to_item_ID;
 2583         Get_B4_DEPENDOFVERSION(1, to_item_ID,                   "to_item_ID");
 2584         Streams[from_item_ID].Infos_List[To].push_back(to_item_ID);
 2585         Streams[to_item_ID].Infos_List[From].push_back(from_item_ID);
 2586     }
 2587 }
 2588 
 2589 //---------------------------------------------------------------------------
 2590 void File_Mpeg4::meta_pitm()
 2591 {
 2592     NAME_VERSION_FLAG("Primary Item Reference");
 2593 
 2594     //Parsing
 2595     if (Version>1)
 2596         return;
 2597     int32u item_ID;
 2598     Get_B4_DEPENDOFVERSION(1, item_ID,                          "item_ID");
 2599 
 2600     FILLING_BEGIN();
 2601         meta_pitm_item_ID=item_ID;
 2602         for (streams::iterator Temp=Streams.begin(); Temp!=Streams.end(); ++Temp)
 2603             if (Temp->first!=item_ID)
 2604                 Temp->second.IsEnabled=false;
 2605     FILLING_END();
 2606 }
 2607 
 2608 //---------------------------------------------------------------------------
 2609 void File_Mpeg4::mfra()
 2610 {
 2611     Element_Name("Movie Fragment Random Access");
 2612 }
 2613 
 2614 //---------------------------------------------------------------------------
 2615 void File_Mpeg4::mfra_mfro()
 2616 {
 2617     NAME_VERSION_FLAG("Movie Fragment Random Access Offset");
 2618 
 2619     //Parsing
 2620     Skip_B4(                                                    "size");
 2621 }
 2622 
 2623 //---------------------------------------------------------------------------
 2624 void File_Mpeg4::mfra_tfra()
 2625 {
 2626     NAME_VERSION_FLAG("Track Fragment Random Access");
 2627 
 2628     //Parsing
 2629     int32u number_of_entry;
 2630     int8u length_size_of_traf_num, length_size_of_trun_num, length_size_of_sample_num;
 2631     Skip_B4(                                                    "track_ID");
 2632     BS_Begin();
 2633     Skip_S1(26,                                                 "reserved");
 2634     Get_S1 (2, length_size_of_traf_num,                         "length_size_of_traf_num");
 2635     Get_S1 (2, length_size_of_trun_num,                         "length_size_of_trun_num");
 2636     Get_S1 (2, length_size_of_sample_num,                       "length_size_of_sample_num");
 2637     BS_End();
 2638     Get_B4(number_of_entry,                                     "number_of_entry");
 2639     for(int32u Pos=0; Pos<number_of_entry; Pos++)
 2640     {
 2641         Element_Begin1("entry");
 2642         int64u time, moof_offset;
 2643         Get_B_DEPENDOFVERSION(time,                             "time");
 2644         Get_B_DEPENDOFVERSION(moof_offset,                      "moof_offset");
 2645         switch (length_size_of_traf_num)
 2646         {
 2647             case 0 : Skip_B1(                                   "traf_number"); break;
 2648             case 1 : Skip_B2(                                   "traf_number"); break;
 2649             case 2 : Skip_B3(                                   "traf_number"); break;
 2650             case 3 : Skip_B4(                                   "traf_number"); break;
 2651             default: ;
 2652         }
 2653         switch (length_size_of_trun_num)
 2654         {
 2655             case 0 : Skip_B1(                                   "trun_num"); break;
 2656             case 1 : Skip_B2(                                   "trun_num"); break;
 2657             case 2 : Skip_B3(                                   "trun_num"); break;
 2658             case 3 : Skip_B4(                                   "trun_num"); break;
 2659             default: ;
 2660         }
 2661         switch (length_size_of_sample_num)
 2662         {
 2663             case 0 : Skip_B1(                                   "sample_num"); break;
 2664             case 1 : Skip_B2(                                   "sample_num"); break;
 2665             case 2 : Skip_B3(                                   "sample_num"); break;
 2666             case 3 : Skip_B4(                                   "sample_num"); break;
 2667             default: ;
 2668         }
 2669         Element_End0();
 2670     }
 2671 }
 2672 
 2673 //---------------------------------------------------------------------------
 2674 void File_Mpeg4::moof()
 2675 {
 2676     Element_Name("Movie Fragment");
 2677 
 2678     if (IsSecondPass)
 2679     {
 2680         Skip_XX(Element_TotalSize_Get(),                        "Data");
 2681         #if MEDIAINFO_HASH
 2682             if (Hash && !IsSecondPass)
 2683                 GoTo(File_Offset+Buffer_Offset+Element_TotalSize_Get()); //Hash will be done during second pass
 2684         #endif //MEDIAINFO_HASH
 2685         return;
 2686     }
 2687 
 2688     IsFragmented=true;
 2689     moof_base_data_offset=File_Offset+Buffer_Offset-Header_Size;
 2690     data_offset_present=true;
 2691 }
 2692 
 2693 //---------------------------------------------------------------------------
 2694 void File_Mpeg4::moof_mfhd()
 2695 {
 2696     NAME_VERSION_FLAG("Movie Fragment Header");
 2697 
 2698     //Parsing
 2699     Skip_B4(                                                    "sequence_number");
 2700 }
 2701 
 2702 //---------------------------------------------------------------------------
 2703 void File_Mpeg4::moof_traf()
 2704 {
 2705     Element_Name("Track Fragment");
 2706 
 2707     //Filling
 2708     moof_traf_base_data_offset=(int64u)-1;
 2709     if (Streams.empty())
 2710         Streams[(int32u)-1]; //Creating a virtual track in case there is no track
 2711     Stream=Streams.begin(); //Using first track in case there is no track header
 2712     moof_traf_default_sample_duration=Stream->second.mvex_trex_default_sample_duration;
 2713     moof_traf_default_sample_size=Stream->second.mvex_trex_default_sample_size;
 2714 }
 2715 
 2716 //---------------------------------------------------------------------------
 2717 void File_Mpeg4::moof_traf_sdtp()
 2718 {
 2719     NAME_VERSION_FLAG("Independent and Disposable Samples");
 2720 
 2721     //Parsing
 2722     //for (int32u Pos=0; Pos<sample_count; Pos++) //sample_count should be taken from stsz or stz2
 2723     while (Element_Offset<Element_Size)
 2724     {
 2725         Element_Begin1("sample");
 2726         BS_Begin();
 2727         Skip_S1(2,                                              "reserved");
 2728         Info_S1(2, sample_depends_on,                           "sample_depends_on"); Param_Info1(Mpeg4_sample_depends_on[sample_depends_on]);
 2729         Info_S1(2, sample_is_depended_on,                       "sample_is_depended_on"); Param_Info1(Mpeg4_sample_is_depended_on[sample_is_depended_on]);
 2730         Info_S1(2, sample_has_redundancy,                       "sample_has_redundancy"); Param_Info1(Mpeg4_sample_has_redundancy[sample_has_redundancy]);
 2731         BS_End();
 2732         Element_End0();
 2733     }
 2734 }
 2735 
 2736 //---------------------------------------------------------------------------
 2737 void File_Mpeg4::moof_traf_tfhd()
 2738 {
 2739     NAME_VERSION_FLAG("Track Fragment Header");
 2740 
 2741     //Parsing
 2742     bool base_data_offset_present, sample_description_index_present, default_sample_duration_present, default_sample_size_present, default_sample_flags_present;
 2743         Get_Flags (Flags,  0, base_data_offset_present,         "base-data-offset-present");
 2744         Get_Flags (Flags,  1, sample_description_index_present, "sample-description-index-present");
 2745         Get_Flags (Flags,  3, default_sample_duration_present,  "default-sample-duration-present");
 2746         Get_Flags (Flags,  4, default_sample_size_present,      "default-sample-size-present");
 2747         Get_Flags (Flags,  5, default_sample_flags_present,     "default-sample-flags-present");
 2748         Skip_Flags(Flags, 16,                                   "duration-is-empty");
 2749     Get_B4 (moov_trak_tkhd_TrackID,                             "track_ID");
 2750     if (base_data_offset_present)
 2751         Get_B8 (moof_traf_base_data_offset,                     "base_data_offset");
 2752     if (sample_description_index_present)
 2753         Skip_B4(                                                "sample_description_index");
 2754     if (default_sample_duration_present)
 2755         Get_B4 (moof_traf_default_sample_duration,              "default_sample_duration");
 2756     if (default_sample_size_present)
 2757         Get_B4 (moof_traf_default_sample_size,                  "default_sample_size");
 2758     if (default_sample_flags_present)
 2759         Skip_B4(                                                "default_sample_flags");
 2760 
 2761     FILLING_BEGIN();
 2762         Stream=Streams.find(moov_trak_tkhd_TrackID);
 2763         if (Stream==Streams.end())
 2764             Stream=Streams.begin();
 2765         if (!default_sample_duration_present)
 2766             moof_traf_default_sample_duration=Stream->second.mvex_trex_default_sample_duration;
 2767         if (!default_sample_size_present)
 2768             moof_traf_default_sample_size=Stream->second.mvex_trex_default_sample_size;
 2769     FILLING_END();
 2770 }
 2771 
 2772 //---------------------------------------------------------------------------
 2773 void File_Mpeg4::moof_traf_trun()
 2774 {
 2775     NAME_VERSION_FLAG("Track Fragment Run");
 2776 
 2777     //Parsing
 2778     int32u sample_count;
 2779     bool first_sample_flags_present, sample_duration_present, sample_size_present, sample_flags_present, sample_composition_time_offset_present;
 2780         Get_Flags (Flags,  0, data_offset_present,              "data-offset-present");
 2781         Get_Flags (Flags,  2, first_sample_flags_present,       "first-sample-flags-present");
 2782         Get_Flags (Flags,  8, sample_duration_present,          "sample-duration-present");
 2783         Get_Flags (Flags,  9, sample_size_present,              "sample-size-present");
 2784         Get_Flags (Flags, 10, sample_flags_present,             "sample-flags-present");
 2785         Get_Flags (Flags, 11, sample_composition_time_offset_present, "sample-composition-time-offsets-present");
 2786     Get_B4 (sample_count,                                       "sample_count");
 2787     int64u data_offset_Final=moof_traf_base_data_offset!=(int64u)-1?moof_traf_base_data_offset:moof_base_data_offset;
 2788     if (data_offset_present)
 2789     {
 2790         int32u data_offset;
 2791         Get_B4 (data_offset,                                    "data_offset");
 2792         data_offset_Final+=data_offset;
 2793     }
 2794 
 2795     //Filling
 2796     if (moof_traf_base_data_offset!=(int64u)-1 || data_offset_present)
 2797         Stream->second.stco.push_back(data_offset_Final);
 2798     stream::stsc_struct Stsc;
 2799     if (Stream->second.stsc.empty())
 2800         Stsc.FirstChunk=1;
 2801     else
 2802         Stsc.FirstChunk=Stream->second.stsc[Stream->second.stsc.size()-1].FirstChunk+1;
 2803     Stsc.SamplesPerChunk=sample_count;
 2804     Stream->second.stsc.push_back(Stsc);
 2805     FILLING_BEGIN();
 2806         if (!sample_duration_present)
 2807             Stream->second.moov_trak_mdia_minf_stbl_stts_Common(sample_count, moof_traf_default_sample_duration);
 2808     FILLING_END();
 2809     if (!sample_size_present)
 2810         Stream->second.stsz.resize(Stream->second.stsz.size()+sample_count, moof_traf_default_sample_size);
 2811 
 2812     if (first_sample_flags_present)
 2813         Skip_B4(                                                "first_sample_flags");
 2814     for (int32u Pos=0; Pos<sample_count; Pos++)
 2815     {
 2816         Element_Begin1("sample");
 2817         if (sample_duration_present)
 2818         {
 2819             int32u sample_duration;
 2820             Get_B4 (sample_duration,                            "sample_duration");
 2821 
 2822             FILLING_BEGIN(); 
 2823                 Stream->second.moov_trak_mdia_minf_stbl_stts_Common(1, sample_duration);
 2824             FILLING_END();
 2825         }
 2826         if (sample_size_present)
 2827         {
 2828             int32u sample_size;
 2829             Get_B4 (sample_size,                                "sample_size");
 2830 
 2831             //Filling
 2832             Stream->second.stsz_StreamSize+=sample_size;
 2833             Stream->second.stsz_Total.push_back(sample_size);
 2834             if (Stream->second.stsz.size()<FrameCount_MaxPerStream)
 2835                 Stream->second.stsz.push_back(sample_size);
 2836         }
 2837         if (sample_flags_present)
 2838             Skip_B4(                                            "sample_flags");
 2839         if (sample_composition_time_offset_present)
 2840             Skip_B4(                                            "sample_composition_time_offset");
 2841         Element_End0();
 2842     }
 2843 }
 2844 
 2845 //---------------------------------------------------------------------------
 2846 void File_Mpeg4::moov()
 2847 {
 2848     if (!Status[IsAccepted])
 2849     {
 2850         Data_Accept("MPEG-4");
 2851 
 2852         Fill(Stream_General, 0, General_Format, "QuickTime"); //If there is no ftyp atom, this is an old Quictime file
 2853     }
 2854     Element_Name("File header");
 2855 
 2856     if (IsSecondPass || FirstMoovPos!=(int64u)-1) //Currently, the 1 moov atom is used
 2857     {
 2858         Skip_XX(Element_TotalSize_Get(),                        "Data");
 2859         #if MEDIAINFO_HASH
 2860             if (Hash && !IsSecondPass)
 2861                 GoTo(File_Offset+Buffer_Offset+Element_TotalSize_Get()); //Hash will be done during second pass
 2862         #endif //MEDIAINFO_HASH
 2863         return;
 2864     }
 2865 
 2866     if (FirstMoovPos==(int64u)-1)
 2867         FirstMoovPos=File_Offset+Buffer_Offset-Header_Size;
 2868     /*
 2869     else
 2870     {
 2871         //In case of more than 1 moov atom, the last one is used (previous ones are trashed)
 2872         Streams.clear();
 2873         for (size_t StreamKind=Stream_General+1; StreamKind<Stream_Max; StreamKind++)
 2874             while (Count_Get((stream_t)StreamKind))
 2875                 Stream_Erase((stream_t)StreamKind, Count_Get((stream_t)StreamKind)-1);
 2876     }
 2877     */
 2878 }
 2879 
 2880 //-------------------------------------------------------------------------
 2881 void File_Mpeg4::moov_ainf()
 2882 {
 2883     NAME_VERSION_FLAG("Asset Information");
 2884 
 2885     //Parsing
 2886     Skip_C4(                                                    "profile_version");
 2887     Skip_String(Element_Size-Element_Offset,                    "APID");
 2888 }
 2889 
 2890 //---------------------------------------------------------------------------
 2891 void File_Mpeg4::moov_cmov()
 2892 {
 2893     Element_Name("Compressed file header");
 2894 }
 2895 
 2896 //---------------------------------------------------------------------------
 2897 void File_Mpeg4::moov_cmov_cmvd()
 2898 {
 2899     Element_Name("Data");
 2900 
 2901     switch (moov_cmov_dcom_Compressor)
 2902     {
 2903         case Elements::moov_cmov_dcom_zlib : moov_cmov_cmvd_zlib(); break;
 2904         default: Skip_XX(Element_Size,                          "Data");
 2905     }
 2906 }
 2907 
 2908 //---------------------------------------------------------------------------
 2909 void File_Mpeg4::moov_cmov_cmvd_zlib()
 2910 {
 2911     Element_Name("Zlib");
 2912 
 2913     //Parsing
 2914     int32u Dest_Size32;
 2915     Get_B4(Dest_Size32,                                         "Destination size");
 2916 
 2917     FILLING_BEGIN();
 2918         //Sizes
 2919         unsigned long Source_Size=(unsigned long)(Element_Size-Element_Offset);
 2920         unsigned long Dest_Size=Dest_Size32;
 2921 
 2922         //Uncompressing
 2923         int8u* Dest=new int8u[Dest_Size];
 2924         if (uncompress((Bytef*)Dest, &Dest_Size, (const Bytef*)Buffer+Buffer_Offset+4, Source_Size)<0)
 2925         {
 2926             Skip_XX(Element_Size,                               "Problem during the decompression");
 2927             delete[] Dest; //Dest=NULL;
 2928             return;
 2929         }
 2930 
 2931         //Exiting this element
 2932         Skip_XX(Element_Size-Element_Offset,                    "Will be parsed");
 2933 
 2934         //Configuring level
 2935         std::vector<int64u> Element_Sizes_Sav;
 2936         size_t Element_Level_Sav=Element_Level;
 2937         while(Element_Level)
 2938         {
 2939             Element_Sizes_Sav.push_back(Element_TotalSize_Get());
 2940             Element_End0();
 2941         }
 2942 
 2943         //Configuring buffer
 2944         const int8u* Buffer_Sav=Buffer;
 2945         size_t Buffer_Size_Sav=Buffer_Size;
 2946         int8u* Buffer_Temp_Sav=Buffer_Temp;
 2947         size_t Buffer_Temp_Size_Sav=Buffer_Temp_Size;
 2948         size_t Buffer_Offset_Sav=Buffer_Offset;
 2949         size_t Buffer_Offset_Temp_Sav=Buffer_Offset_Temp;
 2950         Buffer=NULL;
 2951         Buffer_Size=0;
 2952         Buffer_Temp=NULL;
 2953         Buffer_Temp_Size=0;
 2954         Buffer_Offset=0;
 2955         Buffer_Offset_Temp=0;
 2956 
 2957         //Configuring file size
 2958         int64u File_Offset_Sav=File_Offset;
 2959         int64u File_Size_Sav=File_Size;
 2960         if (File_Size<File_Offset+Buffer_Offset+Element_Offset+Dest_Size)
 2961             File_Size=File_Offset+Buffer_Offset+Element_Offset+Dest_Size;
 2962         Element_Level++;
 2963         Header_Fill_Size(File_Size);
 2964         Element_Level--;
 2965 
 2966         //Configuring some status info
 2967         FirstMoovPos=(int64u)-1;
 2968 
 2969         //Parsing
 2970         Buffer=Dest;
 2971         Buffer_Size=Dest_Size;
 2972         while (Open_Buffer_Continue_Loop());
 2973         delete[] Dest; //Dest=NULL;
 2974 
 2975         //Resetting file info
 2976         File_Offset=File_Offset_Sav;
 2977         File_Size=File_Size_Sav;
 2978 
 2979         //Resetting buffer
 2980         Buffer=Buffer_Sav;
 2981         Buffer_Size=Buffer_Size_Sav;
 2982         Buffer_Temp=Buffer_Temp_Sav;
 2983         Buffer_Temp_Size=Buffer_Temp_Size_Sav;
 2984         Buffer_Offset=Buffer_Offset_Sav;
 2985         Buffer_Offset_Temp=Buffer_Offset_Temp_Sav;
 2986 
 2987         //Configuring level
 2988         while(Element_Level)
 2989             Element_End0();
 2990         Element_Level++;
 2991         Header_Fill_Size(File_Size-(File_Offset+Buffer_Offset));
 2992         Element_Level--;
 2993         while(Element_Level<Element_Level_Sav)
 2994         {
 2995             Element_Begin1(__T("...Continued")); //TODO: better method
 2996             Element_Begin1(__T("...Continued"));
 2997             Header_Fill_Size(Element_Sizes_Sav[0]);
 2998             Element_End0();
 2999         }
 3000 
 3001         //Filling
 3002         Fill(Stream_General, 0, General_Format_Settings, "Compressed header");
 3003     FILLING_END();
 3004 }
 3005 
 3006 //---------------------------------------------------------------------------
 3007 void File_Mpeg4::moov_ctab()
 3008 {
 3009     Element_Name("Color Table");
 3010 
 3011     //Parsing
 3012     int16u Size;
 3013     Skip_B4(                                                    "Color table seed");
 3014     Skip_B2(                                                    "Color table flags");
 3015     Get_B2 (Size,                                               "Color table size");
 3016     for (int16u Pos=0; Pos<=Size; Pos++)
 3017     {
 3018         Skip_B2(                                                "Zero");
 3019         Skip_B2(                                                "Red");
 3020         Skip_B2(                                                "Green");
 3021         Skip_B2(                                                "Blue");
 3022     }
 3023 }
 3024 
 3025 //---------------------------------------------------------------------------
 3026 void File_Mpeg4::moov_cmov_dcom()
 3027 {
 3028     Element_Name("Data compressor name");
 3029 
 3030     //Parsing
 3031     Get_C4 (moov_cmov_dcom_Compressor,                          "Value");
 3032 }
 3033 
 3034 //---------------------------------------------------------------------------
 3035 void File_Mpeg4::moov_iods()
 3036 {
 3037     NAME_VERSION_FLAG("Initial object descriptor");
 3038     INTEGRITY_VERSION(0);
 3039 
 3040     FILLING_BEGIN();
 3041         Descriptors();
 3042     FILLING_END();
 3043 }
 3044 
 3045 //---------------------------------------------------------------------------
 3046 void File_Mpeg4::moov_meta()
 3047 {
 3048     Element_Name("Metadata");
 3049 
 3050     //Filling
 3051     moov_meta_hdlr_Type=0;
 3052 }
 3053 
 3054 //---------------------------------------------------------------------------
 3055 void File_Mpeg4::moov_meta_bxml()
 3056 {
 3057     NAME_VERSION_FLAG("Binary XML"); //ISO/IEC 14496-12
 3058     INTEGRITY(moov_meta_hdlr_Type==Elements::moov_meta_hdlr_mp7b, "Bad meta type");
 3059 
 3060     //Parsing
 3061     Skip_XX(Element_Size-Element_Offset,                        "Binary XML dump");
 3062 }
 3063 
 3064 //---------------------------------------------------------------------------
 3065 void File_Mpeg4::moov_meta_hdlr()
 3066 {
 3067     NAME_VERSION_FLAG("Metadata Header"); //ISO/IEC 14496-12 handler
 3068 
 3069     //Parsing
 3070     Skip_C4(                                                    "Type (Quicktime)"); //Filled if Quicktime
 3071     Get_C4 (moov_meta_hdlr_Type,                                "Metadata type");
 3072     if (Element_Offset+12<=Element_Size)
 3073     {
 3074         Skip_C4(                                                "Manufacturer");
 3075         Skip_B4(                                                "Component reserved flags"); //Filled if Quicktime
 3076         Skip_B4(                                                "Component reserved flags mask"); //Filled if Quicktime
 3077         if (Element_Offset<Element_Size)
 3078             Skip_UTF8(Element_Size-Element_Offset,              "Component type name");
 3079     }
 3080     else if (Element_Offset<Element_Size)
 3081         Skip_XX(Element_Size-Element_Offset,                    "Unknown");
 3082 }
 3083 
 3084 //---------------------------------------------------------------------------
 3085 void File_Mpeg4::moov_meta_keys()
 3086 {
 3087     NAME_VERSION_FLAG("Keys");
 3088     INTEGRITY(moov_meta_hdlr_Type==Elements::moov_meta_hdlr_mdta, "Bad meta type");
 3089 
 3090     //Parsing
 3091     Skip_B4(                                                    "Count");
 3092 }
 3093 
 3094 //---------------------------------------------------------------------------
 3095 void File_Mpeg4::moov_meta_keys_mdta()
 3096 {
 3097     Element_Name("Name");
 3098     INTEGRITY(moov_meta_hdlr_Type==Elements::moov_meta_hdlr_mdta, "Bad meta type");
 3099 
 3100     //Parsing
 3101     std::string Value;
 3102     Get_String(Element_Size, Value,                             "Value");
 3103 
 3104     //Filling
 3105     moov_udta_meta_keys_List.push_back(Value);
 3106 }
 3107 
 3108 //---------------------------------------------------------------------------
 3109 void File_Mpeg4::moov_meta_ilst()
 3110 {
 3111     Element_Name("List");
 3112 
 3113     //Filling
 3114     moov_udta_meta_keys_ilst_Pos=0;
 3115 }
 3116 
 3117 //---------------------------------------------------------------------------
 3118 void File_Mpeg4::moov_meta_ilst_xxxx()
 3119 {
 3120     Element_Name("Element");
 3121 
 3122     //Filling
 3123     moov_meta_ilst_xxxx_name_Name.clear(); //useful if metadata type = "mdir"
 3124 }
 3125 
 3126 //---------------------------------------------------------------------------
 3127 void File_Mpeg4::moov_meta_ilst_xxxx_data()
 3128 {
 3129     Element_Name("Data");
 3130 
 3131     //Parsing
 3132     int32u Kind, Language;
 3133     Ztring Value;
 3134     Get_B4(Kind,                                                  "Kind"); Param_Info1(Mpeg4_Meta_Kind(Kind));
 3135 
 3136     //Error detection
 3137     switch (Element_Code_Get(Element_Level-1))
 3138     {
 3139         case Elements::moov_meta__disk :
 3140         case Elements::moov_meta__trkn :
 3141                                          if (Kind)
 3142                                          {
 3143                                              //Not normal
 3144                                              Kind=0x00;
 3145                                          }
 3146         default                        : ;
 3147     }
 3148 
 3149     switch (Kind)
 3150     {
 3151         case 0x00 : //Binary
 3152                     Get_B4(Language,                            "Language");
 3153                     switch (Element_Code_Get(Element_Level-1))
 3154                     {
 3155                         case Elements::moov_meta__disk :
 3156                             {
 3157                             //Parsing
 3158                             int16u Position, Total;
 3159                             Skip_B2(                            "Reserved");
 3160                             Get_B2(Position,                    "Position");
 3161                             Get_B2(Total,                       "Total");
 3162                             if (Element_Offset+2<=Element_Size)
 3163                                 Skip_B2(                        "Reserved"); //Sometimes there are 2 more bytes, unknown
 3164 
 3165                             //Filling
 3166                             if (Position)
 3167                                 Fill(Stream_General, 0, General_Part_Position, Position, 10, true);
 3168                             if (Total)
 3169                                 Fill(Stream_General, 0, General_Part_Position_Total, Total, 10, true);
 3170                             }
 3171                             return;
 3172                         case Elements::moov_meta__trkn :
 3173                             {
 3174                             //Parsing
 3175                             int16u Position, Total;
 3176                             Skip_B2(                            "Reserved");
 3177                             Get_B2(Position,                    "Position");
 3178                             Get_B2(Total,                       "Total");
 3179                             if (Element_Offset+2<=Element_Size)
 3180                                 Skip_B2(                        "Reserved"); //Sometimes there are 2 more bytes, unknown
 3181 
 3182                             //Filling
 3183                             if (Position)
 3184                                 Fill(Stream_General, 0, General_Track_Position, Position, 10, true);
 3185                             if (Total)
 3186                                 Fill(Stream_General, 0, General_Track_Position_Total, Total, 10, true);
 3187                             }
 3188                             return;
 3189                         case Elements::moov_meta__covr :
 3190                             {
 3191                             //Filling
 3192                             #if MEDIAINFO_ADVANCED
 3193                                 if (MediaInfoLib::Config.Flags1_Get(Flags_Cover_Data_base64))
 3194                                 {
 3195                                     std::string Data_Raw((const char*)(Buffer+(size_t)(Buffer_Offset+Element_Offset)), (size_t)(Element_Size-Element_Offset));
 3196                                     std::string Data_Base64(Base64::encode(Data_Raw));
 3197                                     Fill(Stream_General, 0, General_Cover_Data, Data_Base64);
 3198                                 }
 3199                             #endif //MEDIAINFO_ADVANCED
 3200                             Fill(Stream_General, 0, General_Cover, "Yes");
 3201 
 3202                             Skip_XX(Element_Size-Element_Offset, "Data");
 3203                             }
 3204                             return;
 3205                         case Elements::moov_meta__gnre :
 3206                             {
 3207                             if (Element_Size-Element_Offset==2)
 3208                             {
 3209                                 int16u Genre;
 3210                                 Get_B2(Genre,                   "Genre");
 3211 
 3212                                 //Filling
 3213                                 if (Genre)
 3214                                     Fill(Stream_General, 0, General_Genre, Genre-1);
 3215                             }
 3216                             else
 3217                                 Skip_XX(Element_Size-Element_Offset,"Data");
 3218                             }
 3219                             return;
 3220                         default:
 3221                             Skip_XX(Element_Size-Element_Offset,"To decode!");
 3222                             Value=__T("(Binary)");
 3223                     }
 3224                     break;
 3225         case 0x01 : //UTF-8
 3226                     Get_B4(Language,                            "Language");
 3227                     switch (Element_Code_Get(Element_Level-1))
 3228                     {
 3229                         case Elements::moov_meta___day :
 3230                             {
 3231                             std::string ValueS;
 3232                             Get_String(Element_Size-Element_Offset, ValueS, "Value");
 3233                             Value.Date_From_String(ValueS.c_str(), ValueS.size());
 3234                             }
 3235                             break;
 3236                         default:
 3237                             Get_UTF8(Element_Size-Element_Offset, Value, "Value");
 3238                     }
 3239                      break;
 3240         case 0x02 : //UTF-16
 3241                     Value=__T("UTF-16 encoding not yet supported");
 3242                     break;
 3243         case 0x03 : //Mac String
 3244                     Get_B4(Language,                            "Language"); //To confirm
 3245                     Get_UTF8(Element_Size-Element_Offset, Value, "Value");
 3246                     break;
 3247         case 0x0D : //JPEG
 3248                     Get_B4(Language,                            "Language");
 3249                     switch (Element_Code_Get(Element_Level-1))
 3250                     {
 3251                         case Elements::moov_meta__covr :
 3252                             {
 3253                             //Filling
 3254                             #if MEDIAINFO_ADVANCED
 3255                                 if (MediaInfoLib::Config.Flags1_Get(Flags_Cover_Data_base64))
 3256                                 {
 3257                                     std::string Data_Raw((const char*)(Buffer+(size_t)(Buffer_Offset+Element_Offset)), (size_t)(Element_Size-Element_Offset));
 3258                                     std::string Data_Base64(Base64::encode(Data_Raw));
 3259                                     Fill(Stream_General, 0, General_Cover_Data, Data_Base64);
 3260                                 }
 3261                             #endif //MEDIAINFO_ADVANCED
 3262                             Fill(Stream_General, 0, General_Cover, "Yes");
 3263 
 3264                             Skip_XX(Element_Size-Element_Offset, "Data");
 3265                             }
 3266                             return;
 3267                         default:
 3268                             Value=__T("(Binary)");
 3269                     }
 3270                     break;
 3271         case 0x0E : //PNG
 3272                     Get_B4(Language,                            "Language");
 3273                     switch (Element_Code_Get(Element_Level-1))
 3274                     {
 3275                         case Elements::moov_meta__covr :
 3276                             {
 3277                             //Filling
 3278                             #if MEDIAINFO_ADVANCED
 3279                                 if (MediaInfoLib::Config.Flags1_Get(Flags_Cover_Data_base64))
 3280                                 {
 3281                                     std::string Data_Raw((const char*)(Buffer+(size_t)(Buffer_Offset+Element_Offset)), (size_t)(Element_Size-Element_Offset));
 3282                                     std::string Data_Base64(Base64::encode(Data_Raw));
 3283                                     Fill(Stream_General, 0, General_Cover_Data, Data_Base64);
 3284                                 }
 3285                             #endif //MEDIAINFO_ADVANCED
 3286                             Fill(Stream_General, 0, General_Cover, "Yes");
 3287 
 3288                             Skip_XX(Element_Size-Element_Offset, "Data");
 3289                             }
 3290                             return;
 3291                         default:
 3292                             Value=__T("(Binary)");
 3293                     }
 3294                     break;
 3295         case 0x15 : //Signed Integer
 3296                     {
 3297                     Get_B4(Language,                            "Language");
 3298                     switch (Element_Size-Element_Offset)
 3299                     {
 3300                         case 1 : {int8u  ValueI; Get_B1(ValueI, "Value"); Value.From_Number((int8s) ValueI);}; break;
 3301                         case 2 : {int16u ValueI; Get_B2(ValueI, "Value"); Value.From_Number((int16s)ValueI);}; break;
 3302                         case 4 : {int32u ValueI; Get_B4(ValueI, "Value"); Value.From_Number((int32s)ValueI);}; break;
 3303                         case 8 : {int64u ValueI; Get_B8(ValueI, "Value"); Value.From_Number((int64s)ValueI);}; break;
 3304                         default  : Value=__T("Unknown kind of integer value!");
 3305                     }
 3306                     }
 3307                     break;
 3308         case 0x16 : //Float 32
 3309                     Skip_XX(4,                                  "To decode!");
 3310                     //Value=__T("Float32 encoding not yet supported");
 3311                     break;
 3312         case 0x17 : //Float 64
 3313                     Skip_XX(8,                                  "To decode!");
 3314                     //Value=__T("Float64 encoding not yet supported");
 3315                     break;
 3316         default: Value=__T("Unknown kind of value!");
 3317    }
 3318 
 3319     switch (moov_meta_hdlr_Type)
 3320     {
 3321         case Elements::moov_meta_hdlr_mdir :
 3322             {
 3323                 FILLING_BEGIN();
 3324                     std::string Parameter;
 3325                     if (Element_Code_Get(Element_Level-1)==Elements::moov_meta______)
 3326                     {
 3327                         if (moov_meta_ilst_xxxx_name_Name=="iTunMOVI" && Element_Size>8)
 3328                         {
 3329                             #if defined(MEDIAINFO_PROPERTYLIST_YES)
 3330                                 File_PropertyList MI;
 3331                                 Open_Buffer_Init(&MI);
 3332                                 Open_Buffer_Continue(&MI, Buffer+Buffer_Offset+8, (size_t)(Element_Size-8));
 3333                                 Open_Buffer_Finalize(&MI);
 3334                                 Merge(MI, Stream_General, 0, 0);
 3335                             #endif //defined(MEDIAINFO_PROPERTYLIST_YES)
 3336                         }
 3337                         else
 3338                             Metadata_Get(Parameter, moov_meta_ilst_xxxx_name_Name);
 3339                     }
 3340                     else
 3341                         Metadata_Get(Parameter, Element_Code_Get(Element_Level-1));
 3342                     if (Parameter=="Encoded_Application")
 3343                     {
 3344                         if (Value.find(__T("Nero AAC codec"))==0)
 3345                         {
 3346                             ZtringList List; List.Separator_Set(0, __T(" / "));
 3347                             List.Write(Value);
 3348                             Element_Info1(Parameter.c_str());
 3349                             Fill(Stream_Audio, StreamPos_Last, Audio_Encoded_Library_Name, List(0), true);
 3350                             Fill(Stream_Audio, StreamPos_Last, Audio_Encoded_Library_Version, List(1), true);
 3351                             Parameter.clear(); //Set as already filled
 3352                         }
 3353                     }
 3354                     if (Parameter=="cdec")
 3355                     {
 3356                         if (Value.find(__T("ndaudio "))==0)
 3357                         {
 3358                             ZtringList List; List.Separator_Set(0, __T(" / "));
 3359                             List.Write(Value);
 3360                             Element_Info1(Parameter.c_str());
 3361                             Fill(Stream_Audio, StreamPos_Last, Audio_Encoded_Library_Name, "Nero AAC codec", Unlimited, true, true);
 3362                             Fill(Stream_Audio, StreamPos_Last, Audio_Encoded_Library_Name, List(0).substr(8, string::npos), true);
 3363                             Fill(Stream_Audio, StreamPos_Last, Audio_Encoded_Library_Settings, List(1), true);
 3364                             Parameter.clear(); //Set as already filled
 3365                         }
 3366                     }
 3367                     if (Parameter=="Compilation" || Parameter=="HDVideo" || Parameter=="iTunesU" || Parameter=="Podcast")
 3368                     {
 3369                         if (Value==__T("1"))
 3370                             Value=__T("Yes");
 3371                         else
 3372                             Value.clear(); //This is usually set to 0 even if the user did not explicitely indicated something (default)
 3373                     }
 3374                     if (Parameter=="BPM")
 3375                     {
 3376                         if (Value==__T("0"))
 3377                             Value.clear();
 3378                     }
 3379                     if (Parameter=="ContentType")
 3380                     {
 3381                              if (Value==__T("0"))  Value=__T("Movie");
 3382                         else if (Value==__T("1"))  Value=__T("Music");
 3383                         else if (Value==__T("2"))  Value=__T("Audiobook");
 3384                         else if (Value==__T("5"))  Value=__T("Whacked Bookmark");
 3385                         else if (Value==__T("6"))  Value=__T("Music Video");
 3386                         else if (Value==__T("9"))  Value=__T("Short Film");
 3387                         else if (Value==__T("10")) Value=__T("TV Show");
 3388                         else if (Value==__T("11")) Value=__T("Booklet");
 3389                         else if (Value==__T("14")) Value=__T("Ringtone");
 3390                         else if (Value==__T("21")) Value=__T("Podcast");
 3391                         else Value=__T("Unknown Type");
 3392                         Fill(Stream_General, 0, General_ContentType, Value);
 3393                     }
 3394                     if (Parameter=="AppleStoreAccountType")
 3395                     {
 3396                         if (Value==__T("0"))
 3397                             Value=__T("iTunes");
 3398                         else
 3399                             Value=__T("AOL");
 3400                         Fill(Stream_General, 0, General_ServiceName, Value);
 3401                     }
 3402                     if (Parameter=="Rating")
 3403                     {
 3404                              if (Value==__T("0")) Value=__T("None");
 3405                         else if (Value==__T("2")) Value=__T("Clean");
 3406                         else Value=__T("Explicit");
 3407                     }
 3408                     if (Parameter=="AppleStoreCountry")
 3409                     {
 3410                              if (Value==__T("143441")) Value=__T("United States");
 3411                         else if (Value==__T("143442")) Value=__T("France");
 3412                         else if (Value==__T("143443")) Value=__T("Germany");
 3413                         else if (Value==__T("143444")) Value=__T("United Kingdom");
 3414                         else if (Value==__T("143445")) Value=__T("Austria");
 3415                         else if (Value==__T("143446")) Value=__T("Belgium");
 3416                         else if (Value==__T("143447")) Value=__T("Finland");
 3417                         else if (Value==__T("143448")) Value=__T("Greece");
 3418                         else if (Value==__T("143449")) Value=__T("Ireland");
 3419                         else if (Value==__T("143450")) Value=__T("Italy");
 3420                         else if (Value==__T("143451")) Value=__T("Luxembourg");
 3421                         else if (Value==__T("143452")) Value=__T("Netherlands");
 3422                         else if (Value==__T("143453")) Value=__T("Portugal");
 3423                         else if (Value==__T("143454")) Value=__T("Spain");
 3424                         else if (Value==__T("143455")) Value=__T("Canada");
 3425                         else if (Value==__T("143456")) Value=__T("Sweden");
 3426                         else if (Value==__T("143457")) Value=__T("Norway");
 3427                         else if (Value==__T("143458")) Value=__T("Denmark");
 3428                         else if (Value==__T("143459")) Value=__T("Switzerland");
 3429                         else if (Value==__T("143460")) Value=__T("Australia");
 3430                         else if (Value==__T("143461")) Value=__T("New Zealand");
 3431                         else if (Value==__T("143462")) Value=__T("Japan");
 3432                         else if (Value==__T("143463")) Value=__T("Hong Kong");
 3433                         else if (Value==__T("143464")) Value=__T("Singapore");
 3434                         else if (Value==__T("143466")) Value=__T("South Korea");
 3435                         else if (Value==__T("143467")) Value=__T("India");
 3436                         else if (Value==__T("143468")) Value=__T("Mexico");
 3437                         else if (Value==__T("143469")) Value=__T("Russia");
 3438                         else if (Value==__T("143470")) Value=__T("Taiwan");
 3439                         else if (Value==__T("143471")) Value=__T("Vietnam");
 3440                         else if (Value==__T("143473")) Value=__T("Malaysia");
 3441                         else if (Value==__T("143474")) Value=__T("Philippines");
 3442                         else if (Value==__T("143475")) Value=__T("Thailand");
 3443                         else if (Value==__T("143476")) Value=__T("Indonesia");
 3444                         else if (Value==__T("143479")) Value=__T("Saudi Arabia");
 3445                         else if (Value==__T("143480")) Value=__T("Turkey");
 3446                         else if (Value==__T("143481")) Value=__T("United Arab Emirates");
 3447                         else if (Value==__T("143482")) Value=__T("Hungary");
 3448                         else if (Value==__T("143483")) Value=__T("Chile");
 3449                         else if (Value==__T("143485")) Value=__T("Panama");
 3450                         else if (Value==__T("143487")) Value=__T("Romania");
 3451                         else if (Value==__T("143488")) Value=__T("Maldives");
 3452                         else if (Value==__T("143489")) Value=__T("Czech Republic");
 3453                         else if (Value==__T("143492")) Value=__T("Ukraine");
 3454                         else if (Value==__T("143494")) Value=__T("Croatia");
 3455                         else if (Value==__T("143495")) Value=__T("Costa Rica");
 3456                         else if (Value==__T("143498")) Value=__T("Qatar");
 3457                         else if (Value==__T("143501")) Value=__T("Colombia");
 3458                         else if (Value==__T("143502")) Value=__T("Venezuela");
 3459                         else if (Value==__T("143503")) Value=__T("Brazil");
 3460                         else if (Value==__T("143504")) Value=__T("Guatemala");
 3461                         else if (Value==__T("143505")) Value=__T("Argentina");
 3462                         else if (Value==__T("143506")) Value=__T("El Salvador");
 3463                         else if (Value==__T("143507")) Value=__T("Peru");
 3464                         else if (Value==__T("143508")) Value=__T("Dominican Republic");
 3465                         else if (Value==__T("143509")) Value=__T("Ecuador");
 3466                         else if (Value==__T("143510")) Value=__T("Honduras");
 3467                         else if (Value==__T("143511")) Value=__T("Jamaica");
 3468                         else if (Value==__T("143512")) Value=__T("Nicaragua");
 3469                         else if (Value==__T("143513")) Value=__T("Paraguay");
 3470                         else if (Value==__T("143514")) Value=__T("Uruguay");
 3471                         else if (Value==__T("143516")) Value=__T("Egypt");
 3472                         else if (Value==__T("143520")) Value=__T("Lithuania");
 3473                         else if (Value==__T("143526")) Value=__T("Bulgaria");
 3474                         else if (Value==__T("143529")) Value=__T("Kenya");
 3475                         else if (Value==__T("143539")) Value=__T("The Bahamas");
 3476                         else if (Value==__T("143541")) Value=__T("Barbados");
 3477                         else if (Value==__T("143553")) Value=__T("Guyana");
 3478                         else if (Value==__T("143555")) Value=__T("Belize");
 3479                         else if (Value==__T("143556")) Value=__T("Bolivia");
 3480                         else if (Value==__T("143558")) Value=__T("Iceland");
 3481                         else if (Value==__T("143565")) Value=__T("Belarus");
 3482                         else if (Value==__T("143583")) Value=__T("Fiji Islands");
 3483                         else if (Value==__T("143597")) Value=__T("Papua New Guinea");
 3484                     }
 3485                     if (!Parameter.empty())
 3486                     {
 3487                         Element_Info1(Parameter.c_str());
 3488                         if (Value!=Retrieve(Stream_General, 0, Parameter.c_str()))
 3489                             Fill(Stream_General, 0, Parameter.c_str(), Value);
 3490                     }
 3491                 FILLING_END();
 3492             }
 3493             break;
 3494         case Elements::moov_meta_hdlr_mdta :
 3495             if(!moov_udta_meta_keys_List.empty())
 3496             {
 3497                 FILLING_BEGIN();
 3498                     std::string Parameter;
 3499                     int32u keys_Pos=Element_Code_Get(Element_Level-1);
 3500                     if (keys_Pos && keys_Pos<=moov_udta_meta_keys_List.size())
 3501                         Metadata_Get(Parameter, moov_udta_meta_keys_List[keys_Pos-1]);
 3502                     if (Parameter=="Recorded_Date" && Value.size()>=10 && Value[4]==__T(':') && Value[7]==__T(':'))
 3503                     {
 3504                         Value[4]=__T('-');
 3505                         Value[7]=__T('-');
 3506                     }
 3507                     if (Parameter=="com.apple.quicktime.version")
 3508                         Vendor_Version=Value.SubString(__T(""), __T(" "));
 3509                     else if (Parameter=="com.apple.quicktime.player.version")
 3510                         Vendor_Version=Value.SubString(__T(""), __T(" "));
 3511                     else if (Parameter=="com.apple.quicktime.comment")
 3512                         Fill(Stream_General, 0, General_Comment, Value, true);
 3513                     else if (Parameter=="com.apple.quicktime.description")
 3514                         Fill(Stream_General, 0, General_Description, Value, true);
 3515                     else if (Parameter=="com.apple.finalcutstudio.media.uuid")
 3516                         Fill(Stream_General, 0, "Media/UUID", Value);
 3517                     else if (Parameter=="com.apple.finalcutstudio.media.history.uuid")
 3518                         Fill(Stream_General, 0, "Media/History/UUID", Value);
 3519                     else if (Parameter=="com.universaladid.idregistry")
 3520                     {
 3521                         Fill(Stream_General, 0, "UniversalAdID_Registry", Value);
 3522                         Fill_SetOptions(Stream_General, 0, "UniversalAdID_Registry", "N NTY");
 3523                         if (!Retrieve(Stream_General, 0, "UniversalAdID_Value").empty())
 3524                         {
 3525                             Fill(Stream_General, 0, "UniversalAdID/String", Value+__T(" (")+Retrieve(Stream_General, 0, "UniversalAdID_Registry")+__T(")"), true);
 3526                             Fill_SetOptions(Stream_General, 0, "UniversalAdID/String", "Y NTN");
 3527                         }
 3528                     }
 3529                     else if (Parameter=="com.universaladid.idvalue")
 3530                     {
 3531                         Fill(Stream_General, 0, "UniversalAdID_Value", Value);
 3532                         Fill_SetOptions(Stream_General, 0, "UniversalAdID_Value", "N NTY");
 3533                         if (!Retrieve(Stream_General, 0, "UniversalAdID_Registry").empty())
 3534                         {
 3535                             Fill(Stream_General, 0, "UniversalAdID/String", Value+__T(" (")+Retrieve(Stream_General, 0, "UniversalAdID_Registry")+__T(")"), true);
 3536                             Fill_SetOptions(Stream_General, 0, "UniversalAdID/String", "Y NTN");
 3537                         }
 3538                     }
 3539                     else if (Parameter=="DisplayAspectRatio")
 3540                     {
 3541                         DisplayAspectRatio=Value;
 3542                         size_t i=DisplayAspectRatio.find(':');
 3543                         if (i!=string::npos)
 3544                             DisplayAspectRatio.From_Number(Ztring(DisplayAspectRatio.substr(0, i)).To_float64()/Ztring(DisplayAspectRatio.substr(i+1)).To_float64(), 3);
 3545                     }
 3546                     else if (!Parameter.empty())
 3547                         Fill(Stream_General, 0, Parameter.c_str(), Value, true);
 3548                 FILLING_END();
 3549                 moov_udta_meta_keys_ilst_Pos++;
 3550             }
 3551             else
 3552                 Param2("Keys atom is missing!", 0);
 3553             break;
 3554         case Elements::moov_udta_meta :
 3555             {
 3556                 FILLING_BEGIN();
 3557                     std::string Parameter;
 3558                     Metadata_Get(Parameter, (int32u)Element_Code_Get(Element_Level-1));
 3559                     if (!Parameter.empty())
 3560                         Fill(Stream_General, 0, Parameter.c_str(), Value, true);
 3561                 FILLING_END();
 3562             }
 3563         default: ;
 3564     }
 3565 }
 3566 
 3567 //---------------------------------------------------------------------------
 3568 void File_Mpeg4::moov_meta_ilst_xxxx_mean()
 3569 {
 3570     Element_Name("Mean");
 3571 
 3572     //Parsing
 3573     Skip_B4(                                                    "Unknown");
 3574     Skip_UTF8(Element_Size-Element_Offset,                      "Value");
 3575 }
 3576 
 3577 //---------------------------------------------------------------------------
 3578 void File_Mpeg4::moov_meta_ilst_xxxx_name()
 3579 {
 3580     Element_Name("Name");
 3581 
 3582     //Parsing
 3583     Skip_B4(                                                    "Unknown");
 3584     Get_String(Element_Size-Element_Offset, moov_meta_ilst_xxxx_name_Name, "Value");
 3585 }
 3586 
 3587 //---------------------------------------------------------------------------
 3588 void File_Mpeg4::moov_meta_xml()
 3589 {
 3590     NAME_VERSION_FLAG("XML"); //ISO/IEC 14496-12
 3591     INTEGRITY(moov_meta_hdlr_Type==Elements::moov_meta_hdlr_mp7t, "Bad meta type");
 3592 
 3593     //Parsing
 3594     Skip_XX(Element_Size-Element_Offset,                        "XML dump");
 3595 }
 3596 
 3597 //---------------------------------------------------------------------------
 3598 void File_Mpeg4::moov_mvex()
 3599 {
 3600     Element_Name("Movie Extends");
 3601 }
 3602 
 3603 //---------------------------------------------------------------------------
 3604 void File_Mpeg4::moov_mvex_mehd()
 3605 {
 3606     NAME_VERSION_FLAG("Movie Extends Header");
 3607 
 3608     //Parsing
 3609     int64u fragment_duration;
 3610     Get_B_DEPENDOFVERSION(fragment_duration,                    "fragment_duration");
 3611 }
 3612 
 3613 //---------------------------------------------------------------------------
 3614 void File_Mpeg4::moov_mvex_trex()
 3615 {
 3616     NAME_VERSION_FLAG("Movie Extends Defaults");
 3617 
 3618     //Parsing
 3619     int32u default_sample_duration;
 3620     int32u default_sample_size;
 3621     Get_B4 (moov_trak_tkhd_TrackID,                             "track_ID");
 3622     Skip_B4(                                                    "default_sample_description_index");
 3623     Get_B4 (default_sample_duration,                            "default_sample_duration");
 3624     Get_B4 (default_sample_size,                                "default_sample_size");
 3625     Element_Begin1("default_sample_flags");
 3626         BS_Begin();
 3627         Skip_S1(6,                                              "reserved");
 3628         Skip_S1(2,                                              "sample_depends_on");
 3629         Skip_S1(2,                                              "sample_is_depended_on");
 3630         Skip_S1(2,                                              "sample_has_redundancy");
 3631         Skip_S1(3,                                              "sample_padding_value");
 3632         Skip_SB(                                                "sample_is_difference_sample");
 3633         BS_End();
 3634         Skip_B2(                                                "sample_degradation_priority");
 3635     Element_End0();
 3636 
 3637     FILLING_BEGIN();
 3638         Streams[moov_trak_tkhd_TrackID].mvex_trex_default_sample_duration=default_sample_duration;
 3639         Streams[moov_trak_tkhd_TrackID].mvex_trex_default_sample_size=default_sample_size;
 3640     FILLING_END();
 3641 }
 3642 
 3643 //---------------------------------------------------------------------------
 3644 void File_Mpeg4::moov_mvhd()
 3645 {
 3646     NAME_VERSION_FLAG("Movie header");
 3647 
 3648     //Parsing
 3649     Ztring Date_Created, Date_Modified;
 3650     int64u Duration;
 3651     float32 a, b, u, c, d, v, x, y, w;
 3652     int32u Rate;
 3653     int16u Volume;
 3654     Get_DATE1904_DEPENDOFVERSION(Date_Created,                  "Creation time");
 3655     Get_DATE1904_DEPENDOFVERSION(Date_Modified,                 "Modification time");
 3656     Get_B4(moov_mvhd_TimeScale,                                 "Time scale"); Param_Info1(Ztring::ToZtring(moov_mvhd_TimeScale)+__T(" Hz"));
 3657     Get_B_DEPENDOFVERSION(Duration,                             "Duration"); Param_Info1C(moov_mvhd_TimeScale, Ztring::ToZtring((int64u)Duration*1000/moov_mvhd_TimeScale)+__T(" ms"));
 3658     Get_B4 (Rate,                                               "Preferred rate"); Param_Info1(Ztring::ToZtring(((float32)Rate)/0x10000));
 3659     Get_B2 (Volume,                                             "Preferred volume"); Param_Info1(Ztring::ToZtring(((float32)Volume)/0x100));
 3660     Skip_XX(10,                                                 "Reserved");
 3661     Element_Begin1("Matrix structure");
 3662         Get_BFP4(16, a,                                         "a (width scale)");
 3663         Get_BFP4(16, b,                                         "b (width rotate)");
 3664         Get_BFP4( 2, u,                                         "u (width angle)");
 3665         Get_BFP4(16, c,                                         "c (height rotate)");
 3666         Get_BFP4(16, d,                                         "d (height scale)");
 3667         Get_BFP4( 2, v,                                         "v (height angle)");
 3668         Get_BFP4(16, x,                                         "x (position left)");
 3669         Get_BFP4(16, y,                                         "y (position top)");
 3670         Get_BFP4( 2, w,                                         "w (divider)");
 3671     Element_End0();
 3672     Skip_B4(                                                    "Preview time");
 3673     Skip_B4(                                                    "Preview duration");
 3674     Skip_B4(                                                    "Poster time");
 3675     Skip_B4(                                                    "Selection time");
 3676     Skip_B4(                                                    "Selection duration");
 3677     Skip_B4(                                                    "Current time");
 3678     Skip_B4(                                                    "Next track ID");
 3679 
 3680     FILLING_BEGIN();
 3681         //if (moov_mvhd_TimeScale)
 3682         //{
 3683             //int32u Duration=(int32u)(((float)Duration)/TimeScale*1000);
 3684             //Fill("Duration", Duration);
 3685         //}
 3686         if (Date_Created.find(__T('\r'))!=std::string::npos)
 3687             Date_Created.resize(Date_Created.find(__T('\r')));
 3688         if (Date_Created.find(__T('\n'))!=std::string::npos)
 3689             Date_Created.resize(Date_Created.find(__T('\n')));
 3690         Fill(Stream_General, 0, "Encoded_Date", Date_Created);
 3691         if (Date_Modified.find(__T('\r'))!=std::string::npos)
 3692             Date_Modified.resize(Date_Modified.find(__T('\r')));
 3693         if (Date_Modified.find(__T('\n'))!=std::string::npos)
 3694             Date_Modified.resize(Date_Modified.find(__T('\n')));
 3695         Fill(Stream_General, 0, "Tagged_Date", Date_Modified);
 3696     FILLING_END();
 3697 }
 3698 
 3699 //---------------------------------------------------------------------------
 3700 void File_Mpeg4::moov_trak()
 3701 {
 3702     Element_Name("Track");
 3703 
 3704     FILLING_BEGIN();
 3705         Fill_Flush();
 3706         moov_trak_tkhd_TrackID=(int32u)-1;
 3707         moov_trak_tkhd_Width=0;
 3708         moov_trak_tkhd_Height=0;
 3709         moov_trak_tkhd_DisplayAspectRatio=0;
 3710         moov_trak_tkhd_Rotation=0;
 3711         Stream_Prepare(Stream_Max); //clear filling
 3712         Streams.erase((int32u)-1);
 3713         Fill(StreamKind_Last, StreamPos_Last, General_StreamOrder, StreamOrder);
 3714         ++StreamOrder;
 3715     FILLING_END();
 3716 }
 3717 
 3718 //---------------------------------------------------------------------------
 3719 void File_Mpeg4::moov_trak_edts()
 3720 {
 3721     Element_Name("Edit");
 3722 }
 3723 
 3724 //---------------------------------------------------------------------------
 3725 void File_Mpeg4::moov_trak_edts_elst()
 3726 {
 3727     NAME_VERSION_FLAG("Edit List");
 3728 
 3729     //Parsing
 3730     int32u Count;
 3731     Get_B4 (Count,                                              "Number of entries");
 3732     for (int32u Pos=0; Pos<Count; Pos++)
 3733     {
 3734         stream::edts_struct edts;
 3735         Element_Begin1("Entry");
 3736         Get_B_DEPENDOFVERSION(edts.Duration,                    "Track duration"); Param_Info2C(moov_mvhd_TimeScale, (int64u)edts.Duration*1000/moov_mvhd_TimeScale, " ms");
 3737         Get_B_DEPENDOFVERSION(edts.Delay,                       "Media time"); Param_Info2C(moov_mvhd_TimeScale && (edts.Delay!=(int32u)-1), (int64u)edts.Delay*1000/moov_mvhd_TimeScale, " ms");
 3738         Get_B4 (edts.Rate,                                      "Media rate"); Param_Info1(((float)edts.Rate)/0x10000);
 3739         Element_End0();
 3740 
 3741         Streams[moov_trak_tkhd_TrackID].edts.push_back(edts);
 3742     }
 3743 }
 3744 
 3745 //---------------------------------------------------------------------------
 3746 void File_Mpeg4::moov_trak_load()
 3747 {
 3748     Element_Name("Preload");
 3749 
 3750     //Parsing
 3751     Info_B4(PreloadTime,                                        "Preload time"); Param_Info2C(moov_mvhd_TimeScale, PreloadTime*1000/moov_mvhd_TimeScale, " ms");
 3752     Info_B4(PreloadFlags,                                       "Flags");
 3753         Skip_Flags(PreloadFlags, 0,                             "PreloadAlways");
 3754         Skip_Flags(PreloadFlags, 1,                             "TrackEnabledPreload");
 3755     Info_B4(HintFlags,                                          "Hint flags");
 3756         Skip_Flags(HintFlags,  2,                               "KeepInBuffer");
 3757         Skip_Flags(HintFlags,  8,                               "HighQuality");
 3758         Skip_Flags(HintFlags, 20,                               "SingleFieldPlayback");
 3759         Skip_Flags(HintFlags, 26,                               "DeinterlaceFields");
 3760 }
 3761 
 3762 //---------------------------------------------------------------------------
 3763 void File_Mpeg4::moov_trak_mdia()
 3764 {
 3765     Element_Name("Media");
 3766 }
 3767 
 3768 //---------------------------------------------------------------------------
 3769 void File_Mpeg4::moov_trak_mdia_hdlr()
 3770 {
 3771     NAME_VERSION_FLAG("Handler Reference");
 3772 
 3773     //Parsing
 3774     Ztring Title;
 3775     int32u Type, SubType, Manufacturer;
 3776     Get_C4 (Type,                                               "Component type");
 3777     Get_C4 (SubType,                                            "Component subtype");
 3778     Get_C4 (Manufacturer,                                       "Component manufacturer");
 3779     Skip_B4(                                                    "Component flags");
 3780     Skip_B4(                                                    "Component flags mask");
 3781     if (Element_Offset<Element_Size)
 3782     {
 3783         //Found 3 types, whatever is the ftyp:
 3784         //- copy of Type
 3785         //- QuickTime style
 3786         //- ISO style (with or without '\0')
 3787         //With sometimes sub-boxes
 3788 
 3789         //If it is a copy of Type
 3790         bool NameIsParsed=false;
 3791         if (Element_Offset+4==Element_Size || (Element_Offset+4<Element_Size && Buffer[Buffer_Offset+(size_t)Element_Offset+4]=='\0'))
 3792         {
 3793             int32u SubType2;
 3794             Peek_B4(SubType2);
 3795             if (SubType2==SubType)
 3796             {
 3797                 Skip_C4(                                        "Component name");
 3798                 NameIsParsed=true;
 3799             }
 3800         }
 3801         //QuickTime style or ISO style
 3802         if (!NameIsParsed)
 3803         {
 3804             //Looking for trailing nul
 3805             size_t Pos=(size_t)Element_Offset;
 3806             while (Pos<Element_Size && Buffer[Buffer_Offset+Pos]!='\0')
 3807                 Pos++;
 3808 
 3809             //Trying to guess if it is QuickTime style, with all invalid "flavors" found in files (lot of zeroes in the name, size includes the size byte...)
 3810             int8u Size;
 3811             Peek_B1(Size);
 3812             bool IsMacStyle;
 3813             if (Size<0x20 || Element_Offset+1+Size==Element_Size || Element_Offset+1+Size==Pos || (Pos+1<Element_Size && Element_Offset+2+Size==Pos))
 3814             {
 3815                 IsMacStyle=true;
 3816                 if (Element_Offset+Size==Element_Size)
 3817                     Size--;
 3818             }
 3819             else
 3820                 IsMacStyle=false;
 3821 
 3822             //Parsing
 3823             if (IsMacStyle)
 3824             {
 3825                 Skip_B1(                                        IsQt()?"Component name size":"Component name size (not in specs)"); // This is an invalid stream if MP4
 3826                 if (Element_Offset+Size<=Element_Size)
 3827                     Get_MacRoman(Size, Title,                   "Component name");
 3828                 else
 3829                     Skip_XX(Element_Size-Element_Offset,        "Component name decoding issue, skiping");
 3830             }
 3831             else
 3832             {
 3833                 Get_UTF8(Pos-Element_Offset, Title,             "Component name");
 3834                 if (Element_Offset<Element_Size)
 3835                     Element_Offset++; // Skip trailing nul
 3836             }
 3837         }
 3838         
 3839         if (Title.find(__T("Handler"))!=string::npos || Title.find(__T(" handler"))!=string::npos || Title.find(__T("Gestionnaire "))==0 || Title.find(__T("Module "))==0 || Title.find(__T("Gestor "))==0 || Title.find(__T("Procedura "))==0)
 3840             Title.clear(); //This is not a Title
 3841     }
 3842 
 3843     FILLING_BEGIN();
 3844         if (!Title.empty() && Retrieve(Stream_General, 0, General_Title).empty()) Fill(StreamKind_Last, StreamPos_Last, "Title",    Title);
 3845 
 3846         switch (SubType)
 3847         {
 3848             case Elements::moov_trak_mdia_hdlr_clcp :
 3849                 if (StreamKind_Last!=Stream_Text)
 3850                 {
 3851                     Stream_Prepare(Stream_Text);
 3852                 }
 3853                 break;
 3854             case Elements::moov_trak_mdia_hdlr_data :
 3855                 if (StreamKind_Last!=Stream_Other)
 3856                 {
 3857                     Stream_Prepare(Stream_Other);
 3858                     Fill(Stream_Other, StreamPos_Last, Other_Type, "Data");
 3859                 }
 3860                 break;
 3861             case Elements::moov_trak_mdia_hdlr_soun :
 3862                 if (StreamKind_Last!=Stream_Audio)
 3863                 {
 3864                     Stream_Prepare(Stream_Audio);
 3865                 }
 3866                 break;
 3867             case Elements::moov_trak_mdia_hdlr_vide :
 3868                 if (StreamKind_Last!=Stream_Video)
 3869                 {
 3870                     Stream_Prepare(Stream_Video);
 3871                 }
 3872                 break;
 3873             case Elements::moov_trak_mdia_hdlr_text :
 3874             case Elements::moov_trak_mdia_hdlr_sbtl :
 3875                 if (StreamKind_Last!=Stream_Text)
 3876                 {
 3877                     if (Streams[moov_trak_tkhd_TrackID].IsChapter)
 3878                         Stream_Prepare(Stream_Menu);
 3879                     else
 3880                     {
 3881                         Stream_Prepare(Stream_Text);
 3882                         if (SubType!=Elements::moov_trak_mdia_hdlr_text)
 3883                             Fill(Stream_Text, StreamPos_Last, Text_MuxingMode, Ztring().From_CC4(SubType));
 3884                     }
 3885                 }
 3886                 break;
 3887             case Elements::moov_trak_mdia_hdlr_twen :
 3888                 if (StreamKind_Last!=Stream_Text)
 3889                 {
 3890                     Stream_Prepare(Stream_Other);
 3891                     Fill(Stream_Other, StreamPos_Last, Other_Type, "Tween");
 3892                 }
 3893                 break;
 3894             case Elements::moov_trak_mdia_hdlr_tmcd :
 3895                 if (StreamKind_Last!=Stream_Text)
 3896                 {
 3897                     Stream_Prepare(Stream_Other);
 3898                     Fill(Stream_Other, StreamPos_Last, Other_Type, "Time code");
 3899                     Fill(Stream_Other, StreamPos_Last, Other_Format, "QuickTime TC");
 3900                 }
 3901                 break;
 3902             case Elements::moov_trak_mdia_hdlr_subp :
 3903                 if (StreamKind_Last!=Stream_Text)
 3904                 {
 3905                     Stream_Prepare(Stream_Text);
 3906                     //CodecID_Fill(__T("subp"), Stream_Text, StreamPos_Last, InfoCodecID_Format_Mpeg4); //Prioritizing ObjectTypeIndication over SubType
 3907                     //Fill(StreamKind_Last, StreamPos_Last, Text_Codec, "subp");
 3908                 }
 3909                 break;
 3910             case Elements::moov_trak_mdia_hdlr_subt :
 3911                 if (StreamKind_Last!=Stream_Text)
 3912                 {
 3913                     Stream_Prepare(Stream_Text);
 3914                 }
 3915                 break;
 3916             case Elements::moov_trak_mdia_hdlr_MPEG :
 3917                 mdat_MustParse=true; //Data is in MDAT
 3918             case Elements::moov_trak_mdia_hdlr_alis :
 3919                 //Stream_Prepare(Stream_Other);
 3920                 //Fill(Stream_Other, StreamPos_Last, Other_Type, "Alias"); //TODO: what is the meaning of such hdlr?
 3921                 break;
 3922             case Elements::moov_trak_mdia_hdlr_hint :
 3923                 if (StreamKind_Last==Stream_Max) //Note: some files have both vmhd and hmhd, I don't know the meaning of such header, so skipping hmhd for the moment
 3924                 {
 3925                     Stream_Prepare(Stream_Other);
 3926                     Fill(Stream_Other, StreamPos_Last, Other_Type, "Hint");
 3927                     Streams[moov_trak_tkhd_TrackID].StreamKind=Stream_Other;
 3928                     Streams[moov_trak_tkhd_TrackID].StreamPos=StreamPos_Last;
 3929                 }
 3930                 break;
 3931             case Elements::moov_trak_mdia_hdlr_ocsm :
 3932                 if (StreamKind_Last!=Stream_Other)
 3933                     Stream_Prepare(Stream_Other);
 3934                 Fill(Stream_Other, StreamPos_Last, Other_Type, "Object content information");
 3935                 break;
 3936             case Elements::moov_trak_mdia_hdlr_odsm :
 3937                 if (StreamKind_Last!=Stream_Other)
 3938                     Stream_Prepare(Stream_Other);
 3939                 Fill(Stream_Other, StreamPos_Last, Other_Type, "Object description");
 3940                 break;
 3941             case Elements::moov_trak_mdia_hdlr_sdsm :
 3942                 if (StreamKind_Last!=Stream_Other)
 3943                     Stream_Prepare(Stream_Other);
 3944                 Fill(Stream_Other, StreamPos_Last, Other_Type, "Scene description");
 3945                 break;
 3946             default:
 3947                 if (!Streams[moov_trak_tkhd_TrackID].hdlr_SubType) //TODO: check what is the best method to detect SubType (moov_trak_mdia_hdlr vs moov_trak_mdia_minf_hdlr)
 3948                 {
 3949                     Streams[moov_trak_tkhd_TrackID].hdlr_Type=Type;
 3950                     Streams[moov_trak_tkhd_TrackID].hdlr_SubType=SubType;
 3951                     Streams[moov_trak_tkhd_TrackID].hdlr_Manufacturer=Manufacturer;
 3952                 }
 3953         }
 3954 
 3955         if (StreamKind_Last!=Stream_Max)
 3956         {
 3957             Streams[moov_trak_tkhd_TrackID].StreamKind=StreamKind_Last;
 3958             Streams[moov_trak_tkhd_TrackID].StreamPos=StreamPos_Last;
 3959         }
 3960 
 3961         if (Manufacturer!=0x00000000)
 3962         {
 3963             if (Vendor==0x00000000)
 3964                 Vendor=Manufacturer;
 3965             else if (Vendor!=Manufacturer)
 3966                 Vendor=0xFFFFFFFF; //Two names, this is two much
 3967         }
 3968     FILLING_END();
 3969 }
 3970 
 3971 //---------------------------------------------------------------------------
 3972 void File_Mpeg4::moov_trak_mdia_imap()
 3973 {
 3974     Element_Name("Non-primary source input map");
 3975 
 3976     //Parsing
 3977     Skip_B4(                                                    "Unknown");
 3978     Skip_B4(                                                    "Unknown");
 3979     Skip_B4(                                                    "Unknown");
 3980 }
 3981 
 3982 //---------------------------------------------------------------------------
 3983 void File_Mpeg4::moov_trak_mdia_imap_sean()
 3984 {
 3985     //Parsing
 3986     Skip_B4(                                                    "Unknown");
 3987     Skip_B4(                                                    "Unknown");
 3988     Skip_B4(                                                    "Unknown");
 3989 }
 3990 
 3991 //---------------------------------------------------------------------------
 3992 void File_Mpeg4::moov_trak_mdia_imap_sean___in()
 3993 {
 3994     Element_Name("Input");
 3995 
 3996     //Parsing
 3997     Skip_B4(                                                    "Atom ID");
 3998     Skip_B2(                                                    "Zero");
 3999     Skip_B2(                                                    "Number of internal atoms");
 4000     Skip_B4(                                                    "Zero");
 4001 }
 4002 
 4003 //---------------------------------------------------------------------------
 4004 void File_Mpeg4::moov_trak_mdia_imap_sean___in___ty()
 4005 {
 4006     Element_Name("Input type");
 4007 
 4008     //Parsing
 4009     Info_B4(TypeModifierName,                                   "Type modifier name"); Param_Info1(Mpeg4_TypeModifierName(TypeModifierName));
 4010 }
 4011 
 4012 //---------------------------------------------------------------------------
 4013 void File_Mpeg4::moov_trak_mdia_imap_sean___in_dtst()
 4014 {
 4015     //Parsing
 4016     Skip_B4(                                                    "Unknown");
 4017     Skip_B4(                                                    "Unknown");
 4018     Skip_B4(                                                    "Unknown");
 4019     Skip_C4(                                                    "Unknown");
 4020 }
 4021 
 4022 //---------------------------------------------------------------------------
 4023 void File_Mpeg4::moov_trak_mdia_imap_sean___in_obid()
 4024 {
 4025     Element_Name("Object ID");
 4026 
 4027     //Parsing
 4028     Skip_B4(                                                    "Object ID");
 4029 }
 4030 
 4031 //---------------------------------------------------------------------------
 4032 void File_Mpeg4::moov_trak_mdia_mdhd()
 4033 {
 4034     NAME_VERSION_FLAG("Media Header");
 4035 
 4036     //Parsing
 4037     Ztring Date_Created, Date_Modified;
 4038     int64u Duration;
 4039     int32u TimeScale;
 4040     int16u Language;
 4041     Get_DATE1904_DEPENDOFVERSION(Date_Created,                  "Creation time");
 4042     Get_DATE1904_DEPENDOFVERSION(Date_Modified,                 "Modification time");
 4043     Get_B4(TimeScale,                                           "Time scale");
 4044     Get_B_DEPENDOFVERSION(Duration,                             "Duration"); Param_Info2C(TimeScale, Duration*1000/TimeScale, " ms");
 4045     Get_B2 (Language,                                           "Language"); Param_Info1(Language_Get(Language));
 4046     Skip_B2(                                                    "Quality");
 4047 
 4048     FILLING_BEGIN();
 4049         Fill(StreamKind_Last, StreamPos_Last, "Language", Language_Get(Language));
 4050         Streams[moov_trak_tkhd_TrackID].mdhd_Duration=Duration;
 4051         Streams[moov_trak_tkhd_TrackID].mdhd_TimeScale=TimeScale;
 4052 
 4053         //Coherency tests
 4054         if (Streams[moov_trak_tkhd_TrackID].tkhd_Duration*1.01>=Duration*0.99 && Streams[moov_trak_tkhd_TrackID].tkhd_Duration*0.99<=Duration*1.01 && TimeScale && moov_mvhd_TimeScale!=TimeScale && moov_mvhd_TimeScale)
 4055         {
 4056             float64 Ratio=((float64)TimeScale)/((float64)moov_mvhd_TimeScale);
 4057             Streams[moov_trak_tkhd_TrackID].tkhd_Duration=float64_int64s(Streams[moov_trak_tkhd_TrackID].tkhd_Duration/Ratio);
 4058             Clear(StreamKind_Last, StreamPos_Last, "Duration_Source");
 4059             Fill(StreamKind_Last, StreamPos_Last, "Duration", float64_int64s(((float64)Streams[moov_trak_tkhd_TrackID].tkhd_Duration)*1000/((float64)moov_mvhd_TimeScale)), 10, true);
 4060         }
 4061     FILLING_END();
 4062 }
 4063 
 4064 //---------------------------------------------------------------------------
 4065 void File_Mpeg4::moov_trak_mdia_minf()
 4066 {
 4067     Element_Name("Media Information");
 4068 }
 4069 
 4070 //---------------------------------------------------------------------------
 4071 void File_Mpeg4::moov_trak_mdia_minf_code()
 4072 {
 4073     Element_Name("code (found in Avid?)");
 4074 
 4075     //Parsing
 4076     Skip_B4(                                                    "Unknown");
 4077     Skip_B4(                                                    "Unknown");
 4078     Skip_B4(                                                    "Unknown");
 4079 }
 4080 
 4081 //---------------------------------------------------------------------------
 4082 void File_Mpeg4::moov_trak_mdia_minf_code_sean()
 4083 {
 4084     Element_Name("sean (found in Avid?)");
 4085 
 4086     //Parsing
 4087     Skip_B4(                                                    "Unknown");
 4088     Skip_B4(                                                    "Unknown");
 4089     Skip_B4(                                                    "Unknown");
 4090 }
 4091 
 4092 //---------------------------------------------------------------------------
 4093 void File_Mpeg4::moov_trak_mdia_minf_code_sean_RU_A()
 4094 {
 4095     Element_Name("RU*A (found in Avid?)");
 4096 
 4097     //Parsing
 4098     Ztring Path;
 4099     Skip_B4(                                                    "Unknown");
 4100     Skip_B4(                                                    "Unknown");
 4101     Skip_B4(                                                    "Unknown");
 4102     Get_UTF8(Element_Size-Element_Offset, Path,                 "Path?");
 4103 
 4104     FILLING_BEGIN();
 4105         Streams[moov_trak_tkhd_TrackID].File_Name=Path;
 4106     FILLING_END();
 4107 }
 4108 
 4109 //---------------------------------------------------------------------------
 4110 void File_Mpeg4::moov_trak_mdia_minf_dinf()
 4111 {
 4112     Element_Name("Data Information");
 4113 }
 4114 
 4115 //---------------------------------------------------------------------------
 4116 void File_Mpeg4::moov_trak_mdia_minf_dinf_url_()
 4117 {
 4118     NAME_VERSION_FLAG("Data Location");
 4119 
 4120     //Parsing
 4121     Skip_UTF8(Element_Size-Element_Offset,                      "location");
 4122 }
 4123 
 4124 //---------------------------------------------------------------------------
 4125 void File_Mpeg4::moov_trak_mdia_minf_dinf_urn_()
 4126 {
 4127     NAME_VERSION_FLAG("Data Name");
 4128 
 4129     //Parsing
 4130     Skip_UTF8(Element_Size-Element_Offset,                      "name TODO location after null string");
 4131     //Skip_UTF8(Element_Size,                                     location);
 4132 }
 4133 
 4134 //---------------------------------------------------------------------------
 4135 void File_Mpeg4::moov_trak_mdia_minf_dinf_dref()
 4136 {
 4137     NAME_VERSION_FLAG("Data Reference");
 4138 
 4139     //Parsing
 4140     Skip_B4(                                                    "entry_count");
 4141 }
 4142 
 4143 //---------------------------------------------------------------------------
 4144 static const size_t MacAlias_Size=16;
 4145 static const char* MacAlias[MacAlias_Size]=
 4146 {
 4147     "Directory Name",
 4148     "Directory IDs",
 4149     "Absolute Path",
 4150     "AppleShare Zone Name",
 4151     "AppleShare Server Name",
 4152     "AppleShare User Name",
 4153     "Driver Name",
 4154     NULL,
 4155     NULL,
 4156     "Revised AppleShare info",
 4157     "AppleRemoteAccess dialup info",
 4158     NULL,
 4159     NULL,
 4160     NULL,
 4161     "file name (Unicode)?",
 4162     "volume name (Unicode)?",
 4163 };
 4164 void File_Mpeg4::moov_trak_mdia_minf_dinf_dref_alis()
 4165 {
 4166     NAME_VERSION_FLAG("Alias"); //bit 0 = external/internal data
 4167 
 4168     //Often empty
 4169     bool IsInternal;
 4170         Get_Flags (Flags,    0, IsInternal,                     "IsInternal");
 4171     if (IsInternal)
 4172         return; //Internal stream, no alias
 4173 
 4174     //Parsing
 4175     Ztring file_name_string, volume_name_string, Directory_Name;
 4176     int16u record_size, record_version, alias_kind;
 4177     int8u volume_name_string_length, file_name_string_length;
 4178     Element_Begin1("Mac OS Alias Record");
 4179     Skip_B4(                                                    "user type name/app creator code");
 4180     Get_B2 (record_size,                                        "record size");
 4181     Get_B2 (record_version,                                     "record version");
 4182     if (record_version!=2)
 4183     {
 4184         Skip_XX(Element_Size-Element_Offset,                    "unknown");
 4185         return;
 4186     }
 4187     int64u End=Element_Offset-8+record_size;
 4188     if (End>Element_Size)
 4189         End=Element_Size; //Found one file having record_size = the size of the atom, header included
 4190     Get_B2 (alias_kind,                                         "alias kind"); Param_Info1(alias_kind?"directory":"file");
 4191     Get_B1 (volume_name_string_length,                          "volume name string length");
 4192     if (volume_name_string_length>27)
 4193         volume_name_string_length=27;
 4194     Get_UTF8(volume_name_string_length, volume_name_string,     "volume name string");
 4195     if (volume_name_string_length<27)
 4196         Skip_XX(27-volume_name_string_length,                   "volume name string padding");
 4197     Skip_B4(                                                    "volume created mac local date"); //seconds since beginning 1904 to 2040
 4198     Skip_B2(                                                    "file system type");
 4199     Skip_B2(                                                    "drive type");
 4200     Skip_B4(                                                    "parent directory ID");
 4201     Get_B1 (file_name_string_length,                            "file name string length");
 4202     if (file_name_string_length>99)
 4203         file_name_string_length=99;
 4204     Get_UTF8(file_name_string_length, file_name_string,         "file name string");
 4205     if (file_name_string_length<63)
 4206         Skip_XX(63-file_name_string_length,                     "file name string padding");
 4207     if (file_name_string_length<=63)
 4208         Skip_B4(                                                "file number");
 4209     else if (file_name_string_length<67)
 4210         Skip_XX(67-file_name_string_length,                     "file name string padding (hack)");
 4211     if (file_name_string_length<=67)
 4212         Skip_B4(                                                "file created mac local date");
 4213     else if (file_name_string_length<71)
 4214         Skip_XX(71-file_name_string_length,                     "file name string padding (hack)");
 4215     if (file_name_string_length<=71)
 4216         Skip_B4(                                                "file type name");
 4217     else if (file_name_string_length<75)
 4218         Skip_XX(75-file_name_string_length,                     "file name string padding (hack)");
 4219     if (file_name_string_length<=75)
 4220         Skip_B4(                                                "file creator name");
 4221     else if (file_name_string_length<79)
 4222         Skip_XX(79-file_name_string_length,                     "file name string padding (hack)");
 4223     if (file_name_string_length<=79)
 4224         Skip_B2(                                                "next level up from alias");
 4225     else if (file_name_string_length<81)
 4226         Skip_XX(81-file_name_string_length,                     "file name string padding (hack)");
 4227     if (file_name_string_length<=81)
 4228         Skip_B2(                                                "next level down to target");
 4229     else if (file_name_string_length<83)
 4230         Skip_XX(83-file_name_string_length,                     "file name string padding (hack)");
 4231     if (file_name_string_length<=83)
 4232         Skip_B4(                                                "volume attributes");
 4233     else if (file_name_string_length<87)
 4234         Skip_XX(87-file_name_string_length,                     "file name string padding (hack)");
 4235     if (file_name_string_length<=87)
 4236         Skip_B2(                                                "volume file system ID");
 4237     else if (file_name_string_length<89)
 4238         Skip_XX(89-file_name_string_length,                     "file name string padding (hack)");
 4239     if (file_name_string_length<=89)
 4240         Skip_XX(10,                                             "Reserved");
 4241     else if (file_name_string_length<99)
 4242         Skip_XX(99-file_name_string_length,                     "file name string padding (hack)");
 4243     while(Element_Offset<End)
 4244     {
 4245         Element_Begin0();
 4246         Trusted++;
 4247         int16u type, size;
 4248         Get_B2 (type,                                           "type");
 4249         if (type==0xFFFF)
 4250         {
 4251             Skip_XX(End-Element_Offset,                         "Padding");
 4252             break;
 4253         }
 4254         if (type<MacAlias_Size && MacAlias[type])
 4255         {
 4256             Param_Info1(MacAlias[type]);
 4257             Element_Info1(MacAlias[type]);
 4258         }
 4259         else
 4260             Element_Info1(Ztring::ToZtring(type));
 4261         Get_B2 (size,                                           "size");
 4262         switch (type)
 4263         {
 4264             case 0x0000 :
 4265                         Get_UTF8(size, Directory_Name,          "Data");
 4266                         break;
 4267             case 0x000E :
 4268                         {
 4269                         int16u size2;
 4270                         Peek_B2(size2);
 4271                         if (2+size2*2==size)
 4272                         {
 4273                             Skip_B2(                            "size2");
 4274                             Get_UTF16B (size2*2, file_name_string, "Data");
 4275                         }
 4276                         else
 4277                         {
 4278                             Info_UTF8(size, Data,               "Data"); //We try, for info...
 4279                             Element_Info1(Data);
 4280                         }
 4281                         }
 4282                         break;
 4283             case 0x000F :
 4284                         {
 4285                         int16u size2;
 4286                         Peek_B2(size2);
 4287                         if (2+size2*2==size)
 4288                         {
 4289                             Skip_B2(                            "size2");
 4290                             Skip_UTF16B(size2*2,                "Data");
 4291                         }
 4292                         else
 4293                         {
 4294                             Info_UTF8(size, Data,               "Data"); //We try, for info...
 4295                             Element_Info1(Data);
 4296                         }
 4297                         }
 4298                         break;
 4299             default     :
 4300                         {
 4301                         Info_UTF8(size, Data,                   "Data"); //We try, for info...
 4302                         Element_Info1(Data);
 4303                         }
 4304         }
 4305         if (size%2)
 4306             Skip_B1(                                            "Padding");
 4307         Element_End0();
 4308     }
 4309     Element_End0();
 4310 
 4311     if (Element_Offset<Element_Size)
 4312         Skip_XX(Element_Size-Element_Offset,                    "Padding");
 4313 
 4314     FILLING_BEGIN();
 4315         if (Streams[moov_trak_tkhd_TrackID].File_Name.empty()) //Priority to "code" version
 4316         {
 4317             if (!Directory_Name.empty())
 4318             {
 4319                 Streams[moov_trak_tkhd_TrackID].File_Name+=Directory_Name;
 4320                 Streams[moov_trak_tkhd_TrackID].File_Name+=ZenLib::PathSeparator;
 4321             }
 4322             Streams[moov_trak_tkhd_TrackID].File_Name+=file_name_string;
 4323         }
 4324     FILLING_END();
 4325 }
 4326 
 4327 //---------------------------------------------------------------------------
 4328 void File_Mpeg4::moov_trak_mdia_minf_dinf_dref_rsrc()
 4329 {
 4330     Element_Name("Resource alias");
 4331 
 4332     //Parsing
 4333     Skip_B4(                                                    "Flags"); //bit 0 = external/internal data
 4334 }
 4335 
 4336 //---------------------------------------------------------------------------
 4337 void File_Mpeg4::moov_trak_mdia_minf_gmhd()
 4338 {
 4339     Element_Name("Generic Media Header");
 4340 }
 4341 
 4342 //---------------------------------------------------------------------------
 4343 void File_Mpeg4::moov_trak_mdia_minf_gmhd_gmin()
 4344 {
 4345     NAME_VERSION_FLAG("Generic Media Info");
 4346 
 4347     //Parsing
 4348     Skip_B2(                                                    "Graphics mode");
 4349     Skip_B2(                                                    "Opcolor (red)");
 4350     Skip_B2(                                                    "Opcolor (green)");
 4351     Skip_B2(                                                    "Opcolor (blue)");
 4352     Skip_B2(                                                    "Balance");
 4353     Skip_B2(                                                    "Reserved");
 4354 }
 4355 
 4356 //---------------------------------------------------------------------------
 4357 void File_Mpeg4::moov_trak_mdia_minf_gmhd_tmcd()
 4358 {
 4359     Element_Name("TimeCode");
 4360 }
 4361 
 4362 //---------------------------------------------------------------------------
 4363 void File_Mpeg4::moov_trak_mdia_minf_gmhd_tcmi()
 4364 {
 4365     moov_trak_mdia_minf_gmhd_tmcd_tcmi();
 4366 }
 4367 
 4368 //---------------------------------------------------------------------------
 4369 void File_Mpeg4::moov_trak_mdia_minf_gmhd_tmcd_tcmi()
 4370 {
 4371     NAME_VERSION_FLAG("TimeCode Media Information");
 4372 
 4373     //Parsing
 4374     int8u FontNameSize;
 4375     bool IsVisual;
 4376         Get_Flags (Flags,    0, IsVisual,                       "IsVisual");
 4377     Skip_B2(                                                    "Text font");
 4378     Info_B2(TextFace,                                           "Text face");
 4379         Skip_Flags(TextFace, 0,                                 "Bold");
 4380         Skip_Flags(TextFace, 1,                                 "Italic");
 4381         Skip_Flags(TextFace, 2,                                 "Underline");
 4382         Skip_Flags(TextFace, 3,                                 "Outline");
 4383         Skip_Flags(TextFace, 4,                                 "Shadow");
 4384         Skip_Flags(TextFace, 5,                                 "Condense");
 4385         Skip_Flags(TextFace, 6,                                 "Extend");
 4386     if (Element_Size>=25 && 25+(int64u)Buffer[Buffer_Offset+24]==Element_Size)
 4387         Skip_BFP4(16,                                           "Text size"); //Non-Standard, but found in several files
 4388     else
 4389         Skip_B2(                                                "Text size");
 4390     Skip_B2(                                                    "Text color (red)");
 4391     Skip_B2(                                                    "Text color (green)");
 4392     Skip_B2(                                                    "Text color (blue)");
 4393     Skip_B2(                                                    "Background color (red)");
 4394     Skip_B2(                                                    "Background color (green)");
 4395     Skip_B2(                                                    "Background color (blue)");
 4396     Get_B1 (FontNameSize,                                       "Font name size");
 4397     Skip_UTF8(FontNameSize,                                     "Font name");
 4398 
 4399     FILLING_BEGIN();
 4400         Streams[moov_trak_tkhd_TrackID].TimeCode_IsVisual=IsVisual;
 4401     FILLING_END();
 4402 }
 4403 
 4404 //---------------------------------------------------------------------------
 4405 void File_Mpeg4::moov_trak_mdia_minf_hint()
 4406 {
 4407     NAME_VERSION_FLAG("Hint");
 4408 
 4409     //Parsing
 4410     Skip_B2(                                                    "Maximum packet delivery unit");
 4411     Skip_B2(                                                    "Average packet delivery unit");
 4412     Skip_B4(                                                    "Maximum bit rate");
 4413     Skip_B4(                                                    "Average bit rate");
 4414     Skip_B4(                                                    "Reserved");
 4415 }
 4416 
 4417 //---------------------------------------------------------------------------
 4418 void File_Mpeg4::moov_trak_mdia_minf_hdlr()
 4419 {
 4420     moov_trak_mdia_hdlr();
 4421 }
 4422 
 4423 //---------------------------------------------------------------------------
 4424 void File_Mpeg4::moov_trak_mdia_minf_hmhd()
 4425 {
 4426     NAME_VERSION_FLAG("Hint Media Header");
 4427 
 4428     //Parsing
 4429     Skip_B2(                                                    "maxPDUsize");
 4430     Skip_B2(                                                    "avgPDUsize");
 4431     Skip_B4(                                                    "maxbitrate");
 4432     Skip_B4(                                                    "avgbitrate");
 4433     Skip_B4(                                                    "reserved");
 4434 
 4435     FILLING_BEGIN();
 4436         if (StreamKind_Last==Stream_Max) //Note: some files have both vmhd and hmhd, I don't know the meaning of such header, so skipping hmhd for the moment
 4437         {
 4438             Stream_Prepare(Stream_Other);
 4439             Fill(Stream_Other, StreamPos_Last, Other_Type, "Hint");
 4440             Streams[moov_trak_tkhd_TrackID].StreamKind=Stream_Other;
 4441             Streams[moov_trak_tkhd_TrackID].StreamPos=StreamPos_Last;
 4442         }
 4443     FILLING_END();
 4444 }
 4445 
 4446 //---------------------------------------------------------------------------
 4447 void File_Mpeg4::moov_trak_mdia_minf_nmhd()
 4448 {
 4449     NAME_VERSION_FLAG("Null Media Header");
 4450 }
 4451 
 4452 //---------------------------------------------------------------------------
 4453 void File_Mpeg4::moov_trak_mdia_minf_smhd()
 4454 {
 4455     NAME_VERSION_FLAG("Sound Media Header");
 4456 
 4457     //Parsing
 4458     Skip_B2(                                                    "Audio balance");
 4459     Skip_B2(                                                    "Reserved");
 4460 
 4461     FILLING_BEGIN();
 4462         if (StreamKind_Last!=Stream_Audio)
 4463             Stream_Prepare(Stream_Audio);
 4464     FILLING_END();
 4465 }
 4466 
 4467 //---------------------------------------------------------------------------
 4468 void File_Mpeg4::moov_trak_mdia_minf_vmhd()
 4469 {
 4470     NAME_VERSION_FLAG("Video Media Header")
 4471 
 4472     //Parsing
 4473     Skip_B2(                                                    "Graphic mode");
 4474     Skip_B2(                                                    "Graphic mode color R");
 4475     Skip_B2(                                                    "Graphic mode color G");
 4476     Skip_B2(                                                    "Graphic mode color B");
 4477 
 4478     FILLING_BEGIN();
 4479         if (StreamKind_Last!=Stream_Video)
 4480         {
 4481             Stream_Prepare(Stream_Video);
 4482             Streams[moov_trak_tkhd_TrackID].StreamKind=Stream_Video;
 4483             Streams[moov_trak_tkhd_TrackID].StreamPos=StreamPos_Last;
 4484         }
 4485     FILLING_END();
 4486 }
 4487 
 4488 //---------------------------------------------------------------------------
 4489 void File_Mpeg4::moov_trak_mdia_minf_sthd()
 4490 {
 4491     NAME_VERSION_FLAG("Subtitle Media Header")
 4492 
 4493     FILLING_BEGIN();
 4494         if (StreamKind_Last!=Stream_Text)
 4495         {
 4496             Stream_Prepare(Stream_Text);
 4497             Streams[moov_trak_tkhd_TrackID].StreamKind=Stream_Text;
 4498             Streams[moov_trak_tkhd_TrackID].StreamPos=StreamPos_Last;
 4499         }
 4500     FILLING_END();
 4501 }
 4502 
 4503 //---------------------------------------------------------------------------
 4504 void File_Mpeg4::moov_trak_mdia_minf_stbl()
 4505 {
 4506     Element_Name("Sample Table");
 4507 }
 4508 
 4509 //---------------------------------------------------------------------------
 4510 void File_Mpeg4::moov_trak_mdia_minf_stbl_co64()
 4511 {
 4512     NAME_VERSION_FLAG("Chunk offset");
 4513 
 4514     int64u Offset;
 4515     int32u Count;
 4516     Get_B4 (Count,                                              "Number of entries");
 4517 
 4518     if (Count==0)
 4519         return;
 4520 
 4521     std::vector<int64u> &stco=Streams[moov_trak_tkhd_TrackID].stco;
 4522     stco.resize(Count<FrameCount_MaxPerStream?Count:FrameCount_MaxPerStream);
 4523     int64u* stco_Data=&stco[0];
 4524 
 4525     for (int32u Pos=0; Pos<Count; Pos++)
 4526     {
 4527         //Too much slow
 4528         /*
 4529         Get_B8 (Offset,                                     "Offset");
 4530         */
 4531 
 4532         //Faster
 4533         if (Element_Offset+8>Element_Size)
 4534             break; //Problem
 4535         Offset=BigEndian2int64u(Buffer+Buffer_Offset+(size_t)Element_Offset);
 4536         Element_Offset+=8;
 4537 
 4538         if (Pos<FrameCount_MaxPerStream)
 4539         {
 4540             (*stco_Data)=Offset;
 4541             stco_Data++;
 4542         }
 4543     }
 4544 }
 4545 
 4546 //---------------------------------------------------------------------------
 4547 void File_Mpeg4::moov_trak_mdia_minf_stbl_cslg()
 4548 {
 4549     Element_Name("Composition Shift Least Greatest");
 4550 
 4551     //Parsing
 4552     Skip_XX(Element_Size,                                       "Unknown");
 4553 }
 4554 
 4555 //---------------------------------------------------------------------------
 4556 void File_Mpeg4::moov_trak_mdia_minf_stbl_ctts()
 4557 {
 4558     NAME_VERSION_FLAG("Composition Time To Sample");
 4559 
 4560     //Parsing
 4561     int32u entry_count;
 4562     Get_B4 (entry_count,                                        "entry_count");
 4563 
 4564     //Currently no usage
 4565     //for (int32u Pos=0; Pos<entry_count; Pos++)
 4566     {
 4567         //int32u sample_count, sample_offset;
 4568 
 4569         //Too much slow
 4570         /*
 4571         Get_B4 (sample_count,                                   "sample_count");
 4572         Get_B4 (sample_offset,                                  "sample_offset");
 4573         */
 4574 
 4575         //Faster
 4576         /*
 4577         if (Element_Offset+8>Element_Size)
 4578             break; //Problem
 4579         sample_count =BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset  );
 4580         sample_offset=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset+4);
 4581         Element_Offset+=8;
 4582         */
 4583     }
 4584 }
 4585 
 4586 //---------------------------------------------------------------------------
 4587 void File_Mpeg4::moov_trak_mdia_minf_stbl_sdtp()
 4588 {
 4589     Element_Name("Sample Dependency");
 4590 
 4591     //Parsing
 4592     Skip_XX(Element_Size,                                       "Unknown");
 4593 }
 4594 
 4595 //---------------------------------------------------------------------------
 4596 void File_Mpeg4::moov_trak_mdia_minf_stbl_stco()
 4597 {
 4598     NAME_VERSION_FLAG("Chunk offset");
 4599 
 4600     int32u Count, Offset;
 4601     Get_B4 (Count,                                              "Number of entries");
 4602     for (int32u Pos=0; Pos<Count; Pos++)
 4603     {
 4604         //Too much slow
 4605         /*
 4606         Get_B4 (Offset,                                     "Offset");
 4607         */
 4608 
 4609         //Faster
 4610         if (Element_Offset+4>Element_Size)
 4611             break; //Problem
 4612         Offset=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
 4613         Element_Offset+=4;
 4614 
 4615         if (Pos<FrameCount_MaxPerStream)
 4616             Streams[moov_trak_tkhd_TrackID].stco.push_back(Offset);
 4617     }
 4618 }
 4619 
 4620 //---------------------------------------------------------------------------
 4621 void File_Mpeg4::moov_trak_mdia_minf_stbl_stdp()
 4622 {
 4623     Element_Name("Degradation Priority");
 4624 
 4625     //Parsing
 4626     int32u sample_count;
 4627     Get_B4 (sample_count,                                       "sample-count");
 4628 
 4629     for (int32u Pos=0; Pos<sample_count; Pos++)
 4630     {
 4631         Skip_B2(                                                "priority");
 4632     }
 4633 }
 4634 
 4635 //---------------------------------------------------------------------------
 4636 void File_Mpeg4::moov_trak_mdia_minf_stbl_stps()
 4637 {
 4638     NAME_VERSION_FLAG("Partial Sync Sample");
 4639 
 4640     //Parsing
 4641     int32u sample_count;
 4642     Get_B4 (sample_count,                                       "sample-count");
 4643 
 4644     int32u Offset=1; //By default, begin at 1
 4645     bool stss_PreviouslyEmpty=Streams[moov_trak_tkhd_TrackID].stss.empty();
 4646     for (int32u Pos=0; Pos<sample_count; Pos++)
 4647     {
 4648         int32u sample_number;
 4649 
 4650         //Too much slow
 4651         /*
 4652         Get_B4 (sample_number,                                  "sample-number");
 4653         */
 4654 
 4655         //Faster
 4656         if (Element_Offset+4>Element_Size)
 4657             break; //Problem
 4658         sample_number=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset);
 4659         Element_Offset+=4;
 4660 
 4661         //Coherency testing (first frame is 0 or 1)
 4662         if (sample_number==0 && Offset)
 4663         {
 4664             for (size_t Pos=0; Pos<Streams[moov_trak_tkhd_TrackID].stss.size(); Pos++)
 4665                 Streams[moov_trak_tkhd_TrackID].stss[Pos]--;
 4666             Offset=0;
 4667         }
 4668 
 4669         Streams[moov_trak_tkhd_TrackID].stss.push_back(sample_number-Offset);
 4670     }
 4671     if (!stss_PreviouslyEmpty)
 4672         std::sort(Streams[moov_trak_tkhd_TrackID].stss.begin(), Streams[moov_trak_tkhd_TrackID].stss.end());
 4673 }
 4674 
 4675 //---------------------------------------------------------------------------
 4676 void File_Mpeg4::moov_trak_mdia_minf_stbl_stsc()
 4677 {
 4678     NAME_VERSION_FLAG("Sample To Chunk");
 4679 
 4680     //Parsing
 4681     int32u Count;
 4682     stream::stsc_struct Stsc;
 4683     Get_B4 (Count,                                              "Number of entries");
 4684     for (int32u Pos=0; Pos<Count; Pos++)
 4685     {
 4686         //Too much slow
 4687         /*
 4688         Element_Begin1("Entry", 12);
 4689         int32u SampleDescriptionId;
 4690         Get_B4 (Stsc.FirstChunk,                                "First chunk");
 4691         Get_B4 (Stsc.SamplesPerChunk,                           "Samples per chunk");
 4692         Get_B4 (SampleDescriptionId,                            "Sample description ID");
 4693         Element_Info1(Stsc.FirstChunk);
 4694         Element_Info1(Stsc.SamplesPerChunk);
 4695         Element_Info1(SampleDescriptionId);
 4696         Element_End0();
 4697         Streams[moov_trak_tkhd_TrackID].stsc.push_back(Stsc);
 4698         */
 4699 
 4700         //Faster
 4701         if (Pos<FrameCount_MaxPerStream)
 4702         {
 4703             if (Element_Offset+12>Element_Size)
 4704                 break; //Problem
 4705             Stsc.FirstChunk     =BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset  );
 4706             Stsc.SamplesPerChunk=BigEndian2int32u(Buffer+Buffer_Offset+(size_t)Element_Offset+4);
 4707             Element_Offset+=12;
 4708 
 4709             Streams[moov_trak_tkhd_TrackID].stsc.push_back(Stsc);
 4710         }
 4711         else
 4712             Element_Offset=Element_Size; //No need
 4713     }
 4714 }
 4715 
 4716 //---------------------------------------------------------------------------
 4717 void File_Mpeg4::moov_trak_mdia_minf_stbl_stsd()
 4718 {
 4719     NAME_VERSION_FLAG("Sample Description");
 4720 
 4721     //Parsing
 4722     Skip_B4(                                                    "Count");
 4723 
 4724     //Filling
 4725     moov_trak_mdia_minf_stbl_stsd_Pos=0;
 4726 }
 4727 
 4728 //---------------------------------------------------------------------------
 4729 void File_Mpeg4::moov_trak_mdia_minf_stbl_stsd_stpp()
 4730 {
 4731     Element_Name("Subtitle (stpp)");
 4732 
 4733     //Parsing
 4734     string NameSpace;
 4735     Skip_B4(                                                    "Reserved");
 4736     Skip_B2(                                                    "Reserved");
 4737     Skip_B2(                                                    "Data reference index");
 4738     size_t Pos=(size_t)Element_Offset;
 4739     while (Pos<Element_Size)
 4740     {
 4741         if (Buffer[Buffer_Offset+Pos]=='\0')
 4742             break;
 4743         Pos++;
 4744     }
 4745     Get_String(Pos+1-Element_Offset, NameSpace,                  "namespace");
 4746     Pos=(size_t)Element_Offset;
 4747     while (Pos<Element_Size)
 4748     {
 4749         if (Buffer[Buffer_Offset+Pos]=='\0')
 4750             break;
 4751         Pos++;
 4752     }
 4753     Skip_UTF8(Pos+1-Element_Offset,                             "schema_location");
 4754     Pos=(size_t)Element_Offset;
 4755     while (Pos<Element_Size)
 4756     {
 4757         if (Buffer[Buffer_Offset+Pos]=='\0')
 4758             break;
 4759         Pos++;
 4760     }
 4761     Skip_UTF8(Pos+1-Element_Offset,                             "image_mime_type");
 4762 
 4763     FILLING_BEGIN();
 4764         CodecID_Fill(__T("stpp"), StreamKind_Last, StreamPos_Last, InfoCodecID_Format_Mpeg4);
 4765         Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Codec), "stpp", Unlimited, true, true);
 4766         if (NameSpace.find("smpte-tt")!=string::npos)
 4767         {
 4768             Fill(StreamKind_Last, StreamPos_Last, Fill_Parameter(StreamKind_Last, Generic_Format), "Timed Text", Unlimited, true, true);
 4769 
 4770             #ifdef MEDIAINFO_TIMEDTEXT_YES
 4771                 File_TimedText* Parser=new File_TimedText;
 4772                 int64u Elemen_Code_Save=Element_Code;
 4773                 Element_Code=moov_trak_tkhd_TrackID; //Element_Code is use for stream identifier
 4774                 Open_Buffer_Init(Parser);
 4775                 Element_Code=Elemen_Code_Save;
 4776                 Parser->IsChapter=Streams[moov_trak_tkhd_TrackID].IsChapter;
 4777                 Streams[moov_trak_tkhd_TrackID].Parsers.push_back(Parser);
 4778                 mdat_MustParse=true; //Data is in MDAT
 4779             #endif //MEDIAINFO_TIMEDTEXT_YES
 4780         }
 4781     FILLING_END();
 4782 }
 4783 
 4784 //---------------------------------------------------------------------------
 4785 void File_Mpeg4::moov_trak_mdia_minf_stbl_stsd_text()
 4786 {
 4787     Element_Name("Text (Apple)");
 4788 
 4789     //Parsing
 4790     int8u TextName_Size;
 4791     Skip_B4(                                                    "Reserved");
 4792     Skip_B2(                                                    "Reserved");
 4793     Skip_B2(                                                    "Data reference index");
 4794     Info_B4(Flags,                                              "Display flags");
 4795         Skip_Flags(Flags,  1,                                   "Don't auto scale");
 4796         Skip_Flags(Flags,  3,                                   "Use movie background color");
 4797         Skip_Flags(Flags,  5,                                   "Scroll in");
 4798         Skip_Flags(Flags,  6,                                   "Scroll out");
 4799         Skip_Flags(Flags,  7,                                   "Horizontal scroll");
 4800         Skip_Flags(Flags,  8,                                   "Reverse scroll");
 4801         Skip_Flags(Flags,  9,                                   "Continuous scroll");
 4802         Skip_Flags(Flags, 12,                                   "Drop shadow");
 4803         Skip_Flags(Flags, 13,                                   "Anti-alias");
 4804         Skip_Flags(Flags, 14,                                   "Key text");
 4805     Skip_B4(                                                    "Text justification");
 4806     Skip_B2(                                                    "Background color (Red)");
 4807     Skip_B2(                                                    "Background color (Green)");
 4808     Skip_B2(                                                    "Background color (Blue)");
 4809     Element_Begin1("Default text box");
 4810         Skip_B2(                                                "top");
 4811         Skip_B2(                                                "left");
 4812         Skip_B2(                                                "bottom");
 4813         Skip_B2(                                                "right");
 4814     Element_End0();
 4815     Skip_B8(                                                    "Reserved");
 4816     Skip_B2(                                                    "Font number");
 4817     Info_B2(FontFace,                                           "Font face");
 4818         Skip_Flags(FontFace, 0,                                 "Bold");
 4819         Skip_Flags(FontFace, 1,                                 "Italic");
 4820         Skip_Flags(FontFace, 2,                                 "Underline");
 4821         Skip_Flags(FontFace, 3,