Changeset 26261

Show
Ignore:
Timestamp:
07/05/08 14:22:37 (5 months ago)
Author:
stippi
Message:

* The window would not reset the audio/video track to 0 on a new file if

the Controller would keep the last audio/video track index across files
(which would be nice for certain situations).

* Better error message for unsupported files, especially for the

B_MEDIA_NO_HANDLER error.

* In the Controller, try to obtain the track duration and ignore tracks that

return a bogus duration. I have some MP3 files on ZETA that are obviously
not handled correctly by the ZETA mp3 decoder. Previously, the player would
just sit there and appeared to have some other internal error.

Location:
haiku/trunk/src/apps/mediaplayer
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/apps/mediaplayer/Controller.cpp

    r26140 r26261  
    126126Controller::Duration() 
    127127{ 
     128        // TODO: It is not so nice that the MediaPlayer still measures 
     129        // in video frames if only playing audio. Here for example, it will 
     130        // return a duration of 0 if the audio clip happens to be shorter than 
     131        // one video frame at 25 fps. 
    128132        return (int64)((double)fDuration * fVideoFrameRate / 1000000.0); 
    129133} 
     
    196200        status_t err; 
    197201         
    198         BMediaFile *mf = new BMediaFile(&ref); 
     202        BMediaFile* mf = new BMediaFile(&ref); 
    199203        ObjectDeleter<BMediaFile> mediaFileDeleter(mf); 
    200204 
     
    214218         
    215219        for (int i = 0; i < trackcount; i++) { 
    216                 BMediaTrack *t = mf->TrackAt(i); 
     220                BMediaTrack* t = mf->TrackAt(i); 
    217221                media_format f; 
    218222                err = t->EncodedFormat(&f); 
    219                 if (err != B_OK) { 
     223                if (err != B_OK || t->Duration() <= 0) { 
    220224                        printf("Controller::SetTo: EncodedFormat failed for track index %d, error 0x%08lx (%s)\n", 
    221225                                i, err, strerror(err)); 
     
    224228                } 
    225229                if (f.IsAudio()) { 
    226                         fAudioTrackList.AddItem(t); 
     230                        if (!fAudioTrackList.AddItem(t)) 
     231                                return B_NO_MEMORY; 
    227232                } else if (f.IsVideo()) { 
    228                         fVideoTrackList.AddItem(t); 
     233                        if (!fVideoTrackList.AddItem(t)) 
     234                                return B_NO_MEMORY; 
    229235                } else { 
    230236                        printf("Controller::SetTo: track index %d has unknown type\n", i); 
     
    327333 
    328334        ObjectDeleter<AudioTrackSupplier> deleter(fAudioTrackSupplier); 
    329         fAudioTrackSupplier = new MediaTrackAudioSupplier(track); 
     335        fAudioTrackSupplier = new MediaTrackAudioSupplier(track, n); 
    330336 
    331337        bigtime_t a = fAudioTrackSupplier->Duration(); 
     
    335341        // TODO: notify duration changed! 
    336342 
    337         // TODO: Not good, because the ProxyAudioSupplier currently 
    338         // uses the supplier without locking the Controller! 
    339         // This is only a problem when selecting a different audio track 
    340         // from the interface menu. 
    341343        fAudioSupplier->SetSupplier(fAudioTrackSupplier, fVideoFrameRate); 
    342344 
    343345        _NotifyAudioTrackChanged(n); 
    344346        return B_OK; 
     347} 
     348 
     349 
     350int 
     351Controller::CurrentAudioTrack() 
     352{ 
     353        BAutolock _(this); 
     354 
     355        if (fAudioTrackSupplier == NULL) 
     356                return -1; 
     357 
     358        return fAudioTrackSupplier->TrackIndex(); 
    345359} 
    346360 
     
    357371        status_t initStatus; 
    358372        ObjectDeleter<VideoTrackSupplier> deleter(fVideoTrackSupplier); 
    359         fVideoTrackSupplier = new MediaTrackVideoSupplier(track, initStatus); 
     373        fVideoTrackSupplier = new MediaTrackVideoSupplier(track, n, initStatus); 
    360374        if (initStatus < B_OK) { 
    361375                delete fVideoTrackSupplier; 
     
    381395        _NotifyVideoTrackChanged(n); 
    382396        return B_OK; 
     397} 
     398 
     399 
     400int 
     401Controller::CurrentVideoTrack() 
     402{ 
     403        BAutolock _(this); 
     404 
     405        if (fVideoTrackSupplier == NULL) 
     406                return -1; 
     407 
     408        return fVideoTrackSupplier->TrackIndex(); 
    383409} 
    384410 
  • haiku/trunk/src/apps/mediaplayer/Controller.h

    r26140 r26261  
    8484         
    8585                        status_t                        SelectAudioTrack(int n); 
     86                        int                                     CurrentAudioTrack(); 
    8687                        status_t                        SelectVideoTrack(int n); 
     88                        int                                     CurrentVideoTrack(); 
    8789 
    8890                        void                            Stop(); 
  • haiku/trunk/src/apps/mediaplayer/MainWin.cpp

    r25894 r26261  
    710710                if (fPlaylist->CountItems() == 1) { 
    711711                        // display error if this is the only file we're supposed to play 
    712                         char s[300]; 
    713                         sprintf(s, "Can't open file\n\n%s\n\nError 0x%08lx\n(%s)\n", 
    714                                 ref.name, err, strerror(err)); 
    715                         (new BAlert("error", s, "OK"))->Go(); 
     712                        BString message; 
     713                        message << "The file '"; 
     714                        message << ref.name; 
     715                        message << "' could not be opened.\n\n"; 
     716                         
     717                        if (err == B_MEDIA_NO_HANDLER) { 
     718                                // give a more detailed message for the most likely of all 
     719                                // errors 
     720                                message << "There is no decoder installed to handle the " 
     721                                        "file format, or the decoder has trouble with the specific " 
     722                                        "version of the format."; 
     723                        } else { 
     724                                message << "Error: " << strerror(err); 
     725                        } 
     726                        (new BAlert("error", message.String(), "OK"))->Go(); 
    716727                } else { 
    717728                        // just go to the next file and don't bother user 
     
    829840        fAudioTrackMenu->SetEnabled(fHasFile); 
    830841        fVideoTrackMenu->SetEnabled(fHasFile); 
    831         // Select first track (might be "none") in both 
    832         fAudioTrackMenu->ItemAt(0)->SetMarked(true); 
    833         fVideoTrackMenu->ItemAt(0)->SetMarked(true); 
    834842 
    835843        fVideoMenu->SetEnabled(fHasVideo); 
     
    848856        _UpdateControlsEnabledStatus(); 
    849857 
     858        // TODO: Don't if the video size did not change! Also don't 
     859        // exit full screen mode. 
    850860        _ResizeWindow(100); 
    851861 
     
    959969        fVideoTrackMenu->RemoveItems(0, fVideoTrackMenu->CountItems(), true); 
    960970         
    961         int c, i; 
    962971        char s[100]; 
    963972         
    964         c = fController->AudioTrackCount(); 
    965         for (i = 0; i < c; i++) { 
     973        int count = fController->AudioTrackCount(); 
     974        int current = fController->CurrentAudioTrack(); 
     975        for (int i = 0; i < count; i++) { 
    966976                sprintf(s, "Track %d", i + 1); 
    967                 fAudioTrackMenu->AddItem(new BMenuItem(s, 
    968                         new BMessage(M_SELECT_AUDIO_TRACK + i))); 
    969         } 
    970         if (!c) 
     977                BMenuItem* item = new BMenuItem(s, 
     978                        new BMessage(M_SELECT_AUDIO_TRACK + i)); 
     979                item->SetMarked(i == current); 
     980                fAudioTrackMenu->AddItem(item); 
     981        } 
     982        if (!count) { 
    971983                fAudioTrackMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY))); 
    972  
    973         c = fController->VideoTrackCount(); 
    974         for (i = 0; i < c; i++) { 
     984                fAudioTrackMenu->ItemAt(0)->SetMarked(true); 
     985        } 
     986 
     987 
     988        count = fController->VideoTrackCount(); 
     989        current = fController->CurrentVideoTrack(); 
     990        for (int i = 0; i < count; i++) { 
    975991                sprintf(s, "Track %d", i + 1); 
    976                 fVideoTrackMenu->AddItem(new BMenuItem(s, 
    977                         new BMessage(M_SELECT_VIDEO_TRACK + i))); 
    978         } 
    979         if (!c) 
     992                BMenuItem* item = new BMenuItem(s, 
     993                        new BMessage(M_SELECT_VIDEO_TRACK + i)); 
     994                item->SetMarked(i == current); 
     995                fVideoTrackMenu->AddItem(item); 
     996        } 
     997        if (!count) { 
    980998                fVideoTrackMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY))); 
     999                fVideoTrackMenu->ItemAt(0)->SetMarked(true); 
     1000        } 
    9811001} 
    9821002 
  • haiku/trunk/src/apps/mediaplayer/supplier/AudioTrackSupplier.h

    r25725 r26261  
    2424        virtual status_t                        GetCodecInfo(media_codec_info* info) const = 0; 
    2525        virtual bigtime_t                       Duration() const = 0; 
     26 
     27        virtual int32                           TrackIndex() const = 0; 
    2628}; 
    2729 
  • haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp

    r25725 r26261  
    5555 
    5656 
    57 MediaTrackAudioSupplier::MediaTrackAudioSupplier(BMediaTrack* mediaTrack) 
     57MediaTrackAudioSupplier::MediaTrackAudioSupplier(BMediaTrack* mediaTrack, 
     58                int32 trackIndex) 
    5859        : AudioTrackSupplier(), 
    5960          fMediaTrack(mediaTrack), 
     
    6465          fHasKeyFrames(false), 
    6566          fCountFrames(0), 
    66           fReportSeekError(true) 
     67          fReportSeekError(true), 
     68          fTrackIndex(trackIndex) 
    6769{ 
    6870        _InitFromTrack(); 
     
    105107MediaTrackAudioSupplier::Duration() const 
    106108{ 
     109        fMediaTrack, fMediaTrack ? fMediaTrack->Duration() : 0LL, fCountFrames); 
    107110        if (!fMediaTrack) 
    108111                return 0; 
     
    200203                // get the length of the track 
    201204                fCountFrames = fMediaTrack->CountFrames(); 
     205 
     206                TRACE("MediaTrackAudioSupplier: keyframes: %d, frame count: %lld\n", 
     207                        fHasKeyFrames, fCountFrames); 
    202208        } else 
    203209                fMediaTrack = NULL; 
  • haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.h

    r25725 r26261  
    1717class MediaTrackAudioSupplier : public AudioTrackSupplier { 
    1818 public: 
    19                                                                 MediaTrackAudioSupplier(BMediaTrack* track); 
     19                                                                MediaTrackAudioSupplier(BMediaTrack* track, 
     20                                                                        int32 trackIndex); 
    2021        virtual                                         ~MediaTrackAudioSupplier(); 
    2122 
     
    3031 
    3132        virtual status_t                        InitCheck() const; 
     33 
     34        virtual int32                           TrackIndex() const 
     35                                                                        { return fTrackIndex; } 
    3236 
    3337 private: 
     
    8589                        int64                           fCountFrames; 
    8690                        bool                            fReportSeekError; 
     91                        int32                           fTrackIndex; 
    8792}; 
    8893 
  • haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.cpp

    r25824 r26261  
    2525// constructor 
    2626MediaTrackVideoSupplier::MediaTrackVideoSupplier(BMediaTrack* track, 
    27                 status_t& initStatus) 
     27                int32 trackIndex, status_t& initStatus) 
    2828        : VideoTrackSupplier() 
    2929        , fVideoTrack(track) 
     
    3232        , fDuration(0) 
    3333        , fCurrentFrame(0) 
     34 
     35        , fTrackIndex(trackIndex) 
    3436{ 
    3537        if (!fVideoTrack) { 
  • haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.h

    r25824 r26261  
    1818 public: 
    1919                                                                MediaTrackVideoSupplier(BMediaTrack* track, 
    20                                                                         status_t& initStatus); 
     20                                                                        int32 trackIndex, status_t& initStatus); 
    2121        virtual                                         ~MediaTrackVideoSupplier(); 
    2222 
     
    4343        virtual uint32                          BytesPerRow() const; 
    4444 
     45        virtual int32                           TrackIndex() const 
     46                                                                        { return fTrackIndex; } 
     47 
    4548 private: 
    4649                        status_t                        _SwitchFormat(color_space format, 
     
    5659                        bigtime_t                       fDuration; 
    5760                        int64                           fCurrentFrame; 
     61 
     62                        int32                           fTrackIndex; 
    5863}; 
    5964 
  • haiku/trunk/src/apps/mediaplayer/supplier/VideoTrackSupplier.h

    r25725 r26261  
    3232        virtual bigtime_t                       Duration() const = 0; 
    3333        virtual int64                           CurrentFrame() const = 0; 
     34 
     35        virtual int32                           TrackIndex() const = 0; 
    3436}; 
    3537