示例#1
0
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;
	}
}
示例#2
0
void 
MediaFileInfoView::_GetFileInfo(BString* audioFormat, BString* videoFormat,
	BString* audioDetails, BString* videoDetails, BString* duration)
{
	fDuration = 0;
	if (fMediaFile == NULL)
		return;
	
	BMediaTrack* track;
	media_format format;
	memset(&format, 0, sizeof(format));
	media_codec_info codecInfo;
	bool audioDone(false), videoDone(false);
	bigtime_t audioDuration = 0;
	bigtime_t videoDuration = 0;
	int32 tracks = fMediaFile->CountTracks();
	int64 videoFrames = 0;
	int64 audioFrames = 0;
	for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
		track = fMediaFile->TrackAt(i);
		if (track != NULL) {
			track->EncodedFormat(&format);
			if (format.IsVideo()) {
				memset(&format, 0, sizeof(format));
				format.type = B_MEDIA_RAW_VIDEO;
				track->DecodedFormat(&format);
				media_raw_video_format *rvf = &(format.u.raw_video);

				track->GetCodecInfo(&codecInfo);
				*videoFormat << codecInfo.pretty_name;
				videoDuration = track->Duration();
				videoFrames = track->CountFrames();

				*videoDetails << (int32)format.Width() << "x" << (int32)format.Height()
							 << " " << (int32)(rvf->field_rate / rvf->interlace)
							 << " fps / "  << videoFrames << " frames";

				videoDone = true;

			} else if (format.IsAudio()) {
				memset(&format, 0, sizeof(format));
				format.type = B_MEDIA_RAW_AUDIO;
				track->DecodedFormat(&format);
				media_raw_audio_format *raf = &(format.u.raw_audio);
				char bytesPerSample = (char)(raf->format & 0xf);
				if (bytesPerSample == 1) {
					*audioDetails << "8 bit ";
				} else if (bytesPerSample == 2) {
					*audioDetails << "16 bit ";
				} else {
					*audioDetails << bytesPerSample << "byte ";
				}

				track->GetCodecInfo(&codecInfo);
				*audioFormat << codecInfo.pretty_name;
				audioDuration = track->Duration();
				audioFrames = track->CountFrames();

				*audioDetails << (float)(raf->frame_rate / 1000.0f) << " kHz";
				if (raf->channel_count == 1) {
					*audioDetails << " mono / ";
				} else if (raf->channel_count == 2) {
					*audioDetails << " stereo / ";
				} else {
					*audioDetails << (int32)raf->channel_count << " channel / " ;
				}
				*audioDetails << audioFrames << " frames";
				audioDone = true;
			}
			fMediaFile->ReleaseTrack(track);
		}	
	}

	fDuration = MAX(audioDuration, videoDuration);
	*duration << (int32)(fDuration / 1000000)
			  << " seconds";
}
示例#3
0
status_t
MediaFileInfo::LoadInfo(BMediaFile* file)
{
	_Reset();
	if (!file)
		return B_BAD_VALUE;
	
	BMediaTrack* track;
	media_format format;
	memset(&format, 0, sizeof(format));
	media_codec_info codecInfo;
	bool audioDone(false), videoDone(false);
	bigtime_t audioDuration = 0;
	bigtime_t videoDuration = 0;
	int32 tracks = file->CountTracks();
	int64 videoFrames = 0;
	int64 audioFrames = 0;
	status_t ret = B_OK;

	for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
		track = file->TrackAt(i);
		if (track == NULL)
			return B_ERROR;

		ret = track->InitCheck();
		if (ret != B_OK)
			return ret;

		ret = track->EncodedFormat(&format);
		if (ret != B_OK)
			return ret;

		if (format.IsVideo()) {
			memset(&format, 0, sizeof(format));
			format.type = B_MEDIA_RAW_VIDEO;

			ret = track->DecodedFormat(&format);
			if (ret != B_OK)
				return ret;

			media_raw_video_format *rvf = &(format.u.raw_video);

			ret = track->GetCodecInfo(&codecInfo);
			if (ret != B_OK)
				return ret;

			video.format << codecInfo.pretty_name;
			videoDuration = track->Duration();
			videoFrames = track->CountFrames();

			BString details;
			snprintf(details.LockBuffer(256), 256,
					B_TRANSLATE_COMMENT("%u x %u, %.2ffps / %Ld frames",
					"Width x Height, fps / frames"),
					format.Width(), format.Height(),
					rvf->field_rate / rvf->interlace, videoFrames);
			details.UnlockBuffer();
			video.details << details;
			videoDone = true;

		} else if (format.IsAudio()) {
			memset(&format, 0, sizeof(format));
			format.type = B_MEDIA_RAW_AUDIO;
			ret = track->DecodedFormat(&format);
			if (ret != B_OK)
				return ret;
			media_raw_audio_format *raf = &(format.u.raw_audio);
			char bytesPerSample = (char)(raf->format & 0xf);

			BString details;
			if (bytesPerSample == 1 || bytesPerSample == 2) {
				snprintf(details.LockBuffer(16), 16,
						B_TRANSLATE("%d bit "), bytesPerSample * 8);
			} else {
				snprintf(details.LockBuffer(16), 16,
						B_TRANSLATE("%d byte "), bytesPerSample);
			}
			details.UnlockBuffer();
			audio.details << details;

			ret = track->GetCodecInfo(&codecInfo);
			if (ret != B_OK)
				return ret;

			audio.format << codecInfo.pretty_name;
			audioDuration = track->Duration();
			audioFrames = track->CountFrames();
			BString channels;
			if (raf->channel_count == 1) {
				snprintf(channels.LockBuffer(64), 64,
				B_TRANSLATE("%.1f kHz mono / %lld frames"), 
				raf->frame_rate / 1000.f, audioFrames);
			} else if (raf->channel_count == 2) {
				snprintf(channels.LockBuffer(64), 64,
				B_TRANSLATE("%.1f kHz stereo / %lld frames"), 
				raf->frame_rate / 1000.f, audioFrames);
			} else {
				snprintf(channels.LockBuffer(64), 64,
				B_TRANSLATE("%.1f kHz %ld channel / %lld frames"), 
				raf->frame_rate / 1000.f, raf->channel_count, audioFrames);
			}
			channels.UnlockBuffer();
			audio.details << channels;

			audioDone = true;
		}
		ret = file->ReleaseTrack(track);
		if (ret != B_OK)
			return ret;
	}

	useconds = MAX(audioDuration, videoDuration);
	duration << (int32)(useconds / 1000000)
			  << B_TRANSLATE(" seconds");

	return B_OK;
}