/* isAudioDisc * checks if selected files are audio files, and greps the playtime of them * when all files audio files * returns true if audio disc */ bool ProjectTypeSelector::isAudioDisc() { BString *FileType; for(int i = 0; i < TypeList->CountItems(); i++) { FileType = (BString*)TypeList->ItemAt(i); if(FileType->Compare("audio", 5) != 0) return false; } entry_ref ref; BMediaFile *mediaFile; bigtime_t time = 0; for(int i = 0; i < FileList->CountItems(); i++){ get_ref_for_path(((BString*)FileList->ItemAt(i))->String(), &ref); mediaFile = new BMediaFile(&ref); BMediaTrack *track = NULL; for(int j = 0; j < mediaFile->CountTracks(); j++){ track = mediaFile->TrackAt(j); time = track->Duration(); intPlayTime += ((int)time / 1000000); } delete mediaFile; } return true; }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage:\n %s <filename>\n", argv[0]); return 1; } entry_ref ref; if (get_ref_for_path(argv[1], &ref)!=B_OK) return 2; BMediaFile *playFile = new BMediaFile(&ref); if (playFile->InitCheck()<B_OK) { delete playFile; return 2; } for (int ix=0; ix<playFile->CountTracks(); ix++) { BMediaTrack * track = playFile->TrackAt(ix); playFormat.type = B_MEDIA_RAW_AUDIO; if ((track->DecodedFormat(&playFormat) == B_OK) && (playFormat.type == B_MEDIA_RAW_AUDIO)) { playTrack = track; break; } if (track) playFile->ReleaseTrack(track); } // Good relations with the Wookiees, I have. signal(SIGINT, keyb_int); new BApplication("application/x-vnd.Antares-playfile"); finished = create_sem(0, "finish wait"); printf("playing file...\n"); // Execute Plan 66! sp = new BSoundPlayer(&playFormat.u.raw_audio, "playfile", play_buffer); sp->SetVolume(1.0f); // Join me, Padmé and together we can rule this galaxy. sp->SetHasData(true); sp->Start(); acquire_sem(finished); if (interrupt) { // Once more, the Sith will rule the galaxy. printf("interrupted\n"); sp->Stop(); kill_thread(reader); } printf("playback finished\n"); delete sp; delete playFile; }
bool EMBeMediaFileManager::CheckFileForVideoFormat(const string* p_opFileName) { entry_ref m_sRef; BEntry oEntry(p_opFileName -> c_str(), false); oEntry.GetRef(&m_sRef); BMediaFile* opFile = new BMediaFile(&m_sRef, B_MEDIA_FILE_UNBUFFERED); //Point vidtrack to the Video-Track (temporary static at 0) (input file) //It is not always that the video data is on track 0? int32 tracks = opFile->CountTracks(); media_format sFormat; BMediaTrack* opTrackOut = NULL; for (int32 i = 0; i < tracks; i++) { opTrackOut = opFile -> TrackAt(i); //m_opTrackOut->EncodedFormat(&outfmt); //We wannt RAW Video.. nothing else can be handled :) //So we will have to negotiate for RAW_VIDEO through DecodeFormat(..) sFormat.type = B_MEDIA_RAW_VIDEO; sFormat.u.raw_video = media_raw_video_format::wildcard; status_t vErrorCode = opTrackOut -> DecodedFormat(&sFormat); if(vErrorCode != B_OK) { opFile -> ReleaseTrack(opTrackOut); opFile -> CloseFile(); delete opFile; return false; } if(sFormat.IsVideo()) { opFile -> ReleaseTrack(opTrackOut); opFile -> CloseFile(); delete opFile; return true; } } if(opTrackOut != NULL) opFile -> ReleaseTrack(opTrackOut); opFile -> CloseFile(); delete opFile; return false; }
status_t MainView::LoadWave(const entry_ref& ref) { bigtime_t startLoadWave = system_time(); fDestCursor = 0; fSourceCursor = 0; fAverage = 0.0f; fAverageCursor = 0; fDownsamplingWidth = 0; fDownsampleCount = 0; // instantiate a BMediaFile object, and make sure there was no error. /*BEntry entry("./song.wav"); entry_ref ref; entry.GetRef(&ref);*/ BMediaFile* mediaFile = new BMediaFile(&ref); status_t err = mediaFile->InitCheck(); if (err != B_OK) { printf("cannot contruct BMediaFile object -- %s\n", strerror(err)); return err; } for (int32 i = 0; i < mediaFile->CountTracks(); i++) { BMediaTrack* track = mediaFile->TrackAt(i); if (track == NULL) { printf("cannot contruct BMediaTrack object\n"); return B_ERROR; } media_format format; format.type = B_MEDIA_RAW_AUDIO; format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT; err = track->DecodedFormat(&format); if (err != B_OK) { printf("BMediaTrack::DecodedFormat error -- %s\n", strerror(err)); return err; } if (format.type == B_MEDIA_RAW_AUDIO) { // get the actual sourceWindow.left obtained by seeking bigtime_t start = system_time(); int64 actualSeekFrame = fSourceWindow.left; err = track->SeekToFrame(&actualSeekFrame); if (err != B_OK) { printf("BMediaTrack::SeekToFrame(%lli) error -- %s\n", fSourceWindow.left, strerror(err)); return err; } printf("BMediaTrack::SeekToFrame(%lli) seekedto=%lli in %llims\n", fSourceWindow.left, actualSeekFrame, (system_time() - start) / 1000); fSourceWindow.left = actualSeekFrame; frame_range destWindow(0, (uint64) fWaveFrame.Width()); int64 totalSourceFrameCount = track->CountFrames(); fDownsamplingWidth = fSourceWindow.Width() / destWindow.Width(); printf("Source window left=%lli right=%lli width=%lli (total=%lli)\n", fSourceWindow.left, fSourceWindow.right, fSourceWindow.Width(), totalSourceFrameCount); printf("Dest window left=%lli right=%lli width=%lli\n", destWindow.left, destWindow.right, destWindow.Width()); printf("Downsampling width=%lli\n", fDownsamplingWidth); delete [] fWave; fWave = NULL; fWave = new(std::nothrow) float[fSourceWindow.Width() / fDownsamplingWidth]; // ATT: on en prend plus que la largeur de dest car downsampling width entier if (fWave == NULL) return B_NO_MEMORY; char* buffer = new(std::nothrow) char[format.u.raw_audio.buffer_size]; if (buffer == NULL) return B_NO_MEMORY; int64 readFrameCount = 0; media_header mediaHeader; fSourceCursor = fSourceWindow.left; for(int64 j = 0; j < fSourceWindow.Width(); j += readFrameCount) { err = track->ReadFrames(buffer, &readFrameCount, &mediaHeader); if (err) { printf("BMediaTrack::ReadFrames error -- %s\n", strerror(err)); delete [] buffer; break; // TODO fatal error? } if (fSourceCursor + readFrameCount >= fSourceWindow.right) { readFrameCount = fSourceWindow.right - fSourceCursor; printf("yes readFrameCount = %lli\n", readFrameCount); } _ProcessAudio(buffer, &format, readFrameCount); } printf("Source cursor %li (read %li)\n", fSourceCursor, fSourceCursor - fSourceWindow.left); printf("Dest cursor %li\n", fDestCursor); delete [] buffer; } mediaFile->ReleaseTrack(track); } delete mediaFile; printf("LoadWave in %lims\n", (system_time() - startLoadWave) / 1000 ); fCurrentEntryRef = ref; return B_OK; }
int media_play(const char* uri) { BUrl url; entry_ref ref; BMediaFile* playFile; if (get_ref_for_path(uri, &ref) != B_OK) { url.SetUrlString(uri); if (url.IsValid()) { playFile = new BMediaFile(url); } else return 2; } else playFile = new BMediaFile(&ref); if (playFile->InitCheck() != B_OK) { delete playFile; return 2; } for (int i = 0; i < playFile->CountTracks(); i++) { BMediaTrack* track = playFile->TrackAt(i); playFormat.type = B_MEDIA_RAW_AUDIO; if ((track->DecodedFormat(&playFormat) == B_OK) && (playFormat.type == B_MEDIA_RAW_AUDIO)) { playTrack = track; break; } if (track) playFile->ReleaseTrack(track); } // Good relations with the Wookiees, I have. signal(SIGINT, keyb_int); finished = create_sem(0, "finish wait"); printf("Playing file...\n"); // Execute Plan 66! player = new BSoundPlayer(&playFormat.u.raw_audio, "playfile", play_buffer); player->SetVolume(1.0f); // Join me, Padmé and together we can rule this galaxy. player->SetHasData(true); player->Start(); acquire_sem(finished); if (interrupt == true) { // Once more, the Sith will rule the galaxy. printf("Interrupted\n"); player->Stop(); kill_thread(reader); } printf("Playback finished.\n"); delete player; delete playFile; return 0; }