Changeset 1243

Show
Ignore:
Timestamp:
01/09/10 03:35:20 (2 months ago)
Author:
astrange
Message:

Make MKV import track-enabling code match its comment.

It turns out that many MKV files have no tracks of some
type with 'default' set, so we really do want to always
enable one. This restores the track enabled behavior of
1.1.4, but using the first instead of the last track of
the type.

We still need to respect the forced flag.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MatroskaImportPrivate.cpp

    r1240 r1243  
    235235ComponentResult MatroskaImport::ReadTracks(KaxTracks &trackEntries) 
    236236{ 
    237         Track firstVideoTrack = NULL; short firstVideoTrackLang = 0; 
    238         Track firstAudioTrack = NULL; short firstAudioTrackLang = 0; 
    239         Track firstSubtitleTrack = NULL; short firstSubtitleTrackLang = 0; 
     237        Track firstVideoTrack = NULL; short firstVideoTrackLang = 0; bool videoEnabled = false; 
     238        Track firstAudioTrack = NULL; short firstAudioTrackLang = 0; bool audioEnabled = false; 
     239        Track firstSubtitleTrack = NULL; short firstSubtitleTrackLang = 0; bool subtitleEnabled = false; 
    240240        ComponentResult err = noErr; 
    241         bool foundAnEnabledTrack = false; 
    242241         
    243242        if (seenTracks) 
     
    262261                        mkvTrack.type = uint8(type); 
    263262                        mkvTrack.defaultDuration = uint32(defaultDuration) / float(timecodeScale) + .5; 
     263                        mkvTrack.isEnabled = uint8(enabled); 
     264                        mkvTrack.usesLacing = uint8(lacing); 
    264265                         
    265266                        KaxTrackLanguage & trackLang = GetChild<KaxTrackLanguage>(track); 
     
    273274                                        err = AddVideoTrack(track, mkvTrack); 
    274275                                        if (err) return err; 
     276                                         
     277                                        if (mkvTrack.isEnabled) 
     278                                                videoEnabled = true; 
    275279                                         
    276280                                        if (firstVideoTrack && qtLang != firstVideoTrackLang) 
     
    287291                                        if (err) return err; 
    288292                                         
     293                                        if (mkvTrack.isEnabled) 
     294                                                audioEnabled = true; 
     295                                         
    289296                                        if (firstAudioTrack && qtLang != firstAudioTrackLang) 
    290297                                                SetTrackAlternate(firstAudioTrack, mkvTrack.theTrack); 
     
    300307                                        if (err) return err; 
    301308                                        if (mkvTrack.theTrack == NULL) continue; 
     309                                         
     310                                        if (mkvTrack.isEnabled) 
     311                                                subtitleEnabled = true; 
    302312                                         
    303313                                        if (firstSubtitleTrack && qtLang != firstSubtitleTrackLang) 
     
    317327                                        continue; 
    318328                        } 
    319                          
    320                         mkvTrack.isEnabled = uint8(enabled); 
    321                         mkvTrack.usesLacing = uint8(lacing); 
    322329                         
    323330                        if (encodings) { 
     
    362369        for (int i = 0; i < tracks.size(); i++) { 
    363370                SetTrackEnabled(tracks[i].theTrack, tracks[i].isEnabled); 
    364                 if (tracks[i].isEnabled) 
    365                         foundAnEnabledTrack = true; 
    366371        } 
    367372        // ffmpeg used to write a TrackDefault of 0 for all tracks 
    368373        // ensure that at least one track of each media type is enabled, if none were originally 
    369374        // this picks the first track, which may not be the best, but the situation is quite rare anyway 
    370         if (!foundAnEnabledTrack) { 
    371                 if (firstVideoTrack) 
    372                         SetTrackEnabled(firstVideoTrack, 1); 
    373                 if (firstAudioTrack) 
    374                         SetTrackEnabled(firstAudioTrack, 1); 
    375                 if (firstSubtitleTrack) 
    376                         SetTrackEnabled(firstSubtitleTrack, 1); 
    377         } 
     375        // FIXME properly choose tracks based on forced/default/language flags, and consider turning auto-alternates back on 
     376        if (!videoEnabled && firstVideoTrack) 
     377                SetTrackEnabled(firstVideoTrack, 1); 
     378        if (!audioEnabled && firstAudioTrack) 
     379                SetTrackEnabled(firstAudioTrack, 1); 
     380        if (!subtitleEnabled && firstSubtitleTrack) 
     381                SetTrackEnabled(firstSubtitleTrack, 1); 
    378382         
    379383        seenTracks = true;