Changeset 26261
- Timestamp:
- 07/05/08 14:22:37 (5 months ago)
- Location:
- haiku/trunk/src/apps/mediaplayer
- Files:
-
- 9 modified
-
Controller.cpp (modified) (8 diffs)
-
Controller.h (modified) (1 diff)
-
MainWin.cpp (modified) (4 diffs)
-
supplier/AudioTrackSupplier.h (modified) (1 diff)
-
supplier/MediaTrackAudioSupplier.cpp (modified) (4 diffs)
-
supplier/MediaTrackAudioSupplier.h (modified) (3 diffs)
-
supplier/MediaTrackVideoSupplier.cpp (modified) (2 diffs)
-
supplier/MediaTrackVideoSupplier.h (modified) (3 diffs)
-
supplier/VideoTrackSupplier.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/src/apps/mediaplayer/Controller.cpp
r26140 r26261 126 126 Controller::Duration() 127 127 { 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. 128 132 return (int64)((double)fDuration * fVideoFrameRate / 1000000.0); 129 133 } … … 196 200 status_t err; 197 201 198 BMediaFile *mf = new BMediaFile(&ref);202 BMediaFile* mf = new BMediaFile(&ref); 199 203 ObjectDeleter<BMediaFile> mediaFileDeleter(mf); 200 204 … … 214 218 215 219 for (int i = 0; i < trackcount; i++) { 216 BMediaTrack *t = mf->TrackAt(i);220 BMediaTrack* t = mf->TrackAt(i); 217 221 media_format f; 218 222 err = t->EncodedFormat(&f); 219 if (err != B_OK ) {223 if (err != B_OK || t->Duration() <= 0) { 220 224 printf("Controller::SetTo: EncodedFormat failed for track index %d, error 0x%08lx (%s)\n", 221 225 i, err, strerror(err)); … … 224 228 } 225 229 if (f.IsAudio()) { 226 fAudioTrackList.AddItem(t); 230 if (!fAudioTrackList.AddItem(t)) 231 return B_NO_MEMORY; 227 232 } else if (f.IsVideo()) { 228 fVideoTrackList.AddItem(t); 233 if (!fVideoTrackList.AddItem(t)) 234 return B_NO_MEMORY; 229 235 } else { 230 236 printf("Controller::SetTo: track index %d has unknown type\n", i); … … 327 333 328 334 ObjectDeleter<AudioTrackSupplier> deleter(fAudioTrackSupplier); 329 fAudioTrackSupplier = new MediaTrackAudioSupplier(track );335 fAudioTrackSupplier = new MediaTrackAudioSupplier(track, n); 330 336 331 337 bigtime_t a = fAudioTrackSupplier->Duration(); … … 335 341 // TODO: notify duration changed! 336 342 337 // TODO: Not good, because the ProxyAudioSupplier currently338 // uses the supplier without locking the Controller!339 // This is only a problem when selecting a different audio track340 // from the interface menu.341 343 fAudioSupplier->SetSupplier(fAudioTrackSupplier, fVideoFrameRate); 342 344 343 345 _NotifyAudioTrackChanged(n); 344 346 return B_OK; 347 } 348 349 350 int 351 Controller::CurrentAudioTrack() 352 { 353 BAutolock _(this); 354 355 if (fAudioTrackSupplier == NULL) 356 return -1; 357 358 return fAudioTrackSupplier->TrackIndex(); 345 359 } 346 360 … … 357 371 status_t initStatus; 358 372 ObjectDeleter<VideoTrackSupplier> deleter(fVideoTrackSupplier); 359 fVideoTrackSupplier = new MediaTrackVideoSupplier(track, initStatus);373 fVideoTrackSupplier = new MediaTrackVideoSupplier(track, n, initStatus); 360 374 if (initStatus < B_OK) { 361 375 delete fVideoTrackSupplier; … … 381 395 _NotifyVideoTrackChanged(n); 382 396 return B_OK; 397 } 398 399 400 int 401 Controller::CurrentVideoTrack() 402 { 403 BAutolock _(this); 404 405 if (fVideoTrackSupplier == NULL) 406 return -1; 407 408 return fVideoTrackSupplier->TrackIndex(); 383 409 } 384 410 -
haiku/trunk/src/apps/mediaplayer/Controller.h
r26140 r26261 84 84 85 85 status_t SelectAudioTrack(int n); 86 int CurrentAudioTrack(); 86 87 status_t SelectVideoTrack(int n); 88 int CurrentVideoTrack(); 87 89 88 90 void Stop(); -
haiku/trunk/src/apps/mediaplayer/MainWin.cpp
r25894 r26261 710 710 if (fPlaylist->CountItems() == 1) { 711 711 // 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(); 716 727 } else { 717 728 // just go to the next file and don't bother user … … 829 840 fAudioTrackMenu->SetEnabled(fHasFile); 830 841 fVideoTrackMenu->SetEnabled(fHasFile); 831 // Select first track (might be "none") in both832 fAudioTrackMenu->ItemAt(0)->SetMarked(true);833 fVideoTrackMenu->ItemAt(0)->SetMarked(true);834 842 835 843 fVideoMenu->SetEnabled(fHasVideo); … … 848 856 _UpdateControlsEnabledStatus(); 849 857 858 // TODO: Don't if the video size did not change! Also don't 859 // exit full screen mode. 850 860 _ResizeWindow(100); 851 861 … … 959 969 fVideoTrackMenu->RemoveItems(0, fVideoTrackMenu->CountItems(), true); 960 970 961 int c, i;962 971 char s[100]; 963 972 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++) { 966 976 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) { 971 983 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++) { 975 991 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) { 980 998 fVideoTrackMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY))); 999 fVideoTrackMenu->ItemAt(0)->SetMarked(true); 1000 } 981 1001 } 982 1002 -
haiku/trunk/src/apps/mediaplayer/supplier/AudioTrackSupplier.h
r25725 r26261 24 24 virtual status_t GetCodecInfo(media_codec_info* info) const = 0; 25 25 virtual bigtime_t Duration() const = 0; 26 27 virtual int32 TrackIndex() const = 0; 26 28 }; 27 29 -
haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp
r25725 r26261 55 55 56 56 57 MediaTrackAudioSupplier::MediaTrackAudioSupplier(BMediaTrack* mediaTrack) 57 MediaTrackAudioSupplier::MediaTrackAudioSupplier(BMediaTrack* mediaTrack, 58 int32 trackIndex) 58 59 : AudioTrackSupplier(), 59 60 fMediaTrack(mediaTrack), … … 64 65 fHasKeyFrames(false), 65 66 fCountFrames(0), 66 fReportSeekError(true) 67 fReportSeekError(true), 68 fTrackIndex(trackIndex) 67 69 { 68 70 _InitFromTrack(); … … 105 107 MediaTrackAudioSupplier::Duration() const 106 108 { 109 fMediaTrack, fMediaTrack ? fMediaTrack->Duration() : 0LL, fCountFrames); 107 110 if (!fMediaTrack) 108 111 return 0; … … 200 203 // get the length of the track 201 204 fCountFrames = fMediaTrack->CountFrames(); 205 206 TRACE("MediaTrackAudioSupplier: keyframes: %d, frame count: %lld\n", 207 fHasKeyFrames, fCountFrames); 202 208 } else 203 209 fMediaTrack = NULL; -
haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.h
r25725 r26261 17 17 class MediaTrackAudioSupplier : public AudioTrackSupplier { 18 18 public: 19 MediaTrackAudioSupplier(BMediaTrack* track); 19 MediaTrackAudioSupplier(BMediaTrack* track, 20 int32 trackIndex); 20 21 virtual ~MediaTrackAudioSupplier(); 21 22 … … 30 31 31 32 virtual status_t InitCheck() const; 33 34 virtual int32 TrackIndex() const 35 { return fTrackIndex; } 32 36 33 37 private: … … 85 89 int64 fCountFrames; 86 90 bool fReportSeekError; 91 int32 fTrackIndex; 87 92 }; 88 93 -
haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.cpp
r25824 r26261 25 25 // constructor 26 26 MediaTrackVideoSupplier::MediaTrackVideoSupplier(BMediaTrack* track, 27 status_t& initStatus)27 int32 trackIndex, status_t& initStatus) 28 28 : VideoTrackSupplier() 29 29 , fVideoTrack(track) … … 32 32 , fDuration(0) 33 33 , fCurrentFrame(0) 34 35 , fTrackIndex(trackIndex) 34 36 { 35 37 if (!fVideoTrack) { -
haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.h
r25824 r26261 18 18 public: 19 19 MediaTrackVideoSupplier(BMediaTrack* track, 20 status_t& initStatus);20 int32 trackIndex, status_t& initStatus); 21 21 virtual ~MediaTrackVideoSupplier(); 22 22 … … 43 43 virtual uint32 BytesPerRow() const; 44 44 45 virtual int32 TrackIndex() const 46 { return fTrackIndex; } 47 45 48 private: 46 49 status_t _SwitchFormat(color_space format, … … 56 59 bigtime_t fDuration; 57 60 int64 fCurrentFrame; 61 62 int32 fTrackIndex; 58 63 }; 59 64 -
haiku/trunk/src/apps/mediaplayer/supplier/VideoTrackSupplier.h
r25725 r26261 32 32 virtual bigtime_t Duration() const = 0; 33 33 virtual int64 CurrentFrame() const = 0; 34 35 virtual int32 TrackIndex() const = 0; 34 36 }; 35 37
