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; }
void MediaConverterApp::RefsReceived(BMessage* msg) { entry_ref ref; int32 i = 0; BString errorFiles; int32 errors = 0; // from Open dialog or drag & drop while (msg->FindRef("refs", i++, &ref) == B_OK) { uint32 flags = 0; // B_MEDIA_FILE_NO_READ_AHEAD BMediaFile* file = new(std::nothrow) BMediaFile(&ref, flags); if (file == NULL || file->InitCheck() != B_OK) { errorFiles << ref.name << "\n"; errors++; delete file; continue; } if (fWin->Lock()) { if (!fWin->AddSourceFile(file, ref)) delete file; fWin->Unlock(); } } if (errors) { BString alertText; if (errors > 1) { alertText = B_TRANSLATE( "%amountOfFiles files were not recognized" " as supported media files:"); BString amount; amount << errors; alertText.ReplaceAll("%amountOfFiles", amount); } else { alertText = B_TRANSLATE( "The file was not recognized as a supported media file:"); } alertText << "\n" << errorFiles; BAlert* alert = new BAlert((errors > 1) ? B_TRANSLATE("Error loading files") : B_TRANSLATE("Error loading a file"), alertText.String(), B_TRANSLATE("Continue"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->Go(); } }
status_t MovieEncoder::_CreateFile( const entry_ref& ref, const media_file_format& mff, const media_format& inputFormat, const media_codec_info& mci, float quality) { BMediaFile* file = new BMediaFile(&ref, &mff); status_t err = file->InitCheck(); if (err == B_OK) { fIsFileOpen = true; fHeaderCommitted = false; fMediaFile = file; // This next line casts away const to avoid a warning. MediaFile::CreateTrack() // *should* have the input format argument declared const, but it doesn't, and // it can't be changed because it would break binary compatibility. Oh, well. fMediaTrack = file->CreateTrack(const_cast<media_format *>(&inputFormat), &mci); if (!fMediaTrack) err = B_ERROR; else { if (quality >= 0) fMediaTrack->SetQuality(quality); } } // clean up if we incurred an error if (err < B_OK) { fIsFileOpen = fHeaderCommitted = false; delete fMediaFile; fMediaFile = NULL; } return err; }
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; }
void LeftList::MessageReceived(BMessage* msg) { struct AudioInfo fAudioInfo; BMediaFile* testfile; bool fIsAudio = false; BMediaTrack* track; media_codec_info codecInfo; media_format format; memset(&format, 0, sizeof(format)); entry_ref ref; int32 counter = 0; switch (msg->what) { case B_SIMPLE_DATA: while (msg->FindRef("refs", counter++, &ref) == B_OK) { if ((testfile = new BMediaFile(&ref)) != NULL) { testfile->InitCheck(); track = testfile->TrackAt(0); if (track != NULL) { track->EncodedFormat(&format); if (format.IsAudio()) { memset(&format, 0, sizeof(format)); format.type = B_MEDIA_RAW_AUDIO; track->DecodedFormat(&format); fAudioInfo.total_time = track->Duration(); media_raw_audio_format* raf = &(format.u.raw_audio); fAudioInfo.bps = (int32)(raf->format & 0xf); fAudioInfo.frame_rate = (int32)raf->frame_rate; fAudioInfo.channels = (int32)raf->channel_count; track->GetCodecInfo(&codecInfo); strcpy(fAudioInfo.pretty_name, codecInfo.pretty_name); strcpy(fAudioInfo.short_name, codecInfo.short_name); fIsAudio = true; } } } else WriteLog("MediaFile NULL (file doesnt exists!?)"); delete testfile; if (fIsAudio) { if (!strcmp(fAudioInfo.pretty_name, "Raw Audio") && (fAudioInfo.channels == 2) && (fAudioInfo.frame_rate == 44100) && (fAudioInfo.bps == 2)) AddItem(new LeftListItem(&ref, ref.name, fAudioBitmap, &fAudioInfo)); else { BAlert* MyAlert = new BAlert("BurnItNow", "You can only burn 16 bits stereo 44.1 kHz Raw Audio files.\n (More audio files will be supported in the future)", "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT); MyAlert->Go(); } } else { BPath temp_path; BEntry(&ref).GetPath(&temp_path); jpWindow* win = dynamic_cast<jpWindow*>(Window()); if (win != NULL) win->SetISOFile((char*)temp_path.Path()); } } break; default: BListView::MessageReceived(msg); break; } }
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; }