当前位置: 首页>>代码示例>>C++>>正文


C++ BMediaFormats::GetFormatFor方法代码示例

本文整理汇总了C++中BMediaFormats::GetFormatFor方法的典型用法代码示例。如果您正苦于以下问题:C++ BMediaFormats::GetFormatFor方法的具体用法?C++ BMediaFormats::GetFormatFor怎么用?C++ BMediaFormats::GetFormatFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BMediaFormats的用法示例。


在下文中一共展示了BMediaFormats::GetFormatFor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: register_encoder

void register_encoder()
{
	status_t err;
	media_format				tempFormat, mediaFormat;
	media_format_description	formatDescription;
	BMediaFormats				formatObject;

	formatObject.Lock();

	/* register as a WAV codec */
	memset(&mediaFormat, 0, sizeof(media_format));
	mediaFormat.type = B_MEDIA_ENCODED_AUDIO;
	mediaFormat.u.encoded_audio = media_encoded_audio_format::wildcard;
	memset(&formatDescription, 0, sizeof(media_format_description));
	formatDescription.family = B_WAV_FORMAT_FAMILY;
	formatDescription.u.wav.codec = WAVE_FORMAT_MPEG;
	err = formatObject.MakeFormatFor(formatDescription, mediaFormat, &tempFormat);
	if (err == B_MEDIA_DUPLICATE_FORMAT)
		formatObject.GetFormatFor(formatDescription, &tempFormat);
	s_wavFormat = tempFormat;

	/* register as a MPEG codec */
	memset(&mediaFormat, 0, sizeof(media_format));
	mediaFormat.type = B_MEDIA_ENCODED_AUDIO;
	mediaFormat.u.encoded_audio = media_encoded_audio_format::wildcard;
	memset(&formatDescription, 0, sizeof(media_format_description));
	formatDescription.family = B_MPEG_FORMAT_FAMILY;
	formatDescription.u.mpeg.id = B_MPEG_1_AUDIO_LAYER_3;
	err = formatObject.MakeFormatFor(formatDescription, mediaFormat, &tempFormat);
	if (err == B_MEDIA_DUPLICATE_FORMAT)
		formatObject.GetFormatFor(formatDescription, &tempFormat);
	s_mpegFormat = tempFormat;

	formatObject.Unlock();
}
开发者ID:HaikuArchives,项目名称:UltraEncode,代码行数:35,代码来源:MP3Encoder.cpp

示例2:

status_t 
BMediaFormats::GetBeOSFormatFor(uint32 format, 
	media_format* _format, media_type type)
{
	BMediaFormats formats;

	media_format_description description;
	description.family = B_BEOS_FORMAT_FAMILY;
	description.u.beos.format = format;

	status_t status = formats.GetFormatFor(description, _format);
	if (status < B_OK)
		return status;

	if (type != B_MEDIA_UNKNOWN_TYPE && type != _format->type)
		return B_BAD_TYPE;

	return B_OK;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:19,代码来源:MediaFormats.cpp

示例3: get_media_format_for

status_t OpenSoundDevice::get_media_format_for(int fmt, media_format &format)
{
	status_t err;
	BMediaFormats formats;
	if (formats.InitCheck() < B_OK)
		return formats.InitCheck();
	/* shortcut for raw */
	if (fmt & AFMT_SUPPORTED_PCM) {
		format = media_format();
		format.type = B_MEDIA_RAW_AUDIO;
		format.u.raw_audio = media_raw_audio_format::wildcard;
		return B_OK;
	}
	media_format_description desc;
	err = get_media_format_description_for(fmt, &desc);
	if (err < B_OK)
		return err;
	err = formats.GetFormatFor(desc, &format);
	return err;
};
开发者ID:jiangxilong,项目名称:haiku,代码行数:20,代码来源:OpenSoundDevice.cpp

示例4:

static status_t
get_text_format(tobias_stream_header * header, media_format * format)
{
	TRACE("  get_text_format\n");
	// get the format for the description
	media_format_description description = tobias_text_description();
	BMediaFormats formats;
	status_t result = formats.InitCheck();
	if (result == B_OK) {
		result = formats.GetFormatFor(description, format);
	}
	if (result != B_OK) {
		*format = tobias_text_encoded_media_format();
		// ignore error, allow user to use ReadChunk interface
	}

	// fill out format from header packet

	return B_OK;
}
开发者ID:mariuz,项目名称:haiku,代码行数:20,代码来源:OggTobiasSeekable.cpp

示例5: AudioBufferSize

static status_t
get_audio_format(tobias_stream_header * header, media_format * format)
{
	TRACE("  get_audio_format\n");
	// get the format for the description
	media_format_description description = tobias_audio_description();
	unsigned int wav_id = 0;
	sscanf(header->subtype, "%04x", &wav_id);
	description.u.wav.codec = wav_id;
	BMediaFormats formats;
	status_t result = formats.InitCheck();
	if (result == B_OK) {
		result = formats.GetFormatFor(description, format);
	}
	if (result != B_OK) {
		*format = tobias_audio_encoded_media_format();
		// ignore error, allow user to use ReadChunk interface
	}

	// fill out format from header packet
	format->user_data_type = B_CODEC_TYPE_INFO;
	strncpy((char*)format->user_data, header->subtype, 4);
	format->u.encoded_audio.bit_rate = header->audio.avgbytespersec * 8;
	if (header->audio.channels == 1) {
		format->u.encoded_audio.multi_info.channel_mask = B_CHANNEL_LEFT;
	} else {
		format->u.encoded_audio.multi_info.channel_mask = B_CHANNEL_LEFT | B_CHANNEL_RIGHT;
	}
	format->u.encoded_audio.output.frame_rate = header->samples_per_unit * 10000000.0 / header->time_unit;
	format->u.encoded_audio.output.channel_count = header->audio.channels;
	format->u.encoded_audio.output.buffer_size
	  = AudioBufferSize(&format->u.encoded_audio.output);

	// TODO: wring more info out of the headers

	return B_OK;
}
开发者ID:mariuz,项目名称:haiku,代码行数:37,代码来源:OggTobiasSeekable.cpp

示例6: codecOpener


//.........这里部分代码省略.........
					= B_MEDIA_BIG_ENDIAN;
				break;
			case CODEC_ID_PCM_U16LE:
//				format->u.raw_audio.format
//					= media_raw_audio_format::B_AUDIO_USHORT;
//				format->u.raw_audio.byte_order
//					= B_MEDIA_LITTLE_ENDIAN;
				return B_NOT_SUPPORTED;
				break;
			case CODEC_ID_PCM_U16BE:
//				format->u.raw_audio.format
//					= media_raw_audio_format::B_AUDIO_USHORT;
//				format->u.raw_audio.byte_order
//					= B_MEDIA_BIG_ENDIAN;
				return B_NOT_SUPPORTED;
				break;
			case CODEC_ID_PCM_S8:
				format->u.raw_audio.format
					= media_raw_audio_format::B_AUDIO_CHAR;
				break;
			case CODEC_ID_PCM_U8:
				format->u.raw_audio.format
					= media_raw_audio_format::B_AUDIO_UCHAR;
				break;
			default:
				return B_NOT_SUPPORTED;
				break;
		}
	} else {
		if (description.family == B_MISC_FORMAT_FAMILY)
			description.u.misc.codec = codecContext->codec_id;

		BMediaFormats formats;
		status_t status = formats.GetFormatFor(description, format);
		if (status < B_OK)
			TRACE("  formats.GetFormatFor() error: %s\n", strerror(status));

		format->user_data_type = B_CODEC_TYPE_INFO;
		*(uint32*)format->user_data = codecContext->codec_tag;
		format->user_data[4] = 0;
	}

	format->require_flags = 0;
	format->deny_flags = B_MEDIA_MAUI_UNDEFINED_FLAGS;

	switch (format->type) {
		case B_MEDIA_RAW_AUDIO:
			format->u.raw_audio.frame_rate = (float)codecContext->sample_rate;
			format->u.raw_audio.channel_count = codecContext->channels;
			format->u.raw_audio.channel_mask = codecContext->channel_layout;
			format->u.raw_audio.byte_order
				= avformat_to_beos_byte_order(codecContext->sample_fmt);
			format->u.raw_audio.format
				= avformat_to_beos_format(codecContext->sample_fmt);
			format->u.raw_audio.buffer_size = 0;

			// Read one packet and mark it for later re-use. (So our first
			// GetNextChunk() call does not read another packet.)
			if (_NextPacket(true) == B_OK) {
				TRACE("  successfully determined audio buffer size: %d\n",
					fPacket.size);
				format->u.raw_audio.buffer_size = fPacket.size;
			}
			break;

		case B_MEDIA_ENCODED_AUDIO:
开发者ID:RAZVOR,项目名称:haiku,代码行数:67,代码来源:AVFormatReader.cpp

示例7: Source


//.........这里部分代码省略.........
		case SND_FORMAT_LINEAR_32:
			fBitsPerSample = 32; fRaw = true; break;
		case SND_FORMAT_FLOAT:
			fBitsPerSample = 32; fRaw = true; break;
		case SND_FORMAT_DOUBLE:
			fBitsPerSample = 64; fRaw = true; break;
		case SND_FORMAT_ADPCM_G721:
			fBitsPerSample = 4; fRaw = false; break;
		case SND_FORMAT_ADPCM_G722:
			fBitsPerSample = 8; fRaw = false; break;
		case SND_FORMAT_ADPCM_G723_3:
			fBitsPerSample = 3; fRaw = false; break;
		case SND_FORMAT_ADPCM_G723_5:
			fBitsPerSample = 5; fRaw = false; break;
		case SND_FORMAT_ALAW_8:
			fBitsPerSample = 8; fRaw = false; break;
		default:
			fBitsPerSample = 0; break;
	}
	if (fBitsPerSample == 0) {
		TRACE("auReader::Sniff: sample format not recognized\n");
		return B_ERROR;
	}
	
	fFrameCount = (8 * fDataSize) / (fChannelCount * fBitsPerSample);
	fDuration = (1000000LL * fFrameCount) / fFrameRate;
	fBitsPerFrame = fChannelCount * fBitsPerSample;
	fBlockAlign = fBitsPerFrame;
	while (fBlockAlign % 8 && fBlockAlign < 1000)
		fBlockAlign += fBlockAlign;
	if (fBlockAlign % 8) {
		TRACE("auReader::Sniff: can't find block alignment, fChannelCount %d, fBitsPerSample %d\n", fChannelCount, fBitsPerSample);
		return B_ERROR;
	}
	fBlockAlign /= 8;

	fPosition = 0;
	
	fBufferSize = (BUFFER_SIZE / fBlockAlign) * fBlockAlign;
	fBuffer = malloc(fBufferSize);

	TRACE("  fDataStart     %Ld\n", fDataStart);
	TRACE("  fDataSize      %Ld\n", fDataSize);
	TRACE("  fFrameCount    %Ld\n", fFrameCount);
	TRACE("  fDuration      %Ld\n", fDuration);
	TRACE("  fChannelCount  %d\n", fChannelCount);
	TRACE("  fFrameRate     %ld\n", fFrameRate);
	TRACE("  fBitsPerSample %d\n", fBitsPerSample);
	TRACE("  fBlockAlign    %d\n", fBlockAlign);
	TRACE("  fFormatCode    %ld\n", fFormatCode);
	TRACE("  fRaw           %d\n", fRaw);
	
	BMediaFormats formats;
	if (fRaw) {
		// a raw PCM format
		media_format_description description;
		description.family = B_BEOS_FORMAT_FAMILY;
		description.u.beos.format = B_BEOS_FORMAT_RAW_AUDIO;
		formats.GetFormatFor(description, &fFormat);
		fFormat.u.raw_audio.frame_rate = (fFrameRate == 8012) ? SND_RATE_8012 : fFrameRate;
		fFormat.u.raw_audio.channel_count = fChannelCount;
		switch (fFormatCode) {
			case SND_FORMAT_LINEAR_8:
				fFormat.u.raw_audio.format = media_raw_audio_format::B_AUDIO_UCHAR;
				break;
			case SND_FORMAT_LINEAR_16:
				fFormat.u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT;
				break;
			case SND_FORMAT_LINEAR_24:
				fFormat.u.raw_audio.format = B_AUDIO_FORMAT_INT24;
				break;
			case SND_FORMAT_LINEAR_32:
				fFormat.u.raw_audio.format = media_raw_audio_format::B_AUDIO_INT;
				break;
			case SND_FORMAT_FLOAT:
				fFormat.u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
				break;
			case SND_FORMAT_DOUBLE:
				fFormat.u.raw_audio.format = B_AUDIO_FORMAT_FLOAT64;
				break;
			default:
				TRACE("auReader::Sniff: unhandled raw format\n");
				return B_ERROR;
		}
		fFormat.u.raw_audio.byte_order = B_MEDIA_BIG_ENDIAN;
		fFormat.u.raw_audio.buffer_size = fBufferSize;
	} else {
		// some encoded format
		media_format_description description;
		description.family = B_MISC_FORMAT_FAMILY;
		description.u.misc.file_format = 'au';
		description.u.misc.codec = fFormatCode;
		formats.GetFormatFor(description, &fFormat);
		fFormat.u.encoded_audio.output.frame_rate = fFrameRate;
		fFormat.u.encoded_audio.output.channel_count = fChannelCount;
	}
	
	*streamCount = 1;
	return B_OK;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:101,代码来源:au_reader.cpp

示例8: GetPacket

status_t
OggVorbisSeekable::GetStreamInfo(int64 *frameCount, bigtime_t *duration,
                               media_format *format)
{
	TRACE("OggVorbisSeekable::GetStreamInfo\n");
	status_t result = B_OK;
	ogg_packet packet;

	// get header packet
	if (GetHeaderPackets().size() < 1) {
		result = GetPacket(&packet);
		if (result != B_OK) {
			return result;
		}
		SaveHeaderPacket(packet);
	}
	packet = GetHeaderPackets()[0];
	if (!packet.b_o_s) {
		return B_ERROR; // first packet was not beginning of stream
	}

	// parse header packet
	// based on libvorbis/info.c vorbis_synthesis_headerin(...)
	oggpack_buffer opb;
	oggpack_readinit(&opb, packet.packet, packet.bytes);
	int packtype = oggpack_read(&opb, 8);
	if (packtype != 0x01) {
		return B_ERROR; // first packet was not an info packet
	}
	// discard vorbis string
	for (uint i = 0 ; i < sizeof("vorbis") - 1 ; i++) {
		oggpack_read(&opb, 8);
	}
	vorbis_info info;
	if (_vorbis_unpack_info(&info, &opb) != 0) {
		return B_ERROR; // couldn't unpack info
	}

	// get the format for the description
	media_format_description description = vorbis_description();
	BMediaFormats formats;
	result = formats.InitCheck();
	if (result == B_OK) {
		result = formats.GetFormatFor(description, format);
	}
	if (result != B_OK) {
		*format = vorbis_encoded_media_format();
		// ignore error, allow user to use ReadChunk interface
	}

	// fill out format from header packet
	if (info.bitrate_nominal > 0) {
		format->u.encoded_audio.bit_rate = info.bitrate_nominal;
	} else if (info.bitrate_upper > 0) {
		format->u.encoded_audio.bit_rate = info.bitrate_upper;
	} else if (info.bitrate_lower > 0) {
		format->u.encoded_audio.bit_rate = info.bitrate_lower;
	}
	if (info.channels == 1) {
		format->u.encoded_audio.multi_info.channel_mask = B_CHANNEL_LEFT;
	} else {
		format->u.encoded_audio.multi_info.channel_mask = B_CHANNEL_LEFT | B_CHANNEL_RIGHT;
	}
	fFrameRate = format->u.encoded_audio.output.frame_rate = (float)info.rate;
	format->u.encoded_audio.output.channel_count = info.channels;
	format->u.encoded_audio.output.buffer_size
	  = AudioBufferSize(&format->u.encoded_audio.output);

	// get comment packet
	if (GetHeaderPackets().size() < 2) {
		result = GetPacket(&packet);
		if (result != B_OK) {
			return result;
		}
		SaveHeaderPacket(packet);
	}

	// get codebook packet
	if (GetHeaderPackets().size() < 3) {
		result = GetPacket(&packet);
		if (result != B_OK) {
			return result;
		}
		SaveHeaderPacket(packet);
	}

	format->SetMetaData((void*)&GetHeaderPackets(),sizeof(GetHeaderPackets()));

	// TODO: count the frames in the first page.. somehow.. :-/
	int64 frames = 0;

	ogg_page page;
	// read the first page
	result = ReadPage(&page);
	if (result != B_OK) {
		return result;
	}
	int64 fFirstGranulepos = ogg_page_granulepos(&page);
	TRACE("OggVorbisSeekable::GetStreamInfo: first granulepos: %lld\n", fFirstGranulepos);
	// read our last page
//.........这里部分代码省略.........
开发者ID:mariuz,项目名称:haiku,代码行数:101,代码来源:OggVorbisSeekable.cpp


注:本文中的BMediaFormats::GetFormatFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。