static BMediaFile* init_media_file(media_format format, BMediaTrack** _track) { static BMediaFile* file = NULL; static BMediaTrack* track = NULL; if (file == NULL) { entry_ref ref; get_ref_for_path("/boot/home/Desktop/test.wav", &ref); media_file_format fileFormat; int32 cookie = 0; while (get_next_file_format(&cookie, &fileFormat) == B_OK) { if (strcmp(fileFormat.short_name, "wav") == 0) { break; } } file = new BMediaFile(&ref, &fileFormat); media_codec_info info; cookie = 0; while (get_next_encoder(&cookie, &info) == B_OK) { if (strcmp(info.short_name, "raw-audio") == 0) break; } track = file->CreateTrack(&format, &info); if (!track) printf("failed to create track\n"); file->CommitHeader(); } *_track = track; return track != NULL ? file : NULL; }
status_t OutputView::GetCodecsForFamily(const media_format_family &family, const int32 &width, const int32 &height, BMenu *codecs, media_format &initialFormat) { SetInitialFormat(width, height, Settings().ClipDepth(), 10, initialFormat); // find the full media_file_format corresponding to // the given format family (e.g. AVI) media_file_format fileFormat; if (!GetMediaFileFormat(family, fileFormat)) return B_ERROR; BString currentCodec; BMenuItem *marked = codecs->FindMarked(); if (marked != NULL) currentCodec = marked->Label(); // suspend updates while we're rebuilding this menu in order to // reduce window flicker and other annoyances Window()->BeginViewTransaction(); codecs->RemoveItems(0, codecs->CountItems(), true); int32 cookie = 0; media_codec_info codec; media_format dummyFormat; while (get_next_encoder(&cookie, &fileFormat, &initialFormat, &dummyFormat, &codec) == B_OK) { BMenuItem *item = CreateCodecMenuItem(codec); if (item != NULL) codecs->AddItem(item); if (codec.pretty_name == currentCodec) item->SetMarked(true); } if (codecs->FindMarked() == NULL) { BMenuItem *item = codecs->ItemAt(0); if (item != NULL) item->SetMarked(true); } Window()->EndViewTransaction(); marked = codecs->FindMarked(); BMessage *message = marked->Message(); media_codec_info *info; ssize_t size; if (message->FindData(kCodecData, B_SIMPLE_DATA, (const void **)&info, &size) == B_OK) fController->SetMediaCodecInfo(*info); return B_OK; }
void VideoRecorderNode::BuildCodecMenu(media_format_family mf_family) { LockParameterWeb(); INFO("VideoRecorderNode::BuildCodecMenu()"); // remember the currently-selected codec /* media_codec_info current_codec= *((media_codec_info *)(codecList->ItemAt(videoCodec))); int32 current = current_codec.id; // remember the current codec current_codec.id = -2; // magic invalid value*/ // find the full media_file_format corresponding to the given format family (e.g. AVI) status_t err; media_file_format mff; int32 cookie = 0; while ((err = get_next_file_format(&cookie, &mff)) == B_OK) { if (mff.family == mf_family) break; } // hmm, something is desperately wrong -- we couldn't find the "current" format family if (err) { fprintf(stderr, "ERROR: couldn't find current media format family\n"); //*** we need some other error handling.. // exit(1); } codec->MakeEmpty(); void *item; while ((item = codecList->RemoveItem(int32(0))) != NULL) { delete item; } codecList->MakeEmpty(); // fill in the list of available codecs for this media format and file family media_codec_info *codec_info=new media_codec_info; // media_codec_info firstCodec; media_format outFormat; cookie = 0; while (get_next_encoder(&cookie, &mff, &filterInput.format, &outFormat, codec_info) == B_OK) { codec->AddItem(codecList->CountItems(),codec_info->pretty_name); codecList->AddItem(codec_info); codec_info=new media_codec_info; videoCodec=1; } UnlockParameterWeb(); //** Select one??? // SetParameterWeb(web); }
// Should be called every time the media_format_family is changed status_t Controller::UpdateMediaFormatAndCodecsForCurrentFamily() { BAutolock _(this); Settings settings; BRect targetRect = settings.TargetRect(); targetRect.right++; targetRect.bottom++; targetRect.PrintToStream(); const int32 frameRate = 10; media_format mediaFormat = _ComputeMediaFormat(targetRect.IntegerWidth(), targetRect.IntegerHeight(), settings.ClipDepth(), frameRate); fEncoder->SetMediaFormat(mediaFormat); delete fCodecList; fCodecList = new BObjectList<media_codec_info> (1, true); int32 cookie = 0; media_codec_info codec; media_format dummyFormat; media_file_format fileFormat = fEncoder->MediaFileFormat(); while (get_next_encoder(&cookie, &fileFormat, &mediaFormat, &dummyFormat, &codec) == B_OK) { media_codec_info* newCodec = new media_codec_info; *newCodec = codec; fCodecList->AddItem(newCodec); } SendNotices(kMsgControllerCodecListUpdated); return B_OK; }
void MediaConverterWindow::BuildAudioVideoMenus() { BMenu* menu = fAudioMenu->Menu(); BMenuItem* item; // clear out old audio codec menu items while ((item = menu->RemoveItem((int32)0)) != NULL) delete item; bool separator = true; // get selected file format FileFormatMenuItem* ffmi = (FileFormatMenuItem*)fFormatMenu->Menu()->FindMarked(); media_file_format* mf_format = &(ffmi->fFileFormat); media_format format, outfmt; memset(&format, 0, sizeof(format)); media_codec_info codec_info; int32 cookie = 0; CodecMenuItem* cmi; // add available audio encoders to menu format.type = B_MEDIA_RAW_AUDIO; format.u.raw_audio = media_raw_audio_format::wildcard; while (get_next_encoder(&cookie, mf_format, &format, &outfmt, &codec_info) == B_OK) { if (separator) { menu->AddItem(new BMenuItem( B_TRANSLATE_CONTEXT("No audio", "Audio codecs list"), new BMessage(AUDIO_CODEC_SELECT_MESSAGE))); menu->AddSeparatorItem(); separator = false; } cmi = new CodecMenuItem(&codec_info, AUDIO_CODEC_SELECT_MESSAGE); menu->AddItem(cmi); // reset media format struct /* format.type = B_MEDIA_RAW_AUDIO; format.u.raw_audio = media_raw_audio_format::wildcard; */ } // mark first audio encoder item = menu->ItemAt(0); if (item != NULL) { fAudioMenu->SetEnabled(fEnabled); fAudioQualitySlider->SetEnabled(fEnabled); item->SetMarked(true); ((BInvoker*)item)->Invoke(); } else { item = new BMenuItem( B_TRANSLATE_CONTEXT("None available", "Audio codecs"), NULL); menu->AddItem(item); item->SetMarked(true); fAudioMenu->SetEnabled(false); fAudioQualitySlider->SetEnabled(false); } // clear out old video codec menu items menu = fVideoMenu->Menu(); while ((item = menu->RemoveItem((int32)0)) != NULL) delete item; separator = true; // construct a generic video format. Some of these parameters // seem silly, but are needed for R4.5.x, which is more picky // than subsequent BeOS releases will be. memset(&format, 0, sizeof(format)); format.type = B_MEDIA_RAW_VIDEO; format.u.raw_video.last_active = (uint32)(240 - 1); format.u.raw_video.orientation = B_VIDEO_TOP_LEFT_RIGHT; format.u.raw_video.display.format = B_RGB32; format.u.raw_video.display.line_width = (int32)320; format.u.raw_video.display.line_count = (int32)240; format.u.raw_video.display.bytes_per_row = 4 * 320; // add available video encoders to menu cookie = 0; while (get_next_encoder(&cookie, mf_format, &format, &outfmt, &codec_info) == B_OK) { if (separator) { menu->AddItem(new BMenuItem( B_TRANSLATE_CONTEXT("No video", "Video codecs list"), new BMessage(VIDEO_CODEC_SELECT_MESSAGE))); menu->AddSeparatorItem(); separator = false; } cmi = new CodecMenuItem(&codec_info, VIDEO_CODEC_SELECT_MESSAGE); menu->AddItem(cmi); } // mark first video encoder item = menu->ItemAt(0); if (item != NULL) { fVideoMenu->SetEnabled(fEnabled); fVideoQualitySlider->SetEnabled(fEnabled); item->SetMarked(true); ((BInvoker*)item)->Invoke(); } else { item = new BMenuItem( B_TRANSLATE_CONTEXT("None available", "Video codecs"), NULL); menu->AddItem(item); item->SetMarked(true); fVideoMenu->SetEnabled(false); fVideoQualitySlider->SetEnabled(false); } }